akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
vector<int> p,q,a;
int main(void)
{
    int n,t,x,y;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> t;
        p.push_back(t);
    }
    for(int i=1;i<=n;i++)
    {
        cin >> t;
        q.push_back(t);
    }
    for(int i=1;i<=n;i++)
    {
        a.push_back(i);
    }
    int i=0;
    do {
        i++;
        if(p==a) x=i;
        if(q==a) y=i;
    } while (next_permutation(a.begin(), a.end()));
    cout << abs(x-y);
    return 0;
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll N;cin>>N;
    ll ans=0;
    REPS(i,N){
        if(i%2==0)continue;
        ll cnt=0;
        REPS(k,i){
            if(i%k==0)cnt++;
        }
        if(cnt==8)ans++;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
import math
N,D=map(int,input().split())
X=[0]*N
for i in range(N):
  X[i]=list(map(int,input().split()))
count=0
for i in range(N):
  for j in range(i,N):
    dis=0
    for k in range(D):
      dis += pow(X[i][k]-X[j][k],2) 
    dis = math.sqrt(dis)

    if dis==int(dis) and dis!=0:
      count+=1
print(count)

Measured memory_bytes: 3064
#include<string>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<ios>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<type_traits>
#include<random>
#include<vector>

using namespace std;

	

int main()
{
	int  N,M;

	cin >> N >> M;

	int K[N];

	int A[N][M];

	for(int n=0;n<N;n++)
	{
		cin >> K[n];
		for(int m=0;m<K[n];m++)
		{
			cin >> A[n][m];
		}
	}
	int sum = 0;
	for(int mm=0;mm<M;mm++)
	{
		int count = 0;
		for(int i=0;i<N;i++)
		{
			bool judge_mm = 0;
			for(int j=0;j<K[i];j++)
			{
				if(A[i][j]==mm+1)
				{
					judge_mm = 1;
				}
			}
			if(judge_mm==1)
			{
				count = count + 1;
			}
		}
		if(count == N)
		{
			sum = sum + 1;
		}
	}
	cout << sum << endl;
}






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

int main(void)
{
	int i=0,k;
	long int queue[100001];
	long int x;
	int head=1,tail=10;

	for(i=1;i<=9;i++)
		queue[i]=i;

  scanf("%d",&k);

	while(tail<=k){
		x=queue[head++];
		if(x%10!=0)
			queue[tail++]=10*x+x%10-1;
		queue[tail++]=10*x+x%10;
		if(x%10!=9)
			queue[tail++]=10*x+x%10+1;
	}
	printf("%ld",queue[k]);

	return 0;
}


Measured memory_bytes: 896
fun main(args: Array<String>) {
    val (N, X) = readLine()!!.split(" ").map { it.toInt() }
    val Ls = readLine ()!!.split(" ").map { it.toInt() }
    var total: Int = 0
    Ls.forEachIndexed { i,L ->
        total += L
        if (total > X) {
            println(i+1)
            return@main
        }
    }
    println(N+1)
}

Measured memory_bytes: 37820
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node{
    int parent;
    int left;
    int right;
};

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
    if(u==NIL)
        return;
    D[u]=d;
    setDepth(T[u].left,d+1);
    setDepth(T[u].right,d+1);
}

int setHeight(int u){
    int h1=0;
    int h2=0;
    if(T[u].left!=NIL)
        h1=setHeight(T[u].left)+1;
    if(T[u].right!=NIL)
        h2=setHeight(T[u].right)+1;
    return H[u]=(h1>h2?h1:h2);
}

//????????????u???????????????
int getSibling(int u){
    if(T[u].parent==NIL)
        return NIL;
    if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ",u);
    printf("parent = %d, ",T[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg = 0;
    if(T[u].left!=NIL)
        deg++;
    if(T[u].right!=NIL)
        deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",D[u]);
    printf("height = %d, ",H[u]);

    if(T[u].parent==NIL){
        printf("root\n");
    }
    else if(T[u].left==NIL&&T[u].right==NIL){
        printf("leaf\n");
    }
    else{
        printf("internal node\n");
    }
}

int main(){
    int v;
    int l;
    int r;
    int root=0;
    scanf("%d",&n);

    for(int i=0;i<n;i++)
        T[i].parent=NIL;

    for(int i=0;i<n;i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].left=l;
        T[v].right=r;
        if(l!=NIL)
            T[l].parent=v;
        if(r!=NIL)
            T[r].parent=v;
    }

    for(int i=0;i<n;i++)
        if(T[i].parent==NIL)
            root=i;
    setDepth(root,0);
    setHeight(root);

    for(int i=0;i<n;i++){
        print(i);
    }
}

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

int main()
{
	long long  A, B, C, K;
	cin >> A >> B >> C >> K;

	// A:1, B:0, C:-1

	long long  max;
	if(A > K){
		max = K;
	}else{
		max = A;
		if((A+B) < K){
			max += -1 * (K - A - B);
		}
	}

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, d[100000];

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
	}
	sort(d, d + N);
	cout << d[N / 2] - d[N / 2 - 1] << endl;
}

Measured memory_bytes: 640
#include<iostream>
 
