akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const int MAX_N = 100;

int main(void){
    int N, X;
    int L[MAX_N];
    int answer = 0;
    int D = 0;

    cin >> N >> X;
    
    rep(i, N) cin >> L[i];
    int i = 0;

    while(D <= X && answer < N + 1){
        D += L[i];
        i ++;
        answer ++;
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
l,r=[int(i) for i in input().split()]
l2,r2=l%2019,r%2019
if l//2019<r//2019:
  print(0)
else:
  k=2019*2019
  for i in range(l,r):
    for j in range(i+1,r+1):
      k=min(k,i*j%2019)
  print(k)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 13
#define N 1000001
char arr[N][LEN];
int maxi=0;//max value of i (for double hashing)
void init(void);
void insert(char*);
void find(char*);
int hash1(int);
int hash2(int);
int toNumber(char*);
int main(void)
{
  int i;//counter
  int n;//the number of instructions
  char op[7];//operation(insert/find)
  char str[13];//string
  init();
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s%s",op,str);
      if(strcmp(op,"insert")==0) insert(str);
      if(strcmp(op,"find")==0) find(str);
    }
  return 0;
}
void init(void)
{
  int i;//counter
  for(i=0;i<N;i++) strcpy(arr[i],""); 
}
void insert(char *str)
{
  int i;//counter
  int h;//hash number
  int k=toNumber(str);//key number
  int h1=hash1(k);
  int h2=hash2(k);
  for(i=0;;i++)
    {
      if(maxi<i) maxi=i;
      h=(h1+i*h2)%N;
      if(strcmp(arr[h],"")==0)
	{
	  strcpy(arr[h],str);
	  break;
	}
    }
}
void find(char *str)
{
  int i;//counter
  int h;//hash number
  int k=toNumber(str);//key number
  int h1=hash1(k);
  int h2=hash2(k);
  int flag=0;//judging whether str is found or not
  for(i=0;i<=maxi;i++)
    {
      h=(h1+i*h2)%N;
      if(strcmp(str,arr[h])==0)
	{
	  flag=1;
	  break;
	}
      if(strcmp(arr[h],"")==0)
	{
	  flag=0;
	  break;
	}
    }
  if(flag==1) printf("yes\n");
  else printf("no\n");
}
int hash1(int k)
{
  return k%N;
}
int hash2(int k)
{
  return 1+k%(N-1);
}
int toNumber(char *str)
{
  int i;//counter
  int key=0;//return number
  int num;//value of the digit
  int dig=1;//the number of digits as 4 decimal
  for(i=0;i<strlen(str);i++)
    {
      switch(str[i])
	{
	case 'A':
	  num=0;
	  break;
	case 'C':
	  num=1;
	  break;
	case 'G':
	  num=2;
	  break;
	case 'T':
	  num=3;
	  break;
	default:
	  exit(1);
	}
      key+=num*dig;
      dig*=4;
    }
  return key;
}



Measured memory_bytes: 14432
#include<bits/stdc++.h>
using namespace std;
 
using lint=long long;
template<typename T> T LargestRectangle(vector<T>& h)
{
   // be careful not to overflow
   int N=h.size();
   vector<int> l(N),r(N);
   stack<int> S;
   for(int i=0;i<N;i++){
      while(!S.empty() and h[S.top()]>=h[i]) S.pop();
      l[i]=(S.empty()? 0:S.top()+1); S.push(i);
   }
   S=stack<int>();
   for(int i=N-1;i>=0;i--){
      while(!S.empty() and h[S.top()]>=h[i]) S.pop();
      r[i]=(S.empty()? N:S.top()); S.push(i);
   }
   T res=0;
   for(int i=0;i<N;i++) res=max(res,(h[i]+1)*(r[i]-l[i]+1));
   return res;
}

int main()
{
   int H,W; cin>>H>>W;
   vector<string> s(H);
   for(int i=0;i<H;i++) cin>>s[i];

   vector<vector<int>> a(H-1,vector<int>(W-1));
   for(int i=0;i<H-1;i++){
      for(int j=0;j<W-1;j++){
         int cnt=0;
         for(int dy=0;dy<2;dy++) for(int dx=0;dx<2;dx++){
            if(s[i+dy][j+dx]=='#') cnt++;
         }
         a[i][j]=cnt%2;
      }
   }

   int ans=max(H,W);
   vector<int> cnt(W-1);
   for(int i=0;i<H-1;i++){
      for(int j=0;j<W-1;j++){
         if(a[i][j]) cnt[j]=0;
         else cnt[j]++;
      }
      ans=max(ans,LargestRectangle(cnt));
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 22144
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    vecveci F(N,veci(10));
    vecveci P(N,veci(11));
    REP(i,N) REP(j,10) cin >> F[i][j];
    REP(i,N) REP(j,11) cin >> P[i][j];
    int ans = 1000000000;
    ans *= -1;
    for(int bit = 0; bit < (1<<10); bit++) {
        if(bit == 0) continue;
        int total = 0;
        REP(i,N) {
            int cnt = 0;
            REP(j,10) if((bit & (1<<j)) && F[i][j]) cnt++;
            //cout << cnt << endl;
            total += P[i][cnt];
        }
        chmax(ans,total);
    }
    cout << ans << endl;
}

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

int main() {
	int n,k,a[1000];
	cin >> n>>k;
	for(int i=0; i<n; i++) cin>>a[i];
	sort(a, a+n);
	int sum=0;
	for(int i=0; i<k; i++) sum+=a[i];
	cout<<sum;
	return 0;
}

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

int main(){

    string s;
    cin >> s;
    bool f = 0;

    for(int i = 0; i < s.size(); ++i){
        if(i%2 == 0){
            if(s.at(i) == 'L')f = 1;
        }else{
            if(s.at(i) == 'R')f = 1;
        }
    }

    if(f)cout << "No" << endl;
    else cout << "Yes" << endl;

}

Measured memory_bytes: 384
#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 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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

bool is_int(double x){
    if(ceil(x) != floor(x)){
        return false;
    }else{
        return true;
    }
}

int main() {
	llong N;
    cin >>N;
    llong ans =0;
    llong r = sqrt(N)+1;
    FOR(i,1,min(r,N)){
        double s = double(N)/(i);
        if(! is_int(s)) continue;
        llong m = N/i - 1;
        if(i>=m){
            break;
        }else{
            ans+=m;
        }

    }
    


    cout << ans << endl;


    

    




}


Measured memory_bytes: 256
d,g = gets.chomp.split.map(&:to_i)
ps,cs = d.times.map{gets.chomp.split.map(&:to_i)}.transpose
ans = 10**5
(2 ** d).times do |i|
  sum = 0
  cnt = 0
  num = 0
  d.times do |j|
    if i[j] == 1
      cnt += ps[j]
      sum += (ps[j] * 100 * (j+1) + cs[j])
    else
      num = j
    end
  end

  if sum < g
    temp = ((g - sum).to_f / (100 * (num+1)) ).ceil
    if temp < ps[num]
      cnt += temp
      ans = cnt if ans > cnt
    end
  else
    ans = cnt if ans > cnt
  end
end

puts ans


Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    int n;
    cin>>n;
    double t,a;
    cin>>t>>a;
    vector<pair<double,int>> s(n);
    rep(i,n){
        double h;
        cin>>h;
        s[i]=mp(abs(t-h*0.006-a),i+1);
    }
    sort(all(s));
    cout<<s[0].sc;
}

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

int main(){
  long long N,ans1=0,ans2=0;
  cin >> N;
  vector<int> A1(N) , A2(N);
  for(int i=0;i<N;i++){
    cin >> A1[i];
    A2[i] = A1[i];
  }
  
  if(A1[0]<=0){
    ans1 -= A1[0]-1;
    A1[0] -= A1[0]-1;
  }
  for(int i=1;i<N;i++){
    A1[i] += A1[i-1];
    if(A1[i-1]>0 && A1[i]>=0){
      ans1 += A1[i]+1;
      A1[i] -= A1[i]+1;
    }
    if(A1[i-1]<0 && A1[i]<=0){
      ans1 -= A1[i]-1;
      A1[i] -= A1[i]-1;
    }
  }
  
  if(A2[0]>=0){
    ans2 += A2[0]+1;
    A2[0] -= A2[0]+1;
  }
  for(int i=1;i<N;i++){
    A2[i] += A2[i-1];
    if(A2[i-1]>0 && A2[i]>=0){
      ans2 += A2[i]+1;
      A2[i] -= A2[i]+1;
    }
    if(A2[i-1]<0 && A2[i]<=0){
      ans2 -= A2[i]-1;
      A2[i] -= A2[i]-1;
    }
  }
  
  cout << min(ans1,ans2) << endl;
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		WriteLine(Max(I[0] + I[1], Max(I[0] - I[1], I[0] * I[1])));
	}
}


