akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 方向は関係ない
int q, p, n;
char c;
ll s;

signed main() {
	cin >> q;
	while (q--) {
		cin >> p >> c >> n;
		int t = (c=='(' ? -1 : 1);
		s += t*n;
		cout << (s==0 ? "Yes" : "No") << ln;
	}
}


Measured memory_bytes: 3220
#include <iostream>

using namespace std;

long long int XOR(long long int a, long long int b){
    if(a == 0){
        if((b + 1) % 2 == 0){
            if(((b + 1) / 2) % 2 == 0){
                return 0;
            }else{
                return 1;
            }
        }else{
            if(((b + 1) / 2) % 2 == 0){
                return b;
            }else{
                return (1 ^ b);
            }
        }
    }else{
        return XOR(0, a - 1) ^ XOR(0, b);
    }
}

int main(){
    long long int A, B;
    long long int result = 0;
    cin >> A >> B;
    cout << XOR(A, B) << endl;
}

Measured memory_bytes: 256
def erato(n)
  numbers = (0..n).to_a
  numbers[0], numbers[1] = nil
  m = []
  for d in numbers
    next unless(d)
    break if (Math::sqrt(n) < d)
    (2*d..n).step(d){|e| numbers[e] = nil}
  end
  numbers.delete(nil)
  s = numbers.size
  return s
end
while line = gets
  p erato(line.to_i)
end

Measured memory_bytes: 32984
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
    int n, ba;
    string  c;
    while(1){
        int papa[10] = {};
        ba = 0;
        cin >> n;
        if(n == 0){
            break;
        }
        cin >> c;
        for(int i = 0; i < 100; i++){ 
            if(c[i] == 'M'){
                papa[i % n]++;
            }
            else if(c[i] == 'S'){
                ba += papa[i % n] + 1;
                papa[i % n] = 0;
            }
            else{
                papa[i % n] += ba + 1;
                ba = 0;
            }
        }
        sort(papa, papa + n);
        for(int i = 0; i < n; i++){
            cout << papa[i] << ' ';
        }
        cout << ba << endl;
    }
    return 0;
}

Measured memory_bytes: 3208
void main() {
  problem();
}

void problem() {
  enum CONTESTS = 26;
  const days = scan!int;
  const dec = scan!long(CONTESTS);
  const inc = days.iota.map!(x => scan!long(CONTESTS)).array;

  long calcSatisfactionValue(long[] contests) {
    auto desat = new long[CONTESTS];
    long sat;

    foreach(i, c; contests) {
      sat += inc[i][c];
      foreach(o; 0..CONTESTS) {
        desat[o] = c == o ? 0 : desat[o] + dec[o];
        sat -= desat[o];
      }
    }

    return sat;
  }

  long[] solve() {
    auto desat = new long[CONTESTS];
    auto value = new long[CONTESTS];
    const potential = CONTESTS.iota.map!(c => inc.map!(i => i[c]).sum).array;
    deb(potential);

    long decideNextContest(long day, const long[] inc, long[] dec) {
      long contestCanditate;
      long score = long.min;
      const sumDec = dec.sum;

      foreach(c; 0..CONTESTS) {
        long testScore = inc[c] + dec[c] - sumDec;
        if (score < testScore) {
          contestCanditate = c;
          score = testScore;
        }
      }
      return contestCanditate;
    }

    long[] ans;
    foreach(i; 0..days) {
      auto c = decideNextContest(i, inc[i], desat);
      ans ~= c;

      value[c] += inc[i][c];

      foreach(o; 0..CONTESTS) {
        desat[o] = c == o ? 0 : desat[o] + dec[o];
        value[o] -= desat[o];
      }
    }

    foreach(__; 0..10) {
    long[] necks;
    foreach(_; 0..CONTESTS) {
      const worstIndex = value.minIndex;
      necks ~= worstIndex;
      value[worstIndex] = long.max;
    }

    foreach(n; necks[0..CONTESTS]) {
      auto newAns = ans.dup;
      long maxTry = 0;
      long maxValue = calcSatisfactionValue(ans);
      foreach(i; days/5..days*4/5) {
        const origin = newAns[i];
        newAns[i] = n;
        
        const v = calcSatisfactionValue(newAns);
        if (v > maxValue) {
          maxValue = v;
          maxTry = i;
        }

        newAns[i] = origin;
      }

      if (maxTry != 0) ans[maxTry] = n;
    }

    value[] = 0;
    desat[] = 0;
    foreach(i, c; ans) {
      value[c] += inc[i][c];
      foreach(o; 0..CONTESTS) {
        desat[o] = c == o ? 0 : desat[o] + dec[o];
        value[o] -= desat[o];
      }
    }

    }

    calcSatisfactionValue(ans).deb;
    return ans;
  }

  const r = solve();
  r.each!(c => writeln(c + 1));
}

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

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

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


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

int main() {
  int N, K, i, sum = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    int t = x;
    
    if (x <= K / 2) {
      sum += t;
    }
    
    else {
      t = K - x;
      sum += t;
    }
  }
  
  cout << sum * 2 << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std ;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,a[200000+5];
