akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    string s;
    cin>>s;
    rep(i,3){
        cout<<s[i];
        if(i==2){
            cout<<endl;
        }
    }
    
}



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

using namespace std;
  
int main(){

	int n;
	string ans;
	string bdata=("01234567");
	string adata=("01235789");
	while(1){

		cin>>n;
		if(n==0) break;
		ans="";

		while(n!=0){
			ans+=(n%8)+'0';
			n/=8;
		}

		for(int i=0;i<ans.length();i++){
			ans[i]=adata[bdata.find(ans[i])];
		}
		
		for(int i=ans.length()-1;i>=0;i--) cout<<ans[i];
		cout<<endl;
	}

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int cnt=0;
    for(int i=0; i<n-1; i++){
        int min_num=i;
        for(int j=i+1; j<n; j++){
            if(a[min_num]>a[j]) min_num=j; 
        }
        if(min_num!=i) cnt++;
        swap(a[i],a[min_num]);
    }
    for(int i=0; i<n; i++){
        if(i!=n-1) cout << a[i] << " ";
        else cout << a[i] << endl;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3108
use std::cmp;

macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(i64);
    let k = scan!(i64);
    let mut ans = 1;
    for _ in 0..n {
        ans = cmp::min(ans + k, 2 * ans)
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int f[3][100001];
int main() {
	string s;
	cin >> s;
	ll k = 0, c = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'B')k += s.size() - i - ++c;
	}
	printf("%lld\n", k);
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
	int first, second, add;
	char seiseki;
	while(1){
		scanf("%d %d %d",&first,&second,&add);
		if(first == -1){
			if(second == -1){
				if(add == -1){
					break;
				}
			}
		}
		if(first + second >= 80){
			seiseki = 'A';
		}else if(first + second >= 65){
			seiseki = 'B';
		}else if(first + second >= 50){
			seiseki = 'C';
		}else if(first + second >= 30){
			if(add >= 50){
				seiseki = 'C';
			}else{
				seiseki = 'D';
			}
		}else{
			seiseki = 'F';
		}
		if(first == -1){
			seiseki = 'F';
		}else if(second == -1){
			seiseki = 'F';
		}
		printf("%c\n",seiseki);
	}
	return 0;
}

Measured memory_bytes: 1028
// Sasageyo! Sasageyo! Shinzou wo Sasageyo !
// https://goo.gl/IwJzbx

#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define endl '\n'

int main()
{
	fast_io;
  LL x, a, b;
  cin >> x >> a >> b;
  if (b <= a)
    cout << "delicious" << endl;
  else if (b - a <= x)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int X,N,p[100];
  scanf("%d",&X);
  scanf("%d",&N);
  
  
  
  if(N==0){
   printf("%d",X); 
  }else{
    for(int i=0;i<N;i++){
   scanf("%d",&p[i]);
  }
   for(int i=0;;i++){
     for(int j=0;j<N+1;j++){
        if(j==N){
          printf("%d",X-i);
          return 0;
        }
    	if(X-i == p[j])
          break;
     }
     for(int j=0;j<N+1;j++){
        if(j==N){
          printf("%d",X+i);
          return 0;
        }
    	if(X+i == p[j])
          break;
     }
   }
  }
 return 0; 
}

Measured memory_bytes: 1732
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] balls = new int[n + 1]; // 直感的に扱うために1個多めに確保

        for (int i = 0; i < n; i++) {
            balls[sc.nextInt()]++; // こういう書き方もできる
        }

        Arrays.sort(balls); // 昇順にソート
        int totalK = 0;
        for (int i = n; i >= n - k + 1; i--) {
            totalK += balls[i];
        }
        System.out.println(n - totalK);
    }
}

Measured memory_bytes: 65224
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=998244353;

int N,ans,cnt;int X;
string x;

int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}

int f(int a){//長さaのループがX以下に何種類存在するか
  int res=0;
  for(int i=0;i<a;i++)if(x[i]=='1')res+=pw(2,a-i-1),res%=MOD;
  string s=x.substr(0,a);
  string t=s;
  for(int i=0;i<s.size();i++){
    if(t[i]=='0')t[i]='1';
    else t[i]='0';
  }
  string u;
  for(int i=0;u.size()<N;i++){
    if(i&1)u+=t;
    else u+=s;
  }
  for(int i=a;i<N;i++){
    if(x[i]=='1'&&u[i]=='0'){
      res++;break;
    }
    if(x[i]=='0'&&u[i]=='1'){
      break;
    }
    if(i==N-1)res++;
  }
  return res;
}

int INT(string x){
  int res=0;
  for(char p:x){
    res*=2;
    res+=p-'0';
    res%=MOD;
  }
  return res;
}

