akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	while(cin>>s)
	{
		int f=1;
		if(s[0]!='A')
			f=0;
		for(int i=0;i<s.size();i++)
			if(s[i]!='A' && s[i]!='C')
				if(s[i]<'a' || s[i]>'z')
					f=0;
		int sum=0;
		for(int i=2;i<s.size()-1;i++)
			if(s[i]=='C')
				sum++;
		if(sum!=1)
			f=0;
		if(f==1)
			cout<<"AC"<<endl;
		else
			cout<<"WA"<<endl;
	}
}

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

static class Program
{
    static BigInteger Solve(int N, int[] A)
    {
        var x = new BigInteger(1000);
        for (int i = 0; i < N - 1; ++i)
        {
            if (A[i] < A[i + 1])
            {
                x = A[i + 1] * (x / A[i]) + x % A[i];
            }
        }
        return x;
    }

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(Solve(N, A));
    }
}


Measured memory_bytes: 27780
module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=0)}([function(r,t,e){e(1)(e(2).readFileSync("/dev/stdin","UTF-8"))},function(r,t){function e(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var e=[],n=!0,o=!1,u=void 0;try{for(var i,a=r[Symbol.iterator]();!(n=(i=a.next()).done)&&(e.push(i.value),!t||e.length!==t);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==a.return||a.return()}finally{if(o)throw u}}return e}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var t=r.split("\n"),n=e(t[0].split(" ").map(function(r){return Number(r)}),2),o=n[0],u=n[1],i=[],a=0;a<o;a++){var f=e(t[a+1].split(" ").map(function(r){return Number(r)}),2),l=f[0],c=f[1];i.push({x:l,y:c})}for(var p=[],s=0;s<u;s++){var y=e(t[s+1+o].split(" ").map(function(r){return Number(r)}),2),d=y[0],b=y[1];p.push({x:d,y:b,num:s+1})}for(var v=0;v<o;v++){for(var m=999999999,x=0,h=0;h<u;h++){(b=Math.abs(i[v].x-p[h].x)+Math.abs(i[v].y-p[h].y))<m&&(m=b,x=p[h].num)}console.log(x)}}},function(r,t){r.exports=require("fs")}]);

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

int xs[4] = {-1, 1, 0, 0};
int ys[4] = {0, 0, -1, 1};
int Ds[50][50];

int main() {
  int H,W;
  string Cs[50];
  cin >> H >> W;
  rep(i, H) cin >> Cs[i];
  queue<pair<int, int>> Q;
  Q.push(make_pair(0, 0));
  rep(i, 50) fill(Ds[i], Ds[i]+50, -1);
  Ds[0][0] = 0;
  int d;
  bool flag = false;
  while(Q.size()) {
    auto V = Q.front(); Q.pop();
    d = Ds[V.first][V.second];
    if(V.first == H-1 && V.second == W-1) {
      flag = true;
      break;
    }
    rep(i, 4) {
      int dx = xs[i]; int dy = ys[i];
      int nx = V.second+dx; int ny = V.first+dy;
      if(0<=nx && nx<W && 0<=ny && ny<H && Cs[ny][nx]=='.' && Ds[ny][nx]==-1) {
        Q.push(make_pair(ny, nx));
        Ds[ny][nx] = d+1;
      }
    }
  }
  int sum = 0;
  rep(i, H) rep(j, W) if(Cs[i][j]=='.') sum++;
  if(flag) cout << sum - d - 1<< endl;
  else cout << -1 << endl;
  return 0;
}


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


int main(){
    int x,y,z;
    cin >> x >> y >> z;
    int tmp=x-y-z;
    int cnt=1;
    while(1){
        if(tmp-y-2*z>=0){tmp=tmp-z-y;cnt++;}
        else break;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <set>
#include <locale>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;
//cout << fixed << setprecision(6);
//cout << setfill('0') << right << setw(2);

ll n, a[5], rest, ans = 0;

void calc(int i) {
	if (i == 0) return;
	ll tmp = ans + 1;
	if (a[i - 1] > a[i]) {
		rest = n;
		ans = i;
	}
	ll carry_time = (rest + a[i] - 1) / a[i];
	ans += carry_time;
	ans = max(tmp, ans);
	rest -= (carry_time - 1) * a[i];
}

int main() {
	cin >> n;
	rep(i, 5) cin >> a[i];
	ans += (n + a[0] - 1) / a[0];
	rest = n - ((n + a[0] - 1) / a[0] - 1) * a[0];
	rep(i, 5) calc(i);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


i64 T, n, m, to[10101];
vector<int> v[404];
vector<P> G[404];
vector<vector<int>> dist(404, vector<int>(404, INF));
vector<int> route[404][404];
i64 now = 1, next_t = 0;
i64 have[404] = {0};

void floyd(){
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 1; k <= n; k++){
				if(dist[j][k] > dist[j][i] + dist[i][k]){
					//route[j][k] = route[j][i]+route[i][k];
					route[j][k] = route[j][i];
					route[j][k].insert(route[j][k].end(),route[i][k].begin(),route[i][k].end());
					dist[j][k] = dist[j][i] + dist[i][k];
				}
			}
		}
	}
}

