akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  int a;
  cin >> a;
  int ans = a + a*a + a*a*a;
  cout << ans << endl;
}

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

int main()
{
	int n, a[200000], ans[200000], h, t;
	cin >> n;
	h = 0;
	t = n - 1;
	
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}

	for	(int i = 0; i < n; i++){
		if (i % 2 == 0){ 
			ans[h] = a[n - i - 1];
			h++;
		}
		else {
			ans[t] = a[n - i - 1];
			t--;
		}
	}
	for (int i = 0; i < n - 1; i++){
		cout << ans[i] << " ";
	}
	cout << ans[n - 1] << endl;

	return 0;
}



Measured memory_bytes: 3712
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  b = list(map(int, readline().split()))
  a = [0]*n
  for i in range(n):
    if i == 0:
      a[0]=b[0]
    elif i == n-1:
      a[n-1] = b[n-2]
    else:
      a[i] = min(b[i-1], b[i])
  print(sum(a))
  
  
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 22624
// B - Collatz Problem
#include <bits/stdc++.h>
using namespace std;

int main(){
	int s; cin>>s;
	map<int,int> M;
	M[s]++;
	while(M[s]!=2){
		s = s%2? 3*s+1: s/2;
		M[s]++;
	}
	cout<< M.size()+1 <<endl;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int N; cin >> N;
	int codd = 0, c4 = 0, c2 = 0;
	rep(i, N) {
		int x; cin >> x;
		if (x % 4 == 0) {
			++c4;
		} else if (x % 2 == 0) {
			++c2;
		} else {
			++codd;
		}
	}
	if (c2 > 0) codd++;

	if (codd <= c4 + 1) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
    int N, i, count;
    char S[100000], T;
 
    scanf("%d", &N);
    
    scanf("%s", S);
 
    T = S[0];
 
    count++;
 
    for(i=1; i<N; i++){
        if(S[i] != T){
            T = S[i];
 
            count++;
        }
    }
 
    printf("%d\n", count);
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* {{{ */
/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)

#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
#define print(x) cout << (x) << endl
#define PB push_back
#define pb push_back
#define mp make_pair
#define FI first
#define SE second

inline int in(){int x;std::cin>>x;return x;}

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;
/*-------------------------------*/
/* }}} */ 

signed main(void)
{
  while (true){
    int n = in();
    int m;
    string change_before[n];
    string change_after[n];
  
    if (n == 0) break;

    rep(i, n) cin >> change_before[i] >> change_after[i];
    cin >> m;

    rep(i, m){
      string s;
      bool frag = true;
      cin >> s;

      rep(i, n){
        if (s == change_before[i]){
          cout << change_after[i];
          frag = false;
          break;
        }
      }
      if (frag) cout << s;
    }
    cout << endl;
  }

  return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,A,B;
    string S;
    cin >> A>>B>>N;
    if(B>N){
        ll ans = 0;
        /*REPS(i, N)
        {
            ll tmp = (A * i) / B;
            ll tmp1 = i / B;
            //cout << tmp - A * tmp1 << endl;

            
            ans = max(ans, tmp - A * tmp1);
            
        }
        cout << ans << endl;*/
        ll tmp = (A * N) / B;
        ll tmp1 = N / B;
        cout << tmp - A * tmp1 << endl;
    }

    else{
        ll tmp = (A * (B-1)) / B;
        ll tmp1 = (B-1) / B;

        //cout << "test1" << endl;
        //cout << tmp << " " << tmp1 << endl;

        cout << tmp - A * tmp1 << endl;
    }
}


Measured memory_bytes: 3652
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  getLine >>= print . solve . map read . words

solve :: [Int] -> Int
solve = (\(a, b, _) -> max a b) . foldl' go (0, 0, 0) 
  where
    go :: (Int, Int, Int) -> Int -> (Int, Int, Int)
    go (!mx, !current, !prev) h
      | prev >= h = (mx, current + 1, h)
      | otherwise = (max mx current, 0, h)


Measured memory_bytes: 33148
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
  
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M), D(M);
  vector<bool> checked(M, false);
  vector<vector<int>> edges(N);
  vector<ll> pos(N, LINF);
  rep(i,M) {
    cin >> L[i] >> R[i] >> D[i];
    L[i]--;
    R[i]--;
    edges[L[i]].push_back(i);
    edges[R[i]].push_back(i);
  }

  rep(i,N) {
    if (edges[i].size() <= 0) continue;
    queue<int> que;
    for (int e: edges[i]) {
      if (!checked[e]) que.push(e);
    }
    if (que.empty()) continue;
    pos[i] = 0;
    ll minimum = 0, maximum = 0;
    while (!que.empty()) {
      int p = que.front(); que.pop();
      checked[p] = true;
      if (pos[L[p]] < LINF && pos[R[p]] < LINF) {
        if (pos[R[p]] - pos[L[p]] != D[p]) {
          cout << "No" << endl;
          return 0;
        }
      } else if (pos[L[p]] < LINF) {
        pos[R[p]] = pos[L[p]] + D[p];
        maximum = max(maximum, pos[R[p]]);
        for (int e: edges[R[p]]) {
          if (!checked[e]) que.push(e);
        }
      } else {
        pos[L[p]] = pos[R[p]] - D[p];
        minimum = min(minimum, pos[L[p]]);
        for (int e: edges[L[p]]) {
          if (!checked[e]) que.push(e);
        }
      }
    }
    if (maximum - minimum > 1000000000) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 13452
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int era[55556];
  vector<int> prime;
  for(int i=2;i<=55555;i++){
    era[i]=i;
  }
  for(int i=2;i<=55555;i++){
    if(era[i]==-1)
      continue;
    if(era[i]%5==1)
      prime.push_back(era[i]);
    for(int j=2;j*era[i]<=55555;j++){
      era[j*era[i]]=-1;
    }
  }
  for(int i=0;i<n-1;i++)
    cout<<prime[i]<<" ";
  cout<<prime[n-1]<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vl as(n);
    cin>>as;

    vl bs(n);
    copy(rng(as), bs.begin());
    sort(rng(bs));
    map<ll, ll> mp;
    rep(i, n) mp[as[i]] = i;
    ll ans = 0;
    rep(i, n) ans += ((mp[bs[i]] - i) % 2 + 2) % 2;
    cout<<ans / 2<<endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(void){

    string s;
    cin >> s;

    int res = 0;
    for(int i = 0; i * 2 <(s.size()); i++){
        if(s.substr(0,i) == s.substr(i,i)){
            res = i * 2;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int N;
	scanf("%d",&N);
	int b[N];
	for(int i=0;i<N;i++){
		scanf("%d",&b[i]);
	}
	int max,count=0;
	int i=0;
	for(;i<N;i++){
		if(max<b[i]){
			max=b[i];
			count=i;
		}
	}

	int sec=0;
	b[count]=0;
	i=0;
	for(;i<N;i++){
		if(sec<b[i]){
			sec=b[i];
		}
	}
	i=0;
	for(;i<N;i++){
		if(i==count){
			printf("%d\n",sec);
		}else{
			printf("%d\n",max);
		}
	}

	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10,mod=998244353;
void plusle(int &a,int b){a+=b;if(a>=mod)a-=mod; return;}
void minun(int &a,int b){a-=b; if(a<0)a+=mod; return;}
int add(int a,int b) {a+=b;return a>=mod?a-mod:a;}
int sub(int a,int b) {a-=b;return a<0?a+mod:a;}
int mul(int a,int b) {return (int)((long long)a*b%mod);}
int power(int a,int b) {int res=1;while (b>0) {if (b&1) {res=mul(res,a);}a=mul(a,a);b>>=1;}return res;}

int n,r,b,g,wb,wg,wr;
char s[maxn];
int ans=1;

int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=3*n;i++){
        if(s[i]=='R'){
            if(wr>0){
                ans=mul(ans,wr);
                wr--;
                continue;
            }
            if(b>0||g>0){
                ans=mul(ans,b+g);
                if(b>0){
                    b--;
                    wg++;
                }
                else if(g>0){
                    g--;
                    wb++;
                }
                continue;
            }
            r++;
        }
        if(s[i]=='G'){
            if(wg>0){
                ans=mul(ans,wg);
                wg--;
                continue;
            }
            if(r>0||b>0){
                ans=mul(ans,r+b);
                if(b>0){
                    b--;
                    wr++;
                }
                else if(r>0){
                    r--;
                    wb++;
                }
                continue;
            }
            g++;
        }
        if(s[i]=='B'){
            if(wb>0){
                ans=mul(ans,wb);
                wb--;
                continue;
            }
            if(r>0||g>0){
                ans=mul(ans,r+g);
                if(r>0){
                    r--;
                    wg++;
                }
                else if(g>0){
                    g--;
                    wr++;
                }
                continue;
            }
            b++;
        }
    }
    for(int i=1;i<=n;i++)
        ans=mul(ans,i);
    printf("%d\n",ans);
}
/*
    Good Luck
        -Lucina
*/


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);
    rep(i, n) cin >> a[i];

    rep(j, k) {
        vector<int> b(n, 0);
        rep(i, n) {
            int l = max(0, i - a[i]);
            int r = min(n - 1, i + a[i]);
            b[l]++;
            if (r + 1 < n) b[r + 1]--;
        }
        for (int i = 1; i < n; i++) b[i] += b[i - 1];

        if (a == b) break;
        a = b;
    }

    rep(i, n) {
        cout << a[i];
        if (i == n - 1)
            cout << endl;
        else
            cout << ' ';
    }

    return 0;
}


Measured memory_bytes: 4816
n=int(input())
if n!=2:
    blist=list(map(int,input().split()))
    alist=[blist[0]]
    for i in range(1,n-1):
        alist.append(min(blist[i],blist[i-1]))
    alist.append(blist[n-2])
    gokei=sum(alist)
    print(gokei)
else:
    b=int(input())
    print(int(b*2))

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
	int a, b, c, max, min, tot;
	scanf("%d %d %d", &a, &b, &c);
	tot = a + b + c;
	if(a >= b && a >= c)
	{
		max = a;
	}
	else if(b >= c && b >= a)
	{
		max = b;
	}
	else
	{
		max = c;
	}
	if(a <= b && a <= c)
	{
		min = a;
	}
	else if(b <= c && b <= a)
	{
		min = b;
	}
	else
	{
		min = c;
	}
	printf("%d %d %d\n", min, tot - max - min, max);
	
	return 0;
}


Measured memory_bytes: 2692
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long int ll;
int main(void){
    ll k ;
    cin >> k ;
    ll n ;
    cin >> n ;

    ll a[n] ;
    rep(i , n){
        cin >> a[i] ;
    }

    ll dis[n] ;
    dis[0] = (k - a[n-1])  + a[0] ;
    //cout << dis[0] << endl;
   
    rep(j , n-1){
        dis[j+1] = a[j+1]- a[j] ;
       // cout << dis[j+1] << endl; ;
    }
    
    sort(dis , dis + n) ;

    cout << k- dis[n-1] << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using Int = long long unsigned;

array<int,6> rotdice(char op,array<int,6> ar){
    array<int,6>res;
    if(op=='N'){
        res[0]=ar[1];res[1]=ar[5];res[2]=ar[2];res[3]=ar[3];res[4]=ar[0];res[5]=ar[4];
    }else if(op=='S'){
        res[0]=ar[4];res[1]=ar[0];res[2]=ar[2];res[3]=ar[3];res[4]=ar[5];res[5]=ar[1];
    }else if(op=='E'){
        res[0]=ar[3];res[1]=ar[1];res[2]=ar[0];res[3]=ar[5];res[4]=ar[4];res[5]=ar[2];
    }else{
        res[0]=ar[2];res[1]=ar[1];res[2]=ar[5];res[3]=ar[0];res[4]=ar[4];res[5]=ar[3];
    }
    return res;
}

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

    array<int,6> dice;
    for (int i = 0; i < 6; i++) cin>>dice[i];
    string ope; cin>>ope;
    for (int i = 0; i < ope.size(); i++) dice=rotdice(ope[i],dice);
    cout<<dice[0]<<'\n';
}


Measured memory_bytes: 3216
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int K, T;
    cin >> K >> T;

    vs32 a(T);
    rep (i, T)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end(), greater<int>());

    int ma = a[0];
    for (int i = 1; i < T; ++i)
    {
        ma -= a[i];
    }

    cout << (ma > 0 ? ma - 1 : 0) << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//vector<string>str;
