akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
 int a, b, c, tmp;
 scanf("%d %d %d", &a, &b, &c);
 if(a > b){
 tmp = a;
 a = b;
 b = tmp;
}
 if(b > c){
 tmp = b;
 b = c;
 c = tmp;
}
 if(a > b){
 tmp = a;
 a = b;
 b = tmp;
}
 printf("%d %d %d\n", a, b, c);
 return 0;
}

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

int main(){
  int d, n;
  cin >> d >> n;
  if(d == 0) {
    if(n < 100)
      cout << n << endl;
    else cout << 101 << endl;
    return 0;
  }
  if(d == 1) d = 100;
  if(d == 2) d = 10000;
  if(n < 100)
    cout << n * d << endl;
  else cout << (n + 1) * d << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main(){
    int h,w;
    std::cin >> h >> w;
    int i,j;
    char x;
    std::vector<std::vector<char>> v(h+2,std::vector<char>(w+2,'0'));
    for(i=1;i<h+1;i++){
        for(j=1;j<w+1;j++){
            std::cin >> x;
            v[i][j]=x;
        }
    }
    int y=0;
    for(i=1;i<h+1;i++){
        for(j=1;j<w+1;j++){
            if(v[i][j]=='.'){
                if(v[i-1][j-1]=='#'){
                    y++;
                }if(v[i][j-1]=='#'){
                    y++;
                }if(v[i+1][j-1]=='#'){
                    y++;
                }if(v[i-1][j]=='#'){
                    y++;
                }if(v[i+1][j]=='#'){
                    y++;
                }if(v[i-1][j+1]=='#'){
                    y++;
                }if(v[i][j+1]=='#'){
                    y++;
                }if(v[i+1][j+1]=='#'){
                    y++;
                }
                std::cout << y;
                y = 0;
            }else{
                std::cout << '#';
            }
        }
        std::cout << std::endl;
    }
    return 0;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int N = 200007;

const ll isQuery = -(1LL << 62);

struct Line {
	ll m, b;int id;
	Line(ll m_, ll b_, int id_) : m(m_), b(b_), id(id_) {}
	mutable multiset<Line>::iterator it, e;
	const Line * succ() const {
		return next(it)==e ? 0 : &*next(it);
	}
	bool operator<(const Line& rhs) const {
		if(rhs.b != isQuery) return m < rhs.m;
		const Line* s = succ();
		if (!s) return 0;
		ll x=rhs.m;
		return b - s->b < (s->m - m) * x;
	}
};

struct DynamicHull : public multiset<Line> {
	bool bad(iterator y) {
		auto z=next(y);
		if(y == begin()) {
			if (z == end()) return 0;
			return y->m == z -> m && y->b <= z->b;
		}
		auto x = prev(y);
		if(z == end()) return y->m == x->m and y->b <= x->b;
		return (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m);
	}

	void insertLine(ll m, ll b, int id) {
		auto y = insert({m, b, id});
		y->it = y;
		y->e = end();
		if(bad(y)) { erase(y); return; }
		while( next(y) != end() and bad(next(y)) ) erase(next(y));
		while(y != begin() and bad(prev(y))) erase(prev(y));
	}

	pair<ll, int> getMax(ll x) {
		auto l = *lower_bound({x, isQuery, 0});
		return {l.m * x + l.b, l.id};
	}
};

ll h[N];
ll f[N];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	ll c;

	cin >> n >> c;

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

	for(int i = n-1; i >= 0; --i) {
		if(i < n-1) f[i] = h[i] * h[i] + c;
		else f[i] = 0;


		if(hull.size()) f[i] -= hull.getMax(h[i]).fi;

		hull.insertLine(2ll * h[i], -(h[i] * h[i] + f[i]), i);
	}

	cout << f[0] << '\n';
}

Measured memory_bytes: 19072
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var t1 = new int[1001];
            var t2 = new int[1001];
            var s = "";
            while ((s = Console.ReadLine()) != "")
            {
                var d = int.Parse(s.Split(',')[0]);
                t1[d]++;
            }
            while ((s = Console.ReadLine()) != null)
            {
                var d = int.Parse(s.Split(',')[0]);
                t2[d]++;
            }
            for (int i = 0; i < 1001; i++)
            {
                if (t1[i] > 0 && t2[i] > 0)
                {
                    Console.WriteLine("{0} {1}", i, t1[i] + t2[i]);
                }
            }
        }
    }
}

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

int main(){
    using tisi = tuple<int, string, int>;
    int N;
    cin >> N; 
    vector<tisi> p(N);

    int val;
    string s; 
    rep(i,N){
        cin >> s >> val;
        p.at(i)=make_tuple(i+1,s,val);
    }
    
    stable_sort(p.begin(), p.end(), 
		[](tisi i, tisi j)->bool {return get<2>(i)>get<2>(j);});

    stable_sort(p.begin(), p.end(), 
		[](tisi i, tisi j)->bool {return get<1>(i)<get<1>(j);});


    rep(i,N){
       // cout << get<0>(p.at(i)) << ' ' << get<1>(p.at(i)) << ' ' << get<2>(p.at(i)) << endl;
       cout << get<0>(p.at(i))<< endl;
    }

    return 0;

}