P choice_next(int start, i64 t){
	i64 ma = -1, k = -1;
	for(int i = 2; i <= n; i++){
		if(!have[i]) continue;
		if(dist[start][i] >= T-t) continue;
		i64 cnt = 0;
		for(int j = 0; j < route[start][i].size(); j++){
			cnt += have[route[start][i][j]];
		}
		if(ma < cnt * 333 / (dist[start][i])){
			ma = cnt;
			k = i;
		}
	}
	return P(ma, k);
}

int Move(int start, i64 next_t){
	P choice = choice_next(start, next_t);
	i64 ma = choice.first, k = choice.second;
	if(ma >= 333){
		int npos = route[start][k][0];
		have[npos] = 0;
		for(int i = 0; i < dist[now][npos]; i++){
			if(next_t >= T) break;
			next_t++;
			cout << npos << endl;
		}
		now = npos;
		next_t = Move(now, next_t);
		
		return next_t;
	}
	for(int i = route[1][now].size()-2; i >= -1; i = route[1][now].size()-2){
		int npos;
		if(i == -1) npos = 1;
		else npos = route[1][now][i];
		for(int j = 0; j < dist[now][npos]; j++){
			if(next_t >= T) break;
			next_t++;
			cout << npos << endl;
		}
		now = npos;
	}
	return next_t;
}

int main(){
	cin >> n >> m;
	for(int i = 0; i <= n; i++){
		dist[i][i] = 0;
	}
	for(int i = 0; i < m; i++){
		int a,b,c;
		cin >> a >> b >> c;
		G[a].push_back(P(b,c));
		G[b].push_back(P(a,c));
		dist[a][b] = c;
		dist[b][a] = c;
		route[a][b].push_back(b);
		route[b][a].push_back(a);
	}
	cin >> T;
	for(int i = 0; i < T; i++){
		int a,b,c;
		cin >> a;
		if(a){
			cin >> b >> c;
			v[c].push_back(i);
			to[i] = c;
		}
	}
	
	floyd();
	
	for(i64 t = 0; t < T; t++){
		if(now == 1) have[to[t]] += T*T - t*t;
		if(next_t > t) continue;
		next_t = Move(1, t);
		if(next_t == t){
			cout << -1 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 27136
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){
    
    int N,K; cin>>N>>K;
    vector<ll> a(N+1,0),p(N+1,0);
    REP(i,N)cin>>a[i+1];
    REP(i,N)p[i+1]=(a[i+1]>=0?a[i+1]:0);
    REP(i,N)a[i+1]=a[i]+a[i+1];
    REP(i,N)p[i+1]=p[i]+p[i+1];
    
    ll ans=0;
    for(int i=K;i<=N;i++){
        ans=max(ans,p[N]-p[i]+p[i-K]);
        ans=max(ans,p[N]-p[i]+p[i-K]+a[i]-a[i-K]);
    }
    
    cout<<ans<<endl;
    
    return 0;
}




Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n, k,d;
	cin >> n >> k;
	int sn[102], sk[102] = { 0 };
	for (int i = 1; i <= k; i++) {
		cin >> d;
		for (int i = 0; i < d; i++) {
			cin >> sn[i];
			sk[sn[i]] = 1;
		}
	}
	int sum = 0;
	for (int i = 1; i <= n; i++)
		if (!sk[i]) sum++;
	cout << sum;
	return 0;
}

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

int main() {
  int N, T;
  vector<int> t;

  cin >> N >> T;
  t.resize(N);

  for (int i = 0; i < N; i++)
    cin >> t[i];

  int64_t ans = 0;
  for (int i = 1; i < N; i++) {
    if (t[i] - t[i-1] >= T)
      ans += T;
    else
      ans += t[i] - t[i-1];
  }
  ans += T;

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin >> c;
    cout << (('a' <= c && c <= 'z') ? "a" : "A") << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);

  int Alice = 0, Bob = 0;
  int d;
  for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for (int i = 0; i < N; i++) {
      if(i%2 == 0) {
          Alice += vec.at(i);
      }
      else if(i%2 == 1) {
          Bob += vec.at(i);
      }
  }

  d = Alice - Bob;

  cout << d << endl;
}

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

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

int32_t main()
{
	int n, m;
	cin >> n >> m;
	vector<string> in(n);
	rep(i, n)
	{
	    cin >> in[i];
	}
	int dp[n][m];
	memset(dp, 0, sizeof dp);
	dp[0][0] = 1;
	rep(i, n)
	{
	    rep(j, m)
	    {
	        if(in[i][j] == '#')
	            continue;
	        if(i-1 >= 0)
	            dp[i][j] += dp[i-1][j];
	        if(j-1 >= 0)
	            dp[i][j] += dp[i][j-1];
	        dp[i][j] %= mod;
	    }
	}
// 	rep(i, n)
// 	{
// 	    rep(j, m)
// 	        cout << dp[i][j] << " ";
// 	    cout << "\n";
// 	}
	cout << dp[n-1][m-1];
  	return 0;
}

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


