akhauriyash/Code-Regression huggingface dataset:
// https://atcoder.jp/contests/practice2/tasks/practice2_a

#include <cstddef>
#include <iostream>
#include <vector>

class DisjointSet {
 private:
  class Node {
    friend DisjointSet;

    std::size_t parent;
    std::size_t size;

    Node(const std::size_t parent, const std::size_t size) : parent(parent), size(size) {}
  };

  std::vector<Node> nodes;

 public:
  DisjointSet(const std::size_t n) : nodes(n, Node(n, 1)) {}

  std::size_t size() const { return nodes.size(); }

  std::size_t size(const std::size_t x) { return nodes[root(x)].size; }

  std::size_t root(const std::size_t x) {
    if (nodes[x].parent == size()) return x;
    return nodes[x].parent = root(nodes[x].parent);
  }

  bool is_same(const std::size_t x, const std::size_t y) { return root(x) == root(y); }

  bool unite(const std::size_t x, const std::size_t y) {
    std::size_t rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (nodes[rx].size < nodes[ry].size) std::swap(rx, ry);
    nodes[rx].size += nodes[ry].size;
    nodes[ry].parent = rx;
    return true;
  }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, Q;
  std::cin >> N >> Q;
  DisjointSet ds(N);
  for (int i = 0; i < Q; i++) {
    int t, u, v;
    std::cin >> t >> u >> v;
    switch (t) {
      case 0:
        ds.unite(u, v);
        break;
      case 1:
        if (ds.is_same(u, v)) {
          std::cout << 1 << '\n';
        } else {
          std::cout << 0 << '\n';
        }
        break;
    }
  }
  return 0;
}


Measured memory_bytes: 6200
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <iostream>
#include <map>
#include <cmath>
#include <bitset>

using namespace std;

const int CMax = 100005;

int main()
{
    int n, maxCount = 0;
    string S;
    map <string, int> M;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        cin >> S;
        M[S]++;
        maxCount = max(maxCount, M[S]);
    }

    for (map <string, int>::iterator mit = M.begin(); mit != M.end(); ++mit) {
        if (mit->second == maxCount) cout << mit->first << endl;
    }
}



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

using namespace std;

typedef long long ll;

int main(){
	ll n, h, w;
	cin >> n >> h >> w;
	ll a, b;
	ll ans = 0;
	for(ll i = 0; i < n; i++){
		cin >> a >> b;
		if(a >= h && b >= w)ans++;
	}
	cout << ans << endl;
    return 0;
}

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

const double EPS = 1e-8;

typedef valarray<double> P;

void assign(P &p, double x, double y, double z){
	p.resize(3);
	p[0] = x;
	p[1] = y;
	p[2] = z;
}

double dot(const P &a, const P &b){
	return (a * b).sum();
}

P cross(const P &a, const P &b){
	return a.cshift(-1) * b.cshift(1) - a.cshift(1) * b.cshift(-1);
}

bool check(){
	double x, y, z;
	P pt[5];
	for(int i = 0; i < 5; ++i){
		cin >> x >> y >> z;
		assign(pt[i], x, y, z);
	}

	P n = cross(pt[3] - pt[2], pt[4] - pt[2]);
	double r = dot(pt[2] - pt[0], n);
	double s = dot(pt[1] - pt[0], n);
	if(abs(s) < EPS){ return true; }
	double t = r / s;
	if(t < -EPS || t > 1.0 + EPS){ return true; }
	P c = pt[0] * (1.0 - t) + pt[1] * t;
	P d = cross(pt[3] - pt[2], c - pt[2]);
	if(dot(d, cross(pt[4] - pt[3], c - pt[3])) < -EPS){ return true; }
	if(dot(d, cross(pt[2] - pt[4], c - pt[4])) < -EPS){ return true; }
	return false;
}

int main(){
	cout << (check() ? "HIT\n" : "MISS\n");
}

Measured memory_bytes: 1208
n=input()
s=list(input())
for i in range(len(s)):
    ord_s=int(ord(s[i]))
    if ord_s+int(n)<=90:
        ord_s+=int(n)
        s[i]=chr(ord_s)
    else:
        ord_s=ord_s+int(n)-26
        s[i]=chr(ord_s)
