akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX_COLORS 6
#define MAX_CIRCLES 4
#define MAX_N (MAX_COLORS*MAX_CIRCLES)
#define MAX_STATES (1<<MAX_N)

int biggest, n;

/*
struct circle{
    int x, y, r, c;
};*/

int X[MAX_N];
int Y[MAX_N];
int R[MAX_N];
int C[MAX_N];

//circle C[MAX_N];
char dp[MAX_STATES];

bool isOver( int c1, int c2 ){
    int dx, dy;
    dx = (X[c1] - X[c2]) * (X[c1] - X[c2]);
    dy = (Y[c1] - Y[c2]) * (Y[c1] - Y[c2]);
    return dx + dy < (R[c1] + R[c2])*(R[c1] + R[c2]) ? true : false;
}

bool isDeleted( int state, int num ){
    return (state & (1<<num)) == 0 ? false : true;
}
/*
void pbit(int num){
    //cout << "bit: ";
    do{
        printf("%d", num&1);
        num = num>>1;
    }while(num);
    //printf("\n");
}*/

bool isTop( int state, int num ){
    //pbit(state);
    for( int i = num-1; i >= 0; i-- ){
        if( isDeleted(state, i) ) continue;
        if( isOver(num, i) ) return false;
    }
    //cout << num << " is top" << endl;
    return true;
}

void search(int s){
    //for( int s = 0; s < 1<<n; s++ ){
        /*cout << "s: ";
        pbit(s);
        cout << endl;
        */
        for( int i = 0; i < n; i++ ){
            if( isDeleted(s, i) ) continue;
            //cout << "i: " << i << endl;
            for( int j = i+1; j < n; j++ ){
                if( isDeleted(s, j) ) continue;
                //cout << "i: " << i << endl;
                //cout << "j: " << j << endl;
                if( isTop(s, i) && isTop(s, j) && C[i] == C[j] ){
                    int next = s | 1<<i | 1<<j;
                    bool visited;
                    visited = dp[next] == -1 ? false : true;
                    //next(s);
                    //cout << "," << i << "," << j << endl;
                    if( dp[next] < dp[s]+2 ) dp[next] = dp[s]+2;
                    if( biggest < dp[next] ) biggest = dp[next];
                    if( (next|1) != (1<<n)-1 && !visited ) search(next);
                }
            }
        }
    //}
}

void init(){
    for( int s = 0; s < 1<<n; s++ ){
        dp[s] = -1;
    }
}

int main(){
    while( cin >> n, n ){
        for( int i = 0; i < n; i++ ){
            //circle a;
            //scanf("%d%d%d%d", a.x, a.y, a.r, a.c);
            cin >> X[i] >> Y[i] >> R[i] >> C[i];
            // C[i] = a;
        }
        biggest = 0;
        init();
        dp[0] = 0;
        search(0);
        printf("%d\n", biggest);
        //cout << "ans: " << biggest << endl;
    }
}

