akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long 
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M 			200011
#define LN             14
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
}
set<pii> st;
map<pii,ll> mp;

int main(){
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    ll h,w;
    cin>>h>>w>>n;
    vector<pii> v;
    lp(0,n-1)cin>>x>>y,v.pb({x,y});
    for(auto x:v){
      mp[x]=1;
      for(i=0;i<3;++i){
        for(j=0;j<3;++j){
          if(x.F-i>=1&&x.S-j>=1&&x.F-i+2<=h&&x.S-j+2<=w)st.ins({x.F-i,x.S-j});
        }
      }
    }
    vii ans(10);
    for(auto x:st){
      p=0;
      for(i=0;i<3;++i){
        for(j=0;j<3;++j){
          p+=mp[{x.F+i,x.S+j}];

        }
      }
      ans[p]++;

      // trace(x.F,x.S,p);

    }
    p=0;
    lp(1,9)p+=ans[i];
    ans[0]=(h-2)*(w-2)-p;
    lp(0,9)cout<<ans[i]<<"\n";






}



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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j;i>=k;i--)
#define FORR(i,j,k,l) for(int i=j;i<=k;i+=l)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c)    scanf("%d %d %d", &a, &b, &c)
#define clean(mat,n)   FOR(i,0,n) mat[i].clear()
#define minn          (long long)-1000000000000000000
#define maxx          (long long) 1000000000000000000
#define mod          1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define LL           long long
#define NL '\n'
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define PB push_back
#define F first
#define S second
#define MAX 200010
#define MP make_pair
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
typedef pair<int,int> PR;

int ar[MAX];
int n;
LL prin;

int main()
{
    ios::sync_with_stdio(false);
   /// inf;
    //outf;

    cin >> n;
    FOR(i,0,n-1)
    {
        cin >> ar[i];
    }

    FOR(i,0,n-1)
    {
        if(ar[i] > i)
        {
            prin = -1;
            break;
        }

        if(i != 0 && ar[i] == ar[i - 1] + 1) prin++;
        else if(i != 0) prin += ar[i];
    }

    int c;
    REV(i,n-1,0)
    {
        if(i == n-1) c = ar[i];
        else
        {
            if(ar[i] < c)
            {
                prin = -1;
                break;
            }
            c = max(c, ar[i]);
        }
        c--;
    }

    cout << prin << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <chrono>
#include <complex>
#include <cstdint>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <regex>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        regex  re = regex("^A?KIHA?BA?RA?$");
        string s;
        in >> s;
        bool ans = regex_match(s, re);
        out << (ans ? "YES" : "NO") << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=[]
  for _ in range(n):
    l.append(I())

  l.sort()
  sm=sum(l)
  if sm%10!=0:
    return sm

  for x in l:
    if (sm-x)%10!=0:
      return sm-x

  return 0

print(main())


Measured memory_bytes: 5652
n = 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[n-1])

Measured memory_bytes: 3060
/*
How to lambda
  ex) sort(ALL(cont),[](dat a,dat b){return a.l<b.l;});
lower_bound/upper_bound
  1 2 2 2 3 3 
    ^lb   ^ub */
