akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int n, q;
int A[20];
int m[200];

bool solve(int i, int m)
{
    if (m == 0) {
        return true;
    }
    if (i >= n) {
        return false;
    }
    return solve(i + 1, m) || solve(i + 1, m - A[i]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, n) { cin >> A[i]; }
    cin >> q;
    rep(i, q) { cin >> m[i]; }
    rep(i, q)
    {
        if (solve(0, m[i])) {
            puts("yes");
        } else {
            puts("no");
        }
    }
    // {
    //     bool flag = false;
    //     for (int bit = 0; bit < (1 << n); ++bit) {
    //         int sum = 0;
    //         for (int j = 0; j < n; ++j) {
    //             if (bit & (1 << j)) {
    //                 sum += A[j];
    //             }
    //         }
    //         if (m[i] == sum) {
    //             flag = true;
    //             break;
    //         }
    //     }
    //     if (flag) {
    //         puts("yes");
    //     } else {
    //         puts("no");
    //     }
    // }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

using ll = long long;
const ll INF = 1e18 + 1;


ll ans = 0;
ll h,w, k;

map<string, ll> mp;


ll calc( vector<ll> val, vector<string> ch) {
    ll count = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (val[i] == 0 && val[h+j] == 0 && ch[i][j] == '#') {
                count++;
            }
        }

    }
    return count;
}

string create_str(vector<ll> val) {
    string str;
    for (int i = 0; i < val.size(); ++i) {
        str += (char)(val[i]);
    }
    return str;
}

void compute(vector<ll> val, ll idx, vector<string> ch) {

    if ( mp.find(create_str(val)) == mp.end() &&  calc(val, ch) == k) {
        ans++;
    }

    mp[create_str(val)]++;

    if (idx < val.size()) {
        compute(val, idx+1, ch);
        val[idx] = 1;
        compute(val, idx+1, ch);
    }

}



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

    cin >> h >> w >> k;
    vector<string> ch(h);

    for (int i = 0; i < h; ++i) {
        cin >> ch[i];
    }
    vector<ll> vec(h+w, 0);
    compute(vec, 0LL, ch);

    cout << ans << endl;





}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
const int64_t MAXN = 1e5 + 10;

int main()
{
  string S;
  cin >> S;
  vector<vector<int64_t>> DP(S.size() + 1, vector<int64_t>(13, 0));
  reverse(S.begin(), S.end());
  DP[0][0] = 1;
  int64_t n = 1; // 次の桁のベースの余り数
  for (int i = 0; i < S.size(); i++)
  {
    char c = S[i];
    int64_t r = 0;
    if (c == '?')
    {
      for (int j = 0; j < 13; j++)
      {
        for (int k = 0; k < 10; k++)
        {
          DP[i + 1][(j + k * n) % 13] += DP[i][j];
          DP[i + 1][(j + k * n) % 13] %= MOD;
        }
      }
    }
    else
    {
      int intc = c - '0';
      for (int j = 0; j < 13; j++)
      {
        DP[i + 1][(j + intc * n) % 13] += DP[i][j];
        DP[i + 1][(j + intc * n) % 13] %= MOD;
      }
    }
    n = (n * 10) % 13;
  }
  cout << DP[S.size()][5] << endl;
}


Measured memory_bytes: 13696
/*
	Created by Faisal Ahmed
*/

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int a, b, c;
	
	cin >> a >> b >> c;
	
	int d = a + b + c;
	
	if(d >= 22){
		cout << "bust" << endl;
	}
	else{
		cout << "win" << endl;
	}
	
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool three(int n);

int main(void){
	int n;

	cin >> n;
	for(int i = 3; i <= n; i++)
		if(three(i))
			cout << " " << i;
	cout << endl;
}

bool three(int n){
	if(!(n%3))
		return true;
	do{
		if(n%10 == 3)
			return true;
	}while(n /= 10);

	return false;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll cut(double len,vector<ll> a){
    ll res = 0;
    rep(i,a.size())res += ceil(a[i]/len) -1;
    return res;
}

//ミョ(-ω- ?)
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n,0);
    rep(i,n)cin >> a[i];
    long double l = 0;
    long double r = INF;
    rep(i,100){
        long double mid = l + (r - l)/2.0;
        if(k < cut(mid,a)){//切り刻みすぎた
            l = mid;
        }else r = mid;
    }
    cout << fixed << setprecision(0) << ceil(l) << "\n";
    return 0;
}

Measured memory_bytes: 6304
#include <stdio.h> 
 
 
 int main(){ 
     int m, f, r; 
     while(1){ 
         scanf("%d %d %d ", &m, &f, &r); 
         if(m==-1&&f==-1&&r==-1)break; 
         if(m==-1||f==-1){ 
             printf("F\n"); 
         }else if(m+f>=80){ 
             printf("A\n"); 
         }else if(m+f>=65){ 
             printf("B\n"); 
         }else if(m+f>=50){ 
             printf("C\n"); 
         }else if(m+f>=30){ 
             if(r>=50){ 
                 printf("C\n"); 
             }else{ 
                 printf("D\n"); 
             } 
         }else{ 
             printf("F\n"); 
         } 
     } 
     return 0; 
 } 


