akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s,tmp;
    cin>>s;
    tmp=s;
    reverse(s.begin(),s.end());
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='b') s[i]='d';
        else if(s[i]=='d') s[i]='b';
        else if(s[i]=='q') s[i]='p';
        else if(s[i]=='p') s[i]='q';
    }
    if(s==tmp) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAX 100

int ADJ[MAX+1][MAX+1];

int main(){
    int n, i, j;
    cin >> n;
    for(i = 0; i < n; i++){
        int u, k;
        cin >> u >> k;
        for(j = 0; j < k; j++) {
            int v;
            cin >> v;
            ADJ[u][v] = 1;
        }
    }

    for(i = 1; i <= n; i++){
        for(j = 1; j <= n; j++){
            cout << ADJ[i][j];
            if(j != n) cout << " ";
        }

        cout << endl;
    }

    return 0;
}


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

#define LLD_SPEC "%lld"

long long GetResult(long long x, long long y) {
    long long result = 0;
    while (x > 0 && y > 0) {
        if (x >= y) {
            long long count = x / y;
            result += count * 2LL * y;
            x %= y;
        } else {
            long long count = y / x;
            result += count * 2LL * x;
            y %= x;
        }
    }
    result -= (x + y);
    return result;
}

int main() {
    long long n;
    long long x;
    scanf(LLD_SPEC LLD_SPEC, &n, &x);

    printf(LLD_SPEC "\n", n + GetResult(n - x, x));

    return 0;
}

Measured memory_bytes: 256
h, w = readline.split.map(&:to_i)

grid = []
h.times { grid.push(readline) }

def in?(x, h, y, w)
    return 0 <= x && x < h && 0 <= y && y < w
end

dx = [-1,0,1,0]
dy = [0,1,0,-1]

ok = true
h.times do |i|
    w.times do |j|
        temp = grid[i][j] == '.'
        4.times do |k|
            x = i + dx[k]
            y = j + dy[k]
            temp |= in?(x, h, y, w) && grid[x][y] == '#'
        end
        ok &= temp
    end
end

puts ok ? 'Yes' : 'No'

Measured memory_bytes: 14304
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

//ty beet BellmanFord
template<typename T>
struct BellmanFord{
  struct edge{
    int u,v;
    T w;
    edge(){}
    edge(int u,int v,T w):u(u),v(v),w(w){}
  };

  int n;
  vector< vector<int> > G;
  vector<int> used,reach;
  BellmanFord(int n):n(n),G(n),used(n,0),reach(n,0){}

  vector<edge> es;
  void add_edge(int u,int v,T c){
    es.emplace_back(u,v,c);
    G[u].emplace_back(v);
  }
  //vから各点に到達できるか
  void dfs(int v){
    if(used[v]) return;
    used[v]=1;
    for(int u:G[v]) dfs(u);
  }

  /* bulidを呼び出すときは最初にnegLとか適当に変数定義して、
  int 最短経路コスト=G.build(s,g,negL)とかって使う
  negLの値に応じて場合分け等々*/
  T build(int from,int to,int &neg_loop){
    for(int i=0;i<n;i++){
      //iからtoへと到達できるか->reach配列に格納
      fill(used.begin(),used.end(),0);
      dfs(i);
      reach[i]=used[to];
    }
    const T INFINF = numeric_limits<T>::max();
    vector<T> ds(n,INFINF);
    ds[from]=0;
    for(int j=0;j<n;j++){
      bool update=0;
      for(auto e:es){
        //reachが0->もうやる必要ない
        if(!reach[e.u]||!reach[e.v]||ds[e.u]==INFINF) continue;
        if(ds[e.v]>ds[e.u]+e.w){
          ds[e.v]=ds[e.u]+e.w;
          update=1;
        }
      }
      if(!update) break;
      if(j==n-1){
        //負のループがなければn回以上の更新は起きない
        neg_loop=1;
        return INFINF;
      }
    }
    neg_loop=0;
    return ds[to];
  }
};

