akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    string s;
    while(cin >> s && s!="#"){
        vector<string> list;
        list.push_back(s);

        for(char ch='z';ch>='b';ch--){
            vector<string> tmp;
            copy(list.begin(),list.end(),back_inserter(tmp));
            list.clear();
            while(!tmp.empty()){
                string str=tmp.back();
                tmp.pop_back();

                int p=str.length();
                for(int i=0;i<str.length();i++){
                    if(str[i]==ch){
                        p=i;
                        break;
                    }
                }
                for(int i=0;i<p;i++){
                    if(str[i]==ch-1){
                        string w=str;
                        w[i]=ch;
                        list.push_back(w);
                    }
                }
                if(p==str.length()) list.push_back(str);
            }
        }
        
        sort(list.begin(),list.end());
        int n=list.size();

        cout << n << endl;
        for(int i=0;i<min(5,n);i++) cout << list[i] << endl;
        if(n<=10){
            for(int i=5;i<n;i++) cout << list[i] << endl;
        }else{
            for(int i=5;i>=1;i--) cout << list[n-i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4344
#include<stdio.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i = 0;i < n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a+b==c||b+c==a||c+a==b){
    PRS("Yes");
  }else{
    PRS("No");
  }
  return 0;
}
/*
scanf("%d",&n);
scanf("%d %d",&a,&b);
*/

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<bitset>
#include <numeric>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define LONG_INF 9223372036854775807
#define INF 1000000000LL
#define EPS 1e-10
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define dump(a) rep(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define all(v) v.begin(),v.end()
#define pb push_back

#define INT 1.01

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

    int64_t X;
    cin >> X;

    int64_t v = 100;
    //while(true){
    rep(ret, INF){
        if(X<=v){
            cout << ret << endl;
            break;
        }
        //v *= INT;
        v += 0.01*v;
    }

    //cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	ll r,s,p;
	cin>>r>>s>>p;
	string t;
	cin>>t;
	vector<vector<ll>> dp(n+1,vector<ll>(3,0));
	rep(i,n){
		rep(j,3){
			dp[i+1][j]+=max({dp[i][0],dp[i][1],dp[i][2]});
		}
		if(i<k){
			if(t[i]=='r'){
				dp[i+1][2]+=p;
			}else if(t[i]=='s'){
				dp[i+1][0]+=r;
			}else if(t[i]=='p'){
				dp[i+1][1]+=s;
			}
		}else{
			if(t[i]=='r'){
				if(t[i]==t[i-k]){
					if(dp[i+1-k][2]==dp[i+1-k][1]){
						dp[i+1][2]+=p;
					}
				}else{
					dp[i+1][2]+=p;
				}
			}else if(t[i]=='s'){
				if(t[i]==t[i-k]){
					if(dp[i+1-k][1]==dp[i+1-k][0]){
						dp[i+1][0]+=r;
					}
				}else{
					dp[i+1][0]+=r;
				}
			}else if(t[i]=='p'){
				if(t[i]==t[i-k]){
					if(dp[i+1-k][2]==dp[i+1-k][1]){
						dp[i+1][1]+=s;
					}
				}else{
					dp[i+1][1]+=s;
				}
			}
		}
	}
	//cout<<dp<<endl;
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
}

Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f3f3f3f;
#define ms(a,k)  memset(a,k,sizeof(a))
int a;
int main()
{
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++)cin>>a,ans=__gcd(ans,a*1LL);
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 256
// C++のテンプレート
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
    string s;
    cin >> s;
    string res = "";
    for(int i=0;i<s.size();i++){
        if(s[i] == '0'){
            res = res + "0";
        }else if(s[i] == '1'){
            res = res + "1";
        }else{
            if(!res.empty())
                res.pop_back();
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;


int main(){
  int a, b;
  scanf("%d %d", &a, &b);
  if(a + b == 15){
    printf("+\n");
  }else if(a*b == 15){
    printf("*\n");
  }else{
    printf("x\n");
  }
  return 0;
}


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

using namespace std;

const int mod = 1000000007;

string K;
int D;
int dp[2][102];

void add(int &a, int b) {
	a = (a+b)%mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> K >> D;

	dp[0][0] = 0;
	int cur = 0;
	int prev = 1;

	int dc;
	int csum = 0;
	for (int i = 0; i < K.length(); i++) {
		dc = K[i] - '0';
		swap(prev, cur);

		fill(dp[cur], dp[cur]+D, 0);
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < D; k++) {
				int nx = (k + j)%D;
				add(dp[cur][nx], dp[prev][k]);
			}
		}

		// cout << "meh: " << dp[cur][0] << endl;

		for (int j = 0; j < dc; j++) {
			// cout << i << " this" << endl;
			int nx = (csum + j)%D;
			// cout << " --- "  << nx << endl;
			add(dp[cur][nx], 1);
		}

		csum = (csum + dc)%D;

		// for (int j = 0; j < D;  j++) {
			// cout << i << " " <<j << " : " << dp[cur][j] << endl;
		// }
	}

	if (csum == 0) {
		add(dp[cur][0], 1);
	}
	add(dp[cur][0], mod-1); //subtract out 0

	cout << dp[cur][0] << endl;
	
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	static class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		public FastScanner(InputStream source) {
			in = source;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte()) return buffer[ptr++];
			else return -1;
		}

		private static boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args){

		solve_abc162_b();
	}

  	public static void solve_abc162_b(){

		FastScanner sc = new FastScanner(System.in);

		long a = sc.nextLong();
		long sum = 0;
		
		for(int i=1;i<=a;i++){
			if((i % 3 != 0) && (i % 5 != 0)){
				sum += i;
			}
		}
		
		System.out.println(sum);

	}
}
  

