akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#define swap(type, x, y) {type tmp = x; x = y; y = tmp;}

typedef struct {
    char suit;
    int value;
} card;

int bubbleSort(card *a, int n) {
    int i, j, flag;
    j = 0; flag = 1;
    while (flag) {
        flag = 0;
        for (i = n - 1; i > j; i--) {
            if (a[i].value < a[i - 1].value) {
                swap(card, a[i], a[i - 1]);
                flag = 1;
            }
        }
        j++;
    }
    return 0;
}

int selectionSort(card *b, int n) {
    int i, j, mini;
    for (i = 0; i < n; i++) {
        mini = i;
        for (j = i; j < n; j++) {
            if (b[j].value < b[mini].value) mini = j;
        }
        if (i != mini) {
            swap(card, b[i], b[mini]);
        }
    }
    return 0;
}

int main(void) {
    int N;
    scanf("%d", &N);
    card C[N];
    card A[N];
    card B[N];
    int idx;

    for (idx = 0; idx < N; idx++) {
        getchar();
        scanf("%c %d", &C[idx].suit, &C[idx].value);
        A[idx].suit = C[idx].suit;
        A[idx].value = C[idx].value;
        B[idx].suit = C[idx].suit;
        B[idx].value = C[idx].value;
    }
    bubbleSort(A, N);
    selectionSort(B, N);

    for (idx = 0; idx < N; idx++) {
        printf("%c%d", A[idx].suit, A[idx].value);
        if (idx < N - 1) printf(" ");
    }
    printf("\n");
    printf("Stable\n");

    int fg = 1;
    for (idx = 0; idx < N; idx++) {
        printf("%c%d", B[idx].suit, B[idx].value);
        if (idx < N - 1) printf(" ");
        if (A[idx].suit != B[idx].suit || A[idx].value != B[idx].value) {
            fg = 0;
        }
    }
    printf("\n");

    if (fg) printf("Stable\n");
    else printf("Not stable\n");

    return 0;
}


Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//nの約数を返す関数.sortされてない.
vector<long long int> divisors(long long int n){
	vector<long long int> res;
	for (long long int i = 1; i * i <= n;i++){
		if (n % i == 0){
			res.push_back(i);
			if(i * i != n){
				res.push_back(n / i);
			}
		}
	}
	return res;
}

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

	return 0;
}




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

int search(vector<int>& a,int n,int key){
    int i=0;
    a[n]=key;
    while(a[i]!=key) i++;
    return i!=n;
}

int main(){
    int n,q;
    cin>>n;
    vector<int> s(n+1,0);
    rep(i,n) cin>>s[i];
    cin>>q;
    int key;
    int ans=0;
    rep(i,q){
        cin>>key;
        if(search(s,n,key)) ans++;
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x; cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n,vector<int>(m));
  
  int min_money = 999999999;
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= m; j++){
      if(j == 0)
        cin >> c.at(i);
      else
        cin >> a.at(i).at(j-1);
    }
  }
  
  for(int tmp = 0; tmp < (1 << 12); tmp++){
    vector<int> understand(m,0);
    bitset<12> s(tmp);
    int money = 0;
    
    for(int i = 0; i < n; i++){
      if(s.test(i)){
        money += c.at(i);
        for(int j = 0; j < m; j++){
          understand.at(j) += a.at(i).at(j);
        }
      }
    }
    
    bool achive = true;
    for(int i = 0; i < m; i++) 
      if(understand.at(i) < x) achive = false;
    
    if(achive){
      if(min_money > money)
        min_money = money;
    }
    money = 0;
  }
  if(min_money == 999999999)
    cout << -1;
  else
  	cout << min_money;
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 1005
#define int long long
using namespace std;
int n,m,dp[li][li];
char A[li][li];
bool ok(int a,int b){
	if(a>=1 && a<=n && b>=1 && b<=m && A[a][b]!='#') return true;
	return false;
}
inline int add(int a,int b){
	if(a+b>=md) return a+b-md;
	return a+b;
}
int dfs(int x,int y){
	int cev=0;
	if(x==n && y==m) return 1;
	if(~dp[x][y]) return dp[x][y];
	if(ok(x+1,y)) cev=add(cev,dfs(x+1,y));
	if(ok(x,y+1)) cev=add(cev,dfs(x,y+1));
	return dp[x][y]=cev;
}
main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf(" %c",&A[i][j]);
		}
	}
	int ty=dfs(1,1);
	printf("%lld\n",ty);
	return 0;
}




Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
 
  if (N * A < B) { cout << N * A << endl; }
  else {cout << B << endl; }
  // ここにプログラムを追記
  // op は+, −, ∗, /, ?, =, !のいずれか一つ

}

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

