akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <cstdio>
using namespace std;
 
const int INF = 0x3f3f3f3f;
const int MAXN = 5e5 + 5;
 
template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}
 
template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}
 
template<typename _T>
_T MIN( const _T a, const _T b )
{
	return a < b ? a : b;
}
 
template<typename _T>
_T MAX( const _T a, const _T b )
{
	return a > b ? a : b;
}
 
struct edge
{
	int to, nxt;
}Graph[MAXN << 1];
 
priority_queue<int, vector<int>, greater<int> > q;
 
int mn[MAXN << 2];
 
int seq[MAXN], ans[MAXN];
int A[MAXN], P[MAXN], head[MAXN], deg[MAXN];
int N, K, cnt;
 
void addEdge( const int from, const int to )
{
	Graph[++ cnt].to = to, Graph[cnt].nxt = head[from];
	head[from] = cnt, deg[to] ++;
}
 
void upt( const int x ) { mn[x] = MIN( mn[x << 1], mn[x << 1 | 1] ); }
 
void build( const int x, const int l, const int r )
{
	if( l > r ) return ; mn[x] = INF;
	if( l == r ) return ;
	int mid = l + r >> 1;
	build( x << 1, l, mid );
	build( x << 1 | 1, mid + 1, r );
}
 
void update( const int x, const int l, const int r, const int p, const int v )
{
	if( l == r ) { mn[x] = v; return ; }
	int mid = l + r >> 1;
	if( p <= mid ) update( x << 1, l, mid, p, v );
	else update( x << 1 | 1, mid + 1, r, p, v );
	upt( x );
}
 
int query( const int x, const int l, const int r, const int segL, const int segR )
{
	if( segL <= l && r <= segR ) return mn[x];
	int mid = l + r >> 1, ret = INF;
	if( segL <= mid ) ret = MIN( ret, query( x << 1, l, mid, segL, segR ) );
	if( mid < segR ) ret = MIN( ret, query( x << 1 | 1, mid + 1, r, segL, segR ) );
	return ret;
}
 
int query( const int l, const int r ) { return query( 1, 1, N, MAX( 1, l ), MIN( N, r ) ); }
 
int main()
{
	read( N ), read( K );
	for( int i = 1 ; i <= N ; i ++ ) read( P[i] ), A[P[i]] = i;
	build( 1, 1, N );
	for( int i = N ; i ; i -- )
	{
		int pre = query( A[i] - K + 1, A[i] ),
			nxt = query( A[i], A[i] + K - 1 );
		if( pre < INF ) addEdge( A[i], A[pre] );
		if( nxt < INF ) addEdge( A[i], A[nxt] );  
		update( 1, 1, N, A[i], i );
	}
	for( int i = 1 ; i <= N ; i ++ )
		if( ! deg[i] ) q.push( i );
	int u, v, tot = 0;
	while( ! q.empty() )
	{
		u = seq[++ tot] = q.top(), q.pop();
		for( int i = head[u] ; i ; i = Graph[i].nxt )
			if( ! ( -- deg[v = Graph[i].to] ) )
				q.push( v );
	}
	for( int i = 1 ; i <= N ; i ++ ) ans[seq[i]] = i;
	for( int i = 1 ; i <= N ; i ++ ) write( ans[i] ), putchar( '\n' );
	return 0;
}

Measured memory_bytes: 27540
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>

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

using namespace std;
typedef long long ll;

ll c[10005];

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

	vector<pair<pair<int,int>,int> > a;
	while(true)
	{
		int s,t,e;
		cin >> s >> t >> e;

		if(s == 0 && t == 0 && e == 0) break;

		s--;
		t--;

		a.push_back(make_pair(make_pair(s,t),e));
	}

	int l;
	cin >> l;
	rep(q,l)
	{
		memset(c,0,sizeof(c));
		vector<int> b(m);
		rep(i,m) cin >> b[i];
			
		rep(i,a.size())
		{
			int s = a[i].first.first;
			int t = a[i].first.second;
			int e = a[i].second;

			c[s] += b[t] * e;
		}

		rep(i,n)
		{
			cout << c[i];
			if(i == n-1) cout << endl;
			else cout << " ";
		}
	}	

	return 0;
}

Measured memory_bytes: 1988
N = int(input())

len = 1
cnt = 0
while cnt + pow(26, len) < N:
    cnt += pow(26, len)
    len += 1

for i in range(len):
    N -= pow(26, i)

