akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define sum(x) accumulate(all(x),0)
#define gll greater<ll>()


void solve(){
 ll d;
  cin >> d;
  vll c(26);
  rep(i,0,26) cin >> c[i];  
  
 vvll s(d,vll(26));
  rep(i,0,d){
    rep(j,0,26) cin >> s[i][j]; 
  }
  
  vll t(d);
  rep(i,0,d) {
    cin >> t[i];
    t[i]--;
  }
    
  ll m;
  cin >> m;
  while(m--){
   ll x,q;
    cin >> x >> q;
    x--;
    q--;
   t[x]=q;
 
   
  vll last(26,-1);
  ll ans=0;
  rep(i,0,d){
    ans+=s[i][t[i]];
    last[t[i]]=i;
    rep(j,0,26) ans-=c[j]*(i-last[j]);
  }
  cout << ans << endl; 
  }
}

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 3704
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void combination(int n, vector<vector<long long> >& comb)
{
    comb.assign(n+1, vector<long long>(n+1, 0));
    for(int i=0; i<=n; ++i){
        comb[i][0] = 1;
        for(int j=1; j<=i; ++j)
            comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
    }
}

int main()
{
    vector<vector<long long> > comb;
    combination(60, comb);

    for(;;){
        int n;
        long long m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        int one = 0;
        while(comb[n][one] < m){
            m -= comb[n][one];
            ++ one;
        }

        string ret;
        for(int i=0; i<n; ++i){
            if(comb[n-1-i][one] < m){
                ret += '1';
                m -= comb[n-1-i][one];
                -- one;
            }else{
                ret += '0';
            }
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 1252
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {
bool isNotPalindrome(string s)  {
  if(s.length()%2==0) {
    REP(i,s.length()/2) {
      int e=s.length()-i-1;
      if(s[i]!=s[e]) return true;
    }
    return false;
  } else {
    REP(i,(s.length()-1)/2) {
      int e=s.length()-i-1;
      if(s[i]!=s[e]) return true;
    }
    return false;
  }
}

int main(void) {
  string s;cin>>s;
  if(isNotPalindrome(s)) {
    p("No");
    return 0;
  }
  if(isNotPalindrome(s.substr(0,(s.length()-1)/2))) {
    p("No");
    return 0;
  }
  if(isNotPalindrome(s.substr((s.length()+1)/2,(s.length()-1)/2))) {
    p("No");
    return 0;
  }
  p("Yes");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*C++になってるか確認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  int R; cin>>R;
  cout<<2*acos(-1)*R<<endl;
}

Measured memory_bytes: 3784
N = int(input())
vlist = list(map(int,input().split()))
vlist.sort()
ans = 0
a = len(vlist)-1
for _ in range(a):
    vlist.append((vlist[0]+vlist[1])/2)
    del vlist[0:2]
    vlist.sort()
print(vlist[0])

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#define LL long long
int N,C;
LL D[31][31];
int c[510][510];
int g[3][31];
LL ans=1e15;
int main(){
	std::cin>>N>>C;
	for(int i=1;i<=C;i++){
		for(int j=1;j<=C;j++){
			std::cin>>D[i][j];
		}
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			std::cin>>c[i][j];
			g[(i+j)%3][c[i][j]]++;
		}
	}
	for(int i=1;i<=C;i++){
		for(int j=1;j<=C;j++){
			for(int k=1;k<=C;k++){
				if(i==j||j==k||k==i)continue;
				LL sum=0;
				for(int q=1;q<=C;q++){
					sum+=D[q][i]*g[0][q];
					sum+=D[q][j]*g[1][q];
					sum+=D[q][k]*g[2][q];
				}
				ans=std::min(ans,sum);
			}
		}
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int h, w;
  cin >> h >> w;
  
  string board[50];
  
  for (int i = 0; i < h; ++i) cin >> board[i];
  
  int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (board[i][j] == '#') continue;
      
      int num = 0;
      for (int d = 0; d < 8; ++d) {
        const int ni = i + dy[d];
        const int nj = j + dx[d];
        
        if (ni < 0 || h <= ni) continue;
        if (nj < 0 || w <= nj) continue;
        if (board[ni][nj] =='#') num++;
      }
      
      board[i][j] = char(num + '0');
    }
  }
  
  for (int i = 0; i < h; ++i) cout << board[i] << endl;
  
  return 0;
}
  

Measured memory_bytes: 256
import java.util.*;

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

    int r = sc.nextInt();//グーで勝利する場合の加点
    int s = sc.nextInt();
    int p = sc.nextInt();

    String ss = sc.next();

    char[] c = ss.toCharArray();

    int points = 0;

    for(int i=0; i<c.length;i++){
     if(c[i]==0x73){//相手がチョキ
       if(i<k||(i>=k&&c[i-k]!=c[i])){
         points += r;
         //System.out.println(i+"グーで勝利");
       }else{
         c[i] = 0x00;
       }
     }else if(c[i]==0x70){//相手がgu-

       if(i<k||(i>=k&&c[i-k]!=c[i])){
                         //System.out.println(i+"パーで勝利");
         points += s;
       }else{
         c[i] = 0x00;
       }
     }else if(c[i]==0x72){//相手がパー
       if(i<k||(i>=k&&c[i-k]!=c[i])){
         points += p;
                //System.out.println(i+"チョキで勝利");
       }else{
         c[i] = 0x00;
       }
     }
   }

   System.out.println(points);
  }
}