signed main(){
  cin>>N>>x;
  typedef pair<int,int> P;
  typedef pair<int,P> IP;
  vector<IP> v;
  for(int i=1;i<N;i++){
    if(N%i)continue;
    if((N/i)&1){
      int A=f(i);
      v.push_back(IP(i,P(A,0)));
      /*
      ans+=A*2*i%MOD;ans%=MOD;
      cnt+=A;
      cout<<A<<" "<<i<<endl;
      */
    }
  }
  for(int i=0;i<v.size();i++){
    IP p=v[i];
    int n=p.first,s=p.second.first,t=p.second.second;
    for(int j=i+1;j<v.size();j++){
      if(v[j].first%n==0){
        v[j].second.second+=s-t;
      }
    }
    ans+=(s-t)*2*n%MOD;ans%=MOD;
    cnt+=s-t;cnt%=MOD;
  }
  ans+=(INT(x)+1-cnt)%MOD*N*2%MOD;ans%=MOD;ans+=MOD;ans%=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 1064
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
const int N=3e5+2;
ll M=1e9+7;
ll a[N];
int main()
{
    ft
    ll i,j,n,s=0,l,r,m;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0,m=1;i<61;i++,m*=2)
    {
        l=r=0;
        for(j=0;j<n;j++)
        {
            (a[j]%2)? l++: r++;
            a[j]/=2;
        }
        s+=(((l*r)%M)*(m%M))%M;
        s%=M;
    }
    cout<<s<<"\n";
    return 0;
}

Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define lowbit(x) ((x)&(-x))
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int maxn = 1e5 + 10;
const int maxm = 1e6 + 10;
const ll mod =  998244353;

int a[maxn],b[maxn << 1];

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 0; i < m; i++) scanf("%d",&a[i]);
    if(n >= m) return puts("0"), 0;
    sort(a, a + m);
    int tot = 0;
    b[tot++] = abs(a[0] - a[1]);
    for(int i = 1; i < m - 1; i++) {
        b[tot++] = a[i] - a[i - 1];
        b[tot++] = a[i + 1] - a[i];
    }
    b[tot++] = abs(a[m - 1] - a[m - 2]);
    sort(b, b + tot);
    int now = m;
    ll ans = 0;
    for(int i = 0; i < tot && now > n; i += 2,now--) ans += b[i];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef double db;
