akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <string>

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    map<string, int> c;

    c["SUN"] = 7;
    c["MON"] = 6;
    c["TUE"] = 5;
    c["WED"] = 4;
    c["THU"] = 3;
    c["FRI"] = 2;
    c["SAT"] = 1;
    
    string str;
    cin >> str;
    cout << c[str] << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	vp a;
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++){
		string s(n,'0');
		s[i]=s[j]='1';
		cout<<"? "<<s<<endl;
		int t;
		cin>>t;
		if(t==1) a.push_back({i,j});
	}
	cout<<'!';
	for(int i=0;i<n-1;i++){
		cout<<' '<<'('<<a[i].first<<','<<a[i].second<<')';
	}
	cout<<endl;
}

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

int main() {
  int n = 0;
  cin >> n;
  int m = 0;
  cin >> m;
  int tmp = m;
  for (int i = 0; i < n; i++) {
    int v1 = 0;
    int v2 = 0;
    cin >> v1 >> v2;
    tmp += v1;
    tmp -= v2;
    if (tmp < 0) {
      cout << 0 << '\n';
      return 0;
    }
    m = max(m, tmp);
  }
  cout << m << '\n';

  return 0;
}



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

int a,b;

int main(){
  cin >> a >> b;
  string ab;
  string ba;
  for(int i=0;i<b;i++){
    ab+=to_string(a);
  }
  for(int i=0;i<a;i++){
    ba+=to_string(b);
  }
  if(ab>ba){
    cout << ba << endl;
  }
  else{
    cout << ab << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int N, K;
	cin >> N >> K;

	vector<int> data(N);

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

	sort(all(data), greater<int>());

	int ans = 0;

	for (int i = 0; i < K; i++)
	{
		ans += data[i];
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main(){
    fast();
 
/* you get what you work for not what you wish for */
    
    ll x;
    cin >> x;
    while(1){
        bool check = 1;
        for(ll i=2; i*i<=x; i++){
            if(x%i==0){
                check = 0;
            }
        }
        if(check){
            out(x);
            break;
        }
        x++;
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
std::vector<long long> a,ans;
int n;
inline int solve(long long x)
{
	if (!x) return 0;
	return solve(x/10)+x%10;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=8;i++) ans.push_back(1ll*i);
	n=n;
	if (n<=0) return 0;
	for (int i=0;i<=1000;i++)
	{
		long long k=i;
		for (int j=1;j<=16;j++)
		{
			k=k*10+9;
			a.push_back(k);
		}
	}
	double now=1e30;
	std::sort(a.begin(),a.end());
	for (int i=a.size()-1;i>=0;i--)
	    if (a[i]/(double)solve(a[i])<=now) now=a[i]/(double)solve(a[i]),ans.push_back(a[i]);
	std::sort(ans.begin(),ans.end());
	for (int i=0;i<ans.size();i++)
	{
		if (i==0) --n,printf("%lld\n",ans[i]);
		else if (ans[i]!=ans[i-1]) --n,printf("%lld\n",ans[i]);
		if (n==0) break;
	}
	return 0;
}

Measured memory_bytes: 3336
#include <algorithm>
#include <bitset>
#include <iostream>
#include <vector>

int main(void) {
    using std::bitset;
    using std::cin;
    using std::cout;
    using std::vector;

    int N;
    cin >> N;
    vector<vector<int>> F(N);  // F[i][j] : 店i が 時間帯j に開いている
    for (int i = 0; i < N; ++i) {
        F.at(i).resize(10);
        for (int j = 0; j < 10; ++j) {
            cin >> F.at(i).at(j);
        }
    }
    // P[i][j] : 店iと同時に開く時間帯が丁度j個 のときの 店i についての利益
    vector<vector<int>> P(N);
    for (int i = 0; i < N; ++i) {
        P.at(i).resize(11);
        for (int j = 0; j < 11; ++j) {
            cin >> P.at(i).at(j);
        }
    }

    int x = -1000000000;
    for (std::size_t i = 1UL; i < 1024uL; ++i) {
        // 開店のパターンは2^10通り
        bitset<10> isOpen(i);

        int sum = 0;
        for (int j = 0; j < N; ++j) {
            // 店j と同時に開店している時間帯の個数
            short c = 0;
            for (short k = 0; k < 10; ++k) {
                if (F.at(j).at(k) && isOpen[k]) c++;
            }
            sum += P.at(j).at(c);
        }

        x = std::max(x, sum);
    }

    cout << x << '\n';

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        sc.next();
        List<Integer> numList = new ArrayList<>();
        while(sc.hasNext()){
            numList.add(Integer.parseInt(sc.next()));
        }
        List<Integer> evenList = numList.stream().filter(s -> s%2 ==0).collect(Collectors.toList());
        long cnt = evenList.stream().filter(s-> s%3 ==0 || s%5 ==0).count();
        String str = "DENIED";
        if(evenList.size() == cnt)str = "APPROVED";
        System.out.println(str);
    }
}


Measured memory_bytes: 28624
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector< vector<int> > g;
vector< vector<int> > rg;
vector<int> order;
vector<int> was;
vector<int> scc;

void dfs(int u) {
  was[u] = 1;
  for (auto& v : g[u]) {
    if (!was[v]) {
      dfs(v);
    }
  }
  order.push_back(u);
}

void dfs2(int u, int k) {
  was[u] = 1;
  scc[u] = k;
  for (auto& v : rg[u]) {
    if (!was[v]) {
      dfs2(v, k);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  g = vector< vector<int> >(n);
  rg = vector< vector<int> >(n);
  for (int i = 0; i < m; i++) {
    int from, to;
    cin >> from >> to;
    g[from].push_back(to);
    rg[to].push_back(from);
  }
  was = vector<int>(n, 0);
  scc = vector<int>(n, 0);
  for (int i = 0; i < n; i++) {
    if (!was[i]) {
      dfs(i);
    }
  }
  reverse(order.begin(), order.end());
  was = vector<int>(n, 0);
  int k = 1;
  for (auto& u : order) {
    if (!was[u]) {
      dfs2(u, k++);
    }
  }  
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    cout << (bool) (scc[u] == scc[v]) << '\n';
  }
  return 0;
}


Measured memory_bytes: 4792
/**
 * B - Echo
 * https://atcoder.jp/contests/abc145/tasks/abc145_b
 **/
#include<iostream>
#include<string>

using namespace std;

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

    int s_len = S.length();
    if(s_len % 2 == 1) {
        cout << "No" << endl;  
    } else {
        bool f = true;
        for(int i=0; i<s_len/2; i++) {
            if(S[i] != S[i+s_len/2]) {
                f = false;
                break;
            }
        }
        if(f) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
N, K, *rest = $stdin.read.split.map(&:to_i)
POINTS = rest.each_slice(2).map.with_index(0){|(x, y), i| [i, x, y]}

XPOINTS = POINTS.sort_by{|i, x, y| x}
YPOINTS = POINTS.sort_by{|i, x, y| y}

ans = Float::INFINITY
n_cases = 0
for _l in 0...N
  l = XPOINTS[_l]
  for _r in (_l+1)...N
    r = XPOINTS[_r]
    next if l[1] == r[1]  # 横幅が0でないこと
    for _b in 0...N
      b = YPOINTS[_b]
      next if b[1] < l[1] || b[1] > r[1]   # bがl-r間にあること
      for _t in (_b+1)...N
        t = YPOINTS[_t]
        next if b[2] == t[2]  # 縦幅が0でないこと
        next if t[1] < l[1] || t[1] > r[1]  # tがl-r間にあること
        next if l[2] < b[2] || l[2] > t[2] # lがb-t間にあること
        next if r[2] < b[2] || r[2] > t[2] # rがb-t間にあること

        n_points = 0
        max_x = r[1]
        _l.upto(_r) do |i|
          y = XPOINTS[i][2]
          n_points += 1 if y >= b[2] && y <= t[2]
          break if n_points >= K
        end
        next if n_points < K

        area = (r[1] - l[1]) * (t[2] - b[2])
        #p l: l, r: r, t: t, b: b, n_points: n_points, area: area
        ans = area if area < ans

        n_cases += 1
      end
    end
  end
end
#p n_cases: n_cases
p ans


Measured memory_bytes: 1916
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
 
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}


 
int main(void){
    int N;
    scanf("%d",&N);
    printf("%d",(int)pow(N,3));
}


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        foreach(var index in Enumerable.Range(0, input.Length))
        {
            var test = input[index];

            if (index % 2 == 0)
            {
                if (test == 'L')
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            else
            {
                if (test == 'R')
                {
                    Console.WriteLine("No");
                    return;
                }
            }
        }
        Console.WriteLine("Yes");
        return;
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n,h,w;
  cin>>n>>h>>w;
  cout << (n-h+1)*(n-w+1) << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
 
n, m = map(int, input().split())

adj = [[] for _ in range(n)] # adjacent list

for _ in range(m):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

c = ['w']*n # color of each vertex
con = [0]*n
cnt = 0


def BFS_visit(s):
    global c
    global cnt
    global con
    
    c[s] = 'g'
    con[s] = cnt
    
    Q = deque()
    Q.append(s)
    while Q:
        u = Q.popleft()
        for v in adj[u]:
            if c[v] == 'w':
                c[v] = 'g'
                con[v] = cnt
                Q.append(v)
        c[u] = 'b'
        
for u in range(n):
    if c[u] == 'w':
        cnt += 1
        BFS_visit(u)
        
        
q = int(input())
for _ in range(q):
    u, v = map(int, input().split())
    ans = "yes" if (con[u] == con[v]) else "no"
    print(ans)


Measured memory_bytes: 24344
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
        
    def find_root(self, x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]
        
    def unite(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1
                
    def isSameGroup(self, x, y):
        return self.find_root(x) == self.find_root(y)
    
    def count(self, x):
        return -self.root[self.find_root(x)]
    
    
    
N,M = map(int, input().split())
P = [int(p) for p in input().split()]
L = []
for i in range(M):
    L.append([int(x) for x in input().split()])
    
tree = UnionFind(N)
for i in range(M):
    tree.unite(P[L[i][0]-1], P[L[i][1]-1])
    
ans = 0
for i in range(N):
    if tree.isSameGroup(P[i], i+1):
        ans += 1
        
print(ans)

Measured memory_bytes: 27248
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.141592653589793238462643383279
using namespace std;
//
int main(){
  int N,A,B;
  cin>>N>>A>>B;
  if((A-B-1)%2){
    cout<<"Alice"<<endl;
  }else{
    cout<<"Borys"<<endl;
  }
  return 0;
}


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

#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")

#define mms(a,n) memset(a,0,sizeof((a)[0])*(n))
#define mmp(a,b,n) memcpy(a,b,sizeof((b)[0])*(n))
#define lowbit(x) ((x)&-(x))
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
#define fd(i,r,l) for(register int i=r,_lim_=l;i>=_lim_;i--)
#define fos(i,l,r,d) for(register int i=l,_lim_=r;i<=r;i+=d)
#define fol(i,l,r) for(register ll i=l,_lim_=r;i<=_lim_;i++)
#define fdl(i,r,l) for(register ll i=r,_lim_=l;i>=_lim_;i--)
#define fosl(i,l,r,d) for(register ll i=l,_lim_=r;i<=r;i+=d)
#define Clear(a) memset(a,0,sizeof(a))
#define Copy(a,b) memcpy(a,b,sizeof(b))
#define ALL(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ldb;
typedef double db;
typedef pair<int,int> pi;

const int N=100005;
int n,m,a[N],fa[N],blk;
vector<int>e[N],E;
ll ans;

int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}

int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n)scanf("%d",&a[i]),fa[i]=i,blk++;
	for(int i=1,u,v;i<=m;i++){
		scanf("%d%d",&u,&v);u++;v++;
		if(find(u)!=find(v))fa[find(u)]=find(v),blk--;
	}
	fo(i,1,n)e[find(i)].pb(a[i]);
	if(blk==1)puts("0"),exit(0);
	int cur=blk-2;
	fo(i,1,n)if(e[i].size()){
		sort(ALL(e[i]));
		ans+=e[i][0];
		fo(j,1,int(e[i].size())-1)E.pb(e[i][j]);
	}
	sort(ALL(E));
	if(cur>E.size())puts("Impossible"),exit(0);
	fo(i,0,cur-1)ans+=E[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=100005;

struct E{
	int to,next;
}mem[N<<1];
int n,x,y,num,rt,m;
int head[N],dp[N],d[N],son[N];
bool tag[N];

void add(int x,int y){
	num++;
	mem[num].to=y; mem[num].next=head[x];
	head[x]=num;
}

void dfs(int k,int pre){
	int j,u,cnt=0;
	if (d[k]>2) tag[k]=1;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		dfs(u,k);
		tag[k]|=tag[u];
		if (tag[u]) dp[k]+=dp[u];
		else cnt++;
	}
	if (cnt) dp[k]+=cnt-1;
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<n;i++){
		scanf("%d%d",&x,&y); x++; y++;
		add(x,y); add(y,x);
		d[x]++; d[y]++;
	}
	for (i=1;i<=n;i++)
		if (d[i]>d[rt]) rt=i;
	dfs(rt,0);
	printf("%d\n",max(dp[rt],1));
	return 0;
}

Measured memory_bytes: 9216
int main(void)
{
  int n, x;
  int m[1000];
  int i,sum = 0,min = 9999;

  scanf("%d %d",&n,&x);
  for(i=0;i<n;i++)
  {
    scanf("%d",&m[i]);
  }
  
  for(i=0;i<n;i++)
  {
    sum += m[i];
  }
  
  if(sum < x)
  {
    for(i=0;i<n;i++)
    {
      if(m[i] < min)
      {
        min = m[i];
      }
    }
  }

      
  printf("%d",n + ((x-sum)/min));
  
  return 0;
}

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

int main() {
  int m;
  cin >> m;
  string line;
  for(int i = 0; i < m; i++){
    cin >> line;
    set<string> q;
    for(int j = 1; j < line.size(); j++) {
      string f, l;
      f = line.substr(0, j);
      l = line.substr(j);
      q.insert(f + l);
      q.insert(l + f);
      reverse(f.begin(), f.end());
      q.insert(f + l);
      q.insert(l + f);
      reverse(l.begin(), l.end());
      q.insert(f + l);
      q.insert(l + f);
      reverse(f.begin(), f.end());
      q.insert(f + l);
      q.insert(l + f);
    }
    cout <<  q.size() << endl;
  }
  return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    ll n;
    cin >> n;
    int ans = 0;
    for (ll i = 2;i*i <= n;++i) if (n%i == 0) {
        int cnt = 0;
        while (n%i == 0) {
            n /= i;
            cnt++;
        }
        for (int j = 1;j < 10;++j) {
            if (cnt < j) break;
            ans++;
            cnt -= j;
        }
    }
    if (n > 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3628
import           Control.Monad
import           Control.Applicative
import           Data.IORef
import           Data.List.Split
import           Data.Maybe
import           Data.List

main :: IO ()
main = do
  n <- readLn
  print $ prod 1 [1..n]

prod n [x] = by x n
prod n (x:xs) = prod (by x n) xs

by x n = x * n `mod` (10 ^ 9 + 7)

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

int main(){
    int n;
    bool p=false,w=false,g=false,y=false;
    string s;
    cin >> n;
    for(int i=0;i < n;i++){
        cin >> s;
        if(s == "P") p = true;
        if(s == "W") w = true;
        if(s == "G") g = true;
        if(s == "Y") y = true;
    }
    if(p && w && g){
        if(y){
            cout << "Four" << endl;
        }else{
            cout << "Three" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int check[100005] = {};
int p[100005];
int main() {
	int x, n;
	cin >> x >> n;
	if (n == 0) {
		cout << x << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		if (check[p[i]] == 0) {
		check[p[i]]++;
		}
	}
	int kai1 = inf;
	for (int i = x; i <= 1000; i++) {
		if (check[i] == 0) {
			kai1 = i;
			break;
		}
	}
	int kai2 = inf;
	for (int j = x; j >= 0; j--) {
		if (check[j] == 0) {
			kai2 = j;
			break;
		}
	}

	if (abs(x - kai1) < abs(x - kai2)) {
		cout << kai1 << endl;
	}
	else {
		cout << kai2 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3652
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, X = i2nn()
    L = i2nn()
    c = 1
    p = 0
    for l in L:
        p += l
        if p <= X:
            c += 1
        else:
            break
    print(c)

main()


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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

vvi mul(vvi a,vvi b,int m)
{
	int n=a.size();
	vvi c(n,vi(n));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			for(int k=0;k<n;k++)
				c[i][j]=(c[i][j]+a[i][k]*b[k][j])%m;
	return c;
}

int main()
{
	for(int n,m,a,b,c,t;cin>>n>>m>>a>>b>>c>>t,n|m|a|b|c|t;){
		vi s(n);
		for(int i=0;i<n;i++) cin>>s[i];
		
		vvi T(n,vi(n));
		for(int i=0;i<n;i++){
			if(i-1>=0) T[i][i-1]=a;
			T[i][i]=b;
			if(i+1<n)  T[i][i+1]=c;
		}
		vvi U(n,vi(n));
		for(int i=0;i<n;i++) U[i][i]=1;
		
		for(int i=31;i-->0;){
			U=mul(U,U,m);
			if(t>>i&1) U=mul(U,T,m);
		}
		
		vi res(n);
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				res[i]=(res[i]+U[i][j]*s[j])%m;
		
		for(int i=0;i<n;i++)
			cout<<res[i]<<(i==n-1?'\n':' ');
	}
}

Measured memory_bytes: 1292
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n;
    cin>>n;

    string s;
    cin>>s;

    int suf[3][n+1];
    mem(suf,0);
    for(int i=n-1;i>=0;--i)
    {
        if(s[i]=='R')
            ++suf[0][i];
        else if(s[i]=='G')
            ++suf[1][i];
        else
            ++suf[2][i];

        for(int j=0;j<3;++j)
            suf[j][i]+=suf[j][i+1];
    }

    vector<string> str={"RGB","RBG","BGR","BRG","GBR","GRB"};

    int ans=0,diff;
    for(auto& c:str)
    {
        for(int i=0;i<n;++i)
        {
            for(int j=i+1;j<n;++j)
            {
                if(s[i]==c[0] && s[j]==c[1])
                {
                    if(c[2]=='R')
                        ans+=suf[0][j];
                    else if(c[2]=='G')
                        ans+=suf[1][j];
                    else
                        ans+=suf[2][j];

                    diff=(j-i);

                    if(j+diff<n && s[j+diff]==c[2])
                        --ans;
                }
            }
        }
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    ll N;
    cin>>N;
    N%=10;
    if(N == 3)cout<<"bon";
    else if(N == 0 || N == 1 || N==6 || N==8)cout<<"pon";
    else cout<<"hon";
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
std::vector<int> f;
bool fig[10];
int N, K;
int mods[5] = { 10000,1000,100,10,1 };
int ans;
int main() {
	std::cin >> N >> K;
	for (int i = 0; i < K; i++) {
		int tmp;
		std::cin >> tmp;
		fig[tmp] = true;
	}
	for (int i = 0; i < 10; i++) {
		if (!fig[i]) {
			f.push_back(i);
		}
	}
	int size = f.size();
	for (int i = 0; i < size; i++) {
		ans = f[i] * mods[4];
		if (ans >= N) {
			std::cout << ans << std::endl;
			return 0;
		}
	}
	for (int i = 0; i < size; i++) {
		for (int j = 0; j < size; j++) {
			ans = f[i] * mods[3] + f[j] * mods[4];
			if (ans >= N) {
				std::cout << ans << std::endl;
				return 0;
			}
		}
	}
	for (int i = 0; i < size; i++) {
		for (int j = 0; j < size; j++) {
			for (int k = 0; k < size; k++) {
				ans = f[i] * mods[2] + f[j] * mods[3] + f[k] * mods[4];
				if (ans >= N) {
					std::cout << ans << std::endl;
					return 0;
				}
			}
		}
	}for (int i = 0; i < size; i++) {
		for (int j = 0; j < size; j++) {
			for (int k = 0; k < size; k++) {
				for (int l = 0; l < size; l++) {
					ans = f[i] * mods[1] + f[j] * mods[2] + f[k] * mods[3] + f[l] * mods[4];
					if (ans >= N) {
						std::cout << ans << std::endl;
						return 0;
					}
				}
			}
		}
	}
	ans = 0;
	if (f[0] == 0)ans = f[1] * mods[0];
	else {
		for (int i = 0; i < 5; i++)ans += f[0] * mods[i];
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces680B
gi = lambda : list(map(int,input().split()))
n, = gi()
mag = 1
ans = 0
while 1:
	if mag > n:
		break;
	if 10 * mag > n:
		ans += n - mag + 1
		break
	ans += 9 * mag
	mag *= 100
print(ans)

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

int main() {
  int N; cin >> N;
  int A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  long sum = 0; for (int i = 0; i < N; i++) sum += A[i];
  map<int, int> C; for (int a = 1; a <= 100000; a++) C[a] = 0;
  for (int i = 0; i < N; i++) C[A[i]]++;
  int Q; cin >> Q;
  int b, c;
  for (int q = 0; q < Q; q++) {
    cin >> b >> c;
    int dif_num = C[b];
    C[c] += C[b];
    C[b] = 0;
    sum += dif_num * (long)(c - b);
    cout << sum << endl;
  }
}

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

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define INF 1e9

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 2e5+2;
const int M = 1e9+7;

map<int, ll> cnt;
int main()
{
    _upgrade;
    int n;
    cin>>n;
    ll res = 0;
    vector<int>v(n);
    FOR(i, 0, n)
    {
        cin>>v[i];
        cnt[i-v[i]]++;
    }
    FOR(i, 0, n)
        res += cnt[v[i]+i];
    cout<<res;
}


Measured memory_bytes: 26556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
using vec_i=vector<int>;
const int INF = 1e9;

int main(){
  int N,ans=INF,S1,S2;cin>>N;
  vec_i w_l(N);
  REP(i,0,N)cin>>w_l[i];
  REP(t,0,N){
    S1=accumulate(w_l.begin(),w_l.begin()+t,0);
    S2=accumulate(w_l.begin()+t,w_l.end(),0);
    ans=min(ans,abs(S1-S2));
  }
  print(ans)
}


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

int main(){
    int N;  cin >> N;
    int A[205];
    for(int i = 0; i < N; ++i)   cin >> A[i]; 

    int count = 0;
    while (true){
        bool wareru = true;
        for (int i = 0; i < N; ++i){
            if(A[i] % 2 != 0)   wareru = false;   
        }
        if(wareru != true)  break;

        for(int i = 0; i < N; ++i)  A[i] /= 2;

        count++;
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000

int main() {

	LL k,i, ans = 0;
	cin>>k;
	vector<LL> kfcac, kminus1fac;


	if(k == 2) {
		cout<<"1"<<endl;
		return 0;
	}

	for(i = 2; i*i <= k; i++) {

		if(k % i == 0) {
			kfcac.PB(i);

			//if(k/i != i) kfcac.PB(k/i);
		}
	}

	//for(i = 0; i < kfcac.size(); i++) cout<< " FAC "<<kfcac[i]<<endl;

	for(i = 0 ; i < kfcac.size(); i++) {

		LL kcpy = k;
		while(kcpy % kfcac[i] == 0) kcpy /= kfcac[i];

		if(kcpy % kfcac[i] == 1)  ans++; 
			//cout<<" A " << kfcac[i]<<endl; }

	}


	k--;

	for(i = 2; i*i <= k; i++) {

		if(k % i == 0) {
			kminus1fac.PB(i);

			if(k/i != i) kminus1fac.PB(k/i);
		}
	}

	ans += kminus1fac.size() + 2;

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3656
// 最大値を求めることは簡単(一番小さい約数から淳に選べばよい)
// 最小値を求めるのはどうするか
#include <bits/stdc++.h>
using namespace std;

map<int64_t, int> prime_factor(int64_t n) {
    map<int64_t, int> ret;
    for (int64_t i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

int main() {
    int64_t N;
    cin >> N;
    auto p_factor = prime_factor(N);
    long long Max = 1;
    for (auto p : p_factor) {
        Max *= (p.second + 1);
    }
    --Max;
    cout << p_factor.size() << " " << Max << endl;
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n , a , b;
ll A , B;

int main(){
    scanf("%d",&n);
    scanf("%lld%lld",&A,&B);
    rep(i,1,n){
        scanf("%d%d",&a,&b);
        ll x = max((A + a - 1) / a , (B + b - 1) / b);
        A = x * a , B = x * b;
    }
    printf("%lld\n",A+B);
    return 0;
}


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

#define mod 1000000007

int main(){
	int h,k;
	cin>>h>>k;
	string str[h+1];
	for(int i=0;i<h;i++)
		cin>>str[i];
	long long answer[h+1][k+1];
	for(int i=0;i<=h;i++){
		for(int j=0;j<=k+1;j++){
			if(i==0||j==0)
				answer[i][j]=0;
			else if(i==1 && j==1)
				answer[i][j]=1;
			else{
				if(str[i-1][j-1]=='.'){
					answer[i][j]=(answer[i-1][j]%mod + answer[i][j-1]%mod)%mod;
				}
				else
					answer[i][j]=0;
			}
		}
	}
	cout<<answer[h][k]<<endl;
}

Measured memory_bytes: 9088
#!/usr/bin/env python3

import sys

sys.setrecursionlimit(10**7)


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, A, B = read_h()

    if A % 2 == B % 2:
        print('Alice')
    else:
        print('Borys')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {

      ll n,m,c;
      cin>>n;
      ll a[n];
      ll mx = INT_MIN;
      for(int i=0; i<n; i++) {
            cin>>a[i];
            mx = max(mx, a[i]);
      }
      sort(a, a+n);
      ll s = 0;
      for(int i=0; i<n-1; i++) {
        s += a[i];
      }
      //cout<<"mx = "<<mx<<" " <<"s = "<<s<<endl;
      if(mx < s) cout<<"Yes";
      else cout<<"No";

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void) {
  double x;
  cin >> x;
  x /= 3;
  double res = x * x * x;
  printf("%.10f\n", res);
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,T,A; cin >> N >> T >> A;
    vector<double> H(N);
    for(int i=0;i<N;i++){
        cin >> H[i];
    }
    int best = 1;
    double best_t = abs(T-H[0]*0.006-A);
    for(int i=1;i<N;i++){
        if(best_t > abs(T-H[i]*0.006-A)){
            best_t = abs(T-H[i]*0.006-A);
            best = i+1;
        }
    }
    cout << best << endl;
}

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

#define x first
#define h second

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll n, w, dmg;
  cin >> n >> w >> dmg;
  w = w*2+1;
  vector<pair<ll,ll>> p;
  for (int i = 0; i < n; i++) {
    ll x, h;
    cin >> x >> h;
    p.emplace_back(x, (h+dmg-1)/dmg);
  }
  sort(p.begin(), p.end());
  vector<ll> will(n+1);
  int j = 0;
  ll acc = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    while (j < n && p[j].x-p[i].x < w) j++;
    acc += will[i];
    ll v = max(p[i].h-acc, 0ll);
    ans += v;
    acc += v;
    will[j] -= v;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Stack st=new Stack();
		String t=sc.nextLine();
		String[] tt=t.split(" ");
		for(int i=0; i<tt.length; i++){
			String l=tt[i];

			if(l.equals("+")){
				int a=st.pop();
				int b=st.pop();

				st.push(a+b);

			}else if(l.equals("*")){
				int a=st.pop();
				int b=st.pop();
				st.push(a*b);
			}else if(l.equals("-")){
				int a=st.pop();
				int b=st.pop();
				st.push(b-a);
			}else{
				int a=Integer.parseInt(l);
				st.push(a);

			}




		}

		st.print();


	}

}

	class Stack{
		public int[] s=new int[1000];
		public int top=0;
		public void print(){
			System.out.println(s[top]);
		}
		public Boolean isEmpty(){
			return top==0;
		}
		public Boolean isFull(){
			return top==0;
		}
		public void push(int x){
			top++;
			s[top]=x;
		}
		public int pop(){
			top--;
			return s[top+1];

		}

	}


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

#define inf 2000000000
#define INF 1e18

typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vl;
typedef vector<ii> vii;

#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define lb lower_bound
#define ub upper_bound
#define sz(x) (ll)x.size()
#define all(x) begin(x), end(x)
#define f0r(i, a) for (ll i=0; i<a; i++)
#define FOR(i, a) for (ll i=1; i<=a; i++)
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll a[100005];

int main()
{
    fastread;
     ll i,j,k,n,a,b,m,l,r,x,y,t;
     cin>>n;
     FOR(i,n){
     if(i*1000>=n){
        cout<<(i*1000)-n<<endl;
        break;
     }
     }


   return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;


int main()
{
    fast;
  
    ll n,k;
    cin>>n>>k;
    ll x=((n-1)*(n-2))/2;
    vector<pair<ll,ll> > v;

    if(k>x)
      cout<<-1<<endl;

    else
    {
      ll diff=x-k;
      for(ll i=2;i<=n;i++)
       v.pb(mp(1,i));

        for(ll e=2;e<n;e++)
        {
          ll cur=e+1;
          while(diff>0 and cur<=n)
          {
           v.pb(mp(e,cur));
            cur++;
            diff--;
          }
          if(diff==0)
            break;
        }

        cout<<v.size()<<endl;
        for(auto i:v)
          cout<<i.ff<<" "<<i.ss<<endl;
    }
   }

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

void solve(){

	int n ;
	cin>>n ;

	vector<int> v(n) ;

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

	vector<int> temp=v ;

	sort(v.begin(),v.end()) ;
	
	for(int i=0;i<n;i++){

		if(temp[i]==v[n-1]){
			cout<<v[n-2]<<"\n" ;
		}
		else{
			cout<<v[n-1]<<"\n" ;
		}

	}

}

int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 4716
def bomb(x,y):
    s=M[y]
    if s[x]=="0":return
    M[y]=s[:x]+"0"+s[x+1:]
    R=[-3,-2,-1,1,2,3]
    for e in R:
        bomb(x+e,y)
        bomb(x,y+e)
    return

A=range(14)
B=range(3,11)
M=["0"*14 for i in A]
z="000"
n=input()
for i in range(n):
    s=raw_input()
    for j in B:
        M[j]=z+raw_input()+z
    x=input()+2
    y=input()+2
    bomb(x,y)
    print "Data %d:" %(i+1)
    for j in B:
        print M[j][3:-3]

Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
//#define zerol
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout  << #x << " -> "; err(x); } while (0)
void err() { cout <<  endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

const int MAXN = 1e5+5;
const LL MOD = 1e9+7;

vector<int> p;
bool nop[MAXN];

int n;
LL a, b, x[MAXN];

int main() {
    scanf("%d%lld%lld", &n, &a, &b);
    FOR (i, 0, n) {
        scanf("%lld", &x[i]);
    }

    LL ans = 0;
    FOR (i, 1, n) {
        LL da = (x[i]-x[i-1]) * a, db = b;
        ans += min(da, db);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005;
int in[N],out[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,m;
  cin>>n>>m;
  rep(i,1,m+1)
    {
      int x,y;
      cin>>x>>y;
      out[y]=max(out[y],x);
    }
  int pre=0,ans=0;
  rep(i,1,n+1)
    {
      if(!out[i]) continue;
      if(out[i]>pre) pre=i-1,ans++;
    }
  cout<<ans<<endl;
  return 0 ;
}


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

int sid = 1;
struct segtree {
  int l, r, sl, sr, v;
} s[1000005];

int build(int l, int r) {
  int u = sid++;
  int m = l + r >> 1;

  s[u].l = l;
  s[u].r = r;
  s[u].v = 0; // from problem statement

  if (l != r) {
    s[u].sl = build(l, m);
    s[u].sr = build(m + 1, r);
  }
  
  return u;
}

void update(int u, int l, int r, int v) {
  if (l == s[u].l && r == s[u].r) {
    s[u].v += v;
    return;
  }

  int m = s[u].l + s[u].r >> 1;
  if (r <= m) {
    update(s[u].sl, l, r, v);
  } else if (l > m) {
    update(s[u].sr, l, r, v);
  } else {
    update(s[u].sl, l, m, v);
    update(s[u].sr, m + 1, r, v);
  }
}

int query(int u, int k) {
  if (s[u].l == s[u].r) return s[u].v;

  int m = s[u].l + s[u].r >> 1;
  if (k <= m)
    return s[u].v + query(s[u].sl, k);
  else
    return s[u].v + query(s[u].sr, k);
}

int main() {
  int n, q; cin >> n >> q;
  int T = build(1, n);

  for (int i = 0; i < q; i++) {
    int t; cin >> t;
    if (t == 0) {
      int a, b, c; cin >> a >> b >> c;
      update(T, a, b, c);
    } else {
      int k; cin >> k;
      cout << query(T, k) << endl;
    }
  }
}



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

const int N=201000;

int n,a[N],f[N],Index[N];
int ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{	
		scanf("%d",a+i);
		Index[a[i]]=i;
	}
	for(int i=1;i<=n;i++)
	{
		f[i]=f[Index[a[i]-1]]+1;
		ans=max(ans,f[i]);
	}
	cout<<n-ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
N,K=map(int,input().split())
h=list(map(int,input().split()))
h=sorted(h)
right=-1
left=len(h)
while left-right>1:
  mid=(right+left)//2
  if h[mid]>=K:
    left=mid
  else:
    right=mid
print(len(h)-left)

Measured memory_bytes: 11908
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int N, total = 0;
  cin >> N;
  string S;
  vector<P> p, m;
  for (int i = 0; i < N; i++) {
    cin >> S;
    int d = 0, b = 0;
    for (char c: S) {
      if (c == '(')
        d++;
      else
        d--;
      b = min(b, d);
    }
    if (d>=0)
      p.push_back({b, d});
    else
      m.push_back({b-d, d});
    total += d;
  }
  sort(p.rbegin(), p.rend());
  sort(m.begin(), m.end());
  bool check = (total == 0);
  int h = 0;
  for (P e: p) {
    if (h+e.first<0)
      check = false;
    h += e.second;
  }
  for (P e: m) {
    if (h+e.first+e.second<0)
      check = false;
    h += e.second;
  }
  if (check)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

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

int N, sum, S, ans = 1e9 + 7;

int main()
{
    cin >> N;
    vector<int> W(N);
    for (int i = 0; i < N; i++)
    {
        cin >> W[i];
        sum += W[i];
    }
    for (int i = 0; i + 1 < N; i++)
    {
        S += W[i];
        ans = min(ans, abs(S - (sum - S)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256