#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pair < int , int > pii


int n, ans = 100;


int two(int x){
	int ret = 0;
	while(x%2 == 0){
		x /= 2;
		ret++;
	}
	return ret;
}

int main(){


	cin >> n;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		ans = min(ans, two(x));
	}

	cout << ans << endl;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll a, b;

	cin >> a >> b;

	if (b % a) {
		cout << b - a << endl;
	}
	else {
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program
{
    static void Main()
    {
        long[] inputs = Console.ReadLine().Split(' ')
                                    .Select(val => long.Parse(val))
                                    .ToArray();
        int n = (int)inputs[0];
        long x = inputs[1];
        long[] a = Console.ReadLine().Split(' ')
                                     .Select(val => long.Parse(val))
                                     .ToArray();
        long cnt = 0;
        if(a[0] > x)
        {
            long dif = a[0] - x;
            a[0] = x;
            cnt += dif;
        }
        for(int i = 0; i < n - 1; i++)
        {
            long dif = a[i] + a[i + 1] - x;
            if(dif > 0)
            {
                a[i + 1] -= dif;
                cnt += dif;
            }
        }
        Console.WriteLine(cnt);
    }
}


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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false);
   int N;
   cin >> N;
   vector<int> A(N + 1);
   vector<int> B(N + 1);
   for (int i = 0; i < N; ++i) cin >> A[i], A[N] ^= A[i];
   for (int i = 0; i < N; ++i) cin >> B[i], B[N] ^= B[i];
   {
      vector<int> sortedA(A.begin(), A.end());
      vector<int> sortedB(B.begin(), B.end());
      sort(sortedA.begin(), sortedA.end());
      sort(sortedB.begin(), sortedB.end());
      if (sortedA != sortedB) {
         cout << "-1\n";
         return 0;
      }
   }
   N++;
   vector<int> as(A.begin(), A.end());
   sort(as.begin(), as.end());
   as.resize(unique(as.begin(), as.end()) - as.begin());
   int M = as.size();
   vector<int> root(M);
   iota(root.begin(), root.end(), 0);
   function<int(int)> getRoot = [&](int v) {
      if (v != root[v]) {
         root[v] = getRoot(root[v]);
      }
      return root[v];
   };
   auto merge = [&](int v, int u) {
      v = getRoot(v);
      u = getRoot(u);
      root[u] = v;
   };
   int ans = -2;
   for (int i = 0; i < N; ++i) {
      A[i] = lower_bound(as.begin(), as.end(), A[i]) - as.begin();
      B[i] = lower_bound(as.begin(), as.end(), B[i]) - as.begin();
      if (A[i] != B[i] || i == N - 1) {
         merge(A[i], B[i]);
         ans++;
      }
   }
   vector<bool> flag(M);
   for (int i = 0; i < N; ++i) {
      if (A[i] != B[i] || i == N - 1) {
         flag[getRoot(A[i])] = true;
      }
   }
   for (int i = 0; i < M; ++i) ans += flag[i];
   cout << ans << "\n";
}


Measured memory_bytes: 1904
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int prev = 0;
        long count = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            count += (x + prev) / 2;
            if (x == 0) {
                prev = 0;
            } else {
                prev = (x + prev) % 2;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 48240
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <climits>
#include <map>

using namespace std;

vector <int> edges[100000];
bool fennecs[100000];
bool decided[100000];
bool used[100000];
int N;
int dfs(int cur, int depth){
  used[cur] = true;
  if(cur == N - 1){
    fennecs[N - 1] = false;
    decided[N - 1] = true;
    return depth;
  }
  int ret = -1;
  for(int i = 0; i < edges[cur].size(); i++){
    int next = edges[cur][i];
    if(used[next]){
      continue;
    }
    int tmp_ret = dfs(next, depth + 1);
    if(tmp_ret > 0){
      ret = tmp_ret;
      if(depth <= ret / 2){
        fennecs[cur] = true;
        decided[cur] = true;
      } else {
        fennecs[cur] = false;
        decided[cur] = true;
      }
    }
  }
  return ret;
}

void dfs_possession(int cur, int is_fennecs){
  decided[cur] = true;
  fennecs[cur] = is_fennecs;
  for(int i = 0;  i < edges[cur].size(); i++){
    int next = edges[cur][i];
    if(decided[next]){
      continue;
    }
    dfs_possession(next, is_fennecs);
  }
}

int main(){
  cin >> N;
  for(int i = 0; i < N - 1; i++){
    int a;
    int b;
    cin >> a >> b;
    edges[a - 1].push_back(b - 1);
    edges[b - 1].push_back(a - 1);
  }

  int N_dist = dfs(0, 0);
  for(int i = 0; i < N; i++){
    if(decided[i]){
      dfs_possession(i, fennecs[i]);
    }
  }

  int fennecs_count = 0;
  for(int i = 0; i < N; i++){
    if(fennecs[i]){
      fennecs_count ++;
    }
  }


  if(fennecs_count > N - fennecs_count){
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }
  return 0;
}


Measured memory_bytes: 13824
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int l=sc.nextInt();
        
        int [][] a=new int[n][m];
        int [][] b=new int[m][l];
        long[][] x=new long[n][l];
        
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                a[i][j]=sc.nextInt();
            }
        }
        for(int i=0;i<m;i++){
            for(int j=0;j<l;j++){
                b[i][j]=sc.nextInt();
            }
        }
        
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                for(int k=0;k<l;k++){
                    x[i][k]+=a[i][j]*b[j][k];
                }
            }
        }
        
        for(int i=0;i<n;i++){
            for(int j=0;j<l;j++){
                if(j!=l-1){
                	System.out.print(x[i][j]+" ");
            	}else{
                    System.out.print(x[i][j]);
                }
            }
            System.out.println();
        }
        sc.close();
    }
}



