akhauriyash/Code-Regression huggingface dataset:
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<< i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

  ll n,q;
  std::cin>>n>>q;

  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];

  std::vector<ll> sum(n+1,0),oddsum(n+1,0);
  rep(i,1,n+1)sum[i]=sum[i-1]+a[i-1];
  oddsum[1]=a[0];oddsum[2]=a[1];
  rep(i,3,n+1)oddsum[i]=oddsum[i-2]+a[i-1];

  rep(_,0,q){
    ll x;
    std::cin>>x;

    ll left=n/2+2,right=0;
    while(left-right>1){
      ll mid=right+(left-right)/2;
      if(2*mid+1>n)left=mid;
      else {
        ll leftnum=a[n-2*mid-1],rightnum=a[n-mid-1];
        if(std::abs(rightnum-x)>=std::abs(leftnum-x))right=mid;
        else left=mid;
      }
    }

    std::cout<<sum[n]-sum[n-left]+oddsum[std::max(0ll,n-2*left)]<<"\n";
  }

  return 0;
}

Measured memory_bytes: 4096
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N = int(input())
    A = list(map(int, input().split()))
    count = 0
    for i in range(N):
        for j in range(i + 1, N):
            if A[i] == A[j]:
                continue
            for k in range(j + 1, N):
                if A[i] == A[k] or A[j] == A[k]:
                    continue
                if A[i] + A[j] > A[k] and A[j] + A[k] > A[i] and A[k] + A[i] > A[j]:
                    count += 1
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 68412
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,AC=0,WA=0,TE=0,RE=0;
    map<string,int>mp;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s=="AC")
            AC++;
        else if(s=="WA")
            WA++;
        else if(s=="TLE")
            TE++;
        else
            RE++;

    }
    cout<<"AC x "<<AC<<endl;
    cout<<"WA x "<<WA<<endl;
    cout<<"TLE x "<<TE<<endl;
    cout<<"RE x "<<RE<<endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>
#include <cstdint>

using llint = long long int;

void solve(void){
  int d, t, s;
  std::cin >> d >> t >> s;

  bool is_ok = s*t >= d;
  if(is_ok) std::cout << "Yes" << std::endl;
  else      std::cout << "No"  << std::endl;
  return;
}
int main(void){
  solve();
  return 0;
}





