akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

	vector<long long> A(N), B(N);

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	for (int i = 0; i < N; i++)
	{
		cin >> B[i];
	}

	vector<long long> larges;
	long long point = 0;
	int p_count = 0;
	for (int i = 0; i < N; i++)
	{
		long long x = B[i] - A[i];

		if (x > 0)
		{
			point += x;
			p_count++;
		}
		else if (x < 0)
		{
			larges.push_back(-x);
		}
	}


	if (p_count <= 0)
	{
		cout << 0 << endl;
		return 0;
	}


	sort(larges.begin(), larges.end(), greater<long long>());

	int use_count = 0;
	for (int i = 0; i < larges.size(); i++)
	{
		point -= larges[i];
		use_count++;

		if (point <= 0)
		{
			break;
		}
	}

	if (point > 0)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << use_count + p_count << endl;
	}

	return 0;
}

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

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;
const int INF = 1e9;
int main() {
    int N;
    cin >> N;
    int u, v;
    cin >> u >> v;
    u--, v--;

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

    vector<int> dist(N, INF);
    queue<int> que;
    que.emplace(v);
    dist[v] = 0;
    while (que.size() != 0) {   // 幅優先探索
        int now = que.front();  // 現在の状態
        que.pop();
        for (auto e : G[now]) {
            if (dist[e.to] == INF) {  // 未探索の時のみ行う
                dist[e.to] = dist[now] + 1;
                que.emplace(e.to);
            }
        }
    }

    int ans = 0;
    vector<int> t(N, INF);
    t[u] = 0;
    que.emplace(u);
    while (que.size() != 0) {
        int now = que.front();
        que.pop();
        if (dist[now] >= t[now]) {
            ans = max(ans, dist[now] - 1);
            cerr << now + 1 << " " << ans << endl;
            for (auto e : G[now]) {
                if (t[e.to] == INF) {
                    t[e.to] = t[now] + 1;
                    que.push(e.to);
                }
            }
        } else {
            ans = max(ans, dist[now]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9564
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstdio>

#define INF 1000000000
#define reps(i,f,n) for(int i = f; i < int(n); i++)
#define rep(i,n) reps(i,0,n)

using namespace std;


vector<int> e[128];
int used[128];
int ans;

int func(int index, int cost){
	if(used[index])return cost-1;
	int x = 0;
	rep(i,e[index].size()){
		used[index] = 1;
		x = max(func(e[index][i], cost+1), x);
		used[index] = 0;
	}
	return x;
}


int main(void){
	int n;
	while(scanf("%d", &n), n){
		int a,b;
		int mi = 0;
		ans = 0;
		rep(i,128)e[i].clear();
		
		rep(i,n){
			scanf("%d%d", &a, &b);
			if(a > mi)mi = a;
			if(b > mi)mi = b;
			e[b].push_back(a);
			e[a].push_back(b);
		}
		mi++;
		
		reps(i,1,mi){
			rep(i,128)used[i]=0;
			ans = max(func(i,1), ans);
		}
		printf("%d\n", ans);
	}
	return 0;
	
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    string s;
    cin >> s;
    string a[4] = {"dream", "dreamer", "erase", "eraser"};
    bool flag = true;
    while(flag){
        flag = false;
        int n = s.length();
        for (auto &&x : a) {
            if(s.empty() || n < x.length()) continue;
            if(s.substr(n-x.length(), x.length()) == x){
                s = s.substr(0, n-x.length());
                flag = true;
                break;
            }
        }
    }
    cout << (s.empty() ? "YES" : "NO") << "\n";
    return 0;
}


Measured memory_bytes: 512
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  int i;
  int d;
  while(scanf("%d",&d),d){
    int m,n;
    scanf("%d%d",&m,&n);
    int a[100001];
    a[0]=0;
    a[m]=d;
    for(i=1;i<m;++i)
      scanf("%d",a+i);
    sort(a,a+m+1);
    int sm=0;
    for(i=0;i<n;++i){
      int p,q;
      scanf("%d",&p);
      q=upper_bound(a,a+m+1,p)-a;
      sm+=min(p-a[q-1],a[q]-p);
    }
    printf("%d\n",sm);
  }
  return 0;
}

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

 int main() {

int N;
cin >> N;
vector<int>A(N);

for(int i=0; i<N; i++) cin >> A.at(i);

sort(A.begin(),A.end());
cout << A.at(N-1) - A.at(0) <<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int maxn=100000;
int n;
ll a[maxn+5],b[maxn+5];

int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        scanf("%lld%lld",a+i,b+i);
    }
    ll tot=0;
    for (int i=n;i>=1;i--) {
        a[i]+=tot;
        ll rem=a[i]%b[i];
        if (rem>0) tot+=(b[i]-rem);
    }
    printf("%lld\n",tot);
}


Measured memory_bytes: 1792
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/8/ITP2/5/ITP2_5_A
// https://dai1741.github.io/maximum-algo-2012/docs/cpp-sort/

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

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

    std::vector<std::pair<int, int>> pairs(n);
    for (int i = 0; i < n; i++)
    {
        int x, y;
        std::cin >> x >> y;
        pairs[i] = std::make_pair(x, y);
    }

    std::sort(pairs.begin(), pairs.end());

    for (auto &x : pairs)
    {
        std::cout << x.first << " " << x.second << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3636
n,m,l = map(int,input().split())

A = [list(map(int,input().split())) for _ in range(n)]

B = [list(map(int,input().split())) for _ in range(m)]

C = []

for i in range(n):
    yoko = []
    for j in range(l):
        c = 0
        for k in range(m):
            c += A[i][k]*B[k][j]
        yoko.append(c)
    C.append(yoko)

for m in range(n):
    print(*C[m])



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

int main(int argc, char const *argv[]) {
    int N, K, Q, i, j;
    scanf("%d%d%d", &N, &K, &Q);
    int A[N];
    memset(A, 0, N * sizeof(int));
    for (int i = 0; i < Q; i++) {
        scanf("%d", &j);
        A[j - 1]++;
    }
    for (int i = 0; i < N; i++) 
        if (Q - A[i] < K)
            printf("Yes\n");
        else
            printf("No\n");
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

int dp[3009][3009];
string s, t, ans = "";

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

    cin >> s >> t;

    for (int i = 1; i <= s.size(); i++)
    {
        for (int j = 1; j <= t.size(); j++)
        {
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);

            if (s[i - 1] == t[j - 1])
            {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }

    int n = s.size(), m = t.size();
    while (n > 0 && m > 0)
    {
        if (s[n - 1] == t[m - 1])
        {
            ans += t[m - 1];
            n--;
            m--;
        }
        else
        {
            if (dp[n - 1][m] > dp[n][m - 1])
            {
                n--;
            }
            else
            {
                m--;
            }
        }
    }

    reverse(ans.begin(), ans.end());

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

Measured memory_bytes: 38924
N,M = map(int,input().split())

ab_a = []
for i in range(0,N):
    ab = list(map(int,input().split()))
    ab_a.append(ab)

cd_a = []
for i in range(0,M):
    cd = list(map(int,input().split()))
    cd_a.append(cd)

for i in range(0,N):
    mnh = 10 ** 10
    point = 100
    h = 0
    for h in range(0,M):
        tmp = abs(cd_a[h][0] - ab_a[i][0]) + abs(cd_a[h][1] - ab_a[i][1])
        if tmp < mnh:
            mnh = tmp
            point = h
    print(point + 1)

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

using namespace std;

int main(int argc, char const *argv[]) {
	int N;
	std::cin >> N;
	unsigned long long A[N];
	for (size_t i = 0; i < N; i++) {
		std::cin >> A[i];
	}
	sort(A, A+N);
	reverse(A, A+N);
	bool flag = true;
 	unsigned long long x = 0;
	for (size_t i = 1; i < N; i++) {
		if (A[i] == A[i-1]) {
			if (x == 0) {
				x = A[i];
				i++;
			}
			else {
				std::cout << x * A[i] << '\n';
				flag = false;
				break;
			}
		}
	}
	if (flag) {
		std::cout << 0 << '\n';
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
const int N= 100100;
string s[N];
//map<int,map<char,char>>mp;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin>>n;
	int t;
	ll res;
	map<char,ll>m;
	map<char,ll>p;
	int flag=0;
	for(ll i=0;i<n;i++) 
	{
		cin>>s[i];
		m[s[i][0]]++;
		p[s[i][s[i].size()-1]]++;
		if(s[i][0]=='B'&&s[i][s[i].size()-1]=='A')
			flag++;
	}
	ll a=m['B'],b=p['A'];
	ll c=a-flag,d=b-flag;
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		t=s[i].size();
		for(ll j=0;j<t;j++)
		{
			if(s[i][j+1]=='B'&&s[i][j]=='A')
				ans++;
		}
	}
	res=min(b,a);
	ans+=res;
//	cout<<flag<<endl;
//	cout<<ans<<endl;
	if(c==0&&d==0&&flag!=0) ans--; 
	cout<<ans<<endl;
	return 0;
 } 
  

Measured memory_bytes: 1536
N=int(input())
import math
sqN=math.sqrt(N)
sqN=math.ceil(sqN)
i=1
ans=float('inf')
def digits(n):
    return(math.floor(math.log10(n))+1)
while i <= sqN:
    q,r=divmod(N,i)
    if r==0:
        ans=min(ans,max(digits(i),digits(q)))
    i+=1
print(ans)

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

using namespace std;

#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) x.begin(),x.end()
#define debug(x) cout << x << endl;
#define FOR(x) for(int i =0; i < (x) ; i++)

int main(){
    IOS
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << endl; 
    return 0;
}


Measured memory_bytes: 256
def search(start, N, X, Y):
    dist = [0 for _ in range(N)]
    if start <= X:
        for i in range(X):
            dist[i] = abs(start - i)
        for i in range(Y, N):
            dist[i] = (X - start) + 1 + (i - Y)
        for i in range(X, (Y - X) // 2 + X + 1):
            dist[i] = (i - start)
        for i in range((Y - X) // 2 + X + 1, Y):
            dist[i] = (X - start) + 1 + (Y - i)
    elif start >= Y:
        for i in range(Y, N):
            dist[i] = abs(start - i)
        for i in range(X):
            dist[i] = (start - Y) + 1 + (X - i)
        for i in range(X, (Y - X) // 2 + X):
            dist[i] = (start - Y) + 1 + (i - X)
        for i in range((Y - X) // 2 + X, Y):
            dist[i] = (start - i)
    else:
        toX = min(start - X, Y - start + 1)
        toY = min(Y - start, start - X + 1)
        dist[start] = 0
        for i in range(X):
            dist[i] = (X - i) + toX
        for i in range(Y, N):
            dist[i] = toY + (i - Y)
        for i in range(X, start):
            dist[i] = min(start - i, Y - start + 1 + i - X)
        for i in range(start + 1, Y):
            dist[i] = min(i - start, start - X + 1 + Y - i)
    return dist


def main():
    N, X, Y = [int(n) for n in input().split(" ")]
    #N, X, Y = 10, 3, 8

    X = X - 1
    Y = Y - 1

    lenD = []
    for i in range(N):
        d = search(i, N, X, Y)
        lenD.append(d)

    kcounter = [0 for _ in range(N - 1)]

    for i in range(N):
        for j in range(i + 1, N):
            k = lenD[i][j]
            kcounter[k - 1] += 1

    for k in kcounter:
        print(k)

main()

Measured memory_bytes: 137816
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define PUTS(x) cout << (x) << endl;
using Int = long long;
int main() {
    char c = getchar();
    auto results = vector<vector<int>>(0);
    auto current = vector<int>(1, 0);
    int mode = 0; // 0 = 待機なし, 1 = A連続状態, 2 = A連続後のB
    while (c != EOF) {
        switch (mode) {
        case 0:
            switch (c) {
            case 'A':
                mode = 1;
                (*(current.end() - 1))++;
                break;
            default:
                mode = 0;
                current = vector<int>(1, 0);
                break;
            }
            break;
        case 1:
            switch (c) {
            case 'A':
                mode = 1;
                (*(current.end() - 1))++;
                break;
            case 'B':
                mode = 2;
                break;
            default:
                mode = 0;
                current.erase(current.end() - 1);
                results.PB(current);
                current = vector<int>(1, 0);
                break;
            }
            break;
        case 2:
            switch (c) {
            case 'C':
                mode = 1;
                current.PB(0);
                break;
            case 'A':
                mode = 1;
                current.erase(current.end() - 1);
                results.PB(current);
                current = vector<int>(1, 1);
                break;
            default:
                mode = 0;
                current.erase(current.end() - 1);
                results.PB(current);
                current = vector<int>(1, 0);
                break;
            }
            break;
        }
        c = getchar();
    }
    Int ans = 0;
    for (auto &v : results) {
        auto itr = v.rbegin();
        Int i = 1;
        while (itr != v.rend()) {
            ans += ((Int)(*itr)) * i;
            i++;
            itr++;
        }
    }
    PUTS(ans);
}


Measured memory_bytes: 1936
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final long MOD = 1000000007;
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		if(Math.abs(N-M)>1) {
			System.out.println(0);
		} else {
			long ans = 1;
			for(int i=2; i<=N; i++)
				ans = (ans * i)%MOD;
			for(int i=2; i<=M; i++)
				ans = (ans * i)%MOD;
			if(N==M)
				ans = (ans * 2)%MOD;
			
			System.out.println(ans);
		}
		sc.close();
	}
}


Measured memory_bytes: 23764
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;



int main() {
	//fios;
	int x;
	cin >> x;
	if(x == 0) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}

}

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

long long n, mw, fw;
long long w[105] = {0}, v[105] = {0};
long long dp[105][105][305] = {0};

long long solve();

int main() {
  cin >> n >> mw;
  for(long long i = 0; i < n; ++i) cin >> w[i] >> v[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0, fin = mw / w[0], finw = mw % w[0];
  fw = w[0];
  for(long long i = 0; i < n; ++i) w[i] -= fw;
  dp[0][1][0] = v[0];
  for(long long i = 1; i < n; ++i) {
    for(long long j = 1; j <= n; ++j) {
      for(long long k = 0; k <= 300; ++k) {
        if(i != 0) dp[i][j][k] = dp[i - 1][j][k];
        if(i != 0 && k - w[i] >= 0)
          dp[i][j][k] =
              max(dp[i][j][k],
                  dp[i - 1][j - 1][k - w[i]] + v[i]);
      }
    }
  }
  while(fin > 0) {
    for(long long i = 0; i <= min(300LL, finw); ++i)
      ans = max(ans, dp[n - 1][fin][i]);
    --fin;
    finw += fw;
  }
  return ans;
}

Measured memory_bytes: 24960
import java.util.*;

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		int[][] board = new int[3][3];

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				board[i][j] = sc.nextInt();
			}
		}

		if (check(board)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}

	private boolean check(int[][] board) {
		if (board.length != 3 || board[0].length != 3) {
			throw new IllegalArgumentException();
		}
		boolean check = false;
		for (int i = 0; i < 100; i++) {
			int a1 = i;

			int b1 = board[0][0] - a1;
			int b2 = board[0][1] - a1;
			int b3 = board[0][2] - a1;
			if (withoutRange(b1) || withoutRange(b2) || withoutRange(b3)) {
				continue;
			}
			int a2 = board[1][0] - b1;
			if (withoutRange(a2) || (board[1][1] - b2) != a2 || (board[1][2] - b3) != a2) {
				continue;
			}
			int a3 = board[2][0] - b1;
			if (withoutRange(a3) || (board[2][1] -b2) != a3 || (board[2][2] - b3) != a3) {
				continue;
			}
			
			check = true;
			break;
		}
		return check;
	}

	private boolean withoutRange(int x) {
		return (x < 0 && x > 100);
	}
}

Measured memory_bytes: 23380
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int64_t *a1, int64_t *a2) {
  scanf("%lld %lld", a1, a2);
  return 0;
}

void swap(int64_t *a1, int64_t *a2) {
    int64_t tmp = *a1;
    *a1 = *a2;
    *a2 = tmp;
}

#define QUERY_MAX 100

// int main(void) {
//     int queries = get_int();
// 
//     int i;
//     static int64_t ans[QUERY_MAX];
//     int aidx = 0;
//     for(i = 0; i < queries; i++) {
//         int64_t a1, a2;
//         int64_t res;
//         get_int2(&a1, &a2);
//         if(a1 > a2) swap(&a1, &a2);
//         if(a1 == a2) {
//             res = (a1-1)*2; // exclude a1-a2
//         } else if (a1+1 == a2) {
//             res = (a1-1)*2; // exclude a1-a1 and a2-*
//         } else {
//             int64_t sum = a1*a2;
//             int64_t power_2 = (int64_t)sqrt(-0.5 + sum);
//             if(power_2*(power_2+1) >= sum) {
//                 res = (power_2-1)*2;
//             } else {
//                 res = power_2*2-1;
//             }
//         }
//         ans[aidx++] = res;
//     }
// 
//     for(i = 0; i < aidx; i++) {
//         printf("%lld\n", ans[i]);
//     }
//     return 0;
// }
int main(int argc, char const *argv[]){
  int64_t ans;
  int queries = get_int();
  int i;
  for(i = 0;i < queries;i++){
      int64_t a, b;
      get_int2(&a, &b);
      int64_t t=a*b;
      int64_t s=sqrt(t);
      if(a==b) {
          ans = 2*s-2;
      } else if(s*s==t) {
          ans=2*s-2;
      } else if(s*(s+1)>=t) {
          ans=2*s-1;
      } else { 
          ans=2*s;
      }
      if(a!=b) ans--;
      printf("%lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  int total = 0x3f3f3f3f;
  for (int i = 0; i <= 100; i++) {
    int cur = 0;
    for (int x : X) {
      cur += (x - i) * (x - i);
    }
    total = min(total, cur);
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
using namespace std;
int main(void){
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    int H,W,N;
    scanf("%d %d %d",&H,&W,&N);
    int x[N+1],y[N+1];
    char po[1919][1919];
    for(int i=0;i<H;i++)scanf("%s",po[i]);
    for(int i=0;i<H;i++)for(int j=0;j<W;j++){
        if(po[i][j]=='S'){x[0]=j;y[0]=i;}
        if(po[i][j]-'1'>=0&&po[i][j]-'0'<=N){y[po[i][j]-'0']=i;x[po[i][j]-'0']=j;}
    }
    int ans=0;
    for(int i=1;i<=N;i++){
    queue<pair<pair<int,int>,int> > buri;
    buri.push(make_pair(make_pair(y[i-1],x[i-1]),0));
    char tinpo[1919][1919];
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)tinpo[i][j]=po[i][j];
    while(1){
        pair<pair<int,int>,int> unko=buri.front();
        buri.pop();
        int unkox=unko.first.second;
        int unkoy=unko.first.first;
        int unkost=unko.second;
        if(unkox==x[i]&&unkoy==y[i]){ans+=unkost;break;}
        if(unkoy>=0&&unkox>=0&&unkoy<H&&unkox<W){if(tinpo[unkoy][unkox]!='X')for(int i=0;i<4;i++){
            if(unkoy+dy[i]>=0&&unkox+dx[i]>=0&&unkoy+dy[i]<H&&unkox+dx[i]<W&&tinpo[unkoy+dy[i]][unkox+dx[i]]!='X')buri.push(make_pair(make_pair(unkoy+dy[i],unkox+dx[i]),unkost+1));
        }
        tinpo[unkoy][unkox]='X';
            
        }
    }
    }
    printf("%d\n",ans);
    return 0;
}



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

#define INIT_CAP 10
#define INF 1000000000

#define min(a, b) (((a) < (b)) ? (a) : (b))

typedef struct {
	int to, w;
} Edge;

typedef struct {
	Edge *elem;
	int cap, size;
} VecEdge;

typedef struct {
	int num, d;
} PNumDis;

VecEdge adj[65536];
PNumDis heap[1048576];
int hsize;
int d[65536];

void init(int n) {
	while (n--)
		adj[n] = (VecEdge){malloc(sizeof(Edge) * INIT_CAP), INIT_CAP, 0};
}

void add(int from, int to, int w) {
	if (adj[from].size == adj[from].cap) {
		adj[from].cap <<= 1;
		adj[from].elem = realloc(adj[from].elem, sizeof(Edge) * adj[from].cap);
	}
	adj[from].elem[adj[from].size++] = (Edge){to, w};
}

void freeAll(int n) {
	while (n--)
		free(adj[n].elem);
}

void insert(int num, int d) {
	int i;
	for (i = hsize++; i > 0 && d < heap[i - 1 >> 1].d; i = i - 1 >> 1)
		heap[i] = heap[i - 1 >> 1];
	heap[i] = (PNumDis){num, d};
}

int calcNextIdx(int i) {
	return i * 2 + 1 + (i * 2 + 2 < hsize && heap[i * 2 + 1].d > heap[i * 2 + 2].d);
}

PNumDis delete(void) {
	int i;
	int nextIdx;
	const PNumDis root = heap[0], last = heap[--hsize];

	for (i = 0; i * 2 + 1 < hsize && last.d > heap[nextIdx = calcNextIdx(i)].d; i = nextIdx)
		heap[i] = heap[nextIdx];
	heap[i] = last;

	return root;
}

void dijkstra(int n, int s) {
	int i;

	for (i = 0; i < n; i++)
		d[i] = INF;

	d[s] = 0;
	insert(s, 0);
	while (hsize > 0) {
		const PNumDis fromP = delete();

		if (fromP.d > d[fromP.num])
			continue;

		for (i = 0; i < adj[fromP.num].size; i++) {
			const Edge e = adj[fromP.num].elem[i];
			if (fromP.d + e.w < d[e.to]) {
				d[e.to] = fromP.d + e.w;
				insert(e.to, d[e.to]);
			}
		}
	}
}

int main(void) {
	int i, j, k;
	int n, t[16][17];
	int v;

	while (scanf("%d", &n), n) {
		for (i = 0; i < n; i++)
			for (j = 0; j <= n; j++)
				scanf("%d", t[i] + j);

		v = 1;
		for (i = 0; i < n; i++)
			v <<= 1;

		init(v);
		for (i = 0; i < v - 1; i++)
			for (j = 0; j < n; j++)
				if (!(i & 1 << j)) {
					int min = t[j][0];
					for (k = 0; k < n; k++)
						if (i & 1 << k)
							min = min(min, t[j][k + 1]);
					add(i, i | 1 << j, min);
				}

		dijkstra(v, 0);

		printf("%d\n", d[v - 1]);

		freeAll(v);
	}

	return 0;
}

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

#define loop(x) for(int i = x; i--;)
#define ll long long
#define pb push_back
#define pob pop_back

vector<vector<int>> dp;
vector<int> act;
int solve(vector<vector<int>> &numbers, int day, int a) {
    if(day >= numbers.size()) return 0; 
    if(dp[day][a] != INT_MIN)return dp[day][a];
    int temp = 0; 
    loop(3){
        if(i != a){
            temp = numbers[day][a] + solve(numbers, day+1, i);
            if(temp > dp[day][a]) dp[day][a] = temp;
        }
    }
    return dp[day][a];
}

int main(){
    int t = 1;
    // scanf("%d",&t);
    while(t--) {
        int ans = 0;
        int n = 0 , k = 0;
        vector<vector<int>> numbers;
        scanf("%d",&n); // Input size of array
        for(int i = 0; i < n; i++) { // Input array
            vector<int> temp;
            int temps;
            loop(3){
            scanf("%d",&temps);  
            temp.pb(temps);          
            }
            numbers.push_back(temp);
        }
        dp.reserve(n);
        vector<int> temp;
        for(int i = 0; i < 3;i++) {
            temp.pb(INT_MIN);
        }
        for(int i = 0;i < n; i++) {
            dp.push_back(temp);
        }
        cout << max(solve(numbers,0,0),max(solve(numbers,0,1),solve(numbers,0,2))) << "\n";
        
    }
}

Measured memory_bytes: 19376
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a = INT()
s = input()

if a >= 3200:
	print(s)
else:
	print("red")


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();

        string answer = "ABC" + a;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int N, K;
  cin >> N >> K;

  vector<int> a(N,0);
  vector<int> packet(N+1,0);

  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    ++packet[a[i]];
  }

  sort(packet.begin(), packet.end(), std::greater<int>());

  int  ans=0;
  for (int i = 0; i < N; ++i) {
    if(i > K-1)
      ans+=packet[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=100005;
#define ll long long
ll a[N],f[N],d[N];int top=0;
inline void work(ll x,ll y){
	if (!x) return;
	int t=upper_bound(a+1,a+top+1,x)-a-1;
    if(!t) d[1]+=y,d[x+1]-=y;
    else f[t]+=x/a[t]*y,work(x%a[t],y);
}
int main (){
	int n,m;scanf ("%d%d",&n,&m);
	a[++top]=n;
	for (int i=1;i<=m;i++){
		ll x;scanf ("%lld",&x);
		while (x<=a[top]) --top;
		a[++top]=x;
	}
	f[top]=1;
	for (int i=top;i>=2;i--) f[i-1]+=a[i]/a[i-1]*f[i],work(a[i]%a[i-1],f[i]);
	d[1]+=f[1],d[a[1]+1]-=f[1];
	for (int i=1;i<=n;i++) d[i]+=d[i-1],printf ("%lld\n",d[i]);
	return 0;
}

Measured memory_bytes: 4096
def resolve():
    s=input()
    ki='RUD'
    gu='LUD'
    for i in range(len(s)):
        if (i%2==0 and s[i] not in ki) or (i%2==1 and s[i] not in gu):
            print('No')
            break
    else:
        print('Yes')
resolve()

Measured memory_bytes: 38384
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

typedef map<vi, int> E;

E operator+(E a, const E &b){
	each(i, b) a[i->first] += i->second;
	return a;
}
E operator-(E a, const E &b){
	each(i, b) a[i->first] -= i->second;
	return a;
}
E operator*(const E &a, const E &b){
	E c;
	each(i, a) each(j, b){
		vi v = i->first;
		rep(k, 26) v[k] += (j->first)[k];
		c[v] += i->second * j->second;
	}
	return c;
}
int p;
string in, next;
E expr();
void get(){
	next = "";
	while(p < in.size() && isspace(in[p])) p++;
	if(p >= in.size()) return;
	if(isdigit(in[p])){
		while(p < in.size() && isdigit(in[p])) next += in[p++];
	}else{
		next += in[p++];
	}
}
E primary(){
	E res;
	if(isdigit(next[0])){
		vi v(26);
		res[v] = atoi(next.c_str());
		return res;
	}
	if(isalpha(next[0])){
		vi v(26);
		v[next[0] - 'a'] = 1;
		res[v] = 1;
		return res;
	}
	get();
	res = expr();
	return res;
}
E factor(){
	E res = primary();
	get();
	if(next == "^"){
		get();
		int d = atoi(next.c_str()) - 1;
		E e = res;
		while(d--) res = res * e;
		get();
	}
	return res;
}
E term(){
	E res;
	while(1){
		E f = factor();
		if(res.empty()) res = f;
		else res = res * f;
		if(next == "" || next == "+" || next == "-" || next ==")") break;
	}
	return res;
}
E expr(){
	E t = term();
	while(next == "+" || next == "-"){
		bool op = next == "+";
		get();
		E u = term();
		if(op) t = t + u;
		else t = t - u;
	}
	return t;
}

E parse(){
	p = 0;
	get();
	E e = expr();
	each(i, e) if(i->second == 0) e.erase(i);
	return e;
}
int main(){
	while(getline(cin, in), in != "."){
		E a = parse();
		while(getline(cin, in), in != ".")
			cout << (a == parse() ? "yes" : "no") << endl;
		cout << "." << endl;
	}
	return 0;
}

Measured memory_bytes: 1612
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
long long ex[333];
long long sum[333];
int main()
{
	int k=io::F(),n=io::F();
	if(k%2==0)
	{
		printf("%d",k/2);
		for(register int i=1;i<n;++i)printf(" %d",k);
		puts("");
		return 0;
	}
	if(k==1)
	{
		for(register int i=1;i<=(n+1>>1);++i)printf("1 ");
		return 0;
	}
	if(n==1)
	{
		printf("%d\n",k+1>>1);
		return 0;
	}
	ex[0]=1;
	sum[0]=1;
	int pe=0;
	for(pe=1;sum[pe-1]<100000000000LL;++pe)ex[pe]=ex[pe-1]*k,sum[pe]=sum[pe-1]+ex[pe];
	--pe;
	int now=dmax(1,n-pe);
	long long tot=sum[n-now]-now+1+1>>1;
	tot--;
	for(register int i=1;i<=now;++i)printf("%d ",k+1>>1);
	for(++now;now<=n;++now)
	{
		int ans=0;
		for(register int l=1,r=k,mid=l+r>>1;l<=r;mid=l+r>>1)
			if(sum[n-now]*(mid-1)+1<=tot)ans=mid,l=mid+1;
				else r=mid-1;
		if(ans==0)return 0;
		printf("%d ",ans);
		tot-=sum[n-now]*(ans-1)+1;
	} 
	return 0;
}



Measured memory_bytes: 2176
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    h: i64,
    w: i64,
  }
  let ans = if h == 1 || w == 1 {
    1
  } else {
    (h * w + 1) / 2
  };

  puts!("{}\n", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>

int main()
{ 
     int a,b,c;
     scanf("%d",&a);
      if(a==1){
         printf("Hello World\n");
          return 0;
         }
       else
        {
            scanf("%d %d", &b,&c);
            printf("%d\n",b+c);
        }
return 0;
}

          

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string S){
    bool ok = true;
    if(N%2==1) ok = false;
    else {
        for(int i=0;i<N/2;++i){
            if(S[i]!=S[i+N/2]) ok = false;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


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

int main(){
  int N;
  cin>>N;
  
  vector<int> count(4, 0);
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
    
    if(S=="AC"){
      count.at(0)++;
    }
    else if(S=="WA"){
      count.at(1)++;
    }
    else if(S=="TLE"){
      count.at(2)++;
    }
    else if(S=="RE"){
      count.at(3)++;
    }
  }
  
  printf("AC x %d\n", count.at(0));
  printf("WA x %d\n", count.at(1));
  printf("TLE x %d\n", count.at(2));
  printf("RE x %d\n", count.at(3));
}

Measured memory_bytes: 3724
#include<iostream>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#include<cmath>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
	while (a % b != 0) {
		int c = 0;
		c = a % b;
		a = b;
		b = c;
	}
	return  b;
}
string names;

string karuta[100100];
int nn[400];
int main() {
	int N = 0, L = 0;
	int sa = 10000;
	int summ = 0;
	int c = 0;
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		nn[i] = i + L;
		//cout << nn[i] << ' ';
		sa = min(abs(nn[i]), sa);
		if (abs(nn[i]) == sa) {
			c = nn[i];
		}
		summ += nn[i];
	}
	//cout << sa << endl;
	cout << summ - c << endl;
	return 0;
}

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

using ll = long long;

#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 pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll A, B; cin >> A >> B;
	cout << ((A <= B)?A:A-1) << endl;

	return 0;
}


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

int partition(vector<int>& A, int p, int r) {
	int i,j,x=A[r];
	i=p-1;
	for(j=p; j<r; ++j) {
		if(A[j]<=x) {
			++i;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}

int main() {
	int n;
	int i;
	int q;
	vector<int> A;
	scanf("%d",&n);
	A.resize(n);
	for(i=0; i<n; ++i) {
		scanf("%d",&A[i]);
	}
	q=partition(A,0,n-1);
	for(i=0; i<q; ++i) {
		printf("%d ",A[i]);
	}
	if(q==n-1) {
		printf("[%d]\n",A[q]);
	} else {
		printf("[%d] ",A[q]);
		for(i=q+1; i<n-1; ++i){
			printf("%d ",A[i]);
		}
		printf("%d\n",A[n-1]);
	}
	return 0;
}

Measured memory_bytes: 2784
#!/usr/bin/env python
#-*- coding:utf-8 -*-

N = int(raw_input())

A = map(int,raw_input().split())
counter = 0 
for i in range(len(A)):
    for j in range(len(A) - 1, 0, -1):
        if A[j] < A[j-1]:
            A[j],A[j-1] = A[j-1], A[j]
            counter += 1

print ' '.join(map(str,A))
print counter

Measured memory_bytes: 6448
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    bool ans;
    int N,NN;
    while(cin>>N>>NN,N){
        int data[105]={0},ran[105]={0},lank[105]={0},cnt=1,sum[105]={0},FLG=1;
        while(N--){
            for(int i=0;i<NN;i++){
                cin>>ans;
                if(ans!=0){data[i]++;ran[i]++;}
            }
        }
        sort(ran,ran+NN);
        reverse(ran,ran+NN);
        for(int i=0;i<105;i++){
            if(ran[i]==ran[i-1]&&FLG==0)continue;
            for(int j=0;j<105;j++){
                FLG=0;
                if(ran[i]==data[j]){
                    sum[j]=cnt;
                    cnt++;
                }
            }
        }
        int X=1;
        for(int i=0;i<1000;i++){
                for(int j=0;j<NN;j++){
                    if(sum[j]==X){
                        if(FLG==0){cout<<j+1;FLG=1;}
                        else cout<<" "<<j+1;
                        X++;
                    }
                }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1180
#include <cstdio>

typedef struct timestamp {
        int d, f;
} timestamp;

const int N = 100;
bool graph[N][N] {{false}};
timestamp ts[N];
int time = 0;

void search(int n, int cur) {
        if (ts[cur].d) {
                return;
        }
        ts[cur].d = ++time;
        for (int i = 0; i < n; i++) {
                if (graph[cur][i]) {
                        search(n, i);
                }
        }
        ts[cur].f = ++time;
}

int main() {
        int n, u, k, v;
        for (int i = 0; i < N; i++) {
                ts[i].d = ts[i].f = 0;
        }

        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
                scanf("%d %d", &u, &k);
                for (int j = 0; j < k; j++) {
                        scanf("%d", &v);
                        graph[u-1][v-1] = true;
                }
        }
        for (int cur = 0; cur < n; cur++) {
                search(n, cur);
        }
        for (int i = 0; i < n; i++) {
                printf("%d %d %d\n", i+1, ts[i].d, ts[i].f);
        }

        return 0;
}

Measured memory_bytes: 2704
N, M = map(int, input().split())
S = input()
T = input()
# def gcd(a, b):
#     if a < b:
#         return gcd(b, a)
#     else:
#         return a if b == 0 else gcd(b, a % b)

import fractions
def lcm(a, b):
    return a * b // fractions.gcd(b, a % b)


L = lcm(N, M)

f = False

s_step = L // N
t_step = L // M
sL = lcm(s_step, t_step)
s = 0
t = 0

for i in range(0, L, sL):
    if i == 0:
        if S[i] == T[i]:
            continue
        else:
            f = True
            break
    else:
        s = i // s_step
        t = i // t_step
        if s > N - 1:
            break
        if t > M - 1:
            break
        if S[s] == T[t]:
            continue
        else:
            f = True
            break

if f:
    print(-1)
else:
    print(L)



Measured memory_bytes: 5304
#include <iostream>

using namespace std;

int main()
{
    int ch[2][4] = {0};
    double lim[4] = {1.1, 0.6, 0.2, 0.1};
    double l, r;

    while (cin >> l >> r) {
        for (int i = 0; i < 4; i++) 
            if (l >= lim[i]) {
                ch[0][i]++;
                break;
            }
        for (int i = 0; i < 4; i++) 
            if (r >= lim[i]) {
                ch[1][i]++;
                break;
            }
    }

    for (int i = 0; i < 4; i++)
        cout << ch[0][i] << " " << ch[1][i] << endl;

    return 0;
}

Measured memory_bytes: 1224
use proconio::input;

fn cal(mut x: u64) -> u64 {
    let mut ans = 0;
    while 0 != x {
        ans += x % 10;
        x /= 10;
    }
    ans
}

fn main() {
    let mut snuke = vec![];
    let mut ten_p = 1;
    for p in 0..16 {
        for k in std::iter::successors(Some(0), |k| Some(k + 1))
            .filter(|k| k % 10 != 9)
            .take_while(|&k| (k + 1) * ten_p - 1 <= (cal(k) + 9 * p) * ten_p)
        {
            snuke.push(ten_p * (k + 1) - 1);
        }
        ten_p *= 10;
    }
    snuke.sort();

    input!(k: usize);
    for &x in snuke.iter().skip(1).take(k) {
        println!("{}", x);
    }
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define RG register
#define Min(a,b) (a<b?a:b)
#define ll long long

using namespace std;

inline int gi(){
	RG char ch=getchar();RG int x=0,q=0;
	while(ch<'0' || ch>'9') ch=='-'?(q=1):0,ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return q?(-x):x;
}

char s[300000];
int sum[30000];

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1); ll ans=0;
	for (int i=n; i; --i){
		ans+=(n-i-sum[s[i]-'a']);
		++sum[s[i]-'a'];
	}
	cout<<ans+1;
	return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
  std::vector<int64_t> a(n);
  std::cin >> a;
  std::sort(a.begin(), a.end());

  const auto rank = [&](const int64_t val) {
    int64_t ans = 0;
    int64_t max = -3000000000000000000;
    for (auto itr = a.cbegin(); itr != a.cend(); itr++) {
      const auto n1 = *itr;
      if (n1 < 0) {
        const auto min =
            static_cast<int64_t>(std::ceil(static_cast<double>(val) / n1));
        auto itr2 = std::lower_bound(std::next(itr), a.cend(), min);
        if (itr2 != a.cend()) {
          max = std::max(max, *itr2 * n1);
        }
        ans += std::distance(itr2, a.cend());
      } else if (n1 == 0) {
        if (0 <= val) {
          ans += std::distance(std::next(itr), a.cend());
          max = std::max(max, static_cast<int64_t>(0));
        }
      } else {
        const auto min =
            static_cast<int64_t>(std::floor(static_cast<double>(val) / n1));
        auto itr2 = std::upper_bound(std::next(itr), a.cend(), min);
        ans += std::distance(std::next(itr), itr2);
        itr2--;
        if (itr != itr2) {
          max = std::max(max, *itr2 * n1);
        }
      }
    }
    return std::make_pair(ans, max);
  };

  if (k == n * (n - 1) / 2) {
    const auto ans = rank(3000000000000000000);
    std::cout << ans.second << std::endl;
  } else {
    int64_t min = -3000000000000000000, max = 3000000000000000000;
    auto r_min = rank(min), r_max = rank(max);
    while (r_min.first != r_max.first) {
      const auto next = (min + max) / 2;
      const auto r_next = rank(next);
      if (r_next.first < k) {
        r_min = r_next;
        min = next;
      } else if (r_next.first == k) {
        r_min = r_max = r_next;
        min = max = next;
      } else {
        r_max = r_next;
        max = next;
      }

      if (max - min == 1) {
        break;
      }
    }
    std::cout << r_max.second << std::endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#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>;

void solve()
{
    string s;
    cin >> s;
    set<char> st;
    rep(i, 3) st.insert(s[i]);
    if (st.size() == 3)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3636
use std::io::*;
use std::str::FromStr;

enum Answer {
    Good,
    Bad,
}

fn main() {
    let n: usize = read();
    let l: i32 = read();

    let mut eat_ord = 1 - l;
    if eat_ord > 0 {
        if eat_ord <= n as i32 {
        } else if eat_ord > n as i32 {
            eat_ord = n as i32;
        }
    } else if eat_ord <= 0 {
        eat_ord = 1;
    }

    let answer = ( (n * n) as f64 + ( 2.0*l as f64 - 1.0 )*n as f64 + 2.0*(1.0 -l as f64 - eat_ord as f64 )) / 2.0;
    println!("{}", answer);
}

fn security() {
    let s: String = read();
    let mut temp: u8 = 100; 
    let mut answer: Answer = Answer::Good;
    for i in s.as_bytes().iter() {
        if temp == *i {
            answer = Answer::Bad;
            break;
        } else {
            temp = *i;
        }
    }
    match answer {
        Answer::Good => { println!("{}", "Good"); }
        Answer::Bad  => { println!("{}", "Bad"); }
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    ll n;
    while(cin>>n){
        ll ans=0;
        --n;
        ans=(n+1)*n/2;
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 256