akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
    int a,b,x[5],num,count=0;
    cin>>a>>b;
    
    for(int i=a;i<=b;i++){
        num=i;
        for(int j=0;j<5;j++){
            x[j]=num%10;
            num/=10;
        }
        if(x[0]==x[4]&&x[1]==x[3])
            count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3484
#include "bits/stdc++.h"
using namespace std;

string s,t = "";
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>s;
	for(int i=0;i<s.size();i+=2){
		t += s[i];
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int A[]=new int[N];
		int c=1;
		for(int i=0;i<N;i++) {
			A[i]=sc.nextInt();
			if(A[i]%2==1) {
				A[i]=1;
			}
			else {
				A[i]=2;
			}
			c=c*A[i];
		}
		c=(int)Math.pow(3, N)-c;
		System.out.println(c);
		
	}
}


Measured memory_bytes: 22484
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int dfs(VVI& g, int v, int p, int depth, int k) {
	int ret = 0;
	if (depth > k) {
		ret++;
	}
	for (auto to : g[v]) {
		if (to != p)ret += dfs(g, to, v, depth + 1, k);
	}
	return ret;
}

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	VVI g(n);
	vector<PII> edges(n - 1);
	REP(i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		g[u].PB(v);
		g[v].PB(u);
		edges[i] = MP(min(u, v), max(u, v));
	}
	int ans = 1e9;
	if (k % 2) {
		REP(i, n - 1) {
			ans = min(ans, dfs(g, edges[i].first, edges[i].second, 0, k / 2) + dfs(g, edges[i].second, edges[i].first, 0, k / 2));
		}
	}
	else {
		REP(i, n) {
			ans = min(ans, dfs(g, i, i, 0, k / 2));
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    cout << (s[0] == t[0] ? 1 : 0) + (s[1] == t[1] ? 1 : 0) + (s[2] == t[2] ? 1 : 0) << endl;
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
L, R, U, D = 0, W, H, 0
for p in P:
  x, y, a = p
  if a == 1:
    L = max(L, x)
  elif a == 2:
    R = min(R, x)
  elif a == 3:
    D = max(D, y)
  else:
    U = min(U, y)
print(max(U-D, 0) * max(R-L, 0))


Measured memory_bytes: 9140
n=int(input())
p = list(map(int,input().split(' ')))
i = 1
count=0
while i+1 < n:
    if (p[i]>p[i-1] and p[i]<p[i+1]) or (p[i]<p[i-1] and p[i]>p[i+1]):
        count += 1
    i += 1
print(count)

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

int main() {
	
	int ans=0;
	
	string s;
	
	cin >> s;
	
	if(s=="SUN") ans=7;
	if(s=="MON") ans=6;
	if(s=="TUE") ans=5;
	if(s=="WED") ans=4;
	if(s=="THU") ans=3;
	if(s=="FRI") ans=2;
	if(s=="SAT") ans=1;
	
	
    cout << ans << '\n';
    
    return 0;

}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
c = 0
for i in range(N):
    A = list(map(int, input().split()))
    p = sum([A[i]*B[i] for i in range(M)]) + C
    if p > 0:
        c += 1
print(c)


Measured memory_bytes: 3060
import java.util.*;

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();
		if (c >= a && c <= b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22868
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    
   int a, b;
   cin >> a >> b;

   if(a<=b){
       cout << a << endl;
       return 0;
   }
   else{
       cout << a -1 << endl;
   }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <set>
#include <vector>
using namespace std;


int main(){
    string s;
    cin>>s;
    int i=0;
    for(auto v:s){
        i++;
        if(i==1){
            cout<<v;
            //cout<<s.length();
        }
        if(i==s.length()){
            cout<<i-2<<v<<endl;
        }
    }
    return 0;
}

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

namespace id_0631cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = nm[0];
            var m = nm[1];
            var hits = new List<int>(m);
            foreach(var i in Enumerable.Range(0, m))
            {
                var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                hits.Add(ab[0]);
            }
            hits.Sort();
            var shorts = hits.Skip(1).Where(x => x < n);
            Console.WriteLine(shorts.Count() * n - shorts.Sum());
        }
    }
}



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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  ll k;
  cin >> n >> k;

  vector<ll> cnts(200000, 0);
  for (int i = 0; i < n; ++i) {
    int a;
    ll b;
    cin >> a >> b;
    cnts[a] += b;
  }

  ll acc = 0, ans = 0;
  for (int i = 1; i < cnts.size(); ++i) {
    acc += cnts[i];
    if (acc >= k) {
      ans = i;
      break;
    }
  }

  cout << ans << '\n';

  return 0;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int W, H, N;