#define pb push_back
#define w1 first
#define w2 second
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
const int maxn=205,mod=998244353;
int n,ans,ilg;
int x[maxn],y[maxn],bin[maxn];
map<db,int>cnt;
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int main(){
	read(n);
	bin[0]=1;rep(i,1,n)bin[i]=2ll*bin[i-1]%mod;
	ans=bin[n];
	rep(i,1,n)read(x[i]),read(y[i]);
	rep(i,1,n){
		cnt.clear();
		rep(j,1,n)if(i!=j)cnt[atan2(y[j]-y[i],x[j]-x[i])]++;
		for(map<db,int>::iterator it=cnt.begin();it!=cnt.end();it++)ilg=add(ilg,sub(bin[it->w2],1));
	}
	ilg=1ll*ilg*power(2,mod-2,mod)%mod;
	ilg=add(ilg,n+1);
	printf("%d\n",sub(ans,ilg));
	return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  string S[110];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  sort(S, S + N);
  string ans = "";
  for (int i = 0; i < N; i++) ans += S[i];

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#define ll long long
using namespace std;
ll N,M;
vector<ll> H,A,B;
vector<ll> test;
vector<ll> flag;
int main(){
     cin >> N >> M;
     ll s,t;
     for(int i = 0; i < N; i++){
          cin >> s;
          H.push_back(s);
          test.push_back(0);
          flag.push_back(1);
     }
     for(int i = 0; i < M; i++){
          cin >> s >> t;
          A.push_back(s); B.push_back(t);
          if(H[A[i] - 1] > H[B[i] - 1]){
               flag[A[i] - 1] *= 1;
               flag[B[i] - 1] *= 0;
               test[A[i] - 1] += 1;
               test[B[i] - 1] -= 1;
          }else if(H[A[i] - 1] < H[B[i] - 1]){
               flag[A[i] - 1] *= 0;
               flag[B[i] - 1] *= 1;
               test[A[i] - 1] -= 1;
               test[B[i] - 1] += 1;
          }else if(H[A[i] - 1] == H[B[i] - 1]){
               flag[A[i] - 1] *= 0;
               flag[B[i] - 1] *= 0;
          }
     }
     ll counter = 0;
     for(int i = 0; i < N; i++){
          if(flag[i] == 1){
               counter++;
          }
     }
     cout << counter << endl;
     return 0;
}

Measured memory_bytes: 7968
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,Q=map(int,input().split())
a=tuple(map(int1,input().split()))
lr=[0]*Q
for i in range(Q):
    l,r=map(int1,input().split())
    lr[i]=(r<<40)+(l<<20)+i
lr.sort(reverse=1)
class BIT:
    def __init__(self,n):
        self.num=n
        self.dat=[0]*(self.num+1)
        self.depth=n.bit_length()
    
    def add(self,i,x):
        i+=1
        while i<=self.num:
            self.dat[i]+=x
            i+=i&-i
    
    def sum(self,i):
        i+=1
        s=0
        while i>0:
            s+=self.dat[i]
            i-=i&-i
        return s
    
    def lower_bound(self,x):
        sum_=0
        pos=0
        for i in range(self.depth,-1,-1):
            k=pos+(1<<i)
            if k<=self.num and sum_+self.dat[k]<x:
                sum_+=self.dat[k]
                pos+=1<<i
        return pos, sum_

b=BIT(N)
lastap=[-1]*N
ans=[-1]*Q
mask=(1<<20)-1
lr_pop=lr.pop
lrj=lr_pop()
j=lrj&mask
lrj>>=20
l=lrj&mask
r=lrj>>20
for i,x in enumerate(a):
    if lastap[x]!=-1:
        b.add(lastap[x],-1)
    b.add(i,1)
    lastap[x]=i
    while r==i:
        ans[j]=b.sum(r)-b.sum(l-1)
        if lr:            
            lrj=lr_pop()
            j=lrj&mask
            lrj>>=20
            l=lrj&mask
            r=lrj>>20
        else:
            l,r,j=-1,-1,-1
print(*ans,sep='\n')

Measured memory_bytes: 168500
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <utility>

template <typename C>
void print_container(const C &c, const std::string &name)
{
  std::cout << name << ": ";
  std::for_each(c.cbegin(), c.cend(),
                [](auto &x) { std::cout << x << ", "; });
  std::cout << std::endl;
}

template <typename Container, class T>
bool contains(const Container& c, T v)
{
  return std::find(c.begin(), c.end(), v) != c.end();
}

template <typename Map ,class T>
bool contains_map(const Map &c, const T &v)
{
  return c.find(v) != c.end();
}

int main()
{
  int N, M;
  std::cin >> N >> M;
  std::vector<int> input(N);
  std::vector<int> group_per_num(N); // index of group_val
  std::vector<int> group_val;
  group_val.push_back(-1);
  int g_next = 0;

  for(int i=0; i<N; i++) {
    int p;
    std::cin >> p;
    input[i] = --p; // 0-origin
  }

  std::multimap<int, int> xy;
  for(int i=0; i<M; i++) {
    int x, y;
    std::cin >> x >> y;
    x--; y--;
    if(y < x) {
      std::swap(x, y);
    }
    xy.insert(std::make_pair(x, y));
  }

  // read input and assign group
  std::map<int, int> lut;
  for(auto z: xy) {
    int x = z.first, y = z.second;

    int &gpn_x = group_per_num[x];
    int &gpn_y = group_per_num[y];
    int &gx = group_val[group_per_num[x]];
    int &gy = group_val[group_per_num[y]];

    if(gx < 0 && gy < 0) {
      group_val.push_back(g_next);
      gpn_x = gpn_y = group_val.size() - 1;
      g_next++;
    } else if(gx >= 0 && gy >= 0 && gx != gy) {
      int new_g = std::min(gx, gy);
      int old_g = std::max(gx, gy);
      for(auto &gv: group_val) {
        if(gv == old_g) {
          gv = new_g;
        }
      }

    } else if(gx < 0) {
      gpn_x = gpn_y;
    } else {
      gpn_y = gpn_x;
    }
  }
  // print_container(group_per_num, "group_per_num");

  std::map<int, std::vector<int>> groups;
  int ret = 0;
  for(int i=0; i<N; i++) {
    auto gpn = group_per_num[i];
    auto g = group_val[gpn];
    if(g < 0) {
      if(i == input[i]) {
        ret++;
      }
    } else {
      groups[g].push_back(i);
    }
  }

  // count numbers such that p == i after permutation
  for(auto g: groups) {
    // std::cout << "g.first: " << g.first << std::endl;
    // print_container(g.second, "g.second");
    for(auto i: g.second) {
      // std::cout << "i: " << i << " input[i]" << input[i] << std::endl;
      if(contains(g.second, input[i])) {
        ret++;
      }
    }
  }

  std::cout << ret << std::endl;
  return 0;
}



Measured memory_bytes: 9664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;

int n,u,v,w,q,ty,x;
vector<PII> e[N];
ll dis[N];
int l[N],r[N],tot,id[N],par[N],pare[N],rt;
PII E[N];

void dfs(int u,int f) {
	l[u]=++tot;
	id[tot]=u;
	//printf("%d %d\n",u,f);
	for (auto p:e[u]) {
		if (p.fi==f) continue;
		dis[p.fi]=dis[u]+p.se;
		par[p.fi]=u;
		pare[p.fi]=p.se;
		dfs(p.fi,u);
	}
	r[u]=tot;
}

struct node {
	pair<ll,int> dis;
	ll tag;
}nd[4*N];
void upd(int p) {
	nd[p].dis=max(nd[p+p].dis,nd[p+p+1].dis);
}
void setf(int p,ll v) {
	nd[p].tag+=v;
	nd[p].dis.fi+=v;
}
void build(int p,int l,int r) {
	if (l==r) {
		nd[p].dis=mp(dis[id[l]],id[l]);
	} else {
		int md=(l+r)>>1;
		build(p+p,l,md);
		build(p+p+1,md+1,r);
		upd(p);
	}
}
void push(int p) {
	if (nd[p].tag) {
		setf(p+p,nd[p].tag);
		setf(p+p+1,nd[p].tag);
		nd[p].tag=0;
	}
}
pair<ll,int> query(int p,int l,int r,int tl,int tr) {
	if (tl==l&&tr==r) return nd[p].dis;
	else {
		push(p);
		int md=(l+r)>>1;
		if (tr<=md) return query(p+p,l,md,tl,tr);
		else if (tl>md) return query(p+p+1,md+1,r,tl,tr);
		else return min(query(p+p,l,md,tl,md),query(p+p+1,md+1,r,md+1,tr));
	}
}
void modify(int p,int l,int r,int tl,int tr,ll v) {
	//if (p==1) printf("Modify %d %d %lld\n",tl,tr,v);
	if (tl>tr) return;
	if (tl==l&&tr==r) return setf(p,v);
	else {
		push(p);
		int md=(l+r)>>1;
		if (tr<=md) modify(p+p,l,md,tl,tr,v);
		else if (tl>md) modify(p+p+1,md+1,r,tl,tr,v);
		else modify(p+p,l,md,tl,md,v),modify(p+p+1,md+1,r,md+1,tr,v);
		upd(p);
	}
}

void print() {
	ll x=nd[1].dis.fi;
	VI cc;
	//printf("%lld %d\n",nd[1].dis.fi,nd[1].dis.se);
	while (nd[1].dis.fi==x) {
		int u=nd[1].dis.se;
		cc.pb(u);
		modify(1,1,n,l[u],l[u],-(1ll<<62));
	}
	sort(all(cc));
	printf("%d",SZ(cc));
	for (auto x:cc) {
		printf(" %d",x);
		modify(1,1,n,l[x],l[x],(1ll<<62));	
	}
	puts("");
}

const ll inf=1ll<<42;

int main() {
	scanf("%d",&n);
	rep(i,1,n) {
		scanf("%d%d%d",&u,&v,&w);
		e[u].pb({v,w});
		e[v].pb({u,w});
		E[i]={u,v};
	}
	dfs(1,0);
	build(1,1,n);
	//puts("gg");
	rt=1;
	scanf("%d",&q);
	rep(i,0,q) {
		scanf("%d%d",&ty,&x);
		if (ty==1) {
			// move
			if (x==par[rt]) {
				modify(1,1,n,l[rt],r[rt],2*pare[rt]);
			} else {
				modify(1,1,n,l[x],r[x],-2*pare[x]);
			}
			rt=x;
		} else {
			u=E[x].fi, v=E[x].se;
			if (v==par[u]) swap(u,v); // u=par[v]
			if (l[v]<=l[rt]&&r[rt]<=r[v]) {
				modify(1,1,n,l[v],r[v],(ty==2)?inf:-inf);
			} else {
				modify(1,1,n,l[v],r[v],(ty==2)?-inf:inf);
			}
		}
		print();
	}
}


Measured memory_bytes: 49556
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

ll const mod=1e9+7;

int main(void){
	          ll i;

	          ll m,n;
	          cin >> n >> m;

	          ll ans=1;
	          if(n==m){
	        	  for(i=1;i<=n;i++){
	        		  ans=(ans*i)%mod;
	        		  ans=(ans*i)%mod;
	        	  }
	        	  cout << (2*ans)%mod << endl;
	          }

	          else if(n-m==1 || m-n==1){
	        	  if(m>n){
	        		  for(i=1;i<=n;i++){
	        			  ans=(ans*i)%mod;
	        			  ans=(ans*i)%mod;
	        		  }
	        		  cout << (m*ans)%mod << endl;
	        	  }else{
	        		  for(i=1;i<=m;i++){
	        			  ans=(ans*i)%mod;
	        			  ans=(ans*i)%mod;
	        		  }
	        		  cout << (n*ans)%mod << endl;
	        	  }
	          }

	          else{
	        	  cout << 0 << endl;
	          }

	          return 0;
}


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

int main(){
    int N;
    cin>>N;
    vector<int> t(N),x(N),y(N);
    for(int i=0;i<N;i++){
        cin>>t.at(i)>>x.at(i)>>y.at(i);
    }
    bool check=true;
    for(int i=0;i<N;i++){
        if(x.at(i)<0){
            x.at(i)=-x.at(i);
        }
        if(y.at(i)<0){
            y.at(i)=-y.at(i);
        }
        if(t.at(i)%2!=(x.at(i)+y.at(i))%2||t.at(i)<x.at(i)+y.at(i)){
            check=false;
            break;
        }
    }
    if(check){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
  ll a, b, c; cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  else if(b == c) cout << a << endl;
  else cout << b << endl;
  return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LONG_LONG_MAX / 2;
const ll mod = 1000000000 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  } else if (N == 2) {
    cout << 2 << endl;
    return 0;
  }

  ll ans = 1;
  ll a = 1;
  ll b = 1;
  for (int i = 0; i < N; i++) {
    ans *= 10;
    a *= 9;
    b *= 8;
    ans %= mod;
    a %= mod;
    b %= mod;
  }
  ans += b - a * 2;
  while (ans < 0) {
    ans += mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
import sys
s = input()
def bfs(exp,idx):
    if idx == 3:
        ev = eval(exp+s[idx])
        if ev == 7:
            print(exp+s[idx]+"=7")
            sys.exit(0)
        return False
    exp += s[idx]
    for op in ["+", "-"]:
        bfs(exp+op, idx+1)
bfs("",0)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;

vector<int> primeList;

void setPrimeList()
{
	primeList.push_back(2);
	for(int c = 3; c < 10000; c++) {
		bool flag = true;
		for(int j = 2; j * j <= c; j++) { // ??????????????§???????????°?????????<=???=???????????¨??????9??§??°???
			if(!(c % j)) flag = false;
		}
		if(flag){
			primeList.push_back(c);
		}
	}
}


int main()
{
	setPrimeList();
	int n;
	while(true) {
		cin >> n;
		if(n == 0) break;

		int count = 0;
		int sum = 0; // ?????????????¨????????????¨??????????????£?????????????????§???????????????
		// ????????£????????¨???deque?????????????????????????????§???????????????
		int init_index = 0;
		int end_index = -1; //?????????????????????????????????0??\???-1??\??????

		while(true) { // ?°??????????????????????
			if(sum < n) {
				end_index++;
				if(end_index >= primeList.size()) { //?¶????????????????????????????????°?????¶?????????????????????????
					break;
				} else {
					sum += primeList[end_index]; //?°??????????????????????
				}
			} else if(sum == n){
				count++; //???????????£???????????£??????
				sum -= primeList[init_index]; //?????????
				init_index++; //?????????
			} else {
				sum -= primeList[init_index];
				init_index++;
			}
		}

		cout << count << endl;
	}
}

Measured memory_bytes: 3036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int student[][]=new int[n][2];
		int checkp[][]=new int[m][2];
		for(int i=0;i<n;i++) {
			student[i][0]=scan.nextInt();
			student[i][1]=scan.nextInt();
		}
		for(int i=0;i<m;i++) {
			checkp[i][0]=scan.nextInt();
			checkp[i][1]=scan.nextInt();
		}
		scan.close();

		for(int i=0;i<n;i++) {
			int min=Integer.MAX_VALUE;
			int min_num=0;
			for(int j=0;j<m;j++) {
				int distance = Math.abs(student[i][0]-checkp[j][0])+Math.abs(student[i][1]-checkp[j][1]);
				if(distance<min) {
					min=distance;
					min_num=j+1;
				}
			}
			System.out.println(min_num);
		}
	}
}

Measured memory_bytes: 21844
N, K = gets.split(' ').map(&:to_i)
a_list = gets.split(' ').take(N).map(&:to_i)

MAX_DIGIT = 60
dp = Array.new(MAX_DIGIT + 10) { Array.new(2, -1) }
dp[0][0] = 0

(0...MAX_DIGIT).each do |i|
  bit_pos = MAX_DIGIT - i - 1
  kb = K[bit_pos]
  digit_value = 2 ** bit_pos
  one_count = a_list.count { |a| a[bit_pos] == 1 }
  zero_count = N - one_count
  cost0 = one_count * digit_value
  cost1 = zero_count * digit_value

  # lower -> lower
  if dp[i][1] != -1
    dp[i + 1][1] = dp[i][1] + [cost0, cost1].max
  end

  # same -> lower
  if kb == 1
    dp[i + 1][1] =
      [
        dp[i + 1][1],
        dp[i][0] + cost0
      ].max
  end

  # same -> same
  dp[i + 1][0] = dp[i][0] + (kb == 1 ? cost1 : cost0)
end

puts [dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]].max


