akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
typedef enum {
    S = 0,
    N,
    W,
    E
} cmd;
 
 
void showdice(int dice[7]) {
    int i;
 
    for (i = 1; i <= 6; ++i) {
        printf("%d ", dice[i]);
    }
    printf("\n");
    return;
}
 
void rotation(cmd command, int dice[7]) {
    int tmp;
    switch (command) {
    case S:
        tmp = dice[1];
        dice[1] = dice[5];
        dice[5] = dice[6];
        dice[6] = dice[2];
        dice[2] = tmp;
        break;
    case N:
        tmp = dice[1];
        dice[1] = dice[2];
        dice[2] = dice[6];
        dice[6] = dice[5];
        dice[5] = tmp;
        break;
    case W:
        tmp = dice[1];
        dice[1] = dice[3];
        dice[3] = dice[6];
        dice[6] = dice[4];
        dice[4] = tmp;
        break;
    case E:
        tmp = dice[1];
        dice[1] = dice[4];
        dice[4] = dice[6];
        dice[6] = dice[3];
        dice[3] = tmp;
    }
//  showdice(dice);
    return;
}
 
void toFront(int front, int dice[7]) {
 
     if (front == dice[1]) {
        rotation(S, dice);
    } else if(front == dice[2]) {
        ;
    } else if (front == dice[3]) {
        rotation(E, dice);
        rotation(N, dice);
    } else if (front == dice[4]) {
        rotation(W, dice);
        rotation(N, dice);
    } else if (front == dice[5]) {
        rotation(S, dice);
        rotation(S, dice);
    } else {
        rotation(N, dice);
    }
//   showdice(dice);
    return;
}
 
int isMatch(int dice1[7], int dice2[7]) {
    int i;
     
    toFront(dice1[2], dice2);
//  showdice(dice2);
    for (i = 0; (i < 3) && dice1[1] != dice2[1] ; ++i) {
//      showdice(dice2) ;
        rotation(W, dice2);
    }
    if (dice1[1] != dice2[1]) return 0;
    for (i = 3; i <= 6; ++i) {
        if (dice1[i] != dice2[i]) return 0;
    }
    return 1;
}
 
int main(void) {
    int i, j, n;
    int dices[100][7] = {0};
 
    scanf("%d", &n);
 
    for (i = 0; i < n; ++i) {
        for (j = 1; j <= 6; ++j) {
            scanf("%d", &dices[i][j]);
        }
    }
    for (i = 0; i < n; ++i) {
        for (j = 0; j < n; ++j) {
            if (i != j) {
                if (isMatch(dices[i], dices[j])) {
                    printf("No\n");
                    return 0;
                }
            }
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2108
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int N;
    cin >> N;
    string s;

    int gender[N+1];
    fill(gender, gender+N+1, 0);

    cout << 0 << endl;
    cin >> s;
    if (s == "Male") {
        gender[0] = gender[N] = 1;
    } else if (s == "Female") {
        gender[0] = gender[N] = 2;
    } else {
        return 0;
    }

    int l = N, r = 0;

    while (true) {
        int p = (l + r) / 2;
        cout << p << endl;
        cin >> s;
        if (s == "Male") {
            gender[p] = 1;
        } else if (s == "Female") {
            gender[p] = 2;
        } else {
            return 0;
        }

        if ((p - r) % 2 == 1) {
            if (gender[r] == gender[p]) {
                l = p;
            } else {
                r = p;
            }
        } else {
            if (gender[r] == gender[p]) {
                r = p;
            } else {
                l = p;
            }
        }
    }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;  cin >> N;
  string paper;
  map<string, int> votes;
  
  for(int i = 0;i < N;i++){
  cin >> paper;
  votes[paper]++;
  }

  int max = 0;
  auto begin = votes.begin(), end = votes.end();
  for (auto iter = begin; iter != end; iter++) {
    if(max < iter->second){
    max = iter->second;
    }
  }
  
  for(auto iter = begin; iter != end; iter++){
    if(iter->second == max){
    cout << iter->first << endl;
    }
  }
}

Measured memory_bytes: 25216
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace C_test_For_Atcorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var ans = 0;
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var c = cin.ReadInt;
            var x = cin.ReadInt;
            for (int i = 0; i <= a; i++)
                for (int j = 0; j <= b; j++)
                    for (int k = 0; k <= c; k++)
                        if (500 * i + 100 * j + 50 * k == x)
                            ans++;
            WriteLine(ans);

        }
    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue inputStream;

        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return (string)inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return (string)inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }

}