int x[110], y[110], a[110];
signed main() {
    cin >> W >> H >> N;
    int w = 0, h = 0;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> a[i];
        if (a[i] == 1) {
            w = max(w, x[i]);
            w = min(w, W);
        } else if (a[i] == 2) {
            W = min(W, x[i]);
            W = max(w, W);
        } else if (a[i] == 3) {
            h = max(h, y[i]);
            h = min(h, H);
        } else {
            H = min(H, y[i]);
            H = max(h, H);
        }
    }
    cout << (W - w)*(H - h) << endl;
}

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

#define LL long long
#define mods 1000000009



int main()
{
   // factorila();
    //freopen("amin.txt","w",stdout)
    long long n,i,ss;
    cin>>n>>i;
    LL ans=0;
    if(n>=1)
    {
        if(i>=2LL*n)
        {
            ans=n;
            i=i-2LL*n;
            ans+=(LL)(i/4LL);
        }
        else
        {
            ss=(LL)(i/2LL);
            ans=ss;
        }
    }
    else
    {
        ans=(LL)(i/4LL);
    }
    cout<<ans<<"\n";
}


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

#define ll long long
#define MOD 998244353

using namespace std;

ll r,g,b,n;

int main(){
 cin>>r>>g>>b>>n;
 ll ans=0;
 for(ll i=0;i<=n/r;++i){
    for(ll j=0;j<=(n-i*r)/g;++j){
        ll k=0;
        k=n-i*r-j*g;
        if(k%b==0) {
            ans++;
        }
    }
 }
 
 cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,x;cin>>n>>x;
	ll cnt = 0;
	ll arr[n];
	for(int i = 0; i < n; ++i) cin>>arr[i];
	for(int i = 1; i < n; ++i){
		if(arr[i] + arr[i-1] > x){
			ll val = arr[i] + arr[i-1] - x;
			cnt += val;
			// cout<<val<<endl;
			if(arr[i] >=val){
				arr[i] -= val;
			} else{
				arr[i] = 0;
				val -= arr[i];
				arr[i-1] -= val;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 1024
import java.util.*
 
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    if (listOf(a, b, c).sorted() == listOf(5, 5, 7)) println("YES")
    else println("NO")
}

Measured memory_bytes: 33852
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,y=0;
  cin>>N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  for(int i=1;i<N-1;i++){
    if(P.at(i-1)<=P.at(i)&&P.at(i)<=P.at(i+1)){
      y++;
    }
    if(P.at(i-1)>=P.at(i)&&P.at(i)>=P.at(i+1)){
      y++;
    }
  }
  cout<<y<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

from collections import deque
q = deque([0, es[0][0]])
st = set([0, es[0][0]])

while 1:
    a,b = q[0],q[-1]
    for to in es[a]:
        if to in st: continue
        st.add(to)
        q.appendleft(to)
        break
    else:
        for to in es[b]:
            if to in st: continue
            st.add(to)
            q.append(to)
            break
        else:
            print(len(q))
            print(*[a+1 for a in q])
            exit()

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll dp[12][100010];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    FILL0(dp);

    int N, M, X;
    cin >> N >> M >> X;

    int C[N];
    int A[N][M];
    rep(i, N)
    {
        cin >> C[i];
        rep(j, M)
        {
            cin >> A[i][j];
        }
    }

    vector<ll> minmin;

    for(int bit=0; bit<(1<<N); bit++)
    {
        int und[M]={0};
        for(int i=0; i<N; i++)
        {
            if((1<<i)&bit)
            {
                rep(j, M)
                {
                    und[j]+=A[i][j];
                }
            }
        }
        bool flag=true;
        rep(i, M)
        {
            if(und[i]<X)
            {
                flag=false;
                break;
            }
        }
        if(flag)
        {
            minmin.push_back(bit);
        }
    }

    ll ans = 1e15;

    rep(j, minmin.size())
    {
        ll bit = minmin[j];
        ll money=0;
        rep(i, N)
        {
            if(bit&(1<<i))
            {
                money+=C[i];
            }
        }

        if(money<ans)
        {
            ans=money;
        }
    }

    if(ans!=1e15)
    {
        cout << ans << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    
    

 

 

    return 0;
}



Measured memory_bytes: 13032
#include <stdio.h>
int main()
{
    int a, b, c, d, e, g;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    e = a*b;
    g = c*d;
    if(e>g)
    {
        printf("%d", e);
    }
    else
    {
        printf("%d", g);
    }
    return 0;
}

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

const int MOD = 1000000007;
const int64_t INF = 1LL << 60;

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

    rep(i, s.size())
    {
        if (i % 2 == 0) {
            cout << s.at(i);
        }
    }

    cout << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x, y, t = 1;
        while(true){
            x = sc.nextInt();
            y = sc.nextInt();
            if(x == 0 && y ==0) break;
            else{
                if(x < y) System.out.println(x+" "+y);
                else System.out.println(y+" "+x);
            }
        }
    }
}


Measured memory_bytes: 34464
N=int(input())
A0 = list(map(int, input().split()))
A1 = list(map(int, input().split()))
ans = 0
for i in range(N-1):
  A0[i+1] += A0[i]
for i in range(N-1,0,-1):
  A1[i-1] += A1[i]
for i in range(N):
  ans = max(ans, A0[i] + A1[i])
print(ans)



Measured memory_bytes: 3060
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string S;
  ll wcnt=0,lcnt=0;
  cin >> S;
  REP(i,S.size()){
    if(i % 2 == 0){
      if(S[i] == 'p'){
        lcnt++;
      }else{
        continue;
      }
    }else{
      if(S[i] == 'p'){
        continue;
      }else{
        wcnt++;
      }
    }
  }
  cout << wcnt - lcnt  << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



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

const int K = 18, N = 55;

vector<int> vv[1<<K];

long long C[N][N];

void pre() {
    for (int i=0; i<N; i++) C[i][0] = 1;
    for (int i=1; i<N; i++)
        for (int j=1; j<N; j++)
            C[i][j] = C[i-1][j-1] + C[i-1][j];

    for (int i=0; i<N; i++)
        for (int j=1; j<N; j++)
            C[i][j] += C[i][j-1];
}

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


    int n, k, S, T;
    cin>>n>>k>>S>>T;

    if ( (S&T) != S) {
        cout<<0<<endl;
        return 0;
    }

    for (int i=0; i<n; i++) {
        int x;
        cin>>x;

        if ((x&S) != S) continue;
        if ((x&T) != x) continue;

        for (int mask = 0; mask < (1<<K); mask++) {
            if ((mask&S) != S) continue;
            if ((mask&T) != mask) continue;
            int ans = x & (~mask);
            vv[mask].push_back(ans);
        }
    }

    long long ans = 0;
    for (int mask = 0; mask < (1<<K); mask++) {
        if ((mask&S) != S) continue;
        if ((mask&T) != mask) continue;
        sort(vv[mask].begin(), vv[mask].end());

        long long ww = 0;
        while (vv[mask].size()) {
            int last = vv[mask].back();
            int cnt = 0;
            while (vv[mask].size() && vv[mask].back() == last)  cnt++, vv[mask].pop_back();

            ww += C[cnt][k]-1;
        }

        int bc = __builtin_popcount(mask);
        if (bc%2)   ans += ww;
        else        ans -= ww;
    }
    cout<<abs(ans)<<endl;
}


