akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;

template <typename T>
void read(T &x)
{
    static char ch;
    for (ch = getchar(); !isdigit(ch); ch = getchar()) ;
    for (x = 0; isdigit(ch); ch = getchar())
        x = (x<<3)+(x<<1)+ch-'0';
}

const int N = 105;

int n;
int a[N];

int ans = 1e9;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    for (int i = -100; i < 101; ++i)
    {
        int t = 0;
        for (int j = 1; j <= n; ++j)
        {
            t += (i-a[j])*(i-a[j]);
        }
        ans = min(ans, t);
    }
    cout << ans << endl;
}


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

int main(){
    long long a, b;
    cin >> a >> b;

    long long ans = 0;

    long long tap = 1;
    while(tap < b){
        ans++;
        tap += a-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int gcd(int x,int y){
  if(y == 0)return x;
  return gcd(y,x % y);
}

int main(){
  cin >> n;
  s = "Yes";
  int o = 0,p = 0,q = 0;
  rep(i,0,n){
    int a,b,c;
    cin >> a >> b >> c;
    if(abs(o-a) < abs(p-b)+abs(q-c))s = "No";
    if(!(abs(o-a) == abs(p-b)+abs(q-c))){
      if(abs(o-a) % 2 == 0){
        if((abs(p-b)+abs(q-c)) % 2 != 0)s = "No";
      }
      else{
        if((abs(p-b)+abs(q-c)) % 2 != 1)s = "No";
      }
    }
    o = a;p = b;q = c;
  }
  print(s);
  return 0;
}

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

def dfs(n):
    if int(n) > N:
        return 0

    if all(n.count(i)>0 for i in "753"):
        ret = 1
    else:
        ret = 0
        
    for i in "753":
        ret += dfs(n+i)

    return ret

print(dfs("0"))

Measured memory_bytes: 55004
#include <stdio.h>
#define inf 9999999 
#define r 100 
#define c 100 

int n,M[r][c],a[100];

void matrixChainOrder(int a[])
{
  int i,j,k,l,m;
 
  for(i = 1;i < n; i++){

    M[i][i]=0;
  }
   
  for(k=2;k <= n;k++){
    for(i=1;i <= n+1-k; i++){
      j=k+i-1;
      M[i][j]=inf;

      for(l = i; l <= j-1; l++){
    m = M[i][l] + M[l+1][j] + a[i-1]*a[l]*a[j];
    if(m < M[i][j]) {
      M[i][j] = m; 
      }  
      }
    }
  }
}


 
int main()
{
  int i;
 
  scanf("%d",&n);
  for(i = 1; i <= n;i++){
    scanf("%d%d",&a[i-1],&a[i]);  
    }     
 
  matrixChainOrder(a);
  printf("%d\n",M[1][n]);
 
  return 0;
}
 

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  ll n, m, Q; cin >> n >> m >> Q;
  vvl dp(n+1, vl(n+1, 0));
  rep(i,m) {
    int l, r; scanf("%d %d", &l, &r);
    dp[l][r]++;
  }
  rep(i,n+1) rep(j,n) dp[i][j+1] += dp[i][j];
  rep(i,n) rep(j,n+1) dp[i+1][j] += dp[i][j];
  
  rep(i,Q) {
    int p, q; scanf("%d %d", &p, &q);
    ll ans = dp[q][q];
    ans -= dp[q][p-1];
    ans -= dp[p-1][q];
    ans += dp[p-1][p-1];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2944
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    double R=double.Parse(Console.ReadLine());
      double G=double.Parse(Console.ReadLine());
      double ans;
      //G=(R+ans)/2;
      //2*G=R+ans;
      ans=2*G-R;
      Console.WriteLine(ans);
    }
    
  }

}


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