int main()
{
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        int x;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            a[x]=a[x-1]+1;
        }
        int _max=0;
        for(int i=1;i<=n;i++)
        {
            _max=max(_max,a[i]);
        }
        printf("%d\n",n-_max);
    }

    return 0;
}


Measured memory_bytes: 1152
import sys
from itertools import combinations

input = sys.stdin.readline


def check_num(text):
    cnt = 0
    for i in range(10):
        index = text.find(str(i))
        if index != -1:
            cnt += 1
    return cnt


def main():
    # 種類
    # N = int(input())
    # S = input().strip()
    S = sum(str(i) for i in range(10))
    for i in range(10):
        index = S.find(str(i))
        if index != -1:
            a = check_num(S[index:])
    # 10個の数字
    # 最大1000件
    # 0-9:0-9:0-9
    # print(len(set(combinations(S, 3))))


def hoge():
    N = int(input())
    S = input().strip()
    count = 0
    for x in range(10):
        xindex = S.find(str(x))
        if xindex == -1:
            continue
        for y in range(10):
            yindex = S[xindex + 1 :].find(str(y))
            if yindex == -1:
                continue
            for z in range(10):
                zindex = S[xindex + 1 :][yindex + 1 :].find(str(z))
                if zindex == -1:
                    continue
                count += 1
    print(count)


if __name__ == "__main__":
    hoge()


Measured memory_bytes: 3188
H = int(input())

# nが0になるまで何回割れるか
def divCount(n, cnt = 0):
    if n <= 1:
        return cnt
    return divCount(int(n / 2), cnt + 1)

attackCount = 0
for i in range(0, divCount(H)+1):
    attackCount += pow(2, i)

print(attackCount)

Measured memory_bytes: 3060
S=input()
 
acgt_list=[0]
for i in range(len(S)):
  for j in range(i+1,len(S)+1):
    slen=len(S[i:j])
    temp=0
    for s in S[i:j] :
      if s=='A' or s=='C' or s=='G' or s== 'T':
        temp+=1      
    if temp==slen:
      acgt_list.append(slen)
      
print(max(acgt_list))

Measured memory_bytes: 9080
#include<iostream>
using namespace std;
#define MOD 100000000000007LL
long long dp[1001][1001];
long long x[1001][1001];
long long y[1001][1001];
long long z[1001];
long long H, W, N, M;
long long modpow[1001];
int main() {
	modpow[0] = 1;
	for (int i = 1; i <= 1000; i++) {
		modpow[i] = modpow[i - 1] * 256;
		modpow[i] %= MOD;
	}
	cin >> H >> W; unsigned char c;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> c; x[i][j] = c;
		}
	}
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		long long sum = 0;
		for (int j = 0; j < M; j++) {
			cin >> c; y[i][j] = c;
			sum *= 256; sum %= MOD;
			sum += y[i][j];
		}
		z[i] = sum;
	}
	for (int i = 0; i < H; i++) {
		long long sum = 0;
		for (int j = 0; j < M; j++) {
			sum *= 256; sum %= MOD;
			sum += x[i][j];
		}
		dp[i][0] = sum;
		for (int j = M; j < W; j++) {
			dp[i][j - M + 1] = dp[i][j - M];
			dp[i][j - M + 1] += MOD * 256 - modpow[M - 1] * x[i][j - M];
			dp[i][j - M + 1] *= 256;
			dp[i][j - M + 1] %= MOD;
			dp[i][j - M + 1] += x[i][j];
		}
	}
	for (int i = 0; i <= H - N; i++) {
		for (int j = 0; j <= W - M; j++) {
			for (int k = 0; k < N; k++) {
				if (dp[i + k][j] != z[k]) { goto E; }
			}
			cout << i << ' ' << j << endl;
		E:;
		}
	}
	return 0;
}

