akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)


int main() {
    ll n;
    cin >> n;
    vector<string> s(n);
    vector<ll> t(n);

    rep(i,n){
        cin >> s.at(i) >> t.at(i);
    }

    string x;
    cin >> x;

    ll ans = 0;
    ll flag = 0;
    rep(i,n){
        if(flag == 1){
            ans += t.at(i);
        }
        if(flag == 0 && s.at(i) == x){
            flag = 1;
        }

        
    }

    cout << ans << endl;


    

}


Measured memory_bytes: 256
N = int(input())
s = input()
t = input()
D = {t[-1]: 1}
for i in range(N-2, 0, -1):
    si = s[i]; ti = t[i]
    v = D.get(si, 0)
    D[ti] = (D.get(ti, 0) + v) % (10**9+7)
print(D.get(s[0], 0))



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

bool graph[8][8];
bool visit[8];
int n, m;
bool all_visit;
int ans = 0;

int dfs(int v) {
	visit[v] = true;
	for (int i = 0; i < n; ++i) {
		if (graph[v][i] == false) {
			continue;
		}
		if (visit[i]==true) {
			continue;
		}
		ans += dfs(i);
		visit[i] = false;
	}
	all_visit = true;
	for (int i = 0; i < n; i++) {
		if (visit[i] == false) {
			all_visit = false;
			break;
		}
	}
	if (all_visit == true) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {
	cin >> n >> m;
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		graph[a - 1][b - 1] = graph[b - 1][a - 1] = true;
	}
	for (int i = 0; i < n; i++) {
		visit[i] = false;
	}
	int t = dfs(0);
	cout << ans << endl;
	return 0;
}

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

int main(void){
	int n;
	cin >> n;
	vector<int> d(n);
	vector<int> v;
	for(int i = 0; i < n; ++i){
		cin >> d[i];
	}
	for(int num = 1; num <= 9; ++num){
		for(int i = 0; i < n-num+1; ++i){
			long long sum = 0;
			for(int j = 0; j < num; ++j){
				sum *= 10;
				sum += d[i+j];
			}
			v.push_back(sum);
		}
	}
	sort(v.begin(), v.end());
	int now = 0;
	for (int i = 0; i < v.size(); ++i){
		if(v[i] == now) continue;
		if(v[i] == now + 1){
			now++; continue;
		}
		cout << (now?now+1:0) << endl;
		return 0;
	}

	return 0;
}


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

const int INF = 1e9;

struct edge {
    int to;
    int dist;
    edge (int a, int b) : to(a), dist(b) {}
};

struct info {
    int now;
    int st;
    double dist;
    info (int a, int b, double c) : now(a), st(b), dist(c) {}
    const bool operator < (const info & o) const {
        return dist > o.dist;
    }
};

int main() {
    int n, m, p, a, b;
    while (cin >> n >> m >> p >> a >> b, n) {
        a--; b--;
        vector <int> t(n);
        rep (i, n) cin >> t[i];
        vector <vector <edge>> G(m);
        rep (i, p) {
            int x, y, z;
            cin >> x >> y >> z;
            x--, y--;
            G[x].emplace_back(y, z);
            G[y].emplace_back(x, z);
        }

        //info -> (now, st, dist)
        priority_queue <info> que;
        vector <vector <double>> dp(m, vector <double> (1 << n, INF));
        vector <vector <bool>> used(m, vector <bool> (1 << n, false));
        que.emplace(a, 0, 0);
        dp[a][0] = 0;

        while(!que.empty()) {
            info p = que.top(); que.pop();
            int from = p.now;
            if (used[p.now][p.st]) continue;
            used[p.now][p.st] = true;

            int pre = p.st;
            for(int i = 0; i < (int)G[from].size(); i++) {
                edge e = G[from][i];
                rep (k, n) {
                    p.st = pre;
                    if (p.st >> k & 1) continue;
                    int tmp = 1 << k;
                    p.st |= tmp;
                    if (dp[e.to][p.st] >  p.dist + (1.0 * G[p.now][i].dist / t[k])) {
                        dp[e.to][p.st] =  p.dist + (1.0 * G[p.now][i].dist / t[k]);
                        que.emplace(e.to,
                                    p.st,
                                    p.dist + (1.0 * G[p.now][i].dist / t[k]));
                    }
                }
            }
        }
        double ans = INF;
        rep (i, 1 << n) {
            ans = min(ans, dp[b][i]);
        }
        cout << (ans == INF ? "Impossible" : to_string(ans)) << endl;
    }
    return 0;
}


Measured memory_bytes: 4624
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<"### "<<x<<endl;
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
inline int read(){
    int x=0;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}
const int N=200009;
int a[N],n,b[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)a[i]=read(),b[i]=a[i];
	sort(a+1,a+n+1);
	int ans=0,pos=0;
	for(int i=1;i<=n;i++){
		if(b[i]==a[n])ans++,pos=i;
	}

	if(ans>=2){
		for(int i=1;i<=n;i++)printf("%d\n",a[n]);
	}
	else{
		for(int i=1;i<=n;i++){
			if(i!=pos)printf("%d\n",a[n]);
			else printf("%d\n",a[n-1]);
		}
	}
	
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

pair<int, int> f(int x) {
    int a = x%10;
    int b = 0;
    while(x) {
        b = x;
        x /= 10;
    }
    //cout << a << " " << b << endl;
    return pair<int, int> (a, b);
}

