akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
  int minv;
  int d[MAX],color[MAX];

  for(int i = 0;i < n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    int u = -1;
    for(int i = 0;i < n;i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(int v = 0;v < n;v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(d[v] > d[u] + M[u][v]){
	  d[v] = d[u] + M[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  for(int i = 0;i < n;i++){
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main(){
  cin >> n;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      M[i][j] = INFTY;
    }
  }

  int k,c,u,v;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra();

  return 0;
}



Measured memory_bytes: 3132
import java.util.Scanner;
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		char[] s = new char[n];
		char[] t = new char[n];	
		for(int i = 0;i<n;i++)
			s[i] = S.charAt(i);
		
		for(int i = 0;i<n;i++)
			t[i] = T.charAt(i);
		
		for(int i = 0;i<n;i++) {
			System.out.print(s[i]);
		    System.out.print(t[i]);
		}
		    sc.close();
	}
	public static void main(String[] args) {
		solve();

	}

}


Measured memory_bytes: 21716
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let(a, b) = {
    let tmp: Vec<i8> = read_vec();
    (tmp[0], tmp[1])
  };

  let ans = if a-b*2 <= 0 {
    0
  } else {
    a - b*2
  };

  println!("{}", ans);

}

Measured memory_bytes: 4352
N = int(input())
H = list(map(int, input().split()))
res = "Yes"
lenH = len(H)
val = 0
for i in range(lenH):
  if val <= H[i]-1:
    val = H[i]-1
  elif val == H[i]:
    val = H[i]
  else:
    res = "No"
    break
print(res)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

void NO() {
  cout << "No" << endl;
  exit(0);
}

const int N = 1 << 19;
int s[N];

int idx = 1;
vector<int> adj[N];
int dep[N], par[N];
VI at[30];

string ty[N];
string cur;

multiset<int> ss;
int ans[N], ids[N];

const int INF = 1e9 + 10;

int build(int u, int sub, int d, int p) {
  dep[u] = d;
  par[u] = p;

  int ht = sub;
  cur.push_back(ht + '0');

//  int lim = p == -1 ? INF : ans[p];
//  auto it = ss.lower_bound(lim);
//  if (it == ss.begin()) NO();
//  it--;
//  ans[u] = *it;
//  ss.erase(it);

  for (int i = 0; i < sub; i++) {
    int v = idx++;
    adj[u].push_back(v);
    build(v, sub - 1 - i, d + 1, u);
  }

  at[d].push_back(u);

  ty[u] = cur;
  reverse(ty[u].begin(), ty[u].end());
  cur.pop_back();

  return ht;
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  int sz = 1 << n;
  for (int i = 0; i < sz; i++) {
    cin >> s[i];
    ss.insert(s[i]);
  }

//  sort(s, s + sz);

  build(0, n, 0, -1);


  iota(ids, ids + sz, 0);
  sort(ids, ids + sz, [&](int u, int v) {
    return ty[u] > ty[v];
  });
  for (int i = 0; i < sz; i++) {
    int u = ids[i];
    int lim = par[u] == -1 ? INF : ans[par[u]];
    auto it = ss.lower_bound(lim);
    if (it == ss.begin()) NO();
    it--;
    ans[u] = *it;
    ss.erase(it);
  }

//  idx = 0;
//  for (int d = 29; d >= 0; d--) {
//    reverse(at[d].begin(), at[d].end());
//    for (int u: at[d]) {
//      ans[u] = s[idx++];
//    }
//  }

  for (int u = 0; u < sz; u++) {
    for (int v: adj[u]) {
      if (ans[v] >= ans[u]) NO();
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 54736
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

def main():
    N, K = mi()
    A = lmi()
    F = lmi()
    A.sort()
    F.sort()
    F.reverse()
    ng = -1
    ok = 10**12
    while ok - ng > 1:
        mid = (ok + ng) // 2
        t = 0
        for i in range(N):
            t += max(A[i] - mid // F[i], 0)
        if t <= K:
            ok = mid
        else:
            ng = mid
    print(ok)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 113920
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = sys.stdin.buffer.readline().decode().rstrip()
ok =S[2] == S[3] and S[4] == S[5]
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 13656
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l,count1=0;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC135();
}

void ABC135(){
    int min,index;
    cin>>n;
    vector<int> vec(n),vec2(n);
    for(i=0;i<n;i++){
        cin>>vec[i];
    }
    for(i=0;i<n;i++){
        min=vec[i];
        index=i;
        for(j=i+1;j<n;j++){
            if(vec[j]<min){
                min=vec[j];
                index=j;
            }
        }
        if(i!=index){
            swap(vec[i],vec[index]);
            count1++;
        }
    }
    for(i=0;i<n;i++){
        cerr<<vec[i]<<" ";
    }
    if(count1<=1)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,sum=0;
  int a[LIMIT2]={0};
  ll b[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld",&n);
  rep(i,n){
    scanf("%d",&a[i]);
    sum += (ll)a[i];
  }
  
  for(i=1;i<n-1;i+=2){
    sum -= 2*(ll)a[i];
  }
  b[0] = sum;
  for(i=0;i<n-1;i++){
    b[i+1] = 2*(ll)a[i]-b[i];
  }
  
  rep(i,n) printf("%lld%c",b[i],(i==n-1 ? '\n' : ' '));
  return 0;
}

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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
int cnt[111111];
int odd[111111];

signed main(){
    cin>>N>>M;
    rep(i,N){
        int x;cin>>x;
        cnt[x]++;
    }

    rep(i,100000+1)if(cnt[i]&1)odd[i%M]++,cnt[i]--;
    int ans=0;
    for(int i=0;i<=M-i;i++){
        int a=i,b=(M-i)%M;
        if(a!=b){
            int t=min(odd[a],odd[b]);
            ans+=t;
            odd[a]-=t;
            odd[b]-=t;
        }
        else{
            ans+=odd[i]/2;
            odd[i]%=2;
        }
    }

    for(int i=M;i<=100000;i++)cnt[i%M]+=cnt[i];

    rep(i,M){
        int t=odd[i];
        if(t&1)t--;
        int m=min(t,cnt[(M-i)%M]);
        cnt[(M-i)%M]-=m;
        ans+=m;
    }
    rep(i,M)ans+=cnt[i]/2;
    cout<<ans<<endl;
    return 0;
}


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

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var A = new int[3][];
            for (int i = 0; i < 3; i++)
            {
                A[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }

            var N = int.Parse(Console.ReadLine());

            var b = new int[N];
            for (int i = 0; i < N; i++)
            {
                b[i] = int.Parse(Console.ReadLine());
            }

            var C = new bool[3][];
            for (int i = 0; i < 3; i++)
            {
                C[i] = new bool[3];
            }

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (A[j][k] == b[i])
                        {
                            C[j][k] = true;
                        }
                    }
                }
            }

            var result = false;
            for (int i = 0; i < 3; i++)
            {
                if ((C[i][0] && C[i][1] && C[i][2]) || (C[0][i] && C[1][i] && C[2][i]))
                {
                    result = true;
                }
            }
            if ((C[0][0] && C[1][1] && C[2][2]) || (C[2][0] && C[1][1] && C[0][2]))
            {
                result = true;
            }

            Console.WriteLine($"{(result ? "Yes" : "No")}");
        }
    }
}


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

