akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[N][N];
int color[N], d[N], f[N], tt;
int nt[N];

// u?????£??\??????v?????????????????????
int next(int u) {
  for (int v = nt[u]; v < n; v++) {
    nt[u] = v + 1;
    if (M[u][v]) return v;
  }
  return -1;
}

// ?????????????????¨????????±???????????¢?´¢
void dfs_visit(int r) {
  for (int i = 0; i < n; i++) nt[i] = 0;

  stack<int> S;
  S.push(r);
  color[r] = GRAY;
  d[r] = ++tt;

  while (!S.empty()) {
    int u = S.top();
    int v = next(u);
    if (v != -1) {
      if (color[v] == WHITE) {
        color[v] = GRAY;
        d[v] = ++tt;
        S.push(v);
      }
    } else {
      S.pop();
      color[u] = BLACK;
      f[u] = ++tt;
    }
  }
}

void dfs() {
  // ?????????
  for (int i = 0; i < N; i++) {
    color[i] = WHITE;
    nt[i] = 0;
  }
  tt = 0;

  // ????¨???????u????§??????¨????????±???????????¢?´¢
  for (int u = 0; u < n; u++) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << d[i] << " " << f[i] << endl;
  }
}

int main() {
  int u, k, v, i, j;

  cin >> n;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) M[i][j] = 0;
  }

  for (i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  dfs();

  return 0;
}

Measured memory_bytes: 3120
A,B,M = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

X,Y,C = M.times.map{gets.split.map(&:to_i)}.transpose

a_min = as.min
b_min = bs.min
min = a_min + b_min

M.times do |i|
  min = as[X[i] - 1] + bs[Y[i] - 1] - C[i] if as[X[i] - 1] + bs[Y[i] - 1] - C[i] < min
end

p min

Measured memory_bytes: 20328
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
		for (int i = 0; i <= n; i++) {
		    graph.add(new ArrayList<>());
		}
		for (int i = 0; i < m; i++) {
		    int a = sc.nextInt();
		    int b = sc.nextInt();
		    graph.get(a).add(b);
		    graph.get(b).add(a);
		}
		int[] goals = new int[n + 1];
		PriorityQueue<Path> queue = new PriorityQueue<>();
		queue.add(new Path(1, 1, 0));
		while (queue.size() > 0) {
		    Path p = queue.poll();
		    if (goals[p.idx] != 0) {
		        continue;
		    }
		    goals[p.idx] = p.from;
		    for (int x : graph.get(p.idx)) {
		        queue.add(new Path(x, p.idx, p.value + 1));
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 2; i <= n; i++) {
		    if (goals[i] == 0) {
		        System.out.println("No");
		        return;
		    }
		    sb.append(goals[i]).append("\n");
		}
		System.out.println("Yes");
		System.out.print(sb);
	}
	
	static class Path implements Comparable<Path> {
	    int idx;
	    int from;
	    int value;
	    
	    public Path(int idx, int from, int value) {
	        this.idx = idx;
	        this.from = from;
	        this.value = value;
	    }
	    
	    public int compareTo(Path another) {
	        return value - another.value;
	    }
	}
}
 

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

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;

#define X real()
#define Y imag()

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

double norm(Vector a){
    return a.X * a.X + a.Y * a.Y;
}

double abs(Vector a){
    return sqrt(norm(a));
}

Point getCrossPoint(Segment s1, Segment s2){
    Vector base = s2.second - s2.first;
    double d1 = abs(cross(base, s1.first - s2.first));
    double d2 = abs(cross(base, s1.second - s2.first));
    double t = d1 / (d1 + d2);
    return s1.first + (s1.second - s1.first) * t;
}

int main(){
    int q; cin>>q;
    while(q--){
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
        Segment s1 = {Point(x0, y0), Point(x1, y1)};
        Segment s2 = {Point(x2, y2), Point(x3, y3)};

        Point ansp = getCrossPoint(s1, s2);
        
        printf("%.10f %.10f\n", ansp.X, ansp.Y);
    }
}


Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
// #ifdef DEBUG 
// #define

void Insertion_Sort(int A[], int n){
    for(int i=0; i<n; i++){
        int v= A[i];
        for(int j=i-1; j>=0; j--){
            if(v<A[j]){
                int tmp;
                tmp= A[j+1];
                A[j+1]= A[j];
                A[j]= tmp;
            }
        }
        REP(i,n) cout << A[i] << ((i!=n-1)?" ":"");
        cout << endl;
    }
}
int main(){
    int n;
    cin >> n;
    int A[n];
    REP(i,n) cin >> A[i];
    Insertion_Sort(A,n);
    return 0;
}



Measured memory_bytes: 3068
# abc134_b.py
# https://atcoder.jp/contests/abc134/tasks/abc134_b

# B - Golden Apple /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 一列に並んだ N本の林檎の木のうちいずれかに黄金の林檎が実ると言われています。
# そこで、何人かの監視員を配置してどの林檎の木もいずれかの監視員に監視された状態にしたいです。
# それぞれの監視員は N本の木のうちいずれかに配置します。便宜上、これらの木に 1 から N までの番号をつけます。
# 番号 i の木に配置された監視員は、番号が i−D 以上 i+D以下のすべての林檎の木を監視します。
# 条件を満たすために少なくとも何人の監視員を配置する必要があるか求めてください。

# 制約
#     入力は全て整数である。
#     1≤N≤20
#     1≤D≤20

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N D