print("".join(s))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){
    
    ll N, M;
    cin >> N >> M;
    V v(N + 1, 0);
    rep(i, M){
        ll a, b;
        cin >> a >> b;
        v[a] ^= 1;
        v[b] ^= 1;
    }
    string ans = "YES";
    rep1(i, N)if(v[i])ans = "NO";
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python

N,M=map(int,raw_input().split())
a=[0]*N
b=[0]*N
c=[0]*M
d=[0]*M
for i in range(N):
    a[i],b[i]=map(int,raw_input().split())
for j in range(M):
    c[j],d[j]=map(int,raw_input().split())
for i in range(N):
    dist=[0]*M
    for j in range(M):
        dist[j]=abs(a[i]-c[j])+abs(b[i]-d[j])
        #print "student"+str(i)+": distance "+str(dist[j])
    print [i for i,x in enumerate(dist) if x==min(dist)][0]+1


Measured memory_bytes: 2692
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = A*2
d = []

for i in range(N*2):
  num = B[i]
  target = B[i+1:]
  d.append(len([n for n in target if num > n]))
  
d_each = sum(d[:N]) - sum(d[N:])
first = sum(d[N:])
print(int((K * first + K * (K - 1) * d_each // 2) % (10 ** 9 + 7)))

Measured memory_bytes: 3316
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<utility>
#ifdef XS
	#include<De>
#endif
using namespace std;
#define MS(m) memset(m,0,sizeof(m))

typedef unsigned U;
typedef pair<int,int > P;
typedef long long ll;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	try{
		//while(1)
		//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
		inp();
	}
	catch(... ){
#ifdef XS
		printf("%s","exception");
#endif
	}//for compatibility with cygwin c++ runtime
	return 0;
}
const int N = 51;
const int n = 50;
ll A [N];
void inp(){
	MS(A);
	ll k;cin>>k;
	ll a0 = k/n;
	for(int i = 1;i<=n;i++)A[i] = a0 + i - 1;
	ll r = k%n;
	for(int i = 1;i<=r;i++){
		A[i] += n;
		for(int j = 1;j<=n;j++){
			if(i == j )continue;
			A[j] -= 1;
		}
	}
	//pA(A, n, "A");
	cout<<n<<endl;
	for(int i = 1;i<=n;i++){
		if(i)cout<<' ';
		cout<<A[i];
	}
}
//at79D.cc by xsthunder at Sun Jul 30 10:02:14 2017


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

int ps,pt;

int sdiff(string sx, string tx)
{
  if(sx == tx)
    {ps=1; pt=1;}
  else if(sx > tx)
    {ps=3; pt=0;}
  else
    {ps=0; pt=3;}
  return 0;
}

int main(void)
{
  int n,k,is,it;
  string s[1001]={},t[1001]={};

  cin >> n;

  is=0; it=0;
  for(k = 1; k <= n; k++){
    cin >> s[k] >> t[k];
    sdiff(s[k],t[k]);
    is=is+ps; it=it+pt;
  }

  cout << is << " " << it << endl;

  return 0;
}

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

def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)

mod9 = N//9
res = 10**10

for i in range(0,mod9+1):
    j = (N-i*9)//6
    cnt = 0
    if 9*i+6*j > N:
        break
    else:
        t = base10to(i,9)
        s = base10to(j,6)
        for x in str(t):
            cnt += int(x)
        for y in str(s):
            cnt += int(y)
        cnt += (N-9*i-6*j)
        if cnt <= res:
            res = cnt
print(res)

Measured memory_bytes: 3064
while 1:
    try:
        a, b, c, d, e, f = map(float, input().split())
    except:
        break
    
    x = (c*e - b*f) / (a*e - b*d)
    y = (c*d - a*f) / (b*d - a*e)
    
    if x == 0:      x = 0
    if y == 0:      y = 0
    
    print('{:.3f}'.format(x), '{:.3f}'.format(y))


Measured memory_bytes: 5588
#include<iostream>
#include<vector>
using namespace std;
class DisjoinSet{
    public:
        vector<int> rank,p;

        DisjoinSet(){}
        DisjoinSet(int size){
            rank.resize(size,0);
            p.resize(size,0);
            for(int i=0;i<size;i++)
                makeSet(i);
        }
        void makeSet(int x){
            p[x]=x;
            rank[x]=0;
        }
        int findSet(int x){       
            if(x!=p[x]) p[x]=findSet(p[x]);
            return p[x];
        }    
        bool same(int x,int y){return findSet(x)==findSet(y);}

        void unite(int x,int y){link(findSet(x),findSet(y));}

        void link(int x,int y){
            if(rank[x]>rank[y]) p[y]=x;
            else{
                p[x]=y;
                if(rank[x]==rank[y]) rank[y]++;
            }
        }
};
int main(){

    int n,a,b,q;
    int t;
    cin>>n>>q;
    DisjoinSet ds=DisjoinSet(n);
    for(int i=0;i<q;i++){
        cin>>t>>a>>b;
        if(t==0)ds.unite(a,b);
        else if(t==1){
            if(ds.same(a,b))cout<<1<<"\n";
            else cout<<0<<"\n";
        }
    }
    return 0;
}
    



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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

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

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int N, M; cin >> N >> M;
    vector<int> P(N + 1, 0); P[1] = 1;  // 赤が入っている可能性があれば1
    vector<int> C(N + 1, 1);            // 各箱のボールの個数
    REP(i, M) {
        int x, y;
        cin >> x >> y;
        C[x]--; 
        C[y]++;
        if (P[x]) {
            P[y] = 1;
        }
        if (!C[x]) {
            P[x] = 0;
        }
    } 
    cout << count(P.begin(), P.end(), 1) << "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c; cin>>a>>b>>c;
  if(a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0))cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

int main() {
	int N;
	cin >> N;
	if (N <= 111) {
		cout << 111 << endl;
	}
	else if (N <= 222 && N > 111) {
		cout << 222 << endl;
	}
	else if (N <= 333 && N > 222) {
		cout << 333 << endl;
	}
	else if (N <= 444 && N > 444) {
		cout << 444 << endl;
	}
	else if (N <= 555 && N > 444) {
		cout << 555 << endl;
	}
	else if (N <= 666 && N > 555) {
		cout << 666 << endl;
	}
	else if (N <= 777 && N > 666) {
		cout << 777 << endl;
	}
	else if (N <= 888 && N > 777) {
		cout << 888 << endl;
	}
	else if (N <= 999 && N > 888) {
		cout << 999 << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N; cin >> N;
    vector<vector<pair<int, int>>> A(N);
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        A[i].resize(a);
        for (int j = 0; j < a; j++) {
            int x, y; cin >> x >> y; x--;
            A[i][j] = make_pair(x, y);
        }
    }
    int ans = 0;
    for (int i = 0; i < (1 << N); i++) {
        for (int j = 0; j < N; j++) if (i & (1 << j)){
            for (auto &p : A[j]) {
                if (p.second == 1 && !((1 << p.first) & i)) {
                    goto FAIL;
                }
                if (p.second == 0 && ((1 << p.first) & i)) {
                    goto FAIL;
                }
            }
        }
        ans = max(ans, __builtin_popcount(i));
        FAIL:;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitsf(n) __builtin_popcount(n)

int f(ll a, ll b){
    ll c = (a*b) % 1000000000000000001ll;
    if(a == c/b) return 0;
    return 1;
}
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    quickio
    ll n;
    cin >> n;

    ll pre = 1, p = 1;
    int flag = 1;

    vector<ll> v(n);
    for(auto &i : v) cin >> i;
    sort(all(v));

    for(auto x : v){
        if(x == 0){
            p = 0;
            break;
        }

        if(f(p, x)){
            flag = 0;
            break;
        }

        p *= x;
    }

    if(flag) cout << p;
    else cout << -1;
}
 


Measured memory_bytes: 3976
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
R,G,B,n = readInts()
cnt = 0
for r in range(n+1):
    for g in range(n+1):
        b = n - r*R - g*G
        #print(r,g,b)
        if b >= 0:
            if b%B == 0:
                cnt += 1
print(cnt)


Measured memory_bytes: 77644
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]) {
    // insert code here...
    int n;
    while(scanf("%d",&n)==1){
        
        if(n==0){
            break;
        }
        else{
            int a[1010];
            for(int i=0;i<n;i++){
                scanf("%d",&a[i]);
            }
            int min = 10000000;
            for(int i=0;i<n-1;i++){
                for(int j=i+1;j<n;j++){
                    if(abs(a[i]-a[j])<min){
                        min = abs(a[i]-a[j]);
                    }
                }
            }
            printf("%d\n",min);
        }
            
    }
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    string s;
    long long int k;
    cin>>s>>k;
    REP(i,k){
        if(s[i]!='1'){
            cout<<s[i]<<endl;
            return 0;
        }
    }
    cout<<s[k-1]<<endl;
    

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b, c;
	int N;
	int num;
	while (cin >> N)
	{
		a = b = c = 0;
		while (N--)
		{
			cin >> num;
			if (num % 4 == 0) a++;
			else if (num % 2 == 0) b++;
			else c++;
		}
		if (b == 0)
		{
			if (a >= c - 1) cout << "Yes" << endl;
			else cout << "No" << endl;
			continue;
		}

		if (a >= c) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def main():
	n,k = map(int,input().split())
	ans = 0
	for i in range(n):
		su = i+1
		count = 0
		# print("su= {}".format(su))
		# print("i = {}".format(i))
		while su < k:
			su *= 2
			count += 1
			# print(su)
		# print("count = {}".format(count))
		ans += (1/n)*(0.5)**count
		# print("ans = {}".format(ans))
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 39408
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

bool num[100010];

void eratosthenes(int n) {
    for (int i = 0; i <= n; i++) num[i] = true;

    num[0] = num[1] = false;

    for (int i = 2; i*i <= n; i++) {
        if (num[i]) {
            for (int j = 2*i; j <= n; j += i) {
                num[j] = false;
            }
        }
    }
}

int main()
{
    int q;
    int l, r;
    int ans[100010] = {};
    int rui[100010] = {};
    vector<int> yeah;

    cin >> q;
    
    eratosthenes(100000);

    for (int i = 0; i <= 100000; i++) {
        if (num[i] && num[(i+1) / 2]) {
            ans[i] = 1;
        }
    }

    for (int i = 0; i < 100000; i++) {
        rui[i+1] = rui[i] + ans[i];
    }

    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        yeah.push_back(rui[r+1]-rui[l]);
    }

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

}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;


int main() {

	int n, k;
	cin >> n >> k;

	V<ll> pl, mn;
	int zero = 0;

	rep(i, n) {
		ll a;
		cin >> a;
		if (a > 0)pl.push_back(a);
		if (a < 0)mn.push_back(-a);
		if (a == 0)zero++;
	}
	sort(all(pl), greater<ll>());
	sort(all(mn), greater<ll>());

	if (n == k) {
		if (zero > 0)cout << 0 << endl;
		else {
			ll a = 1;
			for (auto x : pl) { a *= x;a %= MOD; }
			for (auto x : mn) { a *= x;a %= MOD; }
			if (mn.size() % 2) {
				a = (a * (-1) + MOD) % MOD;
			}
			cout << a << endl;
		}
		return 0;
	}

	if (zero > n - k) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 1;
	if (k % 2 == 1 && mn.size() >= k) {
		rep(i, k) {
			ans *= mn[mn.size() - 1 - i];
			ans %= MOD;
		}
		ans *= -1;
		ans += MOD;
		ans %= MOD;
	}

	int p = 0, m = 0;
	ll ans2 = 1;
	if (k % 2) {
		p = 1;
		if (pl.size() == 0) {
			cout << (zero > 0 ? 0 : ans) << endl;
			return 0;
		}
		ans2 = pl[0];
	}
	rep(i, k / 2) {
		ll multi_p = -1, multi_m = -1;
		if (p + 1 < pl.size())multi_p = pl[p] * pl[p + 1];
		if (m + 1 < mn.size())multi_m = mn[m] * mn[m + 1];

		if (multi_p == -1 && multi_m == -1) {
			cout << (zero > 0 ? 0 : ans) << endl;
			return 0;
		}
		if (multi_p <= multi_m) {
			ans2 *= mn[m];ans2 %= MOD;
			ans2 *= mn[m + 1];ans2 %= MOD;
			m += 2;
		}
		if (multi_m < multi_p) {
			ans2 *= pl[p];ans2 %= MOD;
			ans2 *= pl[p + 1];ans2 %= MOD;
			p += 2;
		}

		cerr << m << " " << p << endl;
	}

	cout << ans2 << endl;

}

Measured memory_bytes: 5412
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline void readInt(int &x) {
	x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;
}
inline void readLong(ll &x) {
	x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;
}
/*================Header Template==============*/
vector<int> G[100010];
int n,m,u,v,cntb=0,cntw=0;
int col[100010];
bool isdou=1;
inline void dfs(int u) {
	for(unsigned i=0;i<G[u].size();i++) {
		int v=G[u][i];
		if(col[v]==-1) {
			col[v]=3-col[u];
			dfs(v);
		}
		else {
			if(col[v]==col[u]) {
				isdou=0;
				return;
			}
			else
				continue;
		}
		if(!isdou)
			return;
	}
}
int main() {
	cin>>n>>m;
	for(int i=1;i<=m;i++) {
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	memset(col,-1,sizeof col);
	col[1]=1;
	dfs(1);
	if(isdou) {
		for(int i=1;i<=n;i++)
			if(col[i]==1)
				cntb++;
			else
				cntw++;
		printf("%lld\n",(ll)cntb*cntw-m);
		return 0;
	}
	else {
		printf("%lld\n",(ll)n*(n-1)/2-m);
		return 0;
	}
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[555431];
int l[1];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[1];

P u[555551];
priority_queue<P> q;
//stack<int> s;
set<int> s;
map<long long,int> p;

vector<int> v[400101],v1[400101];

bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  return a.x<b.x;
}

int main()
{
  memset(o,-1,sizeof(o));
  scanf("%d %d",&a,&b);
  z=1000100;
  p[z]=1;
  e=1;
  u[1]={1,0};
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d %d",&n,&m,&c);
    if(!p[n*z+c])
    {
      e++;
      u[e]={n,c};
      p[n*z+c]=e;
      v1[n].push_back(e);
    }
    if(!p[m*z+c])
    {
      e++;
      v1[m].push_back(e);
      u[e]={m,c};
      p[m*z+c]=e;
    }
    v[p[n*z+c]].push_back(p[m*z+c]);
    v[p[m*z+c]].push_back(p[n*z+c]);
  }
  for(int t=1;t<=e;t++)
    o[t]=mod;
  for(int h=0;h<v1[a].size();h++)
  {
    o[v1[a][h]]=1;
    q.push({v1[a][h],1});
  }
  k=mod;
  for(;q.size();)
  if(q.top().y==o[q.top().x])
  {
    P s=q.top();
    q.pop();
    //printf("#%d %d %d\n",u[s.x].x,u[s.x].y,s.y);
    if(u[s.x].x==1)
    {
      k=min(k,s.y);
      continue;
    }
    
    for(int h=0;h<v[s.x].size();h++)
    if(o[v[s.x][h]]==s.y+1)
    {
      o[v[s.x][h]]=s.y;
      q.push({v[s.x][h],s.y});
    }
    else if(o[v[s.x][h]]>s.y)
    {
      int n=u[v[s.x][h]].x,m=u[s.x].y;
      for(int h=0;h<v1[n].size();h++)
      if(u[v1[n][h]].y==m)
      {
        o[v1[n][h]]=s.y;
        q.push({v1[n][h],s.y});
      }
      else
      {
        o[v1[n][h]]=s.y+1;
        q.push({v1[n][h],s.y+1});
      }
    }
    
  }
  else q.pop();
  if(k==mod) puts("-1");
  else printf("%d",k);
}
//0
//20




Measured memory_bytes: 68856
import java.util.*;
public class Main{
    static long[][] dp = new long[100][100001];
    static int[] v = new int[100];
    static int[] w = new int[100];
    static int N, W;
    public static void main(String[]args){
        Scanner in = new Scanner(System.in);
        N = in.nextInt();
        W = in.nextInt();
        for(int i = 0 ; i < N ; ++i){
            w[i] = in.nextInt();
            v[i] = in.nextInt();
        }
        solve();
        System.out.println(dp[N-1][W]);

    }
    private static void solve() {
        Arrays.fill(dp[0], w[0], W+1, v[0]);
        for(int i = 1 ; i < N ; ++i){
            for(int j = 0 ; j <= W ; ++j){
                if(j < w[i])
                    dp[i][j] = dp[i-1][j];
                else
                dp[i][j] = Math.max(dp[i-1][j] ,
                        (dp[i-1][j-w[i]] + v[i]));
            }
        }
    }
}

Measured memory_bytes: 130256
#include <iostream>
#include<algorithm>
#include<stack>
using namespace std;
const int N=2e5+5;
long long arr[N];
stack <int> low;
stack <int> lowindex;
pair <int, int> sor[N];
int main()
{;
    int a, n;
    cin>>n;
    for(a=1; a<=n; a++)
        cin>>arr[a];
    for(a=1; a<=n; a++)
    {
        if(low.empty()==true)
        {
            sor[a].first=0;
            low.push(arr[a]);
            lowindex.push(a);
        }
        else if(low.top()<arr[a])
        {
            sor[a].first=lowindex.top();
            low.push(arr[a]);
            lowindex.push(a);
        }
        else if(low.top()>arr[a])
        {
            while(low.empty()==false)
            {
                if(low.top()<arr[a])
                {
                    sor[a].first=lowindex.top();
                    break;
                }
                else
                {
                    low.pop();
                    lowindex.pop();
                }
            }
            if(low.empty()==true)
                sor[a].first=0;
            low.push(arr[a]);
            lowindex.push(a);
        }
    }
    while(low.empty()==false)
    {
        low.pop();
        lowindex.pop();
    }
    for(a=n; a>0; a--)
    {
        if(low.empty()==true)
        {
            sor[a].second=n+1;
            low.push(arr[a]);
            lowindex.push(a);
        }
        else if(low.top()<arr[a])
        {
            sor[a].second=lowindex.top();
            low.push(arr[a]);
            lowindex.push(a);
        }
        else if(low.top()>arr[a])
        {
            while(low.empty()==false)
            {
                if(low.top()<arr[a])
                {
                    sor[a].second=lowindex.top();
                    break;
                }
                else
                {
                    low.pop();
                    lowindex.pop();
                }
            }
            if(low.empty()==true)
                sor[a].second=n+1;
            low.push(arr[a]);
            lowindex.push(a);
        }
    }
    long long b=0;
    for(a=1; a<=n; a++)
        b+=arr[a]*(sor[a].second-a)*(a-sor[a].first);
    cout<<b;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    LL ans = 1;
    for (int i = 1; i <= n; ++i) {
        ans = ans * i;
        ans%=(1000000000 + 7);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)

const int M=1000000007;
const int MM=998244353;


 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

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

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

const ll N=1e5+5;

ll par[N];

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

void unio(ll a,ll b){
  a=find(a),b=find(b);
  par[a]=b;
}


int main()
{ 

IOS;


ld a,b,x;cin>>a>>b>>x;

ld ans=atan((1.0*2*b*a*a-2*x)/(1.0*a*a*a));

ld ratio=(1.0*x)/(a*a*b);

if(ratio<0.5)
ans=atan((1.0*a*b*b)/(2.0*x));

ans=(1.0*180*ans)/(PI);

cout<<fix(ans,9);

return 0;
 
}


Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#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()
typedef long long ll;

int dp[5010][5010];

int main(){
    int N;
    string S;
    cin >> N;
    cin >> S;

    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==0||j==0){
                if(S[i]==S[j])dp[i][j]=1;
            }else{
                if(S[i]==S[j]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else{
                    dp[i][j]=0;
                }
            }
        }
    }

    int res = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(i+dp[i][j]-1<j)res = max(res,dp[i][j]);
        }
    }

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 98048
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
	int n, m, x[110], y[110];
	scanf("%d %d %d %d", &n, &m, &x[0], &y[0]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &x[i]);
	for (int i = 1; i <= m; i++)
		scanf("%d", &y[i]);
	sort(x, x + n + 1);
	sort(y, y + m + 1);
	if (x[n] < y[0])
		printf("No ");
	printf("War\n");
	return 0;
}

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