Measured memory_bytes: 27120
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        String word ;
        String ans="";
        Scanner input =  new Scanner(System.in);
        word=input.nextLine();

        for(int i =0 ;i<word.length();i++){
            if(word.charAt(i)!='B'){
                ans+=word.charAt(i);
            }
            else{
                if(ans.length()==0){
                    continue;
                }
                else{

                    ans = ans.substring(0, ans.length() - 1);
            }
        }}



        System.out.println(ans);



    }
}

Measured memory_bytes: 20692
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % mod; a = a * a % mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head

const int MAXN = 1000000 + 5;

inline int getC(int n, int m) {
	if ((n & m) == m) return 1;
	return 0;
}

int a[MAXN];

int calc(int len) {
	int ans = 0;
	rep(i, 0, len) {
		ans ^= (getC(len-1, i) * a[i]);
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
#ifdef RG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	string s;
	cin >> s;
	bool flag1 = false;
	rep(i, 0, n) {
		a[i] = s[i] - '1';
		//if (a[i] == 2) a[i] = 1 << 10;
		if (a[i] == 1) flag1 = true;
	}

	if (!flag1) {
		rep(i, 0, n) a[i] /= 2;
	}

	int t = calc(n);
	if (flag1) cout << (t&1) << endl;
	else cout << 2 * t << endl;

	return 0;
}

Measured memory_bytes: 5276
n,m=map(int, input().split())
a=list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
x=[]
for i in range(n):
    x.append([a[i],1])
for i in range(m):
    x.append([bc[i][1],bc[i][0]])
x.sort(reverse=True)
ans=0
count=n
for i in range(n):
    if x[i][1]<count:
        ans+=x[i][0]*x[i][1]
    else:
        ans+=x[i][0]*count
    count-=x[i][1]
    if count<=0:
        break
print(ans)


Measured memory_bytes: 47048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int a = 10 * A + B + C;
		int b = 10 * B + A + C;
		int c = 10 * C + A + B;

		System.out.println(Math.max(a, Math.max(c, b)));
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a==2&&b==2)
  {
    cout<<"Yes"<<endl;
  }
  else if((a==1||a==3||a==5||a==7||a==8||a==10||a==12)&&(b==1||b==3||b==5||b==7||b==8||b==10||b==12))
  {
    cout<<"Yes"<<endl;
  }
  else if((a==4||a==6||a==9||a==11)&&(b==4||b==6||b==9||b==11))
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
}
    

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;


long long c[2001][2001];

int main(){

    long DIV = 1e9 + 7;

    int n, k; 
    cin >> n >> k;

    int Nmax = max(n-k+1, k-1);

    for(int i=0; i<=Nmax; i++){
        for(int j=0; j<=Nmax; j++){
            if(j <= i){
                c[i][j] = 1;
            }
            else{
                c[i][j] = 0;
            }
        }
    }  

    for(int i=2; i<=Nmax; i++){
        for(int j=1; j<=i; j++){
            c[i][j] = (c[i-1][j] + c[i-1][j-1]) % DIV;
        }
    }

    for(int i=0; i<=Nmax; i++){
        for(int j=0; j<=Nmax; j++){
            if( j > i ){
                c[i][j] = 1;
            }
        }
    }

    for(int i=1; i<=k; i++){
        if(i <= n - k + 1){
            cout << (c[n-k+1][i] * c[k-1][i-1]) % DIV << endl;
        }
        else{
            cout << 0 << endl;
        }
    }

    return 0;
}

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