int main() {
  int N;
  int p[20];
  int i;

  std::cin >> N;
  for(i=0; i<N; i++)
    std::cin >> p[i];

  int answer = 0;
  for(i=1; i<N-1; i++) {
    if((p[i-1]<p[i] && p[i]<p[i+1]) || (p[i-1]>p[i] && p[i]>p[i+1]))
      answer=answer+1;
  }
  
  std::cout << answer;

  return 0;

}


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

class Progaram
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var a = l[0]; var b = l[1];
        var sum = 1;
        var count = 0;
        while (sum < b)
        {
            sum--;
            sum += a;
            count++;
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13268
//
// ABC179 A - Plural Form
//

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

int main()
{
    // 標準入力から値を受け取る。
    string s;
    cin >> s;

    // 末尾が"s"かどうか判断し
    // 標準出力に結果を出力する。
    if (s.at(s.size() - 1) == 's')
    {
        cout << s << "es" << endl;
    }
    else
    {
        cout << s << "s" << endl;
    }

    // 戻り値
    return (0);
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = Math.toRadians(sc.nextDouble());
        System.out.println(0.5 * a * b * Math.sin(c));
        System.out.println(a + b + Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(c)));
        System.out.println(b * Math.sin(c));
    }
}

Measured memory_bytes: 27844
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	char s[13];
	int i;
	scanf("%s", s);
	for (i = 0; i < 13; i++) {
		if (i <= 3)printf("%c", s[i]);
		if (i == 4)printf(" ");
		if (i >= 5)printf("%c", s[i-1]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	char s[15];
	cin >> s;
	rep(i, 4) {
		cout << s[i];
	}
	cout << " ";
	rep(i, 8) {
		cout << s[i + 4];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long long 
#define INF 10000000000000000LL
#define pll pair<long long , long long>
const int MAX=2e5+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
int pexp[MAX];
int main() 
{

	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n;
    cin>>n;
    if( n>=400 and n<=599)
    	cout<<8;
    else if(n>=600 and n<=799)
    	cout<<7;
    else if(n>=800 and n<=999)
    	cout<<6;
    else if(n>=1000 and n<=1199)
    	cout<<5;
    else if(n>=1200 and n<=1399)
    	cout<<4;
    else if(n>=1400 and n<=1599)
    	cout<<3;
    else if(n>=1600 and n<=1799)
    	cout<<2;
    else if(n>=1800 and n<=1999)
    	cout<<1;

}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, W;
    cin >> N >> W;
    long long weight[N],value[N];
    long long dp[N+1][W+1];
    for(int i=0; i<N; i++){
        cin >> weight[i] >> value[i];
    }
    for(int i=0; i<N+1; i++){
        dp[i][0]=0;
    }
    for(int i=0; i<W+1; i++){
        dp[0][i]=0;
    }
    for(int j=1; j<=W; j++){
        for(int i=1; i<=N; i++){
            if(weight[i-1]>j){
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=max( dp[i-1][j] , dp[i-1][j-weight[i-1]]+value[i-1] );
            }
        }
    }
    cout << dp[N][W];
    return 0;
}

Measured memory_bytes: 79104
n = int(input())
s = [i for i in range(1,14)]
h = [i for i in range(1,14)]
c = [i for i in range(1,14)]
d = [i for i in range(1,14)]
for i in range(n):
    m = input().split()
    if m[0] == "S":
        s.remove(int(m[1]))
    elif m[0] == "H":
        h.remove(int(m[1]))
    elif m[0] == "C":
        c.remove(int(m[1]))
    else:
        d.remove(int(m[1]))
for i in s:
    print("S",i)
for i in h:
    print("H",i)
for i in c:
    print("C",i)
for i in d:
    print("D",i)


Measured memory_bytes: 5620
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    val (h, w) = intList()
    val counter = hashMapOf<Char, Int>()
    repeat(h) {
        val a = readLine() ?: return
        a.forEach { c ->
            counter[c] = counter.getOrDefault(c, 0) + 1
        }
    }
    val one = when {
        h == 1 -> {
            w
        }
        w == 1 -> {
            h
        }
        else -> {
            0
        }
    }
    if (one > 0) {
        val ok = if (one % 2 == 1) {
            counter.values.count { it % 2 == 1 } == 1
        } else {
            counter.values.count { it % 2 == 1 } == 0
        }
        println(if (ok) "Yes" else "No")
        return
    }

    var g1 = 0
    var g2 = 0
    var g4 = 0
    if (h % 2 == 1 && w % 2 == 1) {
        g1 = 1
        g2 = h / 2 + w / 2
        g4 = (h / 2) * (w / 2)
    } else if (h % 2 == 0 && w % 2 == 0) {
        g4 = (h * w) / 4
    } else {
        g2 = if (h % 2 == 0) {
            h / 2
        } else {
            w / 2
        }
        g4 = (h / 2) * (w / 2)
    }
    repeat(g1) {
        counter.entries.find { (it.value - 3) % 4 == 0 || (it.value - 1) % 4 == 0 }?.let {
            counter[it.key] = counter.getOrDefault(it.key, 0) - 1
        }
    }
    repeat(g2) {
        counter.entries.find { (it.value - 2) % 4 == 0 }?.let {
            counter[it.key] = counter.getOrDefault(it.key, 0) - 2
        }
    }
    repeat(g4) {
        counter.entries.find { it.value > 0 && it.value % 4 == 0 }?.let {
            counter[it.key] = counter.getOrDefault(it.key, 0) - 4
        }
    }
    if (counter.values.all { it == 0 }) {
        println("Yes")
    } else {
        println("No")
    }
}


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

using namespace std;
typedef long long int lli;

const int MAXN = 100010;

int n, k;

int v[MAXN];

lli sv[MAXN];
lli optPrefix[MAXN];
lli optSuffix[MAXN];

int main()
{
	scanf("%d %d",&n,&k);

	for(int i = 1 ; i <= n ; i++)
		scanf("%d",&v[i]);

	for(int i = 1 ; i <= n ; i++)
	{
		sv[i] = sv[i - 1] + v[i];
		optPrefix[i] = optPrefix[i - 1] + max( v[i] , 0 );
	}

	for(int i = n ; i > 0 ; i--)
		optSuffix[i] = optSuffix[i + 1] + max( v[i] , 0 );

	lli ans = 0;

	for(int L = 1 ; L + k - 1 <= n ; L++)
	{
		int R = L + k - 1;

		lli curAns = optPrefix[ L - 1 ];
		curAns += optSuffix[ R + 1 ];
		curAns += max( 0LL , sv[R] - sv[L - 1] );

		ans = max( ans , curAns );
	}

	printf("%lld\n",ans);
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int n;
const double th = M_PI * 60.0 / 180.0;
struct Point
{
    double x;
    double y;
};

void KochCurve(Point p1, Point p2, int i)
{
    if (i == n)
    {
        printf("%.8lf %.8lf\n", p1.x, p1.y);
        return;
    }
    else
    {
        Point s, u, t;
        s.x = (p1.x * 2.0 + p2.x * 1.0) / 3.0;
        s.y = (p1.y * 2.0 + p2.y * 1.0) / 3.0;
        t.x = (p1.x * 1.0 + p2.x * 2.0) / 3.0;
        t.y = (p1.y * 1.0 + p2.y * 2.0) / 3.0;
        u.x = s.x + (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th);
        u.y = s.y + (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th);
        KochCurve(p1, s, i + 1);
        KochCurve(s, u, i + 1);
        KochCurve(u, t, i + 1);
        KochCurve(t, p2, i + 1);
    }
}

int main()
{
    cin >> n;
    Point p1, p2;
    p1.x = 0;
    p1.y = 0;
    p2.x = 100;
    p2.y = 0;
    KochCurve(p1, p2, 0);
    printf("%.8lf %.8lf\n", p2.x, p2.y);
    return 0;
}


Measured memory_bytes: 3180
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;

int n, m;
LL ans;

priority_queue <int> Q;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1, x; i <= n; i ++)
	{
		scanf("%d", &x);
		Q.push(x);
	}
	while (m --)
	{
		int t = Q.top();
		Q.pop();
		Q.push(t / 2);
	}
	while (!Q.empty())
	{
		ans += Q.top();
		Q.pop();
	}
	printf("%lld\n", ans);
	return 0;
}

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

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

  int a, p;
  cin >> a >> p;
  cout << (a * 3 + p) / 2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define P(s) {printf(s"\n");continue;}
