akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll n, P, Q;

main(){
	ios::sync_with_stdio(false);
	cin >> n >> P >> Q;
	vector<ll> d(n);
	REP(i, n){
		int x;
		cin >> x;
		d[i] = x+P*(i+1);
	}
	ll zenbujisui = P*(n*Q + n*(n-1)/2);
	ll ans = zenbujisui;
	ll sum = 0;
	sort(RALL(d));
	REPS(i, n){
		sum += d[i-1];
		ans = max(ans, zenbujisui + sum + P*i*i - i*P*(Q + 2*n));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4956
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <string.h>

using namespace std;
#define ll long long int

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

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

	return 0;
}


Measured memory_bytes: 3652
k = gets.to_i
s = 0
class Array
  def gcd
      self.inject{|a,b| a.gcd(b)}
  end
end
def sp(l)
  sum = 0
  for i in 1..l
    for j in 1..l
      for m in 1..l
       sum += 1 if [i,j,m].gcd == 1
      end
    end
  end
  return sum
end
x = 0
for n in 2..k
  y = sp(k/n)
  x += y
  s += n * y
end

puts s+(k**3)-x

Measured memory_bytes: 14340
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();  
        int N = r.i();
        int[] a = r.ii();
        HashMap<Integer, Integer> hs = new HashMap<>();
        int ans = 0;
        for(int i : a){
            if(!hs.containsKey(i))
                hs.put(i, 1);
            else
                hs.put(i, hs.get(i)+1);
        }
        for(int i : hs.keySet()){
            int count = hs.get(i);
            if(count >= i)
                ans += count-i;
            else
                ans += count;
        }
        println(ans);
    }
    static class EdgeList{
        int id;
        ArrayList<int[]> list = new ArrayList<>();
        int d;
        EdgeList(int n){
            id = n;
        }
        void add(int[] a){
            list.add(a);
        }
        int size(){
            return list.size();
        }
        void setD(int d){
            this.d = d;
        }
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}


Measured memory_bytes: 45780
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < int(n);++i)
#define pb push_back
#define vi vector<int>
#define pll pair<ll,ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define ff first
#define ss second

void solve() {

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    /*ll t = 1;
    cin >> t;
    while (t--) {
        solve();
    }*/
    ll k,x; cin >> k >> x;
    forn(i,k-1){
        cout << x - k + 1 + i << " ";
    }
    cout << x << " ";
    forn(i,k-1){
        cout << x + i + 1 << " ";
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
ll int MOD=998244353;
#define INF 2*1e9
#define N 310000
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

int n;
vector<int> v[N];
int depth(int a){
    if(!v[a].size()) return 0;
    vector<int> w;
    rep(i,v[a].size()){
        w.pb(depth(v[a][i]));
    }
    sort(w.begin(),w.end());
    int ans=0,temp=w.size();
    rep(i,w.size()){
        ans=max(ans,w[i]+temp);
        temp--;
    }
    return ans;
}
main(){
    cin>>n;
    rep2(i,2,n){
        int a;
        cin>>a;
        v[a].push_back(i);
    }
    cout<<depth(1);
    return 0;
}


Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int X;
    cin >> X;

    for(int i=0; i<=X; i++) {
        if(i*(i+1)/2 >= X) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int a, b;
	cin >> a >> b;
	cout << int(max(0, a-b-b)) << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l;i<=r;i++)
#define dn(l,r,i) for(int i=l;i>=r;i--)
#define add(x,y) (x=(x+y)%P)
using namespace std;

typedef long long LL;
const int P	  =1e9+7;
const int INF =2147483647;
int qread(){
	int w=1,c,ret;
	while((c=getchar())> '9'||c< '0')
	w=(c=='-'?-1:1); ret=c-'0';
	while((c=getchar())>='0'&&c<='9')
	ret=ret*10+c-'0';
	return ret*w;
}
const int MAXN =21+3,MAXM=(1<<21)+3;
int dp[MAXN][MAXM],n,mx;
bool mtch[MAXN][MAXN];
int main(){
	n=qread();
	up(1,n,i) up(1,n,j) mtch[i][j]=qread();
	dp[0][0]=1,mx=(1<<n)-1;
	up(0,n-1,i){
		up(0,mx,j) if(dp[i][j]){
			up(1,n,k) if(mtch[i+1][k]&&!(j&(1<<k-1)))
			add(dp[i+1][j|(1<<k-1)],dp[i][j]);
		}
	}
	printf("%d\n",dp[n][mx]);
	return 0;
}


Measured memory_bytes: 164096
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int s, w;
    cin >> s >> w;

    cout << (s <= w ? "unsafe" : "safe") << endl;

    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)			x.begin(),x.end() 
#define FIO				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

int lcm(int x , int y){
	return (x * y) / __gcd(x, y);
}

int modPower(int x, int y , int p) {
	//Used to calculate (x^y)%p
	int res = 1;
	if (y == 0) {
		return 1;
	}

	x = x % p;
	if (x == 0) {
		return 0  ;
	}

	while (y > 0) {
		if (y & 1) {
			res = (res * x) % p;
		}

		y >>= 1;
		x = (x * x) % p;
	}
	return res ;

}

void aryan_p() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}