int main(void){
    int x;
    cin >> x;
    
    if(x == 1){
        cout << 1 << endl;
        return 0;
    }
    
    int ans = 1, ex;
    int i, j;
    for(i = 2; i <= 31; i++){
        for(j = 2; j <= 9; j++){
            ex = pow(i, j);
            if(ex <= x && ex > ans){
                ans = ex;
            }else if(ex > x){
                break;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

a,b,x=get_f
x/=a
k=2.0*x/b
if k>a
    x=a*b-x
    k=2.0*x/a
    c=(k**2+a**2)**0.5
    puts 90.0-Math.acos(k/c)/Math::PI*180
else
    c=(k**2+b**2)**0.5
    puts Math.acos(k/c)/Math::PI*180
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

struct UnionFind{
	vector<int>par,size;
	int find(int x){
		return (par[x]==x?x:par[x]=find(par[x]));
	}
	void merge(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		if(size[x]<size[y]){
			par[x]=y;
			size[y]+=size[x];
		}else {
			par[y]=x;
			size[x]+=size[y];
		}
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int getsize(int x){return size[find(x)];}
	UnionFind(int x,vector<int>&v):size(v){
		rep(i,x){
			par.push_back(i);
		}
	}
};
struct Edge{
	int from,to,weight;
	bool operator<(Edge &e){return weight<e.weight;}
};
struct Edge2{
	int to,weight,idx;
};
int N,M;
vector<int>X;
vector<Edge2>G[100005];
Edge E[100005];
bool ok[100005],usedV[100005],usedE[100005];
void dfs(int x,int MX){
	usedV[x]=true;
	for(Edge2 i:G[x])if(i.weight<=MX){
		if(!usedE[i.idx])usedE[i.idx]=true;
		if(!usedV[i.to])dfs(i.to,MX);
	}
}
signed main(){
	cin>>N>>M;
	X.resize(N);
	for(int &i:X)cin>>i;
	rep(i,M){
		cin>>E[i].from>>E[i].to>>E[i].weight;
		E[i].from--;E[i].to--;
	}
	UnionFind uf(N,X);
	sort(E,E+M);
	rep(i,M){
		uf.merge(E[i].from,E[i].to);
		if(uf.getsize(E[i].from)>=E[i].weight)ok[i]=true;
		G[E[i].from].push_back({E[i].to,E[i].weight,i});
		G[E[i].to].push_back({E[i].from,E[i].weight,i});
	}
	rev(i,M){
		if(!usedV[E[i].from]&&ok[i])dfs(E[i].from,E[i].weight);
	}
	int ans=0;
	rep(i,M)ans+=!usedE[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 21396
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

char upper(char c){
    if('a' <= c and c <= 'z'){
        c = c - 32;
    }
    return c;
}

char lower(char c){
    if('A' <= c and c <= 'Z'){
        c = c + 32;
    }
    return c;

}

int main(){
    int n = 1200;
    char str[n];



    scanf("%[^\n]%*c", str);
    

    int length = strlen(str);

    //printf("length %d\n", length);

    

    for(int i = 0; i < length; i++){
        if('a' <= str[i] and str[i] <= 'z'){
            str[i] = upper(str[i]);
        }
        else if('A' <= str[i] and str[i] <= 'Z'){
            //printf("%c", str[i]);
            str[i] = lower(str[i]);
        }
    }
    
    printf("%s", str);
    printf("\n");

    return 0;

}


Measured memory_bytes: 3208
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

int main(){
    bool table[4][13];

    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            table[i][j] = false;
        }
    }   

    int n;
    cin >> n;
    for(int i=0;i<n;i++) {
        char s; int num;
        cin >> s >> num;

        switch(s){
            case 'S':
                table[0][num-1] = true;
                break;
            case 'H':
                table[1][num-1] = true;
                break;
            case 'C':
                table[2][num-1] = true;
                break;
            case 'D':
                table[3][num-1] = true;
                break;
        }
    }

    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            if(!table[i][j]){
                switch(i){
                    case 0:
                        cout << "S " << j+1 << endl;
                        break;
                    case 1:
                        cout << "H " << j+1 << endl;
                        break;
                    case 2:
                        cout << "C " << j+1 << endl;
                        break;
                    case 3:
                        cout << "D " << j+1 << endl;
                        break;
                }
            }
        }
    }
}


Measured memory_bytes: 3100
r, c = gets.split(" ").map(&:to_i)
hyou = Array.new(r){
  arr = gets.split(" ").map(&:to_i)
  arr << arr.inject(&:+)
}
arr = []
(c + 1).times do |i|
  arr << hyou.inject(0){|sum, item|
    sum + item[i]
  }
  end
hyou.each{|item|puts item.join(" ")}
puts arr.join(" ")
    

Measured memory_bytes: 6140
N = int(input())
S = input()

R = [0] * N
G = [0] * N
B = [0] * N

for i in range(1, N):
    if S[-i] == "R":
        R[-i] += R[-i + 1] + 1 if i != 1 else 1
        G[-i] += G[-i + 1]
        B[-i] += B[-i + 1]
    if S[-i] == "G":
        R[-i] += R[-i + 1]
        G[-i] += G[-i + 1] + 1 if i != 1 else 1
        B[-i] += B[-i + 1]
    if S[-i] == "B":
        R[-i] += R[-i + 1]
        G[-i] += G[-i + 1]
        B[-i] += B[-i + 1] + 1 if i != 1 else 1

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        k = j + 1
        if k >= N:
            break
        if S[i] == S[j]:
            continue
        if not ("R" in S[i] + S[j]):
            ans += R[k]
            if R[k] > 0 and (2 * j - i) < N and S[2 * j - i] == "R":
                ans -= 1
        elif not ("G" in S[i] + S[j]):
            ans += G[k]
            if G[k] > 0 and (2 * j - i) < N and S[2 * j - i] == "G":
                ans -= 1
        else:
            ans += B[k]
            if B[k] > 0 and (2 * j - i) < N and S[2 * j - i] == "B":
                ans -= 1
print(ans)


Measured memory_bytes: 68456
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    if((A == B && A != C) || (B == C && B != A) || (C == A && C != B)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX],n;

	cin>>n;
	for(int i=0;i<n;i++)cin>>R[i];

	int maxv = -2000000000;
	int minv = R[0];

	for(int i=1;i<n;i++){
		maxv = max(maxv, R[i]-minv);
		minv = min(minv, R[i]);
	}

	cout<<maxv<<endl;
	
	return 0;

}


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

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

    int sum = 0;
    for (int i = 0; i < s.size() - 2; i++){
        if (s.substr(i, 3) == "ABC") {
            sum++;
        }
    }
    cout << sum << endl;
}

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

int f(int x, int y, int z)
{
  return x * x + y * y + z * z + x * y + y * z + z * x;
}
int main()
{
  int N;
  cin >> N;
  double limit = sqrt(N);
  int cnt;
  for (int n = 1; n <= N; n++)
  {
    cnt = 0;
    for (int i = 1; i < limit; i++)
    {
      if (f(i, 1, 1) > n)
      {
        break;
      }
      for (int j = 1; j < limit; j++)
      {
        if (f(i, j, 1) > n)
        {
          break;
        }
        for (int k = 1; j < limit; k++)
        {
          if (f(i, j, k) == n)
          {
            cnt++;
          }
          if (f(i, j, k) >= n)
          {
            break;
          }
        }
      }
    }
    cout << cnt << '\n';
  }
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double PI = 3.14159265358979323846;

int gcd(int a, int b) {
    int m1 = max(a, b);
    int m2 = a + b - m1;
    if (m2 == 0) {
        return m1;
    }
    return gcd(m2, m1 % m2);
}

int gcd(int a, int b, int c) {
    return gcd(gcd(a,b), c);
}

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

    int k;
    cin >> k;
    ll ans = 0;
    for (int a = 1; a <= k; ++a) {
        for (int b = 1; b <= k; ++b) {
            for (int c = 1; c <= k; ++c) {
                ans += gcd(a, b, c);
            }
        }
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF  (0x7fffffff)
#else
#define LINF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}




int dp[1123];
int W,n;
int v[1123];
int w[1123];

signed main(void)
{
  int i,j,k=0;

  while(1)
    {
      k++;
      rep(i,1123)dp[i]=0;
      int a=0;
      cin>>W;
      if(!W)break;
      cin>>n;
      rep(i,n)
	scanf("%d%*c%d",&v[i],&w[i]);
      rep(i,n)
	for(j=W;j>=w[i];j--)
	  dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
      rep(i,W+1)
	if(dp[i]>dp[a])a=i;
      printf("Case %d:\n%d\n%d\n",k,dp[a],a);
    }
  return 0;
}

Measured memory_bytes: 3208
#include <stdio.h>
int main() {
	int w, n, a, b;
	scanf(" %d %d", &w, &n);
	int lines[w];
	for (a = 0; a < w; a++) {
		lines[a] = a + 1;
	}
	while (n--) {
		scanf(" %d,%d", &a, &b);
		lines[--a] ^= lines[--b];
		lines[b] ^= lines[a];
		lines[a] ^= lines[b];
	}
	for (a = 0; a < w; a++) {
		printf("%d\n", lines[a]);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[100005];

int main() {
  int N, M;
  cin>>N>>M;
  int tmp;
  map<int, int> amap;
  for(int i=0;i<M;++i) {
    cin>>tmp;
    amap[tmp]++;
  }
  DP[0] = 1;
  for(int i=1;i<=N;++i) {
    if(amap[i]>0) continue;
    if(i==1) DP[i] = DP[i-1]%mod;
    else DP[i] = (DP[i-1]+DP[i-2])%mod;
  }
  cout<<DP[N]<<endl;
}



Measured memory_bytes: 9096
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int D = scan.nextInt();
		int x = scan.nextInt();
		List<Integer> list = new ArrayList<>();
		list.add(x);
		for (int i = 0; i < 10; i++) {
			calc(r, D, list, i);
		}
	}

	public static void calc(int r, int D, List<Integer> list, int i) {
		list.add((r * list.get(i)) - D);
		System.out.println(list.get(i + 1));
	}

}

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

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


int* h = new int[n];

for(int i = 0;i<n;i++)cin>>h[i];
int count = 0;
for(int i = 0;i<n;i++){
if(h[i] >= k)count++;
}
cout<<count<<endl;

}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int a,b;
		double s;
		
		a = scan.nextInt();
		b = scan.nextInt();
		s = (double)(a*b)/3.305785;
		s = Math.ceil(s*1000000)/1000000;
		System.out.println(s);
	}
}

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

