akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
int main( void )
{
	const int dx[4] = { 1, 0, -1, 0 };
	const int dy[4] = { 0, -1, 0, 1 };

	int w, h;
	while ( cin>>w>>h && ( w != 0 && h != 0 ) )
	{
		vector < vector <char> > V( h, vector <char>(w, false) );
		queue < pair<int,int> > Q;

		for ( int i = 0; i < h; i++ )
		{
			for ( int j = 0; j < w; j++ )
			{
				cin >> V[i][j];
				if ( V[i][j] == '@' )
					Q.push( make_pair( i, j ) );
			}
		}

		while ( !Q.empty() )
		{
			pair <int,int> now = Q.front();
			Q.pop();

			V[now.first][now.second] = 'v';

			for ( int i = 0; i < 4; i++ )
			{
				int nx = now.second + dx[i];
				int ny = now.first + dy[i];

				if ( ( nx < 0 || nx >= w ) || ( ny < 0 || ny >= h ) )
					continue;

				if ( V[ny][nx] != '.' )
					continue;

				Q.push( make_pair( ny, nx ) );

			}
		}

		int kotae = 0;
		for ( int i = 0; i < h; i++ )
		{
			for ( int j = 0; j < w; j++ )
			{
				if ( V[i][j] == 'v' )
					kotae++;
			}
		}

		cout << kotae << endl;
	}
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define l(i) (n/2-(n-i+1)/2)
#define r(i) (i+1)/2
#define st(i) i/2-1
using namespace std;
typedef long long ll;
int n,a[200005];
ll ans=-1e16;
ll dp[200005][3],pre[200005][3];//j的范围在i/2-1到(i+1)/2，最多3个
int main() {
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(int i=1; i<=n; i++) {
		for(int j=0; j<3; j++)
			dp[i][j]=-1e16;
	}
	dp[1][1-st(1)]=a[1],dp[2][1-st(2)]=a[2];
	dp[1][0-st(1)]=0;
	if(0-st(2)>=0) dp[2][0-st(2)]=0;
	for(int i=3; i<=n; i++) {
		for(int j=l(i); j<=r(i); j++) {
			if(j==0) dp[i][j-st(i)]=0;
			else {
				for(int k=i-2; l(k)<=j-1&&r(k)>=j-1&&k>=1; k--)
					dp[i][j-st(i)]=max(dp[i][j-st(i)],dp[k][j-1-st(k)]+a[i]);
			}
		}
	}
	for(int i=n/2; i<=n; i++)
		for(int j=l(i); j<=r(i); j++)
			j==n/2 ? ans=max(ans,dp[i][j-st(i)]):0;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9024
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::string s;
	std::cin >> n >> s;
	for(char c:s) {
		char x = c-'A';
		x = (x+n)%26;
		std::cout << (char)(x+'A');
	}
	std::cout << ENDL;
		
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

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

  ll N, K;

  cin >> N >> K;

  ll ans = 0;

  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }

  for (int b = K + 1; b <= N; ++b) {
    int p = N / b, r = N % b;

    ans += (p * std::max(0LL, b - K));
    ans += std::max(0LL, r - (K - 1));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0

for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      if 500 * a + 100 * b + 50 * c == X:
        cnt += 1
        
print(cnt)


Measured memory_bytes: 3060
#include<stdio.h>

#define N 100000

typedef struct
{
  int parent;
  int left;
  int right;
} node;


int finddepth(int);

node A[N];

int main()
{
  int pa, pr, x, i, j, n, k;

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      A[i].parent = -1;
      A[i].left = -1;
      A[i].right = -1;
    }

  for(i=0; i<n; i++)
    {
      scanf("%d%d", &pa, &k);
      if(k!=0)
    {
      scanf("%d", &x);
      A[pa].left = x;
      A[x].parent = pa;
      pr = x;
    }
      for(j=1; j<k; j++)
    {
      scanf("%d", &x);
      A[x].parent = pa;
      A[pr].right = x;
      pr = x;
    }
    }
  for(i=0; i<n; i++)
    {
      printf("node %d: parent = %d, depth = %d, ", i, A[i].parent, finddepth(i));
      if(A[i].parent == -1)
    {
      printf("root, ");
    }
      else if(A[i].left != -1)
    {
      printf("internal node, ");
    }
      else
    {
      printf("leaf, ");
    }
      printf("[");
      if(A[i].left != -1)
    {
      printf("%d", pr=A[i].left);
    }
      while(A[pr].right != -1)
    {
      printf(", %d", A[pr].right);
      pr = A[pr].right;
    }
      printf("]\n");
    }

  return 0;
}

int finddepth(int x)
{
  int c=0;
  while(A[x].parent >= 0)
    {
      c++;
      x = A[x].parent;
    }
  return c;
}

Measured memory_bytes: 1788
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

struct Edge {
	ll from;
	ll to;
};

ll max_path(const vector<vector<Edge>>& graph, ll v, ll* out_depth, vector<bool>& visited) {
	visited[v] = true;
	ll ans = numeric_limits<ll>::min();
	vector<ll> depths;
	for (Edge e : graph[v]) {
		if (visited[e.to]) {
			continue;
		}
		ll mp, depth;
		mp = max_path(graph, e.to, &depth, visited);
		ans = max(ans, mp);
		depths.push_back(depth);
	}
	if (depths.size() >= 2) {
		sort(depths.rbegin(), depths.rend());
		ans = max(ans, depths[0] + depths[1] + 2);
		*out_depth = depths[0] + 1;
	} else if (depths.size() == 1) {
		ans = max(ans, depths[0] + 1);
		*out_depth = depths[0] + 1;
	} else {
		ans = max(ans, (ll)0);
		*out_depth = 0;
	}
	return ans;
}

int main() {
	ll N;
	cin >> N;
	vector<vector<Edge>> graph(N);
	rep(i,0,N-1) {
		ll A, B;
		cin >> A >> B;
		A--;
		B--;
		graph[A].push_back({A, B});
		graph[B].push_back({B, A});
	}
	vector<bool> visited(N);
	ll depth;
	ll len = max_path(graph, 0, &depth, visited);
	// cout << len << endl;
	// cout << depth << endl;
	if (len % 3 == 1) {
		cout << "Second" << endl;
	} else {
		cout << "First" << endl;
	}
}


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

int main(){
	int n;
	cin >> n;
	int s=0, smax=0;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		s++;
		if(a == 0) s=0;
		smax = max(smax, s);
	}
	cout << smax +1 << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 1e5 + 10;
int x[N], fa[N], id[N];
LL sum[N];
int ls[N], rs[N], flag[N], ok[N];

struct Edge{ 
    int u, v, w;
} e[N];

bool cmp(Edge &x, Edge &y) {
    return x.w < y.w;
}

int find(int x) {
    if (fa[x] == x) return x;
    else return fa[x] = find(fa[x]);
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", x + i);
    for (int i = 1; i <= m; i++) {
        int a, b, y;
        scanf("%d%d%d", &a, &b, &y);
        e[i] = {a, b, y};
    }
    sort(e + 1, e + m + 1, cmp);
    for (int i = 1; i <= n; i++) fa[i] = i, sum[i] = x[i];
    for (int i = 1; i <= m; i++) {
        int x = e[i].u, y = e[i].v;
        x = find(x), y = find(y);
        ls[i] = id[x];
        rs[i] = id[y];
        id[x] = i;
        if (x != y) {
            sum[x] += sum[y];
            fa[y] = x;
        }
        flag[i] = e[i].w > sum[x];
    }
    int ans = 0;
    for (int i = m; i >= 1; i--) {
        if (!ok[i] && flag[i]) ans += 1;
        if (!flag[i]) ok[i] = 1;
        if (ok[i]) {
            ok[ls[i]] = ok[rs[i]] = 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 4992
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
ostream &operator<<(ostream &os, const vector<lint> &a) {
	os<<"[";
	rep(i,a.size()){
		os<<a[i];
		if(i<a.size()-1) os<<",";
	}
	os<<"]";
	return os; 
}
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint a[1010],sum[1010];
vector<lint> v;
int main()
{
	int n,K;sum[0]=0;lint out=0;
	cin>>n>>K;
	rep(i,n){
		cin>>a[i];sum[i+1]=sum[i]+a[i];
	}
	rep(i,n) REP(j,i+1,n+1) v.pb(sum[j]-sum[i]);
	sort(All(v));
	for(int i=50;i>=0;i--){
		//cout<<v<<endl;
		vector<lint> ne;
		int t=0;lint b=(1LL<<i)-1;//cout<<b<<endl;
		for(int j=0;j<(int)v.size();j++){
			if(v[j]>b) t++;
		}
		if(t>=K){
			out+=1LL<<i;
			rep(j,v.size()){
				if(v[j]>b) ne.pb((v[j]&b));
			}
		}
		else{
			rep(j,v.size()) ne.pb((v[j]&b));
		}
		v=ne;
		//cout<<v<<endl;
	}
	cout<<out<<endl;
}


Measured memory_bytes: 12488
while True:
    try:
        a = [int(i) for i in input()]
    except:
        break
    while True:
        na = []
        for i in range(len(a) - 1):
            na.append((a[i] + a[i + 1]) % 10)
        if len(na) == 1:
            print(na[0])
            break
        a = na

Measured memory_bytes: 7648
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
static long xa = long.Parse(input[0]);
static long ya = long.Parse(input[1]);
static long xb = long.Parse(input[2]);
static long yb = long.Parse(input[3]);
static long n = long.Parse(Console.ReadLine());
static long[][] vertexes = new long[n][];//ここに受け取る
static long[] LISnums;//xの昇順にyの値を代入
static long[] rightMin;//長さがi+1のときの右端の最小値
static long LISnum = 1;//LISの値
static long compareMemo = 0;
static long LIScount = 0;//範囲内の候補数
static long riverseNum = 9999999999;

	static void Main()
	{
    for(long i = 0; i < n; i++)
    {
      vertexes[i] = new long[2];
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
      vertexes[i][0] = nums[0];
      vertexes[i][1] = nums[1];
      if(Math.Min(xa,xb)<=nums[0] && nums[0]<=Math.Max(xa,xb)
        && Math.Min(ya,yb)<=nums[1] && nums[1]<=Math.Max(ya,yb)) LIScount++;
    }
    LISnums = new long[LIScount];
    rightMin = new long[LIScount];

    if((xb-xa)*(yb-ya) < 0)
    {
      ya = riverseNum - ya;
      yb = riverseNum - yb;
      for(long i = 0; i < n; i++) vertexes[i][1] = riverseNum - vertexes[i][1];
    }
    
    Array.Sort(vertexes, (a, b) => a[0].CompareTo(b[0]));
    double answer = (Math.Abs(xa-xb) + Math.Abs(ya-yb))*100;

    long memo = 0;
    for(long i = 0; i < n; i++)
    {
      if(Math.Min(xa,xb)<=vertexes[i][0] && vertexes[i][0]<=Math.Max(xa,xb)
        && Math.Min(ya,yb)<=vertexes[i][1] && vertexes[i][1]<=Math.Max(ya,yb))
      {
        LISnums[memo] = vertexes[i][1];
        memo++;
      }
    }
    
    if(LIScount >= 2) 
    {
      rightMin[0] = LISnums[0];

      for(long i = 1; i < LIScount; i++)
      {
        if(LISnums[i] > rightMin[LISnum-1])
        {
          rightMin[LISnum] = LISnums[i];
          LISnum++;
        }else
        {
          compareMemo = LISnums[i];
          rightMin[Search(0, LISnum-1)] = LISnums[i];//更新位置を二部探索する
        }
      }
    }else LISnum = LIScount;

    if(LISnum < Math.Min(Math.Abs(xa-xb), Math.Abs(ya-yb))+1)
    {
      answer += (-20+5*Math.PI)*LISnum;
    }else
    {
      if(LISnum >= 1) answer += (-20+5*Math.PI)*(LISnum-1);
      answer += 10*Math.PI - 20;
    }
  
		Console.WriteLine(answer);
	}

  static long Search(long min, long max)//二分探索法で最小値を求める
  {
    while (true)
    {
      long mid = min + (max - min) / 2;
      if(Check(mid)) max = mid;//さらに大きくても成り立つかも
      else min = mid;

      if(max - min <= 1)
      {
        if(Check(min)) 
        {
          return min;//最小値で成り立つかの確認を優先
        }
        else
        {
          return max;
        }
      break;
      }  
    }
  }

  static bool Check(long testNum)
  {
    if(rightMin[testNum] >= compareMemo) return true;//同じ数で右端を複数にしないように、等号を含む
    return false;
  }
  
}

Measured memory_bytes: 31620
#include <stdio.h>

int main(void) {
  int a, b, c, d, diff1, diff2, diff3;

  scanf("%d %d %d %d", &a, &b, &c, &d);

  diff1 = ((c - a) > 0) ? (c - a) : (a - c);
  diff2 = ((b - a) > 0) ? (b - a) : (a - b);
  diff3 = ((c - b) > 0) ? (c - b) : (b - c);

  if ((diff1 <= d) || ((diff2 <= d) && (diff3 <= d))) {
    printf("Yes\n");
  }else {
    printf("No\n");
  }

  return 0;

}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      if (i * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define in(x)  cin>>x
#define o(x)  cout<<x
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS];
int main()
{
    fast;
    in(n);
    fr(i,0,2*n-1)in(ar[i]);
    sort(ar,ar+2*n);
    fr(i,0,2*n-1)c+=ar[i++];
    o(c);
}


Measured memory_bytes: 3628
from collections import defaultdict
l=[list(map(int, input().split())) for _ in range(3)]
dict=defaultdict(lambda: 0)
for i in l:
  dict[i[0]]+=1
  dict[i[1]]+=1

tmp=[]
for k in dict.keys():
  tmp.append(dict[k])

tmp.sort()
if tmp==[1,1,2,2]:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    char c = '!';
    rep(i,n){
        if (c != s[i]){
            ans++;
            c = s[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#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 n, m;
  cin >> n >> m;
  int ans = 0;
  for(int i = 1; i*i <= m; i++) {
    if(m % i != 0) continue;
    if(i >= n) chmax(ans, m/i);
    if(m/i >= n) chmax(ans, i);
  }
  cout << ans << endl;
}

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

#define FOR(i, a, b) for(int(i)=(a);(i)<(b);(i)++)
#define REP(i, n) FOR((i), 0, (n))

#define RFOR(i, b, a) for(int(i)=(b); (i)>=(a); (i)--)
#define RREP(i, n) FOR((i), (n), 0)

#define pb push_back
#define mp make_pair 

using namespace std;

const int INF=INT_MAX/4;
const int MOD=1000000007;
const double EPS=1e-14;

const bool debug_flag=true;

void debug(string str){
	if(debug_flag){
		cout<<str<<endl;
	}
}

void debugs(string str){
	if(debug_flag){
		cout<<str;
	}
}

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout.precision(10);

	vector<long> A(3);
	cin>>A[0]>>A[1]>>A[2];
	
	sort(A.begin(), A.end());
	
	if(A[0]%2==0 || A[1]%2==0 || A[2]%2==0){
		cout<<0<<endl;
	}else{
		cout<<A[0]*A[1]<<endl;
	}

	return 0;
}



Measured memory_bytes: 256
n = int(input())
s = input()

ans = [0] * (n - 1)
cnt = 0
for i in range(n - 1):
    s_1 = set(s[:i + 1])
    s_2 = list(set(s[i + 1:]))

    for j in s_1:
        if j in s_2:
            cnt += 1

    ans[i] = cnt
    cnt = 0

print(max(ans))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int M=1000000007;
const int N=200005;
int i,n,dp[200005][55],p[N],k,T,ans,j;
struct str{
	int a,b;
}a[N];
bool cmp(str a,str b)
{
	return 1ll*(a.b+1)*b.a<1ll*(b.b+1)*a.a;
}
int main()
{
	scanf("%d %d",&n,&T);
	for(i=1;i<=n;++i)
	{
		scanf("%d %d",&a[i].a,&a[i].b);
		if(a[i].a==0)
		{
			p[++k]=a[i].b;
			--i,--n;
		}
	}
	sort(a+1,a+1+n,cmp);
	for(j=1;j<=50;++j)
		dp[0][j]=T+1;
	for(i=1;i<=n;++i)
		for(j=1;j<=50;++j)
			dp[i][j]=min(1ll*dp[i-1][j],dp[i-1][j-1]+1+1ll*(dp[i-1][j-1]+1)*a[i].a+a[i].b);
	sort(p+1,p+1+k);
	for(i=0;i<=30;++i)
		if(dp[n][i]<=T)
		{
			long long s=0;
			for(j=1;j<=k;++j)
			{
				s+=p[j]+1;
				if(dp[n][i]+s>T)
					break;
			}
			ans=max(ans,j-1+i);
		}
	cout<<ans;
}

Measured memory_bytes: 45056
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 400005, MAXM = 102, Mod = 1000000007, MAXLog = 20;


int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

	string s;
	cin >> s;
	vector<int> lft(s.size());
	vector<int> right(s.size());
	int lst = 0;
	for (int i = 0; i < s.size(); ++i) {
		lst = (s[i] == 'R' ? i : lst);
		lft[i] = lst;
	}
	lst = s.size() - 1;
	for (int i = s.size()-1; i >= 0; --i) {
		lst = (s[i] == 'L' ? i : lst);
		right[i] = lst;
	}


	vector<int> ans(s.size(), 0);

	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'R') {
			ans[right[i] - ((right[i] - i) & 1)]++;
		} else {
			ans[lft[i] + ((i - lft[i]) & 1)]++;
		}
	}

	for (int i = 0; i < s.size(); ++i) {
		cout << ans[i] << ' ';
	}
	cout << '\n';

	return 0;
}


Measured memory_bytes: 1872
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    int X,Y;
    cin >> X >> Y;
    int ans = 0;
    if(X == 1){
        ans += 300000;
    }else if(X == 2){
        ans += 200000;
    }else if(X == 3){
        ans += 100000;
    }
    if(Y == 1){
        ans += 300000;
    }else if(Y == 2){
        ans += 200000;
    }else if(Y == 3){
        ans += 100000;
    }
    if(X == 1 && Y == 1) ans += 400000;
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 764
import sys

input = sys.stdin.readline


def solve_K_1(N):
    S = str(N)
    d = len(S)
    return 9 * (d - 1) + int(S[0])


def solve_K_2(N):
    if N <= 99:
        return N - solve_K_1(N)
    S = str(N)
    d = len(S)
    res = 0
    res += 81 * (d - 1) * (d - 2) // 2
    res += 9 * (d - 1) * (int(S[0]) - 1)
    x = 0
    for i in range(1, d):
        if S[i] != "0":
            x = int(S[i])
            break
    i += 1
    res += x + 9 * (d - i)
    return res


def solve_K_3(N):
    if N <= 999:
        return N - solve_K_1(N) - solve_K_2(N)
    S = str(N)
    d = len(S)
    res = 0
    for n in range(3, d):
        res += 729 * (n - 1) * (n - 2) // 2
    res += 81 * (d - 1) * (d - 2) // 2 * (int(S[0]) - 1)
    res += solve_K_2(int(S[1:]))
    return res


def main():
    N = int(input())
    K = int(input())

    if K == 1:
        ans = solve_K_1(N)
    elif K == 2:
        ans = solve_K_2(N)
    elif K == 3:
        ans = solve_K_3(N)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9268
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main(){
  string s, t; cin >> s >> t;
  cout << t + s << endl;
  return 0;
}

// EOF


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N = sc.nextInt();
        // スペース区切りの整数の入力
        // int b = sc.nextInt();
        // int c = sc.nextInt();
        // 文字列の入力
        // String s = sc.next();
        // 出力
        int o = N % 1000;
        if( o == 0){
            System.out.println(o);
        }else{
            int ans = 1000 - o ;
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 35752
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

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

    if (a == b && b != c || a == c && a != b || b == c && b != a)
        cout << "Yes";
    else
        cout << "No";
    
    
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a, b, c,d,e,k;
	
	scanf("%d%d%d%d%d%d", &a,&b,&c,&d,&e,&k);
	
  if(e-a > k)
	printf(":(\n");
  else
	printf("Yay!\n");
     
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i=1; i < n; i++)
#define rev1(i, n) for(int i=n ; i > 0; i--)
#define FOR(i, a, b) for(int i=a ; i < b; i++)

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;
typedef map<ll,ll>::iterator mit;
typedef set<ll>::iterator sit;
typedef vector<ll>::iterator vit;

ll mod = 1e9 + 7;

void solve()
{
	ll n, k;
	cin>>n>>k;
	vll h(n+1, 0);
	rep1(i, n+1)
		cin>>h[i];
	vll dp(n+1, maxl);
	dp[1] = 0;
	for(ll i = 2; i <= n; i++)
	{
		for(ll j = 1; j <= k; j++)
		{
			if(i-j >= 1)
			{
				dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
			}
			else
			{
				break;
			}
		}
	}
	cout<<dp[n]<<endl;
	return;
}


int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
	ll t = 1;
	//cin>>t;
	rep(i, t)
	{
		solve();
	}
	return 0;	
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int a[4];
    rep(i,4) cin >> a[i];
    sort(a, a+4);
    int b[4] = {1, 4, 7, 9};
    string ans = "YES";
    rep(i,4) {
        if (a[i] != b[i]) ans = "NO";    
    }
    cout << ans << endl;
}

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

