akhauriyash/Code-Regression huggingface dataset:
// C - Train Ticket
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	string S; cin>>S;
	int a=S[0]-'0', b=S[1]-'0', c=S[2]-'0', d=S[3]-'0';
	rp(bit, 0, 8){
		int i = (bit&4)==4, j = (bit&2)==2, k = (bit&1)==1;
		if(7 == a + (i? -b: b) + (j? -c: c) + (k? -d: d)){
			cout<< a << (i? '-': '+') << b << (j? '-': '+')
				<< c << (k? '-': '+') << d <<"=7"<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
bool test = 0;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
#define MAX (int)1e6 + 5

int M, N;
char a[105][105];

signed main(void) {
	int i, j, k, l;
	int N, d;
	int p[1005];
	cin >> N >> d;
	rep(i, N) {
		cin >> p[i];
	}
	sort(p, p + N);
	int cnt = 0;
	for (i = N - 1; i > -1; i--) {
		if (p[i] < d) break;
		cnt += p[i] - d;
	}
	if (cnt == 0) puts("kusoge");
	else cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3152
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n+1)
    self.rnk = [0] * (n+1)
    
  def find_root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.find_root(self.root[x])
      return self.root[x]
    
  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1
    
  def isSameGroup(self, x, y):
    return self.find_root(x) == self.find_root(y)
  
  def size(self, x):
    return -self.root[self.find_root(x)]

N, M = map(int, input().split())
hint = [list(map(int, input().split())) for _ in range(M)]

UF = UnionFind(N)
for i in range(M):
  x = hint[i][0]
  y = hint[i][1]
  UF.unite(x, y)
print(len([r for r in UF.root if r < 0]) - 1)

Measured memory_bytes: 29796
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  std::cout << S.substr(0, 3) << std::endl;
  return 0;
}

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

typedef long long int ll;


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

	ll i,j,t,k,l,m,n,x,y,z,c;

	cin >> n;

	if(n >= 400 && n <= 599)
		cout << 8 << '\n';
	else if(n >= 600 && n <= 799)
		cout << 7 << '\n';
	else if(n >= 800 && n <= 999)
		cout << 6 << '\n';
	else if(n >= 1000 && n <= 1199)
		cout << 5 << '\n';
	else if(n >= 1200 && n <= 1399)
		cout << 4 << '\n';
	else if(n >= 1400 && n <= 1599)
		cout << 3 << '\n';
	else if(n >= 1600 && n <= 1799)
		cout << 2 << '\n';
	else if(n >= 1800 && n <= 1999)
		cout << 1 << '\n';

	

	
	

}

Measured memory_bytes: 3648
N = input()

S = set()

# (a*K+1)*K**b==N

# b==0
# a*K+1==N
K = 1
while K*K<=N-1:
  if (N-1)%K==0:
    if K>1:
      S.add(K)
    if (N-1)/K>1:
      S.add((N-1)/K)
  K += 1

# b==1
# (a*K+1)*K==N
K = 1
while K*K<=N:
  if N%K==0:
    if K>1 and (N/K-1)%K==0:
      S.add(K)
    K2 = N/K
    if K2>1 and (N/K2-1)%K2==0:
      S.add(K2)
  K += 1

# b>=2
for b in range(2, 100):
  K = 2
  while True:
    if K**b>N:
      break
    if N%K**b==0 and (N/K**b-1)%K==0:
      S.add(K)
    K += 1

print len(S)


Measured memory_bytes: 2696
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){


}
int main(){
    int n;
    int ans = 0;

    cin >> n;
    vector<int> v;

    int x;
    for (int i = 0; i < n; i++){
        cin >> x;
        v.push_back(x);
    }

    vector<int> odd,even;
    for (int i = 0; i < n; i+=2){
        odd.push_back(v[i]);
    }
    for (int i = 1; i < n; i+=2){
        even.push_back(v[i]);
    }

    int m = *max_element(odd.begin(), odd.end());
    int m2 = *max_element(even.begin(), even.end());

    vector<int> sum(m+1);
    vector<int> sum2(m2+1);

    for (int i = 0; i < odd.size(); i++){
       sum[odd[i]]++; 
    }
    auto Iter1 = max_element(sum.begin(), sum.end());
    int index = distance(sum.begin(), Iter1);
    ans = n/2 - *Iter1;

    for (int i = 0; i < even.size(); i++){
        sum2[even[i]]++;
    }

    vector<int>::iterator Iter2;

    bool t = false;
    while(t == false){
        Iter2 = max_element(sum2.begin(), sum2.end());
        int index2 = distance(sum2.begin(), Iter2);

        if (index != index2){
            t = true;
        } else {
            sum2[index2] = 0;
        }
    }

    ans += n/2 - *Iter2;

    //cout << ans << endl;

    int ans2 = 0;
    vector<int> sum3(m2+1);
    vector<int> sum4(m+1);

    for (int i = 0; i < even.size(); i++){
       sum3[even[i]]++; 
    }
    Iter1 = max_element(sum3.begin(), sum3.end());
    index = distance(sum3.begin(), Iter1);
    ans2 = n/2 - *Iter1;

    for (int i = 0; i < odd.size(); i++){
        sum4[odd[i]]++;
    }

    //vector<int>::iterator Iter2;

    t = false;
    while(t == false){
        Iter2 = max_element(sum4.begin(), sum4.end());
        int index2 = distance(sum4.begin(), Iter2);

        if (index != index2){
            t = true;
        } else {
            sum4[index2] = 0;
        }
    }
    ans2 += n/2 - *Iter2;

    if (ans < ans2) {
        cout << ans << endl;
    } else {
        cout << ans2 << endl;
    }
}


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

