akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->left != NIL){
      x = x->left;
    }

  return x;
}

Node treeMaximum(Node x){

  while(x->right != NIL){
    x = x->right;
  }

  return x;
}

Node treeSearch(Node u, int k){
  Node x;

  x = u;
  while(x != NIL){
    if(k < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
    if(k == x->key) return x;
  }

  return NIL;
}

Node treeSuccessor(Node x){
  Node y;

  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x-> right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else{
    if(z->key < y->key) y->left = z;
    else y->right = z;
  }
}

Node find (Node u,int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

void inorder(Node u){

  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){

  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }else if(com[0] == 'f'){
      scanf("%d",&x);
      Node t = find(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}



Measured memory_bytes: 21444
import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in sys.stdin:
 x=int(x)
 if x:print(sum(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]))


Measured memory_bytes: 8452
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    vector<int> x(m);
    for (int &xi: x) cin >> xi;
    sort(x.begin(), x.end());
    vector<int> diff(m - 1);
    for (int i = 0; i + 1 < m; i++) diff[i] = x[i + 1] - x[i];
    sort(diff.begin(), diff.end());
    int res = 0;
    for (int i = 0; i < m - n; i++) res += diff[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
    int n,i,j,b;
    char a;
    int cards[4][13]={{}};
    cin>>n;
    for(i=0; i<n; i++){
        cin >> a >> b;
        if(a=='S'){
            cards[0][b-1]=1;
        }
        else if(a=='H'){
            cards[1][b-1]=1;
        }
        else if(a=='C'){
            cards[2][b-1]=1;
        }
        else if(a=='D'){
            cards[3][b-1]=1;
        }
        else{   
        }
    }
    // printf("\n");
    for(i=0; i<4; i++){
        for(j=0; j<13;j++){
            //cout<<cards[i][j]<<endl;
            if(cards[i][j]!=1){
                if(i==0){
                    //printf("S %d",j+1);
                    cout<<"S "<<j+1<<endl;
                }
                else if(i==1){
                    cout<<"H "<<j+1<<endl;
                }
                else if(i==2){
                    cout<<"C "<<j+1<<endl;
                }
                else if(i==3){
                    cout<<"D "<<j+1<<endl;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#https://atcoder.jp/contests/abc061/tasks/abc061_d

# coding: utf-8
# Your code here!

#input_template
inpPh = 3
debug = True
debug = False
if not debug:
    inpPh = 0

input1 ='''
3 3
1 2 4
2 3 3
1 3 5 
'''[1:]

input2 ='''
2 2
1 2 1
2 1 1
'''[1:]

input3 ='''
6 5
1 2 -1000000000
2 3 -1000000000
3 4 -1000000000
4 5 -1000000000
5 6 -1000000000
'''[1:]



inputXs = [input1, input2, input3, None]


if debug:
    try:
        inputXs.append(inputA0)
    except:
        pass
    else:
        pass



    
inploc = inpPh - 1 #0,1,2

if inpPh > 0:
    pass
 
   # print(f'selected_input({inpPh}):\n'+inputXs[inploc])


inpX_lst = []
if debug and inpPh > 0:
    inpX_lst = inputXs[inploc].splitlines()


if inpPh == 0:
    N,M = tuple(map(lambda x: int(x), input().split() ) )
else:
    N,M = tuple( map(lambda x: int(x),  inpX_lst.pop(0).split() ) )

elist = []    

for i in range(M):
    if inpPh == 0:
        ai,bi,ci = list(map(lambda x: int(x), input().split() ))
    else:
        ai,bi,ci = list(map(lambda x: int(x), inpX_lst.pop(0).split() ))
    
    ai_loc, bi_loc = ai-1, bi - 1
    elist.append(( ai_loc, bi_loc,-ci))

vlist =[ None for _ in range(N)]    

        
s_loc,g_loc = 0, N-1

vlist[s_loc] = 0
#print(vlist)




is_inf = False
for i in range(len(vlist)):
    for e in elist:
        a,b,c = e
        if vlist[a] == None:
            continue
        elif vlist[b] == None or vlist[b] > vlist[a] + c:
            vlist[b] = vlist[a] + c
            if i == N-1 and b == N-1:
                pass
                is_inf = True
                 
res = -vlist[g_loc]            


if is_inf:
    print('inf')
else:
    print(res)



Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;

template<class T> inline void chmax(T &a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T &a, T b) {
	a = std::min(a, b);
}

int mod_pow(int x, int y, int m = mod) {
	int res = 1;
	while (y) {
		if (y % 2) {
			res *= x;
			res %= m;
		}
		x = x * x % mod;
		y /= 2;
	}
	return res;
}

int n, m;
struct info {
	int to, sum;
};
vector<info> G[100005];
bool used[100005];
int num[100005];
int dis[100005];
void dfs2(int x) {
	used[x] = true;
	for (info e : G[x]) {
		if (!used[e.to]) {
			num[e.to] = e.sum - num[x];
			dfs2(e.to);
		}
	}
}
void dfs(int x, int pre) {
	used[x] = true;
	for (info e : G[x]) {
		if (e.to == pre)
			continue;
		if (used[e.to]) {
			if ((dis[x] + 1 - dis[e.to]) % 2) {
				num[e.to] += (e.sum - num[x] - num[e.to]) / 2;
				memset(used, false, sizeof(used));
				dfs2(e.to);
				rep(i,n)
				{
					if (num[i] <= 0) {
						puts("0");
						exit(0);
					}
					for (info p : G[i]) {
						if (num[i] + num[p.to] != p.sum) {
							puts("0");
							exit(0);
						}
					}
				}
				puts("1");
				exit(0);
			}else {
				if(num[e.to]!=e.sum-num[x]){
					puts("0");
					exit(0);
				}else {
					continue;
				}
			}
		}
		num[e.to] = e.sum - num[x];
		dis[e.to] = dis[x] + 1;
		dfs(e.to, x);
	}
}
signed main() {
	cin >> n >> m;
	rep(i,m)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		G[a].push_back( { b, c });
		G[b].push_back( { a, c });
	}
	dfs(0, -1);
	int ma = inf;
	int least = 0;
	rep(i,n)
	{
		if (dis[i] % 2) {
			chmin(ma, num[i] - 1);
		} else {
			chmax(least, 1 - num[i]);
		}
	}
	cout << max(0ll, ma - least + 1) << endl;
}


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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int main() {
	ios::sync_with_stdio(0);

	int k;
	cin >> k;
	int x = 0;
	for (int i = 1; i <= k; i++) {
		x = (x * 10 + 7) % k;
		if (x == 0) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}


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

int main() {
  int r, c;
  cin >> r >> c;
  int sum = 0;
  vector<int> table(r * c);
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> table.at(i * c + j);
      sum += table.at(i * c + j);
    }
  }
  vector<int> row(r, 0), column(c, 0);
  for (int i = 0; i < r; i++) {
    int count = 0;
    for (int j = 0; j < c; j++) {
      count += table.at(i * c + j);
    }
    row.at(i) = count;
  }
  for (int j = 0; j < c; j++) {
    int count = 0;
    for (int i = 0; i < r; i++) {
      count += table.at(i * c + j);
    }
    column.at(j) = count;
  }
  vector<int> anstable((r + 1) * (c + 1));
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if (i != r && j != c)
        anstable.at(i * (c + 1) + j) = table.at(i * c + j);
      else if (i == r && j != c)
        anstable.at(i * (c + 1) + j) = column.at(j);
      else if (i != r && j == c)
        anstable.at(i * (c + 1) + j) = row.at(i);
      else if (i == r && j == c)
        anstable.at(i * (c + 1) + j) = sum;
    }
  }
  for (int i = 0; i < r + 1; i++) {
    for (int j = 0; j < c + 1; j++) {
      if (j != c)
        cout << anstable.at(i * (c + 1) + j) << " ";
      else
        cout << anstable.at(i * (c + 1) + j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 3152
a,b,c =input().split()
a = int(a)
b = int(b)
c = int(c)
if a == 5:
  if (b== 7 and c==5) or (b== 5 and c==7):
    print("YES")
  else:
    print("NO")
elif a == 7:
  if b==5 and c == 5:
    print("YES")
  else:
    print("NO")
else:
    print("NO")

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

bool f=true;
string s,hoge="YAKI";

signed main() {
    cin >> s;
    if (s.size() < 4) {cout << "No" << endl;return 0;}
    rep(i,4) if (s[i] != hoge[i]) f = false;
    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
}












Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
typedef pair<int, int>P;

int ctoi(char s) {
	return s - '0';
}

int main() {
	char s;
	char t;
	int year = 0, month = 0, day = 0;
	cin >> s;
	year += ctoi(s) * 1000;
	cin >> s;
	year += ctoi(s) * 100;
	cin >> s;
	year += ctoi(s) * 10;
	cin >> s;
	year += ctoi(s);

	cin >> t;
	cin >> s;
	month += ctoi(s) * 10;
	cin >> s;
	month += ctoi(s);

	cin >> t;
	cin >> s;
	day += ctoi(s) * 10;
	cin >> s;
	day += ctoi(s);
	if (year <= 2019 && month <= 4 && day <= 30) {
		cout << "Heisei" << endl;
		return 0;
	}
	cout << "TBD" << endl;
	return 0;
}

Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> data;
    rep(i, N)
    {
        int tmp;
        cin >> tmp;
        data.push_back(tmp);
    }
    sort(data.begin(), data.end());
    int ans = INF;

    for (int i = 0; i + K - 1 < N; i++)
    {
        int tmp_ans = data[i + K - 1] - data[i];
        if (tmp_ans < ans)
        {
            ans = tmp_ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 892
#include <iostream>
using namespace std;
int main() {
  int D; cin >> D;
  switch (D) {
    case 22:
      cout << "Christmas Eve Eve Eve" << endl;
      return 0;
    case 23:
      cout << "Christmas Eve Eve" << endl;
      return 0;
    case 24:
      cout << "Christmas Eve" << endl;
      return 0;
    case 25:
      cout << "Christmas" << endl;
      return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define INF 1<<64
#define sf(a) scanf("%d",&a)
using namespace std;
int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
typedef pair<int,int> pii;
vector<pii> vii;
int n=0;
str s;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    stack<char> que;
    for(int i=0;i<s.length();i++){
        if(s[i]=='B'){
            if(que.size()){
                que.pop();
            }
        }else{
            que.push(s[i]);
        }
    }
    char c[20],cc;
    int i=que.size()-1;
    int j=que.size();
    //que<char> ans;
    while(que.size()){
        cc=que.top();
        c[i]=cc;
        que.pop();
        i--;
    }
    for(int i=0;i<j;i++){
        cout << c[i];
    }
    cout << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

bool seen[500];
string s;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> s;
	for (char i : s)
		seen[i] = true;
	if (seen['N'] ^ seen['S'])
	{
		cout << "No" << endl;
		return 0;
	}
	if (seen['W'] ^ seen['E'])
	{
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
}



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

int main() {
  char c; cin >> c;
  string res;
  if (c == 'A') res = "T";
  else if (c == 'T') res = "A";
  else if (c == 'G') res = "C";
  else res = "G";
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    if(A[0] != 0){
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    for(int i = N-1; i >= 1; i--){
        ans += A[i];
        while(i >= 1 && A[i-1] < A[i]){
            if(A[i-1] <= A[i]-2){
                cout << -1 << endl;
                return 0;
            }
            i--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5224
if __name__ == '__main__':
    N, Y = list(map(int, input().split(' '))) # N = お札の枚数 Y = お年玉の合計
    for a in range(N+1):
        for b in range(N+1-a):
            c = N - a - b
            if ((a * 10000) + (b * 5000) + (c * 1000)) == Y:
                print(a,b,c)
                exit()
    else:
        print('-1 -1 -1')

Measured memory_bytes: 3060
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)


int main() {
    ll N,A,B;
    cin >> N >> A >> B;

    ll AB = B-A;
    
    ll ans=0;
    if(AB % 2 == 0){
        ans = AB/2;
    }else{
        ans = min(A-1,N-B) + 1 + ((B-A-1)/2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
h,w=map(int,input().split())
List=[]
List_gyou=[""]*w
ans=[]
kotae=[]

for i in range(h):
    a=input()
    check=set(a)
    if (check!={"."}):
        List.append(a)
        for j in range(w):
            List_gyou[j]+=a[j]
            
for i in range(w):
    check=set(List_gyou[i])
    if (check!={"."}):
        ans.append(List_gyou[i])

        
#print(ans) 
#print(len(ans))
#print(len(ans[0]))
for i in range(len(ans[0])):
    kore=""
    for j in range(len(ans)):
        kore+=ans[j][i]
    print(kore)
        

#print(List)
#print(List_gyou)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int k;
    cin>>k;
    queue<int> q;
    REP(i,1,9)q.push(i);
    rep(i,k-1){
        int a=q.front();
        q.pop();
        if(a%10!=0)q.push(a*10+a%10-1);
        q.push(a*10+a%10);
        if(a%10!=9)q.push(a*10+a%10+1);
    }
    cout<<q.front()<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] != t[i]) ans++;
	}	
	cout << ans << endl;
}





Measured memory_bytes: 3768
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var n, k int
var t []task
var dp [][]int

type task struct {
	a int
	b int
	c int
}

func dfs(i, tt int) int {
	if dp[i][tt] != -1 {
		return dp[i][tt]
	}
	if i == n {
		return 0
	}
	var x, y, z int
	if tt != 0 {
		x = dfs(i+1, 0) + t[i].a
	}
	if tt != 1 {
		y = dfs(i+1, 1) + t[i].b
	}
	if tt != 2 {
		z = dfs(i+1, 2) + t[i].c
	}
	dp[i][tt] = max(x, max(y, z))
	return dp[i][tt]
}

func main() {
	n = readInt()
	t = make([]task, n)
	for i := range t {
		t[i] = task{
			a: readInt(),
			b: readInt(),
			c: readInt(),
		}
	}
	dp = make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, 3+1)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}

	fmt.Println(dfs(0, 3))
}


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


int n, a[101];

int alice, bob;

int main() {
    ios::sync_with_stdio(false);
    
    cin >> n;
    
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n);
    
    
    for (int i = n-1, j =0 ; i >=0; i--) {
        if (j % 2 ==0)
            alice += a[i];
        else
            bob += a[i];
        
        j++;
    }
    cout << alice - bob << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int serch(int ,int []);

int n;

int main()
{
  int i,S[100000],q,T[50000],count = 0;
  
  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]);
      if(serch(T[i],S)) count++;
	}
    
  printf("%d\n",count);
  return 0;
}
int serch(int a,int S[])
{
  int mid,left = 0,right = n;
  while(left < right)
    {
      mid = (right + left) / 2;
      if(a == S[mid])
	{
	  return 1;
	} else if(a < S[mid])
	{
	  right = mid;
	} else if(a > S[mid])
	{
	  left = mid +1;
	}
    } 
  return 0;
}
  
    
      



Measured memory_bytes: 2280
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
la = [list(map(int,input().split())) for i in range(h)]
for i in range(h):
    l = list(map(int,input().split()))
    for j,num in enumerate(l):
        la[i][j] = abs(la[i][j]-num)
dp = [[0 for i in range(w)] for j in range(h)]
k = (h+w)*80+2
dp[0][0] = 1 << (k+la[0][0]) | 1 << (k-la[0][0])

for i in range(h):
    for j in range(w):
        if i:
            dp[i][j] |= (dp[i-1][j] << la[i][j]) | dp[i-1][j] >> la[i][j]
        if j:
            dp[i][j] |= (dp[i][j-1] << la[i][j]) | dp[i][j-1] >> la[i][j]

check = dp[-1][-1]       
for i in range(k):
    if (check >> k+i) & 1 or (check >> k-i) & 1:
        print(i)
        exit()


Measured memory_bytes: 20212
n, m = map(int, input().split())

a = []

for i in range(n):
  a.append([int(s) for s in input().split()])

b = []

for i in range(m):
  b.append(int(input()))

for i in range(n):
  print(sum([a[i][x] * b[x] for x in range(m)]))



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

int main()
{
    string S;
    cin >> S;

    int size = S.size();

    long ans = 0;
    int index = 0;

    for (int i = 0; i < (1 << size - 1); i++)
    {
        index = size;
        bitset<9> s(i);
        for (int j = 0; j < size - 1; j++)
        {
            if (s.test(j))
            {
                ans += stol(S.substr(size - j - 1, index - (size - j - 1)));
                index = size - j - 1;
            }
        }

        ans += stol(S.substr(0, index));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
ll h, w;
int a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h>>w;
    ll s=h*w;
    if(h%3==0||w%3==0){
        cout << 0 << "\n";
        return 0;
    }
    ll ans = INF;
    if(w>=3){
        ans=min(ans, w);
    }
    if(h>=3)
    ans=min(ans, h);
    for (int i = 1; i <w;i++){
        ll u = i * h;

        ll div = (w - i) * (h / 2);
        ans = min(max(u,max(div,s-u-div))-min(u,min(div,s-u-div)), ans);
    }
    for (int i = 1; i < h; i++)
    {
        ll u = i * w;
        ll div = (h - i) * (w/ 2);
        ans = min(max(u,max(div,s-u-div))-min(u,min(div,s-u-div)), ans);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int dp[1010][1<<3];
const int mod=10007;

map<char,int> con;
int main(void){
	int n;
	cin >> n;
	string s;
	cin >> s;

	con['J']=0;con['O']=1;con['I']=2;
	s="J"+s;
	dp[0][1]=1;

	for(int i=0;i<n;++i){
		for(int j=0;j<8;++j){
			for(int k=0;k<8;++k){

				if(!(j&(1<<con[s[i]]))) continue;
				if(!(k&(1<<con[s[i+1]]))) continue;
				if(!(j&k)) continue;

				dp[i+1][k]=(dp[i+1][k]+dp[i][j])%mod;
			}
		}
	}

	int ans=0;
	for(int i=0;i<8;++i) ans=(ans+dp[n][i])%mod;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1244
import numpy as np
n, m = (int(x) for x in input().split())
h = [int(x) for x in input().split()]
b = np.zeros(n)
for i in range(m):
    s, k = (int(x) for x in input().split())
    if h[s-1] < h[k-1]:
        b[s-1] = 1
    elif h[k-1] < h[s-1]:
        b[k-1] = 1
    else:
        b[s-1] = 1
        b[k-1] = 1

print(np.count_nonzero(b==0))

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

typedef long long ll;

int n;
ll x[100],y[100];;

ll len(int a,int b){
  return (x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]);
}

bool para(int a1,int a2,int b1, int b2){
  return (x[a1]-x[a2])*(y[b1]-y[b2]) - (x[b1]-x[b2])*(y[a1]-y[a2]) == 0;
}

int main(){
  ll cx=0,cy=0;

  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%lld%lld",&x[i],&y[i]);
    cx += x[i]; cy += y[i];
  }

  if(n&1){
    printf("NA\n"); return 0;
  }

  for(int i=0;i<n/2;i++){
    int op = i + n/2, nx = i+1, opnx = (op+1)%n;
    if(len(i,nx) != len(op,opnx) || !para(i,nx,op,opnx)){
      printf("NA\n"); return 0;
    }
  }
  printf("%.8lf %.8lf\n",(double)cx/n,(double)cy/n);
}

Measured memory_bytes: 1068
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const maxHeapify = (arr, i) => {
    const l = i * 2;
    const r = l + 1;
    let max;

    if (l <= arr.length && arr[l-1] > arr[i-1]) {
        max = l;
    } else {
        max = i;
    }
    if (r <= arr.length && arr[r-1] > arr[max-1]) {
        max = r;
    }

    if (max !== i) {
        const tmp = arr[i-1];
        arr[i-1] = arr[max-1];
        arr[max-1] = tmp;
        maxHeapify(arr, max);
    }

};

const buildMaxHeap = arr => {
    for (let i = Math.floor(arr.length / 2); i > 0; i--) {
        maxHeapify(arr, i);
    }

    return arr;
};

const data = line[1].split(' ').map(Number);
console.log(' ' + buildMaxHeap(data).join(' '));



Measured memory_bytes: 106904
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	int N[4], A[4] = { 1, 4, 7, 9 };
	bool ans = true;

	rep(i, 4) cin >> N[i];
	
	sort(N, N + 4);
	rep(i, 4) {
		if (N[i] != A[i]) ans = false;
	}

	cout << (ans ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
      Scanner in=new Scanner(System.in);
      int A=in.nextInt();
      int B=in.nextInt();
      
      int res=0;
      int strip=1;
      while(strip<B){
      	strip=strip-1+A;
        res++;
      }
      System.out.println(res);
      in.close();
    }
}

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

int dp[5009][5], n, p[100009];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i];
	for (int i = 0; i <= n; i++) { for (int j = 0; j <= 4; j++) dp[i][j] = (1 << 30); }
	dp[0][0] = 0; dp[0][1] = 0; dp[0][2] = 0; dp[0][3] = 0; dp[0][4] = 0;
	for (int i = 0; i <= n - 1; i++) {
		for (int j = 0; j <= 4; j++) {
			// j = 次に絶対裏返さなければならない個数
			for (int k = max(j, p[i + 1]); k <= 4; k++) {
				int z = k - j;
				dp[i + 1][z] = min(dp[i + 1][z], dp[i][j] + k);
			}
		}
	}
	int minx = (1 << 30);
	for (int i = 0; i <= 4; i++) minx = min(minx, dp[n][i]);
	cout << minx << endl;
	return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main() {
  ll N,D;
  int ans = 0;
  cin >> N >> D;
  rep(i,N) {
	ll x,y;
	cin >> x >> y;
	if(x*x + y*y <= D*D) {
	  ans++;
	}
  }
  cout << ans << endl;
}



Measured memory_bytes: 3192
from bisect import *
p = [1]*300003
p[0] = p[1] = 0
for i in xrange(2,300003):
    if p[i] and i%7 in (1,6):
        p[2*i::i] = [0]*len(p[2*i::i])
    else:
        p[i] = 0
p = [i for i in xrange(2,300003) if p[i]]

while 1:
    N = int(raw_input())
    if N == 1: break
    ans = [i for i in p[:bisect(p,N+1)] if N%i == 0]
    print "%d: %s"%(N," ".join(map(str,ans)))

Measured memory_bytes: 7556
#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 10000000
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
main(){
    //OJ;
    char c;
    cin>>c;
    if(isupper(c)){
        cout<<"A";
    }
    else if(islower(c)){
        cout<<"a";
    }
    
}

Measured memory_bytes: 3620
var
  a,b:array[0..1000]of longint;
  n,m,i,j,max,min,x,y:longint;
begin
   readln(n,m,x,y);
   max:=x;min:=y;
   for i:=1 to n do
     begin
       read(a[i]);
       if a[i]>max then max:=a[i];
     end;
   readln;
   for i:=1 to m do
     begin
       read(b[i]);
       if b[i]<min then min:=b[i];
     end;

   if min<=max then write('War') else write('No War');
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define mx 1000002
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int f(int a,int b)
{
	while(a%b==0)
		a/=b;
	return a%b==1;
}	
int32_t main() {	
	int n,i,b;
	cin>>n;
	if(n==2)
	{	cout<<"1\n";
		exit(0);
	}
	b=n-1;
	int ans=0;
	for(i=2;i*i<=b;i++)
	{
		if(b%i==0)
		{	ans++;
		if(i*i!=b)
		{
			ans++;
		}
		}
	}
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			ans+=f(n,i);
			if(i*i!=n)
			{
				ans+=f(n,n/i);
			}
		}
	}
	cout<<ans+2<<"\n";
}	

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  int now = 1;
  int ans = 0;
  for(auto k : a){
    if(now == k) now++;
    else ans++;
  }
  
  if(ans == n) ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(ll i = 0;i < n;i++)
#define FOR(i,a,b) for(ll i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int n;
ll a[114514];

ll solve(ll i) {
	ll cnt = 0;
	ll sum = 0;
	REP(j, n) {
		sum += a[j];
		if (sum * i <= 0) {
			cnt += abs(sum - i);
			sum = i;
		}
		i *= -1;
	}
	return cnt;
}

int main() {
	IOS;
	cin >> n;
	REP(i, n)cin >> a[i];
	dump(min(solve(1), solve(-1)));
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll diff = llabs(a-b);
    if (diff % 2 == 0) {
        cout << diff / 2 << endl;
    } else {
        ll m = min(a, b);
        ll M = max(a, b);
        ll tmp0 = m + (M-m-1)/2;
        ll step_up = n-M+1;
        ll tmp1 = step_up + (n-(m+(step_up)))/2;
        cout << min(tmp0, tmp1) << endl;
    }
    return 0;
}




Measured memory_bytes: 256
N, M =map(int, input().split())
a, b = [0]*N, [0]*N
c, d = [0]*M, [0]*M
ans = []
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(M):
    c[i], d[i] = map(int, input().split())
    

for i in range(N):
    length = 10**9
    ind = 0
    for j in range(M):
        man =  abs(a[i] - c[j])+abs(b[i] - d[j])
        if length > man:
            length = man
            ind = j+1
    ans.append(ind)

for i in ans:
    print(i)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int max_num = 0;

    if (k - a > 0)
        max_num += 1 * a;
    else
        max_num += 1 * k;
    if (k - a - b > 0)
        max_num += 0 * b;
    else
        if (k - a > 0) {
            max_num += 0 * (k - a);
        }
    if (k - a - b - c > 0)
        max_num -= 1 * c;
    else {
        if (k - a - b > 0) {
            max_num -= 1 * (k - a - b);
        }
    }

    cout << max_num << endl;
}



Measured memory_bytes: 3636
R,G,B,N = map(int,input().split())
r_max = N//R

ans =0
for i in range(r_max+1):
    n_r = N-(R*i)
    if n_r==0:
        ans+=1
    else:
        g_max = n_r//G
        for j in range(g_max+1):
            n_g = n_r-G*j
            if n_g==0:
                ans+=1
            else:
                if n_g%B==0:
                    ans+=1
print(ans)

Measured memory_bytes: 3064
import numpy as np
a,b,h,m = map(int, input().split())
H = 30*h + 0.5*m
M = 6*m
k = H-M
if k>=180:
    k = (360- k)*(np.pi/180)
else:
    k = k*(np.pi/180)
c = a**2 + b**2 - 2*a*b*np.cos(k)
print(np.sqrt(c))

Measured memory_bytes: 27212
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import           Data.Int
import           Data.Ratio
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List                      ( unfoldr )
-- import qualified Data.Vector.Unboxed           as VU
-- import qualified Data.Vector.Unboxed.Mutable   as VUM
import           Data.Complex
import           Data.Function
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import qualified Data.List as L
import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector.Unboxing.Mutable   as VUM

main :: IO ()
main = do
  x <- readLn :: IO Int
  as <- VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let ms = VU.map toM as
  print $ unM $ VU.sum $ VU.zipWith (*) ms $ VU.scanl (+) 0 ms

-- DO NOT use constructor directry, instead: toM 
newtype MInt = M { unM :: Int64 } deriving (Show, Eq, Ord)

instance VU.Unboxable MInt where
  type Rep MInt = Int64

modNum :: Int64
modNum = 1000000007

toM :: Integral a => a -> MInt
toM a = M (fromIntegral a `mod` modNum)

instance Enum MInt where
  toEnum a = M (toEnum a)
  fromEnum a = fromEnum (unM a)

instance Num MInt where
  a + b = toM (unM a + unM b)
  a - b = toM (unM a - unM b + modNum)
  a * b = toM (unM a * unM b)
  abs a = toM (abs (unM a))
  signum a = toM (signum (unM a))
  fromInteger a = toM (fromIntegral a)

-- Safe only if modNum is prime
instance Fractional MInt where
  fromRational a = fromInteger (numerator a) / fromInteger (denominator a)
  a / b = a * powerMod b (modNum-2) modNum where
    -- SICP Power iteration
    power :: Integral a => (t -> t -> t) -> t -> a -> t -> t
    power _ _ 0 e = e
    power f x n e = power f (f x x) (div n 2) (if odd n then f x e else e)
    powerMod x n _ = power (*) x n 1

-- import Prelude hiding ((^))
(^) :: MInt -> MInt -> MInt
(^) b' e' = M $ fastpow (unM b') (unM e') modNum where
  -- https://www.reddit.com/r/haskell/comments/mqtk6/fast_power_function/
  fastpow :: Int64 -> Int64 -> Int64 -> Int64
  fastpow base exponents modulo = fastpow' (base `mod` modulo) exponents modulo 1
    where fastpow' _ 0 _ !r = r
          fastpow' b e m r = fastpow' (b * b `mod` m) (e `div` 2) m (if even e then r else r * b `mod` m)
infixr 8 ^


Measured memory_bytes: 13956
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = (1LL<<60);
const int inf = (1<<29);

// editorial AC
// bitDP
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


// O(M2^N)
int main () {

    int  N , M;
    cin >> N >> M;
    vector<ll> a(M), b(M);
    vector<int> c(M, 0); //c is bits
    ll dp[1100][5000];

    for(int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        for (int j = 0; j < b[i]; j++) {
            int t; cin >> t; t--;
            c[i] += (1<<t);
        }
    }

    for (int i = 0; i < 1100; i++) {
        for (int j = 0; j < 5000; j++) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for(int i = 0; i < M; i++) {
        for (int j = 0; j < (1<<N); j++) {
            chmin(dp[i+1][j], dp[i][j]);
        
            int nj = j | c[i];
            chmin(dp[i+1][nj], dp[i][j] + a[i]);
        }
    }

    // for(int i = 0; i < M; i++) {
    //     for (int j = 0; j < (1<<N); j++) {
    //         cout << dp[i][j];
    //     }
    //     cout << endl;
    // }

    cout << (dp[M][(1<<N)-1] < INF ? dp[M][(1<<N)-1] : -1) << endl;

    return 0;
}


/* ||WA in contest!!!
   V
int main() {

    int N, M;
    cin >> N >> M;
    
    vector<pint> a;
    vector<int> b(M);
    vector<vector<int>> c(M);
    for (int i = 0; i < M; i++) {
        int cost;
        cin >> cost;
        a.push_back(make_pair(cost, i));
        cin >> b[i];
        for (int j = 0; j < b[i]; j++) {
            int tmp; cin >> tmp;
            c[i].push_back(tmp);
        }
    }

    sort(ALL(a));

    ll ans = 0;
    set<int> st;
    for (int i = 0; i < M; i++) {
        int tmp = a[i].second;
        bool need = false;

        // cout << a[i].first << " " << a[i].second << endl;

        for (int j = 0; j < b[tmp]; j++) {
            // cout << c[tmp][j] << " ";
            auto itr = st.find(c[tmp][j]);
            if (itr == st.end()) {
                st.insert(c[tmp][j]);
                need = true;
            }
        }
        // cout << endl;
        // cout << "need : " << need << endl;
        // cout << "st.size() : " << st.size() << endl;
        
        if (need) ans += a[i].first;
        // cout  << endl;
        
    }
    
    cout << (st.size() == N ? ans : -1) << endl;

    return 0;
}
*/

Measured memory_bytes: 43264
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
    int w, h, n, x, y, a;
    cin >> w >> h >> n;

    int ue = h, sita = 0, hidari = 0, migi = w;
    REP(i, n){
        cin >> x >> y >> a;
        if(a == 1){
            hidari = max(hidari, x);
        }
        else if(a == 2){
            migi = min(migi, x);
        }
        else if(a == 3){
            sita = max(sita, y);
        }
        else{
            ue = min(ue, y);
        }
    }

    cout << max(migi - hidari, 0)*max(ue -sita, 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <clocale>
using namespace std;

int main(void)
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    int x = 0, y = 0, z = 0;
    char next = 'a';

    while (true)
    {
        if (next == 'a')
        {
           
            if (x == sa.length())
                goto loopend;
            next = sa[x];
            x++;
        }
        else if (next == 'b')
        {
            if (y == sb.length())
                goto loopend;
            next = sb[y];
            y++;
        }
        else if (next == 'c')
        {
            if (z == sc.length())
                goto loopend;
            next = sc[z];
            z++;
        }
    }
    loopend:
    if(next=='a')next='A';
    else if(next=='b')next='B';
    else if(next=='c')next='C';
    
    cout << next << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const int MAX=1e7+100;

int main() {
  int N,K;cin>>N>>K;
  (N%K==0) ? OUT(0) : OUT(1);

  return 0;
}

Measured memory_bytes: 256