akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
int main()
{
	char c;
	cin >> c;
	if(c=='A') cout << 'T';
	if(c=='T') cout << 'A';
	if(c=='C') cout << 'G';
	if(c=='G') cout << 'C';

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e10 + 10;;
unsigned long long fac[200001];

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}
long long digits(long long m) {
    long long cnt = 0;
    while (m) {
        cnt++;
        m /= 10;
    }
    return cnt;
}

unsigned long long power(unsigned long long x, unsigned long long y){
    unsigned long long res = 1;
    x = x % MOD;

    while (y > 0) {
        // If y is odd, multiply x with result 
        if (y & 1)
            res = (res * x) % MOD;

        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % MOD;
    }
    return res;
}
unsigned long long modInverse(unsigned long long n) {
    return power(n, MOD - 2);
}

long long nCr(long long n, long long r) {
    if (r > n) return 0;
    return (fac[n] * modInverse(fac[r]) % MOD * modInverse(fac[n - r]) % MOD) % MOD;
}

long long bfs(vector<int> g, queue<int> q) {
    return 1ll;
}

int main() {

    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        a[i] = l + i;
        sum += a[i];
    }
    int mn = 999999;
    int pos = -1;
    for (int i = 0; i < n; i++) {
        if (abs(a[i]) < mn) {
            mn = abs(a[i]);
            pos = i;
        }
    }
    sum -= a[pos];
    cout << sum;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <set>
#include <algorithm>
using namespace std;
int main(void){
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        h -= a.at(i);
    }
    if(h>0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
   long long x,a,b,n;

   scanf("%lld %lld %lld",&a,&b,&n);
   if (n<b) printf("%lld\n",a*n/b-n/b*a);
   else     printf("%lld\n",a*(b-1)/b);
   return 0;
}


Measured memory_bytes: 1728
#include <stdio.h>

