akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var dic = new Dictionary<string, int>();

            var result = 0L;
            for (int i = 0; i < N; i++)
            {
                var s = Console.ReadLine();

                var array = s.ToCharArray();
                Array.Sort(array);
                s = new string(array);

                if (dic.ContainsKey(s))
                {
                    dic[s]++;
                }
                else
                {
                    dic[s] = 0;
                }

                result += dic[s];
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27220
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define UN unsigned int
#define mod 1000000007
#define F first
#define S second
#define mk make_pair
#define B(v) v.begin(), v.end()
#define BS binary_search

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max((a+b),max((a-b),(a*b)))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int MAXN = 1e5+5;
const int INF = 0x3f3f3f3f;
ll v[MAXN],w[MAXN];
ll dp[MAXN];
int main(){
	int N,M;
	memset(dp,INF,sizeof(dp));
	dp[0]=0;
	ll maxx=0;
	cin>>N>>M;
	for(int i=0;i<N;++i){
		cin>>v[i]>>w[i];
	}
	for(int i=0;i<N;++i){
		for(int j=1e5;j>=w[i];--j){
			dp[j]=min(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	for(int i=1e5;i>=0;--i){
		if(dp[i]<=M){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1656
#include<stdio.h>
int main(void){
	int n,a,i,j,s;
	char c;
	int cards[4][13] = {0};
	
	scanf("%d",&n);
	for(a = 0;a < 2*n;a++){
		scanf("%c %d",&c,&s);
		if(c == 'S'){
			cards[0][s-1] = 1;
		}else if(c == 'H'){
			cards[1][s-1] = 1;
		}else if(c == 'C'){
			cards[2][s-1] = 1;
		}else if(c == 'D'){
			cards[3][s-1] = 1;
		}
	}
	
	for(i = 0;i < 4;i++){
		for(j = 0;j < 13;j++){
			if(cards[i][j] == 0){
				if(i == 0) printf("%c %d\n",'S',j+1);
				else if(i == 1) printf("%c %d\n",'H',j+1);
				else if(i == 2) printf("%c %d\n",'C',j+1);
				else if(i == 3) printf("%c %d\n",'D',j+1);
			}
		}
	}
	return 0;
}

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



int main() {
    
    vector<int> s(14,0);
    vector<int> h(14,0);
    vector<int> c(14,0);
    vector<int> d(14,0);
    int n,card;
    char ch;
    cin>>n;
    rep(i, n){
        cin>>ch>>card;
        if(ch=='S') s[card]=1;
        if(ch=='H') h[card]=1;
        if(ch=='C') c[card]=1;
        if(ch=='D') d[card]=1;
        
    }
    for(int i=1; i<14; i++){
        if(s[i]==0) cout<<'S'<<" "<<i<<endl;
    }
    for(int i=1; i<14; i++){
        if(h[i]==0) cout<<'H'<<" "<<i<<endl;
    }
    for(int i=1; i<14; i++){
        if(c[i]==0) cout<<'C'<<" "<<i<<endl;
    }
    for(int i=1; i<14; i++){
        if(d[i]==0) cout<<'D'<<" "<<i<<endl;
    }
  
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        System.out.println(s.substring(0, 5) + " " + s.substring(6, 13) + " " + s.substring(14, 19));

    }

}


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

vector<pair<ll, ll>> prime_factorize(ll N) {
  vector<pair<ll, ll>> res;
  for (ll a = 2; a * a <= N; a++) {
    if (N % a != 0) continue;
    ll ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  auto vec = prime_factorize(N);
  int ans = 0;
  for (auto p : vec) {
    int n = 0;
    int sum = 1;  // sum = 1 + 2 + ...
    while (sum <= p.second) {
      n++;
      sum += n + 1;
    }
    ans += n;
  }
  cout << ans << endl;
}


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

int n;
int a[1000001];
int ans;
int s;

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		int t;
		scanf("%d", &t);
		a[t]++;
		ans++;
		if(a[t] > 2){
			a[t] -= 2;
			ans -= 2;
		}
	}

	for(int i=1; i<100001; i++)
		if(a[i] == 2) s++;

	ans -= (s / 2) * 2;
	s %= 2;

	if(s == 1) ans -= 2;

	printf("%d\n", ans);
}

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

typedef long long int ll;
ll n,W, w[109], val[109];
ll dp[100009][109];
ll solve(ll v,int index)
{
    if(index==n)
    {
        return (v==0?0:INT_MAX);
    }
    if(dp[v][index]!=-1)
    return dp[v][index];
    ll ans =solve(v,index+1);
    if(v>=val[index])
    ans=min(w[index]+solve(v-val[index],index+1),ans);
    
    return dp[v][index]=ans;
    
}
ll func(ll n)
{
    for(ll i=n;i>=1;i--)
    {
        
        if(solve(i,0)<=W)
        return i;
    }
    return 0;
}

int main() {
	
	cin>>n>>W;
	ll v_max=0;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++)
	{
	    cin>>w[i];
	    cin>>val[i];
	    v_max+=val[i];
	}
	
	
	cout<<func(v_max)<<"\n";
	return 0;
}

Measured memory_bytes: 88744
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

//prototype declaration
int getint();
long long getllint();
double getdint();
char getch();
void setstring(char *s);
void showint(int i);
void showllint(long long i);
void showdint(double i);
void showchar(char c);
void showstring(char *s);

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int mod_2(long long int a) {
	if (a > 0) {
		if (a % 2 == 0) {
			return 0;
		} else {
			return 1;
		}
	} else {
		if ( ((-1) * a) % 2 == 0) {
			return 0;
		} else {
			return 1;
		}
	}
}

int main(void) {
	long long int n;
	n = getllint();
	int i, j;
	int s[1000000];
	for (i = 0; n != 0; i++) {
		s[i] = mod_2(n);
		n = (n - s[i]) / (-2);
	}
	if (i == 0) {
		printf("0\n");
		return 0;
	}
	for (j = i - 1; j >= 0; j--) {
		printf("%d", s[j]);
	}
	return 0;
}

int getint() {
	int i;
	scanf("%d", &i);
	return i;
}

long long getllint() {
	long long i;
	scanf("%lld", &i);
	return i;
}

double getdint() {
	double i;
	scanf("%lf", &i);
	return i;
}

char getch() {
	char c;
	scanf("%c", &c);
	return c;
}

void setstring(char *s) {
	scanf("%s", s);
}

void showint(int i) {
	printf("%d\n", i);
}

void showllint(long long i) {
	printf("%lld\n", i);
}

void showdint(double i) {
	printf("%lf\n", i);
}

void showchar(char c) {
	printf("%c\n", c);
}

void showstring(char *s) {
	printf("%s\n", s);
}


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

#define 	pi				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(int i = a ; i < b ; i++)
#define     repn(i, a, b)   for(int i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define     vll             vector<long long int>
#define     pii             pair<int, int>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	io   			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)
// __gcd(a, b);

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

void solve()
{
    ll n, m, sum = 0; cin>>n>>m;
    vll a(m); 
    rep(i, 0, m){
        cin>>a[i]; sum += a[i];
    }
    if(n-sum>=0)
    cout<<n-sum<<nl;
    else cout<<-1<<nl;
}

int main()
{
    //io;
    int t = 1, k = 1;
    // cin>>t; 
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define ll long long
#define mod1 1000000007LL
#define mod2 1000000009LL
#define base1 19
#define base2 31
#define base3 137
#define MAX 1e12
#define MIN -10000000000
#define pi acos(-1)
#define esp 1e-6
#define memz(x) memset(x, 0, sizeof x)
#define memn(x) memset(x, -1, sizeof x)
#define pb push_back
#define nai string::npos
#define in1(a) scanf("%lld", &a)
#define in2(a,b) scanf("%lld%lld", &a, &b)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(i) printf("Case #%lld: ", ++i)
#define FILE    freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout);
using namespace std;
const ll N = 100010;
string s;
ll mem[N][15], n, p[N];
ll dp(ll pos, ll mod)
{
    ll &ret = mem[pos][mod];
    if(ret!=-1)
        return ret;
    if(pos>=n)
    {
        if(mod%13!=5)
        {
            return ret=0;
        }
        return ret=1;
    }
    ret=0;
    if(s[pos]=='?')
    {
    for(int i=0;i<=9;i++)
        {
            ll x = (mod+(i*p[n-pos-1])%13)%13;
            ret=(ret+dp(pos+1, x))%mod1;
        }
    }
    else
    {
        ll x = (mod+((s[pos]-'0')*p[n-pos-1])%13)%13;
        ret=(ret+dp(pos+1, x))%mod1;
    }
    return ret;
}
int main()
{
    FAST
    cin>>s;
    n=s.length();
    p[0]=1;
    for(int i=1;i<=n;i++)
    {
        p[i]=(p[i-1]*10)%13;
    }
    memn(mem);
    cout<<dp(0, 0)<<"\n";
    return 0;
}


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

using namespace std;

#define LL long long

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int h[n];
	for(int i=0; i<n; i++) {
		cin>>h[i];
	}
	int dp[n];
	dp[0] = 0;
	for(int i=1; i<n; i++) {
		if(i==1) {
			dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
		}
		else {
			dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
		}
	}
	cout<<dp[n-1];
}


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

int main() {
  int N, ans = 0;
  cin >> N;
  vector<int> len(2 * N);
  for (int i = 0; i < 2 * N; i++) cin >> len.at(i);
  sort(len.begin(), len.end());
  for (int i = 0; i < 2 * N; i += 2) ans += len.at(i);
  cout << ans << endl;
}


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

int main()
{
	int n, k; cin >> n >> k;
	vector<double> v(n);
	vector<double> expected(n);
	for(int i = 0; i < n; ++i) 
	{
		cin >> v[i];
		expected[i] = ((v[i]*(v[i]+1.0))/2.0)/v[i];
		
		if(i)
			expected[i] += expected[i-1];
		
	}
	double maxi = expected[k-1];
	double tolerance = 0.0000001;
	for(int i = k-1; i < n; ++i)
	{
		int pre = i - k;
		if(pre >= 0)
		{
			double cur = expected[i] - expected[pre];
			if(cur-maxi > tolerance)
				maxi = cur;
		}
	}

	cout << setprecision(17) <<  maxi;

	return 0;
	
}

Measured memory_bytes: 6400
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include<iomanip>

using namespace std;

int main() {
    int N;
    double *v, sum = 0;

    // input
    cin >> N;

    v = new double[N];

    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }

    // process
    sort(v, v + N);

    for (int i = 0; i < N - 1; i++) {
        v[i + 1] = (v[i] + v[i + 1]) / 2;
//        cout << v[i] << " " << v[i + 1] << endl;
    }

    cout << v[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, cnt = 0, ans = 0, v = 0;
  scanf("%lld%lld", &n, &k);
  char s[n + 10];
  vector<ll> vec;
  scanf("%s", s);
  vec.push_back(0);
  if(s[0] == '0') cnt++;
  for(i = 1; i < n; ++i) {
    if(s[i] == '0') {
      if(s[i - 1] == '1') {
        if(ans < i  - vec[v]) ans = i - vec[v];
        cnt++;
        if(cnt > k) v++;
      }
    } else {
      if(s[i - 1] == '0') vec.push_back(i);
    }
  }
  if(ans < n - vec[v]) ans = n - vec[v];
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1020
N,M = map(int,input().split())
city = [0]*N
road = [0]*M
for i in range(M):
  road[i] = list(map(int,input().split()))
for i in range(M):
  city[road[i][0]-1] += 1
  city[road[i][1]-1] += 1
for j in range(N):
  print(city[j])
  

Measured memory_bytes: 3060
d = int(input())
cl = list(map(int, input().split()))
sl = []
for _ in range(d):
    sl.append(list(map(int, input().split())))

tl = []
# for _ in range(d):
#     tl.append(int(input()))

last_di = [-1]*26
ans = 0
for day in range(d):
    best_t = 0
    best_t_val = -999999999999
    for t in range(26):
        curr_val = sl[day][t]*2
        for i in range(26):
            if i == t: continue
            curr_val -= (day-last_di[i])*cl[i]*3
        if curr_val >= best_t_val:
            best_t = t
            best_t_val = curr_val
    tl.append(best_t+1)
    last_di[best_t] = day
    ans += best_t_val
    # print(ans)
    # print('-- {}---'.format(day))
    # print(best_t)
    # print(last_di)

for t in tl:
    print(t)

# for day, t in enumerate(tl):
#     ans += sl[day][t-1]
#     last_di[t-1] = day
#     for ld, c in zip(last_di, cl):
#         # if ld == -1: continue
#         ans -= (day-ld)*c
#     print(ans)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    ll a,b;
    cin >> a >> b;
    ll ans=0;
    if (a==b){
        cout << a << endl;
        return 0;
    }
    for (ll i=a;i%2;i++){
        ans^=i;
        a++;
    }
    ll c=b-a+1;
    if (c%2){
        ans^=b;
        c--;
    }
    if (c%4==2){
        ans^=1;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   IOS;
   ll n;
   ll a,b;
   cin >> n >> a >> b;
   if(a==0&&b==0){
       cout<<0;
       return 0;
   }
   ll k=n%(a+b);
   k=min(k,a);
   ll p=n/(a+b);
   cout<<k+p*a;
}


Measured memory_bytes: 256
s = input()

v = 'hi'

flg = True

while True:
  if len(s) <= 1:
    if len(s) == 1:
      flg = False
    break
  if s[:2] != v:
    flg = False
    break
  else:
    s = s[2:]

if flg:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

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

int gcd(int a,int b);

int main(void)
{
  int n;
  scanf("%d",&n);
  int i;
  int p[11];
  int max=0;
  int sum =  0;
  REP(i,n)
  {
    scanf("%d",&p[i]);
    if(max<p[i]) max = p[i];
    sum += p[i];
  }
  sum -= max/2.0;

  printf("%d",sum);
  
  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


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

int main() {
  int N, max=0, c=0, k;
  cin >> N;
  vector<int> moti(N);
  
  for(int i=0;i<N;i++){
    cin >> moti.at(i);
    if(max < moti.at(i))
      max = moti.at(i);
  }
  k = max+1;
  
  for(int i=0;i<N;i++){
    max=0;
    for(int j=0;j<N;j++){
      if(max < moti.at(j) && moti.at(j) < k)
        max = moti.at(j);
    }
    k=max;
    if(max > 0)
      c++;
    else
      break;
  }
  cout << c << endl;  
}


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

int main()
{
	string s;
	cin >> s;
	
	int len =(int)s.size();
	int sum = 0;
	REP(i, len){
		sum += s[i] - '0';
	}

	int n = stoi(s);

	cout << (n % sum ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int count(char s[], int len, int border){
    int n = 0;
    int s1[26] = {0};
    int s2[26] = {0};
    for(int i = 0; i < len; i++){
        if(i < border){
            s1[s[i] - 'a'] = 1;
        }
        else 
            s2[s[i] - 'a'] = 1;
    }
    for(int i = 0; i < 26; i++){
        if(s1[i] == s2[i]){
            n += s1[i];
        }
    }
    return n;
}

int main(void){
    int N;
    scanf("%d", &N);
    char s[N + 1];
    scanf("%s", s);
    int max = 0;
    for(int i = 1; i < N; i++){
        int tmp = count(s, N, i);
        max = (tmp > max) ? tmp : max;
    }
    printf("%d\n", max);
    return 0; 
}

Measured memory_bytes: 128
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n,W,sum=0;
		cin>>n>>W;
		vector<ll>v(n),w(n);
		for(int i=0;i<n;i++){
			cin>>w[i]>>v[i];
			sum+=v[i];
		}
		ll dp[n+1][sum+1];
		for(int i=0;i<=n;i++){
			for(int j=0;j<=sum;j++){
				dp[i][j]=INT_MAX;
			}
		}
		ll ans=0;
		dp[0][0]=0;
		for(int i=1;i<=n;i++){
			dp[i][0]=0;
		}
		for(ll i=1;i<=n;i++){
			for(ll j=0;j<=sum;j++){
				dp[i][j]=dp[i-1][j];
				if(v[i-1]<=j){
					dp[i][j]=min(dp[i][j],w[i-1]+dp[i-1][j-v[i-1]]);
				}
				// if(dp[i][j]<=W){
				// 	ans=max(ans,j);
				// }
				// cout<<dp[i][j]<<" ";
			}
			// cout<<endl;
		}
		for(int i=1;i<=sum;i++){
			if(dp[n][i]<=W){
				ans=i;
				// break;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 79232
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1000000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
  int x, y;
  cin >> x >> y;
  x %= 500;
  if(x <= y) cout << "Yes" << endl;
  else cout << "No" << endl;
	return 0;
}


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

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

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, M; cin >> N  >> M;
    int cnt = 0;
    int sum = 0;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    rep(i, N) {
        if (A[i] >= (double) sum / (4 * M)) {
            cnt++;
        }
    }

    if (M > cnt) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
	map<string , int> cpp;
	string str;
	int n, com, q;
	cin >> q;
	while (q--)
	{
		cin >> com >> str;
		switch (com)
		{
		case 0:
			cin >> n;
			cpp[str] = n;
			break;
		case 1:
			cout << cpp[str] << endl;
			break;
		case 2:
			cpp.erase(str);
			break;
		}
	}
	return 0;	
}


Measured memory_bytes: 27816
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
	int n;
int a[ 4 ];
	cin>>n;
  	
a[0]=(n/1000);
a[1]=(n/100)%10;
a[2]=(n/10)%10;
a[3]=(n/1)%10;
  	
  
  	
  
    if(((a[1]!=a[2])&&(a[2]!=a[3]))&&(a[0]!=a[1])){
    	cout<<"Good"<<endl;}
  else{
	cout<<"Bad"<<endl;}
 // cout<<a[1]<<a[2]<<a[3]<<a[4]<<endl;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

// O(n^2)
bool check(const string& s, int x) {
    int n = s.size();

    int cnt;
    rep(diff, x, n - x + 1) {
        cnt = 0;
        rep(i, 0, n - diff) {
            // (i, i + diff)
            if (s[i] == s[i + diff]) {
                ++cnt;
                if (cnt == x) { return true; }
            } else {
                cnt = 0;
            }
        }
    }
    return false;
}

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    int ok = 0, ng = n / 2 + 1;
    while (ok + 1 != ng) {
        int mid = (ok + ng) / 2;
        if (check(s, mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define SORT(x) sort((x).begin(),(x).end())
int main(void){
    
    vector<int> A(3);
    cin >>A[0] >>A[1] >>A[2];
    SORT(A);
    
    cout <<A[2]-A[0] <<endl;
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)n - 1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    vector<ll> x(N), y(N);
    vector<ll> plus(N), minus(N);
    rep(i, N) {
        cin >> x[i] >> y[i];
        plus[i] = x[i] + y[i];
        minus[i] = x[i] - y[i];
    }

    sort(all(plus));
    sort(all(minus));
    cout << max(abs(plus[0] - plus[N - 1]), abs(minus[0] - minus[N - 1]))
         << endl;
}

Measured memory_bytes: 9548
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define pb          push_back
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pi          3.14159265358979323

// yutaka1999

const int N = 1e5+5;
vector<ll>g[N];
bool vis[N];
ll dep[N];
ll deg[N];

void dfs(ll v=1, ll p=-1, ll d=0)
{
       vis[v]=true;
       dep[v]=d;
       for(ll to : g[v])
       {
              if(to!=p)
              {
                     if(!vis[to]) dfs(to,v,d+1);
                     else if(dep[to]<dep[v])
                     {
                            cout<<v<<" "<<to<<endl;
                            deg[v]++;
                     }
              }
       }
       if(p!=-1)
       {
              if(deg[v]&1)
              {
                     cout<<v<<" "<<p<<endl;
                     deg[v]++;
              }
              else
              {
                     cout<<p<<" "<<v<<endl;
                     deg[p]++;
              }
       }
}

void solve()
{
       ll n,m; cin>>n>>m;
       rep(i,0,m)
       {
              ll x,y; cin>>x>>y;
              g[x].push_back(y);
              g[y].push_back(x);
       }
       if(m%2==1) { cout<<-1<<endl; return; }
       dfs();
}

int main(){
	int T = 1;
       //pre();
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 16384
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

int H, W, K;
int dp[101][8];
//---------------------------------------------------------------------------------------------------
int check(int msk) {
	rep(i, 0, W - 2) {
		int a = (msk >> i) & 1;
		int b = (msk >> (i + 1)) & 1;
		if (a and b) return 0;
	}
	return 1;
}
//---------------------------------------------------------------------------------------------------
int main() {
	cin >> H >> W >> K;
	K--;

	dp[0][0] = 1;
	rep(h, 0, H) rep(k, 0, W) rep(msk, 0, 1 << (W - 1)) if (check(msk)) {
		if (msk & (1 << k)) dp[h + 1][k + 1] = (dp[h + 1][k + 1] + dp[h][k]) % MOD;
		else if (0 < k and msk & (1 << (k - 1))) dp[h + 1][k - 1] = (dp[h + 1][k - 1] + dp[h][k]) % MOD;
		else dp[h + 1][k] = (dp[h + 1][k] + dp[h][k]) % MOD;
	}

	cout << dp[H][K] % MOD << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char G[307][307];
int ans[307][307];
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for (int i=0;i<n;i++){
		scanf("%s",G+i);
	}
	int prei=0,cnt=0;
	for (int i=0;i<n;i++){
		bool f=false;
		for (int j=0;j<m;j++){
			if (G[i][j]=='#') f=true;
		}
		if (!f) continue;
		int prej=0;
		for (int j=0;j<m;j++){
			if (G[i][j]=='#'){
				cnt++;
				for (int k=prej;k<=j;k++) ans[i][k]=cnt;
				prej=j+1;
			}
		}
		if (prej!=m) for (int j=prej;j<m;j++) ans[i][j]=cnt;
		for (int j=prei;j<i;j++) memcpy(ans[j],ans[i],sizeof(ans[i]));
		prei=i+1;
	}
	if (prei!=n){
		for (int i=prei;i<n;i++){
			memcpy(ans[i],ans[prei-1],sizeof(ans[i]));
		}
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			if (j==m-1) printf("%d\n",ans[i][j]);
			else printf("%d ",ans[i][j]);
		}
	}
	return 0;
} 

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int d;
	cin>>d;
	if(d==22)
	   cout<<"Christmas Eve Eve Eve"<<endl;
	else if(d==23)
	   cout<<"Christmas Eve Eve"<<endl;
	else if(d==24)
	   cout<<"Christmas Eve"<<endl;
	else
	   cout<<"Christmas"<<endl;
	return 0;
}


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

int main(){
  int l, m, n, tmp;
  cin >> l >> n >> m;

  if (l > n) {
    tmp = l;
    l = n;
    n = tmp;
  }
  if (n > m) {
    tmp = n;
    n = m;
    m = tmp;
  }
  if (l > n) {
    tmp = l;
    l = n;
    n = tmp;
  }
  cout << l << ' ' << n << ' ' << m << endl;
}

Measured memory_bytes: 3076
# ID
n,m=map(int,input().split())
s=[[] for _ in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    s[p-1].append([y,i])

for i in range(len(s)):
    s[i].sort()

ans=[]
for i,ss in enumerate(s):
    for j,sss in enumerate(ss):
        id_no=''
        id_no+='0'*(6-len(str(i+1)))+str(i+1)
        id_no+='0'*(6-len(str(j+1)))+str(j+1)
        s[i][j].append(id_no)

for i,ss in enumerate(s):
    for j,sss in enumerate(ss):
        ans.append(s[i][j])
ans.sort(key=lambda x:x[1])
for aa in ans:
    print(aa[2])



Measured memory_bytes: 45488
from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
inin = lambda: int(input())
inar = lambda: list(map(int,input().split()))
from heapq import heappush as hpush,heappop as hpop

s=input()
t=input()
ans=0
for i,j in zip(s,t):
	if i!=j:
		ans+=1
print(ans)

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

int main(){
	int money = 100000, month;
	cin >>month;
	
	for(int i = 0; i < month; i++){
		money *= 1.05;
		if(money % 1000 != 0) money = (int)floor((double)money / 1000) * 1000 + 1000;
	}
	
	cout <<money<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	cin>>s;
	int o1=0,o0=0,e1=0,e0=0;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			if(s[i]=='0') e0++;
			else if(s[i]=='1') e1++;
		}
		else{
			if(s[i]=='0') o0++;
			else if(s[i]=='1') o1++;
		}
	}
	if(e0+o1>o0+e1) cout<<o0+e1<<endl;
	else cout<<e0+o1<<endl;
} 

Measured memory_bytes: 512
N = int(input())
S1 = input()
S2 = input()
S3 = input()
ans = 0
for i in range(N):
  if S1[i] == S2[i] == S3[i]:
    ans += 0
  elif S1[i] != S2[i] and S2[i] != S3[i] and S3[i] != S1[i]:
    ans += 2
  else:
    ans += 1
print(ans)

Measured memory_bytes: 61900
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        aa: [i64;n]
    }
    let mut aa = aa;
    aa.insert(0,0);
    aa.push(0);
    let mut bb: Vec<i64> = Vec::new();
    for i in 0..n+1 {
        bb.push((aa[i] - aa[i+1]).abs());
    }
    let sum = bb.iter().sum::<i64>();
    for i in 0..bb.len()-1 {
        println!("{}", sum - bb[i] - bb[i+1] + (aa[i] - aa[i+2]).abs());
    }
}


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

typedef long long ll;

using namespace std;

int main() {
	int x;
	cin >> x;
	ll ret = 0;
	for (int i = 1; i <= x; i++) {
		for (int j = 1; j <= x; j++) {
			for (int k = 1; k <= x; k++) {
				ret += gcd(gcd(i, j), k);
			}
		}
	}
	cout << ret << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = a; i >= (b); --i)
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
    IOS;
    ll x;
    cin >> x;
    ll now=100;
    ll ans=0;
    while(now<x){
        now+=now*0.01;
        ++ans;
    }
    cout<<ans;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1LL << 62
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i, m) for (int i = 0; i < m; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  int n, o;
  cin >> n >> o;
  P p[n];
  REP(i, n) cin >> p[i].first >> p[i].second;
  vector<ll> x, y;
  REP(i, n) x.pb(p[i].first);
  REP(i, n) y.pb(p[i].second);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  ll ans = INF;
  REP(i, n){
    FOR(j, i+1, n){
      REP(k, n){
        FOR(l, k+1, n){
          int t = 0;
          REP(m, n){
            if(x[i] <= p[m].first && p[m].first <= x[j] && y[k] <= p[m].second && p[m].second <= y[l]) t++;
          }
          if(t >= o){
            if(ans > ((x[j]-x[i])*(y[l]-y[k]))) ans = (x[j]-x[i])*(y[l]-y[k]);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	double a,b;
	vector<vint> vv;
	initvv(vv,4,2);
	rep(i,4){
		rep(j,2){
			vv[i][j]=0;
		}
	}
	vector<double> v(2);
	while(cin>>v[0]){
		cin>>v[1];
		rep(i,2){
			if(v[i]>=1.1){
				vv[0][i]++;
			}
			else if(v[i]>=0.6){
				vv[1][i]++;
			}
			else if(v[i]>=0.2){
				vv[2][i]++;
			}
			else{
				vv[3][i]++;
			}
		}

	}
	rep(i,4){
		rep(j,2){
			if(j){
				cout<<" ";
			}
			cout<<vv[i][j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

LL n,s;

LL func(LL b){
    LL res=0;
    LL m=n;
    while(m>0){
        res+=m%b;
        m/=b;
    }
    return res;
}

int main(){

    cin>>n>>s;

    LL ans=-1;
    if(s==n)ans=n+1;
    else if(s>n)ans=-1;
    else{
        LL digit=2;
        for(LL i=2;i*i<=n;i++){
            if(func(i)==s){
                ans=i;break;
            }
            digit=i;
        }
        if(ans<0){
            while(digit>1){
                LL left=n/digit;
                LL right=n/(digit-1);
                LL k=n/right;
                LL d=n%right;
                if((s-d)%k==0&&(s-d)/k>0&&(s-d)/k<=(right-left)){
                    ans=right+1-(s-d)/k;
                    break;
                }
                digit--;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

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

    vector<int> left(N);
    vector<int> right(N);

    for (int i = 1; i < N; i++){
        left[i] = left[i -1];
        if (S[i - 1] == 'W')left[i]++;
    }

    for (int i = N - 1; i >= 0; i--){
        right[i] = right[i + 1];
        if (S[i + 1] == 'E')right[i]++;
    }

    int ans = 1001001001;
    rep(i, N){
        int X = left[i] + right[i];
        if (X < ans)ans = X;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
#define rep(i,n) ;for( int i =0; i < n ; i ++)
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int fiv(int n){
  if(n==0){
    return 0;
  }
  else if(n==1){
    return 1;
  }
  return fiv(n-1)+fiv(n-2);
}
int main(){
  int n;
  cin>>n;
  int ans=0;
  vector<int> a(4000)
  rep(i,n){
    cin>>a[i];
    ans+=a[i];
  }
  cout<<ans-n<<endl;
}


Measured memory_bytes: 256
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    string ans = "Yes";
    for (int i = 0; i < S.length(); i++) {
        char c = S[i];

        if (i % 2) {
            if (c == 'R') {
                ans = "No";
                break;
            }
        } else if (c == 'L') {
            ans = "No";
            break;
        }
    }

    cout << ans << endl;
    return 0;
}


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

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

using namespace std;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
vector<T> Dijkstra(const weighted_graph<T>& G,int s){
	const T INF=numeric_limits<T>::max();
	int n=G.size();
	vector<T> d(n,INF); d[s]=0;
	priority_queue<pair<T,int>> Q; Q.emplace(0,s);
	while(!Q.empty()){
		T d0=-Q.top().first;
		int u=Q.top().second; Q.pop();
		if(d0>d[u]) continue;
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v);
		}
	}
	return d;
}

int main(){
	int k; scanf("%d",&k);

	weighted_graph<int> G(k);
	rep(i,k){
		G[i].emplace_back((i+1)%k,1);
		G[i].emplace_back((i*10)%k,0);
	}

	printf("%d\n",Dijkstra(G,1)[0]+1);

	return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INFLL=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

vector<int> graph[100];
bool used[100];

bool dfs(int v,int p,int s){
    if(p!=-1 and v==s) return true;
    if(used[v]) return false;
    used[v]=true;
    for(int u:graph[v]){
        if(u==p) continue;
        if(dfs(u,v,s)) return true;
    }
    return false;
}

void solve(){
    int v,e;
    cin >> v >> e;
    rep(i,0,e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
    }
    
    rep(i,0,v){
        fill_n((bool*)used,100,false);
        if(dfs(i,-1,i)){
            cout << 1 << endl;
            return;
        }
    }
    
    cout << 0 << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

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

#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
using namespace std;

int main(){
  while(1){
    int a;
    cin>>a;
    if(a==0) break;
    lp(i,9){
      int b;
      cin>>b;
      a-=b;
    }
    cout<<a<<endl;
  }
  return 0;
}



Measured memory_bytes: 2988
import java.util.Scanner;

public class Main {


	/**
	 * たてとよこの長方形面積と周の長さを求める
	 * @param args　たて、よこ
	 */
		public static void main(String[] args){
			int tate ,yoko;
			Scanner scan = new Scanner(System.in);
			tate =	scan.nextInt();
			yoko = scan.nextInt();
			System.out.println(tate*yoko +" "+(tate+yoko)*2);
		}
}



Measured memory_bytes: 26028
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())	//昇順
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())	//降順
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll N;
	cin >> N ;

	vec a(N);
	REP(i, N) {
		cin >> a[i];
	}

	ISORT(a);
	ll ans = 0;
	REP(i, N) {
		if (i % 2 == 0) ans += a[i];
		else ans -= a[i];
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
var s,t:String;
    i,x:longint;

begin
  readln(s);
  if s[length(s)]<>'A' then s:=s+'A';
  t:='AKIHABARA';
  x:=1;
  for i:=1 to length(s) do
  begin
    if t[x]=s[i] then inc(x) else
    begin
      if (t[x]='A')and(t[x+1]=s[i]) then inc(x,2) else
      begin
        writeln('NO');
        exit;
      end;
    end;
    if (i=length(s))and(x=length(t)+1) then
    begin
      writeln('YES');
      exit;
    end;
  end;
  writeln('NO');
end.

Measured memory_bytes: 128
#B
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

N = int(input())
b = []
for i in range(N):
    b.append(int(input()))
bingo = False
if A[0] in b:
    if A[1] in b:
        if A[2] in b:
            bingo = True

if B[0] in b:
    if B[1] in b:
        if B[2] in b:
            bingo = True


if C[0] in b:
    if C[1] in b:
        if C[2] in b:
            bingo = True

if A[0] in b:
    if B[1] in b:
        if C[2] in b:
            bingo = True


if A[2] in b:
    if B[1] in b:
        if C[0] in b:
            bingo = True

if A[0] in b:
    if B[0] in b:
        if C[0] in b:
            bingo = True

if A[1] in b:
    if B[1] in b:
        if C[1] in b:
            bingo = True

if A[2] in b:
    if B[2] in b:
        if C[2] in b:
            bingo = True

if bingo == False:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> vec(n + 1, 5000);
	for(int i = 1; i <= n; ++i){
		int a;
		cin>>a;
		vec[i] += a;
	}
	long long sum = 0;
	for(int i = 1; i <= n; ++i){
		sum += abs(vec[i] - vec[i - 1]);
	}
	sum += abs(vec[n] - vec[0]);
	long long total = sum;
	for(int i = 1; i < n; ++i){
		sum -= abs(vec[i] - vec[i - 1]);
		sum -= abs(vec[i + 1] - vec[i]);
		sum += abs(vec[i + 1] - vec[i - 1]);
		cout<<sum<<endl;
		sum = total;
	}
	sum = 0;
	for(int i = 1; i < n; ++i){
		sum += abs(vec[i] - vec[i - 1]);
	}
	sum += abs(vec[n - 1] - vec[0]);
	cout<<sum<<endl;	
	return 0;
}

Measured memory_bytes: 1664