akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = (int) 1e9 + 7;
const double EPS = 1e-9;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.length();
  vector<int> v(N, 0);
  vector<int> RL;
  int init = 0;
  while (true) {
    auto pos = S.find("RL", init);
    if (pos != std::string::npos) {
      RL.pb((int) pos);
      init = (int) pos + 1;
    } else break;
  }

  REP(i, N) {
    if (S[i] == 'R') {
      auto itr = lower_bound(ALL(RL), i);
      int d = *itr - i;
      if (d % 2 == 0) ++v[*itr];
      else ++v[*itr + 1];
    } else {
      auto itr = --upper_bound(RL.begin(), RL.end(), i);
      int d = abs(*itr - i);
      if (d % 2 == 0) ++v[*itr];
      else ++v[*itr + 1];
    }
  }

  for (auto e: v) {
    cout << e << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1864
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj0104().doIt();
	}
	class aoj0104{
		int map[][];
		char ctr[] = {'>','<','^','v','.'};
		int xm[] = {1,-1,0,0};
		int ym[] = {0,0,-1,1};
		String ans = "";
		String dfs(int y,int x){
			if(map[y][x] == 4)ans = x+" "+y;
			else if(map[y][x] == -1)ans = "LOOP";
			for(int i = 0;i < 4;i++){
				if(map[y][x] == i){
					map[y][x] = -1;
					dfs(y+ym[i],x+xm[i]);
				}
			}
			return ans;
		}
		void doIt() {
			while(true){
				int y = sc.nextInt();
				int x = sc.nextInt();
				if(y + x == 0)break;
				map = new int [y][x];
				for(int i = 0;i < y;i++){
					String str = sc.next();
					char[] c = str.toCharArray();
					for(int j = 0;j < x;j++){
						for(int k = 0;k < 5;k++){
							if(c[j] == ctr[k])map[i][j] = k;
						}
					}
				}
				System.out.println(dfs(0,0));
			}
		}
	}
}

Measured memory_bytes: 22020
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>

#include <cfenv>
#include <cmath>
typedef long long int ll;

using namespace std;

int main()
{

    ll X;


    cin >> X;


    ll mone =100;


    ll year = 0;


    while(1){


        year++;


        mone =mone*(1.01);
        if(mone >=X){


            cout << year << endl;

            break;





        }
    }

    return 0;



}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

ll N;
string S, T;
map<pair<string, string>, pair<ll, ll>> mp;
void dfs(bool isS, string s0, string s1, ll cnt)
{
  if (cnt == N)
  {
    if (isS)
      mp[make_pair(s0, s1)].first++;
    else
      mp[make_pair(s0, s1)].second++;
    return;
  }

  dfs(isS, s0 + ((isS) ? S : T).at(cnt), s1, cnt + 1);
  dfs(isS, s0, s1 + ((isS) ? S : T).at(cnt), cnt + 1);
}

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

  S = s0.substr(0, N), T = s0.substr(N, N);
  reverse(T.begin(), T.end());

  dfs(true, "", "", 0);
  dfs(false, "", "", 0);

  ll ans = 0;
  for (auto x : mp)
  {
    //cerr << x.first.first << " " << x.first.second << " ";
    //cerr << x.second.first << " " << x.second.second << endl;
    ans += x.second.first * x.second.second;
  }
  cout << ans << endl;
}

