akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

char s[100010];
char m[100010];

int main(){
	scanf("%s" , s);
	int n = 0;
	for(; s[n] != 0 ; ++n){
		if(s[n] == 'b'){
			m[n] = 'd';
		} else if(s[n] == 'd'){
			m[n] = 'b';
		} else if(s[n] == 'p'){
			m[n] = 'q';
		} else {
			m[n] = 'p';
		}
	}
	repp(i,0,n){
		if(s[i] != m[n-i-1]){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}


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

int main(){
  ll n, k, l, r;
  cin >> n >> k >> l >> r;
  ll a[n];
  rep(i,n) cin >> a[i];
  vector<vector<ll>> val(k+1);
  rep(i,(1<<(n/2))) {
    ll cnt = 0;
    ll price = 0;
    rep(j,n/2) {
      if(i & (1<<j)) {
        cnt++;
        price += a[j];
      }
    }
    if(cnt <= k) val[cnt].push_back(price);
  }
  rep(i,k+1) sort(val[i].begin(),val[i].end());
  ll ans = 0;
  rep(i,(1<<(n-n/2))) {
    ll cnt = 0;
    ll price = 0;
    rep(j,n-n/2) {
      if(i & (1<<j)) {
        cnt++;
        price += a[n/2+j];
      }
    }
    if(cnt <= k) ans += upper_bound(val[k-cnt].begin(),val[k-cnt].end(),r-price) - lower_bound(val[k-cnt].begin(),val[k-cnt].end(),l-price);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 12248
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main()
{
    string s;
    cin >> s;
    cout << s.front() << s.size() - 2 << s.back() << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second

int mov[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

int dist[1005][1005];

int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	for (auto &i : a)
		cin >> i;

	memset(dist, 63, sizeof dist);
	queue<pair<int, int>> q;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
		{
			if (a[i][j] == '#')
			{
				dist[i][j] = 0;
				q.push({i, j});
			}
		}

	while (!q.empty())
	{
		int x, y;
		tie(x, y) = q.front();
		q.pop();

		for (int k = 0; k < 4; ++k)
		{
			int nx = x+mov[k][0];
			int ny = y+mov[k][1];

			if (nx >= 0 && nx < n && ny >= 0 && ny < m && dist[x][y]+1 < dist[nx][ny])
			{
				dist[nx][ny] = dist[x][y] + 1;
				q.push({nx, ny});
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			ans = max(ans, dist[i][j]);

	cout << ans << "\n";

	return 0;
}


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

#define int long long
int dp[65][35],ans;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}

void F(string s){
  int two=0,five=0,now=0,a=0,f=0;
  while(now<s.size()){
    if(s[now]=='.')f=1;
    else{
      a*=10;
      a+=s[now]-'0';
      if(f)two--,five--;
    }
    now++;
  }
  while(a%2==0)a/=2,two++;
  while(a%5==0)a/=5,five++;
  for(int i=0;i<65;i++){
    for(int j=0;j<35;j++){
      if(two+i>=30&&five+j>=15)ans+=dp[i][j];
    }
  }
  chmin(two,32LL);
  chmin(five,15LL);
  dp[two+30][five+15]++;
}


signed main(){
  int n;cin>>n;
  int cnt=0;
  for(int i=0;i<n;i++){
    string s;cin>>s;
    F(s);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	long long int n;
	cin >> n;
	vector<long long int> p(n);

	vector<long long int> a;

	for (long long int i = 0; i < n; i++) {
		cin >> p[i];
		if (p[i] == i + 1) {
			a.push_back(p[i]);
		}
	}

	long long int ans = 0;

	for (long long int i = 0; i < a.size(); i++) {
		if (i + 1 == a.size()) {
			ans++;
		} else if (a[i + 1] - a[i] == 1) {
			ans += 1;
			i++;
		}
		else {
			ans++;
		}
	}

	cout << ans << endl;
	

	return 0;
}

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

vector<int> s[10];

int main()
{
	int n, m, p[10];
	cin >> m >> n;
	for (int i = 0; i < n; i++)
	{
		int k;
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			int a;
			cin >> a;
			s[i].push_back(a);
		}
	}
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
	}

	int ans = 0;
	for (int state = 0; state < (1 << m); state++)
	{
		bool flag = true;
		for (int i = 0; i < n; i++)
		{
			int t = 0;
			for (int j = 0; j < s[i].size(); j++)
			{
				if (state&(1<<(s[i][j]-1))) t++;
			}
			if (t % 2 != p[i])
			{
				flag = false;
				break;
			}
			if (flag == false)
				break;
		}
		if (flag == true)
			ans++;
	}

	cout << ans;
}

Measured memory_bytes: 384
loop do
    n = gets.to_i
    
    if n == 0 then
        break
    end
    
    a = gets.split(" ").map(&:to_f)
    
    b = a.sum / a.size
    
    k = 0
    a.each do |i|
        k += (i - b) * (i - b)
    end
    
    print Math.sqrt(k / a.size), "\n"
end


Measured memory_bytes: 6916
import copy 

def gcd(a,b):
    if b > a:
        a, b = b, a
    while b:
        a, b = b, a%b
    return a

N = int(input())
T = list(map(int,input().split()))
T.sort()
LIS = [0]*N
LIS[0] += T[0]
for i in range(N-1):
    LIS[i+1] += gcd(LIS[i],T[i+1])
F = LIS.index(min(LIS))
if len(T) == 2:
    ANS = max(T[0],T[1])
elif F == 0:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(1)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANS = max(ANSU,ANSV)
    
else:
    U = copy.copy(T)
    V = copy.copy(T)
    U.pop(F)
    V.pop(0)
    LU = [0]*(N-1)
    LU[0] = U[0]
    LV = [0]*(N-1)
    LV[0] = V[0]
    ANSU = 0
    ANSV = 0
    for i in range(N-2):
        LU[i+1] += gcd(LU[i],U[i+1])
    ANSU = LU[N-2]
    for i in range(N-2):
        LV[i+1] += gcd(LV[i],V[i+1])
    ANSV = LV[N-2]
    ANSP = max(ANSU,ANSV)
    ANS = max(ANSP,LIS[N-1])
        
print(ANS)

Measured memory_bytes: 21176
#include <iostream>
#define CELL 3
using namespace std;

int main()
{
    int bingoCard[CELL][CELL];
    int row_agg[CELL] = {0}, col_agg[CELL] = {0}, slant_agg[2] = {0};
    int N;
    for (int i = 0; i < CELL; i++)
    {
        for (int j = 0; j < CELL; j++)
        {
            cin >> bingoCard[i][j];
        }
    }
    cin >> N;
    int b[N];
    for (int n = 0; n < N; n++)
    {
        cin >> b[n];
        // check bingo
        for (int i = 0; i < CELL; i++)
        {
            for (int j = 0; j < CELL; j++)
            {
                if (bingoCard[i][j] == b[n])
                {
                    row_agg[i]++;
                    col_agg[j]++;
                    if (i == j)
                    {
                        slant_agg[0]++;
                    }
                    if ((i == 0 && j == 2) || (i == 1 && j == 1) || (i == 2 && j == 0))
                    {
                        slant_agg[1]++;
                    }
                }
            }
        }
    }
    for (int i = 0; i < CELL; i++)
    {
        if (row_agg[i] == CELL || col_agg[i] == CELL)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (slant_agg[0] == CELL || slant_agg[1] == CELL)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int main() {
    ios_base::sync_with_stdio(false);

    long double a, b;
    cin >> a >> b;

    for(int i = 1; i <= 1000; i++) {
        int aa = (int) (0.08 * i);
        int bb = (int) (0.1 * i);
        //cout << "i: " << i << " aa: " << aa << " bb: " << bb << endl;
        if(aa == a && bb == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;
#define F first
#define S second
#define MP make_pair
const int N=5e5+10;
const ll INF=1LL<<60;
ll dis(pi a,pi b){
    ll x=a.F-b.F,y=a.S-b.S;
    return x*x+y*y;
}
int main(){
    int n,lim;
    ll ans=INF;
    pi a[N];
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d%d",&a[i].F,&a[i].S);
    sort(a,a+n);
    lim=min(1000,n);
    for(int i=0;i<lim;i++)for(int j=i+1;j<lim;j++)ans=min(ans,dis(a[i],a[j]));
    for(int i=lim;i<n;i++)for(int j=1;j<lim;j++)ans=min(ans,dis(a[i],a[i-j]));
    printf("%lld\n",ans);
}


Measured memory_bytes: 6588
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n,a;
    cin >> n;
    cin >> a;

    cout << n * n - a << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.15f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto M = RD;
	auto K = RD;

	bool ans;
	foreach (i; 0..N+1)
	{
		foreach (j; 0..M+1)
		{
			auto x = i * M + j * N - (i * j * 2);
			if (x == K)
				ans = true;
		}
	}

	writeln(ans ? "Yes" : "No");
	stdout.flush();
	debug readln();
}

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

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int akyouka=0,bkyouka=0,a=0,b=0,i,j;
	for(i=0;i<4;i++){
		scanf("%d",&akyouka);
		a=a+akyouka;
	}
	for(i=0;i<4;i++){
		scanf("%d",&bkyouka);
		b=b+bkyouka;
	}
	if(a>b){
		printf("%d\n",a);
	}
	else{
		printf("%d\n",b);
	}
	return 0;
}



Measured memory_bytes: 2052
n = int(input())
L = len(str(n))



answer = 0
k = 0
if L == 1:
    print(n)
    
if L % 2 == 0:
    for i in range(1, L,2):
        answer += 9*10**(i-1)
    print(answer)

if L % 2 == 1 and not L ==1:
    
    for j in range(1, L,2):
        answer += 9*10**(j-1)
    k = answer + n - 10**(L-1) + 1
    print(k)






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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int A, B, K;
  cin >> K >> A >> B;
  
  // main procedure
  bool ans = false;
  
  if (A % K == 0) {
    ans = true;
  } else if (B / K - A / K > 0) {
    ans = true;
  }

  // output
  WRITE_N(ans ? "OK" : "NG");

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    ll h, w;
    cin >> h >> w;

    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }
    ll ans = h * w / 2;
    if (h % 2 == 1 && w % 2 == 1) ++ans;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
  // 入力
  unsigned long long H, W;
  cin >> H >> W;

  unsigned long long result;
  if (H==1 || W == 1) {
    result = 1;
  } else {
    if ( (H*W)%2 == 0 ) {
      result = H*W/2;
    } else {
      result = H*W/2 + 1;
    }
  }

  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
n, k = [ int( val ) for val in input( ).split( " " ) ]
w = []
maxW = sumW = 0
for i in range( n ):
	num = int( input( ) )
	sumW += num
	w.append( num )
	if maxW < num:
		maxW = num

minP = 0
if 1 == k:
	minP = sumW
elif n == k:
	minP = maxW
else:
	left = maxW
	right = 100000*10000
	while left <= right:
		middle = ( left+right )//2
		truckCnt = i = loadings = 0
		while i < n:
			loadings += w[i]
			if middle < loadings:
				truckCnt += 1
				if k < truckCnt+1:
					break
				loadings = w[i]
			i += 1

		if truckCnt+1 <= k:
			minP = middle
		
		if k < truckCnt+1:
			left = middle + 1
		else:
			right = middle - 1

print( minP )

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

int dx[] = {-1, 0, 1, 0},
    dy[] = {0, 1, 0, -1};
int n, m, rez;
int a[21][21], inloc[21][21];
char ch;
queue < pair<int, int> > coada;

bool inside(int x, int y)
{
    return (x >= 1 && x <= n && y >= 1 && y <= m);
}

void copiaza()
{
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
            inloc[i][j] = a[i][j];
    }
}

int lee(int x, int y)
{
    int maxx_val = 1, newx, newy;
    coada.push(make_pair(x, y));
    copiaza();
    inloc[x][y] = 1;
    while (!coada.empty())
    {
        x = coada.front().first;
        y = coada.front().second;
        coada.pop();
        for (int i = 0; i <= 3; i++)
        {
            newx = x + dx[i];
            newy = y + dy[i];
            if (inside(newx, newy) && inloc[newx][newy] == 0)
            {
                inloc[newx][newy] = inloc[x][y] + 1;
                if (inloc[newx][newy] > maxx_val) maxx_val = inloc[newx][newy];
                coada.push(make_pair(newx, newy));
            }
        }
    }
    return maxx_val - 1;
}

int main()
{
    cin >> n >> m;
    cin.ignore();
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> ch;
            if (ch == '#') a[i][j] = -1;
        }
        cin.ignore();
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (a[i][j] == 0)
            {
                int dist = lee(i, j);
                if (dist > rez) rez = dist;
            }
        }
    }
    cout << rez;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int q = sc.nextInt();
			ArrayList<Stack<Integer>> S = new ArrayList<Stack<Integer>>();
			for(int i=0;i<n;i++) {
				S.add(new Stack<Integer>());
			}

			for(int i=0;i<q;i++) {
				int query = sc.nextInt();
				int t = sc.nextInt();
				switch(query) {
				case 0:
					S.get(t).push(sc.nextInt());
					break;
				case 1:
					if(S.get(t).size()>0)
						System.out.println(S.get(t).peek());
					break;
				case 2:
					if(S.get(t).size()>0)
						S.get(t).pop();
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 169424
#include <cstdio>
#include <cctype>

using namespace std;

int main(){
    int c;
    
    while((c = getchar()) != EOF){
        if(isupper(c)){
            putchar(tolower(c));
        }
        
        else if(islower(c)){
            putchar(toupper(c));
        }
        
        else {
            putchar(c);
        }
    }
    
    return 0;
}


Measured memory_bytes: 2516
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    long long sum=1000000000009;
    cin>>n;
    for(long long i=1;i*i<=n;i++){
        if(n%i==0) sum=min(sum,i+n/i);
    }
    cout<<sum-2<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int x;
	scanf("%d",&x);
	
	while(x){
		int a = x%10;
		if(a == 7){
			printf("Yes");
			return 0;
		}
		x = x/10;
	}
	
	printf("No");
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  ll kisu = 1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans *= 3;
    if (a % 2 == 1)
      kisu *= 1;
    else
      kisu *= 2;
  }
  cout << ans - kisu << endl;
  return 0;
}

Measured memory_bytes: 256
/*
如何动态维护第k大元素？

*/
#include<bits/stdc++.h>
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const ll MAXN=2e5+5;
const ll INF=1e18;
const ll MOD=1e9+7;
ll l,r,numx[60],numy[60],cntx,cnty;
int dp[60][2][2][2];
ll add(ll x,ll y)
{
    ll ret=x+y;
    if(ret>=MOD)
    {
        return ret-MOD;
    }
    return ret;
}
void getnum()
{
    while(l)
    {
        numx[cntx++]=l%2;
        l/=2;
    }

    while(r)
    {
        numy[cnty++]=r%2;
        r/=2;
    }


}
ll dfs(ll step,ll fx,ll fy,ll fz)
{
    if(step==-1)
    {
        return 1;
    }
    if(dp[step][fx][fy][fz]!=-1)
    {
        return dp[step][fx][fy][fz];
    }


    ll ret=0;
    //0 0
    if(fx||numx[step]==0)
    {
        ret=add(ret,dfs(step-1,fx,numy[step]==1?1:fy,fz));
    }
    //0 1
    if((fx||numx[step]==0)&&(fy||numy[step]==1)&&(fz))
    {
        ret=add(ret,dfs(step-1,fx,fy,fz));
    }
    if(fy||numy[step]==1)
    {
       ret=add(ret,dfs(step-1,numx[step]==0?1:fx,fy,1));
    }
    dp[step][fx][fy][fz]=ret;
    return ret;
}
void solve()
{
    memset(dp,-1,sizeof(dp));


    getnum();

    printf("%lld\n",dfs(59,0,0,0));
}
int main()
{
    while(~scanf("%lld %lld",&l,&r))
    {
        solve();
    }
}


Measured memory_bytes: 256
s = input()

ans = 0
temp = s[0]
for i in range(1,len(s)):
    if temp == s[i]:
        ans += 1
        if temp == "1":
            temp = "0"
        else:
            temp = "1" 
    else:
        temp = s[i]


ans2 = 1
if s[0] == "0":
    temp = "1"
else:
    temp = "0"
for i in range(1,len(s)):
    if temp == s[i]:
        ans2 += 1
        if temp == "1":
            temp = "0"
        else:
            temp = "1" 
    else:
        temp = s[i]

print(min(ans,ans2))


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

int main(){
    ll n,a;
    cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        cin>>a;
        mp[-a]++;
    }
    bool flag=1;
    ll ans=0;
    n--;
    for(auto x:mp){
        if(flag){
            ans+=-x.first*min(n,2*x.second-1);
            n-=min(n,2*x.second-1);
            flag=0;
        }else{
            ans+=-x.first*min(n,2*x.second);
            n-=min(n,2*x.second);
        } 
        if(n==0) break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 16128
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int a,b;
    int c;
    int e;
    cin>>a>>b;
    c=b*2;
    e=a-c;
    if(c>=a)
    {
        cout<<0;
    }
    if(a>c)
    {
        cout<<e;
    }



    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  
  sort(a.begin(), a.end(), greater<int>());
  int alice = 0;
  int bob = 0;
  for (int i = 0; i < n; i++)
  {
    if (i % 2 == 0)
      alice += a[i];
    else
      bob += a[i];
  }
  cout << alice - bob << endl;
}
  

Measured memory_bytes: 256
d={'':0}
for _ in[0]*int(input()):e=input();d[e]=d.get(e,0)+1
for _ in[0]*int(input()):e=input();d[e]=d.get(e,0)-1
#print(max(d[max(d,key=lambda x:d[x])],0))
print(max(d.values()))

Measured memory_bytes: 3060
#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;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (a * b % 2 ? "Odd" : "Even") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;


const ll M = 1000000007;


int main()
{
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (int i = k; i <= n + 1; i++){
    ll now = i*(n - i + 1) + 1;
    now %= M;
    ans += now;
    ans %= M;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
int n,m,x[N];
vi v[N];
signed main()
{
	Very_fast;
	cin>>n>>m;
	rep(i,n)cin>>x[i];
	rep(i,m)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	int ans=0;
	rep(i,n)
	{
		bool f=true;
		rep(j,v[i].size()){
			int to=v[i][j];
			if(x[to]>=x[i])
				f=false;
		}
		ans+=f;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 9148
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  ll K, A, B;
  cin >> K >> A >> B;
  if (K <= A) {
    cout << 1 << endl;
  } else if (A <= B) {
    cout << -1 << endl;
  } else {
    cout << (K-A+A-B-1)/(A-B) * 2 + 1 << endl;    
  }
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;

bool pal[10002]={false};
int main(){
	rep(i,10002){
		char str[10]={0};
		sprintf(str,"%d",i);
		int x = strlen(str);
		reverse(str,str+x);
		int num = atoi(str);
		if(i == num){
			pal[i] = true;
			//cout << i << endl;
		}
	}
	int n;
	scanf("%d",&n);
	int num1,num2;
	num1 = num2 = n;
	int ans = 0;
	while(1){
		if(pal[num1]){
			ans = num1;
			break;
		}
		num1--;
		if(pal[num2]){
			ans = num2;
			break;
		}
		num2++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigboi        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers.

int dp[200][200];
void solve(){	
	int n, m;
	cin>>n>>m;
	char arr[n+12][m+12];
    for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            cin>>arr[i][j];
        }
    }
	 for (int i=0;i<=n;++i){
        for (int j=0;j<=m;++j){
            dp[i][j]=inf;
        }
    }	
	if (arr[1][1]=='#') dp[1][1]=1;
    else dp[1][1]=0;
	FOR(i, 1, n+1){
		FOR(j, 1, m+1){
			if (i==1 && j==1)continue;
            if (arr[i][j]=='#'){
                dp[i][j]=min(dp[i][j],dp[i][j-1]+(arr[i][j]!=arr[i][j-1]));
                dp[i][j]=min(dp[i][j],dp[i-1][j]+(arr[i][j]!=arr[i-1][j]));
            }
            else {
                dp[i][j]=min(dp[i][j],dp[i][j-1]);
                dp[i][j]=min(dp[i][j],dp[i-1][j]);
            }		
		}
	}

	cout<<dp[n][m];
}	
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
  FAST/**/
   
   ll n,m;
   cin>>n>>m;
   
   ll c;
   cin>>c;
   
   pair<ll,ll> arr[c];
   rep(c)
        cin>>arr[i].ff>>arr[i].ss, arr[i].ff--, arr[i].ss--;
   map<pair<ll,ll>,ll> tot;
   map<ll,ll> row,col;
   rep(c)
   {
       row[arr[i].ff]++;
       col[arr[i].ss]++;
       tot[arr[i]]++;
   }
  
   ll ans = 0;
   map<ll,vector<ll>> ma;
   rep(c)
        ma[arr[i].ff].pb(col[arr[i].ss]);
   rep(c)
       ans = max(ans, row[arr[i].ff] + col[arr[i].ss] - tot[arr[i]]);
   multiset<ll> ms;
   rep(m)
        ms.insert(col[i]);
   rep(n)
   {
       auto it = ma.find(i);
       if(it!=ma.end())
       {
           autoit(it->ss,it1)
                ms.erase(ms.find(*it1));
       }
       
       if(ms.size()>0)
            ans = max(ans, row[i] + *ms.rbegin());
       if(it!=ma.end())
       {
           autoit(it->ss,it1)
                ms.insert(*it1);
       }        
   }
   
   cout<<ans;
   
   return 0;        
}  

  
          
   

Measured memory_bytes: 111448
from itertools import accumulate
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
from itertools import chain

dp = []
dp2 = []
aac = []

def fdp(l, r):
    global dp, dp2
    if dp2[l][r]:
        return dp[l][r]
    else:
        dp2[l][r] = 1
        if l == r:
            return 0
        result_tmp = float('inf')
        for kugiri in range(l, r):
            result_tmp = min(result_tmp, fdp(l, kugiri) + fdp(kugiri+1, r))
        result = result_tmp + (aac[r+1] - aac[l])
        dp[l][r] = result
        return result
def main():
    global dp, dp2, aac
    n = int(input())
    a = tuple(map(int, input().split()))
    aac = list(accumulate(a))
    aac = tuple(chain([0], aac))
    dp = [[0] * n for _ in range(n)]
    dp2 = [[0] * n for _ in range(n)]
    fdp(0, n - 1)
    print(dp[0][-1])
if __name__ == '__main__':
    main()


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

void solve(long long X, long long A){
    if (X < A) cout << 0 << '\n';
    else cout << 10 << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long X;
    scanf("%lld",&X);
    long long A;
    scanf("%lld",&A);
    solve(X, A);
    return 0;
}


Measured memory_bytes: 256
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	int n, m;
	int h, w;
	cin >> n >> m;
	cin >> h >> w;

	cout << (n - h)*(m - w) << endl;
	
}




 

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	static InputStream is;
	static String INPUT = "";
	
	static void solve()
	{
		int n = ni();
		int M = 1000001;
		int W = (M>>>6)+1;
		long[] f1 = new long[W];
		long[] f2 = new long[W];
		long[] ex = new long[W];
		for(int i = 0;i < n;i++){
			int v = ni();
			if(f1[v>>>6]<<~v>=0){
				f1[v>>>6] |= 1L<<v;
				if(ex[v>>>6]<<~v>=0){
					for(int j = v*2;j < M;j+=v){
						ex[j>>>6] |= 1L<<j;
					}
				}
			}else{
				f2[v>>>6] |= 1L<<v;
			}
		}
		int ans = 0;
		for(int i = 0;i < W;i++){
			ans += Long.bitCount((f1[i]^f2[i])&~ex[i]);
		}
		System.out.println(ans);
	}

	public static void main(String[] args) throws Exception
	{
		long S = System.currentTimeMillis();
		is = System.in;
		
		solve();
		long G = System.currentTimeMillis();
		tr(G-S+"ms");
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}


Measured memory_bytes: 37024
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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



int main(void) {
	int n, a, b;

	cin >> n >> a >> b;

	cout << min(a, b) <<" "<< max(a + b - n, 0) << endl;


	return 0;
}

Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

void min_self(int &a, int b) {
    a = min(a, b);
}

const int nax = 1e5 + 5;
int memo[105][nax];
int main() {
    // dp[i][j] is smallest weight for jth value after ith element
    int n = nxt(), w = nxt();
    VI weight(n), value(n);
    REP(i, n)
    cin >> weight[i] >> value[i];
    REP(i, 105)
    REP(j, nax)
    memo[i][j] = INF;
    REP(i, 105)
    memo[i][0] = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = nax; j >= 0; j--) {
            min_self(memo[i + 1][j], memo[i][j]);
            if (j + value[i] < nax) min_self(memo[i + 1][j + value[i]], memo[i][j] + weight[i]);
        }
    }
    REP(i, 105) {
        REP(j, nax) {
            if (memo[i][j] <= w) ans = max(ans, j);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 44744
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A, B = ZIP(N)
A = sorted(A)
B = sorted(B)
if N%2 == 0:
	l = (A[N//2]+A[N//2-1])
	r = (B[N//2]+B[N//2-1])
	print(r-l+1)
else:
	print(B[N//2]-A[N//2]+1)


Measured memory_bytes: 114536
n = int(input())

def div(x):
    global count
    if x%2==1:
        return count
    else:
        count += 1
        return div(x//2)
m = -1
for i in range(n):
    count = 0
    r = div(i+1)
    if m < r:
        m = r
        ans = i+1

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){

  string a,b;
  cin >> a >> b;
  if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[105];
int b[1005];
int n;
void bfs(int a[],int t)
{
    int ans=0;
    int sum=0;
    int i;
    for(i=1;i<=n;i++)
    {
        if(i<=t)
            ans+=a[i];
        else
            sum+=a[i];
    }
    b[t]=abs(ans-sum);
}
int main()
{
    scanf("%d",&n);
    int i;
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<n;i++)
        bfs(a,i);
    sort(b+1,b+n);
    printf("%d\n",b[1]);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  //freopen("input.txt","r",stdin);
#endif

  int n;
  cin>>n;
  vector<int> v(n+1);
 for(int i=0;i<=n;i++)
 {
   v[i]=0;
 }
  for(int i=0;i<n-1;i++)
  {
    int x;
    cin>>x;
    v[x]++;
  }

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

  return 0;
}

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
#define ll  unsigned long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 998244353;
const double PI = 3.141592653589793238463;
const int MAXN = 1000030;

int main()
{
    FAST
    int n,x,t;
    cin>>n>>x>>t;
    int temp=t,tt=x;
    while(tt<n){
        tt+=x;
        temp+=t;
    }
    cout<<temp<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;

int main()
{
    fast;

    ll a;
    cin >> a;
    ll x = a/5,y = a/3,z=a/15;
    cout << (a*(a+1))/2 + 15*((z*(z+1))/2) - 5*((x*(x+1))/2) - 3*((y*(y+1))/2);

}






























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

#define watch(x) cerr << (#x) << ": " << (x) << endl

int32_t main() {

    string s; cin >> s;
    int need = 8, rem = 15;
    for(char c : s) {
        if(c == 'o') need--;
        rem--;
    }

    if(rem >= need) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000
 
struct Cards {
	char pattern[2];
	int num;
	int order;
};
int flag=0;

void exchange( struct Cards *pa, struct Cards *pb )
{
	struct Cards t;
	
	t=*pa;
	*pa=*pb;
	*pb=t;

	return;
}

int Partition( struct Cards A[], int p, int r )
{
	struct Cards x;
	int i,j;

	x=A[r];
	i=p-1;
	for( j=p; j<r; j++ ) {
		if( A[j].num <= x.num ) {
			i++;
			exchange( &A[i], &A[j] );
		}

	}
	exchange( &A[i+1], &A[r] );

	return i+1;
}
void QuickSort( struct Cards A[], int p, int r )
{
	int q;
	
	if( p < r ) {
		q=Partition( A, p, r );
		QuickSort( A, p, q-1 );
		QuickSort( A, q+1, r );
	}
	return;
}
int isStable( int n, struct Cards A[], struct Cards B[] )
{
	int i;
	int lo,mi,hi;
	int res=0;
	int s,e,t;
	
	res=1;
    for( i=0; i<n; i++ ) {
        lo=0;
        hi=n;
        while( lo <= hi ) {
            mi=(lo+hi)/2; 
            if( B[i].num == A[mi].num ) {
            	if( A[mi].order ) {
            		if( A[ A[mi].order ].pattern[0] == B[i].pattern[0] ) {
		            	e=s=mi;
		            	while( B[i].num == A[s].num ) { s--; }
		            	s++;
		            	while( B[i].num == A[e].num ) { e++; }
		            	e--;

            			t=A[mi].order+1;
		            	while( s<=e ) {
		            		A[s++].order=t;
		        		}
            			res=1;
            		} else {
            			res=0;
            		}
            	} else {
	            	e=s=mi;
	            	while( B[i].num == A[s].num ) { s--; }
	            	s++;
	            	while( B[i].num == A[e].num ) { e++; }
	            	e--;
        			t=A[mi].order+1;
	            	while( s<=e ) {
	            		A[s++].order=t;
	        		}
        		     
        		}
                break;
            } else if( B[i].num < A[mi].num ) {
                hi=mi-1;
            } else {
                lo=mi+1;         
            }
        }
        if( !res ) {
        	break;
        }
    }
  
   return res;
}

int main( void ) 
{	
	int n,i;
	struct Cards A[MAX+1];
	struct Cards B[MAX+1];
		
    scanf( "%d", &n );
	for( i=0; i<n; i++ ) {
		scanf( "%s%d", A[i].pattern, &A[i].num );
		A[i].order=0;
		B[i]=A[i];
	}
	QuickSort( A, 0, n-1 );
	
	if( isStable( n, A, B ) ) {
		printf( "Stable\n" );
	} else {
		printf( "Not stable\n" );
	}
	for( i=0; i<n; i++ ) {
		printf( "%s %d\n", A[i].pattern, A[i].num );
	}

    return 0;
}

Measured memory_bytes: 2956
/**
 *    author:  yoseph
 *    created: 02.08.2020 20:19:12      
**/
#include <bits/stdc++.h>
using namespace std;

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef LOCAL
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, d;
	cin >> n >> d;
	vector<vector<long long>> xy(n,vector<long long>(2));
	for (int i = 0; i < n; ++i)
		cin >> xy[i][0] >> xy [i][1];
	int ans = 0;
	for (auto p : xy) {
		dbg(p[0]);
		dbg(p[1]);
		dbg(p[0]*p[0]+p[1]*p[1]);
		if (p[0]*p[0]+p[1]*p[1] <= d*d)
			++ans;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 14284
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define	abs(a) ((a)<0?-(a):(a))



int main(void){
	char *s;
	bool flag = false;
	s = calloc(sizeof(char),100000);
	scanf("%s",s);
	while(*s){
		if(*s == 'C'){
			flag = true;
		}
		if(*s == 'F' && flag){
			printf("Yes\n");
			return 0;
		}
		s++;
	}
	printf("No\n");

	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++)
int main(){
  int n;
  cin >> n;
  char c[n];
  int i,l=0,r=0;
  for(i=0;i<n;i++){
    cin >> c[i];
    if(c[i]=='R'){
      l++;
    }else{
      r++;
    }
  }
  int ans=0;
  for(i=0;i<l;i++){
    if(c[i]=='W'){
      ans++;
    }
  }
  for(i=l;i<n;i++){
    if(c[i]=='R'){
      ans++;
    }
  }
  ans=(ans+1)/2;
  cout << ans;
}
  
  


Measured memory_bytes: 3704
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

void dfs(int x, vector<int> &lis, vector<int> &A, vector<vector<int>> &edges, vector<int> &ans){
    if(ans[x]>0){
        return;
    }
    auto it = lower_bound(lis.begin(),lis.end(),A[x]);
    int idx,prev;
    if(it==lis.end()){
        prev=-1;
        lis.push_back(A[x]);
    }else{
        prev=*it;
        idx=distance(lis.begin(),it);
        *it=A[x];
    }
    ans[x]=lis.size();

    int M=edges[x].size();
    for(int i=0; i<M; i++){
        dfs(edges[x][i], lis, A, edges, ans);
    }

    if(prev==-1){
        lis.pop_back();
    }else{
        lis[idx]=prev;
    }
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto &a:A){
        cin >> a;
    }

    vector<vector<int>> edges(N,vector<int>(0));
    for(int i=0; i<N-1; i++){
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    vector<int> ans(N,0);
    vector<int> lis(0);
    dfs(0, lis, A, edges, ans);

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

Measured memory_bytes: 29928
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,k=input2()
A=input_array()

# ある地点から循環に陥る
judge=[True]*n
tmps=[1] #循環手前
count=0 #参照地点

for i in range(2*(10**5)+1):
	if judge[count]==True:
		judge[count]=False
		count=A[count]-1
		tmps.append(count+1)
	else:
		break

loop_st=tmps.index(tmps[-1])
loops=tmps[loop_st:-1]


if k<loop_st:
	print(tmps[k])
else:
	k=k-loop_st
	k%=len(loops)
	print(loops[k])

Measured memory_bytes: 32268