using namespace std;

typedef long long ll;

int uk = 1;
deque <int> a, b;

void solve(ll n) {
  if (n == 2) {
    a.push_back(uk);
    b.push_back(uk);
    ++uk;
    return;
  }
  if (n % 2 == 0) {
    solve(n / 2);
    a.push_back(uk);
    b.push_back(uk);
    ++uk;
  } else {
    solve(n - 1);
    a.push_front(uk);
    b.push_back(uk);
    ++uk;
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  ll n;
  cin >> n;
  ++n;
  solve(n);
  cout << a.size() + b.size() << '\n';
  for (int x : a) {
    cout << x << ' ';
  }
  for (int x : b) {
    cout << x << ' ';
  }
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())

l = [0] * 3

l[0] = a
l[1] = b
l[2] = c

k = [0] * 3

k[0] = l.count(a)
k[1] = l.count(b)
k[2] = l.count(c)

t = max(k)

if t == 1:
	t = 3
elif t ==3:
	t = 1
else:
	pass


print(t)



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
    string S, T;
    int A, B;
    string U;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (S == U) A--;
    if (T == U) B--;
    if (S == U && T == U) A++;

    // 出力
    cout << A << " "<< B << endl;
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	double l,r;
	int al=0,bl=0,cl=0,dl=0,ar=0,br=0,cr=0,dr=0;
	while(scanf("%lf%lf",&l,&r)!=EOF){
		if(l>=1.1){
			al++;
		}else if(l>=0.6){
			bl++;
		}else if(l>=0.2){
			cl++;
		}else{
			dl++;
		}
		if(r>=1.1){
			ar++;
		}else if(r>=0.6){
			br++;
		}else if(r>=0.2){
			cr++;
		}else{
			dr++;
		}
	}
	printf("%d %d\n%d %d\n%d %d\n%d %d\n",al,ar,bl,br,cl,cr,dl,dr);
	return 0;
}

