akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = ( 1 << 21 ) + 7;
const int MAXL = 22;

int n, K;
char is[MAXN];
int a[MAXN];
int dp[MAXN][MAXL];
int val[MAXN];
int qlg[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
	
	qlg[0] = qlg[1] = 0;
	lp ( i, 2, MAXN ) qlg[i] = qlg[i>>1] + 1;
}

void input ()
{
	// input method
	
	scanf ( "%d%d", &n, &K );
	lpi ( i, 0, n ){
		scanf ( "%s", is );
		lp ( j, 0, ( 1 << i ) ) a[j|(1<<i)] = is[j] == '1';
	}
}

void work ()
{
	// main work
	
	++n;
	int ms = ( 1 << n ) - 1, v, msk;
//	lpi ( i, 1, ms ) cerr << a[i] << " "; cerr << endl;
	lpd ( i, ms>>1, 0 ){
		lpdi ( j, qlg[i], 0 ){
			if ( j == qlg[i] ){
				dp[i][j] = dp[i<<1][j+1] + a[i<<1] + dp[i<<1|1][j+1] + a[i<<1|1];
			}else{
				dp[i][j] = dp[i][j+1];
				v = i;
				msk = v >> ( qlg[i] - j ) << ( qlg[i] - j );
				v ^= msk;
				if ( ! ( v >> ( qlg[i] - j - 1 ) & 1 ) ) v |= 1 << ( qlg[i] - j );
				v |= msk << 1;
				dp[i][j] += dp[v][j+1] + a[v];
			}
		}
	}
	
//	lpi ( i, 1, ms ) { cerr << i << " : "; lpi ( j, 0, qlg[i] ) cerr << dp[i][j] << " "; cerr << endl; }
	
	lpi ( i, 1, ms ) val[i] = dp[i][0] + a[i];
	
	int ans = 1;
	lpi ( i, 1, ms ){
		if ( val[i] >= K ){
			if ( qlg[i] > qlg[ans] ) ans = i;
		}
	}
	
	string str;
	for ( int t = ans; t ^ 1; t >>= 1 ) str += ( t & 1 ) + '0';
	reverse ( str.begin (), str.end () );
	cout << str << endl;
}

Measured memory_bytes: 119168
from itertools import permutations


def calcpath(nodes, edges):
    start = nodes[0]
    pattern = permutations(nodes[1:])

    count = 0
    for p in pattern:
        path = [start] + list(p)
        for i in range(len(path) - 1):
            if edges[path[i]][path[i+1]] != 1:
                break
            if i + 1 == len(path) - 1:
                count += 1

    return count


def main():
    n, m = list(map(int, input().split()))
    nodes = [i for i in range(n)]
    edges = [[0 for i in range(n)] for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, input().split()))
        edges[a - 1][b - 1] = 1
        edges[b - 1][a - 1] = 1
    print(calcpath(nodes, edges))


main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846

int main(){

  int n;
  cin >> n;
  int d[n];
  rep(i, n)cin >> d[i];

  ll sum = 0;

  for(int i = 0; i < n - 1; i++){
  int s = n - 1;
    for(int j = 0; j < n - i - 1; j++){

      sum += d[i] * d[s];
      s--;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;



void solve() {
	int n;
	map<string, ll> m;
	ll m_value = -maxn;
	vector<string> v;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		m[s]++;
		m_value = max(m_value, m[s]);
		}
		for(auto x : m) if( x.second== m_value) v.pb(x.first);
		sort(v.begin(), v.end());
		for(auto x : v) cout << x << endl;
}


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	int t;
	solve();
	return 0;
}
 
 
 


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

#define ALL(container) (container).begin(), (container).end()

typedef long long int ll;

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

using namespace std;

int main()
{
    int N, M; cin >> N >> M;
    vector<pair<ll, ll> > pv(N);
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> pv[i].first >> pv[i].second;
    }
    sort(ALL(pv));
    for (int i = 0; i < N; i++)
    {
        ll count = min(pv[i].second, (ll)M);;
        M -= count;
        ans += pv[i].first * count;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void){

int a,b,c,temp1,temp2,temp3;

scanf("%d%d%d", &a,&b,&c);

if(a>b){
temp1=a;
a=b;
b=temp1;
}

if(b>c){
temp2=b;
b=c;
c=temp2;
}

if(a>b){
temp3=a;
a=b;
b=temp3;
}

printf("%d %d %d\n", a,b,c);
}

Measured memory_bytes: 1812
kawaisou = False
a,b,c = list(map(int,input().split()))
if(a == b):
    if(a != c):
        kawaisou = True
if(a == c):
    if(a != b):
        kawaisou = True
if(b == c):
    if(a != b):
        kawaisou = True
if(kawaisou == True):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
p = input().split(" ")
x1 = int(p[0])
y1 = int(p[1])
x2 = int(p[2])
y2 = int(p[3])

DIF1 = x2 - x1
DIF2 = y2 - y1
x3 = x2 - DIF2
y3 = y2 + DIF1
x4 = x1 - DIF2
y4 = y1 + DIF1

print(str(x3)+" "+str(y3)+" "+str(x4)+" "+str(y4))

Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)
l = Array.new(n) { gets.split.map(&:to_i) }.sort
cost = count = 0