int main(void){int m,f,r,s;for(;;){scanf("%d%d%d",&m,&f,&r);if((s=m+f)+r==-3)exit(0);if((m==-1)|(f==-1)|(s<30))P("F")if(s>=80)P("A")if(s>=65)P("B")if((s>=50)|(r>=50))P("C") P("D")}}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    rep (i,A) cin >> p[i];
    rep (i,B) cin >> q[i];
    rep (i,C) cin >> r[i];
    // 降順(リバースイテレーター)
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    vector<int> d;
    rep(i,X) d.push_back(p[i]);
    rep(i,Y) d.push_back(q[i]);
    rep(i,C) d.push_back(r[i]);
    sort(d.rbegin(), d.rend());
    ll ans = 0;
    rep(i,X+Y) ans += d[i];
    cout << ans << endl;

}

Measured memory_bytes: 4724
#include<iostream>
#define MAX_HW 1001
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll h,w;
ll dp[MAX_HW][MAX_HW];
string s[MAX_HW];
ll f(ll x,ll y){
  if(x<0||x>=h||y<0||y>=w) return 0;
  if(s[x][y]=='#') return 0;
  if(dp[x][y]!=-1)return dp[x][y];
  ll tmp=0;
  tmp = f(x-1,y) + f(x,y-1);
  tmp%=MOD;
  return dp[x][y]=tmp;
}
signed main(){
  cin >> h >> w;
  fill(dp[0],dp[MAX_HW],-1);
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  dp[0][0]=1;
  cout << f(h-1,w-1)<<endl;
}


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

int P[101];

void init(int N)
{
	for (int i=0; i<=N; ++i) 
	    P[i] = i;
} 

int root(int a)
{
	if(P[a]==a)   
	   return a;
	else  return(P[a]=root(P[a]));
}
 
bool is_same_set(int a,int b)
{
	return(root(a)==root(b));
}

void unite(int a,int b)
{
	P[root(a)]=root(b);
}