#include <bits/stdc++.h>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define assign_if_greater(V, T) V=max(V,T)
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  cout << fixed << setprecision(15);
  int A,B,K;
  cin >> A >> B >>K;
  for(int i=100;i>=1;--i) {
    if (A%i==0&&B%i==0) {
      K--;
      if (K==0) {
        cout << i << endl;
        exit(0);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map< string, set< int > > memo;

int isalldigit(const string& str)
{
  for(int i = 0; i < str.size(); i++){
    if(!isdigit(str[i])) return false;
  }
  return true;
}

bool dahara(const string& str){
  int foo = 0;
  for(int i = 0; i < str.size(); i++){
    if(str[i] == '(') foo++;
    else if(str[i] == ')') foo--;
    else if(foo == 0) return false;
  }
  return true;
}

set< int > expr(string str)
{
  if(memo.find(str) != memo.end()){
    return memo[str];
  }

  set< int > ret;

  int foo = 0 ;
  if(isalldigit(str)){
    ret.insert(atoi(str.c_str()));
  } else if (dahara(str)){
    return memo[str] = expr( str.substr( 1, str.size() - 2));
  } else {
    for(int i = 0; i < str.size(); i++){
      if(str[i] == '('){ //開き括弧だなぁ
        foo++;
        continue;
      } else if(str[i] == ')'){ //閉じ括弧だなぁ 
        foo--;
        continue;
      } else if(isdigit(str[i])){ //数字はどうでもいいなぁ
        continue;
      }
      if(foo == 0){
        set< int > hori = expr(str.substr( 0, i));
        set< int > tkc = expr(str.substr( i + 1));
        for(set< int >::iterator msy = hori.begin(); msy != hori.end(); msy++){
          for(set< int >::iterator mtur = tkc.begin(); mtur != tkc.end(); mtur++){
            if(str[i] == '+'){
              ret.insert( *msy + *mtur);
            } else if(str[i] == '-'){
              ret.insert( *msy - *mtur);
            } else if(str[i] == '*'){
              ret.insert( *msy * *mtur);
            } else {
              if(*mtur == 0) continue;
              ret.insert( *msy / *mtur);
            }
          }
        }
      }
    }
  }
  return memo[str] = ret;
}


int main()
{
  string s;
  while(cin >> s, s != "#"){
    cout << expr(s).size() << endl;
  }
}

Measured memory_bytes: 1756
n,m=map(int,input().split())
p = 10**9+7

def pfact(m):
	pf = {}
	for i in range(2,int(m**0.5)+1):
		while m%i==0:
			pf[i]=pf.get(i,0)+1
			m//=i
	if m>1:pf[m]=1
	return pf


def cmb(n, r, p):
	if (r < 0) or (n < r):
		return 0
	r = min(r, n - r)
	return fact[n] * factinv[r] * factinv[n - r] % p

N = 3 * 10 ** 5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
	fact.append((fact[-1] * i) % p)
	inv.append((-inv[p % i] * (p // i)) % p)
	factinv.append((factinv[-1] * inv[-1]) % p)

#テンプレ終わり

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

factlist = pfact(m).values()

ans = 1

for i in factlist:
	ans = ans * cmb(i+n-1,i,p) % p

print(ans % p)

Measured memory_bytes: 39056
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    int ans = 0;
    For(i, n){
        if(a[i] == i+1){
            ans ++;
            if(i < n-1) swap(a[i], a[i+1]);
        }
    }
    Cout(ans);
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
int main() {
  int x, y, z;
  int i;
  scanf("%d %d %d", &x, &y, &z);
  for (i = 1; y * i + z * (i + 1) <= x; i++) {}
  printf("%d\n", i - 1);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int player_num;
	static int[] sum;
	
	static void erase_row_data(int[][] data, int match) {
		for(int r = 0; r < player_num; r++) {
			int buf = data[r][match]; //比較データ
			boolean flag = true;
			for(int c = 0; c < player_num; c++) {
				if(data[c][match] == buf && c != r) {
					data[c][match] = 0; //同じ得点があったら消去
					flag = false;
				}
			}
			if(!flag) data[r][match] = 0;
		}
	}
	
	static void calc_sum(int[][] data, int match) {
		for(int r = 0; r < player_num; r++) {
			sum[r] += data[r][match];
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		
		player_num = stdIn.nextInt();//プレイヤーの人数
		final int match = 3; //試合数
		int[][] data = new int[player_num][3];//登録データ
		
		for(int r = 0; r < player_num; r++) {
			for(int c = 0; c < match; c++) {
				data[r][c] = stdIn.nextInt();
			}
		}
		
		for(int r = 0; r < match; r++) 
			erase_row_data(data, r);
		sum = new int[player_num];
		for(int r = 0; r < match; r++)
			calc_sum(data, r);
		
		for(int r = 0; r < player_num; r++)
			System.out.println(sum[r]);
	}
}

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

int main(void) {
  int a, b, c, d;

  scanf("%d %d %d %d ", &a, &b, &c, &d);

  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
   
int main(){
int w,h;
while(true){
std::cin>>h;
std::cin>>w;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
std::cout<<"#";
}
std::cout<<std::endl;
}
if(w==0&&h==0){
break;
}
std::cout<<std::endl;
};
return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
namespace IO{/*{{{*/
	const int S=5000005;
	char inbuf[S];
	int pos;
	void Load(){
		fread(inbuf,1,S,stdin);
		pos=0;
	}
	char getChar(){
		return inbuf[pos++];		
	}
	char getC(){
		char c=getChar();
		while(c!='.'&&c!='#') c=getChar();
		return c;
	}
	int getInt(){
		char c=getChar();
		int x=0,f=1;
		while(c<'0'||c>'9'){if(c=='-')f=-1;c=getChar();}
		while('0'<=c&&c<='9'){x=x*10+c-'0';c=getChar();}
		return x*f;
	}
	ll getLong(){
		char c=getChar();
		ll x=0,f=1;
		while(c<'0'||c>'9'){if(c=='-')f=-1;c=getChar();}
		while('0'<=c&&c<='9'){x=x*10+c-'0';c=getChar();}
		return x*f;
	}
}/*}}}*/
using IO::getC;
using IO::getInt;
using IO::getLong;
const int N=1005;
const int MOD=1e9+7;
int n,m,blacksum;
ll kk;
char str[N][N];
int map[N][N];
int hcnt,vcnt,lh,lv;
inline void plus(int &x,int y){
	x=(x+y>=MOD)?(x+y-MOD):x+y;
}
inline void swap(int &x,int &y){
	x^=y^=x^=y;
}
inline int fmi(int x,ll y){
	int res=1;
	for(;y;x=1LL*x*x%MOD,y>>=1)
		if(y&1)
			res=1LL*res*x%MOD;
	return res;
}
struct Mat{/*{{{*/
	int n,m;
	int a[4][4];
	Mat(){
	}
	Mat(int _n,int _m){
		n=_n; m=_m;
		clear();
	}
	void setUnit(){
		if(n!=m) return;
		for(int i=1;i<=n;i++)
			a[i][i]=1;
	}
	void clear(){
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
				a[i][j]=0;
	}
	friend Mat operator * (Mat &u,Mat &v){
		Mat res=Mat(u.n,v.m);
		for(int i=1;i<=u.n;i++)
			for(int j=1;j<=v.m;j++)
				for(int k=1;k<=u.m;k++)
					plus(res.a[i][j],1LL*u.a[i][k]*v.a[k][j]%MOD);
		return res;
	}
}O,T;/*}}}*/
void readData(){
	IO::Load();
	n=getInt(); m=getInt(); kk=getLong();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			str[i][j]=IO::getC();
			blacksum+=(str[i][j]=='#');
		}
}
int getTypeAndInit(){
	for(int i=1;i<=n;i++)
		hcnt+=(str[i][1]=='#'&&str[i][m]=='#');
	for(int j=1;j<=m;j++)
		vcnt+=(str[1][j]=='#'&&str[n][j]=='#');
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(j<m)
				lh+=(str[i][j]=='#'&&str[i][j+1]=='#');
			if(i<n)
				lv+=(str[i][j]=='#'&&str[i+1][j]=='#');
		}
	if(hcnt&&vcnt) return 1;
	else if(!hcnt&&!vcnt) return 2;
	if(hcnt){
		swap(hcnt,vcnt);
		swap(lh,lv);
	}
	return 3;
}
void fillMatrix(){
	O=Mat(1,3);
	O.a[1][1]=blacksum; O.a[1][2]=lv; O.a[1][3]=vcnt;
	T=Mat(3,3);
	T.a[1][1]=blacksum;
	T.a[2][2]=blacksum; T.a[3][2]=lv;
	T.a[3][3]=vcnt;
}
Mat mat_fmi(Mat x,ll y){
	Mat res=Mat(x.n,x.n);
	res.setUnit();
	for(;y;x=x*x,y>>=1)
		if(y&1)
			res=res*x;
	return res;
}
void solve(){
	fillMatrix();
	T=mat_fmi(T,kk-2);
	O=O*T;
	int ans=O.a[1][1]-O.a[1][2];
	printf("%d\n",ans<0?ans+MOD:ans);
}
int main(){
	readData();	
	if(kk<=1){
		puts("1");
		return 0;
	}
	int type=getTypeAndInit();
	if(type==1)//whole
		puts("1");
	else if(type==2)//isolated
		printf("%d\n",kk==0?1:fmi(blacksum,kk-1));
	else
		solve();
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int n,d,x;
  cin>>n>>d>>x;
  int cho=x;
  rep(i,n){
    int a;
    cin>>a;
    //cout<<(d-1)/a+1<<endl;;
    cho+=(d-1)/a+1;
  }
  cout<<cho<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
using lint = long long;
using P = pair<int, int>;

int F, H, I, J, K, L, M, N, S, T, U;
// lint F, H, I, J, K, L, M, N, S, T, U;
// string S, T;
string ans;

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

	cin >> N >> M;

	if (N == M) {
		ans = "Yes";
	} else {
		ans = "No";
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int ev=0;
  if(n!=1)ev=n*(n-1)/2;
  int odd=0;
  if(m!=1)odd=m*(m-1)/2;
  cout<<odd+ev<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  
  if (n < 1 || n > 100000)
  {
    cout << "Invalid number of ID cards" << endl;
    return 1;
  }
  else if (m < 1 || m > 100000)
  {
    cout << "Invalid number of Gates" << endl;
    return 1;
  }

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

  int left, right;  
 
  left = min (a, b);
  right = max (a, b);
  
  while (cin)
  {
    left = max (a, left);
    right = min (b, right);
    
    cin >> a >> b;
  }
  
  int numGates = 0;
  for (int i = left; i <= right; i++)
  {
    numGates++;
  }
  cout << numGates << endl;
  
  return 0;
}
      
int min (int a, int b) {
  if (a <= b) return a;
  else return b;
}

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


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0; i < n; i++){
			s[i] = sc.next();
		}
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		for(int i = 0; i < n; i++){
			int[] a = new int[10];
			for(int j = 0; j < 10; j++){
				a[j] = s[i].charAt(j);
			}
			Arrays.sort(a);
			String b = "";
			for(int j = 0; j < 10; j++){
				b+=b + a[j];
			}
			if(map.containsKey(b)){
				map.put(b,map.get(b)+1);
			}else{
				map.put(b,0);
			}
		}
		long ans = 0;
		Iterator<String> it = map.keySet().iterator();
		while (it.hasNext()) {
			String key = it.next();
			long tmp = (long)map.get(key)*(map.get(key)+1)/2;
			ans+=tmp;
		}
		System.out.print(ans);
	}
}


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

using static Input;
using static Util;
class Program
{
    static int N, M;
    static Queue<int>[] G;
    static int[] T;
    static void INPUT()
    {
        N = NextInt();
        M = NextInt();
        G = new Queue<int>[N + 1];
        T = new int[N + 1];
        for (int i = 0; i <= N; i++)
        {
            G[i] = new Queue<int>();
        }
        for (int i = 0; i < M; i++)
        {
            var s = NextInt();
            var t = NextInt();

            G[s].Enqueue(t);
            T[t]++;
        }
    }

    static void OUT()
    {
        var s = new Queue<int>();
        var dp = new int[N + 1];
        for (int i = 1; i < T.Length; i++)
        {
            if (T[i] == 0) s.Enqueue(i);
        }

        while(s.Count > 0)
        {
            var n = s.Dequeue();
            foreach (var nn in G[n])
            {
                T[nn]--;
                if (T[nn] == 0) s.Enqueue(nn);
                dp[nn] = dp[n] + 1;
            }
        }

        var max = 0;
        foreach (var nn in dp)
        {
            max = Math.Max(max, nn);
        }
        Console.WriteLine(max);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 29828
use std::io;
fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned();
    let mut ws = s.split_whitespace();
    let a: i32 = ws.next().unwrap().parse().unwrap();
    let b: i32 = ws.next().unwrap().parse().unwrap();
    let c: i32 = ws.next().unwrap().parse().unwrap();
    let d: i32 = ws.next().unwrap().parse().unwrap();

    if a + b < c + d {
        println!("Right");
    }
    else if (a + b > c + d){
        println!("Left");
    }
    else {
        println!("Balanced");
    }
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
#define _ << ' ' <<
#define _squ(x)  ((x) * (x))
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define line_debug(var)  do{std::cout << "l" << __LINE__ << " " << #var << " : "; view(var);}while(0)
#define _max(v)  *max_element(v.begin(), v.end())
#define _min(v)  *min_element(v.begin(), v.end())
#define _sort(var)  std::sort(var.begin(), var.end());
#define _rsort(var)  std::sort(var.begin(), var.end(), std::greater<>());
using namespace std;
using ll = long long;
int gcd(int m, int n){return !n ? m : gcd(n, m%n);}
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> void view(const T e){ std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){ for(const auto& e : v) std::cout << e << " "; std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T>>& vv){ for(const auto& v : vv){ view(v); } }

int main(){
	string S;
	cin >> S;
	int dif = 0;
	for(int i=0; i<S.length()/2; ++i) {
		if(S[i]!=S[S.length()-1-i]) dif++;
	}
	cout << dif << endl;
	return 0;
}


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

int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(k, 60) {
    ll odd = 0, even = 0;
    rep(j, n) a[j] >> k & 1 ? odd++ : even++;
    ll sum = odd * even % mod;
    rep(j, k) sum = sum * 2 % mod;
    ans += sum;
    ans %= mod;
  }
  cout << ans << endl;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int K; cin >>K;
    ANS((K/2)*((K+1)/2));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
//#define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 3e5 + 5;

int n;
char s[N];
int pre[N], suf[N];

void run() {
    cin >> s + 1;
    for(int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1];
        if(s[i] == 'W') ++pre[i];
    }
    suf[n + 1] = 0;
    for(int i = n; i >= 1; i--) {
        suf[i] = suf[i + 1];
        if(s[i] == 'E') ++suf[i];
    }
    int ans = n + 1;
    for(int i = 1; i <= n; i++) {
        ans = min(ans, pre[i - 1] + suf[i + 1]);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
#ifdef Local
    freopen("../input.in", "r", stdin);
    freopen("../output.out", "w", stdout);
#endif
    while(cin >> n) run();
    return 0;
}


Measured memory_bytes: 2944
N, M = map(int, input().split())
heights = list(map(int, input().split()))

roots = [[] for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    roots[a-1].append(b-1)
    roots[b-1].append(a-1)

ans = 0
for i in range(len(roots)):
    root = roots[i]
    if not root:
        ans += 1
        continue
    good = True
    for j in root:
        if heights[i] <= heights[j]:
            good = False
            break
    if good:
        ans += 1

print(ans)


Measured memory_bytes: 29428
//NAME-ADITYYA OJHA
                                               /*
                                                      GURU(MENTOR)-AARADHYA
                                               */
/*
 *     Heart beats fast
 *         Colors and promises
 *             How to be brave
 *                 How can I love when I am afraid to fall...
                                             (courtesy-amnesiac_dusk)
 */

#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007
using namespace std;

/*
check for corner cases(for n==1)
 check for int overflow
 run on some sample cases before submitting
*/

/*FERMAT THEOREM

       pow(x,m-1)%m=1 (x and m are co-prime)
*/
/*MODULAR INVERSE

        pow(x,-1)=pow(x,m-2) (x and m are co-prime)
*/

/*
ll  mode(ll x,ll n,ll mod)
{
    if(n==0)return 1%mod;

    ll u=mode(x,n/2,mod);
    u=(u*u)%mod;
    if(n & 1)u=(u*x)%mod;
}
*/
const ll INF=1e11+ 5;
int main()
{
   fast;
    ll n;
    cin>>n;
    if(n%1000==0)
        cout<<0<<endl;
        else
        {
            ll z= (n/1000 + 1)*1000-n;
            cout<<z<<endl;
        }


}


































Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll N, K;
vector<ll> ball;
set<ll> pool;
vector<ll> countnum;

int main() {
    cin >> N >> K;
    ball.resize(N); countnum.resize(N+1);
    for (int i = 0; i < N; i++) scanf("%Ld", &ball[i]);
    for (int i = 0; i < N; i++) countnum[ball[i]]++;
    sort(countnum.begin(), countnum.end(), greater<ll>());
    ll sum = 0;
    for (int i = K; i < countnum.size(); i++) sum += countnum[i];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
  string s;
  cin >> s;
  if(s.length()==2) {
    cout << s << endl;
  } else {
    for(int i=2; i>=0; i--){
      cout << s[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
from collections import deque

H,W = map(int,input().split())
C = list(map(int,input().split()))
D = list(map(int,input().split()))

F = [["#"]*(W+4)]
F += [["#"]*(W+4)]
F += [["#"]+["#"]+list(input())+["#"]+["#"] for _ in range(H)]
F += [["#"]*(W+4)]
F += [["#"]*(W+4)]

res = [[-1]*(W+4) for _ in range(H+4)]

Q = deque()
Q2 = deque()
Q.append([C[0]+1,C[1]+1])
Q2.append([C[0]+1,C[1]+1])
f_n = True
nd = ((0,1),(0,-1),(1,0),(-1,0))
bnum = 0

while f_n:
  f_n = False
  while len(Q)>0:
    x,y = Q.popleft()
    Q2.append([x,y])
    for dx,dy in nd:
      xx = x+dx
      yy = y+dy
      if F[xx][yy] == "." and res[xx][yy] == -1:
        Q.append([xx,yy])
        res[xx][yy] = bnum
  bnum += 1
  while len(Q2)>0:
    x,y = Q2.popleft()
    for i in range(-2,3):
      for j in range(-2,3):
        xx = x+i
        yy = y+j
        if F[xx][yy] == "." and res[xx][yy] == -1:
          Q.append([xx,yy])
          res[xx][yy] = bnum
          f_n = True
        

print(res[D[0]+1][D[1]+1])

Measured memory_bytes: 135096
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
int add(int a, int b) {a=(a%mod + b%mod)%mod;return a;}
int sub(int a, int b) {a =(a%mod - b%mod + mod)%mod ;return a;}
int mul(int a, int b) {return (a%mod * b%mod) % mod;}
 
/* brownsands :Arpit */		

void solve()
{   int i,j,k,x,ans=0;
    cin >> k;
    for(i=1;i<=k;i++)
    for(j=1;j<=k;j++)
    for(x=1;x<=k;x++)
    ans+=__gcd(i,__gcd(j,x));

    cout << ans;
}
signed main()
{ 
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int test=0,t;
  //  cin>>t;
    t=1;
   while(test++ <t){         
   	//cout<<"Case# "<<test<<": ";
        solve();}
  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
  }


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

int main() {
  long long A, B, C, K, max;
    cin >> A >> B >> C >> K;
    ((A + B) > K) ? (max = min(A, K)) : (max = (A * 2LL + B - K));
    cout << max << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
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;}
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a)  (a).begin(),(a).end()
#define P pair<int, int>
#define ll long long
const int MOD = 1000000007;
//bitset<64>(x).count()
//fixed << setprecision(15) << 

int main(){
  int m[3][3];
  rep(i, 3){
    rep(j, 3)
      cin >> m[i][j];
  }
  int a[3], b[3]={};
  rep(i,3)
    a[i] = m[i][0];
  b[1] = m[0][1] - a[0];
  b[2] = m[0][2] - a[0];
  string ans = "Yes";
  rep(i, 3){
    rep(j, 3){
      if(m[i][j]!=a[i]+b[j])
        ans = "No";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
#include <iostream>

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

    return 0;
}


Measured memory_bytes: 3096
from math import floor,sqrt
x = int(input())

if x==2 :
  print(2)
  exit()
elif x == 3:
  print(3)
  exit()
else:
  pass

while True:
  if all(x % i != 0 for i in range(2,int(floor(sqrt(x)))+1)) == True:
    print(x)
    exit()
  else:
    x += 1

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-9;

bool dp[10010];

int main() {
	int n;	cin >> n;
	vint s(n);
	rep(i, n)	cin >> s[i];
	dp[0] = true;
	rep(i, n) {
		rrep(j, 10010-s[i]) {
			dp[j + s[i]] |= dp[j];
		}
	}
	rrep(i, 10010) {
		if (dp[i] && i % 10 != 0) {
			cout << i << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

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

typedef long long ll;

int cou;
int m;
ll g[1000000];

int setg(int n){
    int ret=0;
    bool flg=true;
    for(int i=2;i<1000000;i++){
        g[i]=3*g[i-1]+1;
        if(g[i]>=n&&flg){
            ret=i-1;
            flg=false;
            break;
        }
    }
    return ret;
}

void insertsort(vector<int> &v,int n, int h){
    for(int i=0;i<h;i++){

        for(int j=i+h;j<n;j+=h){
            for(int k=j;k>=h;k-=h){
                if(v[k]<v[k-h])swap(v[k],v[k-h]);
                else break;
                cou++;
            }
        }

    }
}

void shell(vector<int> &v,int n){
    cou=0;
    g[1]=1;
    m=setg(n);

    for(int i=m;i>=1;i--){
        insertsort(v,n,g[i]);
    }
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> vc(n);
    for(int i=0;i<n;i++)cin >> vc[i];

    shell(vc,n);

    cout << m << endl;
    for(int i=m;i>=1;i--)cout << g[i] << (i!=1?" ":"\n");
    cout << cou << endl;
    for(int i=0;i<n;i++){
        cout << vc[i] << endl;
    }

}



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

int main (){
    int n;
    string str ;
    cin >> n >> str ;  
    int loc = 0;
    int ans = 1;
    while((loc + 1) != str.length()){
        if(str[loc] != str[loc+1]) ans++;
        loc++;
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define int long long
#define P pair<int,int>

const int N = 505;
int board[N][N];
bool visited[N][N];

struct points{
    int x;
    int y;
    int nx;
    int ny;
};

signed main() {
    int h,w;
    cin >> h >> w;

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

    vector<points> ans;

    bool flag = true;
    for(int i = 1; i <= h; i++){
        if(flag){
            for(int j = 1; j <= w; j++){
                if(j == w) {
                    if(i == h) continue;
                    if(board[i][j] % 2 == 1) {
                        board[i+1][j]++;
                        points V = {i,j,i+1,j};
                        ans.push_back(V);
                    }
                } else {
                    if(board[i][j] % 2 == 1) {
                        board[i][j + 1]++;
                        points V = {i,j,i,j+1};
                        ans.push_back(V);
                    }
                }
            }
        } else {
            for(int j = w; j >= 1; j--){
                if(j == 1) {
                    if(i == h) continue;
                    if(board[i][j] % 2 == 1) {
                        board[i+1][j]++;
                        points V = {i,j,i+1,j};
                        ans.push_back(V);
                    }
                } else {
                    if(board[i][j] % 2 == 1) {
                        board[i][j - 1]++;
                        points V = {i,j,i,j-1};
                        ans.push_back(V);
                    }
                }
            }
        }
        flag = !flag;
    }

    cout << ans.size() << endl;
    for(auto i: ans){
        cout << i.x << " " << i.y << " " << i.nx << " " << i.ny << endl;
    }
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[15];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }

    {
        ll B[15];
        REP(i, N) {
            B[i] = A[i];
        }
        for (ll i = N - 2; i >= 0; --i) {
            if (A[i] < A[i + 1])
                continue;
            ll m = -1;
            FOR(j, N, i + 1) {
                if (A[i] > A[j]) {
                    if (m == -1 || A[m] < A[j])
                        m = j;
                }
            }
            swap(B[m], B[i]);
            FOR(j, N, i + 1) {
                ll t = j;
                FOR(k, N, j) {
                    if (B[t] < B[k])
                        t = k;
                }
                swap(B[t], B[j]);
            }
            REP(j, N) {
                cout << B[j];
                if (j < N - 1)
                    cout << " ";
            }
            cout << endl;
            break;
        }
    }
    REP(i, N) {
        cout << A[i];
        if (i < N - 1)
            cout << " ";
    }
    cout << endl;
    {
        ll B[15];
        REP(i, N) {
            B[i] = A[i];
        }
        for (ll i = N - 1; i >= 0; --i) {
            ll m = -1;
            FOR(j, N, i + 1) {
                if (A[i] < A[j])
                    if (m == -1 || A[m] > A[j])
                        m = j;
            }
            if (m < 0)
                continue;
            swap(B[i], B[m]);
            FOR(j, N, i + 1) {
                ll m = j;
                FOR(k, N, j) {
                    if (B[m] > B[k])
                        m = k;
                }
                swap(B[m], B[j]);
            }

            REP(j, N) {
                cout << B[j];
                if (j < N - 1)
                    cout << " ";
            }
            cout << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    ll n;
    cin >> n;
    ll a[n];
    ll s=0;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        s += a[i];
    }
    ll minx = s, sum = 0;
    for(int i = 1; i <= n; i++) {
        sum += a[i];
        minx = min(minx, abs(sum - (s - sum)));
    }

    cout << minx << endl;

    return 0;
}

Measured memory_bytes: 5200
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//HELPERS

vector<int> powers2(32,0);void initialize(){ for(int i=1;i<powers2.size();i++) powers2[i] = powers2[i-1]*2;}
int32_t main()
{
IOS
int a,b,n;
cin>>a>>b>>n;
cout<<a*min(b-1,n)/b;
return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 3604
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 1e2+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll dp[N][100005], weights[N], values[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, W; cin >> n >> W;
    rep (i, 0, n) {
        cin >> weights[i];
        cin >> values[i];
    }
    for (int w = 0; w <= W; ++w)
        dp[0][w] = (weights[0] <= w) ? values[0] : 0;

    for (int id = 1; id < n; ++id) {
        for (int w = 0; w <= W; ++w) {
            dp[id][w] = max(dp[id-1][w],
                            (w>=weights[id]) ? dp[id-1][w-weights[id]]+values[id]:0);
        }
    }

    cout << dp[n-1][W] << endl;

    return 0;
}

Measured memory_bytes: 80128
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	int i, s_l = s.length();
	int tot = 0;
	for (i = 0; i < s_l; i++) 
	{
		if (s[i] == 'C' && tot == 0)
			tot++;
		else if (s[i] == 'F' && tot == 1)
			tot++;
	}
	if (tot == 2)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
require "bigdecimal"
require "bigdecimal/util"

def gi() gets.to_i end
def gs() gets.chomp end
def gim() gets.split.map(&:to_i) end
def gsm() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end

#####
n,x,y = gim
distDic = {}
resDic = {}
(1..(n-1)).each do |fir|
  ((fir+1)..n).each do |sec|
    dist = 0
    if fir <= x && y <= sec
      dist = x-fir + sec-y + 1
    else
      if fir > x && y > sec
        dist = [sec - fir, fir-x + y-sec +1].min
      else
        if y > sec
          dist = [sec - fir, x-fir + y-sec +1].min
        end
        if fir > x
          dist = [sec - fir, fir-x + sec-y +1].min
        end
        end
    end
    resDic[dist] = 0 if resDic[dist] == nil
    resDic[dist] += 1 #ここ計算量食ってるかも
  end
end
# puts (1 <= x && y <= 3)
#
# print distDic
# puts
# print distDic.filter{|k,v| v == 1}
# puts
# print distDic[[4,6]]
# print resDic

(n-1).times do |i|
  if resDic[i+1] == nil
    puts 0
  else
    puts resDic[i+1]
  end
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
int main(){

	int n,k,x,y,sum; cin>>n>>k>>x>>y;

	if(n>k)
       sum= k*x+(n-k)*y;
	else
      sum= n*x;
    

	cout<<sum<<endl;

	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
int main(void)
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        string s, t;
        cin >> s >> t;

        int dp[1010][1010];
        for (int i = 0; i < 1010; ++i)
            for (int j = 0; j < 1010; ++j)
                dp[i][j] = 0;

        int n = s.size();
        int m = t.size();

        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                if (s[i] == t[j])
                {
                    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
                }
                else
                {
                    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                    dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
                    dp[i + 1][j + 1] = max({dp[i + 1][j + 1], dp[i + 1][j], dp[i][j + 1]});
                }
            }
        }

        cout << dp[n][m] << endl;
    }
    return 0;
}


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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i) << ", ";
  }
  cout << "]" << endl;
}

int main()
{
  int a, b, c, tmp;
  cin >> 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);
}



Measured memory_bytes: 3200
fn main() {
    let s: String = read();
    if !s.contains("B") || !s.contains("A") {
        println!("No");
    } else {
        println!("Yes");
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 4352