akhauriyash/Code-Regression huggingface dataset:
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#define l(x) (x<<1)
#define r(x) ((x<<1)+1)
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define INF 0x3f3f3f3f
using namespace std;

LL T,n,i,m,x,y,k;
int a[N],b[N];
char c[N];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}

IL LL read(){
	LL p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	x=read();	y=read();	k=read();
	n=0;
	for (i=x;i<=y;i++)
		if ((i%k)==0)	n++;
	cout<<n<<endl;
	//cout<<(y/k)-(x/k)<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
    int c[6]={};
    int i,tot;
    
    for(i=0;i<6;i++){
        scanf("%d",&c[i]);
    }
    
    tot=c[0]+5*c[1]+10*c[2]+50*c[3]+100*c[4]+500*c[5];
    
    if(tot>=1000){
        puts("1");
    }
    else puts("0");
    
    return 0;
}

Measured memory_bytes: 584
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  vector<ll> aaa = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
  ll K;
  cin >> K;
  K--;
  cout << aaa[K] << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
D = [0] * N
i = 0
judge = True
while i < N - 1:
    h1 = H[i]
    h2 = H[i + 1]
    if h2 - h1 < 0:
        if D[i] == 0:
            H[i] -= 1
            D[i] = 1
            i -= 1
            if i < 0:
                i == 0
        else:
            judge = False
            break

    else:
        i += 1

if judge:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14396
import collections
def MI(): return map(int, input().split())
N,Q=MI()
Edge=[[] for _ in range(N)]
Point=[0]*(N)
for _ in range(N-1):
  a,b=MI()
  Edge[a-1].append(b-1)
  Edge[b-1].append(a-1)
for _ in range(Q):
  p,x=MI()
  Point[p-1]+=x
check=[0]*N
que=collections.deque()
que.append(0)
while que:
  v=que.pop()
  check[v]=1
  for u in Edge[v]:
    if check[u]==1:
      continue    
    Point[u]+=Point[v]
    que.append(u)  
'''
def dfs(now,pre=-1):
  for nxt in Edge[now]:
    if nxt==pre:
      continue
    Point[nxt]+=Point[now]
    #print(*Point)
    dfs(nxt,now)
dfs(0)
'''
print(*Point)

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

int main()
{
  int64_t N, M, d, t;
  priority_queue<int64_t> D, T;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> d;
    D.push(d);
  }
  cin >> M;
  for (int i = 0; i < M; i++)
  {
    cin >> t;
    T.push(t);
  }
  while (!T.empty())
  {
    while (!D.empty())
    {
      if (T.top() == D.top())
      {
        T.pop();
        D.pop();
        break;
      }
      else
      {
        D.pop();
      }
    }
    if (D.empty() && !T.empty())
    {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 4848
using System;
using System.Text;
using System.Collections.Generic;

namespace AOJ2
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> resultList = new List<int>();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0)
                {
                    break;
                }

                int count = 0;
                while (n / 5 >= 1)
                {
                    count += n / 5;
                    n /= 5;
                }

                resultList.Add(count);
            }

            foreach (int a in resultList)
            {
                Console.WriteLine(a);
            }


        }

    }
}

Measured memory_bytes: 5656
import Data.List
import Control.Monad

f::[String]->Bool
f []=True
f (x:[])=True
f (x:y:ys)=if (last x)==(head y) then  f(y:ys) else False

main = do
       n<-readLn
       ws<-replicateM n getLine
       let ws2=nub ws
       putStrLn $ if (length ws2)==(length ws) && (f ws) then "Yes" else "No"

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


int main() {
  long long a,b,c; cin >> a >> b >> c ;
  if(a % 2 == 1 && b % 2 == 1 && c % 2 == 1){
    cout << min(a*b,min(b*c,a*c)) << endl;
  }
  else cout << 0 << endl;
}

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

