akhauriyash/Code-Regression huggingface dataset:
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int m1,d1,m2,d2;cin>>m1>>d1>>m2>>d2;
    if(d2==1)
        cout<<1<<endl;
    else
        cout<<0<<endl;
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
# Aの先頭の桁と末尾の桁の組み合わせは9*10=90通りだけ
table = np.zeros((10, 10)).astype(int)
for x in range(1, N+1):
    x = str(x)
    i = int(x[0])
    j = int(x[-1])
    table[i][j] += 1

table = np.array(table)
answer = (table * table.T).sum()
print(answer)


Measured memory_bytes: 12496
def union(x,y):
    par[x]+=par[y]
    par[y]=x
    


def find(a):
    ans=[]
    while par[a]>=0:
        ans.append(a)
        a=par[a]
    for i in ans:
        par[i]=a
    return a



n,q=map(int,input().split())
par={i:-1 for i in range(n)}
for _ in range(q):
    a,b,c=map(int,input().split())
    if a==0:
        x,y=find(b),find(c)
        if x!=y:
            union(x,y)
    else:
        x,y=find(b),find(c)
        if x==y:
            print('1')
        else:
            print('0')
    
        


Measured memory_bytes: 30020
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_map>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 2000000000
typedef long long ll;


int main(){
    int N;
    string c;
    cin >> N;
    cin >> c;
    vector<int> R(N+1);
    vector<int> W(N+1);
    R.at(0) = 0;
    W.at(0) = 0;
    int r = 0;
    int w = 0;
    REP(i,N){
        if(c.at(i)=='R') r++;
        else w++;
        R.at(i+1) = r;
        W.at(i+1) = w;
    }
    int ans = N;
    REP(i,N+1){
        //cout << W.at(i) << " " << R.at(N)-R.at(i) << endl;
        ans = min(ans,max(W.at(i),R.at(N)-R.at(i)));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4548
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n%2==0){
        ll m = (a[n/2-1] + a[n/2]);
        ll l = (b[n/2-1] + b[n/2]);
        ll ans = (l-m) + 1;
        cout << ans << endl;
    }else{
        ll m = a[n/2];
        ll l = b[n/2];
        ll ans = (l-m) + 1;
        cout << ans << endl;
    }
   
    return 0;
}

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

int main() {
  int N, A;
  cin >> N;
  while (cin >> A) {
    if (A % 2) continue;
    if (A % 3 && A % 5) return cout << "DENIED" << "\n", 0;
  }
  cout << "APPROVED" << "\n";
}

Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int K = sc.nextInt();
		
		int[] g_count = new int[10];
		Arrays.fill(g_count, 1);
		
		int[][] data_tmp = new int[10][N+1];
		
		for(int i = 0; i < N; i++){
			final int c = sc.nextInt();
			final int g = sc.nextInt() - 1;
			
			data_tmp[g][g_count[g]++] = c;
		}
		
		int[][] data = new int[10][];
		for(int i = 0; i < 10; i++){
			data[i] = new int[g_count[i]];
			System.arraycopy(data_tmp[i], 0, data[i], 0, g_count[i]);
		}
		
		for(int i = 0; i < data.length; i++){
			Arrays.sort(data[i]);
			
			for(int start = 1; start < (data[i].length + 1) / 2; start++){
				int tmp = data[i][start];
				data[i][start] = data[i][data[i].length - start];
				data[i][data[i].length - start] = tmp;
			}
		}
		/*
		for(int g = 0; g < 10; g++){
			System.out.print(g + " :");
			for(int i : data[g]){
				System.out.printf(" %3d", i);
			}
			System.out.println();
		}
		System.out.println("--------------------------------------");
		*/
		for(int i = 0; i < data.length; i++){
			for(int j = 0; j < g_count[i]; j++){
				if(j == 0){
					continue;
				}
				
				data[i][j] += data[i][j-1];
			}
		}
		
		for(int i = 0; i < data.length; i++){
			for(int j = 0; j < g_count[i]; j++){
				data[i][j] += j * (j - 1);
			}
		}
		/*
		for(int g = 0; g < 10; g++){
			System.out.print(g + " :");
			for(int i : data[g]){
				System.out.printf(" %3d", i);
			}
			System.out.println();
		}
		System.out.println("--------------------------------------");
		*/
		int[][] DP = new int[K + 1][10];
		
		for(int g = 0; g < 10; g++){
			if(g == 0){
				final int min = Math.min(g_count[g], DP.length);
				for(int k = 0; k < min; k++){
					DP[k][g] = data[g][k];
				}
			}else{
				for(int k = 0; k < DP.length; k++){
					for(int pos = k - (g_count[g] - 1); pos <= k; pos++){
						if(pos < 0){
							continue;
						}
						
						DP[k][g] = Math.max(DP[k][g], DP[pos][g-1] + data[g][k - pos]);
					}
				}
			}
			/*
			for(int k = 0; k < DP.length; k++){
				System.out.print(k + " :");
				for(int i = 0; i < 10; i++){
					System.out.printf(" %3d", DP[k][i]);
				}
				System.out.println();
			}
			System.out.println("------------------------------------");
			*/
		}
		
		System.out.println(DP[K][9]);
		
	}

}

