akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int unsigned long long
#define rep(i,m,n) for(int i=m;i<n;i++)
#define repr(i,n,m) for(int i=n;i>=m ;i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
#define pp pop_back
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 
bool sortbysec(const pair<int,int> &a,
             const pair<int,int> &b)
{
   return (a.second < b.second);
}
bool sortinrev(const pair<int,int> &a,  
              const pair<int,int> &b)
{
      return (a.first > b.first);
}
int ispal(string s)
{
	int x=s.length();
	for(int i=0,j=x-1;i<x/2,j>=x-x/2;i++,j--)
		if(s[i]!=s[j])
			return 0;
	return 1;
}
void solve()
{
	int n,total=0;
	cin>>n;
	rep(i,1,n+1)
	{
		rep(j,1,n+1)
		{
			rep(k,1,n+1)
			{
				total+=__gcd(i,__gcd(j,k));
			}
		}
	}cout<<total;
}	
signed main()
{
           	    // #ifndef ONLINE_JUDGE
                // freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
                // #endif 
  int t=1;
 //cin>>t;
  while(t--){
  solve();
  cout<<"\n";
}
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
 return 0;
}  


Measured memory_bytes: 3788
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
  a = list(map(int,input().split()))
  d = sum(ai*bi for ai,bi in zip(a,b)) 
  if d+c >0:
    count += 1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)     for(long long int i=a; i<n; i++)
#define loop(i,a,n)     for(long long int i=a; i>=n; i--) 
int seg[4*300000], lazy[4*300000];

void update(int node, int val, int low, int high, int pos)
{
	if(low==high)
	{
		seg[node]=val;
		return;
	}
	if(low>high)
		return;
	int mid=(low+high)/2;
	if(pos<=mid)
		update(2*node+1, val, low, mid, pos);
	else	
		update(2*node+2, val, mid+1, high, pos);
	seg[node]=max(seg[node*2+1], seg[node*2+2]);
}

