akhauriyash/Code-Regression huggingface dataset:
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
lint f(lint a){
  lint res=1;
  a+=7;
  REP(i,7) res*=a-i,res/=i+1;
  return res;
}

int ar[1000];
int main(){
  lint K;cin>>K;

  for(int i=600;i>=0;--i){
    if(i>=590) dump(K),dump(f(i));
    ar[i]=K/f(i);
    K-=ar[i]*f(i);
  }
  string res;
  REP(i,601){
    res+="FESTIVA";
    res+=string(ar[i],'L');
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
        a[i]--;
    }
    int ans = 0;
    rep(i, 0, n - 1){
        if(a[i] == i){
            ans++;
            swap(a[i], a[i + 1]);
        }
    }
    if(a[n - 1] == n - 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());
    int Q = Integer.parseInt(sc.next());
    int[] ans = new int[N];
    for(int i=0;i<Q;i++){
      ans[Integer.parseInt(sc.next())-1]++;
    }
    StringBuilder sb = new StringBuilder();
   
    for(int i=0;i<N;i++){
      if((K-(Q-ans[i]))>0){
        sb.append("Yes\n");
      }else{
        sb.append("No\n");
      }
    }
    System.out.print(sb.toString());
    System.out.flush();
  }
}

Measured memory_bytes: 49244
#include <iostream>
#include <string>
using namespace std;
#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
typedef long long ll;

void solve(){
    string s;
    cin >> s;
    if(s == "SUN")
        cout << 7 << '\n';
    else if(s == "MON")
        cout << 6 << '\n';
    else if(s == "TUE")
        cout << 5 << '\n';
    else if(s == "WED")
        cout << 4 << '\n';
    else if(s == "THU")
        cout << 3 << '\n';
    else if(s == "FRI")
        cout << 2 << '\n';
    else if(s == "SAT")
        cout << 1 << '\n';
    else{}
}