#define pb push_back
#define mp make_pair
#define inside sl<=l&&r<=sr
#define outside r<sl||sr<l
#define INF 1000000009
#define mod 1000000007
using namespace std;
typedef long long ll;

int n;
list<int> adj[100005];
ll dp[100005][2];

void dfs(int node, int ata){
	ll beyaz = 1;
	ll siyah = 1;
	for (int ch: adj[node]){
		if (ch == ata) continue;
		dfs(ch, node);
		beyaz *= (dp[ch][0] + dp[ch][1]);
		siyah *= dp[ch][0];
		beyaz %= mod;
		siyah %= mod;
	}
	dp[node][0] = beyaz;
	dp[node][1] = siyah;
}

int main(){
	//freopen("stl.gir", "r", stdin);
	
	cin >> n;
	for (int i = 0; i < n-1; i++){
		int u, v;
		cin >> u >> v;
		u--; v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	
	dfs(0, -1);
	
//	for (int i = 0; i < n; i++) cout << dp[i][0] << " " << dp[i][1] << endl;
	cout << (dp[0][0] + dp[0][1])%mod << endl;
}

Measured memory_bytes: 16512
class Dice:
    def __init__(self):
        self.diceNum: List[int] = [] 

    def setNum(self,i):
        self.pos = i[0]
        self.diceNum.append(i[0])
        self.diceNum.append(i[1])
        self.diceNum.append(i[2])
        self.diceNum.append(i[3])
        self.diceNum.append(i[4])
        self.diceNum.append(i[5])
    def getTopPos(self):
        return self.diceNum[0]    
    def moveToTopnum(self,n):
        i = 0
        for i in range(0,4):
            if (self.getTopPos() == n ):
                return True
            self.move("S")
        else:
            for j in range(0,4):
                if (self.getTopPos() == n ):
                    return True
                self.move("E")
        return False
    def getFrontPos(self):
        return self.diceNum[1]
    def getRightPos(self):
        return self.diceNum[2]
    def yokoRotate(self):
            i0=self.diceNum[0]
            i1=self.diceNum[2] 
            i2=self.diceNum[4] 
            i3=self.diceNum[1]
            i4=self.diceNum[3]
            i5=self.diceNum[5]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
    def move(self,d):
        if (d == "E"):
            i0=self.diceNum[3]
            i1=self.diceNum[1] 
            i2=self.diceNum[0] 
            i3=self.diceNum[5]
            i4=self.diceNum[4]
            i5=self.diceNum[2]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "W"):
            i0=self.diceNum[2]
            i1=self.diceNum[1] 
            i2=self.diceNum[5] 
            i3=self.diceNum[0]
            i4=self.diceNum[4]
            i5=self.diceNum[3]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "S"):
            i0=self.diceNum[4]
            i1=self.diceNum[0] 
            i2=self.diceNum[2] 
            i3=self.diceNum[3]
            i4=self.diceNum[5]
            i5=self.diceNum[1]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
        if (d == "N"):
            i0=self.diceNum[1]
            i1=self.diceNum[5] 
            i2=self.diceNum[2] 
            i3=self.diceNum[3]
            i4=self.diceNum[0]
            i5=self.diceNum[4]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
    def rotateToFrontnum(self,n):
        for i in range(0,4):
            self.yokoRotate()
            if ( self.getFrontPos() == n):
                return True
        return False
    def isEqual(self,d):
        for i in range(0,6):
            if (self.diceNum[i] != d.diceNum[i]):
                return False
        return True

 
l = list(map(int,input().split()))
dice = Dice()
dice.setNum(l)

min = 10000
r_num = 0
for i in set(l):
    if (min > l.count(i)):
       min = l.count(i)
       r_num = i
dice.moveToTopnum(r_num)


l2 = list(map(int,input().split()))
dice2 = Dice()
dice2.setNum(l2)

t = dice.getTopPos()
f = dice.getFrontPos()
r = dice.getRightPos()
#print ("test0:",t,f,r)
if (dice2.moveToTopnum(t) != True):
    print ("No")
#    print ("t1")
elif (dice2.rotateToFrontnum(f) != True):
    print ("No")
#    print ("t2")

elif (dice.isEqual(dice2) == False ):
    print ("No")
#    print ("t3")
else:
    print ("Yes")    
#print (dice.diceNum)
#print (dice2.diceNum)