Measured memory_bytes: 13140
from itertools import product

n = int(input())
x = []
y = []
for i in range(n):
    xx = []
    yy = []
    for i in range(int(input())):
        arr = [int(i) for i in input().split()]
        xx.append(arr[0])
        yy.append(arr[1])
    x.append(xx)
    y.append(yy)

max_honest = 0
for honest in product([0,1], repeat=n):
    if sum(honest) < max_honest:
        continue
    for i, h in enumerate(honest):
        if h:
            for xx, yy in zip(x[i], y[i]):
                if honest[xx-1] != yy:
                    break
            else:
                continue
            break
    else:
        max_honest = sum(honest)

print(max_honest)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main() {
	string r, a;
	while (cin >> r >> a, r != "0" || a != "0") {
		int hit = 0, blow = 0;
		
		bool done[10] = {};
		REP(i, 4) done[r[i]-'0'] = true;
		REP(i, 4) {
			if (r[i] == a[i]) hit++;
			else if (done[a[i]-'0']) blow++;
		}
		
		printf("%d %d\n", hit, blow);
	}
	return 0;
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

int N;
bool A[1000000001];

int main(){
    cin >> N;
    REP(i,N)
    {
      ll a;
      cin >> a;
      if(A[a]){cout << "NO" << endl;return 0;}
      A[a]=true;

    }
    cout << "YES" << endl;
    return 0;
}

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

using namespace std;
#define int            long long
#define f(i,n)        for(int i=0;i<(n);++i)
#define fa(i,a,n)     for(int i=a;i<=(n);++i)
#define fd(i,a,n)     for(int i=a;i>=(n);--i)
#define tc 			  int t;cin>>t;f(testcase,t)
#define pii             pair<int,int>
void c_p_c() {

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

}

int32_t main() {

	c_p_c();

	int a, b;
	char c;
	cin >> a >> c >> b;
	if (c == '+')
		cout << a + b;
	else
		cout << a - b;


	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  OI Powtórczenie
//
//  Created by Jędrzej Dudzicz on 24/01/2019.
//  Copyright © 2019 Jędrzej Dudzicz. All rights reserved.
//

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <sys/time.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
using namespace std;
const int MXN=3e4+5;
typedef long long LL;
vector<pair<long long,pair<int,int> > >graph;
int miliseconds(){
    struct timeval tp;
    gettimeofday(&tp,NULL);
    return int(tp.tv_sec*1000+tp.tv_usec/1000);
}
int t,n,m;
long long p[MXN];
double a,b;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    scanf("%lf%lf",&a,&b);
    printf("%lf",a/b);
    return 0;
}


Measured memory_bytes: 256
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  int ans=0;
  string S(4,0);
  FOR(i,0,4){
    cin>>S[i];
    if(S[i] == '+'){
      ans++;
    }else if(S[i] =='-'){
      ans--;
    }else{
      cerr<<"something wrong just happened."<<endl;
      return -1;
    }
  }
  cout<<ans<<endl;
  
  
  
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n;
    long long sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        long long int a;
        cin>>a;
        sum+=a;
    }
    cout<<sum/n<<endl;
    return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <string.h>

int main() {
	int n;
	double val, ans = 0.0;
	char kode[5];
	scanf("%d", &n);
	while (n--) {
		scanf("%lf %s", &val, kode);
		if (strcmp(kode, "BTC") == 0)
			val *= 380000.0;
		ans += val;
	}
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define sync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,n) for(int i=0; i<int(n); ++i)
#define repp(i,a,n) for(int i=a; i<int(n); ++i)
#define sz(x) (x).size()
#define pq priority_queue
#define pb push_back
#define mp make_pair

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T> &input){for (auto const& i: input) {os << i << " ";}return os;}
template<class T1,class T2> std::ostream& operator<<(std::ostream& os, const std::pair<T1,T2> &input){os << "(" << input.first << ", " << input.second << ')';return os;}

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<pi> vp;
typedef vector<ll> vl;
typedef vector<vi> vvi;


const int maxn = 1e6;

void pre(){
}