Measured memory_bytes: 24484
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, t=0, i=0;
  string col;
  cin >> N;
  for(;i<N;i++){
    cin >> col;
    //cout << col << endl;
    if(col =="Y" && t ==0){
      t++;
    }
    if(i+1==N){
      if(t==0){
        cout << "Three" << endl;
      } else {
        cout <<"Four" << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


struct edge
{
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};

struct P
{
  int pnt, ticket, cost;
  P(int pnt = 0, int ticket = 0, int cost = 0) : pnt(pnt), ticket(ticket), cost(cost) {}
};

bool operator>(const P& left, const P& right)
{
  return left.cost > right.cost;
}

int D[16][128];

int main()
{
  int c, n, m, s, d;
  while(cin >> c >> n >> m >> s >> d && c){
    memset(D, -1, sizeof D);
    vector<vector<edge> > edges(n);

    rep(i, m){
      int a, b, f;
      cin >> a >> b >> f;

      edges[a - 1].push_back(edge(b - 1, f));
      edges[b - 1].push_back(edge(a - 1, f));
    }

    priority_queue<P, vector<P>, greater<P> > que;
    for(que.push(P(s - 1, c, 0)); !que.empty(); que.pop()){
      P v = que.top();

      if(D[v.ticket][v.pnt] != -1 && D[v.ticket][v.pnt] <= v.cost) continue;
      D[v.ticket][v.pnt] = v.cost;
      
      rep(i, edges[v.pnt].size()){
	int to = edges[v.pnt][i].to, cost = edges[v.pnt][i].cost;

	que.push(P(to, v.ticket, v.cost + cost));
	if(0 < v.ticket) que.push(P(to, v.ticket - 1, v.cost + cost / 2));
      }
    }

    int ans = 1 << 30;
    rep(i, c+1) if(D[i][d - 1] != -1) chmin(ans, D[i][d - 1]);

    cout << ans << endl;
  }
}

Measured memory_bytes: 1340
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

    int64_t x = max(a,b);
    int64_t y = min(a,b);

    int64_t ans = 1;

    reps(i,y){
        ans = x*i;
        if(ans % y == 0) break;
    }

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

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

#define repeat(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int table[11][11];

int main() {
  for (;;) {
    int n;
    scanf("%i", &n);
    if (!n) return 0;
    memset(table, 0, sizeof table);
    repeat(i, n) {
      repeat(j, n) {
        scanf("%i", &table[i][j]);
        table[i][n] += table[i][j];
        table[n][j] += table[i][j];
        printf("%5i", table[i][j]);
      }
      printf("%5i\n", table[i][n]);
    }
    repeat(i, n)
      table[n][n] += table[n][i];
    repeat (i, n+1)
      printf("%5i", table[n][i]);
    puts("");
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    string t = "AKIHABARA";
    cin >> s;
    int n = s.size();
    if(n > t.size()){
        cout << "NO" << endl;
        return 0;
    }
    int cnt = 0;
    bool ok = 1;
    rep(i,n){
        if(s[i]==t[cnt])cnt++;
        else if(t[cnt]=='A'){
            cnt++;
            if(t[cnt]==s[i])cnt++;
            else ok = 0;
        }else ok = 0;
    }
    if(ok && cnt>=8)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void solve() {
    int n,W;cin>>n>>W;
    int wt[n],val[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }
    int dp[n+1][W+1];
    memset(dp,0,sizeof dp);
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=W;j++){
            dp[i][j]=dp[i-1][j];
            if(j-wt[i-1]>=0){
                dp[i][j]=max(dp[i][j],val[i-1]+dp[i-1][j-wt[i-1]]);
            }
            ans=max(ans,dp[i][j]);
        }
    }
    cout<<ans<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 79232
n,m=map(int,input().split())
D={}
for i in range(m):
    p,s=input().split()
    if p not in D:
        if s=="AC":
            D[p]=[["AC",1],["WA",0]]
        else:
            D[p]=[["AC",0],["WA",1]]
    else:
        if D[p][0][1]==1:
            continue
        else:
            if s=="AC":
                D[p][0][1]+=1
            else:
                D[p][1][1]+=1
AC,WA=0,0
for i in D:
    if D[i][0][1]==1:
        AC+=1
        WA+=D[i][1][1]

print(AC,WA)

Measured memory_bytes: 82392
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define L first.first
#define R first.second
#define C second

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, M;
	vector<int> dis;
	vector<pair<pair<int,int>,int>> in;
	vector<vector<pair<int,int>>> z;
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> Q;
	
	cin>>N>>M;
	
	in.resize(M);
	z.resize(N+10);
	dis.resize(N+10,INF);
	
	for(int i = 0; i < M; i++){
		cin>>in[i].L>>in[i].R>>in[i].C;
		z[in[i].L].push_back(make_pair(in[i].R, in[i].C));
	}
	
	sort(in.begin(), in.end());
	
	dis[1] = 0;
	int c = 0;
	
	for(int i = 0; i < z[1].size(); i++){
		Q.push(make_pair(z[1][i].second, z[1][i].first));
	}
	
	for(int i = 2; i <= N; i++){
		pair<int,int> t;
		
		if(Q.size())t = Q.top();
		else {
			cout<<-1<<endl;
			return 0;
		}
		
		while(t.second < i){
			Q.pop();
			if(Q.size() == 0){
				cout<<-1<<endl;
				return 0;
			}
			
			t = Q.top(); 
		}
		
		dis[i] = t.first;
		
		for(int j = 0; j < z[i].size(); j++){
			Q.push(make_pair(z[i][j].second + dis[i], z[i][j].first));
		}
	}
	
	
	if(dis[N] != INF)cout<<dis[N]<<endl;
	else cout<<-1<<endl;
	
	return 0;
}

Measured memory_bytes: 10104
N = int(input())
cij = [10*[0] for i in range(0, 10)]

for s in range(1, N+1):
    s = str(s)
    i = int(s[0])
    j = int(s[-1])
    cij[i][j] += 1

counts = 0 
for i in range(1, 10):
    for j in range(1, 10):
        counts += cij[i][j] * cij[j][i]
print(counts)

Measured memory_bytes: 3064
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  long long x;
  cin >> n >> x;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (a[i] <= x) {
      if (i == n - 1 && a[i] < x) {

      } else {
        ans++;
        x -= a[i];
      }
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e16;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 998244353;


int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    
    int n;
    cin >> n;
    int a = n / 500;
    n = n % 500;
    int b = n / 5;
    cout << (a * 1000 + b * 5) << endl;

    return 0;
}

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

int main(void){
   double Px,Py,r;
   double x1,y1,x2,y2,x3,y3;
   double a1,b1,c1,a2,b2,c2;
   int n,i;
   
   scanf("%d",&n);
   for(i=0;i<n;i++){
       scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
       
       a1=2*(x1-x2);
       b1=2*(y1-y2);
       c1=(x1*x1)-(x2*x2)+(y1*y1)-(y2*y2);
       a2=2*(x1-x3);
       b2=2*(y1-y3);
       c2=(x1*x1)-(x3*x3)+(y1*y1)-(y3*y3);
       
       Px=((b2*c1)-(b1*c2))/((a1*b2)-(a2*b1));
       Py=((a1*c2)-(a2*c1))/((a1*b2)-(a2*b1));
       
       r=sqrt((x1-Px)*(x1-Px)+(y1-Py)*(y1-Py));
       
       if(Px<0){
           Px=(int)(Px*1000-0.5);
       }else{
           Px=(int)(Px*1000+0.5);
       }
       
       if(Py<0){
            Py=(int)(Py*1000-0.5);
       }else{
            Py=(int)(Py*1000+0.5);
       }
       
       r=(int)(r*1000+0.5);
       
       printf("%.3lf %.3lf %.3lf\n",((double)Px)/1000,((double)Py)/1000,((double)r)/1000);
       
   }
   
   return 0;
    
}




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

using namespace std;
const int MAXN = 3e3 + 7;

long long dp[MAXN][MAXN][2], a[MAXN], n;

long long solve(int l, int r, int p) {
  if(l == r) return a[l];
  long long &ans = dp[l][r][p];
  if (~ans) return ans;
  ans = max(a[l] - solve(l + 1, r, !p), a[r] - solve(l, r - 1, !p));
  return ans;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << solve(0, n-1, 0);
  return 0;
}

Measured memory_bytes: 141824
#include<iostream>
#include<vector>
#define M   1500000
using namespace std;
int main(void){
int n,m;
while(1){
cin>>n>>m;
if(n==0)break;
vector<int> h(n),w(m);
vector<int> hl(M,0),wl(M,0);
for(int i=0;i<n;i++){
	cin>>h[i];
}
for(int i=0;i<m;i++){
	cin>>w[i];
}
int sum=0;
for(int i=0;i<n;i++){
	 sum=0;
	for(int j=i;j<n;j++){
		sum+=h[j];
		hl[sum-1]++;
	}
}
for(int i=0;i<m;i++){
	 sum=0;
	for(int j=i;j<m;j++){
		sum+=w[j];
		wl[sum-1]++;
	}
}
int t=0;
for(int i=0;i<M;i++){
		t+=hl[i]*wl[i];
	
}
cout<<t<<endl;
}
	return 0;
}

Measured memory_bytes: 14560
#include <iostream>
#include <queue>
using namespace std;
struct masu { int y, x; };

int h, w, check[50][50];
int X[] = { -1, 0, 1, 0 };
int Y[] = { 0, -1, 0, 1 };
char s[50][50];

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

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			check[i][j] = INT32_MAX;
		}
	}
	check[0][0] = 0;

	//cout << "a" << endl;
	deque<masu>que;
	que.push_back(masu{ 0, 0 });
	while (!que.empty()) {
		masu m = que.front();
		que.pop_front();
		//cout << "y:" << m.y << "x:" << m.x << endl;
		for (int i = 0; i < 4; i++) {
			int y = m.y + Y[i];
			int x = m.x + X[i];
			//cout << "y:" << y << " x:" << x << endl;
			if (0 <= y && y < h && 0 <= x && x < w && check[y][x] == INT32_MAX && s[y][x] == '.') {
				check[y][x] = check[m.y][m.x] + 1;
				que.push_back(masu{ y, x });
			}
		}
	}

	//cout << "b" << endl;
	int y = h - 1, x = w - 1;
	while (true) {
		s[y][x] = '#';
		if (y == 0 && x == 0 || check[y][x] == INT32_MAX)break;

		for (int i = 0; i < 4; i++) {
			int y2 = y + Y[i];
			int x2 = x + X[i];
			if (0 <= y2 && y2 < h && 0 <= x2 && x2 < w && check[y2][x2] == check[y][x] - 1) {
				y = y2;
				x = x2;
				break;
			}
		}
	}
	//cout << "c" << endl;

	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.')ans++;
		}
	}

	cout << (s[0][0] == '.' ? -1 : ans) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <typeinfo>