Measured memory_bytes: 54788
sx,sy,tx,ty=map(int,input().split())

s='U'*(ty-sy)
s+='R'*(tx-sx)
s+='D'*(ty-sy)
s+='L'*(tx-sx+1)
s+='U'*(ty-sy+1)
s+='R'*(tx-sx+1)
s+='DR'
s+='D'*(ty-sy+1)
s+='L'*(tx-sx+1)
s+='U'

print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int n; cin >> n;
  struct Block { int w, s, v; };
  vector<Block> bs(n);
  REP (i, n) {
    int w, s, v; cin >> w >> s >> v;
    bs[i] = {w, s, v};
  }
  sort(ALL(bs), [](Block& b1, Block& b2) { return b1.w + b1.s < b2.w + b2.s; });
  const int W = 1e7;
  vector<int> dp(W + 1);
  for (Block b: bs) {
    for (int w = b.s; w >= 0; w--) {
      chmax(dp[w + b.w], dp[w] + b.v);
    }
  }
  cout << *max_element(ALL(dp)) << endl;
}


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

int main()
{
	// 入力
	int A, B;
	cin >> A >> B;
	
	// AとBの偶数、奇数が異なるとき
	if (A % 2 != B % 2)
	{
		cout << "IMPOSSIBLE" << endl;
	}
	// AとBの偶数、奇数が等しい場合
	else {
		int answer = (A + B) / 2;
		cout << answer << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] x = new int[2];
		int[] y = new int[2];
		int gcd = 1;
		int lcm;
		int temp;
		while (scan.hasNext()) {
			for (int i = 0; i < x.length; i++) {
				x[i] = scan.nextInt();
				y[i]=x[i];
			}
			Arrays.sort(x);
			while(true){
			if(x[0]==0){
				gcd=x[1];
				break;
			}
			else{
				temp=x[0];
				x[0]=x[1]%x[0];
				x[1]=temp;
			}
			}

			y[0] /= gcd;
			y[1] /= gcd;
			lcm = y[0] * y[1] * gcd;
			System.out.println(gcd + " " + lcm);
		}
	}
}