int main(){
    solve();
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N;
  cin >> N;
  int d11, d21, d12, d22, d31, d32;
  cin >> d11 >> d12 >> d21 >> d22;
  for(int i = 0; i < N-2; i++){  
    cin >> d31 >> d32;
    if(d11 == d12 && d21 == d22 && d31 == d32){  
      cout << "Yes" <<endl; 
      return 0;
    }
    d11 = d21;
    d12 = d22;
    d21 = d31;
    d22 = d32;
  }
  cout << "No" <<endl;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
typedef long long LL;
const int N = 1e7+10;
LL sum[N];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j+=i){
			sum[j]+=1;
		}
	}
	LL ans=0;
	for(int i=1;i<=n;i++){
		ans+=i*sum[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 81732
N,M=map(int,input().split())
x=[]
y=0
for i in range(N):
    a,b=map(int,input().split())
    x+=[[a,b]]
x=sorted(x)
for i in range(N):
  if x[i][1]<=M:
    y+=x[i][0]*x[i][1]
    M-=x[i][1]
  else:
    y+=M*x[i][0]
    break
print(y)

Measured memory_bytes: 20764
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c;
    scanf("%i",&a);
    scanf("%i",&b);
    scanf("%i",&c);
    if(a<b && b<c)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2120
using System;

namespace ABC144c_2 {
    class Program {
        static void Main(string[] args) {
            var n = long.Parse(Console.ReadLine());

            var sqrt = (long)Math.Sqrt(n);
            for (var i = sqrt; i > 0; i--) {
                if (n % i == 0) {
                    Console.WriteLine(i + n / i - 2);
                    return;
                }
            }
        }
    }
}

Measured memory_bytes: 13140
#!/usr/bin/env python3
import sys
import fractions
import math


def solve(N: int, A: "List[int]"):
    L = []
    last = A[0]
    for i in range(N):
        last = fractions.gcd(last, A[i])
        L.append(last)
    last = A[-1]
    R = []
    for i in range(1, N+1):
        last = fractions.gcd(last, A[-i])
        R.append(last)
    R.reverse()
    if N == 2:
        print(max(A[0], A[1]))
        return
    maxGCD = max(L[-2], R[1])
    for i in range(1, N-1):
        maxGCD = max(fractions.gcd(L[i-1], R[i+1]), maxGCD)
    print(maxGCD)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 19036
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;
//using namespace __gnu_pbds;

mt19937_64 gen(time(0));

//typedef tree<
//pair <int, int>,
//null_type,
//less<pair <int, int>>,
//rb_tree_tag,
//tree_order_statistics_node_update>
//ordered_set;

//const int mod = 1e9 + 7;
//const int inf = 2e9 + 6555;
const int maxn = 3e5 + 23;

int cnt1[maxn];
int cnt2[maxn];


signed main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif
    int h, w, m;
    cin >> h >> w >> m;
    vector <int> vc1[h];
    vector <int> vc2[w];

    for(int i = 0; i < m; ++i)
    {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        vc1[x].pb(y);
        vc2[y].pb(x);
        cnt1[x]++;
        cnt2[y]++;
    }

    multiset <int> st1;
    multiset <int> st2;

    for(int i = 0; i < h; ++i)
        st1.insert(cnt1[i]);

    for(int i = 0; i < w; ++i)
        st2.insert(cnt2[i]);

    int ans = 0;
    for(int i = 0; i < h; ++i)
    {
        for(int j : vc1[i])
        {
            st2.erase(st2.find(cnt2[j]));
            cnt2[j] -= 1;
            st2.insert(cnt2[j]);
        }
        ans = max(ans, int(vc1[i].size()) + (*(--st2.end())));
        for(int j : vc1[i])
        {
            st2.erase(st2.find(cnt2[j]));
            cnt2[j] += 1;
            st2.insert(cnt2[j]);
        }
    }

    for(int i = 0; i < w; ++i)
    {
        for(int j : vc2[i])
        {
            st1.erase(st1.find(cnt1[j]));
            cnt1[j] -= 1;
            st1.insert(cnt1[j]);
        }
        ans = max(ans, int(vc2[i].size()) + (*(--st1.end())));
        for(int j : vc2[i])
        {
            st1.erase(st1.find(cnt1[j]));
            cnt1[j] += 1;
            st1.insert(cnt1[j]);
        }
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 66896
using System;
using System.Linq;
class c
{
    static void Main()
    {
        var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        if (ab[1] % ab[0] == 0) Console.WriteLine(ab.Sum());
        else Console.WriteLine(ab[1] - ab[0]);
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int X = scanner.nextInt();

    for (int i = 1; i <= X; i++) {
      int d = i * (i + 1) / 2;
      if (d >= X) {
        System.out.println(i);
        return;
      }
    }
  }
}


Measured memory_bytes: 22996
# coding: utf-8
from math import gcd


def solve(*args: str) -> str:
    k = int(args[0])

    memo = [[0]*(k+1) for _ in range(k+1)]

    for i in range(1, k+1):
        for j in range(i, k+1):
            m = gcd(i, j)
            memo[i][j] = m
            memo[j][i] = m

    ret = 0
    for a in range(1, k+1):
        for b in range(1, k+1):
            ab = memo[a][b]
            for c in range(1, k+1):
                ret += memo[ab][c]

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 9444
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#define REP(i, n) for(int i = 0; i < n; 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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  int X, A;
  cin >> X >> A;
  if(X < A){
    cout << 0;
  }else{
    cout << 10;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>

using namespace std;

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

#define X real()
#define Y imag()

typedef complex<double> P;

const double EPS = 1e-8;
const double PI = acos(-1);

int sig(double r) {return (r < -EPS) ? -1 : (r > EPS) ? 1: 0;}
bool eq(double a, double b) {return abs(a - b) < EPS;}

namespace std{
  bool operator<(const P &a, const P &b){
    double arg1 = arg(a), arg2 = arg(b);
    if (sig(arg1 - PI) >= 0) arg1 = -PI;
    if (sig(arg2 - PI) >= 0) arg2 = -PI;
    if(!eq(arg1, arg2)) return arg1 < arg2;
    return norm(a) < norm(b);
  }
}

P plr(double theta) {return polar(1., theta);}

int main() {
  int n;
  for (;;) {
    cin >> n;
    if (n == 0) break;
    vector<P> v;
    rep (i, n) {
      int x, y;
      cin >> x >> y;
      v.push_back(P(x, y));
    }
    rep (i, n) {
      v[i] = v[i] * plr(PI / 2);
      v[i].Y *= -1;
    }
    double res = 0;
    rep (i, n) {
      sort(v.begin(), v.end());
      res += abs(v[0]);
      vector<P> vv;
      rep (j, v.size() - 1) {
	vv.push_back((v[j + 1] - v[0]) * plr(-PI - arg(v[0])));
      }
      v = vv;
    }
    printf("%.1lf\n", res);
  }
}

Measured memory_bytes: 996
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int gcd(int m, int n) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

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

    int n;
    cin >> n;

    int m = (int)1e6;
    vector<char> b(m + 1, 0);
    int r = 0, x = 0;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        x = gcd(x, a);

        b[a]++;
    }

    if (x != 1) r = 2;

    if (r == 0) {
        for (int i = 2; i <= m; i++) {
            int t = 0;
            for (int j = i; j <= m; j += i) {
                t += b[j];
            }
            if (t > 1) r = 1;
        }
    }

    const char *c[3] = { "pairwise coprime", "setwise coprime", "not coprime" };
    cout << c[r] << endl;

    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int m, n;
bool check(vector<int> v,int mid){
  int h = 1;
  int w = 0;
  rep(i,n){
    if(v[i] > mid){
      return false;
    }
    if(w + v[i] <= mid){
      w += v[i];
    }
    else{
      w = v[i];
      ++h;
    }
  }
  if(h > m){
    return false;
  }
  return true;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(cin >> m >> n&&m&&n){
    vary(int,v,n,0);
    rep(i,n){
      cin >> v[i];
    }
    int lb = 0,ub = 1500000;
    while(1){
      int mid = (lb+ub)/2;
      if(mid == ub) break;
      if(check(v,mid)){
        ub = mid;
      }
      else{
        lb = mid+1;
      }
    }
    cout << ub << endl;
  }
  return 0;
}

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

typedef long long ll;

unordered_map<ll,char> m;
string z;
string o;
ll n;
const ll mod = 1000000007;
ll z_siz;
ll o_siz;

ll powl(ll x, ll r, ll mod = mod){
	ll ret = 1;
	for(;r != 0;r >>= 1){
		if(r&1 != 0) ret *= x, ret %= mod;
		x *= x,x %= mod;
	}
	return ret;
}

void error(){
	cout << 0 << endl;
	exit(0);
}

int main(){
	cin >> z;
	cin >> o;
	cin >> n;
	z_siz = z.size();
	o_siz = o.size();
	for(ll i = 0;i < o_siz;i++){
		m[i] = o[o_siz-i-1];
	}
	for(ll i = 0;i < z_siz;i++){
		if(m[o_siz-z_siz+i] == 0) m[o_siz-z_siz+i] = z[z_siz-i-1];
		else{
			if(m[o_siz-z_siz+i] != z[z_siz-i-1]) error();
		}

	}
	for(ll i = 0;i < z_siz;i++){
		if(m[-z_siz+i] == 0) m[-z_siz+i] = z[i];
		else{
			if(m[-z_siz+i] != z[i]) error();
		}

	}
	for(ll i = 0;i < o_siz;i++){
		if(m[n+i] == 0) m[n+i] = o[i];
		else{
			if(m[n+i] != o[i]) error();
		}
	}
	ll k = 0;
	for(auto x : m){
		ll i = x.first;
		ll ri = o_siz-z_siz-i-1;
		if(m.find(ri) != m.end()){
			if(m[i] != m[ri]) error();
		}else{
			m[ri] = m[i];
		}

	}
	for(auto x : m){
		ll i = x.first;
		if(i >= 0 && i < n) k++;
	}



	k = n-k;
	ll free_k = (k+1)/2;
	ll ans = powl(26, free_k, mod);
	cout << ans << endl;

}


Measured memory_bytes: 16872
from heapq import*
i=input
for s in[0]*int(i()):
 n,x,*y=int(i()),[]
 for _ in'_'*n:k,l,r=t=[*map(int,i().split())];x+=[t]*(l>r);y+=[[n-k,r,l]]*(l<=r)
 for x in x,y:
  x.sort();n,*h=len(x),
  while h or x:
   while[[n]]<x[-1:]:k,l,r=x.pop();heappush(h,(r-l,l,r))
   if h:s+=heappop(h)[~(n>0)]
   n-=1
 print(s)

Measured memory_bytes: 47716
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b;
    while(cin>>a>>b){
        int rs=a+b;
        if(rs<10)cout<<rs<<endl;
        else cout<<"error"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){  

int n,a,b,c,i;  

long d=0;  

b=-1000000;  

c=1000000;  

scanf("%d",&n);  

for(a=0;a<n;a++){   

scanf("%d",&i);   

if(b<i){    

b=i;   

}   

if(c>i){    

c=i;   

}   

d+=i;  

}  

printf("%d %d %ld\n",c,b,d);    

return 0;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int dig_sum(int num) {
    int res = 0;
    while(num > 0) {
        res += num % 10;
        num /= 10;
    }
    return res;
}

int main() {
    int n, a, b; cin >> n >> a >> b;
    int cnt = 0;
    rep(i, n+1) {
        int sum = dig_sum(i);
        if(a <= sum && sum <= b) cnt += i;
    }
    cout << cnt << endl;
    return 0;
}


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
    freopen ("D.in", "r", stdin);
    freopen ("D.out", "w", stdout);
#endif
}

const int N = 110;

int tot[4], pre[4][N], val[4][N];

int main() {

	File();

	int n = read(), W = read(); long long base = 0;

	For (i, 1, n) {
		int w = read(), v = read(); 
		if (!base) base = w;
		int cur = w - base;
		val[cur][++ tot[cur]] = v;
	}

	Rep (i, 4) {
		sort(val[i] + 1, val[i] + tot[i] + 1, greater<int>());
		For (j, 1, tot[i])
			pre[i][j] = pre[i][j - 1] + val[i][j];
	}

	int ans = 0;
	For (a, 0, tot[0]) For (b, 0, tot[1]) For (c, 0, tot[2]) For (d, 0, tot[3])
		if (a * base + b * (base + 1) + c * (base + 2) + d * (base + 3) <= W)
			chkmax(ans, pre[0][a] + pre[1][b] + pre[2][c] + pre[3][d]);
	printf ("%d\n", ans);

	return 0;

}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const double PI = 3.14159265358979;
struct Edge{ ll cost, to; };


void solve()
{
  ll n, u, v;
  cin >> n;
  vector< vector<Edge> > G(n, vector<Edge>());
  for(int i = 0; i < n - 1; ++i)
  {
    cin >> u >> v;
    u--; v--;
    G[u].emplace_back(Edge{1, v});
    G[v].emplace_back(Edge{1, u});
  }

  const ll INF = 1LL << 60;
  vector<ll> d1(n, INF);
  d1[0] = 0;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, 0)); // P(cost, start)
  while (!que.empty())
  {
    P p = que.top();
    que.pop();
    ll node = p.second;
    if (d1[node] < p.first) continue;
    for (const auto& edge : G[node])
    {
        if (d1[edge.to] > d1[node] + edge.cost)
        {
            d1[edge.to] = d1[node] + edge.cost;
            que.push(P(d1[edge.to], edge.to));
        }
    }
  }
  
  vector<ll> dn(n, INF);
  dn[n - 1] = 0;
  que.push(P(0, n - 1)); // P(cost, start)
  while (!que.empty())
  {
    P p = que.top();
    que.pop();
    ll node = p.second;
    if (dn[node] < p.first) continue;
    for (const auto& edge : G[node])
    {
        if (dn[edge.to] > dn[node] + edge.cost)
        {
            dn[edge.to] = dn[node] + edge.cost;
            que.push(P(dn[edge.to], edge.to));
        }
    }
  }

  int n1 = 0;
  for(int i = 0; i < n; ++i)
  {
    n1 += d1[i] <= dn[i];
  }
  cout << (n1 * 2 <= n ? "Snuke" : "Fennec");
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 12300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<iii> viii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef map<int,int> mpii;
typedef map<string,int> mpsi;
typedef set<int> si;
typedef set<ll> sll;
#define pb push_back
#define I insert
#define INF 1000000000
#define LINF (ll)INF*INF
#define all(x) x.begin(),x.end()
#define F first
#define S second
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,M;cin>>n>>M;
	vi a(n);for(int i=0;i<n;i++) cin>>a[i];
	vll b(n+1);
	map<int,int> mp;
	for(int i=0;i<n;i++) b[i+1]=b[i]+a[i],b[i+1]%=M,mp[b[i+1]]++;
//	mp[b[0]]--;
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ll curr = b[i];
	//	cout<<b[i]<<" "<<mp[curr]<<endl;
		ans+=mp[curr];
	//	cout<<mp[curr]<<endl;
		mp[b[i+1]]--;
	}
	cout<<ans<<endl;
	return 0;
}
/*
	Two roads diverged in a wood, and I—
	I took the one less traveled by,
	And that has made all the difference.
*/

