akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Maybe
import Data.Char

solve :: [(Int,Int)] -> Int -> Int -> Int
solve [] memo bridges = bridges 
solve ((to,from):xs) memo bridges
  | from <= memo = solve xs memo bridges
  | otherwise = solve xs (to-1) (bridges+1)

main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  xs <- replicateM m $ do 
      s <- BS.getLine
      let (from, s') = fromJust $ BS.readInt s
      let (to, _) = fromJust $ BS.readInt $ BS.dropWhile isSpace s'
      return (to, from)
  
  print $ solve (sort xs) 0 0

Measured memory_bytes: 47868
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long h, long long n, std::vector<long long> a, std::vector<long long> b){
    vector<i64> dp(h + 1, INF);
    dp[h] = 0;
    for(int i = 0; i < n; ++i){
        for(int j = h; j >= 0; --j)
            chmin(dp[max(0LL, j - a[i])], dp[j] + b[i]);
    }
    cout << dp[0] << endl;
}


signed main(){
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(H, N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 384
#!/usr/local/bin/python3.5 -tt

import random
import sys

if __name__ == '__main__':
    def _(f):
        for l in f:
            for i in l.split():
                yield i

    g = _(sys.stdin)

    N, S = (int(next(g)),
                next(g),
    )

    SS = S

    while S:
        while '()' in S:
            S = S.replace('()', '')

        while S.startswith(')'):
            S = S[1:]
            
            SS = '(' + SS

        while S.endswith('('):
            S = S[:-1]

            SS += ')'

    print(SS)


Measured memory_bytes: 5224
# coding: utf-8
# Your code here!
N=int(input())
A=[]

for _ in range(N):
    a,b=map(int,input().split())
    A.append([a,b])

cost=0
for _ in range(N):
    a,b=A.pop(-1)
    a+=cost
    if a%b!=0:
        cost+=b-(a%b)
    #print(cost)

print(cost)

Measured memory_bytes: 19616
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_abc165_a();
	}
	
	public static void solve_abc165_a(){
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int R = sc.nextInt();
		
		if(N < 10){
			R += 100 * (10 -N);
		}
		
		System.out.println(R);
	}
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	int A[3];
	cin>>A[0]>>A[1]>>A[2];
	sort(A,A+3);
	if(A[0]+A[1]==A[2]) _P("Yes\n");
	else _P("No\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
/*
        Author: Prokash
                CSE48, JU

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int ara[2005];
int main()
{
    FAST;
    string str;
    cin>>str;
    int one=0,zero=0,ans=0;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]=='0')
        {
            zero++;
        }
        else
        {
            one++;
        }
        ans=min(zero,one);
    }
    cout<<ans*2<<endl;
    return 0;
}

Measured memory_bytes: 512
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    H, W, K = map(int, input().split())
    C = [input() for _ in [0] * H]

    ans, total = 0, 0
    for c in C:
        total += c.count('#')

    for mask in range(1 << H):
        c = C[:]
        x = []
        for i in range(H):
            if mask & 1 << i:
                x.append(i)
        n = total
        for i in x:
            n -= c[i].count('#')
            c[i] = '.' * W

        for mask in range(1 << W):
            k, y = n, []
            for i in range(W):
                if mask & 1 << i:
                    y.append(i)
            for i in range(H):
                for j in y:
                    if c[i][j] == '#':
                        k -= 1
            if k == K:
                ans += 1
    print(ans)


main()


Measured memory_bytes: 9168
#include <cstdio>
int main() {
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	if (a>b)a += b, b = a - b, a -= b;
	scanf("%d", &c);
	if (b>c)b += c, c = b - c, b -= c;
	if (a>b)a += b, b = a - b, a -= b;
	printf("%d %d %d\n", a, b, c);
}

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

using namespace std;

typedef long long ll;

class union_find {
    vector<int> par, sz, h;

public:
    union_find(int n) {
        par.resize(n);
        h.resize(n, 0);
        sz.resize(n,1);
        for (int i = 0; i < n; i++)
            par[i] = i;
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else 
            return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)
            return ;
        
        if (h[x] < h[y])
            swap(x, y);
        
        sz[x] += sz[y];
        sz[y] = sz[x];
        par[y] = x;
        if (h[x] == h[y])
            h[x]++;
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
    
    int size(int x) {
        return sz[x] = sz[find(x)];
    }
};

int main() {
    int n, m;   cin >> n >> m;
    union_find uf(n);
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }

    vector<ll> cnt(m+1);
    cnt[m] = (ll)n*(n-1)/2;
    for (int i = m-1; i >= 0; i--) {
        
        if (uf.same(a[i], b[i])) {
            cnt[i] = cnt[i+1];
            continue;
        }
        cnt[i] = cnt[i+1] - (ll)uf.size(a[i])*(ll)uf.size(b[i]);
        uf.unite(a[i], b[i]);
    }

    for (int i = 1; i <= m; i++)
        cout << cnt[i] << endl;

    return 0;
}


Measured memory_bytes: 5820
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}
signed main() {
  int n,k;
  cin>>n>>k;
   vector<int>a(n);
   int minu=0,plu=0,zero=0;
   rep(i,n){
     cin>>a[i];
     if(a[i]<0)minu++;
     else if(a[i]>0) plu++;
     else zero++;
   }
   sort(a.begin(), a.end(), [](int i, int j) -> bool {
    return abs(i) < abs(j);
  });
  int ans=1;
  if(plu==0&&k%2==1&&zero){cout<<0;exit(0);}
  if((minu%2==1&&n==k)||(plu==0&&k%2==1)){
       rep(i,k){
         ans=ans*a[i]%MOD;
         while(ans<0)ans+=MOD;
       }
        while(ans<0)ans+=MOD;
       cout<<ans<<endl;
       exit(0);
     }
  rep(i,k){
    ans=ans*a[n-i-1]%MOD;
  }
  if(ans>=0){cout<<ans;exit(0);}
  ans*=-1;
  int p=0,q=0,r=0,s=0;
  rep(i,k){if(a[n-k+i]>0){p=a[n-k+i];break;}}
  rep(i,k){if(a[n-k+i]<0){r=a[n-k+i];break;}}
  rep(i,n-k){if(a[n-k-i-1]<0){q=a[n-k-i-1];break;}}
  rep(i,n-k){if(a[n-k-i-1]>0){s=a[n-k-i-1];break;}}
  if(q*r>s*p&&q!=0&&p!=0){
    ans=(-gyaku(p)*q)%MOD*ans%MOD;
  	while(ans<0)ans=ans+MOD;  
  }
  else {
    ans=(gyaku(-r)*s)%MOD*ans%MOD;
 	while(ans<0)ans=ans+MOD;
       }
  cout<<ans<<endl;
}


Measured memory_bytes: 5116
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<vector>
#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string>

using namespace std;

const int MX=500011;
int n,D;
int d[MX];
int mnf[MX],v[MX];
int main(){
	scanf("%d%d",&n,&D);
	for(int i=1;i<=n;i++)scanf("%d",&d[i]);
	mnf[n+1]=1;
	for(int i=n;i;i--)
		mnf[i]=(mnf[i+1]<=(d[i]>>1)?mnf[i+1]:min(mnf[i+1]+d[i],D+1));
	v[1]=D;
	for(int i=1;i<=n;i++)v[i+1]=min(v[i],abs(v[i]-d[i]));
	int q;scanf("%d",&q);
	while(q--){
		int t;scanf("%d",&t);
		puts(v[t]>=mnf[t+1]?"YES":"NO");
	}
	return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
    SPEED;
    string str;
    cin>>str;
    if(str[2]==str[3] && str[4]==str[5])
    {
        cout<<"Yes";
    }
    else
    cout<<"No";
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        String str, input;

        while(true){
            str = s.next();
            input = s.next();

            if(input.charAt(0) == 'X') break;

            String change = "";
            String[]column = str.split("_");
            
            switch(input.charAt(0)){
                case 'U':
                    if(column.length == 1){
                        change = (char)(str.charAt(0)&(~32)) + str.substring(1);
                    }else{
                        for(int i = 0; i < column.length; i++){
                            change += (char)(column[i].charAt(0)&(~32)) + column[i].substring(1);
                        }
                    }
                    break;
                case 'L':
                    if(column.length == 1){
                        change = (char)(str.charAt(0)|(32)) + str.substring(1);
                    }else{
                        change += column[0];
                        for(int i = 1; i < column.length; i++){
                            change += (char)(column[i].charAt(0)&(~32)) + column[i].substring(1);
                        }
                    }
                    break;
                case 'D':
                    if(column.length !=1 ) change = str;
                    else for(int i = 0; i < str.length(); i++){
                        if(i > 0 && str.charAt(i) >= 'A' && str.charAt(i) <= 'Z'){
                            change += "_"+(char)(str.charAt(i)|32);
                        }
                        else change += (char)(str.charAt(i)|32);
                    }
                    break;
            }
            System.out.println(change);
        }
    }
}

Measured memory_bytes: 26368
a=int(input())

import sys
b = [input() for i in range(a)]
c=set(b)
if len(b)!=len(c):
    print('No')
    sys.exit()
for i in range(a-1):
    if b[i][-1]==b[i+1][0]:
        pass
    else:
        print('No')
        sys.exit()
print('Yes')




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

int main(){
    cout<<"Yes"<<endl;
    long n,m;cin>>n>>m;
    vector<vector<int>> graph(n+1);
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> prev(n+1,0);
    queue<int> q;
    q.push(1);
    while(q.size()!=0){
        int a=q.front();
        q.pop();
        for(int i=0;i<graph[a].size();i++){
            if(prev[graph[a][i]]==0){
                prev[graph[a][i]]=a;
                q.push(graph[a][i]);
            }
        }
    }
    for(int i=2;i<prev.size();i++)cout<<prev[i]<<endl;
}

Measured memory_bytes: 10100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		h = sc.nextInt();
		w = sc.nextInt();
		K = sc.nextInt();

		board = new char[h][w];

		for(int i = 0; i < h; i++){
			String str = sc.next();

			board[i] = str.toCharArray();
		}

		int result = 0;

		for(int i = 0; i <= Math.pow(2, h) - 1; i++){
			int tmpI = i;
			boolean useH[] = new boolean[h];
			for(int j = 0; j < h; j++){
				if(tmpI % 2 == 1){
					useH[j] = true;
				}
				tmpI /= 2;
			}

			for(int j = 0; j <= Math.pow(2, w) - 1; j++){
				int tmpJ = j;
				boolean useW[] = new boolean[w];
				for(int k = 0; k < w; k++){
					if(tmpJ % 2 == 1){
						useW[k] = true;
					}
					tmpJ /= 2;
				}

				int count = 0;

				for(int k = 0; k < h; k++){
					for(int l = 0; l < w; l++){
						if(useH[k] == true && useW[l] == true && board[k][l] == '#'){
							count++;
						}
					}
				}

				if(count == K){
					result++;
				}
			}
		}

		System.out.println(result);
	}

	static int h;
	static int w;
	static int K;

	static char[][] board;
}

Measured memory_bytes: 28588
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const ll MOD = 1000000007LL;
/*メモ XOR問題のまとめ
性質 1「交換則、結合則が成り立つ」
　　 2「a xor a = 0」
　　 3「ある数xのb番目のビットが1である <=> x mod 2^(b+1) ≧ 2^b」
　　 4「0≦aのとき、4a, 4a+1, 4a+2, 4a+3のxor和は0」
方針 
!!!!!1「xor計算は各ビットで独立なので別々に計算」
　　 2「trieを使ったxorの最大最小探索がある解説」
・しゃくとり法は[ｌ,r)で考えるとわかりやすいよ！
*/
int main(){
    int a,b,c;
    std::cin >> a>>b>>c;
    if(a==b&&b==c){
        std::cout << "No" << std::endl;
    }
    else{
        if(a==b||b==c||c==a)std::cout << "Yes" << std::endl;
        else std::cout << "No" << std::endl;
    }
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    ll d, t, s;
    cin >> d >> t >> s;
    if(d > t * s) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<ll,ll> P;
ll bit[500010];
class BIT{
public:
  ll n;
  BIT(){fill(bit,bit+500010,0);}
  void add(ll i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  ll sum(ll i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};
bool cmp(P a, P b) {
  if(a.F==b.F) return a.S<b.S;
  return a.F>b.F;
}

P p[111111];
ll d[111111],b[111111];
vector<P> a;
vector<ll> c[111111];
BIT t=BIT();

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  ll n,m;
  cin >> n >> m;
  for(int i=0; i<m; i++) {
    ll x,y,z;
    cin >> x >> y;
    if(!x) {
      cin >> z;
      y--;
      d[y]+=z;
      a.push_back(P(d[y],y));
    }
    p[i]=P(x,y);
  }
  for(int i=0; i<n; i++) a.push_back(P(0,i));
  t.n=a.size();
  a.push_back(P(0,-1));
  ll k=a.size();
  sort(a.begin(),a.end(),cmp);
  for(int i=k-1; i>=0; i--) c[a[i].S].push_back(i+1);
  for(int i=0; i<n; i++) {
    t.add(c[i][b[i]],1);
    b[i]++;
  }
  for(int i=0; i<m; i++) {
    if(!p[i].F) {
      ll x=p[i].S;
      t.add(c[x][b[x]-1],-1);
      t.add(c[x][b[x]],1);
      b[x]++;
    } else {
      ll l=0,r=k;
      while(l+1!=r) {
        ll m=(l+r)/2;
        if(t.sum(m)<p[i].S) l=m;
        else r=m;
      }
      cout << a[l].second+1 << " " << a[l].first << endl;
    }
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int nowX =0,nowY=0,now = 0;

    for(int i=0;i<n;i++){
        int t,x,y;
        cin >> t >> x >> y;
        int cost = abs(nowX-x)+abs(nowY-y);
        if(cost<=t-now&&(t-now-cost)%2==0){
            nowX =x;
            nowY =y;
            now = t;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int N, M;
int WA[105000];
bool AC[105000];
 
void solve() {
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for(int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }
    while(M--) {
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        if(S == "AC") {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA") {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int n;
    cin >> n;
    vector<int> h(n);
    REP(i, n) { cin >> h.at(i); }

    vector<int> dp(n + 1);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    FOR(i, 2, n) { dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])); }

    cout << dp[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 1024
def solve(x):
    if x == 0:
        return INF

    sgn = (-1) ** (x < 0)
    ret = abs(a[0] - x)
    sm = x
    for e in a[1:]:
        sgn *= -1

        if sgn < 0:
            if sm + e < 0:
                sm += e
            else:
                ret += e + 1 + sm
                sm = -1

        else:
            if sm + e > 0:
                sm += e
            else:
                ret -= e - 1 + sm
                sm = 1

    return ret


n = int(input())
a = list(map(int, input().split()))
INF = 10 ** 18

ans = min(solve(1), solve(-1), solve(a[0]))
print(ans)


Measured memory_bytes: 20124
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <algorithm>
using namespace std;
int _P=998244353;
int main(){
	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	for(int i=0;i<n;++i) cin >> a[i];
	vector<vector<int>> f(n+1, vector<int>(s+1));
	f[0][0]=1;
	for(int i=1;i<=n;++i) f[i][0] = (2*f[i-1][0])%_P;
	for(int i=1;i<=s;++i) f[0][i] = 0;
	for(int i=1;i<=n;++i) {
		for(int j=1;j<=s;++j) {
			f[i][j]=(2*f[i-1][j])%_P;
			if(a[i-1]<=j) f[i][j]=(f[i][j]+f[i-1][j-a[i-1]])%_P;
		}
	}
	cout << f[n][s];
	return 0;
}

Measured memory_bytes: 38636
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>
using namespace std;

int main(void){
    // Your code here!
    long long n, t;
    vector<long long> v;
    long long count = 0;
    
    cin >> n >> t;
    
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        v.push_back(temp);
    }
    
    v.push_back(LLONG_MAX);
    
    for(int i = 1; i < n + 1; i++){
        if(v[i] - v[i-1] > t)
            count += t;
        else
            count += v[i] - v[i-1];
    }
    
    cout << count << endl;
    
    return 0;
        
}

Measured memory_bytes: 2420
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int c[4][4];
int a1ja2,a2ja3,b1jb2,b2jb3,a1ja3,b1jb3;
int main()
{
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			scanf("%d",&c[i][j]);
		}
	}
	a1ja2=c[1][1]-c[2][1];
	a2ja3=c[2][1]-c[3][1];a1ja3=a1ja2+a2ja3;
	b1jb2=c[1][1]-c[1][2];
	b2jb3=c[1][2]-c[1][3];b1jb3=b1jb2+b2jb3;
	// judge a;
	if(c[1][1]-c[3][1]!=a1ja3){
		cout<<"No";return 0;
	}
	if(c[1][2]-c[2][2]!=a1ja2){
		cout<<"No";return 0;
	}
	if(c[2][2]-c[3][2]!=a2ja3){
		cout<<"No";return 0;
	}
	if(c[1][2]-c[3][2]!=a1ja3){
		cout<<"No";return 0;
	}
	if(c[1][3]-c[2][3]!=a1ja2){
		cout<<"No";return 0;
	}
	if(c[2][3]-c[3][3]!=a2ja3){
		cout<<"No";return 0;
	}
	if(c[1][3]-c[3][3]!=a1ja3){
		cout<<"No";return 0;
	}
	//judge b
	if(c[1][1]-c[1][3]!=b1jb3){
		cout<<"No";return 0;
	}
	if(c[2][1]-c[2][2]!=b1jb2){
		cout<<"No";return 0;
	}
	if(c[2][2]-c[2][3]!=b2jb3){
		cout<<"No";return 0;
	}
	if(c[2][1]-c[2][3]!=b1jb3){
		cout<<"No";return 0;
	}
	if(c[3][1]-c[3][2]!=b1jb2){
		cout<<"No";return 0;
	}
	if(c[3][2]-c[3][3]!=b2jb3){
		cout<<"No";return 0;
	}
	if(c[3][1]-c[3][3]!=b1jb3){
		cout<<"No";return 0;
	} 
	cout<<"Yes";
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int n;
    while (cin >> n , n) {
        int m = 1000 - n;
        int ans = 0;
        if (m >= 500) {
            ans ++;
            m -= 500;
        }
        //cout << m << " " << ans << endl;
        if (m >= 100) {
            ans += m/100;
            m = m % 100;
        }
        //cout << m << " " << ans << endl;
        if (m >= 50) {
            ans += m/50;
            m = m % 50;
        }
        //cout << m << " " << ans << endl;
        if (m >= 10) {
            ans += m / 10;
            m = m % 10;
        }
        //cout << m << " " << ans << endl;
        if (m >= 5) {
            ans += m / 5;
            m = m % 5;
        }
        if (m >= 1) {
            ans += m/1;
            m = m % 1;
        }
        //cout << m << " " << ans << endl;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
N, M = list(map(int, input().split()))
submits = [[] for i in range(M)]
for i in range(M):
    submits[i] = input().split()
    submits[i][0] = int(submits[i][0])

AC_number = [0 for i in range(N)] #バケット
WA_number = [0 for i in range(N)] #バケット
for i in range(M):
     #ACが出たら
    if submits[i][1] == 'AC':
        AC_number[submits[i][0] - 1] = 1
    #まだ終わってない問題なら
    elif AC_number[submits[i][0] - 1] == 0:
        WA_number[submits[i][0] - 1] += 1

AC_count = 0
WA_count = 0
for i in range(N):
    if AC_number[i] == 1:
        AC_count += 1
        WA_count += WA_number[i]
print(AC_count, WA_count)
    
    

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

void print_result(string& s, int l, int r) {
  // debug
  // printf("print_result l=%d, r=%d\n", l, r);

  int rl = l;
  for (int i = l; i < r; i++) {
    // if (s[i] == 'R' && s[i + 1] == 'L') {
    //   rl = i;
    //   if ((r - l + 1) % 2 == 0) {
    //     printf("%d %d ", (r - l + 1) / 2, (r - l + 1) / 2);
    //   } else {
    //     if ((l % 2) == (i % 2)) {
    //       printf("%d %d ", ((r - l + 1) / 2) + 1, (r - l + 1) / 2);
    //     } else {
    //       printf("%d %d ", ((r - l + 1) / 2), ((r - l + 1) / 2) + 1);
    //     }
    //   }
    //   i++;
    // } else {
    //   printf("0 ");
    // }

    if (s[i] == 'R' && s[i + 1] == 'L') {
      rl = i;
      break;
    }
  }
  // debug
  // printf("print_result rl=%d\n", rl);
  for (int i = l; i <= r; i++) {
    if (i != rl && i != (rl + 1)) {
      printf("0 ");
    } else {
      if ((r - l + 1) % 2 == 1) {
        // if (i == rl) {
        if ((l % 2) == (i % 2)) {
          printf("%d ", ((r - l + 1) / 2) + 1);
        } else {
          printf("%d ", ((r - l + 1) / 2));
        }
        // } else {
        //   if ((l % 2) == (i % 2)) {
        //     printf("%d ", ((r - l + 1) / 2) + 1);
        //     // printf("%d ", (r - l + 1) / 2);
        //   } else {
        //     printf("%d ", ((r - l + 1) / 2));
        //     // printf("%d ", ((r - l + 1) / 2) + 1);
        //   }
        // }
      } else {
        printf("%d ", (r - l + 1) / 2);
      }

      // if (i == rl) {
      //   if ((r - l + 1) % 2 == 0) {
      //     printf("%d ", (r - l + 1) / 2);
      //   } else {
      //   }

      //   if (rl % 2 == 1) {
      //     printf("%d ", (r - l + 1) / 2);
      //   } else {
      //     printf("%d ", (r - l + 2) / 2);
      //   }
      // } else {
      //   if ((r - l + 1) % 2 == 0) {
      //     printf("%d ", (r - l + 1) / 2);
      //   } else {
      //   }

      //   if (rl % 2 == 1) {
      //     printf("%d ", (r - l + 2) / 2);
      //   } else {
      //     printf("%d ", (r - l + 1) / 2);
      //   }
      // }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int l = 0;
  int r = 0;
  for (int i = 0; i < s.length(); i++) {
    if (i == (s.length() - 1) || (s[i] == 'L' && s[i + 1] == 'R')) {
      print_result(s, l, i);
      l = i + 1;
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 999999999
#define llong long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
dreameraser
)");
#define cin input
#endif

int main()
{
	string s;
	cin >> s;
	reverse(s.begin(), s.end());

	while (s!="")
	{
		if (s.substr(0,6)=="resare")
			s.erase(s.begin(), s.begin()+6);
		else if (s.substr(0,5)=="esare")
			s.erase(s.begin(), s.begin()+5);
		else if (s.substr(0,7)=="remaerd")
			s.erase(s.begin(), s.begin()+7);
		else if (s.substr(0,5)=="maerd")
			s.erase(s.begin(), s.begin()+5);
		else
			break;
	}
	
	if (s=="")
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 512
N = int(input())
a_list = list(map(int, input().split()))

odd_sum = [0]
even_sum = [0]

for i in range(N):
    if i % 2 == 0:
        odd_sum.append(odd_sum[-1] + a_list[i])
        even_sum.append(even_sum[-1] - a_list[i])
    else:
        odd_sum.append(odd_sum[-1] - a_list[i])
        even_sum.append(even_sum[-1] + a_list[i])

ans = []
for i in range(N):
    a = a_list[i]

    if i % 2 == 0:
        a += (odd_sum[-1] - odd_sum[i + 1])
        a += even_sum[i]
    else:
        a += (even_sum[-1] - even_sum[i + 1])
        a += odd_sum[i]
    print(a)
    # if i == 0:
    #     break
    # flg = False
    # for j in range(i + 1, N + i):
    #     b = a_list[j % N]
    #     if flg:
    #         flg = False
    #         a += b
    #     else:
    #         flg = True
    #         a -= b
    # print(a)


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

int main(){
  int i;
  char T[1000], P[1000];

  scanf("%s%s", T, P);

  for(i=0; i<strlen(T); i++){
    if(strncmp(&T[i], P, strlen(P)) == 0) printf("%d\n", i);
  }

  return 0;
}

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

namespace AtCoder
{
    class Abc161A
    {
        public static void Main()
        {
            var XYZ = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            Console.WriteLine(XYZ[2].ToString() + " " + XYZ[0] + " " + XYZ[1]);
        }
    }
}


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

using namespace std;
#define For(i,x,y) for (int i =x; i<=y; ++i)
string s,tmp ;
int cnt;
stack<string> S;
int main()
{
    cin>>s;
    tmp=s[0];
    S.push(tmp);
    int n =s.size()-1 ;
    int i =1;
    while (i<=n)
    {
        tmp=s[i];
        ++i;
        while (i<=n && tmp==S.top())
        {
            tmp=tmp+s[i];
            //cout<<i<<" "<<s[i]<<"\n";
            ++i;

        }
      // cout<<i<<" "<<tmp<<"\n";
        S.push(tmp);
    }
    string hjhj=S.top(); S.pop();
    if (hjhj==S.top()) cout<<S.size();else cout<<S.size()+1;
    return 0;
}

Measured memory_bytes: 11012
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	
const int N = 2e5 + 5;
int n,m,i,j,x,y;
/*
int recur(string s,int i,int j)
{

	if(i>j)
		return 0;
	if(s[i]==s[j])
		return recur(s,i+1,j-1);
	return 1+min(recur(s,i+1,j),recur(s,i,j-1));
}*/
int main(){
	fast;
	int t;
	cin>>t;
	int a[t+1];
	int dp[t+1];
	for(int i=0;i<t;i++){
		dp[i]=0;
		cin>>a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(int i=2;i<t;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));	
	}
	cout<<dp[t-1];


}



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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N;
    cin >> N;
    unordered_set<string> st;
    for (ll i = 0; i < N; i++) {
        string s;
        cin >> s;
        st.emplace(s);
    }

    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 17716
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

vll a, p;

ll f(ll n, ll x) {
    if (n == 0) {
        return (x <= 0 ? 0 : 1);
    } else if (x <= 1 + a[n - 1]) {
        return f(n - 1, x - 1);
    } else {
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1]);
    }
}

int main()
{
    ll N, X; cin >> N >> X;
    a.push_back(1), p.push_back(1);
    rep(i, N) {
        a.push_back(a[i] * 2 + 3);
        p.push_back(p[i] * 2 + 1);
    }
    cout << f(N, X) << endl;
    return 0;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var data = new List<string>();
            for(int i = 0; i < a[0]; i++)
            {
                data.Add(Console.ReadLine());
            }
            Console.Write("#");
            for (int i = 0; i < a[1]; i++)
            {
                Console.Write("#");
            }
            Console.Write("#\n");

            for (int i = 0; i < a[0]; i++)
            {
                Console.WriteLine($"#{data[i]}#");
            }
            Console.Write("#");
            for (int i = 0; i < a[1]; i++)
            {
                Console.Write("#");
            }
            Console.Write("#\n");
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define poq pop_back
#define tof ios_base :: sync_with_stdio(NULL);cin.tie(0);cout.tie(0)




using namespace std;

int main()
{
    int a,b,c,aa,bb,cc;
    cin>>a>>b>>c;
    if (a==b&&a==c&&a%2==0)
    {
        cout<<-1;
        return 0;
    }
    if (a%2==1||b%2==1||b%2==1)
    {
        cout<<0;
        return 0;
    }
    ll aans=0;
    while (!((a&1)||(b&1)||(c&1)))
    {
        aa=(b+c)/2;
        bb=(a+c)/2;
        cc=(a+b)/2;
        a=aa;
        b=bb;
        c=cc;
        aans++;
    }
cout<<aans;

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		
		int n = Integer.parseInt(tmpArray[0]);
		int m = Integer.parseInt(tmpArray[1]);
		
		int time = 0;
		if(m == 0){
			time = n * 100;
		}
		else if(m == 1){
			time = 200*(n + 18);
		}
		else if(m == 2){
			time = 400*(n + 36);
		}
		else if(m == 3){
			time = 800*(n + 54);
		}
		else if(m == 4){
			time = 1600*(n + 72);
		}
		else {
			time = 3200*(n + 90);
		}
		
		System.out.println(time);
	}

}


Measured memory_bytes: 21332
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {

  int n;
  ll a[150000];
  cin >> n;
  rep(i, n) cin >> a[i];

  ll ans = a[0] - 1;
  ll k = 2;
  for (int i = 1; i < n; i++) {
    if (a[i] == k) k++;
    if (a[i] % k == 0) ans += a[i] / k - 1;
    else ans += a[i] / k;
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf = sizeof(Def) == sizeof(ll) ? 2e18 : 1e9+10;

#include<complex>
typedef complex<double> P;
typedef vector<P> G;
typedef vector<double> vd;
typedef vector<vd> vvd;

struct L :public vector<P>{
	L(){}
	L(const P &a, const P &b){
		push_back(a);
		push_back(b);
	}
};
struct C{
	P c;double r;
	C(const P &c, double r):c(c),r(r){}
};

namespace std{
	bool operator < (const P& a,const P& b){
		return real(a)!=real(b) ? real(a) < real(b) : imag(a)<imag(b);
	}
	bool operator == (const P& a,const P& b){
		return a.real()==b.real() && a.imag() == b.imag();
	}
	
}

double dot(P a,P b){
	return real(conj(a)*b);
}
double cross(P a, P b){
	return imag(conj(a)*b);
}

int ccw(P a,P b,P c){
	b-=a; c-=a;
	if(cross(b,c) > 0)return 1;
	if(cross(b,c) < 0)return -1;
	if(dot(b,c) < 0) return 2;
	if(norm(b) < norm(c)) return -2;
	return 0;
}

bool intersectSS(const L &s,const L &t){
	return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
			ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

L crosspointCC(C a, C b){
	P tmp=b.c-a.c;
	double d=abs(tmp);
	double q=acos((a.r*a.r+d*d-b.r*b.r)/(2*a.r*d));
	double t=arg(tmp);
	P p1=a.c+polar(a.r,t+q);
	P p2=a.c+polar(a.r,t-q);
	if(p2<p1)swap(p1,p2);
	return L(p1,p2);
}
int n;
vector<L>w;
bool f(int a,P st,int b,P go){
	bool h=true;
	loop(i,a,b){
		if(!intersectSS(L(st,go),w[i]))h=false;
	}
	return h;
}
signed main(){
	while(cin>>n,n){
		vector<C>in;
		rep(i,n){
			double a,b,c;cin>>a>>b>>c;
			in.pb(C(P(a,b),c));
		}
		w=vector<L>(n-1);
		rep(i,n-1)w[i]=crosspointCC(in[i],in[i+1]);
		double dp[110][2]={0};
		rep(i,110)rep(j,2)dp[i][j]=inf;
		dp[0][0]=abs(in[0].c-w[0][0]);
		dp[0][1]=abs(in[0].c-w[0][1]);
		rep(i,n-2)rep(j,2){
			double out=inf;
			if(f(0,in[0].c,i+1,w[i+1][j]))out=abs(in[0].c-w[i+1][j]);
			rep(k,i+1)rep(l,2)
				if(f(k,w[k][l],i+1,w[i+1][j]))out=min(out,abs(w[k][l]-w[i+1][j])+dp[k][l]);
			dp[i+1][j]=out;
		}
		double out=inf;
		if(f(0,in[0].c,n-1,in[n-1].c))out=abs(in[0].c-in[n-1].c);
		rep(i,n-1){
			if(f(i,w[i][0],n-1,in[n-1].c))out=min(out,abs(in[n-1].c-w[i][0])+dp[i][0]);
			if(f(i,w[i][1],n-1,in[n-1].c))out=min(out,abs(in[n-1].c-w[i][1])+dp[i][1]);
		}
		cout<<shosu(9)<<out<<endl;
	}
}









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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
}

int main()
{
    ll N, R;
    cin >> N >> R;
    if (N >= 10) {
        print(R);
    } else {
        print(R + 100 * (10 - N));
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;
const ll INF = INT_MAX;


struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    // 元配列 v をセグメント木で表現する
    SegmentTree(vector<int> v) {
        // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        // セグメント木全体で必要なノード数は 2n-1 個である
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);

        // 最下段に値を入れたあとに、下の段から順番に値を入れる
        // 値を入れるには、自分の子の 2 値を参照すれば良い
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(int x, int val){
        //最下段のノードにアクセスする
        x += (n - 1);

        //最下段のノードを更新したら，あとは親に上って更新していく
        node[x] = val;
        while(x > 0){
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1],node[2*x+2]);
        }
    }

    //要求区間[a,b)中の要素の最小値を答える
    //k := 自分がいるノードのインデックス
    //対象区間は[l,r)に当たる

    int getmin(int a, int b, int k=0, int l=0, int r=-1){
        //最初に呼び出されたときの対象区間は[0,n);
        if(r < 0) r = n;

        //要求区間と対象区間が交わらない -> INFを返す
        if(r <= a || b <= l) return INF;

        //要求区間が対象を完全に被覆している -> 対象区間の答えを計算に使う
        if(a <= l && r <= b) return node[k];

        //要求区間が対象区間の一部を被覆 -> 子について探索を行う
        //左側の子を vl，右側の子を vr としている
        //新しい対象区間は，現在の対象区間を半分に割ったもの
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl,vr);
    }
};

int main(){
    int n,q;cin >> n >> q;
    vector<int> xy[q];
    rep(i,q){
        int com,x,y;cin >> com >> x >> y;
        // xy[i] = {com,x,y};
        xy[i].pb(com);xy[i].pb(x);xy[i].pb(y);
    }
    vector<int> a(n,INF);

    SegmentTree seg(a);
    rep(i,q){
        int com,x,y;
        com = xy[i][0];x = xy[i][1];y = xy[i][2];
        if(!com)seg.update(x,y);
        else cout << seg.getmin(x,y+1) << endl;

    }
    return 0;

}


Measured memory_bytes: 10244
import java.util.*;

public class Main {

  public static void main(String[] args) throws Exception {
    Scanner scn = new Scanner(System.in);

    int N = scn.nextInt(), M = scn.nextInt();
    int s[] = new int[M], c[] = new int[M];
    for (int i = 0; i < M; i++) {
      s[i] = scn.nextInt();
      c[i] = scn.nextInt();
    }

    int ans = -1;
    int t = (N != 1 ? (int) Math.pow(10, N - 1) : 0);
    for (int i = t; i < (int) Math.pow(10, N); i++) {
      Boolean flag = true;
      for (int j = 0; j < M; j++) {
        if (N < j) {
          flag = false;
          break;
        }
        String str = String.valueOf(i);
        String C = String.valueOf(c[j]);
        if (!str.substring(s[j] - 1, s[j]).equals(C)) {
          flag = false;
          break;
        }
      }
      if (flag) {
        ans = i;
        break;
      }
    }

    System.out.println(ans);
  }
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    double x,y;
    cin>>x>>y;
    cout<<x/y;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
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; }

int main() {
    int N; cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];

    vector<int> dp(N + 2, INF);
    dp[0] = 0;
    for (int i = 1; i < N; i++) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#define M 1046257
#define NIL (-1)
#define L 14
char H[M][L];
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}
int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }
int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}
int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}
int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16096
import heapq
def dijkstra(s, n, g): # s: start, n: |V|, g; glaph 
    INF = 10**18
    d = [INF] * n
    d[s] = 0
    que = [] # (a,b): a... shortest dist, b... v
    heapq.heappush(que, (0, s))

    while que:
        dist, v = heapq.heappop(que)
        if d[v] < dist: continue # if v has been already used -> continue
        for next_v, cost in g[v]:
            if d[next_v] > d[v] + cost:
                d[next_v] = d[v] + cost
                heapq.heappush(que, (d[next_v], next_v))
    return d


def main():
    n,m,s = map(int, input().split())
    g = [ [] for _ in range(n*2501+1)]
    for _ in range(m):
        u,v,a,b = map(int, input().split())
        u-=1
        v-=1
        for j in range(2501):
            if j < a: continue
            g[u*2501+j].append((v*2501+j-a,b))
            g[v*2501+j].append((u*2501+j-a,b))


    cdl = [(-1,-1)]
    for i in range(n):
        c,d = map(int, input().split())
        for j in range(2501):
            maxc = min(2500,j+c)
            g[i*2501+j].append((i*2501+maxc,d))

    s = min(2500,s)
    dist = dijkstra(s, n*2501+1, g)
    # print(dist)
    for i in range(1,n):
        ans = min(dist[i*2501:i*2501+2500])
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 118668
/*
問題文
シカのAtCoDeerくんはペンキをこれまでに3つ買いました。
おととい買ったペンキの色は a , 昨日買ったペンキの色は b , 今日買ったペンキの色は c です。
各ペンキの色は1以上100以下の整数で表されます。
AtCoDeerくんはわすれんぼうなため、同じ色のペンキを買ってしまっていることがあります。
AtCoDeerくんが買ったペンキの色の種類の個数を教えてあげてください。
*/
#include<iostream>
#include<string>
#include<vector>
#include<map>

int main() {
	int i = 1;
	std::map<int, int> mp;
	std::vector<int>v;
	std::map < int, int > ::iterator itr;
	
	
	v.resize(3);

	for (int i = 0; i < v.size(); i++) {
		std::cin >> v[i];
	}
	

	mp[v[0]] = v[0];
	mp[v[1]] = v[1];
	mp[v[2]] = v[2];


	//mapは２分木(黒赤木)
	
	for (itr = mp.begin(); itr != mp.end(); ++itr) {

		if (std::next(itr) == mp.end()) { //これがなかったのでnext()がend()(end()は配列の一個あとを示すためいわゆるヌル文字的な何かを参照してしまいエラーになった)
			break;
		}
			
		if (itr->second != (std::next(itr)->second)) {
			i++;
		}
	}

	std::cout << i << std::endl;

	return 0;
}

/*
if (*itr!= *(std::next(itr))) {
i++;
}
*/

/*
今日のまとめ
× *itr
〇 itr->first

× (*itr!= *(std::next(itr)))
× itr->second!= std::next(itr->second)
× (itr->second != std::next(itr)->second)
*/

Measured memory_bytes: 256
n = int(input())
x = [int(a) for a in input().split()]
l = max(x) - min(x)

sho = []
for i in range(min(x), min(x)+l+1):
    something = 0
    for k in range(n):
        something += (abs(i - x[k]))**2
    sho.append(something)
print(min(sho))

Measured memory_bytes: 3060
S = input()
modulo = 10 ** 9 + 7

remainder = {0: 1}

for s in S:
    rx = {r: 0 for r in range(13)}
    for n in (range(10) if s == '?' else [int(s)]):
        for r in remainder:
            r2 = (r * 10 + n) % 13
            rx[r2] += remainder[r]
            rx[r2]  = rx[r2] % modulo
    remainder = rx

print(remainder[5] % modulo)

Measured memory_bytes: 44076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define EFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i, n) FOR(i,0,n)

int main(void){
    int x;
    cin >> x;
    if(x == 0) cout << "1" << endl;
    else cout << "0" << endl;
    return 0;
}

Measured memory_bytes: 3632