akhauriyash/Code-Regression huggingface dataset:
// 物极必反

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 5e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 998244353;
const long long INF = 1e18 + 9;
const int SM = 3e3 + 5;
const int logN = 22, BL = 400;
const long double EPS = 1e-14;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n; cin >> n;

    long long k = log2(n) * 1ll;
    cout << (1 << k);

    return 0;
}


Measured memory_bytes: 3824
import math
"""
def distance(a,b):
    ans=0
    for (i,j) in zip(a,b):
        ans+=(i-j)**2
    return math.sqrt(ans)
"""
n,d=map(int,input().split())
x=[]
for j in range(n):
    tmp=list(map(int,input().split()))
    x.append(tmp)

count=0
for i in range(n-1):
    for j in range(i+1,n):
        ans=0
        for (a,b) in zip(x[i],x[j]):
            ans+=(a-b)**2
        if math.sqrt(ans).is_integer():
            count+=1

print(count)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
const ll INF=1e18;
const ll MOD=998244353;
const double pi=3.1415926;
ll n,m,imos[MAXN];
void solve()
{
    ll t=0,ans=0;
    for(ll i=1;i<=n;i++)
    {
        t+=imos[i];
        if(t==m)
        {
            ans++;
        }
    }
    printf("%lld\n",ans);
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);
 //   printf("%d",1^2^3^4^5^6^7^8^9^10^11^12^13^14^15);
    while(~scanf("%lld %lld",&n,&m))
    {
        for(ll i=1;i<=m;i++)
        {
            ll l,r;
            scanf("%lld %lld",&l,&r);
            imos[l]++;
            imos[r+1]--;
        }
        solve();
    }
}
/*
100
3
1 1
1
4
1 1 1
1 1
1
*/


Measured memory_bytes: 1024
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] tn = new int[n];
		int sum = 0;
		for( int i=0; i<n; i++ ){
			tn[i] = sc.nextInt();
			sum += tn[i];
		}

		int m = sc.nextInt();
		int p=0;
		int x=0;
		for( int j=0; j<m; j++ ){
			p = sc.nextInt();
			x = sc.nextInt();
			System.out.println(sum-tn[p-1]+x);
		}
                return;
	}
}

Measured memory_bytes: 10312
#include <iostream>

