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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end

struct C{
    double x,y;
    C(double _x=0,double _y=0):x(_x),y(_y){}
    C operator~()const{return {x,-y};}
    C operator+(const C& c)const{return {x+c.x,y+c.y};}
    C operator-(const C& c)const{return {x-c.x,y-c.y};}
    C operator*(const C& c)const{return {x*c.x-y*c.y,x*c.y+y*c.x};}
};
vector<C> rt;
void init(int lg=20){
    rt.resize(1<<lg,1);
    rep(k,1,lg){
        int d=1<<k;
        rep(i,0,d){
            if(i&1)rt[d+i-1]=C(cos(2*M_PI*i/d),sin(2*M_PI*i/d));
            else rt[d+i-1]=rt[(d+i)/2-1];
        }
    }
}
void fft(vector<C>& a,bool inv=0){
   int n=a.size(); assert((n&(n-1))==0);
   if(inv){
       for(int i=1;i<n;i<<=1){
           for(int j=0;j<n;j+=i*2){
               rep(k,0,i){
                   a[i+j+k]=a[i+j+k]*~rt[i*2-1+k];
                   const C tmp=a[j+k]-a[i+j+k];
                   a[j+k]=a[j+k]+a[i+j+k]; a[i+j+k]=tmp;
               }
           }
       }
       rep(i,0,n)a[i].x/=n,a[i].y/=n;
   }
   else{
       for(int i=n>>1;i;i>>=1){
           for(int j=0;j<n;j+=i*2){
               rep(k,0,i){
                   const C tmp=a[j+k]-a[i+j+k];
                   a[j+k]=a[j+k]+a[i+j+k]; a[i+j+k]=tmp*rt[i*2-1+k];
               }
           }
       }
   }
} //need to initialize