int count(string s){
	string v = "ABC";
	size_t found = s.find(v);

	int ans = 0; 
	while(found!=string::npos){
		ans++;
		found = s.find(v, found + 1);
	}
	return ans;
}

int32_t main() {
	//aryan_p();
	FIO;
	int n;
	cin >> n;
	string s;
	cin >> s;

	int ans = count(s);
	cout << ans;



	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int box[10000000];
void soinsuu(ll n){
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            box[i]++;
            n/=i;    
        }
        if(n==1)break;
    } 
}
int main(){
    ll n,p;
    cin>>n>>p;
    if(n==1){
        cout<<p<<endl;
        return 0;
    }
    soinsuu(p);
    ll ans=1;
    for(ll i=2;i*i<=p;i++){
        while(box[i]>=n){
            ans*=i;
            box[i]-=n;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 100005

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  int N,i,j;
  double ans;
  scanf("%d",&N);
  int x[N],y[N];
  FOR(i,0,N)scanf("%d%d",&x[i],&y[i]);
  FOR(i,0,N)FOR(j,0,i)ans+=sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
  ans=ans/N*2.0;

  printf("%.10f\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

void sort(vector<pair<double, string>> &v){
    rep(i,v.size() - 1){
        rep(j,v.size() - 1){
            if(v[j].first < v[j + 1].first){
                swap(v[j], v[j + 1]);
            }else if(v[j].first == v[j + 1].first && v[j].second > v[j + 1].second){
                swap(v[j], v[j + 1]);
            }
        }
    }
}
int main(){
    int n;
    while(cin >> n,n){
        vector<pair<double, string>> v;
        string str;
        double p, a, b, c, d, e, f, s, m;

        rep(i,n){
            cin >> str >> p >> a >> b >> c >> d >> e >> f >> s >> m;
            double mi = f * m, t = a + b + c;
            t += (d + e) * m;
            v.emplace_back(make_pair((mi * s - p) / t, str));
        }
        sort(v);
        for(auto it:v){
            cout << it.second << endl;
        }
        cout << '#' << endl;
    }
}

Measured memory_bytes: 3228
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let N = read int64

    seq {
        for h in 1L .. 3500L do
            for n in 1L .. 3500L do
                let numer = h * n * N
                let deno = (4L * h * n) - (n * N) - (h * N)
                if deno <> 0L && numer % deno = 0L then
                    let w = numer / deno
                    if w > 0L then yield (h, n, w)
    }
    |> Seq.head
    |> fun (h, n, w) -> printfn "%d %d %d" h n w
    0 // return an integer exit code


Measured memory_bytes: 14160
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 2*1e5;


ll ans = 0;

int main(){
    AC
    ll a, b, n;
    cin>>a>>b>>n;
    ll x = min(b-1, n);
    ans = max(ans, (ll)floor((double)(a*x)/b));

    x = min(n, 2*b-1);
    ll test = floor((double)(a*x)/b) - a*(x/b);
    ans = max(ans, test);

    cout<<ans<<endl;

}

Measured memory_bytes: 3712
N, L = list(map(int, input().split()))

S = []

for i in range(N):
    S.append(abs(L+i))

mi = min(S)

su = int(N * (L + (L+N-1)) / 2)

if su < 0:
    print(su+mi)
else:
    print(su-mi)

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

using namespace std;
long long n,k,i,maxi;
long long st,dr,mij,last;
long long a[200005];
bool ok(int val)
{
    long long ans=0;
    for(long long i=1;i<=n;i++)
    {
        ans+=(a[i]-1)/val;
    }

    return ans<=k;
}
int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        maxi=max(maxi, a[i]);
    }

    last=maxi;
    st=1;
    dr=maxi;

    while(st<=dr)
    {
        mij=(st+dr)/2;

        if(ok(mij))
        {
            last=mij;
            dr=mij-1;
        }
        else
            st=mij+1;
    }

    cout<<last;
    return 0;
}


Measured memory_bytes: 5196
#include <climits>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, x, y;
  cin >> n >> x >> y;

  vector<vector<int>> vec(n + 1, vector<int>(n + 1, 0));

  for (int i = 1; i < n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      int a = vec[i][j - 1] + 1;
      int b = vec[i][x] + 1;
      vec[i][j] = vec[j][i] = (j != y) ? a : min(a, b);
    }
  }

  for (int i = 1; i < n; ++i) {
    for (int j = n; i < j; --j) {
      if (vec[i][j - 1] > vec[i][j] + 1)
        vec[i][j - 1] = vec[j - 1][i] = vec[i][j] + 1;
    }
  }

  vector<int> vec2(n + 1, 0);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      ++vec2[vec[i][j]];

  for (int i = 1; i < n; ++i)
    cout << vec2[i] / 2 << endl;
}

