akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
using namespace std;
ll max(ll a, ll b){
    if(a > b) return a;
    return b;
}
ll knapSack(ll W, ll wt[], ll val[], ll n){
    ll K[n + 1][W + 1];
    for(ll i = 0; i <= n; i++){
        for(ll w = 0; w <= W; w++){
            if(i == 0 || w == 0)
                K[i][w] = 0;
            else if(wt[i - 1] <= w)
                K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
            else
                K[i][w] = K[i - 1][w];
        }
    }
    return K[n][W];
}
int main(){
    int n, W;
    cin >> n >> W;
    ll val[n], wt[n];
    for (int i = 0; i < n; i++)
         cin >> wt[i] >> val[i];
    cout << knapSack(W, wt, val, n) << "\n";
    return 0;
}


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

int main(){
    lint N;
    lint A[200002];
    lint sumA = 0;
    lint mindiff = 1e18;

    cin >> N;
    for(lint i=0;i<N;i++){
        cin >> A[i];
        sumA += A[i];
    }
    lint runA = 0;
    for(lint i=0;i<N;i++){
        runA += A[i];
        sumA -= A[i];
        if(abs(runA - sumA) < mindiff){
            mindiff = abs(runA - sumA);
        }
    }
    cout << mindiff << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,tot,b[100001],s,a,bi;
char vis[100001],col[100001];
struct Edge{
	int to,nxt;
}e[400001];
void dfs1(int x){
	vis[x]=1;
	for (int i=b[x];i;i=e[i].nxt){
		int p=e[i].to;
		if (!vis[p]) dfs1(p);
	}
}
int dfs(int x,char c){
	vis[x]=1;
	col[x]=c;
	c^=1;
	int ans=1;
	//printf("x=%d\n");
	for (int i=b[x];i;i=e[i].nxt){
		int p=e[i].to;
		if (!ans) dfs1(p);
		else if (col[p]!=-1){
			if (col[p]!=c) ans=0;
		}else ans=dfs(p,c);
	}
	return ans;
}
void read(int& x){
    x=0;
    int y=1;
    char ch=getchar();
    while (ch<'0'||ch>'9'){
        if (ch=='-') y=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    x=x*y;
}
int main(){
	int i,x,y,t=0,j,k,l;
	long long ans;
	read(n);
	read(m);
	for (i=1;i<=m;++i){
		read(x);
		read(y);
		e[++tot]=(Edge){y,b[x]};
		b[x]=tot;
		e[++tot]=(Edge){x,b[y]};
		b[y]=tot;
	}
	for (i=1;i<=n;++i)
		if (!b[i]){
			++s;
			vis[i]=1;
		}
	memset(col,-1,sizeof(col));
	for (i=1;i<=n;++i){
		if (!vis[i]){
	//printf("ok");
			if (!dfs(i,0)) ++bi;//非二分 
			else ++a;//二分 
		}
	}
	ans=(long long)s*((n<<1)-s)+(long long)a*a+(long long)(a+bi)*(a+bi);
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	int c[1000];
	int i,j;
	for (i = 0;i < 999;i++) {
		int temp = 0;
		for (j = 0;j <= i;j++) {
			temp += j + 1;
		}
		c[i] = temp;
	}
	for (i = 0;i < 998;i++) {
		j = 1;
		while (c[i] - j > a && c[i + 1] - j > b ) j++;
		if (c[i] - j == a && c[i + 1] - j == b) break;
	}
	cout << j << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
using namespace std;
int main()
{
    int n,i,j;
    scanf("%d",&n);
    int a[n][3],b[n][3];
    for(i=0;i<n;++i){
    	for(j=0;j<3;++j){
    		scanf("%d",&a[i][j]);
		}
	}
	memset(b,0,sizeof(b));
	
	for(i=0;i<3;++i){
		b[n-1][i]=a[n-1][i];
	}
	for(i=n-2;i>=0;--i){
		
		b[i][0]=(b[i+1][1]+a[i][0]) >(b[i+1][2]+a[i][0]) ? b[i+1][1]+a[i][0] : b[i+1][2]+a[i][0];
		b[i][1]=(b[i+1][0]+a[i][1]) > (b[i+1][2]+a[i][1]) ? b[i+1][0]+a[i][1] : b[i+1][2]+a[i][1];
		b[i][2]=(b[i+1][0]+a[i][2]) > (b[i+1][1]+a[i][2]) ? b[i+1][0]+a[i][2] : b[i+1][1]+a[i][2];
	}
	
	if(b[0][0]>b[0][1] && b[0][0]>b[0][2]){
		printf("%d",b[0][0]);
	}
	else if(b[0][1]>b[0][0] && b[0][1]>b[0][2]){
		printf("%d",b[0][1]);
	}
	else{
		printf("%d",b[0][2]);
	}
    
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 998244353
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 200003
#define pc(x) putchar_unlocked(x);
int dep[mx],a[mx];
int n;
string ss;
set<int>isi[30];
int dp(int now){
	if(now==n)return 1;
	if(now==n+1)return 0;
	int&ret=dep[now];
	if(ret!=-1)return ret;
	ret=1e9;
	for(int i=0;i<26;i++){
		auto nxt=isi[i].lower_bound(now);
		ret=min(ret,dp(*nxt+1)+1);
	}
	return ret;
}
vector<int>ans;
void back(int now){
	if(now==n+1)return;
	if(now==n){
		ans.pb(0);
		return;
	}
	int ret=dep[now];
	for(int i=0;i<26;i++){
		auto nxt=isi[i].lower_bound(now);
		if(ret==dp(*nxt+1)+1){
			ans.pb(i);
			back(*nxt+1);
			return;
		}
	}
}

int main(){
	cin>>ss;
	n=ss.length();
	for(int i=0;i<n;i++)a[i]=ss[i]-'a';
	for(int i=0;i<n;i++){
		isi[a[i]].insert(i);
	}
	for(int i=0;i<26;i++)isi[i].insert(n);
	reset(dep,-1);
	int jaw=dp(0);
	back(0);
	for(int i:ans){
		char a=i+'a';
		cout<<a;
	}
}




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

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i = 0; i < tx - sx; i++){
        cout << 'R';
    }
    for(int i = 0; i < ty - sy + 1; i++){
        cout << 'U';
    }
    for(int i = 0; i < tx - sx + 1; i++){
        cout << 'L';
    }
    for(int i = 0; i < ty - sy + 1; i++){
        cout << 'D';
    }
    cout << 'R' << 'D';
    for(int i = 0; i < tx - sx + 1; i++){
        cout << 'R';
    }
    for(int i = 0; i < ty - sy + 1; i++){
        cout << 'U';
    }
    for(int i = 0; i < tx - sx + 1; i++){
        cout << 'L';
    }
    for(int i = 0; i < ty - sy; i++){
        cout << 'D';
    }
    cout << endl;
}

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

int h, w, k, sx, sy, ex, ey;

vector<vector<char>> grid;
vector<vector<int>> dist, vis;
int dix[] = { 0, 0, -1, 1 };
int diy[] = { 1, -1, 0, 0 };

void bfs(int sx, int sy)
{
    queue<pair<int, int>> q;
    q.push({ sx, sy });
    vis[sx][sy] = 1;
    while (!q.empty()) {
        int x = q.front().first, y = q.front().second;
        q.pop();
        for (int direction = 0; direction < 4; direction++) {
            for (int length = 1; length <= k; length++) {
                int dx = x + (dix[direction] * length), dy = y + (diy[direction] * length);
                if (dx < 1 || dy < 1 || dx > h || dy > w)
                    break;
                else if (grid[dx][dy] == '@')
                    break;
                else if (vis[dx][dy] && dist[dx][dy] < dist[x][y] + 1)
                    break;
                else if (vis[dx][dy])
                    continue;
                vis[dx][dy] = 1;
                dist[dx][dy] = dist[x][y] + 1;
                q.push({ dx, dy });
            }
        }
    }
}

void solve()
{
    cin >> h >> w >> k >> sx >> sy >> ex >> ey;
    grid = vector<vector<char>>(h + 1, vector<char>(w + 1));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++)
            cin >> grid[i][j];
    }
    dist = vis = vector<vector<int>>(h + 1, vector<int>(w + 1, 0));
    bfs(sx, sy);
    if (!vis[ex][ey])
        cout << -1 << '\n';
    else
        cout << dist[ex][ey] << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 44364
#include <stdio.h>

int main(void){

	char mark[9];
	int num[9], r_num[9], b_num[9], g_num[9], set, i, j;
	

	scanf("%d", &set);	/* ???????????°?????\??? */
	int ans[set];

	for(i = 0 ; i < 9 ; i++){	/* ????????????????????? */
		r_num[i] = 0;
		g_num[i] = 0;
		b_num[i] = 0;
	}

	for(i = 0 ; i < set ; i++){
		ans[i] = 0;
	}

	for(i = 0 ; i < set ; i++){	/* ???????????°?????°????????? */

	for(j = 0 ; j < 9 ; j++){
		scanf("%d", &num[j]);
		}
		for(j = 0 ; j < 9 ; j++){

	if(j == 9){
		scanf("%c", &mark[j]);
			}else
	{

	scanf(" %c", &mark[j]);
		}
			}

	for(j = 0 ; j < 9 ; j++){		/* ????????¨?????????????????? */
		if(mark[j] == 'R'){
			r_num[j] = num[j];
	}
		else if(mark[j] == 'G'){
			g_num[j] = num[j];
	}
		else if(mark[j] == 'B'){
			b_num[j] = num[j];
			}
		}

	sort(r_num);	/* ??????????????? */
	sort(g_num);	/* ??????????????? */
	sort(b_num);	/* ??????????????? */

	if(judge(r_num) == 1 && judge(g_num) == 1 && judge(b_num) == 1){	/* ???????????? */
			ans[i] = 1;
		}else
	{
		ans[i] = 0;
	}

		for(j = 0 ; j < 9 ; j++){	/* ????????????????????? */
			r_num[j] = 0;
			g_num[j] = 0;
			b_num[j] = 0;
		}
	}

		for(i = 0 ; i < set ; i++){
			printf("%d\n", ans[i]);
	}

	return 0;
}


void sort(int num[]){

	int p, q, tmp;

	for(p = 0; p < 8; p++){
		for(q = p + 1; q < 9; q++){
			if(num[p] > num[q]){
				tmp = num[p];
				num[p] = num[q];
				num[q] = tmp;
				}
			}
		}   
	}

int judge(int num[]){

	int cnt = 0;
	int i, j, k;

	for(i = 0; i < 9; i++){
		if(num[i] == 0){
			cnt++;			/* ???????????????0?????°??????????????? */
		}
	}

	if(cnt % 3 != 0){		/* 0?????°???3????????°??§???????????°0????????? */
		return 0;
	}

	for(i = cnt; i < 9; i++){	/* ???????????¶?????????????????????????????? */
		if(num[i] != 0){
			for(j = cnt; j < 9; j++){
				if(num[j] != 0 && j != i){
					if(num[i] == num[j]){
						for(k = cnt; k < 9; k++){
							if(num[k] != 0 && (k != i && k != j)){
								if(num[i] == num[k]){
									num[i] = 0;
									num[j] = 0;
									num[k] = 0;
								}
							}
						}
					}

					else if(num[j] - num[i] == 1){
						for(k = cnt; k < 9; k++){
							if(num[k] != 0 && (k != i && k != j)){
								if(num[k] - num[j] == 1){
									num[i] = 0;
									num[j] = 0;
									num[k] = 0;
								}
							}
						}
					}
				}
			}
		}
	}
	cnt = 0;
	for(i = 0; i < 9; i++){
		if(num[i] == 0){
			cnt++;
		}
	}
			if(cnt == 9){
				return 1;
			}
		else
	{

		return 0;
	}

}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

unsigned long long L(int n)
{
    static unsigned long long l[86] = {};
    if (n==0){
        return 2;
    }
    if (n==1){
        return 1;
    }
    if (l[n]==0){
        l[n] = L(n - 1) + L(n - 2);
    }
    return l[n];
}

int main(){
    int n;
    cin >> n;
    cout << L(n) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::string A, std::string B){
    if (A.size() > B.size()) cout << "GREATER" << '\n';
    else if(A.size() < B.size()) cout << "LESS" << '\n';
    else {
        bool loop = true;
        REP(i, A.size()) {
            if (A[i] == B[i]) continue ;
            if (A[i] > B[i]) {
                loop = false;
                cout << "GREATER" << '\n';
                break ;
            } else {
                loop = false;
                cout << "LESS" << '\n';
                break ;
            }
        }
        if (loop) cout << "EQUAL" << '\n';
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string A;
    std::cin >> A;
    std::string B;
    std::cin >> B;
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    int c = Integer.parseInt(sc.next());
if(a+b==c||a+c==b||c+b==a){
    out.println("Yes");
}else{
    out.println("No");
}
}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define inf (1e8)
using namespace std;

int n,m,c,s,g;
int dis[21][101][101];
int cost[21][20001];

class State{
public:
  int v,cost;
  State(int v,int cost):v(v),cost(cost){}
  bool operator<(State s)const{
    return s.cost<cost;
  }
};

void init(){
  for(int i=0;i<c;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	if(j==k)dis[i][j][k]=0;
	else dis[i][j][k]=inf;
      }
    }
    for(int j=0;j<20001;j++)cost[i][j]=0;
  }
}