Measured memory_bytes: 4352
n = int(input())
d = {}
for i in range(n):
    s = input()
    if s in d.keys():
        d[s] += 1
    else:
        d[s] = 1
x = 0
for i in d.keys():
    x = max(x,d[i])
d = sorted(d.items())
for i in d:
    if i[1] == x:
        print(i[0])


Measured memory_bytes: 137636
import numpy as np
s = input()
q = int(input())
rbef = []
aft = []
sgn = 1
for i in range(q):
    qi = np.array(input().split(),dtype=str)
    if qi[0] == "1":
        sgn *= -1
    else:
        if (qi[1] == "1" or sgn == -1) and (qi[1] == "2" or sgn == 1):
            rbef.append(qi[2])
        else:
            aft.append(qi[2])

bef = "".join(reversed(rbef))
taft = "".join(aft)
ans = bef + s + taft

if sgn == 1:
    print(ans)
else:
    rans = ''.join(list(reversed(ans)))
    print(rans)


Measured memory_bytes: 36068
def bb087():
    a = int(input()) # 500
    b = int(input()) # 100
    c = int(input()) #  50
    x = int(input())

    cnt = 0

    for d in range(0,a+1):
        for e in range(0,b+1):
            for f in range(0,c+1):
                g = 500*d + 100*e + 50*f
                if g == x:
                    cnt += 1
    print(cnt)