int main() {
	int x,y;
	bool hantei = true;
	cin >> x >> y;

	if (y % 4 != 0) {
	
	}
	else {
	
	}


	if (x * 2 > y || x * 4 < y || y % 2 == 1)
		hantei = false;

	if (hantei)//出力
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;
 /*temp*/

int main(){
    int a[10];
    REP(i,10){
        cin >> a[i];
    }
    sort(a, a+10);
    cout << a[9] << '\n'
         << a[8] << '\n'
         << a[7] << '\n';
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int x[5];
	cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
	rep (i, 5) {if (x[i] == 0) {cout << i+1 << endl; break;}}
}


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

using namespace std;

int main() {
  char a, b;
  cin >> a >> b;

  if (a == 'H') {
    cout << b << endl;
  } else {
    if (b == 'H') {
      b = 'D';
    } else {
      b = 'H';
    }
    cout << b << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
   int a,b;cin>>a>>b;
   if (a<9&&b<9)
   {
      /* code */
      cout<<"Yay!"<<endl;
   }
   else
   {
      cout<<":("<<endl;
   }
   
   
   }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main() {
  int i, j;
  int v[3];
  REP(i, 3) cin >> v[i];

  for (i = 2; i > 0; i--) {
    for (j = 0; j < 2; j++) {
      if (v[j] > v[j + 1]) {
        swap(v[j], v[j + 1]);
      }
    }
  }
  REP(i, 2) cout << v[i] << ' ';
  cout << v[2] << endl;

  return  0;
}



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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);

		int manysti = 0;
		long st[] = new long[2];
		st[1]=0;
		st[0]=0;
		for (int i = n - 1; i >= 1; i--) {
			if (a[i] == a[i - 1]) {

				st[manysti] = a[i];
				i--;
				manysti++;
				if (manysti == 2) {
					break;
				}
			}
		}

		System.out.println(st[0]*st[1]);
	}
}

Measured memory_bytes: 51744
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

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

	int max_num = ceil((-1.0 + sqrt(1 + 8*N))/2.0);
	int tmp = max_num;
	while( N > 0 ){
		cout << tmp << endl;
		N -= tmp;

		if( N >= tmp ){
			--tmp;
		}
		else{
			if( N != 0 ) cout << N << endl;
			break;
		}
	}
}


Measured memory_bytes: 256
//abc072_b.cpp
//Sat Sep  8 18:30:24 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	for (int i=0;i<s.length();i=i+2){
		cout << s[i];
	}

	printf("\n");

//	printf("%.4f\n",ans);
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int X=stdIn.nextInt();
		int A[]=new int[N];
		int B[]=new int[N-1];
		int z=0,y=0,x=0;
		long ans=0;
		while(z<N){
			A[z]=stdIn.nextInt();
			z++;
		}z=0;
		while(z<N-1){
			B[z]=A[z]+A[z+1];
			z++;
		}z=0;
		while(z<N-1){
			if(B[z]>X){
				y=B[z]-X;
				if(y>A[z+1]){
					x=y-A[z+1];y=A[z+1];
				}
				A[z]-=x;
				A[z+1]-=y;
				if(z!=N-2)
					B[z+1]-=y;
				ans+=x+y;
			}
			x=0;y=0;z++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 64044
function abc069_b()

	# STEP.01
	# get the target date
	word = Base.chomp( Base.readline( Base.STDIN ) )

	# STEP.02
	# output the result
	Base.println( Base.STDOUT, word[1:1],Base.length( word )-2,word[end:end] )

	# STEP.TRUE_END
	return Base.nothing

end

#===================================================================================#

Main.abc069_b()


Measured memory_bytes: 164180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 200010
#define N 1010 
#define inf 0x7fffffff
/*------------------------------------------------------------*/

bool f[N][N];
bool used[N];
int match[N];
int n,m,e;
struct node{
	int x,y;
}a[maxn];
bool DFS(int pos)
{
    for(int i=1; i<=2*n; i++)
    {
        if(f[pos][i] && !used[i])
        {
            used[i] = true;
            if(!match[i] || DFS(match[i])) //如果这个点i还未匹配则pos和他匹配，如果这个点已经匹配，那么如果本来和他匹配的点match[i]还能找到另一个点匹配则pos把i“抢”过来，让match[i]去匹配另一个点，否则就不干涉i和match[i]匹配
            {
                match[i] = pos;
                return true;
            }
        }
    }
    return false; 
}					
int main(){
	in(n);
	FOR(i,1,n)in2(a[i].x,a[i].y);
	FOR(i,n+1,n*2)in2(a[i].x,a[i].y);
	FOR(i,1,n)
		FOR(j,n+1,n*2)
			if(a[i].x<a[j].x&&a[i].y<a[j].y){
				f[i][j]=true;
			}
	int ans=0;
	FOR(i,1,n){
		memset(used,false,sizeof(used)); 
		if(DFS(i))ans++;
	}
	out(ans); 
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

map<int, int> res;

void prime_factor(int n){
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n]++;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        prime_factor(i);
    }
    int ans = 1;
    for(auto i : res){
        ans *= i.second + 1;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int K = int.Parse(Console.ReadLine());
        int res = 0;
        for (int a = 1; a <= K; a++)
        {
            for (int b = 1; b <= K; b++)
            {
                for (int c = 1; c <= K; c++)
                {
                    res += ArrayGcd(new int[] { a, b, c });
                }
            }
        }
        Console.WriteLine(res);
    }
    static int Gcd(int a, int b)
    {
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
    static int ArrayGcd(int[] a)
    {
        int res = Gcd(a[0], a[1]);
        for (int i = 2; i < a.Length; i++)
            res = Gcd(res, a[2]);
        return res;
    }
}


Measured memory_bytes: 40552
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
const int MAXN = 300005;
long long bit[64]={0};
long long pow1[64]={0};
long long a[MAXN];
int maxlen = 0 ;
void add(long long a){
    int i;
    for(i=0;a;i++){
        bit[i]+=(a%2);
        a/=2;
    }
    maxlen = max(maxlen,i);
}
int main()
{
    pow1[0]=1;
    for(int i=1;i<63;i++)
        pow1[i]=pow1[i-1]*2%mod;
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        add(a[i]);
    }
    long long ans = 0 ;
    for(int j=0;j<n;j++){
        for(int i=0;i<maxlen;i++){
        if(a[j]&1)
            ans= (ans + pow1[i]*(n-bit[i])%mod)%mod;
        else
            ans= (ans + pow1[i]*bit[i]%mod)%mod;
            a[j]/=2;
        //cout << ans <<endl;
        }
    }
    cout << ans*((mod+1)/2)%mod << endl;
    return 0;
}