int main(){
    int n,m,p;
    cin>>n>>m>>p;
    //pが時間で払う金
    BellmanFord<int> B(n);
    rep(i,m){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        B.add_edge(a,b,p-c);
    }
    int neg_loop;
    int ans=B.build(0,n-1,neg_loop);
    if(neg_loop){
        cout<<-1<<endl;
    }
    else{
        cout<<max(-ans,0)<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<math.h>
using namespace std;

void a(){
    int n;
    cin >>n;
    n = n%10;
    if(n==3)
    {
        cout<<"bon";
    }
    else if(n==0 ||n==1 ||n==6 ||n==8)
    {
        cout<<"pon";
    }
    else cout<<"hon";
    return;
}

void b(){
    int k;
    string s;
    cin >> k>>s;
    if(s.length()<=k)cout<<s;
    else
    {
        cout<<s.substr(0,k)+"...";
    }
}

void c(){
   int n,m;
   cin>>n>>m;
   vector<int>h;
   for(int i=0;i<n;i++)
   {
       int t;
       cin >> t;
       h.push_back(t);
   }
   vector<int>f(n,0);
   for(int j=0;j<m;j++)
   {
       int a,b;
       cin >> a>>b;
       if(h[a-1]>h[b-1])
       {
           f[b-1]=1;
       }
       else if(h[a-1]<h[b-1])
       {
           f[a-1]=1;
       }
       else
       {
           f[a-1]=1;
           f[b-1]=1;
       }
   }
   int count=0;
   for(int i=0;i<n;i++)
   {
       if(f[i]==0)count++;
   }
   cout<<count;
   return;
}

void d(){
    int x;
    cin >>x;
    int vmax = ceil( pow(x,1/5));

    
}
void e(){
    int n;
    cin >>n;
    vector<int>a;
    a.push_back(0);
    map<int,int>c;
    int vmin = INT32_MAX;
    int vmax = INT32_MIN;
    for(int i=0;i<n;i++)
    {
        int ai;
        cin >>ai;
        a.push_back(ai);
    }
    long long int pcount=0;
    
    for(int i=n-1;i>0;i--)
    {
        if(c.count(-(a[i+1]-(i+1)))==0){
            c[-(a[i+1]-(i+1))]=1;
        }
        else{
            c[-(a[i+1]-(i+1))]=c[-(a[i+1]-(i+1))]+1;
        }
        if(c.count(i+a[i])!=0)
        pcount+= c[i+a[i]];
    }
    cout << pcount;
    return;

}
int main(void){
    //a();
    b();
    //c();
    //d();
    //e();

}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;
import java.util.Set;
import java.util.HashMap;
import java.util.Map;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer 降順ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    /*標準入力long*/
    static long inputLong() throws Exception {
        return Long.parseLong(br.readLine());
    }



    public static void main(String[] args) throws Exception {
        // write your code here
        int [] inputVal = inputval();
        int a = inputVal[0];
        int b = inputVal[1];
        int c = inputVal[2];
        int d = inputVal[3];
        int e = inputVal[4];
        int f = inputVal[5];
        int ansW = 0;
        int ansS = 0;
        double maxRate = 0;



        for (int i = 0; i*100<=f; i+=a){
            for(int j=0; i*100+j*100<=f; j+=b){
                if (i==0 && j==0){
                    continue;
                }
                int water = 100*(i+j);

                for(int k=0; 100*k<=e * water && (k+water) <=f;k+=c){
                    for(int l=0; 100*k + 100*l<=e * water && (k+l+water) <=f;l+=d){
                        if ((k+l)*100 > maxRate * (water + k + l)){
                            ansW = water;
                            ansS = k + l;
                            maxRate = Math.max((k+l)*100.0 /(water + k + l),maxRate);
                        }

                    }

                }

            }
        }


        if(ansS == 0){
            System.out.println(100*a + " " + ansS);
        }else{
            System.out.println(ansW+ansS + " " + ansS);
        }




    }

}



Measured memory_bytes: 36732
// Problem : F - Distributing Integers
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_f
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

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

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n;
vi graph[maxN];
ll fact[maxN], invFact[maxN];
ll dp[maxN], ans[maxN];
int treesz[maxN];

ll pow2(ll a, ll b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	ll d = pow2(a, b / 2);
	d = (d * d) % MOD;
	if (b % 2) return (d * a) % MOD;
	return d;	
}

void facts() {
	fact[0] = 1;
	invFact[0] = 1;
	RI(i, n) {
		fact[i] = (fact[i - 1] * i) % MOD;
		invFact[i] = pow2(fact[i], MOD - 2);
	}
}

void DFS(int u, int par) {
	ll tmp = 1;
	for (auto v: graph[u]) {
		if (v != par) {
			DFS(v, u);
			treesz[u] += treesz[v];
			tmp = (tmp * dp[v]) % MOD;
			tmp = (tmp * invFact[treesz[v]]) % MOD;
		}
	}
	dp[u] = (tmp * fact[treesz[u]]) % MOD;
	treesz[u]++;
}

void DFS2(int u, int par) {
	ans[u] = dp[u];
	for (auto v: graph[u]) {
		if (v != par) {
			//cout << u << " " << v << endl;
			ll prevU = dp[u];
			ll prevV = dp[v];
			int prevVsz = treesz[v];
			//dp[u] = fact[treesz[u] - 1 - treesz[v]]
			dp[u] = (dp[u] * invFact[treesz[u] - 1]) % MOD; // dzielimy przez mianownik u gory
			dp[u] = (dp[u] * pow2(dp[v], MOD - 2)) % MOD; // dzielimy przez dp[v]
			dp[u] = (dp[u] * fact[treesz[v]]) % MOD; // mnozomy przez rozmv silnia
			dp[u] = (dp[u] * fact[treesz[u] - 1 - treesz[v]]) % MOD; // mnozymy przez mniejszy mianownik
			//cout << "new u " << dp[u] << endl;
			dp[v] = (dp[v] * invFact[treesz[v] - 1]) % MOD;
			dp[v] = (dp[v] * fact[n - 1]) % MOD;
			dp[v] = (dp[v] * invFact[treesz[u] - treesz[v]]) % MOD;
			dp[v] = (dp[v] * dp[u]) % MOD;
			//cout << "new v " << dp[v] << endl;
			treesz[u] -= treesz[v];
			treesz[v] = n;
			
			DFS2(v, u);
			
			treesz[v] = prevVsz;
			treesz[u] = n;
			dp[u] = prevU;
			dp[v] = prevV;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	facts();
	REP(_, n - 1) {
		int a, b;
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	DFS(1, -1);
	DFS2(1, -1);
	RI(i, n) {
		cout << ans[i] << "\n";
	}
	return 0;
}
 


Measured memory_bytes: 50164
n,q = map(int,input().split())
s = list(input())
LR = [0]*q
for i in range(q):
    LR[i] = list(map(int,input().split()))
d = [0]*(n+1)
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        d[i+1] += d[i] + 1
    else:
        d[i+1] = d[i]
for L,R in LR:
    print(d[R-1]-d[L-1])

Measured memory_bytes: 31312
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, k) = get!(usize, usize);
    let (r, s, p) = get!(usize, usize, usize);
    let mut t = String::new();

    std::io::stdin().read_line(&mut t).unwrap();

    let mut vs: Vec<Vec<(char, usize)>> = vec![vec![]; k];

    for (i, x) in t.chars().enumerate() {
        if x == 'r' {
            vs[i%k].push(('r', p));
        } else if x == 's' {
            vs[i%k].push(('s', r));
        } else if x == 'p' {
            vs[i%k].push(('p', s));
        }
    }

    //println!("{:?}", vs);

    let mut ans = 0;

    for i in (0..k) {
        let mut prv = ('a', 0);

        for j in (0..vs[i].len()) {
            //println!("{:?}, {:?}", vs[i][j], prv);
            if vs[i][j].0 != prv.0 {
                ans += vs[i][j].1;
                prv = vs[i][j];
            } else {
                let ma = std::cmp::max( prv.1, vs[i][j].1 );
                
                if prv.1 == vs[i][j].1 {
                    prv = ('a',0);
                } else if ma == prv.1 {
                    prv = vs[i][j];
                    ans += ma;
                } else {
                    prv = ('a', 0);
                }
            }
        }
    }

    println!("{}", ans);
}

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

int main() {
  unsigned long long a,a1,a2;
  string s;
  
  cin >> a >> s;
  a1 = (s[0] - '0')*100 + (s[2] - '0')*10 + (s[3] - '0');
  a2 = a * a1 / 100;
  cout << setprecision(30) << a2 << endl;
 
  return(0);
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <utility>
#include <string>
typedef unsigned long ul;

using namespace std;

int main(){
	ul x, r, n;
	cin >> n;
	x = 100000;
	while(n--){
		x = x * 1.05;
		if((r = x % 1000) != 0){
			x = x + 1000 - r;
		}
	}
	cout << x << endl;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};

int main() {
  int N, M;
  cin >> N >> M;
  vector<map<int, int>> p(N + 1);
  vector<string> S(M);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    p[a][b] = i;
  }
  for (int i = 1; i <= N; i++) {
    int id = 1;
    for (auto s : p[i]) {
      string tmpl = to_string(i);
      string tmpr = to_string(id);
      reverse(tmpl.begin(), tmpl.end());
      reverse(tmpr.begin(), tmpr.end());
      while (tmpl.size() < 6) {
        tmpl.push_back('0');
      }
      while (tmpr.size() < 6) {
        tmpr.push_back('0');
      }
      reverse(tmpl.begin(), tmpl.end());
      reverse(tmpr.begin(), tmpr.end());
      S[s.second] = tmpl + tmpr;
      id++;
    }
  }
  REP(i, S.size()) { cout << S[i] << "\n"; }
}

Measured memory_bytes: 15648
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <random>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
   
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

int n;
vector<string> res;

void dfs(int k,string s,char maxc){
  if(k == n){
    res.emplace_back(s);
    return;
  }
  for(char c = 'a'; c <= maxc + 1 && c - 'a' <= k; ++c){
    dfs(k+1,s + string(1,c),max(maxc,c));
  }
  return;
}

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

  cin >> n;
  dfs(0,"",'a');

  //sort(all(res));

  for(auto e : res){
    cout << e << '\n';
  }

  return 0;
}

Measured memory_bytes: 7796
while True:
    try:
        N, Q = map(int, input().split())
        verts = [None] * N
        qs = [0] * N
        results = [0] * N
        for i in range(N - 1):
            a, b = map(int, input().split())
            a -= 1
            b -= 1
            if verts[a] is None:
                verts[a] = list()
            if verts[b] is None:
                verts[b] = list()
            verts[a].append(b)
            verts[b].append(a)
        for i in range(Q):
            q, x = map(int, input().split())
            q -= 1
            qs[q] += x
        rests = [(0, None)]
        while rests:
            x, parent = rests.pop()
            if parent is not None:
                results[x] += results[parent]
            results[x] += qs[x]
            for i in verts[x]:
                if i != parent:
                    rests.append((i, x))
        print(" ".join(map(str, results)))
    except EOFError:
        break

Measured memory_bytes: 72152
#include <stdio.h>

int main(void)
{
	int in[100], out[100];
	int i, j, f;
	
	i = 0;
	j = 0;
	
	
	while (scanf("%d", &in[i]) != EOF){
		if (in[i] == 0){
			out[j] = in[i - 1];
			in[i - 1] = 0;
			i--;
			j++;
		}
		else {
			i++;
		}
	}
	
	for (f = 0; f < j; f++){
		printf("%d\n", out[f]);
	}
	
	return (0);
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c;
  while (cin >> a >> b >> c) {
    cout << min(b / a, c) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC115_B();
        }

        static void ABC115_B()
        {
            var N = int.Parse(Console.ReadLine());

            var P = new List<int>();
            for (var n = 0; n < N; n++)
                P.Add(int.Parse(Console.ReadLine()));

            var ordered = P.OrderByDescending(x => x).ToList();
            var max = ordered[0];
            ordered.RemoveAt(0);
            Console.WriteLine((max / 2) + ordered.Sum());
        }
    }
}

