akhauriyash/Code-Regression huggingface dataset:
// 2015/03/09 Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		int i[1000], p[1000], q[1000], r[1000];
		for(int j=0; j<n; j++){
			cin >> i[j] >> p[j] >> q[j] >> r[j];
		}

		int P, Q, R, C;
		cin >> P >> Q >> R >> C;

		bool flg = false;

		for(int j=0; j<n; j++){
			if(p[j]<=P && q[j]<=Q && r[j]<=R && 4*p[j]+9*q[j]+4*r[j]<=C){
				cout << i[j] << endl;
				flg = true;
			}
		}

		if(!flg){
			cout << "NA" << endl;
		}
	}

	return 0;
}

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

#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl

typedef long long ll;

using namespace std;

int A[3][3];
bool ans[3][3];
int N;

void solve() {
    
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
            ans[i][j] = false;
        }
    } 
    cin >> N;
    vector<int> B(N);
    REP(i, N) cin >> B[i];

    for (int b = 0; b < N; b++) {
        int t = B[b];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (t == A[i][j]) ans[i][j] = true;
            }
        }
    }

    bool flag = false;
    for (int i = 0; i < 3; i++) {
        bool tmp = true;
        for (int j = 0; j < 3; j++) {
            if (!ans[i][j]) {
                tmp = false;
                break;
            }
        }
        if (tmp) {
            flag = true;
        }
    }
    for (int i = 0; i < 3; i++) {
        bool tmp = true;
        for (int j = 0; j < 3; j++) {
            if (!ans[j][i]) {
                tmp = false;
                break;
            }
        }
        if (tmp) {
            flag = true;
        }
    }

    if (ans[0][0] && ans[1][1] && ans[2][2]) flag = true;
    if (ans[0][2] && ans[1][1] && ans[2][0]) flag = true;

    if (flag) print("Yes");
    else print("No");

}

signed main() {
    solve();
}


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

def gcd(x,y):
  while y:
    x, y = y, x%y
  return x

ll, lr = [0]*n, [0]*n
ll[0], lr[n-1] = a[0], a[n-1]
for i in range(1,n):
  ll[i] = gcd(ll[i-1], a[i])
  lr[n-i-1] = gcd(lr[n-i], a[n-i-1])

print(max(ll[n-2], lr[1], *[gcd(l,r) for l,r in zip(ll[:n-2], lr[2:])]))

Measured memory_bytes: 14076
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n,q;
	for(;cin>>n>>q;){
		if(n==0)break;
		int m,t;vector<int> k(101);k[0]=q-1;
		for(;n--;){
			cin>>m;
			for(;m--;k[t]++)cin>>t;
		}
		int v=0,r=0;
		for(int i=0;i<101;i++)
			if(k[i]>v)v=k[i],r=i;
		cout<<r<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second

void solve()
{
    int k, a, b;
    cin>>k>>a>>b;
    int tmp=a/k, tmp1=b/k;
    if(tmp<tmp1 || a%k==0)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;
}

int32_t main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--)
        solve();
	return 0;
}

Measured memory_bytes: 3652
#include<cstdio>

