akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n;
cin>>n;
char a[n];
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
int cnt =1;

for(int i=1;i<n;i++)
{
    if(a[i]!=a[i-1]) cnt++;
}
if(cnt==3) cout<<"Three";
else cout<<"Four";
return 0;
}


Measured memory_bytes: 256
#coding: utf-8

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

ans = 0
lenS = len(S)
for i in T:
    idxL = 0
    idxR = lenS
    mch = -1
    while idxL < idxR:
        idxM = (idxL + idxR) // 2
        if S[idxM] == i:
            mch = idxM
            break
        elif S[idxM] < i:
            idxL = idxM + 1
        else:
            idxR = idxM
    if mch >= 0:
        ans += 1

print(ans)



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

#define int long long

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

  if(a % 2 && b % 2 && c % 2) {
    if(a > b) swap(a, b);
    if(b > c) swap(b, c);
    cout << a * b << endl;
  } else {
    cout << 0 << endl;
  }

  return (0);
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        int T = cin.nextInt();
        for (int i = 0; i < T; i++)
        {
            Console.WriteLine(calc2());
        }
    }

    int calc2()
    {
        int N = cin.nextInt();
        long[] A = cin.ArrayLong(N);
        string S = cin.next();
        int cnt = S.Length - 1;

        List<long> LA = new List<long>();

        while (cnt >= 0)
        {
            List<long> LB = new List<long>();

            while (cnt >= 0 && S[cnt] == '0') { LA.Add(A[cnt--]); }
            while (cnt >= 0 && S[cnt] == '1') { LB.Add(A[cnt--]); }

            LA.Sort();
            LA.Reverse();
            for (int i = 0; i < LA.Count; i++)
            {
                for (int j = i + 1; j < LA.Count; j++)
                {
                    long next = LA[i] ^ LA[j];
                    if (next < LA[j]) LA[j] = next;
                }
                LA.Sort();
                LA.Reverse();
            }

            foreach (var b in LB)
            {
                long now = b;
                foreach (var a in LA)
                {
                    if (now > (now ^ a)) now ^= a;
                }
                if (now != 0) return 1;
            }
        }

        return 0;
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 31516
import sys
import os
import itertools
import numpy as np
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    N=int(input())
    while N>0:
        N-=1000

    print(abs(N))

if __name__ == '__main__':
    main()


Measured memory_bytes: 27120
#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 <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int gcd(int x, int y) { return x%y ? gcd(y, x%y) : y; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  /*
    M = max(A[0]〜A[N-1])
    G = gcd(A[0]〜A[N-1])
    Kが既にあるor作れるための条件（必要条件）は
    ・K <= M
      計算で作れるのはM未満の数だけ
    ・K%G == 0
      Aの中に存在するのはGの倍数だけ
      また、どんな計算をしてもGの倍数しか作れない
    上記を満たしている場合、必ずKが既にあるor作れること（十分性）を証明する
    まず、A[0]〜A[N-1]について互減法をすることでGを作ることができる
    また、 (M-G)-G のような操作は M-G*2 と言い換えられる
    MはGの倍数なので、MからGを任意の回数引くことでM未満の全てのGの倍数を作れる（Mは既に存在する）
  */
  int g = A[0], mx = 0;
  rep(i, N) {
    g = gcd(g, A[i]);
    chmax(mx, A[i]);
  }
  if (K<=mx && !(K%g))
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
if m >= 2:
  if n < 2:
    print(int(m*(m-1)/2))
    quit()
  else:
    print(int(m*(m-1)/2 + n*(n-1)/2))
    quit()
    
if m < 2:
  if n < 2:
    print(0)
  else:
    print(int(n*(n-1)/2))
  


Measured memory_bytes: 3060
//
// Created by yijiezhu on 12/20/16.
//

#include <bitset>
#include <iostream>
using namespace std;

int n, ball[10];

bool valid(int iter) {
    int left = 0, right = 0;
    auto bs = bitset<10>(iter);
    for (int i = 0; i < 10; i++) {
        if (bs[i]) {
            if (ball[i] < left) return false;
            left = ball[i];
        } else {
            if (ball[i] < right) return false;
            right = ball[i];
        }
    }
    return true;
}

int main() {
    cin >> n;
    while (n-- > 0) {
        for (int i = 0; i < 10; i++) {
            cin >> ball[i];
        }
        bool found = false;
        for (int iter = 0; iter < (1 << 10); iter++) {
            if (valid(iter)) {
                cout << "YES\n";
                found = true;
                break;
            }
        }
        if (!found) cout << "NO\n";
    }
}

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

int inverse(int a){
	return power(a, p - 2);
}

int comb(int n, int k){
	if(k == 0){
		return 1;
	}
	else{
		return MOD(MOD(n * inverse(k)) * comb(n - 1, k - 1));
	}
}

signed main(){
	int N, M, i, j, ans = 1;
	scanf("%lld%lld", &N, &M);
	for(i = 2; M > 1; i++){
		for(j = 0; M % i == 0; j++, M /= i){}
		ans = MOD(ans * comb(j + N - 1, j));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

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

    int ans = 1;
    REP(i,1,n) {
        if (s[i-1]==s[i]) continue;
        ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf 1e18

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

ll m,n;
ll a,b;
ll p,q;

char mat[1005][1005];
ll cost[1005][1005];
bool visited[1005][1005];

void dfs(ll x,ll y,ll c,vector<pair<pll,ll>> &ar)
{
    visited[x][y]=true;
    ar.pb({{x,y},c});

    cost[x][y]=c;

    if(x-1>=0 && mat[x-1][y]=='.' && !visited[x-1][y])
    {
        dfs(x-1,y,c,ar);
    }

    if(x+1<n && mat[x+1][y]=='.' && !visited[x+1][y])
    {
        dfs(x+1,y,c,ar);
    }

    if(y-1>=0 && mat[x][y-1]=='.' && !visited[x][y-1])
    {
        dfs(x,y-1,c,ar);
    }

    if(y+1<m && mat[x][y+1]=='.' && !visited[x][y+1])
    {
        dfs(x,y+1,c,ar);
    }

    // for(ll i=x-2;i<=x+2;i++)
    // {
    //     for(ll j=y-2;j<=y+2;j++)
    //     {
    //         if(i>=0 && i<n && j>=0 && j<m)
    //         {
    //             if(!visited[i][j] && mat[i][j]=='.')
    //             {
    //                 dfs(i,j,c+1);
    //             }
    //         }
    //     }
    // }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    

    ll test=1;
    // cin>>test;
    while(test--)
    {
        cin>>n>>m;
        cin>>a>>b;
        cin>>p>>q;

        a--,b--;
        p--,q--;

        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<m;j++)
            {
                cin>>mat[i][j];
                cost[i][j]=-1;
                visited[i][j]=false;
            }
        }

        vector<pair<pll,ll>> ar;

        dfs(a,b,0,ar);

        for(ll it=0;it<ar.size();it++)
        {
            ll x=ar[it].ff.ff;
            ll y=ar[it].ff.ss;
            ll c=ar[it].ss;

            for(ll i=x-2;i<=x+2;i++)
            {
                for(ll j=y-2;j<=y+2;j++)
                {
                    if(i>=0 && i<n && j>=0 && j<m)
                    {
                        if(!visited[i][j] && mat[i][j]=='.')
                        {
                            dfs(i,j,c+1,ar);
                        }
                    }
                }
            }
        }

        cout<<cost[p][q];
    }
}

Measured memory_bytes: 25200
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] sunuke = new int[N];
        for(int k=0;k<K;k++){
            int d = sc.nextInt();
            for(int i=0;i<d;i++){
                sunuke[sc.nextInt()-1]++;
            }
        }
        for(int i=0;i<N;i++){
            if(sunuke[i]==0)ans++;
        }
        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 46188
#include<bits/stdc++.h>
#define io freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define lli long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fi(a,n) for(lli i=a; i<=n; i++)
const int M=1000000007;
using namespace std;
const int mxn=2e5;
int n,m,p[mxn];
vector<int> adj[mxn],ans;
int dp[mxn];
int vis[mxn],act[mxn];



int main() {
	// io
fast
string s;
cin>>s;
lli n=s.size();
if(s[n-1]=='s')s+="es";
else s+='s';
cout<<s<<endl;

}


Measured memory_bytes: 8348
#include <iostream>
#include <vector>
using namespace std;
template <class T> inline bool chmin(T& a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
}

int INF = 1e9;
int main() {
  int N;
  cin >> N;
  vector<int> l2r(N, 0);
  vector<int> r2l(N, 0);
  string S;
  cin >> S;
  { // 先頭からお尻への黒の累積和
    int count = 0;
    for(int i = 0; i < S.size(); ++i) {
      if(S[i] == '#') {
        count++;
      }
      l2r[i] = count;
    }
  }
  { // お尻から先頭への白の累積和
    int count = 0;
    for(int i = S.size() - 1; i >= 0; --i) {
      if(S[i] == '.') {
        count++;
      }
      r2l[i] = count;
    }
  }
  int ans = INF;
  for(int i = 0; i < S.size(); ++i) {
    if(0 <= i - 1 && i + 1 < S.size()) {
      chmin(ans, l2r[i - 1] + r2l[i + 1]);
    } else if(i - 1 < 0) {
      chmin(ans, r2l[i + 1]);
    } else if(i + 1 >= S.size()) {
      chmin(ans, l2r[i - 1]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
//#define INF 9223372036854775807
const ll mod=998244353;



int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll a,b;
    cin>>a>>b;
    cout<<a*b;

    return 0;
}



Measured memory_bytes: 3636
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

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

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define ld             long double
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[N], n, m, k;

void solve()
{
	int i, j;
	char c; cin >> c;
	c++;
	cout << c;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



	cout << setprecision(9) << fixed;
	clock_t z = clock();
	solve();
	cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

	return 0;
}

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

const i64 INF = 1e18;

struct SegmentTree
{
  i64 size = 1;
  vector<i64> node;

  SegmentTree(i64 n)
  {
    while (size < n)
      size *= 2;
    node.resize(2 * size - 1, INF);
  }

  void update(i64 x, i64 val)
  {
    x += (size - 1);
    node[x] = val;
    while (x > 0)
    {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }

  i64 query(i64 a, i64 b, i64 k = 0, i64 l = 0, i64 r = -1)
  {
    if (r < 0)
      r = size;
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= b)
      return node[k];

    i64 vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    i64 vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};

int main()
{
  i64 n, q;
  cin >> n >> q;
  vector<i64> s(n), t(n), x(n);
  vector<pair<pair<i64, i64>, i64>> c;
  for (i64 i = 0; i < n; i++)
  {
    cin >> s[i] >> t[i] >> x[i];
    c.push_back({{s[i] - x[i], 0}, i});
    c.push_back({{t[i] - x[i], 1}, i});
  }
  vector<i64> qu(q);
  for (i64 i = 0; i < q; i++)
  {
    cin >> qu[i];
    c.push_back({{qu[i], 2}, 0});
  }
  sort(c.begin(), c.end());
  i64 size = c.size();
  SegmentTree seg(n);
  for (i64 i = 0; i < size; i++)
  {
    if (c[i].first.second == 0)
      seg.update(c[i].second, x[c[i].second]);
    else if (c[i].first.second == 1)
      seg.update(c[i].second, INF);
    else
    {
      i64 ans = seg.query(0, n);
      if (ans == INF)
        cout << -1 << endl;
      else
        cout << ans << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 33000
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4

int main(){
  int N; cin >> N;
  vector<int> A(N), P(N), Q(N);
  rep(i,N) A[i] = i+1;
  rep(i,N) cin >> P[i];
  rep(i,N) cin >> Q[i];

  bool samep = true, sameq = true;
  int cnt=0,a=0,b=0;
  do{
    samep = true;
    sameq = true;
    rep(i,N) {
      if (A[i]!=P[i]) samep = false;
      if (A[i]!=Q[i]) sameq = false;
    }

    if (samep) a = cnt;
    if (sameq) b = cnt;
    
    cnt++;
  }while(next_permutation(all(A)));

  cout << abs(a-b) << endl;
  //cout << a << " " << b << endl;

  return 0;
}

Measured memory_bytes: 256
import sys

N = int(input())

A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)

sum = 0
for i in range(1, N+2):
    sum += abs(A[i]-A[i-1])

for i in range(1, N+1):
    print(sum+abs(A[i-1]-A[i+1])-abs(A[i-1]-A[i])-abs(A[i]-A[i+1]))


Measured memory_bytes: 20556
from collections import deque
def main():
    n, x, y = map(int, input().split())
    g = dict()
    for i in range(n):
        if i == 0:
            g[i] = [i+1]
        elif i == n-1:
            g[i] = [i-1]
        else:
            g[i] = [i-1, i+1]
    g[x-1].append(y-1)
    g[y-1].append(x-1)
    distance = [0]*(n-1)
# 1番ノードから各ノードへの最短距離を求めていく.
    for i in range(n):
        queue = deque()
        visited = [0]*n
    # まず処理される予定のノードが格納されているqueueに最初のノードを格納する
        queue.append(i)
        while queue:
            target = queue.popleft()
            for j in g[target]:
                if visited[j] == 0 or visited[j] > visited[target] + 1:
                    visited[j] = visited[target] + 1
                    queue.append(j)
        for k, a in enumerate(visited):
            if k > i:
                if a >= 1:
                    distance[a-1] += 1
    # print(f"{i}番ノードからの各ノードへの最短距離は{visited}である")
    for l in distance:
        print(l)

if __name__ == "__main__":
    main()

Measured memory_bytes: 47196
N,D = gets.split.map(&:to_i)
X = N.times.map { gets.split.map(&:to_i) }

# 配列から2個の要素を選んだときの組み合わせ数
ans = X.combination(2).count do |(y, z)|
  dist = Math.sqrt((0..(D-1)).reduce(0) { |s,i| s += (y[i]-z[i]) ** 2 } )
  dist - dist.to_i == 0
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

vint dx = {1,0};
vint dy = {0,1};

int h, w;
vector<string> field;
vvint ct;

void dfs(int x, int y) {
    rep(i,2) {
        int n_x = x + dx[i];
        int n_y = y + dy[i];
        if ((n_x >= 1 && n_x <= w &&  n_y <= h) || (x == w && y == h)) {
            if (field[y][x] != field[n_y][n_x]) {
                if (chmin(ct[n_y][n_x],ct[y][x]+1)) dfs(n_x,n_y);
            } else {
                if (chmin(ct[n_y][n_x],ct[y][x])) dfs(n_x,n_y);
            }
        }
    }
}

int main() {
    cin >> h >> w;
    field.assign(h+2,string(w+2,'.'));
    ct.assign(h+2,vint(w+2,inf));
    ct[1][0] = 0;
    REP(i,h+1) {
        string s; cin >> s;
        REP(j,w+1) field[i][j] = s[j-1];
    }
    dfs(0,1);
    int ans = ct[h+1][w] / 2;
    cout << ans << endl;
}

Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
#define ll long long
#include <cstdint>

int main() {
	string c[2];
	cin >> c[0] >> c[1];
	reverse(c[1].begin(), c[1].end());
	if (c[0] == c[1])cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int H1,M1,H2,M2,K;
	cin>>H1>>M1>>H2>>M2>>K;
	
	int T1 = H1*60+M1;
	int T2 = H2*60+M2;
	
	cout<<(T2-T1)-K<<endl;
	
	return 0;
}

Measured memory_bytes: 3624
import Data.List

toInt :: String -> Int
toInt = read :: String -> Int

solve :: Int -> String
solve n
  | m == 3 = "bon"
  | m == 0 || m == 1 || m == 6 || m == 8 = "pon"
  | otherwise = "hon"
    where
      m = mod n 10

main = do
  n <- toInt <$> getLine
  putStrLn $ solve n


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

int main()
{	
	char s[3];
	for(int i=0;i<3;i++)
		cin >> s[i];
	sort(s, s+3);
	if (s[0]=='a'&&s[1]=='b'&&s[2]=='c')cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  int n;
  F f;
  G g;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int n_,F f,G g,T ti):
    f(f),g(g),ti(ti){
    init(n_);
  }
  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i>0;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void update(int k,E a){
    k+=n;
    dat[k]=g(dat[k],a);
    while(k>0){
      k>>=1;
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
    }
  }
  inline T query(int a,int b){
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
  int find(int a,int b,function<bool(T)> &check,int k,int l,int r){
    if(!check(dat[k])||r<=a||b<=l) return -1;
    if(k>=n) return k-n;
    int m=(l+r)>>1;
    int vl=find(a,b,check,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(a,b,check,(k<<1)|1,m,r);
  }
  int find(int a,int b,function<bool(T)> &check){
    return find(a,b,check,1,0,n);
  }
};
//END CUT HERE
signed AOJ_DSL2A(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,q;
  cin>>n>>q;
  SegmentTree<int,int> rmq(n,
			   [](int a,int b){return min(a,b);},
			   [](int a,int b){++a;return b;},
			   INT_MAX);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<rmq.query(x,y+1)<<endl;
    else rmq.update(x,y);
  }
  return 0;
}
/*
  verified on 2018/03/04
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
*/

signed ARC038_C(){
  Int n;
  cin>>n;
  vector<Int> c(n,0),a(n,0);
  for(Int i=1;i<n;i++) cin>>c[i]>>a[i];
  
  SegmentTree<Int, Int>::F f=[](Int a,Int b){return min(a,b);};
  SegmentTree<Int, Int>::G g=[](Int a,Int b){return max(a,b);};
  SegmentTree<Int, Int> seg(n,f,g,-1);
  
  vector<Int> dp(n);
  dp[0]=0;
  seg.update(0,0);
  for(Int i=1;i<n;i++){
    function<bool(Int)> check=[&](Int x){return x<i-c[i];};
    dp[i]=seg.find(0,n,check);
    seg.update(dp[i],i);
  }
  
  Int ans=0;
  for(Int i=1;i<n;i++)
    if(a[i]&1) ans^=dp[i];
  
  cout<<(ans?"First":"Second")<<endl;
  return 0;
}

/*
  verified on 2018/01/30
  https://beta.atcoder.jp/contests/arc038/tasks/arc038_c
*/

signed main(){
  AOJ_DSL2A();
  //ARC038_C();
  return 0;
}



Measured memory_bytes: 3900
s = int(input())
arr = list(map(int, input().split()))

ans = 0

for i in range(1,s):
    if arr[i] < arr[i-1]:
        #print((arr[i-1]-arr[i]))
        ans += (arr[i-1]-arr[i])
        arr[i] = arr[i-1]

print(ans)   

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

const int id = INT_MAX;

int op(int l, int r) {
	return min(l, r);
}

struct node {
	int pos, val, all;
	node *lch, *rch;
	node(int p, int v)
		: pos(p), val(v), all(v), lch(nullptr), rch(nullptr) {}
};

void update_up(node* t) {
	t->all = op(op((t->lch ? t->lch->all : id), t->val), (t->rch ? t->rch->all : id));
}

node *update(node* t, int p, int val, int lb, int ub) {
	if (!t) return new node(p, val);
	if (t->pos == p) {
		t->val = val;
		update_up(t);
		return t;
	}
	int m = (lb + ub) >> 1;
	if (p < m) {
		t->lch = update(t->lch, p, val, lb, m);
	}
	else {
		t->rch = update(t->rch, p, val, m, ub);
	}
	update_up(t);
	return t;
}

int find(node* t, int l, int r, int lb, int ub) {
	if (!t || r <= lb || ub <= l) return id;
	if (l <= lb && ub <= r) return t->all;
	int m = (lb + ub) >> 1;
	return op(op(find(t->lch, l, r, lb, m), find(t->rch, l, r, m, ub)), l <= t->pos && t->pos < r ? t->val : id);
}

int main()
{
	int n, q;
	scanf("%d%d", &n, &q);
	node *seg = nullptr;
	while (q--) {
		int com, x, y;
		scanf("%d%d%d", &com, &x, &y);
		if (com == 0) {
			seg = update(seg, x, y, 0, n);
		}
		else {
			printf("%d\n", find(seg, x, y + 1, 0, n));
		}
	}
	return 0;
}



Measured memory_bytes: 5488
import collections
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = set(ar)
cr = collections.Counter(ar)
n = len(br) - b
dr = []
for v in cr.values():
    dr.append(v)
dr.sort()
count = 0
for i in range(n):
    count += dr[i]
print(count)

Measured memory_bytes: 45356
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;

        static void SolveA()
        {
            var o = ReadAndParseIntArr();
            int r = o[0];
            int g = o[1];
            int b = o[2];
            int n = r * 100 + g * 10 + b;
            string ans = n % 4 == 0 ? "YES" : "NO";
            Console.WriteLine(ans);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 11092
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
struct UnionFind{
    vector<int> parent;
    vector<int> s;
 
    UnionFind(int n){
        parent.resize(n);
        s.resize(n, 1);
        for(int i = 0; i < n; i++) parent[i] = i;
    }
 
    int root(int node){
        if(parent[node] == node){
            return node;
        } else {
            return parent[node] = root(parent[node]);
        }
    }
 
    void unite(int x, int y){
        int rootx = root(x);
        int rooty = root(y);
        if(rootx == rooty) return;
        if(s[rootx] < s[rooty]) swap(rootx, rooty);
        s[rootx] += s[rooty];
        parent[rooty] = rootx;
    }
 
    bool isSame(int x, int y){
        return root(x) == root(y);
    }
 
    int size(int x){
        return s[root(x)];
    }
};
int main(void){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> ab(m);
    for(int i = 0; i < m; i++){
        cin >> ab[i].first >> ab[i].second;
        ab[i].first--;
        ab[i].second--;
    }

    reverse(all(ab));

    vector<ll> ans;
    UnionFind uf(n);
    //ll original = nCr(n, 2LL);
    ll tmp = nCr(n, 2LL);
    ans.push_back(tmp);
    for(int i = 0; i < m; i++){
        if(!uf.isSame(ab[i].first, ab[i].second)){
            tmp = max(0LL, tmp - uf.size(ab[i].first) * uf.size(ab[i].second));
        }

        if(i != m - 1) ans.push_back(tmp);
        uf.unite(ab[i].first, ab[i].second);
    }

    reverse(all(ans));
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << endl;
    }

}   

Measured memory_bytes: 6900
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#define maxn 2020
using namespace std;
int n,k,q,a[maxn];
priority_queue<int>q1,q2;
struct node{int v,id;}b[maxn];
inline bool cmp(node a,node b){return a.v<b.v;}
void init(){
	scanf("%d%d%d",&n,&k,&q);
	for(int i=1;i<=n;++i){
	    scanf("%d",&a[i]);
	    b[i].v=a[i];b[i].id=i;
    }
	sort(b+1,b+n+1,cmp);
}
inline void extend(int l,int r){
	if(l>r)return;
	int s=0;
	while(r-l+1-s>=k){
		int u=q1.top();q1.pop();
		q2.push(u);++s;
	}
}
void solve(){
	int ans=2e9;
	for(int t=1;t<=n;++t){
		int la=1;
		while(!q2.empty())q2.pop();
		for(int i=1;i<=n;++i){
			if(a[i])q1.push(-a[i]);
			if(!a[i]||i==n){
				if(i==n&&a[i])++i;
				extend(la,i-1);
				la=i+1;
				while(!q1.empty())q1.pop();
			}
		}
		if(q2.size()<q)break;
		int mn=2e9,mx=0;
		for(int i=1;i<=q;++i){
			int u=-q2.top();q2.pop();
			mn=min(mn,u),mx=max(mx,u);
		}
		ans=min(mx-mn,ans);
		a[b[t].id]=0;
		while(b[t+1].v==b[t].v)++t,a[b[t].id]=0;
	}
	printf("%d\n",ans);
}
int main(){
	init();
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lint long long int
using namespace std;
int main() 
{
	lint x=0;
	lint ch=100;
	lint ans=0;
	cin>>x;
	while(1)
	{
		ch+=ch*0.01;
		ans++;
		if(ch>=x) break;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define int long long 

int go(int * a,int *b,int ti,int tw,int**output)
{
	if(ti==0||tw<=0)
	return 0;
	if(output[ti][tw]!=-1)
	return output[ti][tw];
  if(b[0]>tw)
return go(a+1,b+1,ti-1,tw,output);
	int ans=go(a+1,b+1,ti-1,tw-b[0],output)+a[0];
	int ans1=go(a+1,b+1,ti-1,tw,output);
	output[ti][tw] =max(ans1,ans);
	return output[ti][tw];
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int ti,tw;
   cin >> ti >> tw;
   int a[ti];
   int b[ti];
   for(int i=0;i<ti;++i)
   {
	   int v,w;
	   cin >> w >> v;
	   a[i]=v;
	   b[i]=w;
	   
   }
   int ** output=new int*[ti+1];
   for(int i=0;i<=ti;i++)
   {
	   output[i]=new int[tw+1];
	   for(int j=0;j<=tw;j++)
	   output[i][j]=-1;
   }
   int ans=go(a,b,ti,tw,output);
   cout << ans <<endl;
   
}



Measured memory_bytes: 79488
N = int(input())
Bn =  list(map(int,input().split(' ')))

output_list = []

for i in reversed(range(N)):
    current_sum = 0
    target_num = i+1
    target_num_idx = 0
    for j in range((N)//(target_num)):
        target_num_idx = target_num_idx + target_num
        current_sum += Bn[target_num_idx -1]
    if current_sum % 2 != Bn[i]:
        if Bn[i] == 1:
            Bn[i] = 0
        else:
            Bn[i] = 1
    if Bn[i] == 1:
        output_list.append(target_num)
print(len(output_list))
output_list.reverse()
print(' '.join(map(str,output_list)))

Measured memory_bytes: 18468
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#include <random>
#include <map>
#pragma warning(disable : 4996)

#define MAX_N 100


int main(void) {
	char s[1024];
	scanf("%s", &s[0]);
	s[5] = ' ';
	s[13] = ' ';
	printf("%s", s);
	return 0;
}


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

using namespace std;

int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	int n  , ans = 0 ;
	string input ;  
	set<string> s ; 
	cin >> n ;
	for(int i = 0 ; i < n ; i ++)
	{
		cin >> input ; 
		if(!s.count(input))
		{
			++ans ;
			s.insert(input); 
		}
	}
	cout << ans ; 

}



Measured memory_bytes: 19292
#include<iostream>

int main()
{
	int a = 1;
	int h;
	int w;

	while (a){
		std::cin >> h;
		std::cin >> w;

		if (h == 0 && w == 0){
			break;
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				std::cout << '#';
			}
			std::cout << '\n';
		}
		std::cout << '\n';
	}

}


Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static List<int>[] li;
	static bool[] b;
	static long[] h;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int n=s[0],m=n-1;
		li=new List<int>[n+1];
		b=new bool[n+1];
		h=new long[n];
		for(int i=1;i<=n;i++){li[i]=new List<int>();}
		for(int i=0;i<m;i++){
			int[] e=sc.Ia;
			li[e[0]].Add(e[1]);
			li[e[1]].Add(e[0]);
		}
		for(int i = 0;i<s[1];i++) {
			int[] e=sc.Ia;
			h[e[0]-1]+=e[1];
		}
		Fu(1,0);
		Console.WriteLine("{0}",String.Join(" ",h));
	}
	static void Fu(int a,long g){
		b[a]=true;
		long p=h[a-1];
		h[a-1]+=g;
		g+=p;
		for(int i=0;i<li[a].Count;i++){
			if(!b[li[a][i]]){
				Fu(li[a][i],g);
			}
		}
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 68228
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  string s, t;
  cin >> s >> t;
  map<char, vector<ll> > c2v;
  for (ll i = 0; i < (ll)s.size(); ++i) {
    char c = s[i];
    c2v[c].push_back(i);
  }

  for (auto c : t) {
    if (c2v[c].size() == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  
  char c = t[0];
  ll prev = c2v[c][0];
  ll cnt = 0;
  for (ll i = 1; i < (ll)t.size(); ++i) {
    char c = t[i];
    vector<ll> &v = c2v[c];
    auto it = upper_bound(v.begin(), v.end(), prev);
    if (it != v.end()) {
      prev = *it;
    } else {
      ++cnt;
      prev = v[0];
    }
  }

  ll ans = cnt * (ll)s.size() + prev + 1;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1664
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

struct Stack {
    int t = 0, S[10000];
    void push(int n) {
        S[t + 1] = n;
        t++;
    }
    void pop() { t--; }
    int top() { return S[t]; }
};

int main() {
    Stack st;
    string s;
    getline(cin, s);

    istringstream iss(s);
    string word;
    while (iss >> word) {
        if (word[0] == '+') {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a + b);
        } else if (word[0] == '-') {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(b - a);
        } else if (word[0] == '*') {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a * b);
        } else {
            int a = stoi(word);
            st.push(a);
        }
    }

    cout << st.top() << endl;
}


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


int main(){
    ll n;   cin >> n;
    vector<pair<ll, ll>> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i).first;
        a.at(i).second = i;
    }
    sort(a.begin(), a.end(), greater<pair<ll,ll>>());
    vector<vector<ll>> dp(n+1, vector<ll>(n+1));

    for(int i=0; i<n; i++){
        for(int j=0; j<i+1; j++){
            dp[i+1][j+1] = max(dp[i+1][j+1], 
                dp[i][j]+abs(j-a.at(i).second)*a.at(i).first);
            
            dp[i+1][j] = max(dp[i+1][j],
                dp[i][j]+abs(n-i+j-1-a.at(i).second)*a.at(i).first);

        }
    }
    ll ans= 0;
    for(int i=0; i<=n; i++)
        ans = max(ans, dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 34684
while(True):
    H, W = map(int, input().split())
    if(H == W == 0):
        break
    str = "#." * (W // 2 + 1)
    for i in range(H):
        if(i % 2 == 0):
            print(str[:W:])
        else:
            print(str[1:W + 1:])
    print()

Measured memory_bytes: 7684
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
#define int long long
const int inf = 999999999999999999;
typedef long long ll;
typedef long double ld;
string a, b;
int dp[1001][1001];
signed main() {
	cin >> a >> b;
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < b.size(); j++)
			dp[i][j] = inf;
	for (int i = 0; i <= a.size(); i++)
		dp[i][0] = i;
	for (int i = 0; i <= b.size(); i++)
		dp[0][i] = i;
	for (int i = 1; i <= a.size(); i++) {
		for (int j = 1; j <= b.size(); j++) {
			int cost = 1;
			if (a[i-1] == b[j-1])
				cost = 0;
			dp[i][j] = min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + cost));
		}
	}
	cout << dp[a.size()][b.size()] << endl;
	getchar(); getchar();
}

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

bool vis[100001];

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

    int n, m, ac = 0, p = 0, prob;
    string s;
    cin >> n >> m;
    map<int, int> mp;
    while(m--){
    	cin >> prob >> s;
    	if(s == "WA")
    		mp[prob]++;
    	else{
    		if(!vis[prob]){
    			ac++;
    			p += mp[prob];
    		}
    		vis[prob] = 1;
    	}
    }
    cout << ac << " " << p << '\n';
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
  int s,s1,s2,s3;
  cin >> s;
  s1 = s / 100;
  s2 = (s % 100) / 10;
  s3 = s % 10;
  cout << s1 + s2 + s3 << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int k,s;
    ll ans=0;
    cin >> k >> s;
    rep(i,k+1){
        if(i>s) break;
        rep(j,k+1){
            if(i+j>s) break;
            if((s-i-j)<=k) ++ans;
        }
    }

    cout << ans << "\n";
    return 0;
}   

Measured memory_bytes: 3568
N, L = map(int, input().split())

sum = int(L*N + N*(N+1)/2 - N)
if (L <= 0) & (L + N - 1 >=0):
    print(sum)
elif L > 0:
    print(sum-L)
elif L + N - 1 < 0:
    print(sum-(L+N-1))

Measured memory_bytes: 3060
local mod = 1000000007
local function badd(x, y)
  return (x + y) % mod
end
local n = io.read("*n")
local t = {}
local colors = {}
local pos = {}
for i = 1, n do
  local c = io.read("*n")
  t[i] = c
  if not colors[c] then colors[c] = {} end
  table.insert(colors[c], i)
  pos[i] = #colors[c]
end
local cnt = {}
for i = 1, n do
  cnt[i] = 1
end
for i = n - 1, 1, -1 do
  local c, p = t[i], pos[i]
  if p < #colors[c] and i + 1 < colors[c][p + 1] then
    cnt[i] = badd(cnt[i + 1], cnt[colors[c][p + 1]])
  else
    cnt[i] = cnt[i + 1]
  end
end
print(cnt[1])


Measured memory_bytes: 37080
n, a, b = list(map(int, input().split()))
MAX = 510000
MOD = 1000000007


fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
com = [0 for i in range(MAX)]
power = [2 for i in range(32)]

for i in range(1, 32) :
  power[i] = power[i-1] * power[i-1] % MOD

def cominit() :
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  com[1] = n
  for i in range(2, MAX) :
    fac[i] = fac[i-1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * int(MOD / i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD
    com[i] = com[i-1] * (n-(i-1)) * inv[i] % MOD
    
  return fac, finv, inv, com


def two_n_mod(n) :
  ans = 1
  temp_i = 0
  temp = [0 for i in range(32)]
    
  for i in range(32) :
    temp[i] += n%2
    n = int(n/2)
  ans = (2**n) % MOD
  for i in range(32) :
    ans = ans * (power[i] ** temp[i]) % MOD
  return ans

temp = cominit()
##print(two_n_mod(1000000000))
##print(2**n % MOD)
print((two_n_mod(n) - 1 - com[a] - com[b]) % MOD)



Measured memory_bytes: 83888
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <iomanip>
#define FI first
#define SE second
#define EB emplace_back
#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 1100000000
#define LLINF 1100000000000000000LL
#define Decimal fixed << setprecision(20)
#define ALL(c) c.begin(),c.end()
#define SHOWVEC(v, sz) for(int i = 0; i < sz; i++) cerr << v[i] << ' '; cerr << endl;
#define SHOWX(x) cerr << #x << ": " << x << endl;
#define SHOWP(p) cerr << "[" << p.first << ',' << p.second << "]";

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main()
{
  string s, t;
  cin >> s >> t;
  int ans = 0;
  REP(i, s.size()) ans += s[i] == t[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import Data.List

ans x =
  let a = sum $ take 3 $ reverse $ sort $ take 4 x
      b = sum $ take 1 $ reverse $ sort $ drop 4 x
  in
    a + b

main = do
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = ans i
  print o
      

Measured memory_bytes: 3616
n = int(input())
s = input()
count = 0
state = 0
for i in range(len(s)):
    if s[i] == "A":
        state = 1
        continue
    if s[i] == "B":
        if state == 1:
            state = 2
            continue
        state = 0
        continue
    if s[i] == "C":
        if state == 2:
            count += 1
        state = 0

print(count)

Measured memory_bytes: 3060