Measured memory_bytes: 5740
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	int a, b; char op; cin >> a >> op >> b;
	cout << (op == '+' ? a + b : a - b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<tuple<int, int, int>> vec(m);
  
  rep(i,m){
    int p,y;
    cin >> p >> y;
    vec[i] = make_tuple(y, p, i);
  }
  
  sort(vec.begin(), vec.end()); //
  
  vector<int> cnt(n+1);
  vector<pair<int,int>> id(m);
  
  rep(i,m){
    int y,p,idx;
    tie(y,p,idx) = vec[i]; //データ取り出し
    cnt[p]++; //ID割り振り
    id[idx] = make_pair(p,cnt[p]); //元の順番通りに格納
  }
  
  rep(i,m){
    printf("%06d%06d\n",id[i].first,id[i].second);
  }
  return 0;
}

Measured memory_bytes: 3840
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY puts("Yes")
#define NN puts("No")
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,n - 2){
    if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')ans++;
  }
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,x;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    int cnt=0; 
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==x) cnt++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int i, n, a, b, c, temp;

    scanf("%d", &n);

    for(i=0; i<n; i++) {
        scanf("%d%d%d", &a, &b, &c);
        if(a > c) {
            temp = c;
            c = a;
            a = temp;
        }
        if(b > c) {
            temp = c;
            c = b;
            b = temp;
        }

        if(c*c == a*a + b*b) {
            puts("YES");
        } else {
            puts("NO");
        }
    }

    return 0;
}

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

typedef unsigned long long ull;

int main(){
  ull n;
  while(cin >> n , n){
    ull s = -n;
    for(ull i=1; i*i <= n; i++){
      if(n%i == 0){
	if(n!=i*i)
	  s += i + n/i;
	else
	  s += i;
      }
    }
    if(s < n)
      cout << "deficient number" << endl;
    else if(n < s)
      cout << "abundant number" << endl;
    else
      cout << "perfect number" << endl;
  }
}

Measured memory_bytes: 1148
#include <algorithm>
#include <cmath>
#include <cstdio>
const double PI = acos(-1);
int A, B, X;

int main() {
    scanf(" %d%d%d", &A, &B, &X);
    int face = A*A;
    int volume = (face * B - X);
    double H = 2.0 * volume / face;
    if (H > B) {
        // The remaining water forms a triangle
        double K = 2.0 * X / A / B;
        double theta = atan2(K, B) / PI * 180.0;
        printf("%.9f\n", 90.0 - theta);
    } else {
        // The empty air forms a triangle
        double deg = atan2(H, A) / PI * 180.0;
        printf("%.9f\n", deg);
    }
    return 0;
}

Measured memory_bytes: 256
import bisect

n = int(input())
abc = [tuple(map(int, input().split(" "))) for i in range(3)]
# n = 100000
# abc = [tuple(range(n)) for i in range(3)]

a, b, c = [sorted(abc_i) for abc_i in abc]

print(sum(bisect.bisect_left(a, b_i) * (n-bisect.bisect_right(c, b_i)) for b_i in b))

Measured memory_bytes: 23200
/*  ex3_4
    yy8332  */

#include <stdio.h>

int main(void){
  int number, i, j;

  //入力読み取り
  scanf("%d", &number);

  //判定
  for(i = 1; i <= 9; i++)for(j = 1; j <= 9; j++){
    if(number == i * j){
      //出力
      printf("Yes\n");
      return 0;
    }
  }
  //出力
  printf("No\n");

  return 0;
}


Measured memory_bytes: 128
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    n = len(s) + 1
    arr = [0] * n
    for i in range(n - 1):
        if s[i] == '<':
            arr[i + 1] = arr[i] + 1
        else:
            arr[i + 1] = 0
    for i in reversed(range(n - 1)):
        if s[i] == '>':
            arr[i] = max(arr[i], arr[i + 1] + 1)

    print(sum(arr))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 83392
using System;
using System.Collections.Generic;
class Program
{
    /*  Listに入れて
        1番目からK番目までを出力する
     */
    static void Main(string[] args)
    {
        string[] NK = Console.ReadLine().Split();
        string[] P = Console.ReadLine().Split();
        List<int> imput = new List<int>();
        int K = int.Parse(NK[1]);
        int Add = 0;
        int a = 0;
        while (true)
        {
            if (a == P.Length)
            {
                break;
            }
            imput.Add(int.Parse(P[a]));
            
            a++;
        }
       imput.Sort();
        a = 0;
        for(int i = 1; i <= K; i++)
        {
            Add += imput[a];
            a++;
        }
        Console.WriteLine(Add);
       
 
    }
}

Measured memory_bytes: 18536
def make_checker_board_list(h, w):
    return [['#' if (i+j)%2 == 0 else '.' for i in range(w)] for j in range(h)]

while True:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    else:
        for l in make_checker_board_list(h, w):
            print(''.join(l))
        print()



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

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

const int MAXN = 100;
const int MAXW = 1e5;

int N, W, C[MAXN+10], V[MAXN+10];
ll dp[MAXN+10][MAXW+10];

int main()
{
    int i, j;
    scanf("%d%d", &N, &W);
    for(i=1; i<=N; i++) scanf("%d%d", &C[i], &V[i]);

    for(i=1; i<=N; i++)
    {
        for(j=0; j<=W; j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=C[i]) dp[i][j]=max(dp[i][j], dp[i-1][j-C[i]]+V[i]);
        }
    }
    printf("%lld", dp[N][W]);
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}