int main() {
    int n;
    cin >> n;
    map<pair<int, int>, int> freq;
    for(int i = 1; i <= n; i++) {
        pair<int, int> p = f(i);
        freq[p]++;
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        pair<int, int> p = f(i);
        pair<int, int> q(p.second, p.first);
        ans += freq[q];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int n = scanner.nextInt();
        int ans = 0;
        for(int i = 1; i < n;i++) {
            if (n - i <= i) break;
            ans++;
        }
        out.println(ans);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23508
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define rep(i, e) for (int i = 0; i < e; i++)
#define repp(i, s, e) for (int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define ll long long

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

int main()
{
    int n,k,ans = 1;cin>>n>>k;
    rep(i,n) {
        ans = min(ans*2, ans+k);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
      	int ansA = 0;
      	int ansB = 0;
        for(int A=0;A<=1000;A++){
          for(int B=-1000;B<=1000;B++){
            double res = Math.pow(A, 5) - Math.pow(B, 5);
            if(res == X){
              ansA = A;
              ansB = B;
              break;
            }
            }
        }
      	
 	    System.out.println(ansA);
      	System.out.println(ansB);
    }
}

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

int main(){
  vector<int> t(5); cin>>t[0]>>t[1]>>t[2]>>t[3]>>t[4];
  int min_time;
  min_time = ((t[0]+9)/10+(t[1]+9)/10+(t[2]+9)/10+(t[3]+9)/10+(t[4]+9)/10)*10-max({(200-t[0])%10,(200-t[1])%10,(200-t[2])%10,(200-t[3])%10,(200-t[4])%10});
  cout << min_time << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  int k; cin >> k;
  int ans = 0;
  rep(a,k) rep(b,k) rep(c,k) ans += gcd(a+1,gcd(b+1,c+1));
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 1005
#define LL long long
#define INF 1000000000
int n;
LL t[MAXN],a[MAXN],g1,g2;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld %lld",&t[i],&a[i]);
		if(t[i]>t[i-1]&&a[i]>a[i-1]) continue;
		g1=t[i-1]/t[i],g2=a[i-1]/a[i];
		if(t[i-1]%t[i]) g1++;
		if(a[i-1]%a[i]) g2++;
		LL d=max(g1,g2);
		t[i]*=d,a[i]*=d;
	}
	printf("%lld",t[n]+a[n]); 
}

Measured memory_bytes: 128
A,B,C,D = map(int,input().split())

thp = A
ahp = C
flag = 0

while flag == 0:

	ahp = ahp - B
	if ahp <= 0:
		flag = 2
		break

	thp = thp - D
	if thp <= 0:
		flag = 1
		break

if flag==1:
	print('No')
elif flag==2:
	print('Yes')

Measured memory_bytes: 9188
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
const int M = 1e9 + 7;
#define fr(i,n) for(int i=0;i<n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b) memset(a,b,sizeof(a)); //works only for 0 and -1
ll mod(long long x){
 return (x%M+M)%M;
}
ll add(long long a,long long  b){
return mod(mod(a)+mod(b));
}
ll mul(long long a,long long b){
return mod(mod(a)*mod(b));
}
ll minu(long long a,long long b){
return mod(mod(a)-mod(b));
}
ll modPow(ll a,ll b){
if(b==0)return 1LL;
if(b==1)return a%M;
ll res= 1;
while(b){
if(b%2==1)
res = mul(res,a);
a = mul(a,a);
b/=2;
}
return res;
}
void solve(){
int n;
cin>>n;
long long arr[n];
  long long mul = 1;
  fr(i,n)cin>>arr[i];
  fr(i,n)if(arr[i]==0){cout<<"0";return ;}
  fr(i,n){
  if(arr[i]<=1000000000000000000LL/mul){
  mul *= arr[i];
  }
    else {cout<<"-1";return ;} 
  }
  cout<<mul;
}
int main(){
  fast();
//  int t;cin>>t;
//  while(t--){
    solve();
    cout<<endl;
//  }
 return 0;
}


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

int main(){
    int s;
    vector<int> a(1000000);
    cin >> s;
    a.at(0) = s;

    int i = 0;
    while(1){
        if(a.at(i)%2 == 0){
            a.at(i+1) = a.at(i) / 2;
            for(int j = 0; j < i+1; j++){
                if(a.at(i+1) == a.at(j)){
                    cout << i+2 << endl;
                    return 0;
                }
            }
            i++;
        }else{
            a.at(i+1) = 3*a.at(i) + 1;
            for(int j = 0; j < i+1; j++){
                if(a.at(i+1) == a.at(j)){
                    cout << i+2 << endl;
                    return 0;
                }
            }
            i++;
        }
    }

}

Measured memory_bytes: 4096
#include <cstdio>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int n, a[101010], b[101010], ans;
map<int, int> id;
int abs(int x) {
	return x > 0 ? x : -x;
}
int main() {
	cin >> n;
	for(int i = 1; i <= n; i ++ ) cin >> a[i], b[i] = a[i];
	sort(a+1, a+n+1);
	for(int i = 1; i <= n; i ++ ) id[a[i]] = i;
	int ans = 0;
	for(int i = 1; i <= n; i ++ ) ans += abs(i - id[b[i]]) & 1;
	cout << (ans>>1) << endl;
}


Measured memory_bytes: 5760
def main():
    N = int(input())
    abc = [
        list(map(int, input().split()))
        for _ in range(N)
    ]

    ans = f(N, abc)
    print(ans)


def f(N, abc):
    """
    2回連続で同じ活動(abc)を行えない

    1: a or b or c
    2:
        1-a: b or c
        1-b: c or a
        1-c: a or b

    1日目
        aをしたときの幸福最大
        bをしたときの幸福最大
        cをしたときの幸福最大
    2日目
        aをしたときの幸福最大(b, c から)
        bをしたときの幸福最大(c, a から)
        cをしたときの幸福最大(a, b から)
    """
    dp = [[None] * 3 for _ in range(N + 1)]
    dp[0] = [0, 0, 0]
    dp[1] = abc[0]

    for i in range(2, N + 1):
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + abc[i-1][0]
        dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + abc[i-1][1]
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + abc[i-1][2]

    ans = max(dp[N])
    return ans


if __name__ == "__main__":
    main()


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

pair<int, int> f(int x) {
	int a = x % 10;
	int b = 0;
	while(x) {
		b = x;
		x /= 10;
	}
	return make_pair(a, b);
}

int main() {
	int N;
	cin >> N;
	map<pair<int, int>, int> freq;
	for(int i = 1; i <= N; i++) {
		pair<int, int> p = f(i);
		freq[p]++;
	}

	long long ans = 0;
	for(int i = 1; i <= N; i++) {
		pair<int, int> p = f(i);
		pair<int, int> q(p.second, p.first);
		ans += freq[q];
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		
		System.out.println(Math.sqrt(Math.pow(x2 - x1, 2)
				+ Math.pow(y2 - y1, 2)));
	}
}


Measured memory_bytes: 27880
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstdlib>
using namespace std;
int main()
{
    char str[102],har[10]={"123456789"};
    int n;
    while(scanf("%s",str)!=EOF){
        for(int i=0;str[i]!='\0';i++){
            if(str[i]=='@'){
                for(int j=0;j<10;j++)if(str[i+1]==har[j])n=j+1;
                i+=2;
                for(int j=0;j<n;j++)cout<<str[i];
            }
            else cout<<str[i];
        }
        cout<<endl;
    }

}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#define ordered_set tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update>
#pragma 03
using namespace std;
using namespace __gnu_pbds;
deque <ll> dq;
void solve(ll k){
	if (k == 1) return; 
	else if (k % 2 == 1){
		solve(k - 1); dq.push_front(dq.size() + 1);
	}
	else{
		solve(k / 2); dq.pb(dq.size() + 1);
	}
}
int main(){
	ll n; cin >> n; n++; solve(n);
	cout << dq.size() * 2 << endl;
	for (ll i = 0; i < dq.size(); i++) cout << dq[i] << " ";
	for (ll i = 0; i < dq.size(); i++) cout << i + 1 << " ";
}

Measured memory_bytes: 256
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};