typedef struct {
  char M;
  int N;
} Card;

void swap(Card *a,Card *b){
  Card tmp;
  tmp=*a;
  *a=*b;
  *b=tmp;
}
void BubbleSort(Card *s,int n){
  int j,i;
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(s[j].N<s[j-1].N) swap(&s[j],&s[j-1]);
    }
  }
}

void SelectionSort(Card *d,int n){
  int i,j,min;
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(d[j].N<d[min].N) min=j;
    }
    swap(&d[i],&d[min]);
  }
}

int Stable(Card *s,Card *d,int n){
  int i;
  for(i=0;i<n;i++){
    if(s[i].M!=d[i].M) return 0;
  }
  return 1;
}
	
	

int main(){
  int n,i;
  Card s[40],d[40];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c%d",&s[i].M,&s[i].N);
    d[i]=s[i];
  }
  BubbleSort(s,n);
  SelectionSort(d,n);
  for(i=0;i<n;i++){
    if(i) printf(" ");
    printf("%c%d",s[i].M,s[i].N);
  }
  printf("\nStable\n");
  for(i=0;i<n;i++){
    if(i) printf(" ");
    printf("%c%d",d[i].M,d[i].N);
  }
  if(Stable(s,d,n)) printf("\nStable\n");
  else printf("\nNot stable\n");
  return 0;
}
  



Measured memory_bytes: 2028
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    int cntn = 0, cntm = 0;
    for (int i = 0; i < n + m;i++){
        if(i%2==0){
            cout << s[cntn];
            cntn++;
        }
        if(i%2==1){
            cout << t[cntm];
            cntm++;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int cat_flag[1001];
int cat[101];
int stack[1001];
int sp;

void push(int c)
{
    stack[sp++] = c;
}

int pop(void)
{
    if (sp == 0){
        return (-9999);
    }
    return (stack[--sp]);
}

int main(void)
{
    int L;
    int c;
    int output;
    int i;
    
    scanf("%d", &L);
    
    for (i = 1; i <= L; i++){
        scanf("%d", &cat[i]);
    }
    
    output = 0;
    for (i = 1; i <= L; i++){
        if (cat[i] > 0){
            if (cat_flag[cat[i]] != 0){
                output = i;
                break;
            }
            cat_flag[cat[i]] = 1;
            push(cat[i]);
        }
        else {
            c = cat[i] * -1;
            if (c != pop()){
                output = i;
                break;
            }
            cat_flag[c] = 0;
        }
    }
    
    if (output == 0){
        printf("OK\n");
    }
    else {
        printf("%d\n", output);
    }
    
    return (0);
}



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

int main(){
	string s;
	map<string,int> m;
	int maxi = 0;
	int maxu = 0;
	string ansi;
	string ansu;
	while(cin >> s){
		m[s]++;
		if(maxi < m[s]){
			maxi = m[s];
			ansi = s;
		}
		if(maxu < s.size()){
			maxu = s.size();
			ansu = s;
		}
	}
	cout << ansi << " " << ansu << endl;
	return 0;
}


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

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = Integer.parseInt(sc.nextLine());
			int[] W = Arrays.stream(sc.nextLine().split(" ")).mapToInt(r -> Integer.parseInt(r)).toArray();

			int min = Integer.MAX_VALUE / 2;
			int pre_sum = W[0];
			int post_sum = Arrays.stream(W).sum() - W[0];
			for (int i = 1; i < N; i++) {
				pre_sum += W[i];
				post_sum -= W[i];
				min = Math.min(min, Math.abs(pre_sum - post_sum));
			}
			System.out.println(min);
		}
	}
}

Measured memory_bytes: 31052
n = int(input())
p = list(map(lambda x: int(x)-1,input().split()))
ans = 0
for i in range(n-1):
    if p[i]==i:
        p[i],p[i+1] = p[i+1],p[i]
        ans += 1
if p[-1]==n-1:ans+=1
print(ans)