Measured memory_bytes: 624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;


int main(void) {

    int n;
    cin>>n;
    cout<<(n-1)/2<<endl;


}


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() {
  ll n, k;
  cin >> n >> k;
  if (n >= k) {
    ll kai = n / k;
    n = n - k * kai;
  }
  if (n < k)
    n = min(n, abs(n - k));
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 3576
for i in range(365):
    print(1)
    
exit()

d = int(input())
c = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(d)]

#t = [int(input()) for i in range(d)]

for i in range(d):
    print(1)
    
exit()

ans = []
last = [[0 for i in range(26)] for j in range(27)]
tmp_ans = [0]*26

for i in range(1,d+1):
    tmp_num = 0
    for j in range(26):
        tmp_ans[j] += s[i-1][j]
        last[j+1][j] = i
        for k in range(26):
            tmp_ans[j] -= (i-last[j+1][k])*c[k]
    idx = tmp_ans.index(max(tmp_ans))
    for j in range(26):
        for k in range(26):
            if k == idx:
                continue
            last[k][j] = last[idx][j]
    print(idx+1)
    #print(tmp_ans)
#print(ans)
    """
            
    ans += s[i-1][t[i-1]-1]
    last[t[i-1]-1] = i
    for j in range(26):
        ans -= (i-last[j])*c[j]
    print(ans)
    """
    