Measured memory_bytes: 5960
import           Control.Applicative
import           Data.List

point :: String -> String -> (Int, Int)
point xs ys
    | xs < ys = (0, 3)
    | xs > ys = (3, 0)
    | otherwise = (1, 1)

addPair :: (Int, Int) -> (Int, Int) -> (Int, Int)
addPair (a,b) (c,d) = (a + c, b + d)

main :: IO ()
main = do
    getLine
    xss <- fmap words . lines <$> getContents
    let (taro, hanako) =
            foldr (\[as, bs] acc -> (point as bs) `addPair` acc) (0, 0) xss
    putStrLn $ show taro ++ " " ++ show hanako



Measured memory_bytes: 4092
#include<iostream>
#include<cstring>
  
using namespace std;
  
const int Height = 5100;
const int Width = 5;
char field[Height][Width];
int top,ans;
int dx[] = {1,0};
int dy[] = {0,-1};
  
void print(int h, int w){
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++) cout << field[i][j];
    cout << endl;
  }
  cout << endl; 
}

bool isInside(int h, int w){ return 0<=h&&h<Height&&0<=w&&w<Width;}

int getH(int d, int len, int pos){
  for(int i = top+10; i>=0; i--){
    int h = i;
    int w = pos;
    for(int j = 0; j < len; j++){
      if(field[h][w] != '?' || !isInside(h,w)) return i+1;
      h += dy[d];
      w += dx[d];
    }
  }
  return 0;
}
 
void down(int n){
  
  for(int i = n; i <= top+6; i++)
    for(int j = 0; j < Width; j++) field[i][j] = field[i+1][j];
  // top--;
}
 
void erase(){
 
  for(int i = 0; i <= top+6; i++){
    bool f = true;
    for(int j = 0; j < Width; j++) if(field[i][j] == '?') f = false;
    if(f){
      ans -= 5;
      down(i--);
    }
  }
}
  
void put(int d, int len, int pos){
  
  int nex = getH(d,len,pos);
  top = max(top,nex);
  
  int h = nex;
  int w = pos;
  
  for(int i = 0; i < len; i++){
    field[h][w] = '.';
    h += dy[d];
    w += dx[d];
  }
}
  