int main() {

  int i, j, num, check, temp;
  int ary[110];

  std::cin >> num;

  for (i = 0; i <= num - 1; i++) std::cin >> ary[i];

  for (i = 0; i <= num - 2; i++) std::cout << ary[i] << " ";
  std::cout << ary[num - 1] << std::endl;

  for (i = 1; i <= num - 1; i++) {

    check = i;

    while (check >= 1 && ary[check - 1] > ary[check]) {

      temp           = ary[check];
      ary[check]     = ary[check - 1];
      ary[check - 1] = temp;

      check --;
    }

    //Output
    for (j = 0; j <= num - 2; j++) std::cout << ary[j] << " ";
    std::cout << ary[num - 1] << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3132
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut simple_edges: Vec<Vec<usize>> = vec![Vec::new(); n];
    for i in 0..n - 1 {
        let a = read::<usize>() - 1;
        simple_edges[i + 1].push(a);
        simple_edges[a].push(i + 1);
    }

    let root = 0;
    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut parent_dict: HashMap<usize, usize> = HashMap::new();
    make_tree(root, n, &simple_edges, &mut tree, &mut parent_dict);
    let mut topological_sorted_indexes = vec![root];
    topological_dfs(root, &tree, &mut topological_sorted_indexes);

    let mut depth = vec![0; n];
    for &ti in topological_sorted_indexes.iter().rev() {
        if tree[ti].is_empty() {
            continue;
        }
        let mut depths = tree[ti].iter().map(|&x| depth[x]).collect::<Vec<_>>();
        depths.sort();
        depths.reverse();
        depth[ti] = (0..depths.len()).map(|x| x + 1 + depths[x]).max().unwrap();
    }
    println!("{}", depth[0]);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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

fn make_tree(
    cur_idx: usize,
    parent_idx: usize,
    edges: &Vec<Vec<usize>>,
    tree: &mut Vec<Vec<usize>>,
    parent_dict: &mut HashMap<usize, usize>,
) {
    for child_idx in edges[cur_idx].iter() {
        if *child_idx == parent_idx {
            continue;
        }
        tree[cur_idx].push(*child_idx);
        parent_dict.insert(*child_idx, cur_idx);
        make_tree(*child_idx, cur_idx, edges, tree, parent_dict);
    }
}

fn topological_dfs(cur_idx: usize, tree: &Vec<Vec<usize>>, result: &mut Vec<usize>) {
    for child_idx in tree[cur_idx].iter() {
        result.push(*child_idx);
        topological_dfs(*child_idx, tree, result);
    }
}


Measured memory_bytes: 63764
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
const ll MX=2147483647;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

const ll MXN=200000;
ll n,dat[2*MXN-1];

void SEGinit(ll N){
    n=1;
    while(n<N){
        n*=2;
    }
    rep(i,2*n-1){
        dat[i]=MX;
    }
}

void update(ll x,ll y){
    x+=n-1;
    dat[x]=y;
    while(x){
        x=(x-1)/2;
        dat[x]=min(dat[2*x+1],dat[2*x+2]);
    }
}

ll find_min(ll a,ll b,ll k,ll l,ll r){//kは親
    if(r<=a||b<=l){
        return MX;
    }
    if(a<=l&&r<=b){
        return dat[k];
    }
    else{
        ll vl=find_min(a,b,2*k+1,l,(l+r)/2);
        ll vr=find_min(a,b,2*k+2,(r+l)/2,r);
        return min(vl,vr);
    }
}

int main() {
    ll N,Q;
    cin >> N >> Q;
    SEGinit(N);
    rep(i,Q){
        ll k,x,y;
        cin >> k >> x >> y;
        if(k==0){
            update(x,y);
        }
        if(k==1){
            cout << find_min(x,y+1,0,0,n) << endl;
        }
    }
}


Measured memory_bytes: 5228
x, n = map(int, input().split())

if n!=0:
    a = list(map(int, input().split()))
else:
    a = []
    
h = {}

for i in range(n):
    h[a[i]] = True

i, left, right = x, x, x

while i<=101:
    if not h.get(i, False):
        left = i
        break
    i += 1

i = x

while i>=0:
    if not h.get(i, False):
        right = i
        break
    i -= 1

if abs(x-left) < abs(x-right):
    print(left)
elif abs(x-left) > abs(x-right):
    print(right)
else:
    print(min(left, right))
        

Measured memory_bytes: 61880
def main():
    n, m = map(int, input().split())
    c = [int(i) for i in input().split()]
    dp = [[10 ** 5 for i in range(n + 1)] for j in range(m + 1)]
    for i in range(m+1):
        dp[i][0] = 0
    for i in range(1, m+1):
        for j in range(1, n+1):
            if c[i - 1] <= j:
                dp[i][j] = min(dp[i][j - c[i - 1]] + 1, dp[i - 1][j])
            else:
                dp[i][j] = dp[i - 1][j]
    print(dp[-1][-1])


if __name__ == '__main__':
    main()



Measured memory_bytes: 43952
n=gets.strip.to_i
ll=gets.strip.split.map(&:to_i).sort

#p ll

result=0
(n-1).downto(2) do |i|
  l=0
  r=i-1
  while l<r
#p [l, r, i, (r-l)]
    if ll[i] < ll[l]+ll[r]
      result += (r-l)
      r -= 1
    else
      l += 1
    end
  end
end

p result


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,a[(1<<18)];
vector<int>dp[(1<<18)][20];
signed main(){
    cin>>n;
    rep(i,(1<<n))cin>>a[i];
    rep(i,(1<<n))dp[i][0]={a[i],0};
    rep(j,n){
        rep(i,(1<<n)){
            if((i>>j)&1){
                vector<int>b;
                for(int hoge:dp[i-(1<<j)][j])b.pb(hoge);
                for(int hoge:dp[i][j])b.pb(hoge);
                sort(all(b),greater<int>());
                b.resize(2);
                dp[i][j+1]=b;
            }
            else{
                dp[i][j+1]=dp[i][j];
            }
        }
    }
    int ans=0;
    rep(i,(1<<n)){
        chmax(ans,dp[i][n][0]+dp[i][n][1]);
        if(i)cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 285696
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define full(v) v.begin(),v.end()

void solve()
{
  int n,k;
  cin >> n >> k;
  vi a(n);
  vecin(n,a);

  for (int i = 0; i < k; i++)
  {
    int cnt = 0;
    for (int j = 0; j < n; j++)
    {
      if (a[j]==n)
        cnt++;
    }

    if (cnt==n)
      break;

    vi pr(n);
    for (int j = 0; j < n; j++)
    {
      pr[max(0,j-a[j])]++;
      if (j+a[j]+1 < n)
        pr[j+a[j]+1]--;
    }

    for (int j = 0; j < n; j++)
    {
      if(j)
        pr[j] += pr[j-1];
    }

    a = pr;
  }

  for (int x : a)
    cout << x << " ";
  cout << endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  // Remove for interactive problems
  //cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  //cin >> t;
  while (t--)
  {
      solve();
  }
}



Measured memory_bytes: 4836
#include <stdio.h>
  int main(){
    int n,i,j,k,l,a,b,c,d,x[100],y[100];
	for(i=0;i<100;i++){
	x[i] = 0;
	y[i] = 0;
	}
      scanf("%d",&n);
	  j = n*(n-1)/2;
        for(i=0;i<j;i++){
          scanf("%d%d%d%d",&a,&b,&c,&d);
            if(c>d){
              x[a-1] += 3;
               }else if(c<d){
                 x[b-1] += 3;
                  }else{
                   x[a-1] += 1;
                    x[b-1] += 1;
                      }
                         }
for(j=0;j<n;j++){
  for(k=0;k<n;k++){
    if(x[j]<x[k])
     y[j] += 1;
}
}
for(l=0;l<n;l++){
  printf("%d\n",y[l]+1);
   }
return 0;
  }

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) (n).begin,(n).end
/*%e9%ab%98%e3%81%84%e5%b1%b1%e4%b8%8a%e3%81%8b%e3%82%893%e3%81%a4%e5%87%ba%e5%8a%9b*/
int main()
{
    vector<int> vc;
    int N;
    while( cin >> N )
    {
        vc.push_back( N );
    }
    sort( vc.begin(), vc.end(), greater<int>() );
    REP( i, 3 )
    {
        cout << vc[ i ] << endl;
    }
    return 0;
}

Measured memory_bytes: 3148
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
K = int(input())
A,B = map(int,input().split())

for i in range(A,B+1):
    if i % K == 0:
        print("OK")
        exit()
print("NG")
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9152
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	int h,w;
	cin >> h >> w;
	char a[h][w];
	rep(i,h) rep(j,w) cin >> a[i][j];

	int d[h][w];
	rep(i,h) rep(j,w) d[i][j] = INF;
	queue<P> que;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(a[i][j] == '#'){
				que.push(make_pair(i,j));
				d[i][j] = 0;
			}
		}
	}

	while(que.size()){
		P p = que.front();
		que.pop();
		for(int k = 0; k < 4; k++){
			int nx = p.second+mx4[k];
			int ny = p.first+my4[k];
			if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
			if(d[ny][nx] != INF) continue;
			que.push(make_pair(ny,nx));
			d[ny][nx] = d[p.first][p.second] + 1;
		}
	}
	int ans = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			ans = max(ans,d[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
	
	while (1) {
		int n, x;
		int way = 0;
		cin >> n >> x;

		if (!n && !x)
			break;

		for (int i = 1; i <= n-2; i++)
		{
			for (int j = i + 1; j <= n - 1; j++)
				for (int a = j + 1; a <= n; a++)
					if (a + j + i == x)
						way++;
		}

		cout << way << endl;
	}
}

Measured memory_bytes: 3048
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXA 1001
#define MAXB 1001
#define MAXH 1000000001
#define MAXW 1000000007
#define INF 1000000007
#define MAXN 100001
#define MAXM 1001
#define MAXP 1000001
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

ll N;
ll A[MAXN];
int main(){
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    sort(A, A + N);

    ll ans = N, block = 0, in = 1;
    for(int i = 0;i < N - 1;i++){
        if(A[i] == A[i + 1]){
            while(A[i] == A[i + 1]){
                in++;
                i++;
            }
            if(in % 2 == 0){
                block++;
                ans -= in - 2;
            }else{
                ans -= in - 1;
            }
            in = 1;
        }
    }
    ans -= block;
    if(block % 2) ans--;
    printf("%lld\n", ans);
    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3])) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int H, W, CH, DH, CW, DW;
    cin >> H >> W >> CH >> CW >> DH >> DW;
    CH--; CW--; DH--; DW--;
    string S[1000];
    REP(i, H) cin >> S[i];

    bool visited[1000][1000] = {};
    deque<pair<int, pii>> que;
    int phase = 0;
    que.push_front({phase, {CH, CW}});
    while (!que.empty()) {
        while (!que.empty() && que.front().first == phase) {
            auto f = que.front(); que.pop_front();
            int h = f.second.first, w = f.second.second;
            visited[h][w] = true;
            if (h == DH && w == DW) {
                cout << phase << endl;
                return 0;
            }

            int dh[4] = {0, 1, 0, -1}, dw[4] = {1, 0, -1, 0};
            REP(i, 4) {
                int nh = h + dh[i], nw = w + dw[i];
                if (nh < 0 || H <= nh || nw < 0 || W <= nw || S[nh][nw] == '#' || visited[nh][nw]) continue;
                que.push_front({phase, {nh, nw}});
            }
            FOR(dh, -2, 3) FOR(dw, -2, 3) {
                int nh = h + dh, nw = w + dw;
                if (nh < 0 || H <= nh || nw < 0 || W <= nw || S[nh][nw] == '#' || visited[nh][nw]) continue;
                que.push_back({phase + 1, {nh, nw}});
            }
        }
        phase++;
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 12340
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = list(map(int, input().split()))
nodes = [[] for i in range(N)]
for i in range(N-1):
  r, e = list(map(int, input().split()))
  r, e = r - 1, e - 1
  nodes[r].append(e)
  nodes[e].append(r)
#print(nodes)

result = [0] * N
for i in range(Q):
  r, s = list(map(int, input().split()))
  result[r-1] += s

def dfs(r, prev=-1):
  for i in nodes[r]:
    if i == prev:
      continue
    result[i] += result[r]
    dfs(i, r)

if __name__ == "__main__":
  dfs(0)
  print(*result)


Measured memory_bytes: 274864
n=int(input())
d={}
for i in range(n):
  s=input()
  if s in d:
    d[s]+=1
  else:
    d[s]=1
m=int(input())
for i in range(m):
  s=input()
  if s in d:
    d[s]-=1
  else:
    d[s]=-1
print(max(int(max(d.values())),0))

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        double r = Double.parseDouble(line);
        System.out.println(String.format("%.6f %.6f", r*r*Math.PI, 2*r*Math.PI));
    }
}

