akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n, m;
  cin >> n >> m;
  vecint a(n);
  for (auto &e : a) {
    cin >> e;
    e %= m;
  }
  vecint sum(n + 1, 0);
  map<int, ll> mp;
  REP(i, n) {
    sum[i + 1] = (sum[i] + a[i]) % m;
    mp[sum[i + 1]]++;
  }
  ll ans = 0;
  // REP(i, n) { cout << sum[i + 1] << " "; }
  cout << endl;
  REPvec(itr, mp) {
    // cout << itr->first << " " << itr->second << endl;
    ans += itr->second * (itr->second - 1) / 2;
  }
  cout << ans + mp[0] << endl;
}


Measured memory_bytes: 4992
using System;using static System.Console;class P{static void Main(){while(1>0){var a=Array.ConvertAll(ReadLine().Split(),int.Parse);if(a[0]+a[1]==0)break;for(int i=0,j;i++<a[0];WriteLine())for(j=0;j<a[1];Write((i+j++)%2>0?"#":"."));WriteLine();}}}


Measured memory_bytes: 15908
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include<math.h>
using namespace std;

 int main(){
   int n,T; cin >>n>>T;
   int c[n],t[n]; int mi=10e6; int res=0;
   for(int i=0;i<n;i++){
     cin >> c[i] >> t[i];
    if(T>=t[i]){
      mi=min(mi,c[i]); res++;
    }
   }
   if(res!=0) cout << mi <<endl;
   if(res==0) cout << "TLE" <<endl;
 }
 
   

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

int seperate(string s)
{
		if(s[0]=='A') 
		{
			//cout<<"1"<<endl;
			return 1;	
		}
		if(s[0]=='W') 
		{
			//cout<<"2"<<endl;
			return 2;
		}
		if(s[0]=='T') 
		{
			//cout<<"3"<<endl;
			return 3;
		}
		if(s[0]=='R') 
		{
			//cout<<"4"<<endl;
			return 4;
	}
}
int main()
{
	int n;
	cin>>n;
	int ans[5];
	string s;
	memset(ans,0,sizeof(ans));
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		ans[seperate(s)]++;
		//memset(s,' ',sizeof(s));
	}
	cout<<"AC x "<<ans[1]<<endl;
	cout<<"WA x "<<ans[2]<<endl;
	cout<<"TLE x "<<ans[3]<<endl;
	cout<<"RE x "<<ans[4]<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include    <algorithm>
#include <cmath>
#include <cstdio>
#include  <cstdlib>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <vector>
#include <string>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef long long lint;
#define SZ(x) ((int)(x).size())
int main()
{
	int a, b;
	cin >> a >> b;
	if(a!=b)cout << 2 * max(a, b)-1 << endl;
	else cout << 2 * a << endl;

	return 0;
}