Measured memory_bytes: 256
package main
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)
func main(){
    stdin := bufio.NewScanner(os.Stdin)
    for stdin.Scan() {
    	R, _ := strconv.Atoi(stdin.Text())
    	if R < 1200 {
          fmt.Println("ABC")
        } else if R < 2800 {
          fmt.Println("ARC")
        } else {
          fmt.Println("AGC")
        }
    }
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main(){
    string s;
    cin>>s;
    if(s[s.size()-1]=='s'){
        cout<<s<<"es"<<endl;
    }
    else{
        cout<<s<<"s"<<endl;
    }
}

Measured memory_bytes: 3632
wordLength,changePlace=input().split(" ")               #文字数と変える文字を読み込む
wordLength = int(wordLength)                            #int変換
changePlace = int(changePlace)                          #int変換
words = input()                                         #文字列の読み込み


words = list(words)                                     #strをリスト型に変換する
words[changePlace - 1] = words[changePlace - 1].lower() #リストの文字を置き換える
correct = "".join(words)                                #str型に戻す
print(correct)                                          #正解を出力する


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define INF 2000000000
#define DESPACITO2 1000000000000000
#define DESPACITO 1000000000000000000
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define vii vector<ii>
#define si set<int>
#define msi map<string,int>
#define REP(i,a,b) for(int i=int(a);i<=int(b);i++)
#define TRvi(c,it) for(vi::iterator it=(c).begin();it!=(c).end();it++)
#define TRvii(c,it) for(vii::iterator it=(c).begin();it!=(c).end();it++)
#define TRmsi(c,it) for(msi::iterator it=(c).begin();it!=(c).end();it++)
 
 
using namespace std;


int main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
    string s,t;
    cin >> s;
    cin >> t;
    REP(i,0,s.length()-1)
    {
    	char ch='y';
    	REP(j,0,s.length()-1)
    	{
    		if(s[(j+i)%(s.length())]!=t[j])
    		{
    			ch='n';
    			break;
    		}
    	}
    	if(ch=='y')
    	{
    		cout << "Yes";
    		return 0;
    	}
    }
    cout << "No";
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n - 1) {
        if(a[i] == a[i+1]){
            ans++;
            a[i + 1] = 100000;
        }
    }
    cout << ans << endl;
}

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

using lli = int64_t;