using namespace std;


// define list


namespace  math{
    const double PI = 3.14;
    const int INF = 1000000007;
    int GCM(int a,int b); //最大公約数
    int LCM(int a,int b); //最小公倍数
    int Pemu(int n,int r); //順列
    int Comb(int n,int m); //組み合わせ
    int Digit(int N); //桁和
    
    int GCM(int a,int b){
        if(a<b){
            swap(a,b);
        }
        int r = a%b;
        while (r!=0)
        {
            a=b;
            b=r;
            r=a%b;
        }
        return b;
    }

    int LCM(int a,int b){
        return a*(b/GCM(a,b));
    }

    int Pemu(int n,int r){
        int ans = n;
        for(int i=1;i<r;i++){
            ans*=(ans-i);
        }
        return ans;
    }

    int Comb(int n,int m){
        int a=n,b=m;
        for(int i=1;i<m;i++){
            a *= (a-i);
        }
        for(int i=1;i<m;i++){
            b *= (b-i);
        }
        
        return a/b;
    }

    int Digit(int N){
        if(N<10){
            return N;
        }
        int r = 0;
        while (N>=10)
        {
            r += (N%10);
            N /= 10;
        }
        r += N;
        return r;
    }
}

namespace SubLib{
    #define int long long
    #define double long double
    #define incin(n) int (n); cin >> (n);
    #define strcin(s) string (s); cin >> (s);
    #define incin2(a,b) int a,b; cin >> a >> b; 
    #define rap(n,i) for(int (i) = 0;i<(n);(i)++)
    #define input(n,v) (v) = SubLib::Input((n),(v))
    #define all(v) (v).begin(),(v).end()
    using intv = vector<int>;
    using douv = vector<double>;
    using strv = vector<string>;
    using charv = vector<char>;
    template <class T1>
    using pvec = vector<pair<T1,T1>>;
    template <typename T> vector<T> Input(int n,vector<T> v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
        return v;
    }
    void YN (bool b){
        if(b){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

using namespace math;
using namespace SubLib;

signed main(){
    incin(n);
    douv a(n);
    double sum = 0;
    rap(n,i){
        cin >> a[i];
        sum += 1/a[i];
    }
    cout<<1/sum<<endl;
    return 0;
}

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

using namespace std;
#define int            long long
#define f(i,n)        for(int i=0;i<(n);++i)
#define fa(i,a,n)     for(int i=a;i<=(n);++i)
#define fd(i,a,n)     for(int i=a;i>=(n);--i)
#define tc 			  int t;cin>>t;f(testcase,t)
#define pii             pair<int,int>
void c_p_c() {

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

}
int dp[51][1000][51];
int ways(int n, int sum, int count, vector<int>& a, int &av ) {
	if (n < 0)
		return 0;

	if (n == 0) {
		if (count == 0)
			return 0;
		int remainder = sum % count;
		if (remainder != 0)
			return 0;
		if (remainder == 0)
		{
			if (sum / count == av)
				return 1;
		}

	}
	if (dp[n][sum][count] != -1)
		return dp[n][sum][count];
	int pick = ways(n - 1, sum + a[n], count + 1, a, av);
	int dpick = ways(n - 1, sum, count, a, av);
	int total = pick + dpick;
	return dp[n][sum][count] = total;
}
int32_t main() {

	c_p_c();
	int n, av;
	cin >> n >> av;
	vector<int> a;
	a.resize(n + 1);
	a[0] = -1;
	fa(i, 1, n)
	cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << ways(n, 0, 0, a, av);



	return 0;
}


Measured memory_bytes: 20608
import heapq
from sys import stdin
input = stdin.readline

#入力
# s = input()[0:-1]
# n = int(input())
n,k = map(int, input().split())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]


# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


     
def main():
    if (n+2-1)//2 <k:
        print("NO")
    else:
        print("YES")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <cstring>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

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


  if(n >= 1000)cout << "ABD" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
template <typename T, typename Can> T bsearch(T L, T R, const Can& can, bool left_feasible = true) {
    static_assert(is_convertible<decltype(can), function<bool(T)>>::value, "can must be bool(T)");
    T& feasible = left_feasible ? L : R;
    T& infeasible = left_feasible ? R : L;
    while(R - L > 1) {
        T M = L + (R - L) / 2;
        (can(M) ? feasible : infeasible) = M;
    }
    return feasible;
}
ll ceildiv(ll x, ll y) {
    return (x + y - 1) / y;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    cout << bsearch(0, *max_element(a.begin(), a.end()), [&](int max_piece) {
        ll needed_cuts = 0;
        for(int ai : a) {
            needed_cuts += ceildiv(ai, max_piece) - 1;
        }
        return needed_cuts <= k;
    }, false) << endl;
    return 0;
}


Measured memory_bytes: 3984
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int a[1005];
int main()
{
	int n,m,num=0;float sum=0;
	cin>>n>>m;
	for(int i=0;i<n;++i)
	{
	cin>>a[i];	sum+=a[i];
	}sum=sum/(4.0*m);
	sort(a,a+n);
	for(int i=n-1;i>=0;--i)
	{
		if(a[i]>=sum)
		num++;
	}
	if(num>=m) cout<<"Yes";
	else cout<<"No";
 } 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int R;
    cin >> R;
    if (R < 1200)
    {
        printf("ABC");
    }
    else if (R >= 1200 && R < 2800)
    {
        printf("ARC");
    }
    else
    {
        printf("AGC");
    }
}

Measured memory_bytes: 504
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  s = readline() |> strip |> collect

