akhauriyash/Code-Regression huggingface dataset:
N = int(input())
L = []
C = []
A = []
b = w = 0
b_d = {}
w_d = {}
for i in range(2*N):
    c, a = input().split()
    a = int(a)
    n = 0
    for cc, aa in zip(C, A):
        if cc == c and aa > a:
            n += 1
    L.append([0] * (N + 1))
    cnt = 0
    for j in range(N, -1, -1):
        L[-1][j] = cnt+n
        if j in (b_d if c=="W" else w_d):
            cnt+=1

    if c=="B":
        b_d[a] = i
        b+=1
    else:
        w_d[a] = i
        w+=1
    C.append(c)
    A.append(a)
#print(L, b_d, w_d)

dp = [[0]*(N+2) for i in range(N+2)]
for i in range(N+1):
    for j in range(N+1):
        if i==j==0:
            continue
        if i==0:
            dp[i][j] = dp[i][j-1] + L[b_d[j]][i]
        elif j==0:
            dp[i][j] = dp[i-1][j] + L[w_d[i]][j]
        else:
            dp[i][j] = min(dp[i-1][j] + L[w_d[i]][j],
                           dp[i][j-1] + L[b_d[j]][i])
print(dp[-2][-2])


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

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

  VI v(n);
  REP(i,n){
    cin >> v[i];
  }

  SORT(v);
  REVERSE(v);
  ll ans = 0;

  FOR(i,0,n-3){
    int max_length = v[i];
    FOR(j,i+1,n-2){
      int mid_l = v[j];
      FOR(k,j+1,n-1){
        if(max_length<mid_l+v[k]){
          ans++;
        }else{
          break;
        }
      }
    }
  }

  ANS(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;


void solve(std::string S){
  char op[2] = {'+', '-'};
  int ret = S[0]-'0';
  for(int i=0; i<2; i++) {
    int x = ret;
    if(op[i]=='+') ret += (S[1]-'0');
    else ret -= (S[1]-'0');
    for(int j=0; j<2; j++) {
      int x = ret;
      if(op[j]=='+') ret += (S[2]-'0');
      else ret -= (S[2]-'0');
      for(int k=0; k<2; k++) {
	int x = ret;
	if(op[k]=='+') ret+= (S[3]-'0');
	else ret -= (S[3]-'0');
	if(ret == 7) {
	  std::cout << S[0]<<op[i]<<S[1]<<op[j]<<S[2]<<op[k]<<S[3]<<"=7"<< std::endl;
	  return;
	}
	ret = x;
      }
      ret = x;
    }
    ret = x;
  }
}

int main(){
    std::string ABCD;
    std::cin >> ABCD;
    solve(ABCD);
    return 0;
}


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

int main() {
    int x;
    cin>>x;
    set<int> st;
    st.insert(1);
    for (int i=2;i*i<=x;i++)
        for (int j=i*i;j<=x;j*=i)
            st.insert(j);
    auto it=st.upper_bound(x);
    it--;
    cout<<*it<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int a,b,c[13],i;

int main(){
  cin>>a>>b;
  for(i=0;i<12;++i){
    c[i]=i+2;
  }
  c[12]=1;
  for(i=0;i<13;++i){
    if(a == c[i]){
      a = i;
      break;
    }
  }
  for(i=0;i<13;++i){
    if(b == c[i]){
      b = i;
      break;
    }
  }
  if(a>b){
    cout<<"Alice"<<endl;
  }else if(a<b){
    cout<<"Bob"<<endl;
  }else{
    cout<<"Draw"<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <stdio.h>

int main(){
    char word[1200] = "word";

    scanf("%[^\n]", word);
    int length = strlen(word);

    for(int i=0; i < length; i++){
        char ch = word[i];
        if(islower(ch)) printf("%c", toupper(ch));
        else if(isupper(ch)) printf("%c", tolower(ch));
        else printf("%c", word[i]);
    }

    
    
    printf("\n");   
    return 0;
}


Measured memory_bytes: 2576
h,w = map(int,input().split())
lst=[list(map(str, input())) for i in range(h)]

ans=lst

dxy = [(1,1),(1,0),(1,-1),(0,1),(0,-1),(-1,1),(-1,0),(-1,-1)]

for y in range(h):
    for x in range(w):
        if lst[y][x] == "#":
            continue
        c = 0
        for dx, dy in dxy:
            if x+dx < 0 or x+dx > w-1 or y+dy < 0 or y+dy > h-1:
                continue
            if lst[y+dy][x+dx] == "#":
                c += 1
        ans[y][x] = c

for row in ans:
    print("".join(list(map(str, row))))

Measured memory_bytes: 3064
main = do
  [n,x]<-map read.words<$>getLine
  ls<-map read.words<$>getLine
  print $ go 0 x (scanl (+) 0 ls)

go _ _ [] = 0
go n x (l:ls)
  | n > x = 0
  | n == l = 1 + go (n+1) x ls
  | otherwise = go (n+1) x (l:ls)


Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;
 
int main()
{
	string str;
	int m;
	int h;

	while (cin >> str)
	{
		if (str == "-") break;

		cin >> m;

		int sum = 0;
		for (int i = 0; i < m; i++)
		{
			cin >> h;
			sum += h;
		}
		cout << str.substr(sum % str.size());
		cout << str.substr(0, sum % str.size()) << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
vector<int> v;
int main() {
  long long int a, b, c;
  cin >> a >> b >> c;
  if (a < b) {
    if (b < c) {
      if (c % 2 == 0) {
        cout << 0 << endl;
      } else {
        cout << a * b << endl;
      }
    } else {
      if (b % 2 == 0) {
        cout << 0 << endl;
      } else {
        cout << a * c << endl;
      }
    }
  } else {
    if (a < c) {
      if (c % 2 == 0) {
        cout << 0 << endl;
      } else {
        cout << a * b << endl;
      }
    } else {
      if (a % 2 == 0) {
        cout << 0 << endl;
      } else {
        cout << b * c << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>A(N);
  for (int i=0; i<N; i++)cin>>A[i];
  int MAX=A[0];
  int cnt=0;
  for (int i=0; i<N; i++){
    if (MAX<A[i])MAX=A[i];
    if (MAX<=A[i])cnt++;
  }
  cout<<cnt<<endl;
}

  
  


Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
int main ()
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(d>=(abs(a-c))){
        printf("Yes\n");
    }

   else if(d>=abs(a-b)&& d>=abs(b-c)){
            printf("Yes\n");
        }
		else{
            printf("No\n");
        }


}


Measured memory_bytes: 1640
import java.util.*;

class Main {
	public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        
        double num1 = sc.nextDouble();
        
        System.out.printf("%.6f %.6f\n",num1 * num1 * Math.PI,2 * num1 * Math.PI);
    }
}


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

int main(){
  int A ,B;
  cin >> A >> B;
  int S = 0;
  for(int i = A; i <= B; i++){
    int a = i / 10000;
    int b = i/ 1000 - a * 10 ;
    int c = i/ 100 - a * 100 - b * 10 ;
    int d = i/ 10 - a * 1000 - b * 100 - c * 10 ;
    int e = i - a * 10000 - b * 1000 - c * 100 - d * 10;
    if(a==e && b==d){
      S++;
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
n, k = [ int(v) for v in input().split() ]
tree_list = [0]*n

for i in range(n):
	tree_list[i] = int(input())

tree_list = sorted(tree_list)


ans = n*10**9
for i in range(n-k+1):
	d = tree_list[k-1+i] - tree_list[i]
	ans = min(ans,d)
print(ans)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep0c(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

typedef pair<int, int> BA;
int N;
multiset<BA> bas;

void solve() {
  int t = 0;
  for(const BA& ba : bas) {
    t += ba.second;
    if(ba.first < t) {
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
  return;
}

int main() {
  scanf("%d", &N);
  rep(i, N) {
    int a, b;
    scanf("%d %d", &a, &b);
    bas.insert(make_pair(b, a));
  }
  solve();
  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

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

    ll dl[n+1],dr[n+2];
    dl[n] = dr[n] = a[n];
    dr[n+1] = 0;
    for(int i = n-1; i >= 0; i--){
        dl[i] = (dl[i+1]+1)/2+a[i];
        dr[i] = dr[i+1]+a[i];
    }

    if(dl[0] > 1) cout << -1 << endl;
    else {
        ll ans = 0;
        ll E = 1;
        for(int i = 0; i < n+1; i++){
            ans += E;
            E -= a[i];
            E = min(E*2,dr[i+1]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5272
#include<iostream>
int i,n,a[52];
long long x;
std::string s,t;
main(){
  std::cin>>n>>s>>t;
  for(s[0]-s[1]?i=1,x=3:(i=2,x=6);i<s.size();x%=1000000007)s[i]-s[i+1]?++i,s[i-2]-t[i-2]?0:x*=2:(i+=2,x*=s[i-4]-s[i-3]?2:3);
  std::cout<<x<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n,k;
    cin>>n>>k;
    ll res = 0;
    for(ll i=0;i<n;i++){
	ll h;
	cin>>h;
	if( h>=k)res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
char S[1002][1002];
D[1002][1002];
H,W;
ans;
sz;fr;
Qx[1100000];
Qy[1100000];
main()
{
	scanf("%d %d\n",&H,&W);
	for(int i=1;i<=H;i++)gets(S[i]+1);
	for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)
	{
		if(S[i][j]=='#')
		{
			Qx[sz]=i;
			Qy[sz]=j;
			++sz;
		}
		else
		{
			D[i][j]=100000000;
		}
	}
	while(fr<sz)
	{
		int x=Qx[fr];
		int y=Qy[fr];
		++fr;
		if(ans<D[x][y])ans=D[x][y];
		if(x>1&&D[x-1][y]>D[x][y]+1)
		{
			D[x-1][y]=D[x][y]+1;
			Qx[sz]=x-1;
			Qy[sz]=y;
			++sz;
		}
		if(x<H&&D[x+1][y]>D[x][y]+1)
		{
			D[x+1][y]=D[x][y]+1;
			Qx[sz]=x+1;
			Qy[sz]=y;
			++sz;
		}
		if(y>1&&D[x][y-1]>D[x][y]+1)
		{
			D[x][y-1]=D[x][y]+1;
			Qx[sz]=x;
			Qy[sz]=y-1;
			++sz;
		}
		if(y<W&&D[x][y+1]>D[x][y]+1)
		{
			D[x][y+1]=D[x][y]+1;
			Qx[sz]=x;
			Qy[sz]=y+1;
			++sz;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 13312
import java.util.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    int n = sc.nextInt(), m = sc.nextInt(), p = 0;
	    if(n+m == 0) break;
	    Queue<Integer> que = new LinkedList<Integer>();
	    for(int i = 1; i <= n; i++) que.add(new Integer(i));
	    for(int i = 1; i <= m; i++){
		String str = sc.next();
		int s = i%3, t = i%5;
		boolean f = false;
		if(s+t == 0){
		    if(str.equals("FizzBuzz")) f = true;
		} else if(s == 0){
		    if(str.equals("Fizz")) f = true;
		} else if(t == 0){
		    if(str.equals("Buzz")) f = true;
		} else {
		    if(str.equals(String.valueOf(i))) f = true;
		}

		if(f || que.size() == 1) que.add(que.poll());
		else que.poll();
	    }

	    int[] a = new int[que.size()+1];
	    while(que.size() > 0) a[p++] = que.poll();
	    Arrays.sort(a);
	    System.out.print(String.valueOf(a[1]));
	    for(int i = 2; i <= p; i++) System.out.print(" "+String.valueOf(a[i]));
	    System.out.println();
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 13000
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, int> mp;
    for(auto &x : a){
        cin >> x;
        mp[x]++;
    }
    sort(ALL(a));
    uni(a);
    reverse(ALL(a));
    ll ans = 0;
    ll mx = 0, mx1 = 0;
    for(int i = 0; i < SZ(a); i++){
        if(mp[a[i]] >= 2){
            mx = max(mx, a[i]);
        }
    }
    mp[mx] -= 2;
    for(int i = 0; i < SZ(a); i++){
        if(mp[a[i]] >= 2){
            mx1 = max(mx1, a[i]);
        }
    }
    cout << mx * mx1;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 7296
n=int(input())
a=input().split()
b1=[a[2*i] for i in range(0,n//2)]
b2=[a[2*i+1] for i in range(0,n//2)]
if n%2: b=[a[-1]]+list(reversed(b1))+b2
else: b=list(reversed(b2))+b1
print(" ".join(b))

Measured memory_bytes: 27716
#include<iostream>
using namespace std;
typedef long long ll;
ll ans;
int n;
int flag;
int a[105], b[105], c[105];
int main(){
	ans = 0;
	cin >> n;
	for(int i =  1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= n; i++)
		cin >> b[i];
	for(int i = 1; i <= n - 1; i++)
		cin >> c[i];
	for(int i = 1; i <= n; i++){
		ans += b[i];
	}
	for(int i = 1; i <= n; i++){
		if(a[i + 1] == a[i] + 1)
			ans += c[a[i]];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

memo =  [[] for _ in range(N+1)]

for _ in range(M):
    Ai, Bi = map(int, input().split())
    memo[Ai].append(Bi)
    memo[Bi].append(Ai)

# print(memo)

visited = [False] * (N+1)
visited[1] = True
ans = [0]*(N+1)

queue = [1]

while queue:
    room = queue.pop(0)
    for connected_room in memo[room]:
        # print(connected_room)
        if visited[connected_room] == True:
            continue
        ans[connected_room] = room
        visited[connected_room] = True
        queue.append(connected_room)
print("Yes")
for a in ans[2:]:
    print(a)


Measured memory_bytes: 35280
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int ans[2];
int used[100000];
vector<P> G[100000];
void dfs(int x,int co=0){
  if(used[x])return;
  used[x]=1;
  if(ans[0]<co){
    ans[0]=co;
    ans[1]=x;
  }
  for(int i=0;i<G[x].size();i++)
    dfs(G[x][i].first,co+G[x][i].second);
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n-1;i++){
    int s,t,w;
    cin>>s>>t>>w;
    G[s].push_back(P(t,w));
    G[t].push_back(P(s,w));
  }
  dfs(0);
  fill(used,used+n,0);
  dfs(ans[1]);
  cout<<ans[0]<<endl;
}



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

int main() {
  
  string S;
  cin >> S;
  
  int ans = 999;
  
  for (int i=0;i<S.size()-2;i++) {
    int num = (S.at(i)-'0')*100 + (S.at(i+1) - '0') * 10 + (S.at(i+2) - '0');
    ans = min(ans,abs(num-753));
  }
  
  cout << ans << endl;
  
  
}
  

Measured memory_bytes: 256
n = int(input())
li = [0]*4
for _ in range(n):
    s = input()
    if s == 'AC':
        li[0]+=1
    elif s == 'WA':
        li[1]+=1
    elif s == 'TLE':
        li[2]+=1
    elif s == 'RE':
        li[3]+=1
print('AC x ',li[0])
print('WA x ',li[1])
print('TLE x ',li[2])
print('RE x ',li[3])

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    int h, w, k;
    cin >> h >> w >> k;
    char in;
    int g[333][333];
    rep(i, h){
        rep(j, w){
            cin >> in;
            if(in == '.') g[i][j] = 0;
            if(in == '#') g[i][j] = 1;
        }
    }

    set<int> aftercare;
    int res[333][333];
    int cnt = 1;
    int now = 0;
    rep(i, h){
        rep(j, w){
            if(!g[i][j]){
                res[i][j] = cnt;
                continue;
            }
            if(now == 0 && g[i][j]){
                now++;
                res[i][j] = cnt;
                continue;
            }
            if(now >= 1 && g[i][j]){
                now++;
                res[i][j] = ++cnt;
                continue;
            }
        }
        if(now == 0){
            rep(j, w){
                res[i][j] = 0;
            }
        }else{
            cnt++;
        }
        now = 0;
    }

    reps(i, 1, h-1){
        rep(j, w){
            if(res[i][j] == 0){
                res[i][j] = res[i-1][j];
            }
        }
    }
    repr(i, h-2, 0){
        rep(j, w){
            if(res[i][j] == 0){
                res[i][j] = res[i+1][j]; 
            }
        }
    }

    rep(i, h){
        rep(j, w){
            cout << res[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}


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

ll checker[200005];

int main()
{
	ll i,j,k,l,m,n,r;

	cin >> n;

	for(i=0;i<(n-1);i++)
	{
		cin >> k;

		checker[k]++; 
	}

	for(i=1;i<=n;i++)
		cout << checker[i] << '\n';
}

Measured memory_bytes: 5176
import sys

MOD = 10 ** 9 + 7

def main():
    n, *a = map(int, sys.stdin.read().split())

    res = 1
    rgb = [0, 0, 0]
    for i in range(n):
        cur = a[i]
        c = rgb.count(cur)
        res = res * c % MOD
        if cur == rgb[0]:
            rgb[0] += 1
        elif cur == rgb[1]:
            rgb[1] += 1
        elif cur == rgb[2]:
            rgb[2] += 1
    print(res)

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	int a[m], b[m];

	for(int i=0; i<m; i++) cin >> a[i] >> b[i];

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

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i, n) {
        cin >> w[i];
    }

    int all = accumulate(w.begin(), w.end(), 0);
    int ans = 100000;
    int sumx = 0;
    rep(i, n-1) {
        sumx += w[i];
        ans = min(ans, abs(2 * sumx - all));
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.Math.sin;
import static java.lang.Math.cos;
import static java.lang.Math.toRadians;

public class Main {

  private static StringBuilder buf = new StringBuilder();

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt( br.readLine() );
      Point2D p1 = new Point2D(0,0);
      Point2D p2 = new Point2D(100, 0);

      buf.append(p1);
      kochCurve( n, p1, p2 );
      buf.append(p2);

      System.out.print(buf);
      
    }
  }

  private static void kochCurve(int d, Point2D p1, Point2D p2) {
    if( d != 0) {
      Point2D s = new Point2D();
      Point2D t = new Point2D();

      s.x = (2*p1.x + p2.x) / 3;
      s.y = (2*p1.y + p2.y) / 3;
      t.x = (p1.x + 2*p2.x) / 3;
      t.y = (p1.y + 2*p2.y) / 3;

      Point2D u = new Point2D();
      double rad = toRadians(60);

      u.x = (t.x - s.x)*cos(rad) - (t.y - s.y)*sin(rad) + s.x;
      u.y = (t.x - s.x)*sin(rad) + (t.y - s.y)*cos(rad) + s.y;

      kochCurve(d-1, p1, s);
      buf.append(s);
      kochCurve(d-1, s, u);
      buf.append(u);
      kochCurve(d-1, u, t);
      buf.append(t);
      kochCurve(d-1, t, p2);
    }
  }
}

class Point2D {
  double x;
  double y;

  public Point2D() { }
  public Point2D(double x,double y) {
    this.x = x;
    this.y = y;
  }

  @Override
  public String toString() {
    return String.format("%.8f %.8f\n", x, y);
  }
  public double distance(Point2D p) {
    return Math.sqrt(Math.pow((p.x - this.x),2) + Math.pow((p.y - this.y), 2));
  }
}


Measured memory_bytes: 39984
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*
AC
上のbitから順に0,1を選択する．
O(log(K)*n)なので間に合う
*/

//累乗法
ll mod_pow(ll x,ll n,ll mod=1e18+7){
	ll res=1;
	while(n){
		if(n&1) (res*=x)%=mod;
		(x*=x)%=mod;
		n>>=1;
	}
	return res;
}

int main(void){
	ll n,k,a[100010],b[100010],cur=0,ans=0;
	cin>>n>>k;
	rep(i,n)cin>>a[i]>>b[i];
	rep(j,n)if((a[j]|k)==k)ans+=b[j];
	// cout<<bitset<8>(k)<<endl;
	irep(i,31){//最上位bitがどうなってるかの確認
		ll c=mod_pow(2,i),d=k/c;//d：最上位bit
		k-=c*d;
		if(d==1){
			//f：d=0にして，下の桁を全て1にした数
			ll f=cur+c-1,sum=0;
			rep(j,n)if((a[j]|f)==f)sum+=b[j];
			ans=max(ans,sum);
			ll e=cur+c;
			sum=0;
			rep(j,n)if((a[j]|e)==e)sum+=b[j];
			ans=max(ans,sum);
			// cout<<bitset<8>(f)<<endl;
		}
		cur+=c*d;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
public static void main(String[] args)
{ 
  Scanner sc=new Scanner(System.in);
  int x=sc.nextInt();
  int y=sc.nextInt();
  boolean flag=solve(x,y);
  System.out.println(flag?"Yes":"No");
}
  static boolean solve(int x,int y)
  {  if(y>x*4 || y%2==1) return false;
   
   if(2*x==y || 4*x==y)
      return true;
   
   if(y/2-x >=0 && 2*x -y/2 >=0)
     return true;
   
   return false;
   
  }
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n,m;
ll a[maxn];

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

  cin>>n>>m;
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  sort(a,a+n);

  vector<pair<ll,ll>> ops; //val,amt

  for (int i=0; i<m; i++) {
    pair<ll,ll> op; cin>>op.second>>op.first;
    ops.push_back(op);
  }

  sort(ops.begin(),ops.end());
  reverse(ops.begin(),ops.end());

  int i = 0;
  auto cur = ops.begin();
  while (i<n) {
    while (cur != ops.end() && cur->second==0) cur++;
    if (i==n || cur == ops.end()) break;
    if (cur->first <= a[i]) break;
    a[i] = cur->first;
    --cur->second;
    i++;
  }


  ll ans = 0;
  for (int i=0; i<n; i++) {
    ans += a[i];
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll K; cin >> K;
    vector<ll> X(50);
    rep(i, 50){
        X[i] = i;
    }

    ll lp = K / 50;
    rep(i, 50){
        X[i] += lp;
    }

    ll nokori = K % 50;
    rep(i, nokori){
        rep(j, 50){
            if(j == i){
                X[j] += 50;
            } else {
                X[j]--;
            }
        }
    }

    cout << 50 << endl;
    rep(i, 50){
        cout << X[i];
        if(i != 49){
            cout << " ";
        } else {
            cout << endl;
        }
    }

    return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, a, p);
  out((a * 3 + p) / 2);
}


Measured memory_bytes: 3596
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int r;
    cin >> r;
    cout << setprecision(20) << 2*M_PI*r << endl;
    return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
int main(){
    // data loader
    int a,b;
    cin>>a>>b;
    
    //main
    if (((a+b)%2)==1){
        cout<<"IMPOSSIBLE"<<endl;
    }else{
        cout<<(a+b)/2<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using LL = long long;
using P = pair<int,int>;


int main(){
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;;
	rep(i,N+1){
		int tmp = i;
		int res = 0;
		while(tmp){
			res += tmp%10;
			tmp /= 10;
		}
		if(A <= res && res <= B){
		   	ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}
			

		












Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <algorithm>
#include "memory.h"
#include <string>
#include <set>

using namespace std;

vector<int> A;

int main() {
	int n;
	scanf("%d", &n);
	A.resize(n);
	for(int i = 0; i < n; i++) scanf("%d", &A[i]);
	sort(A.begin(), A.end());
	if (A.back() - A[0] > 1) { printf("No\n"); return 0; }
	int q = 0;
	while (A[q] == A.back() - 1) q++;
	if (A[0] == A.back() && A[0] == A.size() - 1) { printf("Yes\n"); return 0; }
	if (q > A[0]) { printf("No\n"); return 0; }
	if (A.size() - q < 2*(A.back() - q)) { printf("No\n"); return 0; }
	printf("Yes\n");
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
int r,d,x,i=0;
cin>>r>>d>>x; 
int x1=r*x-d;
int x2=r*x1-d;  
for(;i<10;i++){
  cout<<x1<<endl;
  int x3=r*x2-d;
  x1=x2;
  x2=x3;
	
	
	}
  
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }


int main() {
    ll h, n, a;
    cin >> h >> n;
    ll sum = 0;
    rep1(i, n){
        cin >> a;
        sum += a;
    } 
    if (sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
    //printf("%.12f", ans);
}

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

int main(){
	int Vecesg=0,VecesP=0;
	string s;
	cin >> s;
	int N=s.length();
	for (int i = 0; i < N; ++i)
	{
		if (s[i]=='g') Vecesg++;
		else VecesP++;
	}
	int Limite=N/2;
	int ans=Limite-VecesP;
	cout << ans;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    bool flag = false;
    rep(a, n + 1){
        rep(b, m + 1){
            if ((a * (m - b) + b * (n - a)) == k) flag = true;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = [*map(int, input().split())]
for i in range(k):
    B = [0]*n
    for j in range(n):
        l = max(0, j-A[j])
        r = j + A[j] + 1
        B[l] += 1
        if r <= n-1: B[r] -= 1
    is_same = True
    for j in range(n-1):
        B[j+1] = B[j+1] + B[j]
        if B[j+1] != n: is_same = False
    if is_same: break
    A = B
print(*B,sep=' ')


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;

    cout << a*b/2 << endl;


    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <cstdio>

const int M = 100010;
const int MOD = 1e9+7;
int _w;

void add_mod( int &a, int b ) {
	a += b;
	a -= a >= MOD ? MOD : 0;
}

void mul( int A[4][4], int B[4][4], int C[4][4] ) {
	static int tmp[4][4];
	memset(tmp, 0, sizeof tmp);
	for( int i = 0; i < 4; ++i )
		for( int j = 0; j < 4; ++j )
			for( int k = 0; k < 4; ++k )
				add_mod( tmp[i][j], int(1LL * A[i][k] * B[k][j] % MOD) );
	for( int i = 0; i < 4; ++i )
		for( int j = 0; j < 4; ++j )
			C[i][j] = tmp[i][j];
}

void pow( int A[4][4], int b, int C[4][4] ) {
	static int a[4][4], c[4][4];
	for( int i = 0; i < 4; ++i )
		for( int j = 0; j < 4; ++j )
			a[i][j] = A[i][j];
	memset(c, 0, sizeof c);
	for( int i = 0; i < 4; ++i ) c[i][i] = 1;
	while(b) {
		if( b & 1 ) mul(c, a, c);
		mul(a, a, a);
		b >>= 1;
	}
	for( int i = 0; i < 4; ++i )
		for( int j = 0; j < 4; ++j )
			C[i][j] = c[i][j];
}

int n, m, x[M];
int ans[4][4], Q1[4][4], Q2[4][4], tmp[4][4];

void init() {
	for( int i = 0; i < 4; ++i ) ans[0][i] = 1;
	Q1[0][0] = 1;
	Q1[3][0] = 1;
	Q1[0][1] = 1;
	Q1[1][1] = 1;
	Q1[3][1] = 1;
	Q1[0][2] = 1;
	Q1[2][2] = 1;
	Q1[3][2] = 1;
	Q1[0][3] = 1;
	Q1[1][3] = 1;
	Q1[2][3] = 1;
	Q1[3][3] = 2;
	Q2[0][0] = 1;
	Q2[0][1] = 1;
	Q2[1][1] = 1;
	Q2[0][2] = 1;
	Q2[2][2] = 1;
	Q2[0][3] = 1;
	Q2[1][3] = 1;
	Q2[2][3] = 1;
	Q2[3][3] = 1;
}

int main() {
	_w = scanf( "%d%d", &n, &m );
	for( int i = 1; i <= m; ++i )
		_w = scanf( "%d", x+i );
	init();
	int now = 1;
	for( int i = 1; i <= m; ++i ) {
		pow(Q1, x[i] - now, tmp);
		mul(ans, tmp, ans);
		mul(ans, Q2, ans);
		now = x[i] + 1;
	}
	pow(Q1, n-now, tmp);
	mul(ans, tmp, ans);
	printf( "%d\n", ans[0][3] );
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}


struct dsu {
        vector<int> par, rk;
        dsu(int n) {
                par.resize(n + 1);
                rk.resize(n + 1);
                for (int i = 1; i <= n; i++) {
                        par[i] = i;
                        rk[i] = 1;
                }
        }

        int find(int x) {
                while (x != par[x]) x = par[x];
                return x;
        }

        void unite(int a, int b) {
                a = find(a), b = find(b);
                if (a != b) {
                        if (rk[a] < rk[b]) swap(a, b);
                        par[b] = a;
                        rk[a] += rk[b];
                }
        }
};



void _main() {
        int n, m; cin >> n >> m;
        dsu d(n + 1);
        while (m--) {
                int x, y, z; cin >> x >> y >> z;
                d.unite(d.find(x), d.find(y));
        }


        int cnt = 0;
        set<int> s;
        for (int i = 1; i <= n; i++) {
                s.emplace(d.find(i));
        }

        cout << sz(s);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 8672
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;

struct stu{
	int num,flag;
	bool operator<(stu &s){
		return num<s.num;
	}
}st[maxn];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
	    scanf("%d",&st[i].num);
	    st[i].flag=i+1; 
	} 
	sort(st,st+n);
	for(int i=0;i<n;i++) printf("%d ",st[i].flag);
	return 0;	
} 

Measured memory_bytes: 1536
#include<stdio.h>
main(){
	int a,b;
	scanf("%d %d",&a,&b);
	
	if(a==b){
		printf("a == b\n");
	}else if(a<b){
		printf("a < b\n");
	}else{
		printf("a > b\n");
	}
	
	return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int h, w, n; cin >> h >> w >> n;
    int m = max(h, w);
    cout << (n + m - 1) / m << endl;
    return 0;
}

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



int main(){
    
    int N,K;    
    cin >> N >> K;
    vector<long long> num(K,0);
    for(int i = 1; i <= N;i++)num[i%K]++;
    long long res = 0;
    for(int a = 0; a < K;++a){
        int b = (K - a)%K;
        int c = (K - a)%K;
        if((b+c)%K != 0)continue;
        res += num[a] * num[b] * num[c];
    }
    cout << res << endl;
    
    
}


Measured memory_bytes: 1792
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10;
int n , a , b , h[MAXN];
bool check(int x)
{
	int idx = 0 , ans = 0;
	while(x * b < h[idx])
		ans += ((h[idx] - x * b) + a - b - 1) / (a - b) , idx ++;
	if(x < ans)
		return false;
	return true;
}
int32_t main()
{
	cin >> n >> a >> b;
	for(int i = 0 ; i < n ; i ++)
		cin >> h[i];
	sort(h , h + n) , reverse(h , h + n);
	int l = -1 , r = (1e18 + 1e2) / b;
	while(r - l > 1)
	{
		int mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	return cout << r << endl , 0;
}
														


Measured memory_bytes: 1024
import sys

def main():
    sys.setrecursionlimit(int(1e5))
    nvertices, nedges = map(int, input().split())
    Adj = [[] for i in range(nvertices)]
    AdjRev = [[] for i in range(nvertices)]
    for i in range(nedges):
        u, v = map(int, input().split())
        Adj[u].append(v)
        AdjRev[v].append(u)

    lst = []
    visited = [False] * nvertices
    for u in range(nvertices):
        if not visited[u]:
            dfs_first(u, Adj, visited, lst)

    lst.reverse()
    ids = [-1] * nvertices
    visited = [False] * nvertices
    id = 0
    for u in lst:
        if not visited[u]:
            dfs_second(u, AdjRev, visited, id, ids)
            id += 1

    Q = int(input())
    for i in range(Q):
        u, v = map(int, input().split())
        print(1 if ids[u] == ids[v] else 0)


def dfs_first(u, Adj, visited, lst):
    visited[u] = True
    for v in Adj[u]:
        if not visited[v]:
            dfs_first(v, Adj, visited, lst)
    lst.append(u)


def dfs_second(u, Adj, visited, id, ids):
    ids[u] = id
    visited[u] = True
    for v in Adj[u]:
        if not visited[v]:
            dfs_second(v, Adj, visited, id, ids)

main()

Measured memory_bytes: 19944
import sys

for i in sys.stdin:
    h,w = map(int,i.strip().split())

    if h==0 and w==0:
        break

    for i in range(h):
        str = ''
        for j in range(w):
            if (i+j) % 2 == 0:
                str += '#'
            else:
                str += '.'
        print(str)
    print()

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

/*高速化*/
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* define */
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))
#define REV(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REV(V)

/* 最大値と最小値に置き換える */
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;}


/* 型定義 */
typedef vector<long long> vi;
typedef long long ll;
using Graph = vector<vi>;


/* 定数 */
const double PI = 3.141592;
const double e = 2.6;
const long long Inf = 1LL << 60;
const long long mInf = -Inf;

/* 入力 */
long long N,M,K;

void calc()
{
    cin >> N >> M >> K;
    long long X = (M - 1 >= K ? K : M - 1);
    long long f = floor(X / M);
    long long ans = floor(N * X / M) - N * f;
    cout << ans << '\n';
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    calc();
}


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

long long mod = 1000000007;

long long exp(long long a, long long n) {
  if (n == 1) return a;
  
  if (n % 2 == 0) return exp(a, n / 2) * exp(a, n / 2) % mod;
  else return exp(a, n / 2) * exp(a, n / 2) % mod * a % mod;
}


long long com(long long n, long long r) {
  long long ans = 1;
  for (int i = 0; i < r; ++i) {
    ans *= n - i;
    ans %= mod;
  }
  for (int i = 0; i < r; ++i) {
    ans *= exp(i + 1, mod - 2);
    ans %= mod;
  }
  
  return ans;
}

int main() {
  long long n, a, b;
  cin >> n >> a >> b;
  
  long long ans = (exp(2, n) - 1 - com(n, a) - com(n, b)) % mod;
  if (ans < 0) cout << ans + mod << endl;
  else cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
s=input()
k=int(input())
a=[]
for t in s[:-1]:
  c=123-ord(t)
  if k<c or t=='a':
    a.append(t)
  else:
    k-=c
    a.append('a')
a.append(chr((ord(s[-1])-97+k)%26+97))
print(''.join(a))

Measured memory_bytes: 4272
#include <stdio.h>

int main(int ac, char **av) {
  char buf[256];
  int n, m, i, j;
  char c;
  while(fgets(buf, 256, stdin) != NULL) {
    sscanf(buf, "%d\n", &n);
    if (n == 0) break;
    char table[n][2];
    for(i = 0; i < n; i++) {
      scanf("%c %c\n", &table[i][0], &table[i][1]);
    }
    scanf("%d\n", &m);
    {
      char data[m + 1];
      for(i = 0; i < m; i++) {
        scanf("%c\n", &c);
        for(j = 0; j < n; j++) {
          if(table[j][0] == c) {
            c = table[j][1];
            break;
          }
        }
        data[i] = c;
      }
      data[m] = '\0';
      printf("%s\n", data);
    }
  }
  return 0;
}

Measured memory_bytes: 704
// 4/19 リアルタイム参加

#include <iostream>
using namespace std;

int N;
int A[200000] = {0};  // i番目の社員の先輩のNoを格納する。

// i番目の人に何人の部下がいるかを示すdfs。
// int dfs(int i) {
    
// }

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

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


Measured memory_bytes: 4412
n = str(input())

if n[-1]=='2' or n[-1]=='4' or n[-1]=='5' or n[-1]=='7' or n[-1]=='9':
    print('hon')
elif n[-1]=='0' or n[-1]=='1' or n[-1]=='6' or n[-1]=='8':
    print('pon')
else:
    print('bon')



Measured memory_bytes: 8980
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int A,B,M;
  cin >> A >> B >> M;
  ll amin=INF,bmin=INF;
  vector<ll> a(A),b(B),x(M),y(M),c(M);
  rep(i,A) {
    cin >> a[i];
    chmin(amin,a[i]);
  }
  rep(i,B) {
    cin >> b[i];
    chmin(bmin,b[i]);
  }
  rep(i,M) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--,y[i]--;
  }
  ll ans=amin+bmin;

  rep(i,M){
    ll tmp=a[x[i]]+b[y[i]]-c[i];
    chmin(ans,tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4224
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
  double a, b, c, d, e, f;
  while (scanf("%lf%lf%lf%lf%lf%lf", &a, &b, &c, &d, &e, &f) != EOF) {
    double det = a * e - b * d;
    double x = (c * e - b * f) / det;
    double y = (a * f - c * d) / det;
    if (fabs(x) < 1e-8) { x = 0; }
    if (fabs(y) < 1e-8) { y = 0; }
    printf("%.3f %.3f\n", x, y);
  }
}

Measured memory_bytes: 1084
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
#include<regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


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

	// A[i] < B[j] < C[k]

	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);

	ll ans = 0;

	for (int i = 0; i < N; i++) {
		int* it1 = lower_bound(A, A + N, B[i]); 
		int* it2 = upper_bound(C, C + N, B[i]); 
		ans += (it1 - A) * ((C + N) - it2);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, L;
int coord[30], dir[30];

signed main() {
    while(cin >> N >> L, N || L) {
        string d; int p;
        rep(i,0,N) {
            cin >> d >> p;
            coord[i] = p;
            dir[i] = (d == "L");
        }
        int ma = -1, idx = 0, sec = 0;
        while(1) {
            sec++;
            rep(i,0,N) {
                if(coord[i] < 0) continue;
                coord[i] += (1 * (dir[i] ? -1 : 1));
            }
            rep(i,0,N) rep(j,i+1,N) {
                if(coord[i] == coord[j]) {
                    dir[i] ^= 1;
                    dir[j] ^= 1;
                }
            }

            int cnt = 0;
            rep(i,0,N) {
                if(coord[i] == 0) {
                    ma = sec;
                    idx = i+1;
                    coord[i] = -1;
                }
                if(coord[i] == L) {
                    if(ma != sec) {
                        ma = sec;
                        idx = i+1;
                    }
                    coord[i] = -1;
                }
                if(coord[i] < 0) cnt++;
            }

            if(cnt == N) break;
        }
        printf("%lld %lld\n", ma, idx);
    }
    return 0;
}

Measured memory_bytes: 3096
N = int(input())
A = list(map(int, input().split()))
A.append(0)

total = 0
now = 0
skip = {}

for i in range(N):
    total += abs(A[i] - now)
    skip[i] = abs(A[i+1] - now) - abs(A[i] - now) - abs(A[i+1] - A[i])
    now = A[i]
total += abs(now)

for i in range(N):
    # print(total, skip[i])

    print(total+skip[i])

Measured memory_bytes: 64744