Measured memory_bytes: 16916
#include<bits/stdc++.h>
using namespace std;
char a[100001]; 
int main()
{
	scanf("%s",a);
	int lena=strlen(a);
	if(a[0]==a[lena-1])
	{
		if((lena-2)%2==1)
			printf("Second");
		if((lena-2)%2==0)
			printf("First");
	}
	else{
		if((lena-2)%2==1)
			printf("First");
		if((lena-2)%2==0)
			printf("Second");
	}
} 

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N(2022);
int e[N][N];
int a[N];
bool vst[N];
vector<int> sons[N], ans[N];
int main() {
	int n;
	cin >> n;
	for(int i(0); i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for(int i(0); i < n; i++) {
		for(int j(0); j < i; j++) {
			if(__gcd(a[i], a[j]) != 1) {
				e[i][j] = e[j][i] = 1;
			}
		}
	}
	fill(vst, vst + n, false);
	vector<int> ord;
	ord.push_back(n);
	for(int i(0); i < n; i++) {
		if(!vst[i]) {
			vector<pair<int, int> > q;
			sons[n].push_back(i);
			ord.push_back(i);
			vst[i] = true;
			q.push_back(make_pair(i, 0));
			while(!q.empty()) {
				int v(q.back().first), p(q.back().second++);
				if(p != n) {
					if(e[v][p] && !vst[p]) {
						vst[p] = true;
						ord.push_back(p);
						//cout << v << ' ' << p << endl;
						q.push_back(make_pair(p, 0));
						sons[v].push_back(p);
					}
				}else {
					q.pop_back();
				}
			}
		}
	}
	for(int i(n); i >= 0; i--) {
		int v(ord[i]);
		//cout << v << endl;
		for(int j(0); j < (int)sons[v].size(); j++) {
			int y(sons[v][j]);
			//cout << a[v] << ' ' << a[y] << endl;
			vector<int> vec;
			for(int k1(0), k2(0); k1 < (int)ans[v].size() || k2 < (int)ans[y].size(); ) {
				if(k2 == (int)ans[y].size() || k1 < (int)ans[v].size() && k2 < (int)ans[y].size() && ans[v][k1] > ans[y][k2]) {
					vec.push_back(ans[v][k1]);
					k1++;
				}else {
					vec.push_back(ans[y][k2]);
					k2++;
				}
			}
			swap(vec, ans[v]);
		}
		if(i)
			ans[v].insert(ans[v].begin(), v);
		
	}
	for(int i(0); i < (int)ans[n].size(); i++) {
		printf("%d%c", a[ans[n][i]], i == n - 1 ? '\n' : ' ');
	}
}


Measured memory_bytes: 26880
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
int dp[55][55][3000];
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n;cin>>n;
    int a;cin>>a;
    int x[55];
    int X=-1;
    rep(i,1,n+1){
        cin>>x[i];
        X=max(X,x[i]);
    }
    rep(j,0,n+1){
        rep(k,0,n+1){
            rep(s,0,X*n+1){
                if(j==0&&k==0&&s==0){
                   dp[j][k][s]=1;
                }
                else if(j>0&&s<x[j])dp[j][k][s]=dp[j-1][k][s];
                else if(j>0&&k>=1&&s>=x[j])dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-x[j]];
                else dp[j][k][s]=0;
            }
        }
    }
    int ans=0;
    rep(i,1,n+1){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 67712
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define in insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
void solve(){
	ll n, k;
	cin >> n >> k;
	n -= n / k * k;
	cout << min(abs(n - k), abs(abs(n - k) - k));
}
int main(){
	speed;
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

Measured memory_bytes: 256
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

ll ans,x;

void zzz(ll p,ll q,ll r){
  ans=min(ans,abs(p-x)+abs(p-q)+abs(q-r));
}

void vvv(ll p,ll q){
  ll r=x;
  zzz(p,q,r);
  zzz(p,r,q);
  zzz(q,p,r);
  zzz(q,r,p);
  zzz(r,q,p);
  zzz(r,p,q);
}

int main(){
  ll n;
  ll a,b,q;
  cin>>a>>b>>q;
  vector<ll>v1(a,0);
  vector<ll>v2(b,0);
  for(ll i=0;i<a;i++){
    cin>>v1[i];
  }
  for(ll i=0;i<b;i++){
    cin>>v2[i];
  }
  v1.push_back(-1*(1e+11));
  v1.push_back((1e+11));
  v2.push_back(-1*(1e+11));
  v2.push_back((1e+11));
  sort(v1.begin(),v1.end());
  sort(v2.begin(),v2.end());
  for(ll i=0;i<q;i++){
    ans=(1e+12);
    cin>>x;
    auto u1=lower_bound(v1.begin(), v1.end(), x);
    auto u2=lower_bound(v2.begin(), v2.end(), x);
    ll a2=*u1;
    u1--;
    ll a1=*u1;
    ll b2=*u2;
    u2--;
    ll b1=*u2;
    vvv(a1,b1);
    vvv(a1,b2);
    vvv(a2,b1);
    vvv(a2,b2);
    cout<<ans<<endl;
  }
}


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int a, b;
  cin >> a >> b;

  if ( a > b ) swap(a, b);

  int c = (b-a) / 2;

  if ( a+c == b-c ) cout << a+c << endl;
  else cout << "IMPOSSIBLE" << endl;
  
  return 0;
}


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

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

  long long res = 0;
  
  if ( N%2 == 0){
    res = N/2-1;
  }
  else{
    res = N/2;
  }
  
  cout << res << endl;
}






