akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=1e5+10;
struct edge{int nxt,to;}e[MAXN<<2];
ll res=0;
int lca,dep[MAXN],sum[MAXN],f[MAXN];
int n,m,fx,fy,head[MAXN],x,y,tot,TOT,cnt,t[MAXN];

void add_edge(int x,int y)
{
	e[++TOT]=(edge){head[x],y};head[x]=TOT;
	e[++TOT]=(edge){head[y],x};head[y]=TOT;
}
void dfs(int x,int anc,int val)
{
	sum[x]=val;tot+=val;
	dep[x]=dep[anc]+1;f[x]=anc;
	for(int i=head[x];i;i=e[i].nxt)
		if(e[i].to!=anc)
		{
			if(dep[e[i].to]) 
			{fx=x;fy=e[i].to;continue;}
			dfs(e[i].to,x,-val),sum[x]+=sum[e[i].to];	
		}
}
int LCA(int x,int y)
{
	if(dep[x]<dep[y]) swap(x,y);
	int t=dep[x]-dep[y];
	for(int i=1;i<=t;i++) x=f[x];
	while(x!=y) x=f[x],y=f[y];
	return x;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d%d",&x,&y),add_edge(x,y);
	dfs(1,0,1);
	
	if(m==n-1)
	{
		if(tot) return puts("-1"),0;
		for(int i=1;i<=n;i++) res+=abs(sum[i]);
	}
	else if((dep[fx]-dep[fy])%2==0)
	{
		if(tot%2) return puts("-1"),0;
		lca=LCA(fx,fy);tot=-tot/2;res+=abs(tot);
		
		for(int k=fx;k;k=f[k]) sum[k]+=tot;
		for(int k=fy;k;k=f[k]) sum[k]+=tot;
		for(int i=1;i<=n;i++) res+=abs(sum[i]);
	}
	else
	{
		if(tot) return puts("-1"),0;
		lca=LCA(fx,fy);
		for(int k=fx;k!=lca;k=f[k]) 
			t[++cnt]=sum[k],dep[k]=-1;
		for(int k=fy;k!=lca;k=f[k])
			t[++cnt]=-sum[k],dep[k]=-1;
		t[++cnt]=0;
		sort(t+1,t+cnt+1);int val=t[cnt/2];
		
		for(int i=1;i<=n;i++)
			if(~dep[i]) res+=abs(sum[i]);
		for(int i=1;i<=cnt;i++)
			res+=abs(t[i]-val);
	}
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 8960
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author arauf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int x = 100 * in.nextInt() + 10 * in.nextInt() + in.nextInt();

            if (x % 4 == 0) out.println("YES");
            else out.println("NO");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int read() {
            if (numChars == -1) throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <ctime>
#include <queue>
#include <deque>
#include <unordered_map>
#include <map>
#include <random>
#include <cstdio>
#include <string>
#include <cctype>
#define int long long
#define pb push_back
#define eb emplace_back
#define rs resize
#define ld long double
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define ull unsigned long long 

using namespace std;

const int SZ = (int)1e6 + 228;

void solve() {
    char ch;
    cin >> ch;
    if (ch >= 'a' && ch <= 'z') {
        cout << "a\n";
    }
    else cout << "A\n";
}

signed main() {
    //freopen("olympiad.in", "r", stdin);
    //freopen("olympiad.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    cout.precision(30);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    //   system("pause");
}

Measured memory_bytes: 3024
#include "stack"
#include "stdio.h"
#include "cstdlib"
#include "iostream"
using namespace std;

int main() {
  stack<int> S;
  string s;
  int a, b;

  while(cin >> s){
    if(s[0]=='+') {
      a = S.top(); S.pop();
      b = S.top(); S.pop();
      S.push(a+b);
    }
    else if(s[0]=='-') {
      b = S.top(); S.pop();
      a = S.top(); S.pop();
      S.push(a-b);
    }
    else if(s[0]=='*') {
      a = S.top(); S.pop();
      b = S.top(); S.pop();
      S.push(a*b);
    }
    else {
      S.push(atoi(s.c_str()));
    }
  }

  printf("%d\n", S.top());

  return 0;
}

Measured memory_bytes: 3256
n = int(input())
ans = [0 for i in range(n+1)]
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
            #print(x, y, z, tmp)
            if 1 <= tmp and tmp <= n:
                ans[tmp] += 1
for i in range(1, n+1):
    print(ans[i])


Measured memory_bytes: 69752
import java.util.Scanner;

public class Main {
	
	static int[] s;
	static int max = 1000000001;
	static long count =0;
	
	static void merge(int s[], int left,int mid,int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1+1];
		int[] R = new int[n2+1];
		for(int i=0;i<n1;i++) {
			L[i] = s[left + i];
		}
		L[n1] = max;
		for(int i=0;i<n2;i++) {
			R[i] = s[mid + i];
		}
		R[n2] = max;
		
		for(int i=0, j=0, k=left;k<right;k++) {
			if(L[i] <= R[j]) {
				s[k] = L[i];
				i++;
			}else {
				s[k] = R[j];
				j++;
				count += n1-i;
			}
		}
	}
	
	static void mergeSort(int s[],int left,int right) {
		if(left + 1 < right) {
			int mid = (left + right)/2;
			mergeSort(s,left,mid);
			mergeSort(s,mid,right);
			merge(s,left,mid,right);
		}
	}
	
	void main() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		s = new int[n];
		for(int i=0;i<n;i++) {
			s[i] = sc.nextInt();
		}
		
		int left = 0;
		int right = n;
		mergeSort(s,left,right);
		
//		System.out.print(s[0]);
//		for(int i=1;i<n;i++) {
//			System.out.print(" " + s[i]);
//		}
//		System.out.println();
		System.out.println(count);
	}

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

}



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