int vis[maxn + 1];
int cnt[maxn + 1];

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

	vp a(0);
	rep(i,n){
		int x;
		cin >> x;
		a.pb(mp(x, i));
		cnt[x]++;
	}

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

	int ans = 0;

	for(auto p: a){
		int val = p.first;
		int i = p.second;
		if(cnt[val] == 1 && vis[val] == 0){
			ans++;
		}
		if(vis[val] == 0){
			for(int j=val; j<=maxn; j+=val) vis[j] = 1;
		}
		
	}

	cout << ans;
}


int main() {
    sync;
    int cas = 1;
    // cin >> cas;
    pre();
    rep(ca, cas) solve();
    return 0;
}

Measured memory_bytes: 12540
var
  s:string;
  i,l,sc,sf:longint; 
begin
  readln(s);
  l:=length(s);
  sc:=maxlongint; 
  for i:=1 to l do 
    if s[i]='F'then 
      sf:=i; 
  for i:=l downto 1 do 
    if s[i]='C'then 
      sc:=i;
  if sc<sf then 
    writeln('Yes') else 
    writeln('No'); 
end.

Measured memory_bytes: 128
#include<stdlib.h>
#include<stdio.h>
#include<string.h>


int main(){
  int n,i,a,j,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a==2) count+=1;
    if(a%2!=0){
      j=3;
      while(1){
        if(a%j==0) break;
        if((j*j)>a) break;
        j+=2;
      }
      if((j*j)>a) count+=1;
    }
  }
  printf("%d\n",count);
  return 0;
}
   
  

Measured memory_bytes: 596
n = int(input())
s = str(input())
r = [i for i in range(n) if s[i] == "("]
l = [i for i in range(n) if s[i] == ")"]
if r == []: print(n*"(" + s)
elif l == []: print(s + n*")")
elif min(r) > max(l):
    print(len(l)*"(" + s + len(r)*")")
else:
    cnt = 0
    for i in reversed(range(len(r))):
        if r[i] < max(l):
            cnt += 1
            l.pop(-1)
        if l == []: break
    print((len(l)) * "(" + s + (len(r) - cnt) * ")")

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

ll n;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	ll k=0;
	if(n%2){
		cout << 0 << endl;
		return 0;
	}
	ll p=10;
	while(p<=n&&p>0){
		k+=n/p;
		p*=5;
	}
	cout << k << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;
int gcd(int a,int b){
    if(a < b){
        int c = a;
        a = b;
        b = c;
    }
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x;
        x = x * x;
        n = n >> 1;
    }
    return ans;
}


/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;
	if(n%2 == 1){
		cout << 0 << endl;
		return 0;
	}
	// int ans[100] ={0};
	// ans[0] = ans[1] = 1;
	// rep(i,60)ans[i+2] = (i+2)*ans[i];
	// rep(i,n)cout << i << " " << ans[i] << endl;

	int cnt = 0;
	for(int b = 1;b < 1000;b++){
		int m = n;
		rep(i,b)m /= 5;
		cnt += m/2;
	}
	cout << cnt << endl;
	   
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc148.contest.atcoder.jp/tasks/abc148_b

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

void merge_sort(int *t1, int left, int right){    //アドレスが渡される
    if(left==right){
        ;
    }
    else{
        int n2=(right-left+1)/2;
        int n3=right-left+1-n2;
        int i=0,j=0,k=0;

        merge_sort(t1,left,left+n2-1);
        merge_sort(t1,left+n2,right);

        int t2[n2];
        int t3[n3];
        for(i=0;i<n2;i++){
          t2[i]=t1[left+i];
        }
        for(i=0;i<n3;i++){
          t3[i]=t1[left+n2+i];
        }

        for(i=0;i<n2+n3;i++){
            if(k==n3 || (j<n2 && t2[j]<t3[k])){
                t1[left+i]=t2[j];
                j++;
            }
            else{
                t1[left+i]=t3[k];
                k++;
            }
        }
    }
}

