akhauriyash/Code-Regression huggingface dataset:
<?php
	$s=chop(fgets(STDIN));
	$t=chop(fgets(STDIN));
	if(strlen($s)!=strlen($t)){
		echo strlen($s)<strlen($t)?LESS:GREATER;
	}
	else
	{
		$f=EQUAL;
		for($i=0;$i<strlen($s);$i++){
			if($s[$i]!=$t[$i]){
				$f=$s[$i]<$t[$i]?LESS:GREATER;
				break;
			}
		}
		echo $f;
	}


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max(a*b,max(a+b,a-b)) << endl;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            String strSplit[] = br.readLine().split(" ");
            int A = Integer.parseInt(strSplit[0]);
            int B = Integer.parseInt(strSplit[1]);
            int C = Integer.parseInt(strSplit[2]);
            int D = Integer.parseInt(strSplit[3]);
            
            int AC = Math.max(A, C);
            int BD = Math.min(B, D);
            
            if(BD > AC){
                System.out.println(BD-AC);
            }else{
                System.out.println("0");
            }
            
        }catch(Exception e){
            
        }
    }
}

Measured memory_bytes: 32572
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
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()
q = deque([3,5,7])
res = 0
def chk(s):
    global res
    if min(s.count('3'), s.count('5'), s.count('7')) > 0:
        res += 1
while q:
    now = q.popleft()
    if now > n:
        continue
    chk(str(now))
    for t in ['3', '5', '7']:
        q.append(int(str(now) + t))
print(res)


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

