akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication46
{
    class Program
    {
        static void Main(string[] args)
        {
            string a;
            while ((a = Console.ReadLine()) != null)
            {
                if (a == null)
                    break;
                if (a[0] == 'o' && a[1] == 'o' && a[2] == 'o')
                    Console.WriteLine("o");
                else if (a[3] == 'o' && a[4] == 'o' && a[5] == 'o')
                    Console.WriteLine("o");
                else if (a[6] == 'o' && a[7] == 'o' && a[8] == 'o')
                    Console.WriteLine("o");
                else if (a[0] == 'o' && a[3] == 'o' && a[6] == 'o')
                    Console.WriteLine("o");
                else if (a[1] == 'o' && a[4] == 'o' && a[7] == 'o')
                    Console.WriteLine("o");
                else if (a[2] == 'o' && a[5] == 'o' && a[8] == 'o')
                    Console.WriteLine("o");
                else if (a[0] == 'o' && a[4] == 'o' && a[8] == 'o')
                    Console.WriteLine("o");
                else if (a[2] == 'o' && a[4] == 'o' && a[6] == 'o')
                    Console.WriteLine("o");

                else if (a[0] == 'x' && a[1] == 'x' && a[2] == 'x')
                    Console.WriteLine("x");
                else if (a[3] == 'x' && a[4] == 'x' && a[5] == 'x')
                    Console.WriteLine("x");
                else if (a[6] == 'x' && a[7] == 'x' && a[8] == 'x')
                    Console.WriteLine("x");
                else if (a[0] == 'x' && a[3] == 'x' && a[6] == 'x')
                    Console.WriteLine("x");
                else if (a[1] == 'x' && a[4] == 'x' && a[7] == 'x')
                    Console.WriteLine("x");
                else if (a[2] == 'x' && a[5] == 'x' && a[8] == 'x')
                    Console.WriteLine("x");
                else  if (a[0] == 'x' && a[4] == 'x' && a[8] == 'x')
                    Console.WriteLine("x");
                else if (a[2] == 'x' && a[4] == 'x' && a[6] == 'x')
                    Console.WriteLine("x");
                else Console.WriteLine("d");
            }
        }
    }
}

Measured memory_bytes: 8720
/*
Saurabh Joshi
IIIT Jabalpur
*/
#include<bits/stdc++.h>
#define LL long long int
#define M 1000000007
#define endl "\n"
#define eps 0.00000001
LL pow(LL a,LL b,LL m){ a%=m;LL x=1,y=a;while(b > 0){if(b%2 == 1){x=(x*y);if(x>m) x%=m;}y = (y*y);if(y>m) y%=m;b /= 2;}return x%m;}
LL gcd(LL a,LL b){if(b==0) return a; else return gcd(b,a%b);}
LL gen(LL start,LL end){LL diff = end-start;LL temp = rand()%start;return temp+diff;}
using namespace std;
int w[1001], s[1001], v[1001];
LL dp[1001][10005];
int n;
LL f(int pos,int w) {
    if(pos == n + 1)
        return 0;
    if(dp[pos][w] != -1)
        return dp[pos][w];
    LL ans = f(pos + 1 , w);
    if(w <= s[pos]) {
        ans = max(ans , f(pos + 1 , min(10001 , w + ::w[pos])) + v[pos]);
    }
    return dp[pos][w] = ans;
}
int main()	{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> w[i] >> s[i] >> v[i];
    }
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j++) {
            if(s[i] + w[i] > s[j] + w[j]) {
                swap(w[i] , w[j]);
                swap(s[i] , s[j]);
                swap(v[i] , v[j]);
            }
        }
    }
    memset(dp, -1, sizeof(dp));
    cout << f(1 , 0);
    
}

Measured memory_bytes: 78592
#include<stdio.h>
#include<string.h>
 
#define MAX 1000
 