int main(){
  char buf[1024];
  int N;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d", &N);

  int *A=(int *)malloc(sizeof(int)*N);
  rep(i,N){
    scanf("%d",&A[i]);
  }

  merge_sort(A, 0, N-1);

  int sum=0;
  rep(i,N){
    if(A[i]<0){
      sum=sum-A[i];
    }
    else{
      sum=sum+A[i];
    }
  }

  if(A[0]<0 && A[N-1]>=0){
    printf("%d\n", sum);
  }
  else if(A[0]<0 && A[N-1]<0){
    printf("%d\n", sum+A[N-1]*2);
  }
  else if(A[0]>=0){
    printf("%d\n", sum-A[0]*2);
  }

  if(A[0]<0 && A[N-1]>=0){
    int bound;
    rep(i,N){
      if(A[i]>=0){
        bound=i;
        break;
      }
    }
    int temp=A[bound-1];
    srep(i, bound, N-1){
      printf("%d %d\n", temp, A[i]);
      temp=temp-A[i];
    }
    printf("%d %d\n", A[N-1], temp);
    temp=A[N-1]-temp;
    rep(i, bound-1){
      printf("%d %d\n", temp, A[i]);
      temp=temp-A[i];
    }
  }
  else if(A[0]<0 && A[N-1]<0){
    int temp=A[N-1];
    rrep(i,N-1){
      printf("%d %d\n", temp, A[i]);
      temp=temp-A[i];
    }
  }
  else if(A[0]>=0){
    int temp=A[0];
    srep(i,1,N-1){
      printf("%d %d\n", temp, A[i]);
      temp=temp-A[i];
    }
    printf("%d %d\n", A[N-1], temp);
  }

  return 0;


}


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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
#define mo  (ll)(1e9+7)

int main(void) {
    ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i];
    map<ll, ll> freq;
    ll ret = 1;
    rep(i, n) {
        (ret *= (a[i] == 0 ? 3 : 0) + freq[a[i]-1] - freq[a[i]]) %= mo;
        freq[a[i]]++;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <bitset>
#include <functional>
#include <tuple>
#include <complex>
#include <chrono>
#include <climits>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// default_random_engine generator;
// mt19937 rnd(1);

const int MAXN = 2222;

ll dp[MAXN];
ll cnt[MAXN];
ll len[MAXN];
string s;
vector<int> g[MAXN];

void dfs(int v, int p = -1) {
    cnt[v] = (s[v] == '1');
    len[v] = 0;

    int id = -1;
    ll sum = 0;

    for (int u : g[v]) {
        if (u == p) {
            continue;
        }
        dfs(u, v);
        cnt[v] += cnt[u];
        len[v] += len[u] + cnt[u];

        if (id == -1 || len[u] + cnt[u] - 2 * dp[u] > len[id] + cnt[id] - 2 * dp[id]) {
            id = u;
        }

        sum += len[u] + cnt[u];
    }

    if (id == -1) {
        dp[v] = 0;
        return;
    }

    sum -= len[id] + cnt[id];

    if (sum < len[id] + cnt[id] - 2 * dp[id]) {
        dp[v] = dp[id] + sum;
    } else {
        sum += len[id] + cnt[id];
        dp[v] = sum / 2;
    }
}

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int n;
    cin >> n;
    cin >> s;

    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    ll res = n * n;
    for (int i = 0; i < n; ++i) {
        dfs(i);
        // cout << dp[i] << " " << len[i] << endl;
        if (2 * dp[i] == len[i]) {
            res = min(res, dp[i]);
        }
    }
    if (res == n * n) {
        res = -1;
    }
    cout << res << endl;
}   




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
     
     
#define ll long long
#define sd(x) scanf("%d",&x)
#define sld(x) scanf("%lld",&x)
#define pld(x) printf("%lld\n",x)
#define pd(x) printf("%d\n",x)
#define forn(i,a,n) for(int i = a; i < n ; i++)
const int MOD = 1e9+7, N = 1e7 + 10;

int main() {
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    forn(i,0,n) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "main.cpp"

const std::string YES = "Yes";
const std::string NO = "No";
bool solve(string N) {
  ll c = 0;
  REP(i, N.length()) { c += N[i] - '0'; }
  return c % 9 == 0;
}

// generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)
int main() {
  string N;
  std::cin >> N;
  auto ans = solve(N);
  std::cout << (ans ? YES : NO) << std::endl;
  return 0;
}


Measured memory_bytes: 3828
# Aizu Problem ITP_1_8_D: Ring
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def ring(string, pattern):
    string = string + string
    return string.find(pattern) >= 0

  
string = input().strip()
pattern = input().strip()
print("Yes" if ring(string, pattern) else "No")

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

int n;
ll a[110];
int main(int argc, char const *argv[])
{
	cin>>n;
	ll sum = 0;
	rep(i,0,n)
	{
		cin>>a[i];
		sum += a[i];
	}
	sort(a,a+n);
	sum -= a[n-1];
	if(a[n-1] < sum)
	{
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;
	return 0;

}

Measured memory_bytes: 256
# coding: utf-8
S = sorted(input())
A = ['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']
for i in A:
    if i not in S:
        print(i)
        exit()
else:
    print('None')

Measured memory_bytes: 4408
import math

n = int(input())

x = n / float(1.08)
chk = x - int(x)
if chk > 0:
    tmp = int(x) + 1
    if math.floor(tmp * 1.08) == n:
        print(tmp)
    else:
        print(':(')
else:
    print(int(x))

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

using namespace std;
int main()
{
	long long  n,m;
	cin>>n>>m;

	long long sum=0;

	for(int i=0;i<m;i++)
	{
		long long x;
		cin>>x;
		sum=sum+x;
	}

	if(sum>n)
		cout<<-1<<endl;
	else
		cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Template
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            int x = int.Parse(Console.ReadLine());
            int m=1;
            int a;
            for (int i = 2; i < 33; i++)
            {
                a = i*i;
                while (a <= x)
                {
                    if (m < a) { m = a; }
                    a *= i;
                }
            }

            //出力
            Console.WriteLine(m);
        }
    }
}


