akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
    const int NUM = 10000;
    const int MAX = 1000000;
    long data;
    int num;
    long min, max, sum;

    cin >> num;

    if (num <= 0 || num > 10000) return 0;

    min = 1000000;
    max = -1000000;
    sum = 0;
    
    for (int i = 0; i < num; i++) {
        cin >> data;
        if (data >= -1000000 && data <= 1000000) {
            if (min > data) min = data;
            if (max < data) max = data;
            sum += data;
        }
     }
     cout << min << " " << max << " " << sum << endl;

    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
using namespace std;

int main(){
    int N;
    cin >> N;
    int d[300000];
    for(int i=0;i<N;i++){
        cin >> d[i];
    }

    int maxd = 0;
    for(int i=0;i<N-1;i++){
        maxd = (maxd>d[i])?maxd:d[i];
        if(maxd<10){
            cout << "no" << endl;
            return 0;
        }
        maxd -= 10;
    }

    maxd = 0;
    for(int i=N-1;i>0;i--){
        maxd = (maxd>d[i])?maxd:d[i];
        if(maxd<10){
            cout << "no" << endl;
            return 0;
        }
        maxd -= 10;
    }

    cout << "yes" << endl;
    return 0;
} 


Measured memory_bytes: 4280
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b == c || b + c == a || a + c == b) {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int A = sc.nextInt();
      	int B = sc.nextInt();
      	
      	if(A <= 8 && B <= 8) {
        	System.out.println("Yay!");  
        } else {
        	System.out.println(":(");
        }
    }
}

Measured memory_bytes: 21844
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n;
    cin >> n;   
    cout << n * (n+1) / 2 << endl;
}

Measured memory_bytes: 256
# input
N = int(input())
B = list(map(int, input().split()))

# check
A = []
append = A.append
for i, b in enumerate(B):
    while len(A[i:]) < 2:
        if not A:
            append(b)
        elif i < len(B) - 1 and max([A[i], b]) >= B[i + 1]:
            append(B[i + 1])
        else:
            append(b)

print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    
    if (s == u)
        a--;
    if (t == u)
        b--;
    
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{int N,Y,sum,flag,i,j,k;
	flag=0;
	scanf("%d%d",&N,&Y);
	for(i=0;i<=N;i++){
		for(j=0;j<=N-i;j++){
			sum=10000*i+5000*j+1000*(N-i-j);
			if(sum==Y){
				printf("%d %d %d",i,j,N-i-j);
				flag=1;
				break;}
				}
				if(flag==1)break;}
				
if(flag==0){
printf("-1 -1 -1");}

	return 0;
}