Measured memory_bytes: 256
N = int(input())
results = [input() for _ in range(N)]

result_map = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for result in results:
    result_map[result] += 1

for result, count in result_map.items():
    print('{} x {}'.format(result, count))

Measured memory_bytes: 16328
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200000];

LL ans = 0;

void solve(){
	//数値iが出てきたかどうかをnum[i]とおく
	vector<LL> num(1000001,0); 
	for(int i=0;i<N;i++){
		num[A[i]]++;
	}

	for(int i=0;i<N;i++){
		//printf("A[%d]=%lld\n",i,A[i]);
		bool add_flag = true;
		for(LL j=2;j*j<=A[i];j++){
			if(A[i]%j==0){
				if(num[j]>0){
					//cout << j << endl;
					add_flag = false;
					break;
				}
				if(num[A[i]/j]>0){
					//cout << A[i]/j << endl;
					add_flag = false;
					break;
				}
			}
		}
		if(A[i]!=1 && num[1]>0) add_flag = false;
		if(num[A[i]]>1) add_flag = false;
		if(add_flag){
			ans++;
		}
	}
}

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

    solve();

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

Measured memory_bytes: 12016
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

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

    if (x >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


}


Measured memory_bytes: 3624
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/24/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  struct Num {
    int n, i;
    Num(int n, int i) : n(n),i(i) {}
    bool operator<(const Num& x) const {return n<x.n;}
  };
  int N; cin>>N;
  vector<int> A(N); for(auto& a : A) cin>>a;
  vector<int> B(N); for(auto& b : B) cin>>b;
  auto solve = [&]() -> ll {
    priority_queue<Num, vector<Num>> pq;
    for (int i = 0; i < N; i++) {
      if (B[i] < A[i]) {
        return -1;
      }
      if (B[i] > A[i])
        pq.emplace(B[i], i);
    }
    ll ans = 0;
    while (not pq.empty()) {
      auto t = pq.top(); pq.pop();
      auto a = (t.i+N-1)%N;
      auto c = (t.i+1)%N;
      auto apc = B[a]+B[c];
      if (t.n < apc)
        return -1;
      auto m = t.n%apc;
      if (m < A[t.i]) {
        auto d = t.n-A[t.i];
        if (d%apc>0)
          return -1;
        ans += d/apc;
        B[t.i] = A[t.i];
      } else {
        B[t.i] = m;
        ans += t.n/apc;
        if (m > A[t.i])
          pq.emplace(m, t.i);
      }
    }
    return ans;
  };
  cout << solve() << endl;

  return 0;
}