int main() {
	double t, x;
	cin >> t >> x;
	cout << t / x << endl;

}

Measured memory_bytes: 256
def solve(s, x, y):
    first_t = s.find('T')
    if first_t == -1:
        return x == len(s) and y == 0

    def update(move):
        ncx = set()
        cx = cxy[is_x]
        for x in cx:
            ncx.add(x + move)
            ncx.add(x - move)
        cxy[is_x] = ncx

    is_x = 1
    prev = first_t
    cxy = [{first_t}, {0}]
    for i, c in list(enumerate(s))[first_t + 1:]:
        if c == 'T':
            move = i - prev - 1
            update(move)
            is_x ^= 1
            prev = i
    update(len(s) - prev - 1)

    return x in cxy[0] and y in cxy[1]


s = input()
x, y = map(int, input().split())
print('Yes' if solve(s, x, y) else 'No')


Measured memory_bytes: 4580
const main = (input) => {
  const n = Number(input)
  let result = n-1
  for (let i = 1; i*i <= n; i++) {
    if (n%i === 0) {
    　const num = i + n/i - 2
      result = num < result ? num : result
    }
  }
  console.log(result)

  
  
  
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

void solve_test() {
	int n;
	cin >> n;

	vector<int> div(n + 1);
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j += i)
			div[j]++;

	int total = 0;
	for (int c = 1; c < n; c++)
		total += div[n - c];

	cout << total << '\n';
}

int main() {
	int T;
	T = 1;
	for (int t = 1; t <= T; t++)
		solve_test();

	return 0;
}


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

#define jk(i,j,k) for (int i = (j); i <= (k); i++)
#define kj(i,j,k) for (int i = (j); i >= (k); i--)
#define int long long
#define lb long double
#define ul unsigned long long
#define mp std::make_pair
#define pb push_back
#define pr(a,b) printf(a, b)
#define sc(a,b) scanf(a, &b)
#define x first
#define y second
#define al(x) (x).begin(), (x).end()
#define me(a) memset((a), 0, sizeof(a))

inline int rd() { int data = 0, w = 1; char ch = 0; while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar(); (ch == '-') && ( w = -1, ch = getchar() ); while (ch >= '0' && ch <= '9') { data = data * 10 + ch - '0'; ch = getchar(); } return data * w; }
inline void P (int v) { if (v < 0) { putchar('-'); v = -v; } if (v > 9) P(v / 10); putchar(v % 10 + '0'); }

signed main () {
	int a, b;
	a = rd(); b = rd();
	P(a * b / std::__gcd(a, b));
    return 0;
}

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

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    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 COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

const int D = 80 * 160 + 10;
const int D2 = D*2;
typedef bitset<D2> bs;
int a[100][100];
bs dp[90][90];



const int N = 20;
int h;
int w;
vector<vector<char>> maze(N, vector<char>(N,'#'));

const int MAX_WH = 21;
int d[MAX_WH][MAX_WH];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const int INF = 1001001001;
int bfs(int x, int y) {
    queue<P> que;
    rep(i,MAX_WH) {
        rep(j,MAX_WH) {
            d[j][i] = INF;
        }
    }
    que.push(P(x,y));
    d[x][y] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        for (int i=0; i< 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int mx = 0;
    rep(i,h) rep(j,w) {
            if (d[j][i] == INF) continue;
            mx = max(mx, d[j][i]);
        }
    return mx;
}

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}
void dfs(){

}
const int MX = 100000;
vector<int> G[MX];