Measured memory_bytes: 9100
'use strict';

const main = (input) => {
    const K = parseInt(input, 10);
    // K=2..100
    const oddCount = Math.floor(K / 2);
    const evenCount = Math.floor((K + 1) / 2);
    const result = oddCount * evenCount;
    console.log(result);
};

const isTest = false;

if (isTest) {
    main('3');
    main('6');
    main('11');
    main('50');
} else {
    main(require('fs').readFileSync('/dev/stdin', 'utf8'));
}

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

int main(){
    long long n,k;
    cin>>n>>k;
    string s="";
    while(true){
        int tmp=n/k;
        if(tmp==0){
            s+=to_string(n);
            break;
        }
        else{
            s+=to_string(n%2);
            n=tmp;
        }
    }
    
    cout<<s.size()<<endl;

    return 0;
}

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

int main() {
int n,k,count=0;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=0;i<n;i++){
    if(a[i]>=k){
        count++;
    }
}
cout<<count<<endl;
return 0;
}

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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

using namespace std;

int main ()
{   
    int N,b,allsum,res;
    vector<int> a;

    cin >> N;

    allsum = 0;
    REPI(N)
    {
        cin >> b;
        a.push_back(b);
        allsum ^= b;
    }
    
    REPI(N)
    {
        res = allsum ^ a[i];
        cout << res << " ";
    }
    cout << "\n";

    return 0;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int i = 0; i < K; i++)
  {
    vector<int> B(N, 0);
    for (int j = 0; j < N; j++)
    {
      B.at(max(0, j - A.at(j)))++;
      if (j + A.at(j) + 1 <= N - 1)
        B.at(j + A.at(j) + 1)--;
    }
    int cnt = 0;
    for (int j = 1; j < N; j++)
    {
      B.at(j) += B.at(j - 1);
      if (B.at(j) == N)
        cnt++;
    }
    if (B.at(0) == N)
      cnt++;
    A = B;
    if (cnt == N)
      break;
  }
  for (int i = 0; i < N; i++)
  {
    if (i)
      cout << ' ';
    cout << A.at(i);
  }
  cout << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i<n; i++){
    cin >> d.at(i);
  }

  ll all = 0;

  for(int i = 0; i<n-1; i++){
    for(int j = i+1; j<n; j++){
        all += d.at(i) * d.at(j);
    }
  }

  cout << all << endl;
}


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