Measured memory_bytes: 96000
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int i,n,t=0,p=INT_MAX,m,l,q=0;
    cin>>n;
   int ara[n];
   for(i=0;i<n;i++){
      cin>>ara[i];
      p=min(p,ara[i]);
      if(ara[i]<=p){
        q++;
      }
   }
   cout<<q<<endl;



}




Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll N, M;
    cin >> N;
    vector<ll> D(N);
    rep(i, N) cin >> D[i];
    cin >> M;
    vector<ll> T(M);
    rep(i, M) cin >> T[i];

    map<ll, ll> cd, ct;
    rep(i, N) { cd[D[i]]++; }
    rep(i, M) { ct[T[i]]++; }

    // for (auto elem : cd) {
    //     cout << elem.first << " " << elem.second << endl;
    // }
    // cout << "---" << endl;
    // for (auto elem : ct) {
    //     cout << elem.first << " " << elem.second << endl;
    // }

    rep(i, M) {
        // cout << cd[T[i]] << " / " << ct[T[i]] << endl;
        if (cd[T[i]] < ct[T[i]]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 31260
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 205050

ll n;
ll p;
ll a[N];
ll x[N];
ll b[N],c[N],sum[N];
main(){
    int n=in(),q=in();
    rep2(i,1,n)a[i]=in();
    rep(i,q)x[i]=in();
    b[1]=a[1];
    c[2]=a[2];
    sum[1]=a[1];sum[2]=a[1]+a[2];
    rep2(i,3,n){
        if(i%2)b[i]=b[i-2]+a[i];
        else c[i]=c[i-2]+a[i];
        sum[i]=sum[i-1]+a[i];
    }
    rep(iii,q){
        ll t=x[iii];
        int l=-1,r=INF;
        while(l<r-1){
            ll mid=(l+r)/2;
            int rr=upper_bound(a+1,a+(n+1),t+mid)-a;
            int lll=lower_bound(a+1,a+(n+1),t-mid)-a;
            if(n-rr+1>=rr-lll){
                l=mid;
            }
            else r=mid;
        }
        if(l==-1){
            cout<<b[n]+c[n]<<endl;
            continue;
        }
        int rr=upper_bound(a+1,a+(n+1),t+l)-a;
        int lll=lower_bound(a+1,a+(n+1),t-l)-a;
        int cnt=n-rr+1;     
        cout<<sum[n]-sum[rr-1]+(b[n-2*cnt]+c[n-2*cnt])<<endl;;
    }
}

Measured memory_bytes: 7808
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi co(n+1);
	rep(i,n)co[in[i]]++;
	int sum=0;
	rep(i,n+1)sum+=co[i]*(co[i]-1)/2;
	rep(i,n){
		int out=sum;
		out-=co[in[i]]-1;
		cout<<out<<endl;
	}
}






Measured memory_bytes: 5760
def DP():
    n,W = map(int, input().split(' '))
    WV = (map(int, input().split(' ')) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in WV:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(DP())




Measured memory_bytes: 7668
N=int(input())
a=list(map(int,input().split()))
d2=0
d4=0
dn=0
for i in a:
    if i%4==0:
        d4+=1
    elif i%2==0:
        d2+=1
    else:
        dn+=1
print('Yes' if d4>=dn or (dn-d4==1 and d2==0) else 'No')

Measured memory_bytes: 14252
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[][] points = new int[N][3];
    int[] max = new int[]{0, 0, -1};
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 3; j++) {
        points[i][j] = scanner.nextInt();
        if (points[i][2] > max[2]) {
          max = points[i];
        }
      }
    }

    for (int cxx = max[0]; cxx <= max[0] + 100; cxx++) {
      int cx = cxx;
      if (cx > 100) cx -= 101;
      for (int cyy = max[1]; cyy <= max[1] + 100; cyy++) {
        int cy = cyy;
        if (cy > 100) cy -= 101;
        int H = -1;
        boolean found = true;
        for (int i = 0; i < N; i++) {
          int[] pt = points[i];
          int x = pt[0] - cx;
          int y = pt[1] - cy;
          int h = pt[2];
          if (h == 0) continue;
          final int hh = h + Math.abs(x) + Math.abs(y);
          if (H < 0) {
            H = hh;
          } else if (H != hh) {
            found = false;
            break;
          }
        }
        if (found) {
          System.out.printf("%d %d %d\n", cx, cy, H);
          return;
        }
      }
    }
  }
}


Measured memory_bytes: 26068
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int k = scan.nextInt();

        if(k < a) {
        	System.out.println(k);
        }else if(k <= a + b){
        	System.out.println(a);
        }else {
        	System.out.println(a * 2 + b - k);
        }
    }
}

Measured memory_bytes: 27032
n = int(input())
s = input()

s = s.rstrip('#')
s = s.lstrip('.')

def seek(n, s):
    turn_to_black = s.count('.')
    current_min = turn_to_black
    turn_to_white = 0

    if current_min == 0 or current_min == len(s):
        return(0)
    # seek minimum turns to create "^\.*#*$" 
    for i in range(len(s)):
        if s[i] == '#':
            turn_to_white +=1
        else:
            turn_to_black -=1
        current_min = min(current_min, turn_to_black + turn_to_white)
    return current_min
print(seek(n, s))


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

using ll=long long;