int main() {
	int x;
	bool f = false;
	cin >> x;
	for (int i = x;x > 0;--i) {
		for (int j = 2;j < 10;++j) {
			for (int k = 1;k < 32;++k) {
				if (abs(pow(k,j)-i) < 0.1) {
					cout << i << endl;
					f = true;
				}
				if (f) break;
			}
			if (f) break;
		}
		if (f) break;
	}
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

 bool check(string S, int n){
    int size = S.size();    
    int a;
    unordered_set<string> st;
    FOR(j,0,size-n){
      string sub = S.substr(j,n);
      st.insert(sub);
      if (st.count(S.substr(j+n,n))>0)return true;
    }
    return false;
  }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string S;
  
  cin >> n;
  cin >> S;
  

    int right = n;
    int left = 0;
    int mid;
    int ans = 0;
    while(left<right){
        mid = (left+right)/2;
        dump(mid);
        dump(check(S,mid));
        if(check(S,mid)){
            left = mid+1;
            ans = max(ans,mid);
        }else
        {
            right = mid;
        }
    }
  cout << ans  << endl;

}


Measured memory_bytes: 6640
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
string S,T;
ll N,K;
ll A[100005];
ll M = 1000000007;
ll ans = 0;
int main() {
    cin >> N >> K;
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a >> b;
        if(a*a+b*b<=K*K){
            ans++;
        }
    }
    cout << ans << endl;
        
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