int main() {
  int n, m = 0;
  cin >> n;
  vector<int>h(n), cnt(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < n - 1; i++) {
    if (h[i] >= h[i + 1]) {
      cnt[i + 1] = cnt[i] + 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (m < cnt[i])m = cnt[i];
  }
  cout << m << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e8;
typedef long long ll;
ll mod = 998244353;
long long fast_exp(long long a, long long b)
{
    if(b == 0)
	   return 1;
    else
    {
	   long long res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res)%mod;
	   if(b%2 == 1)
		  res = (res*a)%mod;
	   return res;
 
    }
}
const ll N = 1e6;




int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int x,a;
	cin>>x>>a;
	if(x<a)
		cout<<0<<endl;
	else
		cout<<10<<endl;
	return 0;
	
}


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

int ans[365],c[26],s[365][26],last[26],csum,nowscore,newscore;
const int INF=1e9,d=365,starttemp=4000,endtemp=100;
double temperature,prob;

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

void FIN(bool a){
  if(a){
    ofstream fout("output.txt");
    REP(i,d)fout<<ans[i]+1<<"\n";
    fout.close();
    return;
  }
  REP(i,d)cout<<ans[i]+1<<"\n";
  return;
}
/*
int score(){
  int res=0;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    last[ans[day]]=day;
    REP(i,26)res-=c[i]*(day-last[i]);
  }
  return res;
}
*/
int score(){//上のがO(26*365)、こっちがO(365)のスコア計算
  int res=0,minus=csum;
  memset(last,-1,sizeof(last));
  REP(day,d){
    res+=s[day][ans[day]];
    minus-=c[ans[day]]*(day-last[ans[day]]);
    last[ans[day]]=day;
    res-=minus;
    minus+=csum;
  }
  return res;
}
void swap(){
  int RAND=rand();
  int day=RAND%(d-1);
  RAND^=newscore;
  int diff=RAND%min(d-day,16)+1;
  swap(ans[day],ans[day+diff]);
  newscore=score();
  prob=exp((newscore-nowscore)/temperature);
  if(prob>(rand()%INF)/(double)INF)nowscore=newscore;
  else swap(ans[day],ans[day+diff]);
}
void onechange(){
  int day=rand()%365;
  REP(i,26){
    int tmp=ans[day];
    ans[day]=i;
    newscore=score();
    prob=exp((newscore-nowscore)/temperature);
    if(prob>(rand()%INF)/(double)INF)nowscore=newscore;
    else ans[day]=tmp;
  }
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  clock_t start=clock();
  memset(last,-1,sizeof(last));
  cin>>c[0];
  REP(i,26){cin>>c[i];csum+=c[i];}
  REP(i,d)REP(j,26)cin>>s[i][j];
  REP(day,d){
    int idx,mx=-INF;
    REP(i,26){
      int A=c[i]*(day-last[i])+s[day][i];
      if(mx<A)mx=A,idx=i;
    }
    ans[day]=idx,last[idx]=day;
  }
  nowscore=score();
  while(true){
    clock_t nowt=clock();
    const double Time=static_cast<double>(nowt-start)/CLOCKS_PER_SEC;
    if(Time>1.97)break;
    temperature=starttemp+(double)(endtemp-starttemp)*(nowt-start)/(CLOCKS_PER_SEC*1.97);
    REP(_,50)
      if((_^newscore)&1)swap();
      else onechange();
  }
  FIN(0);
}