bb087()

Measured memory_bytes: 3060
program main
  implicit integer(a-z)
  character(10), dimension(100)::w
  character(3)::ans="Yes"

  read(*,*)n
  do i=1,n
     read(*,*)w(i)
  end do

  do i=2,n
     
     if(w(i-1)(len(trim(adjustl(w(i-1)))):len(trim(adjustl(w(i-1)))))&
          .ne.w(i)(1:1))then
        ans="No"
     end if
 
     do j=1,i-1
        if(w(j).eq.w(i))then
           ans="No"
        end if
     end do
  end do
 
  write(*,*)ans
end program main

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

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];

int main()
{
	long long N, cnt = 0, tmp, ans = 0;
	vector<long long> a(3);
	
	cin >> a[0] >> a[1] >> a[2];

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

	cout << abs(a[2] - a[1])+ abs(a[1] - a[0]);

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define f first
#define s second
using namespace std;

int main() {

  while(1){
  int n,w,d;
  cin >> n >> w >>d;
  if( n == 0 && w == 0 && d == 0) break;

  vector <pair<int,int> > id;
  id.clear();

  pair <int,int> t;

  t.f = w;
  t.s = d;
  id.push_back(t);
  
  for(int i=0;i<n;i++){
    int p,s;
    cin >> p >> s;
    p--;
    
  
     while(1){
      if(s >2*id[p].f+2*id[p].s) s -= 2*id[p].f+2*id[p].s;
      else break;
    } 
    int flg = 0;
    /*while(1) {
      if(flg == 0 && s > id[p].f) s-= id[p].f,flg = 1;
      else if(flg == 0)break;
      if(flg == 1 && s > id[p].s) s-= id[p].s,flg = 0;
      else if(flg == 1)break;
      } */
      
    int s1,s2;
    
    // if(flg == 0) {  
          if(s < id[p].f || (s > id[p].f+id[p].s && s < 2*id[p].f+id[p].s)){
      if(s > id[p].f) s -= (id[p].f + id[p].s);
      s1 = s*id[p].s;
      s2 = (id[p].f-s)*id[p].s;


      t.f = id[p].f-s;
      t.s = id[p].s;
      id[p].f = s;
      id.push_back(t);
      //cout << "tate"<<endl;
      //cout <<"s="<<s<<endl;
      //cout << " s1="<<s1<<" s2="<<s2<<endl;
      
    } else {

      s -= id[p].f;
      if(s > id[p].s) s -= (id[p].f+id[p].s);

      s1 = s*id[p].f;
      s2 = (id[p].s-s)*id[p].f;

      // cout << "yoko"<<endl;
      //cout <<"s="<<s<<endl;
      //cout << " s1="<<s1<<" s2="<<s2<<endl;


      t.s = id[p].s-s;
      t.f = id[p].f;
      id[p].s = s;
      id.push_back(t);

    }
	  id.push_back(id[p]);
	  if(id[id.size()-1].f*id[id.size()-1].s < id[id.size()-2].f*id[id.size()-2].s) swap(id[id.size()-1],id[id.size()-2]);
	  id.erase(id.begin()+p);
	  
	  //for(int i=0;i<id.size();i++) cout << id[i].f*id[i].s <<" ";
	  //cout << endl;

  }

  for(int i=0;i<id.size();i++)
    for(int j=id.size()-1;j>i;j--)
      if(id[j].f*id[j].s < id[j-1].f*id[j-1].s) swap(id[j],id[j-1]);

  for(int i=0;i<id.size();i++){
    cout << id[i].f*id[i].s ;
    if(i != id.size()-1) cout <<" ";
  }
  cout << endl;

  }

  return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int ans,p;
  cin>>ans;
  for(int i=1;i<n;++i)
  {cin>>p;
   ans=__gcd(ans,p);
  }
  cout<<ans;
  return 0;
}
  

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

int main()
 {
  string a,b,c,d;

   cin >> a ;

   if (a.at(0)=='1' &&a.at(1)=='1' &&a.at(2)=='1')
   {
    cout<< 3 <<endl;
   }
   else if (a.at(0)=='0'&&a.at(1)=='0'&&a.at(2)=='0')
   {
    cout<< 0<< endl;
   }

   else if(a.at(0)=='1' &&(a.at(1)=='1' ||a.at(2)=='1')&&(a.at(1)=='1') !=(a.at(2)=='1') )
  {
    cout<< 2 <<endl;
  }
  else if(a.at(2)=='1' &&(a.at(0)=='1' ||a.at(1)=='1')&&(a.at(0)=='1') !=(a.at(1)=='1'))
   {
     cout << 2 <<endl;
   }
   else if(a.at(1)=='1' &&(a.at(0)=='1' ||a.at(2)=='1')&&(a.at(0)=='1') !=(a.at(2)=='1'))
   {
     cout << 2 <<endl;
   }
           else if(a.at(0)=='0' &&(a.at(1)=='1' ||a.at(2)=='1')&&(a.at(1)=='1') !=(a.at(2)=='1') )
          {
            cout<< 1 <<endl;
          }
          else if(a.at(2)=='0' &&(a.at(0)=='1' ||a.at(1)=='1')&&(a.at(0)=='1') !=(a.at(1)=='1'))
           {
             cout << 1 <<endl;
           }
           else if(a.at(1)=='0' &&(a.at(0)=='1' ||a.at(2)=='1')&&(a.at(0)=='1') !=(a.at(2)=='1'))
           {
             cout << 1 <<endl;
           }
   }

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> vect(n,0);
    for(int i=0 ; i<n ; i++){
        cin>>vect[i];
    }
    vector<int> dp(n,INT_MAX);
    dp[0]=0;
    
    for(int i=1 ; i<n ; i++){
        for(int j=i-1 ; j>=0 && j>=i-k ; j--){
            dp[i]=min(dp[i],dp[j]+abs(vect[j]-vect[i]));
        }
        
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
input()
A=[0]+list(map(int,input().split()))
H=len(A)
def h(i):
 l=2*i;r,g=l+1,[i,l][l<H and A[i]<A[l]]
 if r<H and A[g]<A[r]:g=r
 if g!=i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 64176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define int long long
const double PI = 3.141593;
const ll MOD = 1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
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;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}

pii f(int x){
    int a=x%10;
    int b=0;
    while(x){
        b=x;
        x/=10;
    }
    return pii(a,b);
}

signed main()
{
    int n;
    cin>>n;
    map<pii,int> freq;
    for(int i=1;i<=n;++i){
        pii p= f(i);
        freq[p]++;
    }
    ll ans=0;
    for(int i=1;i<=n;++i){
        pii p= f(i);
        pii q(p.second,p.first);
        ans+=freq[q];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

/*
   AtCoder contest
   coder : yoichidon
 */


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int sum = 0;
        int max = 0;
        for(int n=0; n<N; n++){
            int L = sc.nextInt();
            sum += L;
            max = Math.max(max,L);
        }
        System.out.println(sum-max>max ? "Yes" : "No");
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    string s; cin >> s;
    set<char> S;
    for (int i = 0; i < s.size(); i++) {
        S.insert(s[i]);
    }

    if (S.size() == s.size()) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 3524
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

S = input()
Sx = S.replace('x','')

if Sx == Sx[::-1]:
	xx = []
	tmp = 0
	for s in S:
		if s == 'x':
			tmp += 1
		else:
			xx.append(tmp)
			tmp = 0
	xx.append(tmp)
	ans = 0
	L = len(xx)
	for i in range(L//2):
		ans += abs(xx[i]-xx[L-1-i])
	print(ans)
else:
	print(-1)

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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
vector<ll> ret;

int main(){
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    for(auto & tmp:a)cin>>tmp;
    for(auto & tmp:b)cin>>tmp;
    for(auto & tmp:c)cin>>tmp;
    sort(c.rbegin(),c.rend());
    vector<ll> v;
    for(int i=0;i<x;++i)
        for(int j=0;j<y;++j){
            v.push_back(a[i] + b[j]);
        }
    sort(v.rbegin(),v.rend());
    vector<ll> ans;
    for(int i=0,m = min(k,(int)v.size());i<m;++i){
        for(int j=0,n = min(k,(int)c.size());j<n;++j){
            ans.push_back(v[i] + c[j]);
        }
    }
    sort(ans.rbegin(),ans.rend());
    for(int i=0;i<k;++i)cout << ans[i] <<endl;
    return 0;
}



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

int main() {
    long long x, k, d, tmp;
    long long ans;
    cin >> x >> k >> d;

    if(x < 0) x = -1 * x;
    tmp = x / d;
    if(tmp >= k)
    {
        ans = x - (d*k);
    }
    else
    {
        k -= tmp;
        if(k % 2 == 0)
        {
            ans = x - (d*tmp);
        }
        else
        {
            ans = d - (x - (d*tmp));
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3632
def solve_a(a, b):
    if max(a, b) > 9:
        res = -1
    else:
        res = a * b
    return res


def main():
    # input
    a, b = map(int, input().split())
    res = solve_a(a, b)
    print(res)


def test():
    assert solve_a(2, 5) == 10
    assert solve_a(5, 10) == -1
    assert solve_a(9, 9) == 81


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3068
#include <iostream>
using namespace std;
int main () {
	int c[3][3];
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++) cin >> c[i][j];

	for (int i = 0; i < 3; i++) {
		if (c[i][0]-c[(i+1)%3][0] != c[i][1]-c[(i+1)%3][1]
			|| c[i][0]-c[(i+1)%3][0] != c[i][2]-c[(i+1)%3][2]) {
			cout << "No" << endl;
			return 0;
		}
		if (c[0][i]-c[0][(i+1)%3] != c[1][i]-c[1][(i+1)%3]
			|| c[0][i]-c[0][(i+1)%3] != c[2][i]-c[2][(i+1)%3]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

int main() {
  map<string,int> m;
  int n,a,ma;
  string w;
  cin>>n;
  rep(i,n){
    cin>>w;
    if(m.count(w)){
      m[w]++;
    }else{
      m[w]=1;
    }
  }
  cin >>a;
  rep(i,a){
    cin>>w;
    if(m.count(w)){
      m[w]--;
    }else{
      m[w]=-1;
    }
    
  }
  for(auto p:m){
    ma=max(ma,p.second);
  }
  cout <<ma<<endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    string s;
    cin>>s;

    if ( s == "MON" )
    {
        cout<<"6"<<endl;
    }
    else if ( s == "TUE" )
    {
        cout<<"5"<<endl;
    }
    else if ( s == "WED" )
    {
        cout<<"4"<<endl;
    }
    else if ( s == "THU" )
    {
        cout<<"3"<<endl;
    }
    else if ( s == "FRI" )
    {
        cout<<"2"<<endl;
    }
    else if ( s == "SAT" )
    {
        cout<<"1"<<endl;
    }
    else if ( s == "SUN" )
    {
        cout<<"7"<<endl;
    }
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.array;

void main()
{
    int a = readln.split[0].to!int;
    int b = readln.split[0].to!int;
    int c = readln.split[0].to!int;
    int d = readln.split[0].to!int;
    int e = readln.split[0].to!int;
    int k = readln.split[0].to!int;

    if (e - a <= k){
        writeln("Yay!");
    } else {
        writeln(":(");
    }
}



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

int main()
{
	int num;
	int names[5];

	for (int i = 0; i < 5;i++) {
		names[i] = 0;
	}

	std::cin >> num;

	for (int i = 0; i < num; i++) {
		std::string str;
		std::cin >> str;
		switch (str[0]) {
		case 'M':
			names[0]++;
			break;
		case 'A':
			names[1]++;
			break;
		case 'R':
			names[2]++;
			break;
		case 'C':
			names[3]++;
			break;
		case 'H':
			names[4]++;
			break;
		}
	}

	//for (int i = 0; i < 5; i++) {
	//	std::cout << i << ": " << names[i] << std::endl;
	//}

	long long result = 0;

	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			for (int k = j + 1; k < 5; k++) {
				result += (long long)(names[i]) * names[j] * names[k];
			}
		}
	}

	std::cout << result << std::endl;

	std::cin >> num;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<stack>
#define ll long long
#define maxn 1e7+5
using namespace std;
const int mod=1e9+7;
int n,m,f[2][301][301][3];
struct pp
{
	int l,v,next;
}a[301];
int cnt,h[301],ans;
void add(int x,int y,int z)
{
	cnt++;a[cnt].l=y;a[cnt].v=z;a[cnt].next=h[x];h[x]=cnt;
}
void expand(int p,int i,int j,int k,int t)
{
	f[p^1][j][k][t]=(f[p^1][j][k][t]+f[p][j][k][t])%mod;
	if(t==0)
	{
		f[p^1][i][k][1]=(f[p^1][i][k][1]+f[p][j][k][t])%mod;
		f[p^1][i][j][2]=(f[p^1][i][j][2]+f[p][j][k][t])%mod;
	}
	else if(t==1)
	{
		f[p^1][i][k][0]=(f[p^1][i][k][0]+f[p][j][k][t])%mod;
		f[p^1][j][i][2]=(f[p^1][j][i][2]+f[p][j][k][t])%mod;
	}
	else if(t==2)
	{
		f[p^1][k][i][0]=(f[p^1][k][i][0]+f[p][j][k][t])%mod;
		f[p^1][j][i][1]=(f[p^1][j][i][1]+f[p][j][k][t])%mod;
	}
	f[p][j][k][t]=0;
}
int main()
{
	scanf("%d%d",&n,&m);
	int l,r,x;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&l,&r,&x);
		add(r,l,x);
	}
	f[1][0][0][1]=1;f[1][0][0][2]=1;f[1][0][0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<i;j++)
		{
			for(int k=0;k<i;k++)
			{
				for(int t=0;t<3;t++)
				{
					int p=i&1;
					if(f[p][j][k][t]==0)continue;
					for(int z=h[i];z;z=a[z].next)
					{
						l=a[z].l,x=a[z].v;
						int tot=1;if(j>=l)tot++;if(k>=l)tot++;//cout<<tot<<x<<endl;
						if(tot!=x)
						{
							f[p][j][k][0]=0;f[p][j][k][1]=0;f[p][j][k][2]=0;
							break;
						}
					}
					if(f[p][j][k][t]==0)break;
					if(i<n)expand(p,i,j,k,t);
				}
			}
		}
	}
	for(int j=0;j<n;j++)
		for(int k=0;k<n;k++)
			for(int t=0;t<3;t++)
			ans=(ans+f[n&1][j][k][t])%mod;
			cout<<ans;
			
	return 0;
}

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

int data[10000];
int init(void){ memset(data, -1, sizeof(data)); }
int root(int x){ return data[x] < 0 ? x : (data[x] = root(data[x])); }
int size(int x){ return -data[root(x)]; }
int find(int x, int y){ return root(x) == root(y); }
int merge(int x, int y){
	x = root(x);
	y = root(y);
	if (x != y){
		if (data[y] < data[x]) x ^= y ^= x ^= y;
		data[x] += data[y];
		data[y] = x;
	}
	return x != y;
}

typedef struct { int from, to; int v; } Edge;
int cmp_edge(Edge *a, Edge *b){ return a->v - b->v; }
Edge V[10000];

int main(void)
{
	int n;

	while (scanf("%d", &n), n){
		int m, i;
		int minv;
		int count;

		init();

		scanf("%d", &m);
		for (i = 0; i < m; i++){
			int from, to, v;
			scanf("%d,%d,%d", &from, &to, &v);
			V[i] = (Edge){from, to, v / 100 - 1};
		}
		
		qsort(V, m, sizeof(Edge), cmp_edge);

		minv = count = 0;
		for (i = 0; i < m; i++){
			if (count >= n) break;
			if (merge(V[i].from, V[i].to)){
				minv += V[i].v, count++;
			}
		}
		printf("%d\n", minv);
	}
	return (0);
}

Measured memory_bytes: 808
import unittest


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(['beat', 'vet', 'beet', 'bed', 'vet', 'bet', 'beet']), ['beet', 'vet'])

    def test_2(self):
        self.assertEqual(think(['buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo', 'buffalo']), ['buffalo'])

    def test_3(self):
        self.assertEqual(think(['bass', 'bass', 'kick', 'kick', 'bass', 'kick', 'kick']), ['kick'])

    def test_4(self):
        self.assertEqual(think(['ushi', 'tapu', 'nichia', 'kun']), ['kun', 'nichia', 'tapu', 'ushi'])


def solve():
    s = read()
    result = think(s)
    write(result)


def read():
    n = read_int(1)[0]
    s = []
    for _ in range(n):
        s.append(read_line())
    return s


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s):
    d = {}
    for e in s:
        d[e] = d.get(e, 0) + 1
    maximum = 0
    for key, value in d.items():
        maximum = max(maximum, value)
    result = []
    for key, value in d.items():
        if value == maximum:
            result.append(key)
    result.sort()
    return result


def write(result):
    for r in result:
        print(r)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 115020
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int k,x;
    cin>>k>>x;
    for(int i=max(-1000000,x-k+1); i<=min(1000000,x+k-1); i++){
        cout<<i<<" ";
    }

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
using namespace std;
int		cnt;

int		main(void)
{
	int		K, X;
	cin >> K >> X;
	int		min = X - (K - 1);
	int		max = X + (K - 1);
	for (int i = min; i <= max; i++)
	{
		if (i == max)
			cout << i << endl;
		else
			cout << i << " ";
	}
}


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,d,x;cin>>n>>d>>x;
  int a[105];for(int i=0;i<n;i++)cin>>a[i];
  int res = 0;
  for(int i=0;i<n;i++){
    int cnt = 1;
    int j = 1;
    while(cnt<=d){
      res += 1;
      cnt = j * a[i] + 1;
      j++;
    }
  }
  cout<<res + x<<endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int h, w;
    scanf("%d %d\n", &h, &w);
    vector<vector<char>> s(h, vector<char>(w));
    char a;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            scanf("%c", &a);
            
            if(a == '#')
            {
                s[i][j] = a;
                for (int k = -1; k < 2; k++)
                {
                    for (int l = -1; l < 2; l++)
                    {
                        if (k + i >= 0 && k + i < h && l + j >= 0 && l + j < w && s[k + i][l + j] != '#')
                        {
                            if (s[k + i][l + j] == '\0')
                            {
                                s[k + i][l + j] = '1';
                            }
                            else
                            {
                                s[k + i][l + j]++;
                            }
                        }
                    }
                }
            }
            else if(s[i][j] == '\0')
            {
                s[i][j] = '0';
            }
        }
        scanf("\n");
    }
    
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            printf("%c", s[i][j]);
        }
        printf("\n");
    }
}


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