int main()
{
  int R;
  cin >> R;
  
  if(R < 1200)
    cout << "ABC" << endl;
  else if(R < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n,m;
  cin>>n;
  map<pii,int> mp;
  rep(i,n){
    int t;
    cin>>t;
    mp[pii(t,i)]=1;
  }
  cin>>m;
  bool ans=true;
  rep(i,m){
    int t;
    cin>>t;
    auto itr=mp.lower_bound(pii(t,-INF));
    if(itr->first.first!=t)ans=false;
    else mp.erase(itr); 
  }
  if(ans)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 12800
from collections import deque

left = deque()
right = deque()

s = input()
q = int(input())

reverse = False
for i in range(q):
    t_inp = input().split()
    if t_inp[0] == "1":
        reverse = not reverse
    else:
        if t_inp[1] == "1" and reverse:
            right.append(t_inp[2])
        if t_inp[1] == "1" and not reverse:
            left.appendleft(t_inp[2])
        if t_inp[1] == "2" and reverse:
            left.appendleft(t_inp[2])
        if t_inp[1] == "2" and not reverse:
            right.append(t_inp[2])

l_li = list(left)
r_li = list(right)

# print(left)
# print(right)
ans = "".join(l_li)+s+"".join(r_li)

if reverse:
    print(ans[::-1])
else:
    print(ans)


Measured memory_bytes: 7540
#include <iostream>
#include <map>
using namespace std;
int n,m;
map <int,int> mpa;
int main() {
	cin>>n;
	for(int x,i=0;i<n;i++){
		scanf("%d",&x);
		mpa[x]++;
	}
	cin>>m;
	for(int x,i=0;i<m;i++){
		scanf("%d",&x);
	//	cout<<mpa[x]<<" ";
		if(mpa[x]<=0)
			return cout<<"NO",0;
		mpa[x]--;
	}
	cout<<"YES";
	return 0;
}

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

#define F first
#define S second
#define MP make_pair

using namespace std;

const int N = 1e7+100;
pair<long long int, long long int> p[N];

int main () {
    ios::sync_with_stdio(0);
    long long int a, b;
    cin >> a >> b;
    long long int gc = __gcd(a,b);
    long long int ans = 1;
    for(long long int i = 2 ; i*i <= gc ; i++ ) {
        if(gc%i==0) {
            while(gc%i==0)
                gc/=i;
            ans++;
        }
    }
    if(gc!=1)
        ans++;
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

class Bipartite{
private:
    vector<vi> g;
    bool c; //is bipartite graph
    int n;
    vector<int> used;
    int cnt[2];
    vector<pii> p;

    void dfs(int now){
        cnt[used[now]]++;
        rep(i,g[now].size()){
            int ne = g[now][i];
            if(used[ne] == -1){
                used[ne] = 1 - used[now];
                dfs(ne);
            }else if(used[ne] == used[now]){
                c = false;
                return;
            }
        }
    }

public:
    Bipartite(){};
    Bipartite(int size){
        n = size;
        g = vector<vector<int> > (size);
        used = vector<int> (size);
    }

    void add(int a,int b){//無向辺を追加
        g[a].push_back(b);
        g[b].push_back(a);//有向辺の場合はここをコメントアウト
    }

    bool is_bipartite(){//二部グラフ判定
        p.clear();
        c = true;
        rep(i,n) used[i] = -1;
        rep(i,n)if(used[i]==-1){
            used[i] = 0;
            cnt[0] = cnt[1] = 0;
            dfs(i);
            if(c==false) return false;
            p.push_back(pii(cnt[0],cnt[1]));
        }

        return true;
    }

    vector<int> split(){//2つにわけるときの分け方
        vector<int> ret;
        if(is_bipartite() == false)return ret;
        int N = p.size();
        set<int> st;
        st.insert(0);
        rep(i,N){
            set<int> nst;
            for(set<int>::iterator itr = st.begin(); itr != st.end(); ++itr){
                nst.insert(*itr + p[i].first);
                nst.insert(*itr + p[i].second);
            }
            st = nst;
        }
        for(set<int>::iterator itr = st.begin(); itr != st.end(); ++itr) ret.push_back(*itr);
        return ret;
    }

};

signed main(void) {
    int i,j;
    int n,m;
    while(cin >> n >> m, n){
        Bipartite bi(n);
        rep(i,m){
            int a,b;
            cin >> a >> b;
            bi.add(a-1,b-1);
        }
        vi p = bi.split(),ans;
        rep(i,p.size())if(p[i] % 2 == 0)ans.push_back(p[i]/2);
        sort(all(ans));
        cout << ans.size() << endl;
        rep(i,ans.size())cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
(0,0,0)：必敗
(1,0,0)：一意に決まる
(2,0,0)：
低い方に分配すれば基本は勝てる
*/

ll n,a[3];
string s[100010];
char ans[100010];
bool ok=true;

int main(void){
	cin>>n;
	rep(i,3)cin>>a[i];
	rep(i,n)cin>>s[i];
	// シミュレーションする
	rep(i,n){
		int c,d;
		if(s[i]=="AB"){c=0;d=1;}
		if(s[i]=="AC"){c=0;d=2;}
		if(s[i]=="BC"){c=1;d=2;}
		if(a[c]>a[d]){
			ans[i]='A'+d;
			a[c]--;
			a[d]++;
		}else if(a[c]<a[d]){
			ans[i]='A'+c;
			a[c]++;
			a[d]--;
		}else{
			if(i!=n-1 && s[i]!=s[i+1]){  // 個数が一致するときだけ先読み
				if(s[i+1]=="AB"){
					ans[i]='A'+c;
					a[c]++;
					a[d]--;
				}
				if(s[i+1]=="AC"){
					if(c==0){
						ans[i]='A'+c;
						a[c]++;
						a[d]--;
					}else{
						ans[i]='A'+d;
						a[d]++;
						a[c]--;
					}
				}
				if(s[i+1]=="BC"){
					ans[i]='A'+d;
					a[d]++;
					a[c]--;
				}
			}else{  // 適当に動かす
				ans[i]='A'+c;
				a[c]++;
				a[d]--;
			}
		}
		if(a[0]<0 || a[1]<0 || a[2]<0)ok=false;
	}
	if(ok){
		cout<<"Yes"<<endl;
		rep(i,n)cout<<ans[i]<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,t;cin>>n>>t;
    int c,tt;
    int ans=10000,res=0;
    for(int i=0;i<n;i++){
        cin>>c>>tt;
        if(t>=tt&&ans>c){
            ans=c;
            res++;
        }
    }
    if(res==0){
        cout<<"TLE"<<endl;
        return 0;
    }
    cout<<ans<<endl;
}

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

int main(){
    string str;
    cin>>str;
    int w;
    cin>>w;
    size_t k=str.size();
    for(int i=0;i<k;){
        cout<<str[i];
        i+=w;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
    vector<int>arr(n);
    int left = 1, ans = 0;
    for (int i = 0; i < n; i++){
        cin>>arr[i];
    }
    for (size_t i = 0; i < n; i++)
    {
        if(arr[i] == left){
            left++;
        }
        else
        {
            ans++;
        }
    }
    if(left == 0 && ans == 1){
        cout << "-1" << endl;
    }
    else if(ans<n){
        cout << ans << endl;
    }
    else{
        cout << "-1" << endl;
    }
  return 0;
}

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

int selectonSort(int A[], int N){
    int sw = 0;
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i; j < N; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        swap(A[i], A[minj]);
        if(i != minj){
            sw++;
        }
    }
    return sw;
}

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

    for(int i = 0; i < N - 1; i++){
        cout << A[i] << ' ';
    }
    cout << A[N - 1] << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3096
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	static Queue<Pair> queue = new LinkedList<Pair>();

	static class Pair {
		int x, y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int width, height;
		int area[][];
		int tree[][];

		while (true) {
			height = sc.nextInt();
			width = sc.nextInt();
			if ((height | width) == 0) {
				break;
			}
			tree = new int[height][width];
			area = new int[height][width];
			for (int i = 0; i < height; i++) {
				String s = sc.next();
				for (int j = 0; j < width; j++) {
					tree[i][j] = s.charAt(j);
					area[i][j] = 0;
				}
			}
			System.out.println(f(tree, area, height, width));
		}
	}

	public static int f(int tree[][], int area[][], int h, int w) {
		int count = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (area[i][j] == 0) {
					count++;
					g(tree, area, i, j, h, w, count);
					h(tree, area, i, j, h, w, count);
				}
			}
		}
		return count;
	}

	public static void g(int tree[][], int area[][], int i, int j, int h, int w, int count) {
		if (area[i][j] != 0) {
			return ;
		}
		int x = tree[i][j];
		area[i][j] = count;
		if (0 <= i - 1 && tree[i - 1][j] == x) {
			Pair p = new Pair(i - 1, j);
			queue.add(p);
		}
		if (i + 1 < h && tree[i + 1][j] == x) {
			Pair p = new Pair(i + 1, j);
			queue.add(p);
		}
		if (0 <= j - 1 && tree[i][j - 1] == x) {
			Pair p = new Pair(i, j - 1);
			queue.add(p);
		}
		if (j + 1 < w && tree[i][j + 1] == x) {
			Pair p = new Pair(i, j + 1);
			queue.add(p);
		}
	}
	
	public static void h(int tree[][], int area[][], int i, int j, int h, int w, int count) {
		while (!queue.isEmpty()) {
			Pair p = queue.poll();
			g(tree, area, p.x, p.y, h, w, count);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    int n;
    cin>>n;
    vi a(n);
    for(int i=0;i<n;i++) {
        cin>>a[i];
    }
    vi pref(n),suff(n);
    pref[0]=a[0];
    for(int i=1;i<n;i++) {
        pref[i] = pref[i-1]^a[i];
    }

    suff[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--) {
        suff[i] = suff[i+1]^a[i];
    }

    for(int i=0;i<n;i++) {
        if(i==0) cout<<suff[i+1]<<" ";
        else if(i==n-1) cout<<pref[i-1]<<" ";
        else {
            int ans = suff[i+1]^pref[i-1];
            cout<<ans<<" ";
        }
    }
}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 5544
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] read = ReadLine().Split(' ');
//        int read_leng = read.Length;
//        int[] readR = new int[mochinum];
        int tate = int.Parse(read[0]);
        int yoko = int.Parse(read[1]);
        
        char[,] map = new char[tate+2,yoko+2];
        
        string ans = "Yes";
        for(int i=0;i<tate;i++){
            string gyou = ReadLine();
            for(int j=0;j<yoko;j++){
                map[i+1,j+1] = gyou[j];
            }
        }
        
        for(int i=0;i<tate;i++){
            for(int j=0;j<yoko;j++){
                if(map[i+1,j+1] == '.'){
                }else if(map[i+1,j+1] == '#' && (map[i+1,j] == '#' ||map[i,j+1] == '#' || map[i+1,j+2] == '#' || map[i+2,j+1] == '#')){
                }else{
                    /*WriteLine(map[i+1,j+1]);
                    Write(map[i+1,j]);
                    Write(map[i,j+1]);
                    Write(map[i+1,j+2]);
                    WriteLine(map[i+2,j+1]);*/
                    ans = "No";
                }
            }
        }
        WriteLine(ans);
        
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    string s,t;
    cin >> s >> t;
    int mini = t.length();
    for(int i = 0; i <= s.length() - t.length(); i++){
        int tmp = 0;
        for(int j = 0; j < t.length(); j++){
            if(s[i+j] != t[j]) tmp++; 
        }
        mini = min(mini,tmp);
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 3608
/*B - Count ABC*/
#include <iostream>
#include <string>
using namespace std;

int main() 
{
  int n,counter=0;
  string s;
  cin >> n >> s;

  for(int i=0; i<n-2; i++)
  {
    if( s.substr(i,3) == "ABC" )
      counter++;
  }

  cout << counter << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int a, b, c, d, e, A[n];
    rep(i, n) {
      cin >> a >> b >> c >> d >> e;
      A[i] = a + b + c + e + d;
    }
    sort(A, A + n);
    cout << A[n - 1] << ' ' << A[0] << endl;
  }
  return 0;
}

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

using namespace std;

int n, res;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y;
		res += y-x+1;
	}
	cout<<res<<"\n";
}

Measured memory_bytes: 256
import fractions
def main(A,B,C,D):
    allAB = B - A + 1
    divC = B // C - (A-1) // C
    divD = B // D - (A-1) // D
    lcmCD = lcm(C,D)
    divCD = B // (lcmCD) - (A-1) // (lcmCD)
    count = allAB - divC - divD + divCD
    return count

def lcm(x, y):
    return (x*y) // fractions.gcd(x,y)
    
A,B,C,D = map(int, input().split())
print(main(A,B,C,D))

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

map<int,int> m;

int main(){

int n;
cin>>n;

int a[n];
a[0] = 0;

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

sort(a,a+n);

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




}


Measured memory_bytes: 13800
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
    public static void main(String args[])
    {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int a[] = new int[n];
        int x = scn.nextInt();
        int c = n;
        for (int i = 0; i < n; i++)
        {
            a[i] = scn.nextInt();
            x -= a[i];
        }
        Arrays.sort(a);
        c = c + (x / a[0]);
        System.out.println(c);
    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(){
    int N;
    int X;
    int T;

    cin >> N;
    cin >> X;
    cin >> T;


    int q = N/X;
    int r = N%X;
    
    int result;
    if(r==0){
        result = T*q;
    }else{
        result = T*(q+1);
    }

    cout << result << endl;
}

Measured memory_bytes: 3628
from collections import deque
import sys
input=sys.stdin.readline


def BFS():
    color=["white" for _ in range(n)]
    D=[0]*n
    M=[[] for _ in range(n)]

    for u,v,w in UVW:
        M[u-1].append([v-1,w])
        M[v-1].append([u-1,w])

    D[0]=1
    color[0]="gray"
    queue=deque([0])

    while len(queue)>0:
        u=queue.popleft()
        for i,j in M[u]:
            if color[i]=="white":
                if j%2==0:D[i]=D[u]
                elif j%2==1:D[i]=-D[u]
                color[i]="gray"
                queue.append(i)
        color[u]="black"

    return D


n=int(input())
UVW=[list(map(int,input().split())) for _ in range(n-1)]
for i in BFS():
    if i==-1:print(0)
    else:print(i)

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

using namespace std;

typedef unsigned long long ull;
typedef long double ldbl;
typedef long long ll;
typedef double dbl;
const ldbl E = 2.71828182845904523536;
const ldbl pi = acos(-1);
const dbl eps = 1e-9;
//const ll mod = 1e9+7;
const ll inf = 1LL<<30;
#define countones(x) __builtin_popcount (x);
int dcmp(double x, double y)
{ return fabs(x - y) <= eps ? 0 : x < y ? -1 : 1; };

string convertostring(long long  num)
{
    stringstream ss;
    ss << num;
    return ss.str();
}
void PLAY()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(2);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
const ll N=2*1e5+1;
ll mem[N];
int n,k;
vector<int>v;
ll sol(ll i)
{
    if(i==n-1)
        return 0;
ll &ret=mem[i];
if(ret!=-1)return ret;
ret=inf;
for(int j=1;j<=k;j++)
    {
        if(i+j<=n-1)
        {
        ret=min(ret,abs(v[i]-v[i+j])+sol(i+j));
        }
    }
    return ret;
}
int main()
{


cin>>n>>k;
for(int i=0;i<n;i++)
{
    int a;
    cin>>a;
    v.push_back(a);
}
memset(mem,-1,sizeof mem);
cout<<sol(0);








}


Measured memory_bytes: 10104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define Y first
#define X second
#define INF 1 << 30

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

int p, s;
char row[10];
int a[128][128], b[128][128];

int main(){
  bool outf = 0;
  while(scanf("%d", &p) && p){
    scanf("%d", &s);
    rep(i, 128) rep(j, 128) a[i][j] = INF;
    memset(b, 0, sizeof(b));
    rep(i, p+1) rep(j, s+1){
      scanf("%s", row);
      if(row[0] == '?'){
	b[i][j] = -1;
	continue;
      }
      a[i][j] = atoi(row);
    }

   int c, sum, point;
    bool f = true;
    while(f){
      f = false;
      rep(i, p){
	c = 0;
	rep(j, s) if(a[i][j] == INF){ c++; point = j;}
	if(c != 1) continue;
	f = 1;
	sum = 0;
	rep(j, s) if(a[i][j] != INF) sum += a[i][j];
	a[i][point] = a[i][s] - sum;
	//	printf("%d %d\n", i, point);
      }
      rep(j, s){
	c = 0;
	rep(i, p) if(a[i][j] == INF){ c++; point = i;}
	if(c != 1) continue;
	f = 1;
	sum = 0;
	rep(i, p) if(a[i][j] != INF) sum += a[i][j];
	a[point][j] = a[p][j] - sum;
	//	printf("%d %d\n",  point, j);
      }
    }
    //    fprintf(stderr, "end\n");
    if(outf){
      puts("");
    }
    outf = 1;
    rep(i, p) rep(j, s) if(a[i][j] == INF) f = 1;
    if(f){
      puts("NO");
    }else{
      rep(i, p) rep(j, s) if(b[i][j] == -1) printf("%d\n", a[i][j]);
    }

  }
  return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
#define pll pair<ll,ll>
#define pii pair<int, int>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x).size()

const ll Mod = 998244353;

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

    ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    vll p(a),q(b),r(c);
    for(ll i=0;i<a;i++)
        cin>>p[i];
    for(ll i=0;i<b;i++)
        cin>>q[i];
    for(ll i=0;i<c;i++)
        cin>>r[i];

    sort(all(p));sort(all(q));
    reverse(all(p));reverse(all(q));
    set<ll> pr,qr;
    map<ll,ll> pm,qm;
    for(ll i=0;i<x;i++){
        pr.insert(p[i]);
        if(pm.find(p[i])==pm.end()){
            pm[p[i]]=1;
        }else{
            pm[p[i]]++;
        }
    }
    for(ll i=0;i<y;i++){
        qr.insert(q[i]);
        if(qm.find(q[i])==qm.end()){
            qm[q[i]]=1;
        }else{
            qm[q[i]]++;
        }
    }
    sort(all(r));reverse(all(r));
    for(ll i=0;i<c;i++){
        ll p1,q1;
        for(ll i:pr){
            p1=i;
            break;
        }
        for(ll i:qr){
            q1=i;
            break;
        }
        if(r[i]>=p1||r[i]>=q1){
            if(p1>=q1){
                if(qm[q1] <= 1){
                    qm.erase(q1);
                    qr.erase(q1);
                }else{
                    qm[q1]--;
                }
                qr.insert(r[i]);
                if(qm.find(r[i])==qm.end()){
                    qm[r[i]]=1;
                }else{
                    qm[r[i]]++;
                }
            }else{
                if(pm[p1] <= 1){
                    pm.erase(p1);
                    pr.erase(p1);
                }else{
                    pm[p1]--;
                }
                pr.insert(r[i]);
                if(pm.find(r[i])==pm.end()){
                    pm[r[i]]=1;
                }else{
                    pm[r[i]]++;
                }
            }
        }else{
            break;
        }
    }
    ll ans=0;
    for(ll i:pr){
        ans+=(i*pm[i]);
    }
    for(ll i:qr){
        ans+=(i*qm[i]);
    }
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 22272
#include <stdio.h>
int main(void){
	int n, i, j, flag, count, temp, a[100];
	
	scanf("%d", &n);
	
	for(i=0; i<n; i++)
		scanf("%d", &a[i]);
	
	flag = 1;
	i = 0;
	count = 0;
	
	while(flag){
		flag = 0;
		
		for(j=n-1;j>i;j--){
			if(a[j] < a[j-1]){
				temp = a[j];
				a[j] = a[j-1];
				a[j-1] = temp;
				
				count++;
				flag = 1;
			}
		}
		
		i++;
	}
	
	for(i=0; i<n; i++){
		if(i != n-1){
			printf("%d ", a[i]);
		}else{
			printf("%d\n", a[i]);
		}
	}
	
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 600
{-
C++??????????§????
/*
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104
?????????: Country Road
????????????: ??¶?????¨??¨????????§????????????????¢?????????????????????¢?????????????????????????¶????????????????
??????????????¨: ?§???????????????????
*/
-}
import Data.List(sort)

read_ :: String -> Int
read_ = read

main = do
 t' <- getLine
 let t = read_ t'
 sequence_ $ replicate t action
 
action = do
 nk <- getLine
 let [n,k] = map read_ . words $ nk
 xs' <- getLine
 print . sum . drop (k-1) . reverse . sort . makeDiff . map read_ . words $ xs'

makeDiff [_] = []
makeDiff (x:y:xs) = (y-x) : makeDiff (y:xs)

Measured memory_bytes: 38952
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static private Scanner scan = new Scanner(System.in);
    public static void main(String args[]) {
//        int int1 = Integer.parseInt(scan.next());
//        int int2 = Integer.parseInt(scan.next());
//        int int3 = Integer.parseInt(scan.next());
//        int int4 = Integer.parseInt(scan.next());
        int ans_int = 0;
        String ans = "";
//        String temp_str1 = "";
//        String temp_str2 = "";
        int temp_int1 = 0;
        String str1 = scan.next();
        String list_s[] = str1.split("");
//        String str2 = scan.next();
//        String str3 = scan.next();
        double ans_dob = 0;
        ans="Yes";
        for(int i = 1;i<list_s.length+1;i++){
            if(i%2!=0){
                if(list_s[i-1].equals("L")){
                    ans="No";
                    break;
                }
            }else{
                if(list_s[i-1].equals("R")){
                    ans="No";
                    break;
                }
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
        scan.close();
    }
}


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

const int MAX_N = 1010;

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

    int n;
    while(cin >> n && n){

        int y;
        cin >> y;

        int ans = 0;
        int m = 0;
        for(int i = 0; i < n; ++i){
            int b, r, t;
            cin >> b >> r >> t;
            int a = 10000;
            if(t == 1){
                a += a * y * r / 100;
            }
            if(t == 2){
                for(int j = 0; j < y; ++j){
                    a += a * r / 100;
                }
            }
            //cout << a << endl;
            if(m < a){
                m = a;
                ans = b;
            }
        }

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

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,ans=0;
  cin >> A;
  
  A = A - 100;
  if(A >= 0){
  	ans++;
  }else if(A < 0){
  	A = A + 100;
  }
  
  A = A - 10;
  if(A >= 0){
  	ans++;
  }else if(A < 0){
  	A = A + 10;
  }
  
  A = A - 1;
  if(A >= 0){
  	ans++;
  }else if(A < 0){
  	A = A + 1;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int num = 0;

void func(long long x, int a, int b, int c){
  if(x > n){
    return;
  }
  
  if(a && b && c){
    num += 1;
  }

  func(10 * x + 3, 1, b, c);
	func(10 * x + 5, a, 1, c);
	func(10 * x + 7, a, b, 1);

}

int main() {
  cin >> n;
  func(0, 0, 0, 0);
  cout << num << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int main(){ 
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); ++i){
        int j;
        for(j = i; j < s.size(); ++j){
            if(s[j] !='A' && s[j] != 'T' && s[j] != 'G' && s[j] != 'C'){
                break;
            }            
        }
        ans = max(ans, j - i);
        // if(s[i]=='A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C'){
        //     tmp++;
        // }else{
        //     ans = max(ans, tmp);
        //     tmp = 0;
        // }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string i1;
    string i2;
    cin >> i1 >> i2;
    long int Arr[i2.length()+1][i1.length()+1];
    for(long int i=0;i<=i2.length();i++)
    {
        for(long int j=0;j<=i1.length();j++)
        {
            if(i==0 || j==0)
            {
                Arr[i][j]=0;
            }
            else if(i2[i-1]==i1[j-1])
            {
                Arr[i][j]=Arr[i-1][j-1]+1;
            }
            else
            {
                Arr[i][j]=max(Arr[i-1][j],Arr[i][j-1]);
            }
        }
    }
    long int a=i1.length(),b=i2.length();
    if(Arr[b][a]>0)
    {
        int e=Arr[b][a]-1;
        int d=Arr[b][a];
        char Brr[d];
        while(true)
        {
            if(a==0 || b==0)
                break;
            if(Arr[b][a]==Arr[b][a-1])
            {
                a--;
            }
            else if(Arr[b][a]==Arr[b-1][a])
            {
                b--;
            }
            else
            {
                Brr[e]=i1[a-1];
                b--;
                a--;
                e--;
            }
        }
        for(int h=0;h<d;h++)
        {
            cout << Brr[h];
        }
    }
}


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

int main() {
  
  int sum = 0;
  int N,K,x,z;
  cin >> N >> K;
  
  for (int i=0; i<N; i++){
    cin >> x;
    z = abs(x-K);
    if(x >= z)
      sum += z*2;
    else
      sum += x*2;
  }
  
  cout << sum << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
 using std::cin;
 using std::cout;
 using std::endl;
 
 #include <map>
 using std::map;
 
 #include <string>
 using std::string;
 
 map<string, int> memo;
 
 int main (void) {
 int n;
 
 scanf("%lld", &n);
 for (int i = 0; i < n; i++) {
 string s;
 cin >> s;
 
 memo[s] += 1;
 }
 
 int maxv = 0;
 for (const auto& x : memo) {
 int v = x.second;
 if (v > maxv) maxv = v;
 }
 for (auto it = memo.begin(); it != memo.end(); it++) {
 if (it->second == maxv) {
 cout << it->first << endl;
 }
}
 
 return 0;
 }

Measured memory_bytes: 25216
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int H, W;
int a[82][82];
int b[82][82];

bool dp[82][82][82 * 161];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    read(H, W);
    rep(i, 0, H) rep(j, 0, W) read(a[i][j]);
    rep(i, 0, H) rep(j, 0, W) read(b[i][j]);

    const auto diff = [&](int i, int j) { return abs(a[i][j] - b[i][j]); };

    dp[0][0][diff(0, 0)] = true;

    rep(i, 0, H) rep(j, 0, W) {
        rep(s, 0, 81 * 161) if (dp[i][j][s]) {
            {
                const int d = diff(i + 1, j);
                dp[i + 1][j][s + d] = true;
                dp[i + 1][j][abs(s - d)] = true;
            }
            {
                const int d = diff(i, j + 1);
                dp[i][j + 1][s + d] = true;
                dp[i][j + 1][abs(s - d)] = true;
            }
        }
    }

    int ans = 0;
    while (!dp[H - 1][W - 1][ans]) ++ans;
    print(ans);

    return 0;
}


Measured memory_bytes: 85376
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define all(x) (x).begin(),(x).end()
#define print(x) if(x)cout<<"YES\n";else cout<<"NO\n";
#define f(i,x,y) for(ll i=x;i<=y;i++)
#define rf(i,x,y) for(ll i=x;i>=y;i--)
#define pb push_back
#define F first
#define S second
#define mod 998244353
using namespace std;
ll dp[200000 + 1];
unsigned ll pre[200000 + 1];
int main()
{
// #ifndef HP
//   freopen("in.txt", "r", stdin);
//   freopen("out.txt", "w", stdout);
// #endif
 
  fastio;
  int t = 1;
  //cin >> t;
  while (t--)
  {
    ll n, k;
    cin >> n >> k;
    vector<pair<ll, ll> > v;
    f(i, 0, k - 1)
    {
      ll p, q;
      cin >> p >> q;
      v.pb({p, q});
    }
    dp[0] = 0;
    dp[1] = 1;
    pre[0] = 0;
    pre[1] = 1;
    for (ll i = 2; i <= n; i++)
    {
      for (ll j = 0; j < v.size(); j++)
      {
        {
          ll x = max(0LL, i - v[j].F);
          ll y = max(0LL, i - v[j].S - 1);
          dp[i] = (dp[i] + pre[x] - pre[y] ) % mod;
        }
      }
      pre[i] = (pre[i - 1] + dp[i]);
    }
    cout << dp[n] << endl;
  }
}

Measured memory_bytes: 6752
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

// gp_hash_table<int, int> table;

const int N = 2e5 + 5;

vector<int> adj[N];

pair<int, int> getFurthestNode(int node, int parent) {
  pair<int, int> res = { 0, node };
  for (int v : adj[node]) {
    if (v == parent) continue;
    auto tmp = getFurthestNode(v, node);
    ++tmp.first;
    res = max(res, tmp);
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n;
  cin >> n;

  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  auto tmp = getFurthestNode(1, -1);
  auto res = getFurthestNode(tmp.second, -1);

  cout << (res.first % 3 == 1 ? "Second" : "First");
}


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

int main(){
  string s; cin >> s;
  int k; cin >> k;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == '1'){
      if(i == k-1){
        cout << 1 << endl;
        return 0;
      }
      continue;
    }
    else{
      cout << s.at(i) << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#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);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 400001
#define MAX_V 400010
#define vec vector<int>
#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 );
}
main(){
    int n=in();
    int a[N];
    rep(i,n)a[i]=in();
    bool flag=true;
    rep(i,n)if(a[i]%2)flag=false;
    cout<<(flag?"second":"first");
}


Measured memory_bytes: 640
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;




int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> l;
    vector<ll> r;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        if(b<0){l.push_back(-1*b);}
        if(b==0){k--;}
        if(b>0){r.push_back(b);}
    }
    if(k<=0){cout<<0<<endl; return 0;}
    sort(l.begin(),l.end());
    ll mi=E;
    if(l.size()>=k){mi=min(mi,l[k-1]);}
    if(r.size()>=k){mi=min(mi,r[k-1]);}
    for(int i=0;i<l.size() && i<k;i++){
        ll t=k-i-2;
        if(t<r.size() && t>=0){
            mi=min(mi,l[i]+r[t]*2);
            mi=min(mi,l[i]*2+r[t]);
        }
    }
    cout<<mi<<endl;
    
    
    
    return 0;
}


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

int main() {
    //入力
    int n;
    cin >> n;
    vector<int> height(n);
    for (int i=0; i<n; i++) {
        cin >> height.at(i);
    }

    //処理
    int count = 0;
    for (int i=0; i<n; i++) {
      	bool view = true;
        for (int j=0; j<i; j++) {
            if (height.at(j)>height.at(i)) view = false;
        }
        if (view) count++;
    }

    //出力
    cout << count << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
int main() 
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int N,X,Y;
    cin>>N>>X>>Y;
    map<int,int> Hash;
    for(int i=1;i<=N-1;i++)
    {
        for(int j=i+1;j<=N;j++)
        {
            if((X<=i and Y<=i )||(X>=j and Y>=j))
            {
                Hash[j-i]++;
            }
            else if((X<=i and j<=Y))
            {
                if(j-i<i-X+Y-j+1)
                {
                    Hash[j-i]++;
                }
                else
                {
                    Hash[i-X+Y-j+1]++;
                }
            }
            else
            {
                if(X==i and Y==j)
                {
                    Hash[1]++;
                }
                else if(i<X and j>Y)
                {
                    Hash[X-i+j-Y+1]++;
                }
                else if(i<X and j==Y)
                {

                    Hash[X-i+1]++;
                }
                else if(i==X and j>Y)
                {
                    Hash[j-Y+1]++;
                }
                else if(i<X and j<Y)
                {
                    if(X-i+Y-j+1<j-i)
                    {
                        Hash[X-i+Y-j+1]++;
                    }
                    else
                    {
                        Hash[j-i]++;
                    }
                }
                else if(i>X and j>Y)
                {
                    if(i-X+1+j-Y<j-i)
                    Hash[i-X+1+j-Y]++;
                    else
                    {
                        Hash[j-i]++;
                    }
                }
                else
                {
                    Hash[j-i]++;
                }

            }
        }
    }
    for(int i=1;i<N;i++)
    {
        cout<<Hash[i]<<endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const long long infty = 9e18;
int cost (int a, int t) {
  if (t == 0 || t == 4) {
    return a;
  } else if (t == 1 || t == 3) {
    if (a == 0) {
      return 2;
    }
    return a & 1;
  } else {
    return (a + 1) & 1;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(5, infty));
  for (int t = 0; t < 5; t++) {
    dp[0][t] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int t = 0; t < 5; t++) {
      dp[i + 1][t] = min(dp[i + 1][t], dp[i][t] + cost(a[i], t));
      if (t > 0) {
        dp[i + 1][t] = min(dp[i + 1][t], dp[i + 1][t - 1]);
      }
    }
  }
  long long ret = infty;
  for (int t = 0; t < 5; t++) {
    ret = min(ret, dp[n][t]);
  }
  cout << ret << '\n';
  return 0;
}

Measured memory_bytes: 15104
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

typedef long long ll;

int main()
{
    ll n,k=26;
    cin>> n;
    ll p=1,s=0,y=1;
    while(true){
        p*=k;
        if(s+p>=n){
            n-=s;
            break;
        }
        s+=p,y++;
    }
    n--;
    string ss="",aa="abcdefghijklmnopqrstuvwxyz";
    for(ll i=y;i>=1;i--){
        p=pow(26,i);
        ll x=n%p;
        p/=k;
        ll c=x/p;
        ss+=aa[c];
    }
    cout<< ss <<endl;
    return 0;
}

Measured memory_bytes: 4088
N,Y = list(map(int,input().split(" ")))

#10000*x+5000*y+1000*z=Y
#x+y+z=N

for x in range(N+1):
    for y in range(N+1):
        z=N-x-y
        if 10000*x+5000*y+1000*z==Y and z>=0:
            print(x,y,z)
            exit()
print('-1 -1 -1')



Measured memory_bytes: 2940
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize,
        a_: [i64; n],
        b: [i64; n],
        c_: [i64; n]
    }
    let mut a = a_;
    let mut c = c_;
    a.sort();
    c.sort();
    let mut cnt = 0u64;
    for i in 0..n {
        let a_cnt = small(&a, &b[i]) + 1;
        let c_cnt = n - large(&c, &b[i]);
        cnt += a_cnt as u64 * c_cnt as u64;
    }
    println!("{}", cnt);
}

#[allow(dead_code)]
fn small<T: Ord>(arr: &[T], x: &T) -> usize {
    let mut ng = arr.len() as i64;
    let mut ok = -1i64;
    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if &arr[mid as usize] < x {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ok as usize
}

#[allow(dead_code)]
fn large<T: Ord>(arr: &[T], x: &T) -> usize {
    let mut ok = arr.len() as i64;
    let mut ng = -1i64;
    while (ok - ng).abs() > 1 {
        let mid = (ok + ng) / 2;
        if &arr[mid as usize] > x {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    ok as usize
}

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

int main() {
  int n;
  string s;
  int a = 'A';
  cin >> n >> s;
  for(int i = 0; i < s.size(); ++i){
    int b = s.at(i);
    int c = (b - a + n) % 26;
    s.at(i) = 'A' + c;
  }
  cout << s << endl;
}

Measured memory_bytes: 256