Measured memory_bytes: 63332
from collections import deque

# deque
# https://docs.python.org/ja/3/library/collections.html#collections.deque
# pop(0), append が高速

# トポロジカルソート
# https://csacademy.com/lesson/topological_sorting/


N, M = [int(_) for _ in input().split()]
E = [[] for _ in range(N)]

indegree = [0] * N  # 入次数
for i in range(M):
    a, b = [int(_) - 1 for _ in input().split()]
    E[a].append(b)
    indegree[b] += 1

que = deque([i for i in range(N) if indegree[i] == 0])

sorted_nodes = []
dp = [0] * N
while que:
    n = que.popleft()
    sorted_nodes.append(n)
    for next_node in E[n]:
        indegree[next_node] = indegree[next_node] - 1  # 枝刈り
        if indegree[next_node] == 0:  # 入次数0なら queue に追加
            que.append(next_node)

        dp[next_node] = max(dp[next_node], dp[n] + 1)
# print(sorted_nodes)
print(max(dp))


Measured memory_bytes: 66976
import java.io.PrintWriter;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

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

    void run() {

        int n = sc.nextInt();
        int h = sc.nextInt();
        int[][] arr = new int[n][2];
        for (int i=0; i<n; i++) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }

        int aMax = 0;

        int ans = 0;

        for (int i=0; i<n; i++) {
            aMax = Math.max(aMax, arr[i][0]);
        }