int main() {
  vector<int> a(10);
  rep(i,0,4) {
    int N; cin >>N;
    a[N]++;
  }
  if (a[1]==1 and a[9]==1 and a[7]==1 and a[4]==1) {
    cout <<"YES" <<endl;
  } else {
    cout <<"NO" <<endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define  boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb2l(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;

#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define  mat vector<vector<ll>>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
long long int ncr(int n, int r){
  // space O(1) time O(min(r,n-r));
       if(n-r<r){
           r=n-r;
       }
        long long int res=1;
        for(int i=0;i<r;i++){
           res*=(n-i);
            res/=(i+1);
        }
        return res;
    }

void solve(){
 ll n;
 cin>>n;
 map<string,ll>mp;
 string str;
 ll mx=0;
 fr(i,0,n){
     cin>>str;
     mp[str]++;
     mx=max(mx,mp[str]);

 }
 for(auto it=mp.begin();it!=mp.end();it++){
     if(it->second==mx)
     cout<<it->ff<<endl;
 }
  }
int main(){
    ll t=1;
   // cin>>t;
    while(t--){
        solve();
     //   cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 25344
# frozen_string_literal: true

n = gets.to_i
scaffs = gets.split.map(&:to_i)

costs = Array.new(n, Float::INFINITY)
costs[0] = 0

(0...n - 1).each do |i|
  cost1 = costs[i] + (scaffs[i] - scaffs[i + 1]).abs
  costs[i + 1] = [costs[i + 1], cost1].min

  if i + 2 < n
    cost2 = costs[i] + (scaffs[i] - scaffs[i + 2]).abs
    costs[i + 2] = [costs[i + 2], cost2].min
  end
end

puts costs.last


Measured memory_bytes: 11404
import * as fs from 'fs';

namespace AtCoder.abc162 {

    export class Program {

        constructor(private readonly args: string[]) {
        }

        /**
         * in
         *
         * out
         *
         */
        main(this: Program): void {
            const n: string = this.args[0];

            let flg = false;
            n.split('').some((x) => {
                if (x === '7') flg = true;
            });

            console.log(flg ? 'Yes' : 'No');

        }
    }
}

const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg: AtCoder.abc162.Program = new AtCoder.abc162.Program(args);
prg.main();


Measured memory_bytes: 29600
n, k = map(int,input().split())
xs = list(map(int,input().split()))
ans = 1000000000000
if n == 1:
    print(xs[0])
    quit()
if k == 1:
    print(min(list(map(abs,xs))))
    quit()
for i in range(n-k+1):
    a,b = xs[i],xs[i+k-1]
    if b <= 0:
        if ans > (-1 * a):
            ans = (-1 * a)
    elif a >= 0:
        if ans > b:
            ans = b
    else:
        if min(b * 2 - a , b - 2 * a) < ans:
            ans = min(b * 2 - a , b - 2 * a)
print(ans)


Measured memory_bytes: 14128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt(), d = scanner.nextInt();
			System.out.println(Math.max(a * b, c * d));
		}
	}
}


Measured memory_bytes: 35804
#include <stdio.h>

bool BinarySearch(int S[], int n, int t){
    int left = 0;
    int right = n;
    int mid;
    int i = 0;
    while(left < right){
        mid = (left + right) / 2;
        if(t == S[mid]) return true;
        else if(t < S[mid]) right = mid;
        else left = mid + 1;
    }

    return false;
}

int main (void){
    int n, q, t;
    int c = 0;
    bool second_time;

    scanf("%d", &n);
    int S[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &S[i]);
    }

    scanf("%d", &q);
    int same_number[q];
    for(int i = 0; i < q; i++){
        scanf("%d", &t);
        second_time = false;
        for(int j = 0; j < c; j++){
            if(same_number[j] == t) second_time = true;
        }
        if(BinarySearch(S, n, t) && !second_time){
            same_number[c] = t;
            c++;
        }
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

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

typedef long long ll;

using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string ans;
    if (b - a == c - b) ans = "YES";
    else ans = "NO";
    cout << ans << endl;
}


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

using namespace std;
typedef long long int ll;
int main() {
    
    ll n, d, x[200001], y[200001], i, dap=0;
    cin>>n>>d;
    for(i=1;i<=n;i++)
    {
    scanf("%lld %lld", &x[i], &y[i]);
    dap+=((d*d)>=(x[i]*x[i]+(y[i]*y[i])));
    }
    cout<<dap;
    
    return 0;
}

Measured memory_bytes: 6784
using ll=long long;using ull=unsigned long long;
#include<limits>
namespace pcl{template<typename T>constexpr T TNF=std::numeric_limits<T>::max()/2;constexpr int INF=TNF<int>;constexpr ll LNF=TNF<ll>;constexpr double DNF=TNF<double>;constexpr double EPS=1e-8;constexpr int P7=1'000'000'007;constexpr int DX[]={1,0,-1,0,1,1,-1,-1};constexpr int DY[]={0,1,0,-1,-1,1,1,-1};}
#include<algorithm>
#include<cmath>
#include<iostream>
namespace pcl{template<typename T>void updmax(T&a,T const&b){a=std::max(a,b);}template<typename T>void updmin(T&a,T const&b){a=std::min(a,b);}template<typename T,typename U,typename V>bool in_range(T const&begin,U const&mid,V const&end){return begin<=mid&&mid<end;}template<typename T,typename U,typename V>bool in_range(T const&begin,std::initializer_list<U>list,V const&end){auto p=std::minmax_element(list.begin(),list.end());return begin<=*p.first&&*p.second<end;}template<typename T,typename U,typename V>bool in_range_strict(T const&begin,std::initializer_list<U>list,V const&end){if(!std::is_sorted(list.begin(),list.end()))return false;return in_range(begin,list,end);}template<typename T>inline T cget(){T x;std::cin>>x;return x;}}
#include<iostream>
#include<vector>
namespace pcl{template<typename T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){os<<'[';for(size_t i=0;i<v.size();i++){if(i!=0)os<<",";os<<v[i];}os<<']';return os;}template<typename T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(size_t i=0;i<v.size();i++)is>>v[i];return is;}}
#include<bits/stdc++.h>
using namespace std;using namespace pcl;int main(){int N;cin>>N;vector<int>d(N);cin>>d;sort(d.begin(),d.end());int mi=d[N/2-1];int ma=d[N/2];cout<<ma-mi<<endl;}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll int, ll int>
#define ff first
#define ss second
#define debug(n) cout << "DEBUG1 " << n << "\n";
#define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n";
#define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n";
#define debug4(n, m, x, y) cout << "DEBUG4 " << n << ' ' << m << ' ' << x << ' ' << y << "\n";
#define ss_def stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int)
#define upzero(n) rrn < 0) n = 0
#define alive(n) cout << "Alive here: checkpoint " << n << endl
#pragma GCC optimize("Ofast")
using namespace std;
void yes() {
    cout << "Yes\n";
    return;
}
void no() {
    cout << "No\n";
    return;
}
const int mxP = 1e6 + 1;
int ck[mxP];
void prime_fact(int n) {
	if (n % 2 == 0) {
		ck[2]++;
		while (n % 2 == 0) {
			n /= 2;
		}
	}
	for (int i = 3;i <= ceil(sqrt(n));i += 2) {
		if (n % i == 0) {
			ck[i]++;
			while (n % i == 0) {
				n /= i;
			}
		}
	}
	if (n > 2) {
		ck[n]++;
	}
	return;
}
void solve(int case_no) {
    // implementation
    int n;
    cin >> n;
    int a[n];
    int maxi = 0;
    for (int i = 0;i < n;i++) {
    	cin >> a[i];
    	maxi = max(maxi, a[i]);
    	prime_fact(a[i]);
	}
	bool ck1 = true, ck2 = true;
	for (int i = 2;i <= maxi;i++) {
		if (ck[i] > 1) ck1 = false;
		if (ck[i] == n) ck2 = false;
	}
	if (ck1) cout << "pairwise coprime\n";
	else if (ck2)  cout << "setwise coprime\n";
	else cout << "not coprime\n";
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    srand(time(NULL));
    int t = 1;
//    cin >> t;
    for (int i = 1;i <= t;i++) solve(i);
}
/*

*/

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

int main()
{
  int N,a;
  
  cin >> N;
  
  if(N%2 == 0)
  {a=N/2;}
  
  else if(N%2 ==1)
  {a = N/2 +1;}
  
  cout << a <<endl;
}

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

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

fn left(node_id: usize) -> usize {
    return node_id * 2;
}

fn right(node_id: usize) -> usize {
    return node_id * 2 + 1;
}

fn max_heapify(a: &mut Vec<i64>, node_id: usize) {
    let left = left(node_id);
    let right = right(node_id);
    let mut largest: usize;
    if left <= (a.len() - 1) && a[left] > a[node_id] {
        largest = left;
    } else {
        largest = node_id;
    }
    if right <= (a.len() - 1) && a[right] > a[largest] {
        largest = right;
    }

    if largest != node_id {
        a.swap(node_id, largest);
        max_heapify(a, largest);
    }
}

fn build_max_heap(a: &mut Vec<i64>) {
    for i in (1..(((a.len() - 1) / 2) + 1)).rev() {
        max_heapify(a, i);
    }
}

fn main() {
    let h: usize = read();
    let mut a: Vec<i64> = vec![0];
    for _ in 0..h {
        let number: i64 = read();
        a.push(number);
    }
    build_max_heap(&mut a);
    for (index, value) in a.iter().enumerate() {
        if index == 0 {
            continue;
        } else {
            print!(" {}", value);
        }
    }
    println!();
}



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

int main(){
  int n; 
  cin >> n;
  
  vector<int> p(n);
  
  for(int i=0; i<n; i++){
    cin >> p.at(i);
  }
  
  int count;
  count=0;
  
  for(int i=0; i<n-2; i++){
    if(p.at(i)<p.at(i+1) and p.at(i+1)<p.at(i+2)){
      count++;
    }
    if(p.at(i)>p.at(i+1) and p.at(i+1)>p.at(i+2)){
      count++;
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int md = 1e9+7;
const int sz = 2e5;
// int A[sz+1];
// int F[sz+1];

int A[sz+1];
int dp[sz+2][2];

void solve(){
	string s;cin>>s;
    int l = s.size();
    if(s[l-1]=='s'){
        s += "es";
    }else{
        s += "s";
    }
    cout<<s<<endl;


return;
}



int32_t main()
{
    IOS;
    // A[0] = 0;
    // F[0] = 1;

    // for (int i = 1; i <= sz; ++i)
    // {
    // 	A[i] = A[i-1]+i;
    // 	F[i] = F[i-1]*i;
    // }

    // for(int i=0;i<10;i++){
    // 	cout<<A[i]<<" ";
    // }
    // cout<<endl;
    // for(int i=0;i<10;i++){
    // 	cout<<F[i]<<" ";
    // }
    // cout<<endl;    
    // coust<<"A and F is filled"<<endl;
    // int t;
    // cin >> t;
    // while (t--) 
        solve();
    return 0;
        

    
}



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);

//int dxy[5] = {0, 1, 0, -1, 0};
// assign

bool search(vector< vvi > &board, int m);
void push(vector< vvi > &board, int x, int y, int num);

signed main()
{
    Int(n);
    Int(m);
    Int(p);
    while (n) {
        vector< vvi > board(n, vvi(n, vi(n, 0)));
        bool fl = false;
        rep(i, p) {
            int a, b;
            cin >> a >> b;
            push(board, a-1, b-1, i%2 + 1);
            if (!fl && search(board, m)) {
                cout << ((i%2) ? "White " : "Black ") << i+1 << endl;
                fl = true;
            }
            // kuro = 1, shiro = 2, nashi = 0
        }
        if (!fl) {
            cout << "Draw" << endl;
        }
        cin >> n >> m >> p;
    }
    return 0;
}

void push(vector< vvi > &board, int x, int y, int num)
{
    rep(i, board.size()) {
        if (board[x][y][i]) {
            continue;
        } else {
            board[x][y][i] = num;
            break;
        }
    }
}

bool search(vector< vvi > &board, int m)
{
    int n = board.size(), ans = 0, num;
    int dx[13] = {1, 0, 0, 1, 0, 1, -1, 0, 1, 1, 1, 1, -1};
    int dy[13] = {0, 0, 1, 1, 1, 0, 1, -1, 0, 1, 1, -1, 1};
    int dz[13] = {0, 1, 0, 0, 1, 1, 0, 1, -1, 1, -1, 1, 1};

    rep(i, 13) {
        rep(j, n) {
            rep(k, n) {
                rep(l, n) {
                    int x = j, y = k, z = l;
                    num = board[x][y][z]; ans = 1;
                    x += dx[i]; y += dy[i]; z += dz[i];
                    while (0 <= x && x < n &&
                            0 <= y && y < n &&
                            0 <= z && z < n) {
                        if (board[x][y][z] == num) {
                            ans++;
                        } else {
                            ans = 1;
                            num = board[x][y][z];
                        }
                        if (ans >= m && num) {
                            return true;
                        }
                        x += dx[i]; y += dy[i]; z += dz[i];
                    }
                }
            }
        }
    }
    return false;
}

Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 998244353;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    int solve(int n, int k, vector<int>& arr) {
        //vector<vector<vector<int64>>> dp(n + 1, vector<vector<int64>>(k + 1, vector<int64>(3)));
        int64 dp[n + 1][k + 1][3] = {};
        dp[0][0][0] = 1;
        for(int i = 0; i < n; ++i) {
            for(int s = 0; s <= k; ++s) {
                (dp[i + 1][s][0] += dp[i][s][0]) %= mod;
                (dp[i + 1][s][1] += dp[i][s][0] + dp[i][s][1]) %= mod;
                (dp[i + 1][s][2] += dp[i][s][0] + dp[i][s][1] + dp[i][s][2]) %= mod;
                if(s + arr[i] <= k) {
                    (dp[i + 1][s + arr[i]][1] += dp[i][s][0] + dp[i][s][1]) %= mod;
                    (dp[i + 1][s + arr[i]][2] += dp[i][s][0] + dp[i][s][1]) %= mod;
                }
            }
        }
        return dp[n][k][2];
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(int i = 0; i < n; ++i) cin >> arr[i];
    Solution sol;
    auto ret = sol.solve(n, k, arr);
    cout << ret << endl;
}

Measured memory_bytes: 211328
import java.util.Scanner;

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

		int result = 0;
		double min = Double.MAX_VALUE;
		for (int i=1; i<=n; i++) {
			h = sc.nextInt();
			if (Math.abs(t-h*0.006-a) < min) {
				min = Math.abs(t-h*0.006-a);
				result = i;	
			}
		}
		System.out.print(result);
    }
}

Measured memory_bytes: 38776
#include <cstdio>
#define mod 100000

int n, m, ans, p, t;
int s[100000];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i < n; i++) scanf("%d", &s[i]);
	for(int i = 1; i < n; i++) s[i] += s[i-1];
	for(int i = 0; i < m; i++){
		scanf("%d", &t);
		if(t > 0){
			ans += s[p+t]-s[p];
		} else{
			ans += s[p]-s[p+t];
		}
		p += t;
		ans %= mod;
	}
	printf("%d\n", ans);
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n;
string s, l[5];
int main(){
	cin >> n >> s;
	l[0]="SS";
	l[1]="SW";
	l[2]="WS";
	l[3]="WW";
	for(int i=0;i<4;i++){
		for(int j=1;j<n-1;j++){
			if((s[j]=='o'&&l[i][j]=='S')||(s[j]=='x'&&l[i][j]=='W')){
				l[i] += l[i][j-1];
			}else{
				l[i] += 'S'+'W'-l[i][j-1];
			}
		}
		if((s[n-1]=='o'&&l[i][n-1]=='S')||(s[n-1]=='x'&&l[i][n-1]=='W')){
			if(l[i][0]!=l[i][n-2]) continue;
		}else{
			if(l[i][0]!='S'+'W'-l[i][n-2]) continue;
		}
		if((s[0]=='o'&&l[i][0]=='S')||(s[0]=='x'&&l[i][0]=='W')){
			if(l[i][1]!=l[i][n-1]) continue;
		}else{
			if(l[i][1]!='S'+'W'-l[i][n-1]) continue;
		}
		cout << l[i] << endl;
		return 0;
	}
	cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 100000
typedef long long L;
int n,k;
L T[MAX];
int check(L P){
  int i=0,j;
  L s;
  for(j=0;j<k;j++){
     s=0;
    while(s+T[i]<=P){
      s+=T[i];
      i++;
      if(i==n)return n;
    }
  }
  return i;
}
  
int solve(){
  L left=0,right=MAX*10000,mid;
  int v;
  while(right>left+1){
    mid=(right+left)/2;
    v=check(mid);
    if(v>=n)right=mid;
    else left=mid;
  }
  return right;
}
int main(){
  int i;
  L ans;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++)scanf("%d",&T[i]);
  // ans=solve();
  printf("%llu\n",solve());
  return 0;
}