int main(){
  int i, j, m, q, x, y, c[MAX+1][MAX+1];
  char X[MAX], Y[MAX];
 
  scanf("%d",&q);
 
  for(i=0;i<strlen(X);i++)
    c[i][0] = 0;
  for(j=0;j<strlen(Y);j++)
    c[0][j] = 0;
 
  for(m=0;m<q;m++){
    scanf("%s",X);
    scanf("%s",Y);
    x = strlen(X);
    y = strlen(Y);
    for(i=0;i<x;i++)
      c[i][0] = 0;
    for(j=0;j<y;j++)
      c[0][j] = 0;
 
    for(i=1;i<=x;i++){
      for(j=1;j<=y;j++){
    if(X[i-1] == Y[j-1])c[i][j] = c[i-1][j-1] + 1;
    else if(c[i-1][j] >= c[i][j-1])c[i][j] = c[i-1][j];
    else c[i][j] = c[i][j-1];
      }
    }
    printf("%d\n",c[x][y]);
  }
 
  return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const int q_max = 50;
int n, m, q;
vi a(q_max), b(q_max), c(q_max), d(q_max);
int ans = 0;
vector<bool> used(11);
vi nums(10);
void dfs(int dep, int p) {
    if (dep == n) {
        int sum = 0;
        rep(i, q) {
            if (nums[b[i]]-nums[a[i]]==c[i]) sum += d[i];
        }
        ans = max(ans, sum);
        return;
    }
    for (int i=p; i<=m; ++i) {
        nums[dep] = i;
        dfs(dep+1, i);
    }
}

int main(){
    cin >> n >> m >> q;
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i]; --b[i];
    }
    dfs(0, 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
using namespace std;
 
int main()
{
    long long L, R;
    long long ans = 9999999999;
    cin >> L >> R;
 
    if (R - L > 2018)
    {
        cout << 0 << endl;
        return 0;
    }
    L=L%2019;
    R=R%2019;
    for (long long i = L; (i < R ); i++)
    {
        for (long long j = i + 1; (j <= R); j++)
        {
 
            if (ans > (i * j) % (2019))
            {
                ans = (i * j) % ( 2019);
            }
        }
    }
    cout << ans<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()
    A=list(mi())

    v = [0] * 2*10**5
    seen = set([0])
    for i in range(N):
        v[i+1] = A[i] + v[i]
        v[i+1] %= M
        seen.add(v[i+1])
    
    counts = {x:0 for x in seen}
    for i in range(N+1):
        counts[v[i]] += 1
    
    ans = 0
    for _,count in counts.items():
        ans += count * (count-1) // 2
    
    print(ans)
    





if __name__ == "__main__":
    main()

Measured memory_bytes: 23948
#include<stdio.h>
int main(){
int price,fh,oh,fif,ten,five,one,sum;
while(1){
scanf("%d\n",&price);
sum=0;
fh=0;oh=0;fif=0;ten=0;five=0;one=0;
if(price==0)break;
price = 1000 - price;
if (price>=500){
fh = price / 500; 
price -= 500;
}
if(price>=100){
oh = price / 100;
price -= 100*oh;
}
if(price>=50){
fif =  price / 50;
price -= 50;
}
if(price>=10){
ten = price / 10;
price -= 10*ten;
}
if(price>=5){
five = price / 5;
price -= 5;
}
if(price>=1){
one = price / 1;
}
sum = fh+oh+fif+ten+five+one;
printf("%d\n",sum);
}
return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))

// #define DEBUG

#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;

const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}

random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