//        Arrays.sort(arr, (a, b) -> Integer.compare(a[0], b[0]));

        Data[] d = new Data[n];

        for (int i=0; i<n; i++) {
            d[i] = new Data(arr[i][0], arr[i][1]);
        }

        Arrays.sort(d);

//        out.println(d[2].b);
//        out.println(aMax);

        label:
        for (int i=0; i<n; i++) {
            if (d[i].b>aMax) {
                h -= d[i].b;
                ans++;
                if (h<=0) break label;
            }
        }

        if (h<=0) {
            out.print(ans);
            out.flush();
        } else {
            ans += (h+aMax-1)/aMax;

            out.print(ans);
            out.flush();

        }

    }

    public class Data implements Comparable<Data> {
        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }
        public int compareTo(Data other) {
            if (this.b==other.b) {
                return this.b - other.b;
            } else {
                return other.b- this.b;
            }
        }

    }

}


Measured memory_bytes: 94656
use std::cmp;
use std::collections::BTreeSet;


const MAX_D: usize = 50;
const MAX_COST: usize = 1 << 55;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let a: Vec<usize> = (0..n).map(|_| sc.read()).collect();
    let b: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    let mut ans: Vec<usize> = Vec::new();
    for upper in (1..(MAX_D + 2)).rev() {
        let mut costs = vec![vec![MAX_COST; MAX_D + 1]; MAX_D + 1];

        for d in 1..upper {
            for from in 0..(MAX_D + 1) {
                let to = from % d;
                costs[from][to] = (1 << d);
            }
        }

        for d in &ans {
            let d = *d;
            for from in 0..(MAX_D + 1) {
                let to = from % d;
                costs[from][to] = (1 << d);
            }
        }

        for i in 0..(MAX_D + 1) {
            costs[i][i] = 0;
        }

        for k in 0..(MAX_D + 1) {
            for i in 0..(MAX_D + 1) {
                for j in 0..(MAX_D + 1) {
                    costs[i][j] = cmp::min(costs[i][j], costs[i][k] + costs[k][j]);
                }
            }
        }

        let mut check = true;
        for i in 0..n {
            if costs[a[i]][b[i]] == MAX_COST {
                check = false;
            }
        }
        if !check {
            if upper == MAX_D + 1 {
                println!("-1");
                return;
            }
            ans.push(upper);
        }
    }

    let mut cost: usize = 0;
    for a in &ans {
        cost += (1 << *a);
    }
    println!("{}", cost);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



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