void trace(int *A, int N){
    int i;
    for(i=0;i < N;i++){
        if(i > 0)printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertion_sort(int *A, int N){
    int i, j, v;

    for(i = 1;i<N;i++){
        v=A[i];
        j=i-1;

        while(j>=0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, N);
    }


}


int main(){
    int N, i, j;
    int A[100];

    scanf("%d", &N);

    for(i = 0;i<N;i++){
        scanf("%d", &A[i]);
    }

    trace(A,N);
    insertion_sort(A,N);

    return 0;
}


Measured memory_bytes: 2728
def main():
    n = int(input())
    mod = 10**9+7
    dp = [1, 0, 0, 0]
    for i in range(n):
        dp2 = [0, 0, 0, 0]
        dp2[0] = (dp[0]*8) % mod
        dp2[1] = (dp[0]+dp[1]*9) % mod
        dp2[2] = (dp[0]+dp[2]*9) % mod
        dp2[3] = (dp[1]+dp[2]+dp[3]*10) % mod
        dp = dp2
    print(dp[3])


main()


Measured memory_bytes: 64068
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  vector<int> v;
  vector<int> ans;
  cin >> N;
  for(int i=0;i<N;i++){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  for(int i=0;i<N;i++){
    if(v[i] == ans.size() + 1){
      ans.push_back(v[i]);
    }
  }
  if(ans.size() == 0){
    cout << -1 << endl;
    return 0;
  }
  cout << v.size() - ans.size() << endl;
 
  return 0;
}


Measured memory_bytes: 2548
/** 
 *  Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1];
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node { int parent,left,right; };

Node T[MAX];
int n,D[MAX],H[MAX];

void Depth(int u,int d){
  if( u == NIL) return;
  D[u] = d;
  Depth(T[u].left,d + 1);
  Depth(T[u].right,d + 1);
}

int Height(int u){
  int h1 = 0,h2 = 0;

  if(T[u].left != NIL) h1 = Height(T[u].left) + 1;
  if(T[u].right != NIL) h2 = Height(T[u].right) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int Sibling(int u){
  if(T[u].parent == NIL) return NIL;
  if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) return T[T[u].parent].left;
  if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",Sibling(u));
  int deg = 0;
  if(T[u].left != NIL) deg++;
  if(T[u].right != NIL) deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }
  else if(T[u].left == NIL && T[u].right == NIL){
    printf("leaf\n");
  }
  else {
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root = 0;

  scanf("%d",&n);

  for(int i = 0;i < n;i++) T[i].parent = NIL;

  for(int i = 0;i < n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL) T[l].parent = v;
    if(r != NIL) T[r].parent = v;
  }

  for(int i = 0;i < n;i++) if(T[i].parent == NIL) root = i;

  Depth(root,0);
  Height(root);

  for(int  i = 0;i < n;i++) print(i);

  return 0;
}



Measured memory_bytes: 2744
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
    int n;
    int s[5];
    while (true) {
        int total_max = 0;
        int total_min = 500;
        cin >> n;
        if (n == 0) {
            break;
        }
        for (int i=0; i<n; i++) {
            for (int j=0; j<5; j++) {
                cin >> s[j];
            }
            total_max = max(total_max, accumulate(s, s+5, 0));
            total_min = min(total_min, accumulate(s, s+5, 0));
        }
        cout << total_max << ' ' << total_min << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    a, b = map(int, input().split())
    if a <= 0 and b >= 0:
        return "Zero"
    elif a > 0:
        return "Positive"
    else:
        return "Positive" if (b - a + 1) % 2 == 0 else "Negative"

print(main())


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int box[300000];
int cpy[300000];
int x[300000],y[300000];
int main(void){
	int cnt,ans;
	int a,b;
	int n,q;
	int i;
	int flg;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>box[i];
		cpy[i]=box[i];
	}
	sort(cpy,cpy+n);
	cnt=0;
	for(i=0;i<n;i++){
		if(box[i]!=cpy[i]){
			cnt++;
		}
	}
	cin>>q;
	for(i=0;i<q;i++)	cin>>x[i]>>y[i];
	flg=0;
	if(cnt==0)	flg=1;
	if(flg==0){
		ans=-1;
		for(i=0;i<q;i++){
			a=x[i]-1;	b=y[i]-1;
			if(cpy[a]==box[a])	cnt++;
			if(cpy[b]==box[b])	cnt++;
			swap(box[a],box[b]);
			if(cpy[a]==box[a])	cnt--;
			if(cpy[b]==box[b])	cnt--;
			if(cnt==0){
				ans=i+1;
				break;
			}
		}
	}
	if(flg==1)	cout<<0<<endl;
	else		cout<<ans<<endl;
	return 0;
}


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


int main()
{
	int k;
	cin>> k;
	vector<int> p(8), q(8), order(8);
	for(int i=0;i<k;i++){
		cin>> p[i] >> q[i];
	}
	
	for(int i=0;i<8;i++){
		order[i] = i;
	}
	do{
		bool flag = false;
		for(int i=0;i<k;i++){
			if(order[p[i]]!=q[i]){
				flag = true;
				break;
			}
		}
		if(flag) continue;
		for(int i=1;i<8;i++){
			for(int j=0;j<8;j++){
				if(i != j && abs(i-j) == abs(order[i]-order[j])){
					flag = true;
					break;
				}
			}
		}
		if(flag) continue;
		if(!flag) break;
	}while(next_permutation(order.begin(), order.end()));
	
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			if(j<7&&order[i]==j){
				cout<<"Q";
			}else if(j<7&&order[i]!=j){
				cout<<".";
			}
			if(j==7&&order[i]==j){
				cout<<"Q"<<endl;
			}else if(j==7&&order[i]!=j){
				cout<<"."<<endl;
			}
		}
	}
}



Measured memory_bytes: 3108
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)

bool in(int target, int max) { return 0 <= target && target < max - 1; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  int ans = 0;
  if (A >= 13) {
    ans = B;
  } else if (A < 13 && A >= 6) {
    ans = B / 2;
  } else if (A < 6) {
    ans = 0;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
   int n,nn;
   cin>>n;
   nn=n;
   int t=0;
   while(n)
   {
       t+=n%10;
       n/=10;
   }
   if(nn%t==0)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;
    return 0;
}


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

static const int INF = (1<<29);
int N,s[110];

int main(){
  cin >> N;
  for(int i=0;i<110;i++) s[i] = INF;
  for(int i=0;i<N;i++) cin >> s[i];

  int total = 0;
  for(int i=0;i<N;i++) total += s[i];

  if(total%10==0){
    int m=0;
    sort(s,s+N);
    while(s[m]%10==0){
      m++;
    }
    if(m<N) total -= s[m];
    else total = 0;
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int[] a = new int[n];
    int[] a_sort = new int[n];
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(in.readLine());
      a_sort[i] = a[i];
    }
    
    Arrays.sort(a_sort);
    
    for(int i=0; i<n; i++) {
      System.out.println(a_sort[n-1]!=a[i]?a_sort[n-1]:a_sort[n-2]);
    }
  }
}

Measured memory_bytes: 59432
#include<stdio.h>

int main(void){
	int n,k,i,a;
	int ans = 0;
	int buf = 0;
	scanf("%d %d", &n, &k);
	
	for(i = 0; i < n; i++){
		scanf("%d", &a);
	}
	ans = (n + k - 3) / (k - 1);
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
typedef long long ll;
ll n,k;
int main(){
    cin>>n>>k;
    if(n == 0 || n == 1) puts("1");
    else {
        int cnt= 0;
        while(n){
            cnt++;
            n/=k;
        }
        cout<<cnt<<endl;
    }

    return 0;
}

Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int R = Integer.parseInt(reader.readLine());
    System.out.println(2*R*Math.PI);
  }
}

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

int main(){
    int n;
	vector<int> List;
	int count = 0;
	
    cin >> n;
	
	for(int i = 0; i < n; i++){
		int Value;
		cin >> Value;
		List.push_back(Value);
	}
	
	bool Flag = true;
	
	while(Flag){
		Flag = false;
		for(int j = n - 1; j > 0; j--){
			if(List[j] < List[j-1]){
				int Temp;
				Temp = List[j];
				List[j] = List[j-1];
				List[j-1] = Temp;
				Flag = true;
				count++;
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		if(i > 0)	cout << " ";
		cout << List[i];
	}
	cout << endl;
	
	cout << count << endl;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
vector<ull> allPrimes;

const int mod = 1e9 + 7 ;
void sieve(int n)
{
    vector<bool> prime(n+1, true);

    // Loop to update prime[]
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it
        // is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Store primes in the vector allPrimes
    for (int p=2; p<=n; p++)
        if (prime[p])
            allPrimes.push_back(p);
}
ull factorialDivisors(ull n)
{
    sieve(n);
    ull result = 1;
    for (int i=0; i < allPrimes.size(); i++)
    {
        ull p = allPrimes[i];
        ull exp = 0;
        while (p <= n)
        {
            exp = exp + (n/p);
            p = p*allPrimes[i];
        }
        result = result*(exp+1);
        result = result % mod ;
    }

    // return total divisors
    return result % mod;
}

// Driver program to run the cases
int main()
{
    int n ;
    cin >> n ;
    cout << factorialDivisors(n);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main(){
	int n;
	cin>>n;
	bool f=true;
	char a[111][11];
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i>=2){
			for(int j=1;j<i;j++)
				if(strcmp(a[i],a[j])==0){
					f=false;
					break;
				}
						
		}
	}
	if(f==false){
		cout<<"No"<<endl;
		return 0;
	}
	int t[100];
	for(int i=1;i<=n;i++)
		t[i]=strlen(a[i]);
	for(int i=1;i<n;i++){
		if(a[i][t[i]-1]!=a[i+1][0])
			f=false;
	}
	if(f==false)
		cout<<"No"<<endl;
	else 
		cout<<"Yes"<<endl;
}

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

int main(void)
{
	 double a, b, c, d, e, f, x, y;
	 while(cin >> a >> b >> c >> d >> e >> f){
	 	x = (b * f - c * e) / (b * d - a * e) + 0.0001;
	 	y = (a * f - d * c) / (a * e - b * d) + 0.0001;
	 	printf("%.3f %.3f\n", x, y);
	 }
}

Measured memory_bytes: 1240
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if l[i] != l[j]:
            for k in range(j+1,n):
                if l[i] != l[k] and l[j] != l[k]:
                    if l[i] + l[j] > l[k]:
                        ans += 1

print(ans)

Measured memory_bytes: 9192
/*BISMILLAH
THE WHITE WOLF*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 1000003
#define pii pair<int, int>

int main()
{
    io;
    int n;
    cin>>n;
    bool apr = 1;
    while(n--)
    {
        int x;
        cin>>x;
        if(!(x&1))
        {
            if((x%3)&&(x%5))
                apr = 0;
        }
    }
    if(apr)
        cout <<"APPROVED";
    else
        cout <<"DENIED";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

nex = 1
ans = []

for i in range(len(a)):
  if nex == a[i]:
    ans.append(a[i])
    nex = (nex + 1)

if len(ans) == 0:
  print(-1)
else:
  print(len(a) - len(ans))

Measured memory_bytes: 26268
from sys import stdin
N = int(stdin.readline().rstrip())

C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)

for n in range(N-1):
    c, s, f = [int(x) for x in stdin.readline().rstrip().split()]
    C[n] = c
    S[n] = s
    F[n] = f

t = 0
for i in range(N-1):
    for j in range(i,N-1):
        if t < S[j]:
            t = S[j]
        elif (t-S[j])%F[j] == 0:
            pass
        else:
            t = S[j] + (((t - S[j])//F[j])+1)*F[j]

        t += C[j]
    print(t)
    t = 0
print(0)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long l;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SONI ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn=5e5+15;
const int maxm=5000+15;
const int mod=1e9+9;
const int inf=0x3f3f3f3f;
const int MOD=1000000007;

int main()
{
    SONI;
    int n;cin>>n;
    long double p_heads;
    vector<long double> dp(n+1);
    dp[0]=1;
    for(int coin=0;coin<n;coin++)
    {
        cin>>p_heads;
        for(int i=coin+1;i>=0;i--)
        {
            dp[i]=(i==0 ? 0 : dp[i-1]*p_heads) + dp[i]*(1-p_heads);
        }
    }
    
    long double ans = 0;
    for(int i=n/2+1;i<=n;i++)
    {
        ans = ans + dp[i];
    }
    
    cout<<fixed<<setprecision(12)<<ans;
    return 0;
}

Measured memory_bytes: 384
C = []

for i in range(5):
	C.append(int(input()))

k = int(input())

result = "Yay!"
for i in range(5):
	for j in range(i+1,5):
#		print(C[j] - C[i])
		if C[j] - C[i] > k:
			result = ":("

print(result)


Measured memory_bytes: 2940
N = int(input())
C = {i:0 for i in range(1,N+1)}
for x in range(1,142):
    for y in range(1,142):
        for z in range(1,142):
            k = (x+y)**2+(y+z)**2+(z+x)**2
            if k%2==0 and k//2<=N:
                C[k//2] += 1
for i in range(1,N+1):
    print(C[i])

Measured memory_bytes: 69164
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(int i=(int)(n);i<(int)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int i;
  int n,sum=0;
  string s;
  cin>>n>>s;
  s+=' ';
  rep(i,0,n){
    if(s.at(i)!=s.at(i+1))
      ++sum;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;
int main(){
	int a[3], b[3];
	for (int i=0;i<3;i++){
		cin >> a[i] >> b[i];
	}
	int rin[4][4];
	for (int i=0;i<4;i++){
		for (int j = 0;j<4;j++){
			rin[i][j] = 0;
		}
	}
	for (int i=0;i<3;i++){
		rin[a[i]-1][b[i]-1] = 1;
      	rin[b[i]-1][a[i]-1] = 1;
	}
	int last = 0;
	int loop = 1;
	int check[4] = {1,0,0,0};
	while (loop){
      	loop = 0;
		for(int i=0;i<4;i++){
			if(rin[last][i] == 1 && check[i] == 0){
				last = i;
				check[i] = 1;
				loop = 1;
              	break;
			}
		}
	}
	if (check[0] == 1 && check[1] == 1 && check[2] == 1 && check[3] == 1){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}


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

using namespace std;

int main(){
  string devide[4]={"erase","eraser","dream","dreamer"};
  
  string S;
  cin >> S;
  
  reverse(S.begin(),S.end());
  for(int i=0;i<4;i++) reverse(devide[i].begin(),devide[i].end());
  
  bool can=true;
  int i=0;
  while(i<S.size()){
    bool can2=false;
    for(int j=0;j<4;j++){
      string d=devide[j];
      if(S.substr(i,d.size())==d){
        can2=true;
        i+=d.size();
      }
    }
    if(!can2){
      can=false;
      break;
    }
  }
  if(can) {cout << "YES" << endl;}
  else cout << "NO" << endl;
}


Measured memory_bytes: 512
n,m = map(int,input().split())
a = [list(list(input())) for i in range(n)]
b = [list(list(input())) for i in range(n)]
cout = 0

for i in range(n):
    for j in range(m):
        if a[i][j] != b[i][j]:
            cout += 1
print(cout)



Measured memory_bytes: 76468
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int n;
    while(cin >> n && n){
        vector<pair<int,int>> minato={};
        ll child,mother;
        REP(i,1,2*sqrt(n)){
            child = 2*n-i*i-i;
            mother = 2*i;
            if(child%mother==0){
                minato.push_back(make_pair(child/mother+1,i));
            }
        }
        int pos,max=0;
        REP(i,0,minato.size()){
            if(minato[i].first>0){
                if(max<minato[i].second){
                    pos=minato[i].first;
                    max=minato[i].second;
                }
            }
        }
        P2(pos,max);
    }
}


Measured memory_bytes: 3128
from functools import reduce
INF = int(1e9+7)


def primeFactor(n, pf):
    # 素因数分解
    if n == 1:
        return
    f = 2
    while (f * f <= n):
        if (n % f == 0):
            pf[f] += 1
            n = n // f
        else:
            f += 1
    pf[n] += 1


def main():
    N = int(input())
    pf = [0] * (N + 1)
    for i in range(1, N + 1):
        primeFactor(i, pf)
    print(reduce(lambda x, y : x * (y + 1) % INF, pf, 1))
    return


main()


Measured memory_bytes: 3572
# include "algorithm"
# include "iostream"
# include "cstdio"
# include "cmath"

using namespace std;

const int maxm=1e5+10;

int N;

struct thing{
	long long A;
	long long B;
	long long C;
	# define A(x) Thing[x].A
	# define B(x) Thing[x].B
	# define C(x) Thing[x].C
}Thing[maxm];

inline bool Comp(thing a,thing b){return a.C>b.C;}

int main(){
	register int i;
	register long long Ans=0;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		scanf("%lld%lld",&A(i),&B(i));
		C(i)=A(i)+B(i);
		Ans-=B(i);
	}
	sort(Thing+1,Thing+1+N,Comp);
	for(i=1;i<=N;i+=2) Ans+=C(i);
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 2560
// 0529.cpp : 定义控制台应用程序的入口点。
//
#ifndef ONLINE_JUDGE
#define _CRT_SECURE_NO_WARNINGS
#define gets(str) gets_s(str)
#endif

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define INF 999999
using namespace std;


int main()
{
	int n, sum = 0, ave = 0;
	int a[105];
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	ave = (int)round((float)sum / n);
	sum = 0;
	for (int i = 1; i <= n; i++)
		sum += (a[i] - ave)*(a[i] - ave);
	cout << sum << endl;

#ifndef ONLINE_JUDGE
	printf("\n");
	system("pause");
#endif
	return 0;
}

Measured memory_bytes: 632
N, T = map(int,input().split())
c = [0] * N
t = [0] * N
cost = 1001
for i in range(N):
    c[i], t[i] = map(int,input().split())
    if t[i] <= T:
        if c[i] < cost:
            cost = c[i]
if cost == 1001:
    print('TLE')
else:
    print(cost)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <cmath>
using namespace std;

typedef long long ll;

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

  ll all=abs(a[1]-a[0]);
  for(int i=1; i<=n; i++){
    all += abs(a[i+1]-a[i]);
  }

  for(int i=1; i<=n; i++){
    cout << all-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]) << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

const string YES = "YES";
const string NO = "NO";

void solve(std::string S){
    REP(i, S.size()){
        for(ll len = 0; i + len <= S.size(); ++len){
            string head = S.substr(0, i);
            string tail = S.substr(i + len, S.size() - i - len);
            string cand = head + tail;
            if(cand == "keyence"){
                cout << YES << endl;
                return;
            }
        }
    }
    cout << NO << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int a,co;
    co=0;
    for(a=0;a<4;a++){
        if(s.at(a)=='+'){
            co++;
        }
        else{
            co--;
        }
    }
    cout << co << endl;
    return 0;
}

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

int main() {
	int n;cin>>n;
	long long t[n];
	long long maxt=0;
	for(int i=0;i<n;i++){
		cin>>t[i];
		if(maxt<t[i])maxt=t[i];
	}
	long long ans=maxt;
//	while(1){
//		int flag=1;
//		for(int i=0;i<n;i++){
//			if(ans%t[i]){
//				flag=0;
//				break;
//			}
//		}
//		if(flag)break;
//		ans+=maxt;
//	}
	for(int i=0;i<n;i++){
		long long temp=ans;
		while(ans%t[i]){
			ans+=temp;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 20171211;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  ll b[N]={};
  for(ll i=0;i<N-1;i++){
    ll x,y,a;cin>>x>>y>>a;
    b[x]^=a;
    b[y]^=a;
  }
  ll k[16]={};
  for(ll i=0;i<N;i++){
    k[b[i]]++;
  }
  //debugArray(k,16);
  ll ans=0;
  ll rem=0;
  for(ll i=1;i<16;i++){
    ans += k[i]/2;
    rem |= (k[i]&1)<<(i-1);
  }
  ll dp[1<<15]={};
  for(ll S=1;S<1<<15;S++){
    ll x=0;
    for(ll i=0;i<15;i++)if((S>>i)&1){
      x ^= i+1;
    }
    if(!x)dp[S]=max(dp[S],1ll);
    for(ll T=(S-1)&S;T>0;T=(T-1)&S)if(dp[T]>0&&dp[S^T]>0){
      dp[S] = max(dp[S],dp[T]+dp[S^T]);
    }
  }
  /*
  debug(ans);
  debug((bitset<4>)rem);
  debug(dp[rem]);
  */
  ans += __builtin_popcountll(rem)-dp[rem];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<string>
#include<stack>
#include<algorithm>

using namespace std;

void slove(){
    int n;
    cin>>n;
    vector<long long> arr(n);
    for(int i = 0; i < n; ++i){
        cin>>arr[i];
    }

    vector<long long> prefix(n+1,0);
    long long mod = 1e9 + 7;
    long long ans = 0;
    for(int i = 1; i <= n; ++i){
        prefix[i] = (prefix[i-1] + arr[i-1])%mod;
    }
    for(int i = 1; i <= n; ++i){
        ans = (ans + (arr[i-1]*(prefix[n] - prefix[i] + mod)%mod))%mod;
    }
    cout<<ans<<endl;
}

int main(){
    slove();
}


Measured memory_bytes: 6044
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.HashMap;

public class Main
{
    int w, a, b;
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	if(a > b) {
	    int tmp = a;
	    a = b;
	    b = tmp;
	}
	
	out(b - (a + w));
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	w = sc.nextInt();
	a = sc.nextInt();
	b = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int n)
    {
	if(n > 0) System.out.println(n);
	else      System.out.println(0);
    }

    void out(char c)
    {
	System.out.print(c);
    }
    
    void out(String s)
    {
	System.out.println(s);
    }
}


Measured memory_bytes: 21844
import math
A,B,H,M = map(int,input().split())
b = 6*M  #分針
a = (M+(60*H))/2 #時針
r = abs(a-b) #角度
if r >180:
  r = 360-r
cosr = math.cos(math.radians(r))
t = ((A*A)+(B*B)-(2*A*B*cosr))**(1/2)
print(t)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >>n; int ans=0;
  vector<vector<int>>v(15,vector<int>(28,0));
  for(int i=0; i<n; i++){
    int a; cin >>a;
    for(int j=0; j<a; j++){
      cin >>v[i][2*j] >>v[i][2*j+1];
    }
  }
  for(int i=1; i<(1<<n); i++){
    bool shit=1; vector<bool>b(n,0);
    int ii=i,sum=0;
    for(int j=0; j<n; j++){
      if(!ii) break;
      if(ii%2){b[j]=1; sum++;}
      ii/=2;
    }
    for(int j=0; j<n; j++){
      for(int k=0; k<n-1; k++){
        if(v[j][2*k]&&b[j]&&b[v[j][2*k]-1]!=v[j][2*k+1])
        {shit=0; break;}
      }
      if(!shit) break;
    }
    if(shit) ans=max(ans,sum);
  }
  cout <<ans;
return 0;}

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