Measured memory_bytes: 13396
import Data.List
import Control.Monad

solver::[Int]->[Int]->[Int]->[Int]
solver as bs cs = let ab = take 3000 (sortBy (\ x -> \ y ->  compare y x) [a+b|a<-as,b<-bs]) in
                  take 3000 (sortBy (\ x -> \ y ->  compare y x) [x+c|x<-ab,c<-cs])

main::IO()
main=do
  (x:y:z:k:[])<-return.map read.words=<<getLine
  as<-return.map read.words=<<getLine
  bs<-return.map read.words=<<getLine
  cs<-return.map read.words=<<getLine
  forM_ (take k (solver as bs cs)) (\ v ->print v )

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

bool isSmall(char c) { return 'a' <= c && c <= 'z';}
int main() {
	string S;
	cin >> S;
	if (S[0] == 'A' && isSmall(S[1])) {
		int bigC = 0;
		for (int i = 2, l = S.size() - 1;i < l;i ++) {
			if (S[i] == 'C') bigC ++;
			else if (!isSmall(S[i])) {
				cout << "WA";
				return 0;
			}
		}
		if (isSmall(S[S.size() - 1]) && bigC == 1) {
			cout << "AC";
			return 0;
		}
	}
	cout << "WA";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

愚直に試すだけ～
*/

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
 
typedef pair<int,int> P;
typedef pair<int,P> P2; //dis,city,ticket
 
int main(){
  int n,m;
  int a,b,c;
  vector<P> g[110];
  int d[110][2];
 
  while(cin >> n >> m, n||m){
    for(int i=1;i<=n;i++)g[i].clear();
    for(int i=0;i<m;i++){
      cin >> a >> b >> c;
      g[a].push_back(P(c,b));
      g[b].push_back(P(c,a));
    }
 
    priority_queue<P2,vector<P2>,greater<P2> > q;
    q.push(P2(0,P(1,0)));
    for(int i=1;i<=n;i++)d[i][0] = d[i][1] = 100000000;
    d[1][0] = 0;
 
    while(q.size()){
      P2 p = q.top(); q.pop();
      int dis = p.first, city = p.second.first, tick = p.second.second;
 
      for(int i=0;i<(int)g[city].size();i++){
    int cost = dis + g[city][i].first;
    int next = g[city][i].second;
 
    if(cost < d[next][tick]){
      d[next][tick] = cost;
      q.push(P2(cost,P(next,tick)));
    }
    if(!tick){
      for(int j=0;j<(int)g[next].size();j++){
        int next2 = g[next][j].second;
 
        if(dis < d[next2][1]){
          d[next2][1] = dis;
          q.push(P2(dis,P(next2,1)));
        }
      }
    }
      }
    }
 
    cout << min(d[n][0],d[n][1]) << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x,long long y){
    if(x < y) swap(x,y);
    if(y == 0) return x;

    return gcd(y,x%y);
}

int main(){
    int n; cin >> n;
    long long ans = 1;
    for(int i=0;i<n;++i){
        long long t;cin >> t;
        ans/= gcd(t,ans);
        ans *= t;
    }
    cout << ans << endl;
    return 0;
}

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


const int mx = 1e6 + 9;
const int mood = 1e9 + 7;
int f[mx];
int invf[mx];

using namespace std;

int mood_pow(int a , int b){
int res = 1;

while(b>0){
    if(b%2){
       res = ((res%mood)*(a%mood))%mood;
       b--;
    }
    else{
        a = ((a%mood)*(a%mood))%mood;
        b/=2;
    }
}

return res;

}

int ncr(int n , int r){
if(n==r || r==0) return 1;
else{
    return (((f[n]*invf[n-r])%mood) * invf[r]) % mood;

}
}

main(){
int h , w , a , b;
cin>>h>>w>>a>>b;
f[0] = 1;

for(int i=1 ; i<mx ; i++){
    f[i] = (f[i-1] * i)%mood;
    invf[i] = mood_pow(f[i] , mood-2) % mood;
}
int ans = 0;
for(int i=b ; i<w ; i++){
    int x1 = i , y1 = h - a - 1;
    int x2 = w - i - 1 , y2 = a-1;
    int tmp = ((ncr(x1+y1 , x1)) * (ncr(x2+y2 , x2)))%mood;
    ans = (ans + tmp)%mood;
}

cout<<ans<<endl;

}


Measured memory_bytes: 19256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


char first_buf[2000001],buf[2000001];

ll POW[30];
int length;

ll recursive(int left,int right){

	ll ret;

	int depth = 0;
	queue<int> Q;

	for(int i = left; i <= right; i++){
		if(buf[i] == ' ')continue;

		switch(buf[i]){
		case 'S':
			//Do notghin
			break;
		case '<':
			depth++;
			break;
		case '>':
			depth--;
			break;
		case '@':
			if(depth == 0){
				Q.push(i);
			}
			i++;
			break;
		default:
			//Do nothing
			break;
		}
	}

	ll tmp;
	int pre = 0,tmp_left,tmp_right;

	if(Q.empty()){
		int S_loc = -1;

		for(int i = left; i <= right; i++){
			if(buf[i] == 'S'){
				S_loc = i;
				break;
			}
		}

		if(S_loc == -1){
			ret = 0;

			for(int i = left; i <= right; i++){
				if(buf[i] == ' ')continue;
				ret = 10*ret+(buf[i]-'0');
			}

		}else{
			depth = 0;

			for(int i = S_loc; i <= right; i++){
				if(buf[i] == ' ')continue;


				if(buf[i] == '<'){

					if(depth == 0){
						tmp_left = i;
					}
					depth++;
				}else if(buf[i] == '>'){

					depth--;
					if(depth == 0){
						tmp_right = i;
						break;
					}
				}

			}
			tmp = recursive(tmp_left+1,tmp_right-1);

			ret = (tmp*tmp)%MOD;
		}

	}else{

		while(!Q.empty()){
			tmp_right = Q.front();
			Q.pop();

			if(pre == 0){
				ret = recursive(left,tmp_right-1);
			}else{
				tmp = recursive(pre+2,tmp_right-1);
				if(tmp >= 30 || POW[tmp] > ret){
					ret = 0;
				}else{
					ret /= POW[tmp];
				}
			}
			pre = tmp_right;
		}
		tmp = recursive(pre+2,right);

		if(tmp >= 30 || POW[tmp] > ret){
			ret = 0;
		}else{
			ret /= POW[tmp];
		}
	}
	return ret;
}

void func(){

	length = 0;
	for(int i = 0; first_buf[i] != '\0' && first_buf[i] != '\n'; i++){
		if(first_buf[i] == ' ')continue;
		buf[length++] = first_buf[i];
	}

	bool is_pre_num = false,is_pre_S = false;

	for(int i = length-1; i >= 0; i--){
		if(buf[i] == ' ')continue;

		if(buf[i] == 'S'){
			is_pre_num = false;
			is_pre_S = true;
		}else if(buf[i] >= '0' && buf[i] <= '9'){
			is_pre_num = true;
			is_pre_S = false;
		}else if(buf[i] == '<'){
			is_pre_num = false;
			is_pre_S = false;
		}else if(buf[i] == '>'){
			if(is_pre_num == true || is_pre_S == true){
				buf[i] = '@';
				buf[i-1] = '@';
				i--;
			}
			is_pre_num = false;
			is_pre_S = false;
		}
	}
	printf("%lld\n",recursive(0,length-1));
}


int main(){

	for(int i = 0; i < 30; i++)POW[i] = (ll)pow(2,i);

	while(true){
		fgets(first_buf,2000000,stdin);
		if(first_buf[0] == '#')break;

		func();
	}

	return 0;
}

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


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

    int cnt = 0;
    int ans = 0;

    rep(i, 3) {
        if (s[i] == 'R') {
            cnt++;
            umax(ans, cnt);
        } else {
            cnt = 0;
        }
    }

    prt(ans);

    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

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

    for(int i = 0; i < n; i ++){
        N[i] = sc.nextInt();
        }

    int q = sc.nextInt();
    for(int i = 0; i < q ; i ++){
        int x = sc.nextInt();
            boolean flag = solve(N,0,x);
            System.out.println(flag ? "yes" : "no");
        }
    }

    static boolean solve(int[] N,int k,int m){
        if(m == 0) return true;
        if(m < 0 || k >= N.length) return false;
        return solve(N,k + 1,m - N[k]) || solve(N,k + 1,m);
    }
}