int main()
{
	int n,m;
	while(cin >> n >> m)
    {
        if(!n && !m)
          break;
        init(n);
	    int cost[101000],src[101000],dst[101000];
	    for(int i=0;i<m;i++)
	    {
            cin >> src[i] >> dst[i] >> cost[i];
		}
	    pair<int,int> edges[101000];
	    for(int i=0;i<m;i++)
	    {
		    edges[i].first=cost[i];
		    edges[i].second=i;
	    }
	    sort(edges,edges+m);
        int flag=100000;
	    for(int i=0;i<m;i++)
	    {
            int count=0;
            init(n);
            for(int j=i;j<m;j++)
            {
                if(is_same_set(src[edges[j].second],dst[edges[j].second]))
		          continue;
		        unite(src[edges[j].second],dst[edges[j].second]);
                count++;
                if(count==n-1)
                {
                   flag=min(edges[j].first-edges[i].first,flag);
                   break;
                }   
            }
	    }
        if(flag==100000)
          flag=-1;
	    cout << flag << endl;
    }
}


Measured memory_bytes: 3916
#import pysnooper
import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy

setrecursionlimit(10**6)

n=int(input())
s=input()
print(s if n>=3200 else "red")

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

int main() {
    string S, T;
    cin >> S >> T;
    int ans = T.length();
    for(int i = 0; i <= S.length() - T.length(); i++) {
        int d = 0;
        for(int j = 0; j < T.length(); j++) {
            if(T[j] != S[i + j]) {
                d++;
            }
        }
        ans = min(ans, d);
    }
    cout << ans;
}

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

int main() {
    string s;
    cin >> s;
    string f, se;
    f.push_back(s.at(0));
    f.push_back(s.at(1));
    se.push_back(s.at(2));
    se.push_back(s.at(3));

    if (("13" <= f || f == "00") && "01" <= se && se <= "12")
        puts("YYMM");
    else if (("13" <= se || se == "00") && "01" <= f && f <= "12")
        puts("MMYY");
    else if ("01" <= se && se <= "12" && "01" <= f && f <= "12")
        puts("AMBIGUOUS");
    else 
        puts("NA");
    return 0;
}

Measured memory_bytes: 256
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

def llcs(x, y):
    pm = dict((zip(ascii_letters, [0] * 52)))
    for c in pm:
        for i, xc in enumerate(x):
            if c == xc:
                pm[c] |= (1 << i)
    
    V = (1 << len(x)) - 1
    
    for yc in y:
        V = ((V + (V & pm[yc])) | (V & ~pm[yc]))
    
    ans = bin(V)[-len(x):].count('0')
    
    return ans

from sys import stdin

def solve():
    file_input = stdin
    q = int(file_input.readline())
    for i in range(q):
        s1 = file_input.readline().rstrip()
        s2 = file_input.readline().rstrip()
        print(llcs(s1, s2))

solve()


Measured memory_bytes: 5624
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

const long double PI = 3.141592653589793;

int main(){
    long double a,b,x;
    cin >> a >> b >> x;
    long double S = x/a;
//    if(2*S<=a*b){
    //    cout << "45.0000000000" << endl;
    if(a*b>=2*S){
        cout << fixed << setprecision(10) << atan2(b,2*S/b)*180/PI << endl;
    }else{
        cout << fixed << setprecision(10) << 90-atan2(a,2*(a*b-S)/a)*180/PI << endl;
    }
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    vector<int> b(n - 1);
    rep(i, n-1)
        cin >> b.at(i);
    int ans = 0;
    ans = b.at(0);

    for (int i = 1; i < n - 1; i++) {
        ans += min(b.at(i - 1), b.at(i));
    }
    ans += b.at(n - 2);

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


Measured memory_bytes: 256
x,y = map(int,input().split())
mod =10**9+7
 
a=(-x+2*y)//3
b=(2*x-y)//3
n=a+b
 
def fact(x,p):
    ret=1
    for i in range(1,x+1):
        ret*=i
        ret%=p
    return ret
 
 
if a+2*b==x and b+2*a==y and a>=0 and b>=0:
    ans=fact(n,mod) * pow(fact(b,mod),mod-2,mod)*pow(fact(a,mod),mod-2,mod)
    print(ans%mod)
else:
    print("0")

Measured memory_bytes: 38512
package main

import (
	"fmt"
	"sort"
)

func main() {
	var k, x int
	fmt.Scanf("%d %d", &k, &x)

	if k == 1 {
		fmt.Print(x)
		return
	}

	var puls []int
	for i := 0; i < k; i++ {
		puls = append(puls, x+i)
	}

	var d []int
	for i := 1; i < k; i++ {
		d = append(d, x-i)
	}
	sort.Sort(sort.IntSlice(d))
	cal := append(d, puls...)

	for _, c := range cal {
		fmt.Print(c)
		fmt.Print(" ")
	}

}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = ReadIntArray();
            List<string> ret = new List<string>();

            for (int i = 0; i < HW[0]; i++)
            {
                var add = Read();
                ret.Add(add);
                ret.Add(add);
            }

            foreach (var item in ret)
            {
                Console.WriteLine(item);
            }
        }


        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

Measured memory_bytes: 13396
N,M = map(int,input().split())
E = [list(map(int,input().split())) for m in range(M)]
dp = (N+1)*[float("inf")]
dp[1] = 0

for n in range(N):
  for a,b,c in E:
    dp[b] = min(dp[b],dp[a]-c)

x = dp[N]

for a,b,c in E:
  dp[b] = min(dp[b],dp[a]-c)

if x!=dp[N]:
  print("inf")
else:
  print(-x)