l.each do |a, b|
  count += b
  cost += a * b

  if count >= m
    puts cost - (count - m) * a
    exit
  end
end

Measured memory_bytes: 11128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n;
    cin>>n;
    vi a(n), b(n), c(n);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n){
        c[i]=a[i]-b[i];
    }
    lli ans=0;
    sort(all(c));
    reverse(all(c));
    rep(i,n){
        if(c[i]<=0){ 
            break;
        }
        else{ 
            ans+=c[i];
        }
    }
    out(ans);
}

Measured memory_bytes: 3668
N,X = map(int,input().split())

a = [1]
for i in range(N):
    a.append(2*a[-1]+3)

b = [1]
for i in range(N):
    b.append(2*b[-1]+1)

def solve(n,x):
    if n == 0:
        if x == 1:
            return 1
        return 0
    if x == a[n]:
        return b[n]
    if x >= a[n]//2+1:
        return b[n-1] + 1 + solve(n-1,x-a[n]//2-1)
    if x >= 1:
        return solve(n-1,x-1)
    return 0

print(solve(N,X))


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  int H,W,h,w;
  cin>>H>>W>>h>>w;
  if(H%h==0&&W%w==0){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;

  if(W%w!=0){
    vector<int> ww(W);
    for(int i=0;i<W;i++){
      if(i%w==w-1)ww[i]=-1e6*(w-1)-1;
      else ww[i]=1e6;
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(j)cout<<" ";
        cout<<ww[j];
      }
      cout<<endl;
    }
  }else{
    vector<int> hh(H);
    for(int i=0;i<H;i++){
      if(i%h==h-1)hh[i]=-1e6*(h-1)-1;
      else hh[i]=1e6;
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(j)cout<<" ";
        cout<<hh[i];
      }
      cout<<endl;
    }
  }
}


Measured memory_bytes: 2304
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int A, B;
    String op;

    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        op = sc.next();
        B = sc.nextInt();
    }

    void solve(PrintWriter out) {
        out.println(op.equals("+") ? A + B : A - B);
    }

}

class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22228
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false); 
int a[305][305],inv[305][305],ptr[500],haha[500],m,n;  
int remov(int spo){
	int i;
	f(i,1,n+1){
		a[i][inv[i][spo]]=-1;
	}
	return 0;
}
int findnext(int stu){
	int i;
	f(i,ptr[stu],m+1){
		if(a[stu][i]!=-1){
			return 0;
		}
		ptr[stu]++;
	}
	return 0;
}
int main(){
    std::ios::sync_with_stdio(false);
    int i,j;
    cin>>n>>m;
    f(i,1,n+1){
    	f(j,1,m+1){
    		cin>>a[i][j];
    		inv[i][a[i][j]]=j;
    	}
    }
    rep(i,n+10){
    	ptr[i]=1;
    }
    j=0;
    int mini=inf;
    while(j<m){
    	f(i,1,n+1){
    		//cout<<ptr[i]<<" ";
    		haha[a[i][ptr[i]]]++;
    	}
    	//cout<<endl;
    	int maxi=0;
	    f(i,1,m+1){
	    	maxi=max(maxi,haha[i]);
	    }
	    //cout<<maxi<<endl;
	    mini=min(maxi,mini);
	    f(i,1,m+1){
	    	if(haha[i]==maxi){
	    		//cout<<i<<" dsds"<<haha[5]<<endl;
	    		remov(i);
	    		j++;
	    		
	    	}
	    	haha[i]=0;
	    }
	    f(i,1,n+1){
	    	findnext(i);
	    }
    }
    //sort(haha,haha+m);
    //int val=haha[m-1];
    cout<<mini<<endl;


    return 0;      

}



Measured memory_bytes: 1024
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_8_C&lang=jp
# Binary Search Tree I
# 2018.12.01 yonezawa

import sys
input = sys.stdin.readline
import cProfile