set<string>st;
string s;
int k;
int main(){
    cin>>s;
    cin>>k;
    for(int i=0;i<s.size();i++)
            for(int j=i+1;j<=s.size() && j<i+6;j++)
                st.insert(s.substr(i,j-i));
                vector<string>str (st.begin(),st.end());
  //  for(int i=0;i<str.size();i++)
            cout<<str[k-1]<<endl;
            return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define to first
#define wgt second 

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vec;
typedef vector<vec> Graph;

Graph G(11000);
int n,d[11000];

void SPFA()
{
	bool used[11000];
	queue<int> que;
	memset(used,false,sizeof(used));
	fill(d,d+n,INT_MAX);
	d[0]=0;
	que.push(0);
	while(!que.empty())
	{
		int u=que.front();que.pop();
		for(int i=0;i<G[u].size();i++)
			if(d[G[u][i].to]>d[u]+G[u][i].wgt)
			{
				d[G[u][i].to]=d[u]+G[u][i].wgt;
				que.push(G[u][i].to);
			}
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int u,t;
		scanf("%d%d",&u,&t);
		for(int j=0;j<t;j++)
		{
			int v,w;
			scanf("%d%d",&v,&w);
			G[u].push_back(make_pair(v,w));
		}
	}
	SPFA();
	for(int i=0;i<n;i++)
		printf("%d %d\n",i,d[i]);
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;

#define MOD 1000000007

int n,m;
char b[1024][1024];
int f[1024][1024];

void add(int& x, int a){
	x+=a;
	if(x>=MOD)x-=MOD;
}

int main(){
	scanf("%d%d",&n,&m);
	fore(i,0,n)scanf("%s",b[i]);
	f[0][0]=1;
	fore(i,0,n)fore(j,0,m){
		if(b[i][j]=='#')continue;
		add(f[i+1][j],f[i][j]);
		add(f[i][j+1],f[i][j]);
	}
	printf("%d\n",f[n-1][m-1]);
	return 0;
}

Measured memory_bytes: 5376
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

type SortSlice []int

func (s SortSlice) Len() int {
        return len(s)
}

func (s SortSlice) Swap(i, j int) {
        s[i], s[j] = s[j], s[i]
}

func (s SortSlice) Less(i, j int) bool {
        return s[i] < s[j]
}

func reverseString(str string) string {
        buf := []rune(str)
        for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {
                buf[i], buf[j] = buf[j], buf[i]
        }
        return string(buf)
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()
        spl := strSprit(line)

        a := parseInt(spl[0])
        b := parseInt(spl[1])

        diff := b - a

        sum := 0
        for i := 1; i < diff; i++ {
                sum += i
        }

        fmt.Println(sum - a)

}

Measured memory_bytes: 640
import math
import copy
import sys

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# inputaList = [int(n) for n in inputa]

# inputb = input().split()
# inputbList = [int(n) for n in inputb]
#
# inputList = []
# inputNumList = []
# for i in range(a):
#     inputNum = input()
#     inputNumList = list(inputNum)
#     inputList.append(inputNumList)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

anscnt = 0
for i in range(1, a+1, 2):
    cnt = 0

    for j in range(1, i+1, 2):
        if i % j == 0 :
            cnt += 1

    if cnt == 8:
        anscnt += 1

print(int(anscnt))

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

int main() {
    int n, k, d, a, ans = 0;
    cin >> n >> k;
    int x[n] = {0};
    for(int i = 0; i < k; ++i) {
        cin >> d;
        for(int j = 0; j < d; ++j) {
            cin >> a;
            a--;
            x[a]++;
        }
    }

    for(int i = 0; i < n; ++i) {
        if(x[i] == 0) ans++;
    }
    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ll long long

void swap(ll* a, ll* b)
{
    ll t = *a;
    *a = *b;
    *b = t;
}

auto partition2(vector<ll>::iterator l,vector<ll>::iterator r){
    ll pivot = *r;
    auto i = l;
    advance(i,-1);
    for(auto j=l;j<=r-1;++j){
        if(*j<=pivot){
            ++i;
            iter_swap(i,j);
        }
    }
    iter_swap(i+1,r);
    return i+1;
}
int partition (ll array[], ll l, ll r) {
    ll pivot = array[r];
    ll i = (l - 1);

    for (ll j = l; j <= r - 1; j++) {
        if (array[j] <= pivot) {
            i++;
            swap(&array[i], &array[j]);
        }
    }
    swap(&array[i + 1], &array[r]);
    return (i + 1);
}
void quickSort2(vector<ll>::iterator l,vector<ll>::iterator r){
    if(l<r){
        auto pivot = partition2(l, r);
        quickSort2(l, pivot - 1);
        quickSort2(pivot + 1, r);
    }
}
void quickSort(ll array[], ll l, ll r) {
    if (l < r) {
        ll pivot = partition(array, l, r);
        quickSort(array, l, pivot - 1);
        quickSort(array, pivot + 1, r);
    }
}

void bubbleSort(vector<ll>::iterator first,vector<ll>::iterator last,ll c){
    ll count=0;
    for(auto i=last;i>=first;i--){
        for(auto j=first;j<=last-2;j++){
            auto k=j;
            advance(k,1);
            if(*j>*k) iter_swap(j,k);
        }
        //showArray(first, last);
        if(++count==c) break;
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll> p(a),q(b),r(c);
    REP(i,a) cin>>p[i];
    REP(j,b) cin>>q[j];
    REP(k,c) cin>>r[k]; 
    //bubbleSort(p.begin(),p.end(),x); 
    //bubbleSort(q.begin(),q.end(),y);
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());

    for(int i = a-1;i>=a-x;i--) {
        r.push_back(p[i]);
    }
    for(int i = b-1;i>=b-y;i--) {
        r.push_back(q[i]);
    } 
    sort(r.begin(),r.end());
    ll sum=0;
    for(auto t = r.end()-1;t>=r.end()-(x+y);t--)sum+=*t;
    cout << sum << endl;
    return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  if (N % 500 == 0) {
    cout << "Yes";
  } else if (N % 500 <= A) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << endl;
}

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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back

using namespace std;

typedef long long ll;

const int N = 1e6 + 5;

int main() {
	string s;
	int ans = 0, g = 0, p = 0, w = 0, l = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i ++) {
		if (s[i] == 'g') {
			if (p < g) p ++, w ++;
			else g ++;
		}
		else if (s[i] == 'p') {
			if (p < g) p ++;
			else g ++, l ++;
		}
	}
	ans = w - l;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    string s; cin>>s;
    ll a; a=s.length();
    ll r; r=0;
    ll C[a+1]; C[0]=0;
    ll memo;


    rep(i,a){
        if (s[i]=='<'){
            C[i+1]=C[i]+1;
        }
        else{
            C[i+1]=0;
        }
    
    }

    for(int k=a-1; k>=0;k--){
        if (s[k]=='>'){
            memo=C[k];
            C[k]=max(memo,C[k+1]+1);
        }
 
    
    }

    rep(i,a+1) r+=C[i];
    cout<<r<<endl;



}

Measured memory_bytes: 4740
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <list>
#include <cmath>
#include <iomanip>
#define INF 0x3f3f3f3f
#define EPS 10e-5
#define mod 1000003

const int dx[]={-1,0,0,1,0},dy[]={0,1,-1,0,0};
using namespace std;
int n,k,nmod,kl;
int dpa[1005][1005],dpb[1005][1005];
int dp[1005];

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}


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

   while(scanf("%d%d",&n,&k)){
        if(n==0&&k==0)break;
        memset(dpa,0,sizeof(dpa));
        memset(dpb,0,sizeof(dpb));
        memset(dp,0,sizeof(dp));
        int all = 0;
        if(k>=n){
            k = n-1;
            all = 2;
        }
        nmod = n * mod;

        int asum = 1;
        int bsum = 0;

        dpa[1][1] = 1;
        dpb[1][1] = 0;

        for(int i=2;i<=n;++i){
            dpa[i][1] = bsum;
            dpb[i][1] = asum;
            swap(asum,bsum);
            for(int j=2;j<=k;++j){
                dpa[i][j] = dpa[i-1][j-1];
                asum += dpa[i][j];
                asum %= nmod;
                dpb[i][j] = dpb[i-1][j-1];
                bsum += dpb[i][j];
                bsum %= nmod;
            }
        }

        for(int i=1;i<=n;++i){
            for(int j=1;j<=k;++j){
                dp[i] += dpb[i][j];
                dp[i] %= nmod;
            }
        }

        for(int i=1;i<=n;++i){
            for(int j=1;j<k;++j){
                dpb[i][j+1] += dpb[i][j];
                dpb[i][j+1] %= nmod;
            }
        }

        for(int i=1;i<=n;++i){
            for(int p = 1;p<=k&&p<=i;++p){
                dp[i] += dpb[i-p][k-p];
                dp[i] %= nmod;
            }
        }

        long long cnt = 0;

        for(int i=0;i<n;++i){
            cnt += dp[gcd(n,i)];
            cnt %= nmod;
        }

        printf("%lld\n",(2*cnt/n+all)%mod);
    }
    return 0;
}