Measured memory_bytes: 17528
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] ab = new int[M][2];
        for(int i=0;i<M;i++){
            ab[i][0] = sc.nextInt();
            ab[i][1] = sc.nextInt();
        }
        Main.myComparator mc = new Main.myComparator();
        Arrays.sort(ab,mc);
        int ans = 1;
        int i=1;
        int left=ab[0][0];
        int right = ab[0][1];
        while(i<M){
            left = Math.max(left,ab[i][0]);
            right = Math.min(right,ab[i][1]);
            if(left>=right){
                ans++;
                left = ab[i][0];
                right = ab[i][1];
            }
            i++;
        }




        System.out.println(ans);
    }
    public static class myComparator implements Comparator<int[]>{
        @Override
        public int compare(int[] o1, int[] o2) {
            if(o1[0]-o2[0]!=0) return (o1[0]-o2[0]);
            else return o1[1]-o2[1];
        }
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<long long int> a;
    long long int count=0;
    for(int i=0; i < n; i++){
        int tmp;
        cin >> tmp;
        if(tmp % 2 == 0){
            a.push_back(tmp);
        }
    }
    
    for(auto i=0; i < a.size(); i++){
        while(a[i] % 2 == 0){
            a[i] = a[i] / 2;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

void Swap( int& a, int& b ){
    int tmp = std::move(a);
    a = std::move(b);
    b = std::move(tmp);
}

// when 0th Recurtion, params -> Partition( v, 1, v.size()-1 );
int Partition( std::vector<int>& v, int p, int r ){
    int x = v[r];
    //std::cout << "after v[r]\n";
    int i = p - 1;
    //std::cout << "loop: ";
    for( int j = p; j < r; ++j ){
        //std::cout << j << " ";
        if( v[j] <= x ){
            Swap( v[++i], v[j] );
        }
    }
    //std::cout << "\n";
    Swap( v[i+1], v[r] );
    return i + 1;
}

int main(){
    int n;
    std::cin.tie(0);
    std::cin >> n;

    std::vector<int> v(n);
    for( auto& elem : v ){
        std::cin >> elem;
        //std::cout << elem << " ";
    }
    //std::cout << "\n";

    int r = Partition( v, 0, v.size()-1 );

    for( int i = 0; i < v.size(); ++i ){
        if( i != r ){
            std::cout << v[i] << ( ( i != v.size()-1 )? " " : "\n" );
        }else{
            std::cout << "[" << v[i] << "]" << ( ( i != v.size()-1 )? " " : "\n" );
        }
    }

}


Measured memory_bytes: 3068
#include <stdio.h>
int main(void){
	int n, p[20] = {0}, c[20] = {0}, ans = 0;
	scanf("%d", &n);getchar();
	for(int i = 0; i < n; i++){
		scanf("%d", &p[i]);getchar();
	}
	for(int i = 0; i < n; i++){
		scanf("%d", &c[i]);getchar();
	}
	for(int i = 0; i < n; i++){
		p[i] -= c[i];
		if(p[i] > 0){
			ans += p[i];
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
ll power(ll a,ll b)
{ll result=1;
while(b>0)
{if(b%2==1)
 result*=a;
 a*=a;
 b/=2;
}
return result;
}
int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll pr1=a*c;
ll pr2=a*d;
ll pr3=b*c;
ll pr4=b*d;
ll max=std::max({pr1,pr2,pr3,pr4});
cout<<max;
}


Measured memory_bytes: 3652
//Name : Rupa Dey
  //Date : 13 September 2020
//joi sri gour hori gobindo...
//gobindo ja hobe vlor jonnoi hobe..
#include<bits/stdc++.h>
#define ll long long
//#define d double
#define ld long double
#define vi vector<int>
#define vul vector<ull>
#define vl vector<ll>
#define pb push_back
#define si set<int>
#define sl set<ll>
#define yes cout<<"YES\n"<<endl
#define no cout<<"NO\n"<<endl
#define ys cout<<"Yes\n"<<endl
#define n0 cout<<"No\n"<<endl
#define test cin>>t; while(t--)
#define for(i,a,n) for(i=a;i<n;i++)
#define mp make_pair
#define ft first
#define sc second
#define gp ' ';
#define MAX 9999999
#define MOD 1000000007
#define nd endl
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,d,x,y,prod=1,pd=1,pos,neg;
    cin>>a>>b>>c>>d;
    //x = max(a,b);
    //y= max(c,d);

        if(a>0 && b>0 && c>0 && d>0)
     {
         prod = b*d;
            cout<<prod<<nd;
     }
     else
     {
         pos = max(a*c,b*d);
         neg = max(b*c,a*d);
         prod = max(pos,neg);
         cout<<prod<<nd;
     }


}
//hare krishna...
//hey gobindo kripa koro......
//only gobindo exists..^..


Measured memory_bytes: 3592
var    ch:char;
       a:array['a'..'z'] of longint;
begin
   while not eoln do
     begin
      read(ch);
        inc(a[ch]);
      end;
   for ch:='a' to 'z' do
    if a[ch]=0 then begin writeln(ch);exit;end;
        writeln('None');
end.

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <stack>
#include <stdio.h>
#include <map>
#include <set>
#include <time.h>
#include <string>
#include <fstream>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <assert.h>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define pdd pair<double,double>
#define pii pair<ll,ll>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD2 1000000009
#define INF ((ll)1e+18)
#define x1 fldgjdflgjhrthrl
#define x2 fldgjdflgrtyrtyjl
#define y1 fldggfhfghjdflgjl
#define y2 ffgfldgjdflgjl
#define N 131072
#define SUM 377
#define MAG 33554431
#define RED 0
#define BLUE 1
#define eps 1e-7
typedef long long ll;
typedef long double ld;
using namespace std;
ll i,j,n,k,l,m,tot, flag,r,z, K,x1,y1,x2,y2,x3,y3,x,y,h,num,h2,timer,sz,q,ans, curL, curR, SQ, P, Q, bad;
string s, t, s1, t1;
string tran(string x)
{
    for (int i = 0; i < x.size(); i++)
        if (x[i] == 0)
            x[i] = 'S';
        else
            x[i] = 'W';
    return x;
}
int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("output.txt","w",stdout);
 	cin >> n;
 	cin >> s;
 	t = s;
 	for (t[0] = 0; t[0] <= 1; t[0]++)
        for (t[1] = 0; t[1] <= 1; t[1]++)
        {
            for (i = 2; i < n; i++)
            {
                if (s[i-1] == 'x')
                    t[i] = (1^t[i-2]^t[i-1]);
                else
                    t[i] = (t[i-1]^t[i-2]);
            }
            //cout << tran(t) << endl;
            if ((s[0] == 'x' && (t[n-1]^t[0]^1) == t[1] || s[0] == 'o' && (t[n-1]^t[0]) == t[1])&&
                (s[n-1] == 'x' && (t[n-2]^t[n-1]^1) == t[0] || s[n-1] == 'o' && (t[n-2]^t[n-1]) == t[0]))
            {
                cout << tran(t) << endl;
                return 0;
            }
        }
    cout << -1 << endl;
 	return 0;
}


Measured memory_bytes: 640
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n;
    vector <pii> a(n);
    for (int i=0;i<n;i++){
        cin >> a[i].ff >> a[i].ss ; 
    }
    for (int i=0;i<n-2;i++){
        if ( a[i].ff == a[i].ss and a[i+1].ff == a[i+1].ss and a[i+2].ff == a[i+2].ss ){
            co("Yes");
            return ; 
        }
    }
    co("No");
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

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

  int N; cin >> N;
  vector<int> v0(N, 0);
  for (int i = 0; i < N; i++) {
    v0[i] = i + 1;
  }

  vector<int> P(N); for (ll i = 0; i < N; i++) cin >> P[i];
  vector<int> Q(N); for (ll i = 0; i < N; i++) cin >> Q[i];

  int p = 0, q = 0;
  vector<int> v;
  v = v0;
  do {
    p++;
    bool check = true;
    for (int i = 0; i < v.size(); i++) {
      if (v[i] != P[i]) check = false;
    }
    if (check) break;
  } while (next_permutation(v.begin(), v.end()));

  v = v0;
  do {
    q++;
    bool check = true;
    for (int i = 0; i < v.size(); i++) {
      if (v[i] != Q[i]) check = false;
    }
    if (check) break;
  } while (next_permutation(v.begin(), v.end()));

  ll ans = abs(p - q);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter

"""
・左から見て最大値
・自分より右に、自分より以上の数がいくつあるか
・自分の下の数が何か
"""

N = int(input())
A = [int(x) for x in input().split()]

nums = sorted(set(A), reverse = True)
nums.append(0)
answer = [0] * N
counter = Counter(A)
position = dict() # その数字がある左端のインデックス
for i,a in enumerate(A):
    if not (a in position):
        position[a] = i

# 大きい数字から処理していく
for n, next_n in zip(nums[:-1], nums[1:]):
    i = position[n]
    c = counter[n]
    # 山がc個ある。i番を記録しながらnext_nに合流
    counter[n] -= c
    counter[next_n] += c
    if next_n != 0:
        position[next_n] = min(position[next_n], i)
    answer[i] += c * (n - next_n)

print('\n'.join(map(str,answer)))

Measured memory_bytes: 39548
#include <iostream>
using namespace std;
typedef long long ll;

ll calc2(ll num) {
  int cnt1 = (num+1)/2;
  ll ans=cnt1%2;
  if (num%2==0) ans ^= num;
  return ans;
}

ll calc(ll num) {
  if (num<=0) return 0;
  //4 ->0,1,2,3,4 => +1
  num++;
  // 10^3 <= 2^10
  // 1000 <= 1024
  // 10^12 <= 2^40
  ll ans = 0;
  for (int i = 0; i < 50; i++) {
    // 0-digit loop 2
    // 1-digit loop 4
    // 2-digit loop 8
    ll loop = (1LL << (i+1));
    ll cnt = (num/loop)*(loop/2);
    cnt+=max(0LL, (num%loop)-(loop/2));
    if (cnt%2==1) {
      ans+= 1LL << i;
    }
  }
  return ans;
}

int main() {
  ll A, B;
  cin >> A >> B;
  ll ans = calc(B) ^ calc(A-1);
  ll ans2 = calc2(B) ^ calc2(A-1);
  cout << ans << endl;
  //cout << ans2 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String op = sc.next();
		int b = sc.nextInt();
		if(op.equals("+"))System.out.println(a+b);
		else System.out.println(a-b);
		}
		
}


Measured memory_bytes: 23764
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a,b = [0], [0]

for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

j=M
ans = 0
for i in range(N+1):
	if a[i]>K:
		break
	while K-a[i] < b[j]:
		j-=1
	ans=max(ans,i+j)

print(ans)

Measured memory_bytes: 47444
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    string s;
    cin >> s;
    ll n = s.size();
    ll up = 0;
    ll down = 0;
    ll ans = 0;
    vector<ll> number(n+1);
    for (ll i = 0; i < n; i++) {
        if (s.at(i) == '<') {
            up++;
            number.at(i+1) = up;
        } else up = 0;
    }
    for (ll i = n - 1; i >= 0; i--) {
        if (s.at(i) == '>') {
            down++;
            number.at(i) = max(number.at(i), down);
        } else down = 0;
        ans += number.at(i);
    }
    ans += number.at(n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7628
#include <iostream>
#include <vector>
#include <deque>
#include <bitset>

using namespace std;
#define rep(i,n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

bool ok(deque<int> v,ll x){
	bitset<32000> cur;
	cur[16000] = 1;
	for(int i = 0 ; i < v.size() ; i++){
		cur = (cur << v[i]) | (cur >> v[i]);
	}
	return cur[16000 + x];
}
void solve(string s, ll x, ll y){
	s += "T";
	deque<int> v[2];
	int c = 0;
	int t = 0;
	for(int i = 0 ; i < s.size() ; i++){
		if( s[i] == 'T' ) v[t].push_back(c), c = 0, t ^= 1;
		else if( s[i] == 'F' ) c++;
	}
	x -= v[0][0];
	v[0].pop_front();

	cout << (ok(v[0], x) && ok(v[1], y) ? "Yes" : "No") << endl;
}

int main(){	
	ll y;
	string s;
	ll x;
	cin >> s;
	scanf("%lld",&x);
	scanf("%lld",&y);
	solve(s, x, y);
	return 0;
}



Measured memory_bytes: 384
import sys
N, Y = map(int, input().split())

for l in range(N+1):
  for m in range(N-l+1):
    n = N - l - m
    if l * 1000 + m * 5000 + n * 10000 == Y:
      print('{} {} {}'.format(n, m, l))
      sys.exit(0)
print('-1 -1 -1')

Measured memory_bytes: 2940
#include <stdio.h>
#include <list>
using namespace std;
int main(){
    list<int> l;
    list<int>::iterator u=l.begin();
    int n,k;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&k);
        if(k==0){
            scanf("%d",&k);
            u=l.insert(u,k);
        }
        else if(k==1){
            scanf("%d",&k);
            if(k>0)while(k--)u++;
            else{
                k=-k;
                while(k--)u--;
            }
        }
        else u=l.erase(u);
    }
    for(int i:l)printf("%d\n",i);
}


Measured memory_bytes: 18316
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> &lb, vector<int> &ub, vector<int> &P, vector<vector<int>> &ch, bool &ok, int v = 0){
  for (int w : ch[v]){
    dfs(lb, ub, P, ch, ok, w);
    if (!ok){
      return;
    }
    lb[v] = max(lb[v], lb[w] - 1);
    ub[v] = min(ub[v], ub[w] + 1);
  }
  if (P[v] != -1){
    if(P[v] < lb[v] || ub[v] < P[v]){
      ok = false;
      return;
    }
    lb[v] = P[v];
    ub[v] = P[v];
  }
  return;
}
int main(){
  int N;
  cin >> N;
  vector<vector<int>> E(N);
  for (int i = 0; i < N - 1; i++){
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    E[A].push_back(B);
    E[B].push_back(A);
  }
  int K;
  cin >> K;
  vector<int> P(N, -1);
  for (int i = 0; i < K; i++){
    int V;
    cin >> V;
    V--;
    cin >> P[V];
  }
  vector<int> c(N, -1);
  c[0] = 0;
  queue<int> Q;
  Q.push(0);
  while (!Q.empty()){
    int v = Q.front();
    Q.pop();
    for (int w : E[v]){
      if (c[w] == -1){
        c[w] = 1 - c[v];
        Q.push(w);
      }
    }
  }
  array<bool, 2> ex = {false, false};
  for (int i = 0; i < N; i++){
    if (P[i] != -1){
      ex[(P[i] + c[i]) % 2] = true;
    }
  }
  if (ex[0] && ex[1]){
    cout << "No" << endl;
  } else {
    vector<int> p(N, -1);
    vector<vector<int>> ch(N);
    vector<bool> used(N, false);
    used[0] = true;
    queue<int> Q2;
    Q2.push(0);
    while (!Q2.empty()){
      int v = Q2.front();
      Q2.pop();
      for (int w : E[v]){
        if (!used[w]){
          used[w] = true;
          p[w] = v;
          ch[v].push_back(w);
          Q2.push(w);
        }
      }
    }
    vector<int> lb(N, -100000);
    vector<int> ub(N, 1100000);
    bool ok = true;
    dfs(lb, ub, P, ch, ok);
    if (!ok){
      cout << "No" << endl;
    } else {
      vector<int> ans(N);
      ans[0] = lb[0];
      queue<int> Q3;
      Q3.push(0);
      while (!Q3.empty()){
        int v = Q3.front();
        Q3.pop();
        for (int w : ch[v]){
          if (ans[v] - 1 < lb[w]){
            if (ans[v] + 1 > ub[w]){
              ok = false;
            } else {
              ans[w] = ans[v] + 1;
            }
          } else {
            ans[w] = ans[v] - 1;
          }
          Q3.push(w);
        }
      }
      if (!ok){
        cout << "No" << endl;
      } else {
        cout << "Yes" << endl;
        for (int i = 0; i < N; i++){
          cout << ans[i] << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 25900
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int a, b, c, x, ans = 0;
  cin >> a >> b >> c >> x;

  rep(i, a+1){
    rep(j, b+1){
      rep(k, c+1){
        if(500*i + 100*j + 50*k == x) {
          ans++;
          // printf("%d %d %d\n", i, j, k);
        }
      }
    }
  }
  print(ans);

}


Measured memory_bytes: 888
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	String[][] chm = {

			{"a","b","c","d","e"},

			{"f","g","h","i","j"},

			{"k","l","m","n","o"},

			{"p","q","r","s","t"},

			{"u","v","w","x","y"},

			{"z",".","?","!"," "},			

	};

	

	class data{

		int r;

		int c;

		boolean ng = false;

		data(int r,int c){

			this.r = r;

			this.c = c;

			ng = !(this.r < 7 && this.c < 6 && this.r > 0 && this.c > 0);

		}

		@Override

		public String toString() {	

			return chm[r-1][c-1];

		}

	}

	void run(){

		for(;sc.hasNext();){

			String message = sc.next();

			char[] buffer = message.toCharArray();

			int n = buffer.length;

			if((n&1)==1){

				System.out.println("NA");

				continue;

			}

			data[] d =new data[n/2];

			boolean f = false;

			for(int i = 0; i < n;i+=2){

				d[i/2] = new data(buffer[i]-'0',buffer[i+1]-'0');

				f = f||d[i/2].ng;

			}

			if(f){

				System.out.println("NA");

				continue;

			}

			for(int i = 0; i < n/2;i++){

				System.out.print(d[i]);

			}

			System.out.println();

		}

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

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

fn main() {
   input! {
      n: usize,
      m: usize,
   }
   let ans = match (n, m) {
      (1, 1) => 1,
      (1, _) => m-2,
      (_, 1) => n-2,
      _ => (n-2)*(m-2),
   };
   println!("{}", ans);
}


Measured memory_bytes: 4352
//C - Digits in Multiplication: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int divi(ll n) {
    int last = 1;
    for(ll i = 2; i*i <= n; i++) {
        if(n % i == 0) last = i;
    }
    //cout << n << "\n";
    //cout << last << "\n";
    return last;
}

int solve(int x, ll n) {
    ll y = n / x;
    string n1, n2;
    n1 = to_string(x);
    n2 = to_string(y);
    return max(n1.size(), n2.size());
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ll n;
    int ans;
    cin >> n;
    ans = solve(divi(n), n);
    cout << ans << "\n";
}

Measured memory_bytes: 256
def main():
    S = input()
    T = input()

    rs = S.replace("?","a")

    candidate = None

    for i in range(len(S)-len(T)+1):
        ts = S[i:i+len(T)]
        #print("checking:",ts)
        is_mismatched = False
        for ii in range(len(T)):
            if ts[ii] != "?" and ts[ii] != T[ii]:
                is_mismatched = True
                break
        if not is_mismatched:
            candidate = rs[:i] + T + rs[i+len(T):]
           
    return candidate if candidate else "UNRESTORABLE"

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if((b-a) == (c-b)) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	map<char,int> ct;
	int mx=0;
	for (const char ch : s)
		ct[ch]++,mx=max(mx,ct[ch]);
	cout<<(ct.size()==2&&mx==2?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <map>

using namespace std;

int *par, *sz;

void init(int n) {
    par = new int[n];
    sz = new int[n];
    for (int i = 0; i < n; i++) {
        par[i] = i;
        sz[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x)
        return x;
    else 
        return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x), y = find(y);

    if (x == y)
        return ;

    if (sz[x] > sz[y])
        par[y] = x;
    else {
        par[x] = y;
        if (sz[y] == sz[x])
            sz[y]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int n, m, k;    cin >> n >> m >> k;
    init(n);
    vector<set<int> > s(n);
    
    for (int i = 0; i < m; i++) {
        int a, b;   cin >> a >> b;
        a--, b--;
        unite(a, b);
        s[a].insert(b);
        s[b].insert(a);
    }

    for (int i = 0; i < k; i++) {
        int c, d;   cin >> c >> d;
        c--, d--;
        if (same(c, d)) {
            s[c].insert(d);
            s[d].insert(c);
        }
    }

    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        mp[find(i)]++;
    }

    for (int i = 0; i < n; i++) {
        cout << mp[find(i)] - s[i].size() - 1 << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 31788
data = {}

while True:
    team, score = input().split(',')
    if team == score == '0': break
    if int(score) in data:
        data[int(score)].append(team)
    else:
        data[int(score)] = [team]

while True:
    try:
        n = input()
    except:
        break
    for d in data.keys():
        if n in data[d]:
            tmp = reversed(list(data.keys()))
            ind = list(tmp).index(d)
            print(ind + 1)

Measured memory_bytes: 6720
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

class UnionFind {
    int n;
    vector<int> uni;
public:
    explicit UnionFind(int n) : uni(static_cast<u32>(n), -1) , n(n){};

    int root(int a){
        if (uni[a] < 0) return a;
        else return (uni[a] = root(uni[a]));
    }

    bool unite(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] += uni[b];
        uni[b] = a;
        return true;
    }

    int size(int i){ return -uni[root(i)]; }
    bool same(int a, int b) { return root(a) == root(b); }
};

int main() {
    int n;
    cin >> n;
    vector<array<int, 3>> v(n-1);
    for (int i = 0; i < n-1; ++i) {
        scanf("%d %d %d", &v[i][1], &v[i][2], &v[i][0]);
        v[i][1]--; v[i][2]--;
    }
    UnionFind uf(n);
    vector<int> par(n);
    for (int i = 0; i < n; ++i) {
        par[i] = i;
    }
    sort(v.begin(),v.end(), greater<>());
    vector<vector<int>> G(2*n-1);
    vector<ll> dp(2*n-1, 1), dq(2*n-1, 0);
    for (int i = 0; i < n-1; ++i) {
        int x = par[uf.root(v[i][1])], y = par[uf.root(v[i][2])];
        par[uf.root(v[i][1])] = par[uf.root(v[i][2])] = n+i;
        uf.unite(v[i][1], v[i][2]);
        dp[n+i] = dp[x]+dp[y];
        dq[y] += dp[x]*v[i][0], dq[x] += dp[y]*v[i][0];
        G[n+i].emplace_back(y);
        G[n+i].emplace_back(x);
    }
    for (int j = 2*n-2; j >= n; --j) {
        for (auto &&i : G[j]) {
            dq[i] += dq[j];
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%lli\n", dq[i]);
    }
    return 0;
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
/////////////////////////////////
int main(){
    int a,b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b));
}

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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

const int N=100010;
int a[N],b[N],n;
int _a[N<<1],_b[N];
int fa[N<<1],sz[N<<1];

int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}

int main()
{
    n=read();
    int xora=0,xorb=0,ans=0;
    for(int i=1;i<=n;i++) xora^=(_a[i]=a[i]=read());
    for(int i=1;i<=n;i++) xorb^=(_b[i]=b[i]=read());
    a[++n]=xora;b[n]=xorb;_a[n]=a[n];_b[n]=b[n];
    sort(_a+1,_a+1+n);sort(_b+1,_b+1+n);
    for(int i=1;i<=n;i++) if(_a[i]!=_b[i]) return !puts("-1");
    for(int i=1;i<n;i++) ans+=(a[i]!=b[i]);
    if(ans==0) return !puts("0");
    for(int i=1;i<=n;i++) _a[i+n]=_b[i];
    sort(_a+1,_a+1+n);
    int hs=unique(_a+1,_a+1+n)-(_a+1);
    for(int i=1;i<=hs;i++) fa[i]=i,sz[i]=1;
    for(int i=1;i<=n;i++)
    {
        a[i]=lower_bound(_a+1,_a+1+hs,a[i])-_a;
        b[i]=lower_bound(_a+1,_a+1+hs,b[i])-_a;
        int x=find(a[i]),y=find(b[i]);
        if(x!=y) fa[x]=y,sz[y]+=sz[x];
    }
    if(a[n]==b[n]) sz[find(a[n])]++;
    for(int i=1;i<=n;i++) ans+=(fa[i]==i&&sz[i]>1);
    cout<<ans-1<<endl;
    return 0;
}

Measured memory_bytes: 5632
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String line = null;
		try (Scanner sc = new Scanner(System.in)) {
			line = sc.nextLine();

			SimpleDateFormat sd = new SimpleDateFormat("yyyy/MM/dd");

			Date d1 = sd.parse(line);

			Date d2 = sd.parse("2019/04/30");

			String result = "Heisei";
			if (d1.compareTo(d2) > 0) {
				result = "TBD";
			}

			System.out.println(result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 26664
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

type city struct {
	name, pref, year, id int
}

type cityList []city

func (a cityList) Len() int      { return len(a) }
func (a cityList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

type byName struct{ cityList }

func (a byName) Less(i, j int) bool { return a.cityList[i].name < a.cityList[j].name }

type byYear struct{ cityList }

func (a byYear) Less(i, j int) bool {
	if a.cityList[i].pref != a.cityList[j].pref {
		return a.cityList[i].pref < a.cityList[j].pref
	}
	return a.cityList[i].year < a.cityList[j].year
}

func main() {
	sc.Split(bufio.ScanWords)

	_, M := scanInt(), scanInt()
	L := make(cityList, M)
	for i := 0; i < M; i++ {
		L[i].name, L[i].pref, L[i].year = i+1, scanInt(), scanInt()
	}

	sort.Sort(byYear{L})
	L[0].id = 1
	for i := 1; i < M; i++ {
		if L[i].pref == L[i-1].pref {
			L[i].id = L[i-1].id + 1
		} else {
			L[i].id = 1
		}
	}

	sort.Sort(byName{L})
	for _, l := range L {
		fmt.Printf("%06d%06d\n", l.pref, l.id)
	}
}


Measured memory_bytes: 7800
; ABC123-A
(defun maxx(l v)
  (if (equal l nil) (return-from maxx v))
  (let ((fc (car l)))
	(let ((nv (if (> fc v) fc v)))
	  (maxx (cdr l) nv)
	  )
	)
  )

(defun minx(l v)
  (if (equal l nil) (return-from minx v))
  (let ((fc (car l)))
	(let ((nv (if (< fc v) fc v)))
	  (minx (cdr l) nv)
	  )
	)
  )

(defun makelist(l n)
  (if (eql n 0) (return-from makelist nil))
  (return-from makelist (cons (read) (makelist l (- n 1))))
  )

(defun abc123a()
  (let ((l (makelist '() 5)))
	(let ((k (read)))
	  (setq minv (minx (cdr l) (car l)))
	  (setq maxv (maxx (cdr l) (car l)))

	  (format t "~a~%" (if (>= k (- maxv minv)) "Yay!" ":("))
	  )
	)
  )

(abc123a)




Measured memory_bytes: 15460
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    ts <- getIntList
    m <- getInt
    let s = zipWith (+) (scanl (+) 0 ts) (tail (scanr (+) 0 ts))
    replicateM_ m $ do
        [p, x] <- getIntList
        print $ s !! (p - 1) + x

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

int main() {
	string a="";
	cin>>a;
	int total=0;
	for(int i=0;i<a.length()/2;++i)
	{
		if(a[i]!=a[a.length()-i-1])
		++total;
	}
	cout<<total<<"\n";
	return 0;
}

Measured memory_bytes: 256
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            
            string s = Console.ReadLine();
            ulong k = ulong.Parse(Console.ReadLine());
            ulong count = 0;
            ulong count2 = 0;
            int frag = 0;
            int len = s.Length;
          

            for(int i = 1; i < len;i++)
            {
                if(s[i] == s[i -1])
                {
                    count++;
                    i++;
                }
                
                if(i == len - 1 && s[0] == s[len -1] )
                    frag = 1;
            }

            if(frag == 1 && k > 1)
            {
                count2++;
                for(int i = 2; i < len;i++)
                {
                    if(s[i] == s[i - 1])
                    {
                        count2++;
                        i++;
                    }
                    
                    
                    if(i == len)
                        frag = 2;
                }
            }
            
            if(len == 1)
                Console.WriteLine(k /2);
            else if(frag == 1)
                Console.WriteLine(count + count2 *(k -1));
            else if(frag == 2)
                Console.WriteLine(count * (ulong)((k + 1)/2) + count2 * (ulong)(k/2));
            else
                Console.WriteLine(count * k);
                

            
        }
    }

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

typedef long long ll;

int n, r;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> r;
    if (n < 10) {
        cout << r + 100 * (10 - n) << endl;
    } else {
        cout << r << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vvi dist(n,vi(n,INFTY));
		rep(i,m){
			int s,d,w; cin>>s>>d>>w;
			s--; d--;
			dist[s][d]=dist[d][s]=w;
		}
		
		vvi dp(3,vi(n,INFTY)),vis(3,vi(n));
		dp[0][0]=0;
		for(;;){
			int cc=-1,ci=-1;
			rep(c,3) rep(i,n){
				if(vis[c][i])
					continue;
				if(cc==-1 || dp[c][i]<dp[cc][ci]){
					cc=c;
					ci=i;
				}
			}
			if(cc==-1 || dp[cc][ci]==INFTY)
				break;
			vis[cc][ci]=1;
			
			if(cc==0 || cc==1){
				rep(i,n) if(dist[ci][i]!=INFTY)
					dp[cc+1][i]=min(dp[cc+1][i],dp[cc][ci]);
			}
			if(cc==0 || cc==2){
				rep(i,n)
					dp[cc][i]=min(dp[cc][i],dp[cc][ci]+dist[ci][i]);
			}
		}
		
		cout<<min(dp[0][n-1],dp[2][n-1])<<endl;
	}
	
	return 0;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

ll dp[55][55][2510];
// グローバルとローカルではグローバルの方が確保できるメモリの量が大きい。
// ローカルで上記のメモリを確保しようとするとsegmentation faultになるので注意！

int main(){
    int N,A;
    cin >> N >> A;
    vector<int> cards(N);
    REP(i,0,N){
        cin >> cards[i];
    }

    //dp[i][j][k] = i番目までのカードの中でj枚選んだ時に合計がkになる組み合わせの数
    dp[0][0][0]=1;
    REP(i,0,N){
        REP(j,0,N){
            REP(k,0,2500){
                if(dp[i][j][k]){
                    //選ばない場合
                    dp[i+1][j][k] += dp[i][j][k];
                    //選ぶ場合
                    dp[i+1][j+1][k+cards[i]] += dp[i][j][k];
                }
            }
        }
    }

    ll ans=0;
    REP(j,1,N+1) ans+=dp[N][j][A*j];
    P(ans);
}

Measured memory_bytes: 53504
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>

using namespace std;


#define INF pow(10, 9)
// typedef priority_queue<tuple<int,int,int>, vector< tuple<int, int, int> >, greater< tuple<int, int, int> > > PQ;






int main(void)
{


    string S, T;
    cin >> S >> T; // SからTを見る
    int Len_S = S.size();
    int Len_T = T.size();
    int count_max = 0;
    int count;
    for(int i=0; i<Len_S-Len_T+1; i++)
    {

        count =0;
        for(int j=0; j<Len_T; j++)
        {
            if(S[i+j]==T[j]) count++;
            
        }
        if(count > count_max)  count_max = count;


    }

    cout << Len_T-count_max <<endl;




    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  map< int, int > mp;
  REP(i, N) {
    int p;
    cin >> p;
    mp[p]++;
  }
  int evenodd = 0;
  FORA(e, mp) {
    if (e.second > 1)
      evenodd += e.second, evenodd = (evenodd - 1) % 2;
  }
  print(mp.size() - evenodd);
}

Measured memory_bytes: 6528
import queue
N, M = map(int, input().split())
edges = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)

S, T = map(int, input().split())
S -= 1
T -= 1

INF = 1001001001
dist = [[0] * 3 for _ in range(100005)]

for i in range(N):
    for j in range(3):
        dist[i][j] = INF

q = queue.Queue()
q.put((S, 0))
dist[S][0] = 0
while not q.empty():
    e = q.get()
    v = e[0]
    l = e[1]
    for u in edges[v]:
        nl = (l + 1) % 3
        if dist[u][nl] != INF:
            continue
        dist[u][nl] = dist[v][l] + 1
        q.put((u, nl))

ans = dist[T][0]
if ans == INF:
    ans = -1
else:
    ans //= 3
print(ans)

Measured memory_bytes: 78056
def main():
    n, k = map(int, input().split())
    s = [0 for _ in range(n)]
    for _ in range(k):
        d = int(input())
        a = list(map(int, input().split()))
        for aa in a:
            s[aa - 1] += 1
    ans = 0
    for ss in s:
        if ss == 0:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9188
n=int(input())
a=list(map(int,input().split()))
cnt_num=[0]*(n+1)
cnt_num[0]=3
ans=1
p=10**9+7
for i in range(n):
  ans *= cnt_num[a[i]]
  ans %=p
  cnt_num[a[i]+1]+=1
  cnt_num[a[i]]-=1
print(ans%p)

Measured memory_bytes: 85000
N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())

d = [0]*(10**5)

for i in A:
    d[i-1] += 1

ans = sum(A)

for i in range(Q):
    b, c = map(int,input().split())
    ans += (c-b)*d[b-1]
    d[c-1] += d[b-1]
    d[b-1] = 0
    print(ans)

Measured memory_bytes: 20632
n=1000000
pr = [1] * n
pr[0],pr[1]=0,0
for i in range(2, int(n**0.5)+1):
    if pr[i] == 1:
        for j in range(i ** 2, n , i):
                pr[j] =0
for k in range(3, n):
    pr[k] += pr[k-1]
while True:
    try:
        m = int(raw_input())
        print pr[m]
    except:
        break

Measured memory_bytes: 68128
// Problem D

#include <stdio.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <cassert>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <stack>

#define MAXN 300000
#define pb push_back
#define mp make_pair

using namespace std;

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

int N, M;
vector<int> G[MAXN];
int prec[MAXN];

int main() {
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    G[a-1].pb(b-1);
    G[b-1].pb(a-1);
  }
  
  prec[0] = 0;
  for (int i=1; i<N; i++) prec[i] = -1;
  queue<int> tovisit;
  tovisit.push(0);
  int visited = 1;
  while (!tovisit.empty()) {
    int v = tovisit.front();
    //~ cout << "Visiting node " << v << endl;
    visited++;
    tovisit.pop();
    for (int i=0; i<(int)G[v].size(); i++)
      if (prec[G[v][i]] == -1) {
	tovisit.push(G[v][i]);
	prec[G[v][i]] = v;
      }    
  }
  
  if (visited < N) cout << "No\n";
  else {
    cout << "Yes\n";
    for (int i=1; i<N; i++) cout << prec[i]+1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 15152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
ll mod=1000000007;
ll dp[30000];
ll finds(ll in,ll sum)
{
    if(sum>n)return 0;
    if(sum==n)return 1;
    if(dp[sum]!=-1)
        return dp[sum];
    ll ans=0;
    for(int i=3;i<=(n-sum);i++)
    {
        if(sum+i<=n)
            ans+=finds(in+1,sum+i);
        if(ans!=0)
            ans%=mod;
    }
    return dp[sum]=ans;
}
int main()
{
    //IOS;
    //ll t;cin>>t;while(t--)
    {
        memset(dp,-1,sizeof dp);
        ll a,b,c,d,i,j,k,l,m,temp=0,f=0,cnt=0;
        cin>>n;
        cout<<finds(0,0)<<endl;
    }
}


Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	ll n,k;
	cin>>n>>k;
	ll sum=0;
	for(int i=1;i<=n;i++){
		ll x;
		cin>>x;
		if(x>=k)sum++;
	}cout<<sum<<endl;return 0;
}/*『你强归你强，我永不示弱』*/




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

int main()
{
    int n;
    bool flag=true;
    cin>>n;
    --n;
    while(flag)
    {
        flag=false;
        ++n;
        for(int i=2;i*i<=n;i++)
        {
            if((n%i)==0)
                {
                    flag=true;
                    break;
                }
        }
    }
    cout<<n;
    return 0;
}



Measured memory_bytes: 3580
#include <cstdio>

int main()
{
	int a,b;
	
	
	for(a=1;a<10;a++)
	{
		for(b=1;b<10;b++)
		{
			printf("%dx%d=%d\n",a,b,a*b);
		}
	}
	
	return 0;
}

Measured memory_bytes: 924
<?php
list($h, $w, $d) = ints();
for ($i = 0; $i < $h; $i++) {
    $a[] = ints();
}
for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
        $A[$a[$i][$j]] = [$i, $j];
    }
}
$n = $h * $w;
$cusum = array_fill(1, $d, 0);
for ($i = $d + 1; $i <= $n; $i++) {
    $cusum[$i] = $cusum[$i - $d] + abs($A[$i][0] - $A[$i - $d][0]) + abs($A[$i][1] - $A[$i - $d][1]);
}
list($q) = ints();
for ($i = 0; $i < $q; $i++) {
    list($l, $r) = ints();
    $ans[] = $cusum[$r] - $cusum[$l];
}
echo implode(PHP_EOL, $ans);

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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


int main() {
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  int max_dis = k-(a.at(n-1)-a.at(0));
  rep(i,n-1){
    max_dis = max(max_dis,a.at(i+1)-a.at(i));
  }
  int ans = k - max_dis;
  cout << ans << endl;
}


Measured memory_bytes: 4020
#include<stdio.h>

int main(){
    int N, M, X, Y;
    int x[110], y[110];
    int xmax=-110, ymin=110;
    int i;

    scanf("%d %d %d %d", &N, &M, &X, &Y);
    for(i=0; i<N; i++){
        scanf("%d", &x[i]);
        if(xmax < x[i]){
            xmax = x[i];
        }
    }
    for(i=0; i<M; i++){
        scanf("%d", &y[i]);
        if(ymin > y[i]){
            ymin = y[i];
        }
    }

    if(xmax<ymin && X<xmax && ymin<=Y){
        printf("No War");
    }else{
        printf("War");
    }

    return 0;
}

Measured memory_bytes: 128