using namespace std;

vector<int> in(100101);
int n, k;

int tb[100101];

int dp(int i){
	if(i >= n) return 999999999;
	if(i == n-1) return 0;
	
	if(tb[i] != -1) return tb[i];
	
	int total = 999999999;
	for(int j = 1; j <= k; ++j)
		total = min(total, dp(i+j)+abs(in[i] - in[i+j]));

	return tb[i] = total;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	memset(tb,-1,sizeof(tb));
	cin >> n >> k;
	for(int i =0; i < n; ++i)
		cin >> in[i];
	
	cout << dp(0) << endl;
	
	return 0;
}

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

using namespace std;

int main() {
    string s;
    while (cin >> s) {
        int joi = 0, ioi = 0;
        for (int i = 0; i < s.size() - 2; ++i) {
            if (s.substr(i, 3) == "JOI") ++joi;
            if (s.substr(i, 3) == "IOI") ++ioi;
        }
        cout << joi << '\n';
        cout << ioi << '\n';
    }
    return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<set>
#include<map>
#define MAX 100000
using namespace std;

int main() {
	int n,f=-1; long long A[MAX],s=0;
	cin >> n;
	for (int i = 1;i <= n; i++) {
		cin >> A[i];
		f *= -1;
	    s += f * A[i];
	}
	long long x = s; cout << x << " ";
	for (int i = 1;i < n;i++) {
		x = 2*A[i] - x;
		cout << x <<" ";
	}
	cout << endl;
}

Measured memory_bytes: 2048
'use strict'
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
  const s = lines[0]
  const list = s.split('').map(s => /[ACGT]/.test(s) ? 1 : 0)
  let max = 0;
  let tmp = 0;
  list.forEach(v => {
    if (v) {
      tmp += 1
    } else {
      if (tmp !== 0) {
        max = Math.max(tmp, max);
      }
      tmp = 0;
    }
  })
  console.log(Math.max(tmp, max));
});