int main() {
    int n; cin >> n;
    vector<vector<int>> a(3, vector<int>(n + 1));
    for (int i: {1, 2}) for (int j = 1; j <= n; j++) {
        cin >> a[i][j];
        a[i][j] += max(a[i - 1][j], a[i][j - 1]);
    }
    cout << a[2][n] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss string
int main()
{
	int wa[105000],n,m,acnum=0,wanum=0;
    bool ac[105000];
	cin >> n >> m;
	for(int i =1;i<=n;i++)

	{
		wa[i]=0;
		ac[i]=false;
	}
    while(m--)
    {
    	int p;
    	ss s;
    	cin >> p >> s;
         if(ac[p]) continue;
        if(s == "AC") {
            ac[p] = true;
            acnum++;
            wanum += wa[p];
        } else if(s == "WA") {
            wa[p]++;
        }
    }
    	cout << acnum << " " << wanum <<"\n";
}

Measured memory_bytes: 4108
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<int64_t> a(N);
  rep(i, N) { cin >> a[i]; }

  rep(i, N - 1) { a[i + 1] += a[i]; }

  vector<int64_t> b(a);
  b.push_back(0);
  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());

  int64_t result = 0;
  vector<int> cnt(b.size(), 0);
  cnt[lower_bound(b.begin(), b.end(), 0) - b.begin()] = 1;
  rep(i, N) {
    result += cnt[lower_bound(b.begin(), b.end(), a[i]) - b.begin()]++;
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
bool dbg = false;
int a, b, c;
void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> a >> b >> c;
    cout << min(a * b, c) << endl;
    solve();
    return 0;
}


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

int main() {
  
  int a, b;
  char op;
  cin >> a >> op >> b;
 
  if (op == '+') cout << a+b << endl;
  else cout << a-b << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    long int n,k;
    scanf("%ld %ld",&n,&k);
    n-=1;
    k-=1;
    printf("%ld",n/k+(n%k!=0));
    return 0;
}

Measured memory_bytes: 256
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    h,a=MI()
    c=0
    while h>0:
        h-=a
        c+=1
    print(c)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5224
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20

def main():
    a, b = getList()
    ans = 1
    while(a >= 1):
        ans += 1
        a = a/b

    print(ans - 1)

if __name__ == "__main__":
    main()



Measured memory_bytes: 38384
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#define pi 3.141592653589
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
using namespace std;

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



int main() {

	ll n;
	int ans = 0, sum = 0;

	cin >> n;
	while (1) {
		ans++;
		sum += ans;
		if (sum >= n) {
			int tmp = sum - n;
			rep(i, 1, ans  + 1) {
				if (i != tmp)cout << i << endl;
			}
			break;
		}
	}

	return 0;
}

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

int main(void) {
  int n, v[21], c[21], ans = 0;

  if (scanf("%d", &n) != 1) {
    printf("入力エラー");
    return 0;
  }

  for (int i = 0; i < n; i++) {
    if (scanf("%d", &v[i]) != 1) {
      printf("入力エラー");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (scanf("%d", &c[i]) != 1) {
      printf("入力エラー");
      return 0;
    }
  }

  for (int i = 0; i < n; i++) {
    if (v[i] - c[i] > 0) {
      ans += v[i] - c[i];
    }
  }

  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
const int mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0) :x(x%mod) {}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
};
ll check(ll x) {
	ll temp = 1;
	for (int i = 0; i < (x % 6); i++)temp *= 10LL;
	return (temp % 13);
}
 
mint dp[101010][15];
int main() {
	string s;
	cin >> s;
	int N = s.size();
	reverse(all(s));
 
 
	dp[0][0] = 1;
	for (int i = 0; i < N; i++)for (int j = 0; j < 13; j++) {
		if (s[i] != '?') {
			ll c = (s[i]-'0')*check(i);
			dp[i + 1][(j+c)%13] += dp[i][j];
		}
		else {
			for (int k = 0; k < 10; k++) {
				ll c = k*check(i);
				dp[i + 1][(j + c) % 13] += dp[i][j];
			}
		}
	}
	puts(dp[N][5].x);
 
	return 0;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 5005;

int p[sz];
ll a[sz];
bool vis[sz];

ll fnc(vector <ll> b, int k) {
   ll ans = 0;
   vector <ll> ara = b, cum(1, 0);
   for(ll x : b) ara.push_back(x);

   ll j = 0;
   for(ll x : ara) {
      j += x;
      cum.push_back(j);
   }

   for(int i=1; i<=k; i++) {
      for(int j=i; j<cum.size(); j++) {
         ans = max(ans, cum[j] - cum[j-i]);
      }
   }
   return ans;
}

int main() {
   int n, k;
   cin >> n >> k;
   ll mx = LLONG_MIN;
   for(int i=1; i<=n; i++) scanf("%d", &p[i]);
   for(int i=1; i<=n; i++) scanf("%lld", &a[i]), mx = max(mx, a[i]);

   if(mx <= 0) {
      cout << mx << endl;
      exit(0);
   }

   ll ans = 0;
   for(int i=1; i<=n; i++) {
      if(vis[i]) continue;
      vector <ll> ara;
      ll sum = 0;
      int u = i;
      while(1) {
         if(vis[u]) break;
         vis[u] = 1;
         sum += a[u];
         ara.push_back(a[u]);
         u = p[u];
      }

      int z = ara.size();
      int x = k / z, baki = min(k, z);
      ll now = 0;
      if(sum > 0) {
         now += x * sum;
         baki = k % z;
      }
      now += fnc(ara, baki);
      ans = max(ans, now);

      if(!baki) {
         now = (x - 1) * sum;
         now += fnc(ara, z);
         ans = max(ans, now);
      }
   }
   cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
    
  ld d, t, s;
  cin >> d >> t >> s;

  if(d <= t * s) yes();
  else no();
    
  return 0;
}



Measured memory_bytes: 3768
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		int x1, y1, x2, y2, x3, y3, x4, y4;
		x1 = stdin.nextInt();
		y1 = stdin.nextInt();
		x2 = stdin.nextInt();
		y2 = stdin.nextInt();
		
//		System.out.println(x1);
//		System.out.println(y1);
//		System.out.println(x2);
//		System.out.println(y2);
		
		x3 = x2 - (y2 - y1);
		y3 = y2 + (x2 - x1);
		x4 = x3 - (y3 - y2);
		y4 = y3 + (x3 - x2);
		
//		System.out.println(x3);
//		System.out.println(y3);
//		System.out.println(x4);
//		System.out.println(y4);
		
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);

	}

}