using namespace std;

typedef long long llint;

map<long long, int> primefactor(long long n) {
  map<long long, int> ret;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

int main() {
  llint n;
  cin >> n;
  auto mp = primefactor(n);
  llint ans = 0;
  for (auto &v : mp) {
    int i = 1;
    while (0 <= v.second - i) {
      v.second -= i;
      i++;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n int
	var k int
	fmt.Scanf("%d %d", &n, &k)
	d := make([]string, k)
	for i := 0; i < len(d); i++ {
		fmt.Scanf("%s", &d[i])
	}

	var result int
	for i := 0; ; i++ {
		result = i + n
		_result := strconv.Itoa(result)
		if !include(_result, d) {
			break
		}
	}

	fmt.Println(result)
}

func include(s string, d []string) bool {
	for i := 0; i < len(d); i++ {
		if strings.Contains(s, d[i]) {
			return true
		}
	}
	return false
}


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

#define MAX_INT 0x3f3f3f3f 
#define precision(x) setprecision(x)
#define boost ios_base::sync_with_stdio(false); 	cin.tie(NULL);

int main()
{
	boost;
	string s,t;
	cin >> s >> t;
	int n=s.length();
	int count=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]!=t[i])
		{
			count++;
		}
	}
	cout << count << "\n";
}