# 出力
# 条件を満たすために配置する必要のある監視員の人数の最小値を出力せよ。

# 入力例 1
# 6 2

# 出力例 1
# 2

# 例えば、番号 3,4の木に 1人ずつ監視員を配置すれば条件を満たすことができます。

# 入力例 2
# 14 3

# 出力例 2
# 2

# 入力例 3
# 20 4

# 出力例 3
# 3


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, D = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    # 1人あたり2D+1本を監視可能
    result = -(N // (-2*D - 1))

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['6 2']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['14 3']
        lines_export = [2]
    if pattern == 3:
        lines_input = ['20 4']
        lines_export = [3]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  int x;
  cin >> x;
  int k = 0;
  if (x <= 599) k = 8;
  else if (x <= 799) k = 7;
  else if (x <= 999) k = 6;
  else if (x <= 1199) k = 5;
  else if (x <= 1399) k = 4;
  else if (x <= 1599) k = 3;
  else if (x <= 1799) k = 2;
  else if (x <= 1999) k = 1;

  cout << k << endl;

  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std; 
int main(){ 
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
  cout.tie(NULL); 
  int n,k;
  cin>>n>>k;
  vector<int> height(n);
  for(int i=0;i<n;i++){
    cin>>height[i];}
  vector<int> answer(n,INT_MAX);
  answer[0]=0;
  if(n>1){ 
    for (int i=1;i<n;i++){
      for(int j=1;j<=k;j++){
        if((i-j)>=0) {
          if(j==1)
            answer[i]=abs(height[i-j]-height[i])+answer[i-j];
        else
          answer[i]=min(abs(height[i]-height[i-j])+answer[i-j],answer[i]);
      }} } }
  cout<<answer[n-1]; 
  return 0; } 



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

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

  vector<int> X(N), Y(N), H(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i) >> Y.at(i) >> H.at(i);
  }

  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      int Hans = -1;
      bool flag = true;
      for (int i = 0; i < N; i++) {
        if (H[i] == 0) continue;
        if (Hans == -1) {
          Hans = H[i] + abs(X[i] - cx) + abs(Y[i] - cy);
        } else if (Hans != H[i] + abs(X[i] - cx) + abs(Y[i] - cy)) {
          flag = false;
          break;
        }
      }
      if (flag) {
        for (int i = 0; i < N; i++) {
          if (H[i] == 0) {
            if (0 < Hans - abs(X[i] - cx) - abs(Y[i] - cy)) {
              flag = false;
              break;
            }
          }
        }
      }
      if (flag) {
        cout << cx << ' ' << cy << ' ' << Hans << endl;
        return 0;
      }
    }
  }
}

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

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

	int d = a / b;
	int r = a % b;
	double f = 1.0 * a / b;

	cout << d << " " << r << " " <<
	     fixed << setprecision(5) << f << endl;

	return 0; 
}

Measured memory_bytes: 3228
import math
N, X, Y = map(int, input().split())
d = [[0]*(N+1) for _ in range(N+1)]
for i in range(1,N+1):
  for j in range(1,N+1):
    d[i][j] = abs(j-i)
#print(d[1][3])

for i in range(1,X+1):
  for j in range(int((X+Y)/2)+1,N+1):
    d[i][j]= abs(Y-j)+1+(X-i)
#print(d[1][3])
for i in range(X,Y+1):
  for j in range(X,Y+1):
    d[i][j]= min(abs(j-i),min(i,j)-X+Y-max(i,j)+1)
#print(d[1][3]) 
for i in range(X+1,math.ceil((X+Y)/2)):
  for j in range(Y,N+1):
    d[i][j]= (j-Y)+1+(i-X)

#print(d[1][3])
ans = [0]*N
for i in range(1,N):
  for j in range(i+1,N+1):
    ans[d[i][j]] += 1

#print(ans)

print(*ans[1:], sep='\n')

Measured memory_bytes: 78556
#include <cstdio>

inline int min(int a,int b){
	return a<b?a:b;
}

const int inf=1e9;

const int N=2e3+5;

char s[N];

int n,h[N],edge_cnt,sz[N],f[N],ans=inf;

struct Edge{
	int to,nex;
}e[N<<1];

inline void add_edge(int u,int v){
	e[++edge_cnt]=(Edge){v,h[u]};
	h[u]=edge_cnt;
}

void dfs(int u,int pre){
	sz[u]=(s[u]=='1');
	f[u]=0;
	for(int i=h[u];i;i=e[i].nex){
		int v=e[i].to;
		if(v!=pre){
			dfs(v,u);
			sz[u]+=sz[v];
			f[u]+=f[v]+sz[v];
		}
	}
}

int dp(int u,int pre){
	int mx_id=0,mx_n=0;
	for(int i=h[u];i;i=e[i].nex){
		int v=e[i].to;
		if(v!=pre){
			if(!mx_id||f[v]+sz[v]>mx_n){
				mx_id=v;
				mx_n=f[v]+sz[v];
			}
		}
	}
	if(f[u]-mx_n>=mx_n){
		return f[u]&1;
	}
	int d=dp(mx_id,u)+sz[mx_id];
	if(f[u]-mx_n>=d){
		return f[u]&1;
	}else{
		return d-(f[u]-mx_n);
	}
}