fn main() {
    let n = read::<u32>();
    let mut sv: Vec<String> = Vec::new();
    for _ in 0..n {
        let s = read::<String>();
        sv.push(s);
    }
    let m = read::<u32>();
    let mut tv: Vec<String> = Vec::new();
    for _ in 0..m {
        let t = read::<String>();
        tv.push(t);
    }

    let mut map: HashMap<String, i32> = HashMap::new();
    for s in sv {
        match map.entry(s) {
            Vacant(entry) => { entry.insert(1); }
            Occupied(mut entry) => {
                let mut cnt = entry.get_mut();
                *cnt += 1;
            }
        }
    }
    for t in tv {
        match map.entry(t) {
            Vacant(entry) => { entry.insert(-1); }
            Occupied(mut entry) => {
                let mut cnt = entry.get_mut();
                *cnt -= 1;
            }
        }
    }

    let mut max = 0;
    for (_, v) in map.iter() {
        if max < *v {
            max = *v;
        }
    }

    println!("{}", max);
}

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


Measured memory_bytes: 4352
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
using namespace std;

#define MAX 2000000000
#define SIZE 200010
int cnt;
long long inv;
int L[SIZE/2+2],R[SIZE/2+2];

int merge(int a[],int l,int m,int r)
{
	int n1=m-l;
	int n2=r-m;
	for(int i=0;i<n1;i++)
	{
		L[i]=a[l+i];
	}
	L[n1]=MAX;
	for(int i=0;i<n2;i++)
	{
		R[i]=a[m+i];
	}
	R[n2]=MAX;
	int i=0,j=0;
	for(int k=l;k<r;k++)
	{
		if(L[i]<=R[j])
		{
			a[k]=L[i++];
		}
		else
		{
			a[k]=R[j++];
			inv+=n1-i;
		}
		cnt++;
	}
}

int mergeS(int a[],int l,int r)
{
	if(l+1<r)
	{
		int m=(l+r)/2;
		mergeS(a,l,m);
		mergeS(a,m,r);
		merge(a,l,m,r);
	}
}

int main()
{
	int n;cin>>n;int a[SIZE];
	for(int i=0;i<n;cin>>a[i++]);
	mergeS(a,0,n);
	cout<<inv<<endl;
	return 0;
}

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

using namespace std;

int N, a[100009], flow[100009];
vector < int > v[100009];

void Ans (bool ok)
{
    if (ok) printf ("YES\n");
    else printf ("NO\n");
    exit (0);
}

