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

using namespace std;

int main() {
  int i;
  int N;
  long long a[10010], b[10010], diff[10010];
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  for (i = 0; i < N; i++) {
    scanf("%lld", &b[i]);
    diff[i] = a[i] - b[i];
  }
  sort(diff, diff+N);
  long long ans = 0;
  for (i = N-1; i >= 0; i--) {
    if (diff[i] > 0) {
      ans += diff[i];
    } else if (diff[i] < 0) {
      long long minus = (-1)*diff[i];
      ans -= minus / 2;
    }
  }
  if (ans > 0) {
    printf("No");
  } else {
    printf("Yes");
  }
  return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	while(scanf("%d", &n), n!=-1){
		vi v;
		do{
			v.push_back(n%4);
			n /= 4;
		}while(n);
		for(int i=v.size()-1; i>=0; --i)
			printf("%d", v[i]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   

    ll k,x;
    cin >> k >> x;
    for (ll i=-k+1;i<=k-1;i++){
        cout << x+i << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, 0, n) cin >> v[i];
    sort(v.begin(), v.end());
    rep(i, 1, n)
    {
        v[i] = (v[i] + v[i - 1]) / 2;
    }
    cout << setprecision(5) << fixed << v[n - 1] << endl;
}


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

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

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

    int now = a[0];
    int cou = 0;
    int ans = 0;
    for(int i = 1; i < n; i++){
        if(a[i] == now){
            cou++;
        }else{
            now = a[i];
            if(cou != 0){
                if(cou % 2 == 0){
                    ans += (cou / 2);
                }else{
                    ans += (cou / 2);
                    ans++;
                }
            }
            cou = 0;
        }
    }

    if(cou != 0){
        if(cou % 2 == 0){
            ans += (cou / 2);
        }else{
            ans += (cou / 2);
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main(int argc, const char * argv[]) {
    int N, R;
    cin >> N;
    cin >> R;
    
    int ans = R;
    if (N < 10) {
        ans += 100 * (10 - N);
    }
    std::cout << ans;
    return 0;
}


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

using namespace std;

#define MOD 1000000007
typedef long long ll;

int main(){
	ll n, ans = 1, cou = 0;
	string str;
	cin >> n >> str;

	for(int i = 0;i < str.size();i++){
		int now = ((cou % 2 == 0) + (str[i] == 'B')) % 2;

		if(now){
			ans = (ans * cou) % MOD;
			cou--;
		}
		else {
			cou++;
		}

		if(cou < 0){
			cout << 0 << endl;
			return 0;
		}
	}

	for(int i = 1;i <= n;i++){
		ans = (ans * i) % MOD;
	}

	cout << (cou == 0 ? ans : 0) << endl;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 1; i < N; i++) {
    string x = S.substr(0, i);
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    string y = S.substr(i);
    int cnt = 0;
    for (int j = 0; j < x.size(); j++) {
      if (count(y.begin(), y.end(), x.at(j))) cnt++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3580
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
s=list(input())
ans=n
r=[0]*n
l=[0]*n
for i in range(1,n):
    if s[i-1]=="W":
        r[i]=r[i-1]+1
    else:
        r[i]=r[i-1]
    if s[n-i]=="E":
        l[n-1-i]=l[n-i]+1
    else:
        l[n-1-i]=l[n-i]
for i in range(n):
    ans=min(ans,l[i]+r[i])
print(ans)


Measured memory_bytes: 98152
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int n;cin>>n;
    string s,t;cin>>s>>t;
    rep(i,n){
        cout<<s[i]<<t[i];
    }cout<<endl;
    return 0;
}


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

int main(){
  int h, w;
  cin >> h >> w;
  int cnt = 0;
  for (int i = 0; i < h; i++) {
	for (int j = 0; j < w; j++) {
	  char c;
      cin >> c;
      if (c == '#') cnt++;
    }
  }
  if (cnt == h + w -1) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
	char s[100];
	int i;
	int h;
	int cnt = 0;
	scanf("%s", s);
	h = strlen(s);
	
	for (i = 0; i < (h/2); i++) {
		if (s[i]!=s[h-(i+1)])
			cnt++;
	}
	printf("%d", cnt);


}


Measured memory_bytes: 128
/*
// A - abc of ABC
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  string S;
  cin>>S;
  sort(S.begin(),S.end());
  cout<<(S=="abc"?"Yes":"No")<<endl;
  return 0;
}

// B - Small and Large Integers
#include <iostream>
using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int A,B,K;
  cin>>A>>B>>K;
  if ((B-A+1)>2*K) {
    for (int i=0; i<K; i++) {
      cout<<A+i<<endl;
    }
    for (int i=K-1; i>=0; i--) {
      cout<<B-i<<endl;
    }
  } else {
    for (int i=A; i<=B; i++) {
      cout<<i<<endl;
    }
  }
  return 0;
}

// C - Same Integers
#include <iostream>
using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int A,B,C;
  cin>>A>>B>>C;
  int x=max(A,max(B,C));
  if ((3*x-(A+B+C))%2==0) {
    cout<<(3*x-(A+B+C))/2<<endl;
  } else {
    cout<<(3*(x+1)-(A+B+C))/2<<endl;
  }
  return 0;
}
*/
// D - Worst Case
#include <iostream>
#include <cmath>
using namespace std;
using ll=long long;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int Q;
  cin>>Q;
  while (Q--) {
    ll A,B;
    cin>>A>>B;
    if (A>B) {
      swap(A,B);
    }
    if (A==B||A+1==B) {
      cout<<2*A-2<<endl;
    } else {
      ll C=sqrt(A*B);
      if (A*B==C*C) {
        C--;
      }
      if (C*(C+1)<A*B) {
        cout<<2*C-1<<endl;
      } else {
        cout<<2*C-2<<endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )



int N, K;
ull A[200010];

int main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    int right = 0;
    ull x = 0;
    ull cnt = 0;
    for(int l = 0; l < N; l++) {
        while ((right < N) && ((x & A[right]) == 0)) {
            x |= A[right++];
        }
        cnt += right - l;
        if (right == l) {
            right++;
        }else {
            x -= A[l];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
const int mod=1e9+7;
void add(int &a,int b)
{
    a+=b;
    if(a>=mod)a-=mod;
}
void sub(int &a,int b)
{
    a-=b;
    if(a<0)a+=mod;
}
int allnum,n,k,dp[111][2][33323],w[33323];
int main()
{
    scanf("%d%d",&k,&n);
    allnum=sqrt(k);
    dp[1][0][0]=dp[1][1][0]=1;
    rep(j,1,allnum+1)w[j]=k/j-max(allnum,k/(j+1));
    rep(i,1,n+1)
    {
        rep(j, 1, allnum + 1)
        {
            add(dp[i][0][j], dp[i][0][j - 1]), add(dp[i][1][j], dp[i][1][j - 1]);
            add(dp[i + 1][0][0], dp[i][0][j]);
            add(dp[i + 1][1][j], dp[i][0][j]);
        }
        rep(j, 1, allnum + 1)
        {
            dp[i][1][j]=dp[i][1][j]*1ll*w[j]%mod;
            add(dp[i + 1][0][0], dp[i][1][j]), sub(dp[i + 1][0][j + 1], dp[i][1][j]);
        }
    }
    int res=0;
    rep(x,0,2)rep(j,1,allnum+1)
        add(res,dp[n][x][j]);
    printf("%d\n",res);
}

Measured memory_bytes: 28672
#include<bits/stdc++.h> 
using namespace std;
int main(){
string s;cin>>s;
  int c=0;int maxi=0;
  for(int i=0;i<(int)s.size();++i){
if(s[i]=='S')c=0;
    else ++c;
    maxi=max(maxi,c);
  }
  maxi=max(maxi,c);
  cout<<maxi<<endl;
}

Measured memory_bytes: 3568
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn bfs_dist(N:usize,E:&Vec<Vec<usize>>,start:usize) -> Vec<isize>{
    let mut D = (0..N).map(|_| -1).collect::<Vec<_>>();
    D[start] = 0;
    let mut q = vec![start];
    while q.len()>0{
        let mut qq = Vec::new();
        for &i in &q{
            for &j in &E[i]{
                if D[j]!=-1{continue;}
                D[j] = D[i]+1;
                qq.push(j);
            }
        }
        q = qq;
    }
    D
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let N = iter.next().unwrap().parse::<usize>().unwrap();
    let M = iter.next().unwrap().parse::<usize>().unwrap();
    let AB = (0..M).map(|_| (
        iter.next().unwrap().parse::<usize>().unwrap()-1,
        iter.next().unwrap().parse::<usize>().unwrap()-1
    )).collect::<Vec<_>>();

    let mut E = (0..N).map(|_| Vec::new()).collect::<Vec<_>>();
    for &(a,b) in &AB{
        E[a].push(b);
        E[b].push(a);
    }
    let D = bfs_dist(N,&E,0);
    let mut is_bipartite = true;
    for &(a,b) in &AB{
        is_bipartite = (D[a]^D[b])&1==1;
        if !is_bipartite {break;}
    }
    if is_bipartite{
        let mut n0 = 0;
        for &d in &D{
            n0 += (d%2) as usize;
        }
        let n1 = N-n0;
        println!("{}",n0*n1-M);

    } else {
        println!("{}",N*(N-1)/2-M);
    }
}

Measured memory_bytes: 16636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int h,n,d,mp; cin>>h>>n;
    vector<pp> m(n);
    rep(i,n){
        int a,b; cin>>a>>b;
        m[i]=mk(a,b);
    }
    vector<int> dp(h+1,inf);
    dp[0]=0;
    rep(i,h){
        for(auto ma:m){
            tie(d,mp)=ma;
            if(dp[min(h,i+d)]>dp[i]+mp)
            dp[min(h,i+d)]=dp[i]+mp;
        }
    }
    cout<<dp[h]<<endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl

typedef long long LL;
typedef long double LD;

int main(){
  int m,k;
  cin >> m >> k;
  if((1<<m)-1<k){
    cout << -1 << endl;
    return 0;
  }
  if(k==0){
    rep(i,(1<<m)){
      cout << i << " " << i << " ";
    }
    cout << endl;
    return 0;
  }
  if(m==1){
    cout << -1 << endl;
    return 0;
  }
  if(k==1){
    vector<int> ans;
    ans.reserve(1<<(m+1));
    rep(i,1<<(m-1)){
      int x=4*i,y=4*i+2;
      ans.push_back(y);
      ans.push_back(k^y);
      ans.push_back(k^x);
      ans.push_back(x);
      ans.push_back(k^y);
      ans.push_back(y);
      ans.push_back(x);
      ans.push_back(k^x);
    }
    rep(i,1<<(m+1)){
      cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
  }
  vector<int> ans;
  ans.reserve(1<<(m+1));
  vector<bool> usd(1<<m,false);
  rep(i,1<<(m-1)){
    if(usd[2*i]) continue;
    int x=2*i, y=2*i+1;
    usd[k^x]=usd[k^y]=true;
    ans.push_back(y);
    ans.push_back(k^y);
    ans.push_back(k^x);
    ans.push_back(x);
    ans.push_back(k^y);
    ans.push_back(y);
    ans.push_back(x);
    ans.push_back(k^x);
  }
  rep(i,1<<(m+1)){
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3836
#include<iostream>
#include<cstdio>
#define MAX_N 10000
using namespace std;
const int INF = 1 << 30;
int dp[2][MAX_N / 2 + 1][2];
int main() {
	int n, ans = INF, t[MAX_N + 1] = {};
	scanf("%d", &n);
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n / 2 + 1; j++) {
			fill(dp[i][j], dp[i][j] + 2, INF);
		}
	}
	for (int i = 0; i < n - 1; i++) {
		scanf("%d", &t[i]);
	}
	dp[1][1][1] = t[0];
	for (int i = 1; i < n ; i++) {
		for (int j = 0; j < n / 2 + 1; j++) {
			for (int k = 0; k < 2; k++) {
				dp[0][j][k] = dp[1][j][k]; 
				dp[1][j][k] = INF;
			}
		}
		for (int j = 0; j < n / 2; j++) {
			if (j > i) break;
			dp[1][j + 1][0] = min(dp[0][j + 1][1], dp[0][j + 1][0]);
			dp[1][j + 1][1] = min(dp[1][j + 1][1], min(dp[0][j][1] + t[i] - t[i - 1], dp[0][j][0] + t[i] + t[i - 1]));
		}
		ans = min(ans, min(dp[1][n / 2][0], dp[1][n/2][1]));
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1312
ls = sorted(list(map(int,input().split())))
bool = 0 
if ls[0] == ls[1] and ls[1] != ls[2]:
    bool = 1 
elif ls[1] == ls[2] and ls[0] != ls[1]:
    bool = 1
elif ls[0] == ls[2] and ls[0] != ls[1]:
    bool = 1
if bool:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9196
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

ll expo(ll a, ll b){
    ll ex = 1;
    rep(i, b){
        ex *= a;
    }
    return ex;
}

ll fact(ll a){
    ll fc = 1;
    REP(i, 1, a+1){
        fc *= i;
    }
    return fc;
}

int main() {
    str s, t;
    cin >> s >> t;
    bool ans = true;
    rep(i, s.size()){
        if(s[i]!= t[i]) {
            ans = false;
            break;
        }
    }
    if(ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,m;
	bool l=0,flg=0;
	cin>>n;
	string str[n],s;
	for(int i=0;i<n;i++) cin>>str[i];
	cin>>m;
	for(int i=0;i<m;i++){
		flg=0;
		cin>>s;
		for(int j=0;j<n;j++){
			if(s==str[j]){
				flg=1;
				if(l){
					cout<<"Closed by "<<s<<endl;
					l=0;
				}else{
					cout<<"Opened by "<<s<<endl;
					l=1;
				}
				break;
			}
		}
		if(flg==0) cout<<"Unknown "<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
import numpy as np

N, D = map(int, input().split())
X = []
for _ in range(N):
  X.append(list(map(int, input().split())))

cnt = 0
for i in range(N):
  for j in range(i, N):
    if i == j:
      continue
    dis = 0
    for k in range(D):
      dis += (X[i][k] - X[j][k]) ** 2
    dist = np.sqrt(dis)
    if dist == int(dist):
      cnt += 1
print(cnt)

Measured memory_bytes: 21644
#include <stdio.h>

int main(void){
    int a,b,c,count=3,i;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b){
        count--;
        if(b==c){
            count--;
        }
    }else if(b==c){
        count--;
    }else if(a==c){
        count--;
    }
    printf("%d\n",count);
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  if (b / 100 > 0)
    a = a * 10 + b / 100;
  if (b / 10 > 0)
    a = a * 10 + b / 10 % 10;
  a = a * 10 + b % 10;
  for (int i = 1; i * i <= a; i++) {
    if (i * i == a) {
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# B
# input
n = int(input())
a,b = map(int,input().split())
p = list(map(int,input().split()))
# calc
o1 = sum(1 for x in p if x<=a)
o3 = sum(1 for x in p if x>b)
o2 = n-o1-o3
# output
print(min(o1,o2,o3))

Measured memory_bytes: 3064
#include <stdio.h>  
#include <iostream>
#include<fstream>
#include<queue>
#define MAXN 1000005
#define ll long long
using namespace std;


int main() {
	int a[3],sum;
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	sum = a[1] - a[0] + a[2] - a[1];
	cout << sum << endl;
	return 0;
}

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

int main() {
  int N, K;
  
  cin >> N;
  cin >> K;
  
  int f = 1;
  int A, B;
  for (int i = 0; i < N; i++){
    A = f * 2;
    B = f + K;
    if (A < B){
      f = A;
    } else {
      f = B;
    }
  }
  cout << f << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

  int n;

  int n1,n2,st;
  //initialize
  n1=1;
  n2=1;
  st=1;
  //load number
  cin >>n;
  //fibonacci
  for(int i=1;i<n;i++){
    st=n1+n2;
    n1=n2;
    n2=st;
  }
  //print
  cout <<st<<endl;
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,cnt;
	cin>>n;
	cnt=n;
	char a[n];
	cin>>a;
	for(int i=0;i<n;i++)
	{
		if(a[i]-'0'==a[i+1]-'0')
		cnt--;
	}
	cout<<cnt<<endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int H, A, B;
	int i;
	int tomatu = 0;
	if (scanf("%d%d%d", &H, &A, &B) != 3) return 1;
	for (i = A; i <= B; i++) {
		if (H % i == 0) tomatu++;
	}
	printf("%d\n", tomatu);
	return 0;
}



Measured memory_bytes: 2128
def main():
    A = [int(i) for i in input().split()]
    A.sort()
    B = [A[2] - A[0], A[2] - A[1]]
    if B[0] % 2 == B[1] % 2:
        ans = sum(B)//2
    else:
        ans = 0--sum(B)//2 + 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    int A, B;
    cin >> A >> B;
    if(A>9||B>9) cout << -1 << endl;
    else cout << A*B << endl;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double A,B;
    ll N;
    cin >> A >> B >> N;
    double x = B-1;
    if(x > N) x = N;
    double ans = floor(A * x / B) - A * floor(x / B);
    ll res = (ll) ans;
    print(res);

}

Measured memory_bytes: 3736
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    string s;
    cin>>s;
    
    int t = 0;
    
    rep(i,s.size()){
        if(i%2==0&&s[i]=='p')t--;
        if(i%2&&s[i]=='g')t++;
    }
    
    cout<<t<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define umap unordered_map
#define all(v) v.begin(),v.end()
#define st first
#define nd second
#define ln '\n'
#define MAX 1000000009
#define MOD 1000000007
#define N 500005
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pii;
typedef vector<int> vi; 
ll t, n;

int main(){
    #ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    cin >> t >> n;
    if(t == 1 || n == 1){
        cout << 1;
    }
    else cout << (ll)ceil((long double)t * n / 2);
}


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

using namespace std;

typedef long long ll;

#define min(a, b) ((a) < (b)? (a):(b))
#define max(a, b) ((a) > (b)? (a):(b))
#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define abs(a) ((a) < (0)? -(a):(a))
#define pb push_back

int main() {
    int a, b; cin >> a >> b;
    cout << (a<9 && b<9? "Yay!":":(") << endl;
}

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

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

int main() {
	double input;
	vector<double> height;
	while (cin >> input) height.push_back(input);

	rep(i, height.size()) {
		rep(j, height.size() - i) {
			if (height[i + j] > height[i])swap(height[i + j], height[i]);
		}
	}
	cout << height[0] - height.back() << endl;
	return 0;
}

Measured memory_bytes: 3236
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node {
    int key;
    struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(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;
        }
    }
}

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(void) {
    int n, i, x;
    char com[16];
    scanf("%d",&n);
    
    for(i=0;i<n;i++) {
        scanf("%s",com);
        if(!strcmp(com,"insert")) {
            scanf("%d",&x);
            insert(x);
        } else if(!strcmp(com,"print")) {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 25144
from collections import deque
k = int(input())
que = deque(list(range(1,10)))
for i in range(k):
    x = que.popleft()
    if x%10!=0:
        que.append(10*x+x%10-1)
    que.append(10*x+x%10)
    if x%10!=9:
        que.append(10*x+x%10+1)
print(x)

Measured memory_bytes: 18704
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a[5]={0};
    for(int i=1;i<=3;i++){
        int x,y;
        cin>>x>>y;
        a[x]++;
        a[y]++;
    }
    bool ans= true;
    for(int i=1;i<=4;i++){
        ans &=(a[i]<3);
    }
    cout<<(ans?"YES":"NO");
}


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

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

	int coins[6] = {500, 100, 50, 10, 5, 1};

	for(int price; cin >> price, price;) {
		int change = 1000 - price;
		int ans = 0;
		
		for(int i = 0; i < 6; ++i) {
			while(change >= coins[i]) {
				change -= coins[i];
				++ans;
			}
		}
		
		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  int cnt=0;
  int ans=0;
  rep(i,n){
    if(s.at(i)=='L'){
      if(i>0&&s[i-1]=='L')cnt++;
    }
    else{
      if(i+1<n&&s[i+1]=='R')cnt++;
    }
  }
  ans=cnt + 2*k;
  ans=min(ans,n-1);
  cout << ans << endl;
}
      
  
  
  

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

int main() {
    int n;cin>>n;
    int l[n];
    for (int i=0;i<n;i++)
        cin>>l[i];
    sort(l,l+n);
    ll ans=0;
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++)
            ans+=lower_bound(l,l+n,l[i]+l[j])-1-l-j;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int N;
vector<int> h;

int solve() {
	int ans = 0, zero, left, right;

	do {
		left = 0;
		while (left < N && h[left] == 0)left++;
		right = left + 1;
		while (right < N && h[right] != 0) right++;

		if (left >= N) break;

		for (int i = left; i < right; i++) h[i]--;
		ans++;

		zero = 0;
		for (int i = 0; i < N; i++) {
			if (h[i] == 0) zero++;
		}
	} while (zero < N);

	return ans;
}

int main() {
	int i, num;

	cin >> N;

	for (i = 0; i < N; i++) {
		cin >> num;
		h.push_back(num);
	}

	cout << solve() << endl;

	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

bool isValid(int x){ return 0 <= x && x < 10000; }

int R1,R2;
char R3;

int main(){
  string s;
  while( getline(cin,s) ){
    bool error = false;
    R1 = R2 = 0; R3 = '@';
    rep(i,(int)s.size()){

      if( '0' <= s[i] && s[i] <= '9' ) {
        R2 *= 10;
        R2 += s[i] - '0';
        if(!isValid(R2)) error = true;
      } else {
        if( R3 == '@' ) R1 = R2;
        else {
          if( R3 == '+' ) R1 += R2;
          if( R3 == '-' ) R1 -= R2;
          if( R3 == '*' ) R1 *= R2;
        }
        R2 = 0;
        R3 = s[i];
        if(!isValid(R1)) error = true;
        if( s[i] == '=' ) break;
      }
      if( error ) break;
    }
    if( error ) puts("E");
    else printf("%d\n",R1);
  }
  return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N,R;
	while(cin>>N>>R,N||R){
		int P,C;
		vector<int> card;
		for(int i=1;i<=N;i++){
			card.push_back(i);
		}
		for(int i=0;i<R;i++){
			cin>>P>>C;
			vector<int>::iterator a,b;
			card.resize(card.size()+C);
			a = card.end()-C-P-C+1; b = card.end()-C-P+1;
			for(int j=0;j<C;j++){
				card[card.size()-(C-j)] = *(a+j);
			}
			card.erase(a,b);
		}
		printf("%d\n",card.back());
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,g,b,n,s,k;
    cin>>r>>g>>b>>n;
    k=0;
    for(int i=0;i<=n/r;i++)
    {
        for(int j=0;j<=(n-i*r)/g;j++)
        {
            if((n-i*r-j*g)%b==0)
                k++;
        }
    }
    cout<<k;
    return 0;
}


Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    ok = n
    ng = 0

    while ok-ng > 1:
        middle = (ok+ng)//2
        max_score = (middle)*(middle+1)//2
        if max_score >= n:
            ok = middle
        else:
            ng = middle
    
    ans_lst = []
    num = ok

    while n != 0:
        if n > num:
            ans_lst.append(num)
            n -= num
            num -= 1
        else:
            ans_lst.append(n)
            n -= n

    print(*ans_lst, sep="\n")

    # print(ok*(ok+1)//2, ok*(ok-1)//2,sum(ans_lst))

main()


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

int N, M, T;
int X[100000], Y[100000];

void solve1(){
    static bitset<50000> dp[50000], ok;
    for(int i=0; i<N; i++) dp[i][i] = 1;

    for(int i=M-1; i>=0; i--){
        dp[X[i]] |= dp[Y[i]];
        dp[Y[i]] = dp[X[i]];
    }
    ok.set();
    for(int i=0; i<N; i++) ok &= dp[i];

    for(int s=0; s<N; s++) if(ok[s]){
        bitset<50000> avail;
        string ans(M, '^');
        avail[s] = 1;
        for(int i=M-1; i>=0; i--){
            if(avail[X[i]]){
                avail[Y[i]] = 1;
            }else if(avail[Y[i]]){
                avail[X[i]] = 1;
                ans[i] = 'v';
            }
        }
        cout << ans << endl;
        return;
    }
    cout << -1 << endl;
}

void solve2(){
    if(N == 2){
        cout << -1 << endl;
        return;
    }
    vector<int> dest(N);
    vector<int> num(N, 1);
    for(int i=0; i<N; i++) dest[i] = i;
    string ans(M, ' ');
    for(int i=M-1; i>=0; i--){
        if(num[dest[X[i]]] >= 2){
            ans[i] = 'v';
            num[dest[X[i]]]--;
            num[dest[Y[i]]]++;
            dest[X[i]] = dest[Y[i]];
        }else{
            ans[i] = '^';
            num[dest[Y[i]]]--;
            num[dest[X[i]]]++;
            dest[Y[i]] = dest[X[i]];
        }
    }
    cout << ans << endl;
}

int main(){
    cin >> N >> M >> T;
    for(int i=0; i<M; i++){
        cin >> X[i] >> Y[i];
        X[i]--; Y[i]--;
    }
    if(T == 1) solve1();
    else solve2();
    
    return 0;
}


Measured memory_bytes: 306688
def bins(a, x):
    l = -1
    h = len(a)
    while (h-l) > 1:
        m = (l+h)//2
        if x >= a[m]:
            l = m
        else:
            h = m
    return l
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa, pb = [0] * (n+1), [0] * (m+1)
for i in range(n):
    pa[i+1] = pa[i] + a[i]
for i in range(m):
    pb[i+1] = pb[i] + b[i]
m = 0
for i in range(len(pa)):
    if pa[i] > k:
        break
    v = k - pa[i]
    bv = bins(pb, v)
    m = max(m, bv+i)
        
print(m)


Measured memory_bytes: 48544
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int c[3][3];
    bool ok=true;
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    int b[3];
    rep(j, 3)
    {
        b[j] = c[0][j];
    }
    int a2=c[1][0]-b[0];
    rep(i, 3)
    {
        if(a2!=c[1][i]-b[i])
        ok=false;
    }
    int a3=c[2][0]-b[0];
    rep(i, 3)
    {
        if(a3!=c[2][i]-b[i])
        ok=false;
    }
    cout<<(ok?"Yes":"No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=0;string s;cin>>n>>s;
  for(int i=0;i<n;i++){
    if(s.at(i)=='R')a++;
  }
  if(a>n/2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using pint = pair<int, int>;

int main()
{
    ll n, d;
    cin >> n >> d;
    d *= d;
    ll ans = 0;
    while (n--)
    {
        ll x, y;
        cin >> x >> y;
        if (d >= x * x + y * y)
            ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n,m;cin >> n >> m;
	int a[n];
	rep(i,n)cin >> a[i];
	vector<int> s(n+1);
	rep(i,n)s[i+1] = s[i] + a[i];
	map<int,int> mp;
	int ret = 0;
	rep(i,n+1){
		ret += mp[s[i]%m];
		mp[s[i]%m]++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 8736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));

    int sum=0;
    rep(i,n) sum+=abs(a[i]);
    if(a[0]>0) sum-=2*a[0];
    if(a[n-1]<0) sum+=2*a[n-1];
    cout<<sum<<endl;

    int acc=a[0];

    for(int i=1;i<n-1;i++){
        if(a[i]>=0){
            cout<<acc<<" "<<a[i]<<endl;
            acc-=a[i];
        }
    }

    cout<<a[n-1]<<" "<<acc<<endl;
    acc=a[n-1]-acc;

    for(int i=1;i<n-1;i++){
        if(a[i]<0){
            cout<<acc<<" "<<a[i]<<endl;
            acc-=a[i];
        }
    }


}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

vector<P> to[100005];
int ans [100005];

void dfs(int v, int p = -1) {
    for (auto e: to[v]) {
        if (e.first==p) continue;
        ans[e.first] = (ans[v] + e.second)%2;
        dfs(e.first, v);
    }
}

int main(){
    int n;
    cin >> n;
    rep(i, n-1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        to[u].emplace_back(v, w);
        to[v].emplace_back(u, w);
    }
    dfs(0);
    rep(i, n) {
        cout << ans[i] << endl;
    }
    return 0;
}


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

const int MAXN = 256;

int maxi;
int n;
int d[MAXN];
bool vis[MAXN], vis2[MAXN];

int nextPos(int pos, int m) {
  int npos = min(pos + m, n-1);
  npos += d[npos];
  npos = min(npos, n-1);
  npos = max(npos, 0);
  return npos;
}

void rec(int pos) {
  vis[pos] = true;
  for(int m = 1; m <= maxi; ++m) {
    int npos = nextPos(pos, m);
    if(vis[npos]) continue;
    rec(npos);
  }
}

bool rec2(int pos) {
  vis2[pos] = true;
  if(pos == n-1) return true;
  for(int m = 1; m <= maxi; ++m) {
    int npos = nextPos(pos, m);
    if(vis2[npos]) continue;
    if(rec2(npos)) return true;
  }
  return false;
}

int main() {
  while(cin >> maxi && maxi) {
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> d[i+1];
    n += 2;
    d[0] = d[n-1] = 0;
    fill(vis, vis+n, false);
    rec(0);
    bool res = true;
    for(int i = 0; i < n; ++i) {
      if(vis[i]) {
	fill(vis2, vis2+n, false);
	if(!rec2(i)) {
	  res = false;
	  break;
	}
      }
    }
    if(res) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

const ll INF = 1LL << 50;

int a[2000], b[2000];
ll c[2000], dist[1000];
int N, M;

int main() {
    cin >> N >> M;
    REP(i, M) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--; c[i] *= -1;
    }
    REP(i, N) dist[i] = INF;
    dist[0] = 0;

    REP(i, N - 1) REP(j, M) {
        if (dist[a[j]] == INF) continue;

        if (dist[b[j]] > dist[a[j]] + c[j])
            dist[b[j]] = dist[a[j]] + c[j];
    }
    ll ans = dist[N - 1];

    REP(i, N - 1) REP(j, M) {
        if (dist[a[j]] == INF) continue;

        if (dist[b[j]] > dist[a[j]] + c[j])
            dist[b[j]] = dist[a[j]] + c[j];
    }

    if (ans != dist[N - 1]) cout << "inf" << endl;
    else cout << -ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string S; cin >> S;
  rep(i,S.length()) cout << 'x';
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 100010
int n,q;
//int p[N],d[N];
class UnionFind{
private:
    int p[N],d[N];
    int Root(int x){
	int a=x,s=0;
	while(a!=p[a])s+=d[a],a=p[a];
	while(x!=a){int t=p[x];p[x]=a,s-=d[x],d[x]+=s,x=t;}
	return a;
    }
public:
    void Init(){
	lol(i,n)p[i]=i,d[i]=0;
    }
    void Unite(int a,int b,int c){
	int ra=Root(a),rb=Root(b);
	p[ra]=rb;
	d[ra]=c+d[b]-d[a];
    }
    int Query(int a,int b){
	int ra=Root(a),rb=Root(b);
	if(ra!=rb)return mod;
	return d[a]-d[b];
    }
};
int main(){
    cin>>n>>q;
    UnionFind uf;uf.Init();
    while(q--){
	int c;cin>>c;
	if(c==0){
	    int x,y,z;cin>>x>>y>>z;
	    uf.Unite(x,y,z);
	}
	if(c==1){
	    int x,y;cin>>x>>y;
	    int res=uf.Query(x,y);
	    if(res==mod)cout<<"?"<<endl;
	    else cout<<res<<endl;
	}
    }
    return 0;
}



Measured memory_bytes: 3868
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int s[N],a[N];
pair<int ,int >p[N];
int gcd(int a,int b)
{
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	int ans=a[0];
	for(int i=0;i<n;i++)ans=gcd(ans,a[i]);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h> 
 
int main() {
  int n,x;
  int b,i,j,k,a;
 
  while(1) {
    scanf("%d %d",&n,&x);   
    b = 0;
    if( n == 0 && x == 0){
      break;
    }
    for(k = 1; k <= n ; k++) {
 
 
      for(j = 1; j <= n ; j++) {
 
    for(i = 1; i <= n; i++) {
       
      if(i == j || j == k || i ==k) {
         
      }else{
        a = i + j + k;
        if(a == x) {
          
          b += 1;
  
        }
      }
       
    }//i
     
      }//j
 
    }//k
    printf("%d\n",b/6);
  }
 
 
  return 0;
}  


Measured memory_bytes: 2108
#https://abc010.contest.atcoder.jp/tasks/abc010_4
#http://kmjp.hatenablog.jp/entry/2014/06/08/0900

#よくわからない最大フロー用のdfs---------------------------------

num=201 #今回のnの最大値100*2+1

def dfs(cur):
	global vis
	global EE
	vis[cur] = 1

	if cur==num:
		return 1

	for i in range(num+1):
		if vis[i]==0 and EE[cur][i]>0 and dfs(i) > 0:
			EE[cur][i] -= 1
			EE[i][cur] += 1
			return 1
	return 0
#--------------------------------------------------------------

#今回の問題分（インプット～隣接リストの作成）------------------

n=int(input())
s=[]
ss=[]
for i in range(n):
    s.append([int(i) for i in input().split()])
for i in range(n):
    ss.append([int(i) for i in input().split()])
#s.sort(key=lambda x:(x[0],x[1]))
#ss.sort(key=lambda x:(x[0],x[1]))

pair=[]
for i in range(len(s)):
    right=[]
    for j in range(n):    
        if s[j][0]<ss[i][0] and s[j][1]<ss[i][1]:
            right.append(j)
    pair.append(right)
#pair.sort(key=lambda x:len(x))

#print(pair)

#------------------------------------------------------------

#BFSにぶち込む用のグラフ作成---------------------------------

EE = [[0 for x in range(num+1)] for y in range(num+11)]
vis = [0] * (num+1)

for i in range(len(pair)): #1から最大100　始点s（番号0）から青い点への辺
	EE[0][i+1] = 1
#	EE[i+1][0] = 1

for i in range(n): #101から最大200　赤い点から終点t（番号201）への辺
	EE[i+101][num] = 1

for i in range(len(pair)): #青い点（番号1～100に振り直し）から　赤い点（番号101～200）への辺
    for j in range(len(pair[i])):
        node1, node2 = i+1,pair[i][j]+101
#        EE[node1][node2] = EE[node2][node1] = 1　なんでこれダメなんだろう
        EE[node1][node2] = 1

#風呂～～--------------------------------------------------

flow=0
while 1:
    for i in range(0, num+1):
        vis[i] = 0
    if dfs(0) == 0:
        break
    flow += 1

print (flow)

#----------------------------------------------------------


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

int main() {
    int N;
    cin >> N;
    vector<int>B(N-1);
    for (int i = 0; i < N-1; ++i) {
        cin >> B[i];
    }
    vector<int>A(N);
    A[0] = B[0];
    for (int i = 1; i < N - 1; ++i) {
        A[i] = min(B[i-1], B[i]);
    }
    A[N-1] = B[N-2];
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += A[i];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
N = input()
A = list(map(int,input().split()))
mina = 0

while True:
    mina = min(A)
    minain = A.index(mina)
    for i in range(len(A)):
        A[i] = A[i] % mina
    if A.count(0) == len(A):
        break
    else:
        A[minain] = mina
        A = list(filter(lambda s:s != 0, A))
        
print(mina)
    

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
    string s;
    cin >> s;
    int for_num = s.size() / 2;
    int cnt = 0;

    rep(i, for_num){
        if(s.at(i) != s.at(s.size()-1-i)){
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256