int main(){
   init();
   int n; ll m; scanf("%d%lld",&n,&m);
   vector<C> a(1<<18);
   rep(i,0,n){
      int tmp; scanf("%d",&tmp);
      a[tmp].x+=1.0;
   }
   fft(a); rep(i,0,1<<18)a[i]=a[i]*a[i]; fft(a,1);
   ll cnt=0,res=0;
   rrep(i,200010,-1){
      ll tmp=(a[i].x+0.5);
      if(cnt+tmp>m){res+=(m-cnt)*i; break;}
      cnt+=tmp; res+=tmp*i;
   }
   printf("%lld\n",res);
   return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

int N;
int a[111111];
int b[111111];
int c[111111];
int dp[5][111111];

signed main() {
  cin >> N;
  repp (i, 1, N+1) {
    cin >> a[i] >> b[i] >> c[i];
  }

  int ans = 0;
  for (int day = 1; day <= N; day++) {
    for (int bef = 0; bef < 3; bef++) {
      for (int now = 0; now < 3; now++) {
        if (bef == now) continue;
        int cost = 0;
        if (now == 0) cost = a[day];
        if (now == 1) cost = b[day];
        if (now == 2) cost = c[day];
        dp[now][day] = max(dp[now][day], dp[bef][day-1] + cost);
        chmax(ans, dp[now][day]);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6912
/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define dbg(x) cerr<<"["<<#x<<" = "<<x<<"]"

int D;
vector<vector<int>> s;
vector<int> c;

int get_score(vector<int> &sc) {
    unordered_map<int, int> last;
    int S = 0;
    for (int i = 0; i < D; ++i) {
        S += s[i][sc[i] - 1];
        last[sc[i] - 1] = i + 1;
        for (int j = 0; j < 26; j++)S -= c[j] * (i + 1 - last[j]);
//        dbg(S) << endl;
    }
    return max(1000000 + S, 0ll);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

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

    cin >> D;
    c = vector<int>(26);
    s = vector<vector<int>>(D, vector<int>(26));
    for (auto &i:c)cin >> i;
    for (auto &i:s) {
        for (auto &j:i)cin >> j;
    }

    vector<int> ans(D);
    unordered_map<int, int> last;
    int S = 0;

    for (int i = 0; i < D; ++i) {
        int cur = -1e18, pos = -1;
        for (int j = 0; j < 26; ++j) {
            int sc = S + s[i][j];

            for (int k = 0; k < 26; ++k) {
                if (k == j)continue;
                sc -= c[k] * (i + 1 - last[k]);
            }

            if (sc > cur) {
                cur = sc;
                pos = j;
            }
        }
        ans[i] = pos + 1;
        last[pos] = i + 1;
    }
    for (auto i:ans)cout << i << endl;

//    int score = get_score(ans);
//    dbg(score) << endl;
}

Measured memory_bytes: 3748
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def solve1(N, W, weight, value):
    dp = [[0] * (W + 1) for _ in range(N + 1)]
    for i in range(N):
        for w in range(W + 1):
            if w - weight[i] >= 0:
                dp[i + 1][w] = dp[i][w - weight[i]] + value[i]
            if dp[i + 1][w] < dp[i][w]:
                dp[i + 1][w] = dp[i][w]

    return dp[N][W]


def solve2(N, W, weight, value):
    w0 = weight[0]
    M = W // w0
    if M == 0:
        return 0

    weight_adj = [w - w0 for w in weight]
    w_total = sum(weight_adj)

    dp = [[[0] * (w_total + 1) for j in range(N + 1)] for i in range(M + 1)]
    for i in range(M):
        for j in range(N):
            for w in range(w_total + 1):
                if w - weight_adj[j] >= 0:
                    dp[i + 1][j + 1][w] = dp[i][j][w - weight_adj[j]] + value[j]
                if dp[i + 1][j + 1][w] < dp[i + 1][j][w]:
                    dp[i + 1][j + 1][w] = dp[i + 1][j][w]
                if dp[i + 1][j + 1][w] < dp[i][j + 1][w]:
                    dp[i + 1][j + 1][w] = dp[i][j + 1][w]

    return max(dp[M][N][min(W - w0 * M, w_total)], dp[M - 1][N][min(W - w0 * (M - 1), w_total)])


def main():
    N, W, *wv = map(int, read().split())
    weight = wv[::2]
    value = wv[1::2]

    if weight[0] < 500:
        ans = solve1(N, W, weight, value)
    else:
        ans = solve2(N, W, weight, value)

    print(ans)
    return


if __name__ == '__main__':
    main()


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

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

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1 ? 1'000'000'007 : 998'244'353;
using m64 = modint<MOD>;
constexpr m64 operator"" _m(unsigned long long n) { return m64(n); }

template<typename T>
struct combinatorics {
    vector<T> fac;

    combinatorics(i64 n): fac(2*n+1) {
        fac[0] = 1;
        for (i64 i = 1; i <= 2*n; i++) fac[i] = fac[i-1] * i;
    }

    T p(i64 n, i64 k) const {
        if (k < 0 || n < k) return 0;
        return fac[n] / fac[n-k];
    }

    T c(i64 n, i64 k) const {
        if (k < 0 || n < k) return 0;
        return fac[n] / (fac[k] * fac[n-k]);
    }

    T h(i64 n, i64 k) const {
        return c(n+k-1, k);
    }
};

template<typename T>
T fastpow(T x, i64 n) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

void solve() {
    i64 k;
    cin >> k;
    string s;
    cin >> s;

    i64 n = s.size();
    i64 l = k + n;
    combinatorics<m64> c(l);
    m64 ans = 0;
    for (i64 i = n; i <= l; i++) {
        ans += c.c(l, i) * fastpow(25_m, l - i);
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 35612
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t s;
    cin >> s;

    int64_t a = sqrt(s);
    if (a * a > s) {
        --a;
    }
    int64_t t = (a - 1) * (a + 1);

    int64_t y0, x1, x2, y2;
    if (a == 1000000000) {
        y0 = 0;
        x1 = 1000000000;
        x2 = 0;
        y2 = 1000000000;
    } else if (s - t <= 1000000000) {
        y0 = 1;
        x2 = s - t;
        y2 = a;
        x1 = a + 1;
    } else {
        auto u = a * (a + 1);
        y0 = 1;
        x2 = s - u;
        y2 = a + 1;
        x1 = a + 1;
    }

    cerr << (x1 * y2 - y0 * x1 + x2 * y0) << endl;
    cout << 0 << " " << y0 << " " << x1 << " " << 0 << " " << x2 << " " << y2
         << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<28));
const ll linf = (1LL<<58);

int a[12][12];

int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  for(int i=0; i<n; i++)
  {
    cin >> c[i];
    for(int j=0; j<m; j++) cin >> a[i][j];
  }
  int ans = inf;
  for(int bit=0; bit<(1<<n); bit++)
  {
    int cost = 0;
    vector<int> d(m);
    for(int i=0; i<n; i++)
    {
      if(bit>>i & 1)
      {
        cost += c[i];
        for(int j=0; j<m; j++) d[j] += a[i][j];
      }
    }
    bool ok = true;
    for(int j=0; j<m; j++) if(d[j] < x) ok = false;
    if(ok) ans = min(ans, cost);
  }
  if(ans == inf) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

const int max_n = 5000+10;
int dp[max_n][max_n];

int main(void) {
    int N;
    cin>>N;
    string S;
    cin>>S;
    for(int i = 0;i < N;i++) {
        dp[i][i] = 1;
    }

    for(int i = N-1;i >= 0;i--) {
        for(int j = N-1;j >= 0;j--) {
            if(S[i] == S[j]) {
                dp[i][j] = dp[i+1][j+1] + 1;
            } else {
                dp[i][j] = 0;
            }
        }
    }

    int ans = 0;
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < N;j++) {
            if(i >= j)
                continue;
            int now = min(dp[i][j],j-i);
            ans = max(ans,now);
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 98048
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
#define ll long long

int main(void){
    ll N,ans=0,memo=0,ver=1;
    cin>>N;
    vector<int> num(10);
    for(int i=0;i<10;i++){
        num.at(i)=N%10;
        N=N/10;
    }
    reverse(num.begin(),num.end());
    for(int i=0;i<10;i++){
        if(num.at(i)==0) continue;
        if(ans==0){
            memo+=num.at(i);
            ans+=num.at(i);
            continue;
        }
        ans*=10;
        memo+=num.at(i);
        ans+=ver*(memo+num.at(i));
        ver*=2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
A, B, C, D, E, F = [int(i) for i in input().split()]

max_sugar = 0
max_water = 100 * A
max_conc = 0.0
A_limit = F // (100 * A)
for i in range(A_limit + 1):
    B_limit = (F - 100 * A * i) // (100 * B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        sugar_limit = min(E * (A * i + B * j), F - 100 * (A * i + B * j))

        sugar = 0
        for c in range(sugar_limit // C + 1):
            d = (sugar_limit - c * C) // D
            temp_sugar = c * C + d * D
            sugar = max(sugar, temp_sugar)
        temp_cons = sugar / (sugar + 100 * (A * i + B * j))
        if temp_cons > max_conc:
            max_conc = temp_cons
            max_water = 100 * (A * i + B * j)
            max_sugar = sugar
print("{} {}".format(max_water + max_sugar, max_sugar))


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

const int DEBUG = 1;
const int mxn = 2e3;
int n;
bitset<mxn> a[mxn]; 
bitset<mxn> dp[mxn],dpr[mxn]; 

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

// NOT MINE LOL ... See Um_nik's first

int main() {

#ifdef LOCAL
	if (DEBUG) freopen("input.txt", "r", stdin);
	if (DEBUG) freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	cin>>n;

	f(i,1,n) {
		string s;
		cin>>s;
		f(j,0,i) a[i][j] = s[j] == '1', a[j][i] = !a[i][j];
	}	
	f(i,0,n) dp[i][i] = dpr[i][i] = 1;

	f(len,1,n) f(l,0,n-len) {
		int r = l+len;	
		if ((a[l]&dpr[l+1]&dp[r]).any())
			dp[r][l]=1;
		if ((a[r]&dpr[l]&dp[r-1]).any())
			dpr[l][r]=1;
	} 

	cout << (dpr[0]&dp[n-1]).count() << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif


	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>


long long  INF=1000000000000000000;
using namespace std;
int c[10][10];

int dp[10][10];//dp[i][j]//iからjへ行くときの最小コスト

void warshall_floyd(int n){
    for(int k=0;k<n;k++){//経由する頂点
        for(int i=0;i<n;i++){//始点
            for(int j=0;j<n;j++){//終点
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
}



int main(){

int H,W;
cin>>H>>W;



for(int i=0;i<10;i++){
    for(int k=0;k<10;k++){
        cin>>dp[i][k];
    }
}

warshall_floyd(10);
int A[H][W];
long long ans=0;
for(int l=0;l<H;l++){
    for(int s=0;s<W;s++){
        cin>>A[l][s];
        if(A[l][s]!=-1){
            ans+=dp[A[l][s]][1];
        }
    }
}

cout<<ans<<endl;

 return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const double EPS=1e-10;


int main(){
    LL K,A,B;
    cin>>K>>A>>B;
    if(K<=A||B-A<=1){
        cout<<K+1<<endl;
    }else{
        //A枚をB枚に交換するのに2手かかる
        //交換動作をx回とする
        LL tK=K-(A-1);
        cout<<A+(tK/2LL)*(B-A)+tK%2LL<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long total = 0;
        for (int i = 0; i < n; i++) {
            total += sc.nextInt() - (i + 1);
        }
        System.out.println(total);
    }
}



Measured memory_bytes: 68296
/*
Hokudai Practice Contest 2014
D - Cheese

ティツァツ」テヲツウツ陛ッツシツ咤FS
テ」ツδ?」ツδシテ」ツつコテ」ツつ?テ」ツ?、テゥツ」ツ淌」ツ?ケテァツオツづ」ツつ湘」ツ?」テ」ツ?ヲテ」ツ?凝」ツつ嘉ヲツャツ。テ」ツ?ォテ・ツ青妥」ツ?凝」ツ??」ツδ?」ツδシテ」ツつコテ」ツ?ョテ、ツスツ催ァツスツョテ」ツ?古・ツョツ堙」ツつ?」ツつ嘉」ツつ古」ツ?ヲテ」ツ??」ツつ凝」ツ?ョテ」ツ?ァテ」ツ??
(S -> 1テ」ツ?ョテヲツ慊?ァツ淞ュティツキツッ) + (1 -> 2テ」ツ?ョテヲツ慊?ァツ淞ュティツキツッ) + ... + (N-1 -> Nテ」ツ?ョテヲツ慊?ァツ淞ュティツキツッ)テ」ツつ津ヲツアツづ」ツつ?」ツつ古」ツ?ーティツ可ッテ」ツ??」ツ??
テヲツ慊?ァツ淞ュティツキツッテ」ツ?ョティツィツ暗ァツョツ療」ツ?ォテ」ツ?ッBFS(テ・ツケツ?・ツ?ェテ・ツ?暗ヲツ篠「テァツエツ「)テ」ツつ津ァツ板ィテ」ツ??」ツつ凝」ツ?禿」ツ?ィテ」ツ?古」ツ?ァテ」ツ?催」ツつ凝」ツ??

BFSテ、ツクツ?・ツ崢榲」ツ?ョテヲツ卍づゥツ鳴禿ィツィツ暗ァツョツ療ゥツ?湘」ツ?薫(HW)テ」ツ?ァテ」ツ??」ツ?禿」ツつ古」ツつ誰テ・ツ崢榲ィツ。ツ古」ツ??」ツ?ョテ」ツ?ァテ」ツ??・ツ?ィテ、ツスツ禿」ツ?ァO(NHW)テ」ツ?ィテ」ツ?ェテ」ツつ凝」ツ??
*/

#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;

//テゥツ堋」テヲツ篠・4テヲツ鳴ケテ・ツ青妥」ツつ津・ツョツ堙ァツセツゥ
const int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};
const int INF = 1e8;

int main(){
  int h,w,n;
  int x[10],y[10];
  string grid[1000];
  cin >> h >> w >> n;

  for(int i=0;i<h;i++)cin >> grid[i];

  //テ」ツδ?」ツδシテ」ツつコiテ」ツ?ョテ・ツ?エテヲツ可?」ツつ遅[i],y[i]テ」ツ?ォティツィツ佚ゥツ個イ
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(grid[i][j] == 'S'){
	y[0] = i; x[0] = j;
      }
      if(grid[i][j] != 'X' && grid[i][j] != '.'){
	y[grid[i][j] - '0'] = i; x[grid[i][j] - '0'] = j;
      }
    }
  }

  int ans = 0;
  //nテ・ツ崢曖FSテ」ツつ津ィツ。ツ古」ツ??
  for(int i=0;i<n;i++){
    int dis[1000][1000];
    queue<int> qx,qy;

    //テ・ツ按敕ヲツ慊淌・ツ個?
    for(int k=0;k<h;k++){
      for(int j=0;j<w;j++){
	dis[k][j] = INF;
      }
    }
    dis[y[i]][x[i]] = 0;

    qy.push(y[i]); qx.push(x[i]);

    //BFS
    while(!qx.empty()){
      //テァツ渉セテ・ツ慊ィテ」ツ?ョテ、ツスツ催ァツスツョ
      int cy = qy.front(), cx = qx.front();
      qy.pop(); qx.pop();

      //テゥツ堋」テヲツ篠・4テヲツ鳴ケテ・ツ青妥」ツつ津ヲツ篠「テァツエツ「テ」ツ?凖」ツつ?
      for(int d=0;d<4;d++){
	int ny = cy + dy[d], nx = cx + dx[d];
	//テァツ崢、テ・ツ、ツ姪・ツ按、テ・ツョツ?
	if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
	//テゥツ堋愿・ツョツウテァツ可ゥテ・ツ按、テ・ツョツ?
	if(grid[ny][nx] == 'X')continue;

	//dis == INFテ」ツ?ェテ」ツつ嘉」ツ??」ツ?セテ」ツ??ィツィツェテ」ツつ古」ツ?ヲテ」ツ??」ツ?ェテ」ツ??
	if(dis[ny][nx] == INF){
	  dis[ny][nx] = dis[cy][cx] + 1;
	  qy.push(ny); qx.push(nx);
	}
      }
    }

    ans += dis[y[i+1]][x[i+1]];
  }

  cout << ans << endl;
}

Measured memory_bytes: 6180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[3005][3005][2];
ll arr[3005];
ll solve(int left,int right,int flag)
{
    if(left>right) return 0;
    if(memo[left][right][flag]!=-1) return memo[left][right][flag];
    ll ret=0;
    if(flag==0)
    {
        ret=max(arr[left]+solve(left+1,right,1),arr[right]+solve(left,right-1,1));
    }
    
    else
    {
        ret=1e18;
        ret=min(-arr[left]+solve(left+1,right,0),-arr[right]+solve(left,right-1,0));
    }
    
    return memo[left][right][flag]=ret;
}
int main()
{
    memset(memo,-1,sizeof(memo));
    
    int n;
    cin>>n;
    ll tot=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        tot+=arr[i];
    }
    
    ll ans=solve(0,n-1,0);
    printf("%lld\n",ans);
}

Measured memory_bytes: 141568
//==========================================
// ABC140b
//
// 2019/09/07
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  vector<int> a(n), b(50), c(50);
  for(int i=0; i<n; ++i)
  {
    int temp;
    cin >> temp;
    a[i]=temp-1;
  }
  for(int i=0; i<n; ++i) cin >> b[i];
  for(int i=0; i<n-1; ++i) cin >> c[i];

  long cnt=0;
  for(int i=0; i<n; ++i)  
  {
    cnt+=b[a[i]];
    if(i!=0 && a[i]==a[i-1]+1) cnt+=c[a[i-1]];
  }
  cout << cnt << endl;


  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;

int main(){
    int WH[2];
    int W,H;
    INPUT(W);INPUT(H);
    int N = W+H;
    pair<ll,ll> Edges[200000];
    int k = 0;
    REP1(i,W){
        INT(e);
        Edges[k] = make_pair(e,0);
        k++;
    }
    REP1(i,H){
        INT(e);
        Edges[k] = make_pair(e,1);
        k++;
    }
    sort(Edges,Edges+N);
    ll sum = 0;
    
    WH[0] = W+1;
    WH[1] = H+1;
    

    REP1(i,N){
        bool f = Edges[i].second;
        sum += Edges[i].first*WH[!f];
        WH[f]--;
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3328
class Main
{
	static int[] pointer;
	static int[] rank;
	
	public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		
		int n = sc.nextInt();
		int q = sc.nextInt();
		
		pointer = new int[n];
		rank    = new int[n];
		for( int a = 0 ; a < n ; a++ )
		{
			pointer[a] = a;
			rank[a]    = 0;
		}
		
		char sw;
		int x,y;
		for( int a = 0 ; a < q ; a++ )
		{
			sw = ( sc.next().toCharArray()[0] );
			x  = sc.nextInt();
			y  = sc.nextInt();
			switch( sw )
			{
				case '0' : 
					union( x, y );
					break;
				case '1' :
					if( isSame( x, y ) )System.out.println( 1 );
					else System.out.println( 0 );
					break;
			}
		}
	}
	static int findRoot( int x )
	{
		if( x != pointer[x] )
			pointer[x] = findRoot( pointer[x] );
		return pointer[x];
	}
	static boolean isSame( int x, int y )
	{
		if( findRoot( x ) == findRoot( y ) )return true;
		return false;
	}
	static void union( int x, int y )
	{
		link( findRoot( x ), findRoot( y ) );
	}
	static void link( int x, int y )
	{
		if( !isSame( x, y ) )
		{
			if( rank[x] < rank[y] )
			{
				pointer[x] = y;
			}else if( rank[x] > rank[y] )
			{
				pointer[y] = x;
			}else
			{
				pointer[x] = y;
				rank[y]++;
			}
		}
	}
}

Measured memory_bytes: 80276
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes\n";
	else cout<<"No\n"; 
	return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <cstdio>
using namespace std;

int n;
long long e,t;
long long x[100005];
long long dp[100005];

int main(){
  scanf("%d%lld%lld", &n,&e,&t);
  for(int i=0; i<n; ++i){
    scanf("%lld", &x[i]);
    x[i]<<=1;
  }
  x[n] = e<<1;

  long long w = 1ll<<57;
  for(int i=0, j=0; i<n; ++i){
    while(j<i && t < (x[i] - x[j]) ){
      w = min(w, dp[j] + (x[i] - x[j]) );
      j++;
    }
    dp[i+1] = min(w, dp[j] + max((x[i]-x[j]) ,t));
    w += (x[i+1] - x[i]);
  }
  printf("%lld\n", dp[n] + e);
  return 0;
}


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

object Main extends App {
  var continue = true
  while (continue) {
    val input = readLine()
    if ("0".equals(input)) {
      continue = false
    } else {
      val values = readLine().split(" ").map(_.toInt)
      val avg: Double = values.map(_.toDouble).sum / values.length
      val variance: Double = values.map(e => (e - avg) * (e - avg)).sum / values.length
      println(Math.sqrt(variance))
    }
  }
}


Measured memory_bytes: 45064
#include <iostream>

using namespace std;

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

	int at = 0;
	for (int i = 1; i < n; i++) {
		at += i;
	}

	cout << at - a << endl;

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

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

int lx,ly,tx,ty;

void dfs(int u,int v,map<P,int>& mp)
{
    mp[P(u,v)]++;
    lx = min(lx,u),ly = min(ly,v),tx = max(tx,u),ty = max(ty,v);
    rep(i,4){
        int nu = u + dx[i],nv = v + dy[i];
        if(mp[P(nu,nv)] == 1){
            dfs(nu,nv,mp);
        }
    }
}

int main()
{
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        map<P,int> mp;
        lx = ly = INF;
        tx = ty = -INF;
        vector<P> vec;
        vec.pb(P(0,0));
        mp[P(0,0)] = 1;
        rep(i,n-1){
            int x,y;
            cin >> x >> y;
            vec.pb(P(vec[x].fi+dx[y],vec[x].se+dy[y]));
            mp[P(vec[x].fi+dx[y],vec[x].se+dy[y])] = 1;
        }
        dfs(0,0,mp);
        cout << tx-lx+1 << " " << ty-ly+1 << "\n";
    }
}

Measured memory_bytes: 3076
/*
ID: tohoast1
TASK: gymnastics
LANG: C++
*/
#include <bits/stdc++.h>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("gymnastics.in", "r", stdin)
#define fout freopen("gymnastics.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define MIN_INT -999999999
#define MOD 1000000007
#define d109 1000000000
#define basay break
#define bmbr exit(0)

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
int n, M, p, x, cnt;

int main() {
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin >> n;
    int arr[n], hack[n];
    for (int i = 0 ; i < n ; ++ i) {
        cin >> arr[i];
        hack[i] = arr[i];
    }
    cin >> M;
    for (int i = 0 ; i < M ; ++ i) {
        cin >> p >> x;
        arr[p - 1] = x;
        for (int j = 0 ; j < n ; ++ j) {
            cnt += arr[j];
        }
        cout << cnt << '\n';
        cnt = 0;
        for (int h = 0 ; h < n ; ++ h) {
            arr[h] = hack[h];
        }
    }
    ///time;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  int n;
  string s;
  cin>>n>>s;
  int k = n/2;
  string ans = "No";
  if (n%2 == 0 && s.substr(0,k) == s.substr(k,k)) ans = "Yes";
  cout << ans << endl;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m, i, t;
  multiset<int> d;
  cin >> n;
  for(i = 0; i < n; i++){
    cin >> t;
    d.insert(t);
  }
  cin >> m;
  for(i = 0; i < m; i++){
    cin >> t;
    if(d.find(t) == d.end()) break;
    d.erase(d.find(t));
  }
  if(i == m)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

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

    string s; cin >> s;
    int n = s.length();

    int ans = 0;
    for (int i = 0; i < n; i++) {
        static bool flag = false;
        if (i < n - 1 && !flag && s[i] == s[i + 1]) {
            i++; flag = true;
        } else {
            flag = false;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

bool solve(vector<ll> a, ll n){
	if (a[n] == 1) { return false; }
	if (a[1] == 0) { return false; }
	repn(i, n - 1) { if (a[i] != a[n - i]) { return false; } }
	return true;
}



int main() {

	ll A, B;
	cin >> A >> B;

	ll ans=-1;

	repn(i, 10000) {
		ll a = i * 108 / 100 -i;
		ll b = i * 110 / 100-i;

		if (a == A && b == B) { ans = i; break; }
	}

	cout << ans;

	
	
	system("PAUSE");

}





Measured memory_bytes: 504
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll MOD = 1e9 + 7;

ll dfs(int k, const vector<vector<int>> &g, int now, int from) {
    int can_use_color_num = (from == -1) ? k - 1 : k - 2;
    if (k < (int)g[now].size()) {
        return 0;
    } else {
        ll res = 1;
        for (auto &e : g[now]) {
            if (e == from) continue;
            res *= can_use_color_num;
            can_use_color_num--;
            res %= MOD;
        }
        for (auto &e : g[now]) {
            if (e == from) continue;
            res *= dfs(k, g, e, now);
            res %= MOD;
        }
        return res;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<vector<int>> g(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ll ans = k * dfs(k, g, 0, -1);
    ans %= MOD;
    cout << ans << endl;
}

Measured memory_bytes: 11648
import math
def combi(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,a,b = map(int,input().split())
l = sorted(list(map(int,input().split())),reverse = True)
n_max = l.count(max(l))
ans=0
if n_max>a:
    for i in range(a,min(b+1,n_max+1)):
        ans+=combi(n_max,i)
    print(max(l))
    print(ans)
    exit()
n_min = l.count(l[a-1])
i_min = l.index(l[a-1])
k = a-i_min
ans+=combi(n_min,k)
print(sum(l[:a])/a)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define ff first
#define ss second
const int MOD = 1000000007;
int main() {

	ios::sync_with_stdio(0);
	int N, K, current, solution, temp1, temp2;
	cin >> N >> K;
	int arr[N];
	for (int i = 0; i < N; i++) {
		cin >> arr[i];
	}
	
	if (K == 0) {
		cout << 1 << endl;
		return 0;
	}
	
	int dptable[N + 1][K + 1];
	for (int i = 0; i < N + 1; i++) {
		dptable[i][0] = 1;
	}
	for (int i = 0; i < K + 1; i++) {
		dptable[0][i] = 1;
	}

	for (int i = 1; i < N + 1; i++) {
		current = arr[i - 1];
		for (int j = 1; j < K + 1; j++) {
			if (j - current <= 0) {
				solution = dptable[i - 1][j];
			} 
			else {
				temp1 = dptable[i - 1][j]; 
				temp2 = dptable[i - 1][j - current - 1];
				solution = (temp1 - temp2 + MOD) % MOD;
			}
			dptable[i][j] = ((solution % MOD) + (dptable[i][j - 1] % MOD))%MOD;
		}
	}

	// for (int i = 0; i < N + 1; i++) {
	// 	for (int j = 0; j < K + 1; j++) {
	// 		cout << dptable[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	solution = (dptable[N][K] - dptable[N][K - 1] + MOD) % MOD; 
	cout << solution << endl;
	return 0;
}

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c;
	if (a>b){
		std::swap(a,b);
	}
	if (b>c){
		std::swap(b,c);
	}
	if (a>b){
		std::swap(a,b);
	}
	cout << a <<" "<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 1164
n = int(input())
s = input()
l = ["SS", "WS", "SW", "WW"]
for i in range(n):
    for j in range(4):
        if s[i] == "o":
            if l[j][i] == l[j][i + 1]:
                l[j] += "S"
            else:
                l[j] += "W"
        else:
            if l[j][i] == l[j][i + 1]:
                l[j] += "W"
            else:
                l[j] += "S"
for i in range(4):
    if l[i][1] == l[i][n + 1] and l[i][0] == l[i][n]:
        exit(print(l[i][1:n + 1]))
print(-1)

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

int main(){
	stack<int> st;
	int n, a;

	while(cin >> n){
		if(n!=0){
			st.push( n );
		}else{
			a = st.top();
			cout << a << endl;
			st.pop();
		}
	}
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    string s[30][30];
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++){
        cin >> s[i][j];
        if(s[i][j] == "snuke") cout << char('A' + j) << i + 1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s1 = scan.next();
		String s2 = scan.next();
		String s3 = scan.next();
		int len1 = s1.length();
		int len2 = s2.length();
		int len3 = s3.length();

		int counta = 0;
		int countb = 0;
		int countc = 0;

		char temp = 'a';
		char ans;
		while (true) {
			if (temp == 'a') {
				if (len1 <= counta) {
					ans = 'A';
					break;
				}
				temp = s1.charAt(counta);
				counta++;
			} else if (temp == 'b') {
				if (len2 <= countb) {
					ans = 'B';
					break;
				}
				temp = s2.charAt(countb);
				countb++;
			} else if (temp == 'c') {
				if (len3 <= countc) {
					ans = 'C';
					break;
				}
				temp = s3.charAt(countc);
				countc++;
			}
		}
		System.out.println(ans);

	}
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
int n,m,h,w;
int main()
{
	scanf("%d%d%d%d",&n,&m,&h,&w);
	if(n%h||m%w)
	{
		puts("Yes");
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				if(i%h||j%w)printf("1000 ");else printf("%d ",-1000*(h*w-1)-1);
			}
			puts("");
		}
	}
	else puts("No");
	return 0;
}

Measured memory_bytes: 1536
// May this submission get accepted
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;
    ll m = inp1;
    cout << Yes(n == m) << endl;
    
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p.at(i);
    }

    ll ans = 0;
    for(int i = 0; i < n; ++i){
        if(p.at(i) == i + 1){
            if(i < n - 1){
                swap(p.at(i), p.at(i + 1));
            }
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#![allow(unused_imports, unused_macros, non_snake_case)]
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

//{{{ macros missing in 1.15.1
#[macro_use]
mod macros {
    macro_rules! eprint {
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = write!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! eprintln {
        () => { eprintln!(""); };
        ($($t:tt)*) => {{
            use ::std::io::Write;
            let _ = writeln!(::std::io::stderr(), $($t)*);
        }};
    }
    macro_rules! dbg {
        ($val:expr) => {
            match $val {
                tmp => {
                    eprintln!(
                        "[{}:{}] {} = {:#?}",
                        file!(),
                        line!(),
                        stringify!($val),
                        &tmp
                    );
                    tmp
                }
            }
        };
    }
}
//}}}

fn run() {
    let stdin = std::io::stdin();
    let mut sc = Scanner::new(stdin.lock());
    let h: usize = sc.read();
    let w: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();
    for y in 0..h {
        for x in 0..w {
            let mut zero = true;
            if x < a {
                zero = !zero
            }
            if y < b {
                zero = !zero
            }
            print!("{}", if zero { 0 } else { 1 });
            if x + 1 == w {
                print!("\n");
            }
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".to_string())
        .stack_size(1024 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap()
}

//{{{ Scanner
pub struct Scanner<R> {
    reader: R,
}

impl<R> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
}

fn is_whitespace(b: u8) -> bool {
    b == b' ' || b == b'\n' || b == b'\r' || b == b'\t'
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        let buf = std::io::Read::bytes(self.reader.by_ref())
            .map(|b| b.expect("Read failed"))
            .skip_while(|&b| is_whitespace(b))
            .take_while(|&b| !is_whitespace(b))
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error")
    }

    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
//}}}


Measured memory_bytes: 9468
def e_gluttony():
    # 参考: https://atcoder.jp/contests/abc144/submissions/8170912
    import sys
    import numpy as np
    input = sys.stdin.readline
    N, K = [int(i) for i in input().split()]
    A = np.array(sorted([int(i) for i in input().split()]))
    F = np.array(sorted([int(i) for i in input().split()], reverse=True))

    if A.sum() <= K:
        return 0  # 計算するまでもなく、修行してコスト0にできる

    def can_eat(x):
        """全員が x 秒以下で食べるために必要な修行回数は K 以下か？"""
        t = A - (x // F)  # 各人は何回修行すればいいか (0以下なら修行は不要)
        return t[t > 0].sum() <= K

    # 初期値は制約上の A の最大値 * F の最大値 (-1 と平均を取るので +1)
    cannot_eat, lower_bound = -1, 10**12 + 1
    while lower_bound - cannot_eat > 1:
        mid = (cannot_eat + lower_bound) // 2
        if can_eat(mid):
            lower_bound = mid
        else:
            cannot_eat = mid
    return lower_bound

print(e_gluttony())

Measured memory_bytes: 37208
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a, a+2);
  if(a[2]==a[1] && a[1]==a[0]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;



  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		Set<Integer> set = new HashSet<Integer>();
		
		for(int i=0;i<N;i++) {
			int n = sc.nextInt();
			if(!set.contains(n)) {
				set.add(n);
			}
		}
		System.out.println(set.size());
	}
}


Measured memory_bytes: 21076
S = input()

if int(S[:4]) > 2019:
    print('TBD')
elif int(S[:4]) < 2019:
    print('Heisei')
elif int(S[:4]) == 2019:
    if int(S[5:7]+S[8:]) <= 430:
        print('Heisei')
    else:
        print('TBD')

Measured memory_bytes: 3060
require 'pp'

n = gets.chomp!.to_i
chs = gets.chomp!.chars

max = 0
1.upto(n-1) do |i|
    left = chs[0, i]
    right = chs[i, n]

    count = (left & right).length
    if count > max
        max = count
    end
end

puts max


Measured memory_bytes: 2172
#include <iostream>
#include <stdlib.h>
using namespace std;
typedef struct{
int a;int b;
}Pair;
int cmp(const void* a,const void* b){
	return ((Pair*)a)->a - ((Pair*)b)->a;
}
int main(){
	int n;
	long k;

	Pair pair[100000];
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> pair[i].a >> pair[i].b;
	}
	qsort(pair,n,sizeof(Pair),cmp);

	long c=0;
	int i=-1;
	do{
		i++;
		c+=pair[i].b;
	}while(c < k);
	cout << pair[i].a;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> color(8);
    int over=0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a >= 3200) over++;
        else color.at(a/400)=1;
    }
    int tot=0;
    for(int i=0; i<8; i++){
        tot += color.at(i);
    }
    cout << max(1, tot) << " " << tot+over << endl;
}

Measured memory_bytes: 3624