lint D;
lint decrease[26];
lint satis[365][26];
lint last[26];

lint downscore(lint passed) {
	lint sum = 0;
	REP(i, 26) {
		sum += decrease[i] * (passed - last[i]);
	}
	return -sum;
}

int main() {
	cin >> D;
	REP(i, 26) {
		cin >> decrease[i];
	}
	REP(i, D) {
		REP(j, 26) {
			cin >> satis[i][j];
		}
	}

	lint score = 0;
	REP(i, D) {
		lint maxv = -INF, max_idx = -1;
		REP(s, 26) {
			lint inst = 0;
			inst += satis[i][s];
			inst += downscore(i + 1);
			chmax(inst, 0ll);
			if (maxv < inst) {
				maxv = inst;
				max_idx = s;
			}
		}
		last[max_idx] = i + 1;
		cout << 10 << endl;
	}
}


Measured memory_bytes: 3712
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,d,n,maxi=0,f=0,mini=INF,sum=0;
    ll q;
    ll y;
    string str;
    cin>>str;
    stack<char> s;
    rep(i,str.length()){
        if(str[i]=='B'&&!s.empty()) s.pop();
        if(str[i]=='1') s.push('1');
        if(str[i]=='0') s.push('0');
    }
    vector<char> c;
    while(!s.empty()) {
        c.push_back(s.top());
        s.pop();
    }
    reverse(all(c));
    rep(i,c.size()) cout<<c[i];
    ln;
    return 0;
}