Measured memory_bytes: 17220
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, Y = map(int, input().split())
    ret = [-1] * 3
    for x in range(N+1):
        tY = Y - 10000 * x
        tN = N - x
        for y in range(tN+1):
            z = tN - y
            if tY == y * 5000 + z * 1000:
                ret = [x, y, z]
                break
    print(*ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<stdio.h>

int main()
{
	int a,b,n,m,c;
	while((scanf("%d %d",&a,&b))!=EOF){
	m=a+b;
	n=1;
	c=0;
	while(1){
		if(m%n==m)
			break;
		c++;
		n=n*10;
	}
	printf("%d\n",c);
	}
	return 0;
}

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

typedef long long ll;

const int M = (int)1e5;
const int N = (int)1e4;
const int inf = 0x3f3f3f3f;
const ll mod = (ll)1e9 + 7;

int n, m, cnt;
int head[M + 5];
struct node
{
    int v, nx;
}Edge[M * 2 + 5];

int h[M + 5];
int can[M + 5];

void init()
{
    cnt = 0;
    for(int i = 1; i <= n; ++i)
    {
        head[i] = -1;
        can[i] = -1;
    }
}

void add(int u, int v)
{
    Edge[cnt].v = v;
    Edge[cnt].nx = head[u];
    head[u] = cnt++;
}

void work(int u)
{
    for(int i = head[u]; ~i; i = Edge[i].nx)
    {
        int v = Edge[i].v;
        if(h[u] <= h[v])
        {
            can[u] = 0;
            return;
        }
    }
    can[u] = 1;
    for(int i = head[u]; ~i; i = Edge[i].nx)
    {
        int v = Edge[i].v;
        can[v] = 0;
    }
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    scanf("%d %d", &n, &m);
    init();
    for(int i = 1; i <= n; ++i) scanf("%d", &h[i]);
    for(int i = 1, u, v; i <= m; ++i) scanf("%d %d", &u, &v), add(u, v), add(v, u);
    for(int i = 1; i <= n; ++i) if(!~can[i]) work(i);
    int res = 0; for(int i = 1; i <= n; ++i) res += can[i];
    printf("%d\n", res);
    return 0;
}


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

using namespace std;

#define EPS 1e-7
#define equals(a,b) (fabs(a-b) < EPS)

struct Point{
  double x,y,z;

  double getDist(const Point &p){
    return sqrt(pow(x-p.x,2)+pow(y-p.y,2)+pow(z-p.z,2));
  }
};

int main(){
  int Tc,N;
  double QR,RP,PQ;
  cin >> Tc;
  while(Tc--){
    cin >> QR >> RP >> PQ >> N;
    Point p[N];
    for(int i = 0 ; i < N ; i++){
      cin >> p[i].x >> p[i].y >> p[i].z;
    }
    double qr,rp,pq;
    for(int i = 0 ; i < N ; i++){
      for(int j = 0 ; j < N ; j++){
        if(i == j){ continue; }
        for(int k = 0 ; k < N ; k++){
          if(i == k || j == k){ continue; }
          qr = p[j].getDist(p[k]);
          rp = p[k].getDist(p[i]);
          pq = p[i].getDist(p[j]);
          if(equals(QR/qr,RP/rp) && equals(RP/rp,PQ/pq)){
            cout << i+1 << " " << j+1 << " " << k+1 << endl;
            goto end;
          }
        }
      }
    }
  end:;
  }
  return 0;
}

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

int main(){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }
    int a = c[0][0] + c[1][1] + c[2][2];
    int b = c[1][0] + c[2][1] + c[0][2];
    int x = c[2][0] + c[0][1] + c[1][2];
    if(a==b && b==x) cout <<"Yes" <<"\n";
    else cout <<"No" <<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x[ohara],y,sum,pos,k,t[ohara],p[ohara];
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>t[i];
    cin>>m;
    rep(i,m){
        cin>>p[i]>>x[i];
    }
    rep(i,m){
        ans=0;
        rep(j,n){
            if(p[i]-1==j)ans+=x[i];
            else ans+=t[j];
        }
        Cout(ans);
    }
    return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
//#include <iomanip>

using namespace std;


int main()
{
	int N;
	cin >> N;
	vector<pair<int, int>> Works(N);
	for (int i = 0; i < N; i++)
	{
		int A, B;
		cin >> A >> B;
		Works.at(i) = make_pair(B, A);
	}
	sort(Works.begin(), Works.end());

	bool yes = true;
	long long time = 0;
	for (int i = 0; i < N; i++)
	{
		time += Works.at(i).second;

		if (time > Works.at(i).first)
		{
			yes = false;
			break;
		}
	}

	cout << (yes ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 1792
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, k;
	cin >> n >> k;
	int x;
	REP(i, n){
		cin >> x;
		ans += 2 * min(abs(x-0), abs(x-k));
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long LL;

template<typename T> void Chkmax(T &x, const T &y) { x = x > y ? x : y; }
template<typename T> void Chkmin(T &x, const T &y) { x = x < y ? x : y; }

namespace io
{
	const int maxb = 1 << 15;
	char b[maxb], *s = b, *t = b;
	bool Getchar(char &ch)
	{
		return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s ++;
	}
}

int Getint()
{
	using namespace io;
	char ch;
	while (Getchar(ch) && (ch < '0' || ch > '9'));
	int s = ch - '0';
	while (Getchar(ch) && ch >= '0' && ch <= '9')
		s = s * 10 + ch - '0';
	return s;
}

const int maxn = 2e5 + 10;

struct Node
{
	int x, y;
	Node() {}
	Node(int x, int y) : x(min(x, y)), y(max(x, y)) {}
	bool operator < (const Node &a) const { return x < a.x; }
} a[maxn];

int main()
{
	int n = Getint();
	for (int i = 0; i < n; ++ i)
		a[i] = Node(Getint(), Getint());
	if (n == 1)
	{
		puts("0");
		return 0;
	}
	sort(a, a + n);
	int Mx = 0, posMx;
	for (int i = 0; i < n; ++ i)
		if (a[i].y >= Mx)
		{
			Mx = a[i].y;
			posMx = i;
		}
	int Rmax = Mx, Rmin = a[0].y, Bmax = a[posMx].x, Bmin = a[0].x;
	for (int i = 1; i < n; ++ i)
	{
		if (i == posMx) continue;
		Chkmin(Rmin, a[i].y);
		Chkmax(Bmax, a[i].x);
	}
	LL ans = 1ll * (Rmax - Rmin) * (Bmax - Bmin);
	if (!posMx)
	{
		printf("%lld\n", ans);
		return 0;
	}
	Rmax = Mx, Rmin = a[0].x, Bmax = max(max(a[0].y, a[posMx].x), a[n - 1].x), Bmin = min(min(a[0].y, a[posMx].x), a[1].x);
	Chkmin(ans, 1ll * (Rmax - Rmin) * (Bmax - Bmin));
	int preMn = a[0].y;
	a[n].y = Mx;
	for (int i = 1; i < n; ++ i)
	{
		if (i == posMx)
		{
			Chkmin(preMn, a[i].x);
			continue;
		}
		Chkmin(preMn, a[i].y);
		Chkmax(Bmax, a[i].y);
		Bmin = min(preMn, a[i + 1].x);
		Chkmin(ans, 1ll * (Rmax - Rmin) * (Bmax - Bmin));
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
  int n,ac = 0,wa = 0,tle = 0,re = 0;
  cin >> n;
  rep(i,0,n){
    string s;
    cin >> s;
    if(s == "AC") ac++;
    if(s == "WA") wa++;
    if(s == "TLE") tle++;
    if(s == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

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

void solve(long long K){
    if (K % 2) cout << (K / 2) * (K / 2 + 1) << '\n';
    else cout << (K / 2) * (K / 2) << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int N,M,C,count=0;
	int a[101],b[101],c[101];
	scanf("%d %d %d",&N,&M,&C);
	for(int i=0;i<M;i++) scanf("%d",&a[i]);
	for(int i=0;i<N;i++){
		int tmp=0;
		for(int j=0;j<M;j++){
			scanf("%d",&b[j]);
			c[j]=a[j]*b[j];
			tmp+=c[j];
		}
		if(tmp+C>0) count++;
		
	}
	printf("%d\n",count);
 	return 0;
 }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <ios>
#include <iomanip>
#define ll long long
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> P(m),Y(m);
    for(int i=0;i<m;i++){
        cin>>P[i]>>Y[i];
        P[i]--;
    }
    vector<vector<int>>vals(n);
    for(int i=0;i<m;i++){
        vals[P[i]].push_back(Y[i]);
    }
    for(int i=0;i<n;i++){
        sort(vals[i].begin(),vals[i].end());
        vals[i].erase(unique(vals[i].begin(),vals[i].end()),vals[i].end());
    }
    for(int i=0;i<m;i++){
        int v=P[i];
        cout<<setfill('0')<<right<<setw(6)<<v+1;

        int id=lower_bound(vals[v].begin(),vals[v].end(),Y[i])-vals[v].begin();
        cout<<setfill('0')<<right<<setw(6)<<id+1;
        cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
using namespace std;
int main()
{
	int i,j,k,a,b,c,n,ans=0;
	cin>>a>>b>>c>>n;
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				if(i*500+j*100+k*50==n)
					ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(0, min(b, d) - max(a, c)) << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int read()
{
	char ch=getchar();int f=0,x=1;
	while(ch<'0'||ch>'9'){if(ch=='-') x=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){f=(f<<1)+(f<<3)+ch-'0';ch=getchar();}
	return f*x;
}
int n,a[100005];
int main()
{
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	cout<<a[n/2+1]-a[n/2];
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            if (a == 0 && b == 0) break;
            for (int i = 0; i < a; i++) {
                for (int j = 0; j < b; j++) {
                    if (i == 0 || i == a - 1 || j == 0 || j == b - 1) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                    if (j != b - 1) {
                    } else {
                        System.out.println();
                    }
                }
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 36996
import kotlin.math.max
import kotlin.math.min

fun main() {
    val builder = StringBuilder()

    var (a, b, c, k) = readInputLine().split(" ").map { it.toInt() }

    var ans = 0
    ans += min(a, k)
    k = max(0, k - a)

    k = max(0, k - b)

    ans -= k

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36436
//..verified against AOJ GRL_4_B
#include <bits/stdc++.h>
using namespace std;

class Graph {
private:
  int V;
  int E;
  vector <vector <int>> adj;
public:
  Graph(int n, int m);
  void addEdge(int s, int t);
  void topologicalSort();
};

Graph::Graph(int n, int m) {
  this->V = n;
  this->E = m;
  adj.resize(n);
}

void Graph::addEdge(int s, int t) {
  adj[s].push_back(t);
}

void Graph::topologicalSort() {
  vector <int> order;
  vector <int> deg(V, 0);
  for (int u = 0; u < V; u++) {
    for (int v : adj[u]) {
      deg[v]++;
    } 
  }
  queue <int> from;
  for (int u = 0; u < V; u++) {
    if (deg[u] == 0) {
      from.push(u);
    } 
  } 
  while (!from.empty()) {
    int u = from.front();
    from.pop();
    order.emplace_back(u);
    for (int v : adj[u]) {
      if (deg[v] == 1) {
        from.push(v);
      }
      deg[v]--;
    } 
  }
  if ((int) order.size() != V) { //Cycle present
    //TODO
  }
  
  for (int node : order) cout << node << " ";
  cout << endl;
}

int main() {
  int n, m;
  cin >> n >> m;
  Graph g(n, m);
  int s, t;
  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    g.addEdge(s, t);
  } 
  g.topologicalSort();
  return 0;
} 


Measured memory_bytes: 3704
#include<stdio.h>

int main(void)
{
    int H[300], W[300], n=0, i, j, k;
    
    while(1){
        scanf("%d %d", &H[n], &W[n]);
        if(H[n]==0 && W[n]==0){
            break;
        }
        n++;
    }
    
    for(k=0; k<n; k++){
        for(j=0; j<W[k]; j++){
            putchar('#');
        }
        putchar('\n');
        for(i=1; i<H[k]-1; i++){
            putchar('#');
            for(j=1; j<W[k]-1; j++){
                putchar('.');
            }
            printf("#\n");
        }
       for(j=0; j<W[k]; j++){
                putchar('#');
        }
        putchar('\n');
        putchar('\n');
    }
    
    return 0;
}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin >>s;
  if (s==2)cout << 4 <<endl;
  else if(s==1) cout << 4 <<endl;
  else {
    int count=0;
    while(s!=4){
      if(s%2==0)s/=2;
      else s=3*s+1;
      count++;
    }
    cout << count+4 <<endl;
  
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main(){
char s[10001];
cin.getline(s,10000);
int c = strlen(s);
while(c--)
if('a' <= s[c] && s[c] <= 'z')
s[c] += 'A' - 'a';
cout << s << "\n";
return 0;
}

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

int solve()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  vector<int> b(n + 1);
  while (k--)
  {
    for (int i = 0; i <= n; i++)
    {
      b[i] = 0;
    }
    for (int i = 0; i < n; i++)
    {
      int from = max(i - a[i], 0);
      int to = min(i + a[i], n - 1);
      b[from] += 1;
      b[to + 1] -= 1;
    }
    // for (int i = 0; i <= n; i++)
    // {
    //   cout << b[i] << " ";
    // }
    // cout << endl;
    bool changed = false;
    for (int i = 0; i < n; i++)
    {
      if (a[i] != b[i])
        changed = true;
      a[i] = b[i];
      b[i + 1] += b[i];
    }
    if (!changed)
    {
      break;
    }
  }
  for (int i = 0; i < n; i++)
  {
    if (i > 0)
    {
      cout << " ";
    }
    cout << a[i];
  }
  cout << '\n';
  return 0;
}

signed main()
{
  solve();
}

Measured memory_bytes: 4764
#include <stdio.h>

int main(void)
{
    int pasta[3];
    int juice[2];
    int pastaMin;
    int juiceMin;
    int i;

    pastaMin = 2001;
    for (i = 0; i < 3; i++){
        scanf("%d", &pasta[i]);
        if (pastaMin > pasta[i]){
            pastaMin = pasta[i];
        }
    }

    juiceMin = 2001;
    for (i = 0; i < 2; i++){
        scanf("%d", &juice[i]);
        if (juiceMin > juice[i]){
            juiceMin = juice[i];
        }
    }

    printf("%d\n", pastaMin + juiceMin - 50);

    return (0);
}

Measured memory_bytes: 0
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 1;
        int max = sc.nextInt();
        int min = 0;
        
        for(int i = 0;i < n-1;i++){
            int p = sc.nextInt();
            if(i == 0){
                min = p;
                if(max < min){
                    int tmp = min;
                    min = max;
                    max = tmp;
                }
            }

            if(max >= p && min >= p){
                ans++;
            }
            if(p > max)
                max = p;
            if(p < min)
                min = p;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 61404
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
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; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<int> p(300000);
	vector<ll> dp(n);
	dp[0] = 1;
	p[a[0]] = 1;
	for (int i = 1; i < n; i++) {
		dp[i] = dp[i - 1];
		if (a[i] != a[i - 1]) {
			dp[i] += p[a[i]];
			dp[i] %= mod;
			p[a[i]] = dp[i];
		}
	}
	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

ll dp[100003];
const int max_n=1000001;
bool is_prime[max_n];
int sieve(int n){
    int p=0;
    rep(i,n+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    FOR(i,2,n+1){
        if(is_prime[i]){
            for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
        }
    }
    return p;
}
int q[100001];
const int mod=1000000007;
int main(){
    int n;
    cin>>n;
    sieve(1000000);
    dp[0]=1;
    rep(i,n) cin>>q[i];
    rep(i,n){
        if(i+2<=n&&is_prime[q[i]]&&(i+2==n||q[i+2]>q[i])){
            dp[i+2]+=dp[i];
            dp[i+2]%=mod;
        }
        if(is_prime[q[i]]&&(i+1==n||q[i+1]>q[i])){
            dp[i+1]+=dp[i];
            dp[i+1]%=mod;
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

ll dp[5050][5050] = {0};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<ll, ll>> p(n);
  for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end(), [](const pair<ll, ll> &l, const pair<ll, ll> &r) {
    if (l.first + l.second == r.first + r.second)
      return l.second < r.second;
    return l.first + l.second < r.first + r.second;
  });
  ll INF = 2000000000000000000LL;
  for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = INF;
  dp[0][0] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      if (dp[i][j] <= p[i].first) {
        dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + p[i].second);
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    if (dp[n][i] < INF) ans = i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 199040
#include <stdio.h>
#include <string.h>

int main(void) {

	char word[1001],word2[1001],order[1001],change[1001];
	int count = 0, number1 = 0,number2 = 0,k,t;
	for (int i = 0; i < 1001; i++) {
		word[i] = 0;
		order[i] = 0;
		word2[i] = 0;
		change[i] = 0;
	} 
	scanf("%s", word);
	scanf("%d", &count);
	for (int i = 0; i < count; i++) {
		scanf("%s %d %d", order, &number1,&number2);
		if(strcmp(order, "print") == 0) {
			for (k = number1; k <= number2; k++) {
				printf("%c", word[k]);
			}
			printf("\n");
		}
		else if (strcmp(order, "reverse") == 0) {
			t = number1;
			for (k = number1; k <= number2; k++) {
				change[k] = word[k];
			}
			for (k = number2; k >= number1; k--) {
				word[k] = change[t];
				t += 1;
			}
		}
		else if (strcmp(order, "replace") == 0) {
			t = 0;
			scanf("%s", word2);
			for (k = number1; k <= number2; k++) {
				word[k] = word2[t];
				t += 1;
			}

		}

	}

	return 0;
}


Measured memory_bytes: 2140
n=int(input())
zot=lambda x:0 if x==0 else (x+1)%2+1
A=[int(input()) for i in range(n)]
D=[0,0,0,0,0]

for a in A:
  d0 = D[0] + a
  d1 = min(D[:2])+ [2,1,0][zot(a)]
  d2 = min(D[:3])+ [1,0,1][zot(a)]
  d3 = min(D[:4])+ [2,1,0][zot(a)]
  d4 = min(D) + a
  D=[d0,d1,d2,d3,d4]
print(min(D))

Measured memory_bytes: 11040
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int c = scan.nextInt();
        if(c <n+m || c == n+m){
        System.out.println("Yes");
        }else{
        System.out.println("No");
        }
    }

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long MOD = 998244353;

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

    int n, m;
    cin >> n >> m;
    int ans = 0;
    if (n > 1) ans += (n * (n - 1)) / 2;
    if (m > 1) ans += (m * (m - 1)) / 2;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#B
N = int(input())
S = list(str(input()))
A = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
ans = ""
for s in S:
    ans+=A[(A.index(s)+N)%26]
print(ans)




Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#define F 100000
using namespace std;
int s[F],e[F],q;
bool c[F];
void ADD(bool t,bool r){
	if(t){
		if(c[q-1]!=r){
			if(q==1)e[0]++,c[0]=r;
			else{
			e[q-2]=e[q-1]+1;
			q--;
			}
		}
		else e[q-1]++;
		return;
	}
	if(c[q-1]!=r)s[q]=e[q-1],e[q]=s[q]+1,c[q]=r,q++;
	else e[q-1]++;
	return;
}
int main(){
	int n,t;
	while(true){
	cin>>n;
	if(!n)break;
	cin>>t;
	s[0]=0,e[0]=1,c[0]=t;
	q=1;
	for(int i=1;i<n;i++){
		cin>>t;
		ADD(i%2,t);
	}
	int ans=0;
	for(int i=0;i<q;i++)if(!c[i])ans+=e[i]-s[i];
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2992
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> map;
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        map[a]++;
        map[b]++;
    }

    REP(i, n+1) {
        if (i < 1) continue;
        cout << map[i] << endl;
    }
}


Measured memory_bytes: 256
#2:52
import sys

sys.setrecursionlimit(10000000)


dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]



#左上からせめて深さ優先で探索する問題
while True:
    # 地図作る
    width,hight = map(int,input().split())
    if width ==0 :
        break
    d =[]
    for _ in range(hight):
        d.append(list(input()))
    
    def dfs(x, y):
    # いまたどり着いたはずなので1に塗りつぶす
        d[y][x]="d"

    #4方向ループ
    #あくまで方向の表し方dxは
        for i in range(4):
            ny = y + dx[i]
            nx = x + dy[i]

        #行ったことがなくって、迷路の範囲内で、障害物がなければ、進む
            if 0 <= ny and ny < hight \
              and 0 <= nx and nx < width \
              and d[ny][nx] == ".":
                dfs(nx,ny) 

    


    for y in range(hight):
        for x in range(width):
            if d[y][x] == "@":
                dfs(x,y)
    
    sum = 0 
    for _ in range(hight):
        sum = sum + d[_].count('d')
    print(sum)





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

using namespace std;

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

const double PI=3.14159265358979323846;

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

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

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


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

    int n;
    cin >> n;
    string s;
    cin >> s;

    vs64 cnt(26, 0);
    rep (i, n)
    {
        ++cnt[s[i] - 'a'];
    }

    s64 ans = 1;
    rep (i, 26)
    {
        if (cnt[i]) ans = (ans * (cnt[i] + 1)) % MOD;
    }
    ans = (ans + (MOD - 1)) % MOD;

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



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
const ll MOD=1000000007;
ll a,b,c,n,ans=3;
void Main(){
    cin>>n;
    vector<ll> a(n);
    For(i,0,n){
        cin>>a[i];
        if(a[i]>i){
            cout<<0<<endl;
            return;
        }
    }
    ll dp[n+10];
    dp[0]=1;
    ll num[3]={1,0,0};//それまでの人数
    For(i,1,n){
        int cnt=0;
        For(j,0,3){
            if(num[j]==a[i]){
                cnt++;
            }
        }
        For(j,0,3){
            if(num[j]==a[i]){
                num[j]++;
                break;
            }
        }        
        ans*=cnt;
        ans%=MOD;
    }
    cout<<ans%MOD<<endl;
}
main(){
    Main();
}

Measured memory_bytes: 1024