Measured memory_bytes: 4980
from collections import Counter


def solve():
    n, k = map(int, input().split())
    l = [0 for _ in range(n)]
    for _ in range(k):
        input()
        a = list(map(int, input().split()))
        for i in a:
            l[i-1] += 1
    c = Counter(l)
    print(c[0])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9480
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int  n,m,t[505][505],dod[505][505],x,wyn;
pair<pair<int,int>,pair<int,int> >tab[250005];
int main()
{
ios_base::sync_with_stdio(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
    {
    for(int j=1;j<=m;j++)
        {
        cin>>t[i][j];
        if(i%2==1)
            {
            t[i][j]+=dod[i][j];
            if(t[i][j]%2==1)
                {
                if(j!=m)
                    {
                    tab[x++]=make_pair(make_pair(i,j),make_pair(i,j+1));
                    dod[i][j+1]=1;
                    wyn++;
                    }
                else if(i<n)
                    {
                    tab[x++]=make_pair(make_pair(i,j),make_pair(i+1,j));
                    dod[i+1][j]=1;
                    wyn++;
                    }
                }
            }
        }
    if(i%2==0)
        {
        for(int j=m;j>=1;j--)
            {
            t[i][j]+=dod[i][j];
            if(t[i][j]%2==1)
                {
                if(j!=1)
                    {
                    tab[x++]=make_pair(make_pair(i,j),make_pair(i,j-1));
                    dod[i][j-1]=1;
                    wyn++;
                    }
                else if(i<n)
                    {
                    tab[x++]=make_pair(make_pair(i,j),make_pair(i+1,j));
                    dod[i+1][j]=1;
                    wyn++;
                    }
                }
            }
        }
    }
cout<<wyn<<'\n';
for(int i=0;i<x;i++)
    {
    cout<<tab[i].first.first<<' '<<tab[i].first.second<<' '<<tab[i].second.first<<' '<<tab[i].second.second<<'\n';
    }
}


Measured memory_bytes: 7936
import sys, math
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

S = set(input())
if S == {'N', 'S'} or S == {'W', 'E'} or S == {'W', 'E', 'N', 'S'}:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9436
#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<math.h>
#include<string>
#include<utility>
#include<queue>
#include<stdlib.h>
int main() {
	using namespace std;
	int a;
	cin >> a;
	cout << a*a*a << endl;
	return 0;
}


Measured memory_bytes: 3108
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		int numBlue = stdin.nextInt();
		Map<String, Integer> strCountMap = new HashMap<>();
		for (int i = 0; i < numBlue; i++) {
			String str = stdin.next();
			int count = strCountMap.getOrDefault(str, 0) + 1;
			strCountMap.put(str, count);
		}
		int numRed = stdin.nextInt();
		for (int i = 0; i < numRed; i++) {
			String str = stdin.next();
			int count = strCountMap.getOrDefault(str, 0) - 1;
			strCountMap.put(str, count);
		}

		int max = 0;
		for (int count : strCountMap.values()) {
			max = Math.max(max, count);
		}

		System.out.println(max);
	}

}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct ver {
  int i; int w;
  ver(int i, int w){ this->i = i; this->w = w; };
};