Measured memory_bytes: 3880
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		long X = Long.parseLong(sc.next());
		System.out.println(patty(N, X));
	}

	static long patty_sum(int N) {
		return pow(2, N+1)-1;
	}

	static long patty(int N, long X) {
		if (0<=X && X<=1) {
			if (N==0) {
				return 1;
			} else {
				return 0;
			}
		} else if (1<=X && X<=pow(2, N+1)-2) {
			return patty(N-1, X-1);
		} else if (pow(2, N+1)-2<=X && X<=pow(2, N+1)-1) {
			return patty_sum(N-1)+1;
		} else if (pow(2, N+1)-1<=X && X<=pow(2, N+2)-4) {
			return patty_sum(N-1)+1+patty(N-1, X-pow(2, N+1)+1);
		} else {
			return patty_sum(N);
		}
	}

	static long pow(long a,int n) {
	    long res=1;
	    while (n>0) {
	        if ((n-n/2*2)==1) {
	            res=res*a;
	        }
	        a=a*a;
	        n>>=1;
	    }
	    return res;
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  sort(all(a),greater<ll>());
  ll x=-1;
  rep(i,n){
      if(x!=-1&&a[i]!=x&&a[i]==a[i+1]){
          cout<<x*a[i]<<endl;
          return 0;
      }
      if(a[i]==a[i+1]){
          x=a[i];
          if(a[i]==a[i+2]&&a[i]==a[i+3]){
              cout<<x*x<<endl;
            return 0;
          }
      }
  }
  cout<<0<<endl;
  return 0;
  }


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