def showHeap(li):
    #node 2: key = 8, parent key = 7, left key = 2, right key = 3,  
    for i in range(1,len(li)+1):
        n1=n2=n3=n4 =""
        p = i // 2
        r = i * 2 + 1
        l = i * 2
 
        n1 = "node {}: key = {}, ".format(str(i) , str(li[i-1]))
        if p > 0:
            n2 = "parent key = {}, ".format(li[p-1])
        if l -1 < len(li): 
            n3 = "left key = {}, ".format(li[l-1])
        if r -1 < len(li): 
            n4 = "right key = {}, ".format(li[r-1])
        
        print (n1+n2+n3+n4)
            
def main():
    n = int(input())
    l = list(map(int,input().split()))
    showHeap(l)

        
if __name__ == '__main__':
    main()
    #pr = cProfile.Profile()
    #pr.runcall(main)
    #pr.print_stats()


Measured memory_bytes: 7312
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,minn=999999999;
int h[100010];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	  scanf("%d",&h[i]);
	sort(h+1,h+n+1);
	for(int i=k;i<=n;i++)
	  minn=min(minn,h[i]-h[i-k+1]);
	printf("%d",minn);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int t,h,m,s;
	scanf("%d",&t);
	s = t % 60;
	m = ( t / 60 ) % 60;
	h = t / 60 / 60;
	printf("%d:%d:%d\r\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double

using namespace std;

int main()
{
	fio
	long long H,A;
	cin>>H>>A;
	H%A==0?cout<<H/A<<endl:cout<<H/A+1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
#define var auto
int main() {
int a,b;cin>>a>>b;
if(a!=b){
    cout<<6-a-b<<endl;
}
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  int ans = 0;
  rep(i,n){
    if (a[a[i]-1] == i+1){
      ans++;
      a[i] = -1;
    }
  }
  print(ans);
  return 0;
} 


Measured memory_bytes: 640
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int max = 0, x;
  for(int i= 0; i < s.length(); i++){
      if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
          x += 1;
          if(x > max) max = x;
      }else {
          x = 0;
      }
  }
  cout << max ;
}

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

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

        if (S[2] == S[3] && S[4] == S[5])
                cout << "Yes" << endl;
        else
                cout << "No" << endl;

        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    cin>>c;
    ll num=c-'A';
    if(num>=0 && num<26)
    cout<<"A";
    else 
    cout<<"a";


    
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[10001],ans=0,bns=0,n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+2*n);    
    for(int i=1;i<=2*n;i+=2)
    {
        bns+=a[i];
    } 
    printf("%d\n",bns);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a, b;
	int k, i;
	int hah = 0;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &k);

	for (i = 0; i <= k; ){
		if (a % 2 != 0){ a -= 1; }
		else{ ; }
		hah = a / 2;
		a /= 2;
		b += hah;
		i++;
		if (i == k){ break; }

		if (b  % 2 != 0){ b -= 1; }
		else{ ; }
		hah = b / 2;
		b /= 2;
		a += hah;
		i++;
		if (i == k){ break; }
	}
	printf("%d %d",a,b);
	return 0;
}