void wf(){
  for(int a=0;a<c;a++)
    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  dis[a][i][j]=min(dis[a][i][j],dis[a][i][k]+dis[a][k][j]);
}

int main()
{
  int x,y,d,e;

  while(1){
    cin>>n>>m>>c>>s>>g;
    if(n+m+c+s+g==0)break;
    s--;g--;
    init();
    for(int i=0;i<m;i++){
      cin>>x>>y>>d>>e;
      x--;y--;e--;
      dis[e][x][y]=min(d,dis[e][x][y]);
      dis[e][y][x]=min(d,dis[e][y][x]);
    }
    int p[21];
    for(int i=0;i<c;i++)cin>>p[i];
    for(int i=0;i<c;i++){
      int q[51]={},k[51]={};
      for(int j=0;j<p[i]-1;j++)cin>>q[j];
      q[p[i]]=inf;
      for(int j=0;j<p[i];j++)cin>>k[j];
      int tmp=0;
      for(int j=1;j<20001;j++){
	cost[i][j]=cost[i][j-1]+k[tmp];
	if(j==q[tmp])tmp++;
      }
    }
    wf();
  
    priority_queue<State> pq;
    int dp[101];
    for(int i=0;i<101;i++)dp[i]=inf;
    dp[s]=0;
    pq.push(State(s,0));
    int ans=-1;
    while(!pq.empty()){
      State u = pq.top();
      pq.pop();
      //cout<<u.v<<" "<<u.cost<<endl;
      if(u.v==g){
	ans=u.cost;
	break;
      }
      if(dp[u.v]<u.cost)continue;
      for(int i=0;i<n;i++){
	if(i==u.v)continue;
	for(int j=0;j<c;j++){
	  if(dis[j][u.v][i]==inf)continue;
	  int ncost=dp[u.v]+cost[j][dis[j][u.v][i]];
	  if(ncost<dp[i]){
	    dp[i]=ncost;
	    pq.push(State(i,ncost));
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

int palin(string s){
  string b= s;
  reverse(s.begin(),s.end());
  return s==b;
}

int main(){
 string a;
  cin >> a;
  int n = (a.length()) - 1;
  string b = a.substr(0,n/2);
  string c = a.substr((n+3)>>1,n+1);
  //cout << palin("a");
  if(palin(a)&&palin(b)&&palin(c))cout <<"Yes";
  else cout <<"No";
}

Measured memory_bytes: 256
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
use std::collections::{HashMap, HashSet};
fn main() {
    let n: usize = read();
    let a: Vec<i32> = read_vec();
    let mut l = HashMap::new();
    let mut r = HashMap::new();
    let mut x = HashSet::new();
    for i in 0..n {
        let t = vec![i as i32 + 1 + a[i], i as i32 + 1 - a[i]];
        *l.entry(t[0]).or_insert(0) += 1;
        *r.entry(t[1]).or_insert(0) += 1;
        x.insert(t[0]);
        x.insert(t[1]);
    }
    let mut ans: i64 = 0;
    for i in x {
        if l.contains_key(&i) && r.contains_key(&i) {
            ans += l[&i] * r[&i];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 18280
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, Q;
    string str;
    cin >> N >> Q >> str;

    vector<int> S(N + 1, 0);
    for (int i = 1; i < N; i++) {
        S[i+1] = S[i];
        if (str[i - 1] == 'A' && str[i] == 'C') S[i+1]++;
    }

    for (int q = 0; q < Q; q++) {
        int l, r;
        cin >> l >> r;
        cout << S[r] - S[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
n=int(input())
l=[]
for i in range(n):
  l.append(input().split())
last=input()
ind=0
for i in range(n):
  if l[i][0]==last:
    ind=i
sum=0    
for i in range(ind+1,n):
  sum+=int(l[i][1])
print(sum)  

Measured memory_bytes: 3064
from itertools import permutations


def main():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))

    A = [i for i in range(1, N+1)]
    As = list(permutations(A))
    for i in range(len(As)):
        a = As[i]
        for j in range(len(a)):
            if a[j] != P[j]:
                break
        else:
            p_rank = i
            break

    for i in range(len(As)):
        a = As[i]
        for j in range(len(a)):
            if a[j] != Q[j]:
                break
        else:
            q_rank = i
            break
    print(abs(p_rank-q_rank))


if __name__ == '__main__':
    main()

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

using namespace std;

int main()
{
  int N, M;
  cin >> N >> M;
  int latte[200000] = {}, malta[200000] = {};
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if(a == 0) latte[b] = true;
    if(b == N - 1) malta[a] = true;
  }
  for(int i = 0; i < N; i++) {
    if(latte[i] && malta[i]) {
      cout << "POSSIBLE" << endl;
      return (0);
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#define MAXN 190
#define rint register int
#define LL long long
using namespace std;

int h, w, num[MAXN][MAXN], f[MAXN][MAXN][MAXN], g[MAXN][MAXN][MAXN], nf[MAXN][MAXN][MAXN], ng[MAXN][MAXN][MAXN];
char mp[MAXN][MAXN];

int main()
{
    scanf("%d%d", &h, &w);
    for(rint i=1; i<=h; ++i)
    {
        scanf("%s", mp[i]+1);
        for(rint j=1; j<=w; ++j) num[i][j]=num[i][j-1]+(mp[i][j]=='#');
        for(rint j=1; j<=w; ++j) num[i][j]+=num[i-1][j];
    }
    for(rint i=1; i<=h; ++i)
        for(rint j=i; j<=h; ++j)
            for(rint k=1; k<=w; ++k)
            {
                f[i][j][k]=k-1;
                for(rint l=k; l<=w; ++l)
                {
                    int temp=num[j][l]-num[i-1][l]-num[j][k-1]+num[i-1][k-1];
                    if((j-i+1)*(l-k+1)==temp || !temp) f[i][j][k]=l;
                    else break;
                }
            }
    for(rint i=1; i<=w; ++i)
        for(rint j=i; j<=w; ++j)
            for(rint k=1; k<=h; ++k)
            {
                g[i][j][k]=k-1;
                for(rint l=k; l<=h; ++l)
                {
                    int temp=num[l][j]-num[l][i-1]-num[k-1][j]+num[k-1][i-1];
                    if((j-i+1)*(l-k+1)==temp || !temp) g[i][j][k]=l;
                    else break;
                }
            }
    if(f[1][h][1]==w) {printf("0\n"); return 0;}
    for(rint ans=1; ; ans++)
    {
        for(rint i=1; i<=h; ++i)
            for(rint j=i; j<=h; ++j)
                for(rint k=1; k<=w; ++k) nf[i][j][k]=(f[i][j][k]==w?w:f[i][j][f[i][j][k]+1]);
        for(rint i=1; i<=w; ++i)
            for(rint j=i; j<=w; ++j)
                for(rint k=1; k<=h; ++k) ng[i][j][k]=(g[i][j][k]==h?h:g[i][j][g[i][j][k]+1]);
        for(rint i=1; i<=h; ++i)
            for(rint j=i; j<=h; ++j)
                for(rint k=1; k<=w; ++k)
                {
                    int temp=nf[i][j][k];
                    while(ng[k][temp+1][i]>=j && temp<w) temp++;
                    f[i][j][k]=temp;
                }
        for(rint i=1; i<=w; ++i)
            for(rint j=i; j<=w; ++j)
                for(rint k=1; k<=h; ++k)
                {
                    int temp=ng[i][j][k];
                    while(nf[k][temp+1][i]>=j && temp<h) temp++;
                    g[i][j][k]=temp; 
                }
        if(f[1][h][1]==w) {printf("%d\n", ans); return 0;}
    }
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans_max = min(a, b);
  int ans_min;
  ans_min = a + b - n;
  if (ans_min < 0) {
    ans_min = 0;
  }

  cout << ans_max << " " << ans_min << endl;
}


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

using ll = long long;
ll mod = 1e9 + 7;

ll power(ll n, ll p){   // n^p % mod    
    if(p == 0) return 1;
    if(p % 2 == 0){
        ll half = power(n, p/2);
        return half * half % mod;
    }else{
        return n * power(n, p-1) % mod;
    }
}

ll comb(ll n, ll k){
    ll ans = 1;
    for(int i=1; i<=k; i++){
        ans = ((ans * (n-i+1)) % mod * power(i, mod-2) % mod ) % mod;
    }
    return ans;
}

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = power(2, n) - comb(n, a) - comb(n, b) -1;
    while(ans < 0) ans += mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
using pll=pair<long long, long long>;
int main(){
	int n; cin>>n;
	vector<pll> pos(n);
	for(int i=0;i<n;i++) cin>>pos[i].first>>pos[i].second;

	int par=(abs(pos[0].first)+abs(pos[0].second))%2;
	for(int i=0;i<n;i++){
		int par2=(abs(pos[i].first)+abs(pos[i].second))%2;
		pos[i]=pll(pos[i].first+pos[i].second, pos[i].first-pos[i].second);
		if(par2!=par){
			cout << -1 << endl;
			return 0;
		}
	}

	vector<long long> d;
	for(int i=30;i>=0;i--) d.push_back(1LL<<i);
	if(par%2==0) d.push_back(1);
	cout << d.size() << endl;
	for(int i=0;i<d.size();i++) cout << d[i] << ' ';
	cout << endl;

	for(int i=0;i<n;i++){
		int xdir,ydir;
		long long xsum=0,ysum=0;
		for(int j=0;j<d.size();j++){
			if(xsum<=pos[i].first) xdir=1,xsum+=d[j];
			else xdir=-1,xsum-=d[j];
			if(ysum<=pos[i].second) ydir=1,ysum+=d[j];
			else ydir=-1,ysum-=d[j];

			if(xdir==1 && ydir==1) cout << 'R';
			else if(xdir==1 && ydir==-1) cout << 'U';
			else if(xdir==-1 && ydir==-1) cout << 'L';
			else cout << 'D';
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
from numba import njit
from numpy import int64
@njit('i8(i8[:],i8[:])',cache=True)
def func(s,x):
    last=[0]*26
    score=0
    for i,v in enumerate(x,1):
        last[v]=i
        c=0
        for j in range(26):
            c+=s[j]*(i-last[j])
        score=score+s[i*26+v]-c
    return score
def main():
    d,*s=map(int,open(0).read().split())
    s=int64(s)
    x=s[26*-~d:d*27+26]-1
    for d,q in s[27*-~d:].reshape(-1,2):
        x[d-1]=q-1
        print(func(s,x))
main()

Measured memory_bytes: 123076
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,X;
  cin >> N >> X;
  vector<int> L(N);
  for (int i=0;i<N;i++){
    cin >> L.at(i);
  }
  int s=1;
  int D=0;
  for (int i=0;i<N;i++){
    if (D+L.at(i)<=X){
      D+=L.at(i);
      s+=1;
    }
    else{
      break;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	printf("%s\n", a + b >= c?"Yes" : "No");
}

Measured memory_bytes: 128
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

X = nn()

for i in range(len(X)):
    if (X[i] == 0):
        print(i+1)


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m;
string s,t;
vll a;

// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	vll dp(3000,0);

	dp[0] = 1;
	for(ll i=1;i<=n;i++) {
		for(ll j=3;j<=i;j++) {
			if(i-j >= 0) {
				dp[i] = (dp[i] + dp[i-j])%MOD;
			}
		}
	}
	//for(ll i=0;i<=n;i++) cout<<dp[i]<<" ";
	cout<<(dp[n]%MOD+MOD)%MOD;
}
int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



Measured memory_bytes: 3680
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<math.h>
#include<string.h>
#include<stack>
#define n 100000
#define loop(a) for(int i=0; i<a; i++)
using namespace std;
typedef pair<int, int> P;
struct edge{
	int from, to, weight;
	bool operator < (const edge& thing) const
	{
		return thing.weight < weight;
	}
};
bool cmp(int a, int b)
{
	return a > b;
}
vector<edge> V[n + 50];
bool visit[n + 50];
int arr[n + 50], a, b, c, d;
string str1, str2;
void addedge(int a, int b, int c)
{
	edge one, two;
	one.from = a; one.to = b; one.weight = c;
	two.from = b; two.to = a; two.weight = c;
	V[a].push_back(one);
	V[b].push_back(two);
}


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


void solve()
{
	cin >> a;
	int dp[a + 50];
	arr[0] = 1; arr[1] = 6; arr[2] = 9;
	for(int i=0; i<=a; i++)
		dp[i] = 100000000;
	dp[0] = 0;
	for(int i=0; i<3; i++)
	{
		for(int j=0; j<=a; j++)
		{
			for(int k = 1; pow(arr[i], k) <= j; k++)
			{
				int temp = pow(arr[i], k);
				dp[j] = min(dp[j], dp[j - temp] + 1);
				if(arr[i] == 1) break;
			}
		}
	}
	printf("%d\n",dp[a]);
}
int main()
{
	int times = 1;
//	cin << times;
	loop(times)
	{
		solve();
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2944
#include<stdio.h>
 
#define MAXLEN 20000
 
int garea,gareas[(MAXLEN/2)+1],gcnt;
 
 
int getArea( char *inputs, int start, int end )
{
    int i;
    int ravine,water;
    
    gareas[gcnt]=ravine=water=0;
    for( i=start; i!=end; i++ ) {
        if( '\\'== *(inputs+i) ) {
            water+=(ravine*2);
            ravine++;
            water++;
        } else if( 0 != ravine && '/' == *(inputs+i) ) {
        	ravine--;
        } else {
	     	gareas[gcnt]+=ravine;
        }       
    }
	gareas[gcnt]+=water;
    
    return gareas[gcnt];
}
  
int checkRavine( char *inputs, int start )
{
    int i;
    int ravine;
    
    ravine=0;
    for( i=start; '\0'!=*(inputs+i); i++ ) {
        if( '\\'== *(inputs+i) ) {
            ravine++;
        } else if( 0 != ravine && '/' == *(inputs+i) ) {   
            ravine--;
            if( 0 == ravine ) {
            	garea+=getArea( inputs, start, i+1 );
            	gcnt++;
                return i-start;
            }           
        }
    }
    return 0;
}
 
 
void getAreas( char *inputs )
{
    int i,next;
     
    next=0;
    for( i=0; '\0'!=inputs[i]; i++ ) {
        next=checkRavine( inputs, i );
        i+=next;
    }
 
    return;
}
 
int main( void ) 
{
    char inputs[MAXLEN+1];
    int i;
 
    scanf( "%s", inputs );
    garea=gcnt=0;
    getAreas( inputs );
     
    printf( "%d\n", garea );
    
    if( gcnt ) {
        printf( "%d ", gcnt );
        for( i=0; i<gcnt; i++ ) {
            printf( "%d", gareas[i] );
            if( i < gcnt-1 ) {
            	printf( " " );  
            }
        }
        printf( "\n" );
       
    } else {
        printf( "0\n" );
    }
     
    return 0;
}

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


vector<long long> T,M;
void primemake(long long x){
    bool v;
    for(long long i=2;i*i<=x;i++){
        if(M.size()==0) M.push_back(i);
        else{
            v=true;
            for(int j=0;j<M.size();j++){
                if(i%M[i]==0)v=false;
            }
            if(x) M.push_back(i);
        }
    }
}
int main(){
    long long a,b;
    cin>>a>>b;
    primemake(min(a,b));
    long long x=max(a,b),y=min(a,b),z,ans=1;  
    while(x%y!=0){
        z=x;
        x=y;
        y=z%y;
    }
    for(long long i=0;i<M.size();i++){
        if(y%M[i]==0){
            ans++;
            while(y%M[i]==0) y=y/M[i];
        }
    }
    if(y>1) ans++;
    cout<<ans<<endl;
}

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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size()-1;i++){
    if(s[i]=='A' && s[i+1]=='C'){
      cout<<"Yes"<<endl;return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}


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

namespace ConsoleApp11
{
    class Class8
    {
        static void Main()
        {
            string A = Console.ReadLine();
            string B = Console.ReadLine();
            int R = 0;
            for(int i = 0; i < 3; i++)
            {
                if (A[i] == B[i])
                    R += 1;
            }
            Console.WriteLine(R);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;
 
vector < pair < int , ll > > g[N];

ll fun(vector <int> v, int id)
{
    ll res = 0;
    for(int i=0;i<v.size();i++){
        if(i>id){
            if(v[i]) res+=(1LL<<i);
        }

    }
    return res;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    ll l;
    cin>>l;
    vector <int> v;
    while(l>0){
        if(l%2) v.pb(1);
        else v.pb(0);
        l/=2;
    } 
    int m=0;
    int n = v.size();
    int i;
    for(i=1;i<n;i++){
        g[i].pb(mkp(i+1,(1LL<<(i-1))));
        g[i].pb(mkp(i+1,0));
        m+=2;
    }
    for(i=0;i<n-1;i++){
        if(v[i]){
            ll foo = fun(v,i);
            g[i+1].pb(mkp(n,foo));
            m++;
        }
    }
    cout << n << " " << m << endl;
    for(i=1;i<=n;i++){
        for(int j=0;j<g[i].size();j++){
            cout << i << " "<<g[i][j].fi << " "<<g[i][j].se << endl;
        }
    }

 
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = (1 << 30);

const int maxn=8,maxm=28;
int n,m;
vi vec[maxn];
ll ans;

void dfs(int a,set<int> s){
    //show(a);
    //shows(s);
    //show(ans);
    set<int> nx;
    rep(i,vec[a].size()){
        int next=vec[a][i];
        if(s.find(next) ==s.end()){
            nx=s;
            nx.insert(next);
            dfs(next,nx);
        }
    }
    if(s.size()==n){ ans++;/*cerr<<"ans++"<<endl;*/}
}

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

    cin>>n>>m;
    int a,b;
    rep(i,m){
        cin>>a>>b;
        a--;b--;
        vec[a].pb(b);
        vec[b].pb(a);
    }
    ans=0;
    set<int> s;
    s.insert(0);
    dfs(0,s);
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  string s;
  int n = 700;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 'o'){
      n += 100;
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 256
/************************
*                       *
* Nothing Is Impossible *
*                       *
************************/
#include <algorithm>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for (int i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld; 
using namespace std;

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

	int n;	cin >> n;
	int best=0;
	int ans[n];
	Rep(i,0,n)
	{
		cin >> ans[i];
	}
	int sum = 0;
	Rep(i,0,n)
	{
		sum += ans[i];
		best = max(ans[i], best);
	}
	sum -= best;
	if(sum > best)
	{	
		cout << "Yes" << endl;
	}
	else
	{	
		cout << "No" << endl;	
	}
	return 0;
}

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

int main() {
  int N,K,ans=0;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    int h;
    cin >> h;
    if(h>=K) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


constexpr int inf = 1e9 + 334;
constexpr int N = 800;
char str[N+10][N+10];
std::array<std::array<int, N>, N> Dist;
constexpr std::array<std::pair<int, int>, 4> dxdy = {pii(1, 0), pii(-1, 0), pii(0, 1), pii(0, -1)};

int main(void){
    // 入力部分
    int H, W, k; scanf("%d%d%d", &H, &W, &k);
    REP(i, H) scanf("%s", str[i]);

    // 準備部分
    int sx = -1, sy; REP(i, H){  REP(j, W) if(str[i][j] == 'S') {sx = i; sy = j; break; } if(sx != -1) break;}
    std::queue<std::pair<int, int>> Q;

    Dist[sx][sy] = 0; Q.emplace(sx, sy);
    const std::function<bool(int, int)> isIn = [&](int x, int y){
        return 0 <= x and x < H and 0 <= y and y < W;
    };
    const std::function<int(int)> getDistance = [&](int d){
        return (d + k - 1) / k + 1;
    };

    REP(i, H) REP(j, W) Dist[i][j] = inf;
    Q.emplace(sx, sy); Dist[sx][sy] = 0;
    while(not Q.empty()){
        int x, y; std::tie(x, y) = Q.front(); Q.pop();
        for(const auto& itr : dxdy){
            int X = x + itr.first;
            int Y = y + itr.second;
            if((not isIn(X, Y)) or str[X][Y] == '#' or Dist[X][Y] != inf) continue;
            if(Dist[x][y] + 1 <= k){
                Dist[X][Y] = Dist[x][y] + 1; Q.emplace(X, Y);
            }
        }
    }
    REP(i, H) REP(j, W) if(Dist[i][j] <= k) {Dist[i][j] = 0; Q.emplace(i, j);}


    while(not Q.empty()){
        int x, y; std::tie(x, y) = Q.front(); Q.pop();
        for(const auto& itr : dxdy){
            int X = x + itr.first; int Y = y + itr.second;
            if((not isIn(X, Y)) or Dist[X][Y] != inf) continue;
            Dist[X][Y] = Dist[x][y] + 1; Q.emplace(X, Y);
        }
    }
    int res = inf;
    REP(i, H) chmin(res, getDistance(Dist[i][0])), chmin(res, getDistance(Dist[i][W-1]));
    REP(j, W) chmin(res, getDistance(Dist[0][j])), chmin(res, getDistance(Dist[H-1][j]));
    printf("%d\n", res);
    
    return 0;
}

Measured memory_bytes: 8320
#include<tuple>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std ;

int main(){
  int n ; cin >> n ;
  vector<tuple<string,int,int>> g(n) ;
  for(int i=0;i<n;i++){
    cin >> get<0>(g.at(i)) >> get<1>(g.at(i));
    get<1>(g.at(i)) *= -1 ;
    get<2>(g.at(i)) = i+1 ;
  }
  sort(g.begin(),g.end()) ;
  for(int i=0;i<n;i++){
    cout << get<2>(g.at(i)) << endl ;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;
using i8t = std::int64_t;
using vi8t = std::vector<i8t>;
using vvi8t = std::vector<std::vector<i8t>>;
static const i8t i8t_max=numeric_limits<i8t>::max();
static const i8t i8t_min=numeric_limits<i8t>::min();
using u8t = std::uint64_t;
using vu8t = std::vector<u8t>;
#define F3(I,A,B) for(i8t I=A,I##_N=B;I<I##_N;I++)
#define F(I,N) F3(I,0,N)
#define FR(I,N) for(i8t I=N;I--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
template<typename T> T umax(T& ans,T const& value) {if(value>ans)ans=value;return ans;}
template<typename T> T umin(T& ans,T const& value) {if(value<ans)ans=value;return ans;}

int main() {
  R(N)R(K);
  N%=K;
  P(min(N,K-N));
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    long long a, b, c, k, t = 0;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
    
    if (a >= k) {
        t += k;
        k = 0;
    } else if (a < k && k > 0) {
        t += a;
        k -= a;
    }

    if (b >= k)
        k = 0;
    else if (b < k && k > 0)
        k -= b;
    
    if (c >= k) {
        t -= k;
        k = 0;
    } else if (c < k && k > 0) {
        t -= c;
        k -= c;
    }
    
        
    printf("%lld\n", t);
        
    return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    ll n, m;
        cin >> n >> m;
    vector<P> v;
    ll a, b;
        for(int i=0; i<n; i++){
            cin >> a >> b;
            v.push_back(make_pair(a, b));
        }
        sort(v.begin(), v.end());
    
    ll sum=0, ans=0;
        for(int i=0; i<n; i++){
            ll tmp = min(v[i].second, m-sum);
            sum += tmp;
            ans += tmp*v[i].first;
            if(sum==m) break;
        }  
        cout << ans << endl;
}

Measured memory_bytes: 2420
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll,P> PP;
int main() {
	ll n; cin >> n;
	ll a[100000]; ll sum = 0;
	rep(i, n) {
		cin >> a[i]; sum += a[i];
	}
	ll k = n*(n + 1) / 2;
	if (sum%k)cout << "NO" << endl;
	else {
		ll d = sum / k;
		bool f = true;
		if (((a[0] - a[n-1] - d) % n)||a[0]-a[n-1]-d>0)f = false;
		rep(i, n-1) {
			if (((a[i + 1] - a[i] - d) % n) || a[i + 1] - a[i] - d > 0)f = false;
		}
		if (f)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <assert.h>
#include <map>

const int MAXN = 51;

std::vector<int> edges[MAXN];
std::pair<int, int> rest[20];  // restrictions.
std::map<std::pair<int, int>, int> mark;
int pre[MAXN];

void dfs(int u) {
  for (const auto& v : edges[u]) {
    if (v == pre[u]) continue;
    pre[v] = u;
    dfs(v);
  }
}

void mark_edge(int u, int v, int tag) {
  if (u > v) std::swap(u, v);
  std::pair<int, int> edge = std::make_pair(u, v);
  if (!mark.count(edge)) {
    mark[edge] = 0;
  } 
  mark[edge] |= (1 << tag);
}

void mark_path(int u, int v, int tag) {
  pre[u] = -1;
  dfs(u);
  int node = v;
  while (node != u) {
    mark_edge(pre[node], node, tag);
    node = pre[node];
  }
}

// Calc the number of ways to paint the edges that satisfy all the m restrictions.
int64_t solve(int n, int m) {
  auto one_num = [](int x) -> int {
    int ans = 0;
    while (x > 0) {
      if (x & 1) ++ans;
      x >>= 1;
    }
    return ans;
  };

  for (int i = 0; i < m; ++i) {
    mark_path(rest[i].first, rest[i].second, i);
  }  
  int64_t ans = 1LL << (n - 1);  // 2 ^(n - 1).
  int rest_num = 1 << m;
  for (int i = 1; i < rest_num; ++i) {
    int flag = 1;
    if (one_num(i) % 2 == 1) flag = -1;
    int must_while_edges = 0;
    for (const auto& edge : mark) {
      int tag = edge.second;
      // std::cout << edge.first.first << " " << edge.first.second << " " << tag << std::endl;
      if (tag & i) ++must_while_edges;
    }
    assert(n - 1 >= must_while_edges);
    ans += flag * (1LL << (n - 1 - must_while_edges));
  }
  return ans;
}

int main() {
  int n, m;
  std::cin >> n;
  for (int i = 1, u, v; i < n; ++i) {
    std::cin >> u >> v;
    edges[u].emplace_back(v);
    edges[v].emplace_back(u);
  }
  std::cin >> m;
  for (int i = 0; i < m; ++i) {
    std::cin >> rest[i].first >> rest[i].second;
  }
  std::cout << solve(n, m) << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int gcd(int n, int m)
{
    if (m == 0) return n;
    return gcd(m, n%m);
}

int lcm(int n, int m)
{
    int g = gcd(n, m);
    return g * (n/g) * (m/g);
}

int main()
{
    int n;
    int a[1<<4];
    int l;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    l = 1;
    for (int i = 0; i < n; i++) l = lcm(a[i], l);
    printf("%d\n", l);
    return 0;
}



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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};

class UnionFind{
    public:
        UnionFind(int N) : parent(N), rank(N){
            for(int i = 0; i < N; i++){
                parent[i] = i;
                rank[i] = 1;
            }
        }

        int find(int n){
            if(parent[n] == n){
                return n;
            }
            return parent[n] = find(parent[n]);
        }

        void merge(int m, int n){
            int root_x = find(m);
            int root_y = find(n);
            if(root_x == root_y){
                return;
            }
            if(rank[root_x] < rank[root_y]){
                parent[root_x] = root_y;
            }else if(rank[root_x] > rank[root_y]){
                parent[root_y] = root_x;
            }else{
                parent[root_y] = root_x;
                rank[root_x]++;
            }
        }

        bool equivalent(int x, int y){
            return find(x) == find(y);
        }

    private:
        vector<int> parent;
        vector<int> rank;

};

struct edge{
    int cost, x, y;
};

int N;
vector<pint> x, y;  //(point, index)
vector<struct edge> es;

ll kruskal(){
    ll ret = 0;
    sort(ALL(es), [](struct edge u, struct edge v) -> bool{return (u.cost < v.cost);});
    UnionFind uf(N);
    for(auto i : es){
        if(!uf.equivalent(i.x, i.y)){
            ret += i.cost;
            uf.merge(i.x, i.y);
        }
    }
    return ret;
}

signed main(){
    cin >> N;
    int a, b;
    REP(i, N){
        cin >> a >> b;
        x.push_back(pint(a, i));
        y.push_back(pint(b, i));
    }
    sort(ALL(x));
    sort(ALL(y));
    REP(i, N - 1){
        es.push_back({x[i + 1].first - x[i].first, x[i].second, x[i + 1].second});
        es.push_back({y[i + 1].first - y[i].first, y[i].second, y[i + 1].second});
    }
    PRINT(kruskal());
    return 0;
}

Measured memory_bytes: 7016
N, Y = map(int, input().split())

a = 10000
b = 5000
c = 1000

# p = 1 q = 1
# cの枚数 = 5


is_ok = False
for p in range(N+1):
    for q in range(N-p+1):
        tmp = Y - a * p - b * q
        if tmp < 0:
            continue
        if (tmp == 0 and N-p-q == 0) or tmp // c == N-p-q:
            is_ok = True
            break
    if is_ok:
        break
if is_ok:
    print('{} {} {}'.format(p, q, N-p-q))
else:
    print('-1 -1 -1')


Measured memory_bytes: 41068
t,a[51];short*p;Q(){for(p=a;*p=='=Q';p++);}main(i,s){for(;~scanf("%[^\n]\n",s);i=0)i||puts(sscanf(s,">^%[Q=]~%c%c",a,&t,a)-2||t-'~'|(Q(),*p&7|p==a)?sscanf(s,">'%[=]#%[=]%c%c",a,s,&t,a)-3||t-'~'|strcmp(a,s)?"NA":"A":"B");}

Measured memory_bytes: 0