Measured memory_bytes: 28100
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
    int N, R, ans;
    cin >> N >> R;
    if(N < 10){
        ans = R + 100*(10-N);
    } else{
        ans = R;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
int main(){
    int k;
    cin >> k;
    queue<ll> que;
    for(int i=1;i<10;i++){
        que.push(i);
    }
    ll res = 0;
    for(int i=0;i<k;i++){
        ll x = que.front();que.pop();
        res = x;
        ll enq = 10 * x + (x%10);
        if(x%10 != 0) {
          que.push(enq-1);
        }
        que.push(enq);
        if(x%10 != 9) {
            que.push(enq+1);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    string s;
	cin>>s;
	if(s.size()%2==1) cout<<"No";
	else{
		for(int i=0;i<s.size();i+=2)
		if(s[i]!='h'||s[i+1]!='i'){
			cout<<"No";
			return 0; 
		}
	cout<<"Yes";
	}
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		boolean[] expo = new boolean[X + 1];
		expo[1] = true;
		for (int i = 2; i <= X; i++) {
			int v = i * i;
			while (v <= X) {
				expo[v] = true;
				v *= i;
			}
		}
		for (int i = X; i >= 1; i--) {
			if (expo[i]) {
				System.out.println(i);
				break;
			}
		}
		sc.close();
	}
}

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

bool is_integer( double x ){
  return floor(x)==x;
}

int main(void){

    string a,b;
    cin >> a >> b;
    a += b;
    int num = stoi(a);
    
    if(is_integer(sqrt(num))){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
  ll h, w;
  cin >> h >> w;
  vst s(h);
  vin(s);

  vvll row(h, vll(w, 0)), line(h, vll(w, 0));
  rep(i, 0, h){
    ll j = 0, from = -1, light = 0;
    while(j < w){
        if(s.at(i).at(j) == '.'){
            light++;
            if(j == w - 1) rep(k, from + 1, j + 1) line.at(i).at(k) = light;
        }
        else{
            rep(k, from + 1, j) line.at(i).at(k) = light; 
            from = j;
            light = 0;
        }
        j++;
    }
  }
  rep(i, 0, w){
    ll j = 0, from = -1, light = 0;
    while(j < h){
        if(s.at(j).at(i) == '.') {
            light++;
            if(j == h - 1) rep(k, from + 1, j + 1) row.at(k).at(i) = light;
        }
        else{
            rep(k, from + 1, j) row.at(k).at(i) = light; 
            from = j;
            light = 0;
        }
        j++;
    }
  }
  ll ans = 0;
  rep(i, 0, h)rep(j, 0, w) chmax(ans, row.at(i).at(j) + line.at(i).at(j));
  cout << max(ans - 1, 0ll) << endl;
}

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

const int MOD_VALUE = 1000000007;


int main(void){

	int n;
	int i;
	long long int a[200000];
	long long int l;
	long long int r;
	long long int l_l;
	long long int l_r;
	long long int r_l;
	long long int r_r;
	long long int ret;
	long long int ret_r;
	long long int ret_l;

	scanf("%d",&n);

	l = 0;
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		l += a[i];
	}

	r = 0;
	for(i=0;i<n-1;i++){
		r += a[i];

		if(r + a[i+1] >= l - r - a[i+1]){
			l_l = r + a[i+1];
			l_r = l - r - a[i+1];
			r_l = r;
		    r_r = l - r;
			break;
		}
	}

	if(l_l > l_r){
		ret_l = l_l - l_r;
	}else{
		ret_l = l_r - l_l;
	}

	if(r_l > r_r){
		ret_r = r_l - r_r;
	}else{
		ret_r = r_r - r_l;
	}


	if(ret_r > ret_l){
		ret = ret_l;
	}else{
		ret = ret_r;
	}


	printf("%lld\n",ret);

	return 0;
}

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

using namespace std;


int main(){
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int minit=((h2-h1)*60)+(m2-m1);
    if(minit==k){
        cout<<0<<endl;
        return 0;
    }
    cout<<minit-k<<endl;
    return 0;
}


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

int main() {
    int H, W, i, j;
    while (true) {
        cin >> H >> W;
    
        if (H == 0 && W == 0) break;
        for (i = 0; i < H; i++) {
            for (j = 0; j < W; j++) {
                if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

bool isprime(int x){
    if(x==2)return true;
    if(x<2||x%2==0){
        return false;
    }
    int i=3;
    while(i*i<=x){
        if(x%i==0){
            return false;
        }
        i+=2;
    }
    return true;
}

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(isprime(a[i])){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3084
#include <stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[101][101];
int color[101],d[101],f[101],r;
void dfs_visit(int u);
void dfs(void);

int main(){
  int u,v,k,i,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();

  return 0;
}

void dfs_visit(int u){
  int v;
  color[u]=1;
  d[u]=++r;
  for(v=0;v<n;v++){
    if(M[u][v]==0){
      continue;
    }
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++r;
}

void dfs(){
  int u;
  for(u=0;u<n;u++){
    color[u]=WHITE;
  }
  r=0;

  for(u=0;u<n;u++){
    if(color[u]==WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
double dfs(double L, double R, int K, double l, double r, double P, double T){
  if (r <= L || R <= l){
    return 0;
  } else if (L <= l && r <= R){
    return 1;
  } else if (K == 0){
    double m = (l + r) / 2;
    if (L <= m && m <= R){
      return 1;
    } else {
      return 0;
    }
  } else {
    double m = (l + r) / 2;
    double ans1 = dfs(L, R, K - 1, l, m, P, T);
    double ans2 = dfs(L, R, K - 1, m, r, P, T);
    if (m <= T){
      return P * ans1 + (1 - P) * ans2;
    } else {
      return P * ans2 + (1 - P) * ans1;
    }
  }
}
int main(){
  cout << fixed << setprecision(5);
  int K, R, L;
  cin >> K >> R >> L;
  double P;
  cin >> P;
  double E;
  cin >> E;
  double T;
  cin >> T;
  cout << dfs(T - E, T + E, K, R, L, P, T) << endl;
}


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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

signed main()
{
	init();
	solve();
}

int k, s;

void init()
{
	cin >> k >> s;
}



void solve()
{
	ll res = 0;
	rep(i, k+1) {
		rep(j, k+1) {
			if (i + j <= s && i + j + k >= s) res++;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
/*
power and fast-scan code taken from geeks for geeks
*/

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 100001
using namespace std;
typedef long long ll;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}

// void fastscan(int &number) 
// { 
//     //variable to indicate sign of input number 
//     bool negative = false; 
//     register int c; 
  
//     number = 0; 
  
//     // extract current character from buffer 
//     c = getchar(); 
//     if (c=='-') 
//     { 
//         // number is negative 
//         negative = true; 
  
//         // extract the next character from the buffer 
//         c = getchar(); 
//     } 
  
//     // Keep on extracting characters if they are integers 
//     // i.e ASCII Value lies from '0'(48) to '9' (57) 
//     for (; (c>47 && c<58); c=getchar()) 
//         number = number *10 + c - 48; 
  
//     // if scanned input has a negative sign, negate the 
//     // value of the input number 
//     if (negative) 
//         number *= -1; 
// } 

bool comp(ll &a, ll &b){
    return a>b;
}

bool _pal(string s){
    ll n=s.length();
    for(ll i=0, j=n-1;i<j;i++, j--){
        if(s[i]!=s[j]){
            return false;
        }
    }
    return true;

}

int main(){


    // #ifndef ONLINE_JUDGE 

    // // For getting input from input.txt file 
    // freopen("input.txt", "r", stdin); 

    // // Printing the Output to output.txt file 
    // freopen("output.txt", "w", stdout); 
    // #endif 


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }
    unordered_map<ll,ll> count_arr;
    for(ll i=0;i<n;i++){
        count_arr[arr[i]]++;
    }
    ll sum=0;

    for(auto it=count_arr.begin(); it!=count_arr.end(); ++it){
        ll c=it->second;
        sum+=(c*(c-1))/2;
    }
    for(ll i=0;i<n;i++){
        ll c=count_arr[arr[i]];
        ll temp=sum-((c*(c-1))/2);
        c--;
        temp+=(c*(c-1))/2;
        cout<<temp<<endl;
    }


    return 0;
}


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main(){
    string S;
    cin >> S;
    for(int i=0; i<8; i++){
        if(S.substr(0,7-i)+S.substr(S.size()-i,i)=="keyence"){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

// 制約fを満たす最大値（最小値）の二分探索
// ok < ng なら最大値，ok > ng なら最小値探索になる
template<class T, typename F> T bsearch(T ok, T ng, int loop, F f) {
	for(int i = 0; i < loop; ++i) {
		T middle = (ok + ng) / 2;
		(f(middle) ? ok : ng) = middle;
	}
	return ok;
}

#define EPS (1e-10)

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl A(n); REP(i, n) cin >> A[i];
	vl sa(n);
	ll ma = -TEN(10);
	if (n == 1) {
		cout << "YES" << endl;
		return 0;
	}

	REP(i, n) {
		sa[i] = A[i] - A[(i - 1 + n) % n];
		ma = max(ma, sa[i]);
	}
	ll num_max = 0;
	ll cnt = 0;
	vl ccnt(n, 0);
	REP(i, n) {
		if (ma == sa[i]) num_max++;
		else {
			cnt += (ma - sa[i]) / n;
			ccnt[i] = (ma - sa[i]) / n;
		}
	}
	ll mi = TEN(10), idx = -1;
	REP(i, n) if (mi > A[i]) {
		mi = A[i]; idx = i;
	}
	ll sum = 0;
	REP(i, n) sum += ccnt[i] * (1 + (idx - i + n) % n);

	cout << (sum == mi && cnt == ma ? "YES" : "NO") << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <math.h>
using namespace std;

int main(){
  int a, b, n;
  cin >> a >> b;
  n = 100000;
  for (int i = 1250; i > 0; i--)
  {
    if (floor(i * 0.08) == a && floor(i * 0.1) == b)
    {
      n = i;
    }
  }
  if (n > 1250)
  {
    cout << -1 << endl;
    return 0;
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256
n, m=gets.split.map &:to_i
a=(1..n).map{gets.chomp.bytes.map{|e|e%2}}

q=[]
a.each_with_index do |v, i|
    v.each_with_index do |c, j|
        q << i*m+j if a[i][j]==1
    end
end

res=0
h=-1
while t=q[h+=1]
    res=a[r=t/m][c=t%m]-1
    if r>0 && a[nr=r-1][nc=c]==0
        a[nr][nc]=a[r][c]+1
        q << nr*m+nc
    end
    if r<n-1 && a[nr=r+1][nc=c]==0
        a[nr][nc]=a[r][c]+1
        q << nr*m+nc
    end
    if c>0 && a[nr=r][nc=c-1]==0
        a[nr][nc]=a[r][c]+1
        q << nr*m+nc
    end
    if c<m-1 && a[nr=r][nc=c+1]==0
        a[nr][nc]=a[r][c]+1
        q << nr*m+nc
    end
end

p res


Measured memory_bytes: 25652
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long n, k;
    long long sum_count = 0;
    vector<long long> count(200000, 0);
    
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        long long temp;
        cin >> temp;
        count[temp-1]++;
    }
    
    sort(count.begin(), count.end(), [](long long a, long long b){ return a > b; });
    
    for(int i = k; i < n; i++)
        sum_count += count[i];
        
    cout << sum_count << endl;
}

Measured memory_bytes: 1792
def main():
    a,b = map(int,input().split())

    n = int(input())
    s,f = [],[]
    for i in range(n):
        ss,ff = map(int,input().split())
        s.append(ss)
        f.append(ff)

    for i in range(n):
        if f[i] <= a or b <= s[i]:
            continue
        else:
            return 1
    return 0

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 7788
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[] = new int[3];			
		
		for (int i = 0; i < 3; i++) {
			N[i] = sc.nextInt();
		}
		
		Arrays.sort(N);
		
		System.out.println(10 * N[2] + N[1] + N[0]);
	}
}


Measured memory_bytes: 22100
class UnionFind:
    "https://www.kumilog.net/entry/union-find"
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

N, M, K = map(int, input().split(" "))


uf = UnionFind(N)
fr = {}
for _ in range(M):
    a, b = map(int, input().split(" "))
    a -= 1
    b -= 1
    
    uf.union(a, b)

    fr[a] = fr.get(a, 0) + 1
    fr[b] = fr.get(b, 0) + 1

bl = {}
for _ in range(K):
    c, d = map(int, input().split(" "))
    c -= 1
    d -= 1
    if not uf.is_same(c, d):
        continue

    fr[c] = fr.get(c, 0) + 1
    fr[d] = fr.get(d, 0) + 1


for i in range(N):
    s = uf.get_size(i) - 1
    s -= bl.get(i, 0)
    s -= fr.get(i, 0)
    print(s)

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

char chlit(char c){return c+32;}
char chbig(char c){return c-32;}

int main(){
  int i=0;
  while(1){
    string s;cin >> s;
    if(s.length() == 0){cout << endl;return 0;}
    if(i != 0)cout << " ";
    else i = 1;
    rep(i,s.length()){
      if(s[i] >= 'a' && s[i] <= 'z')cout << chbig(s[i]);
      else if(s[i] >= 'A' && s[i] <= 'Z')cout << chlit(s[i]);
      else cout << s[i];
    }
  }
  return 0;
}


Measured memory_bytes: 3128
N,Wmax=map(int,input().split(' '))
W=[]
V=[]
for _ in range(N):
	w,v = map(int,input().split(' '))
	W.append(w)
	V.append(v)

#dp[i][j]=i番目の品物までだけを選び重量制限をjとしたときの価値の最大値
dp = []
dp.append([0]*min(W[0],Wmax+1)+ [V[0]]*max(0, Wmax+1-W[0]))


for i in range(1,N):
	#今回の重量制限をwとする
	#今回は荷物を積む場合: dp[i][w] = dp[i-1][w-w[i]]+v[i] 
	#今回は荷物を積まない場合: dp[i][w] = dp[i-1][w]
	#よってこの2つのうち大きいほうをdp[i][w]に採用する
	dpi = []
	for j in range(Wmax+1):
		if j<W[i]:
			dpi.append(dp[i-1][j])
		else:
			dpi.append(max(dp[i-1][j], dp[i-1][j-W[i]]+V[i]))
	dp.append(dpi)
print(dp[N-1][Wmax])

Measured memory_bytes: 144396
n = int(input())
Asgs = list()

def get_sgs(an):
    sgs = [list(map(int, input().split())) for i in range(an)]
    return sgs


for i in range(n):
    an = int(input())
    Asgs.append(get_sgs(an))

bits = list()
for i in range(2**n):
    bits.append(list(map(int, list(bin(i)[2::].zfill(n)))))


cnt = 0
ps = list()
is_break = False
# print(bits)
# print(Asgs)

for i in range(2**n):
    for j in range(n):
        # j人目の意見
        #j 人目の意見k米
        for k in range(len(Asgs[j])):
            # 正しいとされた人が　とある人を正しいとしているが とある人が正しくないとされている場合
            if bits[i][j] == 1 and Asgs[j][k][1] == 1 and bits[i][Asgs[j][k][0]-1] == 0:
                #矛盾しているので
                bits[i] = [0]*n
            elif bits[i][j] == 1 and Asgs[j][k][1] == 0 and bits[i][Asgs[j][k][0]-1] == 1:
                bits[i] = [0]*n
                
    if bits[i] == [1,1,1]:
        print(i,j,k)
        print('ghogegegaega')
    ps.append(sum(bits[i]))
    

print(max(ps))
#print(ps)
#print(Asgs)

Measured memory_bytes: 13120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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 ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int b;
    while(cin >> b){
        if(b==0){
            return 0;
        }
        int p,q;
        for(ll i=1;i*(i+1)/2<=b;i++){
            ll t=i*(i+1)/2;
            if((b-t)%i==0){
                p=(b-t)/i+1;
                q=i;
            }
        }
        cout << p << " " << q << endl;
    }
}


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

int main() {
  string S; cin >> S;
  int N = S.size();
  bool res = true;
  for (int i = 0; i < (N-1)/2; i++) {
    if (S[i] != S[(N-1)/2 - i - 1]) res = false;
    if (S[i + (N+1)/2] != S[N - i - 1]) res = false;
    if (S[i] != S[N - i - 1]) res = false;
  }
  if (res) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

struct UFNode
{
  int value_;
  int rank_, p_;
  int index_;
  UFNode(int value) : value_(value), rank_(0), p_(-1), index_(-1) {}
};

struct UFSet
{
  vector<UFNode> ufset_;
  void make_set(int value)
  {
    UFNode node(value);
    ufset_.push_back(node);
    ufset_.back().index_ = ufset_.size() - 1;
    ufset_.back().p_ = ufset_.size() - 1;
  }

  // Return index of the root of the tree to which value belongs.
  int find_set(int value, int index = -1)
  {
    int ix = index;
    if (ix == -1) {
      for (int i = 0; i < (int)ufset_.size(); ++i) {
        if (ufset_[i].value_ == value) {
          ix = i;
          break;
        }
      }
    }
    if (ix == -1) {
      fprintf(stderr, "find_set(): node not found!!\n");
      return -1;
    }
    if (ufset_[ix].p_ != ufset_[ix].index_) {
      ufset_[ix].p_ = find_set(ufset_[ufset_[ix].p_].value_, ufset_[ix].p_);
    }
    return ufset_[ix].p_;
  }

  void unite(int x, int y)
  {
    int s1 = find_set(x), s2 = find_set(y);
    if (s1 == s2) { return; }
    if (s1 == -1 || s2 == -1) { return; }
    if (ufset_[s1].rank_ > ufset_[s2].rank_) {
      // connect ufset_[s2] to ufset_[s1]
      ufset_[s2].p_ = s1;
    }
    else {
      // connect ufset_[s1] to ufset_[s2]
      ufset_[s1].p_ = s2;
      if (ufset_[s1].rank_ == ufset_[s2].rank_) {
        ++ufset_[s2].rank_;
      }
    }
  }

  bool is_same(int x, int y)
  {
    return find_set(x) == find_set(y);
  }
};

int main()
{
  int n, q;
  UFSet ufset;
  fscanf(stdin, "%d %d", &n, &q);
  for (int i = 0; i < n; ++i) {
    ufset.make_set(i);
  }
  for (int i = 0; i < q; ++i) {
    int c, x, y;
    fscanf(stdin, "%d %d %d", &c, &x, &y);
    if (c == 0) {
      ufset.unite(x, y);
    }
    else if (c == 1) {
      int ans = ufset.is_same(x, y) ? 1 : 0;
      fprintf(stdout, "%d\n", ans);
    }
  }
  return 0;
}

Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);
int main(){
    int rta=0,cnt=0;
    string s;
    cin >> s;
    if(s[0]=='R' && s[0]==s[1] && s[0]==s[2]) rta=3;
    else if(s[0]=='R' || s[1]=='R' || s[2]=='R') rta=1;
    for(int i=0;i<2;i++){
        if(s[i]=='R' && s[i]==s[i+1]) rta=max(rta,2);
    }
    cout << rta << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <vector>
#include <queue>
using i64 = long long;

/*
 * delta(V v, fn (V t))
 * index(V v) -> int
 */
template<class V, class Delta, class Index>
std::vector<i64> bfs(std::size_t N, V s, Delta delta, Index index) {
  std::vector<i64> dist(N, -1);
  std::queue<V> que;
  dist[index(s)] = 0;
  que.push(s);
  while(!que.empty()) {
    V v = que.front();
    que.pop();
    delta(v, [&](V t) {
        if(dist[index(t)] == -1) {
          dist[index(t)] = dist[index(v)] + 1;
          que.push(t);
        }
    });
  }
  return dist;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  i64 H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,0,H) {
    cin >> S[i];
  }
  i64 ans = 0;
  using P = std::pair<i64, i64>;
  vector<i64> dx { 1, 0, -1, 0 };
  rep(i,0,H) rep(j,0,W) {
    if(S[i][j] == '#') continue;
    auto res = bfs(H * W, P(i, j),
          [&](P v, auto func) {
            i64 i = v.first;
            i64 j = v.second;
            rep(q,0,4) {
              i64 x = i + dx[q];
              i64 y = j + dx[q ^ 1];
              if(0 <= x && x < H && 0 <= y && y < W && S[x][y] == '.') {
                func(P(x, y));
              }
            }
          },
          [&](P v) { return v.first * W + v.second; }
        );
    ans = std::max(ans, *std::max_element(all(res)));
  }
  cout << ans << endl;
}


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

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

  string s;

  // ループ
  for (int i = 0; i < T.size(); ++i)
  {

    if (T[i] == '?')
    {
      s.push_back('D');
    }
    else
    {
      s.push_back(T[i]);
    }
  }
  cout << s << endl;

  return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int cnt;
bool query(string s)
{
    cnt++;
    assert(cnt<=64);

    cout << "? " << s << endl;
    string ans;
    cin >> ans;
    return (ans == "Y");
}

int main()
{
    ios::sync_with_stdio(false);

    int digit_num = 0;
    for (int i=0; i<=10; i++) {
        string n = "1";
        if (i>0) n += string(i, '0');
        if (!query(n)) {
            digit_num = i;
            break;
        }
    }

    if (digit_num == 0) {
        for (int i=0; i<=10; i++) {
            string n = "2";
            if (i>0) n += string(i, '0');
            if (query(n)) {
                n[0] = '1';
                cout << "! " << n << endl;
                return 0;
            }
        }
    }

    // DUMP(digit_num);

    string now = "";
    for (int i=0; i<digit_num-1; i++) {
        int ub = 10, lb = 0;
        while (abs(ub - lb) > 1) {
            int mid = (ub + lb) / 2;
            string n = now;
            n += (mid + '0');
            (query(n) ? lb : ub) = mid;
        }

        if (lb == ub - 1) {
            now += lb + '0';
        } else {
            assert(false);
        }
    }

    {   
        int ub = 9, lb = -1;
        while (abs(ub - lb) > 1) {
            int mid = (ub + lb) / 2;
            string n = now;
            n += (mid + '0');
            n += '9';
            (query(n) ? ub : lb) = mid;
        }
        if (ub == lb + 1) {
            now += ub + '0';
        } else {
            assert(false);
        }
    }

    cout << "! " << now << endl;
}

Measured memory_bytes: 620
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a) memset(a,0,sizeof(a))
#define f first
#define s second
#define M_E 2.71828182845904523536
#define M_PI 3.14159265358979323846
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
int main()
{
    int n;
    cin>>n;
    ll res;
    res=0;
    repA(i,1,n)
    {
        repA(j,1,n)
        {
            int g=gcd(max(i,j),min(i,j));
            repA(k,1,n)
            {
                int gg=gcd(max(g,k),min(g,k));
                res+=gg;
            }

        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define LL long long
inline LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
signed main(){
	int n=read();
	LL x=0,y,z=y=-10000000000000ll;
	for (int i=1;i<=n;++i){
		LL p=read();x+=p;y-=p;z+=p;
		if (p<0){
			z=max(y,z);y=max(x,y);
		}
		x=max(x,y);y=max(y,z);
	}
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

void print(Vl vec){
    rep(i, 0, sz(vec)){
        if(i) cout << " ";
        cout << vec[i];
    }
    coel;
}

////////////////////////////////////////////////////////

vector<Vl> G;
Vl kto; // kから各頂点への距離
ll n; 
map<pair<ll, ll>, ll> dis;
ll q, k; 
ll color[100005];

void bfs(){
    queue<ll> qu;
    qu.push(k);
    color[k] = 1;
    while(!qu.empty()){
        ll v = qu.front(); qu.pop();
        color[v] = 1;
        rep(j, 0, G[v].size()){
            if(color[G[v][j]]) continue;
            qu.push(G[v][j]);
            kto[G[v][j]] = kto[v] + dis[{v, G[v][j]}];
        }
    }
}

int main() {
    cin >> n;
    G.resize(n+1);
    rep(i, 0, n-1){
        ll a, b, c; cin >> a >> b >> c;
        G[a].push_back(b);
        G[b].push_back(a);
        dis[{a, b}] = c;
        dis[{b, a}] = c;
    }
    cin >> q >> k;
    kto.resize(n+1);
    kto[k] = 0;
    bfs();

    Vl ans;
    rep(i, 0, q){
        ll x, y; cin >> x >> y;
        ans.push_back(kto[x]+kto[y]);
    }
    rep(i, 0, q) co(ans[i]);

    return 0;
}


Measured memory_bytes: 22520
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair

struct floppy{
public:
	int p[30]; //0-origin
	void in(){
		for(int i=0; i<30; i++) cin >> p[i];
	}
	void turn(int i){
		if(i == 0) f1();
		if(i == 1) f2();
		if(i == 2) f3();
		if(i == 3) f4();
	}
	void swap(int i, int j){
		std::swap(p[i-1], p[j-1]);
	}
	bool check(){
		for(int i=1; i<9-1; i++){
			if(p[i-1] != p[i]) return false;
		}
		for(int i=10; i<12-1; i++){
			if(p[i-1] != p[i]) return false;
		}
		for(int i=13; i<15-1; i++){
			if(p[i-1] != p[i]) return false;
		}
		for(int i=16; i<18-1; i++){
			if(p[i-1] != p[i]) return false;
		}
		for(int i=19; i<21-1; i++){
			if(p[i-1] != p[i]) return false;
		}
		for(int i=22; i<30-1; i++){
			if(p[i-1] != p[i]) return false;
		}
		return true;
	}
	void f1(){
		swap(1, 28);
		swap(2, 29);
		swap(3, 30);
		swap(19, 21);
		swap(15, 16);
	}
	void f2(){
		swap(1, 24);
		swap(4, 27);
		swap(7, 30);
		swap(16, 18);
		swap(10, 21);
	}
	void f3(){
		swap(7, 22);
		swap(8, 23);
		swap(9, 24);
		swap(10, 12);
		swap(13, 18);
	}
	void f4(){
		swap(3, 22);
		swap(6, 25);
		swap(9, 28);
		swap(13, 15);
		swap(12, 19);
	}
};

int dfs(floppy f, int c){
	if(f.check()) return c;
	if(c > 8) return INT_MAX;
	int m = INT_MAX;
	for(int i=0; i<4; i++){
		f.turn(i);
		m = min(m, dfs(f, c+1));
		f.turn(i);
	}
	return m;
}

int main(){
	int N;
	cin >> N;
	for(int i=0; i<N; i++){
		floppy f;
		f.in();
		cout << dfs(f, 0) << endl;
	}
}


Measured memory_bytes: 3124
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}
 
inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}
 
inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}
 
template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

#define int long long

const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 1e2 + 15;
int n;
pii a[N];

main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    // setin("input.txt");
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i].f >> a[i].se;
    sort(a + 1, a + 1 + n, [&](pii a, pii b) {
        return atan2(a.f, a.se) < atan2(b.f, b.se);
    });
    for(int i = 1; i <= n; ++i)
        a[i + n] = a[i];
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        pii cur(0, 0);
        for(int j = i; j <= i + n - 1; ++j) {
            cur.f += a[j].f;
            cur.se += a[j].se;
            Max(ans, cur.f * cur.f + cur.se * cur.se);
        }
    }
    cout.precision(30);
    cout << sqrt(ans) << endl;
    return 0;
}

Measured memory_bytes: 4172
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	int count = 1;
	int ans = 0;
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[] flag = new boolean[51];
		int[] a = new int[51];
		int[] b = new int[51];
		int[][] V = new int[51][51];
		int m = sc.nextInt();
		for(int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			V[a[i]][b[i]] = V[b[i]][a[i]] = 1;
		}
		Deque<Integer> q = new ArrayDeque<>();
		for(int i = 0; i < m; i++) {
			V[a[i]][b[i]] = V[b[i]][a[i]] = 0;
			q.push(1);
			flag[a[0]] = true;
			while(!q.isEmpty()) {
				int tmp = q.pop();
				for(int j = 1; j <= n; j++) {
					if(V[tmp][j] == 1 && !flag[j]) {
						q.push(j);
						flag[j] = true;
						count++;
					}
				}
			}
			if(count != n) {
				ans++;
			}
			count = 1;
			V[a[i]][b[i]] = V[b[i]][a[i]] = 1;
			Arrays.fill(flag, false);;
		}
		System.out.println(ans);
		sc.close();
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23892
N = gets.to_i
array = gets.split(" ").map{|item| item.to_i}


gaps = []


for i in 1...N
  s1 = 0
  s2 = 0
  subarray1 = array.slice(0, i)
  subarray2 = array.slice(i, N-1)
  for i in 0...subarray1.length
    s1 += subarray1[i]
  end
  for i in 0...subarray2.length
    s2 += subarray2[i]
  end
  gaps.push((s1-s2).abs)
end


p gaps.min

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

int main(){
  int n,m;
  cin >> n >> m;
  int a[m],b[m];
  for(int i=0;i<m;i++){
    cin >> a[i] >> b[i];
  }
  int ans[n];
  for(int i=0;i<n;i++){
    ans[i]=0;
  }
  for(int i=0;i<m;i++){
    ans[a[i]-1]++;
    ans[b[i]-1]++;
  }
  for(int i=0;i<n;i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;

int main()
{
    ll a,b,x,ans=0;
    scanf("%lld %lld %lld",&a,&b,&x);
    ll k,q;
    if (a%x==0) k=a/x;
    else k=a/x+1;
    q=b/x;
    ans=q-k+1;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a;
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

int main() {
	ll H, W;
	cin >> H >> W;
	ll h, w;
	cin >> h >> w;
	cout <<H*W-( H * w + W * h - h * w);
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF (1<<29)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
int N,A[2],a;
int main(void){
    scanf("%d",&N);
    F(N)scanf("%d",&a),++A[a&1];
    printf("%s\n",A[1]&1?"NO":"YES");
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    string n;
    int ct=0,ans=0;
    cin >> n;
    rep(i,n.size()){
        if(n[i] == 'A' || n[i] == 'C'|| n[i] == 'G'|| n[i] == 'T'){
            ct++;
        } else{
            ans=max(ans,ct);
            ct=0;
        }
    }
    cout << max(ans,ct) << endl;
    return 0;
}

Measured memory_bytes: 256