akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

bool cmp(pair<int,int> a,pair<int,int> b)
{
	return a.second<b.second;
}

int main()
{
	int n,m;cin>>n>>m;
	vector<pair<int,int>> ab(m);
	rep(i,m)
	{
		int foo,fooo;
		cin >> foo >> fooo;
		ab[i] = make_pair(foo,fooo);
	}
	sort(ALL(ab),cmp);

	int c = 0;
	for(int i = 0;i<m;)
	{
		int min = ab[i].second;
		//cout<<min<<endl;
		c++;
		while(ab[i].first<min)
		{
			i++;
			if(i==m)break;
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define INF 30
#define MOD 1000000007

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("input.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int a;
    cin >> a;
    int tot=0;
    for(int i=1;i<a;i++)
    {
        int aa=i;
        int bb=a-i;
        if(aa!=bb && bb>0 && bb>aa)
        {
            tot++;
        }
    }
    cout << tot << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    ll n, m, val;
    cin >> n >> m;
    unordered_set<ll> s;
    for(int i = 0; i < n; i++) {
        cin >> val;
        s.insert(val/2);
    }
    ll cur = 1;
    for(auto& num: s) {
        ll g = __gcd(cur, num);
        ll l = cur*(num/g);
        cur = l;
        if (cur > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(auto& num: s) {
        if ((cur / num) % 2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll cnt = m/cur;
    cout << (cnt+1)/2 << endl;
    return 0;
}




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

int main()
{
	int a, b;
	cin >> a >> b;
	double s = b % a * 1.0;
	if(s == 0)
	{
		cout << a + b << endl;
		exit(0);
	}
	else
	{
		cout << b - a << endl;
		exit(0);
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, K, A[101010];

void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N >> K;
    int MAX = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        chmax(MAX, A[i]);
    }
    int tmp = A[0];
    for (int i = 0; i < N; i++) {
        tmp = gcd(tmp, A[i]);
    }

    if (K <= MAX && K % tmp == 0) {
        cout << "POSSIBLE" << endl;
    } else
        cout << "IMPOSSIBLE" << endl;

    solve();
    return 0;
}


Measured memory_bytes: 4324
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K=sc.nextInt();
		int X=sc.nextInt();
		StringBuilder sb = new StringBuilder();
		int left = Math.max(X-(K-1),-1000000);
		int right = Math.min(X+(K-1),1000000);
		for(int i=left;i<=right;i++) {
			sb.append(i);
			sb.append(" ");
		}
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define f first
#define s second
#define mk make_pair
using namespace std;
typedef pair<int,int>P;
int ans,a,b,n;
int main(){
  int n;
  cin>>n;
  r(i,n){
    cin>>a>>b;
    ans+=abs(a-b)+1;
  }
  cout<<ans<<endl;
}

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

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

int main()
{
	ll N, M;
	cin >> N >> M;

	if (N < M) swap(N, M);

	if (N == 1){
		cout << 1 << endl;
	}else if(M == 1){
		cout << N - 2 << endl;
	}else{
		cout << (N - 2) * (M - 2) << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=100007;
int n,m;
long long t1=0,t2=0,t3=0;
std::vector<int>e[N];
int col[N],un;
void dfs(int w,int c){
	if(!col[w])col[w]=c;
	else return void(un|=col[w]!=c);
	for(int i=0;i<e[w].size();++i)dfs(e[w][i],c^3);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0,a,b;i<m;++i){
		scanf("%d%d",&a,&b);
		e[a].push_back(b);
		e[b].push_back(a);
	}
	for(int i=1;i<=n;++i)t1+=e[i].empty();
	for(int i=1;i<=n;++i)if(e[i].size()&&!col[i]){
		un=0;
		dfs(i,1);
		++(un?t3:t2);
	}
	printf("%lld\n",t1*(n*2-t1)+t2*(t2+t3)*2+t3*t3);
	return 0;
}

Measured memory_bytes: 9984
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int a[] = { 1,3,5,7,8,10,12 };
	int b[] = { 4,6,9,11 };
	int c[] = { 2 };
	int x, y, i, z = 0;

	cin >> x >> y;

	for (i = 0; i < 7; i++)
	{
		if (x == a[i])
		{
			for (i = 0; i < 7; i++)
			{
				if (y == a[i])
				{
					cout << "Yes" << endl;
					z = 1;
				}
				
			}
		}
		else if (x == b[i])
		{
			for (i = 0; i < 4; i++)
			{
				if (y == b[i])
				{
					cout << "Yes" << endl;
					z = 2;
				}

			}
		}
		else if (x == c[i])
		{
			break;
		}
		
	}
	if (z == 0)
	{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>



int main()
{
    int A,B;
    std::cin >> A >> B;
    if(A-1 >= B){
        std::cout << 2*A-1 << std::endl;
        return 0;
    }
    if(A == B){
        std::cout << 2*A << std::endl;
        return 0;
    }
    if(B-1 >= A){
        std::cout << 2*B -1 << std::endl;
        return 0;
    }
    return 0;
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, m, correct = 0, penalty = 0;
	cin >> n >> m;
	map<int, int> mp;
	int p;
	string s;
	for(int i = 0 ; i < m ; i++)
	{
		cin >> p >> s;
		if(mp[p] != -1 && s == "AC"){++correct; penalty += mp[p]; mp[p] = -1;}
		if(mp[p] != -1 && s == "WA"){++mp[p];}
	}
	cout << correct << ' ' << penalty << '\n';
	
	return 0;
}

Measured memory_bytes: 4992
s=input()
if s=="SUN":
    print(7)
if s=="MON":
    print(6)
if s=="TUE":
    print(5)
if s=="WED":
    print(4)
if s=="THU":
    print(3)
if s=="FRI":
    print(2)
if s=="SAT":
    print(1)

Measured memory_bytes: 3064
import math

N, D = map(int, input().split())
X = [None]*N

for i in range(N):
    buf = list(map(int, input().split()))
    X[i] = buf

ans = 0

for i in range(N-1):
    for j in range(i+1, N):
        buf = 0
        for p in range(D):
            buf += (X[i][p]-X[j][p])*(X[i][p]-X[j][p])
        buf1 = math.sqrt(buf)
        if buf1 == int(buf1):
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct pos{ll x, y;};
typedef pair<ll,ll> P;

struct UnionFind{
  vector<ll> par;
  vector<ll> rank;
  vector<ll> sizes;

  UnionFind(ll n){
    init(n);
  }

  void init(ll n){
    par.resize(n);
    rank.resize(n);
    sizes.resize(n);
    REP(i,n){
      par[i] = i;
      rank[i] = 0;
      sizes[i] = 1;
    }
  }

  ll find(ll x){
    if(par[x] == x){
      return x;
    }else{
      return par[x] = find(par[x]);
    }
  }

  void unite(ll x, ll y){
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(rank[x]<rank[y]){
      par[x] = y;
      sizes[y] += sizes[x];
    }else{
      par[y] = x;
      sizes[x] += sizes[y];
      if(rank[x]==rank[y]) rank[x]++;
    }
  }

  bool same(ll x, ll y){
    return find(x)==find(y);
  }

  ll size(ll x){
    return sizes[find(x)];
  }
};
struct edge{ll from, to, cost;};
bool compare_edge(const edge& e1, const edge& e2){
  return e1.cost<e2.cost;
}
struct graph{
  vector<edge> es;
  ll V;
  graph(ll n){
    init(n);
  }
  void init(ll n){
    V = n;
  }
  void add_edge(ll from, ll to, ll cost){
    edge e;
    e.from = from, e.to = to, e.cost = cost;
    es.push_back(e);
  }
  ll kruskal(){
    sort(es.begin(),es.end(),compare_edge);
    UnionFind uf(V);
    ll res = 0;
    for(auto e : es){
      if(!uf.same(e.from,e.to)){
        uf.unite(e.from,e.to);
        res += e.cost;
      }
    }
    return res;
  }
};

int main(){
  ll n;
  cin >> n;
  pos p[n];
  REP(i,n){
    ll x,y;
    cin >> x >> y;
    p[i].x = x; p[i].y = y;
  }
  graph g(n);
  vector<P> x_sort;
  REP(i,n){
    x_sort.push_back(P(p[i].x,i));
  }
  sort(x_sort.begin(),x_sort.end());
  REP(i,n-1){
    ll v1 = x_sort[i].second, v2 = x_sort[i+1].second;
    g.add_edge(v1,v2,min(abs(p[v1].x-p[v2].x),abs(p[v1].y-p[v2].y)));
  }
  vector<P> y_sort;
  REP(i,n){
    y_sort.push_back(P(p[i].y,i));
  }
  sort(y_sort.begin(),y_sort.end());
  REP(i,n-1){
    ll v1 = y_sort[i].second, v2 = y_sort[i+1].second;
    g.add_edge(v1,v2,min(abs(p[v1].x-p[v2].x),abs(p[v1].y-p[v2].y)));
  }
  cout << g.kruskal() << endl;
  return 0;
}


Measured memory_bytes: 15212
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 1000000000000
typedef long long ll;
using namespace std;

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(a==b)cout<<c<<endl;
  else if(b==c)cout<<a<<endl;
  else cout<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a;
    cin >> a;
    if(a[0] >= 'A' and a[0] <= 'Z') {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }
}

Measured memory_bytes: 3608
N = int(input())
cmin = N
for i in range(1,N):
    j = N-i
    a = str(i)
    b = str(j)
    cnt = 0
    for k in range(len(a)):
        cnt += int(a[k])
    for k in range(len(b)):
        cnt += int(b[k])
    cmin = min(cmin,cnt)
print(cmin)

Measured memory_bytes: 73624
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"First":"Second")
#define YN(f) ((f)?"YES":"NO")

#define MAX 310000

int a[MAX];
int N, D;
bool flag;

bool solve(){
	if(!flag) return !(N%2);
	int ans = 0;
	for(int i = 0; i < N; i++){
		ans ^= (a[i]-1)%(D+1);
	}
	return ans;
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	cin>>N>>D;
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
		if(a[i] != 1)flag = true;
	}
	
	cout<<yn(solve())<<endl;
	
	return 0;
}


Measured memory_bytes: 5208
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, K = map(int, input().split())

fact = [1]
for i in range(1, N+10):
    fact.append(fact[-1] * i % MOD)
def rev(x):
    return pow(x, MOD-2, MOD)
def cmb(i, k):
    if(i < k): return 0
    return fact[i] * rev(fact[k]) * rev(fact[i-k]) % MOD

for i in range(1, K+1):
    print((cmb(N-K+1, i) * cmb(K-1, i-1))%MOD)



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

void merge(int*,int,int,int);
void mergeSort(int*,int,int);
int count=0;

int main() 
{
  int i,n,S[500000];
 
  scanf("%d",&n);
  for(i=0; i<n; i++) 
    scanf("%d",&S[i]);
  mergeSort(S,0,n);
  for(i=0; i<n; i++) {
    if(i>0) printf(" ");
    printf("%d",S[i]);
  }
 
  printf("\n%d\n",count);
  
  return 0;
}

void merge(int A[],int left,int mid,int right) 
{
  int i,j=0,k;
  int n1 = mid-left, n2 = right - mid; 
  int L[n1+1],R[n2+1];
  
  for(i=0; i<n1; i++) 
    L[i] = A[left+i];
  for(i=0; i<n2; i++) 
    R[i] = A[mid+i];
  L[n1] = (1e+9)+1;
  R[n2] = (1e+9)+1;
  i=0;
  for(k=left; k<right; k++) {
    if(L[i]<=R[j])
      A[k] = L[i++];
    else 
      A[k] = R[j++];
    count++;
  }
}

void mergeSort(int A[],int left,int right) 
{
  int mid;
  if(left+1 < right) {
    mid = (left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {

    vector<pair<int,int>>dish(5);
    REP(i,5){
        int x;
        cin >> x;
        dish[i] = make_pair((x-1)%10, x);
    }
    sort(ALL(dish));
    int ans = dish[0].second;
    FOR(i,1,5){
        ans += ((dish[i].second-1)/10 + 1)*10;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3528
#pragma GCC optimize("O3", "unroll-loops")

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <limits>
#include <ext/rope>

using namespace std;
using namespace __gnu_cxx;

const int inf = (1 << 30) + 9e8;
const int MAXN = 1e5;
const int P = 131;
const long long MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<bool> vb;

#define FAST ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define all(a) a.begin(), a.end()
#define pb push_back
#define files(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define ppb pop_back
#define ppf pop_front
#define fs first
#define sd second
#define eb emplace_back

template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

vi g[MAXN];
vb used;
int n, m;
vll dp;

void dfs(int v) {
    used[v] = true;
    for (auto u : g[v]) {
        if (!used[u])
            dfs(u);
        dp[v] = max(dp[v], dp[u] + 1);
    }
}

void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].pb(b);
    }
    dp.resize(n, 0);
    used.resize(n, false);
    for (int i = 0; i < n; ++i) {
        if (!used[i])
            dfs(i);
    }
    ll mx = -inf;
    for (auto it : dp) {
        mx = max(mx, it);
    }
    cout << mx;
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    FAST;
    int q = 1;
    // cin >> q;
    // int st = clock();
    while (q--) {
        solve();
    }
    // int en = clock();
    // cout << en - st << "ms.";
    return 0;
}


Measured memory_bytes: 12184
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
	string S;
	int Q;
	cin >> S >> Q;
	string fr="", ba="";
	bool reversed=false;
	for(int q=0; q<Q; ++q){
		int T;
		cin >> T;
		if(T==1){
			reversed=(!reversed);
		}else{
			int F;
			char ch;
			cin >> F >> ch;
			if((F==1)^reversed) fr += ch;
			else ba += ch;
		}
	}
	if(reversed){
		reverse(S.begin(), S.end());
		reverse(ba.begin(), ba.end());
		cout << ba << S << fr << endl;
	}else{
		reverse(fr.begin(), fr.end());
		cout << fr << S << ba << endl;
	}
	return 0;
}

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

int main()
{
  char a,b;
  
  int ia,ib;
  
  cin >> a >> b;
  
  ia=a-'0';
  ib=b-'0';
  if(a>b)
  {
    
    for(int i=0;i<ia;i++)
    {
      printf("%c",b);
    }
  }
  else 
  {
    
    for(int i=0;i<ib;i++)
    {
      printf("%c",a);
    }
    
  }
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,s1;
	cin>>s>>s1;
	s1+=s;
	cout<<s1;
    return 0;
}


//252908XL

Measured memory_bytes: 256
def print_chess(width, count):
    chess = ['#', '.']
    if count % 2 != 0:
        for i in range(width):
            if i % 2 == 0:
                print(chess[1], end='')
            else:
                print(chess[0], end='')
    else:
        for i in range(width):
            if i % 2 == 0:
                print(chess[0], end='')
            else:
                print(chess[1], end='')
    print('')


count = 0
while(True):
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    count += 1
    for i in range(h):
        print_chess(w, i)
    print('')


Measured memory_bytes: 7012
import java.util.*;
import java.text.DecimalFormat;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();

		if (a >= b && a >= c)
			System.out.println((a*10)+b+c);
		else if (b >= a && b >= c)
			System.out.println((b*10)+a+c);
		else
			System.out.println((c*10)+b+a);
	}
}

Measured memory_bytes: 22864
const s = require('fs').readFileSync('/dev/stdin','utf8').trim().split('')
const n = s.length
const children = new Array(n).fill(1)
const tmp = new Array(n).fill(0)

const blocks = s.join('').match(/(R+)|(L+)/g)
const maxBlock = blocks.reduce((a, b) => a.length > b.length ? a : b)
const maxBlockSize = maxBlock.length

const numbers = []
for(var i in blocks) {
  var char = blocks[i][0]

  if(char === 'R') {
    for(var j=0;j<blocks[i].length-1;j++) {
      numbers.push(0)
    }

    var num = (blocks[i].length + blocks[i].length % 2) / 2
    numbers.push(num)
    num = (blocks[i].length - blocks[i].length % 2) / 2
    numbers.push(num)
  } else {
    var num = (blocks[i].length - blocks[i].length % 2) / 2
    numbers[numbers.length-2] += num
    num = (blocks[i].length + blocks[i].length % 2) / 2
    numbers[numbers.length-1] += num

    for(var j=0;j<blocks[i].length-1;j++) {
      numbers.push(0)
    }
  }
}

const answer = numbers.join(' ')
console.log(answer)


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> X(M);
  for (int i=0;i<M;i++){
    cin >> X[i];
  }
  sort(X.begin(),X.end());
  vector<int> Y(M-1);
  for (int i=0;i<M-1;i++){
    Y[i]=X[i+1]-X[i];
  }
  sort(Y.begin(),Y.end());
  int ans=0;
  for (int i=0;i<M-N;i++){
    ans+=Y[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll l,r;
	l=r=0;
	for(ll i=0;i<n;i++){
		char now=s[i];
		if(s[i]==')'){
			if(r!=0){
				r--;
			}
			else{
				l++;
			}
		}
		else{
			r++;
		}
	}
	for(ll i=0;i<l;i++){
		cout << '(';
	}
	cout << s;
	l=r=0;
	reverse(s.begin(),s.end());
	for(ll i=0;i<n;i++){
		char now=s[i];
		if(s[i]=='('){
			if(r!=0){
				r--;
			}
			else{
				l++;
			}
		}
		else{
			r++;
		}
	}	
	for(ll i=0;i<l;i++){
		cout << ')';
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;


int main()
{
	long long N;

	cin >> N;

	long long min_p = 1e16;
	long long p;
	for (int ni = 0; ni < 5; ni++){
		cin >> p;
		if (p < min_p) {
			min_p = p;
		}
	}

	long long ans = 4 + (long long)ceil((double)N / min_p );

	std::cout << ans;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    char a[1200];
    int i, n=0;
    while(1){
        scanf("%c", &a[n]);
        if(a[n] == '\n'){
            break;
        }
        n++;
    }
    for(i=0; i<=n; i++){
        if(a[i] >= 0x41 && a[i] <= 0x5A){
            a[i] += 32;
        }else if(a[i] >= 0x61 && a[i] <= 0x7A){
            a[i] -= 32;
        }
        printf("%c", a[i]);
    }
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
vector<long long> fac;
vector<long long> fac_inv;
vector<long long> inv;

void init_combination(long long n, long long mod)
{
	fac.resize(n+1);
	fac_inv.resize(n+1);
	inv.resize(n+1);
	fac[0] = 1;
	fac[1] = 1;
	fac_inv[0] = 1;
	fac_inv[1] = 1;
	inv[1] = 1;
	for (long long i = 2; i <= n; i++) {
		fac[i] = fac[i-1]*i%mod;
		inv[i] = mod - (inv[mod%i] * (mod / i)) % mod;
		fac_inv[i] = fac_inv[i-1] * inv[i] % mod;
	}
}

long long modcomb(long long n, long long r, long long mod)
{
	if (n < r)
		return 0;
	long long result = fac[n]%mod;
	result *= (fac_inv[r] * fac_inv[n-r]) % mod;
	result %= mod;
	return result;
}
const long long p = 1e9+7;
int main(void)
{
	long long n, k;
	cin >> n >> k;
	init_combination(max(k-1, n-k+1), p);
	for (long long i = 1; i <= k; i++) {
		long long ans = modcomb(k-1, i-1, p);
		ans *= modcomb(n-k+1, i, p);
		ans %= p;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int ans=1, tmp=l[0];
    for(int i=1; i<n; i++){
        if(tmp!=l[i]){
            ans++;
            tmp=l[i];
        }
    }
    cout << ans;
    return 0;
}

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

int main(void)
{
	int a, b;
	cin >> a >> b;
	if(a < b) {
		cout << "a < b" << endl;
	}
	else if(a > b) {
		cout << "a > b" << endl;
	}
	else {
		cout << "a == b" << endl;
	}
}

Measured memory_bytes: 1156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Main {
    public static void main(String [] args) {
        FastReader reader = new FastReader();
 
        int n = reader.nextInt();
        int [] a = new int [n];
        long [] sum = new long [n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = reader.nextInt();
            sum [i + 1] = sum [i] + a[i];
        }
 
        long [][] dp = new long [n][n];
        // dp[i][j] -> minimum cost to merge interval i,j
 
        for (int L = n - 1; L >=0; L--) {
            for (int R = L + 1; R < n; R++) {
                dp [L][R] = Long.MAX_VALUE;
                for (int i = L; i < R; i++) {
                    dp[L][R] = Math.min(dp[L][R], dp[L][i] + dp[i + 1][R] + (sum[R + 1] - sum[L]));
                }
            }
        }
 
        System.out.println(dp[0][n - 1]);
 
    }
 
 
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 27428
X = int(input())
ans = 0
while True:
    if X < 5:
        break
    if X >= 500:
        v, r = divmod(X, 500)
        ans += v * 1000
        X = r
    if X >= 5:
        v, r = divmod(X, 5)
        ans += v * 5
        X = r
print(ans)

Measured memory_bytes: 3060
// TOPSIC001_0

#include <bits/stdc++.h>

using namespace std;

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

typedef int _loop_int;
#define REP(i, n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i, a, b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i, a, b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a, b) a=min((a),(b))
#define CHMAX(a, b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a, b) (abs(a-b)<EPS)
typedef complex<Real> P;


int main() {
    int N;
    cin >> N;
    int temp1 = N / 100;
    int temp2 = (N % 100) / 10;
    int temp3 = (N % 100) % 10;


    if (temp1 == temp2 && temp2 == temp3) {
        cout << N;
    } else {
        if (temp1 < temp2) {
            temp1++;
            cout << to_string(temp1) + to_string(temp1) + to_string(temp1);
        }else if(temp1 == temp2){
            if(temp2 < temp3){
                temp1++;
                cout << to_string(temp1) + to_string(temp1) + to_string(temp1);
            }else{
                cout << to_string(temp1) + to_string(temp1) + to_string(temp1);
            }
        }else if(temp2 < temp3){
            cout << to_string(temp1) + to_string(temp1) + to_string(temp1);
        }else{

            if(temp1 > temp2){
                cout << to_string(temp1) + to_string(temp1) + to_string(temp1);
            }else{
                temp1++;
                cout << to_string(temp1) + to_string(temp1) + to_string(temp1);
            }
        }

    }

    return 0;
}


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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
const int INF = numeric_limits<int>::max() / 2;

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

	int T;
	while (true) {
		cin >> T;
		if (T == 0) break;
		vector<int> t(30);
		for (int i = 0; i < T; i++) cin >> t[i];
		int n; cin >> n;
		vector<int> m(110, 24);
		for (int i = 0; i < n; i++) {
			int di, mi; cin >> di >> mi;
			m[di] = min(m[di],mi);
		}
		VVI dp(110, vector<int>(T, INF));
		dp[1][0] = 0;
		for (int i = 2; i <= 100; i++) {
			for (int j = 0; j < T; j++) {
				dp[i][0] = min(dp[i][0], dp[i - 1][j] + 1);
				if (m[i] >= t[j]) dp[i][j] = min(dp[i][j], dp[i - 1][(j + T - 1) % T]);
			}
		}
		int res = INF;
		for (int i = 0; i < T; i++) res = min(res, dp[100][i]);
		cout << res << endl;
	}
}

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

int main(int argc, const char * argv[]) {
    int N, K; cin >> N >> K;
    vector<int> freq(200001, 0);
    for(int i = 0; i < N; i++) {
        int inp; cin >> inp;
        freq[inp]++;
    }
    sort(freq.begin(), freq.end());
    int sum = 0;
    for(int i = 0; i < 200001 - K; i++) sum += freq[i];
    
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int a[100000000];
int check[100000000] = {};
int main(){
int s;
cin >> s;
int ans;
a[0] = s;
for(int i = 0;i < 99999999999;i++){
if(check[a[i]]){
  ans = i;
  break;
}
if(a[i] % 2 == 0)a[i+1] = a[i] / 2;
if(a[i] % 2 == 1)a[i+1] = a[i] * 3 + 1;
check[a[i]] = 1;
}
cout << ans + 1 << endl;
return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main() {

	int n, xsz, flag1=0, flag2, ans=0;
	vector<string> s;
	vector<int> t;
	string x;

	cin >> n;

	s.resize(n);
	t.resize(n);
	for (int i = 0;i<n;i++) cin >> s[i] >> t[i];
	cin >> x;

	xsz = x.size();

	for (int i = 0;i <n ;i++) {
		if (flag1) ans += t[i];
		if (xsz == s[i].size()) {
			flag2 = 1;
			for (int j = 0;j < xsz;j++) {
				if (x[j] != s[i][j]) flag2 = 0;
			}
			if (flag2) flag1 = 1;
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	auto iter1 = s.begin();
	auto iter2 = s.begin() + 2;

	if (*iter1 == *(iter1 + 1) && *iter2 == *(iter2 + 1) && *iter1 != *iter2)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 512
'use strict';

const repeatString = (s, n) => {
  let r = '';
  for (let i = 0; i < n; i++) {
    r += s;
  }
  return r;
};

const input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
const numbers = input[0].split(' ').map(n => parseInt(n, 10));

const h = numbers[0];
const w = numbers[1];

console.log(repeatString('#', w + 2));

for (let i = 1; i < h + 1; i++) {
  const line = input[i];
  console.log('#' + line + '#');
}

console.log(repeatString('#', w + 2));

Measured memory_bytes: 7500
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    sum_A = sum(A)

    cnt = 0
    for i in range(N):
        if A[i] >= sum_A / (4 * M):
            cnt += 1

    if cnt >= M:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <numeric>
#include <cmath>
#include <limits>

using namespace std;
int gcd(long long x, long long y);
int lcm(long long x, long long y);

int main(void){

	string a;
	cin >> a ;
	int cnt = 0;
	for(int i = 0; i < a.size(); i++){
		if(a[i]== '2'){
			cnt ++;
		}
	}
	cout << cnt << endl;

	return 0;
}

int gcd(long long x, long long y)
{
    long long r;

    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

int lcm(long long x, long long y)
{

    return (x * y / gcd(x, y));
}

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

#define ll long long int

int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(n == 1){
        cout<<a[0];
        return 0;
    }
    int dp[n];
    dp[0] = 0;
    for(int i=1;i<n;i++){
        int mx = INT_MAX;
        for(int j=1; j<=i and j<=k; j++)
            mx = min(dp[i-j]+abs(a[i-j]-a[i]),mx);
        dp[i] = mx;
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;
int n;
int a[111111];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a+i);
  }

  ll res = 0;
  int ma = 0;
  for (int i = 0; i < n; i++) {
    res += (a[i]-1)/(ma+1);
    // printf("%lld %d\n", res, ma);
    if (ma <= (a[i]-1)%(ma+1)) {
      if (ma == 0 ||
          a[i]-ma <= 1) {
        ma = (a[i]-1)%(ma+1)+1;
      }
    }
  }
  printf("%lld\n", res);
  return 0;
}


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

int main(){
  int n, m;
  while(cin >> n >> m, n or m){
    vector<int> V(n+m+1);
    V[0] = 0;
    for(int i = 0; i < n+m; ++i) cin >> V[i+1];
    sort(V.begin(), V.end());
    int ans = 0;
    for(int i = 0; i < n+m; ++i) ans = max(ans, V[i+1]-V[i]);
    cout << ans << endl;
  }
}



Measured memory_bytes: 3240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    private static BufferedReader br;
    private static StringTokenizer tokenizer;

    private static void solve() throws IOException {
        int a = nextInt();
        int b = nextInt();
        StringBuilder aSb = new StringBuilder();
        for (int i = 0; i < b; i++) {
            aSb.append(a);
        }

        StringBuilder bSb = new StringBuilder();
        for (int i = 0; i < a; i++) {
            bSb.append(b);
        }

        if (aSb.toString().compareTo(bSb.toString()) < 0) {
            System.out.println(aSb.toString());
        } else {
            System.out.println(bSb.toString());
        }
    }




    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    public static String next() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null)
                throw new IOException();
            tokenizer = new StringTokenizer(line);
        }
        return tokenizer.nextToken();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

}

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

int main() {
    char str[100001];
    scanf("%s", str);

    int a[27]={0};
    char i;
    int j, k;
    for(k=0; k<strlen(str); k++) {
        j=0;
        for(i='a'; i<='z'; i++) {
            if(str[k]==i) a[j]+=1;
            j++;
        }
    }

    int flag=0;
    j=0;
    for(i='a'; i<='z'; i++) {
        if(a[j]==0) {
            printf("%c\n", i);
            return 0;
        }
        j += 1;
    }

    printf("None\n");

    return 0;
    
}

Measured memory_bytes: 256
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

[q,h,s,d] = getlist()
N = getN()

tanka_ni = min([q*8, h*4, s*2, d])

ans = 0

ans += tanka_ni * (N//2)


if N % 2 == 1:
    ans += min([q*4, h*2, s])

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main()
{
  int n, k, r, s, p, cnt=0;
  scanf("%d %d", &n, &k);
  scanf("%d %d %d", &r, &s, &p);

  char tmp[100000];
  scanf("%s", tmp);

  for (int i = 0; i < n; i++) {
    if (i < k) {
      if(tmp[i] == 'r') cnt+=p;
      if(tmp[i] == 's') cnt+=r;
      if(tmp[i] == 'p') cnt+=s;
    }
    else {
      if (tmp[i-k] == tmp[i]) {
        cnt+=0;
        tmp[i] = 'n';
      }
      else {
        if(tmp[i] == 'r') cnt+=p;
        if(tmp[i] == 's') cnt+=r;
        if(tmp[i] == 'p') cnt+=s;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

vector<long long> dp;

vector<long long> h;

void frog(int n);

int main() {
	int N; cin >> N;
	dp.assign(N, -1);
	h.assign(N, 0);
	for (int i = 0; i < N; ++i)
		cin >> h[i];
	dp[0] = 0, dp[1] = abs(h[1] - h[0]);
	frog(N - 1);
	cout << dp[N - 1];
	return 0;
}

void frog(int n) {
	if (dp[n] != -1) return;
	frog(n - 1);
	frog(n - 2);
	long long res = dp[n - 1] + abs(h[n] - h[n - 1]);
	long long res2 = dp[n - 2] + abs(h[n] - h[n - 2]);
	if (res < res2) dp[n] = res;
	else dp[n] = res2;
}

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

int main(){
    int n,m;
    cin>>n>>m;
    n-=1;m-=1;
    int x=(n*(n+1))/2;
    int y=(m*(m+1))/2;
    printf("%d\n",x+y);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>

int main(){
	int c,a[2];
	while(~scanf("%d %d",&a[1],&a[2]))
	{	
		c=2*a[2]-a[1];
	printf("%d\n",c);

	}
	return 0;
	}

Measured memory_bytes: 128
import numpy as np
from collections import deque
import heapq

# s = input()
# n = int(input())
# A = list(map(int, input().split()))
N, M = map(int, input().split())

edges = [set() for _ in range(N)]
degs = [0 for i in range(N)]
parity = [0 for _ in range(N)]
flag = [False for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    edges[a-1].add(b-1)
    edges[b-1].add(a-1)
    degs[a-1] += 1
    degs[b-1] += 1

if M%2 != 0:
    print(-1)
    exit()



Q = []

for i, d in enumerate(degs):
    Q.append((d,i))
heapq.heapify(Q)

while len(Q) > 0:
    _, u = Q[0]
    heapq.heappop(Q)
    if flag[u]:
        continue
    flag[u] = True

    for i, v in enumerate(edges[u]):
        edges[v].remove(u)
        if parity[u] != 0 and i == 0:
            print(u+1, v+1)
            parity[u] = 1 - parity[u]
        else:
            print(v+1, u+1)
            parity[v] = 1 - parity[v]


        degs[v] -= 1
        heapq.heappush(Q, (degs[v], v))
    # print(Q)
    # print(parity)



Measured memory_bytes: 57348
s = input().rstrip()

removed = 0
cnt_s = cnt_t = 0

for c in s:
    if c == 'S':
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s:
        removed += cnt_s
        cnt_s = cnt_t = 0
#     print(cnt_s,cnt_t)
removed += min(cnt_s,cnt_t)
print(len(s) - removed*2)

Measured memory_bytes: 72708
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 10;

ll power_(ll a, ll power){
    ll value = 1;
    
    while(power != 0){
        if(power & 1) value = value * a;
        a = a * a;
        power = power >> 1;
    }

    return value;
}


int main(void){
    ll N;
    ll N_test;
    ll digit[3] = {3, 5, 7};
    ll N_digit[MAX_N];
    ll answer;
    ll cnt = 0;

    cin >> N;
    N_test = N;

    while(N_test > 0){
        N_digit[cnt] = N_test % 10; 
        N_test /= 10; 
        cnt ++;
    }

    answer = 0;

    For(i, 2, cnt - 1) answer += power_(3, i + 1) - 3 * power_(2, i + 1) + 3;
    
    ll start = power_(3, cnt - 1);
    ll end = power_(3, cnt);
    
    rep(i, end){
        ll tmp = i;
        ll n = 0;
        bool counter[3] = {false, false, false};
        rep(i, cnt){
            ll digit_idx = tmp % 3;
            counter[digit_idx] = true;
            n += digit[digit_idx] * power_(10, i);
            tmp /= 3;
        }

        bool yes = (counter[0] && counter[1] && counter[2]);
        if (n <= N && yes) answer ++;
        else if (n > N) break;
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
import java.awt.Point;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			n = scanner.nextInt();
			int[] x1 = new int[n];
			int[] y1 = new int[n];
			int[] x2 = new int[n];
			int[] y2 = new int[n];
			for (int i = 0; i < n; i++) {
				x1[i] = scanner.nextInt();
				y1[i] = scanner.nextInt();
				x2[i] = scanner.nextInt();
				y2[i] = scanner.nextInt();
			}
			w = compress(x1, x2, w);
			h = compress(y1, y2, h);

			boolean[][] a = new boolean[h][w];
			for (int i = 0; i < n; i++) {
				for (int y = y1[i]; y < y2[i]; y++) {
					for (int x = x1[i]; x < x2[i]; x++) {
						a[y][x] = true;
					}
				}
			}
			int ans = 0;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (a[i][j])
						continue;
					ans++;
					a[i][j] = true;
					Deque<Point> deque = new ArrayDeque<Point>();
					deque.push(new Point(j, i));
					while (!deque.isEmpty()) {
						Point p = deque.poll();
						for (int[] m : move) {
							int ny = p.y + m[0];
							int nx = p.x + m[1];
							if (!isOK(ny, nx))
								continue;
							if (a[ny][nx])
								continue;
							a[ny][nx] = true;
							deque.push(new Point(nx, ny));
						}
					}
				}
			}
			System.out.println(ans);
		}
	}

	private boolean isOK(int ny, int nx) {
		if (0 <= ny && ny < h && 0 <= nx && nx < w)
			return true;
		return false;
	}

	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
	int h, w;
	int n;

	private int compress(int[] x1, int[] x2, int wh) {
		NavigableSet<Integer> set = new TreeSet<Integer>();
		set.add(0);
		set.add(wh);
		for (int i = 0; i < n; i++) {
			set.add(x1[i]);
			set.add(x2[i]);
		}
		Integer[] x = set.toArray(new Integer[0]);
		for (int i = 0; i < n; i++) {
			x1[i] = Arrays.binarySearch(x, x1[i]);
			x2[i] = Arrays.binarySearch(x, x2[i]);
		}
		return x.length - 1;
	}
}

Measured memory_bytes: 40536
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 200000;

bool comp(pair<pii, int> a, pair<pii, int> b) {
    return a.ff.ff + a.ff.ss > b.ff.ff + b.ff.ss;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    vector<pair<pii, int>> p(n);

    for (int k = 0; k < n; ++k) {
        cin >> p[k].ff.ff >> p[k].ff.ss >> p[k].ss;
    }

    vii dp(n + 1, vi(1e4 + 1, -1));

    sort(all(p), comp);

    for (int i = 0; i < n; ++i) {
        int w = p[i].ff.ff;
        int s = p[i].ff.ss;
        int c = p[i].ss;

        dp[i + 1][s] = max(dp[i + 1][s], c);

        for (int j = 10000; j >= 0; --j) {
            if (dp[i][j] == -1) continue;

            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j >= w) {
                dp[i + 1][min(j - w, s)] = max(dp[i + 1][min(j - w, s)], dp[i][j] + c);
            }
        }
    }

    cout << *max_element(all(dp[n]));
}

Measured memory_bytes: 81576