Measured memory_bytes: 9304
#include <iostream>
using namespace std;
int main(){
  
  int a;
  cin>>a;
  
  double b;
  
  if(a%2!=0){
    b=((double)(a+1)/2)/(double)a;
  }
  else{
    b=((double)a/2)/(double)a;
  }
  
  cout<<b;
  
  
  return 0;
}


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

struct state {
  int i, j;
  int hp;
  int time;
  state(int a, int b, int c, int d = 0) : i(a), j(b), hp(c), time(d) {}
  bool operator<(const state& rhs) const
  {
    return time > rhs.time;
  }
};

int main()
{
  int w, h;
  while (cin >> w >> h && w != 0) {
    priority_queue<state> q;
    vector<vector<int> > grid(h, vector<int>(w));
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> grid[i][j];
        if (grid[i][j] == 2) {
          grid[i][j] = 1;
          q.push(state(i, j, 6));
        }
      }
    }

    vector<vector<vector<int> > > dist(h, vector<vector<int> >(w, vector<int>(6, 1000000)));
    dist[q.top().i][q.top().j][5] = 0;
    while (!q.empty()) {
      state s = q.top();
      q.pop();
      if (grid[s.i][s.j] == 3) {
        cout << s.time << endl;
        goto NEXT;
      }
      if (grid[s.i][s.j] == 4) {
        s.hp = 6;
      }
      if (s.hp == 1) {
        continue;
      }

      for (int d = 0; d < 4; d++) {
        static const int dir_i[] = {-1, 1, 0, 0};
        static const int dir_j[] = {0, 0, -1, 1};
        const int next_i = s.i + dir_i[d];
        const int next_j = s.j + dir_j[d];
        if (0 <= next_i && next_i < h && 0 <= next_j && next_j < w && grid[next_i][next_j] != 0
            && s.time+1 < dist[next_i][next_j][s.hp-1-1]) {
          q.push(state(next_i, next_j, s.hp-1, s.time+1));
          dist[next_i][next_j][s.hp-1-1] = s.time+1;
        }
      }
    }
    cout << -1 << endl;
NEXT:;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <set>
#include <cstring>
using namespace std;

const int64_t mod = 998244353;

int64_t PowMod(int64_t a, int64_t n) {
  int64_t p = a % mod,
          res = 1;
  while (n > 0) {
    if (n & 1) (res *= p) %= mod;
    (p *= p) %= mod;
    n >>= 1;
  }
  return res;
}

int ComputeChecksum(const string& s) {
  int sum = 0;
  for (char c : s) (sum += c - 'a') %= 3;
  return sum;
}

void BruteForce(const string& s, set<string>& strs) {
  strs.insert(s);

  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) continue;

    string new_s = s;
    char new_c = 'a' ^ 'b' ^ 'c' ^ s[i] ^ s[i + 1];
    new_s[i] = new_s[i + 1] = new_c;

    if (!strs.count(new_s)) BruteForce(new_s, strs);
  }
}

int main() {
  string s;
  cin >> s;

  bool same_all = true,
       diff_all = true;
  for (int i = 0; i < s.size() - 1; i++) {
    same_all = same_all && (s[i] == s[i + 1]);
    diff_all = diff_all && (s[i] != s[i + 1]);
  }

  if (same_all or s.size() <= 3) {
    set<string> strs;
    BruteForce(s, strs);

    cout << strs.size() << endl;
    return 0;
  }

  static int64_t dp[200000][3][3];  // (添字, checksum, 最後に使った文字)
  memset(dp, 0, sizeof(dp));

  dp[0][0][0] = dp[0][1][1] = dp[0][2][2] = 1;

  for (int i = 0; i < s.size() - 1; i++) {
    for (int sum = 0; sum < 3; sum++) {
      for (int d = 0; d < 3; d++) {
        for (int nd = 0; nd < 3; nd++) {
          if (d == nd) continue;
          (dp[i + 1][(sum + nd) % 3][nd] += dp[i][sum][d]) %= mod;
        }
      }
    }
  }

  int checksum = ComputeChecksum(s);
  int64_t ans = PowMod(3, s.size() - 1);
  for (int d = 0; d < 3; d++) ans = (ans - dp[s.size() - 1][checksum][d] + mod) % mod;

  // 今の時点でansは少なくとも1文字は重なりがある
  if (diff_all) ans++;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 14596
using System;

namespace Kyopuro
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());

            string[] str = Console.ReadLine().Split(' ');
            int[] num = new int[a];

            int i;

            bool isNG = false;


            for (i = 0; i < a; i++)
            {
                num[i] = int.Parse(str[i]);
            }


            Array.Sort(num);

            for (i = 1; i < a; i++)
            {
                if (num[i] == num[i - 1])
                {
                    isNG = true;
                }
            }


            if (isNG)
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }


        }
    }
}

Measured memory_bytes: 31196
#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
using namespace std;
const int MAXN = (int) 105;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int m,n;
vector<pair<int,int> > g;

void work(){
    while(~scanf("%d%d",&n,&m)){
        if(m==0&&n==0) return;
        int tot=0;
        g.clear();
        for(int i=1;i<=n;i++){
            int d,p; scanf("%d%d",&d,&p);
            tot+=d;
            g.push_back(make_pair(p,d));
        }
        sort(g.begin(),g.end());
        int ans=0;
        tot-=m;
//        printf("tot = %d , m = %d\n",tot,m);
        for(int i=0;tot>0&&i<g.size();i++){
            int p=g[i].first;
            int d=g[i].second;
            if(tot>d){
                tot-=d;
                ans+=d*p;
            }
            else{
                ans+=tot*p;
                tot=0;
            }
        }
        printf("%d\n",ans);
    }
}