Measured memory_bytes: 2532
s = list(input())
t = list(input())

value = 1000
for i in range(len(s) - len(t) + 1):
    num = 0
    for j in range(len(t)):
        if(t[j] != s[i+j]):
            num += 1
    if num < value:
        value = num
print(value)

Measured memory_bytes: 9032
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

long apple(long a)
{
    return a * 3;
}

void main()
{
    long a, p;
    scan(a, p);
    p += apple(a);
    writeln(p / 2);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define INF 10000000000000000
#define MOD 1000000007
using namespace std;


int main(){
    ll ans=0;
    int N;
    cin >> N;
    ll A[N],B[N];
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
    }
    for(int i=N-1; i>=0; i--){
        A[i]+=ans;
        ll temp=A[i]%B[i];
        if(temp!=0){
            temp=B[i]-temp;
        }
        ans+=temp;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI 3.1415926535897932384626433832795028841971693993
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    int n,k,r,s,p,ans=0;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    vector<bool> dat(n,true);
    rep(i,n){
        if(i-k>=0){
            if(t[i-k]==t[i]&&dat[i-k]){
                dat[i]=false;
                continue;
            }
        }
        if(t[i]=='r') ans+=p;
        else if(t[i]=='s') ans+=r;
        else ans+=s;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3740
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int ans, x;
int a, b, c;
int vis[55][55][55];
void dfs(int u, int v, int w, int sum) {
    if (sum == x) {
        ans++;
        vis[u][v][w] = 1;
        return ;
    }
    vis[u][v][w] = 1;
    if (u < a && !vis[u+1][v][w] && sum + 500 <= x) 
        {
            dfs(u+1, v, w, sum+500);
            //vis[u+1][v][w] = 0;
        }
    if (v < b && !vis[u][v+1][w] && sum + 100 <= x)
        {
            dfs(u, v+1, w, sum+100);
            //vis[u][v+1][w] = 0;
        }
    if (w < c && !vis[u][v][w+1] && sum + 50 <= x)
        {
            dfs(u, v, w+1, sum+50);
            //vis[u][v][w+1] = 0;
        }
    //vis[u][v][w] = 0;
}

int main() {
    cin >> a >> b >> c >> x;
    dfs(0, 0, 0, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
n = int(input())
l = []
x = []
a = []
for i in range(n):
    w = str(input())
    a.append(w)
    l.append(w[0])
    x.append(w[-1])
if len(set(a)) == n:
    if l[1:] == x[:len(x)-1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

/*********** Constants ***********/
const auto INF = static_cast<ll>(1e15);
const auto MOD = static_cast<ll>(1e9 + 7);

/*********** Variables ***********/
ll N, TIME;
queue<pair<string, ll>> TASK, ANS;

/*********** Functions ***********/
bool init() {
    cin >> N >> TIME;
    for (ll i = 0; i < N; i++) {
        string str; ll time;
        cin >> str >> time;
        TASK.emplace(str, time);
    }
    return true;
}

void solve() {
    ll T = 0;
    while (!TASK.empty()) {
        pair<string, ll> task = TASK.front(); TASK.pop();
        if (task.second > TIME) {
            T += TIME;
            task.second -= TIME;
            TASK.emplace(task);
        }
        else {
            ANS.emplace(task.first, task.second + T);
            T += task.second;
        }
    }
}

void output() {
    while (!ANS.empty()) {
        cout << ANS.front().first << " " << ANS.front().second << endl;
        ANS.pop();
    }
}

int main() {
    init();
    solve();
    output();
    return 0;
}


Measured memory_bytes: 6160
#include<bits/stdc++.h>
using namespace std;
int n,m,cnt = 0, k[11],p[11],s[11][11],sw[11] = {0};
bool judge(){
    for(int i = 1; i <= m; i++){
        int sum = 0;
        for(int j = 0; j < k[i]; j++){
            if(sw[s[i][j]] == 1)
                sum++;
        }
        if(sum % 2 != p[i]) 
            return 0;
    }
    return 1;
}
void dfs(int i){
    if(i > n){
        if(judge())
            cnt++;
        return ;
    }
    for(int j = 0; j <= 1; j++){
        sw[i] = j;
        dfs(i+1);
        sw[i] = 0;
    } 
    
}
int main(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 1; i <= m; i++)
        cin >> p[i];
    dfs(1);
    cout << cnt << endl;
}


Measured memory_bytes: 256
record=['A','B','C','D','E','F']
while True:
    m,f,r = map(int,input().split())
    if m==f==r== -1:break 
    elif m==-1 or f==-1:print(record[5])
    elif m+f>=80:print(record[0])
    elif m+f>=65:print(record[1])
    elif m+f>=50 or (m+f>=30 and r>=50):print(record[2])
    elif m+f>=30:print(record[3])
    else:print(record[5])


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define ws fuckinfoasdjfosadjljo
using namespace std;
using lint = long long;
using pi = pair<lint, lint>;
const int MAXN = 100005;
const int mod = 1e9 + 7;
const lint inf = 1e10 + 19;

pi jeop(pi p, int n){
	/*
	vector<pi> v;
	for(int i=0; i<=n; i++){
		for(int j=0; j<=n; j++){
			v.emplace_back(i, j);
		}
	}
	sort(all(v), [&](const pi &a, const pi &b){
		return a.first * p.first + a.second * p.second < 
		b.first * p.first + b.second * p.second;
	});
	pi ret(0, 0);
	for(int i=0; i<n; i++){
		ret.first += v[i].first;
		ret.second += v[i].second;
	}
	return ret;
	*/
	if(p.first < p.second){
		auto ans = jeop(pi(p.second, p.first), n);
		return pi(ans.second, ans.first);
	}
	auto enough = [&](lint k){
		lint ret = 0;
		for(int i=0; i<2000; i++){
			if(k < p.first * i) break;
			ret += (k - p.first * i) / p.second + 1;
			ret = min(ret, (lint)2e9);
		}
		return ret;
	};
	lint s = 0, e = 1e18;
	while(s != e){
		lint m = (s+e)/2;
		if(enough(m) >= n) e = m;
		else s = m + 1;
	}
	pi ret(0, 0);
	for(int i=0; i<2000; i++){
		if(s < p.first * i) break;
		lint cnt = (s - p.first * i) / p.second;
		ret.first += cnt * (cnt + 1) / 2;
		ret.second += (cnt + 1) * i;
	}
	int lim = enough(s) - n;
	for(int i=0; i<2000 && lim; i++){
		if(s < p.first * i) break;
		if((s - p.first * i) % p.second == 0){
			ret.first -= (s - p.first * i) / p.second;
			ret.second -= i;
			lim--;
		}
	}
	swap(ret.first, ret.second);
	return ret;
}

bool good(int n, int x, int y){
	auto ccw = [&](pi a, pi b, pi c){
		lint dx1 = b.first - a.first;
		lint dy1 = b.second - a.second;
		lint dx2 = c.first - a.first;
		lint dy2 = c.second - a.second;
		return dx1 * dy2 - dy1 * dx2;
	};
	lint s = 1, e = inf - 1;
	while(s != e){
		lint m = (s+e)/2;
		//printf("%lld %lld %d -> ", m, inf - m, n);
		//fflush(stdout);
		auto pnt = jeop(pi(m, inf - m), n);
		//printf("%lld %lld\n", pnt.first, pnt.second);
		//fflush(stdout);
		if(pnt.first <= x && pnt.second <= y){
			return 1;
		}
		if(pnt.first >= x && pnt.second >= y){
			return 0;
		}
		if(pnt.first < x) e = m;
		else s = m + 1;
	}
	auto func1 = jeop(pi(s, inf - s), n);
	auto func2 = jeop(pi(s - 1, inf - s + 1), n);
	return ccw(func2, func1, pi(x, y)) <= 0;
}

int main(){
	int x, y;
	cin >> x >> y;
	int s = 0, e = 1e9 + 2;
	while(s != e){
		int m = (s+e+1)/2;
		if(good(m, x, y)) s = m;
		else e = m - 1;
	}
	cout << s - 1 << endl;
}


Measured memory_bytes: 384
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*4
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
int N,M,Q;
int V[MaxN], D[MaxN], C[MaxN];
struct Edge
{
    int u,v,next;
}edge[MaxM];
int cont,head[MaxN];
void add(int u, int v)
{
    edge[cont].u = u, edge[cont].v = v, edge[cont].next = head[u], head[u] = cont++;
}
int num = 0;
int color[MaxN];
int MAX[MaxN];
void Paint(int pre,int u, int d, int c)
{
    if(d && MAX[u]>=d) return ;
    MAX[u] = max(MAX[u],d);
    if(!color[u]) 
    {
        color[u] = c;
        num++;
    }
    if(d==0) return;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        int v = edge[i].v;
        if(v == pre) continue;
        Paint(u, v, d-1, c);
    }
}
void solve()
{
    for(int i=Q-1;i>=0;i--)
    {
        if(D[i] && D[i]<=MAX[V[i]]) continue;
        Paint(0, V[i], D[i], C[i]);
        if(num>=N) break;
    }
    for(int i=1;i<=N;i++) printf("%d\n", color[i]);
}
void init()
{
    cont = 0;
    MST(head,-1);
}
int main()
{
    //std::ios::sync_with_stdio(false);
    init();
    scanf("%d%d", &N, &M);
    int a,b;
    while(M--)
    {
        scanf("%d%d", &a, &b);
        add(a,b),add(b,a);
    }
    scanf("%d", &Q);
    for(int i=0;i<Q;i++) scanf("%d%d%d", &V[i], &D[i], &C[i]);
    solve();
    //system("pause");
}


Measured memory_bytes: 7680
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  string w;
  int c[26]={};
  cin >> w;
  REP(i,w.length()){
    c[alp.find(w[i])]++;
    c[alp.find(w[i])]%=2;
  }
  REP(i,26){
    if(c[i]) {
      Yn(0);
      return 0;
    }
  }
  Yn(1);
  return 0;
}

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

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

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

    int x = 0, maxi = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'I') x++;
        else x--;
        maxi = max(maxi, x);
    }

    cout << maxi << endl;

    return 0;
}