const int M = 7468791;

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

    for(int n, m; cin >> m >> n, m;){
        vi tbl(M);

        int res = -1;
        rep(i, m, M){
            if(tbl[i]) continue;

            if(n == 0){
                res = i;
                break;
            }
            n--;
            for(int j = i; j < M; j += i){
                tbl[j] = true;
            }
        }

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 32392
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    a = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
    b = (h - h // 3) * (w - w // 2) - h // 3 * w
    c = min(h, w)
    h, w = w, h
    d = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
    e = (h - h // 3) * (w - w // 2) - h // 3 * w
    print(min(a, b, c, d, e))

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
  long n,a,b,ans;

  scanf("%ld %ld %ld",&n,&a,&b);
  ans=(n/(a+b))*a;
  if((n%(a+b))>=a){
    ans+=a;
  }else if((n%(a+b))<a){
    ans+=n%(a+b);
  }

  printf("%ld",ans);

  return 0;
}

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

int main()
{
    int A[5][4][11], n;

    for(int i = 1; i <= 4; i++){
        for(int j = 1; j <= 3; j++){
            for(int k = 1; k <= 10; k++){
                A[i][j][k] = 0;
            }
        }
    }
    cin >> n;

    for(int i = 0; i < n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        A[b][f][r] += v;
    }

    for(int b = 1; b <= 4; b++){
        if(b > 1) cout << "####################\n";
        for(int f = 1; f <= 3; f++){
            for(int r = 1; r <=10; r++){
                cout << " " << A[b][f][r]; 
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3068
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in a_count.items():
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])



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

typedef long long ll;

vector<int> D;
//   digit sum flg 
map<ll, ll> dp[15][150][3];

int main(){
	string str;
	cin >> str;
	ll isum = 0;
	ll iprod = 1;
	for(char c : str){
		int cc = c - '0';
		D.push_back(cc);
		isum += cc; 
		iprod *= (cc + 1);
	}
	dp[0][0][1][1] = 1;
	for(int i = 0; i < D.size(); i++) for(int j = 0; j < 150; j++) for(int k = 0; k < 3; k++) for(auto p : dp[i][j][k]){
		ll prod = p.first;
		ll num = p.second;
		for(int l = 0; l < 10; l++){
			//printf("%d %d %d %lld %lld %d\n", i, j, k, prod, num);
			if(k == 0 || (k == 1 && D[i] > l)) dp[i + 1][j + l][0][prod * (l + 1)] += num;
			if(k == 1 && D[i] == l)            dp[i + 1][j + l][1][prod * (l + 1)] += num;
			if(k == 2 || (k == 1 && D[i] < l)) dp[i + 1][j + l][2][prod * (l + 1)] += num;
		}
	}
	ll ans = 0;
	for(int j = 0; j < 150; j++) for(int k = 0; k < 3; k++) for(auto p : dp[D.size()][j][k]){
		ll prod = p.first;
		ll num = p.second;
		if(j < isum){
			ans += num;
		}else if(j == isum){
			if(prod < iprod){
				ans += num;
			}else if(prod == iprod){
				if(k == 0){
					ans += num;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 74632
#include<stdio.h>
int main(void)
{
	int n,s[1000],p[1000],q[1000],r[1000];
	int sum[1000],P,Q,R,C,i,flg;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
			sum[i]=0;
			scanf("%d %d %d %d ",&s[i],&p[i],&q[i],&r[i]);
			sum[i]=p[i]*4+q[i]*9+r[i]*4;
		}
		scanf("%d %d %d %d",&P,&Q,&R,&C);
		flg=0;
		for(i=0;i<n;i++){
			if(p[i]<=P&&q[i]<=Q&&r[i]<=R&&sum[i]<=C){
				printf("%d\n",s[i]);
				flg=1;
			}
		}
		if(flg==0){
			printf("NA\n");
		}
	}
	return 0;
}



Measured memory_bytes: 2104
a, b, c, d = map(int, input().split())

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

def multiple_counting(range, a, b):
    return (range -range//a -range//b +range//lcm(a,b))

def main():
    print(multiple_counting(b, c, d) - multiple_counting(a-1, c, d))

def test():
    from fractions import gcd
    A, B, C, D = map(int, input().split())
    l = C * D // gcd(C, D)
    x = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // l
    y = B - B // C - B // D + B // l
    print(y - x)
main()

Measured memory_bytes: 3064
import math
n = int(input())
l = list(map(int,input().split()))
cnt = 0

for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i] != l[j] and  l[j] != l[k] and  l[k] != l[i]:
        if abs(l[i] - l[j]) < l[k] and l[k] < l[i] + l[j]:
          cnt += 1        
    
print(cnt)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

ll bound;
int cnt = 0;

void dfs( ll n, int k ){
	if( n > bound ){
		return;
	}
	if( k == 7 ) ++cnt;
	dfs( n*10 + 3, k | 1 );
	dfs( n*10 + 5, k | 2 );
	dfs( n*10 + 7, k | 4 );
}

int main(){
	cin >> bound;
	dfs( 0, 0 );
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

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

const ll mod = static_cast<ll>(1e9) + 7;

int main()
{
    string s;
    cin >> s;

    bool res = (s.size() % 2) == 0;

    rep (i, s.size() / 2)
    {
        res &= s[i * 2] == 'h' && s[i * 2 + 1] == 'i';
    }

    cout << (res ? "Yes" : "No") << 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;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  double x, sum = 0;
  string s;
  REP(i, n) {
    cin >> x >> s;
    if (s == "JPY") sum += x;
    else sum += x * 380000.0;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    int m=100000000;
    vector<bool> isPrime(m+1,true);
    isPrime[0]=false;
    isPrime[1]=false;
    for(long long i=2;i*i<=m;i++){
        if(isPrime[i]){
            for(long long j=2;i*j<=m;j++){
                isPrime[i*j]=false;
            }
        }
    }
    int o,ans=0;
    for(int i=0;i<n;i++){
        cin>>o;
        if(isPrime[o]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
const ll INF = 1001001000100010;
const ld PI = 3.14159265358979323846;


int main() {
// 入力
    int N; // 都市数
    cin >> N;
    vector<pair<ld,ld>> dist(N); // 各都市の座標
    for (int i = 0; i < N; ++i) {
        
            cin >> dist[i].first>>dist[i].second;
        
    }

    // 初期順列
    vector<int> order(N);
    for (int i = 0; i < N; ++i) order[i] = i;

    ld average,sum=0,div=1.0;

    // 探索
    
    do {
        
        
        for (int i = 1; i < N; ++i) {
            sum += sqrtl(powl(dist[order[i-1]].first-dist[order[i]].first,2)+powl(dist[order[i-1]].second-dist[order[i]].second,2));
        }
        
    } while (next_permutation(order.begin(), order.end()));
rep3(i,N){
div*=i;
}
average=sum/div;
    // 答えを出力
    cout(10) << average << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int a,b,x;
  cin>>x>>a>>b;
  a = abs(a-x);
  b = abs(b-x);

  if(a<b) cout << "A" << endl;
  else cout << "B" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll a[200010],n,k;
 cin>>n>>k;
 rep(i,0,n)sc(a[i]);
// stirng s;cin>>s;
 ll ans;
 ll sum=0,before;
// rep(i,0,k)sum+=a[i];
 rep(i,k,n){
  if(a[i]>a[i-k])py;
  else pn;
 }
   
  
return 0;}

Measured memory_bytes: 5200
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String[] sArray = new String[3];
    sArray[0] = s.split("")[0];
    sArray[1] = s.split("")[1];
    sArray[2] = s.split("")[2];
    int count = 0;

    if (sArray[0].equals("1")) count += 1;
    if (sArray[1].equals("1")) count += 1;
    if (sArray[2].equals("1")) count += 1;

    System.out.println(count);
  }
}


Measured memory_bytes: 23124
let s = read_line ()
let n = String.length s
let g i = let is_ok = ref true in
  for j = 1 to n - 1 do
    if i <> j then if Char.lowercase s.[j] <> s.[j] then is_ok := false done;
  !is_ok
let f s = try let i = String.index s 'C' in g @@ i + 2 with _ -> false
let _ = print_endline @@ if s.[0] = 'A' && f @@ String.sub s 2 @@ n - 3 then "AC" else "WA"

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int a;
    string s;
    cin>>a;
    int acc=0,wac=0,tlec=0,rec=0;
    for(int i=0;i<a;i++){
        cin>>s;
        if(s=="AC"){
            acc++;
        }
        if(s=="WA"){
            wac++;
        }
        if(s=="TLE"){
            tlec++;
        }
        if(s=="RE"){
            rec++;
        }
    }
    cout<<"AC x " <<acc<<"\n";
    cout<<"WA x " <<wac<<"\n";
    cout<<"TLE x " <<tlec<<"\n";
    cout<<"RE x " <<rec<<"\n";

}

Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <iostream>

using namespace std;
typedef long long ll;
ll a,b,c,i,j,k,n,m,t,r,s,p;
ll arr[100005];


int main(){
	scanf("%lld%lld%lld",&n,&k,&s);
	for(i=0;i<k;i++){
		printf("%lld ",s);
	}
	for(i=0;i<n-k;i++)
        if(s!=999999999)
		printf("%lld ",999999999);
        else
            printf("%lld ",1);
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 100;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> vec;
	ll max_x = 0;
	for(int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		vec.push_back(x);
		max_x += x;
	}
	ll ans = 1000000000000000000LL, x = 0;
	for(int i = 0; i < n - 1; i++)
	{
		x += vec[i];
		ans = min(abs(max_x - 2 * x), ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h> //ABC 162_d
#define ll long long
using namespace std;
string t;
int s[4][4005],a[4005];
long long ans,n;
int main(){
	cin>>n>>t;
	for(int i=1;i<=n;i++){
		if(t[i-1]=='R')a[i]=0;
		if(t[i-1]=='G')a[i]=1;
		if(t[i-1]=='B')a[i]=2;
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<=2;j++)
			s[j][i]=s[j][i-1];
		s[a[i]][i]=s[a[i]][i-1]+1;	
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]==a[j])
				continue;
			ans+=s[3-a[i]-a[j]][n]-s[3-a[i]-a[j]][j];
			if(2*j-i<=n&&a[2*j-i]==3-a[i]-a[j])
				ans--;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  long long a,b,d=0,g=0,f=0;
  priority_queue<int> c;
    cin>>a>>b;
    for(int i=0;i<a;i++){
      cin>>g;
      c.push(g);
    }
    for(int i=1;i<=b;i++){
      g=c.top();
      c.pop();
      g/=2;
      c.push(g);
    }
    for(int i=0;i<a;i++){
      d+=c.top();
      c.pop();
    }
    cout<<d<<"\n";
}


Measured memory_bytes: 1400
#PDF解説
D, G = [int(dg) for dg in input().split()]
P, PC = [], []
for d in range(D):
  p, c = [int(pc) for pc in input().split()]
  P.append(p)
  PC.append(100*(d+1)*p + c)

HMP = []
for i in range(2**D):
  i2 = format(i, "b")
  i2 = "0"*(D-len(i2)) + i2
  score = 0
  howmany_problems = 0
  for j in range(D):
    score += PC[j] * int(i2[j])
    howmany_problems += P[j] * int(i2[j])
    
  if score >= G:
    HMP.append(howmany_problems)
  else: # score < G:
    for k in range(D-1, -1, -1):
      if i2[k] == "0":
        break
    pk = P[k]
    for x in range(1, pk):
      score += 100 * (k+1)
      if score >= G:
        HMP.append(howmany_problems + x)
        break

ans = min(HMP)
print(ans)

Measured memory_bytes: 3064
/*input
6
5 2 4 6 1 3
*/
fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_
}

fn main() {
    read_line();
    let mut v: Vec<i32> = read_line()
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    let mut key: i32;
    let mut j: i32;
    let mut first: bool;
    for i in 0..v.len() {
        key = v[i as usize];
        j = i as i32 - 1;
        while j >= 0 && v[j as usize] > key {
            v[(j + 1) as usize] = v[j as usize];
            j = j - 1;
        }
        v[(j + 1) as usize] = key;
        first = true;
        for k in v.clone() {
            if !first {
                print!(" ");
            } else {
                first = false;
            }
            print!("{}", k);
        }
        print!("\n");
    }
}



Measured memory_bytes: 5028
import scala.io.StdIn.readLine

object Main extends App {

  val arr = readLine.split(" ")
  val stack = new Stack[Int]

  arr foreach {
    case "+" => { stack.push(stack.pop + stack.pop) }
    case "-" => { stack.push(- stack.pop + stack.pop) }
    case "*" => { stack.push(stack.pop * stack.pop) }
    case num => { stack.push(num.toInt) }
  }
  println(stack.pop())

  class Stack[T] {

    class Node[T](v: T) {
      var value: T = v
      var next: Node[T] = null
    }

    var top: Node[T] = null

    def push(value: T): Unit = {
      val newNode = new Node[T](value)
      if (top == null) {
        top = newNode
      } else {
        newNode.next = top
        top = newNode
      }
    }

    def pop(): T = {
      val returnNode = top
      if (returnNode != null) {
        top = returnNode.next
      }
      returnNode.value
    }

  }
}



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

int main() {
  long long n,k;
  cin >> n >> k;
  if(n<k){
    if(n<k-n)
      cout << n << endl;
    else
      cout << k-n << endl;
  }
  else{
    long long amari = n%k;
    if(amari<k-amari)
      cout << amari << endl;
    else
      cout << k-amari <<endl;
  }
}
      



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
int main() {
   int a,b,c,n,m,x,y;
   string s;cin>>s;
   if(s=="AAA"||s=="BBB")cout<<"No";
   else cout<<"Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100005
#define ll long long
using namespace std;

ll n;
int main()
{
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i * i < n; i++)
    {
        if (n % i != 0)
            continue;
        if (n / i - 1 > i)
            ans += n / i - 1;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    double area=(double)w*h;
    double x_mid=((double)w)/2;
    double y_mid=((double)h)/2;
    int flag=0;
    if(x_mid==x && y_mid==y)
        flag=1;
    printf("%lf %d\n",area/2,flag);
}

Measured memory_bytes: 256
use std::io::*;
use std::str::*;
use std::cmp::*;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    pub fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {
            cin: cin,
        }
    }

    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace() || c.is_control())
            .take_while(|c| c.is_alphanumeric())
            .collect::<String>();
        s.parse::<T>().ok().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    
    let n: i64 = sc.read();
    let k: i64 = sc.read();
    
    let mut x = 1;
    for _ in 0..n {
        x = min(x * 2, x + k);
    }

    println!("{}", x);
}

Measured memory_bytes: 4352
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = arg[0].split("");
    const B = arg[1].split("");
    const C = arg[2].split("");
    
    let next = "a";
    
    while(true) {
        if(next === "a") {
            if(A.length === 0) {
                console.log("A");
               return;
            }
            
            next = A.shift();
        } else if(next === "b") {
            if(B.length === 0) {
                console.log("B");
                return;
            }
            
            next = B.shift();
        } else if(next === "c") {
            if(C.length === 0) {
                console.log("C");
                return;
            }
            
            next = C.shift();
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <stdio.h>
#include <math.h>

int main() {
    int n, d;
    scanf("%d %d", &n, &d);
    double x, y;
    int counter = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lf %lf", &x, &y);
        if (sqrt(pow(x, 2) + pow(y, 2)) <= d) {
            counter++;
        }
    }
    printf("%d\n", counter);
}

Measured memory_bytes: 3228
#include <stdio.h>

int main(){

    int n;      // 枠の一辺
    int h;      // ポスターの縦の長さ
    int w;      // ポスターの横の長さ

    int ptn_h;      // 縦の配置パターン
    int ptn_w;      // 横の配置パターン
    int ptn_result; // 配置パターン総計

    scanf("%d\n%d\n%d\n", &n, &h, &w);

    ptn_h = n-h+1;
    ptn_w = n-w+1;
    ptn_result = ptn_h * ptn_w;

    printf("%d", ptn_result);    
}

Measured memory_bytes: 128
a,b,k = map(int, input().split())
setA = set(i for i in range(a,min(a+k,b+1)))
setB = set(j for j in range(b,max(b-k,a-1),-1))
l = list(setA|setB)
l.sort()
for m in l:
  print(m)

Measured memory_bytes: 9200
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;

int main(void)
{
	int i,n;
	int p,j[65000];
	unsigned int psum,jsum;
	int cnt;
	unsigned int kin,mkin;
	
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		psum=0;
		for(i=0;i<n;i++)	{
			scanf("%d",&p);
			psum+=p;
		}
		for(i=0;i<n-1;i++)	{
			scanf("%d",&j[i]);
		}
		sort(j,j+n-1,greater<int>());
		mkin=psum*n;
		jsum=psum;
		for(i=0;i<n-1;i++)	{
			jsum=jsum+j[i];
			kin=(n-(i+1))*jsum;
			if(kin>mkin)	{
				mkin=kin;
			}
		}
		printf("%u\n",mkin);
	}
	return 0;
}


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

#define mod 1000000007
#define lli long long
#define fi first
#define se second
#define pb emplace_back
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(x,v) for(auto x : v)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MAXC 200005
// %

int main(int argc, char **argv)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int d, t, s;
    cin >> d >> t >> s;
    cout << ( t*s >= d ? "Yes\n" : "No\n");
}

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

int main(){
  while(1){
    ll r,c,q;
    cin>>r>>c>>q;
    if(!r&&!c&&!q)return 0;

    ll A[N],B[N],O[N];
    for(int i=0;i<q;i++)cin>>A[i]>>B[i]>>O[i];
    
    ll ans=0,cnt[2]={},rc[]={r,c},used[2][N]={};
    for(int i=q-1;i>=0;i--){
      ll f=A[i],RC=B[i];
      if(used[f][RC]++)continue;
      cnt[f]++;
      ans+=(rc[!f]-cnt[!f])*O[i];
    }
    cout <<ans<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 4932
#include<stdio.h>
#define INFINITY 1000000000

void merge(int*,int,int,int);
void mergesort(int*,int,int);

long long count=0;

int main(){

  int i;
  int n,left,right;

  scanf("%d",&n);
  int N[n];
  for(i=0;i<n;i++){
    scanf("%d",&N[i]);
  }
  left=0;
  right=n;
  mergesort(N,left,right);
  printf("%lld\n",count);
}
void merge(int *N,int left,int mid,int right){

  int i,j,k;
  int r,l;
    
  l=mid-left;
  r=right-mid;
  int L[l],R[r];
  for(i=0;i<l;i++){
    L[i]=N[left+i];
  }
  for(i=0;i<r;i++){
    R[i]=N[mid+i];
  }
  L[l]=INFINITY;
  R[r]=INFINITY;
  
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      N[k]=L[i];
      i++;
    }
    else if(L[i]>R[j]){
      count+=(l-i);
      N[k]=R[j];
      j++;
    }
  }
}
void mergesort(int *N,int left,int right){

  int mid,i;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(N,left,mid);
    mergesort(N,mid,right);
    merge(N,left,mid,right);
  }
}



Measured memory_bytes: 3416
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//221
	int x,a,b;
	cin>>x>>a>>b;
	cout<<x-(((x-a)/b)*b +a);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <utility>
#include <algorithm>

using namespace std;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

template<typename T> 
void show(T a){
  for(auto i : a){ cout << i << " "; }
  cout << endl;
}
template<typename T> 
void showmatrix(T a){
  for(auto j: a){for(auto i : j){ cout << i; }cout << endl;}
  cout << endl;
}
void check(string i = ""){
  cout << "checkpoint:[" << i << "]" << endl;
}

bool check(int y, int m, int d){
  if(y < 2019) return false;
  if(y == 2019 && m < 3) return false;
  if(y == 2019 && m == 4 && d <= 30) return false;
  return true;
}

int main(int argc, char *argv[]){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int year = stoi(s.substr(0, 4));
  string m = s.substr(5, 2);
  int month = stoi(m);
  int day = stoi(s.substr(8, 2));
  if(!check(year, month, day)){
    cout << "Heisei" << endl;
  }
  else{
    cout << "TBD" << endl;
  }
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;
      if(n==0){
        Cout(0);
        return 0;
      }
      while(n!=0){
         ans=n%(-2);
         if(ans==-1){
             ans=1;
             if(n<0){
               n--;
             }
             else{
               n++;
             }
         }
          n/=(-2);
          s+=to_string(ans);
      }
     reverse(all(s));
     Cout(s);
     

       
return 0;
}


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

int h,w,s;
int field[33][33];
int calcsum[33][33];
pair<int,int> memo[33][33][33][33]; // [y][x][y][x]

// (x,y) = (l,t), ??????(l,t), ??????(r,b) ???????????¢???????????????
int getRectDemandSum(int l, int t, int r, int b) {
    int ret = 0;
    ret += calcsum[b][r]; // [y][x]
    if (l - 1 >= 0 && t - 1 >= 0) {
        ret += calcsum[t - 1][l - 1];
    }
    if (t - 1 >= 0) {
        ret -= calcsum[t - 1][r];
    }
    if (l - 1 >= 0) {
        ret -= calcsum[b][l - 1];
    }
    return ret;
}

// <?????§??°???????????°, ?????§?????????>
pair<int,int> solve(int l, int t, int r, int b) {

    if (memo[t][l][b][r].first != -1) return memo[t][l][b][r];

    // ?????¶??????
    int brake = getRectDemandSum(0,0,w-1,h-1) - getRectDemandSum(l,t,r,b);
    pair<int,int> ret = make_pair(0,0);
    if (brake <= s) {
        ret = make_pair(1, brake);
    }
    // ?????´
    for (int x=l; x<r; ++x) {
        pair<int,int> u1 = solve(l,t,x,b);
        pair<int,int> u2 = solve(x+1,t,r,b);
        if (u1.first > 0 && u2.first > 0) {
            pair<int,int> tmp = make_pair(u1.first + u2.first, max(u1.second, u2.second));
            if (ret.first < tmp.first) {
                ret = tmp;
            } else if (ret.first == tmp.first && ret.second > tmp.second) {
                ret = tmp;
            }

            //printf("\tx\t(%d,%d)-(%d,%d) -> (%d,%d)-(%d,%d):[%d %d] & (%d,%d)-(%d,%d):[%d %d]\n", l,t,r,b,l,t,x,b,u1.first,u1.second,x+1,t,r,b,u2.first,u2.second);
        }
    }

    // ?°´???
    for (int y=t; y<b; ++y) {
        pair<int,int> u1 = solve(l,t,r,y);
        pair<int,int> u2 = solve(l,y+1,r,b);
        if (u1.first > 0 && u2.first > 0) {
            pair<int,int> tmp = make_pair(u1.first + u2.first, max(u1.second, u2.second));
            if (ret.first < tmp.first) {
                ret = tmp;
            } else if (ret.first == tmp.first && ret.second > tmp.second) {
                ret = tmp;
            }

            //printf("\ty\t(%d,%d)-(%d,%d) -> (%d,%d)-(%d,%d):[%d %d] & (%d,%d)-(%d,%d):[%d %d]\n", l,t,r,b,l,t,r,y,u1.first,u1.second,l,y+1,r,b,u2.first,u2.second);
        }
    }

    //printf("\tlast\t(%d,%d)-(%d,%d) => %d %d\n",l,t,r,b,ret.first,ret.second);

    return memo[t][l][b][r] = ret;
}

int main() {
    while (cin >> h >> w >> s, h || w || s) {
        // init
        for (int i=0; i<33; ++i) for (int j=0; j<33; ++j)
            for (int k=0; k<33; ++k) for (int l=0; l<33; ++l) memo[i][j][k][l] = make_pair(-1,0);

        for (int i=0; i<h; ++i) {
            for (int j=0; j<w; ++j) {
                cin >> field[i][j];
            }
        }

        // copy
        for (int i=0; i<h; ++i) for (int j=0; j<w; ++j) calcsum[i][j] = field[i][j];

        // ?´???????
        for (int i=0; i<h; ++i) for (int j=1; j<w; ++j) calcsum[i][j] += calcsum[i][j - 1];
        for (int i=1; i<h; ++i) for (int j=0; j<w; ++j) calcsum[i][j] += calcsum[i - 1][j];

        pair<int,int> ans = solve(0,0,w-1,h-1);
        cout << ans.first << " " << s - ans.second << endl;
    }
    return 0;
}

Measured memory_bytes: 12372
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<tuple>
#include<deque>

using namespace std;
int main()
{
    string s;
    int q;
    cin>>s>>q;
    
    map<int,tuple<char,int,int>>ma;
    int ri=0;
    for(int i=0;i<q;++i){
        int qi;cin>>qi;
        if(qi==1){
            ++ri;
        }
        else{
            int fi;char ci;
            cin>>fi>>ci;
            ma[i]=make_tuple(ci,fi,ri);
        }
    }
    
    if(ri%2==1)reverse(s.begin(),s.end());
    deque<char>ds;
    for(auto c:s)ds.push_back(c);
    
    for(auto e:ma){
        tuple<char,int,int>v=e.second;
        if(((ri-get<2>(v))%2==1&&get<1>(v)==2)||((ri-get<2>(v))%2==0&&get<1>(v)==1))
            ds.push_front(get<0>(v));
        else
            ds.push_back(get<0>(v));
    }
    
    for(auto c:ds)cout<<c;
    cout<<endl;
    
    return 0;
}

Measured memory_bytes: 13440
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n;
    cin >> n;
    cout << 1 << " " << 0 << " " << 0 << " " << 1000000000 << " " << (n - 1) / 1000000000 + 1 << " " << (n - 1) % 1000000000 + 1;
}

Measured memory_bytes: 256
a,b,c = map(int,input().split())
if a>b:
    a,b = b,a
else:
    a,b = a,b
if b>c:
    b,c = c,b
else:
    b,c =b,c
if a>b:
    a,b = b,a
else:
    a,b = a,b

print(a,b,c)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
	template <class Arg1, class... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args) {
		const char* sep = strchr(names + 1, ',');
		cerr.write(names, sep - names) << " : " << arg1 << "  ";
		__f(sep + 1, args...);
	}
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<char,int> pci;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plll;
 
 
 
#define pb push_back
 
// order_of_key (k), find_by_order(k)
#define fi first
#define se second
#define input_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>
#define itt iterator
#define initialise(a, x) memset(a, x, sizeof(a))
#define endl '\n'
#define isvowel(a) (a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MAX 1000005
 
#define maxn 3005
#define eps 0.0000001
 
const ll mod=1e9+7;

int n;
double p[maxn];
double dp[maxn][maxn];

double find(int i,int hd)
{
	if(i==n)
	{
		if(hd>n-hd) return 1.0;
		return 0.0;
	}
	if(dp[i][hd]!=-1.0) return dp[i][hd];
	return dp[i][hd]=(p[i]*find(i+1,hd+1))+((1-p[i])*find(i+1,hd));
}



signed main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// freopen("input.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);

	cin>>n;
	for(int i=0;i<n;i++) cin>>p[i];

	for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) dp[i][j]=-1.0;

	cout<<fixed<<setprecision(12)<<find(0,0)<<'\n';


	return 0;
}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
const int mod = 1e9 + 7;
ll modpow(ll a, ll n, ll mod){//a^n-1(mod p)
    ll res = -1;
    while(n > 0){
        if(n & 1)res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll modinv(ll a, ll mod){
    return modpow(a, mod - 2, mod);
}
const int MAX = 10000000;
ll fac[MAX], finv[MAX], inv[MAX];
void comb_init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll n, ll k){
    if(n < k)return 0;
    if(n < 0 || k < 0)return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
    int x, y;
    cin >> x >> y;
    if((2*x-y)%3 != 0 || (2*y-x)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    int n = (2*x-y)/3, m = (2*y-x)/3;
    comb_init();
    cout << combination(n+m, min(n, m)) << endl;
    
    return 0;
}

Measured memory_bytes: 234624
#include <stdio.h>
#include <string.h>
 
int main(void)
{   
    int sum=0;
    int l, i;
    char s[1001];
 
    while(1){
        scanf("%s", s);
        if(s[0] == '0')
            break;
        l = strlen(s);
        for(i=0; i<l; i++){
            sum += s[i] - '0';
        }
        printf("%d\n", sum);
        sum = 0;
    }
    return 0;
}

Measured memory_bytes: 536
import sys
input = sys.stdin.readline
n,C = map(int,input().split())
ch = [[] for _ in range(C)]
tmax = 0
for _ in range(n):
  s,t,c = map(int,input().split())
  ch[c-1].append((s,t))
  tmax = max(tmax,t)
ch = [sorted(i,key= lambda x:x[0]) for i in ch]
imos = [0]*(tmax+2)
for i in ch:
  now = -1
  for ds,dt in i:
    if ds == now:
      imos[ds] +=1
    else:
      imos[ds-1] += 1
    imos[dt] -= 1
    now = dt
for i in range(tmax +1):
  imos[i+1] += imos[i]
print(max(imos))

Measured memory_bytes: 18852
N,M = (int(i) for i in input().split())

a = 0
b = 0

ways = N*[0]

for i in range(M):
    a,b = (int(k) for k in input().split())
    for j in range(1,N+1):
        if (a==j or b==j):
            ways[j-1] = ways[j-1] + 1

for i in range(N):
    print(ways[i])

Measured memory_bytes: 3064
import collections
def solve(n, a_list):

    counter = collections.Counter()

    for i in a_list:
        counter[i] += 1

    ans = sum([v-k if k < v else v for k, v in counter.items() if k != v])

    return ans

if __name__ == "__main__":
    n = int(input())
    a_list = [int(i) for i in input().split()]
    print(solve(n, a_list))

Measured memory_bytes: 18668