akhauriyash/Code-Regression huggingface dataset:
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n, l;
	string[] s;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		auto ar = readln().strip().split().map!(to!int).array();
		n = ar[0];
		l = ar[1];
        s.length = n;
        foreach (i; 0..n)
            s[i] = readln().strip();
	}
}

auto main2(Input* input)
{
	with (input)
	{
		s.sort();
        return s.join();
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`3 3
dxx
axx
cxx`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "axxcxxdxx");
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	alias retType = ReturnType!main2;
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


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

#include <iostream>
// scanf("%d", &x); => std::cin >> x;
// printf("%d\n", x); => std::cout << x << "\n";

int main() {
    char s[1005];
    char adds[] = "s";
    char addes[] = "es";
    scanf("%s", s);
    int len = strlen(s);
    if (s[len - 1] != 's') {
        strcat(s, "s");
    } else {
        strcat(s, "es");
    }
    puts(s);
    return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define LIMIT 1000000007 //10^9+7
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}
int N,M,K;
vector<ll> SA,SB;

bool check(int i, int j){
  if(i>N || i<0)return false;
  if(j>M || j<0)return false;
  if((SA[i]+SB[j])<=K)return true;
  else return false;
}

int main(){
	cin>>N>>M>>K;

  SA.resize(N+1,0);
  SB.resize(M+1,0);

  for(int i=1; i<=N; i++){
    int a;cin>>a;
    SA[i] = SA[i-1]+a;
  }
  for(int i=1; i<=M; i++){
    int b;cin>>b;
    SB[i] = SB[i-1]+b;
  }
  ll ans = 0;
  rep(i,N+1){
    if(SA[i]>K)continue;
    int ok = 0;
    int ng = M+1;
    while((ng-ok)>1){
      int mid = (ok+ng)/2;
      if(check(i,mid)){
        ok = mid;
      }else{
        ng = mid;
      }
    }
    //DEBUG(i,ok);
    ans = max(ans, (ll)i+ok);
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 6400
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0008
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.toInt)
      .map {
        case n if n > 9 * 4 => 0
        case n => {
          val ub = math.min(9, n)
          (for (a <- 0 to ub; b <- 0 to ub; c <- 0 to ub; d <- 0 to ub if a + b + c + d == n) yield 0)
            .length
        }
      }
      .foreach(println)
  }
}

Measured memory_bytes: 61320
#include<bits/stdc++.h>
#define INF            1e9
#define REP(i,n)       for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPI(i,ini,n)  for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPR(i,n)      for(lint i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(lint i=(n);i>0;--i)
#define REPRI(i,ini,n) for(lint i=(ini)-1,i##_len=(n);i>=i##_len;--i)
#define REPC(i,obj)    for(auto i:obj)
#define R_UP(a,b)      (((a)+(b)-1)/(b))
#define ALL(obj)       (obj).begin(),(obj).end()
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
signed main()
{
	int n = in();
	vector<int>s(n);
	REPC(&i, s)i = in();
	int q = in();
	vector<int>t(q);
	REPC(&i, t)i = in();
	int ans = 0;
	REPC(i, t)if (find(ALL(s), i) != s.end())ans++;
	cout << ans << endl;
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		
		// TODO Auto-generated method stub
				Scanner scan= new Scanner(System.in);
				int A = scan.nextInt();
				int B = scan.nextInt();
				int T = scan.nextInt();
				
				int answer=T/A*B;
				System.out.println(answer);
			}

		


}

Measured memory_bytes: 21844
#include <iostream>
#include <map>

using namespace std;

int main() {
    int n;
    cin >> n;
    map<string, int> mymap;
    string good;
    for (int i = 0; i < n; i++) {
        cin >> good;
        if (mymap.count(good) == 0) {
            mymap[good] = 1;
        }
    }
    cout << mymap.size() << endl;
    return 0;
}


Measured memory_bytes: 19248
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0]*n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    x, y, z = map(int, input().split())
    uf.unite(x-1, y-1)
print(sum(uf.par[i] == i for i in range(n)))

Measured memory_bytes: 7856
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define ll long long int
#define v vector
#define MP make_pair
#define F first
#define S second
#define M 1000000007
#define endl "\n"
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

template<typename T>
inline void print(v<T >&a){
	for(int i=0;i<a.size();i++)
		cout<<a[i]<<" ";
	cout<<endl;
}

