akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
priority_queue<int> q;
int h, w, c[26];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  FOR(_, 0, h){
    string s;
    cin >> s;
    FOR(i, 0, w) c[s[i]-'a']++;
  }
  FOR(i, 0, 26) q.push(c[i]);
  int d[3] = {(h/2)*(w/2), h%2*w/2+w%2*h/2, (h%2)*(w%2)};
  int e[3] = {4,2,1};
  FOR(i, 0, 3)FOR(_, 0, d[i]){
    int t = q.top();
    q.pop();
    if(t<e[i]){
      cout << "No" << endl;
      return 0;
    }
    t-=e[i];
    q.push(t);
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100005
#define ll long long
using namespace std;
const int N = 1e5 + 7;
string str[N];
map <string, ll> mp;
int main()
{
    int n; cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> str[i];
        sort(str[i].begin(), str[i].end());
        mp[str[i]]++;
    }
    ll ans = 0;
    for(auto it : mp)
        ans += (it.second * (it.second - 1)) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef vector<int> VI;
typedef VI::iterator VII;

int d, n, m;
VI shop, customer;
int ans;

int main()
{
  while(true){
    scanf("%d", &d);
    if(!d)
      break;
    shop.clear();
    customer.clear();
    ans = 0;

    scanf("%d%d", &n, &m);
    shop.push_back(0);
    for(int i = 1; i < n; i++){
      int in;
      scanf("%d", &in);
      shop.push_back(in);
    }
    shop.push_back(d);
    
    for(int i = 0; i < m; i++){
      int in;
      scanf("%d", &in);
      customer.push_back(in);
    }
    
    sort(shop.begin(), shop.end());
    for(int i = 0; i < m; i++){
      VII p = lower_bound(shop.begin(), shop.end(), customer[i]);
      ans += min(customer[i] - *(p - 1), *p - customer[i]);
    }
    
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1808
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

int main() {
		int N;
		cin >> N;
		vector<ll> d(26, 0);
		for (int i = 0; i < N; i++) {
				string S;
				cin >> S;
				d[S[0]-'A']++;
		}

		ll ans = 0;
		ans += d['M'-'A'] * d['A'-'A'] * d['R'-'A'];
		ans += d['M'-'A'] * d['A'-'A'] * d['C'-'A'];
		ans += d['M'-'A'] * d['A'-'A'] * d['H'-'A'];
		ans += d['M'-'A'] * d['R'-'A'] * d['H'-'A'];
		ans += d['M'-'A'] * d['R'-'A'] * d['C'-'A'];
		ans += d['M'-'A'] * d['C'-'A'] * d['H'-'A'];
		ans += d['A'-'A'] * d['R'-'A'] * d['C'-'A'];
		ans += d['A'-'A'] * d['R'-'A'] * d['H'-'A'];
		ans += d['A'-'A'] * d['C'-'A'] * d['H'-'A'];
		ans += d['R'-'A'] * d['C'-'A'] * d['H'-'A'];

		cout << ans << endl;

		return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 


signed main(){
    FASTER;
    int n;cin>>n;
    int ans=n;
    for(int i=1;i<n;i++){
        int x,y;cin>>x>>y;
        if(x>y)swap(x,y);
        ans-=(x*(n-y+1));
        ans+=i*(n-i+1);
    }
    cout<<ans;
}

Measured memory_bytes: 3528
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long double mod = 1000000007;

struct DSU{
	vector<int> p,sz;
	DSU(int N){
		p.resize(N);
		sz.resize(N,1);
		for(int i = 0;i < N;i++)p[i] = i;
	}
	int par(int x){
		if(x == p[x])
			return x;
		return p[x] = par(p[x]);
	}
	bool mrg(int x,int y){
		x = par(x),y = par(y);
		if(x == y)
			return false;
		if(sz[x] < sz[y]){
			swap(x,y);
		}
		p[y] = p[x];
		sz[x] += sz[y];
		return true;
	}
};

int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int N,M,u,v;
	cin>>N>>M;
	vector<int> p(N);
	DSU dsu(N);
	for(int i = 0;i < N;i++) cin>>p[i],p[i]--;
	for(int i = 0;i < M;i++) {
		cin>>u>>v;
		u--,v--;
		dsu.mrg(u,v);
	}
	int res = 0;
	for(int i = 0;i < N;i++) res += dsu.par(i) == dsu.par(p[i]);
	cout<<res<<'\n';
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[10000];
    int count=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        while(true){
            if(a[i]%2==1)break;
            count++;
            a[i]/=2;
        }
    }
    cout << count << endl;
}

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

int main() {
	int N;
  	cin >> N;
  
  	int i, y = 0;
  	while (i < N) {
    	string h;
      	cin >> h;
      
      	if (h == "Y") {
        	y += 1;
        }
      	i++;
    }
 	
  	if (y >= 1) {
    	cout << "Four" << endl;
    }
  	
  	else if (y == 0){
    	cout << " Three" << endl;
    }
}


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

int main(){
	double a,b,c,d,e,f;
	while(cin >> a >> b >> c >> d >> e >> f){
		double denom = a * e - b * d;
		double x = (c * e - b * f) / denom;
		double y = (a * f - c * d) / denom;
		if(x == 0) x = 0;
		if(y == 0) y = 0;
		printf("%.3lf ", x);
		printf("%.3lf\n", y);
	}
	return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
int main(){
char a[105];
    int N,L;
    int b,ans=0,flag=0;
    string display;

    vector<string> aheahe;


    cin>>N>>L;

    for(int i=0;i<N;i++){
        cin>>display;
        aheahe.push_back(display);
    }
    sort(aheahe.begin(),aheahe.end());


    for(int i=0;i<N;i++){ 
        cout<<aheahe[i];
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

bool solve(){
  int n;
  string s[1000];
  cin >> n;

  if(n == 0) return false;

  int prevLevel = -1;
  
  for(int i=0;i<n;i++){
    cin >> s[i];
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<s[i].size();j++){
      if(s[i][j] != '.') break;
      
      if(s[i][j+1] != '.'){
        s[i][j] = '+';
        for(int k=i-1;k>=0;k--){
          if(s[k][j] == ' ') s[k][j] = '|';
          else break;
        }
      }else{
        s[i][j] = ' ';
      }
    }
  }

  for(int i=0;i<n;i++){
    cout << s[i] << endl;
  }
  
  return true;
}

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



Measured memory_bytes: 3836
from _collections import deque

n = int(input())
data_input = []
dlList = deque()
for i in range(n):
    x = input().split()
    if x[0] == 'insert':
        dlList.appendleft(x[1])
    elif x[0] == 'delete':
        if x[1] in dlList:
            dlList.remove(x[1])
        else :
            pass
    elif x[0] == 'deleteFirst':
        dlList.popleft()
    elif x[0] == 'deleteLast':
        dlList.pop()
    else:
        pass

print(' '.join(dlList))

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N, 0);
    rep(i, N) cin >> a.at(i);
    sort(a.begin(), a.end());
    
    int score = 0;
    rep(i, N) score += pow(-1, i) * a.at(N - i - 1);
    cout << score << endl;

    return 0;
}

Measured memory_bytes: 3884
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    yesno(s < t);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lowbit(i) ((i)&-(i)) 

using namespace std;

int n=100100,bit[100100];

void add(int i,int x)
{
	while(i<=n)
	{
		bit[i]+=x;
		i+=lowbit(i);
	}
}

int sum(int x)
{
	int s=0;
	while(x>0)
	{
		s+=bit[x];
		x-=lowbit(x);
	}
	return s;
}

int main()
{
	int n,t;
	scanf("%d%d",&n,&t);
	memset(bit,0,sizeof(bit));
	for(int i=0;i<n;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		add(l+1,1);add(r+1,-1);
	}
	int ma=0;
	for(int i=0;i<=t+1;i++)
		ma=max(ma,sum(i));
	printf("%d\n",ma);
	return 0;
}

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

int main(void){
	int n,odd_num,even_num;
	double ans;
    cin >> n;
	if(n == 1){
		cout << "1.00" << endl;
	} else if(n % 2 == 0){
		cout << "0.50" << endl;
	} else{
		odd_num = n / 2 + 1;
		ans = (double)odd_num / (double)n;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 20
#define Q 200

void solve(int,int);

int A[N],M[Q];
int count,n;

int main(){ 
  int q,i;
  
  scanf("%d", &n);
  for( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  scanf("%d", &q);
  for( i = 0; i < q; i++ ) scanf("%d", &M[i]);
  
  for(i=0;i<q;i++){
    count=0;
    solve(0,M[i]);
    if(count==0) printf("no\n");
  }
  return 0;
}

void solve(int i,int m){
  if(i<n && count==0 && m>0){
    if(A[i]==m){
      printf("yes\n");
      count++;
      return;
    }
  solve(i+1,m-A[i]);
  solve(i+1,m);
  }
}

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

int main(){

 while(true){

  int x,y;
  cin>>x>>y;

   if(
      x == 0 && y == 0
     )break;
    else if(
            x <= y
                  )cout<<x<<" "<<y<<endl;
    else
         cout<<y<<" " <<x<<endl;

 }
return 0;
}
  


Measured memory_bytes: 3068
N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K):
  new = [0] * (N+1)
  for j in range(N):
    new[max(0, j-A[j])] += 1
    if j+A[j]+1 <= N-1:
      new[j+A[j]+1] -= 1
  A[0] = new[0]
  for j in range(1, N):
    new[j] += new[j-1]
    A[j] = new[j] 
  for ai in A:
    if ai != N:
      break
  else:
    break
    
print(' '.join([str(ai) for ai in A]))


Measured memory_bytes: 148508
import itertools
import math

n=int(input())
a=list(input().split())
b=list(input().split())
a="".join(a)
b="".join(b)
suuji=""
for i in range(1,n+1):
    suuji+=str(i)
info=[]
for i in itertools.permutations(suuji):
    new_i="".join(list(i))
    info.append(new_i)
a_index,b_index=0,0
for i in range(math.factorial(n)):
    if info[i]==a:
        a_index=(i+1)
    if info[i]==b:
        b_index=(i+1)
print(abs(a_index-b_index))

Measured memory_bytes: 6064
#include <iostream>
#include <string>
using namespace std;
int dh[]={-1,0,1,0},dw[]={0,1,0,-1},h,w;
string s[101];
void dfs(int _h,int _w,char ch){
	s[_h][_w]='.';
	for(int i=0;i<4;i++){
		int H=_h+dh[i],W=_w+dw[i];
		if(H>=0&&H<h&&W>=0&&W<w&&s[H][W]==ch)dfs(H,W,ch);
	}
}
int main(){
	while(cin>>h>>w,h){
		int count=0;
		for(int i=0;i<h;i++)cin>>s[i];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(s[i][j]!='.')count++,dfs(i,j,s[i][j]);
		cout<<count<<endl;
	}
}

Measured memory_bytes: 2160
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) {
    cin >> s[i];
  }
  set<string> st;
  rep(i, n) {
    st.insert(s[i]);
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 25012
#include <stdio.h>

int main(void){
	int n,d,cnt=1,ans;
	scanf("%d %d",&n,&d);
	
	ans = 2*d + 1;
	for(int i=0;i<n;i++){
		if(n - ans <= 0){
			break;
		}else{
			cnt++;
			ans += 2*d + 1;
		}
	}
	printf("%d\n",cnt);
	
	
	return 0;
}

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

using namespace std;
string S = "";
string T = "";
string U = "";

typedef long long int LLi;

LLi K;

int main(){

	cin >> S >> K;
	
	T = S + S;
	U = T + S;

    int S_len = S.length();
    int T_len = T.length();
    int U_len = U.length();
    
    string hitomoji = "";
    string hitomoji_mae = "A";
    
    string hajime;
    string owari;
    
    hajime = S[0];
    owari =  S[S.length()-1];
    if(S.length() == 1){
        owari = hajime;
    }
    
    LLi count[3] = {0};
    bool triger = true;
    
    for(LLi i=0; i<S_len;i++){
        hitomoji = S[i];
        
        if(hitomoji == hitomoji_mae){
            if(triger == false){
                triger = true;
            }else{
                count[0] ++;
                triger = false;
            }
        }else{
            triger = true;
        }
        
        hitomoji_mae = hitomoji;
    }
    
    hitomoji = "";
    hitomoji_mae = "A";
    
    for(LLi i=0; i<T_len;i++){
        hitomoji = T[i];
        
        if(hitomoji == hitomoji_mae){
            if(triger == false){
                triger = true;
            }else{
                count[1] ++;
                triger = false;
            }
        }else{
            triger = true;
        }
        
        hitomoji_mae = hitomoji;
    }
    
    
    hitomoji = "";
    hitomoji_mae = "A";
    
    for(LLi i=0; i<U_len;i++){
        hitomoji = U[i];
        
        if(hitomoji == hitomoji_mae){
            if(triger == false){
                triger = true;
            }else{
                count[2] ++;
                triger = false;
            }
        }else{
            triger = true;
        }
        
        hitomoji_mae = hitomoji;
    }
 //   cout << count[0]<< " "<<count[1]<<endl;
    
    
    if(S_len == 1){
        count[0] = 0.5*K;
    }else{
        if(count[0]*2 == count[1]){
            count[0] = count[0] * K;
            
        }else if(count[0]==0 && count[1]==0){
            count[0] = 0;
        
        }else if(count[0]==0 && count[1]>=0){
            count[0] = K-1;
            
        }else{
            
            int hikaku[2] ;
            hikaku[0] = count[1]-count[0];
            hikaku[1] = count[2]-count[1];
  //          cout << count[2] <<count[1]<< count[0]<<en
   //         cout <<hikaku[0]<<" "<<hikaku[1]<<endl;
                if(hikaku[0] == hikaku[1]){
                    count[0] = count[0] + hikaku[0]*(K-1);
                }else{
                    double temp = count[0]+0.5;
                    count[0] = temp * K;
                }
 //           float temp = (float)count[0] + 0.5;
 //           count[0] =((int)(temp*(float)K)); 
        }
    }
    
    cout << count[0]<<endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

vector<vector<int>> table(10, vector<int>(10));

int check(string s)
{
    int res = 0;
    res = table[res][s[0] - '0']; // a
    res = table[res][s[1] - '0']; // b
    res = table[res][s[2] - '0']; // c
    res = table[res][s[3] - '0']; // d
    res = table[res][s[4] - '0']; // e
    return res;
}

int calc(int x)
{
    int res = 0, tmp = x;
    res = table[res][tmp / 1000];
    tmp %= 1000;
    res = table[res][tmp / 100];
    tmp %= 100;
    res = table[res][tmp / 10];
    tmp %= 10;
    res = table[res][tmp];
    return res;
}

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

    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin >> table[i][j];
        }
    }
    int res = 0;
    for (int i = 0; i <= 9999; i++)
    {
        int x = i * 10 + calc(i);
        string s = to_string(x);
        while (s.length() < 5)
        {
            s = '0' + s;
        }
        bool f = false;
        for (int j = 0; j < 4; j++)
        {
            string t = s;
            swap(t[j], t[j + 1]);
            if (s == t)
                continue;
            if (check(t) == 0)
                f = true;
        }
        for (int j = 0; j < 5; j++)
        {
            for (int k = 0; k <= 9; k++)
            {
                string t = s;
                t[j] = '0' + k;
                if (s == t)
                    continue;
                if (check(t) == 0)
                    f = true;
            }
        }
        if (f)
            res++;
    }
    cout << res << endl;
}



Measured memory_bytes: 3296
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    if(n%2==0)
        printf("0.5000000000\n");
    else
    {
        double x=(n+1)/2;
        double y=n;
        double z=x/y;
        printf("%.10lf",z);
    }
    return 0;
}


Measured memory_bytes: 256
dice = list(map(int, input().split()))
dir = list(input())
newdice = [0]*6

for i in dir:
    if i == 'N':
        newdice[0] = dice[1]
        newdice[1] = dice[5]
        newdice[5] = dice[4]
        newdice[4] = dice[0]
        newdice[2] = dice[2]
        newdice[3] = dice[3]

    elif i == 'E':
        newdice[0] = dice[3]
        newdice[3] = dice[5]
        newdice[5] = dice[2]
        newdice[2] = dice[0]
        newdice[1] = dice[1]
        newdice[4] = dice[4]
    elif i == 'S':
        newdice[0] = dice[4]
        newdice[4] = dice[5]
        newdice[5] = dice[1]
        newdice[1] = dice[0]
        newdice[2] = dice[2]
        newdice[3] = dice[3]
    else:
        newdice[0] = dice[2]
        newdice[2] = dice[5]
        newdice[5] = dice[3]
        newdice[3] = dice[0]
        newdice[1] = dice[1]
        newdice[4] = dice[4]

    dice = newdice[:]

print(dice[0])


Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  int sum = 0;
  vector<int> t(N);
  REP(i, N){
    cin >> t[i];
    sum += t[i];
  }

  vector<int> v(N);
  REP(i, N) cin >> v[i];

  int MAX_T = sum*2+1;

  vector<double> vec(MAX_T, INF);

  for(double i = 0; i <= sum; i += 0.5){
    chmin(vec[i*2], i);
    chmin(vec[i*2], (double)sum-i);
  }

  int time = 0;
  REP(i, N){
    for(double j = time; j >= 0; j -= 0.5){
      chmin(vec[j*2], (double)v[i]+(double)(time-j));
    }
    for(double j = time; j <= time+t[i]; j += 0.5){
      chmin(vec[j*2], (double)v[i]);
    }
    for(double j = time+t[i]; j <= sum; j += 0.5){
      chmin(vec[j*2], (double)v[i]+(double)(j-(time+t[i])));
    }
    time += t[i];
  }

  double ans = 0;
  FOR(i, 1, MAX_T){
    ans += (vec[i]+vec[i-1])/4;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()
#include <numeric>
#include <tuple>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);

lint n, d;
lint h, w;

int main(){
//////////////////////////////////////////////////////

    cin >> n;
    vector<lint> a(n);
    vector<lint> b(n);

    rep(i,n)
    {
        cin >> a[i];
        b[i] = a[i];
    }


    //fpair<lint,lint> p = make_pair(1,2);
    //tuple<lint,lint,lint> t  = make_tuple(1,2,3);






    //昇順ソート
    sort(all(b));
    lint max1 = b[n-1];
    lint max2 = b[n-2];

    rep(i,n)
    {
        if(max1 == a[i]) cout << max2 << endl;
        else cout << max1 << endl;

    }



    

   

    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();


    //////////////////////////////////////////////////////
    // DP

//     // 無限大の値
//     const uint64_t INF = (uint64_t)1 << 60;
//     //const int64_t NINF = -1 * ((int64_t)1 << 60 );
 
//     // DP テーブル
//     uint64_t dp[100010];

//     //DPテーブル初期化（最小化用）
//     for (int i = 0; i < 100010; ++i)
//     {
//         //dp[i] = INF;
//         dp[i] = 0;
//     } 

//     // 初期条件
//     dp[0] = 0;

//     // ループ
//     for (int i = 1; i <= n; ++i) {
//         //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
//         //if (i < 2)continue;
//         //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));



//         // chmax ( dp [i] , dp[i - 1]);
//         // chmax ( dp [i] , dp[i - 1] + input[i]);
//         // cout << "dp[" << i <<"] = " << dp[i] << endl;

//     }



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

     //cout << (n+(d*2+1)-1)/(d*2+1) << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
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;
}


// vectorprint用
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// //合計
// template<class T> lint sum(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0);
// }


// //平均
// template<class T> double ave(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }


Measured memory_bytes: 4736
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> B(N - 1);
    for (int i = 0; i < N - 1; i++) {
        cin >> B[i];
    }

    long long ans = 0;
    ans += B[0];
    for (int i = 0; i < N - 2; i++) {
        ans += min(B[i], B[i + 1]);
    }
    ans += B[N - 2];

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const ld pi=acos(-1);
const int N=3005;
ld ansx,ansy;
int a[N];
int main(){
	//cout<<pi<<endl;
	//cout<<cos(pi/4)<<endl;
	int n=read(),L=read();
	For(i,1,n)a[i]=read();
	For(i,1,n){
		For(j,i+1,n){
			ansx+=cos(pi*(a[i]+a[j])/L)*(n-j+i-1-(j-i-1));
			ansy+=sin(pi*(a[i]+a[j])/L)*(n-j+i-1-(j-i-1)); 
			//cout<<cos(pi*(a[i]+a[j])/L)<<endl;
		}
	}
	ll cnt=(ll)n*(n-1)*(n-2)/6;
	ansx/=cnt; ansy/=cnt;
	printf("%.10lf %.10lf\n",ansx,ansy);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
 
signed main(){

	lli x;
	cin>>x;

	if(x==1){
		cout<<1<<endl;
		return 0;
	}
	lli ans=1;

	for(lli b=2;b<=x;b++){
		for(lli j=b*b;j<=x;j*=b){
			ans=max(ans,j);
		}
	}
	cout<<ans<<endl;

	return 0;
 
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

ll N, K;
vector<ll> A;

int main() {
    cin >> N >> K;
    A.resize(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll ans = 0;
    bool under = false;
    for (ll i = 63; i >= 0; i--) {
        ll num1 = 0;
        for (ll j = 0; j < N; j++) {
            num1 += (A[j] & (1LL << i)) != 0;
        }

        if (!under && ((K & (1LL << i)) == 0)) {
            //0しか選べない
        } else {
            if (num1 >= N - num1) {
                //0を選んだ方が良い
                under = true;
            } else {
                //1を選んだ方が良い
                num1 = N - num1;
            }
        }
        ans += num1 * (1LL << i);
    }
    cout << ans << endl;
}

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

int main() {
  string a, b;
  cin >> a;
  cin >> b;
  if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = Integer.parseInt(sc.nextLine().split(" ")[0]);

		List<StringBuilder> outputList = new ArrayList<StringBuilder>();
		String inputLine;
		for (int i = 1; i <= h; i++) {
			inputLine = sc.nextLine();
			if (inputLine.indexOf("#") == -1) {
				continue;
			}
			outputList.add(new StringBuilder(inputLine));
		}
		StringBuilder firstLine = new StringBuilder(outputList.get(0));
		int lastIndex = firstLine.lastIndexOf(".");
		long listSize = outputList.size();
		while (lastIndex >= 0) {
			final int targetIndex = lastIndex;
			if (outputList.stream().filter(e -> (e.charAt(targetIndex) == '.')).count() == listSize) {
				outputList.forEach(e -> e.deleteCharAt(targetIndex));
			}

			firstLine.deleteCharAt(targetIndex);
			lastIndex = firstLine.lastIndexOf(".");
		}

		outputList.forEach(e -> System.out.println(e));

		sc.close();
	}
}

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

bool check(string s) {
  int n = s.length();
  rep(i, n / 2) {
    if (s[i] != s[n - 1 - i]) return false;
  }
  return true;
}

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

  int n = s.length();
  string t = s.substr(0, (n - 1) / 2), u = s.substr((n + 1) / 2);
  if (check(s) && check(t) && check(u)) cout << "Yes" << endl;
  else cout << "No" << endl;



  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n,m;
    cin>>n>>m;
    char datan[51][51]={'\0'},datam[51][51]={'\0'};
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>datan[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            cin>>datam[i][j];
        }
    }
   
    for(int i=0;i<n-m+1;i++){
        for(int j=0;j<n-m+1;j++){
            int s=i,cnt=0;
            for(int k=0;k<m;k++,s++){
                int t=j;
                for(int l=0;l<m;l++,t++){
                    if(datan[s][t]!=datam[k][l]){
                        cnt++;
                    }
                }
            }
            if(cnt==0){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
MAX = int(2e5)


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    ans = 0
    for i in range(K-1, N):
        ans = (ans + A[i] * FACT[i] * INV[K-1] * INV[i - (K-1)]) % MOD
    for i in range(N - (K-1)):
        ans = (ans - A[i] * FACT[N-i-1] * INV[K-1] * INV[N-i-1 - (K-1)]) % MOD
    print(ans)


if __name__ == "__main__":
    main()


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


using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    
    int left = 1,right = N;

    for(int i = 0; i < M; i++){
        int l,r;
        cin >> l >> r;
        left = max(left,l);
        right = min(right, r);
    }
    //一つも存在しないと大抵マイナスになっているので。
    cout << max(0,right - left + 1) <<endl;

    return 0;
}

Measured memory_bytes: 256
N,M,Q = map(int,input().split())
toshi = []
for i in range(M):
  toshi.append(tuple(map(int,input().split())))
query = []
for i in range(Q):
  query.append(tuple(map(int,input().split())))
grid = []
for i in range(N+1):
  grid.append([0]*(N+1))
for i in range(M):
  grid[toshi[i][1]][toshi[i][0]] += 1
for i in range(1,N+1):
  for j in range(1,N+1):
    grid[i][j] += grid[i][j-1]
for i in range(Q):
  ans = 0
  for j in range(query[i][1]-query[i][0]+1):
    ans += (grid[query[i][0]+j][query[i][1]]-grid[query[i][0]+j][query[i][0]-1])
  print(ans)

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

int main(){
    ll n;
    cin >> n;
    ll sum = 1e13;
    for(ll i = 1; i*i <= n; i++){
        if(n % i == 0) sum = min(sum, n/i + i);
    }

    cout << sum-2 << endl;
}

Measured memory_bytes: 3592
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    BC = [list(map(int,input().split())) for _ in range(m)]

    BC = sorted(BC,key=lambda x:(x[1]),reverse=True)
    append_list = []
    for b,c in BC:
        if len(append_list)>=n:
            break
        append_list+=[c]*b
    A+=append_list
    A.sort(reverse=True)
    print(sum(A[:n]))

if __name__=='__main__':
    main()

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 2020;

int n;
pair<ll,ll> a[maxn];
ll dp[maxn][maxn];

ll f(int l, int r) {
    if (l>r) return 0;
    if (~dp[l][r]) return dp[l][r];
    ll &res=dp[l][r]=0;
    ll pos=n-1-(r-l);
    res=max(res,abs(a[pos].second-l)*a[pos].first + f(l+1,r));
    res=max(res,abs(a[pos].second-r)*a[pos].first + f(l,r-1));    
    return res;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>a[i].first;
	a[i].second=i;
    }

    sort(a,a+n);
    reverse(a,a+n);

    f(0,n-1);
    cout<<dp[0][n-1]<<endl;    
  

    return 0;
}


Measured memory_bytes: 35724
from collections import deque
V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
    u, _, *v = map(lambda x: int(x)-1, input().split())
    edge[u] = v
dist = [-1] * V
dist[0] = 0
que = deque([0])

while len(que):
    v = que.popleft()
    for c in edge[v]:
        if dist[c] == -1:
            dist[c] = dist[v] + 1
            que.append(c)
for i, d in enumerate(dist):
    print(i+1, d)

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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define bits(n) __builtin_popcount(n)

void solve()
{
    int r,g,b;
    int k;
    cin>>r>>g>>b;
    cin>>k;

    while(k!=0&& r>=g)
    {
        g*=2;
        k--;
    }
    while (k!=0 && g>=b)
    {
        b*=2;
        k--;
    }
    if(r<g&&r<b&&g<b)
    cout<<"Yes";
    else
    {
        cout<<"No";
    }    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
def myAnswer(N:int,A:list) -> int:
   if(N == 1): return 1
   dic ={}
   for a in A:
      if(a == 0):
         for i in range(2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i]=1
      else:
         for i in range(a-1,a+2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i] = 1
   return max(list(dic.values()))

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

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

int n;
int main() {
    scanf("%d", &n);
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        int p;
        scanf("%d", &p);
        if (p != i) ++cnt;
    }
    if (cnt <= 2)
        puts("YES\n");
    else
        puts("NO\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    string S;
    cin >> S;

    int min = MOD;

    REP(i,int(S.length()) - 2)
    {
        int hyaku = S[i] - '0';
        int juu = S[i+1] - '0';
        int iti = S[i+2] - '0';
        int suuji = hyaku * 100 + juu * 10 + iti;
        int sa = abs(suuji - 753);
        if(sa < min) min = sa;
    }
    cout << min << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<complex>
using namespace std;

typedef complex<double> P;
struct L : public vector<P>{
    L(const P &a, const P &b){
        push_back(a), push_back(b);
    }
};
const double EPS = 1e-8;

namespace std {
  bool operator < (const P& a, const P& b) {
    return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
  }
}

double cross(const P &a, const P &b){
    return imag(conj(a)*b);
}

double dot(const P &a, const P &b){
    return real(conj(a)*b);
}

int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > 0) return +1;
    if(cross(b,c) < 0) return -1;
    if(dot(b,c) < 0) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}

P crosspoint(const L &l, const L &m) {
    double A = cross(l[1] - l[0], m[1] - m[0]);
    double B = cross(l[1] - l[0], l[1] - m[0]);
    if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
    return m[0] + B / A * (m[1] - m[0]);
}

#define curr(G, i) G[i%n]
#define next(G, i) G[(i+1)%n]

double area(vector<P> &G){
    int n = G.size();

    double S = 0;
    for (int i=0;i<n;i++){
        P p = curr(G, i);
        P q = next(G, i);
        S += (1.0/2)*cross(p, q);
    }

    return S;
}

double convexCut(vector<P> &G, P &p1, P &p2){
    int n= G.size();
    L l(p1, p2);
    vector<P> leftG;
    /*
    //??¨????????´???????????´??????0?????????
    bool flag = true;
    for (int i=0;i<n;i++){
        if(ccw(p1, p2, G[i]) == 1){
            flag = false;
        }
    }

    if (flag) return 0;
    */
    //?????\??????????????????1?????\???????????´???????¨????
    for (int i=0;i<n;i++){
        if(ccw(p1, p2, curr(G,i))!= -1){
            leftG.push_back(curr(G,i));
            if(ccw(p1, p2, next(G,i)) == -1 ){
                L s(curr(G, i), next(G, i));
                leftG.push_back(crosspoint(l, s));
            }
        }else{
            if(ccw(p1, p2, next(G,i)) != -1 ){
                L s(curr(G, i), next(G, i));
                leftG.push_back(crosspoint(l, s));
            }
        }
    }
    return area(leftG);
}

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

    vector<P> G;
    P p, q;
    for (int i=0;i<n;i++){
        cin >> p.real() >> p.imag();
        G.push_back(p);
    }

    cin >> Q;
    for (int i=0;i<Q;i++){
        cin >> p.real() >> p.imag() >> q.real() >> q.imag();
        printf("%.7f\n", convexCut(G, p, q));
    }

    return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

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

  int n;
  cin >> n;

  if(n == 0) {
    cout << 0 << endl;
    return 0;
  }

  VI mi(40), ma(40); ma[0] = 1;
  int idx = -2, len;
  FOR(i, 1, 40) {
    if(i%2==0) {
      ma[i] = ma[i-1] + idx;
      mi[i] = mi[i-1];
    } else {
      ma[i] = ma[i-1];
      mi[i] = mi[i-1] + idx;
    }

    if(mi[i] <= n && n <= ma[i]) {
      len = i;
      break;
    }
    idx *= -2;
  }

  string ans = "";
  for(int i=len; i>=1; --i, idx/=-2) {
    // i桁目が+
    if(i%2==0) {
      if(mi[i-1] <= n && n <= ma[i-1]) ans += "0";
      else {
        ans += "1";
        n -= idx;
      }
    }
    // i桁目が-
    else {
      if(mi[i-1] <= n && n <= ma[i-1]) ans += "0";
      else {
        ans += "1";
        n -= idx;
      }
    }
  }
  if(n == 1) ans += "1";
  else ans += "0";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			String S = scan.next();
			
		
			char one  = S.charAt(0);			
			char two  = S.charAt(1);			
			char thr  = S.charAt(2);
			
			
			int max = 0;
		
			if(one=='R') {
				
				max++;
				if(two=='R') {
					max++;
					if(thr=='R') {
						max++;
					}else {
						
					}
				}else {
					if(thr=='R') {
						
					}else {
						
					}
					
				}
			}else {
				if(two=='R') {
					max++;
					if(thr=='R') {
						max++;
					}else {
						
					}
				}else {
					if(thr=='R') {
						max++;
					}else {
						
					}
					
				}
			}
			
			
			System.out.println(max);
			
			
			
		}
		
	
		
	}
		

}


Measured memory_bytes: 35768
p = [[[0 for z in range(10)] for y in range(3)] for x in range(4)]

num = int(input())

for i in range(num):
    b,f,r,v = [ int(x) for x in input().split()]
    p[b-1][f-1][r-1] += v
    
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" ",end="")
            print(p[i][j][k],end="")
        print()
    if i < 3:
        print("####################")
        


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  rep(i, 5) {
    int x;
    cin >> x;
    if (x == 0) cout << i + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
N = int(input())
print(0, flush=True)
s = input()
if s == 'Vacant':
    exit()
l, r = 0, N
while True:
    mid = (l + r) // 2
    print(mid, flush=True)
    t = input()
    if s == 'Vacant':
        break
    # 時計回りに席を埋めていくと奇数席で0と性別が異なる
    if mid % 2:
        if s != t:
            l = mid
        else:
            r = mid
    else:
        if s == t:
            l = mid
        else:
            r = mid

Measured memory_bytes: 3660