class segment_tree
{
private:
const ll llinf = 1e18;
  vector<ll> ST, lazy; int N;
#define lc id << 1
#define rc id << 1 | 1
  void dolazy(int id, int l, int r)
  {
    ST[id] += lazy[id];
    if(l != r){
      lazy[lc] += lazy[id];
      lazy[rc] += lazy[id];
    }
    lazy[id] = 0;
  }

  void update(int id, int l, int r, int L, int R, ll v)
  {
    dolazy(id, l, r);
    if(l > R || L > r) return;
    if(L <= l && r <= R){
      lazy[id] += v;
      dolazy(id, l, r);
      return;
    }
    int mid = (l + r) / 2;
    update(lc, l, mid, L, R, v); update(rc, mid + 1, r, L, R, v);
    ST[id] = min(ST[lc], ST[rc]);
  }

  void Set(int id, int l, int r, int i, ll v)
  {
    dolazy(id, l, r);
    if(l > i || r < i) return;
    if(l == r){
      ST[id] = min(ST[id], v);
      return;
    }
    int mid = (l + r) / 2;
    Set(lc, l, mid, i, v); Set(rc, mid + 1, r, i, v);
    ST[id] = min(ST[lc], ST[rc]);
  }

  ll getmin(int id, int l, int r, int L, int R)
  {
    dolazy(id, l, r);
    if(l > R || L > r) return llinf;
    if(L <= l && r <= R) return ST[id];
    int mid = (l + r) / 2;
    return min(getmin(lc, l, mid, L, R), getmin(rc, mid + 1, r, L, R));
  }
#undef lc
#undef rc
public:
  segment_tree(int n)
  {
    N = n;
    ST.assign(4 * n + 5, 0);
    lazy.assign(4 * n + 5, 0);
  }
  void update(int l, int r, ll v)
  {
    update(1, 1, N, l, r, v);
  }
  ll getmin(int l, int r)
  {
    return getmin(1, 1, N, l, r);
  }
  void Set(int i, ll v)
  {
    Set(1, 1, N, i, v);
  }
};

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if(fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  int N, Q, A, B;
  cin >> N >> Q >> A >> B;
  segment_tree le(N), ri(N);
  vector<int> a(Q + 5);
  a[0] = A;
  for(int i = 1; i <= Q; ++i){
    cin >> a[i];
  }
  for(int i = 1; i <= N; ++i){
    le.update(i, i, abs(B - i) - i);
    ri.update(i, i, abs(B - i) + i);
  }
  for(int i = 1; i <= Q; ++i){
    int d = abs(a[i] - a[i - 1]);
    ll val = min(le.getmin(1, a[i]) + a[i], ri.getmin(a[i], N) - a[i]);
    le.update(1, N, d);
    ri.update(1, N, d);
    le.Set(a[i - 1], val - a[i - 1]);
    ri.Set(a[i - 1], val + a[i - 1]);
    ///cerr << val << '\n';
  }
  ll res = 1e18;
  for(int i = 1; i <= N; ++i){
    res = min(res, le.getmin(i, i) + i);
  }
  cout << res;
}

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

