akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18
const int N = 100010;//10^5+10

int main() {

	int x, y, z; cin >> x >> y >> z;

	int ans1 = 10 * x + y + z;
	int ans2 = x + 10 * y  + z;
	int ans3 = x + y + 10 * z;

	int ans = max(ans1, max(ans2, ans3));

	cout << ans << 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 k, a, b;
cin >> k;
cin >> a >> b;
for(int i = a; i <= b; ++i){
  if(i%k == 0){
    cout << "OK" << endl;
    return 0;
  } 
} 
cout << "NG" << endl;
return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
/*
 *  JUST KEEP GOING
 */
#define endl			'\n'
#define ll				long long
#define all(v)			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define For(i,s)        for(auto i:s)
#define Forr(i,s)        for(auto &i:s)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define vi				vector <int>
#define vl				vector <ll>
#define ii				pair <int,int>
#define vii				vector <ii>
#define vll				vector <pair<ll,ll>>
#define PI				double PPPPPP = 3.14159265358979323846;
#define bit(mask,i) ((mask>>i)&1)
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 2000+5,mod=1e9+7,mod2=998244353,MAXN=100000+29;
void files(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int n,dp[N];
int solve(int sum){
    if(sum>n)
        return 0;
    if(sum==n)
        return 1;
    int &ret = dp[sum];
    if(~ret)
        return ret;
    ret=0;
    for (int j = 3; j <= n-sum ; ++j) {
        ret+=solve(j+sum)%mod;
        ret%=mod;
    }
    return ret;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    files();
    cin>>n;
    clr(dp,-1);
    cout<<solve(0);

}

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

count = 0
flag = 0

while(1):
    for i in range(n):
        if a[i] %2 == 1:
            flag = 1
        else:
            temp = a[i]/2
            a[i] = temp;
    if flag == 1:
        break
    else:
        count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int N,M;cin>>N>>M;
    vector<int> AC(N,0);
    vector<int> WA(N,0);

    REP(i,M){
        int p;
        string S;
        cin>>p>>S;
        if(S=="WA"){
            if(AC[p-1]!=1)WA[p-1]++;
        } else {
            if(AC[p-1]!=1)AC[p-1]=1;
        }
    }

    int ansAC=0;
    int ansWA=0;

    REP(i,N){
        if(AC[i]==1){
            ansAC++;
            ansWA+=WA[i];
        }
    }
    cout<<ansAC<<" "<<ansWA<<endl;
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

while True:
   n = int(input()) # 国民の人数
   if n == 0: break
   
   income = list(map(int, input().split()))
   avg = sum(income) // n
   
   c = 0
   for i in range(n):
      if income[i] <= avg:
         c += 1
   print(c)
   


Measured memory_bytes: 6612
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 
long long int power(long long int x,long long int y,long long int p) 
{ 
    long long int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
long long int modInverse(long long int n,long long int p) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
long long int nCrModPFermat(long long int n,long long int r,long long int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    long long int fac[n+1]; 
    fac[0] = 1; 
    for (long long int i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

int main(){
    long long int x, y, a, b, m, n, p = 1000000007;
    cin >> x >> y;

    a = 2*x-y;
    b = 2*y-x;
  
    if (a % 3 == 0 && b % 3 == 0 && a>=0 && b>= 0)
    {
        n = b/3;
        m = a/3;

        cout << nCrModPFermat(n+m, n, p);
    }
    else
    {
        cout << 0;
    }
    
	return 0;
}




Measured memory_bytes: 5504
#include <cstdio>
#include <cmath>
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
int n;
int a[N],b[N];
int ans;
int main()
{
	scanf("%d",&n);
	ans=1;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[a[i]]++;
		if (b[a[i]]==2)
			ans=ans<<1;
		if (ans>=mod)
			ans-=mod;
	}
	for (int i=1;i<=n;i++)
	{
		int cur=(n-i)-(i-1);
		if (cur<0)
			cur=-cur;
		if ((b[cur]--)==0)
			ans=0;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int n,x,t; cin >> n >> x >> t;
    cout << ((n-1)/x+1) * t << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>

int main(int argc, char** argv)
{
    int iMax=-1;
    int counter=0;
    int N;
    int H;
    std::cin >> N;
    for(int i=0;i<N;i++)
    {
        std::cin >> H;
        if(H >= iMax)
        {
            iMax=H;
            counter++;
        }
    }
    std::cout << counter;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];

Int N,M,K;
Int B,C,H,W;
Int X,Y,Z;
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}
using D=long double;

Int perform(Int x){
    return (x*(x+1))/2LL;
}

int main()
{
        string S,T;cin>>S>>T;
        Int ans=0;
        for(int i=0;i<S.length();++i){
            ans+=S[i]==T[i];
        }
        cout<<ans<<"\n";
        
        
}

Measured memory_bytes: 26956
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

ll ans=0;
string s;
int sizes;

void solve(ll alive,ll dead,int num){
  int x=s[num]-'0';
  if(num==sizes-1){
    ans+=alive*10+dead+x;
    return;
  }
  solve(0,dead+alive*10+x,num+1);
  solve(alive*10+x,dead,num+1);
}

int main(){
  cin>>s;
  sizes=s.size();
  solve(0,0,0);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
while (line = gets)
  a = line.chomp.to_f

  s = a
  even = true

  (2..10).each do |i|
    if i % 2 == 0
      a *= 2
    else
      a /= 3
    end

    s += a
  end

  printf("%.8f\n", s)
end

Measured memory_bytes: 6124
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  auto sed=[&](string s, string a, string b){
    string res;
    Int n = s.size();
    for(Int i=0;i<n;i++){
      if(i + (Int)a.size() <= n && s.substr(i, a.size()) == a) res += b, i += a.size()-1;
      else res += s[i];
    }
    return res;
  };

  while(1){
    Int N;
    cin>>N;
    if(N == 0) break;
    using P = pair<string, string>;
    vector<P> A(N);
    cin>>A;

    string from, target;
    cin>>from>>target;
    map<string, Int> D;
    queue<string> Q;
    D[from] = 0;
    Q.push(from);
    Int ans = -1;
    while(!Q.empty()){
      string s; s = Q.front(); Q.pop();
      Int cost = D[s];
      if(s.size() > target.size()) continue;
      if(s == target){ans = cost; break;}
      for(Int i=0;i<N;i++){
        string ns = sed(s, A[i].first, A[i].second);
        if(D.count(ns)) continue;
        D[ns] = cost + 1;
        Q.push(ns);
      }
    }
    cout<<ans<<endl;

  }

  return 0;
}



Measured memory_bytes: 3884
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    vc S(N);
    in(N,S);
    
    
    int t = N-1;
    int ans = 0;
    rep(s,N){
        if(S[s] == 'W'){
            while (s < t) {
                if(S[t] == 'R') {
                    swap(S[s],S[t]);
                    ans++;
                    break;
                }
                t--;
            }
        }
    }
    
    cout << ans << endl;
    
    
    
    
    

    return 0;
}


Measured memory_bytes: 3648
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

H, W, K = getNM()

if W == 1:
    print(1)
    exit()

# 左からi本目の右、左に橋がかかっている通り、両方に通ってない通り
bridge_right = [0] * W
bridge_left = [0] * W
not_bridge = [0] * W

for bit in range(1 << (W - 1)):
    flag = True
    for i in range(1, (W - 1)):
        if bit & (1 << i) and bit & (1 << (i - 1)):
            flag = False
    if flag:
        for i in range(W):
            if i == 0:
                if bit & (1 << i):
                    bridge_right[i] += 1
                else:
                    not_bridge[i] += 1
            elif i == W - 1:
                if bit & (1 << (i - 1)):
                    bridge_left[i] += 1
                else:
                    not_bridge[i] += 1
            else:
                if bit & (1 << i):
                    bridge_right[i] += 1
                elif bit & (1 << (i - 1)):
                    bridge_left[i] += 1
                else:
                    not_bridge[i] += 1

dp = [[0] * W for i in range(H + 1)]

dp[0][0] = 1
for i in range(1, W):
    dp[0][i] = 0

# まっすぐ降りて来た場合、右から降りてきた場合、左から降りてきた場合
for i in range(1, H + 1):
    for j in range(W):
        dp[i][j] += dp[i - 1][j] * not_bridge[j]
        if j == 0:
            dp[i][j + 1] += dp[i - 1][j] * bridge_right[j]
        elif j == W - 1:
            dp[i][j - 1] += dp[i - 1][j] * bridge_left[j]
        else:
            dp[i][j + 1] += dp[i - 1][j] * bridge_right[j]
            dp[i][j - 1] += dp[i - 1][j] * bridge_left[j]

print(dp[-1][K - 1] % mod)

Measured memory_bytes: 83296
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
int main() {
  int n, m;
  cin >> n >> m;
  char arr[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  ll dp[n][m];
  dp[0][0] = 0;
  bool f1 = true, f2 = true;
  for (int i = 1; i < n; i++) {
    if (arr[i][0] == '#' || !f1) {
      f1 = false;
      dp[i][0] = 0;
    } else
      dp[i][0] = 1;
  }
  for (int i = 1; i < m; i++) {
    if (arr[0][i] == '#' || !f2) {
      dp[0][i] = 0;
      f2 = false;
    } else
      dp[0][i] = 1;
  }

  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (arr[i][j] == '.')
        dp[i][j] = (dp[i - 1][j] %MOD + dp[i][j - 1] %MOD) %MOD;
      else
        dp[i][j] = 0;
    }
  }
  cout << dp[n - 1][m - 1] % MOD;
  return 0;
}

Measured memory_bytes: 9088
#include <iostream>

int main(void)
{
int input;

std::cin >> input;

int h;
int m;
int s;

h = input / 3600;
input = input % 3600;
m = input / 60;
input = input % 60;
s = input;

std::cout << h << ":" << m << ":" << s << std::endl;

return 0;
}

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

using namespace std;

const int MAX_N = 100, MAX_W = 10000;
int N, W;
int dp[MAX_N + 1][MAX_W + 1];
int w[MAX_N], v[MAX_N];

void solve() {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }
        }
    }
    printf("%d\n", dp[N][W]);
}

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) {
        cin >> v[i] >> w[i];
    }
    solve();
}