Measured memory_bytes: 3620
N = int(input())
H = list(map(int, input().split()))
B = [0]*N
B[1]=abs(H[1]-H[0])
for i in range(2, N):
    B[i] = min(B[i-2]+abs(H[i]-H[i-2]), B[i-1]+abs(H[i]-H[i-1]))
print(B[N-1])

Measured memory_bytes: 53496
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main(){
IOS;
lli n,w,x,y,i,j;
cin>>n>>w;
vector<pair<lli,lli> > v;
for(i=0;i<n;i++){
    cin>>x;
    cin>>y;
    v.pb(mp(x,y));
}
lli dp[n][w+1]={0};
sort(v.begin(),v.end());
for(j=0;j<=w;j++){
    if(j<v[0].first)
        dp[0][j]=0;
    else dp[0][j]=v[0].second;
}
for(i=0;i<n;i++){
    dp[i][0]=0;
}
for(i=1;i<n;i++){
    for(j=1;j<=w;j++){
        if(j<v[i].first)
        dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
        else{
            dp[i][j]=max(v[i].second+dp[i-1][j-v[i].first],max(dp[i][j-1],dp[i-1][j]));
        }
    }
}
cout<<dp[n-1][w]<<endl;
}


Measured memory_bytes: 78336
program test
implicit none