Measured memory_bytes: 13268
#include<iostream>
#include<vector>
using ll = long long;
using namespace std;

int main(){
	//swapと-1~1のfor文がミソ
	ll k;
	cin >> k;
	vector<ll> v;
	for(ll i=1;i<10;i++) v.push_back(i);
	while(1)
	{
		//for(auto it : v) cout << it <<" ";
		if(k<=v.size())
		{
			cout << v[k-1];
			return 0;
		}
		k -= v.size();
		vector<ll> old;
		swap(old,v);
		for(auto it : old)
		{
			for(ll i=-1;i<=1;i++)
			{
				ll d = it%10+i;
				if(d<0 || d>9)continue;
				v.push_back(it*10+d);
			}
		}
	}
	return 0;	
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
#define BIT(S,i) ((S&(1ll<<i))>0)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;

signed main(){
	int N;
	cin>>N;
	vector<vector<int>>g(N);
	REP(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	auto dfs = [&](auto&&f,int now,int par)->int{
		int ret = 0;
		for(auto e:g[now]){
			if(e == par)continue;
			ret ^= (1 + f(f,e,now));
		}
		return ret;
	};
	if(dfs(dfs,0,-1))cout<<"Alice"<<endl;
	else cout<<"Bob"<<endl;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

string s = "24579";
string t = "0168";

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	n = n % 10;
	char x = (char)(n + '0');
	if(s.find(x) != string::npos)
		cout << "hon";
	else if(t.find(x) != string::npos)
		cout << "pon";
	else
		cout << "bon";
	return 0;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, h;
  int maxh = 0;
  cin >> n;
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> h;
    if (maxh <= h) {
      count++;
    }
    maxh = max(h, maxh);
  }
  cout << count;
}


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

int main() {
 int x = 1, N, K;
  cin >> N;
  cin >> K;
  for (int i = 0; i < N; i++) {
    if (x * 2 <= x + K)
      x *= 2;
    else
      x += K;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let pat=vec!["maerd","remaerd","esare","resare"];
    let s:String=read::<String>().chars().rev().collect();
    let mut s=&s[..];
    let mut ans=true;
    while s.len()>0{
        let m=pat.iter().find(|&p|s.find(p)==Some(0));
        if let Some(p)=m{s=&s[p.len()..]}
        else{ans=false;break}
    }
    println!("{}",if ans{"YES"}else{"NO"})
}


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

int ctoi(char c) {
  if (c == '0') {return 0;}
  if (c == '1') {return 1;}
  if (c == '2') {return 2;}
  if (c == '3') {return 3;}
  if (c == '4') {return 4;}
  if (c == '5') {return 5;}
  if (c == '6') {return 6;}
  if (c == '7') {return 7;}
  if (c == '8') {return 8;}
  if (c == '9') {return 9;}
}

int main() {
  string s; cin >> s;
  int res = 1000;
  for (int i = 0; i < s.size()-2; i++) {
    int n = ctoi(s[i])*100+ctoi(s[i+1])*10+ctoi(s[i+2]);
    res = min(res, abs(n-753));
  }
  cout << res << endl;
}
    

Measured memory_bytes: 256
s = gets.strip.split('').map(&:to_i)
inv = []
(0..s.length-1).each do |i|
  if s[0] == 0
    if i.even?
      inv[i]= 0
    else
      inv[i]= 1
    end
  else
    if i.even?
      inv[i]= 1
    else
      inv[i]= 0
    end
  end
end
ans = 0

(0..s.length-1).each do |i|
  ans += (s[i]-inv[i]).abs

end

puts ans


Measured memory_bytes: 8644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {


  int h,w;cin>>h>>w;

  for(int i=0;i<w+2;i++)cout<<'#';
  cout<<endl;

  for(int i=0;i<h;i++){
    string s;cin>>s;
    cout<<'#'<<s<<'#'<<endl;
  }

  for(int i=0;i<w+2;i++)cout<<'#';
  cout<<endl;

  return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repi(i, x) for (auto &i : (x))


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    rep(i, sz(v)) cout << v[i] << ",";
    cout << "]";
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}

#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif

template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

int N, H;
int A[2002];

void done() {
    cout << 0 << endl;
    exit(0);
}

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int N, P;
    cin >> N >> P;
    cout << (3*N+P)/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<numeric>

using namespace std;

long long MOD = 1000000007;

int n;

long long a[200005];
long long as[2][200005];

long long b[200005];
long long bs[2][200005];

long long solve(int k, long long base){

  int now = k % 2;
  int prev = now ^ 1;

  int cnta = 0;
  int cntb = 0;

  for(int i = 0;i<n;i++)if((as[prev][i] & base) == 0) cnta++;
  for(int i = 0;i<n;i++)if((bs[prev][i] & base) == 0) cntb++;

  int cnta0 = 0;
  int cnta1 = 0;

  int cntb0 = 0;
  int cntb1 = 0;

  for(int i = 0;i<n;i++){
    if(as[prev][i] & base) as[now][cnta + (cnta1++)] = as[prev][i];
    else as[now][cnta0++] = as[prev][i];

    if(bs[prev][i] & base) bs[now][cntb + (cntb1++)] = bs[prev][i];
    else bs[now][cntb0++] = bs[prev][i];
  }

  //cout<<k<<" "<<base<<endl;
  //cout<<cnta<<" "<<cnta0<<" "<<cnta1<<endl;
  //cout<<cntb<<" "<<cntb0<<" "<<cntb1<<endl;
  //for(int i=0;i<n;i++)cout<<as[now][i]<<" ";cout<<endl;
  //for(int i=0;i<n;i++)cout<<bs[now][i]<<" ";cout<<endl;

  long long cnt = 0;
  long long ma = n-1;
  long long mi = n-1;
  long long mma = n-1;

  for(int i=0;i<n;i++){
      while( (mma!=-1) && ((as[now][i]%(base*2LL)) + (bs[now][mma]%(base*2LL)) >= base*3LL) ) mma--;
      while( (ma!= -1) && ((as[now][i]%(base*2LL)) + (bs[now][ma ]%(base*2LL)) >= base*2LL) ) ma--;
      while( (mi!= -1) && ((as[now][i]%(base*2LL)) + (bs[now][mi ]%(base*2LL)) >= base    ) ) mi--;
      //cout<<i<<" "<<ma<<" "<<mi<<" "<<mma<<endl;
      cnt += (ma-mi) + ((long long)(n-1)-mma);
  }

  return cnt%2LL;

}

int main(){
  cin>>n;

  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n;i++){
    as[1][i] = a[i];
    bs[1][i] = b[i];
  }

  long long ans = 0;
  long long base = 1;

  for(int i=0;i<=30;i++){
    ans += base * solve(i,base);
    base *= 2LL;
    //cout<<ans<<endl;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 9600
INF = 1<<31
V, E, r = map(int, raw_input().split())
edge = [map(int, raw_input().split()) for i in range(E)]
dist = [INF]*V
dist[r] = 0
f = False
for i in xrange(V):
    for u, v, w in edge:
        if dist[u] != INF and dist[v] > dist[u] + w:
            dist[v] = dist[u] + w
            if i == V - 1: f = True 
if f: print "NEGATIVE CYCLE"
else:
    for i in dist: print "INF" if i == INF else i

Measured memory_bytes: 6484
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    ll n,d;cin >> n >> d;
    int cnt=0;
    rep(i,n){
        ll a,b;cin >> a >> b;
        if(a*a+b*b<=d*d)cnt++;
    }
    cout << cnt << endl;
}

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

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



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

    long long int n, m;
    cin >> n >> m;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mincost(int ar[],int n){
	int dp[n+1]={0};
	if(n==0){
		return 0;
	}
	if(n==1){
		dp[1]=0;
	}

	for(int i=2;i<=n;i++){
			int op1=INT_MAX,op2=INT_MAX;
	
		op1 = dp[i-1]+abs(ar[i]-ar[i-1] );

		op2 =i==2?INT_MAX:dp[i-2]+abs(ar[i]-ar[i-2]);
	

	dp[i]=min(op1,op2);
	
	}
return dp[n];
}
int main(){
	int n;
	cin>>n;
	int ar[n];
	for(int i=1;i<=n;i++){
		cin>>ar[i];
	}
	cout<<mincost(ar,n)<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline void rdi(int &x){
	int f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	if(f) x=-x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
int n,h[200005],a[200005];
ll t[200005];
inline void upd(int x,ll y){for(;x<200005;x+=x&-x) t[x]=max(t[x],y);}
inline ll get(int x){ll rt(0);for(;x;x-=x&-x) rt=max(rt,t[x]);return rt;}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	rdi(n);
	int i,j;
	for(i=0;i<n;++i) rdi(h[i]);
	for(i=0;i<n;++i) rdi(a[i]);
	for(i=0;i<n;++i) upd(h[i],get(h[i])+a[i]);
	cout<<get(n)<<endl;
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int H = int.Parse(ReadLine());
        int W = int.Parse(ReadLine());
        int N = int.Parse(ReadLine());
        int paint = Max(H, W);
        int ans = N / paint;
        if (N % paint > 0) ans++;
        WriteLine(ans);
    }
}


Measured memory_bytes: 27276
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N ;
  cin>>N;
  int count = 0;
  for(int i = 0 ;i<N;i++){
    string color;
    cin>>color;
    if (color=="Y"){
      count++;
      break;
    }
  }
  if(count==1){
    cout<<"Four"<<endl;
  }
  else{
    cout<<"Three"<<endl;
  }
}

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

using namespace std;

int main(){

	double cx,cy;cx=cy=0;
	int ca=90;
	int op[2];
	char tmp;
	while(cin>>op[0]>>tmp>>op[1]&&!(op[0]==0&&op[1]==0)){
		cy += op[0]*sin(((double)ca/180)*3.141592);
		cx += op[0]*cos(((double)ca/180)*3.141592);
		ca -= op[1];
	}
	cout<<(int)cx<<endl;
	cout<<(int)cy<<endl;
	return 0;
}

Measured memory_bytes: 0
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let h: Vec<isize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    const INF: usize = 1_000_000_001;
    let mut dp: Vec<usize> = vec![INF; n];
    dp[0] = 0;
    for i in 1..n {
        dp[i] = min(dp[i], dp[i - 1] + (h[i] - h[i - 1]).abs() as usize);
        if i >= 2 {
            dp[i] = min(dp[i], dp[i - 2] + (h[i] - h[i - 2]).abs() as usize);
        }
    }
    return format!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int l,n,m=1; cin>>l;
    l--;
    if(l==1){
        cout<<2<<" "<<2<<endl;
        cout<<1<<" "<<2<<" "<<0<<endl;
        cout<<1<<" "<<2<<" "<<1<<endl;
    }
    else{
    rep(i,21){
        if(m>l){
            n=i; m=2*n-1; break;
        }
        m<<=1;
    }
    for(int i=1;i<n-1;i++)if((1<<i)&l) m++;
    cout<<n<<" "<<(l!=3 ? m : m+1)<<endl;
    rep(i,n-1){
        cout<<i+1<<" "<<i+2<<" "<<0<<endl;
        cout<<i+1<<" "<<i+2<<" "<<(1<<(n-2-i))<<endl;
    }
    int c=(1<<(n-1));
    for(int i=1;i<n-1;i++){
        if((1<<(n-1-i))&l){
            cout<<1<<" "<<i+1<<" "<<c<<endl;
            c+=(1<<(n-1-i));
        }
    }
    if(l==3){
        cout<<1<<" "<<2<<" "<<2<<endl;
        cout<<1<<" "<<2<<" "<<3<<endl;
    }
    else if(1&l){
        cout<<1<<" "<<n-1<<" "<<c<<endl;
    }
    else{
        cout<<1<<" "<<n<<" "<<c<<endl;
    }
    }
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for i in range(A + 1):
    for j in range(B + 1):
        for h in range(C + 1):
            if i * 500 + j * 100 + h * 50 == X:
                count += 1
print(count)

Measured memory_bytes: 67052
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
using namespace std;

const int mmod = 1000000007;

//vector<vector<vector<int> > cnt;

vector<vector<vector<pair<int, int> > > > M;

int calc(int one, int zero, int step, int depth, int k) {
  // one, one-(k-1), ... one-(k-1)*(step-1) are possible.
  // zero is remaining freedom.

  int plus = 0;
  if (one-(k-1)*(step-1) <= 0 && one % (k-1) == 0) {
    plus = 1;
    step = one / (k-1);
  }
  step = min(step, one/(k-1)+1);
  if (zero == 0) {
    return plus;
  }

  if (one < 0 || zero < 0 || step == 0) return plus;

  if (depth == 0) {
    return plus; //one >= 0 && one-(k-1)*(step-1) <= 0 && one % (k-1) == 0;
  }
  while (step && one > 0 && one > depth * (k-1)) {
    one -= k-1;
    step --;
  }
  zero = min(zero, depth * (k-1));
  if (step == 0) return plus;

//  printf("%d %d %d %d\n", one, zero, step, depth);
  int now = (depth << 15) + step;
  for (auto pr : M[zero][one])
    if (pr.first == now) return (pr.second + plus) % mmod;

  int pl = 1;
  int next_step = step;
  for (int j=0; j<depth-1; j++) {
    next_step += pl;
    pl *= k;
    if (one-(k-1)*(next_step-1) < 0) break;
  }
//printf("%d %lld ", one, next_step);
  next_step = min(next_step, one/(k-1)+1);
//printf("%lld\n", next_step);

  int res = 0;
  for (int i=0; i<k; i++) {
    if (i == 0) {
      res = calc(one, zero-(k-1), step, depth-1, k);
      continue;
    }
    int next_zero = zero - (k-1-i);
    int next_one = one - i;
    res += calc(next_one, next_zero, next_step, depth-1, k);
    if (res >= mmod) res -= mmod;
  }
//  printf("one = %d, zero = %d, step = %d, depth = %d, k = %d : %d\n", one, zero, step, depth, k, res);
  M[zero][one].push_back(pair<int, int>(now, res));
  return (res + plus) % mmod;
}


int main()
{
  int n, m, k;
  cin >> n >> m >> k;
  if (k == n+m) {
    printf("1\n");
    return 0;
  }

  int depth = (n+m-1)/(k-1);
  M.resize(n+1);
  for (int i=0; i<=n; i++)
    M[i].resize(m+1);
  // i = 0 .. depth-1
  // p = 0 .. k-1
  // j = 0 .. n+m
/*  cnt.resize(depth);
  for (int i=0; i<depth; i++) {
    cnt[i].resize(k);
    for (int p=0; p<k-1; p++)
      cnt[i][p].resize(n+m);
  }*/

/*  // cnt[i][p][j] : possible ways to make (k^i)*p with j nodes
  for (int i=0; i<depth; i++) {
    cnt[i][1][1] = 1;

    for (int p=1; p<k; p++) {
      
    }
  }*/
    


  cout << calc(m, n, 1, depth, k) << endl;
}



Measured memory_bytes: 219648
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int cnt{};
    for( int i = 0; i <= 100000; i++ )
    {
        if( Y * i + Z * ( i + 1 ) > X )
        {
            break;
        }
        cnt = i;
    }
    cout << cnt << endl;
    return 0;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer x;
  x = nil->next;
  while( x != nil && x ->key != key ){
    x = x->next;
  }
  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->next->prev = t->prev;
  t->prev->next = t->next;

}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}
void deleteLast(){
  NodePointer x = nil->prev;
  if ( x == nil ) return;
  deleteNode(x);
}