void dfs (int nod, int tata)
{
    vector < int > h;
    for (auto it = v[nod].begin (); it != v[nod].end (); it ++)
        if (*it != tata)
            dfs (*it, nod), h.push_back (flow[*it]);
    if (h.empty ()) flow[nod] = a[nod];
    else
    {
        int s = 0;
        for (auto it = h.begin (); it != h.end (); it ++)
        {
            s += *it;
            if (s > 2 * a[nod]) Ans (0);
        }
        flow[nod] = 2 * a[nod] - s;
        if (tata == -1 && flow[nod] > 0)
            Ans (0);
        h.push_back (flow[nod]);
        for (auto it = h.begin (); it != h.end (); it ++)
            if (*it > a[nod])
                Ans (0);
    }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
if (N == 2) Ans (a[1] == a[2]);
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    v[x].push_back (y);
    v[y].push_back (x);
}
int root;
for (int i=1; i<=N; i++)
    if (v[i].size () != 1)
        root = i;
dfs (root, -1);
Ans (1);
return 0;
}


Measured memory_bytes: 13568
#include <cassert>
#include <iostream>
#include <queue>
#include <string>
#include <map>
#include <limits>
#include <vector>
#include <set>

using namespace std;

template< typename T >
struct Edge {
  int from, to;
  T cost;
  Edge() {}
  Edge(int f, int t) : from(f), to(t), cost(1) {}
  Edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  friend bool operator < (const Edge& lhs, const Edge& rhs) { return lhs.cost < rhs.cost; };
  friend bool operator > (const Edge& lhs, const Edge& rhs) { return rhs < lhs; };
  friend bool operator <= (const Edge& lhs, const Edge& rhs) { return !(lhs > rhs); };
  friend bool operator >= (const Edge& lhs, const Edge& rhs) { return !(lhs < rhs); };
};

template< typename T >
using Edges = std::vector< Edge< T > >;
template< typename T >
using Graph = std::vector< Edges< T > >;

typedef long long ll;

vector<int> color(200000, -1);

void dfs(const Graph<int>& g, int v, int d) {
  color[v] = d%2;
  for (auto &e: g[v]) {
    if (color[e.to] >= 0) continue;
    dfs(g, e.to, d+1);
  }
}

int main() {
  int n; cin >> n;
  int n3 = n/3;
  Graph<int> g(n);
  for (int i = 0; i < n-1; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].emplace_back(a, b);
    g[b].emplace_back(b, a);
  }
  dfs(g, 0, 0);
  vector<int> nc(2);
  for (int i = 0; i < n; ++i) {
    ++nc[color[i]];
  }
  vector<int> ans(n, -1);
  int s = 3;
  vector<bool> used(n+1, false);
  if (nc[0] <= n3) {
    for (int i = 0; i < n; ++i) {
      if (color[i] == 0) { used[s] = true; ans[i] = s; s+=3; }
    }
  }
  else if (nc[1] <= n3) {
    for (int i = 0; i < n; ++i) {
      if (color[i] == 1) { used[s] = true; ans[i] = s; s+=3; }
    }
  }
  else {
    int n1 = 1, n2 = 2, n3 = 3;
    for (int i = 0; i < n; ++i) {
      if (color[i] == 0) { 
        if (n1 > n) {
          ans[i] = n3; n3+=3;
        }
        else {
          ans[i] = n1; n1+=3;
        }
      }
      if (color[i] == 1) {
        if (n2 > n) {
          ans[i] = n3; n3+=3;
        }
        else {
          ans[i] = n2; n2+=3;
        }
      }
    }
  }
  int n1 = 1;
  for (int i = 0; i < n; ++i) {
    if (ans[i] == -1) {
      while (used[n1]) ++n1;
      ans[i] = n1;
      ++n1;
    }
  }
  set<int> ln;
  for (int i : ans) {
    assert(i > 0 && i <= n);
    ln.insert(i);
    cout << i << endl;
  }
  assert(ln.size() == n);
}



Measured memory_bytes: 25448
#include<stdio.h>
int main(){
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)break;
		if(x>y)printf("%d %d\n",y,x);
		else printf("%d %d\n",x,y);
	}
	return 0;
}

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

using namespace std;

using ll = long long;

int INF = 1e9 + 5;

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

    int N, W;
    cin >> N >> W;
    
    vector<int> w(N), v(N);
    for(int i=0; i<N; ++i)
    {
        cin >> w[i] >> v[i];
    }
    
    int V = accumulate(begin(v),end(v),0);

    vector<ll> dp(V+1,INF);
    
    dp[0] = 0;
    
    for(int i=0; i<N; ++i)
    {
        for(int j=V; j>=v[i]; --j)
        {
            dp[j] = min( dp[j] , w[i] + dp[j - v[i]]);
        }
        
        //for_each(begin(dp),end(dp),[](auto x){ cout << x << " ";}); cout << endl;
    }
    
    cout << distance(find_if(rbegin(dp),rend(dp),[W](auto x){ return (x<=W);}),rend(dp)) -1;
    
}


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

using namespace std;


const int INF = 1 << 30;

typedef vector< int > vi;

vi operator+(const vi &t, const vi &s)
{
  vi ret(52);
  for(int i = 0; i < 52; i++) ret[i] = t[i] + s[i];
  return (ret);
}

vi operator-(const vi &t)
{
  vi ret(52);
  for(int i = 0; i < 52; i++) ret[i] = t[i] * -1;
  return (ret);
}

vi operator*(const vi &t, int k)
{
  vi ret(52);
  for(int i = 0; i < 52; i++) ret[i] = t[i] * k;
  return (ret);
}

struct Primal_Dual
{
  typedef pair< vi, int > Pi;

  struct edge
  {
    int to, cap;
    vi cost;
    int rev;
  };

  vector< vector< edge > > graph;
  vector< vi > potential, min_cost;
  vector< int > prevv, preve;