int main()
{
    lli x; cin >> x;

    lli u = 3500;

    for(lli a = 1; a <= u; a++)
    for(lli b = 1; b <= u; b++)
    {
        lli q = lli(-1) * a * b * x;
        lli w = b * x + a * x - lli(4) * a * b;

        if(!w || q % w || q / w <= 0) continue;

        cout << a << ' ' << b << ' ' << (q / w) << endl;
        return 0;
    }

    assert(0);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n,a,b;
    scanf("%d",&n);
    a = n/100;
    b = n%100;
    if(a>0 && a<13){
        if (b>0 && b<13) {
            printf("AMBIGUOUS");
        }else
        {
            printf("MMYY");
        }
        
        
    }else
    {
        if (b>0 && b<13) {
            printf("YYMM");
        }else
        {
            printf("NA");
        }
        
        
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main ()
{
    int A,B,C;
    scanf("%d %d",&A,&B);
    if(A==3 && B==1 || A==1 && B==3)
    {
    printf("2");
    }
    else if(A==1 && B==2 || A==2 && B==1)

    {
        printf("3");
        }

 else if(A==3 && B==2 || A==2 && B==3)

    {
        printf("1");
        }

        return 0;
}


Measured memory_bytes: 128
#include <iostream>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
int v[1 + nmax];
int pos[1 + nmax];

int main() {
  int n;
  std::cin >> n;
  for(int i = 1;i <= n; i++)
    std::cin >> v[i];
  int smax = 1, sum = 0;
  for(int i = 1;i <= n; i++)
    pos[v[i]] = i;
  for(int i = 1;i <= n; i++) {
    if(pos[i - 1] < pos[i])
      sum++;
    else
      sum = 1;
    smax = std::max(smax, sum);
  }
  std::cout << n - smax;
}


Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define t(x) cerr<<#x<<":"<<x<<'\n';
#define t2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }
#define t3(a){ cerr<<#a<<" = "; for(auto i: a){ cerr<<i<<" "; } cerr<<'\n'; }



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

	int n,m,c;
	cin>>n>>m>>c;
	vector<int> b(m);
	for(int i=0; i<m; ++i){
		cin>>b[i];
	}
	int cnt = 0;
	for(int i=0; i<n; ++i){
		int ans = c;
		for(int j=0; j<m; ++j){
			int x; cin>>x; ans += b[j] * x;
		}
		if( ans > 0 ){ cnt++; }
	}
	cout<<cnt<<endl;

	#ifdef LOL
	    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}


Measured memory_bytes: 256
#
# smbc2019 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """615"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """217"""
        output = """0"""
        self.assertIO(input, output)


def resolve():
    X = int(input())

    n = X // 100
    r = X % 100
    if 0 <= r <= 5*n:
        print(1)
    else:
        print(0)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16156
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;
const lint INF = 1LL << 60;

const double PI = acos(-1);
const double Rad2Deg = 180.0 / PI;
const double Deg2Rad = PI / 180.0;

int main() {
    lint N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    for (int i = 0; i < Q; i++) cin >> A[i];

    vector<int> S(N, 0);
    for (int i = 0; i < Q; i++) {
        ++S[A[i]-1];
    }

    for (int i = 0; i < N; i++) {
        if (K > Q - S[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define Rint register int
#define C(n,m) (n<m?0:1ll*fac[n]*invfac[n-m]%mod*invfac[m]%mod)
using namespace std;
int T,n,m,p,k,st[4010],t=0,A,B;
char ans[4010];
int query(int x,int y){
	printf("? %d %d\n",x,y);
	fflush(stdout);
	char a;
	scanf(" %c",&a);
	return a=='Y';
}
int main(){
	scanf("%d%d",&A,&B);
	if(A<=B) return puts("Impossible"),fflush(stdout);
	n=A+B;
	for(int i=0;i<n;i++){
		if(!t) st[++t]=i;
		else{
			int res=query(st[t],i);
			if(!res) t--;
			else st[++t]=i;
		}
	}
	for(int i=0;i<n;i++){
		if(i!=st[t]) ans[i]=query(st[t],i)+'0';
		else ans[i]='1';
	}
	putchar('!'),putchar(' ');puts(ans);
	fflush(stdout);
}


Measured memory_bytes: 3712
#include <stdio.h>

#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define STRS(i,str) for(int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define MED(a,b,c) ((a)<(b)?(a)>(c)?(a):(b)<(c)?(b):(c):(a)>(c)?(b)<(c)?(c):(b):(a))
#define RNG(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RNG3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXS(a,b) {if((a)<(b))(a)=(b);}
#define MINS(a,b) {if((a)>(b))(a)=(b);}
#define BEGINFOR(a,b,c,d,e,f,g,h,i) a;goto i##_6;i##_2:c;goto i##_6;i##_3:h;goto i##_7;i##_4:d;goto i##_8;i##_5:f;goto i##_8;i##_6:if(b)goto i##_4;else goto i##_9;i##_7:if(g)goto i##_5;else goto i##_1;i##_8:if(e)goto i##_2;else goto i##_3;i##_9:
#define CONTINUE(i) goto i##_3
#define BREAK(i) goto i##_1
#define ENDFOR(i) goto i##_3;i##_1:

int main(){
	int a;
	scanf("%d", &a);
	printf("%d\n", 48 - a);
}

Measured memory_bytes: 128
#include <stdio.h>


int main(int argc, const char * argv[]) {
    // insert code here...
    
    char s[101];
    char p[101];
    
    scanf("%s",s);
    scanf("%s",p);
    
    int flg = 0;
    
    int i=0;
    while(1){
        if(s[i] == '\0'){
            break;
        }
        
        int j=0;
        int k = i;
        while(1){
            if(p[j] == '\0'){
                flg = 1;
                break;
            }
            else if(p[j] != s[k]){
                break;
            }
            
            
            if(s[k+1] == '\0'){
                k=0;
            }
            else{
                k++;
            }
            
            j++;
        }
        
        i++;
    }
    
    
    
    if(flg){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 524
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);


int c[100][100];

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

int dfs(int y,int x){
	int step=0;
	REP(i,4){
		int yy=y+dy[i];
		int xx=x+dx[i];
		if(yy>=0&&xx>=0&&yy<n&&xx<m&&c[yy][xx]){
			c[yy][xx]=0;
			step=max(step,dfs(yy,xx));
			c[yy][xx]=1;
		}
	}
	return step+1;
}

int main(){
	while(cin>>m>>n,m||n){
		REP(i,n){
			REP(j,m){
				cin>>c[i][j];
			}
		}

		int ans=0;
		REP(i,n){
			REP(j,m){
				if(c[i][j]){
					c[i][j]=0;
					ans=max(ans,dfs(i,j));
					c[i][j]=1;
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1188
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int x1,x2,y1,y2;
int main()
{
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
    int disx=x2-x1;
    int disy=y2-y1;
    printf("%d %d ",x2-disy,y2+disx);
    printf("%d %d",x2-disy-disx,y2+disx-disy);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

typedef tuple<ld, int, int> t;
struct star{
  ld x=0, y=0, z=0;
  ld vx=0, vy=0, vz=0;
  ld r=0, vr=0;
  star(ld a, ld b, ld c, ld d, ld e, ld f, ld g, ld h):
  x(a), y(b), z(c), vx(d), vy(e), vz(f), r(g), vr(h){}
  star(){}
};

ld t_dist(ld t, star a, star b){
  ld A = a.x+a.vx*t;
  ld B = a.y+a.vy*t;
  ld C = a.z+a.vz*t;
  ld R = a.r - a.vr*t;
  ld X = b.x+b.vx*t - A;
  ld Y = b.y+b.vy*t - B;
  ld Z = b.z+b.vz*t - C;
  ld R2 = b.r - b.vr*t;
  ld d = sqrt(X*X+Y*Y+Z*Z);
  d = max((ld)0, d - (R + R2));
  return d;
}

ld ternarySearch(ld l, ld r, star x, star y) {
  for(int i=0;i<100;i++) {
    ld a = (l + l + r) / 3;
    ld b = (l + r + r) / 3;
    if (t_dist(a, x, y) > t_dist(b, x, y)) l = a;
    else r = b;
  }
  return l;
}

ld eps = 1e-8;
bool solve(){
  ll n;std::cin >> n;
  if(n==0) return false;
  vector<star> v(n);
  for(int i=0;i<n;i++){
    ld a, b, c, d, e, f, g, h;
    std::cin >>a>>b>>c>>d>>e>>f>>g>>h;
    v[i] = star(a,b,c,d,e,f,g,h);
  }
  multiset<t> q;

  //自然消滅
  for(int i=0;i<n;i++) q.insert(t(v[i].r/v[i].vr, i, -1));

  //対消滅
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      //三分探索？
      ld collide = ternarySearch(0, 10000, v[i], v[j]);
      //if(i==0&&j==1) std::cout << fixed << setprecision(20) << collide << '\n';
      if(collide>100||t_dist(collide, v[i], v[j])>eps) continue;
      q.insert(t(collide, i, j));
    }
  }
  vector<ld> ans(n, 0);
  vector<bool> use(n, false);

  while(!q.empty()){
    t now = *q.begin();
    q.erase(q.begin());
    int x = get<1>(now);
    int y = get<2>(now);
    ld tm = get<0>(now);
    //自然消滅
    if((!use[x])&&y==-1){
      ans[x] = tm;
      use[x] = 1;
    }
    if(use[x]||use[y]) continue;
    use[x] = use[y] = 1;
    ans[x] = ans[y] = tm;
  }
  for(int i=0;i<n;i++) std::cout << fixed << setprecision(20) << ans[i] << '\n';
  return true;
}
int main(int argc, char const *argv[]) {
  while(true) if(!solve()) break;
  return 0;
}



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

int main()
{
  int a, b;
  cin>>a;
  cin>>b;
  if((a == 1 && b == 2) || (a == 2 && b == 1))
  {
    cout<<"3";
  }
  else if((a == 3 && b == 2) || (a == 2 && b == 3))
  {
    cout<<"1";
  }
  else
    cout<<"2";
  return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

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

func main() {
	var k, s int
	k, s = readInt(), readInt()
	cnt := 0
	if k > s {
		k = s
	}
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			if z := s - (x + y); 0 <= z && z <= k {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
using V = vector<int>;
using Vll = vector<ll>;
using VV = vector<V>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

VV G;
V c, dp;
Vll ans;
int s = 0;

ll chs(ll x) {
  return x*(x+1)/2;
}

void dfs(int u, int p=-1) {
  int tmp = s + dp[c[u]];
  ++s;
  for (auto v : G[u]) if (v != p) {
    dp[c[u]] = -s;
    dfs(v, u);
    ans[c[u]] -= chs(s + dp[c[u]]);
  }
  dp[c[u]] = tmp - s;
}

int main() {
  ll n; cin >> n;
  G.assign(n, V());
  c.assign(n, 0);
  dp.assign(n, 0);
  ans.assign(n, n*(n+1)/2);

  rep(i, n) {
    cin >> c[i];
    --c[i];
  }
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs(0);
  rep(i, n) {
    ans[i] -= chs(s + dp[i]);
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 29800
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		final int w = input.nextInt();
		final int h = input.nextInt();
		final int x = input.nextInt();
		final int y = input.nextInt();
		final int r = input.nextInt();
		input.close();
		
		boolean isIn = (0 <= x-r) && (x + r <= w) && (0 <= y - r) && (y + r <= h);
		String answer = isIn ? "Yes" : "No";
		System.out.println(answer);
	}
}

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

int H, W;
vector<vector<char>> S;

typedef pair<int,int> P;

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

int bfs(int si, int sj) {
  queue<P> q;
  vector<vector<int>> d(H, vector<int>(W, INF));
  q.push(make_pair(si, sj));
  d.at(si).at(sj) = 0;
  
  while ( q.size() ) {
    P p = q.front(); q.pop();
    rep(i,4) {
      int ni = p.first + dx.at(i);
      int nj = p.second + dy.at(i);
      if ( 0 <= nj && nj < W && 0 <= ni && ni < H && S.at(ni).at(nj) != '#'
          && d.at(ni).at(nj) == INF ) {
        q.push(make_pair(ni,nj));
        d.at(ni).at(nj) = d.at(p.first).at(p.second) + 1;
      }
    }
  }
  int ret = 0;
  int dd;
  rep(i,H) {
    rep(j,W) {
      dd = d.at(i).at(j);
      if ( ret < dd && dd < INF ) {
        ret = dd;
      }
    }
  }
  return ret;
}

int main() {
  //input
  cin >> H >> W;
  S.resize(H, vector<char>(W));
  rep(i,H) {
    rep(j,W) {
      cin >> S.at(i).at(j);
    }
  }
  //calc
  int answer = 0;
  rep(i,H) {
    rep(j,W) {
      if ( S.at(i).at(j) == '#' ) {
        continue;
      }
      int dist = bfs(i, j);
//      cout << "(" << i << "," << j << ") -> " << dist << endl;
      if ( answer < dist && dist < INF ) {
        answer = dist;
      }
    }
  }
  //output
  cout << answer << endl;
}

Measured memory_bytes: 256
let n = stdin.ReadLine() |> int
let s = seq{for _ in 1.. n -> stdin.ReadLine()}

let combi2 x =int64 x * int64 (x-1L) / 2L
s |> Seq.map (fun str -> str.ToCharArray() |> Array.sort)
|> Seq.countBy (fun x -> x)
|> Seq.filter (fun (_, count) -> count > 1)
|> Seq.sumBy (fun (_, count) -> combi2 <| int64 count)
|> string
|> stdout.WriteLine


Measured memory_bytes: 35460
#include <stdio.h>
int main(){
  int a,b,c,d,e,f,g,h,t;
  while(1){scanf("%d",&t);
  a=1000-t;
  b=a/500;
  c=a%500/100;
  d=a%500%100/50;
  e=a%500%100%50/10;
  f=a%500%100%50%10/5;
  g=a%500%100%50%10%5;
  h=b+c+d+e+f+g;
  if(t==0){return 0;}
  else{
    printf("%d\n",h);}}
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n - i; j++) {
                int k = n - i - j;
                int total = 10000 * i + 5000 * j + 1000 * k;
                if (total == y) {
                    System.out.printf("%d %d %d", i, j, k);
                    return;
                }
            }
        }
        System.out.println("-1 -1 -1");
    }
}


Measured memory_bytes: 23764
n = int(input())
x = []
for i in range(n):
    a,b = map(int,input().split())
    x.append([a,b])
x = sorted(x,key=lambda x:(x[1],x[0]))
t = 0
for i in range(n):
    t+=x[i][0]
    if t>x[i][1]:
        print("No")
        exit()
else:
    print("Yes")




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

int m,n,k=0;
int a[15][15],hnex[15][15],hpre[15][15],wnex[15][15],wpre[15][15],h[15],w[15];
int ans=0,locx,locy;

int solve(int x,int y){
	int ret=0;
	k--;
	bool b[4]={false,false,false,false};
	if(hpre[x][y]!=0){hnex[hpre[x][y]][y]=hnex[x][y]; b[0]=true;}
	if(hnex[x][y]!=0){hpre[hnex[x][y]][y]=hpre[x][y]; b[1]=true;}
	if(wpre[x][y]!=0){wnex[x][wpre[x][y]]=wnex[x][y]; b[2]=true;}
	if(wnex[x][y]!=0){wpre[x][wnex[x][y]]=wpre[x][y]; b[3]=true;}
	if(k==0){
		k++;
		//cout<<"solve("<<x<<","<<y<<")="<<1<<endl;
		if(x==locx||y==locy)return 1;
		//cout<<"solve("<<x<<","<<y<<")="<<0<<endl;
		return 0;
	}
	if(b[0])ret+=solve(hpre[x][y],y);
	if(b[1])ret+=solve(hnex[x][y],y);
	if(b[2])ret+=solve(x,wpre[x][y]);
	if(b[3])ret+=solve(x,wnex[x][y]);
	if(b[0])hnex[hpre[x][y]][y]=x;
	if(b[1])hpre[hnex[x][y]][y]=x;
	if(b[2])wnex[x][wpre[x][y]]=y;
	if(b[3])wpre[x][wnex[x][y]]=y;
	k++;
	//cout<<"solve("<<x<<","<<y<<")="<<ret<<" "<<k<<endl;
	return ret;
}

int main(){
while(1){
	for(int i=0;i<15;i++)for(int j=0;j<15;j++){a[i][j]=4; wnex[i][j]=0; wpre[i][j]=0; hnex[i][j]=0; hpre[i][j]=0;}
	for(int i=0;i<15;i++){h[i]=0; w[i]=0;}
	k=0;
	scanf("%d%d",&m,&n);
	if(m==0&&n==0)break;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
			if(a[i][j]==1){
				k++;
				hnex[h[j]][j]=i;
				hpre[i][j]=h[j];
				h[j]=i;
				wnex[i][w[i]]=j;
				wpre[i][j]=w[i];
				w[i]=j;
				a[i][j]=3;
			}
			if(a[i][j]==2){
				k++;
				locx=i; locy=j;
				hnex[h[j]][j]=i;
				hpre[i][j]=h[j];
				h[j]=i;
				wnex[i][w[i]]=j;
				wpre[i][j]=w[i];
				w[i]=j;
			}
		}
	}
	ans=solve(locx,locy);
	printf("%d\n",ans);
}
}

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

int N,M;
vector<int> edges[100000];

signed main() {
  cin >> N >> M;
  for(int i=0; i<M; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }

  queue<int> q;
  vector<int> d(N, -1);
  vector<int> s(N, -1);
  d[0] = 0;
  q.push(0);
  while(q.size()) {
    int v = q.front(); q.pop();
    for(auto u : edges[v]) {
      if(d[u] != -1) continue;
      s[u] = v;
      d[u] = d[v] + 1;
      q.push(u);
    }
  }

  puts("Yes");
  for(int i=1; i<N; i++) {
    cout << s[i] + 1 << endl;
  }

}


Measured memory_bytes: 10632
use std::io::stdin;

fn main(){
    let hw = getvec();
    let (h, _) = (hw[0], hw[1]);
    let mut img: Vec<String> = Vec::new();
    for _ in 0..h { img.push(getline()) }
    for s in &img{
        for _ in 0..2{
            println!("{}", s);
        }
    }
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec() -> Vec<i64>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

Measured memory_bytes: 4352
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

const MOD: u64 = 1000000007;

#[derive(Clone, Copy)]
struct ModInt {
    v: u64
}

use::std::ops::*;

impl Add for ModInt {
    type Output = ModInt;
    fn add(self, other: ModInt) -> ModInt {
        let mut d = self.v + other.v;
        if d >= MOD {
            d -= MOD;
        }
        ModInt { v: d }
    }
}

impl Sub for ModInt {
    type Output = ModInt;
    fn sub(self, other: ModInt) -> ModInt {
        let mut d = MOD + self.v - other.v;
        if d >= MOD {
            d -= MOD;
        }
        ModInt { v: d }
    }
}

impl Mul for ModInt {
    type Output = ModInt;
    fn mul(self, other: ModInt) -> ModInt {
        let d = self.v * other.v % MOD;
        ModInt { v: d }
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(v: u64) -> ModInt {
        ModInt { v: v % MOD}
    }
    pub fn one() -> ModInt {
        ModInt { v: 1 % MOD}
    }
    pub fn zero() -> ModInt {
        ModInt { v: 0 }
    }
    pub fn pow(r: ModInt, mut n: u64) -> ModInt {
        let mut t = ModInt::one();
        let mut s = r;
        while n > 0 {
            if (n & 1) == 1 {
                t = t * s;
            }
            s = s * s;
            n >>= 1;
        }
        t
    }
}

impl std::fmt::Display for ModInt {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.v)
    }
}

// ここまで

fn run() {
    input! {
        n: usize,
        x: usize,
        s: [u64; n],
    }
    let mut s = s;
    s.sort();
    let mut dp = vec![ModInt::zero(); x + 1];
    for i in 0..(x + 1) {
        dp[i] = ModInt::new(i as u64);
    }
    for i in 0..n {
        let s = s[i] as usize;
        let i = ModInt::new(i as u64);
        for j in (0..(x + 1)).rev() {
            dp[j] = i * dp[j] + dp[j % s];
        }
    }
    println!("{}", dp[x]);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
A,B,C,D,E,F = map(int, input().split())

a = 0
b = 0
c = 0
for s in range(F//A+2):
    for t in range(F//B+2):
        tempa = 100*(s*A + t*B)
        if tempa >= F or tempa == 0:
            continue
        for u in range((F-tempa)//C+2):
            for v in range((F-tempa)//D+2):
                tempb = u*C+v*D
                if tempa+tempb > F:
                    continue
                if tempb/(tempa+tempb) > E/(100+E):
                    continue
                if c < tempb/(tempa+tempb):
                    a = tempa
                    b = tempb
                    c = tempb/(tempa+tempb)
if a+b == 0:
    a = 100*A
print(a+b, b)

Measured memory_bytes: 3064
/*
	Name:
	Author:
	Date:
	Website:
	Description:
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i>0;i++)
    {
        if(i*1000>=n)
        {
            cout<<i*1000 - n;
            return 0;
        }
    }
	return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <cstdio>
 
#define REDIRECT(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define CLOSEALL() fclose(stdin), fclose(stdout)
 
using namespace std;
 
const int MAXN = 3e5 + 10;
 
int N;
pair <int, int> a[MAXN];
 
int main()
{
	//REDIRECT("sort");
 
	int cnt = 0;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++)
		scanf("%d", &a[i].first), a[i].second = i;
	sort(&a[1], &a[N + 1]);
 
	for(int i = 1; i <= N; i++)
		if((a[i].second % 2) != (i % 2))
			cnt++;
 
	printf("%d\n", cnt / 2);
 
	CLOSEALL();
 
	return 0;
}

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

int pow(int a, int n) {
  int val = 1;
  for (int i = 0; i < n; i++)
    val *= a;

  return val;
}

int count5(int n) {
  int val = 0;
  for (int i = 1; pow(5,i) <= n; i++)
    for (int j = pow(5, i); j <= n; j += pow(5, i))
      val++;

  return val;
}

int main() {
  int n;
  while (cin >> n and n != 0) {
    cout << count5(n) << endl;
  }
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<time.h>
#define ll long long
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define miin(a,b,c) min((a), min((b), (c)))
#define maax(a,b,c) max((a), max((b), (c)))

int k, n, a[222222], d=0;
main(){
    scanf("%d%d", &k, &n);
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
        if(i)d = max(d, a[i]-a[i-1]);
    }
    printf("%d\n", min(k-d, a[n-1]-a[0]));
    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  int sum  = 0;
  bool res = false;
  for (int i = a; i <= 10000; i += a) {
    sum += a;
    if (sum % b == c) {
      res = true;
      break;
    }
  }
  if (res) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector <int> vec(a);
  for (int i = 0; i < a; i++) cin >> vec[i];
  sort(vec.begin(), vec.end());
  cout << vec[a - 1] - vec[0] << endl;
}

Measured memory_bytes: 256
// 2014/06/09 Tazoe

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	while(true){
		double v;
		cin >> v;

		if(cin.eof())
			break;

		int N = ceil(v*v/98.0)+1;

		cout << N << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
import sys

#a, b = map(int, input().split(" "))
N = int(input())
S = input()

w = [0 for i in range(N)]
e = [0 for i in range(N)]

if S[0] =='W':
	w[0] = 1
else:
	e[0] = 1

for i in range(1, N):
	if S[i] =='W':
		w[i] = w[i-1]+1
		e[i] = e[i-1]
	else:
		w[i] = w[i-1]
		e[i] = e[i-1]+1	

ans = N
#print(w)
#print(e)
for i in range(N):
	if S[i] =='E':
		total = (w[i]) + (e[N-1]-e[i])
	else:
		total = (w[i]-w[0]) + (e[N-1]-e[i])
	#print(total)
	ans = min(ans, total)
print(ans)

Measured memory_bytes: 17876
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pa = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, M;
    cin >> N >> M;
    vl A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    ll ok = 0, ng = 1e6;
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        ll cnt = 0;
        rep(i, N)
            cnt += A.end() - lower_bound(all(A), mid - A[i]);
        (cnt >= M ? ok : ng) = mid;
    }
    vl sum(N);
    copy(all(A), sum.begin());
    repe(i, 1, N) sum[i] += sum[i - 1];
    ll ans = 0, cnt = 0;
    rep(i, N) {
        ll p = lower_bound(all(A), ng - A[i]) - A.begin();
        if (p == 0)
            ans += sum[N - 1] + A[i] * N;
        else
            ans += sum[N - 1] - sum[p - 1] + A[i] * (N - p);
        cnt += N - p;
    }

    ans += ok * (M - cnt);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(0, min(b, d) - max(a, c)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N, P; cin >> N >> P;
		bool ok = false;
		rep(i, N) { UL a; cin >> a; if (a & 1) ok = true; }
		ULL all = 1ull << N;
		if (ok) cout << (all >> 1) << endl;
		else cout << (P ? 0 : all) << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#define INF 9999999
using namespace std;
typedef long long int ll;

int main() {
	string l;
	cin >> l;
	
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		if (l[i] == '+') ans++;
		else if (l[i] == '-')ans--;
	}

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


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    int[int] c;
    foreach (ai ; a) {
        int b = ai;
        for (int j = 2; j*j <= ai; j++) {
            int t;
            while (b % j == 0) {
                t++;
                b /= j;
            }
            if (j in c) c[j] = max(c[j], t);
            else c[j] = t;
        }
        if (b > 1) {
            if (b in c) c[b] = max(c[b], 1);
            else c[b] = 1;
        }
    }

    debug {
        writeln(c);
    }

    long M = 1;
    foreach (k, v ; c) {
        (M *= k^^v) %= mod;
    }

    long ans;

    foreach (ai ; a) {
        auto b = M * powmod(ai, mod - 2) % mod;
        (ans += b) %= mod;
    }

    writeln(ans);
}


long powmod(int x, int y) {
    return y > 0 ? powmod(x, y>>1)^^2 % mod * x^^(y&1) % mod : 1;
}















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 2684
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
    string n;
    cin >> n;
    int sum;
    for (int i = 0; i < n.length(); i++)
    {
        sum += (int)(n[i] - '0') % 9;
    }
    string ans = "";
    if (0 == sum % 9)
    {
        ans = "Yes";
    }
    else
    {
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3756
#include<stdio.h>
int main()
{
	int i,n,pm,pe,pj;
	while(1){
	scanf("%d",&n);
	if(n==0)
	break;
	for(i=0;i<n;i++){
		scanf("%d %d %d",&pm,&pe,&pj);
		if(pm==100 || pe ==100|| pj ==100)
			puts("A");
		else if((pe+pm)/2>=90)
			puts("A");
		else if((pe+pm+pj)/3>=80)
			puts("A");
		else if((pe+pm+pj)/3>=70)
			puts("B");
		else if(((pe+pm+pj)/3>=50 )&&(pm>=80 ||pe>=80) )
			puts("B");	
		else
			puts("C");
	}
	}
	return 0;
}


Measured memory_bytes: 2044
N, M = map(int, input().split())

if N == 1 and M == 1:
    print(1)
    
elif N == 1 or M == 1:
    print(N*M -2)

elif N == 2 or M == 2:
    print(0)

else:
    print((N-2)*(M-2))


Measured memory_bytes: 2940
#include<stdio.h>
 
int main()
{
  int t[4][3][10]={0};
  int b,f,r,v,i,j,k,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d%d%d%d",&b,&f,&r,&v);
t[b-1][f-1][r-1]=t[b-1][f-1][r-1]+v;

      
    
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	printf(" %d",t[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3)printf("####################\n");
  }
  return 0;
}



Measured memory_bytes: 2092
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
using namespace std;
constexpr int64_t MOD = 1000000007;

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

  //std::string S;
  //cin >> S;
  int32_t K, X;
  cin >> K >> X;
  if (K*500 >= X) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
   } 

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll lv = 0, rv = 1e9;
    while(rv - lv > 1){
        ll mid = (rv + lv) / 2;
        if(mid*mid <= N){
            lv = mid;
        }else{
            rv = mid;
        }
    }
    print(lv*lv);


}

Measured memory_bytes: 256
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int N=1e5+5;
vector<ii>par;


int main(){	
	fastio;
	ll n,m;cin>>n>>m;
	FER(i,0,n){
		ii pp;cin>>pp.ff>>pp.ss;
		par.pb(pp);
	}
	sort(all(par));
	ll tot=0,c=0,i=0;
	while(c<m){
		tot+=par[i].ff*min(m-c,par[i].ss);
		c+=par[i].ss;
		//trace(tot);
		//trace(c);
		i++;
	}
	cout<<tot<<endl;
	return 0;
}


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

int main(){
    long long int H, W;
    cin >> H >> W;
    if(H == 1 || W == 1){
        cout << "1" << endl;
    } else{
        if((H*W)%2==0){
            cout << (H*W)/2 << endl;
        } else {
            cout << (H*W)/2 + 1 << endl;
        }
    }
}

Measured memory_bytes: 256
# xの各位の和を求めるプログラム
def findSomeofDigits(x):
	s = 0
	while x > 0:
		s = s + x % 10
		x = x // 10
	return s

N,A,B = map(int,input().split())
c = 0
for i in range(N):
	s = findSomeofDigits(i+1)
	if A <= s and s <= B:
		c = c + i + 1
print(c)

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

using Graph=vector<vector<int>>;
using Int=long long;
void makeTree(int v,int pre,Graph &g,Graph &t){
    //cerr<<v<<endl;
    for(int i=0;i<g[v].size();i++){
        if(g[v][i]!=pre){
            t[v].push_back(g[v][i]);
            makeTree(g[v][i],v,g,t);
        }
    }
}

pair<Int,Int> solve(vector<int> &vec,Graph& t){
    vector<int> newvec;
    Int dep=0;
    Int pat=vec.size();
    
    while(true){
        dep++;
        Int chi=0;
        for(int i=0;i<vec.size();i++){
            for(int j=0;j<t[vec[i]].size();j++){
                 newvec.push_back(t[vec[i]][j]);
            }
            chi=max(chi,Int(t[vec[i]].size()));
        }
        if(newvec.size()==0) break;
        pat*=chi;
        if(pat>1e20) return make_pair(Int(1e20),Int(1e20));
        vec=newvec;
        newvec=vector<int>();
    }
    return make_pair(dep,pat);
}



int main(){
    int n;
    cin>>n;
    Graph g(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    pair<Int,Int> res(make_pair(Int(1e20),Int(1e20)));
    for(int i=0;i<n;i++){
        Graph t(n);
        makeTree(i,-1,g,t);
        vector<int> vec(1,i);
        res=min(res,solve(vec,t));
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<g[i].size();j++){
            Graph t(n);
            makeTree(i,g[i][j],g,t);
            makeTree(g[i][j],i,g,t);
            vector<int> vec;
            vec.push_back(i);
            vec.push_back(g[i][j]);    
            res=min(res,solve(vec,t));
        }
    }
    cout<<res.first<<" "<<res.second<<endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        String S,T;
        Scanner si=new Scanner(System.in);
        S=si.nextLine();
        T=si.nextLine();
        int i,j=0,count=0;
        for(i=0;i<S.length();i++)
        {
            if(S.charAt(i)!=T.charAt(j))
            {
                count++;
                j++;
            }
            else
            {
                j++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 42540
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        Solver sol = new Solver();
        sol.Solve();
    }
}

class Solver
{
    int N;
    int T;
    int[] t;
    int X;

    public void Solve()
    {
        X = T;
        for(int i = 1; i <= N - 1; i++)
        {
            if (t[i - 1] + T < t[i])
            {
                X += T;
            }
            else
            {
                X += t[i] - t[i - 1];
            }
        }
        Console.WriteLine(X);
    }

    public Solver()
    {
        int[] nt = ReadIntArray();
        t = ReadIntArray();
        N = nt[0];
        T = nt[1];
    }

    static String ReadString() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static long ReadLong() { return long.Parse(Console.ReadLine()); }
    static double ReadDouble() { return double.Parse(Console.ReadLine()); }
    static String[] ReadStringArray() { return Console.ReadLine().Split(' '); }
    static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
    static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
    static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
}



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

using namespace std;

set<char> s;
int n;

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
	char c;
	cin >> c;
	s.insert(c);
    }
    return cout << (s.size() == 3 ? "Three" : "Four"), 0;
}

Measured memory_bytes: 256