Measured memory_bytes: 2048
//Created Time:2020年03月19日 星期四 09时02分09秒
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 5003

using namespace std;

int n, cnt, m;
int to[N << 3], s[N << 3], t[N << 3], deg[N], fa[N], dep[N], f[N], st[N];
bool vis[N << 3], book[N];

vector<int> e[N], w[N];

void dfs(int ,int);
void get(int ,int);

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i < n; ++i){
		int u, v; scanf("%d%d", &u, &v);
		e[u].push_back(v); e[v].push_back(u);
		++deg[u]; ++deg[v];
	} dfs(1, 0);
	for(int i = 1; i <= m; ++i){
		scanf("%d%d", s + i, t + i);
		to[i] = i; get(s[i], t[i]);
		w[s[i]].push_back(i);
		w[t[i]].push_back(i);
	}
	int ans = 0;
	for(int i = 2; i <= n; ++i)
		if(f[i] > 1) ans += 2;
		else if(f[i] == 1) ++ans;
	printf("%d\n", ans);
	queue<int> Q; int num = m;
	for(int i = 1; i <= n; ++i)
		if(deg[i] == 1) Q.push(i);
	while(!Q.empty()){
		int u = Q.front(), p; Q.pop(); book[u] = true;
		int sz = e[u].size();
		for(int i = 0; i < sz; ++i){
			int v = e[u][i]; --deg[v];
			if(deg[v] == 1) Q.push(v);
			if(!book[v]) p = v;
		}
		sz = w[u].size(); int top = 0;
		for(int i = 0; i < sz; ++i){
			int x = w[u][i]; if(vis[x]) continue;
			st[++top] = x; vis[x] = true;
		}
		if(top & 1){
			int x = st[top--];
			if(s[x] != u) swap(s[x], t[x]);
			if(p != t[x]){
				to[x] = ++num; to[num] = num;
				s[num] = p; t[num] = t[x];
				w[p].push_back(num);
				w[t[x]].push_back(num);
			}
		}
		for(int i = 1; i <= top; i += 2){
			int x = st[i], y = st[i + 1];
			if(s[x] != u) swap(s[x], t[x]);
			if(s[y] != u) swap(s[y], t[y]);
			if(t[x] == t[y]) swap(s[y], t[y]);
			else{
				to[x] = ++num; to[y] = num;
				s[num] = t[x]; t[num] = t[y];
				to[num] = num;
				w[t[x]].push_back(num);
				w[t[y]].push_back(num);
			}
		}
	}
	for(int i = num; i; --i){
		int x = to[i];
		if(s[x] == t[i]) swap(s[i], t[i]);
	}
	for(int i = 1; i <= m; ++i)
		printf("%d %d\n", s[i], t[i]);
	return 0;
}

void dfs(int u, int f){
	fa[u] = f; dep[u] = dep[f] + 1;
	int sz = e[u].size();
	for(int i = 0; i < sz; ++i){
		int v = e[u][i]; if(v == f) continue;
		dfs(v, u);
	} return ;
}

void get(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	while(dep[x] > dep[y]) ++f[x], x = fa[x];
	if(x == y) return ;
	while(x != y) ++f[x], ++f[y], x = fa[x], y = fa[y];
	return ;
}

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

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

ll solve(vector<int> a, int k) {
	int n = (int) a.size();
	vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, -1'000'000'000'000'000LL));

	dp[0][0] = a[0];
	dp[1][0] = a[1];
	dp[0][1] = dp[1][1] = 0;

	for (int i = 2; i < n; i += 2) {
		dp[i][0] = dp[i - 2][0] + a[i];
		dp[i][1] = dp[i - 2][1];

		dp[i + 1][0] = max(dp[i - 1][0], dp[i - 2][0]) + a[i + 1];
		dp[i + 1][1] = max(dp[i - 1][1], dp[i - 2][1]);

		if (i >= 4) {
			dp[i][1] = max(dp[i][1], max(dp[i - 4][0], dp[i - 3][0]));
			dp[i + 1][1] = max(dp[i + 1][1], max(dp[i - 4][0], dp[i - 3][0]));
		}

		dp[i][1] += a[i];
		dp[i + 1][1] += a[i];
	}

	if (n % 2 == 1) {
		return max(dp[n - 3][0], max(dp[n - 2][0], dp[n - 1][1]));
	}

	return max(dp[n - 2][k], dp[n - 1][k]);
}

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

	int n;
	cin >> n;

	vector<int> a(n);

	for (int &x : a) {
		cin >> x;
	}

	if (n == 3) {
		cout << *max_element(a.begin(), a.end());
		return 0;
	}

	if (n % 2 == 0) {
		cout << solve(a, 0);
	} else {
		cout << solve(a, 1);
	}

	return 0;
}

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

int main() {
    int n;

    cin >> n;

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

    vector<int> ans(n, 0);
    for (int i = 1; i < n; i++) {
        ans[a[i]-1]++;
    }

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

    return 0;
}