void delete(int key){
  NodePointer x = listSearch(key);
  if ( x == nil ) return;
  deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}
int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if(!( 0 <= key && key <= 2000000000)){printf("error") ;}
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key); nd++;
      }
      size--;
    }
    if ( size > 1000000 ) { printf("error"); }
  }


  if(!( np+nd <= 2000000)){printf("error") ;}
  if(!( nd <= 20)){printf("error") ;}
  printList();


  return 0;
}




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

int main(){

  int n = 0;
  while(cin >> n){
  int count = 0;

  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
      for(int k =0;k<=9;k++){
	for(int l=0;l<=9;l++){
	  if(n == i+j+k+l){
	    count++;
	  }
	}
      }
    }
  }
  cout << count << endl;
  }


  return 0;
}

Measured memory_bytes: 3100
#include <math.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

constexpr long long INFLL = 1e18;

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n;
  cin >> n;
  ll ans;
  ll pm = 1e9 + 7;
  if (n == 1) {
    ans = 0;
  } else {
    ans = 1;
    ll temp1 = 1;
    ll temp2 = 1;
    for (int i = 0; i < n; i++) {
      ans = ans * 10 % pm;
      temp1 = temp1 * 8 % pm;
      temp2 = temp2 * 9 % pm;
    }
    ans = ans - temp2 * 2 + temp1;
    ans %= pm;
    if (ans < 0) {
      ans += pm;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3184
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()

def solve():
    R, C, N = map(int, line_input())
    u, l, r, d = [], [], [], []
    for i in range(N):
        x, y, z, w = map(int, line_input())
        if x == 0:
            if z == 0: 
                u.append((y, i))
                u.append((w, i))
            elif w == C:
                u.append((y, i))
                r.append((z, i))
            elif z == R:
                u.append((y, i))
                d.append((w, i))
            elif w == 0:
                u.append((y, i))
                l.append((z, i))
        elif x == R:
            if z == 0: 
                d.append((y, i))
                u.append((w, i))
            elif w == C:
                d.append((y, i))
                r.append((z, i))
            elif z == R:
                d.append((y, i))
                d.append((w, i))
            elif w == 0:
                d.append((y, i))
                l.append((z, i))
        elif y == 0:
            if z == 0: 
                l.append((x, i))
                u.append((w, i))
            elif w == C:
                l.append((x, i))
                r.append((z, i))
            elif z == R:
                l.append((x, i))
                d.append((w, i))
            elif w == 0:
                l.append((x, i))
                l.append((z, i))
        elif y == C:
            if z == 0: 
                r.append((x, i))
                u.append((w, i))
            elif w == C:
                r.append((x, i))
                r.append((z, i))
            elif z == R:
                r.append((x, i))
                d.append((w, i))
            elif w == 0:
                r.append((x, i))
                l.append((z, i))
    u.sort()
    r.sort()
    d.sort(reverse = True)
    l.sort(reverse = True)

    s = []
    used = set()
    crossed = True
    for point, n in u:
        if n not in used:
            s.append(n)
            used |= {n}
        else:
            if s[-1] != n: break
            else: s.pop()
    else:
        for point, n in r:
            if n not in used:
                s.append(n)
                used |= {n}
            else:
                if s[-1] != n: break
                else: s.pop()
        else:
            for point, n in d:
                if n not in used:
                    s.append(n)
                    used |= {n}
                else:
                    if s[-1] != n: break
                    else: s.pop()
            else:
                for point, n in l:
                    if n not in used:
                        s.append(n)
                        used |= {n}
                    else:
                        if s[-1] != n: break
                        else: s.pop()
                else: crossed = False

    print("NO" if crossed else "YES")
                            
    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 33724
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;
    int ans = 0;
    for (auto c : s) {
        if (c == 'I') {
            ++x;
        } else {
            --x;
        }
        ans = max(ans, x);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N,K = map(int, input().split())
d = [0]*2*K
for i in range(K):
    d[2*i], d[2*i+1] = map(int, input().split())
a=[0]*(N+1)
b=[0]*(N+1)
a[1]=1
b[1]=1
for i in range(2,N+1):
    t=0
    for j in range(K):
        if i-d[2*j]>0:
            t+=b[i-d[2*j]]
        if i-d[2*j+1]-1>0:
            t-=b[i-d[2*j+1]-1]
    a[i]=t
    b[i]=(b[i-1]+a[i])%998244353
print(a[N]%998244353)


Measured memory_bytes: 76752
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<ctime>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<cstring>
#include<stack>
#include<cctype>
#include<cstdio>
#include<bitset>
#ifdef LOCAL
	#define enu(i,n) for(int i=0;i<n;i++)
	#define tri(x) x*(x+1)/2;
	#define sqrsum(x) x*(x+1)*(2*x+1)/6;
	#define sqrsum_range(a,b) sqrsum(b)-sqrsum(a-1);
#endif
#define FOR(i,a,b) for(int i=a,_b=b;i<_b;i++)
#define REP(i,a,b) FOR(i,a,b+1)
#define ll_max 9223372036854775807LL
#define ll_min -9223372036854775808LL
#define int_max 2147483647
#define int_min -2147483648
#define PI 3.14159265358979323846265
#define eps 0.00000001
#define elif else if
using namespace std;
void fast()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	return ;
}
bool isprime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int GCD(int a,int b)
{
	return (b?GCD(b,a%b):a);
}
struct Tm
{
	int h,m,s;
	bool add()
	{
		s++;
		if(s==60)
			m++,
			s=0;
		if(m==60)
			h++,
			m=0;
		return (h<100);
	}
	void print()
	{
		printf("%02d:%02d:%02d",h,m,s);
		return ;
	}
	void println()
	{
		print();
		puts("");
	}
};
string S;
int dp[100100][15];
int mod[100100];
int main()
{
	cin>>S;
	mod[0]=1;
	for(int i=1;i<S.length();i++)
		mod[i]=(mod[i-1]*10)%13;
	reverse(S.begin(),S.end());
	dp[0][0]=1;
	for(int i=0;i<S.length();i++)
	{
		if(isdigit(S[i]))
		{
			int x=S[i]-'0';
			int M=x*mod[i]%13;
			for(int j=0;j<13;j++)
				dp[i+1][(j+M)%13]=dp[i][j];
		}
		else
			for(int x=0;x<10;x++)
			{
				int M=x*mod[i]%13;
				for(int j=0;j<13;j++)
					dp[i+1][(j+M)%13]=(dp[i][j]+dp[i+1][(j+M)%13])%1000000007;
			}
	}
	cout<<dp[S.length()][5]<<endl;
	return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

int power(int x,int n,int mod){
    //(x^n)%mod
    int result=1;
    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

int inverseMod(int x,int mod){
    return power(x,mod-2,mod);
}



int32_t main() {

    fast
    
    int d,t,s;
    cin>>d>>t>>s;

    if(d<=s*t){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }



    return 0;
}



Measured memory_bytes: 3608
using System;
class Program
{
    static void Main()
    {
        for (int i = 0; i < 4; i++)
        {
            int[] tickets = { 6000, 4000, 3000, 2000 };
            var strs = Console.ReadLine().Split(' ');
            Console.WriteLine(tickets[Int32.Parse(strs[0]) - 1] * Int32.Parse(strs[1]));
        }
    }
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string a, b, c;
  cin >> a >> b >> c;
  if(a.back() == b[0] && b.back() == c[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

#define NIL NULL

struct node{
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};
typedef struct node * Node;

Node g_root;

void insert(int k);
void inorder(Node u);
void preorder(Node u);
Node treeSearch(Node x, int k);
Node treeMinimum(Node x);
Node treeSuccessor(Node x);
void treeDelete(Node z);

int main(){
  int n,i,x;
  char com[20];

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%s",com);
    if(com[0] == 'f'){
      scanf("%d",&x);
      Node t = treeSearch(g_root, x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    }else if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }else if(com[0] == 'p'){
      inorder(g_root);
      printf("\n");
      preorder(g_root);
      printf("\n");
    }else if(com[0] == 'd'){
      scanf("%d",&x);
      treeDelete(treeSearch(g_root, x));
    }
  }
  
  return 0;
}

void insert(int k){
  Node y = NIL;
  Node x = g_root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if(y == NIL) g_root = z;
  else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

void inorder(Node u){
  if(u == NIL) return;

  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;

  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Node treeSearch(Node x, int k){
  while(x != NIL && k != x->key){
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  return x;
}

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  Node x;

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  //yの子を決める
  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) g_root = x;
  else{
    if(y == y->parent->left){
      y->parent->left = x;
    }else{
      y->parent->right = x;
    }
  }
  if(y != z) z->key = y->key;

  free(y);
}




Measured memory_bytes: 20484
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int m,f,r;
    int sum = 0;
    
    while(1){
        scanf("%d %d %d",&m, &f, &r);
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        if(m == -1 || f ==-1){
            printf("F\n");
        }else{
            sum = m + f;
            if(sum >= 80) {
                printf("A\n");
            }else if(65 <= sum && sum < 80){
                printf("B\n");
            }else if(50 <= sum && sum < 65){
                printf("C\n");
            }else if(30 <= sum && sum < 50){
                if(r >= 50){
                    printf("C\n");
                }else{
                printf("D\n");
                }
            }else if(sum < 30){
                printf("F\n");
            }
            
        }
    }
    return 0;
}



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

const long mod = 1000000007;

long fact[200001];

long pow(long a, long b)
{
  if (b == 0)
    return 1;
  if (b % 2 == 0)
  {
    long half = pow(a, b / 2) % mod;
    return half * half % mod;
  }
  else
  {
    return a % mod * pow(a, b - 1) % mod % mod;
  }
}

void calc_fact_table()
{
  for (int i = 1; i <= 200000; i++)
  {
    fact[i] = fact[i - 1] * i % mod;
  }
}

long calc_inv(long n)
{
  return pow(n, mod - 2) % mod;
}

long calc_comb(long n, long r)
{
  if (n - r < r)
    return calc_comb(n, n - r);
  return fact[n] * calc_inv(fact[n - r] * fact[r] % mod) % mod;
}

int main()
{
  long H, W, A, B;
  cin >> H >> W >> A >> B;
  fact[0] = 1;
  calc_fact_table();
  long ans = 0;
  for (int i = 0; i < W - B; i++)
  {
    ans += calc_comb(H - A - 1 + B + i, H - A - 1) * calc_comb(A - 1 + W - B - 1 - i, A - 1) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;
mint modpow(ll _a, ll n) {
 	mint r=1,a=_a;
 	while(n){
 		r*=((n%2)?a:1);
 		a*=a;
 		n>>=1;
 	}
 	return r;
 }
vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
	N = min(N, mint::Mod - 1);
	fact.resize(N + 1); factinv.resize(N + 1);
	fact[0] = 1;
	reg(i, 1, N) fact[i] = fact[i - 1] * i;
	factinv[N] = fact[N].inverse();
	for (int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}
mint nCr(int n, int r) {
	if (n >= mint::Mod)
		return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
	return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}
mint nPr(int n, int r) {
	if (r<0)return 0;
	return r > n ? 0 : fact[n] * factinv[n-r];
}
mint nHr(int n, int r) { return r == 0 ? 1 : nCr(n + r - 1, r); }

int h,w,a,b;
mint ans=0;

int main(void){
	cin>>h>>w>>a>>b;
	nCr_computeFactinv(h+w);
	reg(i,b+1,w)ans += nCr(h - a + i - 2 , i - 1) * nCr(a - 1 + w - i , a - 1);
	cout<<ans.get()<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
static const int MAX=100000;
int a[MAX];
int flag2,flag4,x;

int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>x;
        if(x%4==0)flag4++;
        else if(x%2==0)flag2++;
    }
    if(flag2/2+flag4>=N/2)
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

	int getUpHour, getUpMin, sleepHour, sleepMin, studyTime;	
	int wakeTime = 0, startTime = 0;
	
	scanf("%d%d%d%d%d", &getUpHour, &getUpMin, &sleepHour, &sleepMin, &studyTime);

	wakeTime = (sleepHour - getUpHour) * 60;
	if (sleepMin > getUpMin)
	{
		wakeTime += sleepMin - getUpMin;
	}
	else
	{
		wakeTime -= getUpMin - sleepMin;
	}

	startTime = wakeTime - studyTime;

	printf("%d", startTime);

	}

Measured memory_bytes: 1728
#include<bits/stdc++.h> 
 
using namespace std; 
  
void lcs( string X, string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   int index = L[m][n]; 
  
   char lcs[index+1]; 
   lcs[index] = '\0'; 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
     
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1];  
          i--; j--; index--;      
      } 
  
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   cout<<lcs; 
} 
  
int main() 
{ 
  string x,y;
  cin>>x>>y;
  int m = x.length(); 
  int n = y.length(); 
  lcs(x, y, m, n); 
  return 0; 
} 

Measured memory_bytes: 35456