Measured memory_bytes: 13140
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

T = int(input())


for _ in range(T):
    N, A, B, C, D = map(int, input().split())
    memo = {}


    def f(n):
        if n == 0:
            return 0
        if n == 1:
            return D
        if n in memo.keys():
            return memo[n]

        ret = 1 << 100
        ret = min(ret, f(n // 2) + (n - n // 2 * 2) * D + A, f(n // 2) + (n - n // 2) * D)
        ret = min(ret, f(n // 3) + (n - n // 3 * 3) * D + B, f(n // 3) + (n - n // 3) * D)
        ret = min(ret, f(n // 5) + (n - n // 5 * 5) * D + C, f(n // 5) + (n - n // 5) * D)
        ret = min(ret, f((n + 1) // 2) + ((n + 1) // 2 * 2 - n) * D + A, f((n + 1) // 2) + (n - (n + 1) // 2) * D)
        ret = min(ret, f((n + 2) // 3) + ((n + 2) // 3 * 3 - n) * D + B, f((n + 2) // 3) + (n - (n + 2) // 3) * D)
        ret = min(ret, f((n + 4) // 5) + ((n + 4) // 5 * 5 - n) * D + C, f((n + 4) // 5) + (n - (n + 4) // 5) * D)
        memo[n] = ret
        return ret

    print(f(N))

Measured memory_bytes: 11732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_N = 1e5 + 50, INF = 1e15, MOD = 1e9 + 7;
ll N;
vector<ll> adj[max_N];
ll DP[max_N][2];
// 0 for white and 1 for black

void dfs(ll curr, ll par)
{
    ll w_prdt = 1, bl_prdt = 1;
    for (auto &neigh : adj[curr])
    {
        if (neigh == par)
            continue;
        dfs(neigh, curr);
        w_prdt *= (DP[neigh][0] + DP[neigh][1]);
        bl_prdt *= DP[neigh][0];
        w_prdt %= MOD;
        bl_prdt %= MOD;
    }
    DP[curr][0] = (w_prdt), DP[curr][1] = bl_prdt;
}

int main()
{
    cin >> N;
    ll x, y;
    for (int i = 1; i < N; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    dfs(1, -1);
    cout << (DP[1][0] + DP[1][1]) % MOD << "\n";
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	if (n%1000 == 000 || n%1000 == 111 || n%1000 == 222 || n%1000 == 333 || n%1000 == 444 || n%1000 == 555 || n%1000 == 666 || n%1000 == 777 || n%1000 == 888 || n%1000 == 999){
		cout << "Yes" << endl;
    }
	else if (n/10 == 000 || n/10 == 111 || n/10 == 222 || n/10 == 333 || n/10 == 444 || n/10 == 555 || n/10 == 666 ||n/10 == 777 || n/10 == 888 || n/10 == 999){
		cout << "Yes" << endl;
    }
	else{
		cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import collections

N,M = (int(x) for x in input().split())
fee = []
com = []
ans = []

for i in range(N):
    a = int(input())
    fee.append(a)
    
for i in range(M):
    b = int(input())
    com.append(b)
    
for i in range(M):
    k = 0
    while(com[i] < fee[k]):
        k=k+1
        
    ans.append(k)
    
c = collections.Counter(ans)
    
print(c.most_common()[0][0]+1)


Measured memory_bytes: 6060
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int A, B;
string S;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> A >> B;
  cin >> S;

  if (A + B + 1 != S.length()) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < A; i++) {
    if (!('0' <= S[i] && S[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (S[A] != '-') {
    cout << "No" << endl;
    return 0;
  }
  for (int i = A + 1; i < A + 1 + B; i++) {
    if (!('0' <= S[i] && S[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int param1 = sc.nextInt();
		int param2 = sc.nextInt();
		
		String ret = "";
		if(param1 < param2) {
			ret = "a < b";
		}else if(param1 > param2) {
			ret = "a > b";
		}else {
			ret = "a == b";
		}
		System.out.println(ret);
		sc.close();

	}

}


Measured memory_bytes: 26140
#include <iostream>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	
	if(a+b == c || a+c == b || b+c == a)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<long long> a(n),b(n);

    int cnt=0;
    long long sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<0){
            cnt++;
            b[i]=-a[i];
        }
        else b[i]=a[i];
    }
    for(int i=0;i<n;i++){
        sum+=b[i];
    }
    sort(b.begin(),b.end());
    if(cnt%2==0)cout<<sum<<endl;
    else cout<<sum-b[0]*2<<endl;
}

   


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int n,i,j,r,p,c,sum;
	string s;
	vector<int> v,w,x;
	while(1){
		cin>>n>>r;
		if(n==0&&r==0)break;
		
		v.clear();
		w.clear();
		x.clear();
		rep(i,n) v.push_back(i+1);
		rep(j,r){
			
			cin>>p>>c;
			for(i=0;i<n;i++){
				if(i>=n-(p+c-1)&&i<n-(p+c-1)+c) x.push_back(v[i]);
				else w.push_back(v[i]);
			}
			rep(i,x.size()) w.push_back(x[i]);
			v=w;
		//	cout<<v[v.size()-1]<<endl;
			w.clear();
			x.clear();
		//	cout<<"aaaa"<<v.size()<<endl;
		//	rep(i,v.size())cout<<v[i]<<" ";
		//	cout<<endl;
		}
		cout<<v[v.size()-1]<<endl;
	}/*
	5 2
	3 1
	3 1
	v1 2 4 5 3
	if(i>=2&&i<3)
	w1 2 4 5 3
	x3
	*/
	
	
	
//////////////////////////////////////////////////////
return 0;}












Measured memory_bytes: 3060
import java.util.*;
 
public class Main{
	public static boolean[][] map = new boolean[100][100]; //[red][blue]
	public static int[] blues = new int[100];
	public static int[] reds = new int[100];
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[N];
		int[] d = new int[N];
		for(int i=0;i<N;++i){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		for(int i=0;i<N;++i){
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		for(int i=0;i<N;++i){
			for(int j=0;j<N;++j){
				if(a[i]<c[j]&&b[i]<d[j]){
					map[i][j] = true;
					blues[i]++;
					reds[j]++;
				}
			}
		}
		
		int ans = 0;
		while(!noPair(N)){
			int red = biggest(N);
			int blue = -1;
			int temp = Integer.MAX_VALUE;
			for(int i=0;i<N;++i){
				if(map[red][i]&&reds[i]<temp){
					blue = i;
					temp = reds[i];
				}
			}
			
			delete(red,blue,N);
			ans++;
		}
		
		System.out.println(ans);
		return;
	}
	
	public static boolean noPair(int n){
		for(int i=0;i<n;++i){
			if(reds[i]!=0) return false;
 		}
		return true;
	}
	
	public static int biggest(int n){
		int max = Integer.MAX_VALUE;
		int ret = -1;
		for(int i=0;i<n;++i){
			if(blues[i]!=0&&blues[i]<max){
				max = blues[i];
				ret = i;
			}
		}
		return ret;
	}
	
	public static void delete(int r,int b,int n){
		for(int i=0;i<n;i++){
			if(map[r][i]){
				map[r][i] = false;
				blues[r]--;
				reds[i]--;
			}
			if(map[i][b]){
				map[i][b] = false;
				blues[i]--;
				reds[b]--;
			}
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 100000000;
vector<ll> dx = {1, 0, -1, 0};
vector<ll> dy = {0, 1, 0, -1};

int main() {
  IN(ll, H);
  IN(ll ,W);
  AIN(string, maze, H);
  ll ans = 0;
  vector<vector<ll>> d(H,vector<ll>(W,INF));
  queue<P> que;
  REP(i,H){
    REP(j, W){
      if(maze.at(i).at(j) == '#')
        continue;
      vector<vector<ll>> d2 = d;
      que.push(P(i,j));
      d2.at(i).at(j) = 0;
      ll count = 0;
      while(que.size()){
        P p = que.front();
        que.pop();
        REP(k,4){
          ll ny = p.first + dy.at(k);
          ll nx = p.second + dx.at(k);
          if(0 <= ny && ny < H && 0 <= nx && nx < W && maze.at(ny).at(nx) != '#' && d2.at(ny).at(nx) == INF){
            que.push(P(ny,nx));
            d2.at(ny).at(nx) = d2.at(p.first).at(p.second) + 1;
            count = d2.at(ny).at(nx);
          }
        }
      }
      chmax(ans,count);
    }
  }
  OUT(ans);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+7;
const int M=2e5+7;
inline int read(){
	int x=0; bool f=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
	return f?-x:x;
}

int n,m;
int u[M],v[M],ans[M];
int head[N],to[M],nx[M],ec=1;
inline void add(int a,int b){
	nx[++ec]=head[a]; head[a]=ec; to[ec]=b;
}

int q[M],h,t;
vector<int>vec[N];
vector<int>pre[N];
inline void solve(int x){
	int hst=x;
	for(int i=1;i<=n;++i) pre[i].clear();
	h=1; t=0; pre[x].resize(2);
	for(int i=head[x];i;i=nx[i]){
		int v=to[i]; q[++t]=v;
		pre[v].push_back(i);
	}
	while(h<=t){
		x=q[h++];
		if(pre[x].size()==2){
			for(int i=head[x];i;i=nx[i]){
				int v=to[i];
				if(pre[v].size()==2) continue;
				if(pre[v].size()==1) pre[v].push_back(pre[x][pre[x][0]==pre[v][0]]);
				else pre[v]=pre[x]; q[++t]=v;
			}
		}
		else{
			for(int i=head[x];i;i=nx[i]){
				int v=to[i];
				if(pre[v].size()==2) continue;
				if(pre[v].size()==1&&pre[v][0]==pre[x][0]) continue;
				pre[v].push_back(pre[x][0]); q[++t]=v;
			}
		}
	}
	for(int i=0;i<vec[hst].size();++i){
		int id=vec[hst][i],x=u[id],y=v[id];
		if(hst==y&&pre[x].size()>0) ans[id]^=1;
		if(hst==x&&pre[y].size()>1) ans[id]^=1;
	}
}

int main(){
	n=read(); m=read();
	for(int i=1;i<=m;++i){
		u[i]=read(); v[i]=read(); add(u[i],v[i]);
		vec[u[i]].push_back(i); vec[v[i]].push_back(i);
	}
	for(int i=1;i<=n;++i) if(vec[i].size()) solve(i);
	for(int i=1;i<=m;++i) puts(ans[i]?"diff":"same");
	return 0;
}

Measured memory_bytes: 10320
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

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

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

LL solve(const int N, const string &S, const vector<int> &a, const vector<int> &b, const vector<int> &c)
{
	LL ret = 0;
	FOR(j, 1, N - 1){
		if(b[j - 1] == b[j]) continue;
		ret += a[j - 1] * (c[N - 1] - c[j]);
	}
	return ret;
}

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

	string S;
	cin >> S;

	vector<int> r(N, 0), g(N, 0), b(N, 0);
	if(S[0] == 'R') r[0] = 1;
	if(S[0] == 'G') g[0] = 1;
	if(S[0] == 'B') b[0] = 1;

	FOR(i, 1, N){
		r[i] = r[i - 1] + (S[i] == 'R');
		g[i] = g[i - 1] + (S[i] == 'G');
		b[i] = b[i - 1] + (S[i] == 'B');
	}

	LL ret = 0;
	// cerr << "RGB" << endl;
	ret += solve(N, S, r, g, b);
	// cerr << "RBG" << endl;
	ret += solve(N, S, r, b, g);
	// cerr << "GRB" << endl;
	ret += solve(N, S, g, r, b);
	// cerr << "GBR" << endl;
	ret += solve(N, S, g, b, r);
	// cerr << "BRG" << endl;
	ret += solve(N, S, b, r, g);
	// cerr << "BGR" << endl;
	ret += solve(N, S, b, g, r);

	FOR(j, 1, N - 1){
		FOR(x, 1, N){
			int i = j - x, k = j + x;
			if(i < 0 || N - 1 < k) break;
			if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ret--;
		}
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3672
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int sum;
    
    if(n <= k) {
      sum = n * x;
    } else {
      n = n - k;
      sum = k * x + n * y;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<unordered_set>
#include<iterator>
#include<algorithm>

int main(){
    unsigned long n;
    std::cin >> n;

    std::unordered_set<unsigned long> S;
    std::copy_n(std::istream_iterator<unsigned long>(std::cin), n, inserter(S, std::end(S)));

    unsigned long q;
    std::cin >> q;

    unsigned long ans{0};
    for(unsigned long i{0}, t; i < q; ++i){
        std::cin >> t;
        ans += S.count(t);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3124
n, k = map(int, input().split())
ans = 0

if k == 0:
    ans = n ** 2
else:
    for b in range(k + 1, n + 1):
        q, r = n // b, n % b
        ans += (b - k) * q + max(r + 1 - k, 0)
    
print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int x, t;

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

    void run() {
        FastReader sc = new FastReader();
        x = sc.nextInt();
        t = sc.nextInt();
        solve();
    }

    void solve() {
        int ans = 0;
        if (x > t) {
            ans = x - t;
        }
        System.out.println(ans);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21076
use std::io;

fn main() {
    let _ = get_line();
    let mut cards: Vec<i32> = get_line().split_whitespace().map(|x| {x.parse().unwrap()}).collect();
    cards.sort();
    cards.reverse();
    let mut alice = 0;
    let mut bob = 0;
    for (i,e) in cards.into_iter().enumerate() {
        if i % 2 == 0 {
            alice += e;
        } else {
            bob += e;
        }
    }
    println!("{}", alice - bob);
    

}

fn get_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    return buf;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
ll INF = 1000000000000000001; //10^18+1
ll MOD = 1000000007; //10^9+7
//cout << fixed << setprecision(15); (小数点以下表示)


struct UnionFind {
  vector<int> par;
  vector<int> siz;
  UnionFind(int N):par(N),siz(N){
    for(int i=0;i<N;i++)par[i]=i;
    for(int i=0;i<N;i++)siz[i]=1;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if (rx==ry)return;
    par[rx]=ry;
    siz[ry]+=siz[rx];
  }
  bool same(int x,int y){
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
  }
  int size(int x){
    return siz[root(x)];
  }
};

int main() {
  ll N,M,K,p,q;
  cin >> N >> M >> K;
  UnionFind F(N);
  ll FR[N]={},B[N]={};
  for(int i=0;i<M;i++){
    cin >> p >> q;
    F.unite(p-1,q-1);
    FR[p-1]++;
    FR[q-1]++;
  }
  for(int i=0;i<K;i++){
    cin >> p >> q;
    if(F.root(p-1)==F.root(q-1)){
      B[p-1]++;
      B[q-1]++;
    }
  }
  for(int i=0;i<N;i++){
    cout << F.size(i)-FR[i]-B[i]-1;
    if(i!=N-1)cout << ' ';
  }
  cout << endl;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD{998244353};
    unsigned long N;
    cin >> N;
    constexpr unsigned long maxA{1000000};
    unsigned long tmp{0};
    vector<unsigned long> a(maxA + 1);
    for(unsigned long i{0}, A; i < N; ++i){
        cin >> A;
        (a[A] += A) %= MOD;
        (tmp += A) %= MOD;
    }
    vector<unsigned long> modinv(maxA + 1), coef(maxA + 1);
    modinv[1] = (MOD + 1) / 2;
    for(unsigned long i{2}; i <= maxA; ++i)modinv[i] = modinv[MOD % i] * (MOD - MOD / i) % MOD;
    copy(begin(modinv), end(modinv), begin(coef));
    vector<unsigned long> sieve(maxA + 1, 1);
    for(unsigned long i{2}; i <= maxA; ++i)if(sieve[i])for(unsigned long j{maxA / i + 1}; --j;){
        sieve[j * i] = 0;
        (coef[j * i] += MOD - coef[j]) %= MOD;
        (a[j] += a[j * i]) %= MOD;
    }
    for(unsigned long i{0}; i <= maxA; ++i)(a[i] *= a[i] % MOD) %= MOD;
    cout << inner_product(begin(coef), end(coef), begin(a), 0 - (tmp + (tmp & 1) * MOD) / 2, plus<>(), [](auto i, auto j){return i * j % MOD;}) % MOD << endl;
    return 0;
}

Measured memory_bytes: 34388