akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
V ans;
pq que;
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    cnt=1;
    rep(i,n)cnt*=2;
    rep(i,cnt)cin>>a[i];
    sort(a,a+cnt);
    reverse(a,a+cnt);
    ans.p_b(a[0]);
    multiset<ll> st;
    U_MAP mp;
    st.insert(-LINF);
    rrep(i,1,cnt){
        st.insert(a[i]);
        mp[a[i]]++;
    }
    rep(i,n){
        V tmp;
        rep(j,Size(ans)){
            tmp.p_b(ans[j]);
        }
        rep(j,Size(tmp)){
            ll to;
            auto it=st.lower_bound(tmp[j]);
            it--;
            to=*it;
            if(to==-LINF){
                Cout("No");
                return 0;
            }
            ans.p_b(to);
            mp[to]--;
            if(mp[to]==0)st.erase(to);
        }
    }
    Cout("Yes");
    return 0;
}


Measured memory_bytes: 34036
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  if(N<11){
    cout<<"Yes"<<endl;
  }else if(N==12||N==14||N==15||N==16||N==18||N==20||N==21){
    cout<<"Yes"<<endl;
  }else if(N==24||N==25||N==27||N==28||N==30||N==32||N==35||N==36){
    cout<<"Yes"<<endl;
  }else if(N==40||N==42||N==45||N==48||N==49||N==54||N==56||N==63){
       cout<<"Yes"<<endl;
  }else if(N==64||N==72||N==81){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
N = int(input())

dics = {}

for i in range(N):
    si = input()
    if si in dics.keys():
        dics[si] += 1
    else:
        dics[si] = 1

dic2 = sorted(dics.items(), key=lambda x:x[1], reverse=True)

# print(dic2)

endlist = []

kmax = dic2[0][1]
for kt in dic2:
    v = kt[1]
    if v == kmax:
        endlist.append(kt[0])
    else:
        break

slist = sorted(endlist, key=str.lower)
for s in slist:
    print(s)
    

Measured memory_bytes: 59996
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N;

signed main()
{
	cin >> N;
	vi A(N);
	rep(i, N) cin >> A[i];

	int l = 0, r = 1; // [l, r]

	int Xor = A[0], Sum = A[0]; // [l, r) の xor, sum;

	int ans = 0;

	while (l < N) {
		while (r < N and (Xor ^ A[r]) == (Sum + A[r])) {
			Xor ^= A[r];
			Sum += A[r];
			r++;
		}

		int len = r - l;

		ans += len;

		Xor ^= A[l];
		Sum -= A[l];
		
		l++;
	}

	cout << ans << endl;
}




Measured memory_bytes: 4820
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int D,T,S;

int main(){
    cin>>D>>T>>S;

    if(T*S>=D) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>

#define NIL -1
#define MAX 101

void BFS(int, int);
void Enqueue(int*,int);
int Dequeue(int*);

int Adj[MAX][MAX];
int D[MAX], F[MAX];
int C[MAX]={0};
int count = 1;
int head = 0, tail = 0;

int main(void){
  int i, j, n, u, k, v;

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

  for(i=1; i<n+1; i++){
    scanf("%d%d", &u, &k);
    for(j=1; j<k+1; j++){
      scanf("%d", &v);
      Adj[i][v] = 1;
    }
  }

  /* A.c
  for(i=1; i<n+1; i++){
    for(j=1; j<n+1; j++){
      if(j == n) printf("%d\n", Adj[i][j]);
      else printf("%d ", Adj[i][j]);
    }
    }*/

  BFS(1,n);

  for(i=1; i<n+1; i++) printf("%d %d\n", i, D[i]);

  return 0;
}

void BFS(int i, int n){
  int j, u;

  for(j=1; j<n+1; j++){
    C[j] = 0;
    D[j] = NIL;
  }

  C[i] = 1; D[i] = 0;
  Enqueue(F, i);

  while(head != tail){
    u = Dequeue(F);
    for(j=1; j<n+1; j++){
      if(Adj[u][j] == 1){
        if(C[j] == 0){
          C[j] = 2;
          D[j] = D[u]+1;
          Enqueue(F, j);
        }
      }
    }
    C[u] = 1;
  }

  return;
}

void Enqueue(int *F, int i){

  F[tail]=i;
  tail++;

  return;
}

int Dequeue(int *F){

  head++;
  return F[head-1];
}

Measured memory_bytes: 636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main()
{
	int n, k;
	cin >> n >> k;
	int n1;
	REP(i, n)
	{
		int t;
		cin >> t;
		if (t == 1) n1 = i + 1;
	}
	int r = n - n1;
	int l = n - r - 1;
	//cout << (l - (r % (k - 1)) + 1) / (k - 1) + (r + 1) / (k - 1) << endl;
	cout << (n-1) / (k-1) + ((n - k) % (k-1) > 0 ? 1 : 0) << endl;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>

int main(void){
    int a, b;
    std::cin >> a >> b;
    if(a >= 13) std::cout << b << std::endl;
    else if(a <= 5) std::cout << 0 << std::endl;
    else std::cout << b / 2 << std::endl;
    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef node* Node;
#define NIL NULL
 
node array[500000];
int size=0;
 
Node root = NIL;
  
Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}
  
Node treeSearch(Node u, int k){
  Node i=u;
  while(i!=NIL){
    if(i->key==k)return i;
    else if(i->key<k)i=i->right;
    else i=i->left;     
  }
  return NIL;
}
  
Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
  
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
    
  if(y->left!=NIL)x=y->left;
  else x=y->right;
  
  if(x!=NIL)x->parent=y->parent;
    
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;
  
  if(y!=z)z->key=y->key;
    
  //free(y);
}
  
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = &array[size++];
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;   
}
 
 
void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
 
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
 
 
int main(){
  int n,x;
  char str[20];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s", str);
    if(str[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if (t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }
 
  return 0;
}



Measured memory_bytes: 15180
n, m = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
x, y = Array.new(m) { gets.split.map(&:to_i) }.transpose

ufind = [*0..n]
rank = Array.new(n + 1) { 0 }

def root(ufind, idx)
  ufind[idx] == idx ? idx : (ufind[idx] = root(ufind, ufind[idx]))
end

x.zip(y) do |bx, by|
  bx = root(ufind, bx)
  by = root(ufind, by)

  next if bx == by

  if rank[bx] > rank[by]
    ufind[by] = bx
  else
    ufind[bx] = by
    rank[by] += 1 if rank[bx] == rank[by]
  end
end

puts 1.upto(n).count { |i| root(ufind, i) == root(ufind, p[i - 1]) }

Measured memory_bytes: 25896
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

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

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin>>N;
	map<LL,LL> num;
	LL sum = 0;
	LL A;
	LL ans = 0;
	num[0]++;
	for(int i=0;i<N;++i){
		cin>>A;
		sum += A;
		LL count = num[sum];
		ans += count;
		num[sum]++;
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 12800
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int[] iru = new int[n];
		for (int i = 0; i < n; i++) {
			iru[a[i]]++;
		}
		long count = 1;
		long mod = 1000000007;
		if (n % 2 == 0) {
			for (int i = 1; i < n; i += 2) {
				if (iru[i] != 2) {
					count = 0;
				} else {
					count *= 2;
					count %= mod;
				}
			}
		} else {
			if (iru[0] != 1) {
				count = 0;
			}
			for (int i = 2; i < n; i += 2) {
				if (iru[i] != 2) {
					count = 0;
				} else {
					count *= 2;
					count %= mod;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 49688
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	x := make([]int, n)
	for i := range x {
		sc.Scan()
		x[i], _ = strconv.Atoi(sc.Text())
	}

	k--
	ans := 1000000000
	for i := 0; i+k < n; i++ {
		d := x[i+k] - x[i]
		if v := abs(x[i]) + d; v < ans {
			ans = v
		}
		if v := abs(x[i+k]) + d; v < ans {
			ans = v
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2944
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long[] h = new long[N];
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextLong();
		}
		Arrays.sort(h);
//		System.out.println(Arrays.toString(h));
		
		long diff = 10000000000L;
		int start = 0;
		long d = 0;
		while(start + K <= N) {
			d = h[start+K-1] - h[start];
			if( d < diff ) {
				diff = d;
			}
			start++;
		}
		
		System.out.println(diff);
		

		sc.close();
	}
}


Measured memory_bytes: 59308
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

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

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

const int MAX_V = 100005;
vec v[MAX_V*3];
bool visited[MAX_V*3];


int main(){
    int n, m;
    cin >> n >> m;
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].push_back(b+MAX_V);
        v[a+MAX_V].push_back(b+2*MAX_V);
        v[a+2*MAX_V].push_back(b);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;
    // cout << 1 << endl;
    queue<P> que;
    que.push(P(s, 0));
    visited[s] = true;
    while(que.size() > 0){
        P p = que.front();
        que.pop();
        int e = p.first;
        int c = p.second;
        if(e == t){
            cout << c / 3 << endl;
            return 0;
        }
        rep(i, v[e].size()){
            if(visited[v[e][i]]) continue;
            visited[v[e][i]] = true;
            que.push(P(v[e][i], c + 1));
        }
        // cout << 1 << endl;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 20240
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
ll dp[101][100001];

ll solve(int i, int j, int A[]){
    if(j<0) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    if(i==1 && j>A[i-1]) return 0;
    if(i==1 && j<=A[i-1]) return 1;
    
    ll op=0;
    
    dp[i][j]=(mod+solve(i,j-1,A)+solve(i-1,j,A)-solve(i-1,j-A[i-1]-1,A))%mod;
    return dp[i][j];
 /*   for(ll k=0;k<=A[i-1] && j-k>=0;k++){
        //solve(i-1,j-k,A);
        op+=solve(i-1,j-k,A);
        //dp[i-1][j-k+1]-dp[i-2][j-k+1]+dp[i-2][k-1-A[i-2]];
        op%=mod;
    }
    return dp[i][j]=op;   */
    
}

int main(){
    int n, k; cin>>n>>k;
    int A[n];
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++) cin>>A[i];
    cout<<solve(n,k,A);
 /*   for(int i=0;i<101;i++){
        for(int j=0;j<1001;j++){
            cout<<dp[i][j]<<" ";
        }cout<<"\n";
    }    */
}

Measured memory_bytes: 90312
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin>>N;
  vector<P> a(N);
  rep(i,N){
    ll s, t; cin>>s>>t;
    //firstを右手にする
    a[i].first = s + t;
    a[i].second = s - t;
  }
  SORT(a);

  ll t = -INF-INF;
  ll ans = 0;
  //終了が早い方から見ていく
  for(ll i = 0; i < N; i++){
    if(t <= a[i].second){
      ans++;
      t = a[i].first;
      // cout<<t<<endl;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll K, T;

    cin >> K >> T;

    vector<ll> A(T);
    FOR(i, 0, T){
        cin >> A[i];
    }
    sort(ALL(A));
    ll max_num = A.back();
    ll rest = K - max_num;

    ll a = max(2*max_num - K - 1, 0LL);
    p(a);
    
    return 0;
}

Measured memory_bytes: 256
def main():
    x, y, a, b, c = map(int, input().split())
    p = sorted([int(v) for v in input().split()])[-x:]
    q = sorted([int(v) for v in input().split()])[-y:]
    r = [int(v) for v in input().split()]
    r.extend(p)
    r.extend(q)
    print(sum(sorted(r)[-(x+y):]))


if __name__ == '__main__':
    main()


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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    string s;
    cin >> s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7') puts("Yes");
    else puts("No");

    return 0;
}











Measured memory_bytes: 3620
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

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

  string S;
  cin >> S;

  ll Q;
  cin >> Q;

  bool reversed = false;

  deque<char> deque;
  for (auto s : S) {
    deque.push_back(s);
  }

  for (ll i = 0; i < Q; i++) {
    ll q;
    cin >> q;

    if (q == 1) {
      reversed = !reversed;
    } else {
      ll f;
      char c;
      cin >> f >> c;

      if (f == 1) {
        if (reversed) {
          deque.push_back(c);
        } else {
          deque.push_front(c);
        }
      } else {
        if (reversed) {
          deque.push_front(c);
        } else {
          deque.push_back(c);
        }
      }
    }
  }

  if (reversed) {
    reverse(deque.begin(), deque.end());
  }

  string ans;
  for (auto s : deque) {
    ans.push_back(s);
  }

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

Measured memory_bytes: 1368
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const ll INF = 1000000000000000000;

ll N, K, ans;
vector<ll> H;

int main() {
    cin >> N >> K;
    for(int i=0; i<N; i++){
        ll h;
        cin >> h;
        H.push_back(h);
    }
    sort(H.begin(), H.end(), greater<ll>());

    for(int i=K; i<N; i++){
        ans += H[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 2420
use proconio::input;

fn main() {
    input! {
        n: usize,
        _l: usize,
    }

    let mut s: Vec<String> = Vec::new();
    for _ in 0..n {
        input! {
            t: String,
        }
        s.push(t);
    }

    s.sort();
    for i in 0..n {
        print!("{}", s[i]);
    }
    println!("");
}


Measured memory_bytes: 2104
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

	long long K;
	cin >> K;

	int cnt1 = 0;
	for(int i=0; S[i]=='1'; i++)
		cnt1++;

	char ret;
	if(cnt1 >= K)
		ret = '1';
	else
		ret = S[cnt1];

	cout << ret << endl;
	
	return 0;
}


Measured memory_bytes: 256
n = int(input())

a = [list(map(int,input().split())) for i in range(2)]

total = 0
st_num = 0
max_num = 0
for i in range(n):
    st_num += a[0][i]
    for j in range(i,n):
        total += a[1][j]
    if max_num < st_num+total:
        max_num = st_num+total
    total = 0
print(max_num)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
using namespace std;

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

void Main()
{
	string s;
	cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size()-1] << endl;
}

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

	Main();
	return 0;
}

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size) rep(show_it, size) std::cout << a[show_it] << " \n"[show_it == show_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
  const int MOD = 10007;
  int table[255] = {};
  table['J'] = 1;
  table['O'] = 2;
  table['I'] = 4;

  int N;
  string s;

  cin >> N >> s;
  vector<vector<int> > dp(N + 1, vector<int>(8, 0));
  // dp[日数][出席状況のビット] == その状況になる通り数
  // dp[D][B if B & Sd != 0] += dp[D - 1][Bn if Bn & B != 0]
  dp[0][1] = 1;
  lep(d, N){
    rep(b, 8){
      if ((b & table[s[d - 1]]) == 0) continue;
      rep(pb, 8){
        if ((b & pb) == 0) continue;
        dp[d][b] += dp[d - 1][pb];
        dp[d][b] %= MOD;
      }
    }
  }
  int count = 0;
  rep(b, 8){
    count += dp[N][b];
    count %= MOD;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1288
# AGC033A - Darker and Darker
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.distance_transform_cdt.html
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Measured memory_bytes: 55652
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;


namespace ABC108A
{
    class Class1
    {
        static void Main()
        {
            var K = int.Parse(Console.ReadLine());
            if (K % 2 == 0)
            {
                Console.WriteLine((K / 2) * (K / 2));
            }
            else
            {
                Console.WriteLine(((K - 1) / 2) * ((K + 1) / 2));
            }
        }
    }
}

Measured memory_bytes: 11092
import java.util.Scanner

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val m = sc.nextInt

  val a = Array.fill(n)(sc.next).map(_.toCharArray)
  val b = Array.fill(m)(sc.next).map(_.toCharArray)

  run()

  def run(): Unit = {
    val l = n - m + 1
    val exists = 0.until(l * l).exists(k => {
      val i = k / l
      val j = k % l
      isMatch(i, j)
    })

    val ans = if(exists) "Yes"
    else "No"

    println(ans)

  }

  def isMatch(i: Int, j: Int): Boolean = {
    0.until(m * m).forall(k => {
      val i1 = k / m
      val j1 = k % m
      a(i + i1)(j + j1) == b (i1)(j1)
    })
  }
}


Measured memory_bytes: 22340
#include<iostream>

using namespace std;

int main(){
	int n;
	cin>>n;
	int cnt1[1000000];
	int cnt2[1000000];
	for(int i=0;i<1000000;i++){
		cnt1[i]=0;
		cnt2[i]=0;
	}
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(i%2==0)cnt1[x]++;
		else cnt2[x]++;
	}
	int m1,m11,m2,m22;
	m1=0;
	m11=0;
	m2=0;
	m22=0;
	for(int i=0;i<1000000;i++){//cout<<cnt1[i]<<" "<<cnt2[i]<<endl;
		if(cnt1[m1]<=cnt1[i]){
			m11=m1;
			m1=i;
		}else if(cnt1[m11]<=cnt1[i]){
			m11=i;
		}
		if(cnt2[m2]<=cnt2[i]){
			m22=m2;
			m2=i;
		}else if(cnt2[m22]<=cnt2[i]){
			m22=i;	
		}
	}
	if(m1!=m2){
		cout<<n-cnt1[m1]-cnt2[m2]<<endl;
		return 0;
	}
	//if(m1!=0 && m2!=0){
		//cout<<m1<<" "<<m11<<" "<<m2<<" "<<m22<<endl;
		cout<<min(n-cnt1[m11]-cnt2[m2],n-cnt1[m1]-cnt2[m22])<<endl;
		return 0;
	/*}
	if(m1!=0){
		cout<<min(n-cnt1[m11]-cnt2[m2],n-cnt1[m1]
		return 0;
	}
	if(m2!=0){
		
		return 0;
	}
	cout<<n/2<<endl;
	*/
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int main()
{
    using ll = long long;
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    ll x = n * (n+1) / 2;
    if(sum % x != 0)
    {
        cout << "NO" << endl;
        return 0;
    }
    ll y = sum / x;
    for(int i = 0; i < n; i++)
    {   ll cand = 0;
        cand = a[i+1] - a[i];
        if(i == n-1)
        {
          cand = a[0]-a[i];
        }
        cand -= y;
        if(cand % n != 0 || cand > 0)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;

string num[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

int main(int argc, char **argv)
{
	string str;
	int sum = 0;
	
	while(cin >> str){
		int n = str.size();
		for(int i = 0, f = 0; i < n; f = 0){
			string s = str.substr(i, 1);
			string st = "";
			for(int j = 0; j < 10 && i < n;){
				if(s == num[j]){
					st += s;
					i++;
					f = 1;
					s = str.substr(i, 1);
					j = 0;
				} else {
					j++;
				}
			}
			sum += atoi(st.c_str());
			if(f == 0){
				i++;
			}
		}
	}
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 0
#include <queue>
#include <cstdio>

using namespace std;

int main()
{
	char Query[7]; int Number;

	priority_queue<int> que;

	while (Query[2] != 'd')
	{
		scanf("%s", Query);

		if (Query[0] == 'i') { scanf("%d", &Number); que.push(Number); }
		if (Query[1] == 'x') { printf("%d\n", que.top()); que.pop(); }
	}

	return 0;
}

Measured memory_bytes: 6544
#include <cstdio>
int main(){
int a, b, c, i;
scanf("%d%d%d", &a, &b, &c);
for (i = c; i < 3600; i += 60)
if (0 <= i % (a + b) && i % (a + b) <= a)
break;
printf("%d\n", (i > 3599 ? -1 : i));
return 0;
}

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

char rev(char c){
	if(c == 'R'){
		return 'B';
	}
	else{
		return 'R';
	}
}

int main(){
	int N, i, j;
	string T;
	scanf("%d", &N);
	vector<char> ans(2 * N + 1);
	printf("? ");
	for(i = 1; i <= N; i++){
		printf("%d ", i);
	}
	printf("\n");
	fflush(stdout);
	cin >> T;
	char T0 = T[0];
	int l = 1, h, r = N + 1;
	while(r - l > 1){
		h = (l + r) / 2;
		printf("? ");
		for(i = 0; i < N; i++){
			printf("%d ", h + i);
		}
		printf("\n");
		fflush(stdout);
		cin >> T;
		if(T[0] == T0){
			l = h;
		}
		else{
			r = h;
		}
	}
	ans[l] = T0;
	ans[l + N] = rev(T0);
	for(i = 1; i < l; i++){
		printf("? ");
		printf("%d ", i);
		for(j = l + 1; j < l + N; j++){
			printf("%d ", j);
		}
		printf("\n");
		fflush(stdout);
		cin >> T;
		ans[i] = T[0];
	}
	for(i = r + N; i <= 2 * N; i++){
		printf("? ");
		printf("%d ", i);
		for(j = l + 1; j < l + N; j++){
			printf("%d ", j);
		}
		printf("\n");
		fflush(stdout);
		cin >> T;
		ans[i] = T[0];
	}
	for(i = l + 1; i < l + N; i++){
		printf("? ");
		printf("%d ", i);
		for(j = 1; j < l; j++){
			printf("%d ", j);
		}
		for(j = r + N; j <= 2 * N; j++){
			printf("%d ", j);
		}
		printf("\n");
		fflush(stdout);
		cin >> T;
		ans[i] = T[0];
	}
	printf("! ");
	for(i = 1; i <= 2 * N; i++){
		printf("%c", ans[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    int p, q, r;
    cin >> p >> q >> r;
    cout << min({p+q, q+r, r+p}) << endl;
    return 0;

    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for( int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
#define INF 1000000
using lli = long long int;
using ulli = unsigned long long int;
typedef pair<int, int> P;

struct edge{ int u, v; lli cost; };
struct DirectedGraph
{
  int vertex_num;
  int edge_num;
  vector<edge> edge_list;
  vector< vector<int> > adj_list;
	vector< vector<lli> > distance_matrix;
};

// rand settings
std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<int> randint25(0, 25); // []
std::uniform_real_distribution<double> rand_01(0.0, 1.0); // uniform distribution [0, 1]

template <typename T>
vector<int> argsort(const vector<T> &v) {

  // initialize original index locations
  vector<int> idx(v.size());
  iota(idx.begin(), idx.end(), 0);

  // sort indexes based on comparing values in v
  sort(idx.begin(), idx.end(),
       [&v](int i1, int i2) {return v[i1] < v[i2];});

  return idx;
}

template<typename T>
void displayVector(vector<T> v)
{
	lli n = v.size();
	REP(i,n){
		cout << v[i] << " " ;
	}
	cout << endl;
}

// SA parameter
double Tinit = 10000.0; // start temprature
double alpha = 0.9; // exponential coolong parameter


double Eval(vector<int> x, vector< vector<int> > A){
  double score = 0;
	REP(d, x.size() ){
		score += A[d][ x[d] ];
	}
	return -score;
}

double State_Prob(double dE, double T){
  if(dE <= 1){
    return 1.0;
  }
  else{
    return exp(-dE/T);
  }
}


vector<int> Neighbor( vector<int> x )
{
	vector<int> res;
	uniform_int_distribution<int> randintD(0, x.size()-1);
	int change_num = 5;
	REP(i, change_num){
		x.at( randintD(mt) ) = randint25(mt);
	}

	return x;
}

vector<int> SA_Methd(vector<int> start, vector< vector<int> > A){
  vector<int> s = start; // state
  double e = Eval(s, A); // enegy
  vector<int> s_opt = s;
  double e_opt = e;
 	vector<int> s_next;
	double e_next;

  double T = Tinit; // temprature;

  while(T>1){
    // neighbor
    s_next = Neighbor(s);
    e_next  = Eval(s_next, A);

    if(e_next < e_opt){
      e_opt = e_next;
      s_opt = s_next;
    }

    if( rand_01(mt) < State_Prob(e_next-e, T) ){
      s = s_next;
      e = e_next;
    }

    T = alpha * T; // exponential cooling
  }

  return s_opt;
}



int main(){

	int D; cin >> D;
	vector<int> c(26);
	REP(i, 26){ cin >> c[i]; }

	vector< vector<int> > score(D);
	REP(i, D){
		score[i].resize(26);
		REP(j, 26){ cin >> score[i][j]; }
	}

	vector<int> state(D);
	REP(i, D){ state[i] = i%26; }

	state =  SA_Methd(state, score) ;
	REP(i, D){ cout << state[i]+1 << endl; }
	return 0;
}

Measured memory_bytes: 4292
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	string s,t;
	cin>>s>>t;
	cout<<(s[0]==t[0])+(s[1]==t[1])+(s[2]==t[2]);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 100000000
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

int r,n,x,y,h,B[41]; 
Circle C;

double sq(double a){ return a*a;}

bool Check(double ans){
  for(int i=1-C.r;i<C.r;i++){
    int index=i+20;
    int mh=min(B[index-1],B[index]);
    double d=sq(0.0-(double)i)+sq(ans-(double)mh);
    if(d<=(double)(C.r*C.r))return false;
  }
  return true;
}
 
int main()
{
  while(1){
    cin>>r>>n;
    if(r+n==0)break;
    C.c.x=0;C.c.y=0,C.r=r;
    for(int i=0;i<41;i++)B[i]=0;
    for(int i=0;i<n;i++){
      cin>>x>>y>>h;
      for(int j=x;j<y;j++)B[j+20]=max(B[j+20],h);
    }

    double ans=-r;
    for(double t=-r;t<=20.0;t+=0.0001){
      if(!Check(t)){
	break;
      }
      ans=t;
    }
    printf("%.10f\n",ans+r);
  }
  return 0;
}

Measured memory_bytes: 1196
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  int N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  ll sum = 0;
  rep(i, N) { sum += A[i]; }
  set<ll> candidates;
  for (int i = 1; i * i <= sum; ++i) {
    if (sum % i == 0) {
      candidates.insert(i);
      candidates.insert(sum / i);
    }
  }
  ll ans = 1;
  for (ll x : candidates) {
    ll need; // required operations
    {
      vector<ll> r(N);
      rep(i, N) { r[i] = A[i] % x; }
      sort(all(r));
      ll B = 0;
      rep(i, N) { B += x - r[i]; }
      ll A = 0;
      rep(i, N) {
        A += r[i];
        B -= x - r[i];
        // B - A changes x in each step.
        // B is dividable by x at first, so B - A becomes 0 in somewhere.
        if (A == B) { need = A; }
      }
    }
    if (need <= K) {
      ans = max(ans, x);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// D - Islands War
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using II = pair<int,int>;
using VII = vector<II>;

int solve(int N, int M, VII &V){
	sort(all(V));
	int ans = 0;
	int L = 0, R = 0;
	rp(i, 0, M){
		int l,r; tie(l,r) = V[i];
		if(R <= l){
			L = l, R = r;
			ans++;
		}
		else{
			if(L < l) L = l;
			if(R > r) R = r;
		}
	}
	return ans;
}

int main(){
	int N,M; cin>>N>>M;
	VII V;
	rp(i, 0, M){
		int a,b; cin>>a>>b;
		V.emplace_back(a,b);
	}
	cout<< solve(N,M,V) <<endl;
}

Measured memory_bytes: 1400
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int64 n, A, B;
  cin >> n >> A >> B;
  int64 m = A + B;
  int64 ret = n / m * A;
  n %= m;
  ret += min(n, A);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

int main(){
    llong N,Q;
    string str;
    cin >> N >> Q;
    cin >> str;
    vector<pair<llong, llong> > Query(Q);
    llong l,r;
    for(int i=0; i<Query.size(); i++){
        cin >> l >> r;
        Query[i].first =l;
        Query[i].second =r;
    }
    vector<llong> A(N, 0);
    vector<llong> S(N+1, 0);
    for(int i=0; i<str.size()-1; i++){
        if(str[i]=='A' && str[i+1]=='C'){
            A[i+1] = 1;
        }
    }
    for(int i=0; i<A.size(); i++){
        S[i+1] = S[i] + A[i];
    }
    for(int i=0; i<Query.size(); i++){
        cout << S[Query[i].second]-S[Query[i].first] << endl;
    }
    return 0;
}

//00:81 s

Measured memory_bytes: 6092
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  vector<ll> a(N);
  vector<ll> b(N);
  vector<ll> c(N);

  rep(i, N) cin >> a[i];
  rep(i, N) cin >> b[i];
  rep(i, N) cin >> c[i];
  SORT(a);
  SORT(b);
  SORT(c);

  vector<ll> bk(N);
  vector<ll> bsum(N);
  ll ans = 0;
  rep(i,N){
    // 小さい数の種類
    bk[i] = N - POSU(c, b[i]);
  }
  bsum[N - 1] = bk[N - 1];
  for(ll i = N - 2 ; i >= 0 ; i--){
    bsum[i] = bsum[i + 1] + bk[i];
  }
  rep(i,N){
    ll tmp = POSU(b, a[i]);
    ans += bsum[tmp];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4224
n = int(input())
a, d = map(int, input().split())
mem = {}


def get_mem(num):
    if num in mem:return mem[num]
    else:return num


m = int(input())
for _ in range(m):
  x, y, z = map(int, input().split())
  if x == 0:
    ny, nz = get_mem(y), get_mem(z)
    mem[y] = nz
    mem[z] = ny
  if x == 1:
    nz = get_mem(z)
    mem[y] = nz
k = get_mem(int(input()))
print(a + d * (k - 1))


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define mod 1000000007
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
bool vis[200005];
vector<int> vec[2000005], v1;
int child[2000005];
int parent[2000005];
int div1[100005];
int min_indx[200005];
int count1 = 0;
int height = 0;
int max_indx[200005];
void dfs(int node)
{

    vis[node] = 1;

    min_indx[count1] = node;
    max_indx[node] = min(max_indx[node], count1);
    count1++;

    //  count1++;
    child[node] = height++;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            min_indx[count1] = node;
            max_indx[node] = min(max_indx[node], count1);
            count1++;
        }
    }
    height--;
}
int MAXN = 200005;
int LOGMAXN = (int)log2(200005) + 1;
int M[200005][60];
int ans[200005];
void fun(int a, int b, int c)
{
    //ll val = 1;

    while (a <= b)
    {
        ans[a] += c;
        int p = -a;
        a += (a & p);
    }
}
int find1(int a)
{
    int sum = 0;
    while (a != 0)
    {
        sum += ans[a];
        int p = -a;
        a -= (a & p);
    }
    return sum;
}
void process2(int A[], int N)
{
    int i, j;

    for (i = 0; i < N; i++)
        M[i][0] = i;
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (find1(M[i][j - 1]) < find1(M[i + (1 << (j - 1))][j - 1]))
                M[i][j] = M[i][j - 1];
            else
                M[i][j] = M[i + (1 << (j - 1))][j - 1];
}
int arr1[1000005], arr2[1000005];
int32_t main()
{
    FAST;
    int a, b;
    cin >> a >> b;
    cout << 2 * b - a << "\n";

    return 0;
}

Measured memory_bytes: 50488
H,W,K=map(int,input().split())
C=[list(input()) for i in range(H)]
ans=0
M=0
for i in range(H):
    for j in range(W):
        if C[i][j]=='#':
            M+=1
for i in range(pow(2,H)):
    s=0
    h=[False]*H
    for k in range(H):
        if i>>k & 1:
            h[k]=True
            for x in range(W):
                if C[k][x]=='#':
                    s+=1   
    for j in range(pow(2,W)):
        s_temp=s
        for k in range(W):
            if j>>k & 1:
                for x in range(H):
                    if C[x][k]=='#' and not h[x]:
                        s_temp+=1
        if M-s_temp==K:
            ans+=1
print(ans)

Measured memory_bytes: 9184
S = input()
lenS = len(S)
maxl = 0

for i in range(lenS):
    for j in range(i, lenS):

        now = S[i:j+1]

        nowlist = list(now)
        newlist = [n for n in nowlist if n == 'A' or n == 'C' or n == 'G' or n == 'T']
        if len(newlist) == len(nowlist):
            maxl = max(maxl, len(now))
print(maxl)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n;
    string s;
    cin >> n >> s;
    int ans =0;
    rep(i,s.length()) {
        if (s.substr(i,3) == "ABC")
            ans ++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256