Measured memory_bytes: 16000
import bisect
MOD = 10**9+7

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    X, N = mi()
    p = list(mi())
    i = 0
    while True:
        if not X-i in p:
            print(X-i)
            return
        if not X+i in p:
            print(X+i)
            return
        i += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 61956
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int n;
bool color[8];
int a, cnt;
int main(){
	cnt = 0;
	lp(8)
		color[i] = false;
	cin >> n;
	lp(n) {
		cin >> a;
		if (a < 3200)
			color[a / 400] = true;
		else cnt++;
	}
	int cnt2 = 0;
	lp(8)
		if (color[i])cnt2++;
	if (cnt2 == 0) {
		cout << 1 << ' ' << cnt << endl;
	}
	else cout << cnt2 << ' ' << cnt + cnt2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int H1, M1, H2, M2, K; cin >> H1 >> M1 >> H2 >> M2 >> K;
  cout << 60 * H2 + M2 - (60 * H1 + M1) - K << endl;
}


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

int main(){
    int n;
    cin >> n;
    if (n == 2){
        cout << -1 << endl;
        return 0;
    }

    vector<string>
    p3 = {
        ".aa",
        "b..",
        "b.."
    },
    p4 = {
        "aacd",
        "bbcd",
        "cdaa",
        "cdbb"
    },
    p5 = {
        "aabba",
        "bcc.a",
        "b..cb",
        "a..cb",
        "abbaa"
    },
    p6 = {
        ".aaccd",
        "b..f.d",
        "b..fee",
        "ccd.aa",
        "f.db..",
        "feeb.."
    },
    p7 = {
        ".aa.aac",
        "b..b..c",
        "b..b..b",
        ".aa.aab",
        "b..b..c",
        "b..b..c",
        "aaccaa."
    };

    int i = 0;
    vector<string> ans(n, string(n, '.'));
    auto add = [&](auto &p){
        for (int h = 0; h < p.size(); h++){
            for (int w = 0; w < p.size(); w++)
                ans[i + h][i + w] = p[h][w];
        }
        i += p.size();
    };

    auto output = [&](){
        for (const auto &a: ans)
            cout << a << endl;
    };

    if (n == 3){
        add(p3);
        output();
        return 0;
    }

    if (n % 4 == 1)
        add(p5);
    else if (n % 4 == 2)
        add(p6);
    else if (n % 4 == 3)
        add(p7);

    while(i < n)
        add(p4);

    output();
}

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

const int MAX_N = 100000;