  Primal_Dual(int V) : graph(V) {}

  void add_edge(int from, int to, int cap, vi cost)
  {
    graph[from].push_back((edge) {to, cap, cost, (int) graph[to].size()});
    graph[to].push_back((edge) {from, 0, -cost, (int) graph[from].size() - 1});
  }

  vi min_cost_flow(int s, int t, int f)
  {
    int V = graph.size();
    vi ret(52, 0);
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    potential.assign(V, vi(52, 0));
    preve.assign(V, -1);
    prevv.assign(V, -1);

    while(f > 0) {
      min_cost.assign(V, vi(52, INF));
      que.push(Pi(vi(52, 0), s));
      min_cost[s] = vi(52, 0);

      while(!que.empty()) {
        Pi p = que.top();
        que.pop();
        if(min_cost[p.second] < p.first) continue;
        for(int i = 0; i < graph[p.second].size(); i++) {
          edge &e = graph[p.second][i];
          vi nextCost = min_cost[p.second] + e.cost + potential[p.second] + -potential[e.to];
          if(e.cap > 0 && min_cost[e.to] > nextCost) {
            min_cost[e.to] = nextCost;
            prevv[e.to] = p.second, preve[e.to] = i;
            que.push(Pi(min_cost[e.to], e.to));
          }
        }
      }
      if(min_cost[t][0] == INF) return (vi(52, -1));
      for(int v = 0; v < V; v++) potential[v] = potential[v] + min_cost[v];
      int addflow = f;
      for(int v = t; v != s; v = prevv[v]) {
        addflow = min(addflow, graph[prevv[v]][preve[v]].cap);
      }
      f -= addflow;
      ret = ret + potential[t] * addflow;
      for(int v = t; v != s; v = prevv[v]) {
        edge &e = graph[prevv[v]][preve[v]];
        e.cap -= addflow;
        graph[v][e.rev].cap += addflow;
      }
    }
    return ret;
  }
};

const string temp = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

int main()
{
  int N;
  string S[50];

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

  Primal_Dual flow(N + N + 2);
  const int s = N + N, t = N + N + 1;
  vi vc(52, 0);
  for(int i = 0; i < N; i++) flow.add_edge(s, i, 1, vc);
  for(int i = 0; i < N; i++) flow.add_edge(i + N, t, 1, vc);
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      vc[temp.find(S[i][j])]--;
      flow.add_edge(i, j + N, 1, vc);
      vc[temp.find(S[i][j])]++;
    }
  }

  auto cost = flow.min_cost_flow(s, t, N);
  for(int i = 0; i < 52; i++) cout << string(-cost[i], temp[i]);
  cout << endl;
}

Measured memory_bytes: 4500
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val A = Array(3) { next() }
    var p = 0
    while (A[p].isNotEmpty()) {
        val tmp = A[p][0]
        A[p] = A[p].drop(1)
        p = tmp - 'a'
    }
    println(if (p == 0) "A" else if (p == 1) "B" else "C")
}

Measured memory_bytes: 33496
#include <stdio.h>
 
int money(int p,int q) {
    return p*(100+q)/100;
}
 
int main(void) {
    int x,y,s;
    while(scanf("%d%d%d",&x,&y,&s)&& (x|y|s)!=0) {
        int answer=0;
        int i,j;
        for(i=1;i<s;i++) {
            for(j=i;j<s;j++) {
                if(money(i,x)+money(j,x)==s) {
                    int nm=money(i,y)+money(j,y);
                    if(nm>answer)answer=nm;
                }
            }
        }
        printf("%d\n",answer);
    }
    return 0;
}



Measured memory_bytes: 2104
# 3つの整数 A, B, C が与えられます。
# 整数 C が A 以上 かつ B 以下であるかを判定してください。

# 制約
# −100 ≦ A, B, C ≦ 100
# A, B, C は全て整数

# 標準入力から A, B, C を取得する
a, b, c = map(int, input().split())

# 判定して結果を出力する
resut = "ret"

if a <= c and b >= c:
    result = "Yes"
else:
    result = "No"

print(result)


Measured memory_bytes: 9064
n=int(input())
s=input()
r=[0]*n
g=[0]*n
b=[0]*n
R=0; G=0; B=0
for i in range(n):
    if s[i]=="R":
        r[i]=1
        R+=1
    elif s[i]=="G":
        g[i]=1
        G+=1
    else:
        b[i]=1
        B+=1
