akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
int puz[3][3];
int tmp[3][3];
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
void empty(int *x,int *y) {
  int i,j;
  for(i=0; i<3; i++) {
    for(j=0; j<3; j++) {
      if(!puz[i][j]) {
    *x = j;
    *y = i;
    return;
      }
    }
  }
}
void swap(int *a,int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}   
int cal(){
  int i,a,sum=0; 
  for(i=0; i<9; i++){
    a = puz[i/3][i%3];
    if(a){
      a--;
      sum += abs(i/3 - a/3) + abs(i%3 - a%3);
    }
  }    
  return sum;
}
int dfs(int x,int y,int p,int dep,const int lim){
    int i,h,nx,ny,res;   
    h = cal();
    if(h==0) return dep;
    if(dep+h>lim) return -1; 
    for(i=0; i<4; i++){
        nx = x+dx[i];
        ny = y+dy[i];      
        if(~p && i==(p+2)%4) continue;
        if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;    
        swap(&puz[y][x],&puz[ny][nx]);
        res = dfs(nx,ny,i,dep+1,lim);
        if(~res) return res;       
        swap(&puz[y][x],&puz[ny][nx]);
    }   
    return -1;
}    
int main() {
    int i,j,ans,x,y,l;
       
    for(i=0; i<3; i++){
        for(j=0; j<3; j++) scanf("%d",&puz[i][j]);
    }
        
    empty(&x,&y);
    for(l=0; l<100; l++){
        for(i=0; i<3; i++){
            for(j=0; j<3; j++) tmp[i][j] = puz[i][j];
        }
           
        ans = dfs(x,y,-1,0,l);
        if(ans!=-1){
            printf("%d\n",ans);
            break;
        }
           
        for(i=0; i<3; i++){
            for(j=0; j<3; j++) puz[i][j] = tmp[i][j];
        }
           
        ans = -1;
        if(l==99) printf("%d\n",ans);
    }
       
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#define MAX 100001
#define ll long long int
#define eps 1e-7
using namespace std;


long long int a ,b ,c;
int main(){
  cin>>a>>b>>c;
  long long int s = a*b*c;
  if(a>b) swap(a,b);
  if(b>c) swap(b,c);
  if(a%2==0 || b%2==0 || c%2==0){
    cout<<0<<endl;
    return 0;
  }
  else{
      c = c/2;
  }
  long long int res = s - (a*b*c)*2;
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var x = consoleReader.Int;
            var list = new List<int>() { 1 };
            var sq = (int)Math.Sqrt(x);
            for (int b = 2; b <= sq; b++)
            {
                int pow = b;
                while ((pow *= b) <= x)
                    list.Add(pow);
            }
            list.Sort();
            return list.TakeWhile(i => i <= x).Last();
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }
#pragma warning disable
    public class ConsoleReader
    {
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = textReader.ReadLine().Split();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.textReader.ReadLine().Split(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerable<T> Select<T>(Func<ConsoleReader, T> func) { for (int i = 0; i < count; i++) yield return func(cr); }
            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main(){
    int N, Q;
    cin >> N >> Q;
    Graph G(N);
    
    int ans[N];
    for(int i = 0; i < N; i++) ans[i] = 0;
    
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        int p, x;
        cin >> p >> x; p--;
        ans[p] += x;
    }

    vector<int> dist(N, -1);
    queue<int> que;
    dist[0] = 0;
    que.push(0);
    
    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (int nv : G[v]) {
            if (dist[nv] != -1) continue;
            
            dist[nv] = 1;
            ans[nv] += ans[v];
            que.push(nv);
        }
    }
    for(int i = 0; i < N; i++)
        cout << ans[i] << "\n";
    return 0;
}


Measured memory_bytes: 16372
n = int(input())
p = [int(i) for i in input().split()]
ans =0
check = 0
for n,i in enumerate(p):
    if n+1 == i and check == 0:
        ans += 1
        check =1
    elif n+1 == i and check == 1:
        check = 0
    else:
        check=0
print(ans)

Measured memory_bytes: 20020
N = gets.to_i
es = {}
degs = Array.new(N,0)
(N-1).times {
  a,b = gets.split.map &:to_i
  a -= 1
  b -= 1
  es[a] ||= {}
  es[b] ||= {}
  es[a][b] = b
  es[b][a] = b
  degs[a] += 1
  degs[b] += 1
}

C = (gets.split.map &:to_i).sort

leaves = (0...N).to_a.select{ |a| degs[a] == 1 }

score = 0
pos = Array.new(N, nil)

(0...N).each{ |i|
#  p leaves
  a = leaves.pop
  c = C[i]
  score += c
  pos[a] = c
#  p pos
  b = es[a].keys.first
  break if !b
  degs[a] -= 1
  degs[b] -= 1
  es[a].delete(b)
  es[b].delete(a)
  if degs[b] <= 1
    leaves << b
  end
}

score -= C[-1]

puts score, pos * " "

Measured memory_bytes: 6776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    ll n;
    cin >> n;
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll r = sqrt(n);
    ll sum = 0;
    for (ll y = 1; y <= r; y++) {
        if (n % y != 0) continue;
        ll x = (n/y)-1;
        if (n % x == y) {
            sum += x;
        }
    }
    cout << sum << endl;
    return 0;
}


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