int main() {
    int i = 1;
    while(true) {
        int N;
        cin >> N;
        if(N == 0) {
            break;
        }
        cout << "Case " << i << ": " << N << endl;
        i++;
    }
    return 0;
}


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

using namespace std;
int n,m;
const int maxn=1e5+5;
int a,b,c;
int w[maxn];
int dis[maxn];
int father(int x)
{
    if(w[x]==x)
        return x;
    int r=father(w[x]);
    dis[x]=dis[w[x]]+dis[x];
    return w[x]=r;
}
int mix(int x,int y,int z)
{
    int fx=father(x);
    int fy=father(y);
    if(fx==fy){
        return z==dis[y]-dis[x];
    }
    w[fy]=fx;
    dis[fy]=dis[x]+z-dis[y];
    return 1;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        w[i]=i;
    }
    int f=1;
    for(int i=1;i<=m;i++){
        cin>>a>>b>>c;
        if(f)
            f=mix(a,b,c);
    }
    if(f)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 1024
def ando(x, y):
    return (max(x[0], y[0]), min(x[1], y[1]))

N, M = map(int, input().split())

r = (0, N)
for _ in range(M):
    lr = tuple(map(int, input().split()))
    r = ando(r, lr)

if r[1] >= r[0]:
    print(r[1] - r[0] + 1)