Measured memory_bytes: 7064
#include<iostream>
#include<math.h>

using namespace std;

int main(){

  int prime[1000000];

  for(int i = 0; i < 1000000; i++) prime[i] = 1;

  prime[0] = 0;
  prime[1] = 0;

  for(int i = 2; i < sqrt(1000000); i++){
    if(prime[i] == 1) for(int j = i*2; j < 1000000; j+=i) prime[j] = 0;
  }


  while(1){

    int in;

    cin >> in;
    if(in == 0) break;
    int out = 0, sum = 0;
    for(int i = 0; out < in; i++){
      if(prime[i] == 1){
	out++;
	sum += i;
      }

    }

    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i, x) for(int i = 1; i <= (int)(x); i++)
#define UNIQUE(v) v..erase( unique(v.begin(), v.end()), v.end() );
#define Size(x) ((int)(x).size())
using namespace std;

int main(){
	int n;
	while(cin >> n){
		int cnt = 0;
		rep(a, 10){
			rep(b, 10){
				rep(c, 10){
					rep(d, 10){
						if(a + b + c + d == n) cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}

	return 0;
}



Measured memory_bytes: 3048
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int):
    ans = INF
    for a in range(1,N):
        b = N-a
        ans = min(
            ans, 
            sum(map(int, list(str(a))))
            +sum(map(int, list(str(b))))
        )
    
    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c, i, ans;
    cin >> a >> b >> c;
    ans = 0;
    for(i=a; i<=b; i++)
    {
        if(c % i == 0)
            ans++;
    }
    cout << ans << endl;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
typedef vector<long long> vll, vLL;

bool check(const string& s,const string& t){
	int n = s.size();
	int m = t.size();
	for(int i=0;i<=n-m;i++){
		bool ok = true;
		REP(j,m){
			if(s[i+j]!='?' && s[i+j]!=t[j])ok=false;
		}
		if(ok)return true;
	}
	return false;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	int n = s.size();
	ll ans = 0;
	for(int mask = 0;mask < (1<<(n-1));mask++){
		ll sum = 0;
		ll tmp = 0;
	//cout << "mask=" << mask << endl;
		for(int i=0;i<n-1;i++){
			tmp = tmp * 10 + (s[i]-'0');
			if(mask & (1 << i)){
				// '+'をiとi+1の間に入れる
//	cout << "tmp=" << tmp << endl;
				sum += tmp;
				tmp = 0;
			}
		}
		tmp = tmp * 10 + (s[n-1]-'0');
//	cout << "tmp=" << tmp << endl;
		sum += tmp;
		tmp = 0;
//	cout << "sum=" << sum << endl;
		ans += sum;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
from decimal import Decimal

N, *A = map(Decimal, open(0).read().split())
N = int(N)

d = {}
for a in A:
    a = int(a * (10 ** 9))
    if a == 0:
        t = (0, 0)
    else:
        x = -9
        while a % 2 == 0:
            x += 1
            a //= 2
        y = -9
        while a % 5 == 0:
            y += 1
            a //= 5
        t = (x, y)
    d.setdefault(t, 0)
    d[t] += 1


result = 0
xs = list(d.keys())
for i in range(len(xs)):
    x, y = xs[i]
    t = d[xs[i]]
    if x >= 0 and y >= 0:
        result += t * (t - 1) // 2
    for j in range(i + 1, len(xs)):
        m, n = xs[j]
        if x + m >= 0 and y + n >= 0:
            result += t * d[xs[j]]
print(result)


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
vector<int> u[101];
int d[101];
int f = 0;

void solve(int i, int m, map<int, int> loopU, map<int, int> loopD) {
  if(f) return;
  if(m == 0) {
    if(loopD[i]) {
      f = 1;
      return;
    }
    loopD[i] = 1;
    if(d[i]) solve(d[i], !m, loopU, loopD);
  }else {
    if(loopU[i]) {
      f = 1;
      return;
    }
    loopU[i] = 1;
    rep(j, 0, u[i].size()) {
      solve(u[i][j], !m, loopU, loopD);
    }
  }
}

int main() {
  cin >> n;
  rep(i, 0, n) {
    int a, b;
    string s;
    cin >> a >> s >> b;
    if(s[0] == 'l') {
      d[b] = a;
    }else {
      u[a].pb(b);
    }
  }
  rep(i, 1, 101) {
    if(d[i]) {
      map<int, int> a, b;
      solve(i, 0, a, b);
    }
  }
  rep(i, 1, 101) {
    if(u[i].size() > 0) {
      map<int, int> a, b;
      solve(i, 1, a, b);
    }
  }
  cout << f << endl;
}

Measured memory_bytes: 4152
#include <stdio.h>
#define MAX 100000
int main(){
	int map, load[21][21], i, j, k, a, b, c, d, manyload;
	int money;
	scanf("%d", &map);
	for(i = 1; i <= map; i++){
		for(j = 1; j <= map; j++) load[i][j] = MAX;
	}
	scanf("%d", &manyload);
	for(i = 0; i < manyload; i++){
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		load[a][b] = c;
		load[b][a] = d;
	}
	for(i = 1; i <= map; i++){
		for(j = 1; j <= map; j++){
			for(k = 1; k <= map; k++){
				if(load[j][k] > load[j][i] + load[i][k]) load[j][k] = load[j][i] + load[i][k];
			}
		}
	}
	scanf("%d,%d,%d,%d", &a, &b, &c, &d);
	printf("%d\n", c - d - load[a][b] - load[b][a]);
	return 0;
}

Measured memory_bytes: 600
def main():

    N = int(input())
    X = list(map(int, input().split()))
    Y = sorted(X)
    for i in range(N):
        if X[i] < Y[N//2]:
            print(Y[N//2])
        else:
            print(Y[N//2-1])

if __name__ == '__main__':
    # print(main())
    main()


Measured memory_bytes: 26772
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        int n = c.length;
        int[] a = new int[n];
        for(int i=0 ;i<n; i++) {
            a[i] = c[i] == '0' ? 0 : 1;
        }

        int prev = a[0];
        int rem = 0;
        for(int i=1; i<n; i++) {
            if(i == rem) {
                prev = a[i];
                continue;
            }
            if(prev != a[i]) {
                rem += 2;
            } else {
                prev = a[i];
            }
        }

        System.out.println(rem);


    }

}


Measured memory_bytes: 26468
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<cstdio>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(int i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const int N=7;
const int INF=1e9+7;

int main(){
	ll n,k,ans=0,h1=0,h2=0; scanf("%lld%lld",&n,&k);
	rep(i,n)if(i%k==0)h1++;
	ans+=h1*h1*h1;
	if(k%2==0){
		rep(i,n)if(i%k==k/2)h2++;
		ans+=h2*h2*h2;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int k[100030];
int s[100030];
int main() {
	double T, X;
	cin >> T >> X;
	cout << T / X;
}


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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[1001];
void factorial(int n){
    fact[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD;
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return -1;
    else{
        ll x=fact[r]*fact[n-r]%MOD;
        return fact[n]*fermat_inv(x)%MOD;
    }
}
ll dp[3001][3001][4];
ll a[3001][3001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t=1;
    //cin>>t;
    //SieveOfEratosthenes(1000000);
    //factorial(1000);
    while(t--){
        int r,c,k;
        cin>>r>>c>>k;
        for(int i=0;i<=r;i++)
            for(int j=0;j<=c;j++)
                a[i][j]=0;
        for(int i=0;i<k;i++){
            int x,y,z;
            cin>>x>>y>>z;
            a[x][y]=z;
        }
        dp[1][1][0]=0;
        dp[1][1][1]=a[1][1];
        dp[1][1][2]=a[1][1];
        dp[1][1][3]=a[1][1];
        for(int i=1;i<=r;i++){
            for(int j=1;j<=c;j++){
                if(i==1&&j==1)
                    continue;
                if(i==1){
                    dp[i][j][0]=dp[i][j-1][0];
                    for(int k=1;k<=3;k++){
                        dp[i][j][k]=max(dp[i][j-1][k],dp[i][j-1][k-1]+a[i][j]);
                    }
                }
                else if(j==1){
                    for(int k=0;k<=3;k++){
                        dp[i][j][k]=dp[i-1][j][3];
                        if(k)
                            dp[i][j][k]+=a[i][j];
                    }
                }
                else{
                    dp[i][j][0]=max(dp[i][j-1][0],dp[i-1][j][3]);
                    for(int k=1;k<=3;k++){
                        dp[i][j][k]=max(dp[i][j-1][k],max(dp[i][j-1][k-1]+a[i][j],dp[i-1][j][3]+a[i][j]));
                    }
                }
            }
        }
        ll ans=0;
        for(int k=0;k<4;k++)
            ans=max(ans,dp[r][c][k]);
        cout<<ans;
    }
}

Measured memory_bytes: 355080
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


ll a[100005],b[100005],c[100005],bb[100005];

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;

ll ans=0;
rep(i,1,n)
{
	cin>>a[i];
}

sort(a,a+n+1);

rep(i,1,n)
{
	cin>>b[i];
}

sort(b,b+n+1);

rep(i,1,n)
{
	int id=lower_bound(a,a+n+1,b[i])-a;
	bb[i]=id-1;
	bb[i]+=bb[i-1];
}

rep(i,1,n)
{
	cin>>c[i];
	int id=lower_bound(b,b+n+1,c[i])-b;
	id--;
	ans+=bb[id];
}

ol(ans);


return 0;
}



Measured memory_bytes: 3328
N,k=map(int,input().split())
n=N+1
a1=-(n**3-k**3)*2
a2=-(n**2+k**2)*3
a3=-(n-k)*1
A=(a1+a2+a3)//6
B=n*(n+k)*(n-k+1)//2
C=(n-k+1)
print ((A+B+C)%(10**9+7))

Measured memory_bytes: 9220
#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
int main(void) {
    int i;
    char string[1200];
    fgets(string,sizeof(string),stdin);
    for (i=0; i<strlen(string); i++) {
        if (isalpha(string[i])) {
            if (islower(string[i])) {
                printf("%c",toupper(string[i]));
            } else {
                printf("%c",tolower(string[i]));
            }
        } else {
            printf("%c",string[i]);
        }
    }
    return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define sqr(x) ((x)*(x))
    #define mp make_pair
    #define uint unsigned
    inline char gc(){
        static char buf[100000],*p1=buf,*p2=buf;
        return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
    }
    #define gc getchar
    inline int read(){
    	int x = 0; char ch = gc(); bool positive = 1;
    	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
    	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
    	return positive ? x : -x;
    }
    inline void write(int a){
        if(a>=10)write(a/10);
        putchar('0'+a%10);
    }
    inline void writeln(int a){
        if(a<0){
        	a=-a; putchar('-');
    	}
    	write(a); puts("");
    }
    const int N=100005;
    vector<int> v[N];
    int n,color[N];
    void insert(int a,int b){
    	v[a].push_back(b); v[b].push_back(a);
    }
    struct tree{
    	vector<int> v[N];
    	int vis[N],rt;
    	void dfs(int p){
    		if(v[p].size()%2==0)vis[p]=p;
    		for(unsigned i=0;i<v[p].size();i++){dfs(v[p][i]); if(vis[p]){insert(vis[v[p][i]],vis[p]); vis[p]=0;}else vis[p]=vis[v[p][i]];}
    	}
    	void init(){
    		for(int i=1;i<=n;i++){	
    			int t=read(); if(t==-1)rt=i; else v[t].push_back(i);
    		}
    		dfs(rt);
    	}
    }T[2];
    void ddd(int p,bool dq){
    	color[p]=dq;
    	for(unsigned i=0;i<v[p].size();i++)if(color[v[p][i]]==-1)ddd(v[p][i],dq^1);
    }
    int main(){
    	n=read();
    	T[0].init();
    	T[1].init();
    	for(int i=1;i<=n;i++)if(((T[0].v[i]).size())%2!=((T[1].v[i]).size())%2){
    		puts("IMPOSSIBLE"); return 0;
    	}
    	puts("POSSIBLE");
    	memset(color,-1,sizeof(color));
    	for(int i=1;i<=n;i++)if(color[i]==-1)ddd(i,0);
    	for(int i=1;i<=n;i++)if(T[0].v[i].size()&1){
    		putchar('0'); putchar(' ');
    	}else{
    		if(color[i])putchar('-'); putchar('1'); putchar(' ');
    	}
    }

Measured memory_bytes: 18432
#include "bits/stdc++.h"
#define N 200010 
using namespace std;
int dp[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n,cnt = 0;
	string s;
	cin>>n>>s;
	
	for(int i=0;i<n;i++) 
		if(s[i]=='W') dp[i] = dp[i-1]+1; 
		else          dp[i] = dp[i-1];
	int cntR = 0,ans = 0;
	for(int i=0;i<n;i++) if(s[i]=='R') ++cntR;
	for(int i=0;i<n;i++) if(s[i]=='R')
	{
		--cntR;
		if(!dp[i]) continue;
		if(cntR<dp[i])
		{
			++ans;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 4548
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n)cin >> d[i];
  int sum = 0;
  rep(i,n){
    for(int j=i+1;j<n;j++){
      sum += d[i]* d[j];
    }
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int res = 1;
  int max_cnt = 0;
  for (int i = 1; i <= N; i++) {
    int cur = i;
    int cnt = 0;
	while (true) {
      if ((cur % 2) == 0) {
        cur /= 2;
        ++cnt;
      } else {
        break;
      }
    }
    //cout << i << " " << cnt << endl;
    if (max_cnt < cnt) {
      max_cnt = cnt;
      res = i;
    }
  }
  
  cout << res << endl;
  
  return 0; 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[200006], b[200006], f[200006];
int main () {
    int N, M, K;
    cin >> N >> M >> K;
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }
    for (int i=0; i<M; i++) {
        cin >> b[i];
    }
    int u=0, pt=0;
    for (int i=0; i<M; i++) {
        if (u+b[i]<=K) {
            u+=b[i];
            pt++;
            f[0]++;
        }
        else {
            break;
        }
    }
    int sum=0, ans=f[0];
    for (int i=1; i<=N; i++) {
        sum+=a[i-1];
        if (sum>K) {
            break;
        }
        for (int j=0; j<M; j++) {
            if (sum+u<=K) {
                f[i]+=pt;
                break;
            }
            else {
                if (pt<=0) {
                    break;
                }
                u-=b[pt-1];
                pt--;
            }
        }
        ans=max(ans,f[i]+i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5928
#ifdef _WIN32
#define NOMINMAX
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#define DEBUGBREAK() ::DebugBreak()
#else
#define DEBUGBREAK() static_cast<void>(0)
#endif

#include <iostream>
#include <sstream>
#include <iomanip>
#include <valarray>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
#include <queue>
#include <array>
#include <functional>
#include <stack>
#include <bitset>
#include <random>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int64_t dx4[4] = { 0, -1, 1, 0 };
const int64_t dy4[4] = { -1, 0, 0, 1 };
const int64_t dx5[5] = { 0, -1, 0, 1, 0 };
const int64_t dy5[5] = { -1, 0, 0, 0, 1 };
const int64_t dx8[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int64_t dy8[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int64_t dx9[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
const int64_t dy9[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };

#define REP(i, K) for (int64_t i = 0; i < K; ++i)
#define REPYX() for (int64_t y = 0; y < H; ++y) for (int64_t x = 0; x < W; ++x)
#define REPX() REP(x, W)
#define REPY() REP(y, H)
#define INSIDE(x_, y_) (0 <= (x_) && 0 <= (y_) && (x_) < W && (y_) < H)
#define INSIDE_MARGIN(x_, y_, m_) ((m_) <= (x_) && (m_) <= (y_) && (x_) < W - (m_) && (y_) < H - (m_))

int get_assert_level() {
    const char* s = getenv("ASSERT_LEVEL");
    if (s) { return atoi(s); }
    return 0;
}
static int g_assert_level = get_assert_level();

#define LV_1() if (g_assert_level >= 1)
#define LV_2() if (g_assert_level >= 2)
#define LV_3() if (g_assert_level >= 3)
#define ASSERT_1(expr) do { const bool b = bool(expr); if (g_assert_level >= 1 && !b) { std::cerr << "[ASSERT 1] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_2(expr) do { const bool b = bool(expr); if (g_assert_level >= 2 && !b) { std::cerr << "[ASSERT 2] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_3(expr) do { const bool b = bool(expr); if (g_assert_level >= 3 && !b) { std::cerr << "[ASSERT 3] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)

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

    int X, N;
    cin >> X >> N;

    vector<int> ps1_exist(102, 0);
    REP(i, N) {
        int idx;
        cin >> idx;
        ps1_exist[idx] = 1;
    }

    int best_i1 = 0;
    int best_absdiff = numeric_limits<int>::max();
    for (int i1 = 0; i1 <= 101; ++i1) {
        if (ps1_exist[i1] == 0) {
            int absdiff = abs(i1 - X);
            if (best_absdiff > absdiff) {
                best_absdiff = absdiff;
                best_i1 = i1;
            }
        }
    }
    cout << best_i1 << endl;

    return 0;
}



Measured memory_bytes: 3656
import java.awt.Point;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, 1, 0, -1 };

	public static void main(String[] args) throws Exception {
		while (true) {
			int W = sc.nextInt();
			int H = sc.nextInt();
			if (W == 0) break;
			int[][] f = new int[2 * H - 1][2 * W - 1];
			sc.nextLine();
			for (int i = 0; i < 2 * H - 1; ++i) {
				String line = sc.nextLine();
				for (int j = i % 2 == 0 ? 1 : 0; j < 2 * W - 1; j += 2) {
					f[i][j] = line.charAt(j) - '0';
				}
			}
			ArrayList<Point> list = new ArrayList<Point>();
			list.add(new Point(0, 0));
			int ans = 0;
			OUT: for (int i = 1; !list.isEmpty(); ++i) {
				ArrayList<Point> next = new ArrayList<Point>();
				for (Point p : list) {
					if (p.x == 2 * W - 2 && p.y == 2 * H - 2) {
						ans = i;
						break OUT;
					}
					for (int j = 0; j < 4; ++j) {
						int nr = p.y + DR[j];
						int nc = p.x + DC[j];
						if (nr < 0 || 2 * H - 1 <= nr || nc < 0 || 2 * W - 1 <= nc) continue;
						if (f[nr][nc] == 1 || f[nr + DR[j]][nc + DC[j]] == 1) continue;
						next.add(new Point(nc + DC[j], nr + DR[j]));
						f[nr + DR[j]][nc + DC[j]] = 1;
					}
				}
				list = next;
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 45464
program answer
  implicit none

  integer ::D, N

  read(*,*) D, N

  if(D==0) then
     if(N==100) then
        write(*,*) 101
        stop
     else
        write(*,*) N
        stop
     end if
  else if(D==1) then
     if(N==100) then
        write(*,*) 10100
        stop
     else
        write(*,*) 100*N
        stop
     end if
  else
     if(N==100) then
        write(*,*) 1010000
     else
        write(*,*) 10000*N
     end if
   end if

  stop
 end program answer


Measured memory_bytes: 2828
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

vector<vector<ll>> mul(vector<vector<ll>> &A, vector<vector<ll>> &B){
    vector<vector<ll>> C(A.size(), vector<ll>(B.size()));

    for(int i=0; i<A.size(); i++){
        for(int k=0; k<B.size(); k++){
            for(int j=0; j<B[0].size(); j++){
                (C[i][j] += (A[i][k] * B[k][j]) % MOD) %= MOD;
            }
        }
    }
    
    return C;
}

vector<vector<ll>> pow(vector<vector<ll>> A, ll n){
    vector<vector<ll>> B(A.size(), vector<ll>(A.size()));

    for(int i=0; i<A.size(); i++){
        B[i][i] = 1;
    }

    while(n > 0){
        if(n & 1LL) B = mul(B, A);
        A = mul(A, A);
        n >>= 1LL;
    }

    return B;
}

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

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

    auto A = pow(a, k);

    ll ans = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            (ans += A[i][j]) %= MOD;
        }
    }

    cout << ans << endl;
}

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

int N;
vector<int> A;

int even( int idx, int cnt ) {
	if( idx == N ) {
		return cnt > 0;
	}

	int res = 0;

	for( int i = A[idx]-1; i <= A[idx]+1; ++i ) {
		res += even( idx+1, cnt + (i%2 == 0) );
	}

	return res;
}

int main() {
	ios_base::sync_with_stdio( false );

	cin >> N;
	A.resize( N );
	for( auto& v: A ) { cin >> v; }

	cout << even( 0, 0 ) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 100000

int main(){
    string s;
    int cc[256] ={0},n,ans;
    
    cin >> s;
    
    n = (int)s.size();
    ans = (int)s.size();
    
    for(int i=0;i<n;i++){
        cc[s[i]]++;
    }
    
    
    for(int i='a';i<'x';i++){
        bool flag = true;
        
        while(flag){
            flag = false;

            int min_cc = min({cc[i],cc[i+1],cc[i+2],cc[i+3]});
            if(min_cc==0) continue;
            
        
            for(int j=i+3;j<='z';j++){
                if(cc[j]==0){
                    for(int k=i;k<j;k++){
                        cc[k]--;
                    }
                    ans -= (j-i)-3;
                    flag = true;
                    break;
                }
                
                if(j=='z'){
                    for(int k=i;k<=j;k++){
                        cc[k]--;
                    }
                    ans -= (j-i)-2;
                    flag = true;
                }
            }
        }
    }
    
    for(int i='0';i<'7';i++){
        bool flag = true;
        
        while(flag){
            flag = false;
            
            int min_cc = min({cc[i],cc[i+1],cc[i+2],cc[i+3]});
            if(min_cc==0) continue;
            
            
            for(int j=i+3;j<='9';j++){
                if(cc[j]==0){
                    for(int k=i;k<j;k++){
                        cc[k]--;
                    }
                    ans -= (j-i)-3;
                    flag = true;
                    break;
                }
                
                if(j=='9'){
                    for(int k=i;k<=j;k++){
                        cc[k]--;
                    }
                    ans -= (j-i)-2;
                    flag = true;
                }
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

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

int main(){
  int n,k,q;
  cin >>  n >> k >> q;
  
  vector<int> a(q);
  for(int i=0; i < q; i++){
    cin >> a.at(i);
  }
  
  vector<int> count(n);
  
  for(int i=0; i < q; i++){
    count.at(a.at(i)-1)++;
  }
  
  for(int i =0; i < n; i++){
    if(count.at(i) >= q-k+1){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int search(int x,int n,int p[])
{
    if(binary_search(p,p+n,x))
        return x;
    else
        return -1;
}
void solve(int x,int n,int a[])
{
    int y = 0;
    int z = x;
    while(y == 0)
    {
        if(z == search(z,n,a))
            z++;
        else
            y = 1;
    }
    int w = x;
    y = 0;
    while(y == 0)
    {
        if(w == search(w,n,a))
            w--;
        else
            y = 1;
    }
    if(abs(x-w)>abs(x-z))
        cout<<z;
    else
        cout<<w;
}
int main()
{
    int x,n,p[100];
    cin>>x>>n;
    for(int i = 0;i<n;i++)
        cin>>p[i];
    sort(p,p+n);
    solve(x,n,p);
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int n,c[505],s[505],f[505],ans;
  cin>>n;
  Fr(i,n-1) cin>>c[i]>>s[i]>>f[i];
  Fr(i,n){
    ans=0;
    for(int j=i;j<n;j++){
      ans=max(((ans-1)/f[j]+1)*f[j],s[j])+c[j];
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256