akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
typedef long long ll;


int main(){
  string S;
  cin >> S;
  ll cntW = 0;
  ll ans = 0;
  for(int i = S.size()-1; i >= 0; i--){
    if(S[i] == 'W') cntW ++;
    else{
      ans += cntW;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
using namespace std;
const LL INF = 1e9;
const int MAXN = 1e5+5;
LL a[MAXN], b[MAXN];
int cnt;
bool check(LL x) {
    int sum1=0, sum2=0, sum3=0;
    while(x) {
        if(x%10==3) sum1++;
        if(x%10==5) sum2++;
        if(x%10==7) sum3++;
        x/=10;
    }
    //cout<<sum1<<" "<<sum2<<" "<<sum3<<endl;
    return (sum1&&sum2&&sum3);
}
void dfs(LL x) {
    if(x > INF) return ;
    //if(!check(x)) return;
    a[cnt] = x;
    cnt++;
    dfs(x*10+3);
    dfs(x*10+5);
    dfs(x*10+7);
}
int main() {
    dfs(0);
    sort(a, a+cnt);
    int sum = 0;
    for(int i=0; i<cnt; i++) {
        if(check(a[i])) b[sum++] = a[i];
    }
    LL n; cin>>n;
    cout<<upper_bound(b, b+sum, n)-b<<endl;
    return 0;
}


Measured memory_bytes: 640
/*
 * atcoder/abc142_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
vector<pair<ll, ll> > prime_factorize(ll n) {
  vector<pair<ll, ll> > res;
  for (ll p = 2; p * p <= n; ++p) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) { ++num; n /= p; }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

ll a, b;
void solve() {
  cin >> a >> b;
  auto v1 = prime_factorize(a);
  auto v2 = prime_factorize(b);
  int count = 0; int i_a = 0; int i_b = 0;
  while (i_a < v1.size() and i_b < v2.size()) {
    if (v1[i_a].first == v2[i_b].first) {
      count++;i_a++;i_b++;
      continue;
    }

    if (v1[i_a].first < v2[i_b].first) i_a++;
    else i_b++;
  }

  cout << count + 1 << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

def erase(x, y):
    c[y][x] = '0'
    for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)):
        nx, ny = x + dx, y + dy
        if 0 <= nx <= w -1 and 0 <= ny <= h - 1:
            if c[ny][nx] == '1':
                erase(nx, ny)

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break
    c = [[i for i in input().split()] for _ in range(h)]
    ans = 0
    for y in range(h):
        for x in range(w):
            if c[y][x] == '1':
                ans += 1
                erase(x, y)
    print(ans)

Measured memory_bytes: 9480
import math
a, b, C = map(int, input().split())
C = C / 180 * math.pi
S = a * b * math.sin(C) / 2
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
print('{0}'.format(S))
print('{0}'.format(a + b + c))
print('{0}'.format(2 * S / a))

Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
typedef pair<int,int> P;
int N,M,Q,ans;
vector<P> g,t,G[MAX_N];
int d[MAX_N],C[MAX_N];

void dfs(int pos){
  ans++;
  for(int i=0;i<(int)G[pos].size();i++){
    P &e=G[pos][i];
    if(e.second==1){
      e.second=0;
      C[e.first]--;
      if(C[e.first]==0)dfs(e.first);
    }
  }
}

void bfs(){
  memset(d,-1,sizeof(d));
  queue<int> Q;
  Q.push(0);
  d[0]=0;
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    for(int i=0;i<(int)G[pos].size();i++){
      int to=G[pos][i].first;
      if(d[to]==-1){
        d[to]=d[pos]+1;
        Q.push(to);
        G[pos][i].second=1;
        C[to]++;
      }else if(d[pos]+1==d[to]){
        G[pos][i].second=1;
        C[to]++;
      }
    }
  }
}

int main(){
  scanf("%d %d %d",&N,&M,&Q);
  g.resize(M);t.resize(M);
  for(int i=0;i<M;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--,b--;
    g[i]=P(a,b);
    t[i]=P(G[a].size(),G[b].size());
    G[a].push_back(P(b,0));
    G[b].push_back(P(a,0));
  }
  bfs();
  
  C[0]=1e9;
  while(Q--){
    int id;
    scanf("%d",&id);
    id--;
    int a=g[id].first;
    int b=g[id].second;
    int A=t[id].first;
    int B=t[id].second;
    if(G[a][A].second==1){
      G[a][A].second=0;
      C[b]--;
      if(C[b]==0)dfs(b);
    }
    if(G[b][B].second==1){
      G[b][B].second=0;
      C[a]--;
      if(C[a]==0)dfs(a);
    }
    printf("%d\n",ans);
  }
  return 0;
}

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

using namespace std;

int solve(string s1, string s2){
    int L[s1.size()+1][s2.size()+1];
    for(int i=0;i<=s1.size();i++){
        for(int j=0;j<=s2.size();j++){
            if(i<=0 || j<=0){
                L[i][j]=0;
            }
            else if(s1[i-1] == s2[j-1]){
                L[i][j] = 1 + L[i-1][j-1];
            }
            else{
                L[i][j] = max(L[i][j-1],L[i-1][j]);
            }
        }
    }
    return L[s1.size()][s2.size()];
}

int main(){
    int n ; cin >> n;
    for(int i=0;i<n;i++){
        string s1,s2; cin>> s1 >> s2;
        cout << solve(s1,s2) << endl;
    }
}

Measured memory_bytes: 5128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  ll a_cnt = 0, ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.substr(i, 2) == "BC") {
      ans += a_cnt;
      i++;
    } else if (s[i] == 'A')
      a_cnt++;
    else
      a_cnt = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main (void) {
	for (;;) {
		double x, h;
		
		cin >> x;
		cin >> h;
		
		if (x == 0 && h == 0) {
			break;
		}
		
		double S = 0.0;
		S += pow(x, 2);
		S += 4 * (x * sqrt(pow(x / 2, 2) + pow(h, 2)) / 2);
		
		printf("%lf\n", S);
	}
	
	return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env ruby



$visited = []
$pre_vertex = []


def min a,b
  if a<b then return a else b end
end

def init_dfs v,e
  $visited = Array.new(v,false)
  $pre_vertex = Array.new(v,false)
end

#b -> e ??§edges
def dfs b,e,es
  es[b].each_with_index do |c,v|
    if !$visited[v] and c>0 then
      $visited[v] = true
      $pre_vertex[v] = b
      if v==e then
        return
      end
      dfs(v,e,es)
    end
  end
end


def back_trace b,e,es
  flow =[]
  min_c = 10e8

  to = e
  from = $pre_vertex[e]
  flow=[[from,to]]+flow
  min_c = min(min_c,es[from][to])

  while from != b
    to = from
    from = $pre_vertex[from]
    flow=[[from,to]]+flow
    min_c = min(min_c,es[from][to])
  end
  return flow,min_c
end



#v_size,e_size = gets.chomp.split(/ /).map{|i| i.to_i}

x_size,y_size,e_size = gets.chomp.split(/ /).map{|i| i.to_i}

edges = Array.new(x_size+y_size+2).map{ Array.new(x_size+y_size+2,0)}


e_size.times do
  u,v = gets.chomp.split(/ /).map{|i| i.to_i}
  edges[u][x_size+v] = 1
end
x_size.times do |i|
  edges[x_size+y_size][i] = 1
end
y_size.times do |i|
  edges[x_size+i][x_size+y_size+1] = 1
end


#edges.each do |i| p i end
@ans = 0
v_size = x_size+y_size+2
loop do
  init_dfs(v_size,e_size)
  dfs(x_size+y_size,x_size+y_size+1,edges)
  if $visited[v_size-1] then
    f,min_c = back_trace(x_size+y_size,x_size+y_size+1,edges)
    f.each do |i|
      edges[i[0]][i[1]]=0
      edges[i[1]][i[0]]=1
    end
    @ans = @ans+ min_c
  else
    p @ans
    break
  end
end

Measured memory_bytes: 12460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		solver.readB(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	int M;
	int C;
	int[] B;
	int ans;

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		M = Integer.parseInt(strArr[1]);
		C = Integer.parseInt(strArr[2]);
		B = new int[M];
		ans = 0;
	}

	public void readB(String str) {
		String[] strArr = str.split(" ");
		for (int i = 0; i < M; i++)
			B[i] = Integer.parseInt(strArr[i]);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		String[] strArr = str.split(" ");
		int[] a = new int[M];
		for (int i = 0; i < M; i++)
			a[i] = Integer.parseInt(strArr[i]);

		int v = C;
		for (int i = 0; i < M; i++) {
			v += a[i] * B[i];
		}
		if (v > 0)
			ans++;

		cnt++;
	}

	public void solve() {
		System.out.println(ans);
	}
}


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

void solve() {
    int A, B, C, D;
    scanf("%d %d %d %d", &A, &B, &C, &D);
    int idx = 0;
    while (1) {
        if (idx % 2) {
            A -= D;
            if (A <= 0)
                break;
        } else {
            C -= B;
            if (C <= 0)
                break;
        }
        idx = (idx + 1) % 2;
    }
    if (idx) puts("No");
    else puts("Yes");
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    int  a[5];
    int sum=0;
    int mi=10000;
    int mii=-1;
    for(int i=0;i<5;i++){
        cin >> a[i];
        if(a[i]%10<mi && a[i]%10!=0){
            mi=a[i]%10;
            mii=i;
        }
    }
    for(int i=0;i<5;i++){
        if(a[i]%10==0){
            sum += a[i];
        }else{
            if(i==mii){
                sum += a[i];
            }else{
                sum += a[i]+10-a[i]%10;
            }
        }
    }
    cout << sum << endl;
    return 0;
}


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

typedef signed long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    ((a * 100 + b * 10 + c) % 4 == 0) ? cout << "YES\n": cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <unistd.h>
#include <stdio.h>
#include <algorithm>

typedef long long ll;

int mat[3000][3000];

ll dp0[3000];
ll dp1[3000];
ll dp[4];

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd();
        int c = rd();
        int v = rd();
        mat[r - 1][c - 1] = v;
    }
    for (int y = 0; y < rr; y++) {
        dp[0] = dp[1] = dp[2] = dp[3] = 0;
        for (int x = 0; x < cc; x++) {
            dp[0] = std::max(dp[0], dp0[x]);
            int v = mat[y][x];
            for (int c = 3; c > 0; c--) {
                dp[c] = std::max(dp[c], dp[c - 1] + v);
            }
            dp1[x] = std::max(std::max(dp[0], dp[1]), std::max(dp[2], dp[3]));
        }
        for (int x = 0; x < cc; x++) {
            dp0[x] = dp1[x];
        }
    }
    printf("%lld\n", dp1[cc - 1]);
    return 0;
}

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

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

	if(a==b){
		cout << c << endl;
	}
	else if (a == c) {
		cout << b << endl;
	}
	else {
		cout << a << endl;
	}


	return 0;
}

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

int main() {
  int a, b, c, cnt;
  while (cin >> a >> b) {
    c = a + b;
    cnt = 0;
    while (c > 0) {
      cnt ++;
      c /= 10;
    }
    cout << cnt << endl;
  }
}



Measured memory_bytes: 3092
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
ll prime[1000001];
ll length = 0;
void insert(ll p) { prime[length] = p; length++; return; }
int main() {
	insert(2);
	for (ll i = 3; i < 1000000; i += 2) {
		for (ll j = 0; j < length; j++)
			if (i%prime[j] == 0)goto cont;
			else if (prime[j] > sqrt(i))break;
			insert(i);
		cont:;
	}
	ll n; while (cin >> n) {
		if (n == 0)break;
		ll sum = 0;
		for (ll i = 0; i < n; i++)
			sum += prime[i];
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3668
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
long long modpow(long long a, long long n) {//a^n(MOD)を求める
    long long res = 1;
    while (n > 0) {
         if (n & 1) res = res * a % MOD;
         a= a * a % MOD;//次の準備
         n >>= 1;
      }
 return res;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    char c;
    cin>>c;
    char d=c+1;
    cout<<d<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<unordered_map>
#include<utility>
#include<vector>

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;

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

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

int main(){
    char c;
    std::cin >> c;

    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
        std::cout << "vowel" << std::endl;
    }else{
        std::cout << "consonant" << std::endl;
    }
}

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

using namespace std;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	
	int n, a;
	cin >> n;
	cin >> a;

	int g = n - 500 * (n / 500);

	if (g <= a)cout << "Yes\n"; else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  int X=0;
  int Y=0;
  vector<int>vec(3);
  bool F=false;
  cin>>N>>M;
  for (X=0;X<=N;X++){
    for (Y=0;Y<=N;Y++){
      if (X+Y<=N){
        int Z=N-X-Y;
        if (X+Y+Z==N && X*10000+Y*5000+Z*1000==M){
          vec={X,Y,Z};
          F=true;
        }
      }
    }
  }
  if (F==true){
    cout<<vec.at(0)<<" "<<vec.at(1)<<" "<<vec.at(2)<<endl;
  }
  else{
    cout<<"-1"<<" "<<"-1"<<" "<<"-1"<<endl;
  }
}

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

int main(){
  int n;
  cin >> n;
  int i;

  for(i = 0;i*4 <= n;i++){
    if((n - i*4) % 7 == 0){
      cout << "Yes" << endl;
      break;
    }
  }

  if(i*4 > n){
    cout << "No" << endl;
  }

  return 0;

}

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

int h[101];

int main(){
	int n,i,max=0,br=0;
	cin >> n;
	for(i=0;i<n;i++)
	{
		cin >> h[i];
		if(h[i]>=max){
			br++;
			max=h[i];
		}
	}
	cout << br;
		
	
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <random>

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

using namespace std;

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

ll evalNow(vector<vector<int>>& s, vector<int>& c, vector<int>& t, int d, vector<int> last) {
    ll ans = 0;
    ans += s[d][t[d]-1];
    last[t[d]-1] = d+1;
    rep(j, 26) {
        ans -= c[j]*(d+1 - last[j]);
    }
    return ans;
}

ll evalAll(vector<vector<int>>& s, vector<int>& c, vector<int>& t, int d) {
    ll ans = 0;
    vector<int> last(26,0);
    rep(i, d) {
        ans += s[i][t[i]-1];
        last[t[i]-1] = i+1;
        rep(j, 26) {
            ans -= c[j]*(i+1 - last[j]);
        }
    }
    return ans;
}

int main(){
    int d; cin >> d;
    vector<int> c(26);
    rep(i, 26) {
        cin >> c[i];
    }
    vector<vector<int>> s(d, vector<int>(26,0));
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j];
        }
    }
    vector<int> t(d);
    ll ans = 0;
    vector<int> last(26,0);

    rep(i, d) {
        ll tmpmax = - (1LL << 60);
        ll candidate = -1;
        rep(j, 26) {
            t[i] = j+1;
            if(tmpmax < evalNow(s,c,t,i,last)) {
                tmpmax = evalNow(s,c,t,i,last);
                candidate = j+1;
            }
        }
        last[t[i]-1] = i + 1;
        t[i] = candidate;
    }

    std::random_device rnd;     // 非決定的な乱数生成器を生成
    std::mt19937 mt(rnd());     //  メルセンヌ・ツイスタの32ビット版、引数は初期シード値
    std::uniform_int_distribution<> rand100(0, d);

    //この時点でtはgreedy
    rep(x, 1000) {
        ll candidate;
        int i = rand100(mt);
        ll tmpmax = evalAll(s,c,t,d);
        rep(j, 26) {
            t[i] = j+1;
            ll tmp = evalAll(s,c,t,d);
            if(tmpmax < tmp) {
                tmpmax = tmp;
                candidate = j+1;
            }
        }
        t[i] = candidate;
    }



    rep(i, d) {
        cout << t[i] << endl;
    }
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>
#include <bitset>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9

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

const int INF = 0x7fffffff;
const int maxn = 100;
char s[maxn];
int len;

int main() {
#ifdef __AiR_H
    freopen("B.in", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%s", s); len = strlen(s);
    if (len < 4) { printf("No\n"); }
    else if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


Measured memory_bytes: 256
class Unionfind():  # Unionfind
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):  # 根のリスト
        return [i for i, x in enumerate(self.parents) if x < 0]


n, m = map(int, input().split())
xyz = sorted([list(map(int, input().split())) for _ in range(m)])

uf = Unionfind(n)
for x, y, z in xyz:
    uf.union(x - 1, y - 1)
print(len(uf.roots()))


Measured memory_bytes: 81112
funcCollatz :: Int -> Int
funcCollatz n = case n `mod` 2 of 0 -> n `div` 2
                                  1 -> 3 * n + 1

collatz :: [Int] -> [Int]
collatz (x:xs) = [funcCollatz x] ++ (x:xs)

loop :: Int -> [Int] -> Int
loop k (x:xs) = case dropWhile (/=(funcCollatz x)) xs of []        -> loop (k+1) (collatz (x:xs))
                                                         otherwise -> k+1

main :: IO()
main = getLine >>= \s -> print $ loop 1 [(read s :: Int)]

Measured memory_bytes: 508
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let _n: usize = read();
    let m: usize = read();
    let x: usize = read();
    let mut left = 0;
    let mut right = 0;
    for _ in 0..m {
        let pos: usize = read();
        if pos < x {
            left += 1;
        } else {
            right += 1;
        }
    }
    println!("{}", std::cmp::min(left, right));
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  float a;
  if(n%2==0){
    a=1.0/2.0;

  }else{
      float b,c;
      b=n;
      c=(n+1)/2.0;
      a=c/b;
  }
  printf("%lf",a);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int a, b, c, d, e;
    scanf("%d %d %d",&a,&b,&c);
    d = a + b;
    if(c > d)
    {
        e= d + 1 + b ;
        printf("%d", e);
    }
    else
    {
        e = b + c;
        printf("%d", e);
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5+10;
int a[N];
int main(){
    int n, k;
    scanf("%d%d",&n,&k);
    set<int> st;
    for(int i = 0; i < n; i ++) scanf("%d",&a[i]),st.insert(a[i]);
    sort(a,a+n);
    if(n == 1){
        if(a[0] == k) cout << "POSSIBLE\n";
        else cout << "IMPOSSIBLE\n";
        return 0;
    }
    if(a[n-1] < k){
        cout << "IMPOSSIBLE\n";
    }else{
        int ans = __gcd(a[n-2],a[n-1]);
        for(int i = 0; i < n-1; i ++){
            int ans1 = __gcd(a[i],a[i+1]);
            if(ans1 < ans) ans = ans1;
        }
        bool flag = true;
        for(int i = 0; i < n; i ++) {
            if(a[i]%ans != 0){
                flag = false;
                break;
            }
        }
        //printf("%d %d\n",flag,ans);
        if(!flag){
            cout << "POSSIBLE\n";
        }else{
            if(__gcd(ans,k) == ans){
                cout << "POSSIBLE\n";
            } else cout << "IMPOSSIBLE\n";
        }
    }
    return 0;
}


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

using namespace std;

int main(){
    int n ;

    cin >> n;

    int b;
    vector <int> a(n);


    for(int i = 0 ; i < n; i++){
        cin >> b;
        a[b-1] = i+1;
    }

    for(int i = 0; i < n; i++){
        cout << a[i] << " ";
    }

    cout << endl;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <cstring>
#include <ctype.h>
#include<stdlib.h>

#define fiin        freopen("input.txt", "r", stdin); 
#define fiout       freopen("output.txt", "w", stdout);
#define pi          2 * acos(0.00)
#define ll          long long
#define ull         unsigned long long
#define fastio      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl          '\n'
#define nll         '\0'
#define pb          push_back
#define bdyptb      return 0;
#define testcase    ll t,tt; cin>>tt; for(t=1;t<=tt;t++)
   
#define mx 1000007

using namespace std;

int main()
{
    fastio;
    
    string s,t;
    cin>>s;
    cin>>t;
    int x=0;
    for(int i=0; i<s.size(); i++)
    x+=(s[i]!=t[i]);
    cout<<x<<nl;
    bdyptb;
}

Measured memory_bytes: 3724
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int h, w;
    
    while (1) {
        scanf("%d %d", &h, &w);
        
        if (h == 0 && w == 0) {
            break;
        }
        
        for(int i=0; i<h; i++) {
            for (int j=0; j<w; j++) {
                if ((i+j)%2 == 0) {
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2100
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    @lru_cache(maxsize=None)
    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, X):
    M = Mod(10**9+7)
    ne = 1
    for i in range(2, N):
        ne = M.mul(i, ne)
    ans = 0
    p = 0
    for i in range(N-1):
        d = X[i+1] - X[i]
        p = M.add(p, M.div(ne, i+1))
        ans = M.add(ans, M.mul(d, p))
    return ans

def main():
    N = read_int()
    X = read_int_n()
    print(slv(N, X))

if __name__ == '__main__':
    main()


Measured memory_bytes: 91028
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;
int main() {
	string s;
	cin >> s >> K;
	vector<vector<int>>ch(26);
	for (int i = 0; i < s.size(); i++) {
		ch[s[i] - 'a'].push_back(i);
	}
	string ANS;
	for (int i = 0; i < 26; i++) {
		if (ch[i].size() == 0)continue;
		set<string>set;
		string x = { char(i + 'a') };
		set.insert(x);
		for (int k : ch[i]) {
			for (int j = 2; j < 6; j++) {
				if (k + j > s.size())continue;
				string tmp = s.substr(k, j);
				if (set.count(tmp) == 0) {
					set.insert(tmp);
				}
			}
		}
		if (set.size() < K)K -= set.size();
		else {
			auto itr = set.begin();
			for (int i = 0; i < K - 1; i++)itr++;
			ANS = *itr;
			break;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 384
N = int(input())
D = [0]*N
for i in range(N):
    D[i] = list(map(int,input().split()))
check = 0
answer = 'No'
for i in range(N):
    if D[i][0]==D[i][1]:
        check += 1
    else:
        check = 0
    
    if check == 3:
        answer = 'Yes'
print(answer)

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll x,a,b,n;
  cin>>x>>a>>b>>n;
  vector<string> s(n);
  cin>>s;

  for(auto q:s){
    if(q[0]=='n')x=max(x+a,0ll);
    else if(q[0]=='t')x=max(x+b,0ll);
    else x=0;
  }
  cout<<(x)<<endl;

}



Measured memory_bytes: 3252
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    vector<int>l;
    for (int i = 0; i < N; i++) {
        int count = 0;
        for (int j = 0; i + j < N; j++) {
            if (S[i] != S[i + j])break;
            else count++;
        }
        if(S[i]=='0')l.push_back(-count);
        else l.push_back(+count);
        i += count - 1;
    }

    vector<int>Csum(l.size(),0);
    Csum[0] = abs(l[0]);
    for (int i = 1; i < Csum.size(); i++) {
        Csum[i] = Csum[i-1]+abs(l[i]);
    }

    
    int ans = 0;
   
    for (int i = 0; i < l.size(); i++) {
        int width,x;
        if (l[i] > 0&&i==0) {
            width = min(2*K, (int)l.size()-1 - i);
            x = Csum[width];

        }
        else if (l[i] < 0&&i==0) {
            width = min(2*K - 1, (int)l.size()-1 - i);
            x = Csum[width];
        }
        else if (l[i] > 0) {
            width = min(2*K, (int)l.size()-1 - i);
            x = Csum[i + width] - Csum[i-1];
        }
        else if (l[i] < 0) {
            width = min(2*K - 1, (int)l.size()-1 - i);
            x = Csum[i + width] - Csum[i-1];
        }
        ans = max(ans, x);
    }

    cout << ans << endl;
    




    return 0;
}

Measured memory_bytes: 1272
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		Arrays.setAll(a, i -> sc.nextInt());
		
		LinkedList<Integer> list = new LinkedList<>();
		list.add(a[0]);
		
		int lr = 0;
		for (int i = 1; i < n; i++) {
			if (lr == 0) {
				list.addFirst(a[i]);
			} else {
				list.add(a[i]);
			}
			lr ^= 1;
		}
		
		while (!list.isEmpty()) {
			int num;
			if (lr == 1)
				num = list.poll();
			else
				num = list.pollLast();
			System.out.print(num + " ");
		}
		System.out.println();
		
		sc.close();
	}
}




Measured memory_bytes: 60676
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long x)
{
  cout << (x ^ 1) << endl;
}

int main()
{
  cout << setprecision(10);
  long long x;
  scanf("%lld", &x);
  solve(x);
  return 0;
}


Measured memory_bytes: 3680
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int w;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		w = sc.nextInt();
		if(w == -1)return false;
		return true;
	}
	static void solve(){
		int cost = 0;
		if( w <= 10){
			cost = 1150;
		}else if( w >= 10 && w <= 20){
			cost = 1150 + 125*(w-10);
		}else if( w >= 20 && w <= 30){
			cost = 1150 + 1250 + 140*(w-20);
		}else{
			cost = 1150 + 1250 + 1400 + 160*(w-30);
		}
		//System.out.println("cost = " + cost);
		System.out.println( 4280 - cost );
	}

}

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

using namespace std;

int main(){
    long int X,Y;
    cin >> X >> Y;
    for(int t=0;t<=X;t++){
        for(int k=0;k<=X;k++){
            if(t+k==X&&2*t+4*k==Y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int       long long int
#define vi        vector<int>
#define vii       vector<pii>
#define pii       pair<int, int>
#define mii       map<int, int>
#define pb        push_back
#define rev(v)    reverse(v.begin(), v.end())
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define endl      '\n'
#define F         first
#define S         second
#define PI        3.14159265359
#define MAXN      3001

const int mod = 1e9 + 7;

int32_t main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);

   string s, t;
   cin >> s >> t;

   int ls = s.length();
   int lt = t.length();
   int dp[ls + 1][lt + 1];

   for (int i = 0; i <= ls; ++i)
   {
      for (int j = 0; j <= lt; ++j)
      {
         if (i == 0 or j == 0)
            dp[i][j] = 0;
         else
         {
            if (s[i - 1] == t[j - 1])
            {
               dp[i][j] = max(1 + dp[i - 1][j - 1], max(dp[i - 1][j], dp[i][j - 1]));
            }
            else
            {
               dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
         }
      }
   }

   string lcs = "";
   int i = ls, j = lt;
   while (i > 0 and j > 0)
   {
      if (dp[i][j] != dp[i - 1][j] and dp[i][j] != dp[i][j - 1])
      {
         lcs = s[i - 1] + lcs;
         --i, --j;
      }
      else
      {
         if (dp[i - 1][j] >= dp[i][j - 1])
            --i;
         else
            --j;
      }
   }
   cout << lcs << endl;
   return 0;
}

Measured memory_bytes: 70656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            if (a + b + c >= 22)
                out.print("bust");
            else
                out.print("win");
        }

    }
}



Measured memory_bytes: 23636
#include <cstdio>
#include <algorithm>
using namespace std;
int dp[310][310];
int cost[310][2];
int h, w;
char c[310][310];
const int inf = 1 << 29;
int dh[310][310];
int go(int l, int r) {
	for (int i = 0; i <= h; i++) {
		for (int j = 0; j <= h; j++) {
			dp[i][j] = inf;
			dh[i][j] = 0;
		}
	}
	for (int i = 0; i <= h; i++) {
		dp[i][0] = 0;
	}
	for (int i = 0; i <= h; i++) {
		dp[0][i] = 0;
	}
	for (int i = 0; i < 310; i++) {
		for (int j = 0; j < 310; j++) {
			dh[i][j] = 0;
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < h; j++) {
			dh[i+1][j+1] = dh[i][j] + (c[i][l] == c[j][r]);
		}
	}
	for (int i = 0; i <= h; i++) {
		for (int j = 0; j <= h; j++) {
			if (i < h) {
				dp[i+1][j] = min(dp[i+1][j], dp[i][j] + dh[i+1][j]);
			}
			if (j < h) {
				dp[i][j+1] = min(dp[i][j+1], dp[i][j] + dh[i][j+1]);
			}
		}
	}
	return dp[h][h];
}
int main() {
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; i++) {
		scanf("%s", c[i]);
	}
	int ans = 0;
	for (int i = 0; i < w; i++) {
		for (int dx = 0; dx < 2; dx++) {
			int ni = i + (dx ? 1 : -1);
			if (ni < 0 || ni >= w) continue;
			ans += go(i, ni);
		}
	}
	printf("%d\n", ans / 2);
	return 0;
}


Measured memory_bytes: 1152
/*---> praveenojha33 <---> 03 September 2019 <--- > 14:14:12 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=200005;
int n,q,val[N],ans[N];
vi adj[N];
bool vis[N];
void dfs(int u,int sum){
	sum+=val[u];
	ans[u]=sum;
	vis[u]=true;
	for(int v:adj[u]){
		if(!vis[v])
			dfs(v,sum);
	}
}
int32_t main(){__
	cin>>n>>q;
	int x,y;
	for(int i=0;i<n-1;i++)
		{
			cin>>x>>y;
			adj[x].push_back(y);
			adj[y].push_back(x);
		}
	for(int i=0;i<q;i++){
		cin>>x>>y;
		val[x]+=y;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<" ";
	cout<<"\n";
return 0;
}

Measured memory_bytes: 21632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

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

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

int main()
{
    IOS;
    ll h,w,k;
    cin>>h>>w>>k;
    string s[h];
    repf(i,0,h) cin>>s[i];
    ll ans=1e9;
    repf(i,0,(1<<h)-1)
    {
        ll c=__builtin_popcount(i);
        vector<ll> v[w];
        repf(j,0,w)
        {
            ll tmp=0;
            repf(l,0,h)
            {
                tmp+=(s[l][j]=='1');
                if((i>>l)&1)
                {
                    v[j].pb(tmp);
                    tmp=0;
                }
            }
            v[j].pb(tmp);
            for(auto l:v[j]) 
            {
                if(l>k) c=1e9;
            }
        }
        vector<ll> u(v[0].size(),0);
        repf(j,0,w)
        {
            bool f=false;
            repf(l,0,u.size()) 
            {
                f|=(u[l]+v[j][l])>k;
            }
            if(f)
            {
                repf(l,0,u.size()) u[l]=0;
                c++;
            }
            repf(l,0,u.size()) 
            {
                u[l]+=v[j][l];
            }
        }
        // cout<<i<<" "<<c<<endl;
        ans= min(ans,c);
    }
    cout<<ans<<endl;
}   

Measured memory_bytes: 500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)

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

    int N;
    cin >> N;
    vector<pair<int, int>> tasks;

    int a, b;
    rep(i, 0, N)
    {
        cin >> a >> b;
        tasks.emplace_back(b, a);
    }

    sort(tasks.begin(), tasks.end());
    int sum = 0;
    bool ans = true;
    for (auto c : tasks)
    {
        sum += c.second;
        if (sum > c.first)
        {
            ans = false;
        }
    }
    if (ans)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 5276
#include <iostream>

bool judge(int x, int y, int z);

int main()
{
    int data_num;
    std::cin >> data_num;

    int side1, side2, side3;
    while (data_num--) {
        std::cin >> side1 >> side2 >> side3;
        std::cout << (judge(side1, side2, side3)? "YES": "NO") << std::endl;
    }

    return 0;
}

int pow2(int x);

bool judge(int x, int y, int z)
{
    if (pow2(x) == pow2(y) + pow2(z)) {
        return true;
    } else if (pow2(y) == pow2(z) + pow2(x)) {
        return true;
    } else if (pow2(z) == pow2(x) + pow2(y)) {
        return true;
    } else {
        return false;
    }
}

int pow2(int x)
{
    return (x * x);
}

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

ll A,B,C,K;

int main()
{
  ll ans;

  cin >> A >> B >> C >> K;

  if (A>=K) {
    ans = K;
  } else if (A+B>=K) {
    ans = min(A, K);
  } else {
    C = K - (A+B);
    ans = A - C;
  }

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


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

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

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

const int N=10009;
int ar[N];
void pre()
{
	int i,j,k,n=10000,r;
	for(i=1; ; i++)
	{
		if(i*i>n) break;

		for(j=1; ; j++)
		{
			if(i*i + j*j>n) break;
			for(k=1; ; k++)
			{
				if(i*i + j*j + k*k>n) break;
                r=i*i + j*j + k*k + i*j + j*k + k*i;
                if(r<=n) ar[r]++;

			}
		}
	}

}
int main()
{
  //fastio; 
  pre();
  int n,i;
  scanf("%d",&n);
  for(i=1; i<=n; i++)
  {
  	printf("%d\n",ar[i]);
  }
  return 0;
}

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

using namespace std;

#define LL           long long
#define ULL          long long unsigned
#define LD           long double
#define ff              first
#define ss              second
#define FOR(i,n)     for(int i=0;i<n;i++)
#define FLR(i,n)     for(LL i=0;i<n;i++)
#define RFOR(i,n)    for(int i=n-1;i>=0;i--)
#define RFLR(i,n)    for(LL i=n-1;i>=0;i--)
#define rep(i,a,b)   for(int i=a;i<=b;i++)
#define repl(i,a,b)  for(LL i=a;i<=b;i++)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
#define all(a)       a.begin(),a.end()
#define ABS(x)       ((x)<0?-(x):(x))
#define NL           "\n"
#define pb           push_back
#define mk              make_pair
#define pi           acos(-1.0)
#define prec(n)      fixed << setprecision(n)
#define sq(a)          (a)*(a)
#define asi          cout<<"check"<<" ";
#define all_set(arr,val) memset(arr,val,sizeof(arr))

int main()
{
    fast;
    int i,j,k,n,gcd,x,m;
    cin>>n>>k;
    vector<int>vec;
    FOR(i,n){
        cin>>x;
        vec.pb(x);
    }
    sort(all(vec));
    gcd=vec[0];
    for(i=1;i<n;i++){
        gcd=__gcd(gcd,vec[i]);
    }
    if(k>vec[n-1]){
        cout<<"IMPOSSIBLE";
        return 0;
    }
    if(k%gcd==0){
        cout<<"POSSIBLE";
        return 0;
    }
    else cout<<"IMPOSSIBLE";
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int , int> pi;

void solve()
{
	double p1 = 3.1415;
	double n;
	cin>>n;
	n = 2*n*p1;
	printf("%.3lf", n);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	t = 1;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3796