Measured memory_bytes: 27760
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */

int main(){
    int N; cin >> N;
    char s[1000];
    int i = 0;
    while(abs(N) > 0){
        s[i] = '0' + ((N % -2 == 0) ? 0 : 1);
        N = (N - ((N % -2 == 0) ? 0 : 1)) / -2;
        ++i;
    }
    if(i == 0)cout << 0;
    while(i > 0){
        cout << s[--i];
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define s second
#define VAL 100000
#define ll long long
const int MAX=1e5+8;
using namespace std;
vector<int>adj[MAX];
int vis[MAX];
int cnt[MAX];
int main() 
{ 
	//ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);
//	#ifndef ONLINE_JUDGE
//	freopen("inp.txt" ,"r", stdin );
////	freopen("out.txt", "w", stdout);
//	#endif
	int n , x, y;
	cin>>n>>x>>y;
	int dis[n+1];
	int p=abs(x-y);
	memset(dis, 0 , sizeof(dis));
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int m=abs(i-j);
			int n=abs(x-i)+abs(y-j)+1;
			dis[min(m,n)]++;
			}
	}
	for(int i=1;i<=n-1;i++)
		cout<<dis[i]<<"\n";
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
 
 
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
 
signed main() {
    FAST_IO;
 
    int n;
    cin >> n;
    int jumps[n];
    vector<int> dp(n, 0); // dp[i] : Minimum cost for the frog to reach position i.
    for (int i = 0; i < n; i++) cin >> jumps[i];
    dp[1] = abs(jumps[1] - jumps[0]); // Base value
    for (int i = 2; i < n; i++)
        dp[i] = min(abs(jumps[i] - jumps[i - 1]) + dp[i - 1], abs(jumps[i] - jumps[i - 2]) + dp[i - 2]);
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 4016
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = parseInt(readline())
	e = [Tuple[]for i in 1:n]
	for i in 1:n-1
		a,b,c = readline() |> split |> parseMap
		push!(e[a],(b,c))
		push!(e[b],(a,c))
	end
	q,k = readline() |> split |> parseMap
	now = 0
	stack = Int[k]
	vst = -ones(Int,n)
	vst[k] = 0
	while !isempty(stack)
		now = pop!(stack)
		for i in 1:length(e[now])
			if vst[e[now][i][1]] < 0
				push!(stack, e[now][i][1])
				vst[e[now][i][1]] = vst[now]+e[now][i][2]
			end
		end
	end
	for i in 1:q
		x,y = readline() |> split |> parseMap
		println(vst[x]+vst[y])
	end
end

main()

Measured memory_bytes: 166528
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N; cin >> N;
  if (N <= 999) {
    cout << "ABC" << endl;
  } else {
    cout << "ABD" << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N, M;
const unsigned int MAX_M = static_cast<unsigned int>(1e5);
ll P[MAX_M + 1], Y[MAX_M + 1];
vector<vector<pair<ll, ll>>> v(MAX_M + 1);

void solve() {
    vector<pair<ll, ll>> ans(M);
    FOR(i, 1, N + 1) {
        sort(v[i].begin(), v[i].end());
        REP(j, v[i].size()) ans[v[i][j].second] = make_pair(i, j + 1);
    }

    REP(i, M) printf("%06lli%06lli\n", ans[i].first, ans[i].second);
}

int main() {
    cin >> N >> M;
    REP(i, M) {
        scanf("%lli %lli", &P[i], &Y[i]);
        v[P[i]].emplace_back(make_pair(Y[i], i));
    }
    solve();
    return 0;
}

Measured memory_bytes: 10112
def main():
    import sys
    input = sys.stdin.readline
    from fractions import gcd

    N, M = map(int, input().split())
    A = list(set(map(lambda x: int(x)//2, input().split())))

    l = 1
    div2_count = count_div2(A[0])

    for a in A:
        l = l*a // gcd(l, a)
        c = count_div2(a)
        if div2_count != count_div2(a):
            print(0)
            exit()
    #     div2_count.append(max(count_div2(a), 1))
    # print(div2_count)
    # l *= min(div2_count)
    # print(l)
    # l の奇数倍が1より大きくM以下にいくつあるか

    print((M//l + 1)//2)


def count_div2(x):
    ans = 0
    while x % 2 == 0:
        x = x//2
        ans += 1
    return ans


if __name__ == "__main__":
    main()


Measured memory_bytes: 13324
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int time = Integer.parseInt(str);
			if ((time >= 0) && (time < 864000)) {
				int h = time / 3600;
				int m = (time % 3600) / 60;
				int s = (time % 3600) % 60;
             System.out.println(h + ":" + m + ":" + s);
			}
			//System.out.println(h + ":" + m + ":" + s);
		} catch (Exception e) {
			System.out.println("??¨??????"); 
		}
	}
}
			 

Measured memory_bytes: 24448
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		char[] c1 = sc.next().toCharArray();
		char[] c2 = sc.next().toCharArray();
		boolean ans = false;
		for (int i = 0; i <= c1.length; ++i) {
			boolean f = true;
			for (int j = 0; j < i; ++j) {
				f &= c1[c1.length - i + j] == c2[j];
			}
			for (int j = i; j < c1.length; ++j) {
				f &= c1[j - i] == c2[j];
			}
			ans |= f;
		}
		pw.println(ans ? "Yes" : "No");
		pw.close();
	}

	class Scanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		int nextInt() {
			return (int) nextLong();
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 23124
using System;
public class Program{
  public static void Main(string[] args){
    var beta = Console.ReadLine();
    switch(beta[0]){
      case 'A':
        Console.WriteLine('T');
        break;
      case 'T':
        Console.WriteLine('A');
        break;
      case 'C':
        Console.WriteLine('G');
        break;
      case 'G':
        Console.WriteLine('C');
        break;
    }
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<char> cond(n + 2, '#');
    for(int i = 0; i < m; i++) {
        int s;
        char c;
        cin >> s >> c;
        if(cond[s - 1] == '#') {
            cond[s - 1] = c;
        } else if(cond[s - 1] != c) {
            cout << -1 << endl;
            return 0;
        }
    }

    for(int i = modpow(10, n - 1) - (n == 1); i < modpow(10, n); i++) {
        string s = to_string(i);
        bool flag = true;
        for(int j = 0; j < n + 2; j++) {
            if(cond[j] == '#') {
                continue;
            }
            flag &= (s[j] == cond[j]);
        }
        if(flag) {
            cout << s << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int K;

    AtCoder(FastScanner sc) {
        K = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(K / 2 * (K - K / 2));
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21332
/*
author : seryu
title : NOMURA programming contest 2020
*/
#include <bits/stdc++.h>
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 sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string t;
	cin >> t;
	rep(i, sz(t))
	{
		if(t[i]=='?')t[i] = 'D';
	}
	cout << t << endl;
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3744
#include <iostream>

using namespace std;

int main()
{

    int n, m, x;
    cin >> n >> m >> x;

    int a[101];
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
    }
    int cst_1 = 0;
    int cst_2 = 0;

    for (int i = x; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (i == a[j])
            {
                cst_1++;
            }
        }
    }
    for (int i = x; i > 0; i--)
    {
        for (int j = 0; j < m; j++)
        {
            if (i == a[j])
            {
                cst_2++;
            }
        }
    }
    if (cst_1 < cst_2)
    {
        cout << cst_1 << endl;
    }
    else
    {
        cout << cst_2 << endl;
    }
    return 0;
}


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

#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define full(a, n) a, a + n
#define ma(type, size) (type *)malloc(sizeof(type) * size)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define f0n(i, n) for (i = 0; i < (n); i++)
#define f1n(i, n) for (i = 1; i <= (n); i++)
#define fab(i, a, b) for (i = (a); i <= (b); i++)
#define fr(i, b, a) for (i = (b); i >= (a); i--)

using namespace std;

/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
	tree_order_statistics_node_update> indexed_set;
//*/
typedef long long int ll;
typedef long int lo;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;

//* utility function
inline bool compare(ll i, ll j)
{
    return i < j;
}
//*/

//* function prototypes

//*/

//int row, column;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
#ifdef DEBUG
#endif // DEBUG

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll i, n;

    cin >> n;
    double arr[n];
    f0n(i, n)
    {
        cin >> arr[i];
    }
    sort(full(arr, n));
    double value = arr[0];
    //cout << setprecision(10) << fixed << value << endl;
    for(i = 0; i < n; i++)
    {
        value = (value + arr[i])/2.0;
    }
    cout << setprecision(10) << fixed << value << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n;
  cin >> n;
  if (n % 111 == 0) {
    cout << n << endl;
    return 0;
  } else {
    cout << (n / 111 + 1) * 111 << endl;
    return 0;
  }
}


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

int main(){
  int k,n,a[220000],d=0,sum=0;
  cin>>k>>n;
  for(int i=0;i<n;i++) cin>>a[i];

  for(int i=1;i<n;i++){
    d=max(d,a[i]-a[i-1]);
    sum+=a[i]-a[i-1];
  }
  if(a[0]==0){
    d=max(d,k-a[n-1]);
    sum+=k-a[n-1];
  }
  else{
    d=max(d,k-a[n-1]+a[0]);
    sum+=k-a[n-1]+a[0];
  }
  cout<<sum-d;


}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

int main() {
	ll x, y;
	cin >> x >> y;
	if (y % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	ll low = 2 * x;
	ll u = 4 * x;
	if (low <= y && y <= u) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}
	

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 /*int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }*/
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int a){
	par= vector<int>(a,-1);
  }
  int find(int a){
    if(par[a]<0)
      return a;
    else
      return par[a]=find(par[a]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
int gcm(int a,int b){
    if(b==0)
        return a;
    return gcm(b,a%b);
}
int lcm(int a,int b){
    return a/gcm(a,b)*b;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
/*struct dfs(){

}*/
bool fe(int a,int b){
  a%=10;
  b%=10;
  if(a==0)
    a=10;
  if(b==0)
    b=10;
  if(a>b)
    return true;
  else
    return false;
}
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  fo(i,10){
    c=c*a-b;
    cout<<c<<endl;
  }
}

Measured memory_bytes: 764
from collections import Counter
import sys
H, W, M = map(int, input().split())

h = [0] * M
w = [0] * M
for i in range(M):
    h[i], w[i] = map(int, input().split())


S = Counter(h)
T = Counter(w)

if (M == 1):
    print(1)

else:
    if (S.most_common()[0][1] > T.most_common()[0][1]):
        smc = S.most_common()[0][0]
        for i in range(M):
            if (h[i] == smc):
                w[i] = 'boom'

        w1 = [s for s in w if s != 'boom']
        T = Counter(w1)
        if (len(w1) == 0):
            print(M)
            sys.exit()
        tmc = T.most_common()[0][0]
        for i in range(len(w1)):
            if (w1[i] == tmc):
                w1[i] = 'boom' 

        w2 = [s for s in w1 if s != 'boom']
        print(M-len(w2))

    else:
        tmc = T.most_common()[0][0]
        for i in range(M):
            if (w[i] == tmc):
                h[i] = 'boom'

        h1 = [s for s in h if s != 'boom']
        S = Counter(h1)
        if (len(h1) == 0):
            print(M)
            sys.exit()
        smc = S.most_common()[0][0]
        for i in range(len(h1)):
            if (h1[i] == smc):
                h1[i] = 'boom' 

        h2 = [s for s in h1 if s != 'boom']
        print(M-len(h2))

Measured memory_bytes: 85200
#include<bits/stdc++.h>
using namespace std;
long long x,k,d;
int main(){
	cin>>x>>k>>d;
	if (x>0){
		if (x/d<=k)
			k-=x/d,x=x%d;
		else
			x-=k*d,k=0;
		if (k%2==0)
			cout<<x<<endl;
		else
			cout<<abs(x-d)<<endl;
	}
	else if (x<0){
		if ((-1*x)/d<=k)
			k-=(-1*x)/d,x=-1*((-1*x)%d);
		else
			x+=k*d,k=0;
		if (k%2==0)
			cout<<abs(x)<<endl;
		else
			cout<<abs(x+d)<<endl;
	}
	else{
		if (k%2==0)
			cout<<0<<endl;
		else
			cout<<abs(d)<<endl;
	}
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll d; cin >> d;
  vector <ll> c(26);
  rep(i, 26) cin >> c.at(i);
  vector <vector <ll>> s(d, vector <ll> (26));
  rep(i, d) {
    rep(j, 26) {
      cin >> s.at(i).at(j);
    }
  }
  vector <ll> last(26, 0);
  ll res = 0;
  rep(i, d) {
    ll t; cin >> t;
    t--;
    res += s.at(i).at(t);
    last.at(t) = i+1;
    rep(j, 26) res -= c.at(j)*(i+1-last.at(j));
    cout << res << endl;
  }
}

Measured memory_bytes: 3688
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n, q; cin >> n >> q;
    string s; cin >> s;
    ll l[q], r[q];
    rep(i, q){
        cin >> l[i] >> r[i];
        l[i]--; r[i]--;
    }

    ll cntac[n] = {};
    cntac[0] = 0;
    reps(i, 1, n){
        if(s[i-1] == 'A' && s[i] == 'C'){
            cntac[i] = cntac[i-1] + 1;
        }
        else{
            cntac[i] = cntac[i-1];
        }
    }

    rep(i, q){
        cout << cntac[r[i]] - cntac[l[i]] << endl;
    }

    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

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

int main() {
  ll N;
  cin >> N;
  cout << N*(N-1)/2 << endl;
};


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

typedef long long ll;

const long double PI = (acos(-1));

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

  int n;
  string s;
  cin >> n >> s;

  string ans = "Yes";
  if (n % 2 == 0){
    for (int i = 0; i < n / 2; i++){
      if (s.at(i) != s.at(i + n / 2)){
        ans = "No";
        break;
      } 
    }
  }else {
    ans = "No";
  }

  cout << ans << endl; 

  return 0;
}

Measured memory_bytes: 256
using System;

class Rectangle
{
    public static void Main()
    {
        String[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        Console.WriteLine("{0} {1}", a * b, 2 * a + 2 * b);
    }
}


Measured memory_bytes: 9260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT32_MAX;

ll i,j,k;
long long ruijou(long long x, long long y){
    if(y==0) return 1;
    else if(y%2==0) return ruijou(x*x%mod,y/2);
    else return x*ruijou(x,y-1)%mod;
}



int main(){
   ll N,K;
   cin>>N>>K;
   const ll q=K;
   ll sd[K+1];
   for(ll p=K;p>=1;p--){
      sd[p]=ruijou(K/p,N);
      if(K/p>=2){
         for(ll q=2;q<=K/p;q++){
            sd[p]=(sd[p]-sd[q*p])%mod;
         }
      }
   }
   ll ans=0;
   for(ll q=1;q<=K;q++)ans=(ans+sd[q]*q)%mod;

   if(ans>=0)cout<<ans<<endl;
   else cout<<mod+ans<<endl;
   



}

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

int main(){
  int n;
  int temp;
  cin >> n;
  vector<vector<int>> time(n, vector<int>(2, 0));
  for(int i = 0; i < n; i++) {
    cin >> temp;
    time[i][1] = temp;
    cin >> temp;
    time[i][0] = temp;
  }
  sort(time.begin(), time.end());
  
  bool check = true;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += time[i][1];
    if(time[i][0] < sum) check = false;
  }
  if(check) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 11136
N, x = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
if A[0] > x:
    ans += A[0] - x
    A[0] = x

for i, a in enumerate(A[:-1]):
    if A[i] + A[i+1] >= x:
        ans += A[i+1] - (x - A[i])
        A[i+1] = x - A[i]

print(ans)

Measured memory_bytes: 14132
#include <bits/stdc++.h> 
    #include<ext/pb_ds/assoc_container.hpp> 
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long  
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define INF 1e10
    const double pi=3.14159265358979323;
    const int mod=1e9+7;
    const int MAX=1e7+5;
    int gcd(int a, int b) 
    { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
    } 
    void swap(int a,int b)
    {
      int temp=a;
      a=b;
      b=temp;
    } 
    int  binpow(int  a,int  b) 
    {
    int res = 1;
    while (b > 0) {
        if (b%2 == 1)
            res = (res * a)%mod;
        a = (a* a)% mod;
        b >>= 1;
    }
    return res;
}
    int modinv(int y)
    {
        return binpow(y,mod-2);
    }

    int fact[500000+5];
    void precal()
    {
    fact[0]=1;
    for(int i=1;i<500000+5;i++)
    {
        fact[i]=(i*fact[i-1])%mod;
    }
}   
    bool isPrime(int n) 
    { 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
   
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
    } 
    
    signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    #ifndef ONLINE_JUDGE
     if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout); 
      }
    #endif  
    // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1; 
    //cin>>t;
    while(t--)
    {   
        string a,b;
        cin>>a>>b;
        int n=a.length();
        int cnt=0;
        f(i,0,n)
        {
            if(a[i]!=b[i])
                cnt++;
        }
        cout<<cnt<<endl;
    }
}
  

Measured memory_bytes: 3888
import math

a, b, h, m = map(int, input().split())

# 時針はh時間で30度ずれ、m分で0.5度（m / 2）ずれる
hour_hand = h * 30 + m / 2
# 分針は60分で一周するので1分でずれるのは6度
minute_hand = m * 6
deg = minute_hand - hour_hand
rad = math.radians(deg)

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(math.sqrt(c2))


Measured memory_bytes: 9376
#include <stdio.h>

int main() {
  int n,h,o = 0,m = 0;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d\n", &h);
    if (h >= m) {
      m = h;
      o++;
    }
  }
  printf("%d\n", o);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxl = 20;
int mat[maxl][maxl],arr[maxl];
int N,M,C;
int main(){
	scanf("%d%d%d",&N,&M,&C);
	for(int i = 0 ; i < M ; ++i) scanf("%d",&arr[i]);
	for(int i = 0 ; i < N ; ++i){
		for(int j = 0 ; j < M ; ++j){
			scanf("%d",&mat[i][j]);
		}
	}
	
	LL ans = 0;
	for(int i = 0 ; i < N ; ++i){
		LL res =  0;
		for(int j= 0 ; j < M ; ++j){
			res += mat[i][j]*arr[j];
		}
		res += C;
		if(res > 0)++ans;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> num(N);
  for(int i=0;i<N;i++){
    cin>>num.at(i);
  }
  int count =0;
  for (int i=0;i<N;i++){
    int minnum=i;
    for(int j=i+1;j<N;j++){
      if(num[minnum]>num[j]){
        minnum=j;
      }
    }
    swap(num[i],num[minnum]);
    if(minnum!=i){
      count++;
    }
  }
  for(int i=0;i<N;i++){
    if(i==N-1){
      cout<<num[N-1]<<endl;
      break;
    }
    cout<<num[i]<<" ";
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3076
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>

uint64_t *pnf, *ipnf;

uint64_t powmod(uint64_t x, uint64_t y, uint64_t p)
{
	if(y == 0){
		return 1;
	} else if(y % 2 == 1){
		return (powmod(x, y-1, p) * x) % p;
	} else {
		uint64_t t = powmod(x, y/2, p);
		return (t * t) % p;
	}
}

void fmod_init(uint64_t n, uint64_t p)
{
    pnf = malloc(sizeof(uint64_t) * (n+1));
    ipnf = malloc(sizeof(uint64_t) * (n+1));
	pnf[0] = 1;
	for(uint64_t i=0; i<n; i++){
		pnf[i+1] = (pnf[i] * (i+1)) % p;
	}
	ipnf[n] = powmod(pnf[n], p-2, p);
	for(uint64_t i=n; i>0; i--){
		ipnf[i-1] = (ipnf[i] * i) % p;
	}
}

uint64_t cmod(uint64_t n, uint64_t m, uint64_t p)
{
    if(n<m){
        return 0;
    }
	return (pnf[n] * ipnf[n-m]) % p * ipnf[m] % p;
}

int64_t extGCD(int64_t a, int64_t b, int64_t *x, int64_t *y) {
    if (b == 0) {
        *x = 1;
        *y = 0;
        return a;
    }
    int64_t d = extGCD(b, a%b, y, x);
    (*y) -= a/b * (*x);
    return d;
}

uint64_t invmod(uint64_t x, uint64_t p)
{
	int64_t r, s;
	if(extGCD(x, p, &r, &s)!=1){
		printf("ERR\n");
		abort();
	};
	return (r + p) % p;
}

int comp(const void *lhs, const void *rhs)
{
    return *(int*)lhs - *(int*)rhs;
}

int main()
{
    int N, K, *A;
    scanf("%d%d", &N, &K);

    
    A = malloc(sizeof(int) * N);
    uint64_t P = 1000000007;
    fmod_init(N, P);

    for(int ni=0; ni<N; ni++){
        scanf("%d", A+ni);
    }

    qsort(A, N, sizeof(int), comp);

    uint64_t res = 0;
    for(int ni=0; ni<N; ni++){
        res += (P+A[ni]) % P * cmod(ni, K-1, P) % P;
        res += P - (P+A[ni]) % P * cmod(N-ni-1, K-1, P) % P;
        res %= P;
    }

    printf("%"PRIu64"\n", res);
    return 0;
}


Measured memory_bytes: 2556
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;

int gcd(int x, int y){
  if(x%y) return gcd(y, x%y);
  return y;
}

int lcm(int x, int y){
  return x*y/gcd(x, y);
}

int N, M, A[1024];

int main(){
  memset(A, 0, sizeof(A));
  queue<int> q;
  cin >> N >> M;
  for(int i=0;i<N;i++){
    int x; cin >> x;
    q.push(x);
  }

  int res = 0;
  int l = lcm(N, M);
  for(int i=0;i<l/M;i++){
    int maxr = 0, minr = 1<<20;
    for(int j=0;j<M;j++){
      int p = q.front(); q.pop();
      maxr = max(maxr, p);
      minr = min(minr, p);
      q.push(p);
    }
    res += maxr - minr;
  }

  cout << res << endl;
  return 0;
}

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

typedef long long ll;
using Graph = vector<vector<int>>;

int ans[200050];

void dfs(const Graph &G, int v, int p=-1){
    for(auto nv : G[v]){
        if(nv==p) continue;
        ans[nv] += ans[v];
        dfs(G,nv,v);
    }
}

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

    int n,q;
    cin >> n >> q;
    Graph G(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    memset(ans,0,sizeof(ans));
    for(int i=0;i<q;i++){
        int p,x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    int root = 0;
    dfs(G,root);
    for(int i=0;i<n;i++) cout << ans[i] << ' ';
    cout << endl;
    return 0;
}

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

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

using namespace std;

const int MOD = 10000;
int dp[2][510][2][3][10]; // dp[桁][%M][値未満か][形状][１つ前] := 総数%MOD
// 形状 0 -> V, 1 -> A, 2 -> malicious end point

int compute(string N,int M){

  rep(j,M)rep(k,2)rep(m,3)rep(l,10) dp[1][j][k][m][l] = 0;
  rep(i,N[0]-'0') dp[1][i%M][1][2][i] = 1;
  dp[1][(N[0]-'0')%M][0][2][N[0]-'0'] = 1;

  int len = N.size();

  REP(i,1,len){ // 桁
    int phase = i & 1;
    rep(j,M)rep(k,2)rep(l,3)rep(m,10) dp[!phase][j][k][l][m] = 0;
    rep(j,10){  // 今みてる値
      rep(k,10){// 次の値
        if( j == 0 ) ( dp[!phase][k%M][1][2][k] += 1 ) %= MOD;

        if( j == k ) continue;

        int state = -1;
        if( j > k ) state = 0;
        else        state = 1;

        rep(l,2){
          bool lt = l | ( N[i]-'0' > k );
          if( !lt && N[i]-'0' < k ) continue;
          rep(m,M) ( dp[!phase][(m*10+k)%M][lt][state&1][k] += ( dp[phase][m][l][(state+1)&1][j] + (j?dp[phase][m][l][2][j]:0) ) ) %= MOD;
        }
      }
    }
  }


  int ret = 0;
  rep(i,2)rep(j,3)rep(k,10) ( ret += dp[len&1][0][i][j][k] ) %= MOD;
  return ret;
}

string minus_one(string s){
  reverse(s.begin(),s.end());
  rep(i,s.size()){
    if( s[i] != '0' ){
      s[i] = (char)((s[i]-'0'-1)+'0');
      reverse(s.begin(),s.end());
      if( s.size() >= 2 && i == (int)s.size()-1 ) s = s.substr(1);
      return s;
    }
    s[i] = '9';
  }
  return "@";
}

int main(){
  string A,B;
  int M;
  while(cin>>A >> B>>M) cout << ( compute(B,M) - compute(minus_one(A),M) + MOD ) % MOD << endl;
  return 0;
}

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

int main() {
	int n, d; scanf("%d%d", &n, &d);
	int sum = 0;
	rep(i, n) {
		int p; scanf("%d", &p);
		if (p > d)sum += p - d;
	}
	if (sum == 0)puts("kusoge");
	else printf("%d\n", sum);
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int H, W; 
vector<vector<char>> S(110, vector<char>(110));
vector<vector<int>> dp(110, vector<int>(110,1e8));

int main(){
    cin >> H >> W;
    rep(i,H) rep(j,W) cin >> S[i][j];

    dp[0][0] = (S[0][0] == '#');

    rep(i, H){
        rep(j, W){
            if(S[i][j] != '#' && S[i+1][j] == '#'){
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]+1);
            } else {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            }

            if(S[i][j] != '#' && S[i][j+1] == '#'){
                dp[i][j+1] = min(dp[i][j+1], dp[i][j]+1);
            } else {
                dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
            }
        }
    }

    cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jul 25 22:14:29 JST 2020
 **/

template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }

signed main() {
    int n;
    std::cin >> n;
    int x[n], y[n];
    Int p[n];
    REP(i, n) std::cin >> x[i] >> y[i] >> p[i];
    std::vector<int> x_ord(n), y_ord(n);
    std::iota(ALL(x_ord), 0), std::sort(ALL(x_ord), [&](int i, int j) { return x[i] < x[j]; });
    std::iota(ALL(y_ord), 0), std::sort(ALL(y_ord), [&](int i, int j) { return y[i] < y[j]; });
    int min_dist[n], orig_dist[n];
    REP(i, n) orig_dist[i] = std::min(std::abs(x[i]), std::abs(y[i]));
    std::vector<Int> ans(n + 1, 1e18);
    REP(S, 1 << n) {
        Int cnt = __builtin_popcount(S);
        // Sの部分集合の列挙
        for (int T = S;; T = (T - 1) & S) {
            // 操作
            REP(i, n) min_dist[i] = orig_dist[i];
            int l = 1e9;
            REP(k, n) {
                int i = x_ord[k];
                if (T >> i & 1) l = x[i];
                chmin(min_dist[i], std::abs(x[i] - l));
            }
            l = 1e9;
            for (int k = n - 1; k >= 0; k--) {
                int i = x_ord[k];
                if (T >> i & 1) l = x[i];
                chmin(min_dist[i], std::abs(x[i] - l));
            }
            l = 1e9;
            REP(k, n) {
                int i = y_ord[k];
                if ((S ^ T) >> i & 1) l = y[i];
                chmin(min_dist[i], std::abs(y[i] - l));
            }
            l = 1e9;
            for (int k = n - 1; k >= 0; k--) {
                int i = y_ord[k];
                if ((S ^ T) >> i & 1) l = y[i];
                chmin(min_dist[i], std::abs(y[i] - l));
            }
            Int acc = 0;
            REP(i, n) acc += p[i] * min_dist[i];
            chmin(ans[cnt], acc);
            if (T == 0) break;
        }
    }
    for (Int z : ans) std::cout << z << "\n";
}


Measured memory_bytes: 3604
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline

def diff(node_a, node_b):
    root_a, cost_a = node_a.root(0)
    root_b, cost_b = node_b.root(0)
    if root_a == root_b:
        return True, cost_a - cost_b
    else:
        return False, cost_a - cost_b

def merge(node_a, node_b, weight):
    root_a, cost_a = node_a.root(0)
    root_b, cost_b = node_b.root(0)
    root_a.weight = weight + cost_b - cost_a
    root_a.is_root = False
    root_a.parent = root_b

class Node:
    def __init__(self):
        self.is_root = True
        self.parent = None
        self.weight = 0
    
    def root(self, cost):
        if self.is_root:
            return self, cost
        root, max_ = self.parent.root(cost + self.weight)
        self.parent = root
        self.weight = max_ - cost
        return root, max_

def main():
    n, q = map(int, input().split())
    
    nodes = [Node() for i in range(n)]

    for i in range(q):
        query = list(map(int, input().split()))
        if query[0] == 0:
            x, y, z = query[1:]
            if not diff(nodes[x], nodes[y])[0]:
                merge(nodes[x], nodes[y], z)
        else:
            x, y = query[1:]
            jud, ans = diff(nodes[x], nodes[y])
            if jud:
                print(ans)
            else:
                print("?")

if __name__ == "__main__":
    main()


Measured memory_bytes: 65128