akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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 Monoid>
struct SegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;

  int sz;
  vector<Monoid> seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while (sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) { seg[k + sz] = x; }

  void build() {
    for (int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while (k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const { return seg[k + sz]; }

  template <typename C>
  int find_subtree(int a, const C &check, Monoid &M, bool type) {
    while (a < sz) {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if (check(nxt))
        a = 2 * a + type;
      else
        M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template <typename C>
  int find_first(int a, const C &check) {
    Monoid L = M1;
    if (a <= 0) {
      if (check(f(L, seg[1]))) return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) {
        Monoid nxt = f(L, seg[a]);
        if (check(nxt)) return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template <typename C>
  int find_last(int b, const C &check) {
    Monoid R = M1;
    if (b >= sz) {
      if (check(f(seg[1], R))) return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for (b += sz; a < b; a >>= 1, b >>= 1) {
      if (b & 1) {
        Monoid nxt = f(seg[--b], R);
        if (check(nxt)) return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

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

  int Q;
  cin >> Q;

  SegmentTree<int> seg(
      N, [](int a, int b) { return a | b; }, 0);
  for (int i = 0; i < (int)(N); ++i) { seg.update(i, 1 << (S[i] - 'a')); }

  for (int i = 0; i < (int)(Q); ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      int s = seg[i];
      s = s & ~(1 << (S[i] - 'a'));
      s |= 1 << (c - 'a');
      S[i] = c;
      seg.update(i, s);
    } else {
      int l, r;
      cin >> l >> r;
      --l, --r;
      cout << __builtin_popcount(seg.query(l, r + 1)) << endl;
    }
  }
  return 0;
}


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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    int upper = max(a,c);
    int lower = min(b,d);
    int ans = max(0,lower-upper);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
string c[10]={" ","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"};
int main(){
	string buf;
	while(cin>>buf){
		int pb=buf[0]-'0',cb,t=-1;
		rep(i,buf.size()){
			cb=buf[i]-'0';
 			if(pb!=0&&pb!=cb||cb==0) cout<<c[pb][t%c[pb].size()],t=0;
 			else pb?t++:t=0;
			pb=cb;
		}
		cout<<c[pb][t%c[pb].size()]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
S = input()
l = int(len(S))
n = int((l-1)/2)
m = int(l/2)
count = 0
if l%2 == 1 :
    for i in range(0, n) :
        if S[i] != S[l-1-i]:
            count += 1
else:
    for i in range(0, m):
        if S[i] != S[l-1-i]:
            count += 1
print(count)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int n;
int v[50];
int c[50];
int dfs(int cost, int va, int i){
    if(i==n){
        return(va-cost);
    }
    int ans1=dfs(cost,va,i+1);
    int ans2=dfs(cost+c[i],va+v[i],i+1);
    return max(ans1,ans2);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i=0;i<n;i++) {
        cin>>v[i];
    }
    for(int i=0;i<n;i++) {
        cin>>c[i];
    }
    int ans=dfs(0,0,0);
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define S(num)  ((num) * (num))
#define H(n)    ((5.0) * (n) - (5.0))
 
int main(void)
{
    float in_data;
    float time;
    float high;
    int i;
     
    while (scanf("%f", &in_data) != EOF){
        time = in_data / 9.8;
        high = 4.9 * S(time);
        i = 0;
        while (1)if (H(++i) >= high)break;
         
        printf("%d\n", i);
    }
     
    return (0);
}

Measured memory_bytes: 620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp31 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            var dp = new int[100010];

            dp[0] = 0;

            for (int i = 1; i <= N; i++) {
                dp[i] = 1000000;

                int power_6 = 1;
                while (power_6 <= i) {
                    dp[i] = Math.Min(dp[i], 1 + dp[i - power_6]);
                    power_6 *= 6;
                }

                int power_9 = 1;
                while (power_9 <= i) {
                    dp[i] = Math.Min(dp[i], 1 + dp[i - power_9]);
                    power_9 *= 9;
                }
            }

            Console.WriteLine(dp[N]);
        }
    }
}


Measured memory_bytes: 13280
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int n) {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        auto s = i.to!string;
        if (s.length % 2 == 1) ans++;
    }
    return ans;
}

void main() {
    int n; scan(n);
    writeln(calc(n));
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int c=0;
    map<long long,int>m;
    for(int i=0;i<n;i++)
    {
        long long  x;
        cin>>x;
        m[x]++;
    }
    for(auto u:m)
    {
        if(u.first>u.second)
            c=u.second+c;
        else if(u.first==u.second)
            c=c+0;
        else
            c=c+u.second-u.first;
    }
    cout<<c;
}


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

int main(){
	int sold[10], n;
	while( cin >> n, n ){
		for( int i=0; i<10; i++ )	sold[i]=0;
		for( int i=0; i<n; i++ ){
			int k;
			cin >> k;
			sold[k]++;
		}
		for( int i=0; i<10; i++ ){
			if( sold[i] == 0 )
				cout << "-" << endl;
			else{
				for( int j=0; j<sold[i]; j++ )
					cout << "*";
				cout << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);


int main(){
    int n, k;
    std::cin >> n >> k;
    std::vector<ll> sum_2e(n+1,0);
    rep(i,n){
        ll pi; std::cin >> pi;
        ll ei = pi+1;
        sum_2e[i+1] = ei + sum_2e[i];
    }

    ll ans = 0;
    for(ll i=0; i+k<n+1; i++){
        ans = std::max(ans, sum_2e[i+k]-sum_2e[i]);
    }

    std::cout << std::fixed << std::setprecision(10) << ans/2.0 << "\n";
    return 0;
}


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

int main(){
	string s;
	cin>>s;
	if(s=="SUN")cout<<7<<endl;
	else if(s=="MON")cout<<6<<endl;
	else if(s=="TUE")cout<<5<<endl;
	else if(s=="WED")cout<<4<<endl;
	else if(s=="THU")cout<<3<<endl;
	else if(s=="FRI")cout<<2<<endl;
	else cout<<1<<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;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  map <int,int> dp;
  rep(i,n) cin >> a[i];
  int count = 0;
  
  rep(i,n){
    dp[a[i]]++;
  }
  
  for(auto mp : dp){
    int b = mp.first;
    int c = mp.second;
    
    if(b < c){
      count += c-b;
    }else if(b > c){
      count += c;
    }
  }
  
  cout << count;
  
  return 0;
}

Measured memory_bytes: 5120
s=input()

if s=="SUN":
    print(7)
elif s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
elif s=="SAT":
    print(1)

Measured memory_bytes: 3060
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


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

ll lcm(vector<ll> &A){
    ll ret=1;
    for(int i=0;i<A.size();i++){
        ret/=gcd(ret,A[i]);
        ret*=A[i];
    }
    return ret;
}




int main(){
    ll mx=100000;
    vector<bool> A(mx,1);
    vector<ll> P;
    for(ll i=2;i<mx;i++){
        if(A[i]){
            for(ll t=1;i*t<mx;t*=i){
                P.push_back(i*t);
            }
            for(ll t=2;i*t<mx;t++){
                A[i*t]=0;
            }
        }
    }
    sort(P.begin(),P.end());
    vector<vector<ll>> a(500,vector<ll>(500,1));
    for(int i=0;i<500;i++){
        for(int t=0;t<500;t++){
            if((i+t)&1){
                a[i][t]*=P[(i+t)/2];
            }
            if((i-t)&1){
                a[i][t]*=P[500+(500+i-t)/2];
            }
        }
    }
    vector<ll> dx={0,1,0,-1};
    vector<ll> dy={1,0,-1,0};
    for(int i=0;i<500;i++){
        for(int t=0;t<500;t++){
            if(a[i][t]==1){
                vector<ll> A;
                for(int h=0;h<4;h++){
                    ll x=i+dx[h];
                    ll y=t+dy[h];
                    if(x<0 || y<0 || x>=500 || y>=500){continue;}
                    A.push_back(a[x][y]);
                }
                a[i][t]=lcm(A)+1;
            }
        }
    }
    ll n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int t=0;t<n;t++){
            cout<<a[i][t];
            if(t+1!=n){cout<<" ";}
        }
        cout<<endl;
    }
    
    
    
    
    return 0;
}




Measured memory_bytes: 5120
import heapq

def main():
    n, m = map(int, input().split())
    uvs = [tuple(map(int, input().split())) for _ in range(m)]
    s, t = map(int, input().split())
    edges = [{} for _ in range(n*3)]
    for u, v in uvs:
        x, y = u-1, v-1
        for i in range(3):
            c = 1 if i == 0 else 0
            z = y + n*((i+1)%3)
            edges[x + n*i][z] = c
    l = dijkstra(edges, s-1, t-1)
    if l is None:
        print(-1)
    else:
        print(l)

def dijkstra(graph, start, end):
    q = []
    heapq.heapify(q)
    visited = set()

    for next_, cost in graph[start].items():
        heapq.heappush(q, (cost, next_))

    while len(q) > 0:
        node_cost, current = heapq.heappop(q)
        if current in visited:
            continue
        if current == end:
            return node_cost

        visited.add(current)
        for next_, path_cost in graph[current].items():
            heapq.heappush(q, (node_cost + path_cost, next_))

    return None

main()

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

#define LL long long
#define N 100010


int main(){
    int n,a,b;
    cin>>n>>a>>b;
    if(a+1==b)puts("Borys");
    else if(a+2==b){
        puts("Alice");
    }else{
        int aa=b-a;
        if(aa&1)puts("Borys");
        else puts("Alice");
    }
    
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {  
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int K = I.nextInt();
		long[] a = new long[11];
		Arrays.fill(a,-1);
		long ans = 0;
		while (K>0) {
			UPD(a,a.length-1);
			//for (int i = 0; i < a.length; i++) O.p(a[i]+" ");
			//O.p("\n");
			long mult = 1;
			ans = 0;
			for (int i = a.length-1; i >= 0; i--) {
				ans+=Math.max(a[i],0)*mult;
				mult*=10;
			} 
			K--;
		}
		O.pln(ans);
	}
	public static void UPD(long[] a, int in) {
		if (a[in]==-1) a[in]=1;
		else {
			a[in]++;
			a[in]%=10;
			if (a[in]==0) {
				UPD(a,in-1);
				a[in]=a[in-1]-1;
				a[in]=Math.max(a[in], 0); //Can't have negative digits now
			}
			if (a[in-1]!=-1&&Math.abs(a[in]-a[in-1])>1) {
				//-1 means those digit slots haven't been used yet
				UPD(a,in-1);
				a[in]=a[in-1]-1; //Reset and recurse left starting with lower-bound
				a[in]=Math.max(a[in], 0); //Can't have negative digits now
			}
		}
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 27264
a, b, c, d, e, f = map(int, input().split())

waters = set()
sugars = set()

for i in range(0, f+1):
    for j in range(0, f+1):
        watersum = 100*a*i + 100*b*j
        if watersum == 0 or watersum > f:
            break
        waters.add(watersum)

for i in range(0, f+1):
    for j in range(0, f+1):
        sugarsum = c*i + d*j
        if sugarsum > f:
            break
        sugars.add(sugarsum)


maxx = 0
answ, anss = 100*a, 0

for water in waters:
    for sugar in sugars:
        if water + sugar > f or sugar*(100+e) > e*(water+sugar):
            continue
        conc = sugar / (water + sugar)
        if maxx < conc:
            maxx = conc
            answ, anss = water, sugar

print(answ+anss, anss)







Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cmath>

int main(){
	int n,y;
	const double genkin=10000;
	while(scanf("%d", &n)){
		if(n == 0)return 0;
		scanf("%d",&y);
		int ans=0,mans=0;
		for(int i=0;i<n;++i){
			int b,r,t;
			scanf("%d %d %d",&b, &r, &t);
			double genri;
			double y_=y, r_=r;
			if(t == 1){
				genri = genkin * (1 + y_ * r_ / 100.0);
			}else {
				genri = genkin * std::pow(1+r_/100,y);
			}
			if(genri > mans){
				mans=genri;
				ans=b;
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1192
N,W=map(int,input().split())
vw=[list(map(int,input().split())) for _ in range(N)]
DP=[[0 for i in range(10001)] for j in range(100)]
for idx in range(N):
    for weight in range(10001):
        if weight<vw[idx][1]:
            DP[idx][weight]=DP[idx-1][weight]
        else:
            DP[idx][weight]=max(DP[idx-1][weight-vw[idx][1]]+vw[idx][0],DP[idx-1][weight])

print(DP[N-1][W])


Measured memory_bytes: 42376
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	bool ok=true;
	rep(i,s.size()){
		if(i==a){if(s[i]!='-') ok=false;}
		else if(s[i]=='-') ok=false;
	}
	Yn(ok);
}

Measured memory_bytes: 256
from collections import deque
H,W = map(int, input().split())
grid = [input() for i in range(H)]

# 黒か白かどうか　初期化
dist = [[-1]*W for _ in range(H)]

# #の位置をキューに追加（今回はスタートが複数 複数追加される）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h,w))
            dist[h][w] = 0
def bfs(black_cells, dist):
    """
        BFSを用いて、全マス目を黒くする回数を求める

    Args:
        black_cells: 「開始時の黒マス」の座標が入ったキュー（複数座標あり）
        dist: 「開始時の黒マス」からの距離の入ったリスト  [[-1, -1, 0], ...]
        　　　（白マスの初期値は0）

    Returns:
        g: 操作を繰り返した数
    """
    d = 0
    while black_cells:
        h, w =  black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1,0), (0,1), (-1,0), (0,-1)):
            new_h = h+dy
            new_w = w+dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白であるとき
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)

Measured memory_bytes: 86620
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
using namespace std;
typedef long long int ll;
const int MOD = 1000000007;

int d[10];
bool C(int n){
  while(n>0){
    int t=n%10;
    if(d[t] == 1){
      return false;
    }
    n /= 10;
  }
  return true;
}
int main(){
  int N,K;
  cin >> N >> K;
  for(int i=0;i<K;i++){
    int t;
    cin >> t;
    d[t] = 1;
  }
  while(1){
    if(C(N)){
      cout << N << endl;
      return 0;
    }
    N++;
  }
}

Measured memory_bytes: 256
main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- getLine
      let ls' = map read . words $ ls
      print $ solve ls'
      main

solve :: [Int] -> Int
solve ls
  | isTriNum (sum ls) = loop ls 0
  | otherwise = -1
  where
    isTriNum :: Int -> Bool
    isTriNum n = check n 1
      where
        check :: Int -> Int -> Bool
        check n c
          | n == 0 = True
          | n < 0 = False
          | otherwise = check (n-c) (c+1)
          
    loop :: [Int] -> Int -> Int
    loop ls c
      | c > 10000 = -1
      | isTri ls = c
      | all (0 <) ls = loop ((map (\x -> x-1) ls) ++ [length ls]) (c+1)
      | otherwise = loop (filter (0 <) ls) c
      where
        isTri :: [Int] -> Bool
        isTri ls = all (\(a,b) -> a == b) (zip ls [1..])

Measured memory_bytes: 5452
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	cin >> n;
  	int ctr = 0;
  	for(int i=1; i<n; i++){
    	int temp = n-i;
      	if(temp>i && temp!=i)
          	ctr++;
    }
  	cout << ctr;
  	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

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

using namespace std;

typedef long long ll;

#define f(i,j,k) (a[i]+a[j]>a[k])

int main(){
	int n; scanf("%d",&n);
	static ll a[100000];
	rep(i,n) scanf("%lld",a+i);

	sort(a,a+n);

	static ll dp[100000];
	rep(i,n-2){
		if(f(i,i+1,i+2)) dp[i+2]=a[i]+a[i+1]+a[i+2]; else dp[i+2]=dp[i+1];
	}

	ll ans=0;
	rep(i,n-5){
		if(f(i+3,i+4,i+5) && dp[i+2]>0){
			ans=max(ans,dp[i+2]+a[i+3]+a[i+4]+a[i+5]);
		}
		if(f(i+0,i+2,i+3) && f(i+1,i+4,i+5)
		|| f(i+0,i+3,i+4) && f(i+1,i+2,i+5)
		|| f(i+1,i+2,i+3) && f(i+0,i+4,i+5)){
			ans=max(ans,a[i]+a[i+1]+a[i+2]+a[i+3]+a[i+4]+a[i+5]);
		}
	}
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while ((str = reader.readLine()) != null) {
			int ans = 0;
			int n = Integer.parseInt(str);
			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 == n) {
								ans++;
							}
						}
					}
				}
			}
			System.out.println(ans);
		}
		reader.close();
	}
}



Measured memory_bytes: 24932
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
ll inf = 1e10;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n*2);
  rep(i, n*2) cin >> a[i];
  ll ans = 0;
  rep(i, n){
    ll tmp = 0;
    for(int j = 0; j <= i; ++j) tmp += a[j];
    for(int j = i; j <= n-1; ++j) tmp += a[j+n];
    ans = max(ans, tmp);
  }
  
  
  cout << ans << "\n";
  
}  

Measured memory_bytes: 256
#include <iostream>
#include <set>

#define maxN 100010

int main()
{
	std::set<std::pair<int,int>> set;
	int up[maxN]={0},down[maxN]={0},ss[maxN],ts[maxN],cs[maxN],max=0,n,c,count=0;
	std::cin>>n>>c;
	for (int i=0;i<n;++i)
	{
		std::cin>>ss[i]>>ts[i]>>cs[i];
		
		set.insert(std::make_pair(ts[i], cs[i]));
	}
	
	for (int i=0;i<n;++i)
	{
		if (set.count(std::make_pair(ss[i],cs[i])))
		{
			--down[ss[i]];
			--up[ss[i]];
		}
		++up[ss[i]];
		++down[ts[i]];
	}
	for (int i=0;i<=100000;++i)
	{
		count+=up[i];
		max=std::max(max,count);
		count-=down[i];
	}
	std::cout<<max;
}

Measured memory_bytes: 6912
n = int(input())
a, b = [], []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x + y)
    b.append(x - y)