int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<vector<ll>> a(100001);
  for(i=0;i<m;i++){
    ll p,q;
    cin>>p>>q;
    a[p-1].push_back(q-1);
  }
  ll l,r;cin>>l>>r;l--;r--;
  ll dp[n][3];
  for(i=0;i<n;i++)for(j=0;j<3;j++)dp[i][j]=INF;
  queue<P> q;
  q.push({l,0});
  while(!q.empty()){
    buf=q.front().fi;
    buf2=q.front().se;
    //cout<<buf spa buf2<<endl;
    if(dp[buf][buf2%3]>buf2){
      dp[buf][buf2%3]=buf2;
      for(i=0;i<a[buf].size();i++){
        q.push({a[buf][i],buf2+1});
        //cout<<buf spa buf2 spa i<<endl;
      }
    }
    q.pop();
  }
  chmin(res1,dp[r][0]);
  if(res1==INF)cout<<-1<<endl;
  else cout<<res1/3<<endl;
  return 0;
}

Measured memory_bytes: 8064
x = int(input())

a = 0
while True:
	t = abs(a**5-x)
	s = 0
	c = 0
	while s<t:
		c += 1
		s = c**5
	
	if s == t:
		b = int(c*((a**5-x)/t))
		break
	a += 1

print('{} {}'.format(a, b))
	


Measured memory_bytes: 9188
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        ArrayList<Integer> l = new ArrayList<>();
        ArrayList<Integer> r = new ArrayList<>();


        for (int i = 0; i < m; i++) {
            l.add(scanner.nextInt());
            r.add(scanner.nextInt());
        }

        if (Collections.min(r) >= Collections.max(l)) {
            System.out.println(Collections.min(r) - Collections.max(l) + 1);
        } else {
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 84060
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N;
    cin >> N;
    veci A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    int max = A[N-1];
    int m = max/2;
    int a,b;
    int r = N-1;
    int l = -1;
    while(r-l > 1) {
        int mid = (r+l)/2;
        if(A[mid] <= m) l = mid;
        else r = mid;
    }
    a = A[l];
    r = N-1;
    l = -1;
    while(r-l > 1) {
        int mid = (r+l)/2;
        if(A[mid] < m) l = mid;
        else r = mid;
    }   
    b = A[r];
    if(a >= max-b) cout << max<< " " << a << endl;
    else cout << max << " " << b << endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
#define int long long 
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
ll f[1000010][5];
int n,A[1000010],B[1000010];
int mp[11][11];
inline void Init()
{
	mp[1][0]=2;mp[1][1]=1;mp[1][2]=0;
	mp[3][0]=2;mp[3][1]=1;mp[3][2]=0;
	mp[2][0]=1;mp[2][2]=1;mp[2][1]=0;
}
signed main()
{
	n=read();Init();
	for(rint i=1;i<=n;++i) A[i]=read(),B[i]=A[i];
	for(rint i=1;i<=n;++i) if(A[i]==0) continue;else {if(A[i]%2==1) A[i]=1;else A[i]=2;}
	memset(f,0x3f,sizeof(f));
	memset(f[0],0,sizeof(f[0]));
	for(rint i=1;i<=n;++i)
	{
		for(rint j=0;j<5;++j)
		{
			int tmp=mp[j][A[i]];
			if(j==0||j==4) tmp=B[i];
			ll Min=1e18;
			for(rint k=0;k<=j;++k) Min=min(Min,f[i-1][k]);
			f[i][j]=Min+tmp;
		}
	} 
	ll ans=1e18;
	for(rint j=0;j<5;++j) ans=min(1ll*ans,f[n][j]);
	cout<<ans;
	return 0;
}

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

using namespace std;

template<class INT>
std::vector<INT> get_min_prime_fact_table(INT n){
    std::vector<INT> lp(n + 1), P;
    for (INT i = 2; i <= n; i++){
        if (lp[i] == 0){
            lp[i] = i;
            P.push_back(i);
        }
        for (INT j = 0; j <= P.size() and P[j] <= lp[i] and i * P[j] <= n; j++)
            lp[i * P[j]] = P[j];
    }

    return lp;
}

template<class INT>
std::vector<INT> prime_factorize(INT n, std::vector<INT>& lp){
    vector<INT> res;
    while (n != 1){
        res.push_back(lp[n]);
        n /= lp[n];
    }

    return res;
}

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());

    int g = 0;
    for (const auto &a: A)
        g = gcd(g, a);
    
    if (g != 1){
        puts("not coprime");
        return 0;
    }

    auto lp = get_min_prime_fact_table(int(1e6));
    vector<int> DP(1e6 + 1);
    DP[1] = 1;
    for (int i = 2; i <= int(1e6); i++)
        DP[i] = DP[i / lp[i]] * (lp[i] == lp[i / lp[i]] ? 1 : lp[i]);
    
    vector<int> P(1e6 + 1);
    for (const auto &a: A){
        for (const auto &p: prime_factorize(DP[a], lp)){
            if (P[p] == 1){
                puts("setwise coprime");
                return 0;
            }
            P[p]++;
        }
    }

    puts("pairwise coprime");
}