Measured memory_bytes: 4284
#include "bits/stdc++.h"
using namespace std;

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

	int num, m=0, count, ans;
	for(int i=1;i<=n;i++) {
		count = 0;
		num = i;
		for(int j=i;j%2 == 0;j /= 2) count++;
		m = max(m, count);
		if(m == count) ans = i;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

struct mypair{
    LL x;
    bool y;

    mypair(){}
    
    mypair(LL a,bool b):x(a),y(b){

    }

    bool operator <(const mypair & right)const{
        return x < right.x;
    }

};

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

    LL n;
    cin >> n;
    vector<mypair> a(2*n);

    for(int i = 0; i < n; i++){
        LL tmp;
        cin >> tmp;
        a[i] = mypair(tmp,true);
    }

    for(int i = n; i < 2*n; i++){
        LL tmp;
        cin >> tmp;
        a[i] = mypair(tmp,false);
    }

    sort(a.begin(),a.end());

    LL count = 1;
    bool frag = a[0].y;

    LL ans = 1;

    for(int i = 1; i < 2*n; i++){
        if(count == 0){
            count++;
            frag = a[i].y;
        }else{
            if(frag^a[i].y){
                ans = (ans*count)%MOD;
                count--;
            }else{
                count++;
            }
        }
    }

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

Measured memory_bytes: 3456
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N = I()
S = input()

blacks = S.count('#')
if blacks == 0:
    print(0)
    exit(0)

ans = blacks

# w[i] := i番目以降にいくつの白があるか
# b[i] := i番目より前にいくつの黒があるか
w = [0] * N
b = [0] * N
for i, c in enumerate(S):
    if i == 0:
        continue
    if S[i - 1] == '#':
        b[i] += 1
    if i < N - 1:
        b[i + 1] = b[i]
for i, c in enumerate(reversed(S)):
    i = N - i - 1
    if i == N - 1:
        if c == '.':
            w[i] = 1
        continue
    w[i] = w[i + 1]
    if c == '.':
        w[i] += 1


for i, c in enumerate(S):
    if c == '#':
        ans = min(ans, w[i] + b[i])

print(ans)


Measured memory_bytes: 46540
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

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

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
	ll a,b;
	cin>>a>>b;
	if(abs(a-b)<=1)
		cout<<a+b<<endl;
	else if(a>b)
		cout<<2*a-1<<endl;
	else
		cout<<2*b-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define ALL(a) (a).begin(),(a).end()
#define Inf 1e9
#define Mod 1000000007
#define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
using namespace std;
using namespace __gnu_cxx;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int Uint;
typedef long long INT;
typedef pair<INT,INT> PII;

string st;

int main()
{
	cin>>st;
	int n=SZ(st);
	for(int i=n-1;i>=0;i--)
	{
		if(st.substr(0,i/2)==st.substr(i/2,i/2)&&i%2==0)
		{
			cout<<i<<endl;
			return 0;
		}
	}
}


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

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    VI vi = VI(999,0);
    vi[0] = 1;
    for (int i = 1; i < 999; ++i) vi[i] = vi[i-1] + i + 1;
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = 0; i < 998; ++i)
    {
        if (vi[i] <= a) continue;
        else 
        {
            ans = vi[i] - a;
            if (b == (vi[i+1] - ans)) break;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pll = pair<ll, ll>;

#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair


template <typename T>
using vv = vector<vector<T>>;

void solve() {
    int n; cin >> n;
    string s; cin >> s;
    int l = 0, r = n - 1;
    ll res = 0;
    while (1) {
        while (l < r) {
            if (s[l] == 'W') break;
            l++;
        }
        while (l < r) {
            if (s[r] == 'R') break;
            r--;
        }
        if (l >= r) break;
        res++;
        l++, r--;
    }
    cout << res;
}



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


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    map<ll, ll> mp;
    ll cnt = 0;

    rep(i, n){
        ll a; cin >> a;
        mp[a]++;
    }

    for(auto p: mp){
        if(p.first > p.second){
            // 回数が足りない場合
            cnt += p.second;
        }
        else if(p.first < p.second){
            // 回数が多い場合
            cnt += p.second - p.first;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 6272
#include <stdio.h>

int main(void) {
	int i,sum;
	char num[1000];
	while (1){
		scanf("%s",num);
		sum=0;
		i=0;
		while(num[i]!= '\0'){
			sum+=num[i]-'0';
			i++;
		}
		if(sum==0) break;
		printf("%d\n",sum);
	}
	return 0;
}

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

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

    long long a, sumA = 0, sumB = 0, mA = 0, mB = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        sumA += a;
        sumB += a;

        if(i % 2){
            if(sumA <= 0){
                mA += 1 - sumA; // required manipulation
                sumA = 1;       // - -> +
            }
            if(sumB >= 0){
                mB += 1 + sumB;
                sumB = -1;
            }
        }else{
            if(sumA >= 0){
                mA += 1 + sumA;
                sumA = -1;
            }
            if(sumB <= 0){
                mB += 1 - sumB;
                sumB = 1;
            }
        }
    }
    cout << min(mA, mB) << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << ' ' << y << ' ' << z << endl;
    
    
    return 0;

}


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 200005, M = 1000005;

int n;
char a[M];
int id[N];

int rt, cnt;
int ex[M], fa[M], fw[M], go[M][26];

void init() {
	cnt = rt = 1;
	ex[rt] = 0, fa[rt] = 0;
}

int insert(char *a, int len) {
	int u = rt;
	for (int i = 1; i <= len; ++i) {
		if (!go[u][a[i] - 'a']) {
			go[u][a[i] - 'a'] = ++cnt;
			fa[cnt] = u, fw[cnt] = a[i] - 'a';
		}
		u = go[u][a[i] - 'a'];
	}
	ex[u] = 1;
	return u;
}

int main() {
	read(n);
	init();
	for (int i = 1; i <= n; ++i) {
		int len = readStr(a + 1);
		std::reverse(a + 1, a + len + 1);
		id[i] = insert(a, len);
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		static int ch[26];
		memset(ch, 0, sizeof ch);
		for (int u = id[i]; u; u = fa[u]) {
			for (int k = 0; k < 26; ++k) {
				if (ch[k] && go[u][k] && ex[go[u][k]]) {
					++ans;
				}
			}
			++ch[fw[u]];
		}
	}
	print(ans - n);
}

Measured memory_bytes: 116764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define endl "\n"
using Edge = pair<int,ll>;
using Graph = vector<vector<Edge>>;
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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int V,E;
Graph Gy;
Graph Gs;
ll dy[100050]; //MAX_V
ll ds[100050]; //MAX_V
const ll INF = 1001001001001000;

void dijkstra(int s, ll d[], Graph G){
  priority_queue<Edge, vector<Edge>, greater<Edge>> que;
  fill(d, d+V, INF);
  d[s] = 0;
  que.push(Edge(0,s));

  while(!que.empty()){
    Edge p = que.top(); que.pop();
    int v = p.second;
    if(d[v]<p.first) continue;
    for(auto x: G[v]){
      if(d[x.first]>d[v]+x.second){
        d[x.first] = d[v]+x.second;
        que.push(Edge(d[x.first],x.first));
      }
    }
  }
}

int main(void){
  std::cout<<std::fixed<<std::setprecision(10);
  int s,t;
  cin >> V >> E >> s >> t;
  --s; --t;
  Gy.assign(V,vector<Edge>());
  Gs.assign(V,vector<Edge>());
  FOR(i,0,E-1){
    int u,v; ll a,b; cin >> u >> v >> a >> b;
    --u; --v;
    Gy[u].PB(MP(v,a));
    Gy[v].PB(MP(u,a));
    Gs[u].PB(MP(v,b));
    Gs[v].PB(MP(u,b));
  }
  dijkstra(s,dy,Gy);
  dijkstra(t,ds,Gs);

  ll dist[100010];
  FOR(i,0,V-1) dist[i] = dy[i] + ds[i];
  FORD(i,V-2,0) chmin(dist[i],dist[i+1]);

  FOR(i,0,V-1) cout << 1000000000000000LL - dist[i] << endl;
}




Measured memory_bytes: 25964
/*
[abc142] C - Go to School
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;

int N;
int A[MAX_N];

void solve() {
    vector<pii> ais;
    for (int i = 0; i < N; i++) {
        ais.push_back({A[i], i});
    }
    sort(ALL(ais));

    for (auto& ai : ais) {
        cout << ai.second + 1 << " ";
    }
    cout << endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 2164