else:
    print(0)


Measured memory_bytes: 3060
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n = II()
    hh = MII()
    tmp = 0
    cnt = 0
    for h in hh:
        if h < tmp:
            cnt += tmp-h
        tmp = h
    cnt += tmp
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a,0,sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i,a,b)  for(int i=(a);i<(b);i++)
#define REP(i,a,b)  for(int i=(a);i<=(b);i++)
#define DOWN(i,a,b) for(int i=(a);i>=(b);i--)

using namespace std;

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

const double eps=1e-8;
const int INF=0x3f3f3f3f;
const ll LL_INf=0x3f3f3f3f3f3f3f3f;
const ll mod=1000000009;
const int N=30+10;

int n,cnt;
char ch;
int a[N];

int main(){
	cin>>n;
	FOR(i,0,n) {
		cin>>ch;
		a[ch-'A']++;
	}
	FOR(i,0,26) {
		if (a[i]) cnt++;
	}
	if (cnt==3) cout<<"Three"<<endl;
	else cout<<"Four"<<endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
G = [[] for i in range(n)]
E = []
for i in range(m):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
    E.append((a-1, b-1))
from collections import deque
def solve(s, t):
    if len(G[s]) == 1 or len(G[t]) == 1:
        return 1
    used = [0]*n
    que = deque()
    used[s] = 1
    for v in G[s]:
        if v == t:
            continue
        used[v] = 1
        que.append(v)
    while que:
        u = que.popleft()
        for v in G[u]:
            if not used[v]:
                used[v] = 1
                que.append(v)
    return sum(used) != n
ans = 0
for a, b in E:
    ans += solve(a, b)
print(ans)


Measured memory_bytes: 3444
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    int64_t N, Ma, Mb;
    std::cin >> N >> Ma >> Mb;

    struct Med {
        int64_t a;
        int64_t b;
        int64_t c;
    };

    std::vector<Med> med;
    for (decltype(N) i = 0; i < N; ++i) {
        Med t;
        std::cin >> t.a >> t.b >> t.c;
        med.push_back(t);
    }

    constexpr int64_t maxCost = 40*100*2;

    boost::multi_array<int64_t, 3> memo(boost::extents[10*40+1][10*40+1][N+1]);
    std::fill(memo.data(), memo.data() + memo.num_elements(), -1);

    auto f = [&memo, &med, N, Ma, Mb, maxCost](auto F, int64_t ma, int64_t mb, int64_t n ) -> int64_t {
        if (memo[ma][mb][n] != -1) {
            // nop
        }
        else if (ma != 0 && mb != 0 && ma*Mb == mb*Ma) {
            memo[ma][mb][n] = 0;
        }
        else if (n == N) {
            memo[ma][mb][n] = maxCost;
        }
        else {
            memo[ma][mb][n] = std::min(F(F, ma, mb, n+1),
                                       F(F, ma+med[n].a, mb+med[n].b, n+1) + med[n].c);
        }

        return memo[ma][mb][n];
    };

    auto c = f(f, 0, 0, 0);

    if (c == maxCost) {
        c = -1;
    }
    std::cout << c << std::endl;

    return 0;
}


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