Measured memory_bytes: 26784
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let n: usize = read_as_vec()[0];
    let x = read_as_vec::<u64>();

    let mut sorted_x = x.clone();
    sorted_x.sort();

    let mid_pos = n/2-1;
    let median = sorted_x[mid_pos];
    for i in 0..n{
        if median >= x[i]{
            println!("{}", sorted_x[mid_pos+1]);
        }else{
            println!("{}", sorted_x[mid_pos]);
        }
    }
}


Measured memory_bytes: 10492
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strings"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func nextLine() string {
	sc.Scan()
	return sc.Text()
}
 
func main() {
	line := nextLine()
	words := strings.Split(line, " ")
	res := ""
	for _, word := range words {
		res += string(word[0])
	}
	fmt.Println(strings.ToUpper(res))
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

struct UnionFind {  
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  UnionFind(int n) : par(n) { //最初は全てが根であるとして初期化
    for(int i=0; i<n; i++){ par[i]=i; }  
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x]==x){ return x; }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry){ return; }//xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool check(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

int main() {
  int n,m; cin >> n >> m;
  UnionFind tree(n);
  vector<int> a(n);
  rep(i,n){ cin>>a[i]; a[i]--; }
  rep(i,m){
    int x,y; cin >> x >> y;
    tree.unite(x-1,y-1);
  }
  int ans=0;
  rep(i,n){ if(tree.check(i,a[i])){ ans++; } }
  
  cout << ans << endl;
  return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(i, v) for(auto i =  v.begin(); i !=  v.end(); ++i)
#define RFOR(i, v) for(auto i = v.rbegin(); i != v.rend(); ++i)

template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> ostream & operator<<(ostream & os, const vector<T> & v) {
	os << "[";
	FOR(it, v) {
		if(it != v.begin()) { os << ", "; }
		os << *it;
	}
	os << "]";
	return os;
}
template<typename F, typename S> ostream & operator<<(ostream & os, const pair<F, S> & p) {
	os << "<" << p.FI << ", " << p.SE << ">";
	return os;
}

// ---- ----

int n, x[500], a[500 * 500];
bool flag[501];
// int b[501];

bool solve() {
	inc(i, n) {
		if(a[ x[i] ] != 0) { return false; }
		a[ x[i] ] = i + 1;
	}
	
	inc(i, n * n) {
		if(a[i] != 0) {
			int j = 0, c = 0;
			while(j < i && c < a[i] - 1) {
				if(a[j] == 0) { a[j] = a[i]; c++; }
				j++;
			}
			if(c < a[i] - 1) { return false; }
		}
	}
	
	dec(i, n * n) {
		if(a[i] != 0 && ! flag[ a[i] ]) {
			int j = n * n - 1, c = 0;
			while(i < j && c < n - a[i]) {
				if(a[j] == 0) { a[j] = a[i]; c++; }
				j--;
			}
			if(c < n - a[i]) { return false; }
			
			flag[ a[i] ] = true;
		}
	}
	
	return true;
}

int main() {
	cin >> n;
	inc(i, n) { cin >> x[i]; x[i]--; }
	
	if(! solve()) { cout << "No" << endl; }
	else {
		cout << "Yes" << endl;
		inc(i, n * n) {
			cout << (i == 0 ? "" : " ") << a[i];
		}
		cout << endl;
	}
}


Measured memory_bytes: 2176
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string str;
int main() {
	cin >> str;
	queue<string> que; que.push(str);
	bool ret = (str == "ABC");
	while (!ret && !que.empty()) {
		string s1 = que.front(); que.pop();
		vector<int> v1(s1.size(), 0);
		for (int i = 2; i < s1.size(); i++) {
			if (s1[i - 2] == 'A' && s1[i - 1] == 'B' && s1[i] == 'C') {
				v1[i - 2] = v1[i - 1] = v1[i] = 1;
			}
		}
		vector<int> ok1(3, 1);
		for (int i = 0; i < s1.size(); i++) ok1[s1[i] - 65] &= v1[i];
		if (ok1[0] + ok1[1] + ok1[2] != 1) continue;
		for (int i = 0; i < 3; i++) {
			if (!ok1[i]) continue;
			string res;
			for (int j = 0; j < s1.size();) {
				if (j <= s1.size() - 3 && v1[j] == 1) res += (char)(i + 65), j += 3;
				else res += s1[j], j++;
			}
			if (res == "ABC") { ret = true; break; }
			if(res.size() != s1.size()) que.push(res);
		}
	}
	cout << (ret ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 3264
function main()
    n=myread(Int)
    cnt=0
    for i=1:n
        d1,d2=myreads(Int)
         if d1==d2
             cnt+=1
         else
             cnt=0
         end
         if cnt>=3
             println("Yes")
             return
         end
     end
     println("No")
end

# ----------input function----------
sread()=chomp(readline())
sreads(sp=" ")=split(readline(),sp)
myread(ty)=parse(ty,readline())
myreads(ty)=map(x->parse(ty,x),split(readline()))
main()

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N; 
    cin>>N;
    vector<plong> A(N);
    vvl DP(N+1, vl(N+1));
    REP(i, 0, N){
        int a;
        cin >> a;
        A[i] = {a, i + 1};
    }
    sort(A.rbegin(), A.rend());
    
    DP[1][0] = A[0].first * (N - A[0].second);
    DP[0][1] = A[0].first * (A[0].second -1);
    REP(i, 2, N+1){
        REP(j, 0, i + 1){
            if(j == 0){
                DP[i][0] = DP[i-1][0] + A[i-1].first * (N + 1 - i - A[i-1].second);
                continue;
            }
            if(j == i){
                DP[0][i] = DP[0][i-1] + A[i-1].first * (A[i-1].second - i);
                continue;
            }
            DP[i - j][j] = max(DP[i - 1 - j][j] + A[i-1].first * (N + 1 - (i - j) - A[i-1].second), 
                               DP[i - j][j - 1] + A[i-1].first * (A[i-1].second- j));
        }
    }

    long ans = 0;
    REP(i, 0, N+1) ans = max(ans, DP[N - i][i]);
    cout << ans << endl;
    /*
    REP(i, 0, N+1){
        REP(j, 0, N+1) cout << setw(3) << DP[i][j];
        cout << endl;
    }
    */
}

Measured memory_bytes: 34588
#include<iostream>
using namespace std;
int main(){
  int n,W;
  cin>>n>>W;
  long v[n],w[n];
  for(int i=0;i<n;i++)cin>>w[i]>>v[i];
  long dp[n+1][W+1];
  for(int i=0;i<=n;i++){
    for(int j=0;j<=W;j++){
      if(i==0||j==0)dp[i][j]=0;
      else if(j>=w[i-1])
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
      else
      dp[i][j]=dp[i-1][j];
    
    }}
  cout<<dp[n][W];

return 0;}

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

using namespace std;
typedef long long LL;

const LL N=200010;

LL a[N],n,i,j,t,ans=0,sum[N]={0},m,d,mind=LONG_LONG_MAX;

int main()
{
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(i){sum[i]=a[i]+sum[i-1];}
        else sum[0]=a[0];
    }
    for(i=0;i<n-1;i++){
        d=abs(sum[n-1]-sum[i]*2);
        if(d<mind)mind=d;
    }

    printf("%lld",mind);
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (i && A[i] == A[i - 1] + 1) {
            ans++;
            continue;
        }
        if (A[i] > i || (i && A[i] > A[i - 1] + 1)) {
            cout << -1 << endl;
            return 0;
        } else {
            ans += A[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


fn print_vec(vec: &Vec<i32>) {
    for i in 0..vec.len()-1 {
        print!("{} ", vec[i]);
    }
    println!("{}", vec[vec.len()-1]);
}

fn main() {
    let N: usize = read_line().parse().unwrap();
    let mut h: Vec<i32> = read_vec();
    h.insert(0, 0);
    h.push(0);
    let mut ans = 0;
    while h.iter().any(|&x| x > 0) {
        let first = h.iter().position(|&x| x != 0).unwrap();
        let second = first + h[first..].iter().position(|&x| x == 0).unwrap();
        for i in first..second {
            h[i] -= 1;
        }
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
signed main(){
	
	int n;
	string s;
	cin>>n>>s;
	int b[222222],w[222222];
	int kb=0,kw=0;
	b[0]=0;w[0]=0;
	for(int i=1;i<=s.size();i++){
		if(s[i-1]=='#')kb++;
		else kw++;
		b[i]=kb;
		w[i]=kw;
	}
	int min=INF;
	rep(i,s.size()+1){
		min=std::min(b[i]+w[s.size()]-w[i],min);
	}
	cout<<min<<endl;

}

Measured memory_bytes: 3844
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var a = consoleReader.Int;
            var b = consoleReader.Int;
            var c = consoleReader.Int;

            return new[]
            {
                Math.Abs(a-b) +Math.Abs(a-c),
                Math.Abs(a-b) +Math.Abs(b-c),
                Math.Abs(c-b) +Math.Abs(a-c),
            }.Min();
        }


        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader
    {
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = textReader.ReadLine().Split();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.textReader.ReadLine().Split(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 13268
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vi a(N + 1, 0); FOR(i, 1, N + 1) cin >> a[i];
    
    int ans = -1;
    int p = 1;
    REP(i,N+MGN) {
        if (p==2) {
            ans = i;
            break;
        }
        else p = a[p];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
N = int(input())
P = list(map(int, input().split(" ")))


ans = 0

for i in range(N-2):
    p = P[i:i+3]
    p_min = min(p)
    p_max = max(p)
    if p[1] != p_min and p[1] != p_max:
        ans += 1

print(ans)

Measured memory_bytes: 3060