Measured memory_bytes: 256
/*
─────────▄▄▄▄▄▄▄▄▄▄▄▄─────────
─────▄▄▀▀░░░░░░░░░░░░▀▀▄▄─────
───▄▀░░░░░░░░░░░░░░░░░░░░▀▄───
──█░░░░░▄▄▄▄▄░░░░▄▄▄▄▄░░░░░█──
─█░░░░░██░█░██▄▄██░█░██░░░░░█─
█░░░░░░░▀▀▀▀▀░░░░▀▀▀▀▀░░░░░░░█
█░░░░▄▄▄░░░░░░░░░░░░░░▄▄▄░░░░█
█░░░░██▀█▄▄▄▄▄▄▄▄▄▄▄▄██▀█░░░░█
─█░░░▀██▄████████▄▄▄▄██▄▀░░░█─
──█░░░░▀██▀▀▀▀████████▀░░░░█──
───▀▄░░░░▀▄▄▄▄██████▀░░░░▄▀───
─────▀▀▄▄░░░░░░░░░░░░▄▄▀▀─────
─────────▀▀▀▀▀▀▀▀▀▀▀▀─────────
*/
#include <bits/stdc++.h>

using namespace std;

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

	int n;
	cin >> n;
	vector<int> a(n), b(n);
	priority_queue<pair<int, int>> q;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
		if (b[i] < a[i]) {
			cout << -1;
			return 0;
		}
		q.emplace(b[i], i);
	}
	long long ans = 0;
	while (q.size()) {
		auto p = q.top();
		q.pop();
		int l = (p.second - 1 + n) % n, r = (p.second + 1) % n;
		if ((b[p.second] - a[p.second]) % (b[l] + b[r]) == 0) {
			ans += (b[p.second] - a[p.second]) / (b[l] + b[r]);
			b[p.second] = a[p.second];
			continue;
		}
		if (b[p.second] <= b[l] + b[r]) {
			cout << -1;
			return 0;
		}
		ans += b[p.second] / (b[l] + b[r]);
		b[p.second] %= (b[l] + b[r]);
		if (b[p.second] < a[p.second]) {
			cout << -1;
			return 0;
		}
		q.emplace(b[p.second], p.second);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3956
import sys


def handler():
    n = int(input().strip())
    a = [int(i) for i in input().strip().split()]
    cash, stock = 1000, 0
    buyin = 0
    for i in range(n):
        if stock > 0:
            # sys.stderr.write('[%d] sold %d (buyin = %d)\n' % (i, stock, buyin))
            cash += stock * max(buyin, a[i])
            stock = 0
        if i < n - 1 and cash >= a[i] and a[i] <= max(a[i + 1:]):
            buyin = a[i]
            k = cash // a[i]
            cash -= k * a[i]
            stock += k
            # sys.stderr.write('[%d] buy %d\n' % (i, k))
        # sys.stderr.write('%d, %d\n' % (cash, stock))
    sys.stdout.write('%d\n' % cash)


def main():
    while True:
        try:
            handler()
        except ValueError:
            continue
        except EOFError:
            break


if __name__ == '__main__':
    main()

Measured memory_bytes: 63024
/**
 *      purpose : ABC 72 D
 *      author  : kyomukyomupurin
 *      created : 2018-11-03 02:14:21
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int p[N] = {};
    for (int i = 0; i < N; ++i) cin >> p[i];

    int beg = 0; 
    int sum = 0;
    while (beg < N){
        int end = beg;
        while (end < N && p[end] == end + 1){
            ++end;
        }
        int len = end - beg;
        if (len >= 2){
            if (len % 2 == 0) sum += (len / 2);
            else if (len % 2 == 1) sum += ((len + 1) / 2);
        }
        else if (len == 1) ++sum;

        beg = end + 1;
    }
    print(sum);

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second

void solve() {
    int n, m;
    cin >> n >> m;
    ll ans = 0;
    vector<ll> X(n), Y(n), Z(n);
    rep(i, n) cin >> X[i] >> Y[i] >> Z[i];
    for(int x = 1; x >= -1; x -= 2) for(int y = 1; y >= -1; y -= 2) for(int z = 1; z >= -1; z -= 2){
        vector<ll> A(n);
        rep(i, n) {
            A[i] = X[i] * x + Y[i] * y + Z[i] * z;
        }
        sort(rall(A));
        ll ret = 0;
        rep(i, m) ret += A[i];
        ans = max(ans, ret);
    }
    cout << ans << endl;
    return;
}

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


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int x, y;
    cin >> x >> y;
    int group[] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};

    // 処理
    // 出力
    cout << (group[x] == group[y] ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256