int main(){
    int n; cin >> n;
    map<string, int> m;
    int mx = 0;
    rep(i,n) {
        string s; cin >> s;
        m[s]++;
        mx = max(m[s],mx);
    }
    vector<string> ans;
    for (auto p : m){
        if (p.second == mx) {
            ans.push_back(p.first);
        }
    }
    sort(ans.begin(),ans.end());
    rep (i,ans.size()) {
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 30964
#6 Dubious Document 2
s=input()
t=input()
ls=len(s)
lt=len(t)

cand=[]
for i in range(ls-lt+1):
    scut =s[i:i+lt]
#    for j,tt in enumerate(t):
    if all(tt==ss or ss=="?" for tt,ss in zip(t,scut) ):
        cand.append(i)
        
ans=[]
for c in cand:
    ans.append( (s[:c]+ t+ s[c+lt:]).replace("?","a") )

if len(ans)==0:
    print("UNRESTORABLE")
else:
    print(min(ans))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define int long
#define mp make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
signed main(){
  int n;
  cin>>n;
  if(n%2)return cout<<0,0;
  int two=0,five=0;
  int k=2;
  while(n/k>0)two+=n/k,k*=2;
  k=5;
  n/=2;
  while(n/k>0)five+=n/k,k*=5;
  cout<<min(two,five);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int dx[4]={-1,1,0,0};
int dy[4]={0,0,1,-1};
typedef pair<int,int> P;
int main(){
  int n;
  cin >> n;
  int t[n];P z[n+1];
  z[0].first=0;z[0].second=0;t[0]=0;
  for(int i=1;i<=n;i++){
    cin >> t[i];
    cin >> z[i].first>>z[i].second;
  }
  for(int i=0;i<n;i++){
    int ti=t[i+1]-t[i];
  int d=abs(z[i].first-z[i+1].first)+abs(z[i].second-z[i+1].second);
  if(ti<d){
    cout <<"No"<<endl;
    return 0;
  }
  else{
    if((ti-d)%2!=0) {
      cout <<"No"<<endl; return 0;
    }
  }
}
cout <<"Yes"<<endl;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main()
{
    long long int x;
    scanf("%lld",&x);
    
    long long int y = (long long int)x/500;
    long long int z = x - y*500;
    long long int a  = (long long int)z/5;
    long long int ans = 1000*y + 5*a;
    printf("%lld",ans);
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
 int N,flag=0;
 cin>>N;
for(int i=0;i<=N/4;i++){
    for(int j=0;j<=N/7;j++){
        if(4*i+7*j==N) flag=1;
    }
}
if(flag) p("Yes");
else p("No");
}

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

#define N_MAX 100

long L[2 * N_MAX];

int comp(const void* a, const void* b){
    return *(long*)a - *(long*)b;
}

int main(void){
    long i, N, ans = 0;
    scanf("%ld", &N);
    for(i = 0; i < 2 * N; i++) scanf("%ld", &(L[i]));
    qsort(L, 2 * N, sizeof(long), comp);
    for(i = 0; i < N; i++) ans += L[2 * i];
    printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 128
parseInt(x) = parse(Int, x)
n = parseInt(readline())
K=split(readline())
x=map(x->parse(Int,x),K)
ans = n * 101^2

for i in 1:100
    sum = 0
    for j in 1:n
        sum += (x[j] - i)^2
    end
    if sum < ans
        ans = sum
    end
end
print(ans)

Measured memory_bytes: 110344
N,M = map(int,input().split())
key = []
for i in range(M):
  a,b = map(int,input().split())
  C = list(map(int,input().split()))
  s = 0
  for i in range(b):
    C[i] -=1 #oindex
    s = s|1<<C[i] #それぞれの宝箱の番号で左シフトしてorをとることでどの宝箱を開けられるかを保存。
  key.append((s,a)) #開けられる宝箱とコストを保存
#print(key)
INF = float("inf")  
dp = [INF for _ in range(1<<N)]
dp[0] = 0
#配るDP O(2^N*M)
for s in range(1<<N): #小さい順からやるとうまく遷移ができる。
  for i in range(M): #すべてのカギについて遷移を試す。
    t = s|key[i][0] #現在の宝箱の状態sに対して、新しい鍵を加えたときに開けられる宝箱の状態。 
    dp[t] = min(dp[t],dp[s] + key[i][1])
#print(dp)
if dp[-1] == INF:
  ans = -1
else:
  ans = dp[-1]
print(ans)

Measured memory_bytes: 9276
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  int res = 0, cur = 0;
  rrep(i,n,1) {
    if(h[i] <= h[i-1]) cur++;
    else cur = 0;
    res = max(res, cur);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 640
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

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

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var n, k int
var h []int
var dp [][]int

func dfs(i, kk int) int {
	if dp[i][kk] != -1 {
		return dp[i][kk]
	}
	if i == n-1 {
		return 0
	}
	if i+kk+1 < n && kk+1 <= k {
		dp[i][kk] = min(dfs(i, kk+1), dfs(i+kk+1, 0)+abs(h[i]-h[i+kk+1]))
	} else {
		dp[i][kk] = dfs(i+kk, 0) + abs(h[i]-h[i+kk])
	}
	return dp[i][kk]
}

func main() {
	n = readInt()
	k = readInt()
	h = make([]int, n)
	for i := range h {
		h[i] = readInt()
	}
	dp = make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, k+1)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}

	fmt.Println(dfs(0, 0))
}


Measured memory_bytes: 111616
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cd = [list(map(int, input().split())) for _ in range(M)]
for student in ab:
    minimum = 1e+9
    for i, check in enumerate(cd):
        distance = abs(student[0] - check[0]) + abs(student[1] - check[1])
        if minimum > distance:
            ans = i+1
            minimum = distance
    print(ans)


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

const int M=5e5+5;
const int MO=1e9+7;
inline int add(int x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
	return x;
}
inline int sub(int x,int y)
{
	x-=y;
	if(x<0) x+=MO;
	return x;
}
inline int mul(int x,int y)
{
	return 1LL*x*y%MO;
}
inline void addv(int &x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
}
inline void subv(int &x,int y)
{
	x-=y;
	if(x<0) x+=MO;
}
inline void mulv(int &x,int y)
{
	x=1LL*x*y%MO;
}
 
int inv[M],fa[M],ifa[M];
void init()
{
	fa[0]=ifa[0]=1;
	inv[1]=fa[1]=ifa[1]=1;
    for(int i=2;i<M;i++)
    {
    	fa[i]=mul(fa[i-1],i);
    	inv[i]=mul(MO-MO/i,inv[MO%i]);
    	ifa[i]=mul(inv[i],ifa[i-1]);
    }
}
 
int C(int n,int m)
{
	if(n<m) return 0;
	return mul(mul(fa[n],ifa[m]),ifa[n-m]);
}

int A(int n,int m)
{
	return mul(fa[n],ifa[n-m]);
}

int main()
{
	init();
	int n,m; scanf("%d%d",&n,&m);
	int ans=mul(A(m,n),A(m,n));
	//cout<<ans<<endl;
	for(int i=1;i<=n;i++)
	{
		int nans=mul(C(n,i),A(m,i));
		nans=mul(nans,mul(A(m-i,n-i),A(m-i,n-i)));
		if(i&1) subv(ans,nans);
		else addv(ans,nans);
		//cout<<ans<<endl;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9656
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A.at(i);
    
    int c1=0;
    for(int i=0; i<N; i++){
        if(A.at(i)!=i+1){
            c1++;
        }
        if(c1>2) break;
    }
    
    if(c1==2 || c1==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int n;
char s[105];
int main(){
    scanf("%d%s",&n,s+1);
    bool flag = 1;
    if(n&1)
        flag = 0;
    else{
        int tmp = n>>1;
        for(int i=1;i<=tmp;++i)
            if(s[i]!=s[tmp+i])
                flag = 0;
    }
    if(flag)
        printf("Yes");
    else
        printf("No");
    return 0;
}

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


namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();

            int n = int.Parse(a);


            int[] s = new int[13];
            int[] h = new int[13];
            int[] c = new int[13];
            int[] d = new int[13];

            for (int i = 0; i < n; i++)
            {
                string[] ss = Console.ReadLine().Split(' ');
                string mark = ss[0];
                int rank = int.Parse(ss[1]);

                if (mark == "S")
                {
                    s[rank - 1] = 1;
            
                }
                if (mark == "H")
                {
                    h[rank - 1] = 1;

                }

                if (mark == "C")
                {
                    c[rank - 1] = 1;

                } 
                if (mark == "D")
                {
                    d[rank - 1] = 1;

                }

            }
            for (int one = 0; one < 13; one++) 
            {
                if (s[one] != 1)
                {
                    Console.WriteLine("S "+(one+1));
                }

            }
            for (int two = 0; two < 13; two++)
            {
                if (h[two] != 1)
                {
                    Console.WriteLine("H " +(two+1));
                }
            }
            for (int three = 0; three < 13; three++)
            {
                if (c[three] != 1)
                {
                    Console.WriteLine("C " + (three+1));
                }
            }
            for (int four = 0; four < 13; four++)
            {
                if (d[four] != 1)
                {
                    Console.WriteLine("D " + (four+1));
                }
            }


        }
    }
}

Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int a[100];
	int b,sum=0,point;
	while(1){
		cin >> b;
		if(b==0) break;
		for(int i=0;i<b;i++){
			cin >> a[i];
			
		}
		sort(a,a+b);
		for(int j=1;j<b-1;j++){
			sum+=a[j];
		}
		point=sum/(b-2);
		cout << point << endl;
		sum=0;
		
	}
	return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))

#define rdi(i) ll i; scanf("%lld", &i)
#define rds(s) string s; cin >> s
#define rdc(c) char c; cin >> c

#define INF 10000000000
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

vector<ll> as;
vector<vector<ll>> vs;
vector<ll> result;
vector<ll> work;

void dfs(ll n, ll from)
{
    auto it = lower_bound(work.begin(), work.end(), as[n]);
    bool replaced = false;
    decltype(it) index;
    ll orig = -1;
    if (it != work.end()) {
        replaced = true;
        index = it;
        orig = *it;
        *it = as[n];
    }
    result[n] = lower_bound(work.begin(), work.end(), INF) - work.begin();
    rep(i, vs[n].size()) {
        if (vs[n][i] != from) {
            dfs(vs[n][i], n);
        }
    }
    if (replaced) {
        *it = orig;
    }
}

int main()
{
    ll n;
    cin >> n;
    as.resize(n);
    vs.resize(n);
    result.resize(n, 0);
    work.resize(n, INF);
    rep(i, n) {
        cin >> as[i];
    }
    rrep(i, 1, n) {
        ll u, v;
        cin >> u >> v;
        --u; --v;
        vs[u].push_back(v);
        vs[v].push_back(u);
    }
    dfs(0, -1);
    rep(i, n) {
        cout << result[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 29956
#include<bits/stdc++.h>
using namespace std;
int h,heap[500001];
void maxHeapify(int i){
    int left,right,largest;
    left=i*2;
    right=left+1;
    if(left<=h&&heap[i]<heap[left]) largest=left;
    else largest=i;
    if(right<=h&&heap[largest]<heap[right]) largest=right;
    if(largest!=i){
        swap(heap[i],heap[largest]);
        maxHeapify(largest);
    }
}
int main(){
    scanf("%d",&h);
    for(int i=1;i<=h;++i) scanf("%d",&heap[i]);
    for(int i=h/2;i>0;--i) maxHeapify(i);
    for(int i=1;i<=h;++i) printf(" %d",heap[i]);
    putchar('\n');
    return 0;
}

Measured memory_bytes: 5068
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    long long int n,ans1=0,ans2=0,bans=0,c1,c2;
    cin>>n;
    long long int a[n],b[n];
    REP(i,n)cin>>a[i];
    REP(i,n)b[i]=a[i]-i-1;
    sort(b, b+n);
    c1=b[(n-1)/2];
    c2=b[(n/2)-1];
    REP(j,n){
        ans1+=abs(a[j]-(j+1+c1));
        ans2+=abs(a[j]-(j+1+c2));
    }
    cout<<min(ans1,ans2)<<endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(void){
  	int n;
  int sum = 0;
  int a = 0;
  	cin >> n;
  	vector<int> vec(n);
  for(int k = 0; k < n; k++){
    	cin >> vec.at(k);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int i = 0; i < n; i=i+2){
    	sum += vec.at(i);
  }
  for(int j = 1; j < n; j = j + 2){
    	a += vec.at(j);
  }
  cout << sum - a << endl;
}
  
  


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	long long ans = 0;
	for (int i = K + 1; i <= N; ++i) {
		int sub = (N + 1) / i * (i - K);
		if ((N + 1) % i >= K) {
			sub += (N + 1) % i - K;
		}
		ans += sub;
		if (K == 0) --ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    string s;
    cin >> s;
    bool f = 1;
    for(int i = 0;i < s.length();++i){
        if((i+1) % 2 == 0){
            if(s[i] == 'R') {
                f = 0;
                break;
            }
        }
        else {
            if(s[i] == 'L'){
                f = 0;
                break;
            }
        }
    }
    if(f) cout << "Yes";
    else cout << "No";


    return 0;
}

Measured memory_bytes: 256
s=gets.chomp
ss=s.delete ?x
c=true
(ss.size/2).times do |i|
  if ss[i]!=ss[ss.length-1-i]
    c=false
  end
end
cc=0
if c
  cc=0
  t=s.size-1
  tt=0
  while true do
    break if tt>=t
    if s[t]==?x
      if s[tt]==?x
        t-=1
        tt+=1
      else
        t-=1
        cc+=1
      end
    else
      if s[tt]==?x
        tt+=1
        cc+=1
      else
        t-=1
        tt+=1
      end
    end
  end
end
puts c ? cc : -1


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

int A[3];

signed main()
{
  REP(n,3) {
    cin >> A[n];
  }

  if(A[0] == A[1] && A[0] != A[2]) {
    cout << "Yes" << endl;
  } else if(A[0] == A[2] && A[0] != A[1]) {
    cout << "Yes" << endl;
  } else if(A[1] == A[2] && A[0] != A[1]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
k = int(input())

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(a[k - 1])

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

//Math/ModInt
template<long long mod = 1000000007>
struct modint{
	long long a;

	constexpr modint() : a(0){}
	constexpr modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	constexpr operator long long() const{ return a; }

	constexpr bool operator==(const modint &x) const{ return a == x.a; }
	constexpr bool operator!=(const modint &x) const{ return a != x.a; }

	constexpr modint operator-() const{ return modint(a ? (mod - a) : 0); }
	constexpr modint operator~() const{ return pow(mod - 2); }

	constexpr modint operator+(const modint &x) const{ return modint(*this) += x; }
	constexpr modint operator-(const modint &x) const{ return modint(*this) -= x; }
	constexpr modint operator*(const modint &x) const{ return modint(*this) *= x; }
	constexpr modint operator/(const modint &x) const{ return modint(*this) /= x; }

	constexpr modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	constexpr modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	constexpr modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	constexpr modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	constexpr modint &operator++(){ return (*this) += 1; }
	constexpr modint &operator--(){ return (*this) -= 1; }
	constexpr modint &operator++(int){
		modint tmp = *this;
		(*this) += 1;
		return tmp;
	}
	constexpr modint &operator--(int){
		modint tmp = *this;
		(*this) -= 1;
		return tmp;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	constexpr modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

//Math/Combination
template<class T>
struct Combination{
	vector<T> fact,factinv;
	Combination(int n) : fact(n + 1),factinv(n + 1){
		fact[0] = 1;
		for(int i = 1;i <= n;i++) fact[i] = fact[i - 1] * T(i);
		factinv[n] = ~fact[n];
		for(int i = n;i >= 1;i--) factinv[i - 1] = factinv[i] * T(i);
	}
	T nCr(int n,int r){
		if(r < 0 || n < r) return 0;
		return fact[n] * factinv[r] * factinv[n - r];
	}
};

const int MOD = 1000003;

signed main(){
	int q;
	scanf("%d",&q);
	Combination<modint<MOD>> comb(MOD - 1);
	for(int i = 0;i < q;i++){
		int x,d,n;
		scanf("%d %d %d",&x,&d,&n);
		modint<MOD> mx = x,md = d,a = mx / md;
		if(!d) printf("%d\n",mx.pow(n));
		else if(n >= MOD || (int)a > (int)(a + modint<MOD>(n - 1))) puts("0");
		else printf("%d\n",comb.fact[(int)a + n - 1] * comb.factinv[(int)a - 1] * md.pow(n));
	}
}


Measured memory_bytes: 16512
n = int(input())

a = list(map(int, input().split()))

ans = 0
cost = float('inf')
count = 0

for i in a:
    ans += abs(i)
    cost = min(cost,abs(i))
    if i < 0:
        count += 1

if 0 not in a:
    # count = max(count,n-count)
    if count % 2 != 0:
        ans -= 2*cost

print(ans)

Measured memory_bytes: 14412
#include <cassert>
#include <cmath>
#include <iostream>

int main()
{
    double x = 0;
    double y = 0;
    double a = M_PI_2;
    while(true){
        int d, t;
        char c;
        std::cin >> d >> c >> t;
        if(d == 0 && t == 0) break;
        x += d * std::cos(a);
        y += d * std::sin(a);
        a += (-t * M_PI / 180);
    }
    std::cout << int(x) << std::endl;
    std::cout << int(y) << std::endl;
    return 0;
}

Measured memory_bytes: 3252
N=int(input())
tmp = input().split()
A=[0]*N
ind=[0]*N
for i in range(N):
    card=tmp[i]
    A[i]=int(card[1])
    ind[i]=i

def BubbleSort(A,N):
    A_bubble=A[:]
    ind_bubble=ind[:]
    flag=1
    while flag:
        flag=0
        j=0
        for i in range(N-1-j):
            if A_bubble[i] > A_bubble[i+1]:
                a=A_bubble[i]
                A_bubble[i]=A_bubble[i+1]
                A_bubble[i+1]=a
                flag=1
                a=ind_bubble[i]
                ind_bubble[i]=ind_bubble[i+1]
                ind_bubble[i+1]=a
    return ind_bubble


def SelectionSort(A,N):
    A_selection=A[:]
    ind_selection=ind[:]
    for i in range(N):
        mini=i
        for j in range(i+1,N):
            if A_selection[j] < A_selection[mini]:
                mini=j
        if mini != i:
            a=A_selection[i]
            A_selection[i]=A_selection[mini]
            A_selection[mini]=a
            a=ind_selection[i]
            ind_selection[i]=ind_selection[mini]
            ind_selection[mini]=a
    return ind_selection


i_b=BubbleSort(A,N)
i_s=SelectionSort(A,N)
ans_b=[]
ans_s=[]
for i in range(N):
    ans_b.append("".join([tmp[i_b[i]][0],tmp[i_b[i]][1]]))
    ans_s.append("".join([tmp[i_s[i]][0],tmp[i_s[i]][1]]))

print(*ans_b)
print("Stable")
print(*ans_s)
if ans_b != ans_s:
    print("Not stable")
else:
    print("Stable")



Measured memory_bytes: 5620
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<math.h>
#include<stack>
#include<sstream>
#include<queue>
#include<list>
#include<iomanip>
#include<bitset>
#include<limits.h>
#include <bits/stdc++.h>
#define MOD  1000000007
#define BIG  1000000005
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define pi pair<int,int>;
typedef long long ll;
using namespace std;

bool calc(int arr){
    if(!(arr&1) && arr!=2){return 1 ;}
for(int i = 3 ; i*i<=arr ; i+=2){
    if(arr%i==0){
        return 1 ;
    }
    if( (arr/i)%arr == 0 )
        return 1;
}
return 0 ;
}
int main()
{
    //freopen("input.txt", "r", stdin);
     int n ;
     cin >> n ;
    for(int i = 31 ; i<55555 ; i+=30 ){
            if(!calc(i) ){
        if(i!=31)cout<< " " ;
        cout << i ;
        n-- ;
            }
            if(n == 0 )break ;
    }
       cout << endl ;
            return 0 ;

}


Measured memory_bytes: 256
Limit = 1500000

until (given = $<.gets.split.map(&:to_i)) == [0, 0]
  m, n = given
  books = n.times.map {$<.gets.to_i}
  
  f = ->(width) {
    need = 1
    sum = 0
    books.each do |book|
      return false if book > width
      sum += book
      if sum > width
        need += 1
        sum = book
      end
    end
    need <= m    
  }
  
  puts (1..Limit).bsearch {|width| f.(width)}
end



Measured memory_bytes: 6864
n = gets.to_i

a = gets.split(' ').map(&:to_i)

b = Hash.new(0)
sum = Hash.new(0)

a.each do |i|
 b[i] += 1 
end

b.each_key do |k|
 sum[k] = b[k]*(b[k]-1)/ 2
end

total = 0
sum.each_key do |k|
 total += sum[k] 
end

a.each do |k|
 cnt = b[k]
 if cnt > 1
  puts total - sum[k] + (cnt-1)*(cnt-2)/2  
 else
  puts total
 end
end

Measured memory_bytes: 36876
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
        int n;
        cin >> n;
        string s[n];
        char t,u;
        bool flag=true;
        rep(i,n){
                cin  >> s[i];
        }
        rep(i,n){
                for(int j=i+1; j<n; j++) {
                        if(s[i]==s[j]) {
                                flag=false;
                        }
                }
        }
        rep(i,n-1){
                if(s[i][s[i].size()-1]!=s[i+1][0]) {
                        flag=false;
                }
        }
        if(flag) {
                cout << "Yes" << endl;

        }else{
                cout << "No" << endl;

        }

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep (i, N) {
    int a; cin >> a;
    A[i] = a - (i + 1);
  }
  sort(A.begin(), A.end());
  
  int b;
  if (N > 2) {
    if (N & 1) b = A[N / 2];
    else b = (A[N / 2 - 1] + A[N / 2]) / 2;
  } else if (N == 2) {
    b = (A[0] + A[1]) / 2;
  } else if (N == 1) {
    b = A[0];
  }

  ll ans = 0;
  for (auto v : A) ans += abs(v - b);

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


Measured memory_bytes: 4052
#include<stdio.h>

int main(){

  int n, i; 
  int F[44];

  scanf("%d", &n);

  F[0] = 1;
  F[1] = 1;

  for ( i = 2; i <= n; i++ ) {
    F[i] = F[i-1] + F[i-2];
  }
  
  printf("%d\n", F[n]);

  return 0;
}

Measured memory_bytes: 596
n,m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

lcm = a.map{|i|i/2}.sort.reverse.inject{|s,r|s.lcm(r)}

if a.map{|i|i.to_s(2).reverse.index(?1)}.uniq.size != 1
  ans = 0
else
  ans = (m-lcm)/(lcm*2)+1
end
p ans

Measured memory_bytes: 15736