int main(){
  
  int n;
  while(cin >> n && n){
    memset(field,'?',sizeof(field));
    ans = top = 0;
     
    while(n--){
      int d, len, pos;
      cin >> d >> len >> pos;
      ans += len;
      put(d-1,len,pos-1);
      erase();
    }
    cout << ans << endl;
    //  print(10,5);
  }
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    sort(A, A+N, greater<ll>());
    vector<pair<ll, int>> B;
    int row = 0;
    rep(i, N){
        if(i == 0){
            row++;
        }
        else if(i == N-1){
            if(A[i] != A[i-1]){
                B.push_back(make_pair(A[i-1], row));
                B.push_back(make_pair(A[i], 1));
            }
            else{
                row++;
                B.push_back(make_pair(A[i], row));
            }
        }
        else{
            if(A[i] != A[i-1]){
                B.push_back(make_pair(A[i-1], row));
                row = 1;
            }
            else row++;
        }
    }
    int idx = 0, cnt = 0;
    ll pow2[32] = {1};
    for(int i = 1; i < 32; i++){
        pow2[i] = pow2[i-1]*2;
    }

    while(idx < B.size()){
        ll num = B[idx].first;
        if(B[idx].second == 0){
            idx++;
            continue;
        }
        bool found = false;
        int beki = (int) log2(num);
        ll aim = pow2[beki+1] - num;
        //cout << num << " " << aim << endl;
        //aimをBの中からにぶたん、あればfound = true
        int ng = -1, ok = B.size();
        int m = (ng+ok)/2;
        while(abs(ng-ok) > 1){
            if(B[m].first > aim) ng = m;
            else ok = m;
            m = (ng+ok)/2;
        }
        if(B[ok].first == aim && B[ok].second > 0) found = true;
        if(aim == num && B[ok].second <= 1) found = false;

        if(found){
            cnt++;
            B[idx].second -= 1;
            B[ok].second -= 1;
            if(B[idx].second == 0) idx++;
        }
        else idx++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 7920
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  cin >> n;
  int sum = 0;
  for(int i=0; i<n; i++){
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;

  return 0;
}

// EOF


Measured memory_bytes: 256
#include<cstdio>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define calc(xl,xr,yl,yr) (sum[xr][yr]-sum[xl-1][yr]-sum[xr][yl-1]+sum[xl-1][yl-1])
const int N=105;
int n,m,ex,ey,ans,sum[N][N],f[2][N][N][N];
char s[N][N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++){
			sum[i][j]=sum[i][j-1];
			if(s[i][j]=='E'){
				ex=i;
				ey=j;
			}else if(s[i][j]=='o'){
				sum[i][j]++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			sum[i][j]+=sum[i-1][j];
		}
	}
	int sta=0;
	for(int i=1;i<=n;i++,sta^=1){
		for(int j=n;j>=i;j--){
			for(int k=1;k<=m;k++){
				for(int l=m;l>=k;l--){
					if(i-1>=1&&((i-1<=ex&&j+ex-(i-1)<=n)||(i-1>=ex&&j-((i-1)-ex)>=1))){
						f[sta][j][k][l]=max(f[sta][j][k][l],f[sta^1][j][k][l]+calc(i-1,i-1,max(k,ey-(m-l)),min(l,ey+k-1)));
					}
					if(j+1<=n&&((j+1<=ex&&i+ex-(j+1)<=n)||(j+1>=ex&&i-((j+1)-ex)>=1))){
						f[sta][j][k][l]=max(f[sta][j][k][l],f[sta][j+1][k][l]+calc(j+1,j+1,max(k,ey-(m-l)),min(l,ey+k-1)));
					}
					if(k-1>=1&&((k-1<=ey&&l+ey-(k-1)<=m)||(k-1>=ey&&l-((k-1)-ey)>=1))){
						f[sta][j][k][l]=max(f[sta][j][k][l],f[sta][j][k-1][l]+calc(max(i,ex-(n-j)),min(j,ex+i-1),k-1,k-1));
					}
					if(l+1<=m&&((l+1<=ey&&k+ey-(l+1)<=m)||(l+1>=ey&&k-((l+1)-ey)>=1))){
						f[sta][j][k][l]=max(f[sta][j][k][l],f[sta][j][k][l+1]+calc(max(i,ex-(n-j)),min(j,ex+i-1),l+1,l+1));
					}
					if(i==j&&k==l){
						ans=max(ans,f[sta][j][k][l]+(s[i][k]=='o'));
					}
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9216
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := next()
	sum := 0
	slice := strings.Split(n, "")
	for i := 0; i < len(slice); i++ {
		num, _ := strconv.Atoi(slice[i])
		sum += num
	}
	if sum%9 == 0 {
		fmt.Fprintf(out, "%s\n", "Yes")
	} else {
		fmt.Fprintf(out, "%s\n", "No")
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func quickSort(val []int) []int {
	if len(val) < 2 {
		return val
	}

	pivot := val[0]

	left := []int{}
	right := []int{}

	for _, v := range val[1:] {
		if pivot > v {
			left = append(left, v)
		} else {
			right = append(right, v)
		}
	}

	left = quickSort(left)
	right = quickSort(right)

	ret := append(left, pivot)
	ret = append(ret, right...)

	return ret
}


Measured memory_bytes: 5476
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
int main(){
    cs;
    set<char> t;
    t.insert('A');
    t.insert('T');
    t.insert('C');
    t.insert('G');
    string s;
    cin>>s;
    s.push_back('Z');
    int ans=0,tmp=0;
    rep(i,s.size()) {
        if(t.count(s[i])) tmp++;
        else {ans=max(ans,tmp);tmp=0;} 
    }
    cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
       List<String> list = Arrays.asList(sc.next().split(""));
       Collections.sort(list);
    
		// 出力
		System.out.println(list.get(0).equals(list.get(1))
       && list.get(2).equals(list.get(3)) && !list.get(1).equals(list.get(2)) ? "Yes" : "No");
	}
}

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

struct Node_tag{
	int key;
	Node_tag *parent, *left, *right;
};

typedef struct Node_tag Node;

Node *root;
Node *nil = (Node *)malloc(sizeof(Node));

void init(){
	nil->parent = nil->left = nil->right = nil;
	root = nil;
}


void inParse(Node *u){
	if(u == nil)
		return;
	inParse(u->left);
	printf(" %d", u->key);
	inParse(u->right);
}

void preParse(Node *u){
	if(u == nil)
		return;
	printf(" %d", u->key);
	preParse(u->left);
	preParse(u->right);
}

void insert(Node *z){
	Node *x = root, *y = nil;
	while(x != nil){
		y = x;
		if(z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;

    if (y == nil)
        root = z;
    else if(z->key < y->key)
        y->left = z;
    else
        y->right = z;
}

Node* find(Node *x, int k){
	while(x != nil && k != x->key){
		if(k < x->key)
			x = x->left;
		else
			x = x->right;
	}
	return x;
}

int main(void){
	int m, i, key;
	char S[10];
	init();
	scanf("%d", &m);
	for(i = 0;i < m;i++){
		scanf("%s", S);
		if(S[0] == 'i'){
			scanf("%d", &key);
			Node *z = (Node *)malloc(sizeof(Node));
			z->key = key;
			z->left = z->right = nil;
			insert(z);
		} else if(S[0] == 'p'){
			inParse(root);
			printf("\n");
			preParse(root);
			printf("\n");
		} else {
			scanf("%d", &key);
			if(find(root, key) != nil)
				printf("yes\n");
			else
				printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 21332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		//System.out.println("??\???>>");

		Scanner scan = new Scanner(System.in);

		int w = scan.nextInt();
		int h = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();

		//
		if(r <= x && (x + r) <= w && r <= y && (y + r) <= h){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

		scan.close();

	}

}

Measured memory_bytes: 17228
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const ll MOD=1e9+7;
    static const int MAXN=2e5+10;
    ll factor[MAXN];
    ll N,M,K;
    Solver(){
        factor[0]=1;
        for(ll i=1;i<MAXN;i++){
            factor[i]=i*factor[i-1]%MOD;
        }
    }
    ll egcd(ll a,ll b,ll &x,ll &y){
        if(a==0){
            x=0;
            y=1;
            return b;
        }
        ll x1,y1;
        ll d=egcd(b%a,a,x1,y1);
        x=y1-(b/a)*x1;
        y=x1;
        return d;
    }
    ll modInv(ll k){
        ll g,x,y;
        g=egcd(k,MOD,x,y);
        if(g!=1)return -1;
        return (x%MOD+MOD)%MOD;
    }
    ll comb(ll n,ll m){
        if(n<m)swap(n,m);
        ll rt=factor[n]*modInv(factor[m])%MOD;
        rt=rt*modInv(factor[n-m])%MOD;
        return rt;
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin>>N>>M>>K;
        ll ans=0;
        for(ll d=1;d<=N-1;d++){
            ll tmp=d*M*M%MOD*(N-d)%MOD;
            ans=(ans+tmp*comb(N*M-2,K-2)%MOD)%MOD;
        }
        for(ll d=1;d<=M-1;d++){
            ll tmp=d*N*N%MOD*(M-d)%MOD;
            ans=(ans+tmp*comb(N*M-2,K-2)%MOD)%MOD;
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int N, L, i, sum=0;
  scanf("%d", &N);
  vector<int> v(N);
  for (i=0; i<N; i++) {
    scanf("%d", &v[i]);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (i=1; i<N; i++) sum+=v[i];
  if (v[0]<sum) printf("Yes\n");
  else printf("No\n");
}

Measured memory_bytes: 256
// C
 #ifndef _GLIBCXX_NO_ASSERT
 #include <cassert>
 #endif
 #include <cctype>
 #include <cerrno>
 #include <cfloat>
 #include <ciso646>
 #include <climits>
 #include <clocale>
 #include <cmath>
 #include <csetjmp>
 #include <csignal>
 #include <cstdarg>
 #include <cstddef>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <ctime> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <ccomplex>
 #include <cfenv>
 #include <cinttypes>
 #include <cstdbool>
 #include <cstdint>
 #include <ctgmath>
 #include <cwchar>
 #include <cwctype>
 #endif
 
 // C++
 #include <algorithm>
 #include <bitset>
 #include <complex>
 #include <deque>
 #include <exception>
 #include <fstream>
 #include <functional>
 #include <iomanip>
 #include <ios>
 #include <iosfwd>
 #include <iostream>
 #include <istream>
 #include <iterator>
 #include <limits>
 #include <list>
 #include <locale>
 #include <map>
 #include <memory>
 #include <new>
 #include <numeric>
 #include <ostream>
 #include <queue>
 #include <set>
 #include <sstream>
 #include <stack>
 #include <stdexcept>
 #include <streambuf>
 #include <string>
 #include <typeinfo>
 #include <utility>
 #include <valarray>
 #include <vector> 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
 #include <array>
 #include <atomic>
 #include <chrono>
 #include <condition_variable>
 #include <forward_list>
 #include <future>
 #include <initializer_list>
 #include <mutex>
 #include <random>
 #include <ratio>
 #include <regex>
 #include <system_error>
 #include <thread>
 #include <tuple>
 #include <typeindex>
 #include <type_traits>
 #include <unordered_map>
 #include <unordered_set>
 #endif
 
using namespace std;

int main(){
    int n,q;
    cin >> n;
    vector<long long> s(n);
    for(int i=0;i<n;++i) cin >> s[i];
    cin >> q;
    vector<long long> t(q);
    for(int i=0;i<q;++i) cin >> t[i];
    long long left,right;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());

    long long ct=0;
    for(int i=0;i<q;++i){
        left = 0;
        right = n-1;
        while(left<=right){
            long long mid = (left+right)/2;
            if(s[mid] == t[i]){
                ct++;
                break;
            }
            else if(s[mid] > t[i]){
                right = mid-1;
            }
            else left = mid+1;
        }
    }
    cout << ct << endl;
    return 0;
}


Measured memory_bytes: 3788
s = input()
K = int(input())
l = ['zzzzzzzzzzzzzzz','zzzzzzzzzzzzzzz','zzzzzzzzzzzzz','zzzzzzzzzzzz','zzzzzzzzz']
N = len(s)

for i in range(K+1):
    for j in range(N-i):
        tmp = s[j:j+i+1]
        if tmp not in l:
            l.append(tmp)
        l.sort()
        l = l[0:5]


l.sort()
#print(l)


ans = l[K-1]
print(ans)



Measured memory_bytes: 3060
"""
Warshall-Floyd
"""

INF = 10 ** 20

v_num, e_num = map(int, input().split())
dist_lst = [[INF] * v_num for _ in range(v_num)]
negative_cycle_flag = False
for _ in range(e_num):
  s, t, dist = map(int, input().split())
  dist_lst[s][t] = dist

for v in range(v_num):
  dist_lst[v][v] = 0

for k in range(v_num):
  for i in range(v_num):
    for j in range(v_num):
      if dist_lst[i][k] != INF and dist_lst[k][j] != INF:
        if dist_lst[i][j] > dist_lst[i][k] + dist_lst[k][j]:
          dist_lst[i][j] = dist_lst[i][k] + dist_lst[k][j]

for v in range(v_num):
  if dist_lst[v][v] < 0:
    negative_cycle_flag = True

if negative_cycle_flag:
  print("NEGATIVE CYCLE")
else:
  for lst in dist_lst:
    put = ""
    for i in lst:
      if i == INF:
        put += "INF" + " "
      else:
        put += str(i) + " "
    print(put.rstrip())


Measured memory_bytes: 5988
import java.util.*;

public class Main {
    static int head = 0;
    static int tail = 0;
    static final int MAX = 100000;
    static int[] Q = new int[MAX];
    static int NOW = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        LinkedList<String> name = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            name.offer(sc.next());
            enqueue(sc.nextInt());
        }

        ArrayList<String> ansName = new ArrayList<>();
        ArrayList<Integer> ansTime = new ArrayList<>();
        String tmpName;
        int tmpTime;

        while(!isEmpty()){
            tmpName = name.poll();
            tmpTime = dequeue();
            if(tmpTime <= q){
                NOW += tmpTime;
                ansName.add(tmpName);
                ansTime.add(NOW);
            }else{
                NOW += q;
                name.offer(tmpName);
                tmpTime -= q;
                enqueue(tmpTime);
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(ansName.get(i) + " " + ansTime.get(i));
        }
    }

    static Boolean isEmpty(){
        return head == tail;
    }

    static void enqueue(int x){
        Q[tail] = x;
        if(tail + 1 == MAX){
            tail = 0;
        }else{
            tail ++;
        }
    }

    static int dequeue(){
        int x = Q[head];
        if(head + 1 == MAX){
            head = 0;
        }else {
            head++;
        }
        return x;
    }
}



Measured memory_bytes: 84732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#define _GLIBCXX_DEBUG
     
int main() {
  int val_a, val_b, val_c, want_x, want_y;
  cin >> val_a >> val_b >> val_c >> want_x >> want_y;

  int a=0, b=0, c=max(want_x, want_y) * 2;
  ll ans = c * val_c;
  for (--c; c>=0; --c) {
    if (want_x > a + c / 2) ++a;
    if (want_y > b + c / 2) ++b;
    if (ans > a * val_a + b * val_b + c * val_c) {
      ans = a * val_a + b * val_b + c * val_c;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    n = gets.chomp.to_i

    1.upto(9) do |a|
      d, r = n.divmod(a)
      next if 0 < r

      if 1 <= d && d <= 9
        puts "Yes"
        return
      end
    end

    puts "No"
  end
end

if __FILE__ == $0
  Solver.new.main
end


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


int main(){
    int a[10000];
    int total = 0;
    for(int i = 0 ;i <= 10000; i ++){
        int tmp;
        cin >> tmp;
//        if(tmp < 0 || tmp >= 10000) return -1;
        if(tmp == 0){
            break;
        }
        a[i] = tmp;
        total ++;
    }

    for(int j = 0; j <= total-1; j ++)
        cout << "Case " << j+1 << ": " << a[j] << endl;

    return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a, b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(0LL, a + b - n) << "\n";
    cerr << "Heloo\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
i64 k;
i64 a[100010];
i64 b[100010];


i64 cal(int K)
{
    i64 value = 0;
    rep(i,0,n - 1)
    {
        if(!(a[i] & ~K))
        {
            value += b[i];
        }
    }
    return value;
}

int main()
{
    cin >> n >> k;
    rep(i,0,n - 1) cin >> a[i] >> b[i];

    i64 result = cal(k);
    int MAX = log2(k) + 1;
    rep(i,0,MAX)
    {
        if(k & (1 << i))
        {
            int temp = k;
            temp = temp & ~(1 << i);
            temp = temp | ((1 << i) - 1);
            result = max(result ,cal(temp));
        }
    }
    cout << result << endl;
}

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

using namespace std;


#define PI 3.14159265
#define int long long
#define double long double

const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;

char f(char a, char b){
	int ans = 'R' + 'G' + 'B';
	
	return (char)(ans - a - b);
}


void solve(){
	
	int n; cin >> n;

	string s; cin >> s;

	map <int, vector <int> > m;

	for(int i = 0; i < n; i++){
		m[s[i]].emplace_back(i);
	}

	int ans = 0;

	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){

			if(s[i] != s[j]){
				char c = f(s[i], s[j]);
				auto it = upper_bound(m[c].begin(), m[c].end(), j);
				int add = m[c].end() - it;

				if(2 * j - i < n and s[2 * j - i] != s[i] and s[2 * j - i] != s[j]){
					ans += add - 1;
				}else{
					ans += add;
				}
			}
		}
	}


	cout << ans << endl;
	
}



main(){

	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);


	int test = 1;

	// cin >> test;

	while(test--){
		solve();
	}


	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

// main starts here

int main(){
    vector<vector<unsigned short>> dp(200000,vector<unsigned short>(2019,0));
    string s; cin >> s;
    ll ss = s.size();
    ll x = s.at(0) - '0';
    dp[0][x]=1;
    ll ans = 0;
    for(int i=1;i<ss;i++){
        x = s.at(i) - '0';
        for(int j=0;j<2019;j++){
            ll y = (j*10+x)%2019;
            dp[i][y] += dp[i-1][j];
        }
        dp[i][x]++;
        ans+=dp[i][0];        
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 798972
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>

using namespace std;

bool flag = 1;
int C = 0;
int n;

void dfs(int u, vector<int>& col, vector<int> &used, vector<vector<int> >& graph) {
	used[u] = C;
	for (int v : graph[u]) {
		if (col[v] == -1) {
			col[v] = col[u] ^ 1;
			dfs(v, col, used, graph);
			if (!flag)
				return;
			continue;
		}
		if (col[v] == col[u]) {
			flag = 0;
			return;
		}
	}
}

int bfs(int u, vector<vector<int> >& graph) {
	vector<int> dist(n);
	//dist.resize(n);
	for (int i = 0; i < n; i++)
		dist[i] = -1;
	dist[u] = 0;
	deque<int> d;
	d.push_back(u);
	int maxim = 0;
	while (d.size() > 0) {
		int now = d[0];
		maxim = dist[now];
		d.pop_front();
		for (int v : graph[now]) {
			if (dist[v] == -1) {
				dist[v] = dist[now] + 1;
				d.push_back(v);
			}
		}
	}
	return maxim;
}

int main() {
	cin >> n;
	string help;
	vector<vector<int> > graph(n);
	vector<string> mat(n);
	for (int i = 0; i < n; i++) {
		cin >> help;
		mat[i] = help;
		for (int j = 0; j < n; j++) {
			if (mat[i][j] == '1')
				graph[i].push_back(j);
		}
	}
	vector<int> col(n);
	vector<int> used(n);
	for (int i = 0; i < n; i++) {
		col[i] = -1;
		used[i] = -1;
	}
	for (int i = 0; i < n; i++) {
		if (col[i] != -1)
			continue;
		col[i] = 0;
		dfs(i, col, used, graph);
		C++;
		if (!flag) {
			cout << -1 << endl;
			return 0;
		}
	}
	vector<int> maxim(C);
	for (int i = 0; i < C; i++)
		maxim[i] = 0;
	for (int i = 0; i < n; i++) {
		int ind = used[i];
		int val = bfs(i, graph);
		maxim[ind] = max(maxim[ind], val);
	}
	int ans = 0;
	for (auto elem : maxim)
		ans += elem + 1;
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

string change(string boo){
  string str = "123";
  rep(i,0,boo.sz){
    if(boo[i] == '1')swap(str[1],str[2]);
    else swap(str[1],str[0]);
  }
  return str;
}

string exchange(string str,string key){
  if(key == "132")swap(str[1],str[2]);
  if(key == "321")swap(str[0],str[2]);
  if(key == "213")swap(str[0],str[1]);
  if(key == "231"){
    swap(str[0],str[1]);
    swap(str[1],str[2]);
  }
  if(key == "312"){
    swap(str[0],str[1]);
    swap(str[0],str[2]);
  }
  return str;
}

int main(){
  t = "no";
  int num[6] = {0,1,1,1,2,2};
  cin >> n;
  vector<string> vec{"123","132","321","213","231","312"};
  map<string,int> test;
  rep(i,0,n){
    string boolean;
    cin >> m;
    rep(j,0,m){
      char c;
      cin >> c;
      boolean += c;
    }
    test[change(boolean)]++;
  }
  rep(i,0,vec.sz)if(test[vec[i]] > num[i])t = "yes";
  if(t != "yes"){
    vector<string> vec2;
    rep(i,1,6){
      rep(j,0,test[vec[i]])vec2.pb(vec[i]);
    }
    sort(all(vec));
    do{
      string res = vec2[0];
      // cout << "first_res:" << res << endl;
      rep(i,1,vec2.sz){
        res = exchange(res,vec2[i]);
        // cout << "res:" << res << endl;
        if(res == "123")t = "yes";
      }
    }while(next_permutation(vec2.begin(),vec2.end()));
  }
  print(t);
  return 0;
}


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

long long modpow(long long a, long long b, long long m) {
	long long p = 1, q = a;
	for (int i = 0; i < 30; i++) {
		if ((b / (1LL << i)) % 2 == 1) { p *= q; p %= m; }
		q *= q; q %= m;
	}
	return p;
}
long long Div(long long a, long long b, long long m) {
	return (a*modpow(b, m - 2, m)) % m;
}

long long fact[300009], inv[300009], mod = 998244353;

void init() {
	fact[0] = 1; for (int i = 1; i <= 300000; i++) fact[i] = (1LL * fact[i - 1] * i) % mod;
	for (int i = 0; i <= 300000; i++) inv[i] = Div(1, fact[i], mod);
}
long long ncr(long long n, long long r) {
	if (r < 0 || n < r) return 0;
	return ((fact[n] * inv[r]) % mod)*inv[n - r] % mod;
}

long long N, K, A, B;

int main() {
	init();
	cin >> N >> A >> B >> K;
	long long sum = 0;
	for (int i = 0; i <= N; i++) {
		long long S = K - 1LL * A*i; if (S < 0 || S%B != 0) continue;
		long long A1 = i, A2 = S / B;
		long long V1 = ncr(N, A1), V2 = ncr(N, A2);
		sum += V1*V2; sum %= mod;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
 using namespace std;
 int main(){
     int A,B,C;
     
     cin >> A >> B >> C;
     
     if(B + C - A > 0){
     cout << B + C - A <<endl;
     }else{
         cout << 0 << endl;
     }
 }
 

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:10240000")
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX = 3500;

int main ()
{
    int n;
    scanf ("%d", &n);
    bool flag = false;
    for (int i = 1; i <= MAX; i ++)
    {
        for (int j = 1; j <= MAX; j ++)
        {
            long long x = (long long) n * i * j;
            long long y = (long long) 4 * i * j - (i + j) * n;
            if ((y > 0) && (x % y == 0))
            {
                long long tmp = x / y;
                if (tmp > 0)
                {
                    printf ("%d %d %I64d\n", i, j, tmp);
                    flag = true;
                    break;
                }
            }
        }
        if (flag)
        {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256