Measured memory_bytes: 3612
import java.util.Arrays;
import java.util.Scanner;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ans = 0;

    String s = sc.next();
    System.out.println(s.replace("2017", "2018"));

    sc.close();
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
string s[10010];
int main(){
	int n;
	cin>>n;
	int cnt=0;
	int a=0;
	int b=0;
	int c=0;
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=0;j<s[i].size()-1;j++){
			if(s[i][j]=='A'&&s[i][j+1]=='B')cnt++;
		}
		if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')c++;
		else if(s[i][0]=='B'&&s[i][s[i].size()-1]!='A')a++;
		else if(s[i][0]!='B'&&s[i][s[i].size()-1]=='A')b++;
	}
	if(a==0&&b==0){
		if(c>0)cnt+=c-1;
	}
	else{
		cnt+=c+min(a,b);
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 768
#include<iostream>

using namespace std;

int main(){
  int A,B,C,X;
  cin >>A >>B>>C>>X;
  int count =0;
  for(int a=0;a<=A;a++){
    for(int b=0;b<=B;b++){
      for(int c=0;c<=C;c++){
        if(a*500+b*100+c*50==X) count++;
      }
    }
  }
  cout << count;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<map>
#include<vector>
using namespace std;
const pair<int,int> no=make_pair(-1,2333333);
#define N 50050
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,T,x[N<<1],y[N<<1],col[N<<1];
void Output(){
	for(int i=1;i<=m;++i){
		putchar(col[i]?'^':'v');
	}
	putchar('\n');
}
namespace Task_1{
	bitset<N> to[N];
	int ok[N];
	void Find(int k){
		ok[x[k]]=ok[y[k]]=1;
		for(int i=k-1;i>=1;--i){
			if(!ok[x[i]]&&!ok[y[i]])continue;
			if(ok[x[i]])col[i]=1;
			ok[x[i]]=ok[y[i]]=1;
		}
	}
	void Solve(){
		for(int i=1;i<=n;++i){
			to[i][i]=1;
		}
		for(int i=1;i<=m;++i){
			to[x[i]]=to[y[i]]=to[x[i]]|to[y[i]];
			if((int)to[x[i]].count()==n){
				Find(i);
				Output();
				return;
			}
		}
		printf("-1\n");
	}
}
namespace Task_2{
	vector<pair<int,int> > vec[N]; 
	void Solve(){
		if(n==2){
			puts("-1");return;
		}
		for(int i=m;i>=1;--i){
			vec[x[i]].emplace_back(y[i],i);
			vec[y[i]].emplace_back(x[i],i);
		}
		int A=x[1],B=y[1]+1;
		if(B>n)A=x[1]-1,B=y[1];
		if(A<1)A=x[1]+1,B=y[1];
		for(int i=1;i<=m;++i){
			while(!vec[A].empty()&&vec[A].back().second<=i)vec[A].pop_back();
			while(!vec[B].empty()&&vec[B].back().second<=i)vec[B].pop_back();
			auto tA=vec[A].empty()?no:vec[A].back();
			auto tB=vec[B].empty()?no:vec[B].back();
			bool rev=(tA.second<tB.second&&tA.first==B)||(tA.second>=tB.second&&tB.first==A);
			if(x[i]==A||y[i]==A){
				col[i]=rev^(x[i]==A);
				if(rev)A=(x[i]==A)?y[i]:x[i];
			}
			else if(x[i]==B||y[i]==B){
				col[i]=rev^(x[i]==B);
				if(rev)B=(x[i]==B)?y[i]:x[i];	
			}
		}
		Output();
	}
}
int main(){
	n=read(),m=read(),T=read();
	for(int i=1;i<=m;++i){
		x[i]=read(),y[i]=read();
	}
	if(T==1){
		Task_1::Solve();
	}
	else{
		Task_2::Solve();
	}
	return 0;
}


Measured memory_bytes: 311900
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int a, b, n;
  cin >> a >> b >> n;
 
  int px, py;
  cin >> px >> py;
  int ans = 0;
  int nx, ny;
  for(int i = 0 ; i < n-1 ; i++){
    cin >> nx >> ny;
    int X = nx, Y = ny;
    if(nx < px && ny < py){
      int t = min( abs(nx - px), abs(ny - py));
      ans += t;
      px -= nx, py -= ny;
      ans += max(px, py) - t;
    }
    else if(nx > px && ny > py){
      int t = min( abs(nx - px), abs(ny - py));
      ans += t;
      nx -= px, ny -= py;
      ans += max(nx, ny) - t;
    }
    else{
      ans += abs(nx - px) + abs(ny - py);
    }
    px = X, py = Y;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1160
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        for (int i = 0; i < s.length(); i++) {
            int m = Integer.parseInt(s.substring(i, i+1));
            ans += m;
        }
        if (ans == 1) {
            ans = 10;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    N = int(inputs[0])
    fn = reduce(lambda acc, x: acc + int(x), str(N), 0)
    if N % fn == 0:
        return 'Yes'
    return 'No'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )
 
 
int main() {
   
  ll n;
  cin>>n;
  vector<pii>A;
  REP(i,0,n)
  {
      ll x,y;
      cin>>x>>y;
      A.pb({x+y,x-y});
  }
  sort(A.begin(),A.end());
  ll next=INT_MIN;ll ans=0;
  REP(i,0,n)
  {
      pii temp=A[i];
      ll curr=temp.second;
      
      if(curr>=next)
      {
          ans++;next=temp.first;
      }
  }
  cout<<ans;
	return 0;
}

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

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

    int aind = 0;
    int zind = 0;

    for(int i = 0; i < s.size(); i++){
        if(s[i]=='A'){
            aind = i;
            break;
        }
    }

    for(int i = s.size()-1; i >= 0; i--){
        if(s[i]=='Z'){
            zind = i;
            break;
        }
    }

    cout << zind - aind + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;




#define P pair<ll,ll>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define st std::string 
#define pb push_back 
#define ll long long 
#define pq(x) std::priority_queue<x> 
#define ultapq(x) priority_queue<x,vector<x>,greater<x>> cle
#define show_pq(x,n) for(ll i = 0; i < n; i++){cout<<x.top(); x.pop();} 
#define itrt(yo) for(auto x:yo){std::cout<<x<<" ";} 
#define vec(x) std::vector<x> 
#define inll(x)  ll x; cin>>x;
#define inint(x)  ll x; cin>>x;
#define nl '\n' 
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define ALL(x) x.begin(),x.end() 
#define BN(x) x.begin()
#define ED(x) x.end()
#define MAP_traverse(it,x)  for(auto it = BN(x); it!= ED(x); it++)
#define PI 3.14159265358979323846264338327950L
int main()
{
   double a,b,h,m;
   cin>>a>>b>>h>>m;

   double hr = 30*h;
   double sec = 6*m;

   hr+= sec/12;
    double deg = abs(hr-sec);
    double cdeg = cos((deg*PI)/180);
    double ans = sqrt(a*a + b*b - 2*a*b*cdeg);
    cout<<fixed<<setprecision(20)<<ans;
    
    
    
     
}

Measured memory_bytes: 4116
x, k, d = map(int, input().split())
x = abs(x)

div = x // d
sur = x % d

ans = 0
if k > div:
	residual = k - div
	if residual % 2 == 0:
		ans = sur
	else:
		ans = d - sur
else:
	ans = x - k * d
print(ans)

Measured memory_bytes: 9096
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        x: u128,
    }

    let d = x / 11;
    let r = x % 11;
    let mut ans = 0;
    if r==0 {
        ans = 2*d;
    } else if 1<=r && r<=6 {
        ans = 2*d + 1;
    } else {
        ans = 2*d + 2;
    }
    println!("{}", ans);
}


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

int main() {
  int N;
  cin >> N;
  vector<string> A(N);
  for(int i = 0; i < N; i++) cin >> A.at(i);
  
  set<string> Set;
  for(int i = 0; i < N; i++) Set.insert(A.at(i));
  if( Set.size() != N ){
    cout << "No" << endl;
    return 0;
  }
  
  for(int i = 0; i < N-1; i++){
    if( A.at(i).at(A.at(i).size()-1) != A.at(i+1).at(0)){
    cout << "No" << endl;
    return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;
int n;
int dp[1001];
int main(){
	while(1){
		cin >> n;
		if(n==0)break;
		vector<int> r(n),w(n);
		vector<pair<int,pair<int,int> > > p;
		for(int i=0;i<n;i++){
			cin >> r[i] >> w[i];
			p.push_back(make_pair(r[i],make_pair(w[i],i)));
		}
		sort(p.begin(),p.end());
		int sum=0;
		for(int i=0;i<n-1;i++){
			sum+=p[i].first;
		}
		if(sum>=p[n-1].first){
			sum+=p[n-1].first;
			int sumw=0;
			for(int i=0;i<n;i++){
				sumw+=p[i].second.first;
			}
			cout << sum+ sumw << endl;
		}
		else{
			int dif=p[n-1].first-sum;
			for(int i=0;i<1001;i++){
				dp[i]=0;
			}
			dp[0]=1;
			for(int i=0;i<n-1;i++){
				int q=p[i].second.first;
				for(int j=1000-q;j>=0;j--){
					if(dp[j]){
						dp[j+q]=1;
					}
				}
			}
			int copy=-1;
			for(int i=dif;i>=0;i--){
				if(dp[i]){
					copy=i;
					break;
				}
			}
			int wait=dif-copy;
			sum+=p[n-1].first;
			int sumw=0;
			for(int i=0;i<n;i++){
				sumw+=p[i].second.first;
			}
			cout << sumw+sum+wait << endl;
		}
	}
}


Measured memory_bytes: 3128
#include<stdio.h>
#define N 100
#define INF 10000000
#define WHITE 0
#define BLACK 1
typedef struct {
  int v[N];
  int c[N];
  int k,d,pi,color;
} Graph;
int n;
Graph g[N];
 
void dijkstra()
{
  int i,j,u,mincost;
  for(i=0; i<n; i++){
    g[i].d = INF;
    g[i].pi = -1;
    g[i].color = WHITE;
  }
  g[0].d = 0;
   
  while(1) {
    mincost = INF;
    for(i=0; i<n; i++) {
      if(g[i].color != BLACK && g[i].d < mincost) {
        mincost = g[i].d;
        u = i;
      }
    }
     
    if(mincost == INF) break;
     
    g[u].color = BLACK;
    for(i=0; i<g[u].k; i++) {
      j = g[u].v[i];
      if(g[j].color != BLACK && g[u].c[i] + g[u].d < g[j].d) {
        g[j].pi = u;
        g[j].d = g[u].c[i] + g[u].d;
      }
    }
  }
}
 
int main()
{
  int i,j,u,ver,cost;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d%d",&u,&g[i].k);
    for(j=0; j<g[i].k; j++) {
      scanf("%d%d",&ver,&cost);
      g[u].v[j]=ver; g[u].c[j] = cost;
    }
  }
   
  dijkstra();
  for(i=0; i<n; i++) printf("%d %d\n",i,g[i].d);
  return 0;
}

Measured memory_bytes: 680
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int C[26];
void Calc(){
	int N = rei();
	string S = res();
	for(int i=0;i<N;i++){
		int c = S[i] - 'a';
		C[c]++;
	}
	long ans = 1;
	for(int i=0;i<26;i++){
		ans *= C[i] + 1;
		ans %= mod;
	}
	ans += mod-1;
	ans %= mod;
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 512
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        a: i64, b: i64, c: i64, d: i64,
    }
    println!("{}", [a * c, a * d, b * c, b * d].iter().max().unwrap());
}


Measured memory_bytes: 2188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#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 all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const ll inf=1e17;
struct UnionFind{
    vector<ll> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
class KRK{//c++11
	public:
	struct edge{
		ll from,to,cost;
	};
	vector<edge>G;
	int n;
	KRK(int size){
		n=size;
	}
	void add_edge(int a,int b,int c){
		edge e={a,b,c};
		G.pb(e);
	}
	ll krk(){
		ll sum=0;
		sort(all(G),[](edge a,edge b){
			return a.cost<b.cost;
		});
		UnionFind uf(n);
		rep(i,G.size()){
			edge e=G[i];
			if(!uf.findSet(e.from,e.to)){
				sum+=e.cost;
				uf.unionSet(e.from,e.to);
			}
		}
		return sum;
	}
};
int main(){
	int n,m;
	cin>>n>>m;
	KRK krk(n);
	vi mi(n,inf);
	while(m--){
		ll a,b,c;
		cin>>a>>b>>c;
		krk.add_edge(a,b,c);
		mi[a]=min(mi[a],c+1);
		mi[b]=min(mi[b],c+2);
	}
	rep(i,2*n)mi[(i+1)%n]=min(mi[(i+1)%n],mi[i%n]+2);
	rep(i,n)krk.add_edge(i,(i+1)%n,mi[i]);
	cout<<krk.krk()<<endl;
}









Measured memory_bytes: 14188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,s,ans=0,mod=998244353;cin>>n>>s;
  lvector A(n),f(3010,0);rep(i,n) cin>>A[i];
  for(ll a:A) {
    f[0]+=1;
    lvector ff;
    rep(i,s-a+1) ff.emplace_back(f[i]);
    rep(i,s-a+1) f[i+a]+=ff[i];
    rep(i,s+1) f[i]%=mod;
    ans=(ans+f[s])%mod;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
char t[100010];
int n, g, p;
int main() {
	scanf("%s",t);
	for(n=0;t[n]!='\0';n++) {
		if(t[n]=='g') g++;
		else p++;
	}
	printf("%d\n",n/2-p);
	return 0;
}


Measured memory_bytes: 256
// Aizu Vol-1 0184: Tsuruga Castle
// 2017.8.2

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

char *gets(char *);
char buf[100], *p;

int getInt(void)
{
	int n = 0;
	//	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

int cnt[15];

int main()
{
	int i, n, k;

	while (1) {
		gets(p = buf);
		if (!(n = getInt())) break;
		memset(cnt, 0, sizeof(cnt));
		for (i = 0; i < n; i++) {
			gets(p = buf);
			cnt[getInt() / 10]++;
		}
		for (i = k = 0; i < 6; i++) printf("%d\n", cnt[i]), k += cnt[i];
		printf("%d\n", n - k);
	}
	return 0;
}

Measured memory_bytes: 524
MOD=1000000007
N,M=map(int,input().split())
if N>M: N,M=M,N
if M-N>1:
  print(0)
else:
  ans=1
  for i in range(1,N+1):
    ans*=i
    ans%=MOD
  for i in range(1,M+1):
    ans*=i
    ans%=MOD
  if N==M:
    ans*=2
    ans%=MOD
  print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        System.out.println(C + " " + A + " " + B);
    }
}


Measured memory_bytes: 23764
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

a,v = readInts()
b,w = readInts()
t = readInt()

if v<=w:
	print("NO")
else:
	if abs(a-b)<=t*(v-w):
		print("YES")
	else:
		print("NO")

Measured memory_bytes: 9656
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define rg register
#define LL long long
using namespace std;
const int MAXN=500000;
LL N,M,C,ans;
struct node{
	LL a,b;
}s[MAXN];

inline bool cmp(node x,node y){
	return x.a<y.a;
}

signed main(){
	scanf("%lld%lld",&N,&M);
	
	for(rg int i=1;i<=N;i++)
		scanf("%lld%lld",&s[i].a,&s[i].b);
	
	sort(s+1,s+N+1,cmp);
	
	for(rg int i=1;i<=N;i++){
		if(M-s[i].b>0) ans+=s[i].b*s[i].a,M-=s[i].b;
		else{
			ans+=s[i].a*M;
			break;
		}
	}
	
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
  int N;
  long long lucas[100] = {2, 1};
  int i;
  
  scanf("%d", &N);
  for(i = 2; i <= N; i++) lucas[i] = lucas[i-1] + lucas[i-2];
  printf("%lld\n", lucas[N]);
  
  return 0;
}
  

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

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

bool dfs(i64 a, i64 b, i64 l, i64 r, i64 turn) {
  if(a == 0) return true;
  if(b == 0) return false;
  if(turn % 2 == 0) {
    if((a & (1 << r)) || (a & (1 << l))) {
      if(a & (1 << l) && dfs(a & ~(1 << l), b, l - 1, r, turn + 1)) {
        return true;
      }
      if(a & (1 << r)&& dfs(a & ~(1 << r), b, l, r + 1, turn + 1)) {
        return true;
      }
      return false;
    }
    return dfs(a, b, l, r, turn + 1);
  }
  else {

    if((b & (1 << r)) || (b & (1 << l))) {
      if(b & (1 << l) && !dfs(a, b & ~(1 << l), l - 1, r, turn + 1)) {
        return false;
      }
      if(b & (1 << r) && !dfs(a, b & ~(1 << r), l, r + 1, turn + 1)) {
        return false;
      }
      return true;
    }
    return dfs(a, b, l, r, turn + 1);
  }
  return false;
}

int main() {
  i64 N;
  cin >> N;
  for(int i = 0;i < N;i++) {
    set<i64> st;
    rep(i,0,6) {
      i64 a;
      cin >> a;
      st.insert(a);
    }
    i64 a = 0;
    i64 b = 0;
    for(int i = 1;i <= 13;i++){
      if(i == 7) continue;
      if(st.count(i)) a |= (1 << i);
      else b |= (1 << i);
    }
    if(dfs(a, b, 6, 8, 0)) {
      cout << "yes" << endl;
    }
    else {
      cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 3088
#include <iostream>

using namespace std;

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

	int a, b;

	if (n <= 1) a = 0;
	else a = n * (n - 1) / 2;
	
	if (m <= 1) b = 0;
	else b = m * (m - 1) / 2;
	
	cout << a + b << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

LL modpow(LL a, LL n) {
  LL pow = 1;
  while (n > 0) {
    if (n & 1) pow = pow * a % kMod;
    a = a * a % kMod;
    n >>= 1;
  }
  return pow;
}

LL modinv(LL a) { return modpow(a, kMod - 2); }

LL modsub(LL a, LL b) { return (a + kMod - b) % kMod; }

LL nCr(LL n, LL r) {
  LL x = 1, y = 1;
  for (int i = 1; i <= r; ++i) {
    x = (x * (n-i+1)) % kMod;
    y = (y * i) % kMod;
  }
  return (x * modinv(y)) % kMod;
}

int main() {
  LL n, a, b; std::cin >> n >> a >> b;

  LL ans = modpow(2, n)-1;
  LL nCa = nCr(n, a);
  LL nCb = nCr(n, b);

  ans = modsub(ans, nCa);
  ans = modsub(ans, nCb);
  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int n = vs[0];
			int k = vs[1];
			int[] p = Console.ReadLine().Split().Select(int.Parse).OrderBy(p => p).ToArray();

			long ans = 0;
			for (int i = 0; i < k; i++) {
				ans += p[i];
			}
			Console.WriteLine(ans);

		}
	}
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}


void solve()
{
  // ll n, k; cin >> n >> k;
  ll h1, m1, h2, m2, x; cin >> h1 >> m1 >> h2 >> m2 >> x;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  // vector<ll> a(n); rep(i, n) cin >> a[i];
  ll ans = 0;
  // bool ok = false;
  ans = (h2 - h1) * 60 + m2 - m1 - x;
  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 3632
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

bool solve(){
	int n;
	scanf("%d", &n);
	if(n==0) return 0;
	
	vector<int> sh(n), sm(n), ss(n);
	vector<int> rh(n), rm(n), rs(n);
	vector<vector<vector<int> > > imos(30, vector<vector<int> >(65, vector<int>(65, 0)));
	REP(i, n){
		scanf("%d:%d:%d %d:%d:%d", &sh[i], &sm[i], &ss[i], &rh[i], &rm[i], &rs[i]);
		imos[sh[i]][sm[i]][ss[i]]+=1;
		imos[rh[i]][rm[i]][rs[i]]-=1;
	}
	
	REP(i, 24){
		REP(j, 60){
			REP(k, 60){
				if(i+j+k==0) continue;
				
				if(k>0) imos[i][j][k]+=imos[i][j][k-1];
				else if(j>0) imos[i][j][k]+=imos[i][j-1][59];
				else imos[i][j][k]+=imos[i-1][59][59];
			}
		}
	}
	
	int maxi=-1;
	REP(i, 24){
		REP(j, 60){
			REP(k, 60){
				//cout << imos[i][j][k] << endl;
				maxi=max(maxi, imos[i][j][k]);
			}
		}
	}
	
	printf("%d\n", maxi);
	return 1;
}

int main(){
	while(solve()){}
}

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

using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y 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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'



signed main() {
    fio();
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep (i, h) cin >> s[i];

    int ans = 0;

    rep (i, 1 << h) {
        rep (j, 1 << w) {
            vector<string> t = s;
            rep (ii, h) {
                if (i & (1 << ii)) {
                    rep (jj, w) t[ii][jj] = 'r';
                }
            }
            rep (jj, w) {
                if (j & (1 << jj)) {
                    rep (ii, h) t[ii][jj] = 'r';
                }
            }
            int cnt = 0;
            rep (ii, h) rep (jj, w) {
                if (t[ii][jj] == '#') cnt++;
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

const int MAX = 300;
int n;
long long aij[MAX][MAX], bij[MAX][MAX];

void get_input() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> aij[i][j];
        }
    }
}

void init_bij() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            bij[i][j] = aij[i][j];
        }
    }
}

void warshall_floyd() {
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                bij[i][j] = min(bij[i][j], bij[i][k] + bij[k][j]);
            }
        }
    }
}