s=0
for j in range(n):
    for k in range(n):
        if r[j]==1 and g[k]==1:
            if j!=k:
                j1,k1=(max(j,k),min(j,k))
                if (j1-k1)+j1<n:
                    if b[(j1-k1)+j1]==1:
                        s+=1
                if k1-(j1-k1)>=0:
                    if b[k1-(j1-k1)]==1:
                        s+=1
                if (j1-k1)>1 and (j1-k1)%2==0:
                    if b[k1+(j1-k1)//2]==1:
                        s+=1
print(R*G*B-s)

Measured memory_bytes: 69752
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> vs(H);
  FOR(i,0,H) cin >> vs[i];
  FOR(i,0,W+2) cout << "#";
  cout << endl;
  FOR(i,0,H) cout << "#" + vs[i] + "#" << endl;
  FOR(i,0,W+2) cout << "#";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
while True:
    grade = "F"
    m,f,r = [int(x) for x in input().split()]
    if(m == -1 and f == -1 and r == -1):
        break
    
    s = m+f
    if(m == -1 or f == -1):
        grade = "F"
    elif(s >= 80):
        grade = "A"
    elif(s >= 65):
        grade = "B"
    elif(s >= 50 or (s>=30 and r >= 50)):
        grade = "C"
    elif(s >= 30):
        grade = "D"

    print(grade)


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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const lb pi=acos(-1);
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;


int main(){

  ll a,b;cin>>a>>b;
  out(a*b);


  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#pragma warning(disable : 4996)

#define MAX_N 100000
#define INF 1000000000

template <typename T> bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <typename T> bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int Abs(int a) {
	if (a < 0) return a *= -1;
	return a;
}

int N;
std::vector<int> H;
int DP[MAX_N];

int main(void) {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		int h;
		scanf("%d", &h);
		H.push_back(h);
		DP[i] = INF;
	}
	DP[0] = 0;
	DP[1] = Abs(H[1] - H[0]);
	for (int i = 2; i < N; ++i) {
		chmin(DP[i], DP[i - 1] + Abs(H[i] - H[i - 1]));
		chmin(DP[i], DP[i - 2] + Abs(H[i] - H[i - 2]));
	}
	printf("%d", DP[N - 1]);
	return 0;
}


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

int main() {
    int a,b; cin >> a >> b;
    if (a*b % 2 == 0)
    {
        cout << "Even\n";
    } else {
        cout << "Odd\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
// DECLARAÇÕES
int N,T;
int c,t;
int custo = 1000;
int i = 0;

// INSTRUÇÕES
scanf ("%d %d",&N,&T);

for (int aux = 0; aux < N; aux++){
    scanf ("%d %d",&c,&t);

    if (t <= T){
        i = 1;
        if (c < custo)
            custo = c;
    }
}

if ( i == 1)
    printf ("%d\n",custo);
else
    printf ("TLE\n");


return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 2e5+10;
const int M = 2e5+10;
const int INF = 0x3f3f3f3f;

int a[N];

int main(void)
{
//	ios::sync_with_stdio(false);
//	cin.tie(false); cout.tie(false);
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> a[i];
	double res = 0;
	for(int i = 0; i < n; ++i) res += 1.0/a[i];
	printf("%.5f\n", 1/res);
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    int a[101];
    cin>>n;
    if(n!=0){
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=1;i<n;i++){
            cout<<a[n-i]<<" ";
        }
        cout<<a[0]<<endl;
    }
}

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

typedef long long ll;

int main()
{
	vector<int> n(3);
	int x;
	cin >> n[0] >> n[1] >> n[2];
	sort(n.begin(),n.end());
	if((3*n[2])%2 == (n[0]+n[1]+n[2])%2) x = n[2];
	else x = n[2]+1;
	cout << (3*x - n[0] - n[1] - n[2])/2 << '\n';
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
d = [s - a[0]*2,] + [0 for _ in range(n-2)]
for i in range(1,n-1):
    d[i] = d[i-1] - a[i]*2
print(min([abs(i) for i in d]))

Measured memory_bytes: 24824
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

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

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	ll n;
	map<int, ll> field;
	vi jun;

	while(cin >> n, n) {
		field.clear();
		jun.clear();

		int ban;
		ll tan, suu;
		bool flag = true;

		REP(i, n) {
			cin >> ban >> tan >> suu;

			if(!field[ban]) {
				jun.push_back(ban);
			}

			if(field[ban] < 1000000) {
				field[ban] += tan*suu;
			}
		}

		if(jun.size() == 0) {
			cout << "NA" << endl;
		} else {
			REP(i, jun.size()) {
				if(field[jun[i]] >= 1000000) {
					cout << jun[i] << endl;
					flag = false;
				}
			}
			if(flag) {
				cout << "NA" << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1288
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;


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

    long long int res = 0;
    for (long long int i = n - 1; i > 0; i--) {
        res += i;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	long long A, B, C, K;
	cin >> A >> B >> C >> K;
	long long ans = 0;
	long long x;
	
	x = min(A, K);
	ans += x;
	A -= x;
	K -= x;

	x = min(B, K);
	B -= x;
	K -= x;

	x = min(C, K);
	ans -= x;
	C -= x;
	K -= x;

	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <typename T>
class fenwick_tree {
	const int n;
	vector<T> data;
public:
	fenwick_tree(int n_) : n(n_), data(n) {}
	T find(int p) const {
		T res = 0;
		while (p >= 0) {
			res += data[p];
			p = (p & (p + 1)) - 1;
		}
		return res;
	}
	T find(int l, int r) const {
		return find(r) - find(l - 1);
	}
	void add(int p, T val) {
		while (p < n) {
			data[p] += val;
			p |= p + 1;
		}
	}
};

struct RMQ {
	using type = int;
	static type id() { return INT_MAX; }
	static type op(const type& l, const type & r) { return min(l, r); }
};

template <typename M>
class segment_tree {
	using T = typename M::type;
	const int n;
	vector<T> data;
	int expand(int x) {
		int res;
		for (res = 1; res < x; res <<= 1);
		return res;
	}
public:
	segment_tree(int n_) : n(expand(n_)), data(n * 2, M::id()) {}
	segment_tree(int n_, T val) : n(expand(n_)), data(n * 2, val) {}
	void init(const vector<T>& data_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = M::op(data[i * 2], data[i * 2 + 1]);
	}
	void update(int p, T val) {
		data[p += n] = val;
		while (p >>= 1) data[p] = M::op(data[p * 2], data[p * 2 + 1]);
	}
	void add(int p, T val) {
		data[p += n] += val;
		while (p >>= 1) data[p] = M::op(data[p * 2], data[p * 2 + 1]);
	}
	T find(int l, int r) {
		l += n; r += n + 1;
		T res1 = M::id(), res2 = M::id();
		while (l < r) {
			if (l & 1) res1 = M::op(res1, data[l++]);
			if (r & 1) res2 = M::op(data[--r], res2);
			l >>= 1; r >>= 1;
		}
		return M::op(res1, res2);
	}
};

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> x(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}
	auto xs = x;
	sort(xs.begin(), xs.end());
	for (int i = 0; i < N; i++) {
		x[i] = lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin();
	}
	ll rev = 0;
	fenwick_tree<int> ft(N);
	for (int i = 0; i < N; i++) {
		rev += i - ft.find(x[i]);
		ft.add(x[i], 1);
	}
	if (rev <= K) {
		for (int i = 0; i < N; i++) {
			printf("%d\n", xs[x[i]]);
		}
		return 0;
	}
	rev -= K;
	vector<int> pos(N);
	for (int i = 0; i < N; i++) {
		pos[x[i]] = i;
	}
	vector<int> top;
	segment_tree<RMQ> st(N);
	for (int i = 0; i < N; i++) {
		st.update(pos[i], i);
	}
	while (rev > 0) {
		int t;
		{
			int lb = -1, ub = N - 1;
			while (ub - lb > 1) {
				int c = (lb + ub) >> 1;
				if (ft.find(c) <= rev) {
					lb = c;
				}
				else {
					ub = c;
				}
			}
			t = ub;
		}
		int id = st.find(0, t);
		assert(0 <= id && id < N);
		ft.add(pos[id], -1);
		rev -= ft.find(pos[id]);
		st.update(pos[id], INT_MAX);
		top.push_back(id);
	}
	vector<int> res(N);
	for (int i = 0, j = 0; i < N; i++) {
		if (i < (int)top.size()) {
			res[i] = top[i];
		}
		else {
			while (ft.find(j, j) == 0) ++j;
			res[i] = x[j++];
		}
	}
	for (int i = 0; i < N; i++) {
		printf("%d\n", xs[res[i]]);
	}
	return 0;
}



Measured memory_bytes: 6520
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int[] blockDistance = new int[10];
	int v1, v2;
	String[] input;
	while (scan.hasNext()) {
	    input = scan.nextLine().split(",");
	    for (int i = 0; i < 10; i++) {
		blockDistance[i] = Integer.parseInt(input[i]);
	    }
	    v1 = Integer.parseInt(input[10]);
	    v2 = Integer.parseInt(input[11]);
	    System.out.println(solve(v1, v2, blockDistance));
	}
    }
    static int solve (int v1, int v2, int[] blockDistance) {
	int alldistance = 0;
	for (int i = 0; i < 10; i++) {
	    alldistance += blockDistance[i];
	}
	double time = alldistance / (double)(v1 + v2);
	double meetplace = v1 * time;
	int i = 0;
	while (meetplace > 0) {
	    meetplace -= blockDistance[i++];
	}
	return i;
    }
}

Measured memory_bytes: 25720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

struct SegmentTree {
private:
    int n;
    vector<int> node;

public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1; 
        while(n < sz) n *= 2;
        node.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[2*i+1] + node[2*i+2];
    }

    void update(int x) {
        x += (n - 1);

        node[x]++;
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = node[2*x+1] + node[2*x+2];
        }
    }

    int getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;

        if(r <= a || b <= l) return 0;

        if(a <= l && r <= b) return node[k];

        int vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        int vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
        cin >> C[i]; C[i]--;
    }

    vector<int> pre(N, -1);
    vector<iint> A;
    for (int i = 0; i < N; i++) {
        if(pre[C[i]] != -1){
            A.push_back(make_pair(pre[C[i]], i));
        }
        pre[C[i]] = i;
    }

    vector<pair<iint, int>> q;
    for (iint v : A) {
        q.push_back(make_pair(make_pair(v.second, -1), v.first));
    }
    int x,y;
    for (int i = 0; i < Q; i++) {
        cin >> x >> y; x--; y--;
        q.push_back(make_pair(make_pair(y, i), x));
    }
    sort(ALL(q));

    // for (int i = 0; i < q.size(); i++) {
    //     printf("%d %d %d\n", q[i].first.first, q[i].first.second, q[i].second);
    // }

    vector<int> V(N, 0);
    SegmentTree T(V);
    vector<int> ans(Q);
    for (pair<iint, int> v : q) {
        if(v.first.second != -1){
            x = T.getsum(v.second, v.first.first+1);
            ans[v.first.second] = v.first.first - v.second - x + 1;
        }
        else{
            T.update(v.second);
        }
    }

    for (int i = 0; i < Q; i++) {
        printf("%d\n", ans[i]);
    }



}

Measured memory_bytes: 30516
import sys

seq = sys.stdin.readline().strip()
odd_str = 'RUD'
even_str = 'LUD'
result = 'Yes'

for i in range(len(seq)):
    c = seq[i]
    if (i + 1) % 2 == 0:
        if not c in even_str:
            result = 'No'
    else:
        if not c in odd_str:
            result = 'No'

print(result)

Measured memory_bytes: 3064
package main

import "fmt"

// func main() {
// 	var a, b int
//
// 	fmt.Scan(&a, &b)
// 	res := a * b % 2
// 	foo := map[bool]string{true: "Even", false: "Odd"}[res == 0]
// 	fmt.Println(foo)
// }

func main() {
	var a, b int

	fmt.Scan(&a, &b)
	res := a * b % 2
	if res == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<<24)
int N;
int t[500],sum[500];
int dp[500][500];
 
int calc(int X,int Y){
 
  int res=0,c=-1,a,b;
  for(int I=0;I<50;I++){
 
    if(c==-1||c+a+b<10)c=0;
    else c=1;
    a=X%10;
    b=Y%10;
    X/=10;
    Y/=10;
    res+=(a*b+c);
  }
 
  return res;
}
int solve(int l,int r){
 
  if(dp[l][r]!=-1)return dp[l][r];
  if(l==r)return 0;
  int res=INF;
  for(int i=l;i<r;i++){
    
    res=min(res, solve(l,i)+solve(i+1,r)+calc(sum[i]-sum[l-1],sum[r]-sum[i]));
  }
 
  return dp[l][r]=res;
}
 
void init(){
  for(int i=0;i<500;i++){
    t[i]=sum[i]=0;
    for(int j=0;j<500;j++)dp[i][j]=-1;
  }
}
 
int main(){
  init();
  cin>>N;
  for(int i=1;i<=N;i++){
    cin>>t[i];
    sum[i]=t[i]+sum[i-1];
  }
 
  cout<<solve(1,N)<<endl;
  return 0;
}

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

int n, k, m, b;
long long ans, semi, a[31];

int main() {
    cin >> n >> k;
    for (int i=1; i<k+1; i++) {
        if ((k-i)%2 == 0) semi =1;
        else semi = -1;
        a[0] = i; b = n;
        for (int j=0; b > 0; j++) {
            if (b%2 == 1) semi = (semi*a[j]) % 1000000007;
            a[j+1] = (a[j]*a[j]) % 1000000007;
            b/=2;
        }
        if (2*i > k) m = i;
        else m = k-i;
        for (int j=k; j>m; j--) {
            semi = (semi * j) % 1000000007;
        }
        for (int j=2; j<k-m+1; j++) {
            a[0] = j; b = 1000000005;
            for (int s=0; b>0; s++) {
                if (b%2 == 1) semi = (semi * a[s]) % 1000000007;
                a[s+1] = (a[s]*a[s]) % 1000000007;
                b/=2;
            }
        }
        ans = (ans + semi + 1000000007)%1000000007;
    }
    for (int i=2; i<k+1; i++) {
        a[0] = i; b = 1000000005;
        for (int s=0; b>0; s++) {
            if (b%2 == 1) ans = (ans * a[s]) % 1000000007;
            a[s+1] = (a[s]*a[s]) % 1000000007;
            b/=2;
        }
    }
    if (n < k) ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 3124
#include<iostream>
#include<string>
using namespace std;
#define SWAP(a,b) {Trump tmp = a;a = b; b= tmp;}

class Trump{
    int num;
    char mark;
public:
    Trump(int a=1,char b='H'):num(a),mark(b){}
    char getMark(){return mark;}
    void set(int a,char b){
        this->num = a;
        this->mark = b;
    }
    string show(){
        return mark+to_string(num);
    }
    bool operator < (const Trump& right)const{
        return this->num < right.num;
    }
    bool operator > (const Trump& right)const{
        return this->num > right.num;
    }
    bool operator <= (const Trump& right)const{
        return this->num <= right.num;
    }
    bool operator >= (const Trump& right)const{
        return this->num >= right.num;
    }
};

void selectionsort(Trump A[],int n){

    for(int i=0;i<n;i++){
        int minj = i;
        for(int j=i;j<n;j++){
            if(A[j]<A[minj])minj=j;
        }
        if(i!=minj)SWAP(A[i],A[minj]);
    }
}

void bubblesort(Trump A[],int n){
    for(int i=0;i<n;i++){
        for(int j=n-1;j>i;j--){
            if(A[j]<A[j-1])SWAP(A[j],A[j-1]);
        }
    }
}

int main(){
    int n;
    cin >> n;
    Trump A[n],B[n];
    char ct;
    int ci;
    for(int i=0;i<n;i++){cin >> ct >> ci;A[i].set(ci,ct);B[i].set(ci,ct);}
    selectionsort(B,n);
    bubblesort(A,n);
    cout << A[0].show();
    for(int i=1;i<n;i++)cout <<" "<< A[i].show();
    cout << endl;
    cout << "Stable" << endl;
    cout << B[0].show();
    for(int i=1;i<n;i++)cout <<" "<< B[i].show();
    cout << endl;
    for(int i=0;i<n;i++)if(A[i].show()!=B[i].show()){cout << "Not stable" <<endl;return 0;}
    cout << "Stable" << endl;
    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define EB emplace_back

typedef std::vector <int> vector;
const int N = 300054;

int n, R;
int x[N];
vector left[N];

int sum(int h) {int s = 0; for (; h; h &= h - 1) s += x[h]; return s;}
void add(int h, int v) {for (; h <= R; h |= h - 1, ++h) x[h] += v;}

int main() {
	int i, j, l, r, ans;
	scanf("%d%d", &n, &R);
	for (i = 0; i < n; ++i) scanf("%d%d", &l, &r), left[r - l + 1].EB(l);
	for (i = 1; i <= R; ++i) {
		for (ans = n, j = i; j <= R; j += i) ans += sum(j);
		printf("%d\n", ans);
		for (int le : left[i]) add(le, 1), add(le + i, -1), --n;
	}
	return 0;
}

Measured memory_bytes: 12288