int main(void) {
	int map[100],in,i;
	for(i=0;i<100;i++) { map[i]=0; }
	while(scanf("%d",&in)!=EOF) { map[in-1]++; }
	in=0;
	for(i=0;i<100;i++) { if(in<map[i]) { in=map[i]; } }
	for(i=0;i<100;i++) { if(in==map[i]) { printf("%d\n",i+1); } }
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

map<int, int> mp;

void func(int x) {
	rep2(i, 2, x) {
		while (x%i == 0) {
			if (!mp.count(i)) mp[i] = 1;
			mp[i]++;
			x /= i;
		}
	}
}

int main() {
	const i64 MOD = 1e9 + 7;

	int n;
	cin >> n;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	rep2(i, 1, n) {
		func(i);
	}
	i64 ans = 1;
	for (auto &ite : mp) {
		ans = (ans*ite.second) % MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 1;
    rep(i, N - 1){
        if (S[i] != S[i + 1]) ans++;
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);

  for (int j = 0; j < M; j++) {
      int a, b;
      cin >> a >> b;
    for (int i = 0; i < N; i++){
        if (a==i+1||b==i+1)
        vec.at(i)++;
    }     
  }
  for (int i = 0; i < N; i++)
    cout << vec.at(i) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=998244353;
const ll mod=998244353;
signed main(){
    vector<ll>ans(0);
    ll n;cin>>n;
    if(n<=26){
        n--;
        cout<<(char)('a'+n)<<endl;
        return 0;
    }
    ll now=0;
    ll cnt=0;
    ll noww=1;
    while(now<n){
        noww*=26LL;
        now+=noww;
        cnt++;
    }
    n-=now-noww;
    n--;
    ll j=0;
    while(n||j<cnt){
        ans.pb(n%26);
        n/=26;
        j++;
    }
    reverse(all(ans));
    rep(i,cnt){
        cout<<(char)(ans[i]+'a');
        //cout<<ans[i]<<endl;
    }
    cout<<endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
typedef long long ll;
using namespace std;

ll a[100001];

int main(){
  int N;
  int count = 0;
  int count2 = 0;
  int count4 = 0;
  int tmp = 0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a[i];
    tmp = 0;
    while(a[i]%2==0){
      tmp ++;
      a[i] /=2;
    }
    if(tmp>=2){
      count4++;
    }else if(tmp == 1){
      count2++;
    }else{
      count++;
    }
  }
  //cout << count << endl;
  if(count2==0){
    if(count<=count4+1){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if(count <= count4){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }

  return 0;
}

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

enum{TRIANGLE, RIGHT, ACUTE, OBTUSE, N};

int main()
{
    vector<int> count(N, 0);
    vector<int> edge(3);
    while(cin>>edge[0]>>edge[1]>>edge[2]) {
        sort(edge.begin(), edge.end(), greater<int>());

        if(edge[0] < edge[1] + edge[2]) {
            count[TRIANGLE]++;
        } else {
            cout<<count[TRIANGLE];
            for(int i=1; i<N; i++) cout<<" "<<count[i];
            cout<<endl;
            break;
        }

        int d = edge[0]*edge[0] - edge[1]*edge[1] - edge[2]*edge[2];
        if(d == 0) {
            count[RIGHT]++;
        } else if(d < 0) {
            count[ACUTE]++;
        } else if(d > 0) {
            count[OBTUSE]++;
        }
    }
}

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

int main(){
  int N;
  cin >> N;
  vector<long int> a(N);
  for(int i=0;i<N;i++){
    cin >> a.at(i);
  }
  long int ans=0;
  for(int i=0;i<N;i++){
    ans+=a.at(i)-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef struct pp
{   char x[50];
    int t,R;
}S;
S s[105];
bool cmp(S a,S b)
{   if(a.R==b.R)return strcmp(a.x,b.x);
    return a.R>b.R;
}
int main()
{   int i,j,T,n,k,q;int x[100800],a[100800]={0};
    scanf("%d%d%d",&n,&k,&q);
    for(i=0;i<q;i++)
    {   scanf("%d",&x[i]);
        a[x[i]-1]++;
    }
    for(i=0;i<n;i++)
    {   if(a[i]+k-q<=0)printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}



Measured memory_bytes: 1280
#include<cstdio>
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>

#define MAX 24
using namespace std;
typedef pair<int,double> Rec;

bool LessRec(const Rec &a, const Rec &b){
	return a.second < b.second;
}

ostream &operator<<(ostream &os, const Rec t){
	printf("%d %.2f", t.first, t.second);
	//os << t.first << ' ' << setprecision(2) << t.second;
	return os;
}

int main()
{
	vector< pair<int, double> > vPlayers;

	for(int i=0;i<MAX;++i)
	{
		int t;
		double time;
		cin >> t >> time;
		vPlayers.push_back( make_pair(t,time) );
	}

	sort( vPlayers.begin(), vPlayers.begin() + 8, LessRec );
	cout << vPlayers[0] << '\n' << vPlayers[1] << '\n';
	sort( vPlayers.begin() + 8, vPlayers.begin() + 16, LessRec );
	cout << vPlayers[8] << '\n' << vPlayers[9] << '\n';
	sort( vPlayers.begin() + 16, vPlayers.end(), LessRec );
	cout << vPlayers[16] << '\n' << vPlayers[17] << '\n';

	vPlayers.erase( vPlayers.begin() );
	vPlayers.erase( vPlayers.begin() );
	vPlayers.erase( vPlayers.begin()+6 );
	vPlayers.erase( vPlayers.begin()+6 );
	vPlayers.erase( vPlayers.begin()+12 );
	vPlayers.erase( vPlayers.begin()+12 );

	sort( vPlayers.begin(), vPlayers.end(), LessRec );

	cout << vPlayers[0] << '\n' << vPlayers[1] << '\n';	

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
vector<int> adj[MAXN];
int ans[MAXN];

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i){
		int u, v;
		cin >> u >> v;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	queue<int> q;
	q.push(1);
	while (q.size()){
		int u = q.front();
		q.pop();
		for (int v : adj[u]){
			if (!ans[v]){
				ans[v] = u;
				q.push(v);
			}
		}
	}
	for (int i = 1; i <= n; ++i){
		if (!ans[i]){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes\n";
	for (int i = 2; i <= n; ++i){
		cout << ans[i] << "\n";
	}
	return 0;
}



Measured memory_bytes: 10436
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double

using namespace std;

ll lol[10] = {0};

bool check(ll n){
    while(n>0){
        ll x = n%10;
        n /= 10;
        if(lol[x]) return 0;
    }
    return 1;
}

int main()
{
    fastio;

    ll n, k;
    cin >> n >> k;

    vector<ll> a(k);

    for(ll i=0;i<k;i++){
        cin >> a[i];
        lol[a[i]]++;
    }

    while(1){
        if(check(n)){
            cout << n;
            break;
        }
        n++;
    }

    return 0;
}

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

int main(){
  int n;cin>>n;
  vector<int> x(n);
  for(int i=0;i<n;i++)cin>>x[i];
  
  int ans=1000000;
  for(int i=0;i<101;i++){
    int sum=0;
    for(int k=0;k<n;k++)sum+=(i-x[k])*(i-x[k]);
    ans=min(ans,sum);
  }
  
  cout<<ans<<endl;
  
}
                                       

Measured memory_bytes: 256
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n=int(input())
dp=[0]*1020
dp[1]=1
dp[2]=2
mod=10**9+7
from math import sqrt
def eratosu(n):
  if not isinstance(n,int):
    raise TypeError("nがint型になってねえぞ")
  if n<2:
    raise ValueError('nが2よりちっちぇえぞ')
  prime = []
  limit = sqrt(n)
  data = [i+1 for i in range(1, n)]  #2,3,4,...,n
  while True:
    p = data[0]
    if limit <= p:
        return prime + data
    prime.append(p)
    data = [e  for e in data if e % p != 0]
def bunkai(n):
    if n==2: return [[2,1]]
    if n==3: return [[3,1]]
    ans=[]
    temp=n
    #そんな早くしなくてよかったり、何回もするわけじゃないなら、
    #for i in range(2,int(sqrt(n))+1): とかで
    primelist=eratosu( int(sqrt(n)) )
    for i in primelist:
        if temp % i ==0:
            ji=0
            while temp%i==0:
                ji+=1
                temp//=i
            ans.append([i,ji])
    if ans==[]:return([[n,1]])  #素数のとき
    if temp!=1:
        ans.append([temp,1])  #4*5882353とか
    return ans

NOW=defaultdict(int)
for i in range(2,n+1):
    l=bunkai(i)
    # print(l)
    for info in l:
        NOW[info[0]]+= info[1]

qq=list(NOW.values())
ans=1
for i in qq:
    ans*=(i+1) 
    ans%=mod
print(ans)


Measured memory_bytes: 10264
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	p := make([]int, n)
	for i := range p {
		p[i] = scanInt()
	}

	ans := 0
	for i := range p {
		if p[i] == i+1 {
			ans++
			if i+1 < len(p) {
				p[i+1] = p[i]
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3108
//9:55
//10:15
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#define SQR(X) ((X)*(X))

using namespace std;

map<int,int> dp;
int x[24],y[24],r[24],c[24];

int rem(int n,int s){
  if(dp.find(s)!=dp.end())return dp[s];
  bool under[24]={};
  for(int i=0;i<n;i++){
    if((s&(1<<i))==0){
      for(int j=i+1;j<n;j++){
	if(SQR(x[i]-x[j])+SQR(y[i]-y[j])<SQR(r[i]+r[j])){
	  under[j]=true;
	}
      }
    }
  }
  int mr=0;
  for(int i=0;i<n;i++){
    if(((s&(1<<i))==0)&&!under[i]){
      for(int j=i+1;j<n;j++){
	if(((s&(1<<j))==0)&&!under[j]&&c[i]==c[j]){
	  mr=max(mr,rem(n,s|(1<<i)|(1<<j))+2);
	}
      }
    }
  }
  dp[s]=mr;
  return mr;
}

int main(){
  for(int n;cin>>n,n;){
    dp.clear();
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i]>>r[i]>>c[i];
    }
    cout<<rem(n,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 32000
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

struct UnionFind {
    vi d;
    UnionFind(int n = 0): d(n, -1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) {return -d[find(x)];}
};

int fri[100005];
vi to[100005];

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        fri[a]++;
        fri[b]++;
        uf.unite(a, b);
    }
    rep(i, k) {
        int c, d;
        cin >> c >> d;
        --c, --d;
        to[c].push_back(d);
        to[d].push_back(c);
    }
    rep(i, n) {
        int ans = uf.size(i) - 1 - fri[i];
        for(int b : to[i]) {
            if(uf.same(i, b)) --ans;
        }
        printf("%d%c", ans, i == n-1 ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define TO_INT(i) ((i) - 0x30)

int main(void)
{
    string S;

    cin >> S;

    int N = S.length() - 1;

    for (int i = 0; i < 1 << N; i++)
    {
        int ope[3] = { 0,0,0 };
        for (int j = 0; j < 3; j++)
        {
            if (!(i & (1 << j)))
                continue;
            ope[j] = 1;
        }

        int sum = TO_INT(S[0]);
        string output = to_string(sum);
        for (int i = 1,j = 0; i <= 3; i++,j++)
        {
            if (ope[j] == 0)
            {
                sum += TO_INT(S[i]);
                output += "+" + to_string(TO_INT(S[i]));
            }
            else
            {
                sum -= TO_INT(S[i]);
                output += "-" + to_string(TO_INT(S[i]));
            }
        }
        if (sum == 7)
        {
            cout << output  << "=7"<< endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.9lf", sqrt(d));
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int chain(int x,int y);

char mas[8][8];

int main(){
  int n;
  int x,y;
  cin >> n;
  for(int p = 0;p < n;p++){

    for(int i = 0;i < 8;i++){
      for(int j = 0;j < 8;j++){
	cin >> mas[i][j];
      }
    }
    
    cin >> x >> y;
    x--;y--;
    chain(x,y);
    cout << "Data" << " " << p + 1 << ":" << endl;
    for(int i = 0;i < 8;i++){
      for(int j = 0;j < 8;j++){
	cout << mas[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

int chain(int x,int y){
  mas[y][x] = '0';
  for(int i = 1;i <= 3;i++){
    if(x + i <= 7){
      if(mas[y][x + i] == '1'){
	chain(x + i,y);
      }
    }
    if(y + i <= 7){
      if(mas[y + i][x] == '1'){
	chain(x,y + i);
      }
    }
    if(x - i >= 0){
      if(mas[y][x - i] == '1'){
	chain(x - i,y);
      }
    }
    if(y - i >= 0){
      if(mas[y - i][x] == '1'){
	chain(x,y - i);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

vector<int> prime;
int psize;

void calcPrime(){
    prime.pb(2);
    prime.pb(3);
    psize = 2;
    bool flag;
    for(int i = 5; i <= 100003; i++){
        flag = true;
        for(int j = 0; j < psize && flag; j++){
            if(i%prime[j] == 0){
                flag = false;
            }
        }
        if(flag){
            prime.pb(i);
            psize++;
        }
    }
}
int main(){

    calcPrime();
    int x;
    cin >> x;
    for(int i = 0; i < psize; i++){
        if(prime[i] >= x){
            cout << prime[i] << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 384
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x - 1] + b[y - 1] - c)
print(ans)


Measured memory_bytes: 18608
using System;

namespace test
{
   class program
    {
        static void Main()
        {
            while (true)
            {
                string[] str = Console.ReadLine().Split(' ');
                int x = int.Parse(str[0]);
                int y = int.Parse(str[1]);
                if (x == 0 && y == 0) break;
                if (x > y) Console.WriteLine("{0} {1}", y, x);
                if (x < y) Console.WriteLine("{0} {1}", x, y);
                if (x == y) Console.WriteLine("{0} {1}", x, y);
            }
        }
    }
}

Measured memory_bytes: 9384
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n;
double v[60];

double ans;

int main(void){
	cin>>n;
	for (int i = 0; i < n; i++) cin>>v[i];

	sort(v, v + n);
	ll sum = 0;
	ll pow = 1;
	for (int i = 0; i < n; i++) {
		if (i > 1) pow *= 2;
		sum += pow * v[i];
	}

	printf("%.8f\n", (double)sum / (2 * pow));

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
long long f(long long k) {
	return k * k*k;
}
int main() {
	int n, k; cin >> n >> k;
	int p = k % 2;
	if (p)cout << f(n / k);
	else cout << f(n / k) + f((n + k / 2) / k);
	cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long b, a, n, d,rem, ans;
    cin>> n>> b>> a;
    if(n>a+b)
    {
        d= n/(a+b);
        rem=n%(a+b);
        if(rem>=b)
            ans= (d+1)*b;
            else
                ans= d*b+ rem;


    }
    else if(n<=a+b)
    {
        if(n>=b)
            ans=b;
        else
            ans= n;
    }
    cout<< ans<< endl;

    return 0;
}



Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    
    l = []
    l.append(n//k)

    if k % 2 == 0:
        l.append((n+k//2)//k)

    ans = 0
    for i in l:
        ans += i**3

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

ll dp[101][100010];

int main(){
   int n,w;
   cin >> n >> w;
   vector<ll> val(n);
   vector<ll> wight(n);
   rep(i,n){
      ll x,y;
      cin >> x >> y;
      wight[i] = x;
      val[i] = y;
   }
   rep(i,n+1) rep(j,100001){
      if (i == 0) continue;
      if (0 <= j - wight[i-1]) dp[i][j] = max(dp[i-1][j],dp[i-1][j-wight[i-1]] + val[i-1]);
      else dp[i][j] = dp[i-1][j];
   }
   //rep(i,n+1){
   //   rep(j,9){
   //      cout << dp[i][j] << " ";
   //   }
   //   cout << endl;
   //}
   cout << dp[n][w] << endl;
   


  
  return 0;
}


Measured memory_bytes: 81768
// $%D%$.$%M%$.$%Y%$
// $%h%$:$%m%$:$%s%$

#pragma GCC optimize("O3")

#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 IOS ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define ld long double
#define rep(i,a,n) for (int i=(int)(a);i<(int)(n);i++)
#define per(i,a,n) for (int i=(int)(n-1);i>=(int)(a);i--)
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define fi first
#define se second


const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};


template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int main() {
    IOS;
    int n;
    set<pii> s1, s2;
    cin >> n;
    ll ans = 1ll * (n - 2) * (n - 2);
    s1.insert({n, n});
    s2.insert({n, n});

    int q;
    cin >> q;
    while(q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            auto cur = *s2.upper_bound({x, 0});
            //cout << cur.second << '\n';
            ans -= cur.second - 2;
            s1.insert({cur.second - 1, x});
        }
        else {
            auto cur = *s1.upper_bound({x, 0});
            ans -= cur.second - 2;
            s2.insert({cur.second - 1, x});
        }
    }
    cout << ans << '\n';
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<int> ans(n);
    rep(i ,n) { cin >> a[i]; ans[i] = a[i]; }
    int q;cin >> q;
    rep(i ,q){
        int b , m , e;
        cin >> b >> m >> e;
        rep(j , e - b){
            int pos = b + (( j + ( e - m )) % ( e - b ));
            ans[pos] = a[b + j];
        }
        rep(j ,n){
            a[j] = ans[j];
        }
    }
    rep(i ,n - 1) cout << ans[i] << " ";
    cout << ans[n - 1] << endl;
}


Measured memory_bytes: 3116
#include<stdio.h>
#include<string.h>
int main(void){
  char moji[150];
  int i,j,count;
  scanf("%s",moji);
  for(i=0,j=strlen(moji)-1;i<j;i++,j--){
    if(moji[i] != moji[j]){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
typedef long long ll;
#include <bits/stdc++.h>

using namespace std;

ll mod = 1000000007;

template<class Type> inline bool chmax(Type& a, Type b) { if (a < b) { a = b; return 1; } return 0; }
template<class Type> inline bool chmin(Type& a, Type b) { if (a > b) { a = b; return 1; } return 0; }

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n)
	{
		if (n & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y)
	{
		swap(x, y);
	}

	while (0 < y)
	{
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
bool isPrime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2)
	{
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++)
	{
		if (isPrime[i])
		{
			Type j = i + i;
			while (j <= n)
			{
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binarySearch(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok))
	{
		int mid = (ng + ok) / 2;
		if (binarySearchJudge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	string s;
	cin >> s;
	string str = "CODEFESTIVAL2016";
	int count = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != str[i]) count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair<int,int>
#define mp make_pair
using namespace std;
int n;
int id[1005];
int ok[1005];
int a[1005][1005];
int use[1005][1005];
map < int , int > take[1005];
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<n; j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=1; i<=n; i++)
    {
        id[i] = 1;
    }
    int maxx = 0;
    map < ii , int > my;
    vector < ii > v;
    for(int i=1; i<=n; i++)
    {
        my[mp(i,a[i][1])]++;
        my[mp(a[i][1],i)]++;


        if(my[mp(i,a[i][1])] > 1)
        {
            if(!use[i][a[i][1]])
            {
                use[i][a[i][1]] = 1;
                use[a[i][1]][i]= 1;
          v.push_back(mp(i,a[i][1]));
            }
        }
    }
    int ans = 0;
    while(v.size() > 0)
    {
        vector < ii > v2;
        for(int i=0; i<v.size(); i++)
        {
            ii r = v[i];
            id[r.fr]++;
            id[r.sc]++;
            int X = id[r.fr];
            if(X < n)
            {
                my[mp(r.fr,a[r.fr][X])]++;
                my[mp(a[r.fr][X],r.fr)]++;


                if(my[mp(r.fr,a[r.fr][X])] > 1)
                {
                    if(!use[r.fr][a[r.fr][X]])
                    {
                        use[r.fr][a[r.fr][X]] = 1;
                        use[a[r.fr][X]][r.fr] = 1;
                        v2.push_back(mp(r.fr,a[r.fr][X]));
                    }

                }
            }

            swap(r.fr,r.sc);
            X = id[r.fr];
            if(X < n)
            {
                my[mp(r.fr,a[r.fr][X])]++;
                my[mp(a[r.fr][X],r.fr)]++;

                if(my[mp(r.fr,a[r.fr][X])] > 1)
                {
                     if(!use[r.fr][a[r.fr][X]])
                    {
                        use[r.fr][a[r.fr][X]] = 1;
                        use[a[r.fr][X]][r.fr] = 1;
                        v2.push_back(mp(r.fr,a[r.fr][X]));
                    }
                }
            }
        }
        v.clear();
        v = v2;
        ans++;
    }

    for(int i=1; i<=n; i++)
    {
        if(id[i]!= n)
            ans = -1;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 70784
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


int main(){
    int N; cin >> N;
    vector<long long> a(N);
    long long sum = 0,odd = 0,zer = 0;
    long long mn = MM;
    for (int i = 0; i < N; i++){
        cin >> a[i];
        mn = min(mn,abs(a[i]));
        if (a[i] < 0) odd++;
        sum += abs(a[i]);
        if (a[i] == 0) zer = 1;
    }

    if (odd % 2 == 0 || zer){
        cout << sum << endl;
    } else {
        cout << sum - 2*mn << endl;
    }

}

Measured memory_bytes: 1024
// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 100005, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n,a[N][3],dp[N][3];

int calc(int i,int j) {
    if(i==n)
        return 0;
    int &r = dp[i][j];
    if(r!=-1)
        return r;
    for(int k=0; k<3; k++)
        if(k!=j)
            r = max(r, calc(i+1,k) + a[i][k]);
    return r;
}

int main() {
    scanf("%d",&n);
    for(int i=0; i<n; i++)
        scanf("%d%d%d",&a[i][0], &a[i][1], &a[i][2]);
    int ans = 0;
    for(int i=0; i<3; i++) {
        memset(dp,-1,sizeof dp);
        ans = max(ans, calc(0,i));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 10368
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N;
int p[MAXN], pn;
bool np[MAXN];

inline void init(int n) {
	register int i, j;
	np[1] = 1; p[0] = p[n] = 1;
	for(i = 2; i <= n; ++i) {
		if(!np[i])
			p[++pn] = i;
		for(j = 1; j <= pn && i * p[j] <= n; ++j) {
			np[i * p[j]] = 1;
			if(i % p[j] == 0)
				break;
		}
	}
}

int main() {
	register int i, j; init(1e4);
	scanf("%d", &N);
	for(i = 0; i < N; ++i) {
		for(j = 0; j < N; ++j) {
			int s = (i + j) >> 1, d = (i - j) >> 1;
			if((i ^ j) & 1) printf("%lld ", 1ll * p[s + 1] * p[d + N + (N >> 1) + 1]);
			else printf("%lld ", 1ll * p[s + 1] * p[s] * p[d + N + (N >> 1) + 1] * p[d + N + (N >> 1)] + 1);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <sstream>
#include <vector>
#define INF 0x3f3f3f3f
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 10005;
const double pi = acos(-1.0);

string s,t;

int main()
{
    while(cin >> s)
    {
        cin >> t;
        int len = s.length();
        int flag = 0;
        for(int i = 0; i < len; i ++)
        {
            if(s[i] != t[i])
            {
                flag = 1;
                cout << "No" << endl;
                break;
            }
        }
        if(flag == 0)
            cout << "Yes" << endl;
    }
    return 0;
}



Measured memory_bytes: 3612
def main(input = STDIN)
  min, benefit = 1.0 / 0.0, -1.0 / 0.0
  input.gets.to_i.times do
    i = input.gets.to_i
    benefit = i - min if benefit < i - min
    min = i if min > i
  end
  puts benefit
end
main

Measured memory_bytes: 6100
//B - Papers, Please

#include <iostream>
#include <algorithm>

using namespace std;

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

    int a[n];

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

    bool flag = true;

    for(int i=0; i<n; i++){
        if (a[i]%2 == 0) {
            if ((a[i]%3 == 0) || (a[i]%5 == 0)){

            }else{
                flag = false;
                break;
            }
        }
    }
    
    if (flag) {
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#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 d,n;
	cin >> d >> n;
	if(n == 100){
		if(d == 0) cout << 101 << endl;
		else if(d == 1) cout << 10100 << endl;
		else if(d == 2) cout << 1010000 << endl;
	}
	else{
		if(d == 0) cout << n << endl;
		else if(d == 1) cout << n*100 << endl;
		else if(d == 2) cout << n*100*100 << endl;
	}
}

Measured memory_bytes: 3632
use proconio::input;

fn main() {
	input!(s: String);

	let mut v: String = "".to_string();
	for i in 0..s.len() {
		let c = s.chars().nth(i).unwrap();
		if  c == 'B' {
			v.pop();
		}
		else {
			v.push(c);
		}
	}
	println!("{}", v);
}



Measured memory_bytes: 2096
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int n, k; cin >> n >> k;
  vector<int> v(n);
  REP(i, n) cin >> v[i];

  int ans = 0;
  REP(i, n+1)REP(j, n+1){
    if(i + j > k || i + j > n) continue;

    int tmp = 0;
    vector<int> ng;
    for(int p=0; p<i; p++){
      tmp += v[p];
      if(v[p] < 0) ng.push_back(v[p]);
    }
    for(int p=0; p<j; p++){
      tmp += v[n-p-1];
      if(v[n-p-1] < 0) ng.push_back(v[n-p-1]);
    }

    sort(ng.begin(), ng.end());

    for(int p=0; p < k-(i+j) && p < ng.size(); p++)
      tmp -= ng[p];

    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,n,c = 0;
  cin >> h >> n;
  rep(i, n){
    cin >> c;
    h -= c;
  }
  if(h <= 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>

using namespace std;

string str[71][71];

string func(char a[71][71], bool vis[71][71], int w, int h, int p, int q)
{
  if(!vis[p][q]){
    return str[p][q];
  }
  vis[p][q] = false;
  if(p == h-1 && q == w-1){
    str[p][q] = a[p][q];
    return str[p][q];
  }

  string s = "", t = "";
  int u = p+1, v = q+1;
  if(u < h && a[u][q] >= '0' && a[u][q] <= '9'){
    s = func(a, vis, w, h, u, q);
  }
  if(v < w && a[p][v] >= '0' && a[p][v] <= '9'){
    t = func(a, vis, w, h, p, v);
  }

  if(s.size() > t.size() || (t.size() == s.size() && t < s)){
    str[p][q] = a[p][q] + s;
  } else {
    str[p][q] = a[p][q] + t;
  }

  return str[p][q];
}

bool compareTo(string s1, string s2)
{
  int p, q;
  string str1, str2;
  p = q = 0;

  while(p < s1.size() && s1[p] == '0'){
    p++;
  }
  while(q < s2.size() && s2[q] == '0'){
    q++;
  }
  str1 = s1.substr(p);
  str2 = s2.substr(q);

  if(str1.size() < str2.size()){
    return true;
  } else if(str1.size() > str2.size()){
    return false;
  }

  return ((s1 > s2)? false : true);
}

int main()
{
  int w, h;
  char a[71][71];
  bool vis[71][71];

  while(cin >> w >> h && (w+h)){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	cin >> a[i][j];
      }
    }
    fill(&vis[0][0], &vis[70][70], true);
    fill(&str[0][0], &str[70][70], "");
    string s = "";

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(a[i][j] >= '0' && a[i][j] <= '9' && vis[i][j]){
	  string t = func(a, vis, w, h, i, j);
	  if(s.size() < t.size() || (s.size() == t.size() && s < t)){
	    s = t;
	  }	  
	}
      }
    }
    
    s = "";
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(!vis[i][j] && compareTo(s, str[i][j])){
	  s = str[i][j];
	}
      }
    }
    
    int p = 0;
    while(p < s.size() && s[p] == '0'){
      p++;
    }
    
    cout << s.substr(p) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	for(int i=0;i<3;i++)
	{
		if(s[i] == '1')
			s[i]='9';
		else
			s[i]='1';
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;cin>>n;
	int arr[n];
	for(int i = 0; i< n;++i) cin>>arr[i];
	int mx = INT_MAX;
	for(int  i = 0; i< n-1; ++i){
		int ans1 = 0, ans2 = 0;
		for(int j = 0; j <=i;++j){
			ans1 += arr[j];
		}
		for(int j = i + 1; j < n; ++j){
			ans2 += arr[j];
		}
		mx = min(mx, abs(ans1 - ans2));
	}
	cout<<mx<<endl;
	return 0;
}



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

//#define PRINT_GRAPH

using namespace std;

enum MyEnum
{
	INDEX_X, INDEX_Y, INDEX_A
};

int main()
{
	int W,H,N;
	int W2 = 0, H2 = 0;
	cin >> W >> H >> N;

	vector<vector<int>> in;
	in.resize(N);

	vector<vector<bool>> test;
	int XMAX = W, YMAX = H;
	test.resize(XMAX);
	

	for (int i = 0; i < N; ++i)
	{
		int t1,t2,t3;
		cin >> t1 >> t2 >> t3;
		in.at(i).push_back(t1);
		in.at(i).push_back(t2);
		in.at(i).push_back(t3);
	}

	for (int i = 0; i < XMAX; ++i)
		for (int j = 0; j < YMAX; ++j)
			test.at(i).push_back(false);


	for (auto itr : in)
	{
		switch (itr.at(INDEX_A))
		{
		case 1:
			// x < xi
			if (W2 <= itr.at(INDEX_X))
				W2 = itr.at(INDEX_X) - W2;
			for (int x = 0; x < itr.at(INDEX_X); x++)
				for (int y = 0; y < YMAX; ++y)
					test.at(x).at(y) = true;
			break;
		case 2:
			// x > xi
			if (itr.at(INDEX_X) <= W)
				W = itr.at(INDEX_X);

			for (int x = itr.at(INDEX_X); x < XMAX; x++)
				for (int y = 0; y < YMAX; ++y)
					test.at(x).at(y) = true;

			break;
		case 3:
			// y < yi
			if (H2 <= itr.at(INDEX_Y))
				H2 = itr.at(INDEX_Y) - H2;

			for (int x = 0; x < XMAX; x++)
				for (int y = 0; y < itr.at(INDEX_Y); ++y)
					test.at(x).at(y) = true;
			break;
		case 4:
			// y > yi
			if (itr.at(INDEX_Y) <= H)
				H = itr.at(INDEX_Y);

			for (int x = 0; x < XMAX; x++)
				for (int y = itr.at(INDEX_Y); y < YMAX; ++y)
					test.at(x).at(y) = true;
			break;
		}
		if (W < W2) W = W2 = 0;
		if (H < H2)H = H2 = 0;
	}

	int ans = 0;

	for (int i = 0; i < XMAX; ++i)
	{
		for (int j = YMAX - 1; j >= 0 ; --j)
		{
#ifdef PRINT_GRAPH
			cout << (test.at(i).at(j));
#endif
			if (!(test.at(i).at(j)))ans++;
		}
#ifdef PRINT_GRAPH
		cout << endl;
#endif
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
char a[55][55];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
bool v[55][55];
struct s{
    int x,y,d;
};
int main() {
int n,m;
cin>>n>>m;
int bl=0;
for(int i=0;i<n;i++)
{cin>>a[i];
for(int j=0;j<m;j++)
{
if(a[i][j]=='.')
bl++;
}
}
queue
 q;
s s1;
s1.x=0;
s1.y=0;
s1.d=1;
q.push(s1);
int w=0;
while(!q.empty())
{
s t=q.front();
q.pop();
v[t.x][t.y]=1;

if(t.x==n-1&&t.y==m-1)
{

    w=t.d;
    break;
}
for(int i=0;i<4;i++)
{
    int nx=dx[i]+t.x;
    int ny=dy[i]+t.y;
    if(nx<0||nx>=n||ny<0||ny>=m||v[nx][ny]||a[nx][ny]=='#')
    continue;
    s t1;
    v[nx][ny]=1;
    t1.x=nx;
    t1.y=ny;
    t1.d=t.d+1;
    q.push(t1);
}
}
int ans=bl-w;
if(w!=0)
cout<<ans;
else cout<<-1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main(){
	double r;
	scanf("%lf", &r);
	double area, circum;
	area = r*r*M_PI;
	circum = 2*r*M_PI;
	printf("%f %f \n", area, circum);
	return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<ll> p(n);
  ll an=0;
  rep(i,n){
    cin>>p[i];
    an+=p[i];
  }

  if(n==k){
    cout << max(0ll,an) << endl;
    return 0;
  }

  vector<ll> q(n);
  ll sum=0;
  rep(i,n){
    if(p[i]>0) sum+=p[i];
    q[i]=sum;
  }

  vector<ll> r(n);
  sum=0;
  for(int i=n-1;i>=0;i--){
    if(p[i]>0) sum+=p[i];
    r[i]=sum;
  }

  vector<ll> s(n);
  rep(i,k){
    s[0]+=p[i];
  }
  for(int i=1;i+k-1<n;i++){
    s[i]=s[i-1]+p[i+k-1]-p[i-1];
  }

  ll ans=-INF;
  for(int i=1;i+k-1<n-1;i++){
    ll x=q[i-1]+max(0ll,s[i])+r[i+k];
    chmax(ans,x);
  }

  chmax(ans,s[0]+r[k]);
  chmax(ans,q[n-k-1]+s[n-k]);

  cout << ans << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const long long MOD = (long long)1e9 + 7;
long long dp[100010];
int n, k;

int main(){
    cin >> n >> k;
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        vector<long long> b(k + 1);
        b[0] = dp[0];
        for(int j = 1; j <= k; j++){
            b[j] = (b[j - 1] + dp[j]) % MOD;
        }
        for(int j = 0; j <= k; j++){
            int l = max(0, j - a);
            int r = j;
            dp[j] = b[r];
            if(l > 0) dp[j] = (dp[j] - b[l - 1] + MOD) % MOD;
        }
    }
    cout << dp[k] << endl;
    return 0;
}


Measured memory_bytes: 1916
#include<iostream>
#include<algorithm>
#include<cstdio>
int p[200001];
int a[200001]={0};
using namespace std;

int main() {
	int n,k,s=0,m=0,o;
	cin >> n >> k;
	for(int i=1;i<=n;i++) cin >> p[i];
	for(int i=1;i<=n;i++) a[i]=p[i]+a[i-1];
	for(int i=0;i<n-k+1;i++){
		s=a[i+k]-a[i];
		if(s>m){
			m=s;
			o=i;
		}
	}
	double ans = 0;
	for(int i=o;i<o+k;i++) ans+=(double)(p[i+1]+1)/2;
	printf("%.10f\n",ans);
	return 0;
}

Measured memory_bytes: 1792