bool can_remove_edge_i_j(int i, int j) {
    for (int k = 0; k < n; k++) {
        if (k == i || k == j) continue;
        if (bij[i][j] == bij[i][k] + bij[k][j]) return true;
    }
    return false;
}

long long sum_of_necessary_edges() {
    long long res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (bij[i][j] < aij[i][j]) return -1;
            if (! can_remove_edge_i_j(i, j)) {
                res += aij[i][j];
            }
        }
    }
    assert (res % 2 == 0);
    return res / 2;
}

int main(void) {
    get_input();
    init_bij();
    warshall_floyd();
    cout << sum_of_necessary_edges() << endl;
    return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define pb push_back
#define tp make_tuple
#define srt(a) sort(a.begin(),a.end())
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr(a) printf("%lld\n",a)
#define r0 return 0
#define pi acos(-1)

using namespace std;

vector<ll>v[2000005];
map<ll,ll>mp;
ll cnt=0;

void dfs(ll x)
{
    cnt++;
    mp[x]=1;

    for(ll it : v[x])
    {
        if(!mp[it])dfs(it);
    }
}

int main()
{
    ll n,m,i,j,k,x,y,z,t;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin>>n>>m;

    for(i=0;i<m;i++)
    {
        sc2(x,y);

        v[x].pb(y);
        v[y].pb(x);
    }

    ll ans=0;

    for(i=1;i<=n;i++)
    {
        if(!mp[i]){

            cnt=0;
            dfs(i);

            ans=max(ans,cnt);

        }
    }
    cout<<ans<<endl;


}


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

ll inf=1ll<<60,mod=1000000007;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll i,j,k,n,ans=1,t;
	string a,b;
	cin>>n>>a>>b;
	for (i=0;i<a.size();i++){
		if (i==0){
			if (a[i]==b[i]){
				ans*=3;
			}
			else {
				i++;
				ans*=6;
			}
		}
		else {
			if (a[i]==b[i]){
				if (a[i-1]==b[i-1]){
					ans=(ans*2)%mod;
				}
			}
			else {
				if (a[i-1]!=b[i-1]) {
					ans=(ans*3)%mod;
				}
				else {
					ans=(ans*2)%mod;
				}
				i++;
			}
		} 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main ()
{
    int A,P,total_piece,max_pie;
    scanf ("%d %d",&A,&P);
    total_piece=(3*A)+P;
    max_pie=total_piece/2;
    printf ("%d\n",max_pie);
    return 0;
}


Measured memory_bytes: 3764
import math
 
A, B = list(map(int, input().split()))
 
a_min = math.ceil(A * 100 / 8)        #'ceil' means rounding up 定価を求める
a_max = math.ceil((A + 1) * 100 / 8)
b_min = math.ceil(B * 100 / 10) #税金からの計算でギリ定価になるような最小の数 を切り上げたもの
b_max = math.ceil((B + 1) * 100 / 10) #整数にするため切り上げる（切り下げでは税金が小さくなる）
 #税金A、A＋１に対する最小の値段を求めることでrangeでa_minから（a_max-1）までの数うを羅列したlist作成
 
set_a = {i for i in range(a_min, a_max)} #the set of numbers whose taxes become A
set_b = {i for i in range(b_min, b_max)}
i = set_a.intersection(set_b)  #the set of intersection of set_a and set_b
if len(i) > 0:   #if the set, i has numbers, print the minimum number 
    print(min(i))
else:
    print(-1)

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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7


int main() {
  ll n,x;
  cin>>n>>x;
  vll v(n);
  FOR(i,0,n){
    cin>>v[i];
  }
  ll ans=0;
  vll ve(n+1);
  ve[0]=0;
  FOR(i,1,n+1){
    ve[i]=ve[i-1]+v[i-1];
    if(ve[i]>x){
      ans=i;
      break;
    }
    else{
      ans=n+1;
    }
  }
  co(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define mp make_pair
#define pb push_pack
#define LL long long
#define inf 2e9
#define zeros x^(x-1)&x
using namespace std;

int x,s,nr;
int main()
{
    cin>>x;

    int i = 1;
    while (s<x)
    {
        s+=i;
        nr++;
        i++;
    }
    cout<<nr;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,k=0,ans=0;
  string S;
  cin>>N>>S;
  for(char c:S)
    if(c=='.')
      k++;
  ans=k;
  for(int i=0;i<N;i++){
    if(S[i]=='.')
      k--;
    else
      k++;
    ans=min(ans,k);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3672
import sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


def main():
    N = int(input())
    A = list(map(int, input().split()))
    S = sum(A)
    x = [0] * N
    x[0] = S - 2*(sum(A[1::2]))
    for i in range(1,N):
        x[i] = 2*A[i-1] - x[i-1]
    print(*x)

if __name__ == "__main__":
    main()


Measured memory_bytes: 14092
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
   int n,m;
   cin>>n>>m;
   int a[m];
   rep(i,m)cin>>a[i];
   int sum =0;
   rep(i,m)sum+=a[i];
   if(n-sum>=0)cout<<n-sum<<endl;
   else cout<<-1<<endl;
}


Measured memory_bytes: 3628
use std::io::*;
use std::sync::Mutex;

pub struct Scanner {
    source: Mutex<Bytes<BufReader<Stdin>>>,
}

impl Scanner {
    pub fn new() -> Scanner {
        Scanner {
            source: Mutex::new(Read::bytes(BufReader::new(stdin()))),
        }
    }
    pub fn source(&mut self) -> &Mutex<Bytes<BufReader<Stdin>>> {
        return &self.source;
    }
}

#[allow(unused_macros)]
macro_rules! rin {
    ( from $scanner:ident, $( $rep:tt )* ) => {
        let mut locked_stdin = $scanner.source().lock().unwrap();
        #[allow(unused_mut)]
        let mut buf = move || -> String {
            locked_stdin
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        rin_parse!{buf, $($rep)*}
        drop(buf);
    };
}

#[allow(unused_macros)]
macro_rules! rin_parse {
    ( $buf:expr ) => {};
    ( $buf:expr, ) => {};
    ( $buf:expr, $type:tt : $var:tt, $($r:tt)* ) => {
        rin_read!($buf, $type, $var, false);
        rin_parse!($buf, $($r)*);
    };
    ( $buf:expr, mut $type:tt : $var:tt, $($r:tt)* ) => {
        rin_read!($buf, $type, $var, true);
        rin_parse!($buf, $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! rin_read {
    ( $buf:expr, $type:tt, $var:ident, false ) => {
        let $var = read_value!($buf, $type);
    };
    ( $buf:expr, $type:tt, [$($var:ident),*], false ) => {
        $( let $var = read_value!($buf, $type); )*
    };

    ( $buf:expr, $type:tt, $var:ident, true ) => {
        let mut $var = read_value!($buf, $type);
    };
    ( $buf:expr, $type:tt, [$($r:tt)*], true ) => {
        $( let mut $var = read_value!($buf, $type); )*
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ( $next:expr, ( $($t:tt),* ) ) => {
        ( $(read_value!($next, $t)),* )
    };
    ( $next:expr, [ $t:tt ; [$d1:expr, $d2:expr] ] ) => {
        (0..$d1).map(|_| read_value!($next, [$t; $d2])).collect::<Vec<_>>()
    };
    ( $next:expr, [ $t:tt ; $len:expr ] ) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };   
    ( $next:expr, chars ) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ( $next:expr, usize1 ) => {
        read_value!($next, usize) - 1
    };
    ( $next:expr, $t:ty ) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// main function

fn main() {
    let mut sc : Scanner = Scanner::new();
    let t = 1;
    // rin!( from sc, usize : t, );
    for _ in 0..t { solve(&mut sc); }
}

fn solve(sc: &mut Scanner) {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    rin! {
        from sc,
        chars : [s, t],
    }

    let mut ans = 0;
    for i in 0..s.len() {
        if s[i] != t[i] { ans += 1; }
    }

    write!(out, "{}\n", ans).ok();
}

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

int main(){
  int n;
  cin >> n;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  sort(an.begin(),an.end());
  int ans = 0;
  for(int i=0; i<n; ++i){
    if(i == 0 && an[i] > 0) ans -= an[0];
    else if(i == n-1 && an[i] < 0) ans += an[n-1]; 
    else ans += abs(an[i]);
  }
  cout << ans << endl;
  for(int i=n-2; an[i]>=0 && i>0; --i){
    printf("%d %d\n", an[0], an[i]);
    an[0] -= an[i];
  }
  for(int i=1; an[i]<0 && i<n-1 ; ++i){
    printf("%d %d\n", an[n-1], an[i]);
    an[n-1] -= an[i];
  }
  printf("%d %d\n", an[n-1], an[0]);
}

Measured memory_bytes: 3776
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	string s;
	cin >> s;
	string t = "CODEFESTIVAL2016";
	int a = 0;
	for(int i = 0; i < 16; i++){
		if(s[i] != t[i]) a++;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	for(;;){
	int kane, sub, cont = 0;
	
	cin >> kane;
	if(kane == 0){
		break;
	}
	
	kane = 1000 - kane;
	sub = kane;
	for(;;){
		if(sub - 500>= 0){
			cont++;
			sub -= 500;
		}
		else{
			break;
		}
	}
//	cout <<"500:" << cont << endl;
	for(;;){
		if(sub - 100 >= 0){
			cont++;
			sub -= 100;
		}
		else{
			break;
		}
	}
//	cout <<"100:" <<cont<< endl;
	for(;;){
		if(sub - 50 >= 0){
			cont++;
			sub -= 50;
		}
		else{
			break;
		}
	}
	
//	cout << "50:" << cont << endl;
	for(;;){
		if(sub - 10 >= 0){
			cont++;
			sub -= 10;
		}
		else{
			break;
		}
	}

	for(;;){
		if(sub - 10 >= 0){
			cont++;
			sub -= 10;
		}
		else{
			break;
		}
	}

	for(;;){
		if(sub - 5 >= 0){
			cont++;
			sub -= 5;
		}
		else{
			break;
		}
	}
	
	for(;;){
		if(sub - 1 >= 0){
			cont++;
			sub -= 1;
		}
		else{
			break;
		}
	}
	
	cout << cont << endl;
}
}

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

int main() {
    int x, y;
    cin >> x >> y;
    cout << (x % y ? x : -1) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double r = sc.nextDouble(); 
     double pi = Math.PI; 

     double area = r*r*pi;
     double length = 2*r*pi;

     System.out.printf("%f %f", area, length);

     sc.close();

}

}


Measured memory_bytes: 27984
#include <iostream>

int main()
{
    int H, W;
    while (1) {
        std::cin >> H >> W;
        if (H == 0 || W == 0)
            break;
        char c = '#';
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                c = (i == 0 || i == H-1 || j == 0 || j == W-1) ? '#' : '.';
                std::cout << c;
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }
}

Measured memory_bytes: 3032
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include <map>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  int n,k;
  cin >> n >> k;
  map<int, int> snack;
  for (int i=0; i<k; ++i) {
    int d;
    cin >> d;
    for (int j=0; j<d; ++j) {
      int temp;
      cin >> temp;
      // cout << "i " << i << " " << snack[i] << endl;
      snack[temp] = 1;
    }
  }
  int ans = 0;
  for (int i=1; i<=n; ++i) {
    // cout << "i " << i << " " << snack[i] << endl;
    if (snack[i] != 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 3632
from collections import deque
from itertools import permutations as perm

N,M = map(int, input().split())
A = {}
for i in range(M):
    a,b = map(int, input().split())
    if a not in A:
        A[a] = {}
    if b not in A:
        A[b] = {}
    A[a][b] = A[b][a] = 1

ans = 0
for lst in perm([i for i in range(2,N+1)]):
    tmp = 1
    for i in range(N-1):
        if lst[i] not in A[tmp]:
            break
        tmp = lst[i]
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3444
import java.util.*;

public class Main{
  public static void main(String[] args){
    int n,r,p,c,num;
    Scanner sc = new Scanner(System.in);
    while((n = sc.nextInt()) != 0 | (r = sc.nextInt()) != 0){
      num=1;
      int[] cards = new int[n];
      for(int i=n-1;i>=0;i--){
        cards[i]=num;
        num++;
      }
      for(int i=0;i<r;i++){
        p = sc.nextInt();
        c = sc.nextInt();
        int[] cardsc = new int[c];
        for(int j=p-1;j<p-1+c;j++)cardsc[j-(p-1)] = cards[j];
        for(int j=p-2;j>=0;j--)cards[j+c] = cards[j];
        for(int j=0;j<c;j++)cards[j]=cardsc[j];
        //for(int j=0;j<n;j++)System.out.println(" " + cards[j]);
      }
      System.out.println(cards[0]);
    }
  }
}


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

int main() {
  int X, Y;
  cin >> X >> Y;
  int ans = 0;
  if (X == 1 && Y == 1) {
    cout << 1000000;
    return 0;
  }
  
  if (X == 1) ans += 300000;
  if (X == 2) ans += 200000;
  if (X == 3) ans += 100000;

  if (Y == 1) ans += 300000;
  if (Y == 2) ans += 200000;
  if (Y == 3) ans += 100000;

  cout << ans;
  return 0;
}

Measured memory_bytes: 256