int main(){
#ifdef NNever
    freopen("data.in","r",stdin);
    freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}



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

int main(){
	int n;
  	string s;
  	cin >> n >> s;
  
  	bool ok = true;
  	if(n % 2 == 1) ok = false;
  	rep(i, n/2){
    	if(s[i] != s[i + n/2]) ok = false;
    }
  
  	if(ok) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	int a[]=new int[100];
	int max=0;
	while(scan.hasNext())
	    {
		int x=scan.nextInt()-1;
		
		a[x]++;
		
		for(int i=0;i<100;i++)
		    {
			if(max<a[i])
			    {
				max=a[i];
			    }
		    }
		
		
	    }
	for(int i=0;i<100;i++)
	    {
		if(a[i]==max)System.out.println(i+1);
	    }
    }
}

Measured memory_bytes: 18152
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
inline int Log2(ll x) {int k; for(k=0; x>0; ++k) x>>=1; return k;} // number of binary digits
template<typename T> inline int count_between(vector<T>& a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l); // [l, r)
}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {
  rep(i, v.size()) is >> v[i]; return is;
}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
  rep(i, v.size()) os << v[i] << " "; return os;
}
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


int main() {
  ll n, k; cin >> n >> k;

  ll ans;
  ll m = n % k;
  if (m <= k/2) ans = m;
  else ans = abs(m-k);

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


Measured memory_bytes: 256
n,m=map(int,input().split())
abc=[tuple(map(int,input().split())) for _ in range(m)]
Inf=float('inf')
dist=[Inf]*n
dist[0]=0
for i in range(n):
    for a,b,c in abc:
        a,b,c=a-1,b-1,-c
        if dist[b] >dist[a]+c:
            dist[b]=dist[a]+c
            if i==n-1 and b==n-1:
                print('inf')
                exit()
print(-dist[-1])

Measured memory_bytes: 9336
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n,m;
  cin >> n >> m;
  
  vector<pair<int,int>> vn(n);
  vector<pair<int,int>> vm(m);
  
  rep(i,n){
    int a,b;
    cin >> a >> b;
    vn[i] = make_pair(a,b);
  }
  rep(i,m){
    int c,d;
    cin >> c >> d;
    vm[i] = make_pair(c,d);
  }
  

  rep(i,n){
    int d_tmp;
    int ans;
    int d = 1 << 30;
    rep(j,m){
      d_tmp = abs(vn[i].first - vm[j].first) + abs(vn[i].second - vm[j].second);
      //printf("i=%d, j=%d, d_tmp=%d\n",i,j,d_tmp);
      if(d_tmp < d){
        d = d_tmp;
        ans = j+1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
 
ans=0
for i in range(1,N+1):
    n=K/i
    p=0
    while n>1:
        n/=2
        p+=1
    if p==0: ans+=1
    else: ans+=1/(2**p)
    
 
print(ans/N)

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <array>
#include <limits>
#define _USE_MATH_DEFINES
#include <cmath>
#include <tuple>
#include <queue>
#include <functional>
#include <list>

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

const int MAX_NODE_NUM = 10005;
const int MAX_EDGE_NUM = 100005;

list<tuple<int,int>> adjLists[MAX_NODE_NUM];
bool isNodeInST[MAX_NODE_NUM];
int main() {
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int w, s, t;
		cin >> s >> t >> w;
		adjLists[s].push_back(make_tuple(w,t));
		adjLists[t].push_back(make_tuple(w, s));
	}

	using EdgeType = tuple<int, int>;
	priority_queue<EdgeType, vector<EdgeType>, greater<EdgeType>> q;
	long long cost = 0;
	int stNodeNum = 0;
	int newNode = 0;
	int newCost = 0;
	q.push(make_tuple(newCost, newNode));
	while (stNodeNum < n) {
		tie(newCost, newNode) = q.top();
		q.pop();
		if (isNodeInST[newNode] == false) {
			isNodeInST[newNode] = true;
			cost += newCost;
			stNodeNum++;
			for (auto t : adjLists[newNode]) {
				q.push(t);
			}
		}
	}
	
	cout << cost << endl;

	return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int m = s.size();
  int n = t.size();
  vector<vector<int>> dp(m+1, vector<int>(n+1));
  for (int i = 0; i <= m; ++i) dp[i][0] = 0;
  for (int j = 0; j <= n; ++j) dp[0][j] = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
      else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
    }
  }
  string a;
  int i = m;
  int j = n;
  while (i > 0 && j > 0) {
    if (dp[i][j] == dp[i-1][j]) --i;
    else if (dp[i][j] == dp[i][j-1]) --j;
    else {
      a.push_back(s[i-1]);
      --i; --j;
    }
  }
  reverse(a.begin(), a.end());
  cout << a << endl;

  return 0;
}


Measured memory_bytes: 35584
#include<iostream>
using namespace std;
#define n 44
int F[n],Fl[n];
int fibonacci(int na)
{
    if( na == 1 || na == 2)
        return F[na] = 1;
    if(F[na])
        return F[na];
    return F[na] = fibonacci(na - 1) +fibonacci(na - 2 ) ;
}

void makeFibonacci()
{
    Fl[1] = Fl[0] = 1;
    for(int i=2;i<=n;i++)
    {
        Fl[i] = Fl[i-1] + Fl[i-2];
    }
}

int main()
{
    int na;
    cin>>na;
    //cout<<fibonacci(na)%10007<<endl;
    makeFibonacci();
    cout<<Fl[na]<<endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double A,B,C,D,H,K,L,M,N,T,W,X;
  
  string S;
  cin >> N >> K;
  vector<long long> vec(N),vsum(N);
  for (int i=0;i<N;i++) {
   cin >> vec.at(i);
   if (i==K-1) {
     for (int j=0;j<K;j++)  {
	   A+=vec.at(j); //Aは1~K番目の総和
	 }
	 B=A; //Bは総和の最大
   }
   else if (i>K-1) {
     A=A+vec.at(i)-vec.at(i-K);
	 if (A>B) {B=A;}
   }
  }
  cout << fixed << setprecision(10) << (B+K)/2 << endl;  
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define maxn 1000005
#define mod 998244353
using namespace std;
int n,m,fac[maxn],inv[maxn],ans;
int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
int mul(int a,int b){return 1ll*a*b%mod;}
int ksm(int a,int b)
{
    int s=1;
    for(;b;b>>=1,a=mul(a,a))
        if(b&1) s=mul(s,a);
    return s;
}
int C(int a,int b) {return mul(fac[a],mul(inv[b],inv[a-b]));}
int main()
{
    fac[0]=inv[0]=1;
    for(int i=1;i<maxn;i++)
        fac[i]=mul(fac[i-1],i),inv[i]=ksm(fac[i],mod-2);
    scanf("%d%d",&n,&m);
    if(n<m) swap(n,m);
    for(int i=1;i<=m;i++)
        ans=add(ans,mul(C(i+i,i),C(n+m-2*i,n-i)));
    ans=mul(ans,mul((mod+1)/2,ksm(C(n+m,n),mod-2))),printf("%d\n",add(ans,n));
    return 0;
}

Measured memory_bytes: 7936
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0]*N
    B=[]
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            if ans[j-1] == 1:
                cons += 1
        if A[i-1] == 1 and cons % 2 == 0:
            ans[i-1] = 1
            B.append(i)
            continue
        if A[i-1] == 0 and cons % 2 == 1:
            ans[i-1] = 1
            B.append(i)
            continue
            
    print(len(B))
    print(*B)
            	
if __name__ == "__main__":
	main()


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

int main(){
	string s;
	cin >> s;
	int i=0, j=s.size()-1;
	for(i=0;i<j;i++){
		if(s[i]=='A') break;
	}
	for(j=s.size()-1; i<j; j--){
		if(s[j]=='Z') break;
	}
	cout << j-i+1 << endl;
}

Measured memory_bytes: 640
n = gets.to_i
d = gets.split.map(&:to_i)
mul = 0
max = 0
roots = Array.new(100000,0)
d.each do |i|
  roots[i] += 1
  max = i if max < i
end
mul = 1 if d[0] == 0 && roots[0] == 1
1.upto(max) do |i|
  mul *= roots[i-1]**roots[i]
end
puts mul % 998244353

Measured memory_bytes: 57180
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int R = Integer.parseInt(sc.next());
        sc.close();

        if (R < 1200) {
            out.printf("ABC\n");
        } else if (R < 2800) {
            out.printf("ARC\n");
        } else {
            out.printf("AGC\n");
        }
        out.flush();
    }
}