a.sort()
b.sort()

ans = max(a[-1] - a[0], b[-1] - b[0])

print(ans)


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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  ll sum = 0;
  map<int, int> nums;
  rep(i, n) {
     cin >> a[i];
     nums[a[i]] += 1;
     sum += a[i];
  }

  int q; cin >> q;
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    if (nums[b] > 0){
        int diff = c - b;
        sum += diff * nums[b];
        cout << sum << endl;
        nums[c] += nums[b];
        nums[b] = 0;
    } else {
        cout << sum << endl;
    }
  }
}


Measured memory_bytes: 7844
# B - RGB Boxes
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
R,G,B,N = map(int, input().split())
ans = 0
for r in range(3001):
    for g in range(N-r+1):
        t = N-(R*r+g*G)
        if t>=0 and t%B==0:
            ans += 1
print(ans)



Measured memory_bytes: 40812
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T, typename U> inline void chmax(T &x, U y) { if (x < y) x = y; }
template<typename T, typename U> inline void chmin(T &x, U y) { if (x > y) x = y; }


int main() {
    ll n, m;
    cin >> n >> m;
    if (n - 2 >= 0) n -= 2;
    if (m - 2 >= 0) m -= 2;
    cout << n*m << "\n";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

def count_kth_bit(k):
    ret = 0
    t = 2**k
    am = list(sorted([a%(2*t) for a in A]))
    bm = list(sorted([b%(2*t) for b in B]))

    r1 = r2 = r3 = 0
    for a in reversed(am):
        while r1 < N and a + bm[r1] < t:
            r1 += 1
        while r2 < N and a + bm[r2] < 2*t:
            r2 += 1
        while r3 < N and a + bm[r3] < 3*t:
            r3 += 1
        ret += (r2-r1) + (N-r3)
    return ret

ans = 0
for k in range(29):
    c = count_kth_bit(k)
    ans += ((c%2) << k)
print(ans)

Measured memory_bytes: 145700
#include <iostream>
#include <vector>
using namespace std;
inline bool chmax(long long& a, long long b){if (a<b){a = b; return true;}return false;}

int max(long long x, long long y)
{
  return (x>y) ? x : y ;
}

int main()
{
  int n;
  long long W;
  cin >> n;
  cin>>W;
  vector<long long> weight(n), value(n);
  
  for(int i = 0 ; i < n ; i++ )
  {
    cin >>weight[i]>>value[i];
  }

  vector<vector<long long> > dp(n+2, vector<long long>(100100, 0));

  for(int i = 0 ; i < n ; i++ )
  {
    for(int j = 0 ; j <= W ; j++ )
    {
        if(j >= weight[i])
        {
            chmax(dp[i+1][j] , dp[i][j-weight[i]] + value[i]);
        }
        chmax(dp[i+1][j], dp[i][j]);
    }
  }

  cout<<dp[n][W];
}


Measured memory_bytes: 81024
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int x;
    cin >> x;
    if (x == 0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3192
import sys
def cv1(c):
    o=ord(c)
    if 65<=o<=90:
        return format(o-65,"05b")
    elif o==32:
        return "11010"
    elif o==46:
        return "11011"
    elif o==44:
        return "11100"
    elif o==45:
        return "11101"
    elif o==39:
        return "11110"
    elif o==63:
        return "11111"

d={"101":" ",
   "000000":"'",
   "000011":",",
   "10010001":"-",
   "010001":".",
   "000001":"?",
   "100101":"A",
   "10011010":"B",
   "0101":"C",
   "0001":"D",
   "110":"E",
   "01001":"F",
   "10011011":"G",
   "010000":"H",
   "0111":"I",
   "10011000":"J",
   "0110":"K",
   "00100":"L",
   "10011001":"M",
   "10011110":"N",
   "00101":"O",
   "111":"P",
   "10011111":"Q",
   "1000":"R",
   "00110":"S",
   "00111":"T",
   "10011100":"U",
   "10011101":"V",
   "000010":"W",
   "10010010":"X",
   "10010011":"Y",
   "10010000":"Z"
    }

sk=sorted(d.keys(),key=lambda x:len(x))   
for t in sys.stdin:
    cn=0
    st=""
    ta="".join([cv1(i) for i in t[:-1]])
    tmp=""
    for i in ta:
        tmp+=i
        if tmp in d:
            st+=d[tmp]
            tmp=""
    print(st)



Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int X;
  cin >> X;

  for(int i = 0;i <= 99;i++) {
    for(int j = 0;i+2*j <= 99;j++) {
      for(int k = 0;i+2*j+3*k <= 99;k++) {
        for(int l = 0;i+2*j+3*k+4*l <= 99;l++) {
          for(int m = 0;i+2*j+3*k+4*l+5*m <= 99;m++) {
            int sum = 100*(i+j+k+l+m)+i+2*j+3*k+4*l+5*m;
            if(sum <= X && (X-sum)%100 == 0) {
              cout << 1 << endl;
              return 0;
            }
          }
        }
      }
    }
  }

  cout << 0 << endl;

}





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


int main() {
    ll n,k,q;
    cin >> n >> k >> q;
    vector<int> a(q);
    rep(i,q) cin >> a.at(i);

    vector<int> v(n,0);
    rep(i,q){
        v.at(a.at(i)-1)++;
    }

    vector<string> ans(n,"No");

    rep(i,n){
        if(q-v.at(i)<k){
            ans.at(i)="Yes";
        }
        cout << ans.at(i) << endl;
    }

}

Measured memory_bytes: 6912
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
vector<pair<LL,int>> x;
void solve(long long N, vector<long long> A){
	for(int i=0; i<N; ++i) {
		x.push_back(make_pair(A[i],i+1));
	}
	sort(x.begin(),x.end());
	int cnt=0;
	for(int i=0; i<N; ++i) {
		debug(x[i].second);
		if (x[i].second%2==i%2) ++cnt;
	}
	cout<<cnt/2<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353
const int INF = 1 << 28;



struct Unionfind {
    vector<int> par, num;
    vector<bool> done;
    Unionfind(int n): par(n), num(n, 1), done(n, false) {
        iota(par.begin(), par.end(), 0);
    }
    int root(int v) {
        return (par[v] == v) ? v : (par[v] = root(par[v]));
    }
    void unite(int u, int v) {
        u = root(u), v = root(v);
        if (u == v)return;
        if (num[u] < num[v])swap(u, v);
        num[u] += num[v];
        par[v] = u;
        done[u] = done[u] | done[v];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    bool ispar(int v) {
        return v == root(v);
    }
    int size(int v) {
        return num[root(v)];
    }
};


struct Edge {
    int from, to; ll cost;
    Edge(){}
    Edge(int a, int b, ll c): from(a), to(b), cost(c) {}
};
bool comp(const Edge &e1, const Edge &e2) {
    return e1.cost < e2.cost;
}

int E;
vector<Edge> es(E);


int main() {
    int H, W; cin >> E >> H >> W;
    rep(i, E) {
        int r, c, a; cin >> r >> c >> a;
        r--; c--;
        es.pb(Edge(r, c + H, a));
    }

    ll ans = 0;
    sort(all(es), comp);
    reverse(all(es));
    Unionfind tree(H + W);

    rep(i, E) {
        auto e = es[i];
        if (!tree.same(e.from, e.to)) { //e.fromとe.toが異なる連結成分の場合
            if (tree.done[tree.root(e.from)] && tree.done[tree.root(e.to)])continue; //二つともサイクルがある
            tree.unite(e.from, e.to);
            ans += e.cost;
        }
        else if (!tree.done[tree.root(e.from)]) { //同じ連結成分でまだサイクルが無い場合
            tree.done[tree.root(e.from)] = true;
            ans += e.cost;
        }
    }
    cout << ans << endl;

}






Measured memory_bytes: 3440
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main()
{
	int k;
	cin>>k;
	map<int,int> bc;
	rep(i,k){
		int x,y;
		cin>>x>>y;
		bc.insert(make_pair(x,y));
	}
	int queen[8];
	rep(i,8){
		queen[i] = i;
	}
	do{
		bool canMake = true;
		for(auto iter = bc.begin(); iter != bc.end(); iter++){
			int x= iter->first;
			int y= iter->second;
			if( queen[x] != y){
				canMake = false;
				break;
			}
		}
		for(int i = 0 ; i < 8; i++){
			for(int j = i + 1; j < 8; j++){
				if( queen[j] == queen[i] + (j-i) || queen[j] == queen[i] - (j-i)){
					canMake = false;
					break;
				}
			}
		}
		if(canMake == true){
			break;
		}
	}while(next_permutation(queen,queen+8));

	for(int i = 0; i < 8;i++){
		for(int j = 0; j < 8; j++){
			if( queen[i] == j){
				cout<<"Q";
			}else{
				cout<<".";
			}
		}
		cout<<endl;
	}
	return 0;
}




Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;


namespace GRL5_A
{
    class Edge
    {
        public int t;
        public int w;
        public Edge(int t,int w)
        {
            this.t = t;
            this.w = w;
        }
    }
   
    class Program
    {
        const int MAX = 100000;
        const int INF = 1 << 30;
        static int n;
        static int[] d;
        static List<Edge>[] G = Enumerable.Range(0, MAX).Select(i =>new List<Edge>()).ToArray();
        static void Main(string[] args)
        {
            n = scan[0];
            for (int i = 0; i < n-1; i++)
            {
                var t = scan;
                G[t[0]].Add(new Edge(t[1], t[2]));
                G[t[1]].Add(new Edge(t[0], t[2]));
            }
            bfs(0);
            bfs(Array.IndexOf(d, d.Where(s => s != INF).Max()));
            Console.WriteLine(d.Where(s => s != INF).Max());
        }
        static void bfs(int s)
        {
            d = Enumerable.Repeat(INF, MAX).ToArray();
            var Q = new Queue<int>();
            Q.Enqueue(s);
            d[s] = 0;
            int u;
            while(Q.Any())
            {
                u = Q.Dequeue();
                for (int i = 0; i < G[u].Count; i++)
                {
                    Edge e = G[u][i];
                    if (d[e.t] == INF)
                    {
                        d[e.t] = d[u] + e.w;
                        Q.Enqueue(e.t);
                    }
                }
            }
        }
        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n;cin >> n;
	FOR(i,1,n){
		FOR(j,i+1,n+1){
			int cnt=1;
			int t=2;
			while(i%t==j%t){
				t*=2;
				cnt++;
			}
			cout << cnt << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define log(i,n) log(n)/log(i);
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;


int main()
{
	ll n,k;
	cin >> n >> k;
	vector<ll>h(100010,0),dp(100010,INF);
	rep(i, n)cin >> h[i];
	dp[0] = 0;//初期条件（dpの初項）

	for (ll i = 0; i < n; ++i) {
		for (ll j = 1; j <= k; ++j) {
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}

	// 答え
	cout << dp[n - 1] << endl;
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	cout<<x2-y2+y1<<" "<<y2+x2-x1<<" "<<x1-y2+y1<<" "<<y1+x2-x1;
	return 0;
}

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

int main() {
	int N = 0;
  	int M = 0;
  	cin >> N >> M;
  
	int gu = N * (N - 1) / 2;
	int ki = M * (M - 1) / 2;
  
  	cout << gu + ki << endl;
  
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

Ans();

			//更新する
			Console.Out.Flush();
			
		}
public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = (int)inputArray[0];
			var numArray = retreiveLongArray();

			var ruisekiwa = Enumerable.Repeat((long)0, N + 1).ToArray();

			//先頭に0を足すことで計算しやすくする
			ruisekiwa[0] = 0;
			for (int i = 0; i < N; i++) {
				ruisekiwa[i + 1] = ruisekiwa[i] + numArray[i];
			}

			var ruisekiDic = new Dictionary<long, long>();

			foreach (var rw in ruisekiwa) {

				if (ruisekiDic.ContainsKey(rw)) {
					ruisekiDic[rw]++;
				}
				else {
					ruisekiDic.Add(rw, 1);
				}

			}

			long sum = 0;
			foreach (var item in ruisekiDic) {

				var c = item.Value * (item.Value - 1) / 2;
				sum += c;
			}

			//答えの出力
			var ans = sum;
			Console.WriteLine(ans);

		}

		

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


Measured memory_bytes: 61008
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  int c,d,e;
  c=a+b;
  d=a-b;
  e=a*b;
  if(c>=d&&c>=e)
    cout<<c;
  else if(d>=c&&d>=e)
    cout<<d;
  else
    cout<<e;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
int x[maxn], y[maxn];
ll sufx, sufy, h, w;
void norm(ll & x)
{
	while(x < 0) x += mod;
	while(x >= mod) x -= mod;
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &x[i]);
	for(int i = n; i; --i)
	{
		sufx += x[i]; 
		norm(sufx);
		w += sufx - 1ll * x[i] * (n - i + 1) % mod;
		norm(w);
	}
	for(int i = 1; i <= m; ++i)
		scanf("%d", &y[i]);
	for(int i = m; i; --i)
	{
		sufy += y[i];
		norm(sufy);
		h += sufy - 1ll * y[i] * (m - i + 1) % mod;
		norm(h);
	}
	cout << h * w % mod << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
	static final int mod=1000000007;

	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		long[]a=new long[n+1];
		int[][]b=new int[60][n+1];
		for(int i=1;i<=n;++i) {
			long v=a[i]=s.nextLong();
			long d=1;
			for(int j=0;j<60;++j,d<<=1)
				b[j][i]=(v&d)>0?1:0;
		}
		for(int[]bb:b)
			Arrays.parallelPrefix(bb,Integer::sum);

		long r=0;
		for(int i=1;i<n;++i) {
			long d=1;
			for(int j=0;j<60;++j,d<<=1) {
				int c=b[j][n]-b[j][i];
				int f=(a[i]&d)>0?(n-i-c):c;
				r+=d%mod*f;
				r%=mod;
			}
		}

		System.out.println(r);
	}
}


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

int main() {
  long N, K;
  std::cin >> N >> K;
  //N = 100;
  std::vector<long> a(N), b(N);
  for (long i=0; i<N; i++) {
    std::cin >> a.at(i) >> b.at(i);
  }
  /*for(int i=0; i<N; i++) {
    a.at(i) = i;
    b.at(i) = i * i;
  }*/
  
  map<long,long> m;
  for (long i=0; i<N; i++) {
    m[a[i]] += b[i];
  }
  
  for (auto it=m.begin(); it!=m.end(); it++) {
    cerr << it->first << ' ' << it->second << endl;
  }
  
  /*vector<int> a2(N,999999), b2(N,999999);
  a2.at(0) = a.at(0);
  b2.at(0) = b.at(0);
  for(int i=1; i<N; i++) {
    for(int j=0; j<i+1; j++) {
      if(a.at(i) < a2.at(j)) {
        for(int k=N-2; k>j-1; k--) {
          a2.at(k+1) = a2.at(k);
          b2.at(k+1) = b2.at(k);
        }
        a2.at(j) = a.at(i);
        b2.at(j) = b.at(i);
        break;
      }
    }
  }*/
  long count = 0;
  /*for(int i=0; i<N; i++) {
    count += b.at(i);
    if(count>=K) {
      cout << a.at(i) << endl;
      break;
    }
  }*/
  for (auto it=m.begin(); it!=m.end(); it++) {
    count += it->second;
    //cerr << it->first << endl;
    if (count>=K) {
      cout << it->first << endl;
      break;
    }
  }
  return 0;
}

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

div = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        div.append(i)
        if i ** 2 != n:
            div.append(n // i)

cnt = 0
for i in range(1, int((n-1)**0.5)+1):
    if (n - 1) % i == 0:
        if i ** 2 == n - 1:
            cnt += 1
        else:
            cnt += 2

res = cnt - 1
for v in div[1:]:
    tmp = n
    while tmp % v == 0:
        tmp //= v
    if tmp % v == 1:
        res += 1

print(res)

Measured memory_bytes: 68692
#include <iostream>
using namespace std;
int main(void){
    int n,a=2;
    cin>>n;
    
   for(int i=9;i>1;i-=1){
       if(n%i==0){
           n/=i;
           if(n<=9){
               cout<<"Yes"<<endl;
           }
           else{
               cout<<"No"<<endl;
           }
           break;
       }
            if(n==1){
                cout<<"Yes"<<endl;
                break;
            }
            else if(i==2){
                cout<<"No"<<endl;
            }
   }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))
// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((a) >> (b)) & 1
#define bitcount(a) __builtin_popcountll((a))
//
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
//
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N;
  string S, res = "";
  cin >> N;
  cin >> S;
  REP(i, 2) {
    REP(j, 2) {
      res = "";
      if (i == 0) {
        res += "S";
      } else {
        res += "W";
      }
      if (j == 0) {
        res += "S";
      } else {
        res += "W";
      }
      for (int k = 1; k < N - 1; k++) {
        if (res[k] == 'S') {
          if (S[k] == 'o') {
            res.push_back(res[k - 1]);
          } else {
            res.push_back(res[k - 1] == 'S' ? 'W' : 'S');
          }
        } else {
          if (S[k] == 'x') {
            res.push_back(res[k - 1]);
          } else {
            res.push_back(res[k - 1] == 'S' ? 'W' : 'S');
          }
        }
      }
      int f = 1;
      REP(i, N) {
        if (S[i] == 'o') {
          if (res[i] == 'S') {
            if (res[(N + i - 1) % N] != res[(N + i + 1) % N])
              f = 0;
          } else {
            if (res[(N + i - 1) % N] == res[(N + i + 1) % N])
              f = 0;
          }
        } else {
          if (res[i] == 'S') {
            if (res[(N + i - 1) % N] == res[(N + i + 1) % N])
              f = 0;
          } else {
            if (res[(N + i - 1) % N] != res[(N + i + 1) % N])
              f = 0;
          }
        }
      }
      if (f) {
        cout << res << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 640
package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    line := readLine(reader)
    arr := strings.Split(line, " ")
    A, _ := strconv.Atoi(arr[0])
    B, _ := strconv.Atoi(arr[1])
    C, _ := strconv.Atoi(arr[2])
    D, _ := strconv.Atoi(arr[3])
    var cnt int = 0
    var arr_a [101]int
    var arr_b [101]int

    for i := 0; i <= 100; i++ {
        if i >= A && i <= B {
            arr_a[i] = 1
        } else {
            arr_a[i] = 0
        }

        if i >= C && i <= D {
            arr_b[i] = 1
        } else {
            arr_b[i] = 0
        }
    }

    for i := 0; i <= 100; i++ {
        if arr_a[i] == 1 && arr_b[i] == 1 {
            cnt++
        }
    }

    if cnt > 0 {
        cnt--
    }

    fmt.Println(cnt)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 640