akhauriyash/Code-Regression huggingface dataset:
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  int d,t,s; cin>>d>>t>>s;
  if (t*s>=d) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3588
/*-- ILSH  --*/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < ll >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < ll , ll >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 
const ll inf=1e18+1e17;
const ll mod =1e9+7;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=	(a*a)%mod;b>>=1;}return (res%mod);}
const int N=1e5+5;
ll arr[N];
void solve(){
	int n,l;
	cin>>n>>l;

	for ( int i=0;i<n;i++)
		cin>>arr[i];
	int mark=-1;
	for ( int i=1;i<n;i++)
		if ( arr[i]+arr[i-1]>=l)
			mark=i;
	if ( mark==-1){
		cout<<"Impossible\n";
		return;
	}
	cout<<"Possible\n";
	vii v;
	for ( int i=mark;i<n;i++)
		v.pb( i);
	for ( int i=mark-1;i>0;i--)
		v.pb(i);
	reverse( v.begin(),v.end());
	for ( int i: v)
		cout<<i<<'\n';



}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	ll t=1;
	//cin>>t;
	for ( ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
    	solve();
    }
}

Measured memory_bytes: 5104
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n;
    cin >> s;
    ll ans = 0;
    char first, second, third='N';
    first = s[0];
    REP(i,1,n)
    {
        if(s[i] != first)
        {
            second = s[i];
            break;
        }
    }
    REP(i,2,n)
    {
        if(s[i] != first && s[i] != second)
        {
            third = s[i];
            break;
        }
    }
    if(third == 'N')
    {
        cout << 0;
        return 0;
    }
    int t=0;
    REP(i,0,n)
    {
        if(s[i] == third) t++;
    }
    REP(i,0,n-1)
    {
        REP(j,i+1,n)
        {
            if((s[i]==first && s[j]==second) || (s[i]==second && s[j]==first))
            {
                ans += t;
                if((j-i+1)%2==1 && s[(i+j)/2] == third) ans--;
                if(2*j-i<n && s[2*j-i] == third) ans--;
                if(2*i-j>=0 && s[2*i-j] == third) ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  int nums[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  if (nums[x] == nums[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

typedef long long ll;

int main(){
  string ip;
  
  cin>>ip;
  ll n=ip.length();
  bool isPossible=false;
  string pattern[4];
  pattern[0]="maerd";
  pattern[1]="remaerd";
  pattern[2]="esare";
  pattern[3]="resare";
  
  ll i=n-1;
  string temp="";
  while(i>=0){
    temp+=ip[i];
    bool found=false;
    for(int j=0;j<4&&!found;j++){
      if(temp==pattern[j]){
        found=true;
        temp="";
      }
    }
    i--;
  }
  
  if(temp==""){
    isPossible=true;
  }
  
  if(isPossible){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3772
(let* ((n (read))
       (k (read))
       (flags (make-array (1+ n) :initial-element nil)))
  (loop for i from 1 to k
        do (let ((d (read)))
             (loop repeat d
                          do (setf (aref flags (read)) t))))
  (format t "~A~%" (1- (count nil flags))))

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

using i64 = long long;

vector<bitset<50>> use_edge;
vector<vector<pair<int, int>>> edge;

bool dfs(int v, int i, int n, int p = -1) {
  if(n == v) return true;
  
  for(auto &e : edge[n]) {
    if(e.first == p) continue;
    
    bool res = dfs(v, i, e.first, n);
    
    if(res) {
      use_edge[i].set(e.second);
      return true;
    }
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  edge = vector<vector<pair<int, int>>>(n);
  for(int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    edge[a - 1].push_back({ b - 1, i });
    edge[b - 1].push_back({ a - 1, i });
  }
  int m;
  cin >> m;
  use_edge = vector<bitset<50>>(m, bitset<50>(0));
  for(int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    dfs(v - 1, i, u - 1);
  }

  i64 cnt = 0;
  for(int bit = 1; bit < (1 << m); ++bit) {
    int popcnt = 0;
    bitset<50> b(0);
    
    for(int i = 0; i < m; ++i) {
      if(bit & (1 << i)) {
        b |= use_edge[i];
        popcnt++;
      }
    }
    
    int e = (n - 1) - b.count();
    
    if(popcnt & 1 == 1) cnt += (1ll << e);
    else cnt -= (1ll << e);
  }

  i64 ans = (1ll << (n - 1)) - cnt;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  int a,b,ans;cin>>a>>b;
  if(a>=13){
    ans = b;
  }else if(a>=6){
    ans = b/2;
  }else{
    ans = 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//Catchharsh
    //I Luv Kunj017
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (int x,int n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    vector<ll> seve;
    void  seveprime()
    {
      int prime[1000000]={0};
      for(int i=2;i*i<1000000;i++)
       {
        if(prime[i]==0)
         {
          for(int j=i*2;j<=1000000;j+=i)
           prime[j]=1;
         }
       }
       for(int i=2;i<=1000000;i++)
       {
         if(prime[i]==0)
           seve.pb(i);
       }
    }
    int main()
    {   
         IOS;
          ll n,m,i,j,k;
          cin>>n;
          vector<ll> v(n);
          vector<ll> ans(n);
          ll sum=0;
          ll osum=0;
          for(i=0;i<n;i++)
          {
            cin>>v[i];
            sum+=v[i];
            if(i%2==0&&i!=(n-1))
              osum=osum+v[i];
          }
          ll last=sum/2-osum;
          ans[n-1]=last;
          for(i=n-2;i>=0;i--)
          {
            ans[i]=v[i]-ans[i+1];
          }
          for(i=0;i<n;i++)
            cout<<ans[i]*2<<" ";
    }

Measured memory_bytes: 2944
#include <cstdio>
#include <algorithm>

const int N = 100000 + 10;

int n, m, a[N];
int pre[N], suf[N];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  pre[1] = a[1];
  for (int i = 2; i <= n; ++i) pre[i] = std::min(a[i], pre[i - 1]);
  int ans = 0, cur = 0;
  for (int i = 2; i <= n; ++i) cur = std::max(cur, a[i] - pre[i - 1]);
  for (int i = 2; i <= n; ++i) if (a[i] - pre[i - 1] == cur) ++ans;
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_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)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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


int n;
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    vl a(n);

    ll ans=1;
    //unsigned long long uans = 1;
    ll LIM=1000000000000000000;
    //ll A=1e18;
    REP(i,n){
        cin>>a[i];
    }

    sort(ALL(a));
    if(a[0] == 0){
        cout<<"0"<<endl;
        return 0;
    }

    ll prv = ans;
    REP(i,n){
        //ll aa;
        //cin>>aa;
        ans *= a[i];
        //uans *= a[i];
        //DEBUG2(ans, uans);
        if( (ans > LIM) || (ans < prv) ){
            ans = -1;
            cout << ans << endl;
            return 0;
        }

        prv = ans;
    }

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

Measured memory_bytes: 3988
N = int(input())
E = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v = sorted(list(map(int, input().split())))
    E[v-1].append(u-1)
ans = 0
for u, adj in enumerate(E):
    ans += (u + 1) * (u + 2) // 2
    if not adj: continue
    adj = sorted(adj, reverse=True)
    for v in adj:
        ans -= (N - u) * (v + 1)
print(ans)

Measured memory_bytes: 35664
#include<bits/stdc++.h>
using namespace std;
int read(){
	int x;scanf("%d",&x);return x;
}
char ch[2001020];
int ans = 0;
int main()
{
	cin>>ch;
	int L = strlen(ch);
	for(int i = 0;i < L;i++) {
		ans += (int)(ch[i]-'0');
		ans %= 9;
	}
	if(ans) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3776
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int D = sc.nextInt();
			int cnt = 0;
			for(int i=0;i<N;++i) {
				long x = sc.nextInt();
				long y = sc.nextInt();
				double sum = Math.sqrt(x*x+y*y);
				if(sum<=D) {
					cnt++;
				}				
			}
			
			System.out.println(cnt);
	}	
}

Measured memory_bytes: 59704
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    A, B, C, D, E, F = ILI()
    return A, B, C, D, E, F


def solve(A, B, C, D, E, F):
    s_wat = set()
    for a in range(F // (100 * A) + 1):
        now_wat = a * 100 * A
        while now_wat <= F:
            if now_wat != 0:
                s_wat.add(now_wat)
            now_wat += 100 * B
    par = -1
    ans_sug_wat = 0
    ans_sug = 0
    for wat in sorted(list(s_wat)):
        sug_limit = min(((wat // 100) * E), F - wat)
        for c in range(sug_limit // C + 1):
            now_sug = c * C
            now_sug += ((sug_limit - now_sug) // D) * D
            now_par = 100 * (now_sug / (now_sug + wat))
            if now_par > par:
                ans_sug_wat = now_sug + wat
                ans_sug = now_sug
                par = now_par
    ans = "{} {}".format(ans_sug_wat, ans_sug)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include "iostream"
#include "algorithm"
#include "string"
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int a[26][26] = {0};

  for (int i = 0; i < s.size(); i++) a[s[i] - 'a'][t[i] - 'a'] = 1;


  int x[26] = {0};
  int y[26] = {0};

  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) {
      x[i] += a[i][j];
      y[i] += a[j][i];
    }
  }

  bool ans = true;

  for (int i = 0; i < 26; i++) {
    if (x[i] > 1 || y[i] > 1) ans = false;
  }

  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 776
import java.util.Scanner;

public class Main {



	/**第二引数 の中にある 第一引数 の数を出力するプログラム
	 *
	 * @param args
	 */
	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args){

		String search = scan.next();
//		String search = args[0];
		int count = 0;

		for(String now_script = scan.next(); !(now_script.equals("END_OF_TEXT"));now_script = scan.next()	){
			now_script = now_script.toLowerCase();		//文章を小文字に変換する。equalsは文字の大小も判定に含むため
			if(search.equals(now_script)){
				count++;
			}
		}
		System.out.println(count);
	}


}



Measured memory_bytes: 26144
#include <iostream>
using namespace std;
int main(){

int N,M;

int a[55],b[55];

cin>>N>>M;

for (int i = 0; i < M; i++) {
  cin>>a[i]>>b[i];
  a[i]--;
  b[i]--;
}

int ans[55];
for (int i = 0; i < 55; i++) {
  ans[i]=0;
}
//二重for
for (int i = 0; i < N; i++) {
  for (int j = 0; j < M; j++) {
    if(a[j]==i||b[j]==i){
      ans[i]++;

    }else{}
  }
  cout<<ans[i]<<endl;

}



return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  int l[2*n];
  for(int i=0;i<2*n;i++){
    cin>>l[i];
  }
  sort(l,l+2*n);
  for(int i=0;i<2*n;i+=2){
    ans+=l[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)
#define maxx 1000001
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main() {
    FASTIO
    int n;
    string s,t,ss;
    cin>>n>>s;
    if(n%2) cout<<"No"<<endl;
    else{
        ss=s.substr(0,n/2);
        t=s.substr(n/2,n/2);
        if(ss==t) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int x, a;
    cin >> x >> a;
    cout << (x < a ? 0 : 10) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
using namespace std;
 
int main() {
   long int a,b=0,c=0,e=1000000;
  cin>>a;
  vector<int>d(a);
for(int i=0;i<a;i++){
  cin>>d.at(i);
  c+=d.at(i);
}
for(c=0;c<100;c++){
  for(int i=0;i<a;i++){
    b+=(d.at(i)-c)*(d.at(i)-c);
  }
  e=min(e,b);
  b=0;
}
  cout<<e;  
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int k = stdIn.nextInt();
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		int g = b/k*k;
		if(a<=g) {
			System.out.println("OK");
		}else {
			System.out.println("NG");
		}
		
		
	}

}


Measured memory_bytes: 35480
import java.util.*;
 
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double ans = 0;
		
		for (int i=0; i<N; i++) {
			ans += (double)1/sc.nextInt();
		}
		System.out.println(1/ans);
	}
}

Measured memory_bytes: 21844
def calc(n, x):
    ans = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            k = x - i - j
            if j < k <= n:
                ans += 1
    return ans


while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    print(calc(n, x))



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

using namespace std;

const int maxn=1e5+5;

typedef long long ll;

char s[maxn];

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++){
		if(i&1){
			if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
				printf("No");return 0;
			}
		}
		else{
			if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
				printf("No");return 0;
			}
		}
	}
	printf("Yes");
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
int a[123456];
int main()
{
int n,ans=0,p=66;
bool f=false;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
p++;
if(a[i]==i){
ans++;
if(f)
ans--;
else{
f=true;
p=0;
}
}
if(p==1)
f=false;
}
cout<<ans;
system ("pause");
return 0;
}

Measured memory_bytes: 888
N, K = gets.chomp.split(" ").map(&:to_i);

def coins(k, i)
  ((Math.log10(k) - Math.log10(i)) / Math.log10(2)).ceil
end

coincnt = Array.new(coins(K, 1) + 1, 0)
dicemax, nocoin = N < K ? [N, 0]: [K - 1, N - K + 1]

(1..dicemax).each{|i|
  coincnt[coins(K, i)] += 1
}
ans = 0.0
coincnt.each_with_index{|i, idx|
  ans += i * 0.5 ** idx
}
ans = (ans + nocoin) / N.to_f

printf("#{ans}")


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
#define MAX 1000100
using namespace std;
bool sosu[MAX]={1,1,0};
int main(){
  for(int i=4;i<MAX;i+=2)sosu[i]=1;
  for(int i=3;i<MAX;i+=2){
    if(sosu[i])continue;
    for(int j=i*3;j<MAX;j+=i*2)sosu[j]=1;
  }
  int a,b,c;
  while(cin>>a>>b>>c,a||b||c){
    int co=0;
    if(!sosu[a])co++;
    while(co!=c){
      a+=b;
      if(!sosu[a])co++;
      if(co==c)break;
    }
    cout<<a<<endl;
  }
}

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

using namespace std;

typedef long long ll;
const ll INF = 1001001001100100100;

int main(){
    int A, B, C;
    vector<int> length(3);
    vector<int> half(3);
    for(int i = 0; i < 3; ++i){
        cin >> length[i];
        half[i] = length[i] / 2;
    }
    
    ll ans = INF;
    for(int i = 0; i < 3; ++i){
        if(2 * half[i] == length[i]){
            cout << 0 << endl;
            return 0;
        }
        
        ll temp = 1;
        for(int j = 0; j < 3; ++j){
            if(i == j)      continue;
            
            temp *= length[j];
        }
        
        ans = min(ans, temp);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int n; vector<int> A; int q; vector<int> M;
    cin >> n;
    REP(i,n){
        int a; cin >> a; A.push_back(a);
    }
    cin >> q;
    REP(i,q){
        int m; cin >> m; M.push_back(m);
    }
    //sort(ALL(M));
    vector<bool> flag(q,false);

    for(int bit = 0; bit < (1 << n); bit++){
        int ans = 0;
        for(int i = 0; i < n; i++){
            if(bit & (1<<i)){
                ans += A[i];
            }
        }
        REP(i,q){
            if(M[i] == ans){flag[i] = true;}
        }
    }

    REP(i,q){
        cout <<(flag[i] ? "yes":"no") << endl;
    }

}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
using namespace std;
int main(){
  int x,t;
  cin >> x >> t;
  if(x < t) cout << 0 << '\n';
  else cout << x - t << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
long long f[200][200];
char str[50];
int n;
int main()
{
    int i,cnt1,cnt2,j,k;
    long long t,ans=0;
    double x;
    cin>>n;
    for(i=1;i<=n;i++)
    {
      cin>>str;
      int m=strlen(str),p=0;
      long long x=0ll;
      for(j=0;j<m;j++)
      {
       if(str[j]=='.') p=m-j-1;
       else x=x*10+str[j]-'0';
        }
        for(j=p+1;j<=9;j++)
   x*=10;
        cnt1=0;
        t=x;
        //cout<<t<<" ";
        while(1)
        {
            if(t%2!=0) break;
            cnt1++;
            t/=2;
        }
        cnt1=min(cnt1,18);
        cnt2=0;
        while(1)
        {
            if(t%5!=0) break;
            cnt2++;
            t/=5;
        }
        cnt2=min(cnt2,18);
        //cout<<cnt1<<" "<<cnt2<<endl; 
        for(j=0;j<=18;j++)
         for(k=0;k<=18;k++)
          if(min(cnt1+j,cnt2+k)>=18)
           ans+=f[j][k];
         //cout<<ans<<endl;
        f[cnt1][cnt2]++;
    }
    cout<<ans;
    system("pause");
}


Measured memory_bytes: 3660
h, w = list(map(int, input().split()))
s = [list(input()) for i in range(h)]
dir = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for y in range(h):
    for x in range(w):
        can_put = True
        if s[y][x] == "#":
            for dx, dy in dir:
                cx = x + dx
                cy = y + dy
                if cx >= 0 and cx < w and cy >= 0 and cy < h:
                    if s[cy][cx] == "#":
                        can_put = True
                        break
            else:
                can_put = False
        if can_put == False:
            break
    else:
        continue
    break
if can_put == True:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
count = dict(Counter(a))
for i in count:
    j = count[i]
    if i > j:
        ans += j
    elif i==j:
        continue
    else:
        ans += j-i
print(ans)

Measured memory_bytes: 74536
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    string s;cin>>s;
    reverse(all(s));
    s+='0';
    vector<vector<ll> >dp(s.size(),vector<ll>(2,inf));
    dp[0][0]=0;
    rep(i,s.size()-1){
        ll c=s[i]-'0';
        dp[i+1][0]=min(dp[i][0]+c,dp[i+1][0]);
        dp[i+1][1]=min(dp[i][0]+10-c,dp[i+1][1]);
        dp[i+1][0]=min(dp[i][1]+c+1,dp[i+1][0]);
        dp[i+1][1]=min(dp[i][1]+10-c-1,dp[i+1][1]);
    }
    ll ans=min(dp[s.size()-1][0],dp[s.size()-1][1]+1);
    cout<<ans<<endl;
}

Measured memory_bytes: 55940
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  int a; cin >> a;
  cout << a + a*a + a*a*a << endl;
}


Measured memory_bytes: 3616
# F - Many Many Paths
def get_factorials(lim: int, MOD: int) -> list:
    """Compute a table of factorials (1-indexed)."""
    factorials = [1] * (lim + 1)
    x = 1
    for i in range(1, lim + 1):
        x = (x * i) % MOD
        factorials[i] = x
    return factorials


def mod_comb_with_pow(n: int, k: int, MOD: int) -> int:
    """Compute nCr % MOD using pow(), not an inverse factorial table."""
    return fact[n] * pow(fact[k], MOD - 2, MOD) * pow(fact[n - k], MOD - 2, MOD) % MOD


def main():
    global fact
    MOD = 10 ** 9 + 7
    R1, C1, R2, C2 = map(int, input().split())
    fact = get_factorials(2 * 10 ** 6 + 10, MOD)
    f = lambda x, y: mod_comb_with_pow(x, y, MOD)
    ans = (f(C1 + R1, R1) - f(C1 + R2 + 1, R2 + 1) - f(C2 + R1 + 1, R1) + f(C2 + R2 + 2, R2 + 1)) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 82164
S = input()
i = 0
j = len(S) - 1
cnt = 0

while i < j:
    if S[i] == S[j]:
        i += 1
        j -= 1
    elif S[i] == 'x':
        cnt += 1
        i += 1
    elif S[j] == 'x':
        cnt += 1
        j -= 1
    else:
        print(-1)
        exit()
print(cnt)


Measured memory_bytes: 68076
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();

        final String[] words = new String[n];
        for (int i = 0; i < n; i++) {
            words[i] = scanner.next();
        }

        for (int i = 1; i < n; i++) {
            if (words[i].charAt(0) != words[i - 1].charAt(words[i - 1].length() - 1)) {
                System.out.println("No");
                return;
            }
        }

        final HashSet<String> wordsSet = new HashSet<>(Arrays.asList(words));
        if (words.length != wordsSet.size()) {
            System.out.println("No");
            return;
        }

        System.out.println("Yes");
    }

}


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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())
#define mp            make_pair
#define pb            push_back


typedef long long ll;

using namespace std;

int main(){
  vector<int> abc(3);
  cin >> abc[0] >> abc[1] >> abc[2];
  sort(all(abc));

  cout << abc[2]*10+abc[1]+abc[0] << endl;

  return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int h,w,n,d[3]={1,0,-1},ans[10];
map<pair<int,int>,int> m;

signed main() {
    cin >> h >> w >> n;
    rep(k,n) {
        int a,b;
        cin >> a >> b;
        rep(i,3) rep(j,3) if (0 < a+d[i] && a+d[i] <= h && 0 < b+d[j] && b+d[j] <= w) m[mp(a+d[i], b+d[j])]++;
    }
    int hoge = 0;
    ans[0] = (h-2)*(w-2);
    for(auto i : m) if (1 < i.fi.fi && i.fi.fi < h && 1 < i.fi.se && i.fi.se < w) ans[i.se]++, hoge++;
    ans[0] -= hoge;
    rep(i,10) cout << ans[i] << endl;
}


Measured memory_bytes: 56448
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
#define MAX 70

struct rect{
  int lowx, highx, lowy, highy;
  inline void read(){ scanf("%d%d%d%d", &lowx, &highy, &highx, &lowy); }
} rects[MAX];

int n, xs[MAX << 2], xlen, ys[MAX << 2], ylen, mark;
bool xexists[1000100], yexists[1000100];
int xidxs[1000100], yidxs[1000100];
int board[150][150];
const int dirs[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

inline void bfs(int r, int c, int minr, int maxr, int minc, int maxc, int color){
  int ori_color = board[r][c];
  
  queue<int> rs, cs;
  board[r][c] = color;
  rs.push(r); cs.push(c);
  while(!rs.empty()){
    int fr = rs.front(); rs.pop();
    int fc = cs.front(); cs.pop();
    
    for(int i = 0; i < 4; i++){
      int nxtr = fr + dirs[i][0];
      int nxtc = fc + dirs[i][1];
      if(minr <= nxtr && nxtr < maxr && minc <= nxtc && nxtc < maxc && board[nxtr][nxtc] == ori_color){
        board[nxtr][nxtc] = color;
        rs.push(nxtr); cs.push(nxtc);
      }
    }
  }
}

inline void add(int idx){
  int minr = xidxs[rects[idx].lowx], maxr = xidxs[rects[idx].highx];
  int minc = yidxs[rects[idx].lowy], maxc = yidxs[rects[idx].highy];
  int ori_mark = mark;
  
  for(int r = minr; r < maxr; r++)
  for(int c = minc; c < maxc; c++)
    if(board[r][c] < ori_mark) bfs(r, c, minr, maxr, minc, maxc, mark++);
}

inline int cnt(){  
  int res = 0;
  
  
  for(int r = 0; r <= xlen; r++)
  for(int c = 0; c <= ylen; c++)
    if(board[r][c] != -1){ res++; bfs(r, c, 0, xlen + 1, 0, ylen + 1,-1);}
  return res;
}

int main(){
  while(scanf("%d", &n) == 1 && n){
    xlen = ylen = 0;
    mark = 1;
    memset(xexists, false, sizeof(xexists));
    memset(yexists, false, sizeof(yexists));
    memset(board, 0, sizeof(board));
    
    for(int i = 1; i <= n; i++) rects[i].read();
    for(int i = 1; i <= n; i++){
      if(!xexists[rects[i].lowx]) xs[++xlen] = rects[i].lowx, xexists[rects[i].lowx];
      if(!xexists[rects[i].highx]) xs[++xlen] = rects[i].highx, xexists[rects[i].highx];
      if(!yexists[rects[i].lowy]) ys[++ylen] = rects[i].lowy, yexists[rects[i].lowy];
      if(!yexists[rects[i].highy]) ys[++ylen] = rects[i].highy, yexists[rects[i].highy];
    }
    
    sort(xs + 1, xs + xlen + 1);
    sort(ys + 1, ys + ylen + 1);
    
    for(int i = 1; i <= xlen; i++) xidxs[xs[i]] = i;
    for(int i = 1; i <= ylen; i++) yidxs[ys[i]] = i;
    
    for(int i = 1; i <= n; i++) add(i);
    
    printf("%d\n", cnt());
  }
  return 0;
}

Measured memory_bytes: 10916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> a (n);
    for(int i=0; i<n;i++){
        cin >> a.at(i);
    }
    int ans = 0;
    sort(a.begin(),a.end());
    if(n == 1){
        ans = 1;
    }
    else{
        vector<pair<int,int>> b;
        int now = a.at(0);
        int count = 1;
        b.push_back(make_pair(-5,0));
        for(int i=1; i<n; i++){
            if(now == a.at(i)){
                count++;
            }
            else{
                b.push_back(make_pair(now,count));
                now = a.at(i);
                count = 1;
            }
        }
        if(n > 1 || a.at(a.size()-1) == a.at(a.size()-2)){
            b.push_back(make_pair(now,count));
        }
        sort(b.begin(),b.end());
        if(n == 1){
            ans = 1;
        }
        else{
            for(int i=1; i<b.size() - 1; i++){
                count = 0;
                if(b.at(i).first - b.at(i-1).first == 1){
                    count += b.at(i-1).second;
                }
                count += b.at(i).second;
                if(b.at(i+1).first - b.at(i).first == 1){
                    count += b.at(i+1).second;
                }
                if(ans < count){
                    ans = count;
                }
            }
        }
    }
    if(a.at(0) == a.at(a.size()-1)){
        ans = n;
    }
    cout << ans << endl;
}

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

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

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

int main() {
  int d,n;cin>>d>>n;
  int ans=1;
  rep(i,d)ans*=100;
  if(n==100)n++;
  cout<<ans*n<<endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
  string S;
  cin >> S;
  
  int n = S.length();
  int ans = 10000;
  
  for (int i=0; i<=n-3; i++) {
    int a = S[i]-'0';
    int b = S[i+1]-'0';
    int c = S[i+2]-'0';
    
    int z = 100*a + 10*b + c;
    ans = min(ans,abs(753-z));
  }
  cout << ans << endl;
}

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

int main()
{
    priority_queue<int> q;
    char op[20];
    int k;
    while (scanf("%s", op) != EOF&&op[2] != 'd') {
        if (op[0] == 'i') {
            scanf("%d", &k);
            q.push(k);
        }
        else {
            int k = q.top();
            q.pop();
            printf("%d\n", k);
        }
    }
    return 0;
}


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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, rt = 1, a[nsz + 5];
int pr[nsz + 5], dfn[nsz + 5], siz[nsz + 5];
vector<int> g[nsz + 5], p[nsz + 5];

struct fenwick_tree {
	int tr[nsz + 5];
	
	void inline upd(int u, int w) {
		for (; u <= n; tr[u] += w, u += u & -u);
	}
	
	int inline qry(int u) {
		int res = 0;
		for (; u > 0; res += tr[u], u -= u & -u);
		return res;
	}
	
	int inline qry(int l, int r) { return qry(r) - qry(l - 1); }
};
fenwick_tree tr;

void dfs(int u = rt) {
	static int t = 0;
	dfn[u] = ++t;
	siz[u] = 1;
	loop (i, g[u].size()) {
		int v = g[u][i];
		if (v == pr[u])  continue;
		pr[v] = u;
		dfs(v);
		siz[u] += siz[v];
	}
}

void bfs() {
	static int q[nsz + 5];
	int ql = 0, qr = 0;
	q[qr++] = rt;
	for (; ql != qr;) {
		int u = q[ql++];
		p[a[u]].push_back(u);
		loop (i, g[u].size()) {
			int v = g[u][i];
			if (v == pr[u])  continue;
			q[qr++] = v;
		}
	}
}

int inline qry_subtree(int u) { return tr.qry(dfn[u], dfn[u] + siz[u] - 1); }

num inline solve(int c) {
	num res = (num) n * (n + 1) / 2;
	reverse(all(p[c]));
	loop (i, p[c].size()) {
		int u = p[c][i], s = siz[u];
		loop (i, g[u].size()) {
			int v = g[u][i];
			if (v == pr[u])  continue;
			int k = qry_subtree(v), kk = siz[v] - k;
			res -= (num) kk * (kk + 1) / 2;
			s -= k;
		}
		tr.upd(dfn[u], s);
	}
	int k = siz[rt] - qry_subtree(rt);
	res -= (num) k * (k + 1) / 2;
	loop (i, p[c].size()) {
		int u = p[c][i], k = tr.qry(dfn[u], dfn[u]);
		tr.upd(dfn[u], -k);
	}
	return res;
}

int main() {
	scanf("%d", &n);
	cont (i, n) {
		scanf("%d", &a[i]);
	}
	cont (i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(), bfs();
	cont (c, n) {
		printf("%lld\n", solve(c));
	}
}

Measured memory_bytes: 43512
import scala.io.StdIn.readLine

object Main extends App {
  var n:Array[Int] = readLine.split(" ").map(_.toInt)

  while( n(0) != -1 || n(1) != -1 || n(2) != -1 ) {
    val Array(m,f,r) = n
    val score = m+f
    var grade = ""

    if( m == -1 || f == -1)
      grade = "F"
    else if(score >= 80)
      grade = "A"
    else if(score < 80 && score >= 65)
      grade = "B"
    else if(score < 65 && score >= 50)
      grade = "C"
    else if(score < 50 && score >= 30)
      if(r>=50)
          grade = "C"
      else
          grade = "D"
    else
        grade = "F"

    println(grade)


    n = readLine.split(" ").map(_.toInt)
  }
}

Measured memory_bytes: 44088
/// إِنَّ مَعَ الْعُسْرِ يُسْرًا
/// لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ

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

using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld  double

#define HabdModeActive ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define S second
#define F first
#define PI acos(-1)
#define MAX 5000005
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
const int N = 2e5 + 5;


int main() {
    HabdModeActive
    string s;
    cin>>s;
    int cnt1 =0 ,cnt2=0;
    for(int i=0 ;i<s.size() ; i++)
    {
        if(i%2==0 && s[i]=='0')
            cnt1++;
        else if(i%2==1 && s[i]=='1')
            cnt1++;

        if(i%2==0 && s[i]=='1')
            cnt2++;
        else if(i%2==1 && s[i]=='0')
            cnt2++;

    }
    cout<<min(cnt1,cnt2);

    return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}


int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    
    return ret;
}
int ma(int x){
    if(x%10==0){
        return x;
    }else{
        int tmp=10-(x%10);
        return x+tmp;
    }
}
int main(){
    int a,b,c,d,e;
    

    cin >>a>>b>>c>>d>>e;
    
    

    int a0=a+ma(b)+ma(c)+ma(d)+ma(e);
    int b0=ma(a)+b+ma(c)+ma(d)+ma(e);
    int c0=ma(a)+ma(b)+c+ma(d)+ma(e);
    int d0=ma(a)+ma(b)+ma(c)+d+ma(e);
    int e0=ma(a)+ma(b)+ma(c)+ma(d)+e;

    int ans=min(a0,min(b0,min(c0,min(d0,e0))));


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

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

using namespace std;
typedef unsigned long long ull;

ull PickLargestMinimumPiece(const ull _total_size, const ull _piece1_s, const ull _piece1_l, const ull _piece3_s, const ull _piece3_l){
	ull tmp = min(_piece1_s, _piece3_s);
	
	ull piece2 = _total_size - _piece1_s - _piece3_l;
	tmp = max(tmp, min(_piece1_s, piece2));

	piece2 = _total_size - _piece1_l - _piece3_s;
	tmp = max(tmp, min(_piece3_s, piece2));

	piece2 = _total_size - _piece1_l - _piece3_l;
	tmp = max(tmp, piece2);

	return tmp;
}

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

	int N;	//切れ込みの個数
	cin >> N;

	int *A = new int[N];	//各ピースの大きさを格納する配列
	ull total_size = 0;	//バームクーヘンの大きさ
	int i1_ini = 0;
	int A_max = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		total_size += A[i];
		if (A[i] > A_max){
			A_max = A[i];
			i1_ini = i;
		}
	}
	ull one_third_size = total_size / 3;
	ull answer = 0;
	if (A_max > one_third_size){
		ull half_size = (total_size - A_max) / 2;
		ull tmp = 0;
		ull piece2 = 0;
		for (int i3 = i1_ini + 1; i3 < i1_ini + N - 1; i3++){
			piece2 = tmp;
			tmp += A[i3%N];
			if (tmp > half_size) break;
		}
		ull piece3 = total_size - A_max - tmp;
		answer = max(piece2, piece3);
		cout << answer << endl;
		delete[] A;
		return 0;
	}

	int i2 = i1_ini;
	ull piece1_s = 0;
	ull piece1_l = 0;
	for (; i2 < i1_ini + N - 2;){
		piece1_s = piece1_l;
		piece1_l += A[i2%N];
		i2++;
		if (piece1_l > one_third_size) break;
	}
	const int i1_fin = i2;

	/*int i3 = i1_ini + N;
	ull piece3_s = 0;
	ull piece3_l = 0;
	for (; i3 > i2 + 1;){
		piece3_s = piece3_l;
		i3--;
		piece3_l += A[i3%N];
		if (piece3_l > one_third_size) break;
	}
	i3++;*/
	int i3 = i2;
	ull piece3_s = total_size - piece1_l;
	ull piece3_l = 0;
	for (; i3 < i1_ini + N - 1;){
		piece3_l = piece3_s;
		piece3_s -= A[i3%N];
		i3++;
		if (piece3_s <= one_third_size) break;
	}

	answer = PickLargestMinimumPiece(total_size, piece1_s, piece1_l, piece3_s, piece3_l);

	for (int i1 = i1_ini + 1; i1 < i1_fin; i1++){
		int A_tmp = A[(i1 - 1) % N];
		piece1_l -= A_tmp;
		if (piece1_l > one_third_size) piece1_s -= A_tmp;
		else{
			for (; i2 < i1 + N - 2;){
				piece1_s = piece1_l;
				piece1_l += A[i2%N];
				i2++;
				if (piece1_l > one_third_size) break;
			}
		}

		piece3_s += A_tmp;
		if (piece3_s <= one_third_size) piece3_l += A_tmp;
		else{
			for (; i3 < i1 + N - 1;){
				piece3_l = piece3_s;
				piece3_s -= A[i3%N];
				i3++;
				if (piece3_s <= one_third_size) break;
			}
		}

		answer = max(answer, PickLargestMinimumPiece(total_size, piece1_s, piece1_l, piece3_s, piece3_l));
	}

	cout << answer << endl;

	delete[] A;

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  vi m(n);
  int minNum = 1000;
  rep(i, n){
    cin >> m[i];
    x -= m[i];
    minNum = minNum > m[i] ? m[i] : minNum;
  }
  cout << n + int(x / minNum) << endl;
}

Measured memory_bytes: 256
n = input()
g = [[] for i in xrange(n)]
for i in xrange(n-1):
    a, b = map(int, raw_input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
import sys
sys.setrecursionlimit(10**6)
used = {}
flag = [[0]*2 for i in xrange(n)]
def dfs(v, prev):
    if (v, prev) in used:
        return used[v, prev]
    su = 1
    for t in g[v]:
        if t != prev:
            su += dfs(t, v)
    used[v, prev] = su
    return su

for i in xrange(n):
    dfs(i, -1)
for v in xrange(n):
    cnt_o = 0
    for t in g[v]:
        if used[t, v] % 2 == 1:
            cnt_o += 1
    if cnt_o > 1:
        print "First"
        break
else:
    print "Second"


Measured memory_bytes: 74144
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main()
{
  string S, T;
  cin >> S >> T;
  int i, j, equal, s_len, t_len, max_eq;
    
  s_len = S.size();
  t_len = T.size();
  
  max_eq = 0;
  for (i = 0; i <= (s_len- t_len); i++) {
    equal = 0;
    for (j = 0; j < t_len; j++) {
      if (S[i+j] == T[j]) {
        equal++;
      }
    }
    if (equal > max_eq) {
      max_eq = equal;
    }
  }
  printf("%d", t_len - max_eq);
  return 0;
}

Measured memory_bytes: 3672
#include<iostream>
using namespace std;
long long gcd(long long y, long long z) { return z == 0 ? y : gcd(z, y%z); }
int main() {
	long long a, b, c, d,cnt=0,min,max,q;
	cin >> a >> b >> c >> d;

	q = a % c;
	if (q == 0) min = a;
	else min = a + c - q;
	q = b % c;
	if (q == 0) max = b;
	else max = b - q;
	cnt = max/c - min/c + 1;

	q = a % d;
	if (q == 0) min = a;
	else min = a + d - q;
	q = b % d;
	if (q == 0) max = b;
	else max = b - q;
	cnt += (max / d - min / d + 1);

	long long e = gcd(d,c);
	long long x = c * d / e;
	q = a % x;
	if (q == 0) min = a;
	else min = a + x - q;
	q = b % x;
	if (q == 0) max = b;
	else max = b - q;
	cnt -= (max / x - min / x + 1);

	cout << b-a-cnt+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,q,x,A[200005];
map <long long,long long> mp,mp1;
long long go(long long n) {
           if(n==1) return 1;
           return 2*go(n/2)+1;
}
int main() {
           cin>>n;
           cout<<go(n);
}


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


// A
bool isCheck(int y){
    return y % 3 == 0;
}

int main(){
    int n, i,j,k,l,y,m,d;

    cin >> n;
    for(i=0; i<n; i++){
        cin >> y >> m >> d;
        
        int res = 0;
        for(j=y; j<1000; j++){ // year
            for(k=(j == y ? m : 1); k<=10; k++){ // month
                int t = 19 + (k % 2 == 1 || j % 3 == 0 ? 1 : 0);
                res += t - (j == y && k == m ? d : 1) + 1;
            }
        }
        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 0