int main(){
	int node[10][10];
	node[0][0] = 1; node[0][1] = 2;
	node[1][0] = -1; node[1][1] = 3;
	node[2][0] = 1; node[2][1] = -1;
	node[3][0] = 4; node[3][1] = 5;
	node[4][0] = 5; node[4][1] = 2;
	node[5][0] = 2; node[5][1] = 1;
	while(1){
		string str;
		cin >> str;
		if(str == "#") break;
		int len = str.size();
		int now=0;
		for(int i=0;i<len;i++){
			if(now == -1) break;
			int f = str[i] - '0';
			now = node[now][f];
		}
		if(now == 5) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

const int maxN = 1e5 + 10;

int n, v[3][maxN], f[3][maxN];

int main()
{
    scanf("%d", &n);
    for (int j = 1; j <= n; ++j)
        for (int i = 0; i < 3; ++i)
            scanf("%d", &v[i][j]);
    
    f[0][0] = f[1][0] = f[2][0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        f[0][i] = max(f[1][i - 1], f[2][i - 1]) + v[0][i];
        f[1][i] = max(f[2][i - 1], f[0][i - 1]) + v[1][i];
        f[2][i] = max(f[0][i - 1], f[1][i - 1]) + v[2][i];
    }
    printf("%d", max(max(f[0][n], f[1][n]), f[2][n]));
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,x;
	cin>>N;
	int bandera=0;
	x=N;
	while(bandera!=1)
	{
		if(x%2==0 && x%N==0)bandera =1;
		else
		{
			x*=2;
		}
	}
	cout<<x<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define fi first
#define se second
#define gc getchar
#define pc putchar
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void wri(ll x){write(x);pc(' ');}
inline void writeln(ll x){write(x);pc('\n');}
const int maxn = 5005;
char s[maxn],t[maxn];
int n,ans,a[maxn],b[maxn];
int main(){
	n = read();scanf("%s%s",s+1,t+1);
	if(s[1] != t[1]) a[++*a] = 0;
	rep(i,1,n) if(s[i] != s[i+1]) a[++*a] = i;
	rep(i,1,n) if(t[i] != t[i+1]) b[++*b] = i;
	ans = 1<<30;
	for(int i=0;i<=*a;i+=2){
		int x = i + 1,y = 1,tmp = 0;
		Rep(j,1,i) tmp += a[j];
		while(x <= *a || y <= *b){
			if(x<=*a&&y<=*b) tmp+=abs(a[x++]-b[y++]); else
			if(x<=*a) tmp+=n-a[x++]; else tmp+=n-b[y++];
		}ans=min(ans,tmp);
	}
	for(int i=0;i<=*b;i+=2){
		int x = 1,y = i+1,tmp = 0;
		Rep(j,1,i) tmp += b[j];
		while(x <= *a || y <= *b){
			if(x<=*a&&y<=*b) tmp+=abs(a[x++]-b[y++]); else
			if(x<=*a) tmp+=n-a[x++]; else tmp+=n-b[y++],y;
		}ans=min(ans,tmp);
	}writeln(ans);
	return 0;
}

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

const int mod = 1000000000 + 7;

int N;
string S;

ll dp[3010][3010];
ll sums[3010];

int main() {

    cin >> N;
    cin >> S;
    for(int pos = N - 1; pos >= 0; pos--){
        for(int upper = 0; upper <= N; upper++){
            ll ans = 0;
            if(pos == N - 1){
                ans = 1;
            }
            else{
                // int pos = N - (lower + upper) - 1;
                // より大きい
                if(S[pos] == '<'){
                    if(upper > 0) {
                        (ans += (sums[upper] - sums[0] + mod)) %= mod;
                    }
                    // // いくつめのupperを利用するか
                    // for(int i = 1; i <= upper; i++){
                    //     (ans += dp[pos + 1][upper - i]) %= mod;
                    // }
                }
                // より小さい
                else{
                    int lower = N - ((pos + 1) + upper);
                    if(lower > 0) {
                        (ans += (sums[upper + lower] - sums[upper] + mod)) %= mod;
                    }
                    // // いくつめのlowerを利用するか
                    // for(int i = 1; i <= lower; i++){
                    //     (ans += dp[pos + 1][upper + (i - 1)]) %= mod;
                    // }
                }
            }
            dp[pos][upper] = ans;
        }
        sums[0] = 0;
        for(int i = 0; i <= N; i++){
            sums[i + 1] = (sums[i] + dp[pos][i]) % mod;
        }
    }
    
    ll ans = 0;
    for(int i = 0; i < N; i++){
        (ans += dp[0][N - i - 1]) %= mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 70784
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        
        AtCoder problem = new AtCoder(sc);
        problem.solve(out);
        
        out.flush();
    }
    
}

class AtCoder {
    final String S,T;
    AtCoder(FastScanner sc) {
        S = sc.next();
        T = sc.next();
    }

    void solve(PrintWriter out) {
        out.println(T + S);
    }
    
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {
    
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    
    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }
    
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }
    
    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 20692
#include <stdio.h>

int main(void)
{
	int k, a, b;

	scanf("%d %d %d", &k, &a, &b);
	
	for (int i = a; i <= b; i++)
		if (i % k == 0)
		{
			printf("OK");
			return 0;
		}
	printf("NG");
	return 0;
}

Measured memory_bytes: 1728