Measured memory_bytes: 18916
#include<iostream>
using namespace std;
int n,k;
int w[100000];
int check(int p){
    int num=0;
    int s;
    for(int i=0;i<k;i++){
        s=0;
        while((s+w[num])<=p){
            s+=w[num++];
            if(num==n)return n;
        }
    }
    return num;
}
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>w[i];
    }
    int left=0,right=100000*10000;
    int mid,v;
    v=check(right);
    if(v<n)return 0;
    do{
        mid=(left+right)/2;
        v=check(mid);
        if(v<n){
            left=mid;
        }
        else if(v==n){
            right=mid;
        }
    }while((right-left)>1);
    cout << right << endl;
    return 0;
}



Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define SZ(x) ((int)(x).size())
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
template <typename T>
inline void _read(T& x){
    cin>>x;
}
void R(){}
template <typename T,typename... U>
void R(T&head,U&... tail){
    _read(head);
    R(tail...);
}

template <typename T>
inline void _write(const T& x){
    cout<<x<<' ';
}
void W(){cout<<endl;}
template <typename T,typename... U>
void W(const T&head,const U&... tail){
    _write(head);
    W(tail...);
}

void go();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    go();
    return 0;
}
/****************ackun*********************/
void go(){
    int n,m;
    R(n,m);
    vector<pii> v;
    rep(i,1,n){
        int x,y;
        R(x,y);
        v.pb({x,y});
    }
    sort(v.begin(),v.end());
    ll ans=0;
    int cnt=0;
    for(auto x:v){
        //W(x.fi,x.se,cnt);
        if(cnt+x.se<=m){
            cnt+=x.se;
            ans+=1LL*x.fi*x.se;
        }else{
            ans+=1LL*x.fi*(m-cnt);
            cnt+=m-cnt;
        }
        if(cnt==m){
            break;
        }
    }
    W(ans);
}