bool operator< (const ver &x, const ver &y) { return x.w > y.w; };

int N, M;
vector<int> color, D, len;
map<int, map<int, int>> e;
priority_queue<ver> dq;

void dfs(int n, int p=-1) {
  for (auto x: e[n]) {
    if (x.first==p) continue;
    if (color[x.first]!=-1) {
      if (len[x.second]==0&&D[n]<=D[x.first]) len[x.second] = pow(10,9);
    }
    else if (D[n]<D[x.first]) {
      color[x.first] = color[n];
      len[x.second] = D[x.first] - D[n];
      dfs(x.first,n);
    }
  }
}

int main() {
  cin >> N >> M;
  color.resize(N,-1);
  D.resize(N); rep(i,N) { cin >> D[i]; dq.push(ver(i,D[i])); }
  len.resize(M,0);
  rep(i,M) {
    int U, V; cin >> U >> V; U--; V--;
    e[U][V] = i; e[V][U] = i;
  }
  while(dq.size()) {
    ver now = dq.top(); dq.pop();

    bool ok = false;
    for (auto x: e[now.i]) {
      if (D[x.first]==D[now.i]) {
        ok = true;
        len[e[now.i][x.first]] = D[now.i];
        if (color[x.first]!=-1) {
          color[now.i] = !color[x.first];
          dfs(now.i);
        }
        else { 
          color[now.i] = 0; color[x.first] = 1; 
          dfs(now.i); dfs(x.first);
        }
        break;
      }
    }
    if (!ok) { cout << -1 << endl; return 0; }
    while (dq.size()&&color[dq.top().i]!=-1) dq.pop();
  }
  for (auto x: color) cout << (x ? "B" : "W"); cout << endl;
  for (auto x: len) cout << x << endl;
  // debug(all(len));
  // cout << result << endl;
  return 0;
}