Measured memory_bytes: 13880
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	int tmp;
	vector<int> city(N);
	for (int i = 0; i < M * 2; i++) {
		cin >> tmp;
		city[tmp - 1]++;
	}

	for (const auto &elem : city) {

		cout << elem << "\n";
	}
	return 0;
}

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

int main(void){
    int n, m;
    cin>>n>>m;
    int ans=(n-1)*(m-1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

  while(1){
    int n,sum=0,k;
    cin >> n;
    if(!n) break;
    k = n*(n-1)/2;
    while(k--){
      int c;
      cin >> c;
      sum += c;
    }

    cout << sum / (n-1) << endl;
  }

  return 0;
}
    

Measured memory_bytes: 0
string = list(input())
length = len(string)
l = list()
if length % 2 ==0:
    for i in range (int(length/2),length):
        l.append(string[i])
    l.reverse()
else:
    for i in range (int(length/2)+1,length):
        l.append(string[i])
    l.reverse()
result = 0
for i in range(len(l)):
    if not l[i] == string[i]:
        result = result + 1
print(result)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#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;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> dp(n + 1);
  vector<bool> visit(n);
  dp[0] = 1;
  while (m--) {
    int x;
    scanf("%d", &x);
    visit[x] = true;
  }
  for (int i = 1; i <= n; ++i) {
    if (visit[i]) continue;
    if (i - 1 >= 0) dp[i] = (dp[i] + dp[i - 1]) % MOD;
    if (i - 2 >= 0) dp[i] = (dp[i] + dp[i - 2]) % MOD;
  }
  printf("%d\n", dp[n]);
  return 0;
}


Measured memory_bytes: 640
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}