Measured memory_bytes: 4844
# coding: utf-8
from itertools import *
import sys
import time


#################### library ####################


#################### naive ####################


#################### process ####################

def read_input():
	_ = raw_input()
	s = raw_input()
	v = s.split()
	return map(int, v)

def f(v):
	return reduce(max, (sum(1 for _ in w)
			   for k, w in groupby(h1 >= h2 for h1, h2 in zip(v, v[1:]))
			   if k), 0)


#################### main ####################

#t0 = time.clock()
v = read_input()
print f(v)


Measured memory_bytes: 45796
#include <stdio.h>
#include <ctype.h>

int main()
{
    char str[55];
    char ch;
    int n, k;

    scanf("%d %d", &n, &k);
    k--;

    for (int i = 0; i < n; i++) {
        scanf(" %c", &ch);

        if (i == k) {
            ch = tolower(ch);
        }

        putchar(ch);
    }
    putchar('\n');
    
    return 0;
}


Measured memory_bytes: 128
//CardGameforThree.cpp (B)
#include <iostream>
#include <string>
using namespace std;

int main(){
  string Sa,Sb,Sc;
  int a,b,c;
  a = 0,b = 0, c = 0;
  char F;
  cin >> Sa >> Sb >> Sc;
  F = Sa[0];
  ++a;
  while(a <= Sa.size()&&b <= Sb.size()&&c <= Sc.size()){
    if(F == 'a'){
      if(a < Sa.size()) F = Sa[a], ++a;
      else F = 'a', ++a;
    }else if(F == 'b'){
      if(b < Sb.size()) F = Sb[b], ++b;
      else F = 'b', ++b;
    }else{
      if(c < Sc.size()) F = Sc[c], ++c;
      else F = 'c', ++c;
    }
  }
  if(F == 'a') printf("A\n");
  else if(F == 'b') printf("B\n");
  else printf("C\n");

  return 0;
}


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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  ll C;
  cin >> N >> C;
  vector<ll> x(N), v(N), rv;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> v[i];
  }
  rv = v;
  reverse(rv.begin(), rv.end());
  vector<ll> a = v, b = rv;
  for (int i = 0; i + 1 < N; i++) {
    a[i + 1] += a[i];
    b[i + 1] += b[i];
  }
  for (int i = 0; i < N; i++) {
    a[i] -= x[i];
    b[i] -= C - x[N - i - 1];
  }

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, a[i]);
    ans = max(ans, b[i]);
  }
  vector<int> idxa(N, 0), idxb(N, 0);
  for (int i = 1; i < N; i++) {
    idxa[i] = idxa[i - 1];
    if (a[i] > a[idxa[i]]) idxa[i] = i;
    idxb[i] = idxb[i - 1];
    if (b[i] > b[idxb[i]]) idxb[i] = i;
  }
  for (int i = 0; i + 1 < N; i++) {
    ll sum = a[i] - x[i];
    sum += b[idxb[N - i - 2]];
    ans = max(ans, sum);
  }
  for (int i = 0; i + 1 < N; i++) {
    ll sum = b[i] - (C - x[N - i - 1]);
    sum += a[idxa[N - i - 2]];
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4992
N, K = map(int, raw_input().split())
a = [0]*N
b = [0]*N
for i in range(N):
  a[i], b[i] = map(int, raw_input().split())
sa = range(N)
sa.sort(key=lambda i:a[i])
c = 0
for i in range(N):
  c += b[sa[i]]
  if c >= K:
    print a[sa[i]]
    break

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

using namespace std;

// ord := rootを0とした時、DFSを行った時の順序番号
// lowlink := 頂点vからDFS木の葉方向の辺を0回以上、後退辺を0回以上1回以下通っていける頂点のordの最小値

vector<int> G[100010];
vector<pair<int, int>> bridge;
vector<int> Articulation;
int ord[100010], lowlink[100010];
bool visited[100010];
void dfs(int v, int p, int &k)
{
  visited[v] = true;

  ord[v] = k++;
  lowlink[v] = ord[v];

  bool isArticulation = false;
  int ct = 0;

  for (int i = 0; i < G[v].size(); i++)
  {
    if (!visited[G[v][i]])
    {
      ct++;
      dfs(G[v][i], v, k);
      lowlink[v] = min(lowlink[v], lowlink[G[v][i]]);

      if (~p && ord[v] <= lowlink[G[v][i]])
        isArticulation = true;

      if (ord[v] < lowlink[G[v][i]])
        bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
    }
    else if (G[v][i] != p)
    {
      lowlink[v] = min(lowlink[v], ord[G[v][i]]);
    }
  }

  //根の場合子が一つなら関節点ではなく、そうでなければ関節点
  if (p == -1 && ct > 1)
    isArticulation = true;

  if (isArticulation)
    Articulation.push_back(v);
}
int main()
{
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < m; i++)
  {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  int k = 0;
  for (int i = 0; i < n; i++)
  {
    if (!visited[i])
      dfs(i, -1, k);
  }

  sort(Articulation.begin(), Articulation.end());
  for (int i = 0; i < Articulation.size(); i++)
  {
    cout << Articulation[i] << endl;
  }
  return 0;
}

// Varify
// https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/3/GRL_3_A
// 参考
// npca2014年部誌 競技プログラミングで使えるグラフ理論の基本
// http://kagamiz.hatenablog.com/entry/2013/10/05/005213


Measured memory_bytes: 7108
object Main {
  def Print(x:Int){
    for(i<-1 to x) print("#")
    println()
  }
  def main(args:Array[String]){
    val sc=new java.util.Scanner(System.in)
    var tmp=false  
      while(true){
       val h,w=sc.nextInt
       if(tmp) println()
       if(h==0&&w==0) return
       Print(w)
       for(i<-1 to h-2;j<-1 to w){
         if(j==1||j==w) print("#")
         else print(".")
         if(j==w) println()
       }
       if(h!=1) Print(w)
       tmp=true
     }
  }
}

Measured memory_bytes: 53116
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


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

	int n;
	string s, t;
	cin >> n >> s >> t;
	int a = s.size() + t.size();
	for (int i = n;;i++) {
		if (a<i || s.substr(s.size() - (a-i)) == t.substr(0,a-i)) {
			cout << i << endl;
			break;
		}
	}


	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;

int yakusu(int x){
  int ans = 0;
  for(int i = 1; i <= x; i++){
    if(x % i == 0)
      ans++;
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  int x = 0;
  int ans = 0;
  while(2 * x + 1 <= n){
    if(yakusu(2 * x + 1) == 8){
      ans++;
      x++;
    }else x++;   
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s,S,T;
int main()
{
	cin>>s;
	if (s=="keyence")
	{
		puts("YES");
		return 0;
	}
	n=s.length();
	for (int i=0; i<n; ++i)
		for (int j=i+1; j<n; ++j)
		{
			S=""; T="";
			for (int k=0; k<=i; ++k) S+=s[k];
			for (int k=j; k<n; ++k) T+=s[k];
			if (S+T=="keyence")
			{
				puts("YES");
				return 0;
			}
		}
	puts("NO");
}

Measured memory_bytes: 256
sa = list(input())
sb = list(input())
sc = list(input())

card = sa.pop(0)
while 1:
    if card == "a":
        if sa == []:
            print("A")
            break
        else:
            card = sa.pop(0)

    elif card == "b":
        if sb == []:
            print("B")
            break
        else:
            card = sb.pop(0)

    else:
        if sc == []:
            print("C")
            break
        else:
            card = sc.pop(0)

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

l_max = 0
r_min = N
for i in range(M):
    l, r = map(int, input().split())
    if l > l_max:
        l_max = l
    if r < r_min:
        r_min = r

print(max(0, r_min - l_max + 1))

Measured memory_bytes: 3188
#include <stdio.h>
int main (void){
    int n,i,b,p,x,y,ans1,ans2=100000000;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d%d%d",&x,&y,&b,&p);
        ans1=x*b+y*p;
        if(b<5&&p<2){
            ans2=x*5+y*2;
        }
        else if(b<5&&p>=2){
            ans2=(x*5+y*p)*8/10;
        }
        else if(b>=5&&p<2){
            ans2=(x*b+y*2)*8/10;
        }
        else if(b>=5&&p>=2){
            ans2=ans1*8/10;
        }
        if(ans1<ans2)printf("%d\n",ans1);
        else if(ans2<=ans1) printf("%d\n",ans2);
    }
return 0;
}

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

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

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

map<string, int> v;

using state = string::const_iterator;

int parse(state &cur){
    int ans = 0;
    while(true){
        if(isupper(*cur)){
            string s(1, *cur);
            cur++;
            while(islower(*cur)){
                s += *cur;
                cur++;
            }
            if(!v.count(s)){
                return -1;
            }else {
                int k = 0;
                while(isdigit(*cur)) {
                    k = k*10+(*cur-'0');
                    cur++;
                }
                ans += v[s]*max(1, k);
            }
        }else if(*cur == '('){
            cur++;
            int x = parse(cur);
            if(x == -1) return -1;
            cur++;
            int k = 0;
            while(isdigit(*cur)) {
                k = k*10+(*cur-'0');
                cur++;
            }
            ans += k*x;
        }else break;
    }
    return ans;
}

int main() {
    string s;
    while(cin >> s, s != "END_OF_FIRST_PART"){
        int x;
        cin >> x;
        v[s] = x;
    }
    while(cin >> s, s != "0"){
        state cur = s.begin();
        int ans = parse(cur);
        if(ans == -1) puts("UNKNOWN");
        else cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3160
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    #r = stdin.readline()[:-1]
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #n = int(r)
    #a = r.split()
    #a,b,c = r.split()
    #a = list(map(int, r.split()))
    #a,b,c,d = map(int, r.split())
    #a = list(map(int, r.split()))
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #a = [list(map(int, input().split())) for i in range(1,n+1)]
    #res = 0

    a= list(map(int, input().split()))
    if len(set(a)) == 2:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  int count = 0 ;
  int N ;
  cin >> N ;
  vector<int> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  map<int,int> score ;
  rep(i,N){
    score[A.at(i)]++ ;
  }
  for(auto p : score ) {
  auto key = p.first ;
  auto value = p.second;
    if( value%2  ==  1 ) count++ ;
}
  cout << count << endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  vector<int> x(n);
  vector<int> y(m);

  REP(i, n) cin >> x[i];
  REP(i, m) cin >> y[i];

  ll xsum = 0;
  FOR(i, 1, n) {
    ll t = x[i] - x[i - 1] % mod;
    t = t * i % mod * (n - i) % mod;
    xsum = (xsum + t) % mod;
  }

  ll ysum = 0;
  FOR(i, 1, m) {
    ll t = y[i] - y[i -1] % mod;
    t = t * i % mod * (m - i) % mod;
    ysum = (ysum + t) % mod;
  }

  cout << (xsum * ysum % mod) << endl;
}


Measured memory_bytes: 1024
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	while (true) {
		LL h = -1, w = -1, a, b;
		cin >> h >> w >> a >> b;
		if (h <= 0 || w <= 0) break;
		for (int i = 0; i < h; ++i) {
			string s;
			if (i < b) {
				s = string(a, '0') + string(w - a, '1');
			} else {
				s = string(a, '1') + string(w - a, '0');

			}
			cout << s << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)cout << "Possible";
	else cout << "Impossible";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int l, r, d;
    cin >> l >> r >> d;
    int cnt = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <iostream>
 #include <vector>
 #include <map>
 #include <string>
 #include <algorithm>
 using namespace std;

 template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

 typedef long long ll;
 const long long INF = 1LL << 60;



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

   int data[15][15];
   for(int i = 0; i < 15; i++)
   {
       for(int j = 0; j < 15; j++)
       {
           data[i][j] = -1;
       }
   }

   for(int i = 0;i < n; i++)
   {
       int a;
       cin >> a;
       for(int j = 0; j < a;j++)
       {
           int x, y;
           cin >> x >> y;
           x--;
           data[i][x] = y;
       }
   }

    /*for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(j) cout << " ";
            cout << data[i][j];
        }
        cout << endl;
    }*/

   int ans = 0;

   for(int i = 0; i < (1<<n); i++)
   {
       bool flag = true;
       for(int j = 0; j < n; j++)
       {
           if(i>>j&1)
           {
               for(int k = 0; k < n; k++)
               {
                   if(data[j][k] == -1) continue;
                   if(data[j][k] != (i>>k&1)) flag = false;
               }
           }
       }
       if(flag)
       {
            ans = max(ans, __builtin_popcount(i));
            //cout << i << endl;
       }
   }

   cout << ans << endl;


    return 0;
 }

Measured memory_bytes: 256
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
mod=998244353
inv=pow(2,mod-2,mod)
S=sum(A)

dp=[0 for j in range(S+1)]
sub=[0 for j in range(S+1)]
dp[0]=pow(2,N,mod)
dp[A[0]]=pow(2,N-1,mod)
sub[0]=1
sub[A[0]]=1

for i in range(1,N):
    for j in range(S,A[i]-1,-1):
        dp[j]=(dp[j]+inv*dp[j-A[i]])%mod
        sub[j]=(sub[j]+sub[j-A[i]])%mod

if S%2==1:
    ans=pow(3,N,mod)
    for i in range((S+1)//2,S+1):
        ans-=3*dp[i]
        ans%=mod
    print(ans)
else:
    ans=pow(3,N,mod)
    for i in range((S+1)//2,S+1):
        ans-=3*dp[i]
        ans%=mod
    ans+=3*sub[S//2]
    ans%=mod
    print(ans)


Measured memory_bytes: 78984
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
  int64_t v;
  Mint() { v = 0; }
  Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

  Mint operator-() { return Mint{-v}; };
  Mint operator+(Mint x) { return Mint(v + x.v); };
  Mint operator-(Mint x) { return Mint(v - x.v); };
  Mint operator*(Mint x) { return Mint(v * x.v); };
  Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

  Mint& operator+=(Mint x) { return *this = (*this + x); };
  Mint& operator-=(Mint x) { return *this = (*this - x); };
  Mint& operator*=(Mint x) { return *this = (*this * x); };
  Mint& operator/=(Mint x) { return *this = (*this / x); };

  static Mint pow(Mint base, int64_t exp) {
    if(exp == 0)  return Mint(1);
    return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
  }

  friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<998244353>;

template<class T, int N> struct Polynomial {
  deque<T> f;
  Polynomial() { f.assign(N, T{}); }
  Polynomial(deque<T> f) : f(f) {}
  Polynomial(Polynomial &g) : f(g.f) {}

  void operator+=(Polynomial g) { for(int i=0; i<N; i++) f[i]+=g[i]; }
  void operator>>=(int c) { while(c--) f.push_front(T{}), f.pop_back(); }
  void operator<<=(int c) { while(c--) f.push_back(T{}), f.pop_front(); }
  void operator*=(T c) { for(auto& e : f) e *= c; }

  Polynomial operator+(Polynomial g) { auto r=Polynomial(f); r+=g; return r; }
  Polynomial operator>>(int c) { auto r=Polynomial(f); r>>=c; return r; }
  Polynomial operator<<(int c) { auto r=Polynomial(f); r<<=c; return r; }
  Polynomial operator*(T c) { auto r=Polynomial(f); r*=c; return r; }

  T& operator[](int i) { return f[i]; }
};

int main() {
  lint N, S;
  cin >> N >> S;

  vector<lint> A(N);
  for(auto& elem : A)  cin >> elem;

  using P = Polynomial<mint, 3123>;
  P f; f[0] = 1;
  for(auto a : A) f = (P(f)*2) + (P(f)>>a);
  cout << f[S] << endl;
}

Measured memory_bytes: 3860
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
  if p[i-1] < p[i] and p[i] < p[i+1]:
    ans+=1
  elif p[i-1] > p[i] and p[i] > p[i+1]:
    ans+=1
print(ans)

Measured memory_bytes: 9116
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static void Write(object obj) {
#if DEBUG
        Debug.Write(obj.ToString());
#else
        Console.Write(obj.ToString());
#endif
    }
    static void WriteLine(object obj) {
#if DEBUG
        Debug.WriteLine(obj.ToString());
#else
        Console.WriteLine(obj.ToString());
#endif
    }

    static long mod = 1000000007;

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var k     = int.Parse(spl[1]);

        var l = n - k;

        for(int i=1; i<=k; i++) {
            WriteLine(Calc(k, l, i));
        }
        return null;
    }

    static long Calc(long b, long r, long i) {
        var ptn = CombinationMod(r + 1, i);

        var oneptn = CombinationMod(b - 1, i - 1);

        return ptn * oneptn % mod;
    }

    static long CombinationMod(long m, long n) {
        Func<long, long, long> ModPow = (x1, x2) => {
            long ans = 1;
            while (x2 > 0) {
                if (x2 % 2 == 1) {
                    ans = (ans * x1) % mod;
                }
                x1 = (x1 * x1) % mod;
                x2 /= 2;
            }
            return ans % mod;
        };

        var a = 1L;
        var b = 1L;
        for(long i=1; i<=n; i++) {
            a = (a * (m - i + 1)) % mod;
            b = (b * i) % mod;
        }

        long bb = ModPow(b, mod - 2);
        return (a * bb) % mod;
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		while(true){
			int H=scan.nextInt();
			int W=scan.nextInt();
			
			if(H==0 && W==0)break;
			
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 36408
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int x, a, b;
	scanf("%d%d%d", &x, &a, &b);
	printf("%s\n", abs(x - a) < abs(x - b) ? "A" : "B");
	
	Please AC;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <iostream>

using namespace std;

void swap(string *a,string *b)
{
	string c;

	c = *b;
	*b = *a;
	*a = c;
}

int selection_sort(int n,string *a)
{
	int min;
	int ans=0;
	for(int i=0;i<n;i++){
		min = i;
		for(int j = i;j<n;j++){
			if(a[j][1] < a[min][1]){
				min = j;
			}
		}
		if(i != min){
			swap(&a[i],&a[min]);
			ans++;
		}
	}

	return ans;
}

int bubble_sort(int n,string *a)
{
	int flag = 1;
	int ans=0;

	while(flag){
		flag = 0;
		for(int i=n-1;i>0;i--){
			if(a[i][1] < a[i-1][1]){
				swap(&a[i],&a[i-1]);
				ans++;
				flag = 1;
			}
		}
	}

	return ans;
}

int main()
{
	int n;
	scanf("%d",&n);

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


	int ans=0;
	ans = bubble_sort(n,a);	
	for(int i=0;i<n;i++){
		cout << a[i];
		if (i < n-1)
			printf(" ");
	}
	printf("\n");
	printf("Stable\n");

	selection_sort(n,a1);	
	for(int i=0;i<n;i++){
		cout << a1[i];
		if (i<n-1)
			printf(" ");
	}
	printf("\n");

	int f=0;
	for(int i=0;i<n;i++){
		if(a[i][0] != a1[i][0]){
			f = 1;
			break;
		}
	}
	if(f == 1){
		printf("Not stable\n");
	}
	else{
		printf("Stable\n");
	}

	return 0;
}



Measured memory_bytes: 3256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    int res = max(res, a + a - 1);
    res = max(res, b + b - 1);
    res = max(res, a + b);

    cout << res << '\n';


    return 0;
}

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

int main() {
  ll a,b,k;
  cin >> a >> b >> k;
  a-=k;
  if(a<=0) {
    b+=a;
    a=0;
  }
  if(b<0) {
    b=0;
  }
  cout << a << " " << b << endl;
}

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


const int N = 1e5 + 10, M = 998244353;
int n, a[N];
int dp[N];
bool flag[N];
int solve(int i) {
	if (i == n - 1) {
		return 0;
	}
	if (flag[i]) {
		return dp[i];
	}
	else {
		if (i == n - 2) {
			dp[i] = abs(a[i] - a[i + 1]) + solve(i + 1);
		}
		else {
			dp[i] = min(abs(a[i] - a[i + 1]) + solve(i + 1), abs(a[i] - a[i + 2]) + solve(i + 2));
		}
		flag[i] = true;
		return dp[i];
	}
}
int main() {


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

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	cout << solve(0) << endl;
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n,k;
cin >> n >> k;
map<int,int> a;
for(int i = 0; i < n; i++){
    int b,c;
    cin >> b >> c;
    a[b] += c;
} 
int sum = 0;
for(int i = 1; i <= 100000; i++){
    sum += a[i];
    if(sum >= k)
    {
        cout << i << endl;
        return 0;
    }
}
}


Measured memory_bytes: 6528
class UnionFind
  def initialize(n)
    @size = Array.new(n + 1, 1)
    @rank = Array.new(n + 1, 0)
    @parent = []

    (0..n).each do |i|
      @parent[i] = i
    end
  end

  def find(x)
    if @parent[x] == x
      x
    else
      @parent[x] = find(@parent[x])
    end
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return if x == y

    if @rank[x] < @rank[y]
      @parent[x] = y
      @size[y] += @size[x]
    else
      @parent[y] = x
      @size[x] += @size[y]

      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def size(x)
    @size[find(x)]
  end
end

N, M = gets.split.map(&:to_i)

edges = M.times.map { gets.split.map(&:to_i) }

uf = UnionFind.new(N)
cnt = (1..(N - 1)).inject(:+)
ans = [cnt]

edges.reverse_each do |a, b|
  if uf.find(a) != uf.find(b)
    cnt -= uf.size(a) * uf.size(b)
  end

  uf.unite(a, b)

  ans << cnt
end

puts ans[0..-2].reverse


Measured memory_bytes: 14920
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
    
ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 47340
#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(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
		a[i]--;
	}
	int cnt = 0;
	int sta = 0;
	while(1){
		sta = a[sta];
		cnt++;
		if(sta == 1){
			cout << cnt << endl;
			return 0;
		}
		if(cnt >= n+1){
            cout << -1 << endl;return 0;
        }
    }
}


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

int main(){
    int ABCD;
    cin >> ABCD;
    int A, B, C, D;
    int N[4];
    for (int i = 0; i < 4; i++){
        N[3 - i] = ABCD % 10;
       // cout << N[3 -i] << endl;
        ABCD = ABCD / 10;
    }
    int B2[2] = {-N[1], N[1]};
    int C2[2] = {-N[2], N[2]};
    int D2[2] = {-N[3], N[3]};
    int ii, jj, kk;
    for (int i = 0; i < 2; i++){
        for (int j = 0; j < 2; j++){
            for (int k = 0; k < 2; k++){
                if (N[0] + B2[i] + C2[j] + D2[k] == 7){
                ii = i; jj = j; kk = k;
                goto OUT; 
                }
            }
        }
    }
    OUT:
    string sig = "-+";
    cout << N[0] << sig[ii] << N[1] << sig[jj] << N[2] << sig[kk] << N[3] << "=7" <<  endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <map>

using namespace std;
typedef long long LL;
const int maxn = 800005;
const LL inf = 1ll<<50;
int n,a[maxn],b[maxn],K;LL s[maxn];
LL disc[maxn],_[maxn],ans=inf;int tot;

namespace ST {
	#define ls rt<<1
	#define rs rt<<1|1
	bool tag[maxn];LL val[maxn],mi[maxn];
	void assign(int rt) {
		tag[rt]=true;val[rt]=mi[rt]=inf;
	}
	void pushdown(int rt) {
		if (tag[rt]) {
			tag[rt]=false;assign(ls);assign(rs);
		}
	}
	void update(int rt) {
		mi[rt]=min(mi[ls],mi[rs]);
	}
	void modify(int rt,int L,int R,int p,LL w)
	{
		if (L>=R) {
			tag[rt]=false;val[rt]=w;mi[rt]=w-disc[L];
			return ;
		}
		int mid=L+R>>1;pushdown(rt);
		if (p<=mid) modify(ls,L,mid,p,w);
		else modify(rs,mid+1,R,p,w);
		update(rt);
	}
	void build(int rt,int L,int R)
	{
		if (L>=R) {
			mi[rt]=-disc[L];
			return ;
		}
		int mid=L+R>>1;
		build(ls,L,mid);
		build(rs,mid+1,R);
		update(rt);
	}
	void assign(int rt,int L,int R,int l,int r)
	{
		if (l>r||tag[rt]) return ;
		if (L>=l&&R<=r) {
			assign(rt);return ;
		}
		int mid=L+R>>1;pushdown(rt);
		if (l<=mid) assign(ls,L,mid,l,r);
		if (r>mid) assign(rs,mid+1,R,l,r);
		update(rt);
	}
	LL query(int rt,int L,int R,int l,int r)
	{
		if (L>=l&&R<=r) return mi[rt];
		int mid=L+R>>1;pushdown(rt);LL res=inf;
		if (l<=mid) res=min(res,query(ls,L,mid,l,r));
		if (r>mid) res=min(res,query(rs,mid+1,R,l,r));
		return res;
	}
	void getans(int rt,int L,int R)
	{
		if (L>=R) {
			ans=min(ans,val[rt]);return ;
		}
		int mid=L+R>>1;pushdown(rt);
		getans(ls,L,mid);
		getans(rs,mid+1,R);
	}
}
using namespace ST;
int main()
{
	#ifdef Amberframe
		freopen("agc011f.in","r",stdin);
		freopen("agc011f.out","w",stdout);
	#endif
	scanf("%d %d",&n,&K);disc[++tot]=0;
	for (int i=1;i<=n;i++) {
		scanf("%d %d",&a[i],&b[i]);
		s[i]=s[i-1]+a[i];_[i]=-2ll*s[i]%K;
		_[i]<0?_[i]+=K:0;disc[++tot]=_[i];
		if (b[i]==1&&a[i]*2ll>K) {puts("-1");exit(0);}
	}
	sort(disc+1,disc+tot+1);
	tot=unique(disc+1,disc+tot+1)-disc-1;
	build(1,1,tot);
	
	for (int i=1;i<=n;i++)
	{
		int v=lower_bound(disc+1,disc+tot+1,_[i-1])-disc;
		int u=lower_bound(disc+1,disc+tot+1,_[i])-disc;
		LL dpu=min(query(1,1,tot,1,u),query(1,1,tot,u,tot)+K)+disc[u];
		LL dpv=min(query(1,1,tot,1,v),query(1,1,tot,v,tot)+K)+disc[v];
		modify(1,1,tot,u,dpu);
		modify(1,1,tot,v,dpv);
		if (b[i]==2) continue;
		if (u<v) {
			assign(1,1,tot,u+1,v-1);
		}
		if (u>=v) {
			assign(1,1,tot,1,v-1);
			assign(1,1,tot,u+1,tot);
		}
	}
	getans(1,1,tot);
	printf("%lld",ans+(s[n]<<1));
	return 0;
}

Measured memory_bytes: 18688
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int c[N],a[N],b[N],d=0,e=0,f=0,g=0;
int main(){
	int n=read();
	for (int i=1;i<=n;i++){
		c[i]=read();
	}
	for (int i=1;i<=n;i+=2){
		a[c[i]]++;
		if (c[i]==d) continue;
		if (a[c[i]]>a[d]){ e=d;d=c[i];}
		else if (a[c[i]]>a[e]) e=c[i];
	}
	for (int i=2;i<=n;i+=2){
		b[c[i]]++;
		if (c[i]==f) continue;
		if (b[c[i]]>b[f]){g=f; f=c[i];}
		else if (b[c[i]]>b[g]) g=c[i]; 
	}
	if (d==f&&g==0&&e==0){printf("%d\n",n/2); return 0;}
	if (d==f){if (a[d]+b[g]>b[f]+a[e]) swap(f,g); else swap(d,e); }
	int ans=0;
	for (int i=1;i<=n;i+=2)
	if (c[i]!=d) ans++;
	for (int i=2;i<=n;i+=2)
	if (c[i]!=f) ans++;
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    ll arr[n];
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    int l = 0;
    ll st = 1000;
    ll ct = 0;
    while(l < n)
    {
        int r = l;
        while(r < n-1 && arr[r] <= arr[r+1])
        {
            r++;
        }
        if(arr[r] > arr[l])
        {
            ct += st/arr[l];
            st -= (st/arr[l]) * arr[l];
            st += ct * arr[r];
            ct = 0;
        }
        l = r+1;
    }
    cout << st;
    return 0;
}


Measured memory_bytes: 3612
S = list(input())
T = list(input())
s = len(S)
t = len(T)
l = []
for i in range(s-t+1):
    c = 0
    for j in range(t):
        if S[i+j] != T[j]:
            c += 1
    l.append(c)
print(min(l))

Measured memory_bytes: 65300
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

#include<bits/stdc++.h>
using namespace std;

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    vmax(a)        *max_element(all(a))
#define    vmin(a)        *min_element(all(a))
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"Yes"<<nn
#define    no             cout<<"No"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }
ll power(ll n , ll k) { if(k == 0) return 1 ; if(k&1) return n*sqr(power(n,k/2)) ; else return sqr(power(n,k/2)); }

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;
const   int dx[] =   {+1,+2,+2,+1,-1,-2,-2,-1};
const   int dy[] =   {-2,-1,+1,+2,+2,+1,-1,-2};

int main() {ikarus_101

    ll n,m,i,j,k,x;



    cin>>n;
    cout << sqr(n) << nn;









    return 0;
}


Measured memory_bytes: 3640
import sys
input = sys.stdin.readline

S = input().strip()
T = input().strip()
dic = {}

for s, t in zip(S, T):
    if s not in dic:
        dic[s] = t
    elif dic[s] != t:
        print('No')
        exit()

if len(dic) != len(set(dic.values())):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3632
import sys
from collections import deque
from collections import  Counter
import statistics
import math

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b, c, d = na()
if (abs(a - b) <= d and abs(b - c) <= d) or abs(a -c) <=d:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5132