integer(8) :: i,j,a(0:200001)=2,n,ans=0,b=0
character(len = 200000) :: s

read(*,*) s

n = len_trim(s)

do i= 1,n
	if(s(i:i) == "B")then
		a(i) = 0
	else
		a(i) = 1
	endif
enddo

do i= 1,n
	if(a(i) == 0) then
	b = b+1
	else
	ans = ans + b
	endif
enddo

write(*,*) ans










contains
subroutine heapsort_down(n,y1,y2)
 
	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n
 
	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif
 
		 i = l
		 j = l+l
 
		 do while(j <= k)
				if(j < k) then
					 if(y1(j) > y1(j+1)) j = j+1
				endif
				
				if (t1 > y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return
 
end subroutine heapsort_down
 
subroutine heapsort_up(n,y1,y2)
 
	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n
 
	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif
 
		 i = l
		 j = l+l
 
		 do while(j <= k)
				if(j < k) then
					 if(y1(j) < y1(j+1)) j = j+1
				endif
				
				if (t1 < y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return
 
end subroutine heapsort_up
 
end program


Measured memory_bytes: 2828
from collections import deque

K = int(input())

d = [-1, 0, 1]

que = deque([])
for i in range(1, 10):
    que.append(i)
cnt = 0
while que:
    p = que.popleft()
    cnt += 1
    if cnt == K:
        print(p)
        break
    for i in d:
        if 0 <= int(str(p)[-1]) + i <= 9:
            que.append(int(str(p) + str(int(str(p)[-1]) + i)))

Measured memory_bytes: 10904
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;

int main(){
    int n;
    std::cin >> n;
    VEC(ll,a,n);
    ll han=1,ma=0;
    rep(i,n-1){
        ma=max(ma,a[i]-1);
        if(ma>a[i+1])han=0;
    }
    if(han)std::cout << Yes << std::endl;
    else std::cout << No << std::endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
ll n,k,c;
vector<int> calc(string s){
    vector<int> day;
    int interval=c+1;
    For(i,0,n){
        if(s[i]=='x') {
            interval++;
        }
        else{
            if(interval<c){
                interval++;
            } 
            else{
                day.push_back(i+1);
                interval=0;
            }
        }
    }
    return day;
}
void Main(){
    cin>>n>>k>>c;
    string s;cin>>s;
    vector<int> dp=calc(s);
    if(dp.size()>k) return;
    reverse(ALL(s));
    vector<int> pd=calc(s);
    For(i,0,k){
        pd[i]=n+1-pd[i];
    }
    reverse(ALL(pd));
    For(i,0,k){
        if(pd[i]==dp[i]) cout<<dp[i]<<endl;
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  long check[n];
  for (int i = 0; i < n; i++) {
    check[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    check[a[i]-1]++;
  }

  long combinations = 0;
  for (int i = 0; i < n; i++) {
    combinations += check[i]*(check[i]-1)/2;
  }

  for (int i = 0; i < n; i++) {
    printf("%ld\n", combinations-check[a[i]-1]+1);
  }

  return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using pii = pair<int, int>;



struct UnionFind
{
    int n;
    vector<int> parent;
    vector<int> rank;
    UnionFind(int _n) :n(_n)
    {
        parent.assign(n, -1);
        rank.assign(n, 1);
    }

    int find(int i)
    {
        if (parent[i] == -1)
            return i;
        else
            return parent[i] = find(parent[i]);
    }

    void unite(int i, int j)
    {
        i = find(i);
        j = find(j);

        if (i == j) return;

        if (rank[i] == rank[j])
        {
            parent[j] = i;
            ++rank[i];
        }
        else
        {
            if (rank[i] < rank[j]) swap(i, j);
            parent[j] = i;
        }
    }

    bool is_same(int i, int j)
    {
        return find(i) == find(j);
    }
};

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

    UnionFind uf_road(n);
    rep(i, 0, k)
    {
        int p, q;
        cin >> p >> q;
        --p, --q;
        uf_road.unite(p, q);
    }

    UnionFind uf_express(n);
    rep(i, 0, l)
    {
        int p, q;
        cin >> p >> q;
        --p, --q;
        uf_express.unite(p, q);
    }

    map<pii, int> type_cnt;
    rep(i, 0, n)
    {
        int p1, p2;
        p1 = uf_road.find(i);
        p2 = uf_express.find(i);
        ++type_cnt[make_pair(p1, p2)];
    }
    rep(i, 0, n)
    {
        int p1, p2;
        p1 = uf_road.find(i);
        p2 = uf_express.find(i);
        printf("%d ", type_cnt[make_pair(p1, p2)]);
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int T1, T2;
  scanf("%d", &T1);
  scanf("%d", &T2);
  long long A1, A2, B1, B2;
  scanf("%lld", &A1);
  scanf("%lld", &A2);
  scanf("%lld", &B1);
  scanf("%lld", &B2);
  long long A = A1*T1 + A2*T2;
  long long B = B1*T1 + B2*T2;
  //printf("%lld %lld\n", A, B);
  if (A == B){
    printf("infinity\n");
  } else if (A>B){
    long long D = A-B;
    if (A1>B1){
      printf("0\n");
    } else {
      long long d = B1*T1 - A1*T1;
      long long ans = 2*(((d+D-1)/D)-1) + 1;
      if (d%D==0) ans++;
      printf("%lld\n", ans);
    }
  } else if (A<B){
    long long D = B-A;
    if (A1<B1){
      printf("0\n");
    } else {
      long long d = A1*T1 - B1*T1;
      long long ans = 2*(((d+D-1)/D)-1) + 1;
      if (d%D==0) ans++;
      printf("%lld\n", ans);
    }
  }
  return 0;
}
 

Measured memory_bytes: 3184
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll INF = 1ll << 60;

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (ll &x : A) cin >> x;
    vector<ll> dp(2, -INF);
    dp[0] = 0;
    for (int i = 0; i < N - 1; i++) {
      vector<ll> ndp(2, -INF);
      for (int p = 0; p < 2; p++) {
        if (dp[p] <= -INF) continue;
        for (int np = 0; np < 2; np++) {
          chmax(ndp[np], dp[p] + A[i] * ((p ^ np) ? -1 : 1));
        }
      }
      dp = ndp;
    }
    ll res = -INF;
    for (int p = 0; p < 2; p++) {
      if (dp[p] <= -INF) continue;
      res = max(res, dp[p] + A[N - 1] * (p ? -1 : 1));
    } 
    cout << res << endl;
  }
  return 0;
}


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

#define MOD 1000000007
#define SIZE_1 2000005
#define SIZE_2 1000000
#define INT_BITS 32
typedef long long int ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;

set<ll> s;
ll mx = 400000000;

void backtrack(ll x)
{
    if (s.find(x) != s.end())
        return;

    s.insert(x);
    if (x >= mx)
        return;

    if (x == 0)
        for (int i = 1; i <= 9; i++)
            backtrack(i);

    else
    {
        int t = x % 10;

        if (t > 0)
            backtrack(x * 10 + (t - 1));
        
        backtrack(x * 10 + t);
    
        if(t < 9)
            backtrack(x * 10 + (t + 1));
    }
}

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

    backtrack(0);
    int k;
    cin >> k;
    while(k)
    {
        s.erase(s.begin());
        --k;
    }

    cout << *s.begin();

    return 0;
}


Measured memory_bytes: 5504
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A2.reverse()

for i in range(1, N):
    A1[i] += A1[i - 1]
    A2[i] += A2[i - 1]

A2.reverse()

ans = 0
for i in range(N):
    ans = max(ans, A1[i] + A2[i])

print(ans)



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

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<double> vd;

#define REP(i,a,b) for(int i=(a);i<=(b);++i)
#define pb push_back

const int N = 1e5;
const ll L = 1e18;
const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n, sumA = 0, sumB = 0;
	cin >> n;

	vi v(n);

	REP(i, 0, n-1)
		cin >> v[i];

	sort(v.begin(), v.end(), greater<>());

	for(int i = n-1; i >= 0; --i) {
		if(i % 2 == 0) sumA += v[i];
		else sumB += v[i];
	}

	cout << abs(sumA - sumB) << endl;

	return 0; 	
}

Measured memory_bytes: 256
Q, H, S, D = map(int, input().split())

N = int(input())
ans = 0

Q *= 4
H *= 2
twiceQ = Q * 2
twiceH = H * 2
twiceS = S * 2

a = N % 2
if a == 0:
    num = N // 2
    ans += num * min(twiceQ, twiceH, twiceS, D)
else:
    num = (N-1) // 2
    ans += num * min(twiceQ, twiceH, twiceS, D)
    ans += min(Q, H, S)

print(ans)


Measured memory_bytes: 3316
# coding: utf-8
# Your code here!
N = int(input())
ans = 0
for i in range(1,N+1):
    if i%3 == 0 and i%5 ==0:
        continue
    elif i%3 ==0:
        continue
    elif i%5 == 0:
        continue
    else:
        ans+=i
    
print(ans)

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

using namespace std; 

int n; 
int main () {
	scanf("%d", &n); 
	int cnt = 0; 
	for (int i = 1; i <= n; i++) {
		int x; 
		scanf("%d", &x);
		cnt += x % 2; 
	}

	cout << (cnt % 2 ? "NO" : "YES");
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define dbg2(x,y) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<endl
#define dbg3(x,y,z) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<endl
#define dbg4(x,y,z,q) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<<", "<<#z<<" = "<<z<<", "<<#q<<" = "<<q<<endl
#define dbg_array(x,sz) for (int i = 0; i < sz; ++i) cout << x[i] << " \n"[i==sz-1]
using namespace std;

const ll N = 100 + 9, M = 400 - 9, Max_ans = 1LL * (1e16);
int a[N];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef ECLIPSE
	freopen("input.in", "rt", stdin);
	//freopen("output.out", "wt", stdout);
#endif
	int n, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (i % 2 && a[i] % 2)
			++cnt;
	}
	printf("%d\n", cnt);
	return 0;
}



Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[200010];
ll cnt[200010],ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]),cnt[a[i]]++;
	for(int i=1;i<=n;++i) ans+=cnt[i]*(cnt[i]-1)/2;
	for(int i=1;i<=n;++i) printf("%lld\n",ans-(cnt[a[i]]-1));
	return 0;
}

Measured memory_bytes: 3968
/*************************************************************************
    > File Name: C.cpp
    > Author: PumpkinYing
    > Created Time: 2018/8/18 20:16:55
 ************************************************************************/

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
typedef long long ll;

char s[110];

int main()
{
	scanf("%s",s);
	ll k;
	scanf("%lld",&k);
	int n = 0;

	while(s[n] == '1') n++;
	
	if(k <= n) printf("1\n");
	else printf("%c\n",s[n]);

    return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h, w, n;
    cin >> h >> w >> n;
    cout << min((n + h - 1) / h, (n + w - 1) / w) << "\n";

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans=0;
  cin >> n;
  vector<long> l(n),r(n);
  for(long i=0;i<n;i++) {
    cin >> l[i] >> r[i];
    ans+=r[i]-l[i]+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648