Measured memory_bytes: 24148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

vector<vector<P>> to(100000);
vector<int> c(100000, 0);
vector<bool> vis(100000, false);

void dfs(int v, int p){
    int cnt = 1;
    vis[v] = true;
    for(P t : to[v]){
        if(vis[t.first])continue;
        if(cnt == p)cnt++;
        dfs(t.first, cnt);
        c[t.second] = cnt;
        cnt++;
    }
}

int main() {
    int n;
    cin >> n;
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(make_pair(b, i));
        to[b].push_back(make_pair(a, i));
    }
    int k = 0;
    rep(i, n)k = max(k, (int)to[i].size());
    dfs(0, 0);
    cout << k << endl;
    rep(i, n - 1)cout << c[i] << endl;

}

Measured memory_bytes: 8576
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int H = Integer.parseInt(scanner.next());
        int W = Integer.parseInt(scanner.next());
        scanner.nextLine();

        String[] C = new String[H];
        for (int i = 0; i < H; i++) {
            C[i] = scanner.nextLine();
        }
        scanner.close();

        for (String c : C) {
            System.out.println(c);
            System.out.println(c);
        }
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
int main()
{
  	cin.tie(0);
	ios::sync_with_stdio(false);
    int x, y, z, K;
    cin >> x >> y >> z >> K;
    vector<long long> A(x), B(y), C(z);
    for (int i = 0; i < x; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < y; i++)
    {
        cin >> B[i];
    }
    for (int i = 0; i < z; i++)
    {
        cin >> C[i];
    }
  	sort(A.rbegin(),A.rend());
  	sort(B.rbegin(),B.rend());
  	sort(C.rbegin(),C.rend());
    priority_queue<long long> P;
  	vector<long long>v;
    for (long long i = 0; i < x; i++)
    {
        for (long long j = 0; j < y; j++)
        {
            for (long long k = 0; k < z; k++)
            {
              if(i*j*k>=3000)continue;
              v.push_back(A[i]+B[j]+C[k]);
            }
        }
    }
	sort(v.rbegin(),v.rend());
    for (int i = 0; i < K; i++)
    {
      cout<<v[i]<<endl;
    }
}
 


Measured memory_bytes: 35176
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NM_MAX = 2002;

int n, m, q;

bool ma[NM_MAX][NM_MAX];

int da[] = {-1, 0, 1, 0}, db[] = {0, 1, 0, -1};

bool inside (int a, int b)
{
    return (1 <= a && a <= n && 1 <= b && b <= m);
}

int blue[NM_MAX][NM_MAX];

int cut[NM_MAX][NM_MAX][4];

int cnt[NM_MAX][NM_MAX];

int sumBlue (int a1, int b1, int a2, int b2)
{
    return blue[a2][b2] - blue[a1 - 1][b2] - blue[a2][b1 - 1] + blue[a1 - 1][b1 - 1];
}

int sumCnt (int a1, int b1, int a2, int b2)
{
    return cnt[a2][b2] - cnt[a1 - 1][b2] - cnt[a2][b1 - 1] + cnt[a1 - 1][b1 - 1];
}

