akhauriyash/Code-Regression huggingface dataset:
import sys
from io import StringIO
import unittest
import os
from collections import deque

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    que = deque()
    que.extend(list(input()))
    q = int(input())
    query_s = [list(input().split()) for i in range(q)]

    isReverse = False
    for query in query_s:
        if query[0] == "1":
            isReverse = True if not isReverse else False
        else:
            # 先頭に追加
            if (isReverse is False and query[1] == "1") or (isReverse and query[1] == "2"):
                que.appendleft(query[2])
            # 末尾に追加
            else:
                que.append(query[2])

    ans = ""
    if isReverse:
        ans = "".join(list(reversed(que)))
    else:
        ans = "".join(que)

    print(ans.replace("\r", ""))


# パターン
# !isReverse 1(先頭)　= 先頭に追加
#  isReverse 1(先頭)　= 末尾に追加
# !isReverse 2(末尾)　= 先頭に追加
#  isReverse 2(末尾)　= 先頭に追加

# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """a
4
2 1 p
1
2 2 c
1"""
        output = """cpa"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """a
6
2 2 a
2 1 b
1
2 2 c
1
1"""
        output = """aabc"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """y
1
2 1 x"""
        output = """xy"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 41628
#include<bits/stdc++.h>
using namespace std;
int w,h,sy,sx,gx,gy,n;
int color;
int c,d,x,y;
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
int maps[105][105];
int mem[105][105];
int dfs(int nowx,int nowy);
main(){
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    cin>>sx>>sy>>gx>>gy;
    cin>>n;
    memset(maps,0,sizeof(maps));
    memset(mem,0,sizeof(maps));
    for(int i=0;i<n;i++){
      cin>>c>>d>>x>>y;
      for(int i=0;i<4;i++){
	if(d==0){
	  maps[y][x+i]=c;
	  maps[y+1][x+i]=c;
	}
	else{
	  maps[y+i][x]=c;
	  maps[y+i][x+1]=c;
	}
      }
    }
    /*
    for(int i=1;i<=h;i++){
      for(int j=1;j<=w;j++){
	cout<<maps[i][j]<<" ";
      }
      cout<<endl;
    }
    */
    color=maps[sy][sx];
    if(dfs(sx,sy)==1){
      cout<<"OK"<<endl;
    }
    else{
      cout<<"NG"<<endl;
    }
  }
}
int dfs(int nowx,int nowy){
  int check=0;
  if(nowx==gx&&nowy==gy){
    return 1;
  }
  else{
    for(int i=0;i<4;i++){
      if(nowx+dx[i]>=1&&nowx+dx[i]<=w&&nowy+dy[i]>=1&&nowy+dy[i]<=h&&maps[nowy+dy[i]][nowx+dx[i]]==color&&mem[nowy+dy[i]][nowx+dx[i]]==0){
	mem[nowy+dy[i]][nowx+dx[i]]=1;
	check=max(dfs(nowx+dx[i],nowy+dy[i]),check);
      }
    }
    return check;
  }
}
  

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

int main(){
  int N, T;
  cin >> N >> T;
  
  int cost = 2147483647;
    int c, t;
  bool ret = false;
  for(int i = 0 ; i < N ; i++){
  
    cin >> c >> t;
    if(t <= T && cost > c){
      cost = c;
      ret = true;
    }
   
  }
  
  if(ret) cout << cost << endl;
  else cout << "TLE" << endl;
  
  return 0;
}

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

using namespace std;

int toi(char a){
	if(a <= '9' && a >= '0'){
		return (int)(a - '0');
	}
	else{
		switch(a){
			case 'T': return 10;
			case 'J': return 11;
			case 'Q': return 12;
			case 'K': return 13;
			case 'A': return 14;
		}
	}
}

int con_suit(char a){
	switch(a){
		case 'S': return 0;
		case 'H': return 1;
		case 'D': return 2;
		case 'C': return 3;
	}
}