int main(){
	scanf("%d%s",&n,s+1);
	for(int i=1,u,v;i<n;++i){
		scanf("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	for(int u=1;u<=n;++u){
		dfs(u,0);
		if(dp(u,0)==0){
			ans=min(ans,f[u]/2);
		}
	}
	printf("%d\n",ans==inf?-1:ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
int main(){
    int n;
    cin  >> n;

    int w[110] = {0};

    int sum = 0;
    int sum2 = 0;

    for(int i = 0; i < n; ++i){
        cin >> w[i];
        sum += w[i];
    }

    int remain = 0;
    int now = 0;
    int ans = 99999;
    
    for(int i = 0; i < n; ++i){

        sum2 += w[i];
        remain = sum - sum2;


        if(abs(sum2 - remain) < ans){
            ans = abs(sum2 - remain);
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;

int main() {
    int n;
    scanInt(n);
    string s;
    vector<string> a;
    rep(i, n) {
        cin >> s;
        a.push_back(s);
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    printInt((int)a.size());
    return 0;
}

Measured memory_bytes: 11704
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;

using VI = vector <int> ;
using VVI = vector <VI> ;

int main() {
    string str;

    cin >> str;
    int cnt[2] = {0, 0};

    for (int i = 0; i < str.size(); ++i) {
        ++cnt[str[i]-'A'];
    }

    if (cnt[0] && cnt[1]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=15;
char s[N][10000];
int cnt[N];
int h,w,K,ans=0x3f3f3f3f;
int main()
{
	scanf("%d %d %d",&h,&w,&K);
	for(int i=0;i<h;i++) cin>>s[i];
	for(int i=0;i<1<<h-1;i++) //枚举横切 
	{
		memset(cnt,0,sizeof cnt); //记录每一块区域1的个数 
		bool f=0;
		int now=0;//记录总共的切数 
		for(int j=0;j<h-1;j++) if(i>>j&1) now++;
		for(int j=0;j<w;j++)//枚举竖切 
		{
			int id=0;
			bool flag=0;
			for(int k=0;k<h;k++) //遍历横切和竖切所包围的区域1的个数 
			{
				cnt[id]+=(s[k][j]=='1');
				if(cnt[id]>K)  flag=1; //这个说明需要竖切 
				if(i>>k&1) id++; //跳到下个区域中 
			}
			if(flag==1) 
			{
				now++;//总切数+1 
		
				memset(cnt,0,sizeof cnt); //把之前的切数置0，但是后面的不需要，因为后面的还是满足条件的 
				id=0;
				for(int k=0;k<h;k++)
				{
					cnt[id]+=(s[k][j]=='1');
					if(cnt[id]>K)  f=1; //这边不满足的意思和上面的那个不满足意义不一样。这次不满足说明了我需要横切了 
					if(i>>k&1) id++;
				}
			}
		}
		if(!f&&now<ans) 
		{
			ans=now;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define all(x) (x).begin(),(x).end()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n), b(n), c(n - 1); rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n - 1)cin >> c[i];
	int ans = 0;
	int mae = INF;
	rep(i, n) {
		ans += b[a[i] - 1];
		if (a[i] - mae == 1) {
			ans += c[mae - 1];
		}
		mae = a[i];
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  int a, b;
  cin >> a >> b;
  if (a<=b)
  {
    for(int i=0;i<b;i++)
    {
      cout << a ;
    }
  }
  else
  {
    for(int i=0;i<a;i++)
    {
      cout << b;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
if (a < b)
System.out.println("a < b");
else if(a > b)
System.out.println("a > b");
else
System.out.println("a == b");
}
}



Measured memory_bytes: 26184
#include<stdio.h>

int main(void){
  int i,num;
  char class[9][20];
  int amp,pmp;
  int enter[9],income[9];

  for(i=0;i<9;i++){
    scanf("%s",&class[i]);
    scanf("%d%d",&amp,&pmp);
    enter[i]=amp+pmp;
    income[i]=200*amp+300*pmp;
  }
  for(i=0;i<9;i++){
    printf("%s ",class[i]);
    printf("%d %d\n",enter[i],income[i]);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
 
 
int main () {
    string S;
    cin >> S;

    S[3] = '8';
    cout << S << endl;
}

    


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

int main () {
    std::string s, p;
    int ans;
    cin >> s >> p;
    s = s + s;
    ans = s.find(p);
    if (ans == -1){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3216
m,w = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(m)]

dp = [[0]*(w+1) for _ in range(m+1)]

# 初期値を調整
for w_i in range(1, w+1):
  dp[0][w_i] = float("-inf")
  
for w_i in range(w+1):
  for m_i in range(1, m+1):
    if w_i-WV[m_i-1][0]>=0:
      dp[m_i][w_i] = max(dp[m_i-1][w_i], dp[m_i-1][w_i-WV[m_i-1][0]]+WV[m_i-1][1])
    else:
      dp[m_i][w_i] = dp[m_i-1][w_i]

      
print(max(dp[-1]))

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

const int N = 3010;

typedef long long LL;

int mod;

inline int Pow(int x, int y, int mod = mod) {
	int res = 1;
	for (; y; y >>= 1, x = (LL)x * x % mod) if (y & 1) res = (LL)res * x % mod;
	return res; 
}

int S[N][N], C[N][N];

inline void init(int n) {
	S[0][0] = 1;
	for (int i = 0; i <= n; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++) 
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
	}
	for (int i = 1; i <= n; i++) {
		S[i][1] = 1;
		for (int j = 1; j <= i; j++)
			S[i][j] = (S[i - 1][j - 1] + (LL)S[i - 1][j] * j) % mod;
	}
}

int main() {
	int n, res = 0; cin >> n >> mod, init(n + 1);
	for (int i = 0; i <= n; i++) {
		int other = Pow(2, Pow(2, n - i, mod - 1)), tmp = (LL)C[n][i] * other % mod, base = Pow(2, n - i);
		for (int j = 1, t = base; j <= i; j++) {
			tmp = (tmp + (LL)C[n][i] * t % mod * other % mod * S[i + 1][j + 1]) % mod;
			t = (LL)t * base % mod;
		}
		if (i & 1) res = (res - tmp + mod) % mod;
		else res = (res + tmp) % mod;
	}
	cout << res << endl;
}//

Measured memory_bytes: 69632
#include<bits/stdc++.h>
	#include<ext/pb_ds/assoc_container.hpp>
	#include<ext/pb_ds/tree_policy.hpp>
	#define int long long
	#define w(t) int t;cin>>t;while(t--)
	#define pb push_back
	#define mk make_pair
	#define ascSort(v) sort(v.begin(), v.end())
	#define descSort(v) sort(v.begin(), v.end(), greater<int>())
	#define ff first
	#define ss second
	#define pi pair<int,int>
	#define vi vector<int>
	#define umapi unordered_map<int,int>

	const int m=998244353;
	using namespace std;
	using namespace __gnu_pbds;

	typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

	void FIO(){
		#ifndef ONLINE_JUDGE
			freopen("input.txt", "r", stdin);
			freopen("output.txt", "w", stdout);
		#endif
		ios_base::sync_with_stdio(false);
	    cin.tie(NULL);	
	}

	int32_t main(){
		
		//FIO();
		int n;cin>>n;
		vi l(n);
		for(int i=0; i<n; i++)
		cin>>l[i];
		ascSort(l);
		int cnt=0;
		for(int i=0; i<n; i++)
			for(int j=i+1; j<n; j++)
				for(int k=j+1; k<n; k++){
					if(l[k]-l[j]<l[i]&&l[k]!=l[j]&&l[k]!=l[i]&&l[i]!=l[j])
						cnt++;
				}
		cout<<cnt<<"\n";	
		return 0;
		
			
	}



		
		

Measured memory_bytes: 3656
x = input()
split_x = x.split()
split_x_int = [int(i) for i in split_x]
split_x_int.sort()
a = split_x_int[0]
b = split_x_int[1]
c = split_x_int[2]

print(str(a) + " "+ str(b) + " " + str(c))

Measured memory_bytes: 7644
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
ans = ["UNRESTORABLE"]

if "?" not in set(s):
    print("".join(s))
    exit()

for i in range(ls-lt+1):
    f = True
    for j in range(lt):
        f &= (s[i + j] == "?" or s[i + j] == t[j])

    if f:
        ans = s.copy()
        for j in range(lt):
            ans[i+j] = t[j]


print("".join(ans).replace("?", "a"))


Measured memory_bytes: 9036
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;

int main(){

  int n,m;
  int p;
  int x[200];
  while(scanf("%d%d%d",&n,&m,&p),n | m){
    fill(x,x+200,0);
    int sum = 0;
    rep(i,n){ scanf("%d",&x[i]); sum+=x[i];}
    sum*=100;
    //printf("%f\n",(float)(p/100.0));
    sum = sum - sum * (float)(p /100.0);
    if(x[m-1]==0) printf("0\n");
    else printf("%d\n",sum/x[m-1]); 
  }

  return 0;

}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back

int n,mo;
char s[200005];
int P[200005];
int dp[10005];

int expo( int a, int b ){
	if ( b == 0 ) return 1;
	int half = expo(a,b/2);
	half = ( 1LL * half * half ) % mo;
	if ( b & 1 ) half = ( 1LL * half * a ) % mo;
	return half;
}



int main(){
	
	scanf("%d%d",&n,&mo);
	scanf("%s",&s);

	for ( int i = n; i >= 1; i-- ){
		P[i] = (P[i+1]) + ((s[i-1]-'0') * expo(10,n-i))%mo;
		P[i] %= mo;
	}	

	LL ans = 0;
	dp[0]++;
	for ( int i = n; i >= 1; i-- ){
		ans += dp[P[i]];
		dp[P[i]]++;
	}
	
	if ( mo == 2 ){
		ans = 0;
		int cnt = 0;
		for ( int i = n; i >= 1; i-- ){
			if ( (s[i-1]-'0') % 2 == 0 ) cnt++;
			ans += cnt;
		}
	} else if ( mo == 5 ){
		ans = 0;
		int cnt = 0;
		for ( int i = n; i >= 1; i-- ){
			if ( (s[i-1]-'0') % 5 == 0 ) cnt++;
			ans += cnt;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(void){
    int hill[10];
    int top3[3] = {0, 0, 0};
    for(int i=0; i<10; i++){
        scanf("%d", &hill[i]);
    }
    for(int i=0; i<10; i++){
        if(hill[i]>=top3[0]){
            top3[2]=top3[1];
            top3[1]=top3[0];
            top3[0]=hill[i];
        }else if(hill[i]>=top3[1]){
            top3[2]=top3[1];
            top3[1]=hill[i];
        }else if(hill[i]>top3[2]){
            top3[2]=hill[i];
        }
    }
    for(int i=0; i<3; i++){
        printf("%d\n", top3[i]);
    }
    return 0;
}



Measured memory_bytes: 2032
#include <iostream>
#include <string>
using namespace std;
 
class Node{
public:
    Node* prev;
    Node* next;
    int value;
};
 
class DoublyLinkedList{
private:
    Node* first;
    Node* last;
public:
    DoublyLinkedList(){
        first = NULL;
        last = NULL;
    }
    void Insert(int x);
    void Delete(int x);
    void DeleteFirst();
    void DeleteLast();
    void PrintAll();
};
 
void DoublyLinkedList::Insert(int x){
    Node* node = new Node();
    node->value = x;
     
    if(first == NULL){
        first = node;
        node->prev = first;
        node->next = first;
    }else{
        node->prev = first->prev;
        node->next = first;
        first->prev->next = node;
        first->prev = node;
        first = node;
    }
}
 
void DoublyLinkedList::Delete(int x){
    Node* cur = first;
    if(cur==NULL)return;
    do{
        if(cur->value == x){
            if(cur == first){
                if(cur->next == first){
                    first = NULL;
                }else{
                    cur->next->prev = cur->prev;
                    cur->prev->next = cur->next;
                    first = cur->next;
                }
            }else{
                cur->next->prev = cur->prev;
                cur->prev->next = cur->next;
            }
            break;
        }
         
        cur = cur->next;
    }while(cur != first);
}
 
void DoublyLinkedList::DeleteFirst(){
    if(first != NULL){
        if(first->next == first){
            first = NULL;
        }else{
            first->next->prev = first->prev;
            first->prev->next = first->next;
            first = first->next;
        }
    }
}
 
void DoublyLinkedList::DeleteLast(){
    if(first != NULL){
        if(first->next == first){
            first = NULL;
        }else{
            first->prev = first->prev->prev;
            first->prev->next = first;
        }
    }
}
 
void DoublyLinkedList::PrintAll(){
    Node* cur = first;
    if(cur == NULL)return;
    do{
        cout << (cur->value);
        cur = cur->next;
    }while(cur != first && cur != NULL && (cout<<" "));
    cout << "\n";
}
 
int main() {
    DoublyLinkedList list = DoublyLinkedList();
    int n,i,x;
    string com;
	
	cin.tie(0);
	ios::sync_with_stdio(false);
     
    for(cin>>n,i=n;i;--i){
        cin>>com;
         
        if(com == "insert"){
            cin>>x;
            list.Insert(x);
        }else if(com == "delete"){
            cin>>x;
            list.Delete(x);
        }else if(com == "deleteFirst"){
            list.DeleteFirst();
        }else if(com == "deleteLast"){
            list.DeleteLast();
        }
    }
    list.PrintAll();
     
    return 0;
}

Measured memory_bytes: 35596
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>

//入力
#define in(N) cin >> N
#define in2(N,M) in(N) >> M
#define in3(N,M,K) in2(N,M) >> K
#define in4(N,M,K,L) in3(N,M,K) >> L
//出力
#define out(ans) cout << (ans) << endl
#define out2(a,b) cout << (a) << " " << (b) << endl
#define out3(a,b,c) cout << (a) << " " << (b) << " " << (c) << endl
#define outf(ans) cout << fixed << setprecision(6) << (ans) << endl

#define rep(i,n) for(int i=0; i<n; i++) //n回ループ
#define all(v) v.begin(), v.end() //vectorの全体を指定
#define sort_g(A,T) sort(all(A),greater<T>()) //降順ソート

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vstr;
const ll mod=1e9+7;

int main(){
	int K;
	in(K);
	int A,B;
	in2(A,B);
	int flg=0;

	for(int i=A; i<=B; i++){
		if(i%K==0) {
			out("OK");
			return 0;
		}
	}

	out("NG");
	return 0;
}

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

//#define int long long
typedef long long ll;
const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i=0;i<26;i++) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    for (int i=0;i<D;i++){
        for (int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    //初期t[i]の決定
    for (int i=0;i<D;i++) {
        t[i] = i % 26;
    }

    ll oldsum = -INF;
    for (int m=0;m<100000;m++) {
        //ここでt[i]を更新していく
        int process = rand()%2;
        if (process == 0){
            int dd = rand()%D;
            int qq = rand()%26;
            int oldval = t[dd];
            t[dd] = qq;
            ll sum = 0;
            vector<int> last(26);
            for (ll i=0;i<D;i++){
                sum += s[i][t[i]];
                last[t[i]] = i+1;
                for (int j=0;j<26;j++){
                    sum -= c[j]*(i+1-last[j]);
                }
            }
            if (sum > oldsum) {
                oldsum = sum;
            } else {
                t[dd] = oldval;
            }
        } else {
            int dd1 = rand()%D;
            int dd2 = min(dd1+13,D-1);
            int qq1 = t[dd1];
            int qq2 = t[dd2];
            t[dd1] = qq2;
            t[dd2] = qq1;
            ll sum = 0;
            vector<int> last(26);
            for (ll i=0;i<D;i++){
                sum += s[i][t[i]];
                last[t[i]] = i+1;
                for (int j=0;j<26;j++){
                    sum -= c[j]*(i+1-last[j]);
                }
            }
            if (sum > oldsum) {
                oldsum = sum;
            } else {
                t[dd1] = qq1;
                t[dd2] = qq2;
            }
        }
        //=======================       
    }
    for (int i=0;i<D;i++){
        cout << t[i]+1 << "\n";
    }
}

Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define mul(a,b) a=(a*b)%mod;
typedef long long ll;

using namespace std;
ll po(ll x){
    ll res=1;
    for(ll y=2;x;x>>=1,y=y*y%mod){
	if(x&1)res=res*y%mod;
    }
    return res;
}
ll mo(ll x){
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
typedef pair<ll,ll> P;
#define N 110
vector<ll> v[N];
ll n,f[N],g[N],l[N],r[N],w[N],u[N],h[N],m;
ll ans;
void func(ll x){
    ll len=r[x]-l[x]-1;
    if(len==1){
	mul(ans,po(w[x]));
	f[x]=g[x]=0;
	return;
    }
    ll fm=1,gm=1,sum=0;
    for(auto c:v[x]){
	func(c);
	if(r[c]-l[c]-1==1)continue;
	sum+=r[c]-l[c]-1;
	fm=mo(fm*f[c]);
	gm=mo(gm*(2*f[c]+g[c]));
	//cout<<2*f[c]+g[c]<<":"<<gm<<" ";
    }
    if(sum==0){
	f[x]=mo(po(w[x]));
	g[x]=mo(po(len)-2);
	return;
    }
    //cout<<"#"<<x<<" "<<fm<<" "<<gm<<endl;
    f[x]=mo(fm*po(w[x]));
    g[x]=mo(gm*po(len-sum));
    g[x]=mo(g[x]-2*fm);
}
int main(){
    cin>>n;
    if(n==1){
	cin>>n;
	cout<<po(n)<<endl;
	return 0;
    }
    lol(i,n)cin>>h[i];
    unordered_map<ll,vector<ll> >mas;
    lol(i,n){
	mas[h[i]].push_back(i);
    }
    sort(h,h+n);
    set<ll> st; st.insert(-1); st.insert(n);
    m=1,l[0]=-1,r[0]=n,w[0]=u[0]=h[0];
    lol(i,n){
	if(i&&h[i-1]==h[i])continue;
	for(auto x:mas[h[i]]){
	    auto il=st.lower_bound(x); il--;
	    ll L=*il;
	    auto ir=st.upper_bound(x);
	    ll R=*ir;
	    if(l[m-1]==L&&r[m-1]==R)continue;
	    l[m]=L,r[m]=R,u[m]=w[m]=h[i],m++;
	}
	for(auto x:mas[h[i]])st.insert(x);
    }
    lol(i,m){
	for(ll j=i-1;~j;j--){
	    if(l[j]<=l[i]&&r[i]<=r[j]){
		v[j].push_back(i);
		w[i]=u[i]-u[j];
		break;
	    }
	}
    }
    ans=1;
    func(0);
    cout<<mo(ans*(f[0]+g[0]))<<endl;
    /*
    lol(i,m){
	cout<<i<<":"<<l[i]+1<<" "<<r[i]-1<<" "<<w[i]<<endl;
	cout<<"f="<<f[i]<<" g="<<g[i]<<endl;
	for(auto x:v[i])cout<<x<<" ";cout<<endl;
    }*/
    return 0;
}


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

int main(){
    double a,b,c,d=0,e=0;
    cin>>a>>b;
    if(a>=13){cout<<b;}
    if(a<13){
        if(a>5){cout<<b/2;}
        if(a<=5){cout<<'0';}
    }
    return 0;
}


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

using ll = long long;
using ld = long double;

int main()
{
    int k,s,ans=0;
    cin >> k>>s;
    
    for(int x = 0; x <= k; x++)
    {
        
        for(int y = 0; y <= k; y++)
        {
            int z = s - x - y;
            if(0<=z && z<=k) ans++;
        }        
    }
    cout << ans << endl;
    
    return 0;
}

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

int main(){
  int L,R;
  int A,B,C,D;
  
  cin>>A>>B>>C>>D;
  L=A+B;
  R=C+D;
  
  if(L>R){
    cout<<"Left"<<endl;
  }
  if(L<R){
    cout<<"Right"<<endl;
  }
  if(L==R){
    cout<<"Balanced"<<endl;
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ll long long
#define make_pair mp
const int MAX=1e5+10;
using namespace std;

int main(){
  ll N,ans=0,cnt=0;
  cin>>N;
  ll A[N];
  set<ll> s;
  for(ll i=0;i<N;i++){
    cin>>A[i];
    if(i!=0)A[i]+=A[i-1];
  }
  sort(A,A+N);
  for(ll i=0;i<N;i++){
    if(!s.count(A[i])){
      if(cnt!=0) ans+=cnt*(cnt-1)/2;
      s.insert(A[i]);
      cnt=1;
    }else cnt++;
    if(A[i]==0) ans++;
    if(i==N-1) ans+=cnt*(cnt-1)/2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 11136
import java.util.ArrayList;
import java.util.Scanner;




//D
public class Main {

	static int N;
	static int Q;
	static ArrayList<Integer>[] v;
	static int[] ans;
	static int[] parent;
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		N=sc.nextInt();
		Q=sc.nextInt();
		v=new ArrayList[N+1];
		ans=new int[N+1];
		parent=new int[N+1];
		for(int i=1;i<=N;i++) {
			v[i]=new ArrayList<Integer>();
		}
		for(int i=1;i<=N-1;i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			v[a].add(b);
			parent[b]=a;

		}

		for(int i=0;i<Q;i++) {
			int p=sc.nextInt();
			int q=sc.nextInt();
			ans[p]+=q;
		}


		for(int i=2;i<=N;i++) {

			int pi=parent[i];
			// System.err.println("i pi "+i+" "+pi);

			if(pi!=0) {ans[i]+=ans[pi];}

		}

		for(int i=1;i<=N;i++) {
			System.out.print(ans[i]+" ");
		}
		System.out.println();
	}

}


Measured memory_bytes: 187988
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define prsp(v) loop(i,0,v.size())cout<<v[i],sp;nl;
#define prpsp(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S,sp;nl;
#define prnl(v) loop(i,0,v.size())cout<<v[i],nl;nl;
#define prpnl(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S,nl;nl;
#define MOD 1000000007
#define mod(n) (((n%MOD)+MOD)%MOD)
#define all(x) x.begin(),x.end()

const int N = 1e5+5;
int dp[105][5][5][5];

int main() 
{
    fastio();

    int n;
    cin>>n;
    dp[0][0][0][0]=1;
    loop(i,0,n)loop(j,0,5)loop(k,0,5)loop(l,0,5)
    {
        loop(m,0,4)
        {
            if(k==1&&l==2&&m==3)continue;
            if(k==1&&l==3&&m==2)continue;
            if(k==3&&l==1&&m==2)continue;
            if(j==1&&l==3&&m==2)continue;
            if(j==1&&k==3&&m==2)continue;

            dp[i+1][k][l][m] += dp[i][j][k][l];
            dp[i+1][k][l][m] = mod(dp[i+1][k][l][m]);
        }
    }

    ll ans = 0;
    loop(j,0,5)loop(k,0,5)loop(l,0,5)
    {
        ans += dp[n][j][k][l];
        ans = mod(ans);
    }
    cout<<ans,nl;


    return 0;
}

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

using namespace std;

int main() {
  string S;
  int N;
  cin >> S;
  N = stoi(S);

  int sn = 0;
  for (auto c : S) {
    string a{c};
    int i = stoi(a);
    sn+=i;
  }

  if(N % sn == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}


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

int main() {
  int64_t x;
  cin >> x;
  int64_t a = 100;

  int64_t i;
  int64_t p = 100;
  for (i = 1; i <= 10000; ++i) {
    p *= 1.01;
    if (p >= x) {
      break;
    }
  }

  cout << i << endl;
}


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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, s, e) for (int i = (s); i < (e); i++)
#define all(x) x.begin(), x.end()

#define endl "\n"

void use_cio() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}

template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
    os << "[";
    for (auto x : V) os << x << ", ";
    return os << "]";
}
//--------------------------------------------------//

int main() {
    use_cio();
    int a, b;
    cin >> a >> b;
    if (a <= 0 && 0 <= b) return !(cout << "Zero\n");
    if (a > 0) return !(cout << "Positive\n");
    cout << (((b - a) & 1) ? "Positive\n" : "Negative\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll X,Y,A,B,C;
	cin>>X>>Y>>A>>B>>C;
	vector<ll>a(A),b(B),c(C);
	for(int i=0;i<A;i++) cin>>a[i];
	for(int i=0;i<B;i++) cin>>b[i];
	for(int i=0;i<C;i++) cin>>c[i];
	sort(a.rbegin(),a.rend());
	sort(b.rbegin(),b.rend());
	for(int i=0;i<X;i++) c.push_back(a[i]);
	for(int i=0;i<Y;i++) c.push_back(b[i]);
	sort(c.rbegin(),c.rend());
	ll ans=0;
	for(int i=0;i<X+Y;i++) ans+=c[i];
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 6000
#include <stdio.h>
#include <string.h>

int main(void){

  char card[201];
  char f;
  int i, ii, iii, m, h, a, o;

  for(o = 0; o > -1; o++){
    scanf("%s", card);
    if(card[0] == '-') return 0;
    a = strlen(card) -1;
    scanf("%d", &m);
    for(i = 0; i < m; i++){
      scanf("%d", &h);
      for(ii = 0; ii < h; ii++){
	f = card[0];
	for(iii = 0; iii < a; iii++){
	  card[iii] = card[iii+1];
	}
	card[a] = f;
      }
    }
    printf("%s\n", card);
  }
}

Measured memory_bytes: 584
#include <iostream>

using namespace std;
using ll = long long;

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

ll dp[105][100005];

const int INF = 1001001001;

int main() {
  int n, w;
  cin >> n >> w;
  int a[n][2];
  rep(i, n) rep(j, 2) cin >> a[i + 1][j];

  rep(i, 105) rep(j, 100005) dp[i][j] = INF;
  dp[0][0] = 0;

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 100005; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (j - a[i][1] >= 0) {
        dp[i][j] = min(dp[i][j], dp[i - 1][j - a[i][1]] + a[i][0]);
      }
    }
  }

  ll ans = 0;
  rep(i, 100005) {
    if (dp[n][i] <= w) ans = i;
  }

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


Measured memory_bytes: 82432
A, B = map(int, input().split())
cand = [i*(10**4) + j*(10**3) + k*(10**2) + j*10 + i for i in range(1, 10) for j in range(0, 10) for k in range(0, 10)]

count = 0
for c in cand:
    if c >= A and c <= B:
        count += 1
        
print(count)

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
typedef long long ll;
ll x,cnt;
int main(){
    scanf("%lld",&x);
    ll sum=100;
    while(sum<x){
        sum=(long long)(sum*1.01);
        cnt++;
        //printf("%lld ",sum);
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

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

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P == 0) {
        return 1;
    }
    if(P < 0) {
        return 0;
    }
    if(P % 2 == 0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) {
        return N * RS(N,P - 1,M);
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int X;
    cin >> X;
    if(X < 30) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<bool> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    int n;cin>>n;
    VI a(n);rep(i,n)cin>>a[i];
    sort(ALL(a),greater<ll>());
    if(n%2==0){
        ll res=0;
        for(int i=0;i<n/2-1;i++)res+=a[i]*2;
        res+=a[n/2-1];
        res-=a[n/2];
        for(int i=n/2+1;i<n;i++)res-=a[i]*2;
        cout<<res<<endl;
    }
    else{
        ll res=0;
        for(int i=0;i<n/2-1;++i)res+=a[i]*2;
        res+=a[n/2-1]+a[n/2];
        for(int i=n/2+1;i<n;++i)res-=a[i]*2;
        ll res2=0;
        for(int i=0;i<n/2;i++)res2+=a[i]*2;
        res2-=a[n/2]+a[n/2+1];
        for(int i=n/2+2;i<n;i++)res2-=a[i]*2;
        cout<<max(res,res2)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3980
#include <iostream>
#include <string>
using namespace std;
int main() {
    long long n,a,b,sum=0,k,l;
    cin>>n>>a>>b;
    l=n/(a+b);
    n=n-l*(a+b);
    if (n-a<0)cout<<l*a+a+(n-a);
    else cout<<l*a+a;
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
//const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
int MOD = 998244353;
const int maxn = (int) 1e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod; return res;
}

struct Mint
{
    LL x;
    Mint() {x = 0;}
    Mint(int _x): x(_x) {}
    Mint(LL _x): x(_x) {}
    Mint operator - () const{
        return Mint(MOD - x);
    }
    Mint operator + (const Mint &rhs) const{
        LL res = x + rhs.x; if(res >= MOD) res -= MOD; return Mint(res);
    }
    Mint operator - (const Mint &rhs) const{
        LL res = x - rhs.x; if(res < 0) res += MOD; return Mint(res);
    }
    Mint operator * (const Mint &rhs) const{
        return Mint(x * rhs.x % MOD);
    }
    Mint operator / (const Mint &rhs) const{
        return Mint(x * fp(rhs.x, -1) % MOD);
    }
    Mint& operator += (const Mint &rhs) {
        x += rhs.x; if(x >= MOD) x -= MOD; return *this;
    }
    Mint& operator *= (const Mint &rhs) {
        x = (x * rhs.x) % MOD; return *this;
    }
    bool operator == (const Mint &rhs) const{
        return x == rhs.x;
    }
    bool operator != (const Mint &rhs) const{
        return x != rhs.x;
    }
    friend ostream& operator << (ostream &out, const Mint &rhs){
        return out << rhs.x;
    }
    friend istream& operator >> (istream &in, Mint &rhs){
        return in >> rhs.x;
    }
};

int n, m;
Mint dp[5555];

void work()
{
    cin >>n >>m;
    MOD = m;

    dp[0] = Mint(1);
    for(int i = 2; i <= n; i++)
    {
        int t = min(i - 1, n + 2 - i);
        for(int j = t; j < n; j++)
            dp[j] += dp[j - t];
    }

    Mint ans;
    for(int i = 0; i < n; i++)
        ans += dp[i] * Mint(n - i);

    cout <<ans <<endl;
}


int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    A,B,K = list(map(int,input().split()))

    c = K - A
    if(c >= 0):
        result = B-c
        if(result > 0):
            print(0,result)
        else:
            print(0,0)
    else:
        print(A-K,B)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 struct UnionFind {
   // コンストラクタ
     vector<int> par;

     UnionFind(int n) : par(n, -1) { } //初期化

     // メンバ関数
     void init(int n) { par.assign(n, -1); } //途中で初期化したいときに使う。

     int root(int x) {
         if (par[x] < 0) return x;
         else return par[x] = root(par[x]);
     }

     bool issame(int x, int y) {
         return root(x) == root(y);
     }

     void merge(int x, int y) {
         x = root(x); y = root(y);
         if (x == y) return; //root同じ場合
         if (par[x] > par[y]) swap(x, y); // merge technique
         par[x] += par[y];
         par[y] = x;
         return;
     }

     int size(int x) {
         return -par[root(x)];
     }
 };

 int main() {
   int N, M, K; cin >> N >> M >> K;
   UnionFind uf(N);

   vector<set<int>> fri(N);
   vector<set<int>> block(N);

   rep(i, 0, M) {
     int A, B; cin >> A >> B;
     fri.at(A - 1).insert(B - 1);
     fri.at(B - 1).insert(A - 1);
     uf.merge(A - 1, B - 1);
   }

   rep(i, 0, K) {
     int C, D; cin >> C >> D;
     if (uf.issame(C - 1, D - 1)) {
       block.at(C - 1).insert(D - 1);
       block.at(D - 1).insert(C - 1);
     }
   }

   rep(i, 0, N) {
     cout << uf.size(i) - fri.at(i).size() - block.at(i).size() - 1;
     if (i < N - 1) cout << " ";
     else cout << endl;
   }

 }


Measured memory_bytes: 29312