Measured memory_bytes: 11596
#include <iostream>
#include <algorithm>
using namespace std;
int main(){

  int N,K;
  cin >>N>>K;
  
  string s;
  cin >>s;
  
  int ans = 0;
  for(int i=0;i<N-1;i++){
  if(s[i]==s[i+1])ans++;
  }
  cout<<min(ans+2*K,N-1)<<endl;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#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;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"

int main()
{
	int n, x = 0;
	cin >> n >> x;
	int ct = 1;
	int point = 0;
	REP(i, n)
	{
		int num = 0;
		cin >> num;

		point += num;
		if (point <= x)
		{
			ct++;
		}
	}
	COUT(ct);

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7

cums = [0]
for a in A:
    cums.append(cums[-1] + a)

ans = 0
for i,a in enumerate(A):
    ans += a*(cums[-1] - cums[i+1])
    ans %= MOD
print(ans)

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

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

    int n, k;
    cin >> n >> k;

    if (k == 1) {
        cout << 1LL * n * n * n << '\n';
        return 0;
    }

    long long sol = 0;
    if (k % 2 == 0 && (k / 2) <= n) {
        int a = k / 2;
        int nr = (a + n) / k;
        sol += 1LL * nr * nr;
    }

    if (k <= n) {
        int a = k;
        int nr = n / k;
        sol += 1LL * nr * nr;
    }

    for (int a = k + 1; a <= n; a++) {
        if ((2 * a) % k != 0)
            continue;
        int st = (a + 1) / k + (((a + 1) % k) != 0);
        if (st < 1)
            continue;
        int dr = (n + a) / k;
        if (st > dr)
            continue;
        sol += 1LL * (dr - st + 1) * (dr - st + 1);
    }
    cout << sol << '\n';
    return 0;
}


Measured memory_bytes: 256
N  = int(input())
S = input()
idx_arr = [[] for _ in range(10)]
for i in range(N):
  idx_arr[int(S[i])].append(i)
cnt = 0

for j in range(1000):
  target = str("{0:03d}".format(j))
  flag = True
  idx = -1
  for k in range(len(target)):
    if [l for l in idx_arr[int(target[k])] if l > idx]!=[]:
      idx = min([l for l in idx_arr[int(target[k])] if l > idx])
    else:
      flag = False
      break
  if flag:
    cnt += 1
print(cnt)


Measured memory_bytes: 4620
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let mut v: Vec<usize> = read_vec();
    let (n, m) = (v[0], v[1]);
    let mut bridges = Vec::new();
    for _ in 0..m {
        let v = read_vec::<usize>();
        bridges.push((v[0] - 1, v[1] - 1));
    }

    let mut answers = vec![0u64; m];
    answers[m - 1] = n as u64 * (n - 1) as u64 / 2;
    let mut uft = UnionFindTree::new(n);

    for i in (1..m).rev() {
        let a = bridges[i].0;
        let b = bridges[i].1;

        if uft.same(a, b) {
            // already connected
            answers[i - 1] = answers[i];
        } else {
            answers[i - 1] = answers[i] - (uft.get_size(a) * uft.get_size(b)) as u64;
            uft.unite(a, b);
        }
    }

    for i in 0..m {
        println!("{}", answers[i]);
    }
}