int main(){
	while(true){
		char c; cin >> c;
		if(c == '#')break;
		int best = con_suit(c);
		vector< vector<pair<int, int> > >  card(4, vector<pair<int ,int> >(13));
		vector<int> team(2,0);
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 13; j++){
				string str;
				cin >> str;
				card[i][j] = make_pair(toi(str[0]), con_suit(str[1]));
			}
		}
		
		int win = -1;
		int score = 0;
		int suit = card[0][0].second;
		for(int turn = 0; turn < 13; turn++){
			win = -1;
			score = 0;
			for(int mem = 0; mem < 4; mem++){
				int c = card[mem][turn].first;
				//cerr << card[mem][turn].second << " " << suit << " * ";
				if( card[mem][turn].second == best && c > score){
					score = c;
					win = mem;
					//cerr << win << " ";
				}
			}

			//cerr << "done" << endl;
			if(win == -1){
				for(int i = 0; i < 4; i++){
					if( card[i][turn].second == suit && card[i][turn].first > score){
						score = card[i][turn].first;
						win = i;
					}
				}
			}
			if(win == -1){
				for(int i = 0; i < 4; i++){
					if( card[i][turn].first > score){
						score = card[i][turn].first;
						win = i;
					}
				}
			}
			//cout << win << " ";
			if( win % 2 == 0){
				team[0]++;
			}
			else{
				team[1]++;
			}
			suit = card[win][turn < 13 ? turn+1: 0].second;
		}
		if(team[0] > team[1]){
			cout << "NS" << " " << team[0]-6 << endl;
		}
		else{
			cout << "EW" << " " << team[1]-6 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    int n;
    cin >> n;
    int a[114514];
    bool b[114514] = {false};
    for (int i = 0; i < n; i++){
        cin >> a[i];
        b[a[i]] = true;
    }
    int count = 0;
    for (int i = 0; i < 114514; i++){
        if (b[i] == true) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int a, b, h;
  cin >> a >> b >> h;

  cout << (a + b) * h / 2 << endl;
  return 0;
}


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

int main() {
	int a, b, c;
	bool ans = false;

	cin >> a >> b >> c;

	if (a == b && b != c) ans = true;
	if (a == c && b != c) ans = true;
	if (c == b && b != a) ans = true;

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n,m;
	cin >> n >> m;
	VL matti = {0,2,5,5,4,5,6,3,7,6};
	VL a(m);
	vector<PLL> vp(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
		vp[i] = make_pair(a[i],matti[a[i]]);
	}
	sort(RALL(vp));
	VS dp(n+1,"");

	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			int nm = vp[j].second;
			if (i-nm < 0) continue;
			if (dp[i-nm] == "" and i- nm> 0) continue;
			dp[i] = (dp[i - nm].size() + 1) < dp[i].size() ? dp[i]
				: ((dp[i - nm].size() + 1) == dp[i].size()) ? max(dp[i],dp[i-nm] + (char)('0' + vp[j].first))
				: dp[i - nm] + (char)('0' + vp[j].first);
		}
	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 45056
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int k,a,b; 
int main(){
	cin>>k;
	if(k%2==0){
		a=k/2;
		b=k/2;
	}
	else{
		a=(k+1)/2;
		b=a-1;
	}
	cout<<a*b<<endl;
system ("pause");
return 0;
}

Measured memory_bytes: 504
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
  string str; cin >> str;
  int id=0;
  bool ans=true;
  while(id < str.size()){
    if(id+7 < str.size() && str.substr(id, 8)=="dreamera"){
      id = id+5;
    }else if(id+6 < str.size() && str.substr(id, 7)=="dreamer"){
      id = id+7;
    }else if(id+5 < str.size() && str.substr(id, 6)=="eraser"){
      id = id+6;
    }else if(id+4 < str.size() && (str.substr(id, 5)=="dream" || str.substr(id, 5)=="erase")){
      id = id+5;
    }else{
      ans=false;
      break;
    }
  }
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main(){
 
  int N,M;
  cin >> N >> M;
  
  vector<int> A(M);
  int sum=0;
  
  for(int i=0;i<M;i++){
  cin >> A.at(i);
    sum +=A.at(i);
  }
  
  if(N-sum>=0){
   cout << N-sum << endl; 
  }
  else{
   cout << "-1" << endl; 
  }
  }

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

    int x1, y1, x2, y2;
    int x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;

    x3 = x2 - (y2 - y1);
    y3 = y2 + (x2 - x1);
    x4 = x1 - (y2 - y1);
    y4 = y1 + (x2 - x1);

    cout
        << x3 << ' '
        << y3 << ' '
        << x4 << ' '
        << y4 << ' '
        << '\n';

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(a,b) (0<=(a)&&(a)<(b))
using namespace std;

int main(){
	int n;
	cin>>n;
	if(n==0||n==2) p(1);
	else if(n==1) p(2);
	else p(0);
	return 0;
}

Measured memory_bytes: 3092
// C - Divide the Problems
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int k = n / 2;
	cout << (a[k] - a[k - 1]) << endl;

	return 0;
}


