akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <cassert>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

#define st first
#define nd second

const int MAXN = 1e5 + 5, inf = 1e9;
const ll INF = 1e18, mod = 1e9 + 7;
const ld PI = 3.1415926535897932384626433832795;

int cnt[MAXN], a[MAXN];
ll dp[MAXN][2][105];
bool vis[MAXN], used[MAXN];

vector<int> G[MAXN];
vector<ll> V;
set<ll> S;
map<ll, int> M;
stack<ll> St;
queue<ll> Q;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

    //////////////////////////////////////////
    //////////////////////////////////////////

    string s;
    ll d;
    cin >> s >> d;
    int n = s.size();
    for (int i = 1; i <= n; i++) {
        a[i] = s[i - 1] - '0';
    }

    dp[0][1][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < d; j++) {
            for (int dig = 0; dig < 10; dig++) {
                int k = (j + dig) % d;

                dp[i][0][k] = (dp[i][0][k] + dp[i - 1][0][j]) % mod;
                if (dig < a[i]) {
                    dp[i][0][k] = (dp[i][0][k] + dp[i - 1][1][j]) % mod;
                } else if (dig == a[i]) {
                    dp[i][1][k] = (dp[i][1][k] + dp[i - 1][1][j]) % mod;
                }

                /*dp[i][0][j] = (dp[i][0][j] + dp[i - 1][0][k]) % mod;
                if (dig < a[i]) {
                    dp[i][0][j] = (dp[i][0][j] + dp[i - 1][1][k]) % mod;
                } else if (dig == a[i]) {
                    dp[i][1][j] = (dp[i][1][j] + dp[i - 1][1][k]) % mod;
                }*/
            }
            //cout << dp[i][0][j] << " ";
        }
        //cout << "\n";
    }
    //cout << "\n";

    /*for (int k = 0; k < 2; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < d; j++) {
                cout << dp[i][k][j] << " ";
            }
            cout  << "\n";
        }
        cout << "\n";
    }*/

    cout << ((dp[n][0][0] + dp[n][1][0] - 1) % mod + mod) % mod<< "\n";
}


Measured memory_bytes: 20736
from itertools import permutations
from collections import defaultdict
n, C = map(int, input().split())
d = [list(map(int, input().split())) for i in range(C)]
c = [list(map(int, input().split())) for i in range(n)]

counts = [defaultdict(int) for _ in range(3)]
for i in range(n):
    for j in range(n):
        counts[(i+j+2) % 3][c[i][j]-1] += 1

def calc_cost(dic, color):
    cost = 0
    for k, v in dic.items():
        cost += d[k][color] * v
    return cost

INF = 10**9
cost = INF
for colors in permutations(range(C), 3):
    tmp_cost = 0
    for i in range(3):
        tmp_cost += calc_cost(counts[i], colors[i])
    cost = min(cost, tmp_cost)
print(cost)

Measured memory_bytes: 45020
import Control.Monad
import Control.Applicative
import Text.Printf

main = do
    n <- readLn
    replicateM_ n $ do
        [x1, y1, x2, y2, x3, y3] <- map read <$> words <$> getLine
        let det2 = 2 * ((x1 - x2)*(y1 - y3) - (y1 - y2)*(x1 - x3))
            a = x1^2 - x2^2 + y1^2 - y2^2
            b = x1^2 - x3^2 + y1^2 - y3^2
            x = ((y1 - y3)*a - (y1 - y2)*b) / det2 :: Double
            y = ((x1 - x2)*b - (x1 - x3)*a) / det2 :: Double
            r = ((x - x1)^2 + (y - y1)^2) ** 0.5   :: Double
        printf "%.3f %.3f %.3f\n" x y r

Measured memory_bytes: 4576
#include <iostream>
#include <iomanip>
#include<string>
#include <math.h>

using namespace std;

int main(){
        int n,k;
        double p,ans=0.0;
        cin>>n>>k;

        p=1/(double)n;

        for(int i=1; i<=n; i++){
                int cal=i;
                double count=0;
                while(cal<k){
                        cal=cal*2;
                        count++;
                }
                ans+=p*pow(0.5,count);
        }

        cout<<setprecision(12)<<ans<<endl;

        return 0;
}


Measured memory_bytes: 256
from collections import deque
N, Q = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

count = [0] * N
for j in range(Q):
    p, x = map(int, input().split())
    count[p-1] += x

visited = [False] * N
que = deque([0])

while que:
    now = que.pop()
    visited[now] = True
    for nxt in G[now]:
        if visited[nxt]:
            continue
        count[nxt] += count[now]
        que.appendleft(nxt)

print(*count)


Measured memory_bytes: 56616
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

using namespace std;

typedef long long ll;

typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const ll inf=100000000000000;
struct edge{
	int to,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

#define MAX_N 200002
int dp[26][MAX_N]={};
bool d[MAX_N]={};
int pa[MAX_N];
vector<edge> G[MAX_N];
P1 cost[MAX_N]={};
vector<int> child[MAX_N];
vector<int> ra[MAX_N];
priority_queue<P2,vector<P2>,greater<P2>> que;
ll a[100005]={};
ll b[100005]={};
int main() {
	int n;
	cin>>n;
	rep(i,n)cin>>a[i]>>b[i];
	ll t=0;
	rrep(i,n){
		ll k=a[i]+t;
		if(k==0)continue;
		if(k<b[i])t+=b[i]-k;
		else t+=(b[i]-k%b[i])%b[i];
//		cout<<t<<endl;
	}

	cout<<t<<endl;
	return 0;
}





Measured memory_bytes: 18688
#include <stdio.h>

int main(void) {
    char a[50];
    char ans;
    int n,x;
    scanf("%d %d %s",&n,&x,a);
    
   a[x-1] =  a[x-1] + 32;
    
    for(int i = 0;i < n;i++){
        printf("%c",a[i]);
    }
	return 0;
}



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

char tokuten(int m, int f,int r){
	int sum ;
	char seki;
	sum = m + f;
	if( m == -1 || f == -1 ){
		seki = 'F';
	} else if( 80 <= sum ){
		seki = 'A';
	} else if( 65 <= sum && sum < 80 ){
		seki = 'B';
	} else if( 50 <= sum && sum < 65 ){
		seki = 'C';
	} else if( 30 <= sum && sum < 50 ){
		if( 50 <= r )seki = 'C';
		else seki = 'D';
	} else if( sum < 30 ){
		seki = 'F';
	}

	return seki;
}

int main(){
	int m,f,r;
	while(1){
		cin >> m >> f >> r;
		if( m == -1 && f == -1 && r == -1 )break;
		cout << tokuten(m, f, r) << endl;
	}

	return 0;
}

Measured memory_bytes: 3096
N,K = gets.split.map(&:to_i)

puts (K+1..N).map{ |b|
  m1 = (N+1)/b
  n2 = (N % b < b-1) ? [N % b, K-1].max - K + 1 : 0
  #$stderr.puts "#{b}: #{m1} * #{(b-K)} = #{m1*(b-K)} #{n2}"
  m1*(b-K) + n2 + (K == 0 ? -1 : 0)
}.inject(:+)

Measured memory_bytes: 2684
#include <stdio.h>
#include <math.h>
#include <string.h>

#define N	(600000)

char isPrime[N];

int makePrime(void)
{
	int i, j;
	int lim;

	memset(isPrime, 0, sizeof(isPrime));

	lim = sqrt(N);
	for (i = 2; i < lim; i++){
		for (j = i * i; j < N; j += i){
			isPrime[j] = 1;
		}
	}
	return (0);
}

int main(void)
{
	int q, i;
	int count;

	makePrime();
	while (scanf("%d", &q),q){
		count = 0;
		for (i = 2; i <= q / 2; i++){
			if (isPrime[i] + isPrime[q - i] == 0){
				count++;
			}
		}
		printf("%d\n", count);
	}

	return (0);
}

Measured memory_bytes: 1192
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ios>//左右揃え
#include<iomanip>//setwで幅指定

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007LL

int main(void) {
    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define int long long
#define fastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

int T;
int A, B, C, D, MIN;

inline void print1(int pos)
{
	if (pos % (MIN + 1) != MIN) cout << 'A';
	else cout << 'B';
}

inline void print2(int pos)
{
	if (pos % (MIN + 1) != MIN) cout << 'B';
	else cout << 'A';
}

signed main()
{
	fastIO
	cin >> T;
	while (T--)
	{
		cin >> A >> B >> C >> D; C--;
		MIN = (A + B) / (min(A, B) + 1);
		if (MIN == 1)
		{
			if (A >= B)
				for (int i = C; i < D; i++)
					cout << ((i & 1) ? 'B' : 'A');
			else
				for (int i = C; i < D; i++)
					cout << ((i & 1) ? 'A' : 'B'); 
			cout << endl;
			continue;
		}
		int n = A + B, mid = ((MIN + 1) * A - n) / (MIN - 1); 
		for (int i = mid - 5; i <= mid + 5; i++)
			if (0 <= i && i <= n)
			{
				if (i - i / (MIN + 1) + (n - i) / (MIN + 1) != A) continue;
				int la = i % (MIN + 1);//left ones which can be connected to the right part
				int lb = i && !(i % (MIN + 1));//similar
				int ra = (n - i) && !((n - i) % (MIN + 1));//similar
				int rb = (n - i) % (MIN + 1);//similar
				if (la + ra <= MIN && lb + rb <= MIN)
				{
					for (int j = C; j < min(D, i); j++) print1(j);
					for (int j = max(C, i); j < D; j++) print2(n - 1 - j);
					cout << endl;
					break;
				}
			}
	}
	return 0;
}


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

template<class T>
class BIT
{
public:
  int n;
  vector<T> bit;

  BIT(){}

  BIT(int n_)
  {
    init(n_);
  }

  void init(int n_)
  {
    n = n_;
    bit.resize(n+1);
    clear();
  }

  T sum(int i)
  {
    T s = 0;
    while(i > 0){
      s += bit[i];
      i -= i&-i;
    }
    return s;
  }

  void add(int i, T x)
  {
    while(i <= n){
      bit[i] += x;
      i += i&-i;
    }
  }

  void clear()
  {
    for(int i = 0; i < n; i++){
      bit[i] = 0;
    }
  }
};

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

  vl a(n), s(n+1), v;
  v.pb(-linf);
  v.pb(0);
  rep(i, n){
    cin >> a[i];
    a[i] -= k;
    s[i+1] = s[i] + a[i];
    v.pb(s[i+1]);
  }

  sort(all(v));

  ll ans = 0, tmp = 0;
  BIT<ll> bit(n);
  for(int i = n-1; i >= 0; i--){
    int x = lower_bound(all(v), s[i+1])-v.begin();
    int y = lower_bound(all(v), s[i])-v.begin();
    tmp++;
    bit.add(x, 1);
    ans += tmp-bit.sum(y-1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

	static MyReader sc = new MyReader();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		int n = sc.nextInt();
		long ans = 0;
		for(int i = 1; i < n + 1; i++) {
			if(i % 3 == 0 || i % 5 == 0)
				continue;
			ans += i;
		}
		out.println(ans);
		out.close();

	}

	//GCD
	static int GCD(int n, int m) {
		if(m > n)
			return GCD(m, n);
		if(n % m == 0)
			return m;
		else {
			return GCD(m, n % m);
		}
	}

}

class MyReader {
	private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	private static String[] line = new String[0];
	private static int num = 0;

	protected MyReader() {

	}

	private void nextline() throws IOException {
		String s = in.readLine();
		line = s.split(" ");
	}

	protected String next() throws IOException {
		if(num == line.length) {
			nextline();
			num = 0;
		}
		String ret = line[num];
		num++;
		return ret;
	}

	protected int nextInt() throws IOException {
		if(num == line.length) {
			nextline();
			num = 0;
		}
		int ret = Integer.valueOf(line[num]);
		num++;
		return ret;
	}

	protected long nextLong() throws IOException {
		if(num == line.length) {
			nextline();
			num = 0;
		}
		long ret = Long.valueOf(line[num]);
		num++;
		return ret;
	}

}

// 組み合わせ計算
class Combination {
	public static int MAX = 510000;
	public static int MOD = 1000000007;

	public static long[] f = new long[MAX];
	public static long[] finv = new long[MAX];
	public static long[] inv = new long[MAX];

	protected Combination() {
		f[0] = f[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for(int i = 2; i < MAX; i++) {
			f[i] = f[i - 1] * i % MOD;
			inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
			finv[i] = finv[i - 1] * inv[i] % MOD;
		}
	}

	public static long Com(int n, int k) {
		if(n < k)
			return 0;
		if(n < 0 || k < 0)
			return 0;
		return f[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}

	public static long Inverse(int n) {
		return inv[n];
	}

	public static long Factorial(int n) {
		return f[n];
	}
}

// union-find木
class UnionFind {
	private int[] parent;
	private int[] depth;
	private int[] size;

	protected UnionFind(int n) {
		super();
		parent = new int[n];
		for(int i = 0; i < n; i++) {
			parent[i] = i;
		}
		depth = new int[n];
		size = new int[n];
		for(int i = 0; i < n; i++) {
			depth[i] = 1;
			size[i] = 1;
		}
	}

	public int Parent(int n) {
		if(parent[n] == n) {
			return n;
		} else {
			return Parent(parent[n]);
		}
	}

	public void Union(int a, int b) {
		int pa = Parent(a);
		int pb = Parent(b);
		if(pa != pb) {
			if(depth[pa] > depth[pb]) {
				parent[pb] = pa;
				size[pa] += pb;
			} else if(depth[pa] == depth[pb]) {
				parent[pb] = pa;
				size[pa] += pb;
				depth[pa]++;
			} else {
				parent[pa] = pb;
				size[pb] += pa;
			}
		}
	}

	public int Size(int n) {
		return size[Parent(n)];
	}

}

Measured memory_bytes: 32964
#include <bits/stdc++.h>
using namespace std;
 
int euler_phi(int n) {
    int res = n;
    for(int i = 2; i * i <= n; ++i) {
        if(n % i == 0) {
            res = res / i * (i - 1);
            for(; n % i == 0; n /= i);
        }
    }
    if(n != 1) {
        res = res / n * (n - 1);
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    cout << euler_phi(n) << endl;
}


Measured memory_bytes: 3104
# -*- coding: utf-8 -*-

X,Y=map(int, raw_input().split())

mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1, max(X,Y)+1):
    fact_tmp *= i
    fact_tmp %= mod
    fact.append(fact_tmp)
    inv_fact.append(pow(fact_tmp, mod-2, mod))
 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod

if (X+Y)%3!=0:
    print 0
else:
    m=(2*X-Y)/3
    n=(Y-m)/2
    print ncr(m+n,n)


Measured memory_bytes: 128028
#include <iostream>

int main(void)
{
	int count[100]={0},n;
	while(std::cin >> n)
		count[n-1]++;

	int max=0;
	for(int i=0; i<100; i++)
		if(count[i] > max)
			max = count[i];
	for(int i=0; i<100; i++)
		if(max == count[i])
			std::cout << i+1 << std::endl;
	return 0;
}

Measured memory_bytes: 1160
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define INF 10000000000000000000

int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  ll ans = b-a;
  if(k%2 == 0) ans = -ans;
  cout << ans << endl;

  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

  int count = 0;
  for (int i = 1; i <= n; ++i) {
    if (i > 0 && i < 10) {
      ++count;
    }
    if (i >= 100 && i < 1000) {
      ++count;
    }
    if (i >= 10000 && i < 100000) {
      ++count;
    }
  }

  cout << count;

  return 0;
}


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


using namespace std;
typedef long long LL;
const int maxn = 10005;
int a[maxn], b[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    LL x = 0, y = 0;
    for(int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &b[i]);
        int cur = b[i] - a[i];
        if(cur < 0)
            y += -cur;
        else
        {
            x += (cur + 1) / 2;
            y += cur % 2;
        }
    }
    if(x < y)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


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


int main()
{
	int n;
	cin >> n;
	int temp;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		ans += temp - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,b,c = iim()

l = [i*(a%b)%b for i in range(b)]
#print(l)
print('YES' if c in l else 'NO')


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

int main(void){
	
	int a, b;
	
	cin >> a >> b;
	
	if (a < b){
		cout << "a < b" << endl;
	}
	
	else if (a > b){
		cout << "a > b" << endl;
	}
	
	else{
		cout << "a == b" << endl;
	}
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
vi g[125];

int dist1[125], dist2[125];

void dfs1(int p, int b, int d){
  dist1[p] = d;
  for(int to : g[p])if(to!=b){
    dfs1(to,p,d+1);
  }
}

void dfs2(int p, int b, int d){
  dist2[p] = d;
  for(int to : g[p])if(to!=b){
    dfs2(to,p,d+1);
  }
}

int degs[125];

void dfs3(int p, int b, int d){
  int deg = 0;
  for(int to : g[p])if(to!=b){
    deg++;
    dfs3(to,p,d+1);
  }
  CHMAX(degs[d], deg);
}

pll solve1(int root){
  REP(i,n)degs[i] = -1;
  dfs3(root, -1, 0);
  ll dep = 1, lvs = 1;
  REP(i,n+1){
    if(degs[i]==0)break;
    dep++;
    // lvs * degsi >= 1ll<<60
    // lvs >= 1ll<<60 / degsi
    if(lvs >= (1ll<<60) / degs[i]){
      lvs = 1ll<<60;
    }else{
      lvs *= degs[i];
    }
  }
  return pll(dep, lvs);
}
pll solve2(int a, int b){
  REP(i,n)degs[i] = -1;
  dfs3(a, b, 0);
  dfs3(b, a, 0);
  ll dep = 1, lvs = 2;
  REP(i,n+1){
    if(degs[i]==0)break;
    dep++;
    if(lvs >= (1ll<<60) / degs[i]){
      lvs = 1ll<<60;
    }else{
      lvs *= degs[i];
    }
  }
  return pll(dep, lvs);
}

int main(){
  scanf("%d",&n);
  REP(i,n-1){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    // int a = i+1;
    // int b = rand()%a;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  pll ans = pll(n,n);
  REP(i,n)CHMIN(ans,solve1(i));
  REP(i,n)for(int j:g[i]){
    CHMIN(ans,solve2(i,j));
  }
  // // get center
  // dfs1(0,-1,0);
  // int x = max_element(dist1,dist1+n)-dist1;
  // dfs1(x,-1,0);
  // int y = max_element(dist1,dist1+n)-dist1;
  // dfs2(y,-1,0);
  // int diam = *max_element(dist2,dist2+n);
  // if(diam%2==0){
  //   // center vertex
  //   int c = find(dist2,dist2+n,diam/2)-dist2;
  //   CHMIN(ans, solve1(c));
  //   for(int to : g[c]){
  //     CHMIN(ans, solve2(c,to));
  //   }
  // }else{
  //   // center edge
  //   int c = find(dist2,dist2+n,diam/2)-dist2;
  //   for(int to : g[c])if(dist2[to]==diam/2+1){
  //     CHMIN(ans, solve2(c,to));
  //   }
  // }
  printf("%lld %lld\n",ans.first,ans.second);
  return 0;
}


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

const int MAXD = 40;

int test(int n, int m, int d, const string s[]) {
  for(int i = 0; i < d; ++i) {
    if(m != 0 && s[i][m-1] == '1') {
      --m;
    } else if(m != n-1 && s[i][m] == '1') {
      ++m;
    }
  }
  return m;
}

int main() {
  int n, m, atari, d;
  string s[MAXD];
  while(cin >> n && n) {
    cin >> m >> atari >> d;
    --m; --atari;
    for(int i = 0; i < d; ++i) {
      cin >> s[i];
    }
    if(test(n,m,d,s) == atari) {
      cout << 0 << endl;
    } else {
      bool flag = false;
      for(int i = 0; !flag && i < d; ++i) {
        for(int j = 0; !flag && j < n-1; ++j) {
          if(s[i][j] == '0' &&
             (j == 0 || s[i][j-1] == '0') &&
             (j == n-2 || s[i][j+1] == '0')) {
            s[i][j] = '1';
            if(test(n,m,d,s) == atari) {
              cout << i+1 << " " << j+1 << endl;
              flag = true;
              break;
            }
            s[i][j] = '0';
          }
        }
      }
      if(!flag) cout << 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<iterator>
#include<queue>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

class Graph{
    public:
    typedef struct Edge{
        ll from, to, cost;
        Edge(ll f, ll t, ll c): from(f),to(t),cost(c){}
    } Edge;

    bool isDirected;
    ll INF = 1 << 30;
    ll v; // 頂点数
    std::vector<Edge> edges;  // 辺のリスト
    std::vector<std::vector<std::pair<ll,ll>>> list;  // 隣接リスト
    //std::vector<std::vector<ll>> matrix; // 隣接行列

    Graph(ll n, bool isDirected=false) : isDirected(isDirected) { init(n); }
    void init(ll n){
        v=n;
        edges.clear();
        list.assign(n, std::vector<std::pair<ll,ll>>());
        //matrix.assign(n, std::vector<ll>(n, INF));
    }
    void connect(ll from, ll to){
        con(from, to, 1);
        if(!isDirected) con(to, from, 1);
    }
    void connect(ll from, ll to, ll cost){
        con(from, to, cost);
        if(!isDirected) con(to, from, cost);
    }
    void con(ll from, ll to, ll cost){
        edges.push_back(Edge(from,to,cost));
        list[from].push_back(std::make_pair(to, cost));
        //matrix[from][to] = cost;
    }
};

std::vector<ll> Dijkstra(Graph G, ll start, ll inf){
    ll INF = inf;
    std::vector<ll> dist(G.v, INF);
    std::priority_queue<std::pair<ll,ll>, std::vector<std::pair<ll,ll>>, std::greater<std::pair<ll,ll>>> que;
    dist[start] = 0;
    que.push(std::make_pair(0, start));

    while(!que.empty()){
        std::pair<ll,ll> p = que.top();
        que.pop();
        if(dist[p.second] < p.first) continue;
        for(auto i : G.list[p.second]){
            if(dist[i.first] > dist[p.second] + i.second){
                dist[i.first] = dist[p.second] + i.second;
                que.push(std::make_pair(dist[i.first], i.first));
            }
        }
    }
    return dist;
}

int main(){
    int v,e,r, s,t,d;
    cin >> v >> e >> r;
    Graph gr(v, true);
    REP(i,e){
        cin >> s >> t >> d;
        gr.connect(s,t,d);
    }
    std::vector<ll> ans = Dijkstra(gr, r, 1<<30);
    for(auto i : ans){
        if(i==(1<<30)) cout << "INF" << endl;
        else cout << i << endl;
    }
}


Measured memory_bytes: 54632
n, q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

ac_count_before = [0]
for i in range(1, n):
    counter = ac_count_before[-1]
    if s[i-1] == 'A' and s[i] == 'C':
        counter += 1
    ac_count_before.append(counter)

for i in range(q):
    l = lr[i][0] - 1
    r = lr[i][1] - 1
    counter = ac_count_before[r] - ac_count_before[l]
    print(counter)


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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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 int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 //ll  a,b,c,s,t,i,j,k,x,y,z;
 //ll A,B,C,S,T,X,Y,Z;
 ll count;
signed main(){
	int N;

	cin>>  N  ;
	vector <int> X(N);
	vector <int> Y(N);
	vector <int> t(N);
  
  REP(i,N) cin>>  t[i]  >>  X[i]  >>  Y[i]  ;
bool wo = false;
  REP(i,N){
  	wo = true;
  	if(i==0){
  		REP(j,t[i]/2+1){
  			if(X[0]+Y[0]==t[0]-j*2) {
  				wo = false;
  				break;
  		}
  	}
  }
  	else {
  		REP(j,t[i]/2+1){
  		if(abs(X[i]-X[i-1])+abs(Y[i]-Y[i-1])==t[i]-t[i-1]-j*2){
  			wo = false;
  			break;
  		}
  	}
  }
  		if(wo){
  			cout<< "No";
  			return 0;
  		}
  
  }

 cout<<  "Yes"  <<endl;
  
 return 0;
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///**************************DONE****************************///

int main()
{
    string s, t;
    cin >> s >> t;

    cout << (s[0] == t[0]) + (s[1] == t[1]) + (s[2] == t[2]) << '\n';
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ((A + B) > (C + D))
    cout << "Left" << endl;
  else if ((A + B) == (C + D))
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp
//#include <bits/stdc++.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>



using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

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

    cout << double(2*(M_PI)*N)  << endl;

}


Measured memory_bytes: 3788
n = int(input())
p = list(map(int, input().split()))

a = [0] * (n+1)
b = [0] * (n+1)

for i in range(n):
    if i == 0:
        continue
    a[p[i]-1] += i
    a[n] -= i
    b[0] += i
    b[p[i]] -= i

for i in range(n):
    a[i+1] += a[i]
    b[i+1] += b[i]

for i in range(n):
    ai = i+1
    bi = n-i
    a[i] += ai
    b[i] += bi

print(*a[:n])
print(*b[:n])


Measured memory_bytes: 6524
//C

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

long long int k[100002];
#define MOD 1000000007
int main(){
	k[0] = 1;
	for (int i = 1; i < 100002; i++){
		k[i] = k[i - 1] * (long long int)(i);
		k[i] %= MOD;
	}
	int a, b;
	scanf("%d%d", &a, &b);
	if (abs(a - b) <= 1){
		long long int w = k[a] * k[b];
		w %= MOD;
		if (a == b){
			w *= 2LL;
			w %= MOD;
		}
		printf("%lld\n", w);
	}
	else{
		puts("0");
	}
	return 0;
}

Measured memory_bytes: 1024
INF = 10 ** 10
n, m = gets.split.map(&:to_i)
costs = []
keys = []
m.times do
  costs << gets.to_i
  keys << gets.split.map(&:to_i).inject(0) { |res, num| res | 2 ** (num - 1) }
end
dp = Array.new(2 ** n, INF)
dp[0] = 0
keys.each_with_index do |key, i|
  dp.each_with_index do |cost, opened|
    next if cost == INF
    next_opened = (opened | key)
    dp[next_opened] = [dp[next_opened], cost + costs[i]].min
  end
end
puts dp.last == INF ? - 1 : dp.last


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
const int N=1000007;
const long long INF=1000000009;
long long A[N],D[N];
int main(){
  int n,k;
  cin>>n>>k;
  for(int i=1;i<=n;++i)
    cin>>A[i],D[i]=INF;
  D[1]=0;
  for(int i=1;i<=n;++i){
    for(int j=i+1;j<=i+k;++j){
        D[j]=min(D[j],D[i]+abs(A[i]-A[j]));
    }
  }
  cout<<D[n];
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; i++)
#define REP(i, n) for (int i=1; i<=n; i++)
using namespace std;
using f=float; using ll=long long; using ld=long double;
using ull=unsigned long long; using vi=vector<int>; using pii=pair<int, int>;

int gcd(int a, int b) {
    int t;
    while ( b != 0 ) {
        t = a%b; a = b; b = t;
    }
    return a;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    ll sum = 0;
    //REP(i, n+1) if ( gcd(i, 3) == 1 and gcd(i, 5)==1 ) sum += i; 
    REP(i, n) 
        if ( i % 3 == 0 || i % 5 == 0) ;
        else 
            sum += i;
//            if ( i < 100) cout << i << " " << sum << endl;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N,M;
int dp[305][305][305],sum[3][305][305];
vector<pii > v[305];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
bool check(int r,int g,int b,int len) {
    for(int i = 0 ; i < v[len].size() ; ++i) {
	pii t = v[len][i];
	int cnt = 0;
	if(r >= t.fi) ++cnt;
	if(g >= t.fi) ++cnt;
	if(b >= t.fi) ++cnt;
	if(cnt != t.se) return false;
    }
    return true;
}
void increase(int r,int g,int b) {
    sum[0][g][b] = inc(sum[0][g][b],dp[r][g][b]);
    sum[1][r][b] = inc(sum[1][r][b],dp[r][g][b]);
    sum[2][r][g] = inc(sum[2][r][g],dp[r][g][b]);
}
void Solve() {
    read(N);read(M);
    int l,r,x;
    for(int i = 1 ; i <= M ; ++i) {
	read(l);read(r);read(x);
	v[r].pb(mp(l,x));
    }
    dp[0][0][0] = 1;
    sum[0][0][0] = 1;
    sum[1][0][0] = 1;
    sum[2][0][0] = 1;
    for(int i = 1 ; i <= N ; ++i) {
	for(int j = 0 ; j < i ; ++j) {
	    for(int k = 0 ; k < i ; ++k) {
		dp[i][j][k] = sum[0][j][k];
		dp[j][i][k] = sum[1][j][k];
		dp[j][k][i] = sum[2][j][k];
		if(!check(i,j,k,i)) dp[i][j][k] = 0;
		if(!check(j,i,k,i)) dp[j][i][k] = 0;
		if(!check(j,k,i,i)) dp[j][k][i] = 0;
	    }
	}
	memset(sum,0,sizeof(sum));
	for(int j = 0 ; j < i ; ++j) {
	    for(int k = 0 ; k < i ; ++k) {
		increase(i,j,k);
		increase(j,i,k);
		increase(j,k,i);
	    }
	}
    }
    int ans = 0;
    for(int i = 0 ; i < N ; ++i) {
	for(int j = 0 ; j < N ; ++j) {
	    ans = inc(ans,dp[N][i][j]);
	    ans = inc(ans,dp[i][N][j]);
	    ans = inc(ans,dp[i][j][N]);
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

const ll MAXN = 200000;
const ll INF = 1001001001001001;
const ll MOD = 1000000007;

ll N, ans=-INF, tmp1=0, tmp2=0;
vector<ll> A, B, C;
priority_queue<ll, vector<ll>, greater<ll>> pq1;
priority_queue<ll> pq2;

signed main(){
    cin >> N;
    for(int i=0;i<3*N;i++) {
        ll a;
        cin >> a;
        if(i<N) {
            tmp1 += a;
            pq1.push(a);
        }
        if(i>=2*N) {
            tmp2 += a;
            pq2.push(a);
        }
        A.push_back(a);
    }
    B.push_back(tmp1);
    C.push_back(tmp2);
    for(int i=N;i<2*N;i++) {
        tmp1 += A[i];
        pq1.push(A[i]);
        tmp1 -= pq1.top();
        pq1.pop();
        B.push_back(tmp1);
    }
    for(int i=N;i<2*N;i++) {
        tmp2 += A[3*N-1-i];
        pq2.push(A[3*N-1-i]);
        tmp2 -= pq2.top();
        pq2.pop();
        C.push_back(tmp2);
    }
    for(int i=0;i<N+1;i++) {
        ans = max(ans, B[i]-C[N-i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9856
def main():
    N = int(input())
    A = [int(c) for c in input().split() if int(c) > 0]
    MOD = int(10**9+7)
 
    mono = 0
    bi = 0
    for x in A:
        mono += x
        #mono %= MOD
        bi += x**2
        #bi %= MOD
    ans = (mono**2 - bi)//2
    ans %= MOD
    print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 31328
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b, c,d;
  cin >> a >> b >> c>>d;
  cout << min(a,b)+min(c,d) << endl;
}

Measured memory_bytes: 3592
# coding: utf-8
class QuickUnion
  attr :id

  def initialize(n)
    @id = (0...n).to_a
  end

  def root(i)
    while i != @id[i] do
      i = @id[i]
    end
    i
  end

  # find, check if p and q has the same root
  def same?(p, q)
    root(p) == root(q)
  end

  # union, to merge components containing p and q
  # set id of p's root to the id of q's root
  def unite(p, q)
    i = root(p)
    j = root(q)
    @id[i] = j
  end
end

lines = $stdin.read
array = lines.split("\n")

n = array[0].split(" ")[0].to_i
q = array[0].split(" ")[1].to_i

un = QuickUnion.new(n)

for i in 1..q
  com = array[i].split(" ")[0]
  x   = array[i].split(" ")[1].to_i
  y   = array[i].split(" ")[2].to_i

  if com == '0'
    # unite(4,3) id[4] = 3, 4の頭を3にする
    un.unite(x, y)
  else
    # same
    puts un.same?(x, y) ? "1" : "0"
  end
end



Measured memory_bytes: 13440
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, c := iScan(), iScan(), iScan()
	if a < c && c < b {
		fmt.Println("Yes")
	} else if b < c && c < a {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1772
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int Max = -1000000;
  int Min = 1000000;
  ll sum = 0;
  rep(i, n) {
    Max = max(Max, a[i]);
    Min = min(Min, a[i]);
    sum += a[i];
  }
  cout << Min << " " << Max << " " << sum << endl;
  return 0;
}


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

const int MOD = 1000000007;

int pow_mod(int x, int k) {
	int ans = 1;
	while (k) {
		if (k&1) ans = 1LL * ans * x % MOD;
		x = 1LL * x * x % MOD;
		k >>= 1;
	}
	return ans;
}

int n, k;

int fac[222222], fn, dp[222222];

int cal() {
	fn = 0;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			fac[++fn] = i;
			fac[++fn] = n / i;
		}
	}
	sort(fac + 1, fac + fn + 1);
	fn = unique(fac + 1, fac + 1 + fn) - fac - 1;
	for (int i = 1; i <= fn; i++) {
		if (n % 2 == 0 && n / 2 % fac[i] == 0) dp[i] = pow_mod(k, fac[i]);
		else dp[i] = pow_mod(k, (fac[i] + 1) / 2);
		for (int j = 1; j < i; j++) {
			if (fac[i] % fac[j] == 0) {
				dp[i] = (dp[i] - dp[j] + MOD) % MOD;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= fn; i++) ans = (ans + 1LL * dp[i] * fac[i] % MOD) % MOD;
	return ans;
}

int main() {
	scanf("%d%d", &n, &k);
	printf("%d\n", cal());
	return 0;
}


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

int main(){
  long long n,a,b;
  cin >> n >> a >> b;
  if((b-a)%2==0) cout << (b-a)/2 << endl;
  else {
    long long tmp1=(a-1)+1+(b-a-1)/2;
    long long tmp2=(n-b)+1+(b-a-1)/2;
    long long ans=min(tmp1,tmp2);
    cout << ans <<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);     
      int N = sc.nextInt();
      boolean[] J = new boolean[N];
      int[] D1 = new int[N];
      int[] D2 = new int[N];
      for(int i = 0;i<N;i++){
        D1[i]=sc.nextInt();
        D2[i]=sc.nextInt();
        J[i]=D1[i]==D2[i];
      }
      int R = 0;
      boolean re=false;
      for(int i = 0;i<N;i++){
        if(J[i]){
          R++;
        }else{
          R=0;
        }
        if(R>2){
          re=true;
          break;
        }
      }
                         if(re){
                           System.out.println("Yes");
                         }else{
                           System.out.println("No");
                         }
   }
}

Measured memory_bytes: 27272
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC138
{
    class Program
    {
        static void Main(string[] args)
        {
            int r;
            r = int.Parse(Console.ReadLine());
            if (r < 1200)
                Console.WriteLine("ABC");
            else if (r < 2800)
                Console.WriteLine("ARC");
            else
                Console.WriteLine("AGC");
            Console.ReadKey();    
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdlib>

using namespace std;
const static int O_NUM = 32; 
const static int I_MAX = 25;
int main() {
  while( 1 ) {
    int n, i, lis[ I_MAX ];
    cin >> i;
    if( !i ) { return EXIT_SUCCESS; }
    for( int j = 0; j < i; j++ ) {
      cin >> lis[ j ];
    }
    n = O_NUM;
    for( int j = 0; n > 0; j++ ) {
      if( !( j % 2 ) ) {
        n -= ( n - 1 ) % 5;
      } else {
        n -= lis[ j / 2 % i ];
      }
      n = max( 0, n );
      cout << n << endl;
    }
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long

using namespace std;

const ll mod = (ll)1e9 + 7; 
const int N = 200200; 

int n, m, x[N], y[N]; 
int cnt, tot, key[N]; 
ll f[N], c[N]; 

int lb(int x) {
  return x & (-x); 
}

void add(int x, ll d) {
  for(int i = x; i <= tot; i += lb(i))
    c[i] += d, c[i] %= mod; 
}

ll sum(int x) {
  ll ret = 0; 
  for(int i = x; i; i -= lb(i)) 
    ret = (ret + c[i]) % mod; 
  return ret; 
}

pair <int, int> P[N]; 

bool cmp(pair <int, int> x, pair <int, int> y) {
  return x.fi == y.fi ? x.se > y.se : x.fi < y.fi; 
}

int main() {
  scanf("%d %d", &n, &m); 
  for(int i = 1; i <= n; i++) {
    scanf("%d", &x[i]); 
  }
  for(int i = 1; i <= m; i++) {
    scanf("%d", &y[i]); 
  }
  sort(x + 1, x + n + 1); 
  sort(y + 1, y + m + 1); 
  for(int i = 1; i <= n; i++) {
    if(x[i] <= y[1] || x[i] >= y[m]) continue ; 
    int lp, rp; 
    lp = lower_bound(y + 1, y + m + 1, x[i]) - y - 1; 
    rp = lp + 1; 
    if(y[lp] == x[i]) continue ; 
    P[++cnt].fi = x[i] - y[lp]; 
    P[cnt].se = y[rp] - x[i];
    key[cnt] = P[cnt].se;  
  }
  
  sort(key + 1, key + cnt + 1); 
  tot = unique(key + 1, key + cnt + 1) - key - 1; 
  for(int i = 1; i <= cnt; i++) {
    P[i].se = lower_bound(key + 1, key + tot + 1, P[i].se) - key; 
  }
  ll ans = 0; 
  sort(P + 1, P + cnt + 1, cmp);
  cnt = unique(P + 1, P + cnt + 1) - P - 1; 
  for(int i = 1; i <= cnt; i++) {
    ll tmp = sum(P[i].se - 1) + 1; 
    ans += tmp; ans %= mod; 
    add(P[i].se, tmp); 
  }
  printf("%lld\n", (ans + 1) % mod); 
  return 0; 
}

Measured memory_bytes: 6016
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

bool IsPrime[MAX];
ll MinFactor[MAX]; vector<ll> preprocess(ll n = MAX) {
    vector<ll> res;
    for (ll i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
    IsPrime[0] = false; IsPrime[1] = false;
    MinFactor[0] = 0; MinFactor[1] = 1;
    for (ll i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            MinFactor[i] = i;
            res.push_back(i);
            for (ll j = i * 2; j < n; j += i) {
                IsPrime[j] = false;
                if (MinFactor[j] == -1) MinFactor[j] = i;
            }
        }
    }
    return res;
}

vector<pair<ll, ll> > fast_prime_factor(ll n) {
    vector<pair<ll, ll> > res;
    while (n != 1) {
        ll prime = MinFactor[n];
        ll exp = 0;
        while (MinFactor[n] == prime) {
            ++exp;
            n /= prime;
        }
        res.push_back(make_pair(prime, exp));
    }
    return res;
}

ll power(ll x, ll n) {
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 0) {
        return power(x * x, n / 2);
    }
    else {
        return x * power(x, n - 1);
    }
}

ll cnt[105000];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
    preprocess();
	vector<ll> pr;
    for (ll i = 2; i <= 100000; i++) {
        cnt[i] = cnt[i - 1];
        vector<pair<ll, ll>> p = fast_prime_factor(i);
        ll c = 1;
        for (auto e : p) {
            c *= (e.second + 1);
        }
        if (c >= 5) cnt[i]++;
    }
	ll Q; scanf("%lld", &Q);
	while (Q--) {
		ll n; scanf("%lld", &n);
        printf("%lld\n", cnt[n]);
	}
	return 0;
}


Measured memory_bytes: 51728
#include <bits/stdc++.h>
        #include<iostream>
        #include<algorithm>
        #include<set>
        #include<map>
        #include<math.h>
        //#include <ttmath.h>
        #define endl '\n'
        #define modulo 1000000007
        #define int long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        using namespace std;
        int power(int x,int y)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2))%modulo;
        if (y%2 == 0)
        return ((temp%modulo)*temp)%modulo;
        else
        return ((x*temp%modulo)*temp)%modulo;
        }
        int inv(int x)
        {
        return (power(x,modulo-2)+modulo)%modulo;
        }
        /*#include "testlib.h"
        int main(int argc, char* argv[])
        {
        iostream::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        registerGen(argc, argv, 1);
        int n,k;
        n=rnd.next(1,50);
        k=rnd.next(1,n);
        cout<<n<<' '<<k;
        }*/
        bool comp(pair<int,int>a,pair<int,int> b)
        {
            return a.second>b.second;
        }
        int CeilIndex(std::vector<int>& v, int l, int r, int key)
{
    while (r - l > 1) {
        int m = l + (r - l) / 2;
        if (v[m] < key)
            r = m;
        else
            l = m;
    }

    return r;
}

int LDS(std::vector<int>& v)
{
    if (v.size() == 0)
        return 0;

    std::vector<int> tail(v.size(), 0);
    int length = 1; // always points empty slot in tail

    tail[0] = v[0];
    for (size_t i = 1; i < v.size(); i++) {

        // new smallest value
        if (v[i] > tail[0])
            tail[0] = v[i];

        // v[i] extends largest subsequence
        else if (v[i] <= tail[length - 1])
            tail[length++] = v[i];

        // v[i] will become end candidate of an existing
        // subsequence or Throw away larger elements in all
        // LIS, to make room for upcoming grater elements
        // than v[i] (and also, v[i] would have already
        // appeared in one of LIS, identify the location
        // and replace it)
        else
        tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
        }
        return length;
        }
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input4.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            int n,buff;
            cin>>n;
            vector<int>lolz;
            for(int i=0;i<n;i++){
            cin>>buff;
            lolz.push_back(buff);
            }
            cout<<LDS(lolz);
            return 0;
        }


Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, x = 1;
  cin >> N >> K;
  
  for(int i = 0; i < N; i++){
    
    if(x * 2 >= x + K)
      x += K;
    
    else
      x *= 2;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] arg) {
		int MOD = 1000000007;
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] w = new int[N + 1];
		for (int i = 0; i < N; ++i) {
			w[i] = sc.nextInt();
		}
		w[N] = 1 << 30;
		Arrays.sort(w);
		long ans = 0;
		int sum = 0;
		int[] dp = new int[W + 1];
		for (int i = 0; i <= N && sum <= W; ++i) {
			Arrays.fill(dp, 0);
			dp[sum] = 1;
			for (int j = i + 1; j < N; ++j) {
				for (int k = W; k - w[j] >= 0; --k) {
					dp[k] += dp[k - w[j]];
					if (dp[k] >= MOD) dp[k] -= MOD;
				}
			}
			for (int j = W; j + w[i] > W && j >= 0; --j) {
				ans += dp[j];
			}
			sum += w[i];
		}
		System.out.println(ans % MOD);
	}
}

Measured memory_bytes: 21556