ans = ""
for i in range(len-1, -1, -1):
    ans += chr(N//pow(26, i)+97)
    N %= pow(26, i)
print(ans)

Measured memory_bytes: 9196
n,t = map(int,input().split())
tlist = list(map(int,input().split()))
time = t
for i in range(0,n-1):
    if tlist[i+1]- tlist[i] <= t :
        time += tlist[i+1]- tlist[i]
    else:
        time += t
print(time)

Measured memory_bytes: 30640
let [|N; P|] = stdin.ReadLine().Split() |> Array.map int

let A = stdin.ReadLine().Split() |> Array.map int
let odd = A |> Array.filter (fun x -> x % 2 = 1) |> Array.length

if odd = 0
then if P = 0 then (int64 1) <<< N else (int64 0)
else (int64 1) <<< (N-1)
|> stdout.WriteLine

Measured memory_bytes: 11220
#include <cstdio>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

const int MAX = (1 << 20);

int n, e, t;
int w[300];
int g[1000];
int c[1000];
int s[1000][300];
int memo[300];

int buff[300];

int main(){
  scanf("%d%d%d", &n, &e, &t);
  REP(i,n) scanf("%d", w+i);
  REP(i,e){
    scanf("%d%d", g+i, c+i); g[i]--;    
    REP(j,c[i]){scanf("%d", &s[i][j]); s[i][j]--;}
  }

  REP(i,n) memo[i] = w[i] == 1 ? 1 : MAX;
  
  while(true){
    bool ok = true;

    REP(i,e){
      int next = 0;
      REP(j,c[i]){
	buff[j] = - memo[s[i][j]];
      }
      sort(buff, buff + c[i]);

      REP(j,c[i])
	next = max(next, j - buff[j]);

      if(next < memo[g[i]]){
	memo[g[i]] = next;
	ok = false;
      }
    }

    if(ok) break;
  }

  // REP(i,n) printf("%d ", memo[i]); puts("");
  printf("%d\n", memo[t-1] == MAX ? -1 : memo[t-1]);

  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
using namespace std;
long long n;
long long a[200020],ans;
int main()
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			{
				cin>>a[i];
			}
		if(a[1]!=0) 
			{
				cout<<"-1"<<endl;
				return 0;
			}
		for(int i=1;i<=n;i++)
			{
			if(a[i+1]-a[i]>1) 
				{
				cout<<"-1"<<endl;
				return 0;	
				}
				
			}			
			for(int i=1;i<=n;i++)
			{
				if(a[i]==1&&a[i+1]<=1) ans++;
				if(a[i]>1&&a[i+1]<=a[i]) ans+=a[i];
			}
		cout<<ans<<endl;
		}


Measured memory_bytes: 1792
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;

void solve(long long N, std::vector<std::string> s, std::vector<long long> t,
           std::string X) {
  lli cur = 0;
  rep(i, N) {
    cur += t[i];
    if (s[i] == X) {
      break;
    }
  }
  cout << accumulate(t.begin(), t.end(), 0) - cur << endl;
}

int main() {
  int a;
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> s(N);
  std::vector<long long> t(N);
  for (int i = 0; i < N; i++) {
    std::cin >> s[i];
    scanf("%lld", &t[i]);
  }
  std::string X;
  std::cin >> X;
  solve(N, std::move(s), std::move(t), X);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int k (int n) {
    int ok = 0, ng = n + 2;
    while (ng - ok > 1) {
        ll med = (ng + ok) / 2;
        if (med * (med + 1) <= 2 * n) ok = med;
        else ng = med;
    }
    return ok;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    int ans = 0;
    for (auto p : prime_factor(n)) {
        eprintf("%lld %d %d\n", p.first, p.second, k(p.second));
        ans += k(p.second);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include "iostream"
using namespace std;
#define ll long long int
int main()
{
    
    ll n=100;
    ll count=0;
    ll final;
    cin>>final;
    
    while(n<final)
    {
        n=n+ (n/100);
        count++;
        
    }
    
    cout<<count<<endl;
}


Measured memory_bytes: 3628
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int r, g, b;
    cin >> r >> g >> b;
    YESNO((10 * g + b) % 4 == 0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define mc map<char,ll>
#define f(i,a,b) for(int i=a;i<b;i++)
#define fe(i,a,b) for(int i=a;i<=b;i++)
#define fn(i,a,b) for(ll i=a;i>b;i--)
#define fm(it,m) for(it = m.begin();it != m.end();++it)
#define M 1000000007


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

ll prime(ll x)
{ fe(i,2,sqrt(x))
   {if(x%i==0)
    return 0;
   }
return 1;
}


int main()
{ ll t=1;
  //cin>>t;
  while(t--)
  { ll n=0,i=0,j=0,k=0,flag=0;
    cin>>n;
    cout<<n/500*1000 +((n%500)/5)*5<<endl;
  }
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
 
using namespace std;
 
double i_1;
 
double s_n;
 
double fib(int i){
 
  if(i == 0 )
  {
    return i_1;
  }
 
  //偶数番目
  if((i + 1) % 2 == 0){
    return fib(i-1)*2.0;
  }else{
    return fib(i-1)/3.0;
  }
}
 
int main(void){
 
     
  while(scanf("%lf", &i_1) != EOF)
  {
 
      for(int i = 0; i < 10; i++)
      {
        s_n += fib(i);
        if(i == 9)
        {
          printf("%lf\n", s_n);
        }
      }
      s_n = 0;
  }
 
  return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long long> A){
    vector<pair<LL, int>> tmp;
    REP(i, N) tmp.PB(MP(A[i], i));

    sort(ALL(tmp));

    int ans = 0;
    REP(i, N) {
        if(tmp[i].second % 2 != i % 2) ans++;
    }

    cout << (ans/2) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 1;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};


int mp[111][111];
int redev[111];
int sum[111];
set<pair<int,int>> ans;

pair<int,int> add_ans(int a, int b){
	return MP(min(a,b), max(a,b));
}

int main(){

	int n,m;cin >> n >> m;
	REP(i,m){
		int a,b;cin >> a >> b;
		a--;b--;
		mp[a][b] = 1;
		mp[b][a] = 1;
	}
	REP(i,n)mp[i][i] = 2;

	while(1){
		vector<pair<int,pair<int,int>>> v;
		REP(i,n){
			int tmp = 0;
			int su = 0;
			REP(j,n){
				if(mp[i][j] == 0)tmp++;
				if(mp[i][j] != 2)su++;
			}
			redev[i] = tmp;
			sum[i] = su;
			v.PB(MP(tmp,MP(i,su)));;
		}

		sort(ALL(v));

		int now = -1;
		REP(i,n){
			if(v[i].SE.SE % 2){
				now = v[i].SE.FI;
				break;
			}
		}
		if(now == -1)break;
		bool flag = false;

		REP(i,n){
			if(mp[now][v[i].SE.FI] == 0 && (v[i].SE.SE % 2 == 1)){
				mp[now][v[i].SE.FI] = 2;
				mp[v[i].SE.FI][now] = 2;
				flag = true;
				break;
			}
		}
		if(flag)continue;

		REV(i,n){
			if(mp[now][v[i].SE.FI] == 0){
				mp[now][v[i].SE.FI] = 2;
				mp[v[i].SE.FI][now] = 2;
				flag = true;
				break;
			}
		}

		if(!flag){
			cout << -1 << endl;
			return 0;
		}
	}

	UF uf(n);
	REP(i,n){
		REP(j,n){
			if(mp[i][j] != 2)uf.unite(i,j);
		}
	}
	set<int> s;
	REP(i,n)s.insert(uf.find(i));
	if(s.size() > 1){
		cout << -1 << endl;
		return 0;
	}

	REP(i,n){
		REP(j,n){
			if(mp[i][j] == 0)ans.insert(add_ans(i,j));
		}
	}

	cout << ans.size() << endl;
	for(auto it = ans.begin();it != ans.end();it++){
		cout << it->FI + 1 << " " << it->SE + 1 << endl;
	}

	return 0;
}



Measured memory_bytes: 3356
H,W,A,B=map(int,input().split())

s=[[0 for _ in range(W)]for i in range(H)]

for i in range(H):
    for j in range(W):
        if j<A and i<B:
            s[i][j]=0
        elif j<A:
            s[i][j]=1
        elif i<B:
            s[i][j]=1
        else:
            s[i][j]=0
ans=[]
for i in range(H):
    tmp=""
    for j in range(W):
        tmp=tmp+str(s[i][j])
    ans.append(tmp)
for i in range(H):
    print(ans[i])

Measured memory_bytes: 56796
N, M = map(int, input().split())
A = list(map(int, input().split()))
B =[0]
for i in range(N):
    B.append(B[i] + A[i])

dic = dict()
for i in B:
    i = i % M
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

def count(n): #nC2を返す
    return (n * (n - 1))//2

ans = 0
for i in dic:
    ans += count(dic[i])

# print (dic)
print (ans)

Measured memory_bytes: 16552
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
from fractions import gcd
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;pro = 1

a,b=map(int,input().split())
g=gcd(a,b)
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        count=0
        while n % i==0:
            count+=1
            n = n//i
        if count!=0:
            ass.append((i,count))
    if n != 1:
        ass.append((n,1))
    return ass

pr = prime_factor(g)
print(len(pr)+1)
# print(pr)

Measured memory_bytes: 64620
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]

for q in range(Q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = INF
  for S in [s[b - 1], s[b]]:
    for T in [t[d - 1], t[d]]:
      d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
      res = min(res, d1, d2)
  print(res)


Measured memory_bytes: 12812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }

int main() {
  char b;
  cin >> b;

  if (b == 'A') {
    cout << "T" << endl;
  } else if (b == 'T') {
    cout << "A" << endl;
  } else if (b == 'G') {
    cout << "C" << endl;
  } else if (b == 'C') {
    cout << "G" << endl;
  }

  return 0;
}


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

int main(){
    int N,T;
    cin >> N >> T;
    int c[1001];
    int t[1001];
    int a[1001];
    for(int i = 0; i < N;++i){
        cin >> c[i] >> t[i];
        if( T >= t[i]){
            a[i] = c[i];
        }
        else{
            a[i] = 1001;
        }
    }
    sort(a ,a + N);
    if(a[0] == 1001) cout << "TLE" << endl;
    else cout << a[0] << endl;
}


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

int main(){
    string s;   cin >> s;
    if(s[1] == 'B'){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}


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

using namespace std;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

struct BIT {
private:
	int n;
	vector< long long >bit;
public:
	BIT(int sz) {
		n = sz;
		bit.resize(sz);
	}
	void add(int a, long long val) {
		for (int x = a;x < n;x += x & -x)bit[x] += val;
	}
	long long sum(int a) {
		long long ret = 0;
		for (int x = a; x > 0; x -= x & -x) ret += bit[x];
		return ret;
	}
};

int k, n;
string s;
set< int >se[26];

int main() {
	cin >> s >> k;
	n = s.size();
	BIT bit(200010);
	for (int i = 0;i < n;i++) {
		se[s[i] - 'a'].insert(i + 1);
	}
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < 26;j++) {
			if (se[j].empty())continue;
			int near = *se[j].begin();
			int cnt = near - bit.sum(near) - 1;
			if (cnt > k)continue;
			k -= cnt;
			cout << (char)('a' + j);
			bit.add(near, 1);
			se[j].erase(near);
			break;
		}
	}
	cout << endl;
	return 0;
}




Measured memory_bytes: 14100
#include<stdio.h>

int main(){
    int n, m, i, j, k;
    scanf("%d %d", &n, &m);
    int b[m], a[n][m], c[n];
    for(i=0 ;i<n ; i++){
        for(j=0 ;j<m ;j++){
            scanf("%d ", &a[i][j]);
        }
    }
    for(k=0 ; k<m ;k++){
        scanf("%d", &b[k]);
    }
    
    for(i=0 ;i<n ;i++){
        c[i] = 0;
        for(k=0 ;k<m ;k++){
            c[i] += a[i][k] * b[k];
        }
         printf("%d\n", c[i]);
    }
    return 0;
}

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


int main(){
while(1){
int H,W;
cin>>H>>W;
if(H == 0 && W == 0) break;


for(int i=0;i<H;i++){
 for(int j=0;j<W;j++){
  if(i == 0 | i == H-1 | j == 0 | j == W-1) cout<<"#";
   else cout<<".";
   }
  cout<<endl;
  }
 cout<<endl;
 }
  
 return 0;
}


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


#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(arr) arr.begin(),arr.end()
#define INF 2000000000
#define MOD 1000000007
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define um unordered_map
#define us unordered_set
#define ff first
#define ss second
#define FOR(i,n,m) for(int i = (n); i < (m); i++)
#define REP(i,n) FOR(i,0,n)



using namespace std; 
void solve(); 
int main() 
{ 
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 

/*
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin); 
	freopen("error.txt", "w", stderr); 
	freopen("output.txt", "w", stdout); 
#endif 
*/
	ll n,k;
	cin>>n>>k;
	ll x = n%k;
	cout<<min(x,k-x)	;
	//cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0; 
} 
void solve() 
{ 
} 


Measured memory_bytes: 3616
n ,T = map(int, input().split())
tgt = []
for _ in range(n):
    c,t = map(int, input().split())
    if t <= T:
        tgt.append([c,t])
ans = sorted(tgt)
if len(ans)>0:
    print(ans[0][0])
else:
    print("TLE")

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline

def main():
    N = int(input())
    S = input().strip()
    
    E = [0]*N
    W = [0]*N
    for i in range(1,N):
        E[i] = E[i-1]
        if S[i-1] == "W":
            E[i] += 1
    for i in range(N-2,-1,-1):
        W[i] = W[i+1]
        if S[i+1] == "E":
            W[i] += 1

    X = [0]*N
    for i in range(N):
        X[i] = W[i] + E[i]
    print(min(X))
if __name__ == '__main__':
    main()


Measured memory_bytes: 29472
#include <iostream>
#include <queue>
#include <utility>

using namespace std;
using Point = pair<int,int>;

int map[52][52];

void BFS(const Point &p0){
  queue<Point> q;
  q.push(p0);
  map[p0.first][p0.second] = 0;
  while(!q.empty()){
    auto p = q.front();q.pop();
    int y = p.first , x = p.second;

    for(int i=-1;i<=1;++i){
      for(int j=-1;j<=1;++j){
        if(i==0&&j==0)continue;
        if(map[i+y][j+x]){
          q.push(Point(i+y,j+x));
          map[i+y][j+x] = 0;
        }
      }
    }

  }

}

int main(){
  int w,h;
  while(cin>>w>>h&&w>0&&h>0){

    for(int i=1;i<h+1;++i){
      for(int j=1;j<w+1;++j){
        cin >> map[i][j];
      }
    }


    int num = 0;
    for(int i=1;i<h+1;++i){
      for(int j=1;j<w+1;++j){
        if(map[i][j]){
          BFS(Point(i,j));
          num++;
        }
      }
    }
    cout << num << endl;
  }

  return 0;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define For(i, a, b) for (int i = a; i <= b; i++)
#define DFor(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &x)
{
    int f = 1; x = 0; char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
    x *= f;
}

const int N = 1e5 + 5;
const int M = 16;
int n, w[N];

int cnt[M], ans, F[1 << M], sxor[1 << M];
int num[M], tot;
int main()
{
    read(n);
    For (i, 1, n - 1)
    {
        int x, y, z;
        read(x); read(y); read(z);
        x++; y++;
        w[x] ^= z; w[y] ^= z;
    }
    For (i, 1, n) cnt[w[i]]++;
    
    For (i, 1, M - 1)
    {
        ans += cnt[i] / 2;
        if (cnt[i] & 1) num[++tot] = i;
    }
   
    For (i, 1, (1 << tot) - 1)
    {
        int cnt = 0;
        For (j, 0, tot - 1) if (i >> j & 1) { sxor[i] ^= num[j + 1]; cnt++; }
        if (!sxor[i]) F[i] = cnt - 1;
        else F[i] = 0x3f3f3f3f;
    }
    
    For (i, 1, (1 << tot) - 1)
    {
        if (sxor[i]) continue;
        for (int j = i; j; j = (j - 1) & i) 
        if (!sxor[j]) F[i] = min(F[i], F[j] + F[i ^ j]);
    }
    
    printf ("%d\n", ans + F[(1 << tot) - 1]);
    return 0;
}

Measured memory_bytes: 4264
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include <iomanip>

#define rep0(i,N) for(int i=0;i<N;i++)
#define rep1(i,a,N) for(int i=0+a;i<N;i++)
#define lint long long int
#define SIZE 100005

using namespace std;

int main(){
	
	static lint a,b;
	cin>>a>>b;

	if(a==1||a==2){
		cout<<0;
		return 0;
	}
	a=a-2;
	lint num[14][8];
	rep1(i,1,14){
		rep1(j,1,8){
			num[i][j]=i*7+j-7;
		}
	}
	lint cal[12]={};
	lint sum=0,all=0;
	rep1(i,1,12){
		rep1(j,1,6){
			sum=(num[i][j]+8)*9;
			if(sum%11==b){
			cal[i]++;
			}
		}
		all+=cal[i];
	}
	lint c=0,cc;
	cc=a%11;
	c=(a-cc)/11;
	lint d=0;
	rep1(i,1,cc+1){
		d+=cal[i];
	}
	cout<<all*c+d<<endl;
return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define SQR(X) ((X)*(X))


int test = 0;
/* ここからが本編 */
int main(void)
{
  int i,j,k,l;
  int n;
  int w;
  int e[50];
  cin >> w;
  cin >> n;
  rep(i,w+1) {
    e[i] = i;
  }
  rep(i,n) {
    int a,b;
    char c;
    cin >> a >> c >> b;
    swap(e[a],e[b]);
  }
  REP(i,1,w+1) {
    cout << e[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
  int katanaNum;
  int enemyHP;

  cin >> katanaNum >> enemyHP;
  int a[1000000];
  vector<int> d(katanaNum);
  int maxA = 0;

  for(int i=0; i<katanaNum; i++) cin >> a[i] >> d[i];

  maxA = 0;
  for (int i = 0; i<katanaNum; i++) {
  	maxA = (maxA < a[i])? a[i] : maxA;
  }

  sort(d.begin(), d.end(), greater<int>());

  int ans = enemyHP;
  for (int katanaIdx = 0; katanaIdx <= katanaNum; katanaIdx++) {
    if (enemyHP < 0) break;
    enemyHP -= d[katanaIdx];
    int count = 0;
    if(enemyHP > 0) {
    	count = (enemyHP + maxA -1) / maxA;
    }
    ans = min(ans, count + katanaIdx + 1);
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
using i64 = unsigned long long;
using namespace std;

const int maxn = 2e3;
int x, y, mx[3], val;
int sup[3];
vector< array<int, 3> > apple;

int main() {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + (m * (m - 1)) / 2 << endl;
}

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

int main() {
    ll a,b,c,k; cin >> a >> b >> c >> k;

  	ll ans = a - b;
  	if(k % 2 == 1) {
      ans *= -1; 
    }
  	
  	if(abs(ans) > 1000000000000000000) {
      cout << "Unfair" << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3580
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	int curr = 1;
	rep(i,n) {
		if(a[i]==curr) curr++;
	}
	if(curr==1) {
		print(-1);
	} else {
		print(n-curr+1);
	}
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll N;
    cin>>N;
    auto pf=prime_factorize(N);
    ll ans=0;
    for(auto p : pf){
        int c=1;
        int x=p.second;
        while(1){
            if(x>c){
                ans++;
                x-=c;
                c++;
            }
            else if(x==c){
                ans++;
                break;
            }
            else{
                break;
            }
        }
    }

    cout<<ans<<endl;
}

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

int main(){
  cout << fixed << setprecision(12);
  
  double r; //rは実数
  cin>>r;
  
  double area = r * r * M_PI;
  double cir = (r + r) * M_PI;
  cout<<area<<" "<<cir<<endl;
  
  return 0;
}



Measured memory_bytes: 3208
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    int ans = 700;
    if(s[0] == 'o')ans+=100;
    if(s[1] == 'o')ans+=100;
    if(s[2] == 'o')ans+=100;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back;
const int N = 1e5 + 5;
ll dp[5][N];
ll a[5][N];
ll n;
ll res(ll i, ll prev){
    if(i == n+1)return 0;
    if(dp[prev][i] != -1)return dp[prev][i];
    dp[prev][i] = 0;
    for(int j = 1;j <= 3; j++){
        if(j == prev)continue;
        dp[prev][i] = max(dp[prev][i], a[j][i] + res(i + 1, j));
    }
    return dp[prev][i];
}
int main(){
        
    cin >> n ;
    //memset(dp,-1, sizeof(dp)/sizeof(dp[0]));
   memset(dp , -1, sizeof(dp));
   for(int i = 1; i <= n; i++){
        for(int j = 1; j <= 3; j++){
            cin >> a[j][i];
        }
   }
    cout<<res(1, 0);
}

Measured memory_bytes: 15104
import math
H,W=list(map(int,input().split()))
grid=[]
for i in range(H):
    grid.append(input())
after=[]
for i in range(H):
    if grid[i] != '.'*W:
        after.append(grid[i])

H = len(after)
W = len(after[0])

flag = []
for i in range(H):
    r = []
    for j in range(W):
        r.append(1)
    flag.append(r)

for j in range(W):
    c = ''
    for i in range(H):
        c = c+after[i][j]
    if c == '.'*H:
        for k in range(H):
            flag[k][j] = 0
            W -= 1
    else:
        pass
out=[]
for i in range(H):
    out.append([])

for i in range(H):
    for j in range(len(after[0])):
        if flag[i][j] == 1:
            out[i].append(after[i][j])
        else:
            pass

for i in range(H):
    print(''.join(out[i]))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int K, X;
  cin >> K >> X;

  if(500*K >= X) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine().trim();
		if (S.contains("a") && S.contains("b") && S.contains("c")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23764
//
// Created by 中野誠大 on 2019-02-10.
//

#include<iostream>

#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;


int main() {
    long long K;
    cin >> K;
    long long N=50;
    long long N_ind = K/N;
    long long num = K%N;

    vector<long long> base;

    for (int i=0;i<num;i++){
        base.push_back(2*N + N_ind -num);
    }
    for (int i=0;i<N-num;i++){
        base.push_back(N-1+N_ind-num);
    }


    cout << 50 <<endl;
    for (int i=0;i<50;i++){
        cout << base.at(i) << " ";
    }

    return 0;



}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <utility>
#include <string>
#include <cmath>

#define INF 999999999;

using namespace std;

int main() {
  int n;
  string alphabet = "abcdefghijklmnopqrstuvwxyz";
  cin >> n;

  int result[26];
  fill_n(result, 26, 99999999);
  int temp[26];

  for (int i = 0; i < n; i++) {
    fill_n(temp, 26, 0);
    string str;
    cin >> str;

    for (char c: str) {
      int ind = (int)alphabet.find(c);
      temp[ind]++;
    }

    for (int j = 0; j < 26; j++) {
       result[j] = min(result[j], temp[j]);
    }
  }

  string ans = "";

  for (char c : alphabet) {
    for (int i = 0; i < result[(int)alphabet.find(c)]; i++) {
      ans += c;
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
n, m = [int(x) for x in input().split()]

if m != 0:
  g = [set() for _ in range(n)]
  valid = [-1] * n
  set_list = []
  for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a-1].add(b-1)
    g[b-1].add(a-1)

  j = -1
  for i in range(n):
    if valid[i] == -1:
      set_list.append(set())
      j += 1
      stack = [i]
      while len(stack)!=0:
        v = stack.pop()
        set_list[j].add(v)
        valid[v] = 1
        for i in g[v]:
          if valid[i] == -1:
            stack.append(i)
            set_list[j].add(i)
            valid[i] = 1
  ans = 1
  for i in range(len(set_list)):
    ans = max(len(set_list[i]),ans)

  print(ans)

else:
  print(1)

Measured memory_bytes: 164260
import sys
flush = sys.stdout.flush
write = sys.stdout.write
readline = sys.stdin.readline
N = int(readline())
Q0 = ""
Q1 = ""

q0 = "..##"
q1 = ".#.#"

def query(Q0, Q1):
    write("%s\n%s\n" % (Q0, Q1))
    flush()
    r = readline()
    if r == "end\n":
        exit(0)
    return r == "T\n"

while len(Q0) < N:
    for i in range(4):
        if query(Q0+q0[i], Q1+q1[i]):
            Q0 += q0[i]
            Q1 += q1[i]
            break
    else:
        break
while len(Q0) < N:
    for i in range(4):
        if query(q0[i]+Q0, q1[i]+Q1):
            Q0 = q0[i] + Q0
            Q1 = q1[i] + Q1
            break
    else:
        break
exit(1)

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
    int n;
    string s;
    int len[5] = {5,7,5,7,7};
    int count;
    int now;
    int ans;
    while(1){
        cin >> n;
        if(n==0) return 0;
        vector<int> w(n);
        for(int i=0;i<n;i++){
            cin >> s;
            w[i]=s.length();
        }
        ans=-1;
        for(int i=0;i<n;i++){
            count = 0;
            now = 0;
            for(int j=i;j<n;j++){
                count+=w[j];
                if(count==len[now]){
                    now++;
                    count=0;
                    if(now==5){
                        ans=i;
                    }
                }else if(count>len[now]){
                    break;
                }
            }
            if(ans != -1){
                break;
            }
        }
        cout << ans+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	S := nextLine()
	var R, G, B, cnt int
	for i := 0; i < N; i++ {
		switch S[i] {
		case 'R':
			R++
		case 'G':
			G++
		case 'B':
			B++
		}
	}
	for i := 0; i < N-2; i++ {
		for j := 1; i+j+j < N; j++ {
			check := make([]byte, 3)
			check[0] = S[i]
			check[1] = S[i+j]
			check[2] = S[i+j+j]
			switch string(check) {
			case "RGB", "RBG", "GRB", "GBR", "BRG", "BGR":
				cnt++
			}
		}
	}
	fmt.Println(R*B*G - cnt)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 1824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

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

const ll inf = 1LL<<60;

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

  ll mod = n%1000;
  if (mod == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << 1000-mod << endl;

  return 0;
}


Measured memory_bytes: 3632
def BS(A, N):
    A = list(map(int, A.split()))
    flag = 1
    count = 0 
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                unk = A[j]
                A[j] = A[j-1]
                A[j-1] = unk
                flag = 1
                count = count +1
    print(" ".join(map(str,A)))
    print(count)
 
N = int(input())
A = input()
BS(A, N)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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 const INF = 1001001001;
ll const MOD = 1000000007;


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

int A,B,C,D;
cin >> A >> B >> C >> D;
int start = max(A,C),stop = min(B,D);

cout << max(stop-start,0) << endl;

return 0;
}

Measured memory_bytes: 256
#include<assert.h>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

char anti(char c) {
    if (c == 'S') return 'W';
    if (c == 'W') return 'S';
    assert(false);
}
int N;
char S[100111];
char A[100111];
const char *TYPE = "SW";
bool check(int i) {
    int l = A[(i-1+N)%N], r = A[(i+1)%N];
    if (A[i] == 'S') {
	if (S[i] == 'o') return l == r;
	else return l != r;
    } else {
	if (S[i] == 'x') return l == r;
	else return l != r;
    }
}
int main() {
    scanf("%d%s", &N, S);

    REP (a, 2) REP (b, 2) {
	A[0] = TYPE[a];
	A[1] = TYPE[b];
	for (int i=1; i<N-1; i++) {
	    if (A[i] == 'S') {
		if (S[i] == 'o') A[i+1] = A[i-1];
		else A[i+1] = anti(A[i-1]);
	    } else {
		if (S[i] == 'x') A[i+1] = A[i-1];
		else A[i+1] = anti(A[i-1]);
	    }
	}

	bool yes = check(0) && check(N-1);

	if (yes) {
	    puts(A);
	    return 0;
	}
    }
    puts("-1");

    return 0;
}



Measured memory_bytes: 512
from heapq import heappush, heappop

#1. 入力
H,W = map(int, input().split())

INF = float("inf")
graph1 = []

for i in range(10):
    graph1.append(list(map(int, input().split())))

graph2 = [[] for _ in range(10)]
for i in range(10):
    for j in range(10):
        graph2[i].append((graph1[i][j], j))

A = []
for i in range(H):
    A.append(list(map(int, input().split())))

#2. ダイクストラ
def dijkstra(graph:list, node:int, start:int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF]*node
    
    # 始点ノードの距離を0とし、dfsのためのpriority queを作成
    dist[start] = 0
    heap = [(0,start)]
    
    # 未探索のノードをpriority queueに入れる
    while heap:
        cost, cur_node = heappop(heap)
        
        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heappush(heap, (dist[nex_node], nex_node))
    
    return dist

dist_to1 = []
for i in range(10):
    dist = dijkstra(graph2, 10, i)
    dist_to1.append(dist[1])

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] == -1:
            continue
        else:
            ans += dist_to1[A[h][w]]
    
print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>


using namespace std;


template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}


#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(container).begin(), (container).end()

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif



int main()
{
	inp(int, n, m);
	inpva(vector<int>, m, l, r);
	
	int lmax = 1;
	int rmin = n;
	repi(m) {
		if (lmax < l[i]) lmax = l[i];
		if (rmin > r[i]) rmin = r[i];
	}
	
	int ans = rmin - lmax + 1;
	otp(ans < 0 ? 0 : ans);
	
	return 0;
}


Measured memory_bytes: 3572
w, h, n = map(int, input().split())
left_x = 0
right_x = w
up_y = h
down_y = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        left_x = max(left_x, x)
    elif a == 2:
        right_x = min(right_x, x)
    elif a == 3:
        down_y = max(down_y, y)
    else:
        up_y = min(up_y, y)

if right_x - left_x > 0 and up_y - down_y > 0:
    ans = (right_x - left_x) * (up_y - down_y)
else:
    ans = 0
print(ans)

Measured memory_bytes: 38256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        static int MOD = 1000000007;

        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            long n = in.nextInt();
            long ans = power(10, n) - power(9, n) - power(9, n) + power(8, n);
            ans %= MOD;
            ans = (ans + MOD) % MOD;

            out.println(ans);
        }

        static long power(long x, long n, int mod)
        {
            if (n == 0)
            {
                return 1;
            }
            long result = power(x, n / 2, mod);
            result = result * result % mod;
            if (n % 2 == 1)
            {
                result = result * x % mod;
            }
            return result;
        }

        static long power(long x, long n)
        {
            return power(x, n, MOD);
        }

    }
}



Measured memory_bytes: 27028
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	vector<int> v(4);
	int k;
	for(int i = 0; i < 5; i++) cin >> v[i];
	cin >> k;
	for(int i = 0; i < 5; i++) {
		for(int j = i + 1; j < 5; j++) {
			if(abs(v[i]-v[j])>k) {
				cout << ":(";
				exit(0);
			}
		}
	}
	cout << "Yay!";
	return 0;
}


Measured memory_bytes: 256