akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stack>

#define MAX_W 50
#define MAX_H 50
#define LAND 1
#define SEA 0
int map[MAX_H][MAX_W];
int h, w;
using namespace std;
stack<int> x, y;

bool input() {
  int i, j;

  scanf("%d %d", &w, &h);
  if (w == 0 && h == 0) return false;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      scanf("%d", &map[i][j]);
    }
  }

  return true;
}

int main() {
  int i, j, cnt;

  while (input()) {
    cnt = 0;
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        if (map[i][j] == LAND) {
          cnt++;
          x.push(j);
          y.push(i);
          while (!x.empty() && !y.empty()) {
            int a = x.top();
            x.pop();
            int b = y.top();
            y.pop();
            if (a < 0 || w <= a || b < 0 || h <= b || map[b][a] == SEA)
              continue;
            map[b][a] = SEA;
            x.push(a - 1);
            y.push(b - 1);
            x.push(a - 1);
            y.push(b);
            x.push(a - 1);
            y.push(b + 1);
            x.push(a);
            y.push(b - 1);
            x.push(a);
            y.push(b + 1);
            x.push(a + 1);
            y.push(b - 1);
            x.push(a + 1);
            y.push(b);
            x.push(a + 1);
            y.push(b + 1);
          }
        }
      }
    }
    printf("%d\n", cnt);
  }

  return 0;
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int N; cin >> N;
    string S; cin >> S;
    set<char> hoji, judge;
    int ans = 0, cnt;
    for(int i = 0; i < N - 1; i++) {
        cnt = 0;
        if(!hoji.count(S.at(i))) {
            hoji.insert(S.at(i));
        }
        for(int j = i + 1; j < N; j++) {
            if(hoji.count(S.at(j))) {
                if(!judge.count(S.at(j))) {
                judge.insert(S.at(j));
                }
            }
        }
        cnt = judge.size();
        for (auto k: judge) {
            judge.erase(k);
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

int main(void){
    int sum = 0;
    vector<int> inputs(3);

    for(int i=0; i<3; i++){
        cin >> inputs[i];
    }

    sort(inputs.begin(),inputs.end());
    for(int i=0; i<2; i++){
        sum += abs(inputs[i+1] - inputs[i]);
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n; string s;
    cin >> n >> s;
    s = "0" + s + "0";
    vector<int> dp(n+2);
    for (int i = 1; i <= n; ++i) {
        dp[i+1] = max(dp[i+1], dp[i]);
        if(s.substr(i-1, 3) == "101"){
            int cur = i-1;
            while(s[cur] != '0'){
                dp[i+1] = max(dp[i+1], dp[cur-1]+ (i-cur));
                cur--;
            }
            cur = i+1;
            while(s[cur] != '0'){
                dp[cur] = max(dp[cur], dp[i-2]+ (cur-i));
                cur++;
            }
        }
    }
    cout << dp.back() << "\n";
    return 0;
}

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

int main(int , char **)
{
	int N;
	cin >> N;
	ll A[300][300]={},B[300][300]={};

	for(int y=0;y<N;y++){
		for(int x=0;x<N;x++){
			int a;
			cin >> a;
			A[y][x]=a;
			B[y][x]=a;
		}
	}

	for(int k=0;k<N;k++){
		for(int y=0;y<N;y++){
			for(int x=0;x<N;x++){
				if ( A[y][k] + A[k][x] < A[y][x] ){printf("-1\n");return 0;}
				if ( A[y][k] + A[k][x] == A[y][x]){
					if (( B[y][k]!=0 )&&( B[k][x]!=0 ))	{
						B[y][x] = 0;
					}
				}
			}
		}
	}

	ll ans = 0;
	for(int y=0;y<N;y++){
		for(int x=0;x<y;x++){
			ans += B[y][x];
		}
	}

	printf("%ld\n",ans);
	return 0;
}


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


int main() {
  string s;
  cin >> s;
  
  string ans;
  if (s == "Cloudy") {
    ans = "Rainy";
  } else if (s == "Rainy") {
    ans = "Sunny";
  } else {
    ans = "Cloudy";
  }
    
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 256
def main():
    nums = list(map(int, input().split()))
    n, k = nums[0], nums[1]
    graph = {}
    out = list(map(int, input().split()))
    for i in range(n):
        graph[i + 1] = out[i]
    
    cycle_length = None
    visited = {}
    ans = None

    def go(x, rem):
        while rem:
            x = graph[x]
            rem -= 1
        
        nonlocal ans
        ans = x
        return x

    def dfs(i, rem):
        j = i
        while rem:
            if j in visited:
                nonlocal cycle_length
                cycle_length = visited[j] - rem
                steps = rem % cycle_length
                go(j, steps)
                return
            visited[j] = rem
            rem -= 1
            j = graph[j]

        nonlocal ans
        if not ans:
            ans = j
        return j

    dfs(1, k)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 48784
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

vector<vector<vector<double>>> dp(301, vector<vector<double>>(301, vector<double>(301, -1)));

double steps(int x, int y, int z, int n)
{
    if (x == 0 && y == 0 && z == 0)
        return 0;
    if (x < 0 || y < 0 || z < 0)
        return 0;
    if (dp[x][y][z] != -1)
        return dp[x][y][z];

    double p0 = (n - x - y - z) / (n * 1.0),
           p1 = (x) / (n * 1.0),
           p2 = (y) / (n * 1.0),
           p3 = (z) / (n * 1.0);

    double sol = (1.0 + p1 * steps(x - 1, y, z, n) + p2 * steps(x + 1, y - 1, z, n) + p3 * steps(x, y + 1, z - 1, n)) / (1.0 - p0);
    //cout << "(" << x << ", " << y << ", " << z << ")" << sol << endl;
    dp[x][y][z] = sol;
    return sol;
}

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

    int n;
    cin >> n;

    int x = 0, y = 0, z = 0, t;
    for (int i = 0; i < n; ++i)
    {
        cin >> t;
        if (t == 1)
            ++x;
        if (t == 2)
            ++y;
        if (t == 3)
            ++z;
    }
    cout << setprecision(10) << steps(x, y, z, n) << endl;
    return 0;
}

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

int main() {
    string s,t;
    cin >> s;
    cin >> t;
    int a = s.length();
    int b = t.length();
    int ar[a][b];
    for (int i=0;i<a;i++) {
        for(int j=0;j<b;j++) {
            if(s[i] == t[j])
                ar[i][j] = 1;
            else
                ar[i][j] = 0;
        }
    }
    int dp[a][b+1];
    dp[a-1][b-1] = ar[a-1][b-1];
    for(int i=a-2;i>=0;i--) {
        dp[i][b-1] = max(ar[i][b-1], dp[i+1][b-1]);
        dp[i][b] = 0;
    }
    for(int i=b-2;i>=0;i--) {
        dp[a-1][i] = max(ar[a-1][i], dp[a-1][i+1]);
    }
    for (int i=a-2;i>=0;i--) {
        for(int j=b-2;j>=0;j--) {
            int t = dp[i+1][j];
            if(dp[i][j+1] > dp[i+1][j])
                t = dp[i][j+1];
            dp[i][j] =  max(dp[i+1][j+1]+ar[i][j], t);
        }
    }
    string ans = "";
    int max = dp[0][0];
    for(int i=0;i<a;i++) {
        int x = 0;
        for(int j=x;j<b;j++) {
            if((ar[i][j]==1) && (dp[i][j]==max)) {
                ans += s[i];
                x = j++;
                max = max-1;
                break;
                
            }
        }
    }
    cout << ans << endl;
}



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

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define RFOR(i,e,s) for(int (i)=(e)-1;(i)>=(int)(s);(i)--)
#define RREP(i,e) RFOR(i,e,0)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;
typedef priority_queue<int> PQI;
typedef priority_queue<PII> PQII;

const double EPS = 1e-10;
const int N = 100;
const int M = 300;
int n, x, y;
int a[N], b[N], c[N], d[N];
int dp[2][M*2+1][M*2+1];

int main() {
  scanf("%d ", &n);
  scanf("%d%d ", &x, &y);
  REP(i,n) scanf("%d%d%d%d ", a+i, b+i, c+i, d+i);

  memset(dp, -1, sizeof(dp));
  dp[0][M+x][M+y] = 0;
  int crt, nxt;
  REP(i,n) {
    crt = i&1; nxt = (i+1)&1;
    FOR(j,-M,M+1) FOR(k,-M,M+1) {
      if (dp[crt][M+j][M+k]==-1) continue;
      dp[nxt][M+j][M+k] = max(dp[nxt][M+j][M+k], dp[crt][M+j][M+k]);
      if (0<=M+j-a[i] && M+k+b[i]<=M*2)
        dp[nxt][M+j-a[i]][M+k+b[i]] = max(dp[nxt][M+j-a[i]][M+k+b[i]], dp[crt][M+j][M+k]);
      if (0<=M+k-c[i])
        dp[nxt][M+j][M+k-c[i]] = max(dp[nxt][M+j][M+k-c[i]], dp[crt][M+j][M+k] + d[i]);
    }
    memset(dp[crt], -1, sizeof(dp[crt]));
  }

  int res = 0;
  REP(j,M+1) REP(k,M+1) res = max(res, dp[nxt][M+j][M+k]);

  printf("%d\n", res);

  return 0;
}

Measured memory_bytes: 4028
#include "iostream"
#include "math.h"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "numeric"
#include "iomanip"
using namespace std;
typedef long long ll;

int main() {
	int n;
	string str;
	cin >> n >> str;
	int cnt = 0;
	for (int i = 0; i <= n - 3; i++) {
		if (str[i] == 'A'&&str[i + 1] == 'B'&&str[i + 2] == 'C') {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>



int main()
{
    int n, t, x, y;
    int min = 2000;
    std::cin >> n >> t;
    for (int i = 1; i <= n; i++) {
        std::cin >> x >> y;
        if (y <= t) {
            if (x <= min)
                min = x;
        }
    }
    if (min == 2000)
        std::cout << "TLE";
    else
        std::cout << min;

    return 0;
}


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

int main(){
    int N; cin>>N;
    vector<int> a(N);
    
    int sum = 0;
    rep(i,N){
        cin>>a[i];
        sum = sum xor a[i];
    }
    // 合計が0じゃないならNo
    if(sum != 0){
        cout << "No" << endl;
        // return 0;
    }else{
        cout << "Yes" << endl;
    }

    // bool ck=true;
    // for(int i=0; i<N; i++){
    //     int x = a[i];
        
    //     for(int j=0; j<N; j++){
    //         if(i==j) continue;
    //         sum = sum xor a[j];
    //     }

    //     if(x != sum){
    //         ck=false;
    //     }
    // }

    // if(ck){
    //     cout << "Yes" << endl;
    // }else{
    //     cout << "No" << endl;
    // }
}


Measured memory_bytes: 3784
#include <stdio.h>
#include <string.h>
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	char a1[15], b1[15];
	for(int i=0;i<a;i++)
	    a1[i] = b+48;
	a1[a] = '\0';
	for(int i=0;i<b;i++)
	    b1[i] = a+48;
	b1[b] = '\0';
	
//	printf("%s %s\n", a1, b1);
	if(strcmp(a1, b1)<0)
	    printf("%s\n", a1);
	else printf("%s\n", b1);
	return 0;
}

Measured memory_bytes: 128
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define int ll
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=200010,Inf=1e18+10;
int n,m,a[N],b[N],sum[N],f[N],p[N],dp[N],vis[N];
int find(int x){return f[x]!=x?f[x]=find(f[x]):f[x];}
vector<int>G[N];
bool cmp(int A,int B){return a[A]<a[B];}
signed main(){
	n=gi();m=gi();
	for(int i=1;i<=n;i++){
		a[i]=gi();b[i]=gi();a[i]=max(a[i]-b[i],0ll);
		p[i]=f[i]=i;sum[i]=b[i];dp[i]=a[i];
	}
	for(int i=1;i<=m;i++){int u=gi(),v=gi();G[u].push_back(v);G[v].push_back(u);}
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++){
		int u=p[i];vis[u]=1;
		for(int v:G[u])
			if(vis[v]){
				int x=find(u),y=find(v);
				if(x!=y){
					f[y]=x;sum[x]+=sum[y];
					dp[x]=min(dp[x],max(dp[y],a[x]-sum[y]));
				}
			}
	}
	printf("%lld\n",dp[find(1)]+sum[find(1)]);
	return 0;
}


Measured memory_bytes: 18808
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  int Q; cin >> Q;
  priority_queue<int> zen;
  priority_queue<int,vector<int>,greater<int>> kou;
  ll sum_b = 0,sum_zen = 0, sum_kou = 0;
  rep(i,Q){
    int type;
    cin >> type;
    if(type == 1){//更新クエリ
      int a,b; cin >> a >> b;
      sum_b += b;
      if(zen.size() > kou.size()){//前半の方がsizeが大きい場合
        int tmp = zen.top();
        if(tmp > a){
          zen.pop(); sum_zen -= tmp;
          kou.push(tmp); sum_kou += tmp;
          zen.push(a); sum_zen += a;
        }else{
          kou.push(a); sum_kou += a;
        }
      }else{//前半と後半のsizeが同じ場合
        if(zen.empty()){
          zen.push(a); sum_zen += a;
        }else{
          int tmp = kou.top();
          if(tmp > a){
            zen.push(a); sum_zen += a;
          }else{
            kou.pop(); sum_kou -= tmp;
            zen.push(tmp); sum_zen += tmp;
            kou.push(a); sum_kou += a;
          }        
        }
      }
    }else{//求値クエリ
      ll x = zen.top();
      ll ans = (x * (int)zen.size() - sum_zen) + (sum_kou - x * (int)kou.size()) + sum_b;
      cout << x << " " << ans << endl; 
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 3452
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cstring>
#include <map>
#include <stack>
using namespace std;

short ok[5000][5000];
vector<int> e[5000];
int calc(int x){
	queue<int> Q;
	Q.push(x);
	ok[x][x] = 0;
	while( Q.size() ){
		int q = Q.front(); Q.pop();
		for(int i = 0 ; i < e[q].size() ; i++){
			int go = e[q][i];
			if( ok[x][go] == -1 ){
				ok[x][go] = ok[x][q] + 1;
				Q.push(go);
			}
		}
	}
}
int C[5000],R[5000];
int dn[5000];

struct NODE{
	int pos,cost;
	NODE(int pos,int cost) : pos(pos), cost(cost) {}
};

bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
int main(){
	memset(ok,-1,sizeof(ok));
	int N,K;
	cin >> N >> K;
	for(int i = 0 ; i < N ; i++){
		cin >> C[i] >> R[i];
	}
	for(int i = 0 ; i < K ; i++){
		int s,t;
		cin >> s >> t;
		s--,t--;
		e[s].push_back(t);
		e[t].push_back(s);
	}
	for(int i = 0 ; i < N ; i++) calc(i);
	
	priority_queue<NODE> Q;
	Q.push(NODE(0,0));
	while( Q.size() ){
		NODE q = Q.top(); Q.pop();
		if( dn[q.pos]++ ) continue;
		if( q.pos == N - 1 ){
			cout << q.cost << endl;
			return 0;
		}
		for(int i = 0 ; i < N ; i++){
			if( ok[q.pos][i] <= R[q.pos] ){
				Q.push(NODE(i,q.cost+C[q.pos]));
			}
		}
	}
}

Measured memory_bytes: 52336
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e2+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a[3][3];
	for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin>>a[i][j];
	int n;
	cin>>n;
	// int b[n];
	map<int,int> ma;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		ma[x]++;
	}
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(ma[a[i][j]])
			{
				a[i][j]=1;
			}
			else a[i][j]=0;
		}
	}
	for(int i=0;i<3;i++)
	{
		int cnt1=0,cnt2=0;
		for(int j=0;j<3;j++)
		{
			cnt1+=a[i][j];
			cnt2+=a[j][i];
		}
		if(cnt1==3||cnt2==3)
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	if(a[0][0]&&a[1][1]&&a[2][2])
	{
		cout<<"Yes\n";
		return 0;
	}
	if(a[0][2]&&a[1][1]&&a[2][0])
	{
		cout<<"Yes\n";
		return 0;
	}
	cout<<"No\n";
}
// I never lose. I either win or I learn

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    };

    let cnt_of_x_to_0 = x.abs() / d;
    if cnt_of_x_to_0 > k {
        println!("{}", (x.abs() - k * d).abs());
        return;
    };

    let k = k - cnt_of_x_to_0;
    if k % 2 == 0 {
        println!("{}", (x.abs() - cnt_of_x_to_0 * d).abs());
    } else {
        println!("{}", (x.abs() - cnt_of_x_to_0 * d - d).abs());
    }
}


Measured memory_bytes: 2196
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l)
	