Measured memory_bytes: 128
//
//  main.cpp
//  SPG-A
//
//  Created by KJC of Kindai University on 2019/08/28.
//  Copyright © 2019 KJC of Kindai University. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int M,D;
    int d1,d10,m;
    int ans=0;
    cin >> M >> D;
    for (int i=22; i<=D; i++) {
        d1=i%10;
        d10=i/10;
        if (d1>=2&&d10>=2) {//d1とd10が共に2以下の時、
            //cout << d10<<" "<<d1 <<endl;
            m=d1*d10;
            if(m<=M){//計算した結果がM以下だったらOKです。
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
    //入力
    long long n,m;
    cin >> n >> m;
    vector<long long> a(n);
    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<pair<long long, long long>> b(m);
    for(long long i = 0; i < m; i++){
        long long x,y;
        cin >> x >> y;
        b[i].second = x;
        b[i].first = -y;
    }

    //どちらも大きい順でなるようにする
    sort(a.begin(),a.end(),greater<long long>());
    sort(b.begin(),b.end());

    vector<long long> sum;
    long long j = 0;
    long long i = 0;
    //このループで大きい数をn個選んでいく
    while(sum.size() < n){
        //もし元々の配列の方が大きかったらそれを配列に入れて、次のインデックスを指定する。
        if(a[i] > -b[j].first){
            sum.push_back(a[i]);
            i++;
            continue;
        }
        //もし新しい配列の方が大きかったらそれを入れる。
        if(b[j].second > 0){
            sum.push_back(-b[j].first);
            b[j].second--;
            continue;
        }
        //新しい配列のインデックスを指定する。
        j++;
    }

    long long ans = 0;
    for(long long i = 0; i < sum.size(); i++){
        ans += sum[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3704
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	int n, t[100000], x[100000], y[100000], X, Y;
	int i;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d %d %d", &t[i], &x[i], &y[i]);
	}
	char *ans;
	ans="Yes";

	if(t[0]< x[0]+y[0] || (t[0]-x[0]-y[0])%2==1){
		ans="No";
	}

	for(i=0; i<n-1; i++){
		if(x[i]<x[i+1]){
			X=x[i+1]-x[i];
		}else{
			X=x[i]-x[i+1];
		}
		if(y[i]<y[i+1]){
			Y=y[i+1]-y[i];
		}else{
			Y=y[i]-y[i+1];
		}
		if(t[i+1]-t[i]<X+Y || (t[i+1]-t[i]-X-Y)%2==1){
			ans="No";
		}
	}
	printf("%s\n", ans);

	return 0;

}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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 int INF = 1000100100;

int main() {
    ll A, B;
    cin >> A >> B;

    for(ll x = 10*B; x < 10*B + 10; ++x) {
        if((ll)(0.08*x) == A) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

bool rel[128][128];
int disc[128];
int comp[128];
int n, turn = 0;

void dfs(int visit, vector<int> &log){
	if(find(log.begin(), log.end(), visit) == log.end()){
		log.push_back(visit);
		disc[visit] = ++turn;
		for(int i = 1; i <= n; i++){
			if(rel[visit][i] && find(log.begin(), log.end(), i) == log.end()) dfs(i, log);
		}
		comp[visit] = ++turn;
	}
}

int main() {
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++){
		int u, k;
		scanf("%d %d", &u, &k);
		
		for(int j = 1; j <= n; j++){
			rel[u][j] = false;
		}
		while(k--){
			int v;
			scanf("%d", &v);
			rel[u][v] = true;
		}
	}
	
	vector<int> visited;
	for(int i = 1; i <= n; i++){
		dfs(i, visited);
	}
	
	for(int i = 1; i <= n; i++){
		printf("%d %d %d\n", i, disc[i], comp[i]);
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>

using namespace std;

int main()
{    
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" << "\n";
  } else if (s == "Cloudy") {
    cout << "Rainy" << "\n";
  } else {
    cout << "Sunny" << "\n";
  }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = []
for _ in range(n): l.append([int(x) for x in input().split()])
l.sort()
s = cnt = 0
for a, b in l:
    if cnt + b < m:
        s += a*b
        cnt += b
    else:
        s += a * (m - cnt)
        break
print(s)

Measured memory_bytes: 21616
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define hell 1000000007
#define PI 3.14159265358979323846
#include <fstream>
using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--) {
     int n,m,x1,y1,x2,y2,x,y,xx,yy;
     cin>>n>>m>>x1>>y1>>x2>>y2;
     char arr[n+1][m+1];
     int i,j;
     for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        cin>>arr[i][j];
        --x1;--y1;--x2;--y2;
     int dx[]={1,-1,0,0};
     int dy[]={0,0,1,-1};

        priority_queue<pair<int,pair<int,int> >, vector<pair<int,pair<int,int> > >, greater<pair<int,pair<int,int> > > >pq;
        int dis[n+1][m+1];
        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
            dis[i][j]=INT_MAX;
        dis[x1][y1]=0;
        pq.push({0,{x1,y1}});
        while(!pq.empty())
        {
            pair<int,pair<int,int> > p=pq.top();
            pq.pop();
            x=p.second.first;
            y=p.second.second;
            int w=p.first;
            if(w==INT_MAX)
                break;
                for(i=0;i<4;i++)
                {
                    xx=x+dx[i];
                    yy=y+dy[i];
                    if(xx<0 || xx>=n || yy<0 || yy>=m)
                        continue;
                    if(arr[xx][yy]=='#')
                        continue;
                    if(dis[xx][yy]>w)
                    {
                        dis[xx][yy]=w;
                        pq.push({w,{xx,yy}});
                    }
                }
            for(i=-2;i<=2;i++)
                for(j=-2;j<=2;j++)
            {
                if((i==0 && j==0) || (i==1 && j==0) || (i==-1 && j==0) || (i==0 && j==1) || (i==0 && j==-1))
                    continue;
                 xx=x+i;
                    yy=y+j;
                    if(xx<0 || xx>=n || yy<0 || yy>=m)
                        continue;
                    if(arr[xx][yy]=='#')
                        continue;
                    if(dis[xx][yy]>w+1)
                    {
                        dis[xx][yy]=w+1;
                        pq.push({w+1,{xx,yy}});
                    }
            }
        }
        if(dis[x2][y2]==INT_MAX)
            cout<<-1;
        else
            cout<<dis[x2][y2];
    }
}


Measured memory_bytes: 8624
import sys
N, A, B, C, D = map(int, input().split())
S = input()

for x in S[A:max(C, D)-1].split("."):
    if len(x) > 1:
        print("No")
        sys.exit()
    else:
        pass

if C < D:
    print("Yes")
    sys.exit()

for x in S[B-2:D+1].split("#"):
    if len(x) > 2:
        print("Yes")
        sys.exit()
    else:
        pass

print("No")

Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
int tree[maxn << 2], lazy[maxn << 2];
void push(int id, int l, int r){
	if(lazy[id]){
		tree[id] += lazy[id];
		if(l != r){
			lazy[id << 1] += lazy[id];
			lazy[id << 1 | 1] += lazy[id];
		}
		lazy[id] = 0;
	}
}
void add(int id, int l, int r, int x, int y, int v){
	push(id, l, r);
	if(l > y || r < x) return;
	if(x <= l && r <= y){
		lazy[id] += v;
		push(id, l, r);
		return;
	}
	int mid = (l + r) >> 1;
	add(id<<1, l, mid, x, y, v);
	add(id<<1|1, mid + 1, r, x, y, v);
	tree[id] = max(tree[id<<1], tree[id<<1|1]);
}
int get(int id, int l, int r, int x, int y){
	push(id, l, r);
	if(l > y || r < x) return -(1<<30);
	if(x <= l && r <= y) return tree[id];
	int mid = (l + r) >> 1;
	return max(get(id<<1, l, mid, x, y), get(id<<1|1, mid + 1, r, x, y));
}
int main(){
	int n, m; cin >> n >> m;
	vector<int> l(n), r(n);
	for(int i = 0; i < n; i++) cin >> l[i] >> r[i];
	vector<vector<int> > up(m + 3), down(m + 3);
	for(int i = 0; i < n; i++){
		up[l[i]].push_back(r[i] + 1);
		down[r[i] + 1].push_back(r[i] + 1);
	}
	for(int i = 1; i <= m; i++){
		add(1, 0, m + 1, 1, i, -1);
	}
	int open = 0;
	int ans = 0;
	for(int i = 0; i <= m; i++){
		for(int v : up[i]){
			open++;
			add(1, 0, m + 1, v, m + 1, -1);
		}
		for(int v : down[i]){
			open--;
			add(1, 0, m + 1, v, m + 1, 1);
		}
		ans = max(ans, open - i + get(1, 0, m + 1, i + 1, m + 1));
	}
	ans = max(ans, n - m);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 24448
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_H 100
using namespace std;

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

  int h, w;
  cin >> h >> w;
  string t[MAX_H];
  for(int i = 0; i < h; i++){
    cin >> t[i];
  }

  string ans;
  for(int i = 0; i < w + 2; i++){
    ans.push_back('#');
  }
  ans.push_back('\n');
  for(int i = 0; i < h; i++){
    ans.push_back('#');
    ans += t[i];
    ans.push_back('#');
    ans.push_back('\n');
  }
  for(int i = 0; i < w + 2; i++){
    ans.push_back('#');
  }
  ans.push_back('\n');

  cout << ans << endl;

  return 0;
}


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

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

  vector<bool> a(26);
  for (int i = 0; i < s.size(); i ++) {
    a.at(s.at(i) - 'a') = true;
  }

  for (int i = 0; i < 26; i ++) {
    if (!a.at(i)) {
      cout << char(i + 'a') << endl;
      return 0;
    }
  }

  cout << "None" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define PI acos(-1.0)

typedef long long ll;
const int maxn=2e5+10;
int a[maxn],b[maxn];

int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> a[i],b[i]=a[i];
    sort(a+1,a+n+1);
    int mid=n/2;
    for(int i=1;i<=n;i++)
    {
        if(b[i]<=a[mid])
            cout << a[mid+1] << endl;
        else
            cout << a[mid] << endl;
    }
    return 0;
}



Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9;

int32_t main(){
	int n,k,s;
	cin>>n>>k>>s;
	for(int i=0;i<k;i++) cout<<s<<endl;
	for(int i=k;i<n;i++) cout<<(s+1)%M<<endl;

}


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

int main(void){
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    B[i] = A[i];
  }
  sort(B.begin(), B.end());
  for(int i = 0; i < N; i++){
    if(A[i] == B[N - 1])cout << B[N - 2] << endl;
    else cout << B[N -1] << endl;
  }
  
 return 0;
  
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
  
int main() {
    int H,W,M;;
    cin >> H >> W >> M;
  
    vector<int>A(M);
    vector<int>B(M);
    for (int i = 0; i < M; i++) {
      cin >> A.at(i) >> B.at(i);
    }
  
  vector<int>countH(H,0);
  vector<int>counth(H,0);
   for (int i = 0; i < M; i++) {
       countH.at(A.at(i)-1)++; 
   }
  
  for (int i = 0; i < H; i++) {
    counth.at(i) = countH.at(i);
  }
  
   vector<int>countW(W,0);
  vector<int>countw(W,0);
   for (int i = 0; i < M; i++) {
       countW.at(B.at(i)-1)++;
   }
  
  for (int i = 0; i < W; i++) {
    countw.at(i) = countW.at(i);
  }
  
   sort(countH.begin(), countH.end());
   reverse(countH.begin(), countH.end());
   sort(countW.begin(), countW.end());
   reverse(countW.begin(), countW.end());

   int maxH = countH.at(0);
   int maxW = countW.at(0);
  
  long long count1 = 0;;
  for (int i = 0; i < H; i++) {
    if (counth.at(i) == maxH){
      count1++;
    }
  }
  long long count2 = 0;
  for (int i = 0; i < W; i++) {
    if (countw.at(i) == maxW){
      count2++;
    }
  }
 
  long long judge = 0;
  
  for (int i = 0; i < M; i++) {
    if (counth.at(A.at(i)-1) == maxH && countw.at(B.at(i)-1) == maxW){
      judge++;
    }
  }
  
  if (judge < count1*count2){
    cout << maxH + maxW << endl;
  }
  else {
    cout << maxH + maxW - 1 << endl;
  }
}




Measured memory_bytes: 10348
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    S = input()
    T = input()
    ans = 1001
    for i in range(len(S)-len(T)+1):
        temp = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                temp += 1
        ans = min(ans, temp)
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 9136
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long H, W, N;
  cin >> H >> W >> N;
  vector<long> a;
  rep (i, N) {
    long aaa;
    cin >> aaa;
    rep (j, aaa) a.push_back(i + 1);
  }
  sort(a.begin(), a.end());

  vector<vector<long> > ans(H, vector<long>(W, 0));

  rep (i, a.size()) {
    ans[i/W][i%W] = a[i];
  }

  rep (i, H) {
    if (i % 2 == 1) reverse(ans[i].begin(), ans[i].end());
  }

  for (auto it: ans) {
    bool flag = false;
    for (auto it2: it) {
      if (flag) cout << " ";
      flag = true;
      cout << it2;
    }
    cout << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 512
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut f = vec![0; n + 1];

    for i in 0..n+1 {
        if i < 2 {
            f[i] = 1;
        }else{
            f[i] = f[i-1] + f[i-2];
        }
    }

    println!("{}", f[n]);

}



Measured memory_bytes: 5028
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	return 0;
}

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

int main(){

    int N, K;
    int A[100000];
    cin >> N >> K;
    for( int i = 0; i < N; i++) cin >> A[i];


    N -= 1;

    if( N % (K-1) == 0 ) cout << N/(K-1) << endl;
    else cout << N/(K-1) + 1 << endl;

    return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#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 RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> X >> Y;
    map<int, int> mp;
    mp[4] = 1;
    mp[6] = 1;
    mp[9] = 1;
    mp[11] = 1;
    mp[2] = 2;
    if (mp[X] == mp[Y])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll a, b, n;
  cin >> a >> b >> n;

  cout << a * min(b - 1, n) / b << '\n';





  
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int n,x,y,m;
vector<int> dp(100001,-1);
vector<int> adj[100001];
int dfs(int node,vector<bool> &vis){
    int ans = 0;
    vis[node] = 1;
    if(adj[node].size() == 0){return 0;}
    for(auto &i:adj[node]){
        if(dp[i]==-1){
            dp[i] = 1+dfs(i,vis);
        }
        ans = max(ans,dp[i]);
    }
    return ans;
}
int main()
{   
    cin>>n>>m;
    vector<bool> vis(n+1,0);
    for(int i=0;i<m;i++){
        cin>>x>>y;
        adj[x].pb(y);
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(!vis[i])
        {ans = max(ans,dfs(i,vis));}
    }
    cout<<ans;
}

Measured memory_bytes: 8832
a = []
a = gets.split.map(&:to_i)
b = []
b = gets.split.map(&:to_i)
total = 0
for i in 0..a[0]-2
  if b[i] + a[1] >= b[i+1]
    total = total + b[i+1] - b[i]
  else
    total = total +a[1]
  end
end
total += a[1] #最後は絶対a[1]
puts total

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

int N;
vector<int> p_ary;

int main()
{
	bool ans = true;
	cin >> N;
	p_ary = vector<int>(N);

	for (int i = 0; i < N; i++) {
		cin >> p_ary.at(i);
	}

	int p1 = -1, p2 = -1;
	int cr = -1;
	for (int i = 0; i < N; i++) {

		if (p_ary.at(i) >= cr) {
			cr = p_ary.at(i);
			continue;
		}

		cr = p_ary.at(i);

		if (p1 == -1) {
			p1 = i;
		}
		else if (p2 == -1) {
			p2 = i;
		}
		else {
			ans = false;
			break;
		}
	}

	
	if (ans) {
		if (p1 != -1) {
			if (p2 != -1) {
				int tmp = p_ary.at(p1 - 1);
				p_ary.at(p1 - 1) = p_ary.at(p2);
				p_ary.at(p2) = tmp;
			}
			else {
				int tmp = p_ary.at(p1-1);
				p_ary.at(p1-1) = p_ary.at(p1);
				p_ary.at(p1) = tmp;
			}

			cr = -1;
			for (int i = 0; i < N; i++) {

				if (p_ary.at(i) < cr) {
					ans = false;
					break;
				}
				cr = p_ary.at(i);

			}
		}
	}



	if (ans) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ll long long
const int MX=200010;
int N, M, k, x;
int arr[MX];
int main()
{
    cin>>N>>M;
    if(N%500 <= M)
    {
        cout<<"Yes\n";
    }
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
ll n;
const ll a=26;
int main(){
	cin>>n;
	n--;
	ll pw=1,sum=0;int cnt=0;
	while(n>=sum){
		pw*=a;
		sum+=pw;
		cnt++;
	}
	sum-=pw;
	n-=sum;
//	cout<<sum<<' '<<n<<' '<<cnt<<endl;
	vector<int>v(cnt,0);
	for(int i=cnt-1;i>=0;i--){
		v[i]=n%a;
		n/=a;
	}
	rep(i,SZ(v)){
		cout<<(char)(v[i]+'a');
	}
	return 0;
}

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

/*
  let's try computer shogi!!!
 */

/*
  ボールの最大値 - ボールの最大公約数 * n
  の値を実現することができる。ボールの数をソートして最大公約数を求めればOK
  ボールの数字に重複があると怖い
 */

vector<int> getYakusus(int i){
  vector<int> yakusu;
  for(int k=1;k*k<i;++k){
    if(i%k ==0){
      yakusu.push_back(k);
      yakusu.push_back(i/k);
    }
  }
  return yakusu;
}

bool check(vector<int> &inp, int i){
  for(int j=0;j<inp.size();++j){
    if(inp[j] % i != 0){
      return false;
    }
  }
  return true;
}

int main(){

  int N; // ボールの個数
  int A; // 実現したい数
  std::vector<int> nums; //ボールの番号
  cin >> N;
  cin >> A;
  nums.resize(N);
  for(int i=0;i<N;++i){
    cin >> nums[i];
  }

  sort(nums.begin(),nums.end());
  if(nums[N-1]<A){
    cout<<"IMPOSSIBLE";
    return 0;
  }

  // 一番小さい数字の約数を取り出す
  vector<int> kyks = getYakusus(nums[0]);
  int koyaku = 1;
  for(int i=0;i<kyks.size();++i){
    //debug
    //cout<<koyaku<<endl;
    if(check(nums,kyks[i])){
      koyaku = kyks[i];
    }
  }
  //debug
  //cout << koyaku << endl;
  if(A%koyaku==0){
    cout<<"POSSIBLE";
  }else{
    cout<<"IMPOSSIBLE";
  }
  
  return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    double ans = 0.0;
    if(N % 2 == 0){
      ans = 0.5;
    }else{
      ans = (double)((N/2)+1)/N;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


void test(int a,int b){
	int n=a*b;
	int g[1000];
	g[0]=0;
	reg(i,1,n){
		pque(int) gs;
		reg(j,1,floor(1.0*i/a)+0.5){
			gs.push(g[i-j]);
		}
		int t=0;
		while(!gs.empty() && gs.top()<=t){
			if(gs.top()==t)t++;
			gs.pop();
		}
		g[i]=t;
	}
	
	int j=0,k=0,l=0,m=0;
	reg(i,0,n){
		printf("%d%c",g[i],i%a==0?'|':' '); continue;
		if(i%a==0)continue;
		j++;
		printf("%d%c",g[i],j%a==0?'|':' '); continue;
		if(j%a==1)continue;
		k++;
		//printf("%d%c",g[i],k%a==1?'|':' '); continue;
		if(k%a==1)continue;
		l++;
		printf("%d%c",g[i],l%a==1?'|':' '); continue;
		if(l%a==1)continue;
		m++;
		//printf("%d%c",g[i],m%a==1?'|':' '); continue;
	}
}


lli calc(lli a,lli k){
	
	//printf("%lld %lld\n",a,k);
	if(a%k==0)return a/k;
	if(a<k)return 0;
	/*
	if(a<=(k-1)*k){
		lli t=a/k;
		if((a%k)%(t+1)==0)return t;
		else return calc((t-2)*k+(a%k)%(t+1)+k%(t-1),k);
	}
	*/
	
	lli r=(a%k)/(a/k+1);
	if(r<=10)return calc(a-a/k-1,k);
	else return calc(a-r*(a/k+1),k);
}

int n;
int main(void){
	/*
	test(6,20); 
	puts("");
	reg(i,0,120){
		printf("%lld%c",calc(i,6),((i%6==0)?'|':' '));
	}
	return 0;
	*/
	
	lli g=0;
	scanf("%d",&n);
	rep(i,n){
		lli a,k;
		scanf("%lld%lld",&a,&k);
		//printf("%lld %lld : %lld\n",a+1,k,x);
		//printf("%lld ", calc(a,k));
		g ^= calc(a,k);
	}
	puts((g!=0)?"Takahashi":"Aoki");
	return 0;
}






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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (const auto& x : mp) mx = max(mx, x.second);
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        if (it->second == mx) cout << it->first << endl;
        else continue;
    }
    return 0;
}



Measured memory_bytes: 25216
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

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

typedef long long ll;

const ll mod = 1e9+7;
const int MAX = 100005;
const int N = 2;

ll dp[N][MAX];

int a[105];

ll sum(ll a ,ll b){
    return (a+b)%mod;
}

ll sub(ll a, ll b){
    return (a-b+mod)%mod;
}

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

    int acum = 0;
    for(int i = 0; i<N; ++i){
        dp[i][0] = 1;
    }

    int ii;
    for(int i = 1; i<=n; ++i){
        ii = i&1;
        acum+=a[i];
        for(int j = 1; j<= acum && j<= k; ++j){
            dp[ii][j] = sum(dp[ii^1][j], dp[ii][j-1]);
            if(j>a[i]){
                dp[ii][j] = sub(dp[ii][j], dp[ii^1][j-a[i]-1]);
            }
        }
    }
    cout<<dp[n&1][k]<<"\n";
}


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

using ll=long long;
struct Edge{
    int u,v;
    ll cost;
};
using Edges=vector<Edge>;

struct UnionFind{
    int N;
    vector<int> par;
    vector<int> rank;
    public:
    UnionFind(int n):N(n),par(n),rank(n){
        iota(par.begin(),par.end(),0);
    }
    int find(int x){
        if(par[x]==x) return x;
        else return par[x]=find(par[x]);
    }
    void unite(int x,int y){
        x=find(x),y=find(y);
        if(x==y) return;
        if(rank[x]>rank[y]){
            par[y]=x;
        }
        else{
            if(par[x]==par[y]) rank[y]++;
            par[x]=y;
        }
    }
};

bool cmp(Edge lhs,Edge rhs){
    return lhs.cost<rhs.cost;
}
int main(){
    int n,m;
    cin>>n>>m;
    int k;
    cin>>k;
    vector<int> c(n);
    for(int i=0;i<n;i++) cin>>c[i],c[i]--;
    Edges edges;
    int id=k;
    map<int,int> mp;
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--,v--;
        ll w;
        cin>>w;
        if(c[u]==-1){
            if(mp.count(u)) u=mp[u];
            else u=mp[u]=id++;
        }
        else u=c[u];
        if(c[v]==-1){
            if(mp.count(v)) v=mp[v];
            else v=mp[v]=id++;
        }
        else v=c[v];
        edges.push_back(Edge{u,v,w});
    }
    
    sort(edges.begin(),edges.end(),cmp);
    UnionFind uf(n+k);
    int cnt=0;
    ll res=0;
    for(auto e:edges){
        if(cnt==k-1) break;
        int u=uf.find(e.u),v=uf.find(e.v);
        if(u==v) continue;
        else{
            cnt++;
            uf.unite(u,v);
            res+=e.cost;
        }
    }
    if(cnt==k-1){
        cout<<res<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 8432