Measured memory_bytes: 1400
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i <= b; i++) {
    if (i*a % b == c) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$k = (int)$input[1];

$input = explode(' ', trim(fgets(STDIN)));
// 累積和
$csum = [0];
$idx = 1;
foreach ($input as $v) {
	$csum[$idx] = $csum[$idx-1] + e((int)$v);
	$idx += 1;
}
// var_dump($csum);
$max = 0;
for ($i=$k; $i <= $n; $i++) { 
	$max = max($max, $csum[$i] - $csum[$i-$k]);
}
echo $max;



function e($p)
{
	return ($p+1) / 2;
}

Measured memory_bytes: 29168
N = int(input())
list1 = [int(input()) for i in range(N)]

dict2 = {}
for i in list1:
    if(i in dict2):
        dict2[i] += 1
    else:
        dict2[i] = 1

count = 0;
for i in dict2.values():
    if i % 2 == 1:
        count += 1
print(count)

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

using namespace std;

int main(){
    long long n, a, b, ans = 0;

    cin >> n >> a >> b;

    long long complete = n/(a+b);

    long long remaining = n%(a+b);

    cout << a*complete + min(a, remaining) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>

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

int n;
int ans[505][505];

int main(void)
{
	cin >> n;
	if(n == 1){
		cout << "Yes" << endl;
		cout << 1 << endl;
		return 0;
	}
	if(n%2){
		cout << "No" << endl;
		return 0;
	}
	for(int i = 1; i <= n-1; i++){
		for(int j = 1; j <= n-1; j++){
			if(i < j) continue;
			ans[i][j] = (i+j-2)%(n-1)+1;
		}
	}
	for(int j = 1; j <= n-1; j++){
		ans[n][j] = ans[j][j];
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i >= j) continue;
			ans[i][j] = ans[j][i] + n-1;
		}
	}
	for(int i = 1; i <= n; i++) ans[i][i] = 2*n-1;
	
	cout << "Yes" << endl;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			cout << ans[i][j];
			if(j < n) cout << " ";
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 4084
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<typeinfo>
#include<cassert>
#include<functional>
#include<algorithm>
#include<climits>
#include<map>

using namespace std;



int main(){

    int a,b;

    cin >> a >> b;

    string c = to_string(a) + to_string(b);


    int d = sqrt(stoi(c));

    if(d*d == stoi(c)){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define INF 2e9
#define IMAX 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long llong;

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

	int cnt = 0;
	int now = 1;

	while(true) {
		if (now >= B) {
			break;
		}
		now += (A - 1);
		++cnt;
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using LL = long long;
int n;
LL a, b, ans;
int main(){
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a >> b;
		ans += b - a + 1;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
sd = input()
t = input()

n = len(sd)
m = len(t)
s = []

# sd を後ろから見ていき、 t の入りそうな場所を探す
for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        # 1文字ずつ順に入りうるか調べ、最後まで入るなら "?" を "a" に置き換えて出力
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int mx =3007;
vl a(mx);
vector<vl > dp(mx, vl(mx,-1));
ll solve(int i, int j){
	if(i>j)return 0;
	if(dp[i][j]==-1){
		ll aa = a[i] + min(solve(i+1,j-1), solve(i+2,j));
		ll bb = a[j] + min(solve(i+1,j-1), solve(i,j-2));
		dp[i][j] = max(aa,bb);
		// trace3(i,j,dp[i][j])
	}
	return dp[i][j];
}
int main(){
	fast_io;
	int n;
	cin>>n;
	ll sum = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}

	ll f = solve(0,n-1);
	// trace(f)
	ll s = sum - f;
	cout<<f-s;
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 71168
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
const int INF=1e9+7;
int main(){
  ll n,k;
  cin>>k>>n;
  vll a(n),b(n);
  REP(i,n){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  REP(i,n){
    b[i]=a[i+1]-a[i];
    if(i==n-1){
      b[i]=a[0]+k-a[n-1];
    }
  }
  sort(b.begin(),b.end());
  cout<<k-b.back()<<endl;
}

Measured memory_bytes: 3328
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(final String[] args) {
        final Task task = new Task();
        task.solve();
    }
}

class Task {

    public void solve() {
        try(final Scanner scanner = new Scanner(System.in);) {
            final int n = scanner.nextInt();

            final Set<String> input = IntStream.rangeClosed(1, n).mapToObj(i -> scanner.next())
                    .collect(Collectors.toSet());
            System.out.println(input.size());
        }
    }
}


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

int ans = 0;
int input;


int main(){
	while(scanf("%d", &input)!=EOF){
		ans = 0;
		for(int i=0; i < 10; i++){
			for(int j=0; j < 10; j++){
				for(int k =0; k < 10; k++){
					for(int l =0; l < 10; l++){
						if(i+j+k+l == input) ans++;
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1208
// -*- coding: utf-8 -*-
// Last-Updated : <2014/06/19 02:46:20 by samui>

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <bitset>

#define MP(a, b) make_pair(a, b)
#define X first
#define Y second
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); ++(i))
#define rer(i,l,n) for(int (i) = l; (i) <= (int)(n); ++(i))
#define reu(i,l,n) for(int (i) = l; (i) < (int)(n); ++(i))
template<typename T,typename U> inline void amin(T &x,U y){ if(y<x) x = y;}
template<typename T,typename U> inline void amax(T &x,U y){ if(x<y) x = y;}
template<typename TYPE,std::size_t SIZE>
std::size_t len(const TYPE (&array)[SIZE]){return SIZE;}

int main(int argc, char *argv[])
{
  int n,m;
  std::cin>>n>>m;
  std::vector<int> a(m);
  std::vector<int> b(n+1,100000000);
  int t;
  rep(i,m){
    std::cin >> t;
    a[i] = t;
  }
  b[0]=0;
  rep(i,n+1){
    reu(j,0,m){
      if(i-a[j]>=0)
	amin(b[i],b[i-a[j]]+1);
    }
  }
  std::cout<<b[n]<<std::endl;

  return 0;
}

Measured memory_bytes: 1288
x,y = gets.chomp.split(" ").map(&:to_i)

# 鶴がa匹, 亀がb匹とすると
# a + b == x
# 2 * a + 4 * b == y
# の連立方程式
a = 2 * x - y / 2
b = x - a

if y % 2 == 0 && a >= 0 && b >= 0
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 14320
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

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

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vcl;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vcl,less<ll>>;
using pqchoto=priority_queue<ll,vcl,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)
#define    strl(a)        atoi(a.c_str())
string lstr(ll n){stringstream ss;ss<<n;return ss.str();}

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;

int main() {//ikarus_101

    ll n,m,i,j,k,x;

    int a[100] = {0};
    cin >> n;
    rep(i,n)
    {
        string s;cin >> s;
        a[s.front()]++;
    }

    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a['A'],a['W'],a['T'],a['R']);














}


Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int one, two, three;
  if(n >= 9) {
    one = 9;
  } else {
    one = n;
    cout << one << "\n";
    return 0;
  }


  if (n >= 999) {
    two = 900;
  } else if(n >= 100){
    two = n - 99;
    cout << one + two << "\n";
    return 0;
  } else {
    cout << one << "\n";
    return 0;
  }
  if (n >= 99999) {
    three = 90000;
  } else if(n >= 10000){
    three = n - 9999;
  } else {
    three = 0;
  }

  cout << one + two + three << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	// n = even m = odd
	// output even
	int n, m, counter[2] = {0}, sumn = 0, summ = 0;
	scanf ("%d %d", &n, &m);

	//even + even = even
	// odd + odd = odd
	// 3 odd 2 even =  4 ways to make even 0dd1 0dd2 0dd1 0dd3 0dd2 0dd3 even1 even2
	// 4 odd = o1o2 o1o3 o1o4 o2o3o2o4 o3o4
	// 5 odd = n - 1 + n - 2 + n - 3 + n - 4 + n - n
	for (int i = 1; i <= n; i++) {
		sumn += n - i;
	}
	for (int i = 1; i <= m; i++) {
		summ += m - i;
	}
	printf ("%d", sumn + summ);
	return 0;
}

Measured memory_bytes: 1724
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;

typedef int Value1;
typedef int Value2;
const Value1 Zero1(10000000);
const Value2 Zero2(0);

struct Node {
	Value1 sum;//更新された値. この値を参照する時は評価が完全に完了しているようにする.
	Value2 lazy;	//遅延されている値を保存している
	Node() :sum(Zero1) {
		lazy = Zero2;
	}
};
struct lazy_segtree {
	int N;
	vector<Node>dat;
	lazy_segtree(int n) :N(1) {
		while (N < n) N *= 2;
		dat.resize(2 * N);
		for (int i = N - 1; i >= 1; --i) {
			update_node(i);
		}
	}

	Value2 lazy_connect(const Value2 l, const Value2 r) {
		return l+r;
	}

	void lazy_func(const int k, const int a, const int b) {
		dat[k].sum+=dat[k].lazy;
	}

	Value1 connect(const Value1 l, const Value1 r) {
		return min(l,r);

	}

	// inlineつけないと大変なことになるよ!(遅い)
	inline void lazy_evaluate_node(int k, int a, int b) {
		lazy_func(k, a, b);
		if (k < N) { // 2*k(左の子番号) < 2*N (節点の数) のイメージで. 末端ノードじゃなきゃ伝搬するのと等価.
			dat[2 * k].lazy = lazy_connect(dat[2 * k].lazy, dat[k].lazy);	//次は君が伝搬してね☆って感じ.
			dat[2 * k + 1].lazy = lazy_connect(dat[2 * k + 1].lazy, dat[k].lazy);
		}
		dat[k].lazy = Zero2;
	}

	inline void update_node(int k) { // kの子が既に評価されていることが前提. 末端以外のときしか呼び出さないような位置に書くのでif文要らない.
		dat[k].sum = connect(dat[2 * k].sum, dat[2 * k + 1].sum);

	}

	// update(l,r,v) := [l,r)を更新する. 区間は0-indexed.
	void update(int l, int r, Value2 v, int k = 1, int a = 0, int b = -1) {
		if (b == -1)b = N;
		if (l < 0 || r < 0)assert(false);
		lazy_evaluate_node(k, a, b); 	// とりあえず辿ったノードは都合がいいので伝搬しとけ精神.

		if (b <= l || r <= a) //[a,b)と[l,r)が交差している場合
			return;
		if (l <= a && b <= r) { // [l,r)が[a,b)を完全に含んでいる場合
			dat[k].lazy = lazy_connect(dat[k].lazy, v);
			lazy_evaluate_node(k, a, b); //一回遅延評価しとかないと都合悪いので.
			return;
		}

		int m = (a + b) / 2;
		update(l, r, v, 2 * k, a, m);
		update(l, r, v, 2 * k + 1, m, b);
		update_node(k);
	}
	//get(l,r) := [l,r)に対するクエリの答えを得る. 区間は0-indexed.
	Value1 get(int l, int r, int k = 1, int a = 0, int b = -1) {
		if (b == -1)b = N;

		if (l < 0 || r<0)assert(false);
		lazy_evaluate_node(k, a, b); // とりあえず辿ったノードは都合がいいので伝搬しとけ精神.

		if (b <= l || r <= a) //[a,b)と[l,r)が交差している場合
			return Zero1;

		if (l <= a && b <= r) { // [l,r)が[a,b)を完全に含んでいる場合
			return dat[k].sum;
		}

		int m = (a + b) / 2;
		Value1 vl = get(l, r, 2 * k, a, m);
		Value1 vr = get(l, r, 2 * k + 1, m, b);
		update_node(k);
		return connect(vl, vr);
	}
};
int main() {

	int N;cin>>N;
	vector<int>as(N);
	vector<int>bs(N);
	for(int i=0;i<N;++i)cin>>as[i];
	for(int i=0;i<N;++i)cin>>bs[i];

	vector<long long int>pluss;
	vector<long long int>minuss;
	for (int i = 0; i < N; ++i) {
		int sa=as[i]-bs[i];
		if(sa>=0)pluss.push_back(sa);
		else minuss.push_back(-sa);
	}
	long long int need=accumulate(minuss.begin(),minuss.end(),0ll);
	long long int sum=0;
	sort(pluss.begin(),pluss.end(),greater<long long int>());
	int answer=minuss.size();
	for (int i = 0; i < pluss.size(); ++i) {
		if (sum >= need) {
			break;
		}
		else {
			answer++;
		}
		sum += pluss[i];

	}
	if (sum < need) {
		cout<<-1<<endl;
	}
	else {
		cout<<answer<<endl;
	}
	return 0;
}


Measured memory_bytes: 2168
#include<stdio.h>
int main(){
int a,b,c[4][13]={0},d,e,f,g;
char z;
scanf("%d",&a);
for(b=0;b<a;b++){
scanf("%s %d",&z,&e);
if(z=='S')
d=0;
if(z=='H')
d=1;
if(z=='C')
d=2;
if(z=='D')
d=3;
c[d][e-1]=1;
}
for(b=0;b<4;b++){
if(b==0)
z='S';
if(b==1)
z='H';
if(b==2)
z='C';
if(b==3)
z='D';
for(f=0;f<13;f++){
if(c[b][f]!=1)
printf("%c %d\n",z,f+1);
}
}
return 0;
}
 

 

Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long A = sc.nextLong();
    long B = sc.nextLong();
    long a = (N / (A + B) )* A;
    long b = N % (A + B);
    if (b >= A) {
      System.out.println(a + A);
    } else {
      System.out.println(a + b);
    }
  }
}

Measured memory_bytes: 22868
#include <iostream>
using namespace std;
int main(){
  int n;cin>>n;
  int nwx = 0;
  int nwy = 0;
  int nwt = 0;
  for(int i = 0; n > i; i++){
    int t,x,y;cin>>t>>x>>y;
    if(!(t-nwt >= abs(nwx-x)+abs(nwy-y) && ((t-nwt)-(abs(nwx-x)+abs(nwy-y)))%2==0)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
      
    

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
long long Merge(int A[],int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k;
  int L[n1+1],R[n2+1];
  long long res=0;
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=1000000001;
  R[n2]=1000000001;
   
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      j++;
      res+= (long long)n1- (long long)i;
    }
  }
  return res;
}
 
long long Merge_Sort(int A[],int left,int right){
  int mid;
  long long res=0;
  if(left+1<right){
    mid=(left+right)/2;
 
    res+=Merge_Sort(A,left,mid);
    res+=Merge_Sort(A,mid,right);
    res+=Merge(A,left,mid,right);
     
  }
  return res;
}
 
int main(){
  int n,S[200000];
  long long x;
  scanf("%d",&n);
  for(int i=0;i<n;i++)scanf("%d",&S[i]);
 
  x=Merge_Sort(S,0,n);
  printf("%ld\n",x);
  return 0;
}

Measured memory_bytes: 2584
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

vector< vector<int> > value; // ノードの値を持つ配列
int num_leaf;             // 葉の数
 
void update(int i, char x) {
    // i 番目の葉の値を x に変える
    i += num_leaf - 1; // i 番目の葉のノード番号
    REP(idx, 26) {
        if(idx == int(x-'a'))
            value[i][idx] = 1;
        else
            value[i][idx] = 0;
    }
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        vector<int> result(26);
        REP(idx, 26) {
            result[idx] = value[i * 2 + 1][idx] + value[i * 2 + 2][idx];
        }
        value[i] = result;
    }
}

vector<int> query(int a, int b, int k, int l, int r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return vector<int>(26); // 区間が被らない場合は {} を返す
    if (a <= l && r <= b) {
        return value[k];
    } else {
        vector<int> c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        vector<int> c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        vector<int> result(26);
        REP(i, 26) result[i] = c1[i] + c2[i];
        return result;
    }
}

int main() {
    int N, Q;
    string S;
    cin >> N;
    cin >> S;
    cin >> Q;

    vector<int> QType(Q), I(Q), L(Q), R(Q);
    vector<char> C(Q);
    REP(i, Q) {
        int query_type;
        cin >> query_type;
        QType[i] = query_type;
        if(query_type==1) {
            cin >> I[i] >> C[i];
        } else {
            cin >> L[i] >> R[i];
        }
    }

    num_leaf = 1;
    while (num_leaf < N) num_leaf *= 2;
 
    value.resize(2*num_leaf-1);
    REP(i, 2*num_leaf-1) {
        value[i].resize(26);
    }
    REP(i, N) {
        update(i, S[i]);
    }

    REP(i, Q) {
        if(QType[i] == 1) {
            update(I[i]-1, C[i]);
        } else {
            vector<int> result = query(L[i]-1, R[i], 0, 0, num_leaf);
            int ans = 0;
            REP(i, 26) {
                if(result[i] > 0) ans++;
            }
            cout << ans << endl;
        }
    }
    
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
typedef long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int n;
    cin >> n;
    int x;
    cin >> x;
    for (int i = 1; i < n; i++) {
        int b;
        cin >> b;
        x ^= b;
    }
    if (x == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  if (a-b>=0) {
    cout << "delicious" << endl;
  } else if (a+x>=b) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  return 0;
}

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

int main(){

        int n,count;
        count = 0;
        cin >> n;
        vector<int> num(n);

        for(int i = 0;i<n ; i++ ){
            cin >> num.at(i);
        }

    for(int i =0;i<n ;i++ ){
        if( i % 2 == 0 && num.at(i) % 2 == 1) count++;
    }

    cout << count <<endl;
}


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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif
    string str;
    cin >> str;
    for (int i = 1; i < str.size(); i++) {
        if (str[i] == str[i - 1]) {
            cout << i << " " << i + 1 << endl;
            return 0;
        }
        if (i >= 2 && str[i] == str[i - 2]) {
            cout << i - 1 << " " << i + 1 << endl;
            return 0;
        }
    }
    cout << "-1 -1\n";
    return 0;
}

Measured memory_bytes: 512
while True:
    table=input().split()
    a=int(table[0])
    op=table[1]
    b=int(table[2])
    if op == '?':
        break
    if op == '+':
        print("%d"%(a+b))
    elif op == '-':
        print("%d"%(a-b))
    elif op == '/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))


Measured memory_bytes: 5596