template<typename T>
inline void inp(v<T >&a){
	for(int i=0;i<a.size();i++){
		cin>>a[i];
	}
}

template <typename T>inline void out(T t){cout << t << " " ;}
template<typename T, typename... A>
inline void out(T t, A... args){
	cout << t <<" " ;out(args...);
}

int main(){
	fastio();
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
	ll q=x/d,r=x%d;
	ll ans=x;
	if(q>=k)ans=x-(k*d);
	else {
		k-=q;ans=r;
		if(k%2==1)ans-=d;
	}
	ans=abs(ans);
	cout<<ans<<endl;
		
return 0;
}

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

vector<vector<int>> x;
vector<vector<int>> y;

int main()
{
    int n;
    cin >> n;
    x.resize(n);
    y.resize(n);
    rep(i, n)
    {
        int a;
        cin >> a;
        x[i].resize(a);
        y[i].resize(a);
        rep(j, a)
        {
            cin >> x[i][j] >> y[i][j];
            --x[i][j]; // index 整理
        }
    }

    int ans = 0;
    // 正直者がbit立ってる
    for (int bit = 0; bit < (1 << n); ++bit)
    {
        bool is_ok = true;
        int count = 0;
        rep(i, n)
        {
            if (bit & (1 << i))
            {
                bool honest = true;
                rep(j, (int)x[i].size())
                {
                    if (bit & (1 << x[i][j]) && y[i][j])
                        continue;
                    if (!(bit & (1 << x[i][j])) && !(y[i][j]))
                        continue;
                    honest = false;
                    break;
                }
                if (honest)
                    ++count;
                else
                    is_ok = false;
            }
        }
        if (is_ok)
            ans = max(ans, count);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int kind[4] = {10, 50, 100, 500};

int charge(int P, int sum){
  P = sum - P; //otsuri
  int i = 3;
  int need = 0;
  while(P > 0){
    if(P >= kind[i]){
      P -= kind[i];
      need++;
    }else{
      i--;
    }
  }
  return need;
}

int main(){
  int P;
  bool first = true;
  while(cin >> P, P){
    if (!first) {
      cout << endl;
    }
    first = false;
    int coin[4] = {0};
    int need[4] = {0};
    int count = 3;
    int left; //left money
    for(int &c:coin){
      cin >> c;
    }
    /*
    while(P > 0){
      left = 0;
      for(int i=0;i<count;i++){
        left += kind[i]*coin[i];
      }
      if((P >= kind[count] || left < P) && coin[count] > 0){
        P -= kind[count];
        need[count]++;
        coin[count]--;
      }else{
        count--;
      }
    } 
    */

    long minn = 999999;
    for(int c10=0;c10<=coin[0];c10++){
    for(int c50=0;c50<=coin[1];c50++){
    for(int c100=0;c100<=coin[2];c100++){
    for(int c500=0;c500<=coin[3];c500++){
      int sumn = 10*c10+50*c50+100*c100+500*c500;
      if(sumn < P) continue;
      int re = charge(P, sumn);
      re += coin[0] - c10;
      re += coin[1] - c50;
      re += coin[2] - c100;
      re += coin[3] - c500;
      if(re < minn){
        minn = re;
        need[0] = c10;
        need[1] = c50;
        need[2] = c100;
        need[3] = c500;
      }
    }}}}
        

    for(int i=0;i<4;i++){
      if(need[i] > 0)
        cout << kind[i] << " " << need[i] << endl;
    }
  }

  return 0;
}

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

int main(){

	
	
	string s; cin>>s;
	bool flag = false;
	for(int i = 0; i < s.size(); i++) if(s[i] == '7') flag = true;
	if(flag) cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
}

Measured memory_bytes: 3624
v, e = map(int, input().split())
G = [[float('inf')]*v for _ in range(v)]
for _ in range(e):
    s, t, d = map(int, input().split())            
    G[s][t] = d
dist = [[float("inf")]*v for _ in range(1<<v)]
dist[1][0] = 0
for s in range(1<<v):
    for i in range(v):
        for j in range(v):
            # print(bin(s), dist[(1<<i)|s][i], dist[s][j], i, j, G[j][i])
            if (s>>i)&1 == 1:continue
            if (s>>j)&1 == 0:continue
            dist[(1<<i|s)][i] = min(dist[1<<i|s][i], dist[s][j] + G[j][i])

ans = float('inf')
for i in range(v):
    ans = min(ans, dist[(1<<v)-1][i] + G[i][0])
print(ans if ans != float('inf') else -1)



Measured memory_bytes: 16232
#include <stdio.h>
int main() {
  int d, x, y, num;

  // printf("xとyに数字を入力して下さい\n");
  scanf("%d %d", &x, &y);
  // xとyに2つの数字を入力

  num = 0;
  while (1) {
    d = x % y;
    if (d == 0)
      break;
    x = y;
    y = d;
  }

  // printf("最大公約数は%dです\n", y);
  printf("%d\n", y);
}

// Goal: Display the Greatest Common Divisor


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  if(n==1){
    cout<<0;
    return 0;
  }
  else if(s[0]=='1'){
    for(int i=2;i<n;i+=2){
      if(s[i]!='1')ans++;
    }
    for(int i=1;i<n;i+=2){
      if(s[i]=='1')ans++;
  }
  }
  else {
    for(int i=2;i<n;i+=2){
      if(s[i]=='1')ans++;
    }
    for(int i=1;i<n;i+=2){
      if(s[i]!='1')ans++;
  }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}
class DSU{
    public:
        std::vector<int> size,arr;
        int root(int i){
            if (i==arr[i])
                return i;
            else
                return arr[i]=root(arr[i]);
        }
        void Union(int a, int b){
            int A=root(a);
            int B=root(b);
            if (A==B)
                return;
            else if (size[A]<size[B]){
                arr[A]=B;
            }
            else{
                arr[B]=A;
                if (size[A]==size[B])
                    size[A]++;
            }
        }
        DSU(int n): size(n), arr(n) {
            for (int i=0;i<n;i++){
                arr[i]=i;
                size[i]=1;
            }
        }
};

using namespace std;
using ll=long long;

class DFriends {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int n,m;
        cin>>n>>m;
        DSU D(n+5);
        for (int i=0;i<m;i++){
            int a,b;
            cin>>a>>b;
            D.Union(a,b);
        }
        map<int,int> f;
        for (int i=1;i<=n;i++){
            f[D.root(i)]++;
        }
        int ans=0;
        for (auto it:f){
            ans=max(ans,it.second);
        }
        cout<<ans;
	}
};


int main() {
	DFriends solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 14124
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,n) for(int i=1;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;

const int INF=1000000;
char field[101][101];
int d[101][101];
int N,M;
int sx,sy;
int gx,gy;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MAX_N=1000;

int main(){
	
	double s;
	while(cin>>s,s>0){
		string a="";
		bool f=false;
		if(s<256){
			for(int i=7;i>=-4;i--){
				if(s-pow(2,i)>=0){
					s-=pow(2,i);
					a+='1';
				}
				else
					a+='0';
				if(i==0)
					a+='.';
			}
			if(s==0)
				f=true;
			
		}
		if(f)
			cout<<a<<endl;
		else
			cout<<"NA"<<endl;
	}
}

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

using namespace std;
typedef long long ll;
ll d;
map < ll, ll > mp[20];
ll pw10[20];
ll coef[20];
ll gc[20];
int LEN = 0;
int val[25];
int val0[25];
ll solve(int where, ll need) {
    //cout << where << " " << need << endl;
    if (where == LEN) {
        return (need == 0);
    }
    if (gc[where] != 0 && need % gc[where] != 0) return 0;
    //if (need % gc[where] != 0) return 0;
    if (coef[where] == 0) {
        if (need == 0) return 10;
        else return 0;
    }
    if (mp[where].find(need) != mp[where].end()) {
        return mp[where][need];
    }
    ll tot = 0;
    for (int i = -9; i <= 9; i++) {
        if (where) tot += solve(where + 1, need - i * coef[where]) * val[i + 9];
        else {
            tot += solve(where + 1, need - i * coef[where]) * val0[i + 9];
        }
    }
    return mp[where][need] = tot;
}
ll solve(int len) {
    LEN = (len + 1) / 2;
    for (int i = 0; i <= LEN; i++) mp[i].clear();
    for (int i = 0; i < (len + 1) / 2; i++) {
         coef[i] = pw10[len - 1 - i] - pw10[i];
         coef[i] /= 9;
    }
    gc[LEN] = 0;
    for (int i = LEN - 1; i >= 0; i--) gc[i] = __gcd(coef[i], gc[i + 1]);
    return solve(0, d);
}
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    for (int i = 0; i <= 9; i++) {
        for (int j = 0; j <= 9; j++) {
            val[i - j + 9]++;
            if (j) val0[i - j + 9]++;
        }
    }
    pw10[0] = 1;
    for (int i = 1; i <= 18; i++) pw10[i] = 10 * pw10[i - 1];
    cin >> d;
    if (d % 9 != 0) {
        cout << 0;
        return 0;
    }
    d /= 9;
    ll f = 0;
    for (int len = 2; len <= 18; len++) {
        f += solve(len);
    }
    cout << f << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int n;
vector<int> a;
vector<vector<bool> > used(3001, vector<bool>(3001, false));
vector<vector<long long> > memo(3001, vector<long long>(3001));
long long dfs(int left, int right) {
  if (used[left][right]) return memo[left][right];
  used[left][right] = true;
  if (left + right == n) memo[left][right] = 0;
  else if ((left + right) % 2 == 0) memo[left][right] = max(dfs(left + 1, right) + a[left], dfs(left, right + 1) + a[n - right -1]); // taro
  else memo[left][right] = min(dfs(left + 1, right) - a[left], dfs(left, right + 1) - a[n - right - 1]);
  return memo[left][right];
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  cin >> n;
  REP(i, n) {
    int aa; cin >> aa;
    a.push_back(aa);
  }
  cout << dfs(0, 0) << '\n';
  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if(a<b){
    for(int i = 0; i < b; i++)cout << a;
  }else{
    for(int i = 0; i < a; i++)cout << b;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	for(int x=1;x<10;x++)
	{
		for(int y=1;y<10;y++)
		{
			cout << x << "x" << y << "=" << x*y << endl; 
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}


int main(){
    ll n;
    cin >> n;
    ll a[n][3];
    for (ll i=0;i<n;i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    ll dp[n][3];
    for (ll i=0;i<n;i++){
        fill(dp[i],dp[i]+3,0);
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for (ll i=1;i<n;i++){
        for (ll j=0;j<3;j++){
            for (ll k=0;k<3;k++){
                if (j==k)continue;
                chmax(dp[i][k],dp[i-1][j]+a[i][k]);
            }
        }
    }
    cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) << endl;
    return 0;
}


Measured memory_bytes: 4992
#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 all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  if(n == 1) cout << "Hello World" << endl;
  else {
    int a, b; cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from math import gcd
from math import floor
from collections import defaultdict

def eratosthenes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def factorize(N):  # 素因数分解
    prime = set()
    for p in prime_list:
        if p * p > N:
            break
        while N % p == 0:
            N //= p
            prime.add(p)
    if N > 1:
        prime.add(N)
    return prime


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

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print('not coprime')
    exit()

prime_list = eratosthenes(10 ** 6)
num = set()

class PrimeFactorization:
    '''1つの因数分解クエリをO(log(k))で実行する（初期化にO(N))
    >>> pf = PrimeFactorization(100)
    >>> pf.query(100)
    ((2, 2), (5, 2))
    
    '''
    # https://atcoder.jp/contests/abc177/editorial/82
    # 高速素因数分解
    # 問題： A 以下の数が N 個与えられる。全て素因数分解せよ。
    # 前計算としてエラトステネスの篩を行い、「その数をふるい落とした素数」を配列 D に記録します。
    # 例えば D[4]=D[6]=2,D[35]=5 です。x が素数のときは D[x]=x としておきます。この配列はエラトステネスの篩と同様 O(AloglogA) で構築できます。
    # D[x] は x を割り切る最小の素数なので、この配列 D を利用すると素因数分解を行うときに「試し割り」をする必要がなくなり(D[x]で割ればよい)、1つの数の素因数分解が素因数の個数である O(logA) でできるようになります。
    from collections import defaultdict
    def __init__(self, Num=10**6):
        self.Num = Num
        self.D = [-1] * (Num+1)
        for i in range(2, Num+1):
            if self.D[i] != -1:
                continue
            self.D[i] = i
            for j in range(1, floor(Num/i)+1):
                if self.D[j*i] != -1:
                    continue
                else:
                    self.D[j*i] = i
    
    def query(self, k):
        ans = defaultdict(int)
        tmp = k
        while self.D[tmp] != -1:
            div = self.D[tmp]
            ans[div] += 1
            tmp = tmp//div
        return set(ans.keys())
      
pf = PrimeFactorization(10**6)
for ai in a:
    prime = pf.query(ai)
    # prime = factorize(ai)
    if len(prime & num) > 0:
        print('setwise coprime')
        break
    num |= prime
else:
    print('pairwise coprime')


Measured memory_bytes: 184864
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
int kaijou(int n){
    int a=1;
  if(n==0){
    return 1;
  }
    REP(i,n){
        a*=i+1;
    }
    return a;
}
int ncr(int n,int r){
  int a;
  if(n<0||r<0||n<r){
    return 0;
  }
  a=kaijou(n)/kaijou(r)/kaijou(n-r);
  return a;
}
//cout << setprecision(123);
int main(){
  int N,L,n=0;
  cin>>N>>L;
  if(-L+1>N){
    n=N;
  }
  else if(-L+1<1){
    n=1;
  }
  else{
    n=-L+1;
  }
  
  cout<<(N-1)*(L-1)+N*(N+1)/2-n<<endl;
}

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

typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const ll N=210;

int main()
{
    fast();
    ll tot=0,r,c;
    cin>>r>>c;

    char arr[r][c];
    for(ll i=0;i<r;i++){
        for(ll j=0;j<c;j++){
            cin>>arr[i][j];
            if(arr[i][j]=='.')
                tot++;
        }
    }

    ll cnt=0;
    vector< vector<bool> >visited(r , vector<bool>(c,false));
    visited[0][0]=true;
    queue< pair< pair<ll,ll> , ll> >q;

    q.push(make_pair( make_pair(0,0),1) );
    while(!q.empty())
    {
        pair< pair<ll,ll> , ll>top = q.front();
        q.pop();
        ll x = top.first.first;
        ll y = top.first.second;
        ll dist = top.second;
        if(x==r-1 && y==c-1)
        {
            cout<<tot-dist;
            return 0;
        }

        if(x-1>=0 && visited[x-1][y]==false && arr[x-1][y]=='.'){
            q.push(make_pair(make_pair(x-1,y), dist+1));
            visited[x-1][y]=true;
        }
        if(x+1<r && visited[x+1][y]==false && arr[x+1][y]=='.'){
            q.push(make_pair(make_pair(x+1,y), dist+1));
            visited[x+1][y]=true;
        }
        if(y-1>=0 && visited[x][y-1]==false && arr[x][y-1]=='.'){
            q.push(make_pair(make_pair(x,y-1), dist+1));
            visited[x][y-1]=true;
        }
        if(y+1<c && visited[x][y+1]==false && arr[x][y+1]=='.'){
            q.push(make_pair(make_pair(x,y+1), dist+1));
            visited[x][y+1]=true;
        }
    }

    cout<<"-1";
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	vector<double> a;
	for (double b; cin >> b; ) a.pb(b);
	cout<< *max_element(all(a)) - *min_element(all(a)) << endl;
	
	return 0;
}

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

int main(void)
{
    int n;
    cin >> n;
    for (int i=1;i<=n;i++) {
        if (i * 108 / 100 == n) {
            cout << i << endl;
            return (0);
        }  
    }
    cout << ":(" << endl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    from collections import Counter
    c = Counter(A)
    ans = 0
    for v in c.values():
        if v&1:
            ans += 1
    
    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
    int N, M;
    cin >> N >> M;
    string S[2][2000];
    for(int t=0; t<2; t++) for(int i=0; i<N; i++) cin >> S[t][i];
    int ans = 0;
    for(int i=0; i<N; i++) for(int j=0; j<M; j++) if(S[0][i][j] != S[1][i][j]) ans++;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 11264
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <regex>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;

const int MOD = 1e9+7;



int main(void){
  ll sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  for(ll i = 0;i < tx - sx; i++){
    cout << 'R';
  }
  for(ll i = 0;i < ty - sy; i++){
    cout << 'U';
  }
  for(ll i = 0;i < tx - sx; i++){
    cout << 'L';
  }
  for(ll i = 0;i < ty - sy; i++){
    cout << 'D';
  }
  cout << 'D';
  for(ll i = 0;i < tx - sx + 1; i++){
    cout << 'R';
  }
  for(ll i = 0;i < ty - sy + 1; i++){
    cout << 'U';
  }
  cout << "L";
  cout << "U";
  for(ll i = 0;i < tx - sx + 1; i++){
    cout << 'L';
  }
  for(ll i = 0;i < ty - sy + 1; i++){
    cout << 'D';
  }
  cout << 'R';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1l)
const int M = 1000000007;
const int N=3e6+5;
const long long INF = 1e18+5;

//#define rohit
#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif

void solve() {
    int a, b , c , d;
    cin >> a >> b >> c >> d;
    int ans = min(d , a);
    d-=min(d , a);
    d-=min(d,b);
    int k =min(d,c);
    ans-=k;
    cout << ans << endl;

}

signed main(){
    FAST;
    //TODO:  check test cases.
    int tc=1;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++){
        solve();
    }
}

/*Extra Cares
 * 1)In graphs or dp problems sometimes long long creates MLE.
 * 2)Check whether int to long long typecasting is commented or not?
 * 3)Check overflows.
*/

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

int main() {
    int N, Y;
    cin >> N >> Y;

    for(int x=0; x<=N; x++){
        for(int y=0; y<=(N-x); y++){
            int z = N - x - y;
            int l = 10000*x + 5000*y + 1000*z;
            if (l == Y) {
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
    return 0;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int D, G;

vector<int> P;
vector<int> total;

int main(void) {

    cin >> D >> G;

    P.push_back(0);
    total.push_back(0);

    for(int i = 1; i <= D; ++i) {
        int p, c;
        cin >> p >> c;
        P.push_back(p);
        total.push_back(i * 100 * p + c);
    }

    int lowest = 100 * 10;
    for (int bit = 0; bit < (1 << D); ++bit) {
        int sum = 0;
        int solved = 0;
        vector<int> Pt = P;

        // コンプする問題の分だけsumを加算
        for (int i = 0; i < D; ++i) {
            if (bit & (1 << i)) {
                sum += total[i + 1];
                solved += Pt[i + 1];
                Pt[i + 1] = 0;
                if (sum >= G) {
                    break;
                }
            }
        }

        for (int i = D; i > 0; --i) {
            if (sum >= G) break;
            int r = (G - sum) / (i * 100); // 解くべき問題の数
            if (r == 0 || Pt[i] <= 1) continue;

            // 問題数が足りている
            if (Pt[i] - 1 >= r) {
                sum += r * i * 100;
                solved += r;
            }
            // 足りていない
            else {
                sum += (Pt[i] - 1) * i * 100;
                solved += Pt[i] - 1;
            }

        }

        if (sum >= G) {
            lowest = min(lowest, solved);
        }

    }

    cout << lowest << endl;


    return 0;
}

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

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<int> a(500000, 0);
    for (int i = 1; i <= 100; i++)
    {
        for (int j = 1; j <= 100; j++)
        {
            for (int k = 1; k <= 100; k++)
            {
                int num = i * i + j * j + k * k + i * j + j * k + k * i;
                a[num] += 1;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << a[i] << endl;
    }
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 5024
#include<stdio.h>
#include<stdlib.h>

int main(){
	int a[5];
	for(int i = 0; i < 5; i++){
		scanf("%i", &a[i]);
		if(a[i] == 0){
			printf("%i\n", i + 1);
			return 0;
		}
	}

	return 0;
}


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

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

  int n;
  cin >> n;

  string ans;
  int mod = n % 10;
  if (mod == 3) {
    ans = "bon";
  } else if (mod == 0 || mod == 1 || mod == 6 || mod == 8) {
    ans = "pon";
  } else {
    ans = "hon";
  }
  cout << ans << endl;

  return 0;
}


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

namespace ITP1_10_C
{
    public class Program

    {
        public static void Main(string[] args)
        {

            while (true)
            {
                int n = ReadInt();
                if (n == 0) return;

                int[] line = ReadIntAr();

                double ave = line.Average();
                double v = line.Sum(x => Math.Pow(x - ave, 2)) / n;
                Console.WriteLine("{0}",Math.Sqrt(v));
            }
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 18408
"use strict";
main(require("fs").readFileSync("/dev/stdin", "UTF-8"));

function main(input) {
  input = input
    .split("\n")[0]
    .split(" ")
    .map(n => Number(n));

  const area = input[0];
  const base = input[1];

  let array = [];

  for (let i = base - (area - 1); i < base + area; i++) {
    array.push(i);
  }

  console.log(array.join(" "));
}


Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    char dummy;
    int flag[50][3]{0};
    cin>>n>>m;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cin>>dummy;
            switch(dummy){
                    case 'W':
                    ++flag[i][0];
                    break;
                    case 'B':
                    ++flag[i][1];
                    break;
                    case 'R':
                    ++flag[i][2];
            }
        }
    }
    int answer=n*m;
    int W,B,R;
    W=0;
    for(int i=0;i<n-2;++i){
        B=0;
        W+=flag[i][1]+flag[i][2];
        for(int j=i+1;j<n-1;++j){
            B+=flag[j][0]+flag[j][2];
            R=0;
            for(int k=j+1;k<n;++k){
                R+=flag[k][0]+flag[k][1];
            }
            answer=min(answer,W+B+R);
        }
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include <numeric>
#include <iterator>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

int main()
{
    IO;

    vi a(3);

    rep(i, 3) cin >> a[i];

    sort(all(a));
    
    int x = a[2] - a[0], y = a[2] - a[1];

    if (x % 2 == y % 2) {
        cout << (x + y) / 2 << endl;
    }
    else {
        cout << (x + y + 3) / 2 << endl;
    }

}

Measured memory_bytes: 3632
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
#include <tuple>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;

P p[300];
int n;
void exec()
{
	cin >> n;
	if(n==0)exit(0);
	for(int i=0;i<n;i++){
		cin >> p[i].first >> p[i].second;
	}
	sort(p,p+n);
	priority_queue<T, vector<T>, greater<T> > l0, l1;
	int m0=0;
	int m1=0;
	for(int i=0;i<n;i++){
		int a=p[i].first;
		int b=p[i].second;
		l0.push(T(a,a,b));
		m0=a;
	}
	while(l0.size()||l1.size()){
		if(l1.size()==0||(l0.size()&&l0.top()<l1.top())){
			T t=l0.top();
			//cout << "0 " << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << endl;
			l0.pop();
			get<0>(t)=m1=max(m1,get<0>(t)+get<1>(t));
			l1.push(t);
		}
		else
		{
			T t=l1.top();
			//cout << "1 " << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << endl;
			l1.pop();
			get<2>(t)--;
			if(get<2>(t)<=0){
				continue;
			}
			get<0>(t)=m0=max(m0,get<0>(t)+get<1>(t));
			l0.push(t);
		}
	}
	cout << m1 << endl;
}
int main() {
	while(1)exec();
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000000000
#define INF 1000000
#define M 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std; 
int main(){
    fast_io
    char s;
    cin>>s;
    if(isupper(s)){
        cout<<"A"<<endl;
    }
    else{
     cout<<"a"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };


int main(){
	string s;
	string sc;
	while (cin >> s, s != "#"){
		stringstream ss;
		sc = s;
		REP(i, sc.length()){
			switch (sc[i]){
			case 'k':
			case 's':
			case 't':
			case 'h':
			case 'p':
				if (sc[i] == sc[i + 1])sc[i] = 'P';
				else sc[i] = 'M';
				break;
			case 'i':
			case 'u':
				sc[i] = 'I';
				break;
			case 'a':
				sc[i] = 'A';
				break;
			case 'o':
				sc[i] = 'O';
				break;
			case 'e':
				sc[i] = 'E';
				break;
			case 'y':
				if (i != 0 && sc[i - 1] == 'M')sc[i] = 'M';
				else sc[i] = 'N';
				break;
			default:
				sc[i] = 'N';
				break;
			}
		}
		string scc = sc + "M";
		//cout << scc << endl;
		vb result(scc.length(), false);
		bool pm = false;

		FOR(i, 1, scc.length() - 1){
			switch (scc[i]){
			case 'I':
				if (!pm){
					if (scc.find("MIM", i - 1) == i - 1){
						result[i] = true;
						//i++;
						pm = true;
					}
					else if (scc.find("MIPM", i - 1) == i - 1){
						result[i] = true;
						//i += 2;
						pm = true;
					}
				}
				else{
					pm = false;
				}
				break;
			case 'A':
				if (!pm){
					if (scc.find("MAMA", i - 1) == i - 1 || scc.find("MAMMA", i - 1) == i - 1){
						result[i] = true;
						//i += 2;
						pm = true;
					}
				}
				else{
					pm = false;
				}
				break;
			case 'O':
				if (!pm){
					if (scc.find("MOMO", i - 1) == i - 1 || scc.find("MOMMO", i - 1) == i - 1){
						result[i] = true;
						//i += 2;
						pm = true;
					}
				}
				else{
					pm = false;
				}
				break;
			case 'E':
				pm = false;
				break;
			}
		}

		REP(i, s.length()){
			if (result[i])cout << "(" << s[i] << ")";
			else cout << s[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1200
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	char[] S;
	int Q;
	Query[] queries;
	Map<Character, List<Integer>> map;

	static class Query {
		int type;
		int i, l, r;
		char c;

		Query(String line) {
			String[] tokens = line.split(" ");
			type = Integer.parseInt(tokens[0]);
			if (type == 1) {
				i = Integer.parseInt(tokens[1]) - 1;
				c = tokens[2].charAt(0);
			} else {
				l = Integer.parseInt(tokens[1]) - 1;
				r = Integer.parseInt(tokens[2]) - 1;
			}
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		S = in.readLine().toCharArray();
		Q = Integer.parseInt(in.readLine());
		queries = new Query[Q];
		for (int i = 0; i < Q; ++i) {
			queries[i] = new Query(in.readLine());
		}
		this.map = new HashMap<>();
		// まず全アルファベットだけ用意する
		for (int i = (int) 'a'; i <= (int) 'z'; ++i) {
			char c = (char) i;
			map.put(c, new ArrayList<>());
		}
		for (int i = 0; i < N; ++i) {
			Character c = S[i];
			map.get(c).add(i);
		}
	}

	boolean check(int l, int r, List<Integer> positions) {
		if (positions.isEmpty()) {
			return false;
		}
		if (r < positions.get(0)) {
			return false;
		}
		if (positions.get(positions.size() - 1) < l) {
			return false;
		}
		int posL = Collections.binarySearch(positions, l);
		int posR = Collections.binarySearch(positions, r);
		if (posL >= 0 && posR >= 0) {
			return true;
		} else {
			if (posL == posR) {
				return false;
			} else {
				return true;
			}
		}
	}

	int eval(Query query) {
		if (query.type == 1) {
			// replaceする
			char old = S[query.i];
			S[query.i] = query.c;
			// list側もreplaceする
			int index = Collections.binarySearch(map.get(old), query.i);
			map.get(old).remove(index);
			// insertするindexを求める
			int index2 = Collections.binarySearch(map.get(query.c), query.i);
			index2 = (index2 + 1) * -1;
			map.get(query.c).add(index2, query.i);
			return -1;
		} else {
			// countする
			int count = 0;
			for(List<Integer> list: map.values()) {
				if(check(query.l, query.r, list)) {
					++count;
				}
			}
			return count;
		}
	}

	void calc() {
		for (int i = 0; i < Q; ++i) {
			int count = eval(queries[i]);
			if (count >= 0) {
				System.out.println(count);
			}
		}
	}

	void showResult() {
	}

}


Measured memory_bytes: 56940
import java.util.*;

class Main{
    public static void main(String[] args){
        int a, b, b_ = 0, x;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        for(int i = 1; i <= b - a; i++){
            b_ += i;
        }
        x = b_ - b;
        System.out.println(x);
    }
}

Measured memory_bytes: 21972
/* Simplicity and Goodness */

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

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 2e5+2;


void solve()
{
    int n;
    scn(n);

    vl sum(n);
    vi tak(n), aoki(n);

    rep(i, 0, n) {
        scn(tak[i]); scn(aoki[i]);
        sum[i] = tak[i] + aoki[i];
    }

    vi order(n, 0); iota(order.begin(), order.end(), 0);

    sort(order.begin(), order.end(), [&](int i, int j){
        return(sum[i] > sum[j]);
    });

    ll score = 0;

    rep(i, 0, n) {
        if(i & 1) {
            score -= aoki[order[i]];
        } else {
            score += tak[order[i]];
        }
    }

    lprin(score);
}

int main()
{
    int t = 1;
    // scn(t);
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5428
from collections import deque

def bfs(s, n, m):
    q = deque()
    q.append(s)
    INFTY = 1 << 21
    d = [INFTY] * n
    d[s] = 0
    while len(q) != 0:
        u = q[0]
        q.popleft()
        for v in range(n):
            if not m[u][v]:
                continue
            if d[v] != INFTY:
                continue
            d[v] = d[u] + 1
            q.append(v)
    for i in range(n):
        result = str(i+1)
        if d[i] == INFTY:
            result += ' -1'
        else:
            result += ' %d' % d[i]
        print(result)


n = int(input())
m = [[False] * n for i in range(n)]
for i in range(n):
    line = [int(v) for v in input().split()]
    u = line[0] - 1
    for v in line[2:]:
        v -= 1
        m[u][v] = True

bfs(0, n, m)


Measured memory_bytes: 6080