Measured memory_bytes: 128
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,c[200010];
vpi range;
int waiting[200010],dp[200010];
signed main(){
    I(n);
    REP(i,n) {
        I(c[i]);
        if(waiting[c[i]] && waiting[c[i]] != i){
            range.eb(i,waiting[c[i]]-1);
        }
        waiting[c[i]] = i+1;
    }
    sort(all(range),greater<pi>());

    // for(auto v:range) cerr << v.first << " " << v.second << endl;
    int rind = 0;
    int mxrind = sz(range);
    dp[n-1] = 1;
    REPNS(i,n-1){
        while(rind < mxrind && range[rind].first == i){
            dp[range[rind].second] += dp[i];
            dp[range[rind].second] %= mod;
            rind++;
        }
        dp[i-1] += dp[i];
        dp[i-1] %= mod;
        // REP(j,n) cerr << dp[j]  << " " ;
        // cerr << endl;
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 9456
s = input()
a = [int(c) for c in s]


if len(a) < 4:
    print(1000 - int(s))
elif a[-3] != 0:
    print((a[-4]+1)*1000 - int(s))
elif int(s) % 1000 != 0:
    print((a[-4]+1)*1000 - int(s))
else:
    print(0)

Measured memory_bytes: 9160
n, p = map(int, input().split())
a = list(map(int, input().split()))
even_cnt = 1
odd_cnt = 0
for i in range(n):
  if a[i] % 2 == 0:
    even_cnt *= 2
    odd_cnt *= 2
  else:
    k = even_cnt
    l = odd_cnt
    even_cnt = k + l
    odd_cnt = k + l
if p == 0:
  print(even_cnt)
else:
  print(odd_cnt)
    
  

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <ostream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;

template <typename T, typename U>
std::ostream& operator << (std::ostream& out, std::pair<T, U> p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T>
std::ostream& operator << (std::ostream& out, std::vector<T> v) {
  out << "[";
  for (int i = 0; i < v.size(); ++i) {
    out << v[i] << (i == (v.size() - 1) ? "" : ", ");
  }
  out << "]";
  return out;
}

int N;
ll X;
ll burger[51] = { 0 }; // burger[i] := レベル N に含まれるパティの数
ll layer_num = 1;

// バーガーの下(b)と上(t)とレベル(level)
// 閉区間 [b, t]
ll solve(ll b, ll t, ll level) {
  //cerr << "b, t, level = " << b << ", " << t << ", " << level << endl;
  //cerr << endl;
  if (b > X) {
    //cerr << "b >= X" << endl;
    return 0;
  }

  if (level == 0) {
    //cerr << "level 0" << endl;
    return 1;
  }
  if (t <= X) {
    //cerr << "t <= X" << endl;
    return burger[level];
  }
  //cerr << "next : (" << b + 1 << ", " << (t + b) / 2 - 1 << "), ... (" << (t + b) / 2 + 1 << ", " << t - 1 << ")" << endl;
  return solve(b + 1, (t + b) / 2 - 1, level - 1) + solve((t + b) / 2 + 1, t - 1, level - 1) + (X >= (t + b) / 2);
}

int main() {
  cin >> N >> X;
  X--;
  //cerr << "X's index : " << X << endl;

  burger[0] = 1;

  // レベル i に含まれるパティの数を求める
  for (int i = 1; i <= N; ++i) {
    burger[i] = burger[i - 1] * 2 + 1;
  }

  // レベル N のバーガーの総層数を求める
  layer_num = 1;
  for (int i = 1; i <= N; ++i) {
    layer_num = layer_num * 2 + 3;
  }
  cout << solve(0, layer_num - 1, N) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int main(){
  int a;
  cin>>a;
  string s;
  cin>>s;

  if(a>=3200) cout<<s<<endl;
  else cout<<"red"<<endl;

  return 0;
}


Measured memory_bytes: 256
A,B = map(int,input().split())
count = 0
for i in range(A,B+1):
  i = str(i)
  num = 1
  if len(i)%2 == 0:
    num = 0
  left = i[:len(i)//2]
  right = i[len(i)//2+num:]
  right = right[::-1]
  if left == right:
    count += 1
print(count)

Measured memory_bytes: 73260
#include<stdio.h>

int main()
{
  int a,b,c;
  int count,i;
  scanf("%d",&count);
  for(i=0;i<count;i++)
  {
    scanf("%d %d %d",&a,&b,&c);
  
    if(((a*a+b*b)==c*c)||((a*a+c*c)==b*b)||((b*b+c*c)==a*a))printf("YES\n");
    else printf("NO\n");
  }
 return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

ll dp[111][5][5][5];

int main(){
  int N; cin>>N;
  dp[0][0][0][0]=1;
  rep(i,N) rep(j,5) rep(k,5) rep(l,5){
    rep(m,4) (dp[i+1][k][l][m+1]+=dp[i][j][k][l])%=MOD;
    if((j==1&&k==3)||(j==1&&l==3)||(k==3&&l==1)||(k==1&&l==3)){
      // AG GA
      (dp[i+1][k][l][2]+=MOD-dp[i][j][k][l])%=MOD;
    }
    if(k==1&&l==2){
      // AC
      (dp[i+1][k][l][3]+=MOD-dp[i][j][k][l])%=MOD;
    }
  }
  ll ans=0;
  rep(i,4) rep(j,4) rep(k,4) (ans+=dp[N][i+1][j+1][k+1])%=MOD;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3700
using System;

namespace てすと
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputNum = Console.ReadLine().Split(' ');
            var num1 = Convert.ToDecimal(inputNum[0]);
            var num2 = Convert.ToDecimal(inputNum[1]);
            var num3 = Math.Floor(num1 * num2);
            Console.WriteLine(num3);
        }
    }
}

Measured memory_bytes: 27564
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String W = sc.next();
        int count = 0;
        while(true){
            String T = sc.next();
            if(T.equals("END_OF_TEXT")){
                break;
            }
            if((T.toLowerCase()).equals(W)){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26104
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    if(n%2){
        vector<int> m1(n/2+1,0),m2(n/2+1,0),m3(n/2+1,0);
        rep(i,n/2){
                m1[i+1]=m1[i]+a[i*2];
                m2[i+1]=m2[i]+a[i*2+1];
                m3[i+1]=m3[i]+a[i*2+2];
        }
        int ans=LLONG_MIN;
        priority_queue<int> que;
        for(int i=n/2;i>=0;i--){
            que.push((m3[n/2]-m3[i]+m2[i]));
            int it=que.top();
            ans=max(ans,it-m2[i]+m1[i]);
        }
        cout<<ans<<endl;
    }
    else{
        vector<int>m1(n/2+1,0),m2(n/2+1,0);
        rep(i,n/2){
            m1[i+1]=m1[i]+a[i*2];
            m2[i+1]=m2[i]+a[i*2+1];
        }
        int ans=LLONG_MIN;
        rep(i,n/2+1){
            int it=m2[n/2]-m2[i]+m1[i];
            ans=max(ans,it);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 8196
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
    int n;  cin >> n;
    vector<vector<int> > a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
    }

    ll tmp = 1;
    for (int i = 0; i < n; i++)
        tmp *= 2;
    ll mod = 1e9+7;

    vector<ll> dp(tmp, 0);
    dp[0] = 1;

    for (int s = 0; s < (1<<n); s++) {
        int i = 0;
        for (int j = 0; j < n; j++) {
            if ((s>>j) & 1)
                i++;
        }

        for (int j = 0; j < n; j++) {
            if (s>>j & 1 && a[i-1][j])
                dp[s] += dp[s^(1<<j)];
            dp[s] %= mod; 
        }
    }

    cout << dp[tmp-1] << endl;
    return 0;
}

Measured memory_bytes: 19628
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;
 
#define Endl endl
 
map<string, string> mp, mpg, mpa;
 
 
/*--------------------template--------------------*/
 
int main() {
 
    cin >> n >> m;
    cout << (double)2 * m - n << endl;
}

Measured memory_bytes: 256
/*
  双方向連結リスト
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

/*リスト中にキーkeyを持つノードを探索しそのアドレスを返す ただし、存在しない場合はNULLを返す*/
NodePointer listSearch(int key)
{
  NodePointer p;

  nil->key = key;   /*リスト中にkeyがなかったときのためにnil->key に keyを挿入*/
  for( p = nil->next; p->key != key; p = p->next )
    ;

  if( p == nil )
    return NULL;
  else
    return p;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t)
{
  t->prev->next = t->next;
  t->next->prev = t->prev;
  
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer p;
  
  if( nil->next == nil )
    return;
  p = nil->prev;
  nil->prev = p->prev;
  deleteNode( p );
}

void delete(int key)
{
  NodePointer p;

  if( ( p = listSearch(key)) == NULL )
    return;
  
  deleteNode( p );
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  if( nil->next == nil )
    nil->prev = x;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++; }
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32956
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int a=stdIn.nextInt();
		int b=stdIn.nextInt();
		int c=stdIn.nextInt();
		int count=0;
		for(int i=a;i<=b;i++){
			if(c%i==0){
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 26408
#include <iostream>
#include <string>
using namespace std;

int main(){
    string S;
    cin >> S;
    int value = 700;
    if (S[0] == 'o'){
        value += 100;
    }if (S[1] == 'o'){
        value += 100;
    }if (S[2] == 'o'){
        value += 100;
    }
    cout << value << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  int64_t mon=1000, num=0;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++)
    cin >> a[i];
  for(int i=0; i<n-1; i++){
    if(a[i]<a[i+1]){
      num+=mon/a[i];
      mon%=a[i];
    }
    else if(a[i]>a[i+1]){
      mon+=a[i]*num;
      num=0;
    }
  }
  cout << num*a[n-1]+mon;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int count=0;
	int count1=0;
	if(n<105)
	  cout<<"0"<<endl;
	else
	{
		for(int i=106;i<=n;i++)
		{
			count1=0;
			for(int j=1;j<=i;j=j+2)
			{
				if(i%j==0)
				count1++;
			}
			if(count1==8)
			count++;
		}
		cout<<count+1<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
 
  int i,j,n,q,S[10001],T[501];
 
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%d", &S[i] );
  }
 
  scanf("%d", &q );
  for ( i = 0; i < q; i++ ){
    scanf("%d", &T[i] );
  }
 
  int key,cnt;
  cnt = 0;
 
  for ( i = 0; i < q; i++ ){
    key = T[i];
    for ( j = 0; j < n; j++ ){
      if ( S[j] == key ){
    cnt += 1;
    break;
      } 
    }
  }
 
  printf("%d\n", cnt );
 
  return 0;
 
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))


n = inp()
scores = []
for i in range(n):
	scores.append(inlt())
#stones = inlt()

if n == 0: 
	print 0
	
#print n, kk

inf = 2 ** 31
# dp[i][j] states the maximum scores to day i with last step chose j 
dp = [[0, 0, 0] for _ in range(len(scores))]

for choice in range(3):
	dp[0][choice] = scores[0][choice]

for i in range(1, len(dp)):
	for choice in range(3):
		for lastCho in range(3):
			if choice != lastCho: 
				dp[i][choice] = max(dp[i][choice], dp[i-1][lastCho] + scores[i][choice])

print max(dp[-1])


Measured memory_bytes: 45300
#include <iostream>

using namespace std;

int main() {
 int W, H;
 int x, y, r;

 cin >> W >> H >> x >> y >> r;

 if((x + r) <= W && (x - r) >= 0 && (y + r) <= H && (y - r) >= 0) {
  cout << "Yes" << endl;
 } else {
  cout << "No" << endl;
 }

 return 0;
}

Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;


int main()
{
	string s;
	cin >> s;
	
	int n = s.size();
	int cnt0 = 0;
	int cnt1 = 0;

	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			if (s[i] == '0') {
				cnt1++;
			} else {
				cnt0++;
			}
		}
		if (i % 2 != 0) {
			if (s[i] == '0') {
				cnt0++;
			} else {
				cnt1++;
			}
		}
	}

	int ans = min(cnt0, cnt1);

	cout << ans << endl;

}

Measured memory_bytes: 512
import sys

A = list(map(int, input().split()))

N = min(A)
M = max(A)

if(N == 1 and M == 1):
    print(1)
    sys.exit()

if(N > 2 and M > 2):
    print((N - 2) * (M - 2))
else:
    if(N == 2 or M <= 2):
        print(0)
    else:
        print(M-2)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdint>

using namespace std;

int main() {
    int64_t N;
    cin >> N;

    int64_t s = 0;

    for (int64_t i = 1; i <= N; ++i)
    {
        s += i;
    }

    for (int64_t i = 3; i <= N; i += 3)
    {
        s -= i;
    }

    for (int64_t i = 5; i <= N; i += 5)
    {
        s -= i;
    }

    for (int64_t i = 15; i <= N; i += 15)
    {
        s += i;
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3624
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A[] = new int[N];
    int index = 1;
    int broken = 0;
    boolean b = false;
    for(int i=0; i<N; i++){
      A[i]=sc.nextInt();
      if(A[i] == index){
        b = true;
        index++;
      }else{
        broken++;
      }
    }
    if (b){
      System.out.println(broken);
    }else{
      System.out.println("-1");
    }
  }
}
    

Measured memory_bytes: 60584
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }


const int limit =100010;
using edge =struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v,int p,ll d){
  depth[v]=d;
  for(auto &e:tree[v]){
    if(e.to==p) continue;
    dfs(e.to,v,d+e.cost);

  }
}

int main()
{
  int n;
  cin>>n;

  REP(i,n-1)
  {
    int a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    tree[a].push_back({b,c});
    tree[b].push_back({a,c});
  }
    int q,k;
    cin>>q>>k;
    k--;
    dfs(k,-1,0);
    REP(i,q)
    {
      int x,y;
      cin>>x>>y;
      x--,y--;
      cout<<depth[x]+depth[y]<<endl;
    }
return 0;
}


Measured memory_bytes: 14336
num = gets.to_i
arr = []
ans = []
i = 0
loop do
arr[i] = num % 26
num /= 26
	if num == 0
		break
	end
	i += 1
end
arr.reverse!
15.times do
(arr.length).times do |i|
	if arr[i] == 0
		if i == 0
			arr.delete_at(0)
		else
			arr[i-1] -= 1
			arr[i] = 26
			end
	end
end
end

(arr.length).times do |i|
	ans[i] = (arr[i] + 96).chr
end

puts ans.join('')

Measured memory_bytes: 14416
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=2e5+5;
struct edge{int to,nxt,w;}a[N<<2];
int n,p[N],q[N],foo[N],bar[N],tot,S,T,head[N],cnt=1,dep[N],que[N],hd,tl,cur[N],ans;
void link(int u,int v){
	a[++cnt]=(edge){v,head[u],1};head[u]=cnt;
	a[++cnt]=(edge){u,head[v],0};head[v]=cnt;
}
bool bfs(){
	memset(dep,0,sizeof(dep));
	dep[que[hd=tl=1]=S]=1;
	while(hd<=tl)
		for(int u=que[hd++],e=head[u];e;e=a[e].nxt)
			if(a[e].w&&!dep[a[e].to]){
				dep[que[++tl]=a[e].to]=dep[u]+1;
				if(a[e].to==T)return true;
			}
	return false;
}
int dfs(int u,int f){
	if(u==T)return f;int res=0;
	for(int &e=cur[u];e;e=a[e].nxt)
		if(a[e].w&&dep[a[e].to]==dep[u]+1){
			int d=dfs(a[e].to,min(a[e].w,f));
			a[e].w-=d;a[e^1].w+=d;f-=d;res+=d;
			if(!f)break;
		}
	if(!res)dep[u]=0;return res;
}
int dinic(){
	int res=0;
	while(bfs()){
		memcpy(cur,head,sizeof(cur));
		res+=dfs(S,1<<30);
	}
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&p[i]),++p[i];
	for(int i=1;i<=n;++i)scanf("%d",&q[i]),++q[i];
	for(int i=1;i<=n;++i)
		if(!foo[i]){
			++tot;
			for(int j=i;!foo[j];j=p[j])
				foo[j]=tot;
		}
	for(int i=1;i<=n;++i)
		if(!bar[i]){
			++tot;
			for(int j=i;!bar[j];j=q[j])
				bar[j]=tot;
		}
	S=tot+1;T=tot+2;
	for(int i=1;i<=n;++i)
		if(p[i]==i&&q[i]==i)
			++ans;
		else if(p[i]==i)
			link(S,bar[i]);
		else if(q[i]==i)
			link(foo[i],T);
		else{
			link(foo[i],bar[i]);
			if(p[i]==q[i])
				link(bar[i],foo[i]);
		}
	printf("%d\n",n-ans-dinic());
	return 0;
}


Measured memory_bytes: 11904
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

class node{
public:
  int p = -1, l, r;
};

void pr(vector<node>& t, int i){
  if(i == -1) return;
  cout << " " << i;
  pr(t, t[i].l);
  pr(t, t[i].r);
  return;
}
void in(vector<node>& t, int i){
  if(i == -1) return;
  in(t, t[i].l);
  cout << " " << i;
  in(t, t[i].r);
  return;
}
void po(vector<node>& t, int i){
  if(i == -1) return;
  po(t, t[i].l);
  po(t, t[i].r);
  cout << " " << i;
  return;
}



void solve(){
  int n; cin >> n;
  vector<node> t(n);
  for(int i = 0; i < n; i++){
    int id, l, r; cin >> id >> l >> r;
    t[id].l = l;
    t[id].r = r;
    if(l != -1) t[l].p = id;
    if(r != -1) t[r].p = id;
  }
  for(int i = 0; i < n; i++){
    if(t[i].p == -1){
      cout << "Preorder\n";
      pr(t, i);
      cout << endl;
      cout << "Inorder\n";
      in(t, i);
      cout << endl;
      cout << "Postorder\n";
      po(t, i);
      cout << endl;
    }
  }
  return;
}

int main(){
  solve();
  return 0;
}



Measured memory_bytes: 3136
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<numeric>

using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

int main(){
  long long a;
  int n;cin>>n;
  cin>>a;
  for(int i=1;i<n;i++){
    long long tmp;cin>>tmp;
    long long tmp2 = gcd(a,tmp);
    a/= tmp2;
    a *= tmp;
  }
  cout<<a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std ;
int main () {
    string s;
    cin >>s;
    auto x = s.find("A");
    auto y = s.rfind("Z");
    cout << y-x+1 << endl;
    return 0;
} 

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
#define N 305
int n,k,f[N][N][N];char s[N];
int dp(int l,int r,int k){
	if (k<0) return -1000;
	if (l>r) return 0;
	int &res=f[l][r][k];
	if (~res) return res;
	if (l==r) return res=1;
	res=0;
	if (s[l]==s[r]) res=max(res,dp(l+1,r-1,k)+2);
	else res=max(res,max(max(dp(l+1,r,k),dp(l,r-1,k)),dp(l+1,r-1,k-1)+2));
	return res;
}
int main(){
	scanf("%s%d",s+1,&k);n=strlen(s+1);
	memset(f,-1,sizeof(f));
	printf("%d\n",dp(1,n,k));
	return 0;
}

Measured memory_bytes: 111104
#include<cstdio>
using namespace std;

int main(){
  bool p[110][110];
  int n,l[110],m,t;

  while(scanf("%d",&n),n){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++)p[i][j] = false;
      l[i] = false;

      scanf("%d",&m);
      for(int j=0;j<m;j++){
	scanf("%d",&t);
	p[i][t] = true;
      }
    }

    scanf("%d",&m);
    for(int i=0;i<m;i++){
      scanf("%d",&t);
      l[t] = true;
    }

    int ans = -1;
    for(int i=1;i<=n;i++){
      bool f = true;
      for(int j=1;j<=n;j++){
	if(l[j] && !p[i][j]){
	  f = false; break;
	}
      }
      if(f){
	if(ans < 0)ans = i;
	else{
	  ans = -1; break;
	}
      }
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){
	char a[5];
	scanf ("%s", a);
	
	for (int i = 0; i != '/0'; i++){
		if (a[i] == 'B'){
			puts ("ARC");
			break;
		}
		else if (a[i] == 'R'){
			puts ("ABC");
			break;
		}
	}
 	return 0;
}

Measured memory_bytes: 1560
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

typedef pair<double,int> P;

int main(){
  int a;
  double t;

  vector<P> v1,v2,v3,v;
  for(int i = 0 ; i < 8 ; i++){
    cin >> a >> t;
    v1.push_back(P(t,a));
  }
  sort(v1.begin(),v1.end());

  printf("%d %.2f\n" ,v1[0].second ,v1[0].first);
  printf("%d %.2f\n" ,v1[1].second ,v1[1].first);

  for(int i = 2 ; i < 4 ; i++){
    v.push_back(v1[i]);
  }

  for(int i = 0 ; i < 8 ; i++){
    cin >> a >> t;
    v2.push_back(P(t,a));
  }
  sort(v2.begin(),v2.end());

  printf("%d %.2f\n" ,v2[0].second ,v2[0].first);
  printf("%d %.2f\n" ,v2[1].second ,v2[1].first);

  for(int i = 2 ; i < 4 ; i++){
    v.push_back(v2[i]);
  }

  for(int i = 0 ; i < 8 ; i++){
    cin >> a >> t;
    v3.push_back(P(t,a));
  }
  sort(v3.begin(),v3.end());

  printf("%d %.2f\n" ,v3[0].second ,v3[0].first);
  printf("%d %.2f\n" ,v3[1].second ,v3[1].first);

  for(int i = 2 ; i < 4 ; i++){
    v.push_back(v3[i]);
  }

  sort(v.begin(),v.end());
  printf("%d %.2f\n" ,v[0].second ,v[0].first);
  printf("%d %.2f\n" ,v[1].second ,v[1].first);

  return 0;
}

Measured memory_bytes: 1256
#include<iostream>
using namespace std;
int main(){
	long long a,b,i,ans,sum=0;
	while(cin>>a>>b){
		ans=a+b;
		for(i=0;ans>0;i++){
			ans=ans/10;
			sum=sum+1;
		}
		cout<<sum<<endl;
		sum=0;
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a+b+c-max({a,b,c})<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }
 
////////////////////////// Solution starts below. //////////////////////////////

map<int, string> mapa;
map<int, int> penal;

int main(){
  fastio;
  int n, p, totalP = 0, ans = 0;
  cin >> n >> p;
  while(p--){
    int k;
    string str;
    cin >> k >> str;
    if(mapa[k] == "AC") continue;
    else if(str == "WA") penal[k]++;
    else{
      mapa[k] = str;
      ans++;
      totalP += penal[k];
    }
  }
  cout << ans << ' ' << totalP;
  return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAX_N = 2009;
int N, Z, W;
int a[MAX_N];
int dp[MAX_N][2];

int go(int x, int turn)
{
    int& sc = dp[x][turn];
    if(sc!=-1) return sc;
    if(turn){
        sc = abs(a[N]-a[x]);
        for(int i=x+1;i<N;++i) sc=min(sc, go(i, 0));
        return sc;
    }else{
        sc = abs(a[N]-a[x]);
        for(int i=x+1;i<N;++i) sc=max(sc, go(i, 1));
    }
    return sc;
}

void solve()
{
	int ans = abs(a[N]-W); // x can achieve
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<N;++i){
		ans=max(ans, go(i,1));
	}
	cout<<ans<<'\n';
}

int main()
{
	cin >> N >> Z >> W;
	for(int i=1;i<=N;++i) cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 3680
/*
 * Lang  : C++ 17
 * Author: little_angel
 * Date  : 04-07-2020 10:40 04
 */

#include<bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);


    int t;
    cin >> t;
    if (t % 1000 == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << 1000 - t % 1000 << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int main(){
    ll n, m;
    cin >> n >> m;
    vector<string> a(n), b(m);
    for (ll i = 0; i < n; i++) cin >> a[i];
    for (ll i = 0; i < m; i++) cin >> b[i];
    for (ll i = 0; i < n - m + 1; i++) {
        for (ll j = 0; j < n - m + 1; j++) {
            bool flag = true;
            for (ll k = 0; k < m; k++) {
                if (a[i+k].substr(j, m) != b[k]) flag = false;
            }
            if (flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 2019;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S;
    cin >> S;
    int N = S.size();
    vector<int> ten(N+1);
    ten[0] = 1;
    vector<int> list(2019);
    REPS(i,N)ten[i] = modu(ten[i-1]*10);
    vector<int> mods(N+1);
    list[0]++;
    REPS(i,N){
        mods[i] = modu(mods[i-1] + (S[N-i]-'0')*ten[i-1]);
        list[mods[i]]++;
    }
    ll answer = 0;
    REP(i,2019){
        answer += list[i]*(list[i]-1)/2;
    }
    cout << answer << "\n";
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
struct t{
  ll d[55][55];
  t(void){for(int i=0;i<50;i++)for(int j=0;j<50;j++)d[i][j]=0;}
};
ll n,k,ans;
t g;
t mul(t &a,t &b){
    t res;
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++){
            for(int k=0;k<50;k++){
                res.d[i][j]=(res.d[i][j]+a.d[i][k]*b.d[k][j])%M;
            }
        }
    }
    return res;
}
void pw(t &x,ll y){
    t res;
    for(int i=0;i<50;i++)res.d[i][i]=1;
    while(y){
        if(y&1)res=mul(res,x);
        x=mul(x,x);
        y>>=1;
    }
    for(int i=0;i<50;i++)for(int j=0;j<50;j++)ans=(ans+res.d[i][j])%M;
}
int main(void){
    scanf("%lld%lld",&n,&k);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%lld",&g.d[i][j]);
        }
    }
    pw(g,k);
    printf("%lld\n",ans);
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

//ポイントはボトムから剰余を足していけばいいところ
int main(){
  int n; cin >> n;
  int res = n;
  for(int i = 0 ; i <= n; i++){
    int cc = 0;
    int t = i;
    while(t > 0) cc += t%6, t = floor(t/6);
    t = n - i;
    while(t > 0) cc += t%9, t = floor(t/9);
    if(res > cc) res = cc;
  }
  cout << res << endl;
}

/*
int main(){
  int a = 8;
  int b = 8;
  int n;
  cin >> n;
  int ans = 0;
  while(a > 0 || b > 0){
    if(pow(6, a) > pow(9, b)){
      ans += floor(n / pow(6, a));
      n =  n % (int)pow(6, a);
      cout << "a:" << a << " : " << pow(6, a) << " : " << n << " " << ans << endl;
      a--;
    }
    else {
      ans += floor(n / pow(9, b));
      n =  n % (int)pow(9, b);
      cout << "b:" << b << " : " << pow(9, b) << " : " << n << " " << ans << endl;
      b--;
    }
  }
  ans += n;
  cout << ans << endl;
}
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool a[210][210],vis[210];
int dpt[210],n;
void bfs(int x)
{
    queue<int>q;
    q.push(x);
    vis[x]=1;
    while(!q.empty())
    {
        int k=q.front();
        q.pop();
        for(int i=0;i<n;i++)
        {
            if(a[k][i]==0||vis[i])continue;
            vis[i]=1;
            dpt[i]=dpt[k]+1;
            q.push(i);
        }
    }
}
int main()
{
    int ans=-1;
    cin>>n;
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
    {
        char c;
        cin>>c;
        a[i][j]=(bool)(c-'0');
    }
    for(int i=0;i<n;i++)
    {
        memset(vis,0,sizeof(vis));
        memset(dpt,0,sizeof(dpt));
        bfs(i);
        int ok=1,mx=0;
        for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            if(a[i][j]==0)continue;
            if(abs(dpt[i]-dpt[j])!=1)
            {
                ok=0;
                break;
            }
            mx=max(mx,dpt[i]);
        }
        if(ok)ans=max(ans,mx+1);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,m;
	scanf("%d%d%d",&a,&b,&m);
	int ap[a],bp[b],mp[m][3];
	for(int i=0;i<a;i++) 
	    scanf("%d",&ap[i]);
	for(int i=0;i<b;i++) 
	    scanf("%d",&bp[i]);
	for(int i=0;i<m;i++)
	    for(int j=0;j<3;j++)
	    scanf("%d",&mp[i][j]);
	int min[m];
	for(int i=0;i<m;i++)
	    min[i]=ap[mp[i][0]-1]+bp[mp[i][1]-1]-mp[i][2];
	int minp=min[0],mina=ap[0],minb=bp[0];
	for(int i=0;i<m;i++) 
	    if(min[i]<minp) minp=min[i];
	for(int i=0;i<a;i++)
	if(ap[i]<mina) mina=ap[i];
	for(int i=0;i<b;i++)
	if(bp[i]<minb) minb=bp[i];
	printf("%d\n",minp<(mina+minb)?minp:(mina+minb));
	return 0;
	    
 } 

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
const int nmax=1e6+3;
typedef long long ll;
ll inv(ll t2)
{
    ll usu=1ll,p=1ll*mod-2;
    while(p)
    {
        if(p&1) usu=(1ll*usu*t2)%mod;
        p=p>>1;
        t2=(t2*t2)%mod;
    }
    return usu;
}
ll n,v[nmax],sum,f,sol,p[nmax],st,dr,nv[nmax];
int main()
{
    cin>>n;
    for(ll i=1;i<=n;++i)
    {
        cin>>v[i];
        sum=(sum+v[i])%mod;
    }
    f=1ll;
    for(ll i=2;i<=n;++i) f=1ll*f*i%mod;
    sol=sum*f%mod;
    sum=0;
    for(ll i=2;i<=n;++i) nv[i]=f*inv(i)%mod;
    st=2;
    dr=n;
    for(ll i=2;i<=n;++i) sum=(sum+nv[i])%mod;
    sol=((sol+sum*v[1])%mod+sum*v[n])%mod;
    //cout<<sum<<' '<<nv[2]<<' '<<nv[4];
    //return 0;
    for(ll i=2;i<n;++i)
    {
        sum=sum+nv[st]-nv[dr];
        //cout<<sum<<' ';
        ++st;
        --dr;
        while(sum<0) sum+=mod;
        while(sum>=mod) sum-=mod;
        sol=(sol+v[i]*sum%mod)%mod;
    }
    cout<<sol;
    return 0;
}


Measured memory_bytes: 7168
// Ala be zekrellah tatmaenolgholoob ...
// :)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define MP make_pair
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;
const int maxn = 1e5+9;
const int64 mod = 1e9+7;
const int64 inf = 1e9;

int n, p;
int a[55];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> p;
	int num1 = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x % 2) num1++;
	}
	int64 ans = 0;
	if (num1 == 0) {
		if (p == 0)
			ans = (1LL << n);
		return cout << ans << "\n", 0;
	}
	ans += (1LL << (num1 - 1));
	ans *= (1LL << (n - num1));
	cout << ans << "\n";
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import collections
def bfs(sy, sx, gy, gx):
    q = collections.deque()
    q.append((sy, sx))
    dist = [[-1] * W for _ in range(H)]
    dist[sy][sx] = 0
    dx = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    dx2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1),(-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]
    while len(q) != 0:
        h, w = q.popleft()
        d = dist[h][w]
        for x, y in dx:
            h2 = h + y
            w2 = w + x
            if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                if grid[h2][w2] == ".":
                    if dist[h2][w2] == -1:
                        dist[h2][w2] = d
                        q.appendleft((h2, w2))
                    elif d < dist[h2][w2]:
                        dist[h2][w2] = d
                        q.appendleft((h2, w2))
        for x, y in dx2:
            h2 = h + y
            w2 = w + x
            if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                if grid[h2][w2] == "." and (dist[h2][w2] == -1 or d + 1 < dist[h2][w2]):
                    dist[h2][w2] = d + 1
                    q.append((h2, w2))
    return dist[gy][gx]

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
grid = [input() for _ in range(H)]
print(bfs(Ch-1, Cw-1, Dh-1, Dw-1))

Measured memory_bytes: 89820
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF = 1LL << 60;

int main(void){
    int n,m;
    cin >> n >> m;
    vector<int> a(n+m);
    a[0] = 0;
    a[1] = 1;
    for(int i=2; i<n+m; i++){
        a[i] = a[i-1] + i;
    }

    //rep(i,n+m) cout << a[i] << endl;
    if (n>0) n--;
    if (m>0) m--;
    cout << a[n] + a[m] << endl;

    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    int n;
    cin >> n;
    int Max = -1;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        Max = max(Max,a[i]);
    }
    vector<int> mps(Max+1);
    auto mpsinit = [&](){//O(NloglogN)
        for(int i = 0; i <= Max; i++) mps[i] = i;
        for(ll i = 2; i*i <= Max; i++){
            if(mps[i] == i){
                for(ll j = i*i; j <= Max; j += i){
                    if(mps[j] == j) mps[j] = i;
                }
            }
        }
    };
    auto prime_factorization = [&](int n){//O(logN)
        vector<int> ret;
        while(mps[n] != n){
            if(ret.size() != 0 && ret.back() == mps[n]){
                n /= mps[n];
            } else {
                ret.push_back(mps[n]);
                n /= mps[n];
            }
        }
        if(ret.size() == 0 || ret.back() != mps[n]) ret.push_back(mps[n]);
        return ret;
    };

    mpsinit();
    vector<int> seen(Max,0);
    bool pc = true;

    for(int i = 0; i < n; i++){
        if(a[i] == 1) continue;
        vector<int> fp = prime_factorization(a[i]);
        for(auto p:fp){
            if(seen[p]) pc = false;
            seen[p] = true;
        }
    }

    int g = __gcd(a[0],a[1]);
    for(int i = 0; i < n; i++) g = __gcd(g,a[i]);

    if(pc) cout << "pairwise coprime" << endl;
    else if(g == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}

Measured memory_bytes: 15052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
const ll M=1000000007;
//------------------------------------------//

int main(){
    int N,K;cin>>N>>K;
    vector<ll> h(100010);
    rep(i,N) cin>>h[i];

    vector<ll> dp(100010,M);
    dp[0]=0;
    
    for(int i=0;i<N;i++){
        for(int j=1;j<=K;j++){
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 4848
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

    def string():
        return sys.stdin.readline().rstrip()

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    T = Scanner.int_list_list(N)
    x, y, t = 0, 0, 0
    for i in T:
        len = abs(i[1] - x) + abs(i[2] - y)
        time = i[0] - t
        if len <= time and len % 2 == time % 2:
            t, x, y = i
        else:
            print("No")
            return
    print("Yes")
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 56924
N = int(input())
S = input()

c = 0
for i in range(1, N):
    if S[i] == 'E':
        c += 1
dp = [c]

for i in range(1, N):
    c = dp[i-1]
    if S[i-1] == 'W':
        c += 1
    if S[i] == 'E':
        c -= 1
    dp.append(c)
dp.sort()
print(dp[0])

Measured memory_bytes: 16564
unittest
{
	assert( [ "takahashi" ].parse.expand.solve == "tak" );
	assert( [ "naohiro" ].parse.expand.solve == "nao" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	return s[ 0 .. 3 ];
}


Measured memory_bytes: 2792
using System;

namespace abc105_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int number = int.Parse(array[0]);
            int people = int.Parse(array[1]);
            int average = number % people;
            if (average == 0)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("1");
            }
        }
    }
}


Measured memory_bytes: 11092