  n=length(s)
  ix=Tuple{Int, Int}[]
  j = 1
  for i in 2:n
    if s[i-1] == 'L' && s[i] == 'R'
      push!(ix, (j, i-1))
      j = i
    end
  end
  push!(ix, (j, n))

  ans=zeros(Int, n)
  for (i, j) in ix
    n_r = count(c -> c == 'R', s[i:j])
    n_l=j-i+1-n_r
    ans[i+n_r-1]+=n_r÷2+n_r%2+n_l÷2
    ans[i+n_r]+=n_r÷2+n_l÷2+n_l%2
  end

  for i in 1:n
    print(ans[i])
    i!=n && print(" ")
  end
  println()
end

main()


Measured memory_bytes: 153480
N,A,B=map(int,input().split())
H=[]
s=0
cnt_max=0

for i in range(N):
  h=int(input())
  s+=h
  cnt_max+=(h//A+1)
  H.append(h)

cnt_min=sum(H)//(B*N+(A-B)*N)
H.sort(reverse=True)
  
def check(n):
  res=n
  dmg=A-B
  dmg2=n*B
  for i in range(N):
    if H[i]>dmg2:
      if (H[i]-dmg2)%dmg==0:
        res-=((H[i]-dmg2)//dmg)
      else:
        res-=((H[i]-dmg2)//dmg+1)  
    if res<0:
      return False
  return True

while True:
  if cnt_min+1==cnt_max:
    if check(cnt_min):
      print(cnt_min)
      break
    else:
      print(cnt_max)
      break
  ans=(cnt_min+cnt_max)//2
  if check(ans):
    cnt_max=ans
  else:
    cnt_min=ans

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

typedef long long ll;

using namespace std;

bool d[1000004];
int penalty[100004];

int main() {
    int qus, sub;
    int penalties=0, correct=0;
    scanf("%d%d",&qus,&sub);
    int num; char judge[5];
    vector<int> v;
    for (int i=0; i<sub; i++) {
        scanf("%d",&num);
        scanf("%s",judge);
        if (!d[num]) {
            if (judge[0]=='A') {
                correct++;
                v.push_back(num);
                d[num]=1;
            }
            else penalty[num]++;
        }
    }
    for (int i=0; i<v.size(); i++) {
        penalties+=penalty[v[i]];
    }
    printf("%d %d\n",correct,penalties);
    return 0;
}

Measured memory_bytes: 1020
def main():
    N = int(input())
    nums = [1] * (N + 1)
    s = 0
    for i in range(2, N+1):
        tmp = i
        while tmp <= N:
            nums[tmp] += 1 
            tmp += i
    for i in range(1, N+1):
        s += i * nums[i]
    print(s)


if __name__ == '__main__':
    main()


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 1
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	lli sum = 0;
	for(lli i=0;;i++){
		sum += i;
		if(sum>=n){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 100010
int main(){
	int a,b;
	in2(a,b);
	printf("%d",(a-1)*(b-1));
	return 0; 
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
  public static final long MOD = 1000000007;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    String S[] = new String[H];
    char s[][] = new char[H][W];
    for(int i=0; i<H; i++){
      S[i] = sc.next();
      s[i] = S[i].toCharArray();
    }
    String ans = "Yes";
    boolean flag = false;
    for(int i=0; i<H; i++){
      if(flag == true) break;
      for(int j=0; j<W; j++){
        if(flag == true) break;
        if(s[i][j] == '#'){
          if(i > 0 && s[i-1][j] == '#') continue;
          if(i < H-1 && s[i+1][j] == '#') continue;
          if(j > 0 && s[i][j-1] == '#') continue;
          if(j < W-1 && s[i][j+1] == '#') continue;
          ans = "No";
          flag = true;
        }
      }
    }
    System.out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}


Measured memory_bytes: 21844
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    pos = []
    neg = []
    for a in aa:
        if a < 0: neg.append(a)
        else: pos.append(a)
    pn = len(pos)
    nn = len(neg)
    if min(k,nn) // 2 * 2 + pn < k:
        aa.sort(key=lambda x: abs(x))
        print(cal(aa[:k]))
    else:
        pos.sort()
        neg.sort(reverse=True)
        ans = pos.pop() if k & 1 else 1
        mul = []
        while len(pos) > 1: mul.append(pos.pop() * pos.pop())
        while len(neg) > 1: mul.append(neg.pop() * neg.pop())
        mul.sort(reverse=True)
        print(ans * cal(mul[:k // 2]) % md)

def cal(xx):
    res=1
    for x in xx:
        res=res*x%md
    return res

md=10**9+7
n,k=MI()
aa=LI()
main()

Measured memory_bytes: 31468
import java.util.Scanner;

public class Main {
  private static int input_num , temp;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int[] best3_height = {0, 0, 0};
    while (stdIn.hasNextInt()) {
      input_num = stdIn.nextInt();
      if (best3_height[0] < input_num) {
        temp = best3_height[0];
        best3_height[0] = input_num;
        best3_height[2] = best3_height[1];
        best3_height[1] = temp;
        temp = 0;
      } else if (best3_height[1] < input_num) {
        temp = best3_height[1];
        best3_height[1] = input_num;
        best3_height[2] = temp;
        temp = 0;
      } else if (best3_height[2] < input_num) {
        best3_height[2] = input_num;
      } else {
        continue;
      }
    }
    for (int height : best3_height) {
      System.out.println(height);
    }
  }
}

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

int main()
{
	string S; cin >> S;
	string ss = "2019/04/30";
	string ans = "Heisei";
	rep(i, S.size()) {
		if (S[i] != '/') {
			if (S[i] > ss[i]) ans = "TBD";
			if (S[i] < ss[i]) break;
		} 
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
namespace ZheCaoZuoZhenShiBaoZhaAAAA
{
	const int N=200100;
	struct interval
	{
		int L,R,w;
		interval(int a=0,int b=0,int c=0){L=a,R=b,w=c;}
	};
	bool operator < (interval a,interval b){return a.w>b.w;}
	std::priority_queue<interval> Q;
	int s[N],ds[N],t[N];
	int ef[N][22],of[N][22];
	int n,dn,tot;
	void initialize()
	{
		scanf("%d",&n),dn=n>>1;
		for(int i=1;i<=n;i++)
			scanf("%d",s+i),ds[s[i]]=i;
		for(int i=1;i<=dn;i++)
			ef[i][0]=s[i*2],of[i][0]=s[i*2-1];
		for(int k=1;k<=20;k++)
			for(int i=1;i<=dn;i++)
				if(i+(1<<k)-1<=dn)
				{
					ef[i][k]=std::min(ef[i][k-1],ef[i+(1<<(k-1))][k-1]);
					of[i][k]=std::min(of[i][k-1],of[i+(1<<(k-1))][k-1]);
				}
//		printf("fuck %d %d %d\n",of[1][0],of[2][0],of[1][1]);
		while(!Q.empty())Q.pop();
	}
	int query_odd(int L,int R)
	{
//		printf("query : %d %d\n",L,R);
		int x=1,k=0;
		while(x*2<=(R-L+1))x<<=1,k++;
//		printf("%d , %d : %d %d\n",L,R-x+1,of[L][k],of[R-x+1][k]);
		return std::min(of[L][k],of[R-x+1][k]);
	}
	int query_even(int L,int R)
	{
		int x=1,k=0;
		while(x*2<=(R-L+1))x<<=1,k++;
		return std::min(ef[L][k],ef[R-x+1][k]);
	}
	inline int ev(int L,int R){return query_even((L+1)>>1,R>>1);}
	inline int od(int L,int R){return query_odd((L>>1)+1,(R+1)>>1);}
	void solve()
	{
		initialize();
		Q.push(interval(1,n,od(1,n)));
		tot=0;
		for(int p,q;!Q.empty();)
		{
			interval H=Q.top();Q.pop();
//			printf("%d -- %d : %d\n",H.L,H.R,H.w);
			p=ds[H.w];
			if(p&1)q=ds[ev(p+1,H.R)];
			else q=ds[od(p+1,H.R)];
//			printf("%d , %d\n",p,q);
			t[++tot]=s[p],t[++tot]=s[q];

			if(p!=H.L)Q.push(interval(H.L,p-1,H.L&1?od(H.L,p-1):ev(H.L,p-1)));
			if(p+1!=q)Q.push(interval(p+1,q-1,(p+1)&1?od(p+1,q-1):ev(p+1,q-1)));
			if(q!=H.R)Q.push(interval(q+1,H.R,(q+1)&1?od(q+1,H.R):ev(q+1,H.R)));
		}
		for(int i=1;i<=n;i++)
			printf("%d ",t[i]);
		printf("\n");
	}
}
int main()
{
	ZheCaoZuoZhenShiBaoZhaAAAA::solve();
	return 0;
}


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

int main(void){
    int A,B,C,X,Y;
    int kane=0;

    cin>>A>>B>>C>>X>>Y;
    if(A+B < C*2 ){
        kane = A*X+B*Y;
        
    }else if(A > C*2 && B > C*2){
        if(X<Y){
            kane = C*Y*2;

        }else{
            kane = C*X*2;
        }
    }else if(A > C*2 && X>Y){
        kane = C*X*2;
    }else if(B > C*2 && Y>X){
        kane = C*Y*2;
    }else if(A > C*2){
        kane = C*X*2;
        kane = kane + B*(Y-X);
    }else if(B > C*2){
        kane = C*Y*2;
        kane = kane + A*(X-Y);
    }else{
        if(X<Y){
            kane = C*X*2;
            kane = kane + B*(Y-X);
        }else{
            kane = C*Y*2;
            kane = kane + A*(X-Y);
        }
    }
    cout<<kane<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b;
    cin >> a >> b;
    int ans = 0;
    FOR(i, 1, 20)
    {
        if(b <= a + (a-1)*(i-1)){
            ans = i;
            break;
        }
    }

    if(b == 1) ans = 0;
    
    cout << ans << endl;

}

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

int main() {

  string S;
  cin >> S;
  
  reverse(S.begin(), S.end());
  
  if(S.at(0) == 's'){
    reverse(S.begin(), S.end());
    cout << S + "es" << endl;
  }
  else{
    reverse(S.begin(), S.end());
    cout << S + "s" << endl;
  }

return 0;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;
int b[2010][2010];

signed main(){
    int n,x;
    cin >> n >> x;
    int a[2010];
    
    rep(i,n) cin >> a[i];
    rep(i,n) b[i][0] = a[i];
    int ans = 0;
    rep(i,n) ans += a[i];

    for(int k = 1;k <= n-1;k++){
        int bb = 0;

        rep(i,n){
            int p = i-k;
            if(p < 0) p += n;
            b[i][k] = min(a[p],b[i][k-1]);
            bb += b[i][k];
        }
        ans = min(ans, k*x + bb);
    }
  

    cout << ans <<endl;

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
 
int main(void) {
    vector<ll> G[300010];
    vector<ll> get(300010, -1);
    ll n, m, s, t;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;  v--;
        G[3 * u].push_back(3 * v + 1);
        G[3 * u + 1].push_back(3 * v + 2);
        G[3 * u + 2].push_back(3 * v);
    }
    cin >> s >> t;
  s--;  t--;
    
    queue<ll> que;
    ll q[300030] = {};
    que.push(3 * s);
    get[3 * s] = 0;
    q[0] = 1;
 
    for (int i = 0; !que.empty(); i++) {
        for (int j = 0; j < q[i]; j++) {
            ll qt = que.front();
            if (qt == 3 * t) {
                cout << i/3 << endl;
                return 0;
            }
            for (int k = 0; k < G[qt].size(); k++) {
                if (get[G[qt][k]] == -1) {
                    que.push(G[qt][k]);
                    get[G[qt][k]] = i + 1;
                    q[i + 1]++;
                }
            }
            que.pop();
        }
    }
  cout << -1 << endl;
    
    
}


Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
int cnt;
void insertionSort(int *A,int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j];
      j-=g;
      cnt++;
    }
    A[j+g]=v;
  }
}
void shellSort(int *A,int n){
  cnt=0;
  int r=1;
  vector<int> G;
  while(r<=n){
    G.push_back(r);
    r*=2;
  }
  int m=G.size();
  reverse(G.begin(),G.end());
  cout<<m<<endl;
  for(int i=0;i<m;i++) cout<<G[i]<<" \n"[i==m-1];
  for(int i=0;i<m;i++) insertionSort(A,n,G[i]);
  cout<<cnt<<endl;
}
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  shellSort(A,n);
  for(int k=0;k<n;k++) cout<<A[k]<<endl;
  return 0;
}


Measured memory_bytes: 6956
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int q = N;
    int sum = 0;

    while(q != 0){
      sum += q%10; //qの1の位をsumに加える
      q /= 10; //qの1の位を消したものを新たなqとする
    }

    System.out.println(N%sum == 0? "Yes":"No");
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    vector<bool> d(26, false);
    REPS(c, s) d[c - 'A'] = true;
    if (d['E' - 'A'] == d['W' - 'A'] and d['N' - 'A'] == d['S' - 'A']) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main(void) {

	int a[4][13];
	int n,i,j,x,y;
	char c;
	
	scanf("%d",&n);
	
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			a[i][j]=0;
		}
	}
		
	for(i=0;i<n;i++){
		scanf("%s%d",&c,&y);
		if(c=='S'){
			x=0;
		}else if(c=='H'){
			x=1;
		}else if(c=='C'){
			x=2;
		}else{
			x=3;
		}
		a[x][y-1]=1;
	}
	
	for(i=0;i<4;i++){
		for(j=0;j<13;j++){
			if(a[i][j]==0){
				if(i==0){
					c='S';
				}else if(i==1){
					c='H';
				}else if(i==2){
					c='C';
				}else{
					c='D';
				}
				printf("%c %d\n",c,j+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <cstdio>

int main(void)
{
    int a, b;
    while (scanf("%d %d", &a, &b) != EOF)
    {
        if (b % a == 0)
            printf("%d\n", a + b);
        else
            printf("%d\n", b - a);
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int a;
	cin>>a;
	int i;
	int b=100000;
	for(i = 0; i < a; i++){
	b=(b*1.05);
	b=(((b+999)/1000)*1000);
	}
	cout<<b<<endl;
}



Measured memory_bytes: 3092
#include <stdio.h>
#include <ctype.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<string>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;
int main(){
	int N, K;
	string S;
	scanf("%d%d", &N, &K);
	cin >> S;
	char c = S[K - 1];
	c = tolower(c);
	S[K-1] = c;
	cout << S << endl;
}

Measured memory_bytes: 256