akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int dat[501][501] = {};
int dat2[501][501] = {};
bool block[501][501] = {};


struct S {
    int x;
    int y;
    int v;
};

auto cmp = [](const S& lhs, const S& rhs)
{
    return lhs.v > rhs.v;
};

void add(int x, int y, int v, int n, int m, queue<S>& s)
{
    if (x == -1 || x == n || y == -1 || y == n) return;


    if (v < dat[x][y]) {
        dat[x][y] = v;
        int nv = v;
        if (!block[x][y]) nv++;
        s.push({ x, y, nv });
    }
}

void update(int x, int y, int v, int n, int m)
{
    queue<S> search;

    search.push({ x, y, v });
    while (!search.empty()) {
        S s = search.front(); 
        search.pop();

        int cv = s.v;

        add(s.x - 1, s.y, cv, n, m, search);
        add(s.x + 1, s.y, cv, n, m, search);
        add(s.x, s.y - 1, cv, n, m, search);
        add(s.x, s.y + 1, cv, n, m, search);
        //cout << search.size() << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(20);

    int n; cin >> n;

    FOR_LT(i, 0, n) {
        FOR_LT(j, 0, n) {
            int a = i;
            int b = n - i - 1;
            int c = j;
            int d = n - j - 1;
            dat[i][j] = min(min(a, b), min(c, d));
        }
    }

    int64_t ans = 0;
    REP(n * n) {
        int m;  cin >> m; m--;
        int x = m % n;
        int y = m / n;
        int v = dat[x][y];
        block[x][y] = true;
        update(x, y, v, n, m + 1);
        ans += v;
#if 0
        cout << x << "  " << y << " " << v << " " << ans << endl;
        FOR_LT(i, 0, n) {
            FOR_LT(j, 0, n) {
                cout << dat[i][j] << " ";
            }
            cout << endl;
        }
        cout << "map" << endl;
        FOR_LT(i, 0, n) {
            FOR_LT(j, 0, n) {
                cout << block[i][j] << " ";
            }
            cout << endl;
        }
#endif
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4872
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  copy_n(istream_iterator<int>(cin), N, P.begin());
  int result = 0;
  int pmin = P[0];
  for (int i = 0; i < N; ++i) {
    if (P[i] <= pmin) {
      ++result;
      pmin = P[i];
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

bool debug=false;
/*---------------------------------------------------*/

int main(){
  int n,l,r;
  int sum=0;
  cin>>n;
  rep(i,n){
    cin>>l>>r;
    sum+=r-l+1;
  }
  cout<<sum<<endl;
  return 0;
}


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

#define rep(i,n) for(int i = 0 ; i < n ; i++)
class Dice{
public:
	vector<int> dice;
	Dice(){
		dice.resize(6);
		dice[0] = 1;
		dice[1] = 5;
		dice[2] = 3;
		dice[3] = 4;
		dice[4] = 2;
		dice[5] = 6;
	}
	Dice(vector<int> from){ dice = from; }
	void right(){
		int to[] = {1,3,5,2,4,6};
		doRotate(to);
	}
	void west(){
		int to[] = {3,2,6,1,5,4};
		doRotate(to);
	}
	void north(){
		int to[] = {2,6,3,4,1,5};
		doRotate(to);
	}
	void doRotate(int to[6]){
		vector<int> tmp = dice;
		rep(i,6) tmp[i] = dice[to[i]-1];
		dice = tmp;
	}
	vector< vector<int> > generateAllPattern(){
		vector< vector<int> > ans;
		for(int i = 0 ; i < 4 ; i++){
			for(int j = 0 ; j < 4 ; j++){
				for(int k = 0 ; k < 4 ; k++){
					ans.push_back(dice);
					north();
				}
				west();
			}
			right();
		}
		sort(ans.begin(),ans.end());
		ans.erase(unique(ans.begin(),ans.end()),ans.end());
		return ans;
	}
};


int main(){
	int n;
	while(cin >> n && n){
		vector<Dice> dice[300][300];
		vector< vector<int> > pt = Dice().generateAllPattern();
		for(int i = 0 ; i < n ; i++){
			int t,f;
			cin >> t >> f;
			Dice d;
			for(int j = 0 ; j < pt.size() ; j++){
				if( pt[j][0] == t && pt[j][1] == f ){
					d = Dice(pt[j]);
				}
			}
			
			int x = 150 , y = 150;
			dice[y][x].push_back(d);
			
			int dx[] = {0,0,-1,1,0};
			int dy[] = {0,1,0,0,-1};
			while(1){
				int curmax = -1 , dir = 0;
				for(int j = 1 ; j < 5 ; j++)
					if( dice[y][x][dice[y][x].size()-1].dice[j] >= 4 && dice[y+dy[j]][x+dx[j]].size()+1 < dice[y][x].size()){
						
						if( curmax <  dice[y][x][dice[y][x].size()-1].dice[j] ){
							curmax = dice[y][x][dice[y][x].size()-1].dice[j];
							dir = j;
						}
					}
				//cout << x << " " << y << " " << curmax << " " << dir << " " << dice[y][x][dice[y][x].size()-1].dice[0] << endl;
				if( curmax == -1 ) break;
				if( dir == 1 ) rep(j,3) dice[y][x][dice[y][x].size()-1].north();
				if( dir == 2 ) rep(j,3)dice[y][x][dice[y][x].size()-1].west();
				if( dir == 3 )  dice[y][x][dice[y][x].size()-1].west();
				if( dir == 4 ) dice[y][x][dice[y][x].size()-1].north();
				
				dice[y+dy[dir]][x+dx[dir]].push_back(dice[y][x][dice[y][x].size()-1]);
				dice[y][x].pop_back();
				x += dx[dir];
				y += dy[dir];
			}
			
		}
		int ans[7] = {};
		for(int j = 0 ; j < 300 ; j++)
			for(int k = 0 ; k < 300 ; k++)
				if(dice[j][k].size())ans[dice[j][k][dice[j][k].size()-1].dice[0]]++;
		for(int j = 1 ; j <= 6 ; j++)
			cout << ans[j] << (j==6?"\n":" ");
	}
}

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

struct Node{
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listsearch(int key){
  Node *cur= nil->next;
  while(cur!=nil && cur->key != key){
    cur = cur -> next;
  }
  return cur;
}

void init(){
  nil=(Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

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

void deleteNode(Node *t){
  if(t==nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deletefirst(){
  deleteNode(nil->next);
}

void deletelast(){
  deleteNode(nil->prev);
}

void deletekey(int key){
  deleteNode(listsearch(key));
}

void insert(int key){
  Node *x = (Node *)malloc(sizeof(Node));
  x -> key =key;
  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{
	deletekey(key);
	nd++;
      }
      size--;
    }
  }

  printlist();

  return(0);
}

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

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

template <typename T>
struct WeightedUnionFind{
  int n;
  T d;
  vector<int> r, p;
  vector<T> ws;
  WeightedUnionFind(){}
  WeightedUnionFind(int sz, T d_):
    n(sz), d(d_), r(n, 1), p(n), ws(n, d){iota(p.begin(), p.end(), 0);}

  int find(int x){
    if(x == p[x]){
      return x;
    }else{
      int t = find(p[x]);
      ws[x] += ws[ p[x] ];
      return p[x] = t;
    }
  }

  T weight(int x){
    find(x);
    return ws[x];
  }

  int same(int x,int y){
    return find(x) == find(y);
  }

  void unite(int x, int y, T w){
    w += weight(x);
    w -= weight(y);
    x = find(x); y = find(y);
    if(x == y) return;
    if(r[x] < r[y]) swap(x, y), w = -w;
    r[x] += r[y];
    p[y] = x;
    ws[y] = w;
  }

  T diff(int x,int y){
    return weight(y) - weight(x);
  }
};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  while(cin>>n,n){
    WeightedUnionFind<int> uf(n*2,0);
    int sz=0;
    map<string,int> idx;

    int flg=1;
    for(int i=0;i<n;i++){
      string a,b,c,d,e;
      cin>>a>>b>>c>>d>>e;
      if(!idx.count(b)) idx[b]=sz++;
      if(!idx.count(e)) idx[e]=sz++;

      int dif=stoi(d.substr(3));
      if(!uf.same(idx[b],idx[e])){
        uf.unite(idx[b],idx[e],dif);
      }else{
        int act=uf.diff(idx[b],idx[e]);
        //cout<<act<<" "<<dif<<endl;
        flg&=(dif==act);
      }
    }
    cout<<(flg?"Yes":"No")<<endl;
  }

  return 0;
}



Measured memory_bytes: 3196
import java.util.*;

public class Main {
    public static void main(String[] args ) throws Exception {
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long start = 100;
        long interest = 0;
        long count = 0;
        while(true){
          	interest = 0;
          	count++;
            interest += (start/100);
            start += interest;
            if(X <= start){
                System.out.println(count);
              	break;
            }
        }
    }
}


Measured memory_bytes: 26892
// eddy1021
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long ll;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<LD,LD> Pt;
typedef tuple<int,int,int> tiii;
typedef tuple<LL,LL,LL> tlll;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define FI first
#define SE second
#define X FI
#define Y SE
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline ll getint(){
  ll _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline ll add( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x + _y;
  if( _ >= _mod ) _ -= _mod;
  return _;
}
inline ll sub( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x - _y;
  if( _ < 0 ) _ += _mod;
  return _;
}
inline ll mul( ll _x , ll _y , ll _mod = mod7 ){
  ll _ = _x * _y;
  if( _ >= _mod ) _ %= _mod;
  return _;
}
ll mypow( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 1ll;
  ll _tmp = mypow( _a , _x / 2 , _mod );
  _tmp = mul( _tmp , _tmp , _mod );
  if( _x & 1 ) _tmp = mul( _tmp , _a , _mod );
  return _tmp;
}
ll mymul( ll _a , ll _x , ll _mod ){
  if( _x == 0 ) return 0ll;
  ll _tmp = mymul( _a , _x / 2 , _mod );
  _tmp = add( _tmp , _tmp , _mod );
  if( _x & 1 ) _tmp = add( _tmp , _a , _mod );
  return _tmp;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
int __ = 1 , _cs;
/*********default*********/
#define N 1021
void build(){

}
char c[ N ];
int chg( char ctmp ){
  if( ctmp == 'N' ) return 0;
  if( ctmp == 'S' ) return 1;
  if( ctmp == 'W' ) return 2;
  if( ctmp == 'E' ) return 3;
  return -1;
}
bool ap[ 4 ];
void init(){
  scanf( "%s" , c );
}
void solve(){
  int len = strlen( c );
  for( int i = 0 ; i < len ; i ++ )
    ap[ chg( c[ i ] ) ] = true;
  if( ( ap[ 0 ] ^ ap[ 1 ] ) || ( ap[ 2 ] ^ ap[ 3 ] ) )
    puts( "No" );
  else puts( "Yes" );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 764
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
from collections import deque

N, K = mi()
D = li()

r = [i for i in range(10) if i not in D]

if r[0]==0:
    que = deque(r[1:])
    #que = r[:][1:]
else:
    que = deque(r)
    #que = r[:]

for num in que:
    if N <= num:
        print(num)
        exit()
i = 0
while True:
    base = que[i]*10
    for num in r:
        new = base + num
        if new >= N:
            print(new)
            exit()
        que.append(new)
    i += 1


Measured memory_bytes: 38896
N = int(input())
a_list = list(map(int, input().split()))
dic = {}
for i in range(N):
    dic[i+1] = a_list[i]
dic_sorted = sorted(dic.items(), key=lambda x: x[1])
ans = " ".join(["{0}".format(key) for (key, value) in dic_sorted])
print(ans)


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

int ope(int A,int B,int C){
	if(A==1){
		return B-C;
	}
	else if(A==0){
		return B+C;
	}
}

int main() {
	int A,B,C,D;
	string N;
	cin >>N;
	A =N.at(0)-'0';
	B =N.at(1)-'0';
	C =N.at(2)-'0';
	D =N.at(3)-'0';
	
	vector<char> oper(2);
	oper.at(1)='-';
	oper.at(0)='+';
	bool pro=false;
	for (int i=0;i<2;i++){
		for (int j=0;j<2;j++){
			for (int k=0;k<2;k++){
				int ans = ope(i,A,ope(j,B,ope(k,C,D)));
				if(ans==7){
					cout <<A<<oper.at(i)<<B<<oper.at((i+j)%2)<<C<<oper.at((k+i+j)%2)<<D<<"=7"<<endl;
					pro =true;
					break;
				}
			}
		if(pro){
			break;
		}
		}
		if(pro){
			break;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
int main() {
	int n;
	std::cin >> n;
	if (n == 3 || n == 5 || n == 7) {
		std::cout << "YES" << std::endl;
	}
	else {
		std::cout << "NO" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int data[3];
	int i;
	int max=0;
	int sankaku=0,tyokaku=0,eikaku=0,donkaku=0;
	int type;
	while(1){
		max=0;
		for(i=0;i<3;i++){
			scanf("%d",&data[i]);
			if(max<data[i]){
				max=data[i];
			}
		}
		for(i=0;i<3;i++){
			if(data[i]>=data[0]+data[1]+data[2]-data[i]){
				printf("%d %d %d %d\n",sankaku,tyokaku,eikaku,donkaku);
				return 0;
			}
		}
		sankaku++;
		type=data[0]*data[0]+data[1]*data[1]+data[2]*data[2]-max*max*2;
		if(type==0){
			tyokaku++;
		}
		else if(type>0){
			eikaku++;
		}
		else if(type<0){
			donkaku++;
		}
	}
}

Measured memory_bytes: 596
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll X, Y;

void solve() {
    ll i = X;
    ll ans = 1;
    while (i * 2 <= Y) {
        i *= 2;
        ans++;
    }
    cout << ans << endl;
}

int main() {
    cin >> X >> Y;
    solve();
    return 0;
}

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

int main(){
    int x;
    cin >> x;
    if(abs(360%x==0)){
        cout << abs(360/x) << endl;
        return 0;
    }
    else{
        for(int i=2; i<=179; i++){
            if(abs(360*i%x==0)){
                cout << abs(360*i/x) << endl;
                return 0;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 3620
n = int(input())
a = list(map(int, input().split()))

def quicksort(array):
    if len(array) < 2:
        return(array)
    else:
        pivot = array[0]
        less = [i for i in array[1:] if i <= pivot]
        greater = [i for i in array[1:] if i > pivot]

        return quicksort(greater) + [pivot] + quicksort(less)


sorted_a = quicksort(a)
alice = []
bob = []
for i in range(len(sorted_a)):
    if i % 2 == 0:
        alice.append(sorted_a[i])
    else:
        bob.append(sorted_a[i])
print(sum(alice) - sum(bob))


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int[] lasts = new int[26+1];
        Arrays.fill(lasts, 1);
        int[] c = new int[26+1];
        for(int i = 1;i<=26;i++){
            c[i] = sc.nextInt();
        }

        int[][] s = new int[d+1][26+1];
        for(int i = 1;i<=d;i++){
            int maxx = 1;
            int va = -999999;
            for(int j = 1;j<=26;j++){ 
                s[i][j] = sc.nextInt();
                if(va < s[i][j] / lasts[j]) {
                    maxx = j;
                }
            }
            System.out.println(maxx);
            lasts[maxx] = i;
        }
    }
}

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

int main()
{
	char d;
	int p,n,ps,ns,c;
	
	ps=ns=c=0;
	while(cin >> p >> d >> n)
	{
		ps+=p*n;
		ns+=n;
		c++;
	}
	cout << ps << endl << (int)((double)ns/c+0.5) << endl;
}

Measured memory_bytes: 0
#include<cstdio>
int n,h[100005],f[100005]; 
int abs(int x){return x>0?x:-x;}
int min(int a,int b){return a<b?a:b;}
int main()
{
	scanf("%d",&n);if(n)scanf("%d",&h[1]),h[0]=1e9;
	for(int i=2;i<=n;i++)
	{
		scanf("%d",&h[i]);
		f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	}printf("%d\n",f[n]);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n,m,k,i,j,l,a,b,e,inf=1<<28;
  cin>>n>>m>>k;
  int dp[1<<m],d[n],c[k];
  map<int,int> r;
  vector<int> G[n][k];
  for(b=0;b<(1<<m);b++) dp[b]=inf;
  for(i=0;i<m;i++) cin>>d[i],r[--d[i]]=i;
  for(i=0;i<n;i++){
    for(j=0;j<k;j++){
      cin>>e;
      if(r.find(i)!=r.end()) G[e-1][j].push_back(i);
    }
  }
  queue<P> q;
  q.push(P(0,0));
  for(j=0;j<k;j++){
    c[j]=0;
    for(i=0;i<n;i++){
      if(r.find(i)!=r.end()) continue;
      for(l=0;l<G[i][j].size();l++)
	c[j]|=(1<<r[G[i][j][l]]);
    }
  }
  while(!q.empty()){
    a=q.front().first;b=q.front().second;q.pop();
    if(dp[b]<=a) continue;
    dp[b]=a;
    if(b==(1<<m)-1) break;
    for(j=0;j<k;j++){
      int o=0;
      for(i=0;i<m;i++){
	if(((b>>i)&1)==0) continue;
	for(l=0;l<G[d[i]][j].size();l++)
	  o|=(1<<r[G[d[i]][j][l]]);
      }
      if(a+1<dp[(o|c[j])]) q.push(P(a+1,(o|c[j])));
    }
  }
  cout << dp[(1<<m)-1] << endl;
  return 0;
}

Measured memory_bytes: 17584
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int test[123456];
int main(){
  int n, k, a, b, ans = 1; cin >> n;
  int sum = n*100/108;
  if(108*sum/100==n){
    cout<<sum<<endl;
  }
  else if(108*(sum+1)/100==n){
   cout<<sum+1<<endl; 
  }
  else{
   cout<<":("<<endl; 
  }
}

Measured memory_bytes: 256
n = gets.to_i
as = n.times.map { gets.to_i }

if as.count(0) == 0
  p as.inject(&:+) / 2
else
  l = 0
  ans = 0
  as.each_with_index do |ai, i|
    if ai == 0
      if i == 0
        l = 1
      else
        ans += as[l..i].inject(&:+) / 2 if !(as[l..i].empty?)
        # p as[l..i]
        l = i+1
      end
    end
  end
  ans += as[l...n].inject(&:+) / 2 if !(as[l...n].empty?)
  p ans
end


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

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

  int sn = S.size();
  int tn = T.size();

  vector<int> A(1000, 0);

  for(int l = 0; l < tn; ++l){
    char c = T.at(l);
    for(int i = 0; i < sn - tn + 1; ++i){
      if(c == S.at(i+l)){
        ++A.at(i);
      }
    }
  }

  int cnt = 0;
  for(int i = 0; i < 1000; ++i){
    cnt = max(cnt, A.at(i));
  }

  cout << tn - cnt << endl;
}


Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
vector<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
vector<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int n, m, ans = 0;
vector<vector<int>> to(10, vector<int>());
vector<bool> saw(10, false);

void dfs(int v) {
    bool flag = true;
    rep(i, n) {
        if (!saw[i]) flag = false;
    }
    if (flag) {
        ans++;
        return;
    }
    for (int nv : to[v]) {
        if (saw[nv]) continue;
        saw[nv] = true;
        dfs(nv);
        saw[nv] = false;
    }
}


int main () {
    cin >> n >> m;
    rep(i, m) {
        int a, b; cin >> a >> b; a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> vec(n);
    rep(i, n) vec[i] = i;
    saw[0] = true;
    dfs(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iomanip>
//#include <chrono>
//#include <random>

#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define long int64_t
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ std::cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<> dis(0, INF<<1);

const int N = 6001;

int mod, nf, n, n3;

int modexp(int a, int b)
{
	int r = 1;
	while(b)
	{
		if(b & 1)
			r = (r * 1ll * a) % mod;
		a = (a * 1ll * a) % mod;
		b >>= 1;
	}
	return r;
}

int dp[N][N], inv[N+3];

int solve(int i, int j)
{
	if(i > n3 or j > n)
		return 0;
	if(i == n3)
		return nf;
	if(dp[i][j] != -1)
		return dp[i][j];
	int ret = 0;
	for(int k=1; k<=3; k++)
		ret = (ret + inv[i+k] * 1ll * solve(i+k, j + int(k>1))) % mod;
	return dp[i][j] = ret;
}

int main()
{
	fio;
	memset(dp, -1, sizeof dp);
	cin >> n >> mod;
	n3 = n * 3;
	nf = 1;
	for(int i=2; i<=n3; i++)
		nf = (nf * 1ll * i) % mod;
	for(int i=1; i<=n3; i++)
		inv[i] = modexp(i, mod-2);
	cout << solve(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 141440
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
const int maxn = 100;
int check(int x){
    int tmp = x;
    int pos = 0;
    while (tmp){
         pos =pos  * 10 + tmp % 10;
         tmp /= 10; 
    }
    return pos == x;
}
int main(){
   int l;int r;
   scanf("%d%d",&l,&r);
   int ans = 0;
   for (int i = l; i <= r; i++){
       if (check(i)) ans++;
   }
   printf("%d\n",ans);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, q;
const int N = 500000;
#define LL long long
const LL INF = 1e18;
int xi[N];
int lb[N], rb[N], lc[N], rc[N], tot;
LL mnl[N], mnr[N], tag[N], s;
void upd(int t)
{
    mnl[t] = min(mnl[lc[t]], mnl[rc[t]] + rb[lc[t]] - lb[lc[t]] + 1);
    mnr[t] = min(mnr[rc[t]], mnr[lc[t]] + rb[rc[t]] - lb[rc[t]] + 1);
}
int build(int l, int r)
{
    int t = ++ tot;
    lb[t] = l; rb[t] = r;
    if (l != r)
    {
        lc[t] = build(l, (l + r) / 2);
        rc[t] = build((l + r) / 2 + 1, r);
        upd(t);
    }
    else
    {
        mnl[t] = INF;
        mnr[t] = INF;
    }
    return t;
}
LL queryl(int t, int l, int r)
{
    if (l <= lb[t] && rb[t] <= r) return mnl[t] + lb[t] - l;
    LL mn = INF;
    if (l <= rb[lc[t]]) mn = min(mn, queryl(lc[t], l, r));
    if (r >= lb[rc[t]]) mn = min(mn, queryl(rc[t], l, r));
    return mn;
}
LL queryr(int t, int l, int r)
{
    if (l <= lb[t] && rb[t] <= r) return mnr[t] + r - rb[t];
    LL mn = INF;
    if (l <= rb[lc[t]]) mn = min(mn, queryr(lc[t], l, r));
    if (r >= lb[rc[t]]) mn = min(mn, queryr(rc[t], l, r));
    return mn;
}
void modify(int t, int x, LL w)
{
    if (lb[t] == rb[t])
    {
        mnl[t] = mnr[t] = w;
        return;
    }
    if (x <= rb[lc[t]]) modify(lc[t], x, w); else modify(rc[t], x, w);
    upd(t);
}
LL dfs(int t)
{
    if (lb[t] == rb[t]) return mnl[t];
    return min(dfs(lc[t]), dfs(rc[t]));
}
int main()
{
    scanf("%d%d%d%d", &n, &q, &xi[0], &xi[1]);
    build(1, n);
    for (int i = 2; i <= q + 1; ++ i) scanf("%d", &xi[i]);
    modify(1, xi[0], 0);
    for (int i = 2; i <= q + 1; ++ i)
    {
         LL w = min(queryr(1, 1, xi[i]), queryl(1, xi[i], n));
         modify(1, xi[i - 1], w - abs(xi[i] - xi[i - 1])); s += abs(xi[i] - xi[i - 1]);
    }
    printf("%lld\n", dfs(1) + s);
}


Measured memory_bytes: 18816
# s = input()
n = int(input())
# a, b, c = map(int, input().split())
a = list(map(int, input().split()))

for _a in a:
    if _a%2 == 0:
        if _a%3 != 0 and _a%5!=0:
            print("DENIED")
            exit()

print("APPROVED")

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <queue>
using namespace std;
int main(){
    int n,q;
    cin >> n >> q;
    queue<pair<string,int> > Q;
    for(int i=0;i<n;++i){
        pair<string,int> ps;
        cin >> ps.first >> ps.second;
        Q.push(ps);
    }
    int now=0;
    while(!Q.empty()){
        pair<string,int> ps=Q.front();Q.pop();
        if(ps.second<=q){
            now+=ps.second;
            cout << ps.first << ' ' << now << endl;
        }else{
            now+=q;
            ps.second-=q;
            Q.push(ps);
        }
    }
}



Measured memory_bytes: 6204
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=405;
const int mod=998244353;
int pow_mod(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;
}
int f[MAXN][MAXN],fpow[MAXN][MAXN];
int n,a[MAXN],b[MAXN],pre[MAXN],inv[MAXN];
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	for(int i=1;i<MAXN;i++)
	{
		fpow[i][0]=1;
		for(int j=1;j<MAXN;j++)fpow[i][j]=1LL*fpow[i][j-1]*i%mod;
	}
	n=read();f[0][0]=1;int cal=0;
	for(int i=1,pre1=0,pre2=0;i<=n;i++)
	{
		int x=read(),y=read();cal+=x;
		for(int j=pre2;j>=0;j--)for(int k=pre1;k>=0;k--)if(f[j][k])
			for(int l=0;l<y;l++)dl(f[j+x][k+l],1LL*f[j][k]*fpow[x][l]%mod*inv[l]%mod);
		pre2+=x;pre1+=(y-1);
	}int ans=0;
	for(int i=1;i<MAXN;i++)for(int j=0;j<MAXN;j++)if(f[i][j])
	{
		int t=pow_mod(pow_mod(i,j+1),mod-2);
		ad(ans,1LL*f[i][j]*t%mod*pre[j]%mod*cal%mod);
	}
	pr2(mod-ans);
	return 0;
}


Measured memory_bytes: 1408
while True:
    a, op, b = input().split() 
    a = int(a) 
    b = int(b) 
    if op == '?':
        break
    if op == '+':
        print(a+b)
    if op == '-':
        print(a-b)
    if op == '*':
        print(a*b)
    if op == '/':
        print(a//b)



Measured memory_bytes: 5596
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
import math
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
#import numpy as np
#INF = float("inf")
H,W = map(int,input().split())#頂点、辺の数
INF = float("inf")
cost = [list(map(int,input().split())) for _ in range(10)]
#実装
for k in range(10):
    for i in range(10):
        for j in range(10):
            cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j])
s = 0
for _ in range(H):
    A = list(map(int,input().split()))
    for k in A:
        if k == -1:
            continue
        s += cost[k][1]
print(s)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

manzoku = sum(B)
for i in range(N-1):
    if A[i+1] - A[i] == 1:
        manzoku += C[A[i]-1]
print(manzoku)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int a,b; cin>>a>>b;
	if(max(a,b)>=10) cout<<-1<<'\n';
	else cout<<a*b<<'\n';
	
	return 0;
}


Measured memory_bytes: 3624
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	static final Scanner s=new Scanner(System.in);
	
	static int t,p,r;
	public static void main(String __[]) throws FileNotFoundException {
		while(true){
			t=s.nextInt();
			p=s.nextInt();
			r=s.nextInt();
			
			if(t+p+r==0)return;
			
			Team[]teams=IntStream.rangeClosed(1,t).mapToObj(Team::new).toArray(Team[]::new);
			for(int i=0;i<r;i++) {
				int tt=s.nextInt(),pp=s.nextInt(),time=s.nextInt();
				String mes=s.next();
				
				switch(mes){
				case "CORRECT":
					teams[tt-1].pena+=teams[tt-1].wa[pp-1]*1200+time;
					teams[tt-1].solved++;
					break;
				case "WRONG":
					teams[tt-1].wa[pp-1]++;
					break;
				}
			}
			Arrays.stream(teams).sorted(
					Comparator
					.comparingInt(Team::getSolved).reversed()
					.thenComparingInt(Team::getPenalty)
					.thenComparingInt(Team::getID)
					).forEach(System.out::println);
		}
	}
	static class Team{
		int id,pena=0,solved=0,wa[]=new int[p];
		Team(int id){
			this.id=id;
		}
		int getSolved() {
			return solved;
		}
		int getPenalty() {
			return pena;
		}
		int getID() {
			return id;
		}
		@Override
		public String toString(){
			return id+" "+solved+" "+pena;
		}
	}
}

Measured memory_bytes: 73372
import java.util.*;
import static java.lang.System.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			if (sc.nextInt() >= k) {
				cnt++;
			}
		}
		
		out.println(cnt);
		
	}
}

Measured memory_bytes: 47984
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	for (int b = 1;b <= n;++b) {
		int p = n / b;
		int r = n % b;
		ans += p * max(0, b - k) + max(0, r - k + 1);
		if (k == 0)--ans;
	}
	cout << ans << endl;
}

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

	#define scanI(n)    scanf("%d", &n)
	#define scanII(a, b) scanf("%d %d", &a, &b)
	#define scanIII(a, b, c) scanf("%d %d %d", &a, &b, &c)
	#define printI(n) printf("%d", n)
	#define printII(a,b) printf("%d %d", a, b)
	#define ALL(x) x.begin(), x.end()
	#define VI vector<int>
	#define LL long long
	#define PRINT(list) for(auto i : list) printf("%d ", i); printf("\n");
	#define PRINTARR(ar_, n_) for(int i_=0; i_<n_; i_++){printf("%d ", ar_[i_]);} printf("\n");
	#define DPRINT(dlist) for(auto list : dlist) { PRINT(list); printf("\n"); }
	#define INIT(ar, n, val) for(int _i=0; _i<n; _i++) ar[_i] = val;
	#define MOD 1000000007
        #define PI 3.142857
	#define MAX_OP [](int a, int b){return max(a,b);}
	#define MIN_OP [](int a, int b){return min(a,b);}


	using namespace std;

	void test(){

	}

	int main(){
        int n;
        scanI(n);
        int ar[n];
        
        
        for(int i=0; i<n; i++)
            scanI(ar[i]);
        //PRINTARR(ar, n);
        sort(ar, ar+n);
        //PRINTARR(ar, n);
        int max1, max2;
        max1 = max2 = INT_MIN;
        
        int res[2], cnt=0;
        
        for(int i=n-1; i>0; i--){
            if(ar[i] == ar[i-1]){
                res[cnt++] = ar[i];
                i--;
                if(cnt == 2){
                    printf("%lld", (long long)res[0]*res[1]);
                    return 0;
                }
            }
        }
        printf("0");
            

	    return 0;
	}



Measured memory_bytes: 640
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	lint a,b,c,out=1145141919810364364LL;
	cin>>a>>b>>c;
	if(a%2==0 || b%2==0 || c%2==0){
		cout<<0<<endl;return 0;
	}
	out=min(a*b,a*c);out=min(out,b*c);
	cout<<out<<endl;
}


Measured memory_bytes: 256
def main():
    x1, y1, x2, y2 = map(int, input().split())
    edge_x = x2 - x1
    edge_y = y2 - y1
    x3, y3 = x2 - edge_y, y2 + edge_x
    x4, y4 = x1 - edge_y, y1 + edge_x
    print(x3, y3, x4, y4)


if __name__ == "__main__":
    main()


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

using namespace std;

int main(){
  int n;
  cin >> n;
  int ans = INT_MAX;
  vector<int> arr(n);
  int tot = 0;
  for(int i = 0; i < n; i++){
    cin >> arr[i];
    tot += arr[i];
  }
  
  int cur = 0;
  ans = min(ans, abs(cur-tot));
  for(int i = 0; i < n; i++){
    cur += arr[i];
    tot -= arr[i];
    ans = min(ans, abs(cur-tot));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll m, k;
    cin >> m >> k;

    ll b = 1;
    for(int i = 0; i < m; i++){
        b*=2;
    }
    if(b-1<k){cout << -1 << endl; return 0;}
    if(m==1 && k==0){
        cout << "0 0 1 1" << endl; return 0;
    }
    if(m==1 && k==1){
        cout << -1 << endl; return 0;
    }

    for(int i = 0; i < b-1; i++){
        if(i != k){
            cout << i << " ";
        }
    }
    cout << k << " ";
    for(int i = b-2; i >= 0; i--){
        if(i != k){
            cout << i << " ";
        }
    }
    if(b-1 != k){cout << b-1 << " ";}

    cout << k << " ";
    if(b-1 != k){cout << b-1 << " ";}

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;
int n;
lli ans = 0;
vector <vector <int>> a;

void floyd(bool &flag){
	for(int k = 0;k < n;++k){
		for(int i = 0;i < n;++i){
			for(int j = 0;j < n;++j){
				if(a[i][k] + a[k][j] < a[i][j]){
					flag = 1;
					return;
				}
			}
		}
	}
	return;
}

void solve(){
	cin >> n;
	a = vvint(n,vector <int>(n,0));
	for(int i = 0;i < n;++i){
		for(int j = 0;j < n;++j) cin >> a[i][j];
	}
	bool flag = 0;
	floyd(flag);
	if(flag){
		cout << -1 << newl;
		return;
	}
	for(int i = 0;i < n;++i){
		for(int j = i + 1;j < n;++j){
			ans = ans + a[i][j];
			bool flag0 = 0;
			for(int k = 0;k < n;++k){
				if(k == i or k == j) continue;
				if(a[i][k] + a[k][j] == a[i][j]){
					flag0 = 1;
					break;
				}
			}
			if(flag0) ans = ans - a[i][j];
		}
	}
	cout << ans << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3736
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

ans = [0]*n
judge_s = 0
judge_c = 0
sc = sorted(sc)

if m == 0:
    if n == 1:
        ans = 0
    else:
        ans = 10**(n-1)
else:
    for i in range(m):
        if judge_s == sc[i][0] and judge_c != sc[i][1]:
            ans = -1
            break
        if n != 1 and sc[i] == [1,0]:
            ans = -1
            break
        judge_s = sc[i][0]
        judge_c = sc[i][1]
        ans[sc[i][0]-1] = sc[i][1]


    if ans != -1:
        ans_ = ans.copy()
        ans = 0
        for i in range(n):
            ans += ans_[i]*10**(n-i-1)
        
        if ans_[0] == 0 and n != 1:
            ans += 10**(n-1)
            
    
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Stack;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		Stack<Integer> stack = new Stack<Integer>();

		for (int i = 0; i < str.length; i++) {
			if (str[i].equals("+")) {
				stack.push(stack.pop() + stack.pop());
			} else if (str[i].equals("-")) {
				int num01 = stack.pop();
				int num02 = stack.pop();
				stack.push(num02 - num01);
			} else if (str[i].equals("*")) {
				stack.push(stack.pop() * stack.pop());
			} else {
				stack.push(Integer.parseInt(str[i]));
			}
		}
		System.out.println(stack.pop());
	}
}

Measured memory_bytes: 24460
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;
    long long int N;
    long long int K;
    
   int  po(long double,int);
int main(void){
    cin>>N;
    cin>>K;
    long long int count = 1;
    int base = ceil(log2l(K));
    for(long double i=2;i<=N;i++){
        count += po(i,base);
    }
    long double one = pow(2,base)*N;
    //cout<<one<<endl<<count<<endl;
    cout<<setprecision(13)<<count/one<<endl;
    return 0;
}

int po(long double i,int base){
    long double a = log2l(K/i);
    if(a<0) a = 0;
    //cout<<a<<endl;
    long long int p = ceil(a);
    //cout<<pow(2,(base-p))<<endl;
    return pow(2,(base-p));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main() {
  int N; cin >> N;
  vi a(N); rep(i,N) cin >> a.at(i);
  
  int x = 0;
  rep(i,N) {
    x ^= a.at(i);
  }
  
  cout << (x==0 ? "Yes" : "No");
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N, W; cin >> N >> W;
  vector<ll> w(N), v(N);
  for(int i = 0 ; i < N; i++){
    cin >> w[i] >> v[i];
  }
  vector<vector<ll>> dp(N + 1, vector<ll> (W + 1, 0));
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= W; j++){
      if(j < w[i]) dp[i + 1][j] = dp[i][j];
      else{
        dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
      }
    }
  }
  cout << dp[N][W] << endl;
}

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

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

const int N = 2e5+10 , mod = 998244353;

int fac[N];

inline int pw(int x , int y){
   int ret = 1;
   for( ; y ; y /= 2){
      if(y & 1)
         ret = 1ll * ret * x % mod;
      x = 1ll * x * x % mod;
   }
   return ret;
}

inline int c(int x , int y){
   return 1ll * fac[y] * pw(1ll * fac[x] * fac[y - x] % mod , mod - 2) % mod;
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   fac[0] = 1;
   for(int i = 1 ; i < N ; i++)
      fac[i] = 1ll * fac[i - 1] * i % mod;
   int n , m , k;
   cin >> n >> m >> k;
   int ans = 0;
   for(int i = 0 ; i <= k ; i++){
      ans += 1ll * c(i , n - 1) * m % mod * pw(m - 1 , n - 1 - i) % mod;
      if(ans >= mod)
         ans -= mod;
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
  int a;
  cin >> a;
  if(a%2==0){
      cout << a << endl;
  }else{
      cout << 2*a << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}


signed main() {
	int d, n,i=0;
	cin >> d >> n;
	if (n == 100) {
		cout << 101 * modpow(100,d) << endl;
	}
	else {
		cout << n * modpow(100,d) << endl;
	}
}


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

using namespace std;

int ans = (int)1e9, D, G, p[100], c[100];
int score, cnt;

int main(){
    cin >> D >> G;
    for(int i = 0; i < D; ++i) cin >> p[i] >> c[i];

    for(int b = 0; b < (1 << D); ++b){
        score = 0, cnt = 0;
        for(int j = 0; j < D; ++j){
            if(b & (1 << j)){
                cnt += p[j];
                score += (j + 1) * 100 * p[j] + c[j];
            }
        }
        if(score < G){
            for(int j = D - 1; j >= 0; --j){
                if(!(b & (1 << j))){
                    int add_cnt = min(p[j], (int)ceil((G - score) / ((j + 1) * 100.0)) );
                    if((j + 1) * 100 * add_cnt >= G - score){
                        cnt += add_cnt;
                        ans = min(ans, cnt);
                    }
                }
            }
        }
        if(score >= G) ans = min(ans, cnt);
    }
    cout << ans << endl;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	string s;
	cin>>s;
	vector<int> left((int)s.size()+1,0);
	vector<int> right=left;
	int cnt=0;

	for(int i=0;i<(int)s.size();i++){
		if(s.at(i)=='<'){
			cnt++;
		}
		else{
			cnt=0;
		}

		left.at(i+1)=cnt;
	}

	cnt=0;

	for(int i=(int)s.size()-1;i>=0;i--){
		if(s.at(i)=='>'){
			cnt++;
		}else{
			cnt=0;
		}

		right.at(i)=cnt;
	}

	long long ans=0;

	for(int i=0;i<(int)s.size()+1;i++){
		ans+=max(left.at(i),right.at(i));
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 4740
N = int(input())

A = [list(map(int,input().split())) for i in range(2)]

# 各マスの最大値を保持するマスを作成
Am = [[0 for j in range(N)] for i in range(2)]
# ループ内で処理するのめんどう
Am[0][0] = A[0][0]
Am[1][0] = A[0][0] + A[1][0]

# 1段目
for i in range(N):
  if i > 0:
    Am[0][i] = A[0][i] + Am[0][i-1]
# 2段目
for i in range(N):
  if i > 0:
    Am[1][i] = A[1][i] + max( Am[0][i] , Am[1][i - 1])


#print(Am)
print(Am[1][N-1])

Measured memory_bytes: 3064
from itertools import accumulate

while True:
  n, k = map(int, input().split())
  if n == 0 and k == 0:
    break
  A = [int(input()) for _ in range(n)]
  
  S =[0] + list(accumulate(A))
  d = [S[i]-S[i-k] for i in range(k, n+1)]
  print(max(d))



Measured memory_bytes: 15520