Measured memory_bytes: 11140
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
using namespace std;

int main()
{
	string s;
	vector<int> n;
	int ans = 0;
	bool t = false;
	cin >> s;
	
	for (int i = 0;i < s.size();i++)
	{
		if (s[i] == '0')
		{
			n.push_back(0);
		}
		else
		{
			n.push_back(1);
		}
	}

	while (true)
	{
		if (n.size() <= 1)
		{
			break;
		}

		for (int i = 0;i < n.size()-1;i++)
		{
			if (n[i] + n[i + 1] == 1)
			{
				ans += 2;
				n.erase(n.begin() + i);
				n.erase(n.begin() + i);
				t = true;
				break;
			}
		}

		if (t == false)
		{
			break;
		}

		t = false;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1020
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 29996224275833
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
// int mI(int a, int m)  {return power(a, m - 2, m);}
// vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},{1,1},{1,-1},{-1,1},{-1,-1}};



int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    fo(i, n)
            cin >>
        v[i];
    fo(i, n)
        v[i]--;
    map<int, int> m;
    int val = 0;
    vector<int> ans;
    while(m[val]==0){
        m[val] = 1;
        ans.pb(val);
        val = v[val];
    }
    int in = 0;
    fo(i,ans.size()){
        if(ans[i]==val)
            in = i;
    }
    //deb(in);
    if(k<ans.size()){
        cout << ans[k]+1;
    }
    else{
        k -=(ans.size()-1);
        int remain = k % (ans.size()-in);
        if(remain==0){
            remain = ans.size()-in;
        }
        cout << ans[in+remain - 1]+1;
    }

}
    


Measured memory_bytes: 18540
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

int main(){
	ll N,H;cin>>N>>H;
	vector<ll>a(N);
	vector<ll>b(N);
	vector<pair<ll,ll>>v;
	rep(i,N){
		cin>>a[i]>>b[i];
		v.push_back(make_pair(a[i],1));
		v.push_back(make_pair(b[i],0));
	}
	
	sort(v.begin(),v.end(),greater<pair<ll,ll>>());
	
	ll index=0;
	ll ans=0;
	while(H>0){
		auto p=v[index];
		ll num=p.first;
		if(p.second==1){
			//inf
			ans+=(H+num-1)/num;
			H=0;
		}else{
			ans++;
			H-=num;
		}
		index++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 8048
#include<iostream>
#define ll long long
#include<limits>
#include<algorithm>
#include<vector>
#include<math.h>
#include <iomanip>  
#include <deque> 
#include<string> 
#include<string.h>
#define V vector
#define UM unordered_map
#define IT iterator
#define F first
#define S second
#define PQ priority_queue
#define tc(t) long long t; cin >> t; while(t--)
#include<unordered_map>
#include<utility>
#define _I ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD = 1e9 + 7;
const ll INF = INT_MAX;
const ll _INF= INT_MIN;
using namespace std;


int main()
{ 
  _I

int k,a,b;
cin>>k>>a>>b;
bool flag=false;

while(a<=b)
{
  if(a%k==0)
   {
     cout<<"OK";
     flag=true;
     break;
   }
  a++;
}

 if(flag==false)
  cout<<"NG";
 
 return 0;
}


Measured memory_bytes: 3128
N = gets.to_i
array=gets.chomp.split(" ").map(&:to_i)
x2=0.0
x1=0.0
array.each do |a|
    x2 += 1.0
    x1 -= 2*a
end
x = (x1/x2/-2.0).round
puts array.inject(0) {|result,a| result + (x-a)**2 }


Measured memory_bytes: 1916
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception{
        int d,ans;
        try (Scanner sc = new Scanner(System.in)){
            while(sc.hasNextInt()){
                d = sc.nextInt();
                ans = 0;
                for(int p=0;p<600;p+=d){
                    ans += d*p*p;
                }
                System.out.println(ans);
            }
        }
    }
}


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

int main(){
    int n;
    string s,t;
    cin >> n >> s >> t;
    for(int i=0; i<n; i++){
        if(s.substr(i, n-i) == t.substr(0, n-i)){
            cout << n+i << endl;
            return 0;
        }
    }
    cout << 2*n << endl;
    return 0;
}


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

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int h = Integer.parseInt(sc.next());
            int w = Integer.parseInt(sc.next());
            
            if(h==0 && w==0)break;
            
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    System.out.print("#");
                }
                System.out.println("");
            }
            System.out.println("");
        }
    }

}



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