int main() {
    int M1, M2, D1, D2; cin >> M1 >> D1 >> M2 >> D2;
    if(M1+1==M2) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

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

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

const int maxn=100000;

int main(){
    
    int n,a,b,c,d;
    int macnt=0,cnt=0;
    string s;
    cin >> n>>a>>b>>c>>d;
    cin >> s;
    a--;b--;c--;d--;
    
    for(int i=a;i<=max(c,d);i++){
        if(s[i]=='#'){
            cnt++;
            macnt=max(macnt,cnt);
        }else{
            cnt=0;
        }
    }
    
   // macnt=max(macnt,cnt);
    
    if(macnt>=2){
        No;
    }else if(d<c){
        bool key=false;
        for(int i=b;i<=d;i++){
            if(s[i]!='#'&&s[i-1]!='#'&&s[i+1]!='#')key=true;
        }
        
        if(key){
            Yes;
        }else{
            No;
        }
    }else{
        Yes;
    }
        
    return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**7)

def update(v):
    for nv in con[v]:
        if seen[nv]:
            continue
        seen[nv]=1
        update(nv)

N,M=map(int,input().split())
seen=[0]*N
con=[[] for i in range(N)]
cnt=[[i,0] for i in range(N)]
for i in range(M):
    X,Y,Z=map(int,input().split())
    X,Y=X-1,Y-1
    con[X].append(Y)
    con[Y].append(X)
    cnt[X][1]+=1
    cnt[Y][1]+=1
cnt.sort(key=lambda x:x[1],reverse=True)
ans=0
for i,a in cnt:
    if(seen[i]):
        continue
    ans+=1
    seen[i]=1
    update(i)
print(ans)

Measured memory_bytes: 123640
#include<stdio.h>
main(){
  int a,i,j,sum,v[5000],ans;
  while(1){
    scanf("%d",&a);  ans = -100000000;
    if(a==0)break;
    for(i=0;i<a;i++){
      scanf("%d",&v[i]);
    }
    for(i=0;i<a;i++){
      sum=0;
      for(j=i;j<a;j++){
	sum+=v[j];
	if(sum>ans){
	  ans=sum;
	}
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

    
    

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

using namespace std;

int n,W;
int w[100001],v[100001];
long long mem[100][100001];

long long solve(int i,int rem){
    if(i==n)
        return 0;
    if(mem[i][rem]!=-1) return mem[i][rem];
    return mem[i][rem]=max(solve(i+1,rem),rem-w[i]>=0?v[i]+solve(i+1,rem-w[i]):-1000000000);
}

int main() {
    scanf("%d%d",&n,&W);
    for(int i=0;i<n;++i)
        scanf("%d%d",w+i,v+i);
    memset(mem,-1,sizeof mem);
    printf("%lld",solve(0,W));
    return 0;
}


Measured memory_bytes: 78464
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
char c[100];
int check[100010],ans[100100];
int main(){
	int ans1=0,ans2=0;
	n=read();m=read();
	for(register int i=1;i<=m;i++){
		int x=read();
		scanf("%s",c+1);
		if(c[1]=='W' && check[x]==0)ans[x]++;
		else if(c[1]=='A' && check[x]==0){
			check[x]=1;
		}
	}
	for(register int i=1;i<=n;i++){
		if(check[i]){ans2++;ans1+=ans[i];}
	}
	printf("%d %d\n",ans2,ans1);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef vector<ll> vl;
typedef vector<vl> vv;
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define endl '\n'
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }

int main(){
    
    fast();
    //#ifndef ONLINE_JUDGE
	//freopen("F:\\Codes\\input.txt", "r", stdin);
	//freopen("F:\\Codes\\output.txt", "w", stdout);
	//#endif
	
	ll n,i,k,j;
	cin>>n>>k;

	vl hgt(n),dp(n);

	for(i=0;i<n;i++){cin>>hgt[i];dp[i]=INF;}

	dp[0]=0;
	for(i=0;i<n;i++){
		for(j=i+1;j<min(i+k+1,n);j++){
			dp[j]=min(dp[j],abs(hgt[j]-hgt[i])+dp[i]);
		}
		//for(j=0;j<n;j++){cout<<dp[j]<<" ";}cout<<endl;
	}

	cout<<dp[n-1]<<endl;

    
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
sticks = list (map (int, input().strip().split()))
sticks.sort()
ans = 0
for a_idx in range(n - 1, 0, -1):
    b_idx = a_idx - 1
    c_idx = 0
    while c_idx < b_idx:
        if sticks[a_idx] < sticks[b_idx] + sticks[c_idx]:
            ans += b_idx - c_idx
            b_idx -= 1
        else:
            c_idx += 1
print(ans)

Measured memory_bytes: 3188
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int MOD = (int)998244353;

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

    void run() {

        int n = sc.nextInt();
        int m = sc.nextInt();

        System.out.println((100*n+1800*m)*(int)Math.pow(2, m));


    }
}



Measured memory_bytes: 22612
import itertools
import math
import fractions
import functools

n, m, x = map(int, input().split())

c = []
a_do = []
for i in range(n):
    a = list(map(int, input().split()))
    c.append(a[0])
    a_do.append(a[1:])


minimum = 10**20
for pat in range(0, (1<<n)): #参考書の選び方の全パターン
    cost = 0
    rikaido = [0] * m
    for i in range(n):
        if((pat >> i) & 1): #i番目の参考書を読む
            cost += c[i]
            for k in range(m):
                rikaido[k] += a_do[i][k]
    ok = True
    for k in range(m):
        if(rikaido[k] < x):
            ok = False
    if(ok):
        minimum = min(minimum, cost)

if(minimum == 10**20):
    print(-1)
else:
    print(minimum)


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

typedef long long ll;
typedef long double ld;
#define ii pair <int, int>
#define MP make_pair
#define endl "\n"
#define PB push_back
#define F first 
#define int long long 
#define S second
#define rise_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);;
#define all(v) v.begin(), v.end()
#define sz(a) signed((a).size())
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define ford(i,n) for(int i = int(n) - 1; i >= 0; i--)


signed main()
{	
	rise_up
    int t=1; //cin>>t; 
    while(t--){
		int a, b, c, k; cin>>a>>b>>c>>k;
		int ans = 0;
		ans +=  1*min(a, k); k-=min(a, k);
		if(k) 
			k-=min(b, k);
		if(k)
			ans -= min(c, k);
		cout<<ans;		
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	int L; cin >> L;
	double edge = L / 3.;

	printf("%.7lf\n", pow(edge, 3));

	return 0;
}


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

int main() {
  int N, c;
  c=0;
  cin >> N;
  for (int i=0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    c += b-a+1;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
input()
a=[int(i) for i in input().split()]
a.sort(reverse=True)
tyo=0
tan=0
tb=0
for i in range(len(a)-1):
  if tb==1:
    tb=0
  else:
    if a[i]==a[i+1] and tyo==0:
      tyo=a[i]
      tb=1
    elif a[i]==a[i+1]:
      tan=a[i]
      break
print(tyo*tan)

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

using namespace std;

void solution(){
    int A,B,C;
    cin>>A>>B>>C;
    if((A*B*C)==175 && (A+B+C)==17){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
}

int main(){
    solution();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	llint n, m;
	cin >> n >> m;
	llint ans = 0;
	for (llint i = 1; i * i <= m; i++) {
		if (m % i == 0) {
			if (i * n <= m)ans = max(ans, i);
			if ((m / i) * n <= m)ans = max(ans, (m / i));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
public class Test {  
static public void Main() { 
var HN = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var H = HN[0]; var N = HN[1]; 
  
   if(H >= 13){
       Console.WriteLine(N); 
   }else if(H >= 6){
       Console.WriteLine(N/2); 
   }else{
       Console.WriteLine(0);
   }
   }
} 


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

int n;

int main(){
    while(cin>>n&&n!=0){
        vector<string>s(n);
        for(int i=0;i<n;i++){
            cin >> s[i];
        }
        int a = 0;
        int b = 0;
        bool v = 0; 
        int ans = 0;
        for(int i=0;i<n;i++){
            if(s[i]=="lu"){
                a = 1;
                if(v==0&&a==1&&b==1){
                    ans++;
                    v = 1;
                }
            }else if(s[i]=="ru"){
                b = 1;
                if(v==0&&a==1&&b==1){
                    ans++;
                    v = 1;
                }
            }else if(s[i]=="ld"){
                a = 0;
                if(v==1&&a==0&&b==0){
                    ans++;
                    v = 0;
                }
            }else{
                b = 0;
                if(v==1&&a==0&&b==0){
                    ans++;
                    v = 0;
                }
            }

        }
        cout << ans << endl;

    }
    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N; cin >> N;
    map<int,int> mp;
    vector<int> v;
    for(int i = 0; i < N; i++){
        int a; cin >> a;
        if (mp[a] == 0) v.push_back(a);
        mp[a]++;
    }
    int ans = 0;
    for(int i = 0; i < v.size(); i++){
        int tmp = v[i];
        if (mp[tmp] % 2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5368
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[100011];
int dp[100011];
int main (void) {
	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	dp[0] = dp[1] = 0;
	dp[2] = abs(a[1] - a[2]);
	for(int i = 3; i <= n; i++){
		dp[i] = min(dp[i - 1] + abs(a[i - 1] - a[i]), dp[i - 2] + abs(a[i - 2] - a[i]));
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int T[100000];

int main()
{
	int N, C, K, t, cnt = 0, ans = 0;

	cin >> N >> C >> K;
	rep(i, N) cin >> T[i];

	sort(T, T + N);

	rep(i, N) {
		if (i == 0) {
			t = T[i];
			cnt = 1;
			ans++;
		}
		else if (cnt < C && T[i] <= t + K) {
			cnt++;
		}
		else {
			t = T[i];
			cnt = 1;
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1){ }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (data[y] < data[x]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int x) {
        return data[x]<0 ? x : (data[x]=root(data[x]));
    }

    int size(int x) {
        return -data[root(x)];
    }
};


struct edge{
    int src, to, cost;
};
using Edges = vector<edge>;

int kruskal(Edges &E, int V)
{
    sort(all(E), [](const edge &a, const edge &b)
    {
        return (a.cost < b.cost);
    });
    UnionFind tree(V);
    vector<int> MST;
    for(auto &e: E) {
        if(tree.merge(e.src, e.to)) MST.push_back(e.cost);
    }
    sort(all(MST));
    return MST[MST.size()/2];
}

int main(){
    fastcin();

    int n, m;
    cin >> n >> m;
    while(n > 0){
        Edges E(m);
        rep(i, m){
            int s, t, c;
            cin >> s >> t >> c;
            s--; t--;
            E[i] = edge({s, t, c});
        }
        cout << kruskal(E, n) << endl;
        cin >> n >> m;
    }
}


Measured memory_bytes: 3232
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 100100;
int n;
vector<int> g[N];
int dp[N];
int m;

bool solve(int v, int par) {
	vector<int> a;
	if ((int)g[v].size() & 1) a.push_back(0);
	for (int u : g[v]) {
		if (u == par) continue;
		if (!solve(u, v)) return false;
		if (dp[u] != -1)
			a.push_back(dp[u] + 1);
	}
	sort(a.begin(), a.end());
/*
	printf("%d :", v);
	for (int x : a)
		printf(" %d", x);
	printf("\n");
*/
	if ((int)a.size() & 1) {
		int l = -1, r = (int)a.size();
		while(r - l > 1) {
			int x = (l + r) / 2;
			int p1 = 0, p2 = (int)a.size() - 1;
			bool ok = true;
			while(p1 < p2) {
				if (p1 == x) p1++;
				if (p2 == x) p2--;
				if (a[p1] + a[p2] > m) {
					ok = false;
					break;
				}
				p1++;
				p2--;
			}
			if (ok)
				r = x;
			else
				l = x;
		}
		if (r == (int)a.size()) return false;
		dp[v] = a[r];
		return true;
	} else {
		for (int i = 0; i < (int)a.size(); i++)
			if (a[i] + a[(int)a.size() - 1 - i] > m)
				return false;
		dp[v] = -1;
		return true;
	}
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		v--;u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans += (int)g[i].size() & 1;
	printf("%d ", ans / 2);
	int l = 0, r = n;
	while(r - l > 1) {
		m = (l + r) / 2;
		if (solve(0, -1))
			r = m;
		else
			l = m;
	}
	printf("%d\n", r);

	return 0;
}


Measured memory_bytes: 18816
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define Cout(s) cout<<s<<endl

bool sosuu(const int x)
{
	if (x == 2)return true;
	if (x < 2 || x % 2 == 0)return false;
	for (int i = 3; i * i <= x; i += 2)
		if (x % i == 0)return false;
	return true;
}
int gcd(int a, int b)
{
	if (a % b == 0) { return b; }
	else { return gcd(b, a % b); }
}
int ketawa(int a)
{
	if (a < 10)return a;
	else return a % 10 + ketawa(a / 10);
}

typedef long long ll;
using namespace std;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 0, b = 0, c, d, n, k = 0,ans=0;
string s, t;


int main()
{
	cin >> n >> a >> b;
	int cnt = 0;
	rep(i, n + 1)
	{
		if (ketawa(i) >= a && ketawa(i) <= b)
			cnt+=i;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s,t;
  Int a,b;
  string u;
  cin>>s>>t>>a>>b>>u;
  if(s==u) a--;
  if(t==u) b--;
  cout<<a<<" "<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int d = 0;
        for(int i=a;i<=b;i++){
            if(c%i ==0){
                d++;}
        }
        System.out.println(d);
            }
        }

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  string s;
  cin>>s;
  vector<vector<ll>> key = vector<vector<ll>>((ll)s.size(),vector<ll>(4,0));
  int SIZE=s.size();
  //A? C?
  FOR(i,1,(ll)s.size()){
    if(s[i-1]=='A')  key[i][0]=key[i-1][0]+1;
    else key[i][0]=key[i-1][0];
    if(s[i-1]=='?')  key[i][1]=key[i-1][1]+1;
    else key[i][1]=key[i-1][1];
  }
  FOR(i,1,(ll)s.size()){
    if(s[SIZE-i]=='C')  key[SIZE-i-1][2]=key[SIZE-i][2]+1;
    else key[SIZE-i-1][2]=key[SIZE-i][2];
    if(s[SIZE-i]=='?')  key[SIZE-i-1][3]=key[SIZE-i][3]+1;
    else key[SIZE-i-1][3]=key[SIZE-i][3];
  }

  ll z=1000000007;
  vector<ll> three(SIZE+1,1);
  three[0]=0;
  FOR(i,2,SIZE+1){
    three[i]=(three[i-1]*3)%z;
  }
  ll res=0;

  ll p,q,x,y;


  FOR(i,0,SIZE){

    if(s[i]=='B'||s[i]=='?'){
      p=key[i][0];
      q=key[i][1];
      x=key[i][2];
      y=key[i][3];

  //    cout<<p*three[q]<<" "<<q*three[q-1]<<endl;
      res=res+(((p*three[q+1])%z+(q*three[q])%z)*((x*three[y+1])%z+(y*three[y])%z))%z;
    }
  }
cout<<res%z<<endl;
}


Measured memory_bytes: 8192
#include <iostream>

using namespace std;
int test[123456];
int main() {
	long int n;
	long int a;
	long int b;
	cin >> n >> a >> b;
	if(a > b)
	{
		cout << "0";
		return 0;
	}
	if(n == 1 && a!=b)
	{
		cout << "0";
		return 0;
	}
	if(n>0)
	{
	long int max = ((n-1)*a)+b;
	long int min = ((n-1)*b)+a;
	cout << min - max +1;
	}
	else
	{
		cout << 0;
	}	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 55;
int a[N], b[N], c[N], d[N];
int n, m, q, ans;
void dfs(int x, vector<int>& t) {
    if(t.size() == n) {
        int sum = 0;
        for(int i = 0; i < q; i++) {
            if(t[b[i]] - t[a[i]] == c[i]) sum += d[i];
        }
        ans = max(ans, sum);
        return;
    }
    for(int i = x; i <= m; i++) {
        t.push_back(i);
        dfs(i, t);
        t.pop_back();
    }
}
int main() {
    scanf("%d%d%d", &n, &m, &q);
    for(int i = 0; i < q; i++) {
        scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--, b[i]--;
    }
    vector<int> t;
    t.push_back(1);
    dfs(1, t);
    printf("%d\n", ans);
    return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, a;
  cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

ll modpow(ll n, ll k){
    ll rtn = 1;
    while(k > 0){
        if(k&1)rtn=rtn*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return rtn;
}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    for(int i = 0 ; i <= 60 ; i++){
        ll n0 = 0;
        ll n1 = 0;
        for(auto e : a){
            if(1 & (e>>i)) n1++;
            else n0++;
        }
        ans += (((n0*n1)%mod)*modpow(2,i))%mod;
        ans %= mod;
    }
    cout << ans%mod << endl;
}

Measured memory_bytes: 2560
#include<cstdio>
using namespace std;
int a,b;
int main(){
    scanf("%d%d",&a,&b);
    if(a>0)puts("Positive");            
    else if(b>=0)puts("Zero");       
    else if((a&1)^(b&1))puts("Positive");
    else puts("Negative");
    return 0;
}

Measured memory_bytes: 128
import queue
n = int(input())
a = list(map(int,input().split()))
xx = [0]*(n+1)
x = 1
c = 0
for i in range(n+1):
  if x >= a[i]:
    c += a[i]
    xx[i] = x-a[i]
    x = 2*(x-a[i])
  else:
    print(-1)
    exit()
y = a[n]
i = n-1
while y > 0:
  if xx[i] >= y:
    c += y
  else:
    c += xx[i]
    y = xx[i]
  y += a[i]
  if i > 0:
    i -= 1
  else:
    break
print(c)

Measured memory_bytes: 708080
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# K, N = [int(x) for x in input().split()]

from itertools import *

M, N, Q = [int(x) for x in input().split()]

A = []
for n in list(combinations_with_replacement(range(1, N+1), M)):
    if n[0] == 1:
        A.append(n)
score = [0] * len(A)

for q in range(Q):
    a, b, c, d = [int(x) for x in input().split()]
    for idx, l in enumerate(A):
        if l[b-1] - l[a-1] == c:
            score[idx] += d

print(max(score))


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

int main() {
    int64_t N, D;
    cin >> N >> D;
    int64_t X[N];
    int64_t Y[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        cin >> Y[i];
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (D*D >= X[i] * X[i] + Y[i] * Y[i]) {
            ans++;
        }
    }

    cout << ans << endl;
}


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

int main(){
int N; cin >> N;
  vector<int> A(N); vector<int> B(N);
  for(int i = 0; i < N; i++){ cin >> A[i];}
  for(int j = 0; j < N; j++){ cin >> B[j];}
  
  ll res1 = 0; ll res2  =0;
  
  for(int i = 0; i < N; i++){ res1 += max(0,A[i]-B[i]); res2 += max( 0, (B[i]-A[i])/2);}
  
  if( res1 <= res2){ cout << "Yes" << endl;} else{ cout << "No" << endl;}
  return 0;}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
class UnionFind{
    public:
    vector<long long> parent;
    vector<long long> rank;
    UnionFind(long long n){
        parent.resize(n);
        rank.resize(n, 1);
        for(long long i=0; i<n; i++) parent[i] = i;
    }
    long long root(long long x){
        if(parent[x]==x) return x;
        else return parent[x] = root(parent[x]);
    }
    long long getRank(long long x){
        return rank[root(x)];
    }
    void unite(long long x, long long y){
        long long rx = root(x);
        long long ry = root(y);
        if(rx==ry) return;
        else{
            // ry become parent
            if(rank[rx]<rank[ry]){
                rank[ry] += rank[rx]; 
                parent[rx] = ry;
            } 
            else {
                rank[rx] += rank[ry];
                parent[ry] = rx;
            }
        }
        return;
    }
};
signed main(){
    ll H, W; 
    cin >> H >> W;
    vector<string> G(H);
    vector<vector<int>> uh(H, vector<int>(W, 0));
    vector<vector<int>> uv(H, vector<int>(W, 0));
    REP(i, H) cin >> G[i];
    vector<UnionFind> hr(W, UnionFind(H));
    for(ll col=0; col<W; col++){
        for(ll row=0; row<H; row++){
            if(G[row][col]!='#' and !uh[row][col]){
                uh[row][col] = 1;
                ll nr = row + 1; 
                while(nr<H and G[nr][col]!='#') {
                    hr[col].unite(row, nr);
                    uh[nr][col] = 1;
                    nr++;
                }
            } else{
                uh[row][col]=1;
            }
        }
    }
    vector<UnionFind> vt(H, UnionFind(W));
    for(ll row=0; row<H; row++){
        for(ll col=0; col<W; col++){
            if(uv[row][col]) continue;
            if(G[row][col]!='#'){
                uv[row][col] = 1;
                ll nc = col + 1;
                while(nc<W and G[row][nc]!='#'){
                    vt[row].unite(col, nc);
                    uv[row][nc] = 1;
                    nc++;
                }
            } else{
                uv[row][col]=1;
            }
        }
    }
    ll res = 0;
    REP(i, H){
        REP(j, W){
            res = max(res, hr[j].getRank(i) + vt[i].getRank(j) -1);
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int H[N];
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }
    int C[N];
    for(int i = N - 1; i >= 0; i--){
        if(i == N - 1){
            C[i] = 0;
        } else{
            if(H[i + 1] <= H[i]){
                C[i] = C[i + 1] + 1;
            }else{
                C[i] = 0;
            }
        }
    }
    int result = 0;
    for(int i = 0; i < N; i++){
        if(result < C[i]){
            result = C[i];
        }
    }
    cout << result << endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int M = 1e5+10;
int main(){
    int n,a;
    while(cin>>n){
        int f=0,t=0;
        for(int i=0;i<n;++i){
            scanf("%d",&a);
            if(a%4==0) ++f;
            else if(a&1) ++t;
        }
        if(f>=t ||(f==t-1 && f+t==n)) puts("Yes");
        else puts("No");
    }
    return 0;
}


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
 	int a, b; cin >> a >> b;
  	if(a >= 13){
      cout << b << endl;
    }else if(a <= 5){
      cout << 0 << endl;
    }else{
      cout << b/2 << endl;
    }
  
} 


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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    if (dist[i][j] != d) continue;
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9504
n = int(input())
li = list(map(int,input().split()))
split_cnt = 0
p = 0
while p == 0:
    for i in range(len(li)):
        if li[i] % 2 == 1:
            p = 1
            break
        else:
            li[i] = li[i] / 2
    split_cnt += 1
print(split_cnt - 1)

Measured memory_bytes: 3060
import numpy as np
n,k,s = map(int,input().split())
a=np.arange(n)
if k>0 and s<1000000000:
  a[:k]=s
  a[k:]=s+1
elif k>0 and s>=1000000000:
  a[:k]=s
  a[k:]=s-1
elif k==0 and s>=1000000000:
  a[:]=s-1
else:
  a[:]=s+1
for s in a:
  print(s, end =" ")

Measured memory_bytes: 22084
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long A,B,K,n,m;

int main()
{
  cin >>A>>B>>K;

  if(K<=A)
  {
    n=A-K;
    cout <<n <<" " << B; 
  }
  else if(K<=A+B)
  {
    m=A+B-K;
    cout <<0<<" " <<m;
  }
  else
  {
    cout <<0<<" "<<0;
  }
  
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll modpow(ll n, ll r) {
    ll ret = 1;
    ll p = n;
    while (r > 0) {
        if (r & 1) {
            ret = (ret * p) % MOD;
        }
        p = (p * p) % MOD;
        r /= 2;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = modpow(10, N);
    ll t = (modpow(9, N) * 2LL - modpow(8, N) + MOD) % MOD;
    cout << (MOD + ans - t) % MOD << endl;

    return 0;
}

Measured memory_bytes: 3648
a = list(input().split(" "))
x = int(a[0])
if x < 0:
    x *= -1
k = int(a[1])
d = int(a[2])
c = x // d

if c >= k:
    x -= d * k
else:
    x -= d * c
    if (k - c) % 2 == 1:
        x = (x - d) * -1

print(x)


Measured memory_bytes: 9168
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
	  #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
	   ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
		   # #  # # #                   # #      ###### #    # #    # #      #####
	  #    # #   #  #              #    # #      #    # #    # #    # #      #   #
	   ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LL i = 0; i < (n); i++)
#define FOR(in) for(LL i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 
 
LL concate(LL a, LL b)
{
	ostringstream os;
	os <<a <<b;
	istringstream is(os.str());
	LL c;
	is>> c;
	return c;
}
 
 
LL check(char c)
{
	return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';
}
LL mod = 1e9+7;
 
 
int main()
{
	LL q,t;
	//cin>>t;
	//while(t--)
	//{
	   LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
		LL aa[1000];
		LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
		LL ma=0, mi=100000000;
		LL mid=0, temp=0, stop=0, start=0;
		double pi= 3.141592653589793;
		double d1=0.0, d2, d3, d4;
		VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
		VS vs, vs1, vs2, vs3, vs4;
		VP vp, vp1,vp2;
		char ch, ch1, ch2[1001];
		string str, str1, str2, str3, str4, str5;
		pair<LL, LL> pa;
		list<LL> li, li1;
		map<LL, LL> mp, mp1;
		set<LL> st;
		map<LL ,LL> :: iterator imll;
		VLL :: iterator ivll;
		set<LL> :: iterator isll;
		VP :: iterator ivp;
 
		
		cin>>a>>b>>c;
		if(a-b == b-c)cout<<yes<<endl;
		else cout<<no<<endl;
	
	exit()
 
 
}


Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
string s[101];
int main()
{
	int n,l;
	scanf("%d %d",&n,&l);
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	sort(s+1,s+1+n);
	for(int i=1;i<=n;i++){
		cout<<s[i];
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		
		// 計算
		int x3 = x2 - (y2 - y1);
		int y3 = y2 - (x1 - x2);
		int x4 = x1 - (y2 - y1);
		int y4 = y1 - (x1 - x2);
		
		// 出力
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
	}
}


Measured memory_bytes: 23124
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

fn evaluate(v: Vec<char>) -> Vec<u64> {
    let mut out = vec![0u64; v.len()];
    let mut last_left_index = None;
    let mut right_count = 0;
    let mut left_count = 0;
    for (i, c) in v.into_iter().enumerate() {
        if c == 'R' {
            right_count += 1;
            if let Some(index) = last_left_index {
                if left_count & 1 == 1 {
                    out[index] += left_count / 2 + 1;
                    out[index - 1] += left_count / 2;
                } else {
                    out[index] += left_count / 2;
                    out[index - 1] += left_count / 2;
                }
                last_left_index = None;
            }
            left_count = 0;
        } else {
            left_count += 1;
            if right_count > 0 {
                if right_count & 1 == 1 {
                    out[i] = right_count / 2;
                    out[i - 1] = right_count / 2 + 1;
                } else {
                    out[i] = right_count / 2;
                    out[i - 1] = right_count / 2;
                }
                last_left_index = Some(i);
            }
            right_count = 0;
        }
    }

    if let Some(index) = last_left_index {
        if left_count & 1 == 1 {
            out[index] += left_count / 2 + 1;
            out[index - 1] += left_count / 2;
        } else {
            out[index] += left_count / 2;
            out[index - 1] += left_count / 2;
        }
    }
    out
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let v: Vec<char> = iter.next().unwrap().chars().collect();

    println!("{}", evaluate(v).iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" "));
}


Measured memory_bytes: 10620