using namespace std;


int main() {
	vector<long long> A;
	long long N;
	cin >> N;
	A.resize(N);
	vector<long long> A_gcf;
	for (long long i = 0; i < N; ++i) {
		cin >> A[i];
	}


	sort(A.rbegin(), A.rend());

	for (long long j = 0; j <= 1; ++j) {
		for (long long i = 1; i <= pow(double(A[j]), 0.5) + 1;) {
			if (A[j] % i == 0) {
				A_gcf.push_back(i);
				if (i != A[j] / i)A_gcf.push_back(A[j] / i);
			}
			++i;
		}
	}
	sort(A_gcf.rbegin(), A_gcf.rend());

//	for (int i = 0; i < A_gcf.size(); ++i) {
//		cout << A_gcf[i] << endl;
//	}


	long long maxA_gcf = 0;
	for (long long i = 0; i < A_gcf.size(); ++i) {
		bool first = true;
		bool success = true;
		for (long long j = 0; j < N; ++j) {
			if (A[j] % A_gcf[i] != 0 && !first) {
				success = false;
				break;
			}
			else if (A[j] % A_gcf[i] != 0 && first)first = false;
		}
		if (success) {
			maxA_gcf = A_gcf[i];
			break;
		}
	}
	cout << maxA_gcf << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back



int main(){
    int a,b; cin>>a>>b;
    if (a%3 == 0){
        cout<<"Possible";
        return 0;
    }
        if (b%3 == 0){
        cout<<"Possible";
        return 0;
    }
            if ((a+b)%3 == 0){
        cout<<"Possible";
        return 0;
    }
    cout<<"Impossible";
    
}

Measured memory_bytes: 256
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<ll> v(n);
    priority_queue<ll> q;
    for(auto &x:v)
    {
        cin>>x;
        q.push(x);
    }
    while(m-- && (!q.empty()))
    {
        ll x = q.top();
        q.pop();
        x = x/2;
        if(x!=0)
        {
            q.push(x);
        }
    }
    ll sum=0;
    while(!q.empty())
    {
        ll x = q.top();
        sum +=x;
        q.pop();
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 2168