a,b = list(map(int, stdin.readline().rstrip().split()))
if(a == b):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 5612
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,a[100005],i,ans;
	unsigned long long sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	sort(a,a+n);
	sum=0;
	ans=0;
	for(i=0;i<n;i++)
	{
		if(a[i]<=2*sum)
		{
			sum+=a[i];
			ans++;
		}
		else
		{
			sum+=a[i];
			ans=1;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {
    ll X, K, D;
    cin >> X >> K >> D;

    // if(abs(X) < D) {
    //     if(K % 2 == 0) {
    //         cout << D << endl;
    //     } else {
    //         ll x2 = X < 0 ? X + D : X - D;
    //         cout << abs(x2) << endl;
    //         return 0;
    //     }
    // }

    X = abs(X);
    ll k = X / D;
    if(abs(X - D * k) > abs(X - D * (k + 1))) {
        k++;
    }
    if(k > K) {
        ll x2 = X - K * D;
        cout << abs(x2) << endl;
        return 0;
    }

    if(K % 2 == k % 2) {
        ll x2 = X - k * D;
        cout << abs(x2) << endl;
        return 0;
    } else {
        ll x3 = X - (k + 1) * D;
        ll x4 = X - (k - 1) * D;
        ll x2 = min(abs(x3), abs(x4));
        cout << x2 << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
const int INF = 1001001001;
 
int main() {
    int n;
  
    cin >> n;
    map<string, vector<int>> book;
    map<string, int> index;

    rep(i,n) {
        string name;
        int point;
        cin >> name >> point;
        book[name].push_back(point);
        index[name+to_string(point)] = i+1;
    }

    for(auto i : book) {
        sort(i.second.rbegin(), i.second.rend());
    #if 1
        for(auto j : i.second) {
            cout << index[i.first + to_string(j)] << endl;
        }
    #endif
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
        int i;
        char str[1000];

        gets(str);
        for(i=0;str[i+4];i++){
                if(str[i]=='a'&&str[i+1]=='p'&&str[i+2]=='p'&&str[i+3]=='l'&&str[i+4]=='e'){
                        str[i]='p';str[i+1]='e';str[i+2]='a';str[i+3]='c';str[i+4]='h';
                }
                else if(str[i]=='p'&&str[i+1]=='e'&&str[i+2]=='a'&&str[i+3]=='c'&&str[i+4]=='h'){
                        str[i]='a';str[i+1]='p';str[i+2]='p';str[i+3]='l';str[i+4]='e';
                }
        }
        puts(str);
        return 0;
}

Measured memory_bytes: 524
K, N = input().split()
k = int(K)
n = int(N)
A = list(map(int, input().split()))
B = []
for j in range(n):
    if j != n-1:
        B.append(A[j+1] - A[j])
    else:
        B.append(k - A[n-1] + A[0])
print(k - max(B))

Measured memory_bytes: 26444
import math
import itertools


def calc(x1y1, x2y2):
    x1, y1 = x1y1
    x2, y2 = x2y2
    return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)


N = int(input())
addresses = []

for _ in range(N):
    addresses.append(list(map(int, input().split())))

ways = list(itertools.permutations(list(range(N))))

ans = 0
for x in ways:
    dist = 0
    for i in range(N - 1):
        dist += calc(addresses[x[i]], addresses[x[i + 1]])
    ans += dist

print(ans / len(ways))


Measured memory_bytes: 13768
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    map<lint, lint> mp;
    for(lint i=0; i<9; i++) {
        lint a;
        cin >> a;
        mp[a] = i;
    }

    lint n;
    cin >> n;

    vector<lint> v;
    for(lint i=0; i<n; i++) {
        lint b;
        cin >> b;
        if(mp.count(b))  v.push_back(mp[b]);
    }

    auto contain = [&](lint a, lint b, lint c) {
        bool ok = true;
        ok &= (count(v.begin(), v.end(), a) != 0);
        ok &= (count(v.begin(), v.end(), b) != 0);
        ok &= (count(v.begin(), v.end(), c) != 0);
        return ok;
    };

    bool ans = false;

    ans |= contain(0,1,2);
    ans |= contain(3,4,5);
    ans |= contain(6,7,8);
    ans |= contain(0,4,8);
    ans |= contain(2,4,6);
    ans |= contain(0,3,6);
    ans |= contain(1,4,7);
    ans |= contain(2,5,8);

    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int H, N;
  cin >> H >> N;
  vector<pair<int, int>> magics(N+1);
  for (int n = 1; n <= N; ++n) {
    int A, B;
    cin >> A >> B;
    magics[n] = {A, B};
  }
  sort(magics.begin(), magics.end());

  vector<vector<int>> dp(H+1, vector<int>(N+1, 1000000001));
  for (int h = 1; h <= H; ++h) {
    for (int n = 1; n <= N; ++n) {
      int mp = magics[n].second;
      if (magics[n].first <= h) {
        mp = static_cast<int>(ceil(h / static_cast<float>(magics[n].first))) * magics[n].second;
        mp = min(mp, dp[h-magics[n].first][n] + magics[n].second);
      }
      dp[h][n] = min(mp, dp[h][n-1]);
    }
  }
  cout << dp[H][N] << endl;

  return 0;
}


Measured memory_bytes: 42840
#include<stdio.h>
int main(void){
	char S[3],T[3];
	int i;
	int j=0;
	//天気予報
		scanf("%s",S);
	//実際の天気
		scanf("%s",T);
		for(i=0;i<3;i++){
				if(S[i]==T[i]){
					j+=1;
				}
			}
		printf("%d",j);
	return 0;
}		

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

INF = 1 << 20

# bitで１が立っているidxのカードがソートされて左詰めで並んでいるとき、その右端（＝最大のカード）がsとなる最小コスト
dp = [[INF for _ in range(51)] for _ in range(1 << N)]
dp[0][0] = 0

for bit in range(1 << N):

    # 既に並べてあるカードの枚数
    num_used = bin(bit).count("1")

    curr = num_used
    remaining = []
    for i in range(N):
        # bitのi番目に１が立っていない（＝まだ選ばれていない）とき
        if not(bit & (1 << i)):
            remaining.append((i, curr))
            curr += 1

    for s in range(51):
        # あるカードの並べ方について、右端をsにできないならスキップ
        if dp[bit][s] >= INF:
            continue

        for ini, curr in remaining:
            # iniの場所に最初いたカードを、num_usedの位置に持ってくるので、その偶奇によって表か裏かがわかる
            num = A[ini] if abs(num_used - ini) % 2 == 0 else B[ini]

            # numがsより小さい場合、整列したカードの最後尾につけられない
            if num >= s:
                # ある選び方で並んでいるカード群に、ini番目のカードを新たに最後尾に追加したとき、最後尾がnumとなる最小コスト
                dp[bit | (1 << ini)][num] = min(dp[bit | (1 << ini)][num], dp[bit][s] + abs(num_used - curr))

ans = INF
for i in range(51):
    ans = min(ans, dp[-1][i])

print(ans if ans < INF else -1)

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

using namespace std;
using ll = long long;

int main() {
    int n = 0;
    cin >> n;
    int cnt = 0;
    int MIN = 1001001;
    for(int i = 0;i < n;i++){
        int p = 0;
        cin >> p;
        MIN = min(MIN,p);
        if(MIN >= p){
            cnt ++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    int n;
    cin >> n;
    int a[n];
    int num[1100000];
    fill(num,num+1100000,0);
    for (ll i=0;i<n;i++){
        cin >> a[i];
        num[a[i]]++;
    }
    
    bool p=true,s=true;
    bool era[1100000];
    fill(era,era+1100000,true);
    for (ll i=2;i<=1000000;i++){
        if (era[i]){
            int con=0;
            for (ll j=i;j<=1000000;j+=i){
                con+=num[j];
                era[j]=false;
            }
            if (con>1){
                p=false;
            }
            if (con==n){
                s=false;
            }
        }
    }
    if (p){
        cout << "pairwise coprime" << endl;
    }else if (s or num[1]){
        cout << "setwise coprime" << endl;
    }else{
        cout << "not coprime" << endl;
    }
    return 0;
}


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

struct Magic {
  int damage;
  int cost;
};

const int INF = pow(2, 30);

int main() {
  int H, N;
  cin >> H >> N;
  vector<Magic> magics(N);
  
  int max_damage = 0;
  
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    Magic m = { a, b };
    magics.at(i) = m;
    max_damage = max(max_damage, m.damage);
  }
    
  vector<int> memo(H + max_damage, INF);
  
  // 1行目初期化
  memo.at(0) = 0;
  
  for (int i = 0; i < N; i++) {
    Magic m = magics.at(i);
    for (int damage = m.damage; damage < H + max_damage; damage++) {
      memo.at(damage) = min(
        memo.at(damage),
        memo.at(damage - m.damage) + m.cost
      );
    }
  }
  
  int answer = INF;
  
  for (int i = H; i < H + max_damage; i++) {
    answer = min(answer, memo.at(i));
  }

  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll a,b,c;
  cin >> a >> b >> c;
  for(int i=100; i>=1; i--) {
    if(a%i==0&&b%i==0) c--;
    if(!c) {
      pr(i);
      return;
    }
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll i;
    ll ans;
    ll sum[N],W;
    cin >> W;
    sum[0]=W;
    for(i=1;i<N;i++){
        cin >> W;
        sum[i]=sum[i-1]+W;
    }
    ans=sum[N-1];
    for(i=0;i<N;i++){
        ans=min(ans,abs(sum[N-1]-2*sum[i]));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	vi S;
	int i, j;
	for (i = 0; i < N; i++){
		int s;
		cin >> s;
		S.push_back(s);
	}
	sort(S.begin(), S.end());
	int ssum = accumulate(S.begin(), S.end(), 0);
	if (ssum % 10 != 0){
		cout << ssum << endl;
	}
	else{
		for (i = 0; i < N; i++){
			if (S[i] % 10 != 0){
				ssum -= S[i];
				break;
			}
		}
		if (ssum % 10 == 0){
			cout << 0 << endl;
		}
		else{
			cout << ssum << endl;
		}
	}
	return 0;
}


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

int main() {
	string s;
	cin >> s;

	int left;
	for(int i = 0; i < s.size(); i++) {
		if(s.at(i) == 'A') {
			left = i;
			break;
		}
	}

	int right;
	for(int i = s.size() - 1; i > - 1; i--) {
		if(s.at(i) == 'Z') {
			right = i;
			break;
		}
	}

	cout << right - left + 1 << endl;

 	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int k = sc.nextInt();
		int s = sc.nextInt();
		int ret = 0;

		for (int i = 0;i <= k;i++) {
			for (int j = 0;j <= k;j++) {
				int t = s-i-j;
				if (0 <= t && t <= k) ret++;
			}
		}

		System.out.println(ret);
	}
}


Measured memory_bytes: 9804
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int cnt = 0;
  for (int x = a; x <= b; x++)
    if (c % x == 0) ++cnt;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3136
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();

        int[] w = new int[n + 1];
        int[] e = new int[n + 1];
        w[0] = 0; // 左から数えていってwの人の数
        e[0] = 0; // 右から数えていってeの人の数

        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'W') w[i + 1] = w[i] + 1;
            else w[i + 1] = w[i];
            if (s[n - i - 1] == 'E') e[i + 1] = e[i] + 1;
            else e[i + 1] = e[i];
        }
        int ans = int.MaxValue;
        for (int i = 0; i <= n; i++)
        {
            ans = Math.Min(ans, w[i] + e[n - i]);
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 14432
/*input
1
1 5
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <functional>
#include <cmath>
#include <cstring>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include <cstdlib>
#include <list>
#include <cassert>
#include <ctime>
#include <fstream>
#include <sstream>
#define fi first
#define se second
#define endl '\n'
#define N 100005
#define INF 1000000000
#define mod 1000000007
#define oo 1000000000000000000
// #define int long long
using namespace std;
typedef pair<int,int> ii;
long long n,res = 0,u,v;
vector<ii> a,b;
// map<ii,bool> done;
vector<pair<int,ii> > adj;
vector<int> pset;
void init(int n){
	pset.assign(n+1,0);
	for(int i=1;i<=n;i++){
		pset[i] = i;
	}
}
int findset(int i){
	if(pset[i] == i) return i;
	return pset[i] = findset(pset[i]);
}
bool issameset(int i,int j){
	return findset(i) == findset(j);
}
void unionset(int i,int j){
	if(issameset(i,j)) return;
	pset[findset(j)] = findset(i);
}
signed main(){
	ios_base::sync_with_stdio(0);
	// freopen(".inp","r",stdin);
	// freopen(".out","w",stdout);
	cin >> n;
	init(n);
	for(int i=1;i<=n;i++){
		cin >> u >> v;
		a.push_back(ii(u,i));
		b.push_back(ii(v,i));
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for(int i=1;i<n;i++){
		adj.push_back(make_pair(a[i].fi - a[i-1].fi,ii(a[i].se,a[i-1].se)));
		adj.push_back(make_pair(b[i].fi - b[i-1].fi,ii(b[i].se,b[i-1].se)));
	}
	sort(adj.begin(),adj.end());
	for(int i=0;i<adj.size();i++){
		u = adj[i].se.fi, v = adj[i].se.se;
		if(issameset(u,v)) continue;
		unionset(u,v);
		res += adj[i].fi;
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 7656
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion

signed main()
{	
	LL a, b, n;
	cin >> a >> b >> n;

	LL ans;
	if (n < b) {
		LL x = n;
		ans = static_cast<LL>(1.0 * a * x / b) - a * static_cast<LL>(1.0 * x / b);
	}
	else {
		LL x = b - 1;
		ans = static_cast<LL>(1.0 * a * x / b) - a * static_cast<LL>(1.0 * x / b);
	}

	col(ans);
	return 0;
}


Measured memory_bytes: 3600
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vvi a(10);
		for(auto&m:a) m.assign(10, 0);

		for(int i=1;i<=n;i++)
		{
			int back=i%10;
			int front=i;
			for(;front>=10;front/=10)
			{
				;
			}
			a[front][back]++;
		}

		ll ans=0;
		for(int i=1;i<=9;i++)
		{
			for(int j=1;j<=9;j++)
			{
				ans+=a[i][j]*a[j][i];
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


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

int main(void) {
    int c, n;

    while ((c = getc(stdin)) != EOF) {
        if (c == '@') {
            n = getc(stdin) - '0';
            c = getc(stdin);
            while (n--) {
                putc(c, stdout);
            }
        }
        else {
            putc(c, stdout);
        }
    }
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
int main(){
	ll a,b,c;
	scl(a);scl(b);scl(c);
	if(a+b>=c){
		pf("No\n");
	}else {
		if(4*a*b<(c-a-b)*(c-a-b))pf("Yes\n");
		else pf("No\n");
	}
}

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

using namespace std;

int solve(const vector<vector<int>> &v_positions,
          const vector<vector<int>> &h_positions, const pair<int, int> &pos) {
  int pos_x = pos.first, pos_y = pos.second, ans = 0;
  const vector<int> &v_pos = v_positions[pos_x], &h_pos = h_positions[pos_y];

  // up, down, left, right
  ans +=
      pos_y - *lower_bound(v_pos.rbegin(), v_pos.rend(), pos_y, greater<int>());
  ans += *lower_bound(v_pos.begin(), v_pos.end(), pos_y) - pos_y;
  ans +=
      pos_x - *lower_bound(h_pos.rbegin(), h_pos.rend(), pos_x, greater<int>());
  ans += *lower_bound(h_pos.begin(), h_pos.end(), pos_x) - pos_x;

  return max(0, ans - 3);
}

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;

  vector<vector<int>> v_positions(w), h_positions(h);
  for (int i = 0; i < h; ++i) {
    h_positions[i].push_back(-1);
    for (int j = 0; j < w; ++j) {
      char ch;
      cin >> ch;
      if (ch == '#') {
        v_positions[j].push_back(i);
        h_positions[i].push_back(j);
      }
    }
    h_positions[i].push_back(w);
  }

  for (int i = 0; i < w; ++i) {
    v_positions[i].push_back(-1);
    v_positions[i].push_back(h);
    sort(v_positions[i].begin(), v_positions[i].end());
  }

  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ans = max(ans, solve(v_positions, h_positions, {j, i}));
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 34432
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int x; cin>>x;
  int ans=1;
  if(x>1){
    for(int i=2;i<x;i++){
      int a=i;
      while(a<=x){
        a*=i;
      }
      a/=i;
      if(a!=i)
      ans=max(ans,a);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

void print(char str[],int a,int b){
    for(int i = a; i <= b; i++)    printf("%c", str[i]);
    printf("\n");
}
void replace(char str[],char p[],int a,int b){
    int p_length = b-a+1;
    for(int i = 0; i < p_length;i++) str[a+i] = p[i];
}
void reverse(char str[],int a,int b){
    int left = a,right = b;
    while(left < right){
        swap(str[left++],str[right--]);
    }
}

int main(int argc, const char * argv[]) {
    char str[1001], p[1001], order[8];
    int q,a,b;
    scanf("%s", str);
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%s %d %d", order, &a, &b);
        switch(order[2]){
        case 'i':
            print(str,a,b);
            break;
        case 'v':
            reverse(str,a,b);
            break;
        case 'p':
            scanf("%s", p);
            replace(str,p,a,b);
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 2672
R,C,K=map(int,input().split())
l=[[0] * C for i in range(R)]
for i in range(K):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  l[a][b]=c
dp=[[0] * C for i in range(R)]
for i in range(R):
  kdp=[0]*4
  for j in range(C):
    if i>0:
      kdp[0]=max(kdp[0],dp[i-1][j])
    for k in range(2,-1,-1):
      kdp[k+1]=max(kdp[k+1],kdp[k]+l[i][j])
      dp[i][j]=max(dp[i][j],kdp[k+1])
print(dp[R-1][C-1])

Measured memory_bytes: 216392
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var output = new Array(N);
	var map = {};
	for(var i = 1; i <= 200; i++){
		for(var j = 1; j <= 200; j++){
			for(var k = 1; k <= 200; k++){
				var add = i*i + j*j + k*k + i*j + j*k + k*i;
				if(map[add] == null){
					map[add] = 0;
				}
				map[add]++;
			}
		}
	}
	for(var i = 0; i < N; i++){
		if(map[i + 1] == null){
			output[i] = 0;
		}else{
			output[i] = map[i + 1];
		}
	}
	myout(myconv(output,9));
}


Measured memory_bytes: 40784
#include <iostream>
using namespace std;
int main()
{
	char input;
	for (int i = 0; i < 3; i++)
	{
		cin >> input;
		if (input == '7')
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"
#define hhh printf("hhh\n")
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int a[maxn];

int main() {
    int n=read();
    int now=0;
    for(int i=1; i<=n; ++i) {
        int d=read();
        if(d==now+1) now=d;
    }
    printf("%d\n", now==0?-1:n-now);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
       Scanner sc = new Scanner(System.in);
       int n = Integer.parseInt(sc.next());
       int[] num = new int[n];
       for(int i = 0; i < n; i++){
           num[i] = Integer.parseInt(sc.next());
       }
       Arrays.sort(num);
       System.out.println(num[n-1]-num[0]);
    }
}

Measured memory_bytes: 21972
a, b, c, x , y = map(int, input().split())
ans = []
# そのまま
ans.append(a*x + b*y)
# 全部1/2
ans.append(max(x, y)*c*2)
# 1/2 あまりをそのまま
p = a if x > y else b
ans.append(min(x, y)*c*2 + (abs(x - y) * p))
print(min(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];
char field[200][200];

int main(){
  cin >> s;
  rep(i,0,s.sz)d[s[i]-'a']++;
  bool f = true;
  rep(i,0,3)if(d[i] != 1)f = false;
  if(f)puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 2304
using System;
 
class PaizaSample
{
	static void Main()
	{
		string input = Console.ReadLine();
		if (input != null) {
			string[] strs = input.Split(' ');
			if (strs.Length == 2) {
				int a = Int32.Parse (strs[0]);
				int b = Int32.Parse (strs[1]);
				Console.WriteLine(a * b + " " + (a + b) * 2);
			}
		}
	}
}

Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    vector<int> cnt(3, 0), upper(3);
    vector<string> s(3);
    for (int i = 0; i < 3; i++){
        cin >> s[i];
        upper[i] = s[i].size();
    }

    int cur = 0;
    while (true) {
        if (cnt[cur] == upper[cur]) {
            printf("%c\n",'A' + cur); return 0;
        }
        int ne = s[cur][cnt[cur]] - 'a';
        cnt[cur]++;
        cur = ne;
    }
}


Measured memory_bytes: 256
S = input()
#print(len(S))

if len(S) == 1:
    print("1")
    exit()

s_list = []
head_num = 10**6 if S[0] == ">" else 0
s_list.append(head_num)
for i in range(len(S)-1):
    if S[i] == ">" and S[i+1] == "<":
        s_list.append(0)
    elif S[i] == "<":
        s_list.append(s_list[i]+1)
    else:
        s_list.append(s_list[i]-1)
if S[len(S)-1] == "<":
    s_list.append(s_list[len(S)-1] +1)
else:
    s_list.append(s_list[len(S)-1] -1)

#print(s_list)
count = 1
s_list[len(s_list)-1] = 0 if s_list[len(s_list)-1] < 0 else s_list[len(s_list)-1] 
#print(s_list)
for i in range(len(S)-1,0,-1):
    if S[i] == ">" and S[i-1] == ">":
    #if S[i] == ">":
        s_list[i] = count
        count += 1
    elif S[i] == ">" and S[i-1] == "<":
        s_list[i] = max(s_list[i-1], s_list[i+1]) + 1
    else:
        count = 1

if S[0] == ">":
    s_list[0] = s_list[1] + 1
if S[len(S)-1] == ">":
    s_list[len(s_list)-1] =  0

#print(len(s_list))
#print(s_list)

sum = 0
for i in range(len(s_list)):
    sum += s_list[i]

print(sum)
    

Measured memory_bytes: 24096
//  main.cpp
//  AGC040A2
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, const char * argv[]) {
    string S;
    cin>>S;
    vector<int>count_L(S.length()+1,0);
    vector<int>count_R(S.length()+1,0);
    // 左側から<の数を調べる
    for (long i=1; i<=S.length(); i++) {
        if (S.at(i-1)=='<') {
            count_L.at(i)=count_L.at(i-1)+1;
        }else{
            count_L.at(i)=0;
        }
    }
    // 右側から>の数を調べる
    for (long j=S.length()-1; j>=0; j--) {
        if (S.at(j)=='>') {
            count_R.at(j)=count_R.at(j+1)+1;
        }else{
            count_R.at(j)=0;
        }
    }
    // 大きい方をその位置の数値にする
    long long ans=0;
    for (long k=0; k<=S.length(); k++) {
        ans+=max(count_L.at(k),count_R.at(k));
    }
    // 合計（答え）を求める
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4740
import sys
#import cython

def main():
    read = lambda: sys.stdin.readline().rstrip()
    import collections

    N, M = map(int,read().split())
    H = list(map(int,read().split()))
    g = collections.defaultdict(set)
    for _ in range(M):
        x, y = map(int,read().split())
        g[x-1].add(y-1)
        g[y-1].add(x-1)

    def dfs(s, height, visited):
        if not g[s] or s in visited: return True
        visited.add(s)
        for nei in g[s]-visited:
            if H[nei] >= height: return False
            #return dfs(nei, height, visited)
        return True
    cnt = 0
    for i in range(N):
        #print(i, dfs(i, H[i], set()))
        cnt += dfs(i, H[i], set())
    
    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 54248