int main(){
    string N;
    cin >> N;
    if(N[0]=='9'||N[1]=='9'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    string S, T;
    cin >> S >> T;
    sort(S.begin(), S.end());
    sort(T.begin(), T.end());
    reverse(T.begin(), T.end());

    if (S < T)
    {
        Yes
    }
    else
    {
        No
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

//AtCoder Beginner Contest 160
// A - Coffee
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		if (S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	};
}


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

int main()
{
  string s;
  cin >> s;
  int ret = 700;
  for(int i = 0; i < 3; ++i){
    if(s[i] == 'o'){
    ret += 100;
    }
  }
  cout << ret << endl;
  return 0;
}

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

signed main(){
  int N;
  cin>>N;
  vector<int> P(N),Q(N);
  rep(i,N)cin>>P[i];
  rep(i,N)cin>>Q[i];
  vector<int> A(N);
  rep(i,N)A[i]=i+1;
  map<vector<int>,int>MP;
  do{
    MP[A]=MP.size();
  }while(next_permutation(begin(A),end(A)));
  
  int ans=abs(MP[P]-MP[Q]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 9876
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let hp: u64 = buf.trim().parse().unwrap();

    println!("{}", solve(hp));
}

fn solve(mut hp: u64) -> u64{
    let mut attack_counter: u64 = 1;
    while hp > 0{
        if hp == 1{
            hp = 0;
        } else {
            hp /= 2;
        }
        attack_counter *= 2;
    }
    attack_counter - 1
}

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

int top,n[1000];

void push(int x){
  n[++top]=x;
}

int pop(){
  top--;
  return n[top+1];
}

int main(){
  int a,b;
  top=0;
  char s[100];
  while( scanf("%s",s) != EOF ){
    if ( s[0] == '+'){
      a=pop();
      b=pop();    
      push(a+b);
    } else if ( s[0] == '-'){
      b=pop();
      a=pop();    
      push(a-b);
    } else if ( s[0] == '*'){
      a=pop();
      b=pop();    
      push(a*b);
    } else{
      push(atoi(s));
    }
  }
  
  printf("%d\n",pop());
  return 0;
}

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

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

    int s;
    cin >> s;

    map<int, bool> mp;
    mp[s] = true;
    int tmp = s;
    for(int i = 2; i <= 1000000; i++){
        if(tmp % 2 == 0){
            if(mp[tmp / 2] == true){
                cout << i << endl;
                return 0;
            }else{
                mp[tmp / 2] = true;
                tmp = tmp / 2;
            }
        }else{
            if(mp[tmp * 3 + 1] == true){
                cout << i << endl;
                return 0;
            }else{
                mp[tmp * 3 + 1] = true;
                tmp = tmp * 3 + 1;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, m;
	cin >> n >> m;
	ll a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	pair<ll, ll> p[m];
	for(int i=0; i<m; i++){
		ll b, c;
		cin >> b >> c;
		p[i]=make_pair(c, b);
	}
	sort(a, a+n);
	sort(p, p+m, greater<pair<ll, ll>>());
 
	ll curr=0, cnt=0;
	for(int i=0; i<n; i++){
		if(a[i]>=p[curr].first) break;
		a[i]=p[curr].first;
		cnt++;
		if(cnt==p[curr].second){
			curr++;
			cnt=0;
			if(curr==m){
				break;
			}
		}
	}
	ll sum=0;
	for(int i=0; i<n; i++) sum+=a[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int a[2200];
bool pd(int x,int y,int z)
{
	return x+y>z;
}
int main()
{
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	scanf("%d",a+i);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			for(int p=j+1;p<=n;p++)
				if(pd(a[i],a[j],a[p])) ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        int mae = Integer.parseInt(s.substring(0, 2));
        int ushiro = Integer.parseInt(s.substring(2, 4));

        boolean maeIsMM = false;
        boolean ushiroIsMM = false;

        if (mae > 0 && mae < 13) {
            maeIsMM = true;
        }
        if (ushiro > 0 && ushiro < 13) {
            ushiroIsMM = true;
        }


        String ans = "";

        if (maeIsMM && ushiroIsMM) {
            ans = "AMBIGUOUS";
        } else if (maeIsMM) {
            ans = "MMYY";
        } else if (ushiroIsMM) {
            ans = "YYMM";
        } else {
            ans = "NA";
        }

        // 出力
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
A,B,C,D=map(str,list(input()))
nana = False
for i in range(8):
    op1,op2,op3='-','-','-'
    if (i & 0b1) == 1:
        op1='+'
    if ((i>>1) & 0b1) == 1:
        op2='+'
    if ((i>>2) & 0b1) == 1:
        op3='+'
    if eval(A+op1+B+op2+C+op3+D) == 7:
        nana=True
        siki7=A+op1+B+op2+C+op3+D
if nana == True:
    print(siki7+'=7')

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

int main() {
    int a, b, c;  cin >> a >> b >> c;
    if (max({a, b, c}) == a)  cout << a*10 + b + c << endl;
    else if (max({a, b, c}) == b)  cout << a + b*10 + c << endl;
    else  cout << a + b + c*10 << endl;
}

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

struct PrimeTable{
	vector<int> primeList;
	vector<bool> isPrime;
	PrimeTable(int n) : isPrime(n + 1,true){
		isPrime[0] = false;
		isPrime[1] = false;
		for(int i = 4;i <= n;i += 2) isPrime[i] = false;
		for(int i = 3;i * i <= n;i += 2){
			if(!isPrime[i]) continue;
			for(int j = i * 2;j <= n;j += i) isPrime[j] = false;
		}
		for(int i = 0;i <= n;i++){
			if(isPrime[i]) primeList.push_back(i);
		}
	}
};

signed main(){
	int n,ans = 0;
	scanf("%d",&n);
	PrimeTable pt(100000000);
	for(int i = 0;i < n;i++){
		int a;
		scanf("%d",&a);
		if(pt.isPrime[a]) ans++;
	}
	printf("%d\n",ans);
}



Measured memory_bytes: 48036
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        String S = scan.next();
        char[] data = S.toCharArray();
        List<Integer> list = new ArrayList<>();
        int current = N;
        while (0 < current) {
            boolean possible = false;
            for (int i = Math.max(current - M, 0); i < current; i++) {
                if (data[i] == '1') {
                    continue;
                }
                list.add(current - i);
                possible = true;
                current = i;
                break;
            }
            if (!possible) {
                System.out.println(-1);
                return;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = list.size()-1; 0 <= i; i--) {
            sb.append(list.get(i)) ;
            sb.append(" ");
        }
        System.out.println(sb.substring(0, sb.length()-1));
    }
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end() //昇順
#define enb(a) a.rbegin(),a.rend() //降順
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

struct student{
	int n;
	int t;
};

bool operator<(const student &student1,const student &student2){
	return student1.t > student2.t; 
};

int main(){
	int m,l;
	cin >> m;
	priority_queue<student> q;
	student h;
	for(int i = 0; i < m; i++){
		cin >> l;
		h.t = l;
		h.n = i + 1;
		q.push(h);
	}
	for(int i = 0; i < m; i++){
		h = q.top();
		q.pop();
		if(i != m - 1)cout << h.n << " ";
		else cout << h.n << endl;
	}

	return 0;
}



Measured memory_bytes: 1780
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){  
    llint x,n,m;
    llint a[15][15];
    cin >> n >> m >> x;
    llint c[15];
    for(int i=0;i<n;i++){
        cin >> c[i];
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
        }
    }
    llint N=1<<n;
    llint ans=inf;
    llint sum[15];
    llint cost;
    for(int i=0;i<N;i++){
        cost=0;
        for(int j=1;j<=m;j++)sum[j]=0;
        for(int j=0;j<n;j++){
            if(!(i&(1<<j)))continue;
            cost+=c[j];
            for(int k=1;k<=m;k++)sum[k]+=a[j][k];
        }
        bool f=true;
        for(int j=1;j<=m;j++){
            if(sum[j]<x)f=false;
        }
        if(f)ans=min(cost,ans);
    }
    if(ans==inf)cout << -1 << endl;
    else cout << ans << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3612
s = list(input())
n = len(s)
mod = 2019
cnt = [0 for _ in range(mod)]
cnt[0] = 1
r = 0
rs = []
for i in range(n - 1, -1, -1):
    r += int(s[i]) * pow(10, n - 1 - i, mod)
    r %= mod
    cnt[r] += 1
ans = sum([cnt[i] * (cnt[i] - 1) // 2 for i in range(mod)])
print(ans)

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

int const MAX = 200005;
long long a[MAX];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		long long x;
		cin >> x;
		x *= 2;
		a[i] = x;
	}
	a[0] = 0;
	for (int i = 1; i <= n; i++) {
		a[i] += a[i - 1];
	}
	long long ans = 10000000000;
	for (int i = 2; i <= n - 2; i++) {
		long long bc, de;
		bc = a[i] - a[0];
		de = a[n] - a[i];
		int p, q;
		p = lower_bound(a, a + i, bc / 2) - a;
		q = lower_bound(a + i, a + n + 1, de / 2 + bc) - a;
		if (abs(a[p] - bc / 2) > abs(a[p - 1] - bc / 2)) {
			p--;
		}
		if (abs(a[q] - a[i] - de / 2) > abs(a[q - 1] - a[i] - de / 2)) {
			q--;
		}
		long long b, c, d, e;
		b = a[p];
		c = a[i] - a[p];
		d = a[q] - a[i];
		e = a[n] - a[q];
		long long t_max, t_min;
		t_max = max({ b,c,d,e });
		t_min = min({ b,c,d,e });
		ans = min(ans, t_max - t_min);
	}
	cout << ans/2 << endl;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}


map<ll, int> get_primes(ll m, ll M) {
    map<ll, int> p;
    p[1] = 1;
    int s[m];
    REP(i, m) s[i] = i;
    for(int i = 2; i <= m; ++i) {
        if (s[i] != i) continue;

        for(int j=i+i; j <= m; j += i) {
            s[j] = i;
        }

        int cnt = 0;
        while(M % i == 0) {
            M /= i;
            ++cnt;
        }
        if (cnt > 0) p[i] = cnt;
    }
    if (M != 1) p[M] = 1;

    return p;
}


#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N; ll M;
    cin >> N >> M;

    int m = int(floor(sqrt(M))) + 1;
    map<ll, int> p = get_primes(m, M);

    int n = N + 1;
    bool c[n][2];
    REP(i, n) {
        c[i][0] = false;
        c[i][1] = false;
    }
    c[1][0] = true;

    ll mm = inf;
    int b = 0;
//    for (auto it = p.begin(); it != p.end(); ++it) debug(it->fi, it->se)
    for (auto it = p.begin(); it != p.end(); ++it) {
        REP(i, it->se) {
            REP(i, n) {
                if (c[i][b]) {
                    ll t = i * it->fi;
                    if(t < N) {
                        c[i][b^1] = true;
                        c[t][b^1] = true;
                    } else {
                        debug(t)
                        mm = min(mm, t);
                    }
                }
            }
            b ^= 1;
        }
    }
    
    cout << fixed << setprecision(20);
    cout << int(M / mm) << endl;

}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int count =0;
      for(int i=0;i<6;i++){
        if(s.charAt(i)=='1'){
          count++;
        }
      }
      System.out.println(count);
    }
}


Measured memory_bytes: 22100
#include <iostream>
#include <stdio.h>
using namespace std;
char a[4], f[3];
int  t[3];
int  main() {
	for(int i= 0; i < 4; i++) cin >> a[i], a[i]-= '0';
	for(int i= 0; i < 2; i++) {
		 if(!i) t[0]= a[0] + a[1], f[0]= '+';
		 if(i) t[0]= a[0] - a[1], f[0]= '-';
		 for(int j= 0; j < 2; j++) {
			 if(!j) t[1]= t[0] + a[2], f[1]= '+';
			 if(j) t[1]= t[0] - a[2], f[1]= '-';
			 for(int q= 0; q < 2; q++) {
				 if(!q) t[2]= t[1] + a[3], f[2]= '+';
				 if(q) t[2]= t[1] - a[3], f[2]= '-';
				 if(t[2] == 7) {
					 printf("%d%c%d%c%d%c%d=7\n", a[0], f[0], a[1], f[1], a[2], f[2], a[3]);
					 return 0;
				 }
			 }
		 }
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
int n;
char s[N];

int cnt[666];

int main() {
    scanf("%d", &n);
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i++) {
        cnt[s[i]]++;
    }
    int res = 1;
    for (int i = 'a'; i <= 'z'; i++) {
        
        res = (long long)res * (cnt[i] + 1) % MOD;
    }
    printf("%d\n", (res - 1 + MOD) % MOD);
    return 0;
}

Measured memory_bytes: 384
def resolve():
    N, K = map(int, input().split())
    A = list(map(lambda x: int(x) - 1, input().split()))

    visited = set()  # 探索済み
    path = []  # 探索順番
    now = 0
    while now not in visited:
        path.append(now)
        visited.add(now)
        now = A[now]

    s = path.index(now)
    r = len(path) - s

    if K < s:
        print(path[K] + 1)
    else:
        mod = (K - s) % r
        print(path[mod + s] + 1)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 32384
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int a,b,c;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		
		String str;
		//c???????????§??????
		if (a < c){
			if (b < c){
				if (a < b){
					str = "Yes";
				}else{str = "No";}
			}else{str = "No";}
		}else{str = "No";}
		
		System.out.println(str);
	}
}

Measured memory_bytes: 26308
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int k,t;
    cin>>k>>t;
    vector<int> a(t);
    rep(i,t) cin>>a[i];

    sort(all(a));
    cout<<max(0,a[t-1]-1-(k-a[t-1]))<<endl;  
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define MOD 1000000007
#define MAXN 200005
#define MAXC 100000000000014
#define MAXV 1000000009

int ans, n, k, a[MAXN];
map<int, int> mp;

int main()
{
    cin >> n >> k;
    REP(i, 0, n){
        cin >> a[i];
        mp[a[i]]++;
    }
    if(mp.size() <= k){
        cout << "0" << endl;
        return 0;
    }
    PQG que;
    map<int, int> :: iterator ite;
    for(ite = mp.begin();ite != mp.end();++ite){
        que.push(ite->se);
    }
    while(que.size() > k){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;


    return 0;
}
















Measured memory_bytes: 11516
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
vi as,at;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,m,y,z,a,b,c,d;
    string s,t;
    cin>>s>>t;
    ll q;
    n = s.size();
    as.resize(n+1);
    for(int i=0;i<n;i++){
        as[i+1]=(s[i]=='A')?1:2;
        if(i)as[i+1]+=as[i];
    }
    n = t.size();
    at.resize(n+1);
    for(int i=0;i<n;i++){
        at[i+1]=(t[i]=='A')?1:2;
        if(i)at[i+1]+=at[i];
    }
    cin>>q;
    while(q--){
        cin>>a>>b>>c>>d;
        x = as[b] - as[a-1];
        y = at[d] - at[c-1];
        if(((x%3)==(y%3))){
            cout<<"YES\n";
        }
        else{
            cout<<"NO\n";
        }
    }

    return 0;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
    int n, k, c;
    cin>>n>>k>>c;
    string s;
    cin>>s;

    vector<int> w1(k), w2(k);
    for(int i=0, p=0; i<k; i++){
        while(s[p]=='x') p++;
        w1[i]=p;
        p += c+1;
    }

    for(int i=k-1, p=n-1; i>=0; i--){
        while(s[p]=='x') p--;
        w2[i]=p;
        p -= c+1;
    }

    rep(i, k) if(w1[i]==w2[i]) cout<<(w1[i]+1)<<endl;

    return 0;
}


Measured memory_bytes: 5012
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, k, m;
    while(cin >> n >> k >> m, n){
        set<int> s;
        for (int i = 0; i < n; ++i) {
            s.emplace(i);
        }
        auto cur = s.lower_bound(m-1);
        for (int i = 0; i < n-1; ++i) {
            cur = s.erase(cur);
            if(cur == s.end()) cur = s.begin();
            for (int j = 0; j < (k-1)%(n-i-1); ++j) {
                cur++;
                if(cur == s.end()) cur = s.begin();
            }
        }
        cout << (*s.begin())+1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 3544
#!/usr/bin/perl
#arc88_c.pl
#Tue Jan  9 23:04:35 2018
#

use warnings;
use strict;

my $temp = <STDIN>;
my @para = split (" ",$temp);

my $x = $para[0];
my $y = $para[1];

my $answer;
my $num = $x;

while ($x <= $y){
	$answer++;
	$x = $x * 2;
}

print $answer,"\n";

Measured memory_bytes: 896
//atcoder.jp abc 120 d
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fst first
#define scd second
using namespace std;

inline ll read() {
	ll f=1,x=0;
	char ch=getchar();
	
	while(!isdigit(ch)){
	   if(ch=='-')
	      f=-1;
	   ch=getchar();
	}
	
	while(isdigit(ch)){
	   x=x*10+ch-'0';
	   ch=getchar();
	}
	
	return x*f;
}

const int MAXN=1e5+5;
int n,m,fa[MAXN];

struct EDGE {
	int u,v;
}e[MAXN];

ll ans[MAXN],sz[MAXN];

int get_fa(int x) {
	if(x==fa[x]) return x;
	return fa[x]=get_fa(fa[x]);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	n=read();
	m=read();
	
	for(int i=1;i<=m;++i) {
		e[i].u=read(); 
		e[i].v=read();
	}
	
	for(int i=1;i<=n;++i) 
	   fa[i]=i,sz[i]=1;
	
	ans[m]=(ll)n*(n-1)/2;
	
	for(int i=m;i>=1;--i) {
		int u=get_fa(e[i].u),v=get_fa(e[i].v);
		if(u==v) 
		    ans[i-1]=ans[i];
		else {
			ans[i-1]=ans[i]-sz[v]*sz[u];
			sz[v]+=sz[u]; fa[u]=v;
		}
	}
	
	for(int i=1;i<=m;++i) 
	   cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to) 

int main() {
	int t[7][4][4] = {{{1, 1, 0, 0},
					   {1, 1, 0, 0},
					   {0, 0, 0, 0},
					   {0, 0, 0, 0}},

					  {{1, 0, 0, 0},
					   {1, 0, 0, 0},
					   {1, 0, 0, 0},
					   {1, 0, 0, 0}},

					  {{1, 1, 1, 1},
					   {0, 0, 0, 0},
					   {0, 0, 0, 0},
					   {0, 0, 0, 0}},
					  
					  {{0, 1, 0, 0},
			      	   {1, 1, 0, 0},
					   {1, 0, 0, 0},
					   {0, 0, 0, 0}},
					  
					  {{1, 1, 0, 0},
					   {0, 1, 1, 0},
					   {0, 0, 0, 0},
					   {0, 0, 0, 0}},
					  
					  {{1, 0, 0, 0},
					   {1, 1, 0, 0},
					   {0, 1, 0, 0},
					   {0, 0, 0, 0}},
					
				   	  {{0, 1, 1, 0},
				   	   {1, 1, 0, 0},
					   {0, 0, 0, 0},
					   {0, 0, 0, 0}}};
	string str;
	while(cin >> str) {
		vector<string> s(8);
		s[0] = str;
		int board[11][11];
		rep2(i,1,8) {
			cin >> s[i];
		}
		rep(i,11) {
			rep(j,11) {
				board[i][j] = 0;
			}
		}
		
		rep(i,8) {
			rep(j,8) {
				board[i][j] = s[i][j] - '0';
			}
		}
		rep(i,64) {
			bool f = 1;
			rep(k,7) {
				f = 1;
				rep(l,16) {
					if(board[i / 8 + l / 4][i % 8 + l % 4] != t[k][l / 4][l % 4]) {
						f = 0;
						break;
					}
				}
				if(f) {
					cout << (char) (k + 'A') << endl;
					break;
				}
			}
			if(f) break;
		}
	}
	return 0;
}

Measured memory_bytes: 1184
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
from collections import defaultdict
class UnionFind:
    def __init__(self, n):
        class KeyDict(dict):
            # 辞書にないときの対応
            def __missing__(self,key):
                self[key] = key
                return key
        self.parent = KeyDict()
        self.rank = defaultdict(int)
        self.weight = defaultdict(int)

    # 根を探す
    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            # 経路圧縮
            # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に)
            y = self.find(self.parent[x])           
            self.weight[x] += self.weight[self.parent[x]]   #圧縮時にweightを更新(和)
            self.parent[x] = y      #親の置き換え(圧縮)
            return self.parent[x]

    # 結合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

    ### 重み付き
    def weighted_union(self, x, y, w):
        # print("unite",x,y,w,self.weight)
        px = self.find(x)
        py = self.find(y)
        # 低い方を高い方につなげる(親のランクによる)
        # if px == py: return 0
        if self.rank[px] < self.rank[py]:
            self.parent[px] = py
            self.weight[px] = - w - self.weight[x] + self.weight[y]
        else:
            self.parent[py] = px
            self.weight[py] =  w + self.weight[x] - self.weight[y]
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1
        return 0

    # 判定
    def judge(self, x, y):
        return self.find(x) == self.find(y)

cnt = defaultdict(int)
uf = UnionFind(n)
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    if not uf.judge(a,b): uf.union(a,b)
for i in range(n):
    cnt[uf.find(i)] += 1

print(max([cnt[k] for k in cnt.keys()]))

    

Measured memory_bytes: 184296
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli n,k,M=1000000007;
    cin>>n>>k;
    lli i,j,a[n+1],dp[n+1][k+1],prefix[k+1],ans=0;
    memset(dp, 0LL, sizeof(dp));
    
    for(i=1;i<=n;i++) cin>>a[i];
    
    dp[0][0]=1;
    
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=k;j++) prefix[j]=dp[i-1][j];
        
        for(j=1;j<=k;j++) prefix[j]=(prefix[j]+prefix[j-1])%M;
        
        for(j=0;j<=k;j++)
        {
            if(j-a[i]-1>=0)
            dp[i][j]=(prefix[j]-prefix[j-a[i]-1]+M)%M;
            else
            dp[i][j]=prefix[j];
        }
    }
    
    cout<<dp[n][k];
    return 0;
}

Measured memory_bytes: 80000
h,w=map(int,input().split())
 
if w%2==0:
  if h==1:
    print(1)
  else:
    print((w//2)*h)
elif w==1:
  print(1)
elif w%2!=0:
  if h%2==0:
    print(w*(h//2))
  else:
    print(w*((h-1)//2)+(w+1)//2)


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	int n;
	cin >> n;

	vector<long long int> happy(n);
	rep(i, n){
		cin >> happy[i];
	}

	sort(all(happy), greater<long long int>());
	queue<long long int> que;

	que.push(happy[0]);

	long long int ans = 0;

	REP(i, 1, n){
		ans += que.front();
		que.pop();

		que.push(happy[i]);
		que.push(happy[i]);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 6416
#include<string>
#include<iostream>
#include<algorithm>


int main() {
	std::string s;
	std::cin >> s;

	decltype(s.size()) ans = 0;
	for (decltype(s.size()) i{}; i < s.size(); ++i) {
		if (i % 2 == 0)
			ans += s[i] == '0' ? 0 : 1;
		else
			ans += s[i] == '1' ? 0 : 1;
	}

	ans = std::min(ans, s.size() - ans);

	std::cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 512