Measured memory_bytes: 256
a,b = map(int,input().split())
def extgcd(a,b):
    if b:
        y,x = extgcd(b,a%b)
        y -= (a//b)*x
        return x,y
    else:
        return 1,0

x,y = extgcd(a,b)
print(" ".join([str(x),str(y)]))



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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    string s, t; cin>>s>>t;
    int ans = INT_MAX;
    for(i = 0; i < s.size() - t.size() + 1; i++){
        int cnt = 0;
        for(j = 0; j < t.size(); j++){
            if(t[j] != s[i+j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
n = int(input())
s = input()
mx = 0
for i in range(n-1):
  a = [ord(aa) for aa in s[:i+1]]
  b = [ord(bb) for bb in s[i+1:]]
  counter = 0
  for c in range(ord('a'), ord('z')+1):
    if (c in a) and (c in b):
      counter += 1
  if mx < counter:
    mx = counter

print(mx)

Measured memory_bytes: 39280
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>

#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vec vector<int>
#define vecll vector<ll>

using namespace std;
//////////////////////////////////////////////////////////



int main() {
    int x;
    int f5 = 0, f7 = 0;
    rep(i, 3) {
        cin >> x;
        if (x == 5)
            f5++;
        else if (x == 7)
            f7++;
    }

    if (f5 == 2 && f7 == 1)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;



    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ << ' ' <<
#define _squ(x)	((x) * (x))
#define debug(var)	do{std::cout << #var << " : "; view(var);}while(0)
#define line_debug(var)	do{std::cout << "l" << __LINE__ << " " << #var << " : "; view(var);}while(0)
#define _max(v)	*max_element(v.begin(), v.end())
#define _min(v)	*min_element(v.begin(), v.end())
#define _sort(var)	std::sort(var.begin(), var.end());
#define _rsort(var)	std::sort(var.begin(), var.end(), std::greater<>());
using namespace std;
using ll = long long;
int gcd(int m, int n){return !n ? m : gcd(n, m%n);}
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> void view(const T e){ std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){ for(const auto& e : v) std::cout << e << " "; std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T>>& vv){ for(const auto& v : vv){ view(v); } }

int main(){
	int i, j;
	int H, W, N;
	cin >> H >> W >> N;
	if(H>W){
		if(N%H == 0) cout << N/H << endl;
		else cout << N/H+1 << endl;
	}else{
		if(N%W == 0) cout << N/W << endl;
		else cout << N/W+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int N;
vpint adj[101];
int d[101],color[101],p[101];
bool used[101][101]={};
void dijkstra(int s){
	priority_queue<pint> PQ;
	rep(i,N){
		d[i]=INF;
		color[i]=0;
		p[i]=-1;
	}
	d[s]=0;
	color[s]=1;
	PQ.push(mp(0,s));
	while(!PQ.empty()){
		pint f=PQ.top();
		PQ.pop();
		int u=f.second;
		color[u]=2;
		if(d[u]< -f.first) continue;
		rep(j,adj[u].size()){
			int v=adj[u][j].first;
			if(color[v]==2) continue;
			if(d[v]>d[u]+adj[u][j].second){
				d[v]=d[u]+adj[u][j].second;
				PQ.push(mp(-d[v],v));
				color[v]=1;
				p[v]=u;
			}
		}
	}
	rep(i,N){
		if(i==s) continue;
		used[i][p[i]]=true;
		used[p[i]][i]=true;
	}
}
int main(){
	int M;
	scan(N);scan(M);
	int a[1001],b[1001],c[1001];
	rep(i,M){
		scan(a[i]);scan(b[i]);scan(c[i]);
		a[i]--;
		b[i]--;
		adj[a[i]].push_back(mp(b[i],c[i]));
		adj[b[i]].push_back(mp(a[i],c[i]));
	}
	rep(i,N){
		dijkstra(i);
	}
	int ans=0;
	rep(i,M){
		if(used[a[i]][b[i]]==false) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
 
int main(){
    cin >> n;
    for(int i = 1;i <= 9;i++)for(int j = 1;j <= 9;j++){
        if(i * j == n){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Main {
    private final int[][] search = new int[][]{
            {0, 1},
            {0, -1},
            {1, 1},
            {1, -1},
            {1, 0},
            {-1, 1},
            {-1, 0},
            {-1, -1}
    };

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

    private void run() throws IOException {
        boolean b = true;
        final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (b) {
            b = runOnce(reader);
        }

        reader.close();
    }

    private boolean runOnce(final BufferedReader reader) throws IOException {
        final String[] params = reader.readLine().split(" ");
        final int x = Integer.parseInt(params[0]);
        final int y = Integer.parseInt(params[1]);
        if (x == 0 && y == 0) return false;

        final Set<Field> fields = new HashSet<>();
        for (int i = 0; i < y; i++) {
            final String[] line = reader.readLine().split(" ");
            for (int j = 0; j < line.length; j++) {
                final boolean land = line[j].equals("1");
                if (land) {
                    fields.add(new Field(i, j));
                }
            }
        }
        int landCount = 0;
        while (true) {
            final Iterator<Field> iterator = fields.iterator();
            if (!iterator.hasNext()) {
                break;
            }
            final Field next = iterator.next();
            searchLand(next, fields);
            landCount++;
        }
        System.out.println(landCount);
        return true;
    }

    private void searchLand(final Field field, final Set<Field> fields) {
        fields.remove(field);

        final Field tmp = new Field(0, 0);
        for (final int[] s: search) {
            tmp.x = field.x + s[0];
            tmp.y = field.y + s[1];
            if(fields.contains(tmp)) {
                searchLand(tmp, fields);
                fields.remove(tmp);
            }
        }
    }

    private final class Field {
        int x, y;

        Field(final int x, final int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int hashCode() {
            return x * 2 + y * 101;
        }

        @Override
        public boolean equals(final Object obj) {
            if (obj instanceof Field) {
                return ((Field) obj).x == this.x && ((Field) obj).y == this.y;
            }
            return super.equals(obj);
        }
    }
}

Measured memory_bytes: 28976
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Set<String> Dic = new HashSet<String>();
        int Data = sc.nextInt();
        for(int i = 0; i < Data; i++){
            String IorF = sc.next();
            if(IorF.equals("insert")){
                String insert = sc.next();
                Dic.add(insert);
            }else if(IorF.equals("find")){
                String search = sc.next();
                if(Dic.contains(search)){
                    System.out.println("yes");
                }else{
                    System.out.println("no");
                }
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 260052
#!/usr/bin/env python3
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

idx_B = 0
ma = 0
for idx_A, a in enumerate(A):
    while idx_B < N and B[idx_B] < a:
        idx_B += 1
    if ma < idx_A - idx_B:
        ma = idx_A-idx_B

Ans = (B+B)[N-ma-1:2*N-ma-1]

for a, b in zip(A, Ans):
    if a == b:
        print("No")
        exit()
print("Yes")
print(*Ans)


Measured memory_bytes: 40192
#include<bits/stdc++.h>
#define N 50
using namespace std;

string maxNum(string A,string B){
  if(A.size()>B.size()) return A;
  if(A.size()<B.size()) return B;
  for(int i=0;i<A.size();i++){
    if(A[i]>B[i]) return A;
    if(A[i]<B[i]) return B;
  }
  return A;
}

int main(){
  string s;
  cin>>s;
  int slen=s.size();
  string dp[N][N];
  for(int i=0;i<slen;i++){
    string num;
    for(int j=i;j<slen;j++){
      if(('0'<=s[j]&&s[j]<='9')||s[j]=='?'){
	if(s[j]!='?') num+=s[j];
	else num+='9';
	if(num.size()>=2&&num[0]=='0') break;
	dp[i][j]=num;
      }else break;
    }
  }
  for(int w=6;w<=slen;w++){
    for(int i=0;i<=slen-w;i++){
      int r=i+w-1;
      if(s[i]!='?'&&(s[i]!='L'&&s[i]!='R')) continue;
      if(s[i+1]!='?'&&s[i+1]!='(') continue;
      if(s[r]!='?'&&s[r]!=')') continue;
      for(int j=i+3;j<=i+w-3;j++){
	if(s[j]!='?'&&s[j]!=',') continue;
	if(dp[i+2][j-1]==""||dp[j+1][i+w-2]=="") continue;
	if(s[i]=='?'||s[i]=='L')
	  dp[i][r]=maxNum(dp[i][r],dp[i+2][j-1]);
	if(s[i]=='?'||s[i]=='R')
	  dp[i][r]=maxNum(dp[i][r],dp[j+1][r-1]);
      }
    }
  }
  if(dp[0][slen-1]!="") cout<<dp[0][slen-1]<<endl;
  else cout<<"invalid"<<endl;
  return 0;
}

Measured memory_bytes: 3288
#include<iostream>
using namespace std;
int main()
{
    // 入力
    int a;
    cin >> a;

    if (a < 9) {
        cout << a << endl;
    } else if (a < 100) {
        cout << 9 << endl;
    } else if (a < 1000) {
        int a100 = a - 100;
        cout << 10 + a100 << endl;
    } else if (a < 10000) {
        cout << 909 << endl;
    } else if (a < 100000) {
        int a10000 = a - 10000;
        cout << 910 + a10000 << endl;
    } else {
        cout << 90909 << endl;
    }

    // 出力
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    ll n;
    cin >> n;

    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        if( i % 3 == 0 ) continue;
        if( i % 5 == 0 ) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll N,A;
	cin >> N >> A;

	ll x[N];
	ll y[N];
	rep(i,N){
		ll t;
		cin >> t;
		x[i] = t;
		y[i] = t - A;
	}

	ll X = A;
	rep(i,N) X = max(X,x[i]);

	ll dp[N+1][2*N*X+1] = {};
	dp[0][N*X] = 1;

	FOR(j,1,N+1){
		ll ny = y[j-1];
		rep(t,2*N*X+1){
			if(t - ny < 0 || t - ny > 2*N*X) {
				dp[j][t] = dp[j-1][t];
			}else if(0 <= t - ny && t - ny <= 2*N*X){
				dp[j][t] = dp[j-1][t] + dp[j-1][t-ny];
 			} 
		}
	}

	cout << dp[N][N*X] - 1<< endl;
}

Measured memory_bytes: 2304
fun main() {
    var n = nextLong()

    println(res(n))
}

fun res(n: Long): String {
    if (n > 26) {
        return if (n%26L != 0L) {
            res(n/26L) + res(n-(n/26L*26L))
        } else {
            res(n/26L-1L) + res(n-((n/26L-1L)*26L))
        }
    }
    var c = 'a'
    for (i in 1 until n) c++
    return c.toString()
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(' ')
fun nextIntList() = nextList().map { it.toInt() }
fun nextLongList() = nextList().map { it.toLong() }
fun nextDoubleList() = nextList().map { it.toDouble() }


Measured memory_bytes: 34572
#include <iostream>
#include <vector>

int main() {
    int N, X;
    std::cin >> N >> X;

    std::vector<int> L(N);
    for (int i = 0; i < N; i += 1) {
        std::cin >> L[i];
    }

    int count = 1;
    int D = 0;
    for (int i = 0; i < N; i += 1) {
        D += L[i];
        if (D > X) {
            break;
        }
        count += 1;
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
//ProblemC

//#define USE_STDIO
//#define USE_LOG
//#define FILE_ERR

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#ifndef debug
#define debug(...)
#endif // !LOG

//include
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

//for
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define forbe(i, begin, end) for(decltype(begin) i = (begin); i != (end); ++i)
#define forbes(i, begin, end, step) for(decltype(begin) i = (begin); i != (end); i += (step))

//int
using ll = long long;
using ull = unsigned long long;
using uint = unsigned;

//pair
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
#define fi first
#define se second

//vector
template <typename Value>
static inline void fillv(Value& x, const Value& val) { x = val; }
template <typename Vector, typename Value>
static inline void fillv(Vector& v, const Value& val) { for (auto& x : v) fillv(x, val); }

static inline void Solve();

int main(int argc, char* argv[]) {
#ifdef REDIRECT_STDIO
	REDIRECT_STDIO;
#endif // REDIRECT_STDIO

	Solve();
	return 0;
}

//ProblemC
void Solve() {
	int n, k;
	cin >> n >> k;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
	}

	cout << (n - 2) / (k - 1) + 1 << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
s = sum(a)
if s % 10 > 0:
    print(s)
else:
    m = sorted(i for i in a if i % 10 > 0)
    if len(m):
        print(s - m[0])
    else:
        print(0)


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

class Dice{
public:
    Dice(){
        number = new int[6];
        work = new int[6];
    };
    ~Dice(){
        delete[] number;
        delete[] work;
    };

    void setLabel(int index, int num){
        number[index] = num;
    };

    void roll(char dst){
        for(int i = 0; i < 6; i++)  work[i] = number[i];
        
        switch(dst){
        case 'E':
            setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
			break;
		case 'N':
			setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
			break;
		case 'S':
			setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
			break;
		case 'W':
			setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
			break;
		}
	};

	int returnPeek(){
		return number[0];
	}

private:
	void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

private:
	int* number;
	int* work;
};

int main(){
    Dice dice;
    int label;
    char ch;
    for(int i = 0; i < 6; i++){
        scanf("%d",&label);
        dice.setLabel(i, label);
    }
    getchar(); 
    while((ch = getchar()) != '\n'){
        dice.roll(ch);
    }

    printf("%d\n",dice.returnPeek());
}



Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G ((c=A[a]+A[P[a]]+C[a])%k?c:0)+M(
typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L a,L i){for(a=G i++)-M(i);i<2e5;i+=i&-i)B[i]+=a;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){a=X[f];n=X[b];return Z[a]>Z[n]?n=b,b=f,K(n):abs(M(O[f])-(a-n?-G O[a])-K(P[a]):M(O[b])));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(n=0);Z[a=H[P[n]]-n?n:0];*Z=++n)for(;!O[a];S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

Measured memory_bytes: 37204
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll freq[100010];
ll sum = 0;

int main(){
    fill(freq, freq+100010, 0);

    int n; cin >> n;
    
    for(int i=0;i<n;i++){
        int a; cin >> a;
        ++freq[a];
        sum += a;
    }

    int q; cin >> q;
    while(q--){
        ll b, c; cin>>b>>c;

        sum = sum - freq[b]*b + freq[b]*c;
        cout << sum << endl;

        freq[c] += freq[b];
        freq[b] = 0;
    }

    return 0;
}

Measured memory_bytes: 3948
#include<iostream>
#include<queue>
#include<tuple>
#include<string>
using namespace std;

#define MAX_N 63
#define INF 1<<30

int dist[MAX_N][MAX_N][MAX_N][MAX_N];
int dy1[4] = { 0,1,0,-1 };
int dy2[4] = { 0,1,0,-1 };
int dx1[4] = { 1,0,-1,0 };
int dx2[4] = { -1,0,1,0 };
int H, W, map1[MAX_N][MAX_N], map2[MAX_N][MAX_N];
int Lsy, Lsx, Lgy, Lgx;
int Rsy, Rsx, Rgy, Rgx;
string S, T;
queue<tuple<int, int, int, int>>Q;

void _memset() {
	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_N; j++) {
			for (int k = 0; k < MAX_N; k++) {
				for (int l = 0; l < MAX_N; l++) {
					dist[i][j][k][l] = INF;
				}
			}
		}
	}

	for (int i = 0; i < MAX_N; i++) {
		for (int j = 0; j < MAX_N; j++) {
			map1[i][j] = 1;
			map2[i][j] = 1;
		}
	}
}

int main() {
	while (true) {
		//memset.
		_memset();

		//cin.
		cin >> W >> H;
		if (H == 0 && W == 0) {
			break;
		}
		for (int i = 1; i <= H; i++) {
			cin >> S >> T;
			for (int j = 0; j < S.size(); j++) {
				if (S[j] == 'L') {
					Lsx = j + 1; Lsy = i;
					map1[i][j + 1] = 0;
				}
				if (S[j] == '#') {
					map1[i][j + 1] = 1;
				}
				if (S[j] == '.') {
					map1[i][j + 1] = 0;
				}
				if (S[j] == '%') {
					Lgy = i; Lgx = j + 1;
					map1[i][j + 1] = 0;
				}
			}
			for (int j = 0; j < T.size(); j++) {
				if (T[j] == 'R') {
					Rsx = j + 1; Rsy = i;
					map2[i][j + 1] = 0;
				}
				if (T[j] == '#') {
					map2[i][j + 1] = 1;
				}
				if (T[j] == '.') {
					map2[i][j + 1] = 0;
				}
				if (T[j] == '%') {
					Rgy = i; Rgx = j + 1;
					map2[i][j + 1] = 0;
				}
			}
		}

		//bfs.
		Q.push(make_tuple(Lsy, Lsx, Rsy, Rsx));
		dist[Lsy][Lsx][Rsy][Rsx] = 0;

		while (!Q.empty()) {
			tuple<int, int, int, int>tup = Q.front(); Q.pop();
			bool Q1, Q2;
			int ay = get<0>(tup);
			int ax = get<1>(tup);
			int by = get<2>(tup);
			int bx = get<3>(tup);
			for (int i = 0; i < 4; i++) {
				int ey = ay + dy1[i], ex = ax + dx1[i];
				int fy = by + dy2[i], fx = bx + dx2[i];
				if (map1[ey][ex] == 1) {
					ey = ay; ex = ax;
				}
				if (map2[fy][fx] == 1) {
					fy = by; fx = bx;
				}
				if (ey == Lgy && ex == Lgx) {
					Q1 = true;
				}
				else {
					Q1 = false;
				}
				if (fy == Rgy && fx == Rgx) {
					Q2 = true;
				}
				else {
					Q2 = false;
				}
				if (Q1 == true && Q2 == false) {
					goto G;
				}
				if (Q1 == false && Q2 == true) {
					goto G;
				}
				if (dist[ey][ex][fy][fx] == INF) {
					dist[ey][ex][fy][fx] = dist[ay][ax][by][bx] + 1;
					Q.push(make_tuple(ey, ex, fy, fx));
				}
			G:;
			}
		}

		//hantei.
		if (dist[Lgy][Lgx][Rgy][Rgx] == INF) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 65408
b=int(input())
a=input()
s=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
aa=[]
i=0
for x in a:
    for y in s:
        if y==x:
            aa.append(s[i+b])
            break
        i+=1
    i=0
print(''.join(aa))

Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int n, i, kazu;

	scanf("%d", &n);

	int abc[100];

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

	for (i = n - 1; i > 0; i--)
	{
		printf("%d ", abc[i]);
	}

	printf("%d\n", abc[0]);

	return 0;
}



Measured memory_bytes: 2120
#include<bits/stdc++.h>
#define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++)
#define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--)
#define two(a) (1ull<<(a))
#define Upd(Arr,pos) (Arr[X[pos]]^=two(Y[pos]))

using namespace std;
typedef unsigned long long ull;
const int N=2005,T=64,M=N/T+2;
int lca[N][N],tp[N][N],X[N],Y[N],q[N*N][2],hd[N],go[N*2],nx[N*2],fa[N],dep[N],h[101];
ull B[N][M],S[N][M],D[M],cl;
bool bz[N][N];
int n,m,inx,tl,top;

void add(int u,int v){
	go[++tl]=v, nx[tl]=hd[u], hd[u]=tl;
}
void pr(ull a[]){
	fo(i,0,top) printf("%llu ",a[i]);puts("");
}
void dfs(int x){
	dep[x]=dep[fa[x]]+1;
	memcpy(S[x],S[fa[x]],sizeof(S[fa[x]]));
	S[x][X[x]]|=two(Y[x]);

	for(int i=hd[x]; i; i=nx[i]) 
		if(go[i]!=fa[x])
			fa[go[i]]=x, dfs(go[i]);
}
void get(int x,int fr,int la,int g,int t){
	if(g) lca[fr][x]=g, tp[fr][x]=t; else lca[fr][x]=x, tp[fr][x]=la;
	for(int i=hd[x]; i; i=nx[i]) if(go[i]!=la){
		if(dep[go[i]]>dep[x] && !g) get(go[i],fr,x,x,la);
		else get(go[i],fr,x,g,t);
	}
}
int main(){
	register int u,v,l=0,r=0,id; register ull d,low;
	scanf("%d %d",&n,&m); 
	fo(i,1,n-1) scanf("%d %d",&u,&v), add(u,v), add(v,u);

	fo(i,1,n) X[i]=(i-1)/T, Y[i]=(i-1)%T;
	top=X[n];
	cl=0;fo(i,n-Y[n],n) cl|=two(i-n+Y[n]);
//	printf("cl : %llu\n",cl);
	d=1;fo(i,0,T-1) h[d%101]=i, d=d<<1;

	fa[1]=1, dfs(1);
	fo(i,1,n) {
		get(i,i,0,0,0);
		fo(j,1,n) if(lca[i][j]==i) S[i][X[j]]|=two(Y[j]);
//		printf("%d : ",i);pr(S[i]);
		Upd(B[i],i);
	}
//	fo(i,1,n) {fo(j,1,n) printf("%d(%d) ",lca[i][j],tp[i][j]);puts("");}

	fo(i,1,m) {
		scanf("%d %d",&u,&v);
		Upd(B[u],v), Upd(B[v],u);
		++r, q[r][0]=u, q[r][1]=v;
	}

	while(l<r) {
		++l; u=q[l][0], v=q[l][1];
//		printf("%d %d\n",u,v);
		if(dep[u]>dep[v]) u^=v, v^=u, u^=v;
		
		if(lca[u][v]==u) 
			fo(i,0,top) D[i]=(~S[tp[v][u]][i])|S[v][i];
		else {
			fo(i,0,top) D[i]=S[u][i]^S[v][i];
			Upd(D,lca[u][v]);
		}D[top]&=cl;
//		printf("add %d %d D:",u,v);pr(D);
//		printf("Bu : ");pr(B[u]);
//		printf("Bv : ");pr(B[v]);
		
		fo(i,0,top){
			for(d=D[i]&B[u][i]&(~B[v][i]), low=d&(-d); d; d-=low, low=d&(-d)) {
				id=T*i+h[low%101]+1;
//				printf("got %d -- %d ;",id,v);
				Upd(B[v],id), Upd(B[id],v);
				++r, q[r][0]=v, q[r][1]=id;
			}

			for(d=D[i]&B[v][i]&(~B[u][i]), low=d&(-d); d; d-=low, low=d&(-d)) {
				id=T*i+h[low%101]+1;
//				printf("got %d -- %d ;",id,u);
				Upd(B[u],id), Upd(B[id],u);
				++r, q[r][0]=u, q[r][1]=id;
			}
		}//puts("");
	}
	printf("%d\n",r);
	return 0;
}



Measured memory_bytes: 52048
N = gets.to_i
XY = $<.map{|s|
  s.split.map &:to_i
}
XY.sort!

if N < 2
  p 1
  exit
end

h = Hash.new 0
N.times{|i|
  (i+1...N).each{|j|
    x = XY[j][0] - XY[i][0]
    y = XY[j][1] - XY[i][1]
    h[[x,y]] += 1
  }
}
max = h.max_by{|k, v| v }.last
p N - max

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

#define int long long

int G[2][100];

int dx[]{0, 1};
int dy[]{1, 0};

signed main() {
    int n;
    cin >> n;
    for(int i=0; i<2; ++i) {
        for(int j=0; j<n; ++j) cin >> G[i][j];
    }

    queue<pair<int, pair<int,int>>> que;
    que.push(make_pair(G[0][0], make_pair(0, 0)));
    int ans = -1;
    while(!que.empty()) {
        auto p = que.front(); que.pop();
        int ame = p.first;
        int x = p.second.first;
        int y = p.second.second;
        if(y==n-1&&x==1) {
            ans = max(ame, ans);
            continue;
        }
        for(int i=0; i<2; ++i) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx<2&&ny<n)
                que.push(make_pair(ame+G[nx][ny], make_pair(nx, ny)));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int N, i;
  scanf("%d %d", &N, &i);

  int ans = N + 1 - i;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
package main

import "fmt"

func main() {
	a := make([]int, 3)
	for i := range a {
		fmt.Scan(&a[i])
	}

	cnt := make(map[int]int)

	for _, v := range a {
		cnt[v] += 1
	}

	if cnt[5] == 2 && cnt[7] == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
N,M = list(map(int,input().split()))

ref = [i+1 for i in range(M)]
LIKE = [i+1 for i in range(M)]

for i in range(N):
    myLIKE = list(map(int,input().split()[1:]))
    for j in ref:
        try:
            if j not in myLIKE:
                LIKE.remove(j)
        except ValueError:
            pass
            
print(len(LIKE))

Measured memory_bytes: 3060
def main():
    import numpy as np
    from bisect import bisect_left, bisect_right

    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()

    n = bisect_left(A, 0)
    p = bisect_right(A, 0)

    Negative = np.array(A[:n], dtype = np.int64)
    Positive = np.array(A[p:], dtype = np.int64)

    Number_Negative = len(Negative) * len(Positive)
    Number_Positive = len(Negative) * (len(Negative) - 1) // 2 + len(Positive) * (len(Positive) - 1) // 2
    Number_Zero = N * (N - 1) // 2 - Number_Negative - Number_Positive

    # print (Number_Negative)
    # print (Negative)
    # print (Number_Positive)
    # print (Positive)
    # print (Number_Zero)

    def Ncount(x): #x以下の数を数える(x < 0)
        tmp = 0
        for a in Negative:
            tmp += len(Positive) - bisect_left(Positive, (x + a + 1) // a)
        # print (x, tmp)
        return tmp

    def Ncount1(x):
        tmp = (len(Positive) - np.searchsorted(Positive, (-x - 1) // (-Negative), side = 'right')).sum() 
        return tmp 

    def Pcount(x): #x以下の数を数える(x > 0)
        tmp = 0
        for index, a in enumerate(Positive):
            tmp += bisect_right(Positive[index + 1:], x // a)
        for index, b in enumerate(Negative):
            tmp += len(Negative[index + 1:]) - bisect_left(Negative[index + 1:], (x + b + 1) // b)
            # print (bisect_right(Negative[index + 1:], x / b))
        # print (x, tmp)
        return tmp

    def Pcount1(x):
        tmp = 0
        tmp += np.searchsorted(Positive, x // Positive, side = 'right').sum()
        tmp += (len(Negative) - np.searchsorted(Negative, (-x - 1) // (-Negative), side = 'rigth')).sum()
        tmp -= np.count_nonzero(Positive * Positive <= x)
        tmp -= np.count_nonzero(Negative * Negative <= x)
        return tmp // 2

    if Number_Negative >= K:
        # ここに二分探索を書く
        l = -10 ** 18
        r = 0
        while r - l > 1:
            mid = (l + r) // 2
            if K <= Ncount1(mid):
                r = mid
            else:
                l = mid
        print (r)
        exit()
            

    elif Number_Negative < K <= Number_Negative + Number_Zero:
        print (0)
        exit()

    else:
        # ここに二分探索を書く
        l = 0
        r = 10 ** 18
        K -= (Number_Negative + Number_Zero)
        while r - l > 1:
            mid = (l + r) // 2
            if K <= Pcount1(mid):
                r = mid
            else:
                l = mid

        print (r)
        # exit()

    # print (Pcount(l) + Number_Negative + Number_Zero)
    # print (Pcount(r) + Number_Negative + Number_Zero)

if __name__ == '__main__':
    main()

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

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 8;

int N, M;
int a[MAX_N * MAX_N], b[MAX_N * MAX_N];

typedef pair< int, vector< bool > > PIV;

vector< int > e[MAX_N];

int solve()
{
  int res = 0;
  
  vector< bool > state(N, false);
  queue< PIV > q;
  q.push(make_pair(0, state));

  while(!q.empty()) {
    PIV from = q.front(); q.pop();
    from.second[from.first] = true;

    bool ok = true;
    EACH(i, from.second) {
      if (!i) ok = false;
    }
    if (ok) res++;
    
    EACH(ni, e[from.first]) {
      if (from.second[ni]) continue;
      q.push(make_pair(ni, from.second));
    }
  }

  return res;
}

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

  cin >> N >> M;
  REP(i, M) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    e[a[i]].emplace_back(b[i]);
    e[b[i]].emplace_back(a[i]);
  }

  int ans = solve();

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 640
from sys import stdin
data = stdin.read().splitlines()

n = int(data[0].split()[0])
y = int(data[0].split()[1])

ans_a = -1
ans_b = -1
ans_c = -1

a = y // 10000

while a >= 0:
    y -= 10000*a
    b = y // 5000
    while b >= 0:
        y -= 5000*b
        c = y // 1000
        if n == a + b + c:
            ans_a = a
            ans_b = b
            ans_c = c
        y = y + 5000*b
        b -= 1
    y = y + 10000*a
    a -= 1
print("{} {} {}".format(ans_a, ans_b, ans_c))

Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b>> c>> d;
  if((a+b)>(c+d)){
    cout << "Left" <<endl;
  }else if((a+b)<(c+d)){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" <<endl;
  }
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  double N,K;
  cin >> N >> K;
  double ans=0.0;
  for(double i=N;i>0;i--){
    double num=i;
    double cnt=0; 
    if(num>K){
      ans+=1/N;
      continue;
    }
    else{
      while(num<K){
        num*=2;
        cnt++;
      }
      ans+=(1/N)*pow(0.5,cnt);
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
        

}
     

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

int main() {
  int a;
  string b;
  string c = "";
  
  cin >> a;
  cin >> b;
  
  if (a >= b.size()) {
    cout << b;
    return 0;
  }
  
  for (int i = 0; i < a; i++) {
    c = c + b[i];
  }
  
  cout << c;
  cout << "...";
    
  return 0;   
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1000000000
typedef long long ll;

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

	int n;
	cin >> n;
	cout << n / 3 << endl;
	
	return 0;
}

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

const int N = 2e5+7;
typedef long long LL;

int n,sum;
string s;

int quick(int a,int b,int mod)
{
	LL ans=1;
	while(b){
		if(b&1) ans = ans*a%mod;
		a = (LL)a*a%mod;
		b>>=1;
	}
	return ans;
}

int fun(int n){
	int ans=0;
	while(n){
		ans++;
		n  = n &(n-1);
	} return ans;
}

int main()
{
	cin>>n>>s;
	for(auto c :s) if(c=='1') sum++;
	int cnt1 = 0 ,cnt2 = 0, p1 = sum + 1 , p2 = sum - 1;
	
	for(int i=0;i<n;i++)
		if(s[i]=='1'){
			cnt1 = (cnt1 + quick(2,n-i-1,p1))%p1;
			if(p2>0) cnt2 = (cnt2 + quick(2,n-i-1,p2))%p2;
		}
	int t,ans=0;
	for(int i=0;i<n;i++){
		ans=1;
		if(s[i]=='0')  t = (cnt1+quick(2,n-i-1,p1)+p1)%p1;
		else if(p2<=0) {cout<<0<<"\n"; continue;}
		else t = (cnt2-quick(2,n-i-1,p2)+p2)%p2;
		if(!t) cout<<ans<<"\n";
		else {
			while(t) ans++,t = t%fun(t);
			cout<<ans<<endl;
		}
	}
	return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int solve(string bit,string tar){
	int n=tar.size();
	int ans=0;
	for(int i=0;i<n;++i){
		if(bit[i]==tar[i])
			continue;
		for(int j=i+1;j<n;++j){
			if(bit[j]==tar[i]){
				for(int k=j;k>i;--k)
					ans++,swap(bit[k],bit[k-1]);
				break;
			}
		}
	}
	if(tar!=bit)
		return inf;
	else
		return ans;
}

int rsolve(string bit,string tar){
	int n=tar.size();
	int ans=0;
	for(int i=n-1;i>=0;--i){
		if(bit[i]==tar[i])
			continue;
		for(int j=i-1;j>=0;--j){
			if(bit[j]==tar[i]){
				for(int k=j;k<i;++k)
					ans++,swap(bit[k],bit[k+1]);
				break;
			}
		}
	}
	if(tar!=bit)
		return inf;
	else
		return ans;
}

int main(void){
	int n,m;
	cin >> n >> m;
	string bit="";

	rep(i,n){
		int in;
		cin >> in;
		bit+=(in+'0');
	}

	string one="",zero="";
	rep(i,m){
		int in;
		cin >> in;
		if(i&1){
			rep(j,in) one+="0";
			rep(j,in) zero+="1";
		}else{
			rep(j,in) one+="1";
			rep(j,in) zero+="0";
		}
	}

	int ans=min(solve(bit,zero),solve(bit,zero));
	int rans=min(rsolve(bit,zero),rsolve(bit,one));
	reverse(all(bit));
	reverse(all(zero));
	reverse(all(one));

	ans=min(ans,min(solve(bit,zero),solve(bit,zero)));
	rans=min(rans,min(rsolve(bit,zero),rsolve(bit,one)));
	

	cout << min(ans,rans) << endl;

	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
main(){
	int a,b;
	int d1,mo;
	double d2;

	scanf("%d %d",&a,&b);
	d1 = a / b;
	mo = a % b;
	d2 = (double)a / (double)b;

	printf("%d %d %f\n",d1,mo,d2);
	return 0;
}

Measured memory_bytes: 1064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N;
int dp[100001][3];
vector<tuple<int, int, int>> abc;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  abc.resize(N);
  for (int i = 0; i < N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    abc[i] = make_tuple(a, b, c);
  }

  for (int i = 0; i < N; i++) {
    dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + get<1>(abc[i]));
    dp[i + 1][2] = max(dp[i + 1][2], dp[i][0] + get<2>(abc[i]));

    dp[i + 1][2] = max(dp[i + 1][2], dp[i][1] + get<2>(abc[i]));
    dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] + get<0>(abc[i]));

    dp[i + 1][0] = max(dp[i + 1][0], dp[i][2] + get<0>(abc[i]));
    dp[i + 1][1] = max(dp[i + 1][1], dp[i][2] + get<1>(abc[i]));
  }

  int ans = max(dp[N][0], dp[N][1]);
  cout << max(ans, dp[N][2]) << endl;
  return 0;
}

Measured memory_bytes: 2560
n = gets.chomp.to_i

s = []

count = 0
hits = {}

n.times do
  now = gets.chomp.chars.sort.join
  if hits.key?(now)
    count += (hits[now] + 1)
    hits[now] += 1
  else
    hits[now] = 0
  end
end

puts count


Measured memory_bytes: 17020
#include<stdio.h>
#include<string.h>
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
string s;
int max(int a, int b)
{
    return (a>b)?a:b;
}
void lcs(char s1[],char s2[],int n,int m)
{
    int t[n+1][m+1],i,j;
    for(i=0;i<=n;i++)
    {    
        for(j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                t[i][j]=0;
            }
            else
            {
                if(s1[i-1]==s2[j-1])
                {
                    t[i][j]=1+t[i-1][j-1];
                } 
                else  
                {
                    t[i][j]=max(t[i-1][j],t[i][j-1]);
                }
            }
        }
    }
    i=n;
    j=m;
    while(i>0 && j>0)
    {
        if(s1[i-1]==s2[j-1])
        {
            s.push_back(s1[i-1]);
            i--;
            j--;
        }
        else
        {
            if(t[i-1][j]>t[i][j-1])
            {
                i--;
            }
            else
            {
                j--;
            }
        }
    }
    reverse(s.begin(),s.end());
    cout<<s;
}
int main()
{
    char s1[3001],s2[3001];
    scanf("%s",s1);
    scanf("%s",s2);
    lcs(s1,s2,strlen(s1),strlen(s2));
    return 0;
}

Measured memory_bytes: 35456
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

main(){
  int n,k;
  while(cin>>n>>k && n){
    if (true || n%2 == 1){
      rep(i,k){
	int y,x;
	cin>>y>>x;y--;x--;
	int ans=min(n-1-y,min(n-1-x,min(y,x)));
	cout << (ans+3)%3+1 << endl;
      }
    }
    
  }
  return false;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	if (n == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (n == 2) {
		cout << 1 << endl;
		return 0;
	}
	ll ans = n * (n - 1) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

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

	int N; cin >> N;
	vector<ll> A(N+1,0LL);
	for (int i = 1; i <= N; ++i){
		cin >> A[i];
	} // for

	vector<ll> csum(N+1,0LL);
	for (int i = 1; i <= N; ++i){
		csum[i] = csum[i-1] + A[i];
	} // end for

	map<ll,int> cnt; cnt.clear();
	for (int i = 0; i <= N; ++i){
		++cnt[csum[i]];
	} // endf or
	
	ll res = 0LL;
	map<ll,int>::iterator it = cnt.begin();
	for (; it != cnt.end(); ++it){
		int curr = (*it).second;
		res += (ll)curr * ((ll)curr - 1LL) / 2LL;
	} // end for

	cout << res << endl;
 	
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using ll=long long;
int main() {
    ll A,B; cin>>A>>B;
    if(A>B)swap(A,B);
    int div=2;
    int ans=1;
    int prev=1;
    int upper=floor(sqrt(A));
    while(div<=upper){
        if(A%div==0){
            A/=div;
            if(B%div==0 && div!=prev)ans++;
            prev=div;
        }else{
            div++;
        }
    }
    if(A>1 && B%A==0)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3504
#include<iostream>
using namespace std;
int n,h[100000],maxn=-1;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++)cin>>h[i];
	for(int i=0;i<n;i++){
		maxn=max(maxn,h[i]);
		if(maxn-h[i]>=2){cout<<"No";return 0;}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,x[233],y[233];
double p[233];
const double pi=acos(-1.);
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>x[i]>>y[i];
	for(int i=1;i<=n;i++)
	{
		int c=0;
		for(int j=1;j<=n;j++)
			if(i!=j)p[c++]=atan2(y[j]-y[i],x[j]-x[i]);
		sort(p,p+c);
		for(int j=0;j<c;j++)p[j+c]=p[j]+2*pi;
		double ans=0;
		for(int j=0;j<c;j++)ans=max(ans,pi-p[j+c-1]+p[j]);
		printf("%.18f\n",ans/2./pi);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define MAX 1000000
using namespace std;

int main(){
   int tetra[181];
   int dp[MAX+1],dpodd[MAX+1];
   for(int i=0;i<MAX+1;i++) {dp[i]=i; dpodd[i]=i;}
   for(int i=1;i<181;i++){
      tetra[i-1] = i * (i+1) * (i+2) / 6;
   }
   for(int i=0;i<180;i++){
      int p = tetra[i];
      for(int j=0;p+j <= MAX;j++){
         if(dp[p+j] > dp[j]) dp[p+j] = dp[j] + 1;
         if(p%2 == 1){
            if(dpodd[p+j] > dpodd[j]) dpodd[p+j] = dpodd[j] + 1;
         }
      }
   }
   while(1){
      int n;
      cin >> n;
      if(n==0) break;
      cout << dp[n] << " " << dpodd[n] << endl;
   }
}

Measured memory_bytes: 8972
#include<stdio.h>
#define MAX1 2000000
#define MAX2 10000

int main(){
  int N,A[MAX1],B[MAX1],C[MAX2];
  int i;
  
  scanf("%d",&N); 
  for(i=0;i<N;i++) scanf("%d",&A[i]);  
  for(i=0;i<MAX2;i++) C[i]=0;
  for(i=0;i<N;i++) C[A[i]]++;
  for(i=1;i<MAX2;i++) C[i]=C[i]+C[i-1];
  for(i=N-1;i>=0;i--){
      B[C[A[i]]-1]=A[i];
      C[A[i]]--;  
  }

  for(i=0;i<N;i++){
    printf("%d",B[i]);
    if(i!=N-1) printf(" ");
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 17448