int main(void)
{
    string input;
    cin >> input;

    int max_len = 0;

    for (int i = 0; i < input.length(); i++)
    {
        int len = 0;
        for (int j = i; j < input.length(); j++)
        {
            if (!(input[j] == 'A' || input[j] == 'T' || input[j] == 'G' || input[j] == 'C'))
                break;
            len++;
        }
        max_len = max(len, max_len);
    }

    cout << max_len;
    return 0;
}

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

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 200005;

int A[N];
map<int, int > C;

int main() {
  int n;
  S(n);
  int ans = 0;
  rep(i,0,n) {
    S(A[i]);
    C[A[i]]++;
  }
  int up = 1 << 30;
  sort(A,A+n);
  for(int i = n - 1; i >= 0; i--) if(C[A[i]] > 0) {
    C[A[i]]--;
    while(A[i] * 2 < up) {
      up >>= 1;
    }
    int rem = up - A[i];
    if(C[rem] > 0) {
      C[rem]--;
      ans++;
    }
  }
  P(ans);
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
  int x,y;
  string s;
  cin >> s >> x >> y;

  vector<int> xMove;
  vector<int> yMove;
  bool xyFlag = true;
  bool firstFlag = true;
  int moveCnt = 0, firstMove = 0;
  rep(i,s.size()){
    if(s[i] == 'T'){
      if(firstFlag == true){
        firstFlag = false;
        firstMove = moveCnt;
        moveCnt = 0;
      }
      if(xyFlag && moveCnt != 0) xMove.push_back(moveCnt);
      else if(xyFlag == false && moveCnt != 0) yMove.push_back(moveCnt);

      if(xyFlag)  xyFlag = false;
      else        xyFlag = true;

      moveCnt = 0;
    }else{
      moveCnt ++;
    }
    if(i == s.size() - 1) {
      if(firstFlag == true){
        firstFlag = false;
        firstMove = moveCnt;
        moveCnt = 0;
      }
      if(xyFlag && moveCnt != 0)                xMove.push_back(moveCnt);
      else if(xyFlag == false && moveCnt != 0)  yMove.push_back(moveCnt);
    }
  }
  //rep(i,xMove.size()) cout << xMove[i] << ' ' << endl;
  vector< vector<bool> > dp2(xMove.size()+1 ,vector<bool>(20000,false));
  dp2[0][10000+firstMove] = true;
  rep(i,xMove.size()){
    rep(j,20000){
      if(dp2[i][j] == true){
        dp2[i+1][j+xMove[i]] = true;
        dp2[i+1][j-xMove[i]] = true;
      }
    }
  }
  //cout << "[xMove.size()][x+10000] = " << dp2[xMove.size()][x+10000] << endl;
  if(dp2[xMove.size()][x+10000] == false){
    cout << "No" << endl;
    return 0;
  }

  vector< vector<bool> > dp(yMove.size() + 1,vector<bool>(20000,false));
  dp[0][10000] = true;
  rep(i,yMove.size()){
    rep(j,20000){
      if(dp[i][j] == true){
        dp[i+1][j+yMove[i]] = true;
        dp[i+1][j-yMove[i]] = true;
      }
    }
  }
  if(dp[yMove.size()][y + 10000] == false){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() { 
    ll A, B, H, M;
    cin >> A >> B >> H >> M;
    ll angle = 0;
    ll out = 0;
    angle = fabs((M_PI / 6 * H + M_PI*M / 360) - (M_PI * M / 30));
    out = sqrt(A * A + B * B - 2 * A * B * cos(angle));
    cout << fixed << setprecision(9) << out << endl;
    return 0;
}

Measured memory_bytes: 4184
import math
from fractions import gcd
a, b = map(int, input().split())
g = gcd(a, b)
sqrt = math.floor(g ** 0.5)
factors = [1]
z = g
for i in range(2, sqrt + 1):
    if not z % i:
        factors.append(i)
        while z % i == 0:
            z //= i
if z > 1:
    factors.append(z)
print(len(factors))

Measured memory_bytes: 5596
import java.util.*;

public class Main {
	final static int MOD = 1000000007;
	
	public static void main(String[] args) {
		MyScanner in = new MyScanner();
		String s = in.nextLine();
		int a = 0;
		int b = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == '0') {
				a++;
				
			} else {
				b++;
			}
		}
		System.out.println(Math.min(a, b) * 2);
		
	}
	
	static class MyScanner {
		static Scanner sc = new Scanner(System.in);
		
		String next() {
			return sc.next();
		}
		
		String nextLine() {
			return sc.nextLine();
		}
		
		int nextInt() {
			return Integer.parseInt(sc.next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextInt();
			}
			return array;
		}
		
		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextDouble();
			}
			return array;
		}
		
		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}
			return array;
		}
		
		String[] nextLineArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLine();
			}
			return array;
		}
		
		int[][] nextIntMatrix(int n, int m) {
			int[][] matrix = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextInt();
				}
			}
			return matrix;
		}
		
		double[][] nextDoubleMatrix(int n, int m) {
			double[][] matrix = new double[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextDouble();
				}
			}
			return matrix;
		}
		
		long[][] nextLongMatrix(int n, int m) {
			long[][] matrix = new long[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextLong();
				}
			}
			return matrix;
		}
	}
}

Measured memory_bytes: 26396