int range(int qlow, int qhigh, int low, int high, int pos)
{
	if(low>high)
		return 0;
	if(qlow<=low and qhigh>=high)
		return seg[pos];
	else if(low>qhigh or high<qlow)
		return 0;
	int mid=(low+high)/2;
		return max(range(qlow, qhigh, low, mid, 2*pos+1) , range(qlow, qhigh, mid+1, high, 2*pos+2));
}
int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL);
	
	int a, k;
	cin>>a>>k; 
	int b[a], ans=0;
	forr(i, 0, a)
		cin>>b[i];
	
	forr(i, 0, a)
	{
		int x=range(max(b[i]-k, 0), min(b[i]+k, 300000), 0, 300000, 0);
		update(0, x+1, 0, 300000, b[i]);
		ans=max(ans, x+1);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8916
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = list(str(input().rstrip('\n')))
    for i in range(len(s)):
        for j in range(i + 1, len(s)):
            if "".join(s[:i + 1] + s[j:]) == "keyence":
                print("YES")
                exit()
    print("NO")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;

using Graph = vector<vector<int> >;


int main()
{

	int N;

	cin >> N;

	int ans = (N - 1) / 2;

	cout << ans;


	return 0;
}



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

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

    int k, a, b, m;

    cin >> k;
    cin >> a >> b;

    int largest = (b / k) *k;
    if(a <= largest)
        cout << "OK";
    else
        cout << "NG";
  	cout << "\n";
    return 0;

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    std::sort(a.begin(),a.end(),std::greater<int>());
    int sum = 0;
    for (int i = 0; i < n; i++){
        sum += a.at(i);
    }
    if (a.at(m-1) >= (sum-1)/(4*m)+1){
        cout << "Yes" <<endl;
    }
    else {
        cout << "No" <<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  vector<vector<int>> res(N);
  for (int i = 0; i < N; ++i) {
    if (i) {
      int a; cin >> a; --a;
      res[a].push_back(i);
    }
  }
  for (const auto& r : res) {
    cout << r.size() << CRLF;
  }
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 14164
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void)
{
    int n, p, cnt = 0;
    scanf("%d", &n);
    rep(i, n)
    {
        scanf("%d", &p);
        if (p != i + 1)
            cnt++;
        if (cnt > 2)
        {
            puts("NO");
            return 0;
        }
    }

    puts("YES");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;
const double PI = 3.14159265358979323846;
//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


int main(){
cout<<fixed<<setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);

ll N;
  cin>>N;
  //cout<<sqrt(N)<<endl;
  for(int i=1;i<N+1;i++){
    int counter=0;
    for(int j=1;j<sqrt(i)+3;j++){
      for(int k=j;k<sqrt(i)+3;k++){
        for(int l=k;l<sqrt(i)+3;l++){
          if(j*j+k*k+l*l+j*k+k*l+l*j==i){
            if(j==k&&k==l){
            counter++;
            }else if(j!=k&&k!=l&&l!=j){
                counter++;counter++;counter++;counter++;counter++;counter++;
              }else{
              counter++;counter++;counter++;
            }
          }
        }
      }
    } 
    cout<<counter<<endl;
    }
  }
 




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

#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

inline void File() {
	freopen("c.in", "r", stdin);
	freopen("c.out", "w", stdout);
}

const int N = 3e5 + 10;
char s[N];
int a[N], pre[N], suf[N], n;

int main() {

	cin >> n, scanf("%s", s + 1);
	For(i, 1, n) pre[i] = pre[i - 1] + (s[i] == 'E');
	Forr(i, n, 1) suf[i] = suf[i + 1] + (s[i] == 'W');

	int ans = n;
	For(i, 1, n) 
		ans = min(ans, i - 1 - pre[i - 1] + n - i - suf[i + 1]);
	cout << ans << endl;
	
	return 0;	
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

int main(){
	int A,B;
	cin>>A>>B;
	if(A==1){
		int h=100;
		int w=((B+50)/50)*2;
		cout<<w<<" "<<h<<endl;
		REP(i,w/2-1){
			REP(j,50){
				cout<<"#.";
			}
			cout<<endl;
			REP(j,100){
				cout<<".";
			}
			cout<<endl;
		}
		REP(i,B%50){
			cout<<"#.";
		}
		REP(i,50-(B%50)){
			cout<<"..";
		}
		cout<<endl;
		REP(j,100){
			cout<<".";
		}
		cout<<endl;
	} else if(B==1){
		int h=100;
		int w=((A+50)/50)*2;
		cout<<w<<" "<<h<<endl;
		REP(i,w/2-1){
			REP(j,50){
				cout<<".#";
			}
			cout<<endl;
			REP(j,100){
				cout<<"#";
			}
			cout<<endl;
		}
		REP(i,A%50){
			cout<<".#";
		}
		REP(i,50-(A%50)){
			cout<<"##";
		}
		cout<<endl;
		REP(j,100){
			cout<<"#";
		}
		cout<<endl;
	} else {
		int h=100;
		int wb=((B+49)/50)*2;
		int ww=((A+49)/50)*2;
		cout<<wb+ww<<" "<<h<<endl;
		REP(i,wb/2-1){
			REP(j,50){
				cout<<"#.";
			}
			cout<<endl;
			REP(j,100){
				cout<<".";
			}
			cout<<endl;
		}
		REP(i,(B-1)%50){
			cout<<"#.";
		}
		REP(i,50-((B-1)%50)){
			cout<<"..";
		}
		cout<<endl;
		REP(j,100){
			cout<<".";
		}
		cout<<endl;

		REP(j,100){
			cout<<"#";
		}
		cout<<endl;
		REP(i,(A-1)%50){
			cout<<".#";
		}
		REP(i,50-((A-1)%50)){
			cout<<"##";
		}
		cout<<endl;

		REP(i,ww/2-1){
			REP(j,100){
				cout<<"#";
			}
			cout<<endl;
			REP(j,50){
				cout<<".#";
			}
			cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
//2015
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(void){
	int i,ad[4]={0},e=0,f=0,sum=0;
	for(i=0;i<4;i++){
		cin>>ad[i];
	}
	cin>>e;
	cin>>f;
	sort(ad,ad+4,greater<int>());//降順,昇順＝＝sort(ad,ad+4);
	for(i=0;i<3;i++){
		sum+=ad[i];
	}
	if(e<f){
		sum+=f;
	}
	else{
		sum+=e;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3136
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
s = input()
dp = [[0 for i in range(n+5)] for j in range(n+5)]
res = 0
for i in range(n)[::-1]:
    for j in range(n)[::-1]:
        if i >= j: continue
        if s[i] == s[j]:
            dp[i][j] = dp[i+1][j+1] + 1
        else:
            dp[i][j] = 0
for i in range(n):
    for j in range(n):
        tmp = min(j-i, dp[i][j])
        res = max(res, tmp)
print(res)

Measured memory_bytes: 258152
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ,mod = 1e9+7 ;

int n ,m ,x ,mem[N] ;
bool is[N] ;
int solve(int i){
    if(i>n) return 0;
    if(i==n) return 1;
    int&ret = mem[i];
    if(~ret) return ret;
    if(is[i]) return ret=0 ;
    return ret = (solve(i+1) + solve(i+2))%mod;
}
int main(){
    cin >> n >> m ;
    while(m--){
        scanf("%d",&x);
        is[x] = 1 ;
    }
    memset(mem,-1,sizeof mem);
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] dice = new int[n][6];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 6; j++){
                dice[i][j] = sc.nextInt();
            }
        }
        String order = "RRRRNRRRRNRRRRNRRRRWRRRWWRRR";
        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                for(int k = 0; k < order.length(); k++){
                    char c = order.charAt(k);
                    int[] temp = new int[6];
                    if(c == 'R'){
                        temp[0] = dice[j][0];
                        temp[1] = dice[j][3];
                        temp[2] = dice[j][1];
                        temp[3] = dice[j][4];
                        temp[4] = dice[j][2];
                        temp[5] = dice[j][5];
                    }else if(c == 'W'){
                        temp[0] = dice[j][2];
                        temp[1] = dice[j][1];
                        temp[2] = dice[j][5];
                        temp[3] = dice[j][0];
                        temp[4] = dice[j][4];
                        temp[5] = dice[j][3];
                    }else if(c == 'N'){
                        temp[0] = dice[j][1];
                        temp[1] = dice[j][5];
                        temp[2] = dice[j][2];
                        temp[3] = dice[j][3];
                        temp[4] = dice[j][0];
                        temp[5] = dice[j][4];
                    }
                    dice[j] = temp;
                    if(dice[i][0] == dice[j][0] && dice[i][1] == dice[j][1] && dice[i][2] == dice[j][2] && dice[i][3] == dice[j][3] && dice[i][4] == dice[j][4] && dice[i][5] == dice[j][5]){
                        System.out.println("No");
                        return;
                    }
                }
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 34092
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()

using namespace std;

const int N = 2e5 + 101;

int n, k;
int a[N];
int p[N];

int main() {
	scanf ("%d%d", &n, &k);
	rep(i, 1, n) {
		scanf ("%d", a + i);
	}
	while (k--) {
		rep(i, 1, n)
			p[i] = 0;
		int x = n + 1;
		rep(i, 1, n)
			x = min(x, a[i]);
		if (x == n) break;
		rep(i, 1, n) {
			int l = i - a[i];
			int r = i + a[i];
			l = max(l, 1);
			r = min(r, n);
			p[l]++;
			p[r + 1]--;
		}
		rep(i, 1, n)
			p[i] += p[i - 1];
		rep(i, 1, n)
			a[i] = p[i];
	}
	rep(i, 1, n)
		printf ("%d ", a[i]);
		
	
		
	return 0;
}	


Measured memory_bytes: 5348
#include <bits/stdc++.h>
using namespace std;
int main(){
        long long int n, m; cin >> n >> m;
        long long int a = 0;
        for (long long int x = 0; x < m; ++x){
            long long int q; cin >> q;
            a += q;
        }
        cout << ((n - a) >= 0 ? n-a : -1) << endl;
    return 0;
}



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

int main() {
  int n;
  string s;
  cin >>n>>s;
  
  ll sr=0,sg=0,sb=0;

  for(int i=0; i<s.size(); i++){
    if(s.at(i)=='R'){sr++;}
    else if(s.at(i)=='G'){sg++;}
    else if(s.at(i)=='B'){sb++;}  
  }
//  cout<<sr<<" "<<sg<<" "<<sb<<endl;;

  ll all= sr*sg*sb;
  ll exclude=0;
  set<char> rgb{'R','B','G'};

  for(int i=0; i<n; i++){
    for(int j=i+1; j<n ; j++){
      int k;
      if(2*j-i<n) k=2*j-i;
      else{continue;}
      set<char> num{s.at(i),s.at(j),s.at(k)};
      if(num == rgb)exclude++;
    }
  }
  
  cout<< all-exclude;
  }
 







Measured memory_bytes: 3640
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::*;
use proconio::{input, fastout, marker::*};

#[fastout]
fn main() {
  input!{
    n:u64,
    x:u64,
    t:u64
  }
  println!("{}",((n+x-1)/x)*t);
}


Measured memory_bytes: 2172
def main():
  t = input().split(" ")
  A, B, C , K = int(t[0]), int(t[1]), int(t[2]), int(t[3])
  if K % 2 == 0:
    s = 1
  else:
    s = -1
  r = s * (A-B)
  print(r)
main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<vector>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
int main()
{
    fastio;
    int i,n,input,x,count=0;
    cin>>n>>x;
    vector <int> v;
    vector <int> arr;
    arr.push_back(0);
    for (i=0;i<n;i++)
    {
        cin>>input;
        v.push_back(input);
    }
    for (i=0;i<n;i++) 
        arr.push_back(arr[i] + v[i]);
    for (i=0;i<n+1;i++)
    {
        if (arr[i]<=x)
            count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)x.size())
using pii = pair<int, int>;
using vvi = vector<vector<int>>;
using vi  = vector<int>;
constexpr int INF = 1001001001001001001LL;

vi topological_sort(vvi &g) {
    int n = sz(g);
    vi sorted;
    vi deg(n, 0);
    queue<int> q;
    rep(v, 0, n) for (int w : g[v]) deg[w]++;
    rep(v, 0, n) if (deg[v] == 0) q.push(v);
    while (sz(q)) {
        int v = q.front(); q.pop();
        sorted.push_back(v);
        for (int w : g[v]) {
            deg[w]--;
            if (deg[w] == 0) {
                q.push(w);
            }
        }
    }
    return sorted;
}
signed main() {
    int V, E;
    cin >> V >> E;
    vvi G(V);
    rep(i, 0, E) {
        int vs, vt;
        cin >> vs >> vt;
        G[vs].push_back(vt);
    }
    auto ans = topological_sort(G);
    for (int v : ans) {
        cout << v << endl;
    }
}



Measured memory_bytes: 3980
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int box1 = a - b;
		int d = c - box1;

		if (box1 > c) {
			System.out.println("0");
		} else {
			System.out.println(d);
		}
		sc.close();
	}
}

Measured memory_bytes: 27056
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//priority_queue <int, vector <int>, greater <int> > pq; ..for min heap
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979323846264
#define pii pair <int, int>
#define pipii pair <int, pair <int, int> > 
#define piipi pair <pair <int, int>, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
#define FOR(i, x, y) for (int i=x; i<=y; i++)
#define FORD(i, y, x) for (int i=y; i>=x; i--)
#define debug printf("OK\n")
int n, q, a[200005];
vector <int> edges[200005];
void dfs (int x, int p) {
    if (x != 1) a[x] += a[p];
    for (int y : edges[x]) {
        if (y != p) dfs(y, x);
    }
}
int main() {
    scanf("%d %d", &n, &q);
    for (int i=1; i<n; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        edges[u].pb(v);
        edges[v].pb(u);
    }
    for (int i=0; i<q; i++) {
        int x, v;
        scanf("%d %d", &x, &v);
        a[x] += v;
    }
    dfs(1, 0);
    for (int i=1; i<=n; i++) {
        printf("%d%c", a[i], i==n?'\n':' ');
    }
    return 0;
}

Measured memory_bytes: 23424
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v, int num=0){
  if(num == 0) num = (int)v.size();
	for(int i=0; i<num; i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

void calc(int H, int W){
  vector<vector<int>> maze(H, vector<int>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> maze[i][j];
    }
  }

  int score = 0;
  int old_score = -1;
  while(score != old_score){
    old_score = score;
    for(int i=0; i<H; i++){

      map<int, int> mp;//カウント
      for(int j=0; j<W; j++) mp[maze[i][j]]++;

      //消滅処理
      for(pair<int, int> p: mp){
        // cout << " p.first: " << p.first << " p.second: " << p.second << endl;
        if(p.second >= 3){
          int cnt = 0;
          for(int j=0; j<W; j++){
            if(maze[i][j] == p.first) cnt++;
            else cnt = 0;

            if(cnt >= 3){
              for(int k=0; k<cnt; k++){
                if(maze[i][j-k] == p.first){
                  score += p.first;
                  maze[i][j-k] = 0;//消滅
                }
                else break;
              }
            }
          }
        }
      }
    }

    //ここまでで消滅と点数計算が終了
    //以下　落下の処理
    for(int i=H-1; i>=0; i--){
      for(int j=0; j<W; j++){
        if(maze[i][j] == 0){
          for(int k=i-1; k>=0; k--){
            if(maze[k][j] != 0){
              maze[i][j] = maze[k][j];
              maze[k][j] = 0;
              break;
            }
          }
        }
      }
    }
  }
  // cout << " maze: "; print_vec2(maze);
  cout << score << endl;
  return;
}

int main(){
  while(true){
    int H;
    cin >> H;
    if(H==0) return 0;
    const int W = 5;
    calc(H, W);
  }
}




Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,n,i,j;
    cin>>x>>n;
    int p[n+1];
    int flag[102];
    if(x>=1&&x<=100&&n>=0&&n<=100)
    {
        if(n==0)
            cout<<x<<endl;
        else
        {
            for(i=0;i<=101;i++)
                flag[i]=0;
            for(i=1;i<=n;i++)
            {
                cin>>p[i];
                flag[p[i]]=1;
            }
            j=0;
            while(1)
            {
                if(flag[x-j]!=1)
                {
                    cout<<x-j<<endl;
                    break;
                }
                else if(flag[x+j]!=1)
                {
                    cout<<x+j<<endl;
                    break;
                }
                else
                    j++;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3536
N,M= map(int,input().split())
list=[[False for i in range(N)] for j in range(N)]
for i in range (M):
    a,b=map(int,input().split())
    list[a-1][b-1]=True
    list[b-1][a-1]=True
pre = [N for i in range(N)]
low = [N for i in range(N)]
precount=0
count = 0
flag = [False for i in range(N)]
flag[0]=True

def bridge_search (prev,now):
    global precount
    global count
    global flag
    pre[now] = precount
    low[now] = precount
    precount += 1
    flag[now] = True
    for i in range(0,N):
        if(list[now][i] and i != prev):#親ノードへの探索はしない
            if(not flag[i]):#訪れてないなら
                if bridge_search(now,i):#Trueなら辺now-iは橋
                    count += 1
                if low[i] < low[now] and pre[i] > pre[now]:
                    low[now] = low[i]
            else:#訪れているなら
                if low[i] < low[now]:
                    low[now] = low[i]
    #頂点nowの探索終了
    if low[now] >= pre[now]:
        return True
    else:
        return False
    
        
bridge_search(0,0)
print(count)


Measured memory_bytes: 3064
#include <iostream>
#include <climits>

using namespace std;

int main(){
	long int n,x,max,min,sum=0;//最初の時点で暫定一位になる必要がある
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x;
		if(i==0){
			max=x;
			min=x;
		}
		else if(max<x)
			max=x;
		else if(min>x)
			min=x;
		sum+=x;
	}
	cout <<min<<" "<<max<<" "<<sum<<"\n";
}


Measured memory_bytes: 3116
N = int(input())
h = list(map(int,input().split()))
sw = 0
while max(h) != 0:
    for i in range(N):
        if h[i] == 0:
            continue
        j = 0
        for jj in range(i,N+1):
            if jj == N:
                j = jj
                break
            if h[jj] == 0:
                j = jj
                break
        #print(i,j)
        sw += 1
        for jj in range(i,j):
            h[jj] -= 1
        break
print(sw)

Measured memory_bytes: 9200
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
using namespace std;
#define INF 1000000005
int main()
{
int n, c;
std::cin >> n >> c;
std::vector<std::vector<int>> tv;
std::vector<int> flag(200002,0);
for(int i = 0; i < n; i++){
    int s,t,cc;
    std::cin >> s >> t >> cc;
    std::vector<int> temp = {s,t,cc};
    tv.push_back(temp);
}
for(int i = 1; i <= c; i++){
    std::vector<int> temp(200002,0);
    for(int j = 0; j < n; j++){
        if(tv[j][2] == i){
            temp[tv[j][0] * 2 - 1]++;
            temp[tv[j][1] * 2]--;

        }
    }
    for(int j = 0; j < 200002; j++){
        temp[j + 1] += temp[j];
    }
    for(int j = 0; j < 200002; j++){
        if(temp[j] > 0){
            flag[j]++;
        }
    }
}
int max = 0;
for(int i = 0; i < 200002; i++){
    if(flag[i] > max){
        max = flag[i];
    }
}

std::cout << max << std::endl;





return 0;
}

Measured memory_bytes: 7856
#include <stdio.h>

using namespace std;

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

int max(int X, int Y) {
    return X > Y ? X : Y;
}

int min(int X, int Y) {
    return X < Y ? X : Y;
}

int main() {

    int A, B, C, X, Y;
    scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);

    int ans = 0;
    if (A + B <= 2 * C) {
        ans = A * X + B * Y;
    } else {
        // 2 * C < A + B
        if (2 * C <= A && 2 * C <= B) {
            ans = 2 * C * max(X, Y);
        } else if (2 * C <= A) {
            if (Y > X) {
                ans = 2 * C * X + B * (Y - X);
            } else {
                ans = 2 * C * X;
            }
        } else if (2 * C <= B) {
            if (Y > X) {
                ans = 2 * C * Y;
            } else {
                ans = 2 * C * Y + A * (X - Y);
            }
        } else {
            if (Y > X) {
                ans = 2 * C * X + B * (Y - X);
            } else {
                ans = 2 * C * Y + A * (X - Y);
            }
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const long long INF = 1LL << 60;
const int MOD = 1000000007;
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
template <class T> inline bool chmin(T &a, T b) { if ( a > b ) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T &a, T b) { if ( a < b ) { a = b; return 1; } return 0; }
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int N;
int l, r;
int res = 0;

int main(int argc, char *argv[]){
    cin >> N;
    vec H(N);
    rep(i, N) cin >> H[i];
    l = r = 0;
    while(l < N){
        while(H[l] == 0 && l < N) l++;
        r = l;
        if(H[r] > 0 && r < N){
        while(H[r] > 0 && r < N){
            H[r]--;
            r++;
        }
        res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a, b, c, d, n , combinations, sum;

  while(scanf("%d", &n) != EOF){
    combinations = 0;
    for(a = 0; a <= 9; ++a){
      for(b = 0; b <= 9; ++b){
        for(c = 0; c <= 9; ++c){
          for(d = 0; d <= 9; ++d){
            sum = a + b + c + d;
            if(sum == n){
              ++combinations;
              break;
            }
          }
        }
      }
    }
    printf("%d\n", combinations);
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
bool f=false;
int num[10]={};
int N,cou=0,jj=0,sum=0;
while(scanf("%d",&N)!=EOF)
{
	jj=0;cou=0;sum=0;f=false;
do{
num[jj]=N%2;cou++;jj++;
N=N/2;
}while(N!=0);
for(int i=0;i<cou;i++)
{
if(num[i]==1){
	
	sum=pow( 2, (double) (i) );
	if(f==true)cout<<" ";
	cout<<sum;f=true;
}
}
cout<<endl;
}
return 0;
}

Measured memory_bytes: 1248
import sys

a,b,tt = 0,0,0
for i in range(int(input())):
    t,x,y = map(int,input().split())
    dif = abs(x - a) + abs(y - b)
    if (t - tt) % dif != 0:
        print("No")
        sys.exit()
    a,b,tt = x,y,t
print("Yes")    

Measured memory_bytes: 3060
#######################################
def csi(s=gets,spst=" ")
  if s==nil
    return 0
  end
  return s.chomp.split(spst).map(&:to_i)
end
def css(s=gets,spst=" ")
  if s == nil
    raise "nil!"
  end
  return s.chomp.split(spst).map(&:to_s)
end
def ml(n,datatype=:int)
  t = []
  case datatype
  when :int
    n.times do
      t.push(gets.to_i)
    end
  when :str
    n.times do
      t.push(gets.chomp.to_s)
    end
  else
    raise "n!"
  end
end
#######################################

h,n = csi
a = csi
if a.inject(:+) < h
  puts "No"
else
  puts "Yes"
end

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

int main() {
  int N, W;
  cin >> N >> W;
  vector<ll> w(N);
  vector<ll> v(N);
  rep(i, N) cin >> w[i] >> v[i];

  int max_v = 0;
  for(auto val : v) {
    max_v += val;
  }
  ll INF = 10e15;
  vector<vector<ll>> dp(N, vector<ll>(max_v+1, 10e15));

  int cur_v = 0;
  for(int i=0;i<N;i++) {
    cur_v += v[i];
    for(int j=0;j<=cur_v;j++) {
      // vに大して最小の重さを調べる
      if(i==0) {
        dp[0][j] = w[i];
        continue;
      }
      if(j > v[i]) dp[i][j] = min(dp[i-1][j-v[i]] + w[i], dp[i-1][j]);
      else dp[i][j] = min(dp[i-1][j], w[i]);
    }
  }

  int ans = 0;
  for(int j=0;j<=max_v;j++) {
    if(dp[N-1][j] <= W) ans = j;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 82456
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
    const double PI = 2.0 * acos(0);
    double a, b, x;
    cin >> a >> b >> x;
    double piv = atan2(b,a)/PI*180.0;
    double l = 0.0, r = 91;
    for(int i = 0; i < 200; i++){
        double mid = (l+r)/2;
        double afford;
        if(mid < piv){
            afford = a*a*b-a*a/2*a*tan(mid/180*PI);
        }else{
            afford = b*a/2*b*tan((90-mid)/180*PI);
        }
        if(afford >= x) l = mid;
        else            r = mid;
    }
    cout << fixed << setprecision(12) << l << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrep1(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;



typedef struct Node {
	int key;
	Node* parent;
	Node* left;
	Node* right;
} Node;

class BST {
private:
	Node root;

	/* Preorder */
	void PreO(Node* node)
	{
		cout << ' ' << node->key;
		if (node->left != NULL) PreO(node->left);
		if (node->right != NULL) PreO(node->right);
	}
	/* Inorder */
	void InO(Node* node)
	{
		if (node->left != NULL) InO(node->left);
		cout << ' ' << node->key;
		if (node->right != NULL) InO(node->right);
	}
	/* Postorder */
	void PostO(Node* node)
	{
		if (node->left != NULL) PostO(node->left);
		if (node->right != NULL) PostO(node->right);
		cout << ' ' << node->key;
	}
public:
	/* Constructor */
	BST()
	{
		root.key = 2000000001;
		root.parent = NULL;
		root.left = NULL;
		root.right = NULL;
	}
	/* Destructor */
	~BST()
	{

	}
	/* insert */
	void insert(int key)
	{
		if (root.key == 2000000001) {
			root.key = key;
			return;
		}

		Node* add = new Node;
		Node* parent = &root;

		add->key = key;
		add->left = NULL;
		add->right = NULL;

		while (parent != NULL) {
			add->parent = parent;
			if (add->key < parent->key) parent = parent->left;
			else parent = parent->right;
		}

		if (add->key < add->parent->key) add->parent->left = add;
		else add->parent->right = add;
	}
	/* Preorder */
	void Preorder()
	{
		PreO(&root);
		cout << endl;
	}
	/* Inorder */
	void Inorder()
	{
		InO(&root);
		cout << endl;
	}
	/* Postorder */
	void Postorder()
	{
		PostO(&root);
		cout << endl;
	}
};

int main()
{
	BST Tree;
	int n;
	string direction;
	int key;

	cin >> n;

	rep(i, n) {
		cin >> direction;
		if (direction == "insert") {
			cin >> key;
			Tree.insert(key);
		}
		else if (direction == "print") {
			Tree.Inorder();
			Tree.Preorder();
		}
	}

	return 0;
}


Measured memory_bytes: 26608
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	MOD = 1000*1000*1000 + 7
	N   = 3*1000*1000*10 + 10
)

type pos struct {
	x int
	y int
}

var field [][]int
var path [][]int
var waiting []pos

var direct = []pos{
	pos{x: 0, y: 1},
	pos{x: 0, y: -1},
	pos{x: 1, y: 0},
	pos{x: -1, y: 0},
}

func search(H, W int) {
	for {
		if len(waiting) == 0 {
			break
		}

		t := waiting[0]
		waiting = waiting[1:]

		for _, d := range direct {
			if 0 <= t.x+d.x && t.x+d.x < W &&
				0 <= t.y+d.y && t.y+d.y < H {

				if field[t.y+d.y][t.x+d.x] == -1 {
					continue
				}

				if path[t.y+d.y][t.x+d.x] > path[t.y][t.x]+1 {
					path[t.y+d.y][t.x+d.x] = path[t.y][t.x] + 1
					if field[t.y+d.y][t.x+d.x] != 0 {
						field[t.y+d.y][t.x+d.x] = 0
						waiting = append(waiting, pos{x: t.x + d.x, y: t.y + d.y})
					}
				}
			}
		}
	}
}

func main() {
	in := IOInitialize()
	H, W := Int(in), Int(in)
	field = make([][]int, H)
	path = make([][]int, H)
	waiting = make([]pos, 0, H*W+1099)
	count := 0
	//input
	for i := 0; i < H; i++ {
		in.Scan()
		field[i] = make([]int, W)
		path[i] = make([]int, W)
		str := in.Text()
		for jj := range str {
			tmp := -1
			if str[jj] == 46 {
				tmp = 1
				count++
			}
			field[i][jj] = tmp
			path[i][jj] = MOD
		}
	}

	waiting = append(waiting, pos{x: 0, y: 0})
	path[0][0] = 1
	search(H, W)

	if path[H-1][W-1] == MOD {
		fmt.Println(-1)
		return
	}

	fmt.Println(count - path[H-1][W-1])

}

//////////
//
//

func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}

func IntArray(s *bufio.Scanner, size int) []int {
	deepArray := make([]int, size)
	for i := range deepArray {
		deepArray[i] = Int(s)
	}
	return deepArray
}

func GraphSetByEdge(s *bufio.Scanner, v int) [][]int {
	g := make([][]int, v)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for xxNonUsedInLoopI := 0; xxNonUsedInLoopI < v-1; xxNonUsedInLoopI++ {
		a, b := Int(s)-1, Int(s)-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	return g
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    ll h,w;
    cin>>h>>w;

    ll ans=0;

    if(w==1 || h==1)ans=1;
    else if(w%2==0 || h%2==0)ans=h*w/2;
    else ans=(w+1)*(h+1)/4 + (w-1)*(h-1)/4;

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const int N=1e6+5;
using namespace std;
int boom[N];

int primes[N],cnt;
int st[N];
void ola(int n)
{
    for (int i = 2; i <= n; i ++ )
    {
        if (st[i] == 0) primes[cnt ++ ] = i;//将质数存到primes中
        for (int j = 0; primes[j] <= n / i; j ++ )//要确保质数的第i倍是小于等于n的。
        {
            st[primes[j] * i] = 1;
            if (i % primes[j] == 0) break;
        }
    }
}
int main()
{
    ola(2000);
    int n;cin>>n;
    for(int i=0;i<n;i++)
    {
        int t;cin>>t;
        for(int i=0;i<cnt;i++)
        {
            int tot=0;
            while(t%primes[i]==0)
            {
                t/=primes[i];
                tot=1;
            }
            if(tot) boom[primes[i]]++;
        }
        if(t>1) boom[t]++;
    }
    int st=0;
    for(int i=1;i<1000005;i++)
    {
        if(boom[i]>=2) st++;
        if(boom[i]==n)
        {
            cout<<"not coprime"<<endl;
            return 0;
        }
    }
    if(st==0)
    {
        cout<<"pairwise coprime"<<endl;
    }
    else
        cout<<"setwise coprime"<<endl;
    return 0;
}


Measured memory_bytes: 7476
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static long mod = 1000000007;

    public static void main(String[] args) {
    	char[] L = sc.next().toCharArray();
    	long ans = power(3, L.length - 1);
    	long tmp = 2;
    	for(int i=1; i<L.length; i++) {
    		if(L[i] == '1') {
    			ans = (ans + power(3, L.length - i - 1) * tmp % mod ) % mod;
    			tmp = tmp * 2 % mod;
    		}
    	}
    	System.out.println((ans + tmp) % mod);
    }

    static long power(long m , long n){
    	if(n == 0) {
    		return 1;
    	}else if(n == 1){
            return m;
        }else if(n % 2 == 0){
            long s = power(m, n/2);
            return ( (s % mod) * (s % mod) ) % mod;
        }else{
            return ( (m % mod) * (power(m, n-1) % mod) ) % mod;
        }
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 22612
#include <iostream>

using namespace std;

class Dice{
public:
     //  コンストラクタ
     Dice();
     //  デストラクタ
     ~Dice();
     //  メソッド
     int east();
     int west();
     int south();
     int north();
     int side();
     void set(int sai[6]);
     int look(int men);
private:
     int me[7];
};

//  コンストラクタ
Dice::Dice()
{
}
//  デストラクタ
Dice::~Dice()
{
}
void Dice::set(int sai[6])
{
    int i;
    for(i = 0;i<6; i++) {
//        cout << sai[i] << endl;
        me[i+1] = sai[i];
    }
}
int Dice::east()
{
    int tmp = me[4];
    me[4] = me[6];
    me[6] = me[3];
    me[3] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::west()
{
    int tmp = me[3];
    me[3] = me[6];
    me[6] = me[4];
    me[4] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::south()
{
    int tmp     = me[5];
    me[5] = me[6];
    me[6] = me[2];
    me[2] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::north()
{
    int tmp     = me[2];
    me[2] = me[6];
    me[6] = me[5];
    me[5] = me[1];
    me[1] = tmp;
    return(tmp);
}
int Dice::side()
{
    int tmp     = me[3];
    me[3] = me[5];
    me[5] = me[4];
    me[4] = me[2];
    me[2] = tmp;
    return(tmp);
}
int Dice::look(int men)
{
    return(me[men]);
}
int juge(Dice d, Dice e) {
    int i, l, t, f;

    t = e.look(1);
    for (l = 0; l < 3; l++) {
        if (t == d.east())  break;
        if (t == d.north()) break;
    }
    if (l < 3) {
        f = e.look(2);
        l = d.look(2);
        i = 4;
        while (l != f) {
            l = d.side();
            if(i-- < 0) {
                return 0;
            }
        }
        for (l = 0; l < 3; l++) {
            if (e.east() != d.east())  break;
            if (e.north() != d.north()) break;
        }
        if (l < 3) {
            return 0;
        } else { 
            return 1;
        }
    }
    return 0;
}

int main() {
    int sai[6];
    int i, l, j, n, t, f, flg=0;
    char c;

    cin >> n;
    for(i =0; i < 6; i++){
        cin >> l;
        sai[i] = l;
    }
    Dice e;
    Dice d;
    e.set(sai);
    for(j = 1; j < n; j++) {
        for(i =0; i < 6; i++){
            cin >> l;
            sai[i] = l;
        }
        d.set(sai);
        flg += juge(d, e);
    }
    if (flg == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    } 
    return 0;
}



Measured memory_bytes: 3096
import java.util.Scanner;

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

    for (int i = 1; i <= 1000; i++) {
      if (K * i >= A && K * i <= B) {
        System.out.println("OK");
        return;
      }
    }
    System.out.println("NG");

  }
}


Measured memory_bytes: 35708
#include <stdio.h>

int main(){
  int n,i,m,a[200005],b[200005],c=1,d[200005],e;
  long k;
  scanf("%d",&n);
  scanf("%ld",&k);
  for(i=0;i<n;i++){
    scanf("%d",&e);
    a[i]=e-1;
    d[i]=0;
  }
  b[0]=0;
  d[0]=1;
  for(i=a[0];d[i]==0;i=a[i]){
    b[c]=i;
    d[i]=1;
    c++;
  }
  e=1;
  m=i;
  d[0]=m;
  for(i=a[i];i!=m;i=a[i]){
    d[e]=i;
    e++;
  }
  if(k>=(long)c){
    printf("%d",d[(k-(long)c)%(long)e]+1);
  }else{
    printf("%d",b[k]+1);
  }
  return(0);
}


Measured memory_bytes: 3960
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = Integer.parseInt(sc.next());
    }
    int count = 0;
    
    uncode: while(true){
      //if((a[0] + a[1] + a[2]) % 2 != 0){
      for(int i = 0; i < n; i++){
        if(a[i] % 2 != 0){
          break uncode;
        }
        a[i] = a[i] / 2;
      }
      count++;
    }
    System.out.println(count);
  }
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input =new BufferedReader(new InputStreamReader(System.in));
        String[] inputs = input.readLine().split(" ");
        String answer ="";
        for (int i = 0; i < 3; i++) {
            answer+=inputs[i].substring(0,1).toUpperCase();
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const ll MOD=998244353;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<P> a;
    if (n%2==0) {
        rep(i,n) {
            repr(j,i+1,n) {
                if (i+j+2!=n+1) a.push_back({i+1,j+1});
            }
        }
    } else {
        rep(i,n) {
            repr(j,i+1,n) {
                if (i+j+2!=n) a.push_back({i+1,j+1});
            }
        } 
    }
    int m=a.size();
    cout << m << endl;
    rep(i,m) cout << a[i].first << ' ' << a[i].second << endl;

    return 0;

}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	vector<int> a(n), b(n), c(n);
	FOR(i, n) cin >> a[i];
	FOR(i, n) cin >> b[i];
	FOR(i, n) cin >> c[i];
	sort(ALL(a));
	sort(ALL(b));
	sort(ALL(c));
	ll cnt = 0;
	vector<ll> bb(n);
	for (int i = n-1; i >= 0; i--) {
		bb[i] = (ll)(c.end()-upper_bound(ALL(c), b[i]));
		bb[i] += (i==n-1 ? 0LL : bb[i+1]);
	}
	FOR(i, n) {
		cnt += bb[(int)(upper_bound(ALL(b), a[i])-b.begin())];
		// cout << cnt << endl;
		// auto itr = upper_bound(ALL(b), a[i]) - b.begin();
		// for (int j = itr; j < n; j++) {
		// 	cnt += (ll)(c.end()-upper_bound(ALL(c), b[j]));
		// }
		// cnt += lower_bound(ALL(c), *lower_bound(ALL(b), a[i]))-c.begin();
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 999999999
using namespace std;

int main(){
          int n;
          cin >> n;
          int t[n];
          REP(i,n)  cin >> t[i];
          int m;
          cin >> m;
          int p[m],x[m];
          REP(i,m)  cin >> p[i] >> x[i];

          int total=accumulate(t,t+n,0);

          REP(i,m){
                    int ans=0;
                    ans+=total;
                    ans-=t[p[i]-1];
                    ans+=x[i];
                    cout << ans << endl;
          }
          return 0;
}


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

int main() {
	int A;
	int B;
  	int k=1;
  	int n=0;
	cin>>A;
	cin>>B;
  	while(k < B){
      	k = k-1 + A;
      n++;
    }
  cout<<n<<endl;
      
}


Measured memory_bytes: 256