void main()
{
  string s; readV(s);
  string t; readV(t);

  auto ns = s.length.to!int, nt = t.length.to!int;
 loop: foreach_reverse (i; 0..ns-nt+1) {
    auto u = s.dup;
    foreach (j; 0..nt) {
      if (u[i+j] == '?') {
        u[i+j] = t[j];
      } else {
        if (u[i+j] != t[j]) continue loop;
      }
    }

    foreach (ref ui; u)
      if (ui == '?') ui = 'a';
    writeln(u);
    return;
  }

  writeln("UNRESTORABLE");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> tri;

int main(){
  int M,T,P,R;
  int m,t,p,x;
  int wa[55][55], ac[55];
  int sum[55];

  while(cin >> M >> T >> P >> R, M){
    memset(wa,0,sizeof(wa));
    memset(ac,0,sizeof(ac));
    memset(sum,0,sizeof(sum));

    for(int i=0;i<R;i++){
      cin >> m >> t >> p >> x;
      if(x==0)sum[t] += m + wa[t][p]*20, ac[t]++;
      else wa[t][p]++;
    }

    vector<tri> rank;
    for(int i=1;i<=T;i++){
      rank.push_back(tri(pii(-ac[i],sum[i]),-i));
    }

    sort(rank.begin(),rank.end());

    for(int i=0;i<T;i++){
      cout << -rank[i].second;
      if(i+1==T)cout << endl;
      else if(rank[i].first == rank[i+1].first)cout << "=";
      else cout << ",";
    }
  }
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,x,ans=0;
  cin >> n >> x;
  vector<long> layer(51),patty(51);
  layer[0]=1,patty[0]=1;
  for(long i=1;i<=50;i++) layer[i]=layer[i-1]*2+3,patty[i]=patty[i-1]*2+1;
  while(n>0) {
    if(x==1) break;
    if(x==layer[n]) {
      ans+=patty[n];
      break;
    }
    if(x==layer[n]/2+1) {
      ans+=patty[n-1]+1;
      break;
    }
    if(x<layer[n]/2+1) {
      n--,x--;
    } else {
      x-=layer[n-1]+2,ans+=patty[n-1]+1,n--;
    }
  }
  if(n==0) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3616
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Console.WriteLine(new int[]{A + B, A - B, A * B}.Max());
	}
	int A,B;
	public Sol(){
		var d = ria();
		A = d[0]; B = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
typedef long long LL;
#define rep(i,n) for(LL i=0; i<(LL)(n); i++)

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}

LL ans( LL n,LL xx){
	if(n == -1){
		return 0;
	}
	return (n/xx)+1;
}

//main関数
int main(){
	int M,N;
	scanf("%d %d",&N,&M);
	char A[N][N];
	char B[M][M];
	rep ( i , N ){
		scanf("%s",A[i]);
	}
	rep ( i , M ) {
		scanf("%s",B[i]);
	}
	
	rep( i , N-M+1 ){
		rep ( j , N-M+1){
			int flag = 0;
			rep( k , M ){
				rep( m , M ){
					 if( A[ i+k ][ j+m ] != B[k][m]) flag = 1;
				}
			}
			if(flag == 0){
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}







Measured memory_bytes: 1688
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int N, A[200010];

// [l, r) をふたつにきる
pair<int, int> solve(int l, int r) {
    // 総和
    int sum = A[r-1] - A[l-1];
    int idx = lower_bound(A+l, A+r, A[l-1] + sum/2) - A;
    // fprintf(stderr, "solve [%lld, %lld): sum = %lld, idx = %lld\n", l, r, sum, idx);


    int minDiff = INF;
    pair<int, int> ans;
    for(int k=-1; k<1; k++) {
        if(idx + k < l or idx + k >= r-1) continue;
        int nidx = idx + k;
        int sumA = A[nidx] - A[l-1];
        int sumB = A[r-1] - A[nidx];
        if(minDiff > abs(sumA - sumB)) {
            minDiff = abs(sumA - sumB);
            if(sumA > sumB) swap(sumA, sumB);
            ans = make_pair(sumA, sumB);
        }
    }
    return ans;
}

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

    // 半分にきるところ (i と i+1 の間できる)
    int ans = INF;
    for(int i=2; i<=N-2; i++) {
        int mia, maa, mib, mab;
        tie(mia, maa) = solve(1, i+1);
        tie(mib, mab) = solve(i+1, N+1);
        // fprintf(stderr, "mia = %lld, maa = %lld, mib = %lld, mab = %lld\n", mia, maa, mib, mab);
        chmin(ans, max(maa, mab) - min(mia, mib));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
from collections import deque
def dia(i):
	lst = [-1]*N
	lst[i] = 0
	q = deque([i])
	while q:
		c = q.popleft()
		l = lst[c]
		for i in A[c]:
			if lst[i] != -1:
				continue
			else:
				lst[i] = l+1
				q.append(i)
	return lst.index(max(lst))
def dia2(i):
	lst = [-1]*N
	lst[i] = 0
	q = deque([i])
	while q:
		c = q.popleft()
		l = lst[c]
		for i in A[c]:
			if lst[i] != -1:
				continue
			else:
				lst[i] = l+1
				q.append(i)
	return max(lst)+1
N = input()
A = [[] for i in range(N)]
for i in range(N-1):
	a2,b2 = map(int, raw_input().split())
	A[a2-1].append(b2-1)
	A[b2-1].append(a2-1)
if((dia2(dia(0))) % 3 == 2):
	print("Second")
else:
	print("First")

Measured memory_bytes: 47104
import math

while True :
    q = input()
    
    if(q == "0") :
        break
    
    else :
        Color = ["black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"]
        f = int("ff", 16)
        r = int(q[1] + q[2], 16)
        g = int(q[3] + q[4], 16)
        b = int(q[5] + q[6], 16)
        
        d1 = math.sqrt(r ** 2 + g ** 2 + b ** 2)
        d2 = math.sqrt(r ** 2 + g ** 2 + (b - f) ** 2)
        d3 = math.sqrt(r ** 2 + (g - f) ** 2 + b ** 2)
        d4 = math.sqrt(r ** 2 + (g - f) ** 2 + (b - f) ** 2)
        d5 = math.sqrt((r - f) ** 2 + g ** 2 + b ** 2)
        d6 = math.sqrt((r - f) ** 2 + g ** 2 + (b - f) ** 2)
        d7 = math.sqrt((r - f) ** 2 + (g - f) ** 2 + b ** 2)
        d8 = math.sqrt((r - f) ** 2 + (g - f) ** 2 + (b - f) ** 2)
        
        D = [d1, d2, d3, d4, d5, d6, d7, d8]
        
        d = min(D)
        print(Color[D.index(d)])


Measured memory_bytes: 5656
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

vector<char> T;
vector<char> D;
int N, Q;
string s;
int left_g = 0;
int right_g = 0;

void disp(vector<int> v) {
  for (int i : v) {
    cout << i << " ";
  }
  cout << endl;
}

bool check_l(int index) {
  rep(i, Q) {
    if (T[i] == s[index]) {
      if (D[i] == 'L') {
        if (index == 0) {
          return true;
        }
        index--;
      } else {
        if (index == s.size() - 1) {
          return false;
        }
        index++;
      }
    }
  }
  return false;
}

bool check_r(int index) {
  rep(i, Q) {
    if (T[i] == s[index]) {
      if (D[i] == 'L') {
        if (index == 0) {
          return false;
        }
        index--;
      } else {
        if (index == s.size() - 1) {
          return true;
        }
        index++;
      }
    }
  }
  return false;
}

void solve_l() {
  int low = 0;
  int high = s.size() - 1;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (check_l(mid)) {
      if (mid == s.size() - 1 || !check_l(mid + 1)) {
        left_g = mid + 1;
        // cout << "mid " << mid << " left_g " << left_g << endl;
        break;
      }
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
}

void solve_r() {
  int low = 0;
  int high = s.size() - 1;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (check_r(mid)) {
      if (mid == 0 || !check_r(mid - 1)) {
        right_g = s.size() - (mid);
        // cout << "mid " << mid << " right_g " << right_g << endl;
        break;
      }
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
}

// Qlog(N)にしたい
int main() {
  cin >> N >> Q;

  cin >> s;

  rep(i, Q) {
    char t, d;
    cin >> t >> d;
    T.push_back(t);
    D.push_back(d);
  }

  solve_l();
  solve_r();

  // cout << "left_g " << left_g << endl;
  // cout << "right_g " << right_g << endl;

  int result = N - left_g - right_g;

  cout << result << endl;

  return 0;
}


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

int main(){
    int N, X, Y; cin >> N >> X >> Y;
    vector<int> ans(2010, 0);

    X--; Y--;
    if(X > Y) swap(X,Y);

    rep(i, N){
        for(int j=i+1; j<N; j++){
            int dist = min(j-i, abs(X-i)+abs(Y-j)+1);
            ans[dist]++;
        }
    }

    rep1(i,N-1) cout << ans[i] << endl;
}

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


def checkAndPrint(a, b, x):
    if pow(a, 5) - pow(b, 5) == x:
        print(a, b)
        exit()


for a in range(200):
    for b in range(200):
        checkAndPrint(a, b, x)
        checkAndPrint(-a, b, x)
        checkAndPrint(a, -b, x)

Measured memory_bytes: 67816
/**
*    created: 28.06.2020 02:21:50
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
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 (b < a) {a = b; return 1;} return 0;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    int mx = max(a,b);
    if (mx*2 <= 16) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define    ll   long long int
#define    sz   200010
#define    md   1000000007
#define    py   printf("YES\n")
#define    pn   printf("NO\n")

using namespace std;



int main()
{


    ll a,b,c;

    cin>>a>>b>>c;

    cout<<a*b/2<<endl;


    return 0;
}


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


int main()
{
    int n,d;
    cin >> n >> d ;
    vector<long long> x(n);
    vector<long long> y(n);

    for (long long i=0; i<n; i++){
        cin >> x.at(i) >> y.at(i);
        }
    int sum = 0;
    for (long long i=0; i<n; i++){
        long long x_double = pow(x.at(i),2.0);
        long long y_double = pow(y.at(i),2.0);
        long long z =  x_double + y_double;
        if(sqrt(z) <= d){
            sum++ ;
        }
    }

    cout << sum << endl;
    
}

Measured memory_bytes: 6492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

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

  cout << (N[0] == '9' || N[1] == '9' ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int n,ans=0;
  cin>>n;
  int a[2*n];
  rep(i,2*n){
    cin>>a[i];
  }
  sort(a,a+2*n);
  rep(i,n){
    ans+=a[2*i];
  }
  cout<<ans;
}

Measured memory_bytes: 256
def sol(strs):

	ptrA=0;
	ptrZ=len(strs)

	for i in range(len(strs)):
		if strs[i]=="A":
			ptrA=i
			break

	for i in range(len(strs)-1,0,-1):
		if strs[i]=="Z":
			ptrZ=i
			break
	

	return (ptrZ - ptrA+1)





inD =raw_input()

inD = str(inD)

print sol(inD)





Measured memory_bytes: 9192
main(n,a,b,d,x,i){while(~scanf("%d",&n)){if(!n)exit(0);for(a=0,b=500;n-->0;){for(d=i=0;i++<5;d+=x)scanf("%d",&x);a=d>a?d:a;b=d<b?d:b;}printf("%d %d\n",a,b);}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  long a,b;
  cin>>a>>b;
  int num=1;
  for(int i=1;i<=1000000;i++){
    if(a<i ||b<i){
      break;
    }
    if(a%i==0 && b%i==0){
      num=i;
    }
  }
  long ans=0;
  ans=a*b/num;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String inputStrN=sc.nextLine();
	int N = Integer.parseInt(inputStrN);

	if(N == 1){
		System.out.println("Hello World");
	}else{
		int A = Integer.parseInt(sc.nextLine());
		int B = Integer.parseInt(sc.nextLine());

		System.out.println(A+B);
	}

	}
}

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

using namespace std;

int const NMAX = 100;
char v[1 + NMAX][1 + NMAX];

int main() {

  int n = 0, m = 1000000000, k, inp;
  cin >> inp;n = max(n, inp);m = min(m, inp);
  cin >> inp;n = max(n, inp);m = min(m, inp);
  cin >> inp;n = max(n, inp);m = min(m, inp);
  cin >> inp;n = max(n, inp);m = min(m, inp);
  cin >> inp;n = max(n, inp);m = min(m, inp);
  cin >> k;
  if(n -m > k){
    cout << ":(";
  }else{
    cout << "Yay!";
  }
  return 0;
}


Measured memory_bytes: 3456
use std::io;


fn main() {
    let x = read_one::<usize>();
    let mut cnt: usize = (x / 11) * 2;
    let dd: usize = x % 11;
    if dd > 6 { cnt += 1; }
    if x % 11 > 0 { cnt += 1; }
    println!("{}", cnt);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
int dp[100040] = {};
int main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vector<int>ans;
	int i = n;
	while(i > 0) {
		for (int j = m; j > 0; j--) {
			if (i - j <= 0) {
				ans.push_back(i);
				i = -1;
				break;
			}else if (s[i - j] == '0') {
				i = i - j;
				ans.push_back(j);
				break;
			}
			if (j == 1) {
				cout << -1;
				return 0;
			}
		}
	}
	reverse(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
}


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


int main() {

    int64_t n;
    cin>>n;

    int64_t cnt_ac=0,cnt_wa=0,cnt_tle=0,cnt_re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;

        if(s=="AC")
            cnt_ac++;
        else if(s=="WA")
            cnt_wa++;
        else if(s=="TLE")
            cnt_tle++;
        else
            cnt_re++;
    }

    cout<<"AC x "<<cnt_ac<<endl;
    cout<<"WA x "<<cnt_wa<<endl;
    cout<<"TLE x "<<cnt_tle<<endl;
    cout<<"RE x "<<cnt_re<<endl;

	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;


int main()
{
	string S;
	cin >> S;
	for (int i = 0; i < S.length(); ++i)
	{
		if (S[i] == S[i + 1])
		{
			cout << "Bad" << endl;
			return 0;
		}
	}

	cout << "Good" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

int main(){
	fast;
	ll n; cin >> n;
	string s;
	cin >> s;	
	for(int i = 0; i < s.size(); ++i){
		s[i] = ((s[i] - 'A') + n) + 'A';
		s[i] = ((s[i] - 'A') % 26) + 'A';
	}
	cout << s;
	return 0;	
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
int main(){
	int n;
	char a[120];
	scanf("%d",&n);
	if(n%2==1) printf("No");
	else{
	for(int i=0;i<n;i++) scanf(" %c",&a[i]);
	for(int i=0;i<n/2;i++)
		if(a[i]!=a[i+n/2]){
			printf("No");
			return 0;
		}
	printf("Yes");
}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);


int main() {
    int N;
    std::cin >> N;
    std::vector<int> vec(N);
    for(auto& val: vec)
        std::cin >> val;

    auto minItr = std::min_element(begin(vec), end(vec));
    auto maxItr = std::max_element(begin(vec), end(vec));
    auto min = *minItr;
    auto max = *maxItr;

    if(0 <= min) {
        std::cout << N - 1 << '\n';
        for(int i = 1; i < N; ++i) {
            std::cout << i << " " << i + 1 << '\n';
        }
    } else if(max <= 0) {
        std::cout << N - 1 << '\n';
        for(int i = N; i > 1; --i) {
            std::cout << i << " " << i - 1 << '\n';
        }
    } else {
        std::cout << 2 * N - 1 << '\n';
        if(std::abs(min) <= std::abs(max)) {
            for(auto itr = begin(vec); itr != end(vec); ++itr) {
                std::cout << maxItr - begin(vec) + 1 << ' ' << itr - begin(vec) + 1 << '\n';
            }
            for(int i = 1; i < N; ++i) {
                std::cout << i << " " << i + 1 << '\n';
            }
        } else {
            for(auto itr = begin(vec); itr != end(vec); ++itr) {
                std::cout << minItr - begin(vec) + 1 << ' ' << itr - begin(vec) + 1 << '\n';
            }
            for(int i = N; i > 1; --i) {
                std::cout << i << " " << i - 1 << '\n';
            }
        }
    }
    std::cout << std::flush;

    return 0;
}


Measured memory_bytes: 256
# Insertion Sort

n = int(input())
integers = [int(i) for i in input().rstrip().split()]

def show(a):
    for i in range(len(a)):
        if i < len(a) - 1:
            print(a[i], end = ' ')
    return a[len(a) - 1]

def insertionSort(a, n):
    for i in range(1, n):
        print(show(a))
        v = a[i]
        j = i - 1
        while j >= 0 and v < a[j]:
            a[j + 1] = a[j]
            j -= 1
        a[j + 1] = v
    return show(a)

print(insertionSort(integers, n))



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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> W(N);
  
  for( int i = 0; i<N; i++){
    cin >> W.at(i);
  }
  
  int total = 0;
  
  for( int i = 0; i<N; i++){
    total += W.at(i);
  }
  
  vector<int> L(N-1);
  
  L.at(0) = W.at(0);
  
  for( int i = 0; i<N-2; i++){
    L.at(i+1) = L.at(i) + W.at(i+1);
  }
  
  vector<int> D(N-1);
  
  for( int i = 0; i<N-1; i++){
    if( (L.at(i) * 2) - total < 0 ){
      D.at(i) = ((L.at(i) * 2) - total) * -1;
    }else{
      D.at(i) = (L.at(i) * 2) - total;
    }
  }
  
  int ans = D.at(0);
  
  for ( int i = 1; i<N-1; i++){
    if ( ans > D.at(i) ){
      ans = D.at(i);
    }
  }
  
  cout << ans << endl;
 
}

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

using namespace std;
using namespace std::chrono;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
ll mod=1000000007;
const int MX=0x3f3f3f3f;

int main(){
    IOS;
    string s,t;
    cin>>s>>t;
    int i,j,flag=0;
    REP(i,0,s.size()-1) 
        if(s[i]!=t[i]){
            flag=1;
            break;
        }
    if(flag)
         cout<<"No";
    else cout<<"Yes";
	return 0;
} 

Measured memory_bytes: 3644
function main(arg) {
    const [_n , _k] = arg.replace(/\r?\n/g,"").split(" ")
    const n = Number(_n)
    const k = Number(_k)

    if(n + 1 - (k * 2) >= 0){
        console.log("YES")
    }else{
        console.log("NO")
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 11468
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  int n, m;
  readf("%s %s\n", &n, &m);
  long pen;
  int res;
  auto f = new int[](n+1);
  foreach (_; 0..m) {
    auto x = readln.chomp.split;
    auto p = x[0].to!int;
    if (x[1] == "WA" && f[p] != 1) {
      f[p] -= 1;
    } 
    if (x[1] == "AC" && f[p] != 1) {
      res++;
      pen -= f[p];
      f[p] = 1;
    }
  }
  writefln("%s %s", res, pen);
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>


int main()
{
  int cnt;
  int a,b;
  int co = 0;
  int i;

  cnt = scanf("%d %d", &a, &b);

  for (i=0; i<2; i++) {
    if (a > b) {
      co += a;
      a--;
    } else {
      co += b;
      b--;
    }
  }

  printf("%d\n", co);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0;i <(n;i++)
#define RFOR(i, n) for(int i = n;i >= 0;i--)
#define REP(i, m, n) for(int i = m;i < n;i++)
#define RREP(i, m, n) for(int i = m;i >= n;i--)
using namespace std;
int main(int argc, char const *argv[])
{
 int a,b;
 int i,t;

 cin >>a>>b;
 i = a -1;
 t = b -1;
 cout<<i*t<<endl;
 
return 0;

}


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

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

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

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

    return os;
}

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

    return res;
}


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

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

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

void d_err() {
    cerr << endl;
}

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

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

char lower(char x) {
    if (x == 'A') return 'a';
    if (x == 'B') return 'b';
    if (x == 'C') return 'c';
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    S[K-1] = lower(S[K-1]);
    cout << S << endl;
    
    cout << fixed << setprecision(20);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define n_l '\n'
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: "; cerr << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cerr << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cerr << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cerr << endl
#define run(a, b) cerr << fixed << setprecision(6) << (double) (b - a) / (double) (CLOCKS_PER_SEC) << " s" << endl;
#define ll long long
#define INF (1e9 + 5)
#define MOD (int)(1e9 + 7) 

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    vector<int> arr(n);
    vector<int> cnt(1001, 0);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            int k = j;
            for(int b = n; b > 0; b >>= 1) {
                while(k + b < n and arr[k + b] < arr[i] + arr[j]) {
                    k += b;
                }
            }
            ans += max(0, k - j);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    N, x = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    a_sum = sum(A)
    if x == a_sum:
        print(N)
    elif x > a_sum:
        print( N-1 )
    else:
        cnt = 0
        for a in A:
            if x >= a:
                cnt += 1
                x -= a
            else:
                print(cnt)
                return 0

if __name__ == '__main__':
    main()

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B, K;
	cin >> A >> B >> K;

	if (B - A < 2 * K)
	{
		rep(i, A, B + 1)
		{
			cout << i << endl;
		}
	}
	else
	{
		rep(i, 0, K)
		{
			cout << A + i << endl;
		}
		rep(i, 0, K)
		{
			cout << B - (K - 1) + i << endl;
		}
	}

	return 0;
}

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

int main(){
    long long n,i,count = 0;
    long long  a[100010],b[100010];

    scanf("%lld",&n);
    for(i = 1; i <= n+1 ; i++){
        scanf("%lld",&a[i]);
    }
    for(i = 1; i <= n ; i++){
        scanf("%lld",&b[i]);
    }
    for(i = 1; i <= n ; i++){
        if(a[i] <= b[i]){
            count += a[i];
            b[i] -= a[i];
            a[i] = 0;
        }else{
            count += b[i];
            a[i] -= b[i];
            b[i] = 0;
        }
        if(a[i+1] <= b[i]){
            count += a[i+1];
            b[i] -= a[i+1];
            a[i+1] = 0;
        }else{
            count += b[i];
            a[i+1] -= b[i];
            b[i] = 0;
        }

    }




    printf("%lld\n",count);
    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,A,B;
int H[111111];

bool C(int x){
    rep(i,N){
        H[i]-=B*x;
    }

    int cnt=0;
    int uku=A-B;
    rep(i,N){
        if(H[i]<=0)continue;
        cnt+=(H[i]+uku-1)/uku;
    }

    rep(i,N)H[i]+=B*x;
    return cnt<=x;
}

signed main(){
    cin>>N>>A>>B;
    rep(i,N){
        cin>>H[i];
    }

    int lb=0,ub=INT_MAX;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid))ub=mid;
        else lb=mid;
    }
    cout<<ub<<endl;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a // g * b


# 答えをxと仮定
# x以上で切れる最小が答え
N, K = ints()
A = ints()


def is_ok(arg):
    # x以上で切れる場合にTrueを返す
    cnt = 0
    for a in A:
        cnt += a // arg
        if a % arg == 0:  # ぴったり切れるとき
            cnt -= 1
    return cnt <= K  # xでは切れる


def meguru_bisect(ng, ok):
    '''
    define is_okと
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(0, 10**9 + 1))


Measured memory_bytes: 92804
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=0;
  cin>>n;
  bool flg=0;
  for(long i=1;i<n;i++){
  	if(i*i+i<n && n%i==0){
      ans+=(n-i)/i;
    }
    if(i*i+i>=n) flg=1;
    if(flg) break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256