Measured memory_bytes: 81480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
	ll i,j,k,n,s=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		if(i%5!=0 && i%3!=0) s=s+i;
	}
	cout<<s;
    
}

Measured memory_bytes: 3624
use std::io::stdin;

fn read_ints() -> Vec<i32>{
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map(|token| token.parse().unwrap()).collect()
}


fn main() {
    let values = read_ints();
    let max_value = values.iter().max_by_key(|&x| x).unwrap();
    let min_value = values.iter().min_by_key(|&x| x).unwrap();

    let answer = max_value - min_value;

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

Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod=1e9+7;

int main(){
  int a, b, q;
  cin >> a >> b >> q;
  vector<ll> s(a), t(b), x(q);
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
  rep(i,q) cin >> x[i];
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  rep(i,q){
    auto s1=lower_bound(s.begin(),s.end(),x[i]);
    auto s2=s1;
    if(s2!=s.begin())
      s1--;
    auto t1=lower_bound(t.begin(),t.end(),x[i]);
    auto t2=t1;
    if(t1!=t.begin())
      t1--;
    ll ans=1e11;
    if(s2!=s.begin() && t2!=t.begin())
      ans = min(ans, x[i]-min(*s1,*t1));
    if(s2!=s.begin() && t2!=t.end())
      ans = min(ans, *t2-*s1+min(*t2-x[i],x[i]-*s1));
    if(s2!=s.end() && t2!=t.begin())
      ans = min(ans, *s2-*t1+min(*s2-x[i],x[i]-*t1));
    if(s2!=s.end() && t2!=t.end())
      ans = min(ans, max(*s2,*t2)-x[i]);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 3001;
ll dp[MAX][MAX];

int main() {
    
    for (ll i=0;i<MAX;i++){
        dp[0][i] = 0;
        dp[i][0] = 0;
    }
    string s,t;
    cin >> s >> t;
    for (ll i=1;i<=s.length();i++){
        for (ll j=1;j<=t.length();j++){
            if(s[i-1] == t[j-1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }else{
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
    }
//    for (ll i=1;i<=s.length();i++){
//        for (ll j=1;j<=t.length();j++){
//            cout << i << " " << j << " " <<  dp[i][j] << endl;
//        }
//    }
    ll p,q;
    p = s.length();
    q = t.length();
    string ans = "";
    while(dp[p][q]){
        while(dp[p-1][q] == dp[p][q]){
            p--;
        }
        while(dp[p][q-1] == dp[p][q]){
            q--;
        }
        ans += s[p-1];
        p--;
        q--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

}




Measured memory_bytes: 70656
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

string S;
vector<set<int>> posLists;

int main()
{
    int H, W, N; cin >> H >> W >> N;
    int sr, sc; cin >> sr >> sc; --sr; --sc;
    vector<char> S(N), T(N);
    for (auto &Si : S) cin >> Si;
    for (auto &Ti : T) cin >> Ti;
    // より条件が厳しくなる後ろ側から後手の"勝確エリア"を計算していく:O(N)
    int aL = 0, aR = W - 1, aU = 0, aD = H - 1;
    for (int i = N - 1; i >= 0; --i)
    {
        // 後手について，なるべく勝確エリアを広げるように行動する
        switch (T[i])
        {
        case 'L':
            aR = min(aR + 1, W - 1);
            break;
        case 'R':
            aL = max(aL - 1, 0);
            break;
        case 'U':
            aD = min(aD + 1, H - 1);
            break;
        case 'D':
            aU = max(aU - 1, 0);
            break;
        }
        // 先手について，なるべく勝確エリアを狭めるように行動する
        switch (S[i])
        {
        case 'L':
            ++aL;
            break;
        case 'R':
            --aR;
            break;
        case 'U':
            ++aU;
            break;
        case 'D':
            --aD;
            break;
        }
        // もし途中で勝確エリアがつぶれることがあれば，必ず先手の勝利
        if (aL > aR || aU > aD)
        {
            cout << "NO" << endl;
            return 0;
        }
    }
    // 初期位置が勝確エリアにあるかどうか判定
    if (aL <= sc && sc <= aR && aU <= sr && sr <= aD)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;

    if(k%2 == 1) {
        ll m = n/k;
        out(m*m*m);   
    }
    else if(k%2 == 0) {
        ll p = k/2;
        ll ans = 0;
        for(ll a = p; a <= n; a += p) {
            ans += ((a+n)/k - a/k)*((a+n)/k - a/k);
        }
        out(ans);
    }

    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 2000000000;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

typedef tuple<string, int, int> TUP;

bool tuplesort(const TUP &right, const TUP &left)
{
    if (get<0>(right) != get<0>(left))
    {
        return get<0>(left) < get<0>(right);
    }
    if (get<1>(left) != get<1>(right))
    {
        return get<1>(left) > get<1>(right);
    }
    return get<2>(left) < get<2>(right);
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll nCr(int n, int r)
{
    ll ans = 1;
    for (int i = n; i > n - r; --i)
    {
        ans = ans * i;
    }
    for (int i = 1; i < r + 1; ++i)
    {
        ans = ans / i;
    }
    return ans;
}

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


Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n;
    cin >> n;
    set<pair<int, int>> pairs;
    int sum = 0;
    FOR(i, 1, n) {
        int a;
        cin >> a;
        pair<int, int> p;
        if(i<a) p = make_pair(i, a);
        else p = make_pair(a, i);
        if(pairs.find(p) != pairs.end()) sum += 1;
        else pairs.insert(p);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4992
A,B,M = map(int,input().split())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
amin = min(ai)
bmin = min(bi)
ans = amin+bmin
for num in range(M):
    xi,yi,ci=map(int,input().split())
    a = ai[xi-1]
    b = bi[yi-1]
    new = a+b-ci
    if ans>new:
        ans=new
print(ans)

Measured memory_bytes: 70380
N = int(input())
h = list(map(int,input().split()))
rh = list(reversed(h))
for i in range(N-1):
    if rh[i] < rh[i+1]:
        if rh[i+1]-rh[i] >= 2:
            print('No')
            exit(0)
        elif rh[i+1]-rh[i] == 1:
            rh[i+1] -= 1
else:
    print('Yes')

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,i,j;
	scanf("%d",&n);
	int p[n][3],c;
	for(i=0;i<n;i++){
		scanf("%d %d %d",&p[i][0],&p[i][1],&p[i][2]);
		sort(p[i],p[i]+3);
	}
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			if(p[i][0]!=0&&p[i][0]==p[j][0]&&p[i][1]==p[j][1]&&p[i][2]==p[j][2]) p[j][0]=0;
		}
	}
	c=0;
	for(i=1;i<n;i++){ 
		if(p[i][0]==0) c++;
	}
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 3316
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
W = line[0] * 1
H = line[1] * 1 
x = line[2] * 1
y = line[3] * 1
console.log(W * H / 2, W / 2 == x && H / 2 == y ? 1 : 0)


Measured memory_bytes: 7628
#include <stdio.h>

int main()
{
   int N;
   scanf("%d", &N);

   int A[N];
   for (int i = 0; i < N; i++)
      scanf("%d", &A[i]);

   for (int i = 0; i < N; i++) {
      printf("%d", A[i]);

      if (i == N-1)
         printf("\n");
      else 
         printf(" ");
   }
   int v;
   int j;

   for (int i = 1; i <= N-1; i++) {
     v = A[i];
     j = i - 1;
     while (j >= 0 && A[j] > v) {
        A[j+1] = A[j];
        j--;
     }
     A[j+1] = v;

     for (int k = 0; k < N; k++) {
        printf("%d", A[k]);

        if (k == N-1)
           printf("\n");
        else
           printf(" ");
     }
   }

   return 0;
}


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

int main(){
    string S,T;
    cin >> S >> T;
    int count = 0;
    rep(i,3){
        if (S[i] == T[i]){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

long div2(long x){
  long count = 0;
  while(x % 2 == 0){
    x /= 2;
    count++;
  }
  return count;
}

int main(){
  int n;
  cin >> n;
  long a;
  long answer = 0;
  rep(i,n){
    cin >> a;
    answer += div2(a);
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

type MyScanner struct {
	sc *bufio.Scanner
}

type MyWriter struct {
	stdout io.Writer
}

type MyPut interface{}

func getScanner(fp io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 500001), 500000)
	return sc
}

func getHugeScanner(fp io.Reader, size int) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, size), size)
	return sc
}

func (mysc *MyScanner)String() string {
	mysc.sc.Scan()
	return mysc.sc.Text()
}

func (mysc *MyScanner)Int() int {
	i, _ := strconv.Atoi(mysc.String())
	return i
}

func (mysc *MyScanner)Int64() int64 {
	i, _ := strconv.ParseInt(mysc.String(), 10, 64)
	return i
}

func (mysc *MyScanner)Float64() float64 {
	i, _ := strconv.ParseFloat(mysc.String(), 64)
	return i
}

func (mw MyWriter)Puts(v MyPut) {
	_, _ = fmt.Fprintf(mw.stdout, "%v\n", v)
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := MyScanner{getScanner(stdin)}
	mw := MyWriter{stdout}

	n := sc.Int()

	b := make([]int, n - 1)

	for i := 0; i < n - 1; i++ {
		b[i] = sc.Int()
	}

	ans := b[0]

	for i := 1; i < n - 1; i++ {
		if b[i - 1] < b[i] {
			ans += b[i - 1]
		} else {
			ans += b[i]
		}
	}

	ans += b[n - 2]

	mw.Puts(ans)
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] A = new long[N];
		for(int i = 0 ; i < N ; i++){
			A[i] = sc.nextLong();
		}

		sc.close();

		long[] B = new long[N];
		B[0] = A[0];
		for(int i = 1 ; i < N ; i++){
			B[i] = B[i-1] + A[i];
		}

		long snk = 0;
		long arg = 0;
		long ans =0;
		for(int i = 0 ; i < N-1 ; i++){
			snk = B[i];
			arg = B[N-1]-B[i];

			if(i==0){
				ans = Math.abs(snk-arg);
			}
			else{
				ans = Math.min(ans, Math.abs(snk-arg));
			}
		}
		System.out.println(ans);


	}

}

Measured memory_bytes: 76880
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int arr[4][4];
int main(){
    //~ freopen("file.in", "r", stdin);
    for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			scanf("%d",&arr[i][j]);
	for(int a1=0;a1<=100;a1++){
		vector<int>a,b;
		a.pb(a1);
		b.pb(arr[0][0]-a[0]);
		b.pb(arr[0][1]-a[0]);
		b.pb(arr[0][2]-a[0]);
		a.pb(arr[1][0]-b[0]);
		a.pb(arr[2][0]-b[0]);
		int ok=1,mn=INF;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				if(a[i]+b[j]!=arr[i][j])
					ok=0;
		for(int i=0;i<3;i++)
			umin(mn,min(a[i],b[i]));
		if(mn>=0 and ok){
			puts("Yes");
			//~ for(int i=0;i<3;i++)
				//~ cout<<a[i];
			//~ for(int j=0;j<3;j++)
				//~ cout<<b[j];
			//~ cout<<endl;	
			return 0;
		}	
	}		
	puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int max = 0;
	int min = 0;
	int choose = 0;
	int color[8] = {0, 0, 0, 0, 0, 0, 0, 0};
	int n;
	scanf("%d", &n);
	int rate[n];
	for(int i = 0; i < n; i++){
		scanf("%d", rate+i);
	}
	for(int i = 0; i < n; i++){
		if(rate[i] < 400){
			color[0]++;
		}
		else if(rate[i] < 800){
			color[1]++;
		}
		else if(rate[i] < 1200){
			color[2]++;
		}
		else if(rate[i] < 1600){
			color[3]++;
		}
		else if(rate[i] < 2000){
			color[4]++;
		}
		else if(rate[i] < 2400){
			color[5]++;
		}
		else if(rate[i] < 2800){
			color[6]++;
		}
		else if(rate[i] < 3200){
			color[7]++;
		}
		else{
			choose++;
		}
	}
#ifdef DEBUG
for(int i = 0; i < 8; i++){
printf("color[%d] %d\n", i, color[i]);
}
#endif
	for(int i = 0; i < 8; i++){
		if(color[i] > 0){
			max++;
			min++;
		}
	}
	max += choose;
	if(min == 0 && choose > 0){
		min++;
	}
	printf("%d %d\n", min, max);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	int n, t; long double a;
	cin >> n >> t >> a;
	vector<int>h(n);
	vector<long double>w(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		w[i] = t - h[i] * 0.006;
	}
	long double tmp = 5000;
	int tmpi = -1;
	for (int i = 0; i < n; i++) {
		if (fabs(a - w[i]) < tmp) {
			tmp = fabs(a - w[i]);
			tmpi = i;
		}
	}
	cout << tmpi+1 << endl;
}


Measured memory_bytes: 256
//  Friendly NUKE is ready!!
#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define dbg(x) cout<<#x<<": "<<x<<endl
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mo 1000000007
#define inf 1e18
#define eps 0.0000000001
#define stp setprecision(20)
#define all(v) v.begin(),v.end()
#define endl '\n'
using namespace std;
//mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
 
#define N  int(2e5)+10
ll h[3][N] , dp[3][N] ;
int main()
{    SPEED;
      int n,k;
      cin>>n;
      loop(i,1,n+1)cin>>h[0][i]>>h[1][i]>>h[2][i];
       
      loop(i,1,n+1){
      	
      	 dp[0][i] = max(dp[1][i-1]+h[0][i],dp[2][i-1]+h[0][i]) ;
      	 dp[1][i] = max(dp[0][i-1]+h[1][i],dp[2][i-1]+h[1][i]) ;
      	 dp[2][i] = max(dp[1][i-1]+h[2][i],dp[0][i-1]+h[2][i]) ;
      }      
      cout<<max(dp[0][n],max(dp[1][n],dp[2][n])) ;
}

Measured memory_bytes: 8300
#include<stdio.h>
int main(){
  int n,r[10],e,g,k,p,np,nm,m,i,j;
  while(scanf("%d %d %d",&n,&g,&e),n||g||e){
    double a,dp[55][5000]={0};
    int mv[80]={0};
    int d[80]={0};
    for(i=0;i<n;i++)scanf("%d",&r[i]);
    for(i=0;i<e;i++){
      scanf("%d %d %d",&m,&k,&p);
      if(k==1)mv[m]=p;
      if(k==2)d[m]=p;
      if(k==3)d[m]=-p;
    }
    dp[0][0]=1;
    for(i=0;i<g;i++){//printf("a\n");
      for(j=0;j<5000;j++){
	for(k=0;k<n;k++){//printf("a\n");
	  nm=j+d[i+r[k]];
	  np=i+r[k]+mv[i+r[k]];
	  if(nm<0)nm=0;
	  if(np>g)np=g;
	  dp[np][nm]+=dp[i][j]/n;
	  //if(dp[np][nm])printf("%f:%d:%d\n",dp[np][nm],np,nm);
	}
      }//printf("b\n");
    }
    for(i=a=0;i<5000;i++)a+=dp[g][i]*i;
    printf("%d\n",(int)a);
  }
  return 0;
}
  

Measured memory_bytes: 2756
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    int a[N];
    rep(i, N){
        a[i] = 0;
    }
    rep(i, M){
        int c, b;
        cin >> c >> b;
        c--;b--;
        a[c] += 1;
        a[b] += 1;
    }

    rep(i, N){
        if (a[i] % 2 == 1) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 640
n,m = map(int,input().split())
 
p = []
for i in range(m):
  x = str(i)+' '+input()
  p.append(list(map(int,x.split())))

p.sort(key=lambda x:x[2]) 
c = [1]*(n+1)
for i in range(m):
  p[i][2] = c[p[i][1]]
  c[p[i][1]] += 1
p.sort()
for i in range(m):
  print( str(p[i][1]).zfill(6) + str(p[i][2]).zfill(6))

Measured memory_bytes: 31892
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()



int main()
{
  int n, m;
  cin >> n >> m;
  int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }

use std::cmp;
use std::collections::VecDeque;

fn adjacent4(x: usize, y: usize, h: usize, w: usize) -> Vec<(usize, usize)> {
    [(-1, 0), (1, 0), (0, -1), (0, 1)]
        .iter()
        .filter_map(|&(dx, dy)| {
            let nx = x as isize + dx;
            let ny = y as isize + dy;
            if 0 <= nx && nx < h as isize && 0 <= ny && ny < w as isize {
                Some((nx as usize, ny as usize))
            } else {
                None
            }
        })
        .collect()
}

fn bfs(h: usize, w: usize, maze: &Vec<Vec<char>>, s: (usize, usize)) -> usize {
    let mut q = VecDeque::new();
    q.push_back((s.0, s.1, 0));

    let mut visited = vec![vec![false; maze[0].len()]; maze.len()];
    visited[s.0][s.1] = true;

    let mut max_d = 0;
    while let Some((x, y, d)) = q.pop_front() {
        max_d = cmp::max(max_d, d);
        for (nx, ny) in adjacent4(x, y, h, w) {
            if maze[nx][ny] == '.' && !visited[nx][ny] {
                visited[nx][ny] = true;
                q.push_back((nx, ny, d + 1));
            }
        }
    }

    max_d
}

fn main() {
    input! {
        h: usize,
        w: usize,
        maze: [chars; h],
    }

    let mut ans = 0;
    for x in 0..h {
        for y in 0..w {
            if maze[x][y] == '#' {
                continue;
            }

            ans = cmp::max(ans, bfs(h, w, &maze, (x, y)));
        }
    }

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


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
#define M 1000

void push(int *, int);
int pop(int *);

int top=0;

int main(){
  int a, b, S[M];
  char s[N];

  while(scanf("%s", s)!=EOF){
    if(s[0] == '+'){
      a = pop(S);
      b = pop(S);
      push(S, a + b);
    }
    else if(s[0] == '-'){
      a = pop(S);
      b = pop(S);
      push(S, b - a);
    }
    else if(s[0] == '*'){
      a = pop(S);
      b = pop(S);
      push(S, a * b);
    }
    else{
      push(S, atoi(s));
    }
  }

  printf("%d\n", pop(S));

  return 0;
}

void push(int *S, int a){
  S[++top] = a;
}

int pop(int *S){
  top--;
  return S[top+1];
}



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

int main() {
  string s;
  cin >> s;
  string a;
  cin >> a;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != a[i]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
	return 0;
}


Measured memory_bytes: 3616
S = {}
S["a"] = raw_input()
S["b"] = raw_input()
S["c"] = raw_input()
p = "a"
while True:
  if S[p]=="":
    print p.upper()
    break
  else:
    np = S[p][0]
    S[p] = S[p][1:]
    p = np

Measured memory_bytes: 2568
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

int N;
bool is_prime[100005];
int suffix_sum[100005];


void sieve(int end) {

    memset(is_prime, 1, sizeof(bool) * (end + 1));
    // for(int i = 0; i <= end; i++) {
    // 	is_prime[i] = true;
    // }
    is_prime[0] = false;
    is_prime[1] = false;
    
    for(int i = 2; i <= end; i++) {
	if (not is_prime[i]) {
	    continue;
	}

	for(int j = i + i; j < end; j += i) {
	    is_prime[j] = false;
	}
    }
    
}

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

    sieve(100000);
    
    int cnt = 0;
    for(int i = 1; i <= 100000; i++) {
    	if (i % 2 && is_prime[i] && is_prime[(i+1)/2]) {
    	    cnt++;
    	}
    	suffix_sum[i] = cnt;
    }

    cin >> N;
    int l, r;
    for(int i = 0; i < N; i++) {
    	cin >> l >> r;
    	cout << suffix_sum[r] - suffix_sum[l-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<queue>

using namespace std;
class Team{
public:
	int id;
	int time;
	Team(int _id,int _time){
		id=_id;time=_time;
	}
	bool operator < (const Team &o) const{
		return time > o.time;
	}
};
typedef priority_queue<Team> PQ;
int n,c,m,s;
int main(){
	while(cin>>n&&n){
		PQ pq;
		for(int i=0;i<n;i++){
			int sum=0;
			cin>>c;
			for(int j=0;j<4;j++){
				cin>>m>>s;
				sum+=(m*60) + s;
			}

			pq.push(Team(c,sum));
		}
		cout<<pq.top().id<<endl;pq.pop();
		cout<<pq.top().id<<endl;pq.pop();
		while(pq.size()>2){
			pq.pop();
		}
		cout<<pq.top().id<<endl;pq.pop();
	}
	return 0;
}

Measured memory_bytes: 936
//#pragma region ALL(include define etc)
#include <iostream>   // swap(a, b)
#include <string>
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <vector>     // vec.push_back(a) vec.pop_back()
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <functional> // sort(a, a + N, greater<型>());
#include <math.h>
#define int long long
#define ll long long
using namespace std;
//#pragma endregion

signed main()
{
	//int x;

	int N;
	int n;
	//int m;
	//int k;
	//string s;
	//string t;
	//int m1, m2;
	//int a, b, c, k;

	//int k, d;
	int all = 0;
	//int a, b;
	//int a[30000] = { 0 };

	int b = 0;

	//int box[10000] = { 0 };

	bool flag = true;

	//string str;

	cin >> N;

	n = N % 10;

	//cout << endl;
	//for (int i = 0; i <= (k - 2); i++)
	//{
	//	b = a[b];
	//	//cout << b << "\n";
	//}
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
	{
		cout << "hon\n";
	}
	else if (n == 0 || n == 1 || n == 6 || n == 8)
	{
		cout << "pon\n";
	}
	else
	{
		cout << "bon\n";
	}
	
	//cout << b << "\n";

	/*if (flag == true)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}*/
}


Measured memory_bytes: 3636
h,w=map(int,input().split())
a=[input() for i in range(h)]
ans="Yes"
for i in range(h):
    for j in range(w):
        if i==0:
            if j==0:
                if a[i][j]=="#":
                    if h>=2:
                        if not a[i+1][j]=="#":
                            if w>=2:
                                if not a[i][j+1]=="#":
                                    ans="No"
                    elif w>=2:
                        if not a[i][j+1]=="#":
                            ans="No"
                    else:
                        ans="No"
                                    
            elif j==(w-1):
                if a[i][j]=="#":
                    if a[i][j-1]!="#":
                        if h==1:
                            ans="No"
                        else:
                            if a[i+1][j]!="#":
                                ans="No"
            else:
                if a[i][j]=="#":
                    if a[i][j-1]!="#" and a[i][j+1]!="#":
                        if h==1:
                            ans="No"
                        else:
                            if a[i+1][j]!="#":
                                ans="No"
            
        elif i==(h-1):
            if j==0:
                if a[i][j]=="#":
                    if a[i-1][j]!="#":
                        if w==1:
                            ans="No"
                        else:
                            if a[i][j+1]!="#":
                                ans="No"
                
            elif j==(w-1):
                if a[i][j]=="#":
                    if a[i][j-1]!="#" and a[i-1][j]!="#":
                        ans="No"
                
            else:
                if a[i][j]=="#":
                    if a[i][j-1]!="#" and a[i-1][j]!="#" and a[i][j+1]!="#":
                        ans="No"
                
        else:
            if j==0:
                if a[i][j]=="#":
                    if a[i-1][j]!="#" and a[i+1][j]!="#":
                        if w==1:
                            ans="No"
                        else:
                            if a[i][j+1]!="#":
                                ans="No"
            elif j==(w-1):
                if a[i][j]=="#":
                    if a[i][j-1]!="#" and a[i-1][j]!="#" and a[i+1][j]!="#":
                        ans="No"
            else:
                if a[i][j]=="#":
                    if a[i][j-1]!="#" and a[i][j+1]!="#" and a[i-1][j]!="#" and a[i+1][j]!="#":
                        ans="No"

print(ans)

Measured memory_bytes: 9340
#include<stdio.h>
#include<string.h>
#define max(a,b) (((a)>(b))?(a):(b))

int main(void){
	int i,j,k;
	int q,tmp;
	int xLen,yLen;
	int dp[1001][1001]={0};
	char x[1001],y[1001];
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%s",x);
		scanf("%s",y);
		xLen=strlen(x);
		yLen=strlen(y);
		for(j=1;j<xLen+1;j++){
			for(k=1;k<yLen+1;k++){
				if(x[j-1]==y[k-1]){
					dp[j][k]=dp[j-1][k-1]+1;	
				}else{
					dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
				}
			}
		}
		printf("%d\n",dp[xLen][yLen]);
	}
	return 0;
}			

Measured memory_bytes: 4524
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: usize,
        w: usize,
    }

    if s <= w {
        println!("unsafe");
    } else {
        println!("safe");
    }
}


Measured memory_bytes: 2096