Measured memory_bytes: 32884
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  set<ll> st;
  vector<int> A(N);
  rep(i,N){
    cin>>A[i];
    st.insert(A[i]);
  }
 
  if(st.size()==N)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 10368
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

a.sort()
cnt = 0
nmax = a[-1]
table = [True] * (nmax+1)
c = Counter(a)

duplicate = []
for i in c.keys():
    if c[i] > 1:
        duplicate.append(i)
for i in a:
    if not table[i]:
        continue
    if not i in duplicate:
        cnt += 1
    for j in range(i*2, nmax+1, i):
        table[j] = False
print(cnt)

Measured memory_bytes: 121012
#include <stdio.h>

int main(void){
	long x, y=1;
	long m=100.0;
	scanf("%ld", &x);
	while(1){
		m *= 1.01;
		if(x <= m){
			printf("%ld", y);
			break;
		}else{
			y++;
		}
	}
	return 0;
}

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


using namespace std;

int main(){
        string s;
        int sum=0;
        cin>>s;
        for(int i=0; i<s.size(); i++) sum+=s[i]-'0';
        if(sum%9==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

        return 0;
}

Measured memory_bytes: 3708
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    cout << min(N % K, abs(N % K - K)) << endl;
    return 0;
}

Measured memory_bytes: 256
s = list(map(int,list(input())))
# odd  = 0101010101...
# even = 1010101010
# 違ったら足す
odd = 0
even = 0
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] == 0:
            even += 1
        if s[i] == 1:
            odd += 1
    else:
        if s[i] == 0:
            odd += 1
        if s[i] == 1:
            even += 1
    # print("i",i,"s[i]",s[i],"odd",odd,"even",even)
# print("odd",odd)
# print("even",even)
print(min(odd,even))


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main(){
    gearup;
    ll n;cin>>n;
    string s;cin>>s;
    ll r = 0,l=0,r_need = 0,l_need = 0;
    rep(i,n){
        if(s[i] == '('){
            l++;
        }
        else{
            if(l<=0)l_need++;
            else l--;
        }
    }
    r_need = l;
    rep(i,l_need)cout<<'(';
    cout <<s;
    rep(i,r_need)cout<<')';
    cout << endl;
}

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