int sumCut (int a1, int b1, int a2, int b2, int d)
{
    return cut[a2][b2][d] - cut[a1 - 1][b2][d] - cut[a2][b1 - 1][d] + cut[a1 - 1][b1 - 1][d];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        for(int j = 1; j <= m; j++)
            ma[i][j] = (s[j - 1] == '1');
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            if(ma[i][j] == true)
            {
                for(int d = 0; d < 4; d++)
                {
                    int i1 = i + da[d], j1 = j + db[d];
                    cut[i][j][d] = (inside(i1, j1) == true && ma[i1][j1] == true);
                    cnt[i][j] += cut[i][j][d];
                }
                blue[i][j] = 1;
            }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            cnt[i][j] += cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1];
            blue[i][j] += blue[i - 1][j] + blue[i][j - 1] - blue[i - 1][j - 1];
            for(int d = 0; d < 4; d++)
                cut[i][j][d] += cut[i - 1][j][d] + cut[i][j - 1][d] - cut[i - 1][j - 1][d];
        }
    while(q--)
    {
        int a1, b1, a2, b2;
        cin >> a1 >> b1 >> a2 >> b2;
        int qBlue = sumBlue(a1, b1, a2, b2);
        int qAllCuts = sumCnt(a1, b1, a2, b2);
        int qOutCuts = sumCut(a1, b1, a1, b2, 0) + sumCut(a1, b2, a2, b2, 1) + sumCut(a2, b1, a2, b2, 2) + sumCut(a1, b1, a2, b1, 3);
        int qInCuts = (qAllCuts - qOutCuts) / 2;
        cout << qBlue - qInCuts << "\n";
    }
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int A[N];
  int B[N];
  int C[N-1];
  rep(i, N){
    cin >> A[i];
    A[i]--;
  }
  rep(i, N){
    cin >> B[i];
  }
  rep(i, N-1){
    cin >> C[i];
  }
  int ans=0;
  rep(i, N){
    ans += B[A[i]];
    if (A[i+1] - A[i]==1) ans += C[A[i]];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<cstdio>
char N[500010];
int L;
int main(){
	scanf("%s",N+1);
	for(L=1;N[L];L++)N[L]-='0';
	for(int i=L,c=0;i--;){
		c=(N[i]=N[i]*9+c)/10;
		N[i]%=10;
	}
	int t=0,i=0;
	for(;;){
		int j=L-1;while(N[j]==9)N[j--]=0;
		N[j]++;
		while(!N[i])i++; 
		if(i==L-1)break;
		N[i]--;t++;
	}
	printf("%d\n",(t+8)/9);
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
using namespace std;

const int INT__MAX = 2147483647;
const int MOD = 1000000007;

int main() {

	int H, W, N;
	int a[10005];
	int s[10005];
	int tmp[105][105];
	int ans[105][105];
	int count = 0;

	cin >> H >> W >> N;
	for (int i = 1; i <= N; i++) {

		cin >> a[i];

	}

	for (int i = 1; i <= N; i++) {

		for (int j = 1; j <= a[i]; j++) {
			count++;
			
			s[count] = i;

		}

	}
	count = 0;
	for (int i = 1; i <= H; i++) {

		for (int j = 1; j <= W; j++) {
			count++;

			if (i % 2 == 1) {

				ans[i][j] = s[count];

			}
			else {

				ans[i][W - j + 1] = s[count];

			}

		}

	}

	for (int i = 1; i <= H; i++) {

		for (int j = 1; j <= W; j++) {

			cout << ans[i][j] << " ";

		}
		cout << endl;

	}

	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int i,j;
        
        Scanner sc=new Scanner(System.in);
        
        int cnt[]=new int[26];
        
        String str;
        char c;
        while(true){
            try{
               str=sc.next();
               for(i=0;i<str.length();i++){
                   c=str.charAt(i);
                   if(Character.isUpperCase(c))cnt[c-'A']++;
                   else if(Character.isLowerCase(c))cnt[c-'a']++;
               }
            }catch(NoSuchElementException e){
                break;
            }
        }
        c='a';
        for(i=0;i<26;i++){
            System.out.println(c + " : "+ cnt[i]);
            c++;
        }
        
    }
}



Measured memory_bytes: 26252
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	VI A(2);
	cin >> A[0] >> A[1];
	SORT(A);
	if (A[0] == 1 && A[1] == 2) {
		cout << 3<< endl;
	}
	else if (A[0] == 2 && A[1] == 3) {
		cout << 1 << endl;
	}
	else {
		cout << 2 << endl;
	}
	

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f;
vector<ll> factors;
int cd(ll x) {
  int rt = 0;
  if (x == 0)
    return 1;
  while (x)
    x /= 10, rt++;
  return rt;
}
int main() {
  ll n;
  cin >> n;
  for (int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      factors.pb(i);
      // if (n / i != i)
      factors.pb(n / i);
    }
  }
  ll ans = INF;
  sort(factors.begin(), factors.end());
  // for (int i : factors)
  //   cout << i << endl;
  for (int i = 0; i < factors.size() / 2; i++) {
    ll a = factors[i], b = factors[factors.size() - i - 1];
    ans = min(ans, 1LL * max(cd(a), cd(b)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt()
	K := nextInt()

	p := make(prices, N)

	for i := 0; i < N; i++ {
		p[i] = nextInt()
	}
	sort.Sort(p)

	s := 0
	for i := 0; i < K; i++ {
		s += p[i]
	}

	fmt.Println(s)
}

type prices []int

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 1812
while True:
    q=map(int,raw_input().split())
    if sum(q) == 0: break
    print ['Wednesday','Thursday','Friday','Saturday','Sunday','Monday','Tuesday',0][(sum([0,31,29,31,30,31,30,31,31,30,31,30,31][:q[0]])+q[1])%7]

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

int main(){
    int N;
    std::cin >> N;
    
    if(N % 1000 == 0){
        std::cout << 0 << std::endl;
    }else{
        std::cout << 1000 - N % 1000 << std::endl;
    }
    
    return 0;
}



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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    string s;
    cin >> s;
    ll cnt = 0,ans = 0;
    rep(i,0,3){
        if(s[i] == 'S'){
            ans = max(ans,cnt);
            cnt = 0;
        }
        else{
            cnt++;
        
        }
    }
    ans = max(cnt,ans);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h> 
using namespace std; 
 
int main() {
  int n;
  float answer;
  cin >> n;
  if(n % 2 == 0) 
    answer = (float)n / (2 * n);
  else
    answer = (float)(n + 1) / (2 * n);
  
  cout << answer;
  return 0;
}

Measured memory_bytes: 3708
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

nothing = ":("

cand = []

n = ni()
for i in range(n+1):
    if int(i * 1.08) == n:
        cand.append(i)

print(nothing if len(cand) == 0 else cand[0])

Measured memory_bytes: 3064
/*input
a
6
2 2 a
2 1 b
1
2 2 c
1
1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    int r = 0;
    deque<char> dq;
    for(int i = 0; i < s.size(); i++) dq.push_back(s[i]);
    int q; cin >> q;
	while(q--)
	{
		int t; cin >> t;
		if(t == 1) r = 1 - r;
		else
		{
			int f; cin >> f;
			char c; cin >> c;
			if(f == 1)
			{
				if(!r) dq.push_front(c);
				else dq.push_back(c);
			}
			else
			{
				if(!r) dq.push_back(c);
				else dq.push_front(c);
			}
		}
	}
	if(r) while(!dq.empty())
	{
		cout << dq.back();
		dq.pop_back();
	}
	else while(!dq.empty())
	{
		cout << dq.front();
		dq.pop_front();
	}

    return 0;
}

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

typedef long long ll;

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

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int a,b; cin >> a >> b;

  int ans = a-2*b>0?a-2*b:0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    int A, B, C, D, E, F, T = 0;
    cin >> A >> B >> C >> D >> E >> F;
    cout << A + B + C + D - min({A, B, C, D}) + max(E, F) << endl;
}



Measured memory_bytes: 3048
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
 
int main(){
    int ans = 0;

    for(int i = 0;i < 4;i++){
        char c;
        cin >> c;
        if(c == '2')ans++;
    }

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

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;
    cin>>N;
    const long long P=1000000007LL;
    long long ans=1;
    rep(i,N){
        ans=(ans*(i+1))%P;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
dic = defaultdict(int)

for i in range(3):
    p,q = map(int,input().split())
    dic[p] += 1
    dic[q] += 1
#print(dic)
L = []
for v in dic.values():
    L.append(v)

odd = [x%2 ==1 for x in L]
even = [x%2 ==0 for x in L]

if sum(odd) == 2 or sum(even) == 4:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9460
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

A = []
for i in range(3):
    a1, a2, a3 = (input_nums())
    A.append(a1)
    A.append(a2)
    A.append(a3)

def my_index(l, x, default=False):
    return l.index(x) if x in l else default

n = int(input())
for i in range(n):
    b = int(input())
    idx = my_index(A, b, -1)
    if idx == -1:
        continue
    A[idx] = 0

bingo = False
# 横のチェック
for i in range(3):
    if sum(A[i*3:i*3+3]) == 0:
        bingo = True
        break
# 縦のチェック
for i in range(3):
    if A[i] + A[i+3] + A[i+6] == 0:
        bingo=True
        break

# 斜めのチェック
if A[0] + A[4] + A[8] == 0:
    bingo = True
if A[2] + A[4] + A[6] == 0:
    bingo = True

if bingo:
    print('Yes')
else:
    print('No')

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

int main(){
    int y,m,d;
    char s1,s2;
    cin >> y >> s1 >> m >> s2 >> d;
    cout << (m <= 4 ? "Heisei":"TBD") << endl;
}

Measured memory_bytes: 256
// AOJ 2298
#include<iostream>
#include<algorithm>
#include<iomanip>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

typedef long double real;

const int NMAX = 300, LMAX = 100000;
const int KMAX = NMAX;
int N, K, T, U, V, L;
bool D[LMAX], accel[LMAX];

real solve() {
  int bag = 0, limit = 0;
  for (int x = 0; x < L; x++) {
    if (D[x]) {
      if (limit == 0) {
        limit = V * T;
      } else if (bag == K) {
        limit = V * T;
      } else {
        bag++;
      }
    }

    if (limit == 0 and bag > 0) {
      bag--;
      limit = V * T;
    }
    
    if (limit > 0) {
      limit--;
      accel[x] = true;
    } 
  }

  int u = 0, v = 0;
  REP(x, L) {
    if (accel[x]) {
      v++;
    } else {
      u++;
    }
  }

  return ((real) u) / U + ((real) v) / V;
}

int main() {
  cin >> N >> K >> T >> U >> V >> L;
  REP(x, N) {
    int d; cin >> d;
    D[d] = true;
  }

  cout << fixed <<  setprecision(20) << solve() << endl;
}

Measured memory_bytes: 1268
#include <iostream>
#include <vector>
#include <climits>
#include <set>
using namespace std;
typedef long long int ll;

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

	for(int i=1;i<n-1;i++){
		if(a[i] > a[i-1] and a[i+1] > a[i]) ways++;	
		else if(a[i] < a[i-1] and a[i+1] < a[i]) ways++;
	}	

	cout<<ways;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    int t = 0, x = 0, y = 0;
    int nt, nx, ny;
    for (int i = 0; i < n; ++i)
    {
        cin >> nt >> nx >> ny;
        int dt = nt - t;
        int dr = abs(nx - x) + abs(ny - y);
        if ((dt % 2) == (dr % 2) && dt >= dr)
        {
            t = nt, x = nx, y = ny;
        }
        else
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int A, B;
	string op;
	cin >> A >> op >> B;
	if (op[0] == '+') {
		cout << A + B << endl;
	}
	else {
		cout << A - B << endl;
	}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>a(n);for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end(),greater<int>());
  int sa=0,sb=0;
  for(int i=0;i<n;i++){
    if(i%2==0)sa+=a[i];
    else sb+=a[i];
  }
  cout<<sa-sb<<endl;
}

Measured memory_bytes: 256
def actual(N, M, A, B):
    AB = A + B

    counts = [AB.count(i) for i in range(1, N + 1)]
    
    return '\n'.join(map(str, counts))

N, M = map(int, input().split())
A, B = [], []
for _ in range(M):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
print(actual(N, M, A, B))
  

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

int main(){
  int n;
  cin >> n;
  int q=0,d=0,o=0;
  for(int i=0,l;i<n;i++){
    cin >> l;
    if(l%4==0) q++;
    else if(l%2==0) d++;
    else o++;
  }
  //cout << q << '$' << d << '$' << o << "$\n";
  if(o-q>1||(o-q==1&&d>0)) cout << "No\n";
  else cout << "Yes\n";
  return 0;
}

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

const int MAX = 2 * 10 * 10 * 10 * 10 * 10 + 1;
vector<int> tree[MAX];
int q_accm[MAX];
int ans[MAX];

void search(int node, int weight) {
    ans[node] = weight;
    vector<int> *children = tree + node;
    for (auto it = children->begin(); it != children->end(); ++it) {
        int child = *it;
        search(child, weight + q_accm[child]);
    }
}

int main() {
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        tree[a].push_back(b);
    }
    for (int i = 0; i < Q; ++i) {
        int p, x;
        cin >> p >> x;
        q_accm[p] += x;
    }
    search(1, q_accm[1]);
    for (int i = 1; i <= N; ++i) {
        cout << ans[i] << " ";
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 20864
#include<bits/stdc++.h>
using namespace std;
inline long long getnum()
{
    long long now=0;long long fh=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){now=(now<<3)+(now<<1)+ch-'0';ch=getchar();}
    return now*fh;
}
int ch[128];
int n,m;
int md[5];
int main()
{
  n=getnum();
  m=getnum();
  for (int i=1;i<=n*m;i++)
  {
    char tmp=getchar();
    while(tmp<'a'||tmp>'z')
    {
      tmp=getchar();
    }
    ch[(int)tmp]++;
  }
  for (int i='a';i<='z';i++)
  {
    md[ch[i]%4]++;
  }
  if (md[3]!=0)
  {
    printf("No\n");
    return 0;
  }
  if (n%2==0&&m%2==0)
  {
    if (md[1]>0||md[2]>0) printf("No\n"); else printf("Yes\n");
    return 0;
  }
  if (n%2!=0&&m%2!=0)
  {
    if (md[1]>1||md[2]>(n/2+m/2)) printf("No\n"); else printf("Yes\n");
    return 0;
  }
  if (n%2==0)
  {
    if (md[1]>0||md[2]>(n/2))printf("No\n");else printf("Yes\n");
    return 0;
  }else
  {
    if (md[1]>0||md[2]>(m/2))printf("No\n");else printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <time.h>
#include <bits/stdc++.h>

#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
const ll INF=1e18+5;
int w , h;
string grid[1005];
int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    IO;
  cin>>h>>w;
  for(int i =0 ;i < h ;i++)cin>>grid[i];
  int dp[h+2][w+2];
  dp[0][0]=1;
  for(int i =0 ;i< h ; i++){
      for(int j =0 ;j < w ;j ++){
          if(i==0&&j==0)continue;
          if(grid[i][j]=='#')dp[i][j]=0;
          else{
              dp[i][j]=0;
              if(i!=0)dp[i][j]+=dp[i-1][j];
              if(j!=0)dp[i][j]+=dp[i][j-1];
              dp[i][j]%=(1000000007);
          }
      }
  }
  cout<<dp[h-1][w-1]<<endl;
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  int N, A, B;
  cin >> N >> A >> B;
  
  int digit1 = 0;
  int digit2 = 0;
  int digit3 = 0;
  int digit4 = 0;
  int res = 0;
  
  int M;
  if(N==10000){
    M = N-1;
  }else{
    M = N;
  }
  
  if(N==10000 && A==1){
    res+= N;
  }
  
  int sum;
  
  rep(i, M+1){
    digit1 = i/1000;
    digit2 = (i-digit1*1000)/100;
    digit3 = (i-digit1*1000-digit2*100)/10;
    digit4 = (i-digit1*1000-digit2*100-digit3*10);

    sum = digit1 + digit2 + digit3 + digit4;
    if(A <= sum && sum <=B) res+= i;
  }
  
  //cout << digit1 << endl;
  //cout << digit2 << endl;
  //cout << digit3 << endl;
  //cout << digit4 << endl;
  cout << res;
  
}

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

I n;vector<vector<I>> vw;vector<vector<I>> dp;
I c1,c2;

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=c2;k+1;k--){
            if(dp[j-1][k]!=0 or k==0){
                I ne=k+vw[i-1][1];
                if(ne<=c2)dp[i-1][ne]=max(dp[j-1][k]+vw[i-1][0],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(c1,n))dfs(i*2);
    if(i*2+1<=min(c1,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    vw.resize(n);
    REP(i,n){I x,y;cin>>x>>y;vw[i]={x,y};}
    c1=1<<10;c2=100000;
    dp.resize(c1);REP(i,c1)dp[i].resize(c2+1);
    dp[0][vw[0][1]]=vw[0][0];
    dfs(1);
    REP(i,c1)REP(j,c2)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I v,l;cin>>v>>l;
        vector<I> cand;
        while(v>c1){
            cand.push_back(v);
            v=v/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=vw[cand[k]-1][0];
                    w_sub+=vw[cand[k]-1][1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[v-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 418972
# -*- coding: utf-8 -*-
"""
Basic Operations - Lexicographical Comparison
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_3_D&lang=jp

"""
from itertools import zip_longest

_ = input()
A = [int(a) for a in input().split()]
_ = input()
B = [int(b) for b in input().split()]

ans = 0
for a, b in zip_longest(A, B, fillvalue=-1):
    if a > b:
       break
    elif b > a:
        ans = 1
        break
print(ans)



Measured memory_bytes: 5792
#include "bits/stdc++.h"
using namespace std;
int H, W, dp[1002][1002], mod=1e9+7; char g[1002];
int main(){
    scanf("%d %d", &H, &W); dp[1][0] = 1;
    for(int i=1; i<=H; i++){
        scanf("%s", g+1);
        for(int j=1; j<=W; j++){
            if(g[j] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
        }
    }
    printf("%d\n", dp[H][W]);
}

Measured memory_bytes: 4224
#include<iostream>
using namespace std;
#define RIGHT 1
#define LEFT 0
#define BALL 10
#define BAD 1

int main()
{
    int n;
    int num[BALL];
    int siden[BALL];
    cin >> n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<BALL;++j) {cin >> num[j]; }

        int temp,ans =0;
        unsigned int side;
        for(side=0;side<=4050;++side)
        {
            ans = 0;
            for(int j = 0;j<BALL;++j)
            {
                if(((side>>j)&1) ){siden[j] = RIGHT;}
                else {siden[j] = LEFT;}
            }
            int before = -1;
            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==RIGHT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            before = -1;

            for(int j=0;j<BALL;++j)
            {
                if(siden[j]==LEFT)
                {
                    if(before > -1)
                    {
                        if(num[before]>num[j])ans = BAD;
                    }
                    before = j;
                }
            }
            if(ans==0)break;
        }
        if(ans==BAD) cout << "NO" << endl;
        else cout << "YES" << endl;

    }
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
    int N,i,total=0,half,chack=0;
    scanf("%d",&N);
    int W[N+1];
    for(i=0;i<N;i++){
        scanf("%d",&W[i]);
        total+=W[i];
    }
    if(total%2==0) half=total/2;
    else half=total/2+1;
    for(i=0;i<N;i++){
        if(half>chack) chack+=W[i];
        else{
            if(total-chack*2<=(chack+W[i+1])*2-total){
                if(total-chack*2>=0){
                    if(total-(chack-W[i-1])*2>=total-chack*2) printf("%d\n",total-chack*2);
                    else printf("%d\n",total-(chack-W[i-1])*2);
                }
                else if(total-(chack-W[i-1])*2>=chack*2-total) printf("%d\n",chack*2-total);
                else printf("%d\n",total-(chack-W[i-1])*2);
            }
            else printf("%d\n",(chack+W[i+1])*2-total);
            break;
        }
    }
    return 0;
}

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

int main() {
  
  string S;
  cin >> S;
  int x = 10;
  
  bool hantei = true;
  
  for ( int i =0; i < 4; i++) {
    if ( x == S.at(i) ) hantei = false;
    x = S.at(i);
  }
  
  if ( hantei ) cout << "Good" << endl;
   
  else cout << "Bad" << endl;
  
}

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

int main()
{
	int n,a,b;
	cin>>n;
	if(n==1)
	{
		cout<<"Hello World"<<endl;
		return 0;
	}
	else
	{
		cin>>a>>b;
		cout<<a+b<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>

int main(){
    char ch;
    
    while(1){
        scanf("%c",&ch);
        if (isalpha(ch)){
            if(islower(ch)) printf("%c",toupper(ch));
            else printf("%c",tolower(ch));
        }else printf("%c",ch);
            
        if(ch == '\n') break;
    }
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = min(b - (ll)1, n - a);
	if((b - a)%2 == 0) ans = min(ans, (b - a)/2);
	else
	{
		a++;
		ans = min(ans, (b - a)/2 + n - b + 1);
		a--; b--;
		ans = min(ans, (b - a)/2 + a);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }
using P = pair<ll, ll>;
void prp(P& p) {cout << p.first << " " << p.second << endl;}

int main()
{
    ll n, k; cin >> n >> k;
    vector<P> v;
    rep(i, n){
        ll a, b; cin >> a >> b;
        v.push_back({a, b});
    }
    sort(ALL(v));

    rep(i, n){
        if(v[i].second >= k){
            pr(v[i].first);
            break;
        }
        v[i+1].second += v[i].second;
    }
    return 0;}

Measured memory_bytes: 5284