Measured memory_bytes: 23636
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define fe(vec,lambda) std::for_each(vec.begin(), vec.end(), lambda );
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#define printv(val) std::for_each(val.begin(),val.end(),[](auto x){cout<<x<<"\n";});
#define lim 1000000007ll
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T& a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T& b,T a){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template <class T> T gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T lcm(T a, T b){return a * b / gcd(a, b);}
inline bool operator<(const pii &lhs,const pii &rhs){return(lhs.second<rhs.second);}
template<class T> vector<pair<T,T>> duplicator(const vector<T>& input){vector<pair<T,T>> out(input.size()-1);rep(i,input.size()-1){out[i].first =input[i  ];out[i].second=input[i+1];}return(out);}
vector<char> String_to_vector_char(const string& input){vector<char> out(input.size());rep(i,input.size()){out[i]=input[i];}return out;}
void YesNo(bool flag){ cout<<(flag? "Possible":"Impossible");}

ll a,b,c,d,n,x;
vector<ll>v[3];
map<ll,ll>m;
string s,s2;
void input(){
    cin>>s2;
    s="ABC";
}
void src(){
    cout<<(s+s2);
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int ans = s.size() / 2;
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == 'p') --ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def cmb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denom[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numer[k - offset] /= pivot
                denom[k] /= pivot

    result = 1
    for k in range(r):
        if numer[k] > 1:
            result *= int(numer[k])

    return result


def solve(N: int, M: int, K: int):

    sx = 0
    for x in range(1, M+1):
        sx += x*(x-1)//2
        sx %= MOD
    sx *= N*N
    sx %= MOD

    sy = 0
    for y in range(1, N+1):
        sy += y*(y-1)//2
        sy %= MOD
    sy *= M*M
    sy %= MOD

    s = (sx+sy) % MOD
    s = (s*cmb(N*M-2, K-2)) % MOD
    print(s)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, M, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11576
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll intpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = intpow(N, P/2);
        return t*t;
    }
    return N * intpow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}