#[derive(Debug, Clone)]
struct UnionFindTree {
    parent: Vec<isize>,
    size: Vec<usize>,
    height: Vec<u64>,
}

impl UnionFindTree {
    fn new(n: usize) -> UnionFindTree {
        UnionFindTree {
            parent: vec![-1; n],
            size: vec![1usize; n],
            height: vec![0u64; n],
        }
    }

    fn find(&self, index: usize) -> usize {
        let mut index = index;
        while self.parent[index] >= 0 {
            index = self.parent[index] as usize;
        }
        index
    }

    fn same(&self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn get_size(&self, x: usize) -> usize {
        self.size[self.find(x)]
    }

    fn unite(&mut self, index0: usize, index1: usize) -> bool {
        let a = self.find(index0);
        let b = self.find(index1);
        if a == b {
            false
        } else {
            if self.height[a] > self.height[b] {
                self.parent[b] = a as isize;
                self.size[a] += self.size[b];
            } else if self.height[a] < self.height[b] {
                self.parent[a] = b as isize;
                self.size[b] += self.size[a];
            } else {
                self.parent[b] = a as isize;
                self.size[a] += self.size[b];
                self.height[a] += 1;
            }
            true
        }
    }
}


Measured memory_bytes: 11516
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);

// ===

fn main() {
    let n: usize = read();
    let a: Vec<i32> = readnc();
    let b: Vec<i32> = readnc();

    let mut ans = 0;
    for k in 0..29 {
        let mask = 1<<k;
        let lower_mask = mask-1;

        let mut aa = vec![vec![]; 2];
        let mut bb = vec![vec![]; 2];
        for i in 0..n {
            let ai = if a[i] & mask == mask { 1 } else { 0 };
            let bi = if b[i] & mask == mask { 1 } else { 0 };
            aa[ai].push(a[i] & lower_mask);
            bb[bi].push(b[i] & lower_mask);
        }
        for i in 0..2 {
            aa[i].sort();
            bb[i].sort();
        }

        let mut ones = 0;
        for i in 0..2 {
            for j in 0..2 {
                let a = &aa[i];
                let b = &bb[j];
                let an = a.len();
                let bn = b.len();

                let mut notkuri = 0;
                let mut bk = bn;
                for ak in 0..an {
                    while bk >= 1 && b[bk-1] + a[ak] >= mask {
                        bk -= 1;
                    }
                    notkuri += bk;
                }
                if i ^ j == 0 {
                    ones += an * bn - notkuri;
                } else {
                    ones += notkuri;
                }
            }
        }
        if ones % 2 == 1 {
            ans |= mask;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 10232
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(){
    string a, b;
    cin >> a >> b;
    int n,t;
    t = 0;
    n = a.size();
    rep(i, n) {
        if (a[i] == b[i]) {
            t = t + 1;
        }
    }
    cout << n - t << endl;
    return 0;
}

Measured memory_bytes: 3860
#include<bits/stdc++.h>
#define int long long int
#define endl "\n"
#define arrinp(v) for(auto &i:v) cin>>i;
#define arrout(v) for(auto &i:v) cout<<i<<" ";
#define newline cout<<endl;
using namespace std;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t=1;
    // cin >> t;
    while (t--) {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int w=0,r=0;
        for(int i=0;i<s.size();i++){
            if (s[i]=='W'){
                w++;
            }
            else{
                r++;
            }
        }
        int ans=0;ans=min(w,r);
        int l=0,lr=n-1;
        int count=0;
        while(l<lr){
            if(s[l]=='W' && s[lr]=='R'){
                s[l]='R';
                s[lr]='W';
                count++;
            }
            while(s[l]=='R') l++;
            while(s[lr]=='W') lr--;
        }
        // cout<<ans<<endl;
        cout<<min(ans,count)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3716
# coding: utf-8
import sys
input = sys.stdin.readline

N = int(input())
A, B = map(int, input().split())
lst_P = list(map(int, input().split()))

a = sum(1 for x in lst_P if x<=A)
b = sum(1 for x in lst_P if A<x<=B)
c = sum(1 for x in lst_P if x>B)

ans = min(a, b, c)
print(ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int ans[10001],size=2;
bool isP(int x){
  if(x<=1)return false;
  for(int i=2;i*i<=x;i++){
    if(x%i==0)return false;
  }
  return true;
}
int main(){
  ans[1]=2;
  for(int i=3;size<10001;i++){
    if(isP(i)){
      ans[size]=ans[size-1]+i;
      size++;
    }
  }
  int n;
  while(cin>>n&&n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Pair{
	long long int a;
	long long int b;
	Pair(){
		a=0;
		b=0;
	}

	bool operator ()(const Pair x,const Pair y){
		return x.a<y.a;
	}
};
int main(){
	int a,b,t;
	cin>>a>>b>>t;
	cout<<(t/a)*b<<endl;



	return 0;
}

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

int N,M;
double L[20],a[20],b[20],ans=0;
vector<int> V;

double dis2(double x,double y){
  return (x-y)*(x-y);
}

double dis1(int i,int j){
  return dis2(L[i],L[j])+dis2(a[i],a[j])+dis2(b[i],b[j]);
}

void dfs(int n)
{
  V.push_back(n);
  if(V.size()==M){
    double dis=0;
    for(int i=0;i<M;i++){
      for(int j=i+1;j<M;j++){
	dis+=dis1(V[i],V[j]);
      }
    }
    ans=max(ans,dis);
  }
  else{
    for(int i=n+1;i<N;i++){
      dfs(i);
    }
  }
  V.pop_back();
}
int main()
{
  cin>>N>>M;
  for(int i=0;i<N;i++)cin>>L[i]>>a[i]>>b[i];
  for(int i=0;i<N;i++)dfs(i);
  printf("%.10f\n",ans);
  return 0;
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	int a[3];
	char comma,c,b;

	a[0] = a[1] = a[2] = 0;
	a[0] = 1;

	while( cin >> c >> comma >> b ){
		swap( a[c - 'A'], a[b - 'A'] );
	}

	for( int i = 0;i < 3;i++ ){
		if( a[i] ){
			cout << (char)('A' + i) << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> w(n);
	int max = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> w[i];
		max += w[i];
	}

	int min = 0;
	int cnt = 999999999;
	for(int i = 0; i < n; i++)
	{
		min += w[i];
		max -= w[i];
		if(cnt > abs(max-min)) cnt = abs(max-min);
	}

	cout << cnt << endl;

	return 0;
}


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

const ll infll=9223372036854775806;
const int inf=2147483646;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int b,c;
	string a;
	cin>>a;
	b=(a[5]-'0')*10+(a[6]-'0');
	if (b>4){
		cout<<"TBD";
	}	
	else {
		cout<<"Heisei";
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll cnt[12345];

int main(void){
	int n,p=2019,i,r=0,d=1;
	ll ans = 0ll;
	string s;
	cin >> s;
  n = s.l_ength();
	for(i=0; i<n; ++i){
		s[i] -= '0';
	}
	if(p==2 || p==5){
		for(i=0; i<n; ++i){
			if(s[i]%p==0){
				ans += (i+1);
			}
		}
		cout << ans << endl;
		return 0;
	}
	reverse(s.begin(),s.end());
	++cnt[0];
	for(i=0; i<n; ++i){
		r += s[i]*d%p;
		d *= 10; d %= p;
		r %= p;
		ans += cnt[r];
		++cnt[r];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  string s,t;
  ll a,b;
  string u;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s == u){
    a--;
  }
  if(t == u){
    b--;
  }
  cout << a << " " << b << endl;
}

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

int main(void){

    int i,sum = 0;
    
    char a[200000];

    
    scanf("%s",a);
    
    int b[200000];
    
    for(i = 0;i < 200000; i++){
        b[i] = 0;
    
    }
    i = 0;
    while(a[i] != '\0'){
        b[i] = a[i] - 48;
		//printf("%d\n", b[i]);
		sum += b[i];
		
		i++;
	}
	
	if(sum % 9 == 0){
	    printf("Yes\n");
	}
	else{
	    printf("No\n");
	}
	
}

Measured memory_bytes: 1840
#include <iostream>
#include <vector>
 
int main(int argc, char const *argv[])
{
    int n,m,l;
    std::cin >> n >> m >> l;
    std::vector<std::vector<int>> a(n,std::vector<int>(m,0));
    std::vector<std::vector<int>> b(m,std::vector<int>(l,0));
    std::vector<std::vector<long long int>> c(n,std::vector<long long int>(l,0));
    for(int i = 0 ; i < n ; i ++){
        for(int j = 0 ; j < m ; j ++){
            std::cin >>a[i][j] ;
        }
    } 
    for(int i = 0 ; i < m ; i ++){
        for(int j = 0 ; j < l ; j ++){
            std::cin >>b[i][j] ;
        }
    }
    for(int i = 0 ; i < n ; i ++){
        for(int j = 0 ; j < l ; j ++){
            c[i][j] = 0;
            for(int k = 0 ; k< m ; k ++){
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for(int i = 0 ; i < n ; i ++){
        for(int j = 0 ; j < l -1 ; j ++){
            std::cout << c[i][j] << " " ;
        }
        std::cout << c[i][l-1] << std::endl;
    }
    return 0;
}

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

using namespace std;

int main()
{
    int N,K,r=0,h;
    cin>>N>>K;
    for(int i=1; i<=N;i++){
        cin>>h;
        if(h>=K){
            r++;
        }

    }


    cout<<r;
    return 0;



}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    var sA = Array(s.length) { ' ' }
    var tA = Array(t.length) { ' ' }
    for (i in 0 until s.length) {
        sA[i] = s[i]
    }
    for (j in 0 until t.length) {
        tA[j] = t[j]
    }

    (if (judge(calc(sA), calc(tA).reversedArray())) "Yes" else "No")
            .let(::println)
}

fun calc(s: Array<Char>): Array<Char> {
    return s.sortedArray()
}

fun judge(s: Array<Char>, t: Array<Char>): Boolean {
    for (i in 0 until Math.max(s.size, t.size)) {
        if (i >= s.size) {
            return true
        }
        if (i >= t.size) {
            return false
        }
        if (s[i] < t[i]) {
            return true
        }
        if (s[i] > t[i]) {
            return false
        }
    }
    return false
}


Measured memory_bytes: 35932
#include<bits/stdc++.h>
using namespace std;
const long long N=100;
long long dp[N][N];
long long find(long long x){
    while(x){
        if(x/10==0){
            return x;
        }
        x/=10;
    }
}
int main(){
    long long n;
    cin>>n;
    for(long long i=1;i<=n;i++){
        long long h=i;
        long long a1=h%10;
        long long a2=find(h);
        dp[a2][a1]++;
    }
    long long ans=0;
    for(long long i=1;i<=9;i++){
        for(long long j=1;j<=9;j++){
            ans+=dp[i][j]*dp[j][i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<array>
#include<cstdio>
#include<bitset>
#include<vector>
#include<utility>
#include<sstream>
#include<cstring>
#include <climits>
#include <fstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include <unordered_map>
using namespace std;
#define int long long

int32_t main(){
    string s;
    cin >> s;
    int i = 0;
    string cur = "";
    while( i < s.size() ){
        if( s[i] == ',' ){
            cout << cur << " ";
            cur = "";
        }
        else cur += s[i];
        i++;
    }
    cout << cur << endl;
}

Measured memory_bytes: 3620