int main(){
    int N,K;
    cin >> N >> K;
    int ans=1;
    for(int i=0;i<N;i++){
        ans=min(ans*2,ans+K);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!.toCharArray()
    val maxE = s.sumBy { if (it == 'E') 1 else 0 }
    var e = 0
    var w = 0
    val tnl = mutableListOf<Int>()
    for (c in s) {
        if (c == 'E') e++
        tnl.add(w + maxE - e)
        if (c == 'W') w++
    }
    println(tnl.min())
}

Measured memory_bytes: 39520
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;



int main(){
   int n;
   cin >> n;
   vector<ll> a(n);
   rep(i, n)cin >> a[i];
   ll res = 0, m = 1;
   rep(i, n){
      if(a[i] == m)m = a[i] + 1;
      else {
         res += (a[i] / m);
         if(a[i] % m == 0)res--;
      }
     //cout << m << endl;
      if(m == 1)m++;
   }
   cout << res << endl;
}


Measured memory_bytes: 4032
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {

    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    while(true){
        C -= B;
        if(C <= 0){
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if(A <= 0){
            cout << "No" << endl;
            break;
        }
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int maxn = 300001;
long long n, ans;
// set < pair < long long, long long > > res;
int main(){
	// ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	long long lim = sqrt(n);
	for(long long i = 1;i <= lim;++i){
		if(n % i == 0){
			long long a = i, b = n / i;
			if(b - 1 > a)ans += b - 1;
		}
	}
	cout << ans << '\n';
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, q;
string s[100005];
char buf[400005];
int k;
string t;

int nx[444444][26] = {};
int len[444444][26] = {};
int cn[444444][26] = {};
int trc[444444] = {};
int where[444444];
bool fin[444444] = {};
int cnt[444444] = {};
int nodeCount = 1;

void add(string s) {
    int pos = 0;
    for (char cc : s) {
        ++cnt[pos];
        int c = cc - 'a';
        if (!nx[pos][c]) {
            ++trc[pos];
            where[pos] = c;
            len[pos][c] = 1;
            nx[pos][c] = nodeCount++;
        }
        pos = nx[pos][c];
    }
    ++cnt[pos];
    fin[pos] = true;
}

int main() {
    //freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    forn(i, n) {
        scanf("%s", buf);
        s[i] = string(buf);
    }

    for (string x : s) {
        add(x);
    }

    for (int i = nodeCount - 1; i >= 0; --i) {
        forn(j, 26) if (nx[i][j]) {
            int pos = nx[i][j];
            if (trc[pos] == 1 && !fin[pos]) {
                nx[i][j] = nx[pos][where[pos]];
                len[i][j] = 1 + len[pos][where[pos]];
            }
        }
    }

    forn(i, nodeCount) forn(j, 26) if (nx[i][j]) {
        cn[i][j] = cnt[nx[i][j]];
    } else {
        cn[i][j] = 0;
    }

    scanf("%d", &q);
    forn(zzz, q) {
        scanf("%d%s", &k, buf), --k;
        t = string(buf);
        string &s = ::s[k];
        int sz = (int)s.length();
        int pos = 0;
        int ans = 0;
        for (int ind = 0; ind < sz; ) {
            forn(i, 26) {
                if (s[ind] == t[i]) {
                    ind += len[pos][t[i] - 'a'];
                    pos = nx[pos][t[i] - 'a'];
                    if (fin[pos]) {
                        ++ans;
                    }
                    break;
                }
                ans += cn[pos][t[i] - 'a'];
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

int main()
{
	int n;
	long x, havepati = 0;
	cin >> n >> x;
	long pati = (long)pow(2.0, n + 2) - 3;
	if (n == 0) {
		cout << 1 << endl;
		return 0;
	}
	while (pati >5) {
		if (x * 2 == pati + 1) {
			cout << havepati + (long)pow(2.0, n) - 1 + 1 << endl;
			return 0;
		}
		else if (x >= pati - 1) {
			cout << havepati + (long)pow(2.0, n + 1) - 1 << endl;
			return 0;
		}
		else if (x * 2 > pati + 1) {
			havepati += (long)pow(2.0, n) - 1 + 1;
			x -= (pati + 1) / 2;
			n--;
			pati = (pati + 3) / 2 - 3;
		}
		else {
			x--;
			n--;
			pati = (pati + 3) / 2 - 3;
		}
	}
  	if(x!=0)
	cout << (x<5? havepati + x - 1 : havepati + 3)<< endl;
	else
      	cout << havepati << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int tall[5000];
int idx=0;

int main(){
while(~scanf("%d",tall+idx)){
idx++;
}

sort(tall,tall+idx,greater<int>());

for(int i=0;i<3;i++){
printf("%d\n",tall[i]);
}

}

Measured memory_bytes: 0
#include<iostream>

using namespace std;

int main(void)
{
	int a, b, c, gcd;
	int count;
	while(cin >> a >> b >> c){
		count = 0;
		for(int i = a; i <= b; i++){
			gcd = c%i;
			if(gcd == 0)
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

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

main()
{
    long int num1,num2,s,k1,k2;
    int count =0;
    scanf("%ld %ld",&num1,&num2);

    s= ((num1 + num2)/2) ;

    k1= abs(num1-s);
    k2= abs(num2-s);

    if(k1 == k2)
        printf("%ld\n",s);
    else
        printf("IMPOSSIBLE\n");


    return 0;
}






Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	String N = sc.next();
    	sc.close();
    	String ans = "No";
    	if((N.charAt(0) == N.charAt(1) &&
    			N.charAt(1) == N.charAt(2)) ||
    			(N.charAt(1) == N.charAt(2) &&
    			N.charAt(2) == N.charAt(3))) ans = "Yes";
    	System.out.println(ans);
    }
}

Measured memory_bytes: 23764
N=int(input())
s=[]
for i in range(N):
  s.append(sorted(list(input())))
s.sort()
ans=0
ren=1
for i in range(1,N):
  if s[i]==s[i-1]:
    ren+=1
  else:
    ans+=ren*(ren-1)//2
    ren=1
ans+=ren*(ren-1)//2
print(ans)

  


Measured memory_bytes: 98264
/*
СТРОИМ СТЕНУ РАБОТЯГИ!
█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
int x[MAXN];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n;
	scanf("%d", &n);
	int a, b;
	scanf("%d %d", &a, &b);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &x[i]);
	}
	ll res = 0;
	for (int i = 2; i <= n; i++)
	{
		res += min(1LL * (x[i] - x[i - 1]) * a, (ll)b);
	}
	printf("%lld\n", res);
}



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

lli n;

int main(void){
	cin >> n;
	unordered_map<lli, lli> mp;
	rep(i, n){
		lli a;
		cin >> a;
		mp[a]++;
	}
	lli ans = 0;
	for(auto i : mp){
		if(i.first <= i.second) ans+=i.second-i.first;
		else ans+=i.second;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7280
N = int(input())
X_N = list(map(int, input().split()))
tmp = sorted(X_N)
mid_r = tmp[N//2]
mid_l = tmp[N//2-1]
result = []
for i in range(N):
    if X_N[i]<=mid_l:
        result.append(mid_r)
    else:
        result.append(mid_l)
for i in range(N):
    print(result[i])

Measured memory_bytes: 25556
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
const int MOD = 998244353;
template <typename Int, Int MOD, int N>
struct comb_util {
	std::array<Int, N + 1> fc, ifc;

	comb_util() {
		fc[0] = 1;
		for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
		ifc[N] = inv(fc[N]);
		for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
	}

	Int fact(Int n) { return fc[n]; }

	Int inv_fact(Int n) { return ifc[n]; }

	Int inv(Int n) { return pow(n, MOD - 2); }

	Int pow(Int n, Int a) {
		Int res = 1, exp = n;
		for (; a; a /= 2) {
			if (a & 1) res = res * exp % MOD;
			exp = exp * exp % MOD;
		}
		return res;
	}

	Int perm(Int n, Int r) {
		if (r < 0 || n < r)
			return 0;
		else
			return fc[n] * ifc[n - r] % MOD;
	}

	Int binom(Int n, Int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
	}

	Int homo(Int n, Int r) {
		if (n < 0 || r < 0) return 0;
		return r == 0 ? 1 : binom(n + r - 1, r);
	}
};


#define int long long
using comb = comb_util<long long, 998244353, 10000010>;
comb C;
void add(int &a, const int &b) {
	a += b;
	if (a >= MOD)a -= MOD;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int sum = 0;
	int res = 1;
	for (int i = 0; i < N; i++) {
		res = (res * 3) % MOD;
	}
	int t = 0;
	for (int i = (N / 2) + 1; i <= N; i++) {
		add(t, C.binom(N, i) * C.pow(2, N - i) % MOD);
	}
	t = (t * 2) % MOD;
	res = (res - t + 2 * MOD) % MOD;
	
	cout << res << endl;
}

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

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int s;
map<int, int> m;

int main(void)
{
  cin >> s;
  int i = 1;
  m[s]++;
  while (1) {
    i++;
    if (s % 2 == 0)
      s = s / 2;
    else
      s = 3 * s + 1;
    if (m.count(s) > 0) break;
    m[s]++;
  }
  cout << i << endl;
  return 0;
}


Measured memory_bytes: 888
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n, q; cin >> n >> q;
    string s; cin >> s;

    ll a[100001]; INITA(a, 0, 100000, 0);
    ll tmp = 0;
    FOR(i, 1, s.size()-1) {
        if (s[i-1] == 'A' && s[i] == 'C') {
            tmp++;
        }
        a[i] = tmp;
    }

    REP(i, q) {
        ll l, r; cin >> l >> r;
        cout << a[r-1] - a[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 4492
#!/usr/bin/env python
# coding: utf-8


def table_to_string(table):
    lines = []
    for row in table:
        line = ""
        for num in row:
            line += "% 4d" % num
        lines.append(line)
    return "\n".join(lines)


def get_answer(n):
    table = [[0 for i in xrange(n)] for j in xrange(n)]
    x = (n - 1) / 2
    y = (n - 1) / 2 + 1
    for i in xrange(1, n * n + 1):
        while 1:
            if x == n:
                x = 0
            elif x == -1:
                x = n - 1
            if y == n:
                y = 0
            if table[y][x]:
                x -= 1
                y += 1
                continue
            else:
                break
        table[y][x] = i
        x += 1
        y += 1
    return table_to_string(table)


def main():
    params = []
    while 1:
        param = int(raw_input())
        if not param:
            break
        params.append(param)

    for param in params:
        print get_answer(param)

if __name__ == '__main__':
    main()

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

using ll = long long;
static const int MAX = 2e5;
static const ll MOD = 1e9 + 7;

// 隣接リストを用いた深さ優先探索（再帰ver.） O(|V|+|E|)
vector<int> color(MAX, 0);

void dfs(const vector<vector<int>> &G, int u, int &n, vector<ll> &d, vector<vector<ll>> &branch) {
  color[u] = 1; // GRAY
  ll sz = 1, rest = n - 1;
  for (int i = 0; i < G[u].size(); i++) {
    if (color[G[u][i]] == 0) {
      dfs(G, G[u][i], n, d, branch);
      sz += d[G[u][i]];
      branch[u].emplace_back(d[G[u][i]]);
      rest -= d[G[u][i]];
    }
  }
  color[u] = 2; // BLACK
  d[u] = sz;
  if (rest > 0) branch[u].emplace_back(rest);
  return;
}

// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if (n % 2 == 0) res = (res * res) % m;
    else res = (((res * res) % m) * x) % m;
  }
  return res;
}

ll modinv(ll x) {
  return power(x, MOD - 2, MOD);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 無向(有向)グラフの隣接リスト
  int n; // n:頂点数
  cin >> n;
  
  vector<vector<int>> G(n); // G:頂点数nのグラフの隣接リスト
  
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u); // 有向グラフではコメントアウト
  }
  
  vector<ll> subtree_size(n, 1);
  vector<vector<ll>> branch(n);
  dfs(G, 0, n, subtree_size, branch);
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll keep = power(2, n - 1, MOD);
    keep--; // all white
    for (int j = 0; j < branch[i].size(); j++) {
      keep -= power(2, branch[i][j], MOD) - 1; // only one branch is not "all white"
      keep += MOD;
    }
    keep %= MOD;
    ans += keep;
    ans %= MOD;
  }
  
  ans *= modinv(power(2, n, MOD)); // all pattern
  ans %= MOD;
  
  cout << ans << '\n';
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	ll N, D; cin >> N >> D;
	vector<ll> X(N), Y(N);
	ll ans = 0;
	for(int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
		if(X[i] * X[i] + Y[i] * Y[i] <= D * D) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6428
def train(c,s,f,t):
    if t < s:
        t = s
    while (t-s)%f != 0:
        t += 1
    return t+c


N = int(input())
C = []
S = []
F = []
t = 0
for n in range(N-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for n in range(N):
    t = 0
    for i in range(n,N-1):
        t = train(C[i],S[i],F[i],t)
    print(t)

Measured memory_bytes: 3188
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef string Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
//Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	map<pii,ll>ma;
	rep(i,1<<n){
		string a="",b="";
		rep(j,n)if(i&1<<j)a+=s[j];
		else b+=s[j];
		ma[{a,b}]++;
	}
	ll out=0;
	rep(i,1<<n){
		string a="",b="";
		rep(j,n)if(i&1<<j)a+=s[2*n-1-j];
		else b+=s[2*n-1-j];
		out+=ma[{a,b}];
	}
	cout<<out<<endl;
}







Measured memory_bytes: 91904
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
 


int main() {
	string st;
	vector<int>nums(26);
	while (getline(cin, st)) {

		for (auto c : st) {
			if (c <= 'z'&&c >= 'a')nums[c - 'a']++;
			if (c <= 'Z'&&c >= 'A')nums[c - 'A'] ++;
		}
	}
	for (int i = 0; i < 26; ++i) {
		cout << char('a' + i) << " : " << nums[i] << endl;
	}
	return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    string s,t;
    cin >> s >> t;
    vector<vi> dp(3030,vi(3030,0));
    s = 'S' + s;
    t = 'T' + t;
    int x = s.size(),y = t.size();
    rep(i,x){
        rep(j,y){
            if(s[i]==t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }else{
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    string ans ="";
    while(x>0 && y>0){
        if(dp[x][y]==dp[x][y-1]){
            y--;
        }else if(dp[x][y]==dp[x-1][y]){
            x--;
        }else/* if(dp[x][y]==dp[x-1][y-1])*/{
            x--;y--;
            ans += s[x];
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 36224
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    a-=500*(a/500);
    if (a<=b) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

using namespace std;

int main(int argc, const char * argv[]) {
    string S;
    cin >> S;

    char c = S[0];

    for(int i = 1; i < S.length(); i++) {
        if(c == S[i]) {
            cout << "Bad" << endl;
            return 0;
        }
        c = S[i];
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define INF 1000000000000000000
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	sort(h.begin(), h.end(), greater<ll>()); // 降順ソート
	ll sum = 0;
	for (int i = k; i < n; i++) {
		sum += h[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
from bisect import bisect_left, bisect_right

def count(x, li1, li2, p):
    cnt = 0
    now = len(li2)-1 if p else 0
    for ind, i in enumerate(li1):
        rng = range(now, -1, -1) if p else range(now, len(li2))
        for j in rng:
            if p and ind==j:
                continue
            if i*li2[j]<x:
                # print(cnt, ind, j)
                cnt += j+1 if p else len(li2)-j
                cnt -= 1 if p and ind<j else 0
                now = j
                break
        else:
            break
    return cnt//2 if p else cnt

def bisect(ok, ng, solve):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok

def p_solve(x):
    tmp = count(x, posi, posi, True)
    tmp += count(x, nega[::-1], nega[::-1], True)
    # print(x, tmp)
    return np*nn+nn*nz+nz*np+nz*(nz-1)//2+tmp < k

def n_solve(x):
    return count(x, nega, posi, False) < k


n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
nega = a[:bisect_left(a, 0)]
posi = a[bisect_right(a, 0):]
np = len(posi)
nn = len(nega)
nz = n - np - nn
if k <= np*nn:
    ans = bisect(nega[0]*posi[-1]-1, 0, n_solve)
elif k <= np*nn+nn*nz+nz*np+nz*(nz-1)//2:
    ans = 0
else:
    ma = 0
    if len(nega)>1:
        ma = nega[0]*nega[1]
    if len(posi)>1 and ma<posi[-1]*posi[-2]:
        ma = posi[-1]*posi[-2]
    ans = bisect(1, ma+1, p_solve)
print(ans)


Measured memory_bytes: 141436
/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
typedef long long Long;
void FastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
}

const int N = 1e5;

int main()
{
  FastIO();
  int tc, ca = 0;
  string s;
  cin >> s;
  cout << s[0]<<s[1]<<s[2] << '\n';
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int sum;
	int i;
	while(1){
		cin>>n;
		if(cin.eof())	break;
		sum=0;
		for(i=n;i<=600;i+=n){
			sum+=n*pow((i-n),2);
		}
		cout<<sum<<endl;
	}
	return 0;
}



Measured memory_bytes: 3052
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=2e6+5,mod=1e9+7;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    string s;cin>>s;
    if(s.length()<26){
        cout<<s;
        for(char ch='a';ch<='z';ch++)if(s.find(ch)==string::npos)return cout<<ch , 0;
    }
    string t=s;
    bool flg = next_permutation(s.begin(),s.end());
    if(!flg)return cout<<"-1" , 0;

    ll i=0;
    while(i<s.size() && s[i]==t[i])cout<<s[i++];
    cout<<s[i];
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define mii map<int,int>


using namespace std;

ll power(ll a,ll b){
	if(b==0)
		return 1;
	if(b%2==1)
		return power(a,b/2)*power(a,b/2)*a;
	else
		return power(a,b/2)*power(a,b/2);
}

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

    int c=0;
    while(n!=0){
    	c++;
    	n>>=1;
    }

    cout<<power(2,c)-1<<endl;
}

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

int main(){
  int N;
  cin >> N;
  int i = 0;
  
  while (1){
    if (i * 1000 < N){
      i++;
    }
    else{
      break;
    }
  }
    cout << i * 1000 - N << endl; 
}

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

string S;

bool isdiverse(string V) {
	for (int i = 0; i < V.size(); i++) {
		for (int j = i + 1; j < V.size(); j++) {
			if (V[i] == V[j]) return false;
		}
	}
	return true;
}

int main() {
	cin >> S;
	for (int i = S.size(); i >= 0; i--) {
		int t = 'a'; if (i < S.size()) t = S[i] + 1;
		for (char j = t; j <= 'z'; j++) {
			string V = S.substr(0, i);
			V += j;
			if (isdiverse(V) == true) {
				cout << V << endl;
				return 0;
			}
		}
	}
	cout << "-1" << endl;
	return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<int> s(100,1000);
  int sum=0;
  rep(i,n){
    cin>>s[i];
    sum+=s[i];
  }
  
  sort(s.begin(),s.end());
  
  
  
  if(sum%10==0){
    int a=sum;
    rep(i,n){if(s[i]%10 !=0){
      a=s[i];
      break;
    }
            }
    cout<<sum-a<<endl;
  }
  else{cout<<sum<<endl;
      }
    
        
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        SortedMap<Integer, Integer> histogram = new TreeMap<>();
        for(int i=0; i<n; i++) {
            int a = in.nextInt();
            if(histogram.containsKey(a)) {
                histogram.put(a, histogram.get(a)+1);
            }
            else {
                histogram.put(a, 1);
            }
        }
        SortedMap<Integer, Integer> replacements = new TreeMap<>();
        for(int i=0; i<m; i++) {
            int b = in.nextInt();
            int c = in.nextInt();
            if(replacements.containsKey(c)) {
                replacements.put(c, replacements.get(c)+b);
            }
            else {
                replacements.put(c, b);
            }
        }
        Iterator<Integer> it = replacements.keySet().iterator();
        while(it.hasNext()) {
            int c = it.next();
            int b = replacements.get(c);
            while(true) {
                int a = histogram.firstKey();
                if(a >= c) {
                    break;
                }
                int count = histogram.get(a);
                if(count<=0) {
                    histogram.remove(a);
                    continue;
                }
                int consumed = Math.min(count, b);
                int newCount = histogram.get(a)-consumed;
                histogram.put(a, newCount);
                if(newCount<=0) {
                    histogram.remove(a);
                }

                if(histogram.containsKey(c)) {
                    histogram.put(c, histogram.get(c)+consumed);
                }
                else {
                    histogram.put(c, consumed);
                }
                b -= consumed;
                if(b<=0) {
                    break;
                }
            }
        }

        long sum = 0;
        it = histogram.keySet().iterator();
        while(it.hasNext()) {
            int a = it.next();
            sum += (long)a * (long)histogram.get(a);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 110820
////////////////////////////////////
///     Please Give Me AC!!!     ///
////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int N; cin>> N;
    int D1, D2;
    int cnt = 0;
    rep(i, N){
        cin>> D1 >> D2;
        if(D1 == D2){
            cnt++;
        }else{
            cnt = 0;
        }
        if(cnt >= 3){
            cout<< "Yes" << endl;
            return 0;
        }
    }
    cout<< "No" << endl;
}

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

Measured memory_bytes: 47892
#include<bits/stdc++.h>
#define inf (1<<28)
#define maxn 100000
using namespace std;
int d[100000];
struct heapnode{
	int u,*pos;
	bool operator<(const heapnode &a)const{return d[u]<d[a.u];}
	heapnode(int u=0,int *pos=NULL):u(u),pos(pos){}
};
struct heap{
	heapnode h[maxn+10];
	int sz;
	void hswap(int a,int b){
		swap(h[a],h[b]);
		*h[a].pos=a;
		*h[b].pos=b;
	}
	void up(int o){
		while(o>1){
			int f=o>>1;
			if(h[o]<h[f])hswap(o,f),o=f;
			else break;
		}
	}
	void down(int o){
		for(;;){
			int lc=o<<1;
			if(lc>sz)break;
			int t=lc;
			if(sz>lc){
				int rc=lc+1;
				if(h[rc]<h[lc])t=rc;
			}
			if(h[t]<h[o])hswap(t,o),o=t;
			else break;
		}
	}
	void push(int u,int *pos){
		h[++sz]=heapnode(u,pos);
		*pos=sz;
		up(sz);
	}
	void pop(int o){
		hswap(o,sz--);
		update(o);
	}
	void update(int o){
		up(o);
		down(o);
	}
}H;
int id[100000];
int main(){
	int k;
	cin>>k;
	d[0]=inf;
	for(int i=1;i<min(10,k);i++)d[i]=i;
	for(int i=10;i<k;i++)d[i]=inf;
	for(int i=0;i<k;i++)H.push(i,&id[i]);
	for(;;){
		int u=H.h[1].u;
		if(!u)break;
		H.pop(1);
		for(int c=0;c<10;c++){
			int v=(10*u+c)%k;
			if(d[v]>d[u]+c)d[v]=d[u]+c,H.update(id[v]);
		}
	}
	cout<<d[0]<<endl;
	return 0;
}

Measured memory_bytes: 2560
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    s: Chars
    }
    let ns = s.iter().map(|&x| x.to_digit(10).unwrap() as usize).collect::<Vec<usize>>();
    let n = ns.len();
    let mut zero_count = 0;
    let mut one_count = 0;
    let mut ans = 0;
    for i in 0..n {
        if ns[i] == 0 {
            if one_count > 0 {
                ans += 2;
                one_count -= 1;
            } else {
                zero_count += 1;
            }
        } else {
            if zero_count > 0 {
                ans += 2;
                zero_count -= 1;
            } else {
                one_count += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 3324
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int h, w, k;
  cin >> h >> w >> k;
  char c[6][6];
  rep(i, h) rep(j, w) cin >> c[i][j];
  int ans = 0;
  rep(b1, 1 << h)
  {
    rep(b2, 1 << w)
    {
      int cnt = 0;
      rep(i, h) rep(j, w)
      {
        if (b1 & (1 << i))
          continue;
        if (b2 & (1 << j))
          continue;
        if (c[i][j] == '#')
          cnt++;
      }
      if (cnt == k)
        ans++;
    }
  }
  cout << ans << "\n";
}

int main()
{
  init_main();
  solve();

  return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}

int main() {
  ll X; cin >> X;

  ll ans_a = 0;
  ll ans_b = 0;
  bool flag = false;
  for(int i = -1000; i <= 1000; ++i) {
    for(int k = -1000; k <= 1000; ++k) {
      // cout << k << " " << i << " " << pow(i, 5) - pow(k, 5) << " " << X << endl;
      if(pow(i, 5) - pow(k, 5) == X) {
        ans_a = i;
        ans_b = k;
        flag = true;
        break;
      }
    }

    if(flag == true) break;
  }

  cout << ans_a << " " << ans_b << endl;
}

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

using namespace std;

using vec = vector<int>;
using mat = vector<vec>;

int n = 0;
int mod = 1;

vec mvmul(const mat& m, const vec& v) {
    vec res(n);
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            res[i] += m[i][j] * v[j];
        }
        res[i] %= mod;
    }
    return res;
}

mat mmul(const mat& a, const mat& b) {
    mat res(n, vec(n));
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            for(int k=0; k<n; k++) {
                res[i][j] += a[i][k] * b[k][j];
            }
            res[i][j] %= mod;
        }
    }
    return res;
}

mat mpow(const mat& m, int t) {
    mat res(n, vec(n));
    mat a = m;
    for(int i=0; i<n; i++) res[i][i] = 1;
    while(t) {
        if(t&1) res = mmul(res, a);
        a = mmul(a, a);
        t >>= 1;
    }
    return res;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, t;
    while(cin >> n >> mod >> a >> b >> c >> t, n) {
        vec v(n);
        for(int i=0; i<n; i++) cin >> v[i];
        mat m(n, vec(n));
        for(int i=0; i<n; i++) m[i][i] = b;
        for(int i=1; i<n; i++) {
            m[i][i-1] = a;
            m[i-1][i] = c;
        }
        vec res = mvmul(mpow(m, t), v);
        cout << res[0];
        for(int i=1; i<n; i++) cout << " " << res[i];
        cout << endl;
    }
    
}



Measured memory_bytes: 3276