ll dp[100000][13];
ll p=1e9+7;
int main(){
    string s;cin>>s;
    ll n=s.size();
    rep(i,100000){
        rep(j,13)dp[i][j]=0;
    }
    if(s[n-1]=='?')rep(i,10)dp[0][i]=1;
    else dp[0][s[n-1]-'0']=1;
    ll a[13];//amari
    rep(i,6){
        a[i]=intpow(10,i)%13;
    }
    rep(i,n-1){
        if(s[n-2-i]=='?'){
            rep(j,13){
                rep(k,10){
                    dp[i+1][(j+k*a[(i+1)%6])%13]+=dp[i][j];
                    dp[i+1][(j+k*a[(i+1)%6])%13]%=p;
                }
            }
        }
        else{
            
            rep(j,13)dp[i+1][(j+(s[n-2-i]-'0')*a[(i+1)%6])%13]+=dp[i][j];
        }
    }
    cout<<dp[n-1][5]<<endl;
}

Measured memory_bytes: 10624
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    mat = [list(map(int, readline().split())) for _ in range(n - 1)]

    for i in range(n):
        ct = 0
        for c, s, f in mat[i:]:
            if ct < s:
                ct = s
            if (ct-s) % f != 0:
                ct = ct + (f - ((ct-s) % f))
            ct += c
        print(ct)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40432
card_a = list(input())
card_b = list(input())
card_c = list(input())
len_a = len(card_a)
len_b = len(card_b)
len_c = len(card_c)
turn = 'a'

while True:
    if turn == 'a':
        if len_a == 0:
            print("A")
            break
        if len_a > 0:
            turn = card_a.pop(0)
            len_a = len(card_a)
            continue
    if turn == 'b':
        if len_b == 0:
            print("B")
            break
        if len_b > 0:
            turn = card_b.pop(0)
            len_b = len(card_b)
            continue
    if turn == 'c':
        if len_c == 0:
            print("C")
            break
        if len_c > 0:
            turn = card_c.pop(0)
            len_c = len(card_c)
            continue


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

using namespace std;




int main(int argc, char** argv)
{
	int num;
	cin >> num;
	cin.ignore();
	vector<int64_t> array(num);

	int64_t sum = 0;
	for (int i = 0; i < num; i++) {
		std::cin >> array[i];
		sum += array[i];
	}

	int64_t sum2 = array[0];
	sum -= array[0];
	int64_t diff = abs(sum2 - sum);
	for (int i = 1; i < (num - 1); ++i)
	{
		sum2 += array[i];
		sum -= array[i];
		int64_t tmp_diff = abs(sum2 - sum);
		if (diff > tmp_diff)
			diff = tmp_diff;
	}

	cout << diff;


	return 0;
}

Measured memory_bytes: 1792
n = int(input())

isprime = [True for i in range(55556)]
isprime[0] = False
isprime[1] = False
for i in range(4, 55556, 2):
    isprime[i] = False
for i in range(3, 237):
    if isprime[i]:
        for j in range(i*3, 55556, i*2):
            isprime[j] = False
ans = []
for i in range(55556):
    flag = False
    if isprime[i] and i % 5 == 1:
        ans.append(i)
    if len(ans) == n:
        break
for i in ans:
    print(i, end=' ')

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL);
#define endl '\n'
using namespace std;


int main(){
        fast_io
        string s,t;
        cin>>s>>t;
        int c=0;
        for(int i=0;i<3;i++)
            if(s[i]==t[i])
                c++;
            cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[2005];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,x,y,hhh;
	cin >> n >> x >> y;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			hhh=min(abs(i-j),abs(i-x)+abs(j-y)+1);
			//cout << i << " " << j << " " << hhh << endl;
			a[hhh]++;
		}
	}
	for(int i=1;i<n;i++){
		cout << a[i] << endl;
	} 
	return 0;
}


Measured memory_bytes: 256
nd = STDIN.gets().split(" ")

res = 0
for i in 1..nd[0].to_i
  s = STDIN.gets().split(" ")
  d = s[0].to_i * s[0].to_i + s[1].to_i * s[1].to_i
  if d <= nd[1].to_i * nd[1].to_i
    res += 1
  end
end

puts res

Measured memory_bytes: 14432
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
vector<int> v;
int fun(int l,int r,int m){
	if(r==l)return v[l]-m;
	if(r<l)return 0;
	int me=*min_element(v.begin()+l,v.begin()+r+1);
	int ans=me-m;
	int n=v.size();
	vector<int> vv;
	for(int i=l;i<=r;i++){
		if(v[i]==me)vv.pb(i);
	}
	ans+=fun(l,vv[0]-1,me)+fun(vv[vv.size()-1]+1,r,me);
	int g=vv[0]+1;
	for(int i=1;i<vv.size();i++){
		ans+=fun(g,vv[i]-1,me);
		g=vv[i]+1;
	}
	return ans;
}
int main(){
ios;
	int n;cin>>n;
	int x;
	for(int i=0;i<n;i++){
		cin>>x;
		v.pb(x);
	}
	cout<<fun(0,n-1,0)<<endl;
}

Measured memory_bytes: 256