namespace ConsoleApp15
{
    class Class148
    {
        static void Main()
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            char[] ans = new char[S.Length];
            for(int i = S.Length-T.Length;i>=0; i--)
            {
                bool frag = true;
                var s = S.ToArray();
                for(int j = 0; j < T.Length; j++)
                {
                    if (s[j + i] == T[j] || s[j + i] == '?')
                    {
                        s[j + i] = T[j];continue;
                    }
                    frag = false;
                    break;
                }
                if (frag)
                {
                    for (int j = 0; j < s.Length; j++)
                        if (s[j] == '?')
                            s[j] = 'a';
                    Console.WriteLine(s);return;
                }
            }
            Console.WriteLine("UNRESTORABLE");
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int N,M;
main()
{
	cin>>N>>M;
	vector<pair<int,int> >A;
	for(int i=0;i<N;i++)
	{
		int a,b;cin>>a>>b;
		A.push_back(make_pair(a,b));
	}
	sort(A.begin(),A.end());
	int id=0;
	priority_queue<int>P;
	long ans=0;
	for(int i=1;i<=M;i++)
	{
		while(id<N&&A[id].first<=i)P.push(A[id++].second);
		if(!P.empty())
		{
			ans+=P.top();
			P.pop();
		}
	}
	cout<<ans<<endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	int N, ans=0;
	int h[105];

	cin >> N;
	rep(i,N) cin >> h[i];

	rrep(k,101) if( k > 0 ){
		bool bf = false;
		rep(i,N){
			if( h[i] == k ){
				h[i]--;
				ans += !bf;
				bf = true;
			}else{
				bf = false;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#スペース区切りの整数の入力
r, g, b = map(int, raw_input().split())
#入力値の連結
x = str(r)+str(g)+str(b)

#4の倍数か否かの確認
if int(x)%4 == 0:
    print 'YES'
else:
    print'NO'

Measured memory_bytes: 2568
import java.util.*;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        String S = scanner.next();
        scanner.close();

        String[] str = S.split("");

        int count = 0;

        int leftBlack = 0;
        int leftWhite = 0;
        int rigthBlack = 0;
        int rightWhite = 0;

        // 全量
        for (int i = 0; i < N; i++) {
            if (".".equals(str[i])) {
                rightWhite++;
            } else {
                rigthBlack++;
            }
        }

        count = rightWhite;

        // チェック
        for (int i = 0; i < N; i++) {
            if(".".equals(str[i])){
                leftWhite++;
                rightWhite--;
            }else{
                leftBlack++;
                rigthBlack++;
            }
            int calc = leftBlack + rightWhite;
            count = Math.min(count,calc);
        }

        System.out.println(count);

//        System.out.println(System.currentTimeMillis() - startTime);
    }
}


Measured memory_bytes: 54220
import itertools

def solve():
  a, b, c, d = map(int, input().split())
  hoge = 0
  bit = 0
  while True:
    if hoge % 2 == 0:
      c -= b
    if hoge % 2 == 1:
      a -= d
    if a <= 0:
      bit = 0
      break
    if c <= 0:
      bit = 1
      break
    hoge += 1
  if bit == 0:
    print("No")
  else:
    print("Yes")
  return 0
 
if __name__ == "__main__":
  solve()


Measured memory_bytes: 9196
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    cout << "" << std::endl;
    ll Min = 1 << 30;
    for (int i = 0; i <= n-k; ++i) {
        ll x = h[i]-h[i+k-1];
        Min = min(x, Min);
    }
    cout << Min << std::endl;
    return 0;
}

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

using namespace std;
#define ull unsigned long long
#define ll long long
const int inf = 1e9;
const int MAXN = 4e6+4;

vector<vector<int>> vect(3e5+1, vector<int>(0));
vector<bool> was(3e5+1, false);
vector<int> dp(3e5+1, 0);
vector<int> depth(3e5+1, 0);


void solve(){
    int n;
    cin>>n;
    vector<bool> dp(n+1, false);
    dp[0]=true;
    for(int i=100;i<106;i++){
        if(i>n+1) break;
        dp[i]=true;
    }
    for(int i=106;i<n+1;i++){
        dp[i]=(dp[i-100]|dp[i-101]|dp[i-102]|dp[i-103]|dp[i-104]|dp[i-105]);
    }
    cout<<((dp[n])?1:0);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n=1;
    for(int i=0;i<n;i++) solve();
    return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

int p[20], c[20];

int main(){
    int d, g;
    cin >> d >> g;
    for (int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }

    int ans = 2000;
    for (int bit = 0; bit < (1<<d); bit++){
        int score = 0;
        int cnt = 0;
        for (int j = 0; j < d; j++){
            if (bit >> j & 1){
                score += 100 * (j + 1) * p[j] + c[j];
                cnt += p[j];
            }
        }

        if (score >= g){
            ans = min(ans, cnt);
            continue;
        }

        for (int i = d - 1; i >= 0; i--){
            if (bit >> i & 1) continue;
            for (int k = 1; k < p[i]; k++){
                if (score >= g) break;
                score += 100 * (i + 1);
                cnt++;
            }
            if (score >= g){
                ans = min(ans, cnt);
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256