int main(){
	string s;
	cin >> s;
	ll res = s.length()/2, l = s.length()-res, r = res-1;
	char c = s[res];
	while (res<s.length()) {
		res++;
		l--;
		r++;
		if (!(s[l] == c && s[r] == c)) {
			res--;
			break;
		}
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define vi vector <int>
#define endl "\n"
#define f(n) for(int i=0;i<n;i++)
#define vvi vector <vector<int> >
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>=b;i--)
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define gcd __gcd
#define init(i,k) memset(i,k,sizeof i)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define setBits(x) __builtin_popcountll(x)
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define N 100005
#define mod 1000000007
int dp[3001][3001];
vi v(N);
int fun(int i,int j,int n)
{
	if(i>j)
	{
		return 0;
	}
	int r=i+n-1-j;
	if(dp[i][j]!=-1)
	{
		return dp[i][j];
	}
	if(r%2==0)
	{
		dp[i][j]=max((v[i]+fun(i+1,j,n)),(v[j]+fun(i,j-1,n)));
	}
	else
	{
		dp[i][j]=min(fun(i+1,j,n),fun(i,j-1,n));
	}
	return dp[i][j];
}
void solve()
{
	int n;
	cin>>n;
	int sum=0;
	f(n)
	{
		cin>>v[i];
		sum+=v[i];
	}
	int x=fun(0,n-1,n-1);
	int y=sum-x;
	cout<<y-x<<endl;
	return ;

}

signed main()
{
    int t=1;
    //cin>>t;
    for(int i=0;i<3001;i++)
    {
    	for(int j=0;j<3001;j++)
    	{
    		dp[i][j]=-1;
    	}
    }
    for(int i=1;i<=t;i++)
    {
    	//cout<<"Case #"<<i<<": ";
    	solve();
    	//cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 74412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    sort(all(a));
    vector<ll> s(n+1, 0);
    rep (i, n) {
        s[i+1] = s[i] + a[i];
    }
    int ans = 1;
    rep (i, n-1) {
        if (s[n - 1 - i] * 2 >= a[n - 1 - i]) {
            ans++;
        } else {
            break;
        }
    }
    cout << ans << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    cout << a[n-1]-a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
 
#define all(v) v.begin(),v.end()
#define test() int t;cin>>t;while(t--) 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define pb push_back
const int mod = 998244353;
const ll INF = -(ll)1e10;

int main()
{
    string s;
    cin>>s;
    int l = s.length();
    string a = "es", b = "s";
    if(s[l-1]=='s')
        s.append(a);
    else
        s.append(b);
    cout<<s<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
int w, h, lim;
char c[10][10];

void nul(int y, int x, char col){
	char tmp = c[y][x];
	c[y][x] = col;
	rep(d, 4){
		int ny = y + dy[d], nx = x + dx[d];
		if(0 <= ny && ny < h && 0 <= nx && nx < w && c[ny][nx] == tmp)
		nul(ny, nx, col);
	}
}
bool rec(int step){
	bool ok = 1;
	rep(i, h) rep(j, w) if(c[i][j] != c[0][0]) ok = 0;
	if(ok) return 1;
	
	if(step < lim){
		char p[10][10];
		rep(it, 3){
			if("RGB"[it] == c[0][0]) continue;
			
			rep(i, h) rep(j, w) p[i][j] = c[i][j];
			nul(0, 0, "RGB"[it]);
			if(rec(step + 1)) return 1;
			rep(i, h) rep(j, w) c[i][j] = p[i][j];
		}
	}
	return 0;
}

int main(){
	while(cin >> w >> h, h){
		rep(i, h) rep(j, w) cin >> c[i][j];
		for(lim = 0; lim < 20; lim++){
			if(rec(0)) break;
		}
		cout << lim << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main()
{
    int n;
    int p;
    int d1, d2;
    int i, j;

    scanf("%d", &n);
    while (n != 0) {
        int maxp = 0;
        int maxd = 0;

        for (i = 0; i < n; i++) {
            scanf("%d %d %d", &p, &d1, &d2);

            if (maxd < d1 + d2) {
                maxd = d1 + d2;
                maxp = p;
            }
        }

        printf("%d %d\n", maxp, maxd);
        scanf("%d", &n);
    }
    
    return 0;
}



Measured memory_bytes: 2104
N, X = gets.split.map(&:to_i)

A = [1]
P = [1]

(0..N).each do |i|
  A[i + 1] = A[i] * 2 + 3
  P[i + 1] = P[i] * 2 + 1
end

def dfs(n, x)
  if n == 0
    x <= 0 ? 0 : 1
  elsif x <= 1 + A[n - 1]
    dfs(n - 1, x - 1)
  else
    P[n - 1] + 1 + dfs(n - 1, x - 2 - A[n - 1])
  end
end

puts dfs(N, X)

Measured memory_bytes: 1788
H, W = map(int, input().split())
A = [input() for _ in range(H)]

MOD = 10 ** 9 + 7

dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            continue
        if i < 1 or A[i-1][j] == '#':
            pass
        else:
            dp[i][j] += dp[i-1][j]
        if j < 1 or A[i][j-1] == '#':
            pass
        else:
            dp[i][j] += dp[i][j-1]
        dp[i][j] %= MOD

print(dp[H-1][W-1])


Measured memory_bytes: 53616
# Aizu Problem 0242: Input Candidates

import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    n = int(input())
    if n == 0:
        break
    text = []
    count = {}
    for _ in range(n):
        for word in input().split():
            count[word] = count.get(word, 0) + 1
    char = input().strip()
    out = []
    for key, value in sorted(sorted(count.items()), key=lambda x: -x[1]):
        if key[0] == char:
            out.append(key)
        if len(out) == 5:
            break
    if len(out) == 0:
        print("NA")
    else:
        print(' '.join(out))

Measured memory_bytes: 7904
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const MAX: usize = 10000000;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let K: usize = sc.get();
    let mut num = 0;
    for i in 0..MAX {
        num = num * 10 + 7;
        num %= K;
        if num == 0 {
            println!("{}", i+1);
            return;
        }
    }
    println!("-1");
}


Measured memory_bytes: 2132
n, x, y = map(int, input().split())

ans = [0] * (n - 1)

dist = 0

for i in range(1, n):
    for j in range(i + 1, n + 1):
        dist = min(j - i, abs(i - x) + abs(j - y) + 1)
        ans[dist - 1] += 1

for i in range(n - 1):
    print(ans[i])


Measured memory_bytes: 3444
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define N_ 101000
long long D[N_], Mod, DD[N_];
vector<int>E[N_], Ch[N_];
int n, w[N_];
long long UP[N_], LL[N_], RR[N_];
void DFS(int a, int pp) {
	for (auto &x : E[a]) {
		if (x == pp)continue;
		DFS(x, a);
		Ch[a].push_back(x);
	}
	long long s = 1;
	for (auto &x : Ch[a]) {
		s = s*D[x] % Mod;
	}
	D[a] = (s + 1) % Mod;
}
void Go(int a, int pp, long long up) {
	if (a == 1) {
		DD[a] = D[a];
	}
	if (Ch[a].empty())return;
	int cnt = 0;
	for (auto &x : Ch[a]) {
		w[++cnt] = x;
	}
	long long s = 1;
	int i;
	LL[0] = RR[cnt + 1] = 1;
	for (i = 1; i <= cnt; i++) {
		s = s * D[w[i]] % Mod;
		LL[i] = s;
	}
	s = 1;
	for (i = cnt; i >= 1; i--) {
		s = s * D[w[i]] % Mod;
		RR[i] = s;
	}
	for (i = 1; i <= cnt; i++) {
		long long t = (LL[i - 1] * RR[i + 1] % Mod*up + 1) % Mod;
		UP[w[i]] = t;
		DD[w[i]] = ((D[w[i]] + Mod - 1)*t + 1) % Mod;
	}
	for (auto &x : Ch[a]) {
		Go(x, a, UP[x]);
	}
}
int main() {
	int i, a, b;
	scanf("%d%lld", &n, &Mod);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	DFS(1, 0);
	Go(1, 0, 1);
	for (i = 1; i <= n; i++)printf("%lld\n", (DD[i] + Mod - 1) % Mod);
}


Measured memory_bytes: 20096