Measured memory_bytes: 640
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

int N;
int cx, cy, nx, ny, ct, nt;

int main(){
    scan(N);
    bool can = true;
    FOR(i,0,N && can){
        cx = nx;
        cy = ny;
        ct = nt;
        scan(nt,nx,ny);
        int d = abs(nx-cx) + abs(ny-cy), dt = nt-ct;
        if(d>dt){
            can = false;
        }else{
            if((dt-d)%2 == 1) can = false;
        }
    }
    printf(can?"Yes\n":"No\n");
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->


int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	string s;
	vector<string>vec;

	for(int i=0; i<n; i++)
	{
		cin>>s;
		vec.pb(s);
	}

   string ans;

   loop(i,m+2)
   {
   	  ans += '#';
   }

   cout<<ans<<endl;
   
   for(auto it:vec)
   {
   	 cout<<'#'<<it<<"#"<<endl;

   }

   cout<<ans<<endl;


}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define MOD 1000000007
//#define eps 1e-10
#define R freopen("555input.txt","r",stdin);
#define W freopen("medical.out","w",stdout);
//
#define N 100005
#define M 1000000005
int n,i,j,a,b,ans,f[N],t,q,k;
LL d[N],c;
struct edge
{
    int to;
    LL cost;
};
vector <edge>v[N];
queue <int>qu;
int main ()
{
    
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
        edge t;
        scanf("%d%d%lld",&a,&b,&c);
        t.to=b;t.cost=c;
        v[a].push_back(t);
        t.to=a;
        v[b].push_back(t);
    }
    scanf("%d%d",&q,&k);
    qu.push(k);
    f[k]=1;
    while(!qu.empty())
    {
        int cur=qu.front();
        qu.pop();
        int sz=v[cur].size();
        for(i=0;i<sz;i++)
        {
            int now=v[cur][i].to;
            if(f[now])continue;
            qu.push(now);
            d[now]=d[cur]+v[cur][i].cost;
            f[now]=1;
        }
    }
        for(i=0;i<q;i++)
        {
            scanf("%d%d",&a,&b);
            printf("%lld\n",d[a]+d[b]);
        }






    return 0;

}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int n;
	
	cin >> n;
	
	int a[n];
	
	map<int,int> f;
	
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		
		f[a[i]]++;
		f[a[i]-1]++;
		f[a[i]+1]++;
	}
	
	int ans = 0;
	
	for(auto u : f) {
		ans = max(ans , u.S);
	}
	
	cout << ans;
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 10244
#include<cstdio>
int main() {
	int n, a[500][3], i, j, ans;
	scanf("%d", &n);
	for (i = 1; i < n; i++) {
		scanf("%d%d%d", &(a[i][0]), &(a[i][1]), &(a[i][2]));
	}
	for (i = 1; i < n; i++) {
		ans = 0;
		for (j = i; j < n; j++) {
			if (a[j][1] > ans) {
				ans = a[j][1];
			}
			else if(ans%a[j][2]!=0){
				ans = ans - ans%a[j][2] + a[j][2];
			}
			ans += a[j][0];
		}
		printf("%d\n", ans);
	}
	printf("0\n");
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main()
{
	long n, k;
	scanf("%ld %ld", &n, &k);	
	vector<long> a(100000, 0);
	for(long i = 0, j, l; i < n; i++)
	{
		scanf("%ld %ld", &j, &l);
		a[--j] += l;
	}
	for(long i = 0; i < 100000; i++)
	{
		k -= a[i];
		if(k <= 0)
		{
			printf("%ld\n", i + 1);
			break;
		}
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#define EMPTY -1
using namespace std;

int main()
{
  int h;

  for(;;){
    scanf("%d",&h);
    if(h==0)return 0;
    int map[h][5];
    //????????????????????????
    for(int i=0;i<h;i++){
      for(int j=0;j<5;j++){
	scanf("%d",&map[i][j]);
      }
    }

    bool next = true;
    int point;
    point=0;   //????¨????????????????
    for(;;){
      /*/???????¢??????¨
      for(int i=0;i<h;i++){
	for(int j=0;j<5;j++){
	  printf("%3d ",map[i][j]);
	}
	printf("\n");
      }
      printf("\n");
      //???????????§//*/

      if(!next)break;
      next = false;
    
      //???????¨????????????????
      for(int i=0;i<h;i++){  //???????????????????????????????????????(i)
	for(int j = 0;j<5;j++){  //??????????§???°???(j)
	  if(map[i][j]==EMPTY)continue;
	  int count = 1;  //??£?¶??????????????????°(count)
	  int k;  //????????°???(k)
	  for(k=j+1;k<5;k++){
	    if(k>=5)break;
	    if(map[i][j]!=map[i][k])break;
	    count++;
	  }
	  if(count>=3){   //??£?¶???????????????´???
	    next = true;
	    point+=map[i][j]*count;  //????????????
	    //printf("point++(%d*%d)\n",map[i][j],count);
	    //printf("point=%d\n",point);
	    for(int l=0;l<count;l++){ //????????????
	      map[i][j+l]=EMPTY;
	    }
	    count=1;
	  }
	}
      }
   
      /*/???????¢??????¨
      for(int i=0;i<h;i++){
	for(int j=0;j<5;j++){
	  printf("%3d ",map[i][j]);
	}
	printf("\n");
      }
      printf("\n");
      //???????????§//*/

      //????????????
      for(int i=0;i<5;i++){  //???????????????????????????????????????(i,0-5)
	for(int j=h-1;j>=0;j--){  //??\?????????????§???°???(j,(h-1)-0)
	  if(map[j][i]!=EMPTY)continue;
	  for(int k=(j-1);k>=0;k--){  //????§???°???????????????????¨?
	    if(k<0)break;
	    if(map[k][i]!=EMPTY){  //?????????????????£??????????§???°?????¨??\?????????
	      map[j][i]=map[k][i];
	      map[k][i]=EMPTY;
	      break;
	    }
	  }
	}
      }//*/
    
      //printf("%d\n",point);
    }
    printf("%d\n",point);
  }
}
    

Measured memory_bytes: 1188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main()
{
   ll X, K, D;
   cin >> X >> K >> D;
   X = abs(X);
   if (X / D <= K)
   {
      ll t = X / D;
      X -= D * t;
      K -= t;
      if (K % 2 == 1)
      {
         X -= D;
      }
   }
   else
   {
      X -= D * K;
   }
   cout << abs(X) << endl;
   return 0;
}


Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

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

	void run() {
		Scanner sc = new Scanner();
		int a = sc.nextInt();
		String s = sc.next();
		if (a >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

class Scanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 21076
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class T> inline T pow2_L(T a){
  return a*a;
}
int main(){
  long long A;
  long long B;
  long long C;
  long long v;
  rd(A);
  rd(B);
  rd(C);
  if(C - A - B <= 0){
    wt_L("No");
    wt_L('\n');
    return 0;
  }
  v =pow2_L((C - A - B))- 4 * A * B;
  if(v > 0){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200314-1

// --- original code ---
// {
//   ll A, B, C, v;
//   rd(A,B,C);
//   if(C - A - B <= 0) wt("No"), return 0;
//   v = (C - A - B) ** 2 - 4 * A * B;
//   wt(if[v > 0, "Yes", "No"]);
// }


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

string S;
int K;
int num[1001] = {0};
int keta;


int f(int p,int k){
	if(k < 0) return 0;
	if(k == 0) return 1;
	if(p <= 0) return 0;
	return f(p-1,k) + 9*f(p-1,k-1);
}

int solve(){
	int sm = 0;
	int k = K;
	for(int i = keta-1; i > 0; i--){
		if(num[i] != 0){
			sm += f(i,k) + (num[i]-1)*f(i,k-1);
			k--;
		}
	//	if(k < 0) k = 0;
	}
	if(k == 0){
		sm += 1;
	}
	if(k == 1){
		sm += num[0];
	}
	return sm;
}

int main(){
	cin >> S >> K;
	keta = S.size();
	for(int i = 0; i < S.size(); i++){
		num[S.size()-1-i] = S[i] - '0';
	}

	cout << solve() << endl;

	return 0;
}


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

int main()
{

string s,s1;
cin>>s>>s1;
if(stoi(s)<stoi(s1) ){

    for(int i=0;i<stoi(s1);i++)
    cout<<s;
}
else{

    for(int i=0;i<stoi(s);i++){

        cout<<s1;
    }


}


    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
ll dp[200005],per[200005];
void solve()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int a;
		cin >> a;
		per[a]++;
	}
	dp[0] = 1;
	if (per[1] == 0)
		dp[1] = 1;
	for (int i = 2; i <= n; i++)
	{
		if (per[i] == 0)
			dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
		else
			dp[i] = 0;
	}
	cout << dp[n];
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return(0);
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
using namespace std;

const int N = 2e5;
const int lgN = 18;
const int INF = 1e7;
struct Edge
{
	int v,nxt;
} e1[(N<<1)+3],e2[(N<<1)+3];
int fe1[N+3],fe2[N+3];
int dep1[N+3],dep2[N+3];
int fa2[N+3][lgN+3];
int n,en1,en2,s1,s2,ans;

void addedge1(int u,int v)
{
	en1++; e1[en1].v = v;
	e1[en1].nxt = fe1[u]; fe1[u] = en1;
}
void addedge2(int u,int v)
{
	en2++; e2[en2].v = v;
	e2[en2].nxt = fe2[u]; fe2[u] = en2;
}

void dfs1(int u,int prv)
{
	for(int i=fe1[u]; i; i=e1[i].nxt)
	{
		int v = e1[i].v;
		if(v==prv) continue;
		dep1[v] = dep1[u]+1;
		dfs1(v,u);
	}
}

void dfs2(int u)
{
	for(int i=1; i<=lgN; i++) fa2[u][i] = fa2[fa2[u][i-1]][i-1];
	for(int i=fe2[u]; i; i=e2[i].nxt)
	{
		int v = e2[i].v;
		if(v==fa2[u][0]) continue;
		fa2[v][0] = u; dep2[v] = dep2[u]+1;
		dfs2(v);
	}
}

int LCA(int u,int v)
{
	if(dep2[u]<dep2[v]) swap(u,v);
	int dif = dep2[u]-dep2[v];
	for(int i=0; i<=lgN; i++)
	{
		if(dif&(1<<i)) {u = fa2[u][i];}
	}
	if(u==v) return u;
	for(int i=lgN; i>=0; i--)
	{
		if(fa2[u][i]!=fa2[v][i]) {u = fa2[u][i],v = fa2[v][i];}
	}
	return fa2[u][0];
}

void dfs(int u,int fa)
{
	if(dep1[u]>=dep2[u]) {return;}
	ans = max(ans,dep2[u]);
	for(int i=fe1[u]; i; i=e1[i].nxt)
	{
		int v = e1[i].v;
		if(v==fa) continue;
		if(dep2[u]+dep2[v]-2*dep2[LCA(u,v)]>2) {ans = INF; return;}
		dfs(v,u);
	}
}

int main()
{
	scanf("%d%d%d",&n,&s1,&s2);
	for(int i=1; i<n; i++)
	{
		int u,v; scanf("%d%d",&u,&v);
		addedge1(u,v); addedge1(v,u);
	}
	for(int i=1; i<n; i++)
	{
		int u,v; scanf("%d%d",&u,&v);
		addedge2(u,v); addedge2(v,u);
	}
	dfs1(s1,0); dfs2(s2);
	ans = 0; dfs(s1,0);
	printf("%d\n",ans==INF?-1:ans*2);
	return 0;
}

Measured memory_bytes: 34432
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int main()
{
    int n,sum=0;cin>>n;
    int a[n];REP(i,n)cin>>a[i];


    REP(i,n)
    {
        int mn=i;
        rep(j,i,n)
        {
            if(a[j]<a[mn])
            mn=j;
        }
        if(a[mn]!=a[i]){swap(a[mn],a[i]);sum++;}
    }

    REP(i,n)
    {
        if(i!=0)cout<<" ";
        cout<<a[i];
    }cout<<endl;
    cout<<sum<<endl;
}



Measured memory_bytes: 3100
#include <stdio.h>

int main(void) {
  int a, b, c, i, ans = 0;
  scanf("%d%d%d", &a, &b, &c);
  for(i = a; i <= b; ++i) if(!(c % i)) ++ans;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2752
n=int(input())
dp=[[0 for i in range(3)] for i in range(n)]
S=[[0 for i in range(3)] for i in range(n)]
dp[0]=list(map(int,input().split()))
S[0]=dp[0].copy()
for i in range(1,n):
    S[i]=list(map(int,input().split()))
    for j in range(3):
        dp[i][j]=max(dp[i-1][j-1],dp[i-1][j-2])+S[i][j]

print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
#dp[i][j]=i番目にjを選んだ時の最大値(jはa,b,cに対応している。)

Measured memory_bytes: 108028
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, m; scanf("%d %d", &n, &m);
	std::vector<std::vector<int>> vec(n);
	for(int i = 0; i < m; i++) {
		int a, b; scanf("%d %d", &a, &b);
		
		vec[a - 1].push_back(b);
	}
	for(int i = 0; i < n; i++) sort(begin(vec[i]), end(vec[i]));
	
	int ans = 0, mi = 1 << 30;
	for(int i = 0; i < n; i++) {
		if(i + 1 == mi) {
			ans++;
			mi = 1 << 30;
		}
		if(vec[i].size()) {
			mi = std::min(mi, vec[i][0]);
		}
	}
	if(mi != 1 << 30) ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct edge { 
	int to, cap, rev;
	edge(int to, int cap, int rev) :to(to), cap(cap), rev(rev) {}
};
vector<edge> G[100];
bool used[100];

void add_edge(int from, int to, int cap) {
	G[from].emplace_back(to, cap, G[to].size());
	G[to].emplace_back(from, 0, G[from].size() - 1);
}

int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		memset(used, 0, sizeof(used));
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int V, E; cin >> V >> E;
	rep(i, 0, E) {
		int u, v, c; cin >> u >> v >> c;
		add_edge(u, v, c);
	}
	cout << max_flow(0, V - 1) << endl;
	return 0;
}

Measured memory_bytes: 3276
N = int(input())
ful = [i for i in range(1,N+1)]
fi = N//5
fiz = [i*5 for i in range(1,fi+1)]
buz = N//3
buz = [i*3 for i in range(1,buz+1)]
fiz_buz = list(set(fiz) & set(buz))
fiz_and_buz = list((set(fiz) ^ set(buz))) 
ful_and_fi_bz = list(set(fiz_and_buz) ^ set(ful))
ful_and_fi_bz = list(set(ful_and_fi_bz) ^ set(fiz_buz))

print(sum(ful_and_fi_bz))

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int N; cin >> N;
    FORq(i,1,100000){
        if (i * 1000 >= N){
            cout << i * 1000 - N << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> P2;
ll det(P p1,P p2){
  return p1.first*p2.second-p2.first*p1.second;
}
P operator +(const P2 &p1,const P2 &p2){
  return P(p1.first.first+p2.first.first,p1.first.second+p2.first.second);
}
P operator -(const P2 &p1,const P2 &p2){
  return P(p1.first.first-p2.first.first,p1.first.second-p2.first.second);
}
P operator -(const P &p1,const P &p2){
  return P(p1.first-p2.first,p1.second-p2.second);
}
P operator -(const P2 &p1,const P &p2){
  return P(p1.first.first-p2.first,p1.first.second-p2.second);
}
vector<ll> convex(vector<P2> v,ll n){
  sort(v.begin(),v.end());
  ll k=0;
  vector<P> ans(n*2);
  vector<ll> ret(n*2);
  for(ll i=0;i<n;i++){
    while(k>1&&det(ans[k-1]-ans[k-2],v[i]-ans[k-1])<=0) k--;
    ans[k]=v[i].first;
    ret[k]=v[i].second;
    k++;
  }
  for(ll i=n-2,t=k;i>=0;i--){
    while(k>t&&det(ans[k-1]-ans[k-2],v[i]-ans[k-1])<=0) k--;
    ans[k]=v[i].first;
    ret[k]=v[i].second;
    k++;
  }
  ans.resize(k-1);
  ret.resize(k-1);
  return ret;
}
int main(){
  ll n;
  cin>>n;
  vector<P2> vec;
  for(ll i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    vec.push_back(P2(P(a,b),i));
  }
  vector<ll> v=convex(vec,n);
  /*for(int i=0;i<v.size();i++) cout<<v[i]<<" ";
  cout<<endl;*/
  ll vs=v.size();
  double ans[105]={0.0};
  for(ll i=0;i<v.size();i++){
    ll px=vec[v[i]].first.first-vec[v[(i+1)%vs]].first.first;
    ll py=vec[v[i]].first.second-vec[v[(i+1)%vs]].first.second;
    py*=-1;
    double pa=M_PI/2;
    if(py!=0) pa=atan((double)px/py);

    ll zx=vec[v[i]].first.first-vec[v[(i-1)+(i==0?vs:0)]].first.first;
    ll zy=vec[v[i]].first.second-vec[v[(i-1)+(i==0?vs:0)]].first.second;
    zy*=-1;
    double za=-M_PI/2;
    if(zy!=0) za=atan((double)zx/zy);

    double ka=abs(pa-za);
    ll dot=px*(-zx)+(-py)*zy;
    if(dot>0) ka=min(ka,M_PI-ka);
    else if(dot<0) ka=max(ka,M_PI-ka);
    else ka=M_PI/2;
    //cout<<px<<" "<<py<<" "<<zx<<" "<<zy<<" "<<ka<<" "<<dot<<endl;
    ans[vec[v[i]].second]=ka/(M_PI*2);
  }
  for(int i=0;i<n;i++) printf("%.7lf\n",ans[i]);
}


Measured memory_bytes: 512
n = gets.to_i
s = gets.chomp
ans = 0
l, r = 0, 0
while r < n
  subst = s[l..r]
  rest = s[r + 1..-1]
  if rest.slice(subst)
    ans = subst.size if subst.size > ans
    r += 1
  else
    l += 1
    r += 1
  end
end
p ans


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

int main()
{
    ll n,i,j,cnt=1,k,w,a,b,h,m;
   /* freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
    cin>>n>>m;
    if(n==m)
    {
        for(i=0;i<n;i++)
        {
            cout<<n;
        }
    }
    else if(n>m)
    {
        for(i=0;i<n;i++)
        {
            cout<<m;
        }
    }
    else{
        for(i=0;i<m;i++)
        {
            cout<<n;
        }
    }
	    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long[] line = Stream.of(sc.nextLine().split(" ", 0)).mapToLong(Long::parseLong).toArray();
		long ans = 0;

		if (line[0] == 1 || line[1] == 1) {
			ans += 1;
		} else {
			ans += line[0] / 2 * line[1];
			if (line[0] % 2 == 1) {
				ans += line[1] / 2;
				if (line[1] % 2 == 1) {
					ans++;
				}
			}
		}

		 System.out.println(ans);
	}
}


Measured memory_bytes: 35872
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {

  int n;
  string s;
  cin >> s;
  n = s.size();
  int g = 0, p = 0;
  int score = 0;
  rep(i, n) {
    if (g + 1 <= p) {
      g++;
      score += (s[i] == 'g' ? 1 : 0);
    } else {
      if (s[i] == 'g') p++;
      else p++, score--;
    }
  }
  cout << score << endl;

  return 0;

}


Measured memory_bytes: 512
n=int(input())
#n,k=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
stock = 0
money = 1000
for i in range(n-1):
    sell = stock*al[i]
    stock = 0
    money += sell
    if al[i] < al[i+1]:# buy
        buynum = money//al[i]
        stock= buynum
        money -= buynum*al[i]

print(money + stock*al[n-1])


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

const long long MOD = 1e9 + 7;

int n, v1, v2;
int v[1<<20];
long long inv[1<<20], fact[1<<20];

long long pow(long long x) { 
    long long ret = 1;
    for (long long a = MOD - 2; a; a >>= 1) { if (a&1) ret = ret * x % MOD; x = x * x % MOD; }
    return ret;
}

long long C (int k, int m) {
    if (k < 0 || k > m) return 0;
    return fact[m] * inv[k] % MOD * inv[m-k] % MOD;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) v[i] = -1;
    fact[0] = 1, inv[0] = pow(fact[0]);
    for (int i = 1; i <= n; i++) fact[i] = fact[i-1] * i % MOD, inv[i] = pow(fact[i]);
    for (int i = 1; i <= n + 1; i++){
        int x;
        cin >> x;
        if (v[x] == -1) v[x] = i;
        else {
            v1 = v[x];
            v2 = i;
            break;
        }
    }
    cout << n << '\n';
    for (int k = 2; k <= n + 1; k++) {
        cout << (MOD + C(k, n - 1) + 2 * C(k - 1, n - 1) - C(k - 1, n - v2 + v1) + C(k - 2, n - 1)) % MOD << '\n';
    }
}

Measured memory_bytes: 6144
from collections import deque
N = int(input())
A = [int(a) for a in input().split()]

q = deque()
for i in range(N):
    if i%2 == 0:
        q.append(A[i])
    else:
        q.appendleft(A[i])

ans = list(q)
if N%2 == 1:
    ans.reverse()
print(*ans)

Measured memory_bytes: 106988
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <tuple>
using namespace std;

int main(){

    long long L, R; cin >> L >> R;

    if(R > L + 2019){
        R = L + 2019;
    }

    int minv = 2019;
    for(long long i = L; i<R; i++){
        for(long long j = i+1; j<=R; j++){
            int temp = (i * j) % 2019;
            if(temp < minv){
                minv = temp;
            }
        }
    }

    cout << minv;

    return  0;
}

Measured memory_bytes: 256
N,K,Q = gets.split.map &:to_i

a = Array.new(N, 0)

sum = 0

Q.times{
	a[gets.to_i - 1] += 1 
}

a.each{ |ai|
	if K - Q + ai > 0 then
		puts 'Yes'
	else
		puts 'No'
	end
}

Measured memory_bytes: 3196
#include <iostream>
 
using namespace std;
 
int main()
{
  int N;
  cin >> N;
  
  int n = N % 10;
  
  if( (n == 2) || (n == 4) || (n == 5) || (n == 7) || (n == 9) )
  {
    cout << "hon" << endl;
  }
  else if( (n == 0) || (n == 1) || (n == 6) || (n == 8) )
  {
    cout << "pon" << endl;
  }
  else 
  {
    cout << "bon" << endl;
  }
  
}

Measured memory_bytes: 3584
def used(dp,u,v,w):
    n=len(dp)
    for i in range(n):
        for j in range(i+1,n):
            if dp[i][j]==dp[i][u]+w+dp[v][j] or dp[i][j]==dp[i][v]+w+dp[u][j]:
                return True
    return False

while 1:
    try:
        n,m=map(int,input().split())
        es=[]
        for _ in range(m):
            u,v,w=map(int,input().split())
            es.append((u-1,v-1,w))
    except: break

    dp=[[float('inf')]*n for _ in range(n)]
    for i in range(n):
        dp[i][i]=0
    for u,v,w in es:
        dp[u][v]=dp[v][u]=w
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])
    print(sum(int(not used(dp,u,v,w)) for u,v,w in es))


Measured memory_bytes: 47196
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int N[] = new int[n];
		int count = 0;
		int minj = 0;
		
		for (int k = 0; k <= n - 1; k++) {
			int x = scanner.nextInt();
			N[k] = x;
		} //ここまでで配列に要素を入れる
		
        for (int i = 0; i <= n - 1; i++) {
        	minj = i;
            for (int j = i; j <= n - 1; j++) {
                if (N[j] < N[minj]) {
                    minj = j;
                }
            }
            int a = N[i];
            N[i] = N[minj];
            N[minj] = a;
        if (minj != i) {
        	count++;
        }
        }
		for (int k = 0; k < n - 1; k++) {
			System.out.print (N[k] + " ");
			}
		System.out.println (N[n - 1]);
        System.out.println(count);
        }
}


Measured memory_bytes: 26460
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))

ans = 0
for i in range(n):
    tmp = 1
    x = bisect.bisect_left(a, b[i])
    y = bisect.bisect_right(c, b[i])
    ans += x*(n-y)
print(ans)

Measured memory_bytes: 23240
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
long long ans,tot;
int n,flag,cnt[200100];
char s[200010];
long long sum[200010];
int main()
{
	int t1,t2;
	for (int i=1;i<=200005;i++)
	    sum[i]+=sum[i-1]+i;
	scanf("%s",s);
	n=strlen(s);
	for (int i=n;i>=1;i--)
	    s[i]=s[i-1];
	s[0]=' ';
	for (int i=1;i<=n;i++)
		cnt[(int)(s[i]-'a')+1]++;
	for (int i=1;i<=26;i++)
	    tot+=sum[cnt[i]-1];
	tot+=n;
	ans=sum[n];
	printf("%lld",ans-tot+1);
}


Measured memory_bytes: 2048
import math
n,d=map(int,input().split())
ans=0
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
for i in range(n-1):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=(a[i][k]-a[j][k])**2
    if(math.sqrt(dis)-math.floor(math.sqrt(dis))==0):
      ans+=1
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    int count = 0;
    boolean flg = false;
    for(int i=0; i<100000; i++) {
      if(a%2==0 && b%2==0 && c%2==0) {
        int a_tmp = a;
        int b_tmp = b;
        int c_tmp = c;
        a_tmp = b/2 + c/2;
        b_tmp = a/2 + c/2;
        c_tmp = a/2 + b/2;
        a = a_tmp;
        b = b_tmp;
        c = c_tmp;
        count += 1;
      } else {
        flg = true;
        break;
      }
    }
    System.out.println(flg == false?-1:count);
  }
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  int count = 0;
  
  rep(i,n-2){
    if(s.substr(i,3) == "ABC") count++;
  }
  
  cout << count << endl;
  
  
  return 0;
}

Measured memory_bytes: 256