akhauriyash/Code-Regression huggingface dataset:
import copy

N = int(input())
A = input().split(' ')


A1 = copy.deepcopy(A)
for i in range(N-1):
    for j in reversed(range(i+1, N)):
        if A1[j][1] < A1[j-1][1]:
            A1[j], A1[j-1] = A1[j-1], A1[j]
print(*A1)
print('Stable')

A2 = copy.deepcopy(A)
for i in range(N-1):
    minj = i
    for j in range(i+1, N):
        if A2[j][1] < A2[minj][1]:
            minj = j
    A2[i], A2[minj] = A2[minj], A2[i]
print(*A2)

if A1 == A2:
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 6336
/* Tuan Kkura */
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define PROB "text"
#define MAXN 200005

ll S[MAXN];

int main()
{
    _io
    int n, k; cin >> n >> k;
    map <ll, int> M;
    ll sum = 0;
    ll res = 0;
    M[0]++;
    int j = 0;
    FOR(i, 1, n)
    {
        if(i-j >= k)
        {
            M[S[j]-j]--;
            j++;
        }
        int x; cin >> x;
        sum = (sum + x)%k;
        S[i] = sum;
        res += M[sum-i];
        res += M[sum-i+k];
        //cout << i << ' ' << M[sum-i] << ' ' << M[sum-i+k] << '\n';
        //cout << sum-i << ' ' << sum-i+k << '\n';
        M[sum-i]++;
    }
    cout << res;
}


Measured memory_bytes: 26880
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    string S;cin>>S;
    int ans=0;
    REP(i,S.size()/2){
        if(S[i]!=S[S.size()-i-1])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//
//  GRL_1_A.cpp
//  AizuOnlineJudge
//
//  Created by jiji on 2020/01/21.
//  Copyright © 2020 jiji4000. All rights reserved.
//

#include <iostream>
#include <queue>
using namespace std;
#define MAX 100000
#define WHITE 0
#define GRAY 1
#define BLACK 2

// 重み付き有向グラフの隣接リスト
vector<pair<int,int> > adj[MAX];

void dijkstra(int n,int startIndex){
    priority_queue<pair<int,int> >pq;
    // weight[v]に始点sからvまでの最短コストを保存する
    int weight[MAX];
    // 訪問状態を記録
    int color[MAX];
    // 1.初期化
    for(int i = 0;i < n;++i){
        weight[i] = __INT_MAX__;
        color[i] = WHITE;
    }
    
    // 始点
    weight[startIndex] = 0;
    color[startIndex] = GRAY;
    pq.push(make_pair(0,startIndex));
    
    // 2
    while(!pq.empty()){
        // 2.1最小である頂点の決定
        pair<int,int> first = pq.top();
        pq.pop();
        // 頂点
        int u = first.second;
        color[u] = BLACK;
        // 最短値を取りだして、最短でなければ飛ばす
        if(weight[u] < first.first * -1) continue;
        // uに隣接する頂点vが存在する限り最短店を更新する
        for(int i = 0;i < adj[u].size();++i){
            int v = adj[u][i].first;
            if(color[v] == BLACK)continue;
            // 2.2最短点の更新
            if(weight[v] > weight[u] + adj[u][i].second){
                weight[v] = weight[u] + adj[u][i].second;
                // priority_queueはデフォルトで大きい値を優先するので-にする
                pq.push(make_pair(weight[v] * -1, v));
                color[v] = GRAY;
            }
        }
    }
    
    for(int i = 0;i < n;++i){
        if(weight[i] == __INT_MAX__){
            cout << "INF" << endl;
        }
        else{
            cout << weight[i] << endl;
        }
    }
}

int main(){
    int begin,vNum,sideNum;
    cin >> vNum >> sideNum >> begin;
    
    int s,t,d;
    for(int i = 0;i < sideNum;++i){
        cin >> s >> t >> d;
        //gMatrix[s][t] = d;
        adj[s].push_back(make_pair(t,d));
    }
    dijkstra(vNum,begin);
}



Measured memory_bytes: 13452
import itertools
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A.sort()
Balls = [len(list(g)) for k, g in itertools.groupby(A)]
Balls.sort(reverse=True)
cnt = 0
while len(Balls) > K:
    cnt += Balls.pop()
print(cnt)

Measured memory_bytes: 25636
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
 int a,b;
 cin >> a >> b;
 cout << (a+b)%24 << endl;
}


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

#define MAX_S 100000

char s[MAX_S + 1];
char alf[26] = "abcdefghijklmnopqrstuvwxyz";

int main(void)
{
	int l;
	int i, j;
	
	gets(s);
	l = strlen(s);
	
	for( i=0; i<26; i++ ) {
		for( j=0; j<l; j++ ) {
			if ( s[j] == alf[i] ) break;
		}
		if ( j == l ) break;
	}
	
	if ( i == 26 ) printf( "None\n" );
	else printf( "%c\n", alf[i] );
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main()
{
	int n;
	cin >> n;
	memset(a,0,sizeof(a));
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int min=a[0],cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]<=min){
			min=a[i];
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<algorithm>
#define ll long long
using namespace std;
ll dp[50][1<<17];
const ll mod=1e9+7;
int n,x,y,z;
int main()
{
scanf("%d%d%d%d",&n,&x,&y,&z);
memset(dp,0,sizeof(dp));
dp[0][0]=1;
ll ans=1;
int base=((1<<(z-1))|(1<<(y+z-1))|(1<<(x+y+z-1)));
for(int i=1;i<=n;i++)
    ans=ans*10%mod;
    int sta=(1<<(x+y+z))-1;
    for(int i=1;i<=n;i++)
    {
        for(int s=0;s<=sta;s++)
        {if(dp[i-1][s]==0)
        continue;
            for(int k=1;k<=10;k++)
            {
                int now=(s<<k)|(1<<k-1);
                now&=sta;
                if((now&base)!=base)
                    dp[i][now]=(dp[i][now]+dp[i-1][s])%mod;
            }
        }
    }
        for(int i=0;i<=sta;i++)
            ans=(ans-dp[n][i]+mod)%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 51584
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
const int N=2e3+7;
int dp[N][N];
int a[N],b[N];
const ll mod=1e9+7;
int n,m;
ll solve(int i,int j){
	if(dp[i][j]!=-1) {
		return dp[i][j];
	}
	if(i==n+1||j==m+1) {
		return 0;
	}
	ll ans=0;
	if(a[i]==b[j]) {
		ans= 1+solve(i,j+1)+solve(i+1,j);
	}
	else {
		ans=solve(i,j+1)+solve(i+1,j)-solve(i+1,j+1);
	}
	ans+=mod;
	ans%=mod;
	return dp[i][j]=ans;
}
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	cin>>n>>m;
	memset(dp,-1,sizeof dp);
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=m; i++) cin>>b[i];
	ll ans=solve(1,1)+1;
	ans%=mod;
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 16256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed _main(){
  int N; cin >> N;
  v<int> X(N);
  rep(i,N) cin >> X[i];
  int ans=INF;
  for(int i=1;i<=100;i++){
    int res=0;
    rep(j,N){
      res+=(X[j]-i)*(X[j]-i);
    }
    chmin(ans,res);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long n, i, x, min, max, sum;
    cin >> n;
    min = 1000000;
    max = -1000000;
    sum = 0;
    for(i = 0; i < n; i++){
        cin >> x;
        if(x < min) min = x;
        if(x > max) max = x;
        sum += x;
    }
    
    cout << min << " " << max << " " << sum << endl;
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N,A[200010],k=1;		cin>>N;
	FOR(i,0,N){
		cin>>A[i];
		if(A[i]==k)	k++;
	}
	if(k==1)	cout<<"-1"<<endl;
  	else cout<<N-k+1<<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 < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

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


Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = 10**9

for i in range(N-(K-1)):
    L = x[i]
    R = x[i+K-1]
    route1 = abs(L) + R - L
    route2 = abs(R) + R - L
    temp = min(route1, route2)
    ans = min(ans, temp)
    
print(ans)

Measured memory_bytes: 14252
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
mx = max(a)
flag = [True]*(mx+1)
c = Counter(a)
a.sort()
ans = 0
for i in range(n):
    if flag[a[i]]:
        if c[a[i]] == 1: ans += 1
        for j in range(2*a[i],mx+1,a[i]): flag[j] = False
print(ans)

Measured memory_bytes: 125196
import java.util.Scanner;

class Main
{

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if (a == b && c == d || a == c && b == d || a == d && b == c) {
            System.out.println("yes");
        } else {
            System.out.println("no");
        }

    }

}



Measured memory_bytes: 26320
/*input
RDULULDURURLRDULRLR
*/

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

int main() {
    string s;
    cin >> s;
    rep(i, s.size()) {
        if ((i%2 == 0 && s[i] == 'L')
          || (i%2 == 1 && s[i] == 'R')) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_6_C>
 */

func init() {
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var B [4][3][10]int
	for i := 0; i < n; i++ {
		var b, f, r, v int
		fmt.Scanf("%d%d%d%d", &b, &f, &r, &v)
		b--; f--; r--
		B[b][f][r] += v
	}

	for i:= 0; i < 4;i++{
		for j:=0;j<3;j++{
			for k:=0;k < 10;k++{
				fmt.Printf(" %d",B[i][j][k])
			}
			fmt.Print("\n")
		}
		if i != 3{
			fmt.Println("####################")
		}
	}
}



Measured memory_bytes: 1148
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
//#define int long long
#define PI 3.14159265
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int mod=1e9+7;
int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    char arr[n+1][m+1];
    int dp[n+1][m+1]={};
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>arr[i][j];
    dp[1][1]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
                if(i==1&&j==1)
                dp[i][j]=1;
                if((i-1)>0&&arr[i-1][j]=='.')
                dp[i][j]+=dp[i-1][j]%mod;
                if((j-1)>0&&arr[i][j-1]=='.')
                dp[i][j]+=dp[i][j-1]%mod;
        }
    }
    cout<<dp[n][m]%mod<<endl;
}


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

class dice{
	public:
	int d[6];

	void rolls(string str){
		for(int i = 0; str[i] != '\0'; i++)
			roll(str[i]);
	}
	void roll(char in){//4 2 1 6 5 3
		int direc[4][6]={
			{1,5,2,3,0,4},//n
			{3,1,0,5,4,2},//e
			{4,0,2,3,5,1},//s
			{2,1,5,0,4,3}//w
		};
		int news;
		int temp_d[6];
		if(in =='N')news = 0;
		if(in =='E')news = 1;
		if(in =='S')news = 2;
		if(in =='W')news = 3;
		for(int i = 0;i < 6;i++)
			temp_d[i] = d[direc[news][i]];
		for(int i = 0;i < 6;i++)
			d[i] = temp_d[i];
	}
	void print(void){
		for(int i = 0;i < 6; i++){
			cout << d[i];
			if(i==6-1)cout << endl;
			else cout << " ";
		}
	}
};

int checkdice(dice d1, dice d2){
	int i;
	for(i = 0;i < 6;i++)
		if(d1.d[i] != d2.d[i])
			break;
	if(i==6)return 1;
	return 0;
}

int completely_checkdice(dice d1, dice d2){
	int r = 0;

	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}

	d2.roll('N');
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	d2.roll('S');

	d2.roll('W');
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	d2.roll('E');

	d2.roll('E');
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	d2.roll('W');

	d2.roll('S');
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	d2.roll('N');

	d2.rolls("SS");
	for(int i = 0;i < 4;i++){
		r+=checkdice(d1,d2);
		d2.rolls("SEN");
	}
	
	if(r>0)return 1;//same
	return 0;//notsame
}

int main(){
	dice dices[100];
	int n;
	string ans = "Yes";
	
	cin >> n;
	for(int t = 0;t < n;t++){
		for(int i = 0;i < 6; i++){
			cin >> dices[t].d[i];
		}
	}
	for(int i = 0;i < n;i++){
		for(int t = i+1; t < n;t++){
			if(completely_checkdice(dices[i], dices[t]) == 1){
				ans = "No";
				i = t = n;
			}
		}
	}
	cout << ans << endl;
    return 0;
}

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

int main(){

    int N,A;
    set<int> s{};
    cin >> N;
    
    for(int i=0;i<N;i++){
        cin >> A;
        if(s.count(A) == 0) s.insert(A);
        else s.erase(A);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 8072
import math

#n = int(input())
#a = int(input())
#n,a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
string1 = input()
string2 = input()
#ls = [int(input()) for i in range(n)]

ls1 = list(string1)
ls1.sort()
string1 = "".join(ls1)
ls2 = list(string2)
ls2.sort(reverse=True)
string2 = "".join(ls2)
if string1 < string2:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

dic = {}
for i in a:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

sum = 0
for k in dic:
    v = dic[k]
    sum += k*v

for i in bc:
    if i[0] in dic:
        if i[1] in dic:
            dic[i[1]] += dic[i[0]]
        else:
            dic[i[1]] = dic[i[0]]
        o = (i[1]- i[0])*dic[i[0]]
        dic[i[0]] = 0
        sum += o
    print(sum)

Measured memory_bytes: 104844
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;


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

    ll n; cin >> n;
    vector<ll> div;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            div.push_back(i);
            if(i * i != n) div.push_back(n / i);
        }
    }

    ll ans = 0;
    for(auto it : div){
        if(it == 1) continue;
        if(n % (it - 1) == n / (it - 1)) ans += (it - 1);
    }
    cout << ans << endl;
}

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

int main(){
    int n; cin >> n;
    vector<int> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];
    float ave = 0;
    for(int i = 0; i < n; i++) ave += x[i];
    ave /= n;
    int loc = round(ave);
    ll ans = 0;
    for(int i = 0; i < n; i++) ans += (x[i]-loc)*(x[i]-loc);
    cout << ans << endl;
}

Measured memory_bytes: 256
N,A,B = map(int,input().split())

if A == 0:
    print(0)
else:
    if N > A+B:
        a = N // (A+B)
        b = N % (A+B)
        if b > A:
            b = A
        print(a*A + b)
    else:
        if A > N:
            print(N)
        else:
            print(A)
            

Measured memory_bytes: 3060
#include <cstdio>
#include<iostream>

using namespace std;
   
int main(void){
  
	int c1,c2,c3;
	int sum,num;

	while(cin>>c1>>c2>>c3){
		sum=0,num=0;
		for(int i=1;i<=10;i++){
			if(i!=c3&&i!=c2&&i!=c1){
				num++;
				if(c1+c2+i<=20) sum++;
			}
		}
		if((double)sum/num>=0.5) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

    return 0;
}

Measured memory_bytes: 1152
N = int(input())
Assertions = []
ansnum = 0

for i in range(N):
    b = []
    n = int(input())
    for j in range(n):
        xi,yi = map(int,input().split())
        b.append([xi-1,yi])
    Assertions.append(b)

for i in range(2**N):
    select = []
    
    ans = [0 for _ in range(N)]
    index = []
    flag = True
    
    for j in range(N):
        if ((i >> j) & 1):
            select.append(Assertions[j])
            
            index.append(j)
            
            ans[j] = 1
            
    
    for idx in index:
        for Assert in Assertions[idx]:
            if ans[Assert[0]] != Assert[1]:
                flag = False
                break
    
    if flag:
        ansnum = max(ansnum,len(index))

print(ansnum)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	set<string> st;
	ll n; cin >> n;
	zep(i, 0, n){
		string s; cin >> s;
		st.insert(s);
	}
	print(st.size())
	return 0;
}

Measured memory_bytes: 19236
#include<bits/stdc++.h>
using namespace std;
int n;
int a[105];
int q[105];
int s1,s2,ans=1e9;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		q[i]=q[i-1]+a[i];
	}
	for(int i=1;i<n;i++){
		s1=q[i];
		s2=q[n]-q[i];
		ans=min(ans,abs(s2-s1));
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 500100
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
char s[maxn];
int a[maxn];
int len;
bool check(int x)
{
    int sum = x * 9, cnt = 0;
    for (int i = 0; i < len; i++)
    {
        sum += a[i];
        cnt += sum % 10;
        sum /= 10;
    }
    while (sum > 0)
    {
        cnt += sum % 10;
        sum /= 10;
    }
    return cnt <= x * 9;
}
int main()
{
    while (~scanf("%s", s))
    {
        memset(a, 0, sizeof(a));
        len = strlen(s);
        reverse(s, s + len);
        for (int i = 0; i < len; i++)
            a[i] = (s[i] - '0') * 9;
        for (int i = 0; i < len; i++)
        {
            a[i + 1] += a[i] / 10;
            a[i] %= 10;
        }
        if (a[len])
            len++;
        int l = 0, r = len * 2, ans = -1;
        while (l < r)
        {
            int mid = l + r >> 1;
            if (check(mid))
            {
                ans = mid;
                r = mid;
            }
            else
                l = mid + 1;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 2688
import sys
z='abcdefghijklmnopqrstuvwxyz'
e=lambda x,i,j:z[(z.index(x)*i+j)%26]
def f():
 for i in range(1,26,2):
  for j in range(26):
   if''.join(e(c,i,j)for c in'that')in s or''.join(e(c,i,j)for c in'this')in s:return(i,j)
input()
for s in sys.stdin:
 s=s.strip()
 k=f()
 print(s.translate(str.maketrans(''.join(e(c,*k)for c in z),z)))


Measured memory_bytes: 5576
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int a; int b;
    cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int n, A[30];
 
int solve(int i, int m)
{
 int res;

 if(m == 0)
  return 1;
 else if(i >= n)
  return 0;

 res = solve(i+1, m) || solve(i+1, m - A[i]);
 return res;

}

 int main(void)

{
 int q, i;
 int B[2000];

 scanf("%d", &n);
 
 for(i = 0; i < n; i++)
 scanf("%d", &A[i]);

 scanf("%d", &q);

 for(i = 0; i < q; i++)
 scanf("%d", &B[i]);

for(i = 0; i < q; i++)
{
 if(solve(0, B[i]))
  printf("yes\n");
 else
  printf("no\n");
 }






return 0;

}

 


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  vector<int>A(N),B(N);
  int64_t suma=0,sumb=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    suma+=A[i];
  }
  for(int i=0;i<N;i++){
    cin>>B[i];
    sumb+=B[i];
  }
  if(suma<sumb){cout<<-1<<endl;return 0;}
  int64_t r=0,cnt=0;
  vector<int64_t>bag;
  for(int i=0;i<N;i++){
    if(A[i]<B[i]){r+=B[i]-A[i];cnt++;}
    if(A[i]>B[i]){bag.push_back(A[i]-B[i]);}
    //cout<<cnt<<endl;
  }
  sort(bag.rbegin(),bag.rend());
  for(int i=0;i<bag.size();i++){
    if(r<=0){break;}
    cnt++;r-=bag[i];//cout<<bag[i]<<endl;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 4632
/*
  the solution from editorial
*/
#pragma optimize("O3")
#include<bits/stdc++.h>
using namespace std;

long long t, a, b, c, d;
int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> t;
  while(t--){
    cin >> a >> b >> c >> d;
    if(a < b || d < b) cout << "No\n";
    else if(c >= b) cout << "Yes\n";
    else{
      if(a %  __gcd(b, d) > c - b + __gcd(b, d)) cout << "No\n";
      else cout << "Yes\n";
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
	int n1, n2, A[10000], B[10000];
	int i, j, k, l = 0;
	int count = 0;

	scanf("%d", &n1);

	for (i = 0;i < n1;i++) {
		scanf("%d", &A[i]);
	}

	scanf("%d", &n2);

	for (i = 0;i < n2;i++) {
		scanf("%d", &B[i]);
	}
	
	for (i = 0;i < n2;i++) {
		for (j = 0;j < n1;j++) {
			if (A[j] == B[i]) {
				count++;
				break;
			}
		}
	}

	printf("%d\n", count);




	return 0;
}
 



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

int a[200005];
vector<int> aa;

int main()
{
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++) {
    scanf("%d",a+i);
    aa.push_back(a[i]);
  }
  sort(aa.begin(), aa.end());
  int ml = aa[n/2 - 1], mr = aa[n/2];
  for(int i=0;i<n;i++) {
    if(a[i] <= ml) printf("%d\n",mr);
    else printf("%d\n",ml);
  }
}


Measured memory_bytes: 3828
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String str1 = scan.nextLine();
		String str2 = scan.nextLine();
		scan.close();

		int n = Integer.parseInt(str1);
		String[] ai = str2.split(" ", 0);

		int sVal = 0;
		int min = Integer.parseInt(ai[0]);
		for (int i = 0; i < n - 1; i++) {
			int num1 = Integer.parseInt(ai[i]);
			int num2 = Integer.parseInt(ai[i + 1]);
			if (num1 <= num2) {
				sVal = num1;
			} else {
				sVal = num2;
			}
			if (sVal <= min) {
				min = sVal;
			}
		}

		int bVal = 0;
		int max = Integer.parseInt(ai[0]);
		for (int i = 0; i < n - 1; i++) {
			int num1 = Integer.parseInt(ai[i]);
			int num2 = Integer.parseInt(ai[i + 1]);
			if (num1 <= num2) {
				bVal = num2;
			} else {
				bVal = num1;
			}
			if (max <= bVal) {
				max = bVal;
			}
		}

		long sum = Integer.parseInt(ai[0]);
		for (int i = 1; i < n; i++) {
			long num = Integer.parseInt(ai[i]);
			sum += num;
		}

		System.out.println(min + " " + max + " " + sum);

	}
}

Measured memory_bytes: 31212
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	poole = {}

	for i in range(1,N+1):
		ii = str(i)
		start = ii[0]
		end = ii[-1]

		if (start,end) in poole:
			poole[(start,end)] += 1
		else:
			poole[(start,end)] = 1

	ans = 0
	for i in range(1,N+1):
		ii = str(i)
		start = ii[0]
		end = ii[-1]

		if (end,start) in poole:
			tmp = poole[(end,start)]
			ans += tmp

	print(ans)







if __name__ == "__main__":
	main()


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




int main(){
   int n;
   cin>>n;
   int cnt=0;
   int a[101],b[101],c[101];
   rep(i,n)cin>>a[i];
   rep(i,n)cin>>b[i];
   rep(i,n-1)cin>>c[i];
   rep(i,n){
       cnt+=b[a[i]-1];
       if(i!=n-1){
           if(a[i]+1==a[i+1]){
               cnt+=c[a[i]-1];
           }
       }
   }
   cout<<cnt<<endl;
   return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define inf 10000000000000
#define ll unsigned long long
#define boostUP ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fsr(i,n) for(ll i=0;i<n;i++)
#define fcr(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define sz(arr) sizeof(arr)/sizeof(arr[0])
#define mod 1000000007;

using namespace std;
// lower_bound
// it returns pos of the elmnt which is not less then the query elmnt

int main() {
    int n; cin >> n;
    string str;
    cin >> str;
    int count = 0;
    for(int i = 0; i < n-2 ; i++){
        if(str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C'){
            count++;
        }
    }
    cout << count << endl;
}





Measured memory_bytes: 3608
#include<stdio.h>

int main(void){
	int H,W,a[100000],b,c=0,d=0,e=0;
	/*scanf("%d %d",&H,&W);
	a[b]=H;
	a[b+1]=W;*/
	for(b=0;;b++){
		scanf("%d %d",&H,&W);
		a[b]=H;
		a[b+1]=W;
		if(a[b]+a[b+1]==0){
			break;
		}
		b++;
	}
	/*printf("%d %d",a[4],a[5]);*/
	/*???????????????????????£?¢??????¨??????????????\?????????????????????????????\????????????????????????????????????*/
	for(b=0;a[b]+a[b+1]!=0;b++){
		/*printf("%d %d\n",a[b],a[b+1]);*/
		/*??????????????????????????£?¢??????¨2???????????\?????????????????????????????\????????????????????????????????????*/
		for(c=0;c<a[b];c++){
			if(c==0||c>=a[b]-1){
				for(e=0;e<a[b+1];e++){
					printf("#");
					if(c>=a[b]){
						printf("\n");
					}
				}
			}else{
				printf("#");
				for(e=0;e<a[b+1]-2;e++){
					printf(".");
				}
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
		b++;
	}
		return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
#define mod 1000000007
int main()
{	
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int w=1;
	// cin>>w;
	while(w--){
		int n;
		cin>>n;
		int arr[n][3];
		// cin>>arr[0][0]>>arr[0][1]>>arr[0][2];
		for(int i=0;i<n;i++){
			cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
		}
		int dp[n][3];
		dp[0][0]=max(arr[0][1],arr[0][2]);
		dp[0][2]=max(arr[0][0],arr[0][1]);
		dp[0][1]=max(arr[0][0],arr[0][2]);
		F(i,1,n){
			dp[i][0]=max(dp[i-1][1],dp[i-1][2])+arr[i][0];
			dp[i][1]=max(dp[i-1][0],dp[i-1][2])+arr[i][1];
			dp[i][2]=max(dp[i-1][0],dp[i-1][1])+arr[i][2];
		}
		cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

	}
}

Measured memory_bytes: 5836
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N;
map< vector<int>, int > dp;

int solve(vector<int>& vec, int sum = 0, int id = 1) {
    int res = 0;
    if(sum == 10) {
        res++;
        sum = 0; id = 1;
    }
    if(dp.count(vec)) return dp[vec];

    int add = 0;
    for(int i=id; i<=9; i++) {
        if(vec[i] > 0 && sum + i <= 10) {
            vec[i]--; sum += i;
            chmax(add, solve(vec, sum, i));
            vec[i]++; sum -= i;
        }
    }
    res += add;

    if(sum == 0) dp[vec] = res;
    return res;
}

signed main() {
    while(cin >> N, N) {
        dp.clear();
        vector<int> countManju(11);

        for(int i=0; i<N; i++) {
            int val; cin >> val;
            countManju[val]++;
        }
        
        int ans = 0;
        for(int i=1; i<5; i++) {
            int add = min(countManju[i], countManju[10 - i]);
            ans += add;
            countManju[i     ] -= add;
            countManju[10 - i] -= add;
        }
        ans += countManju[5] / 2;
        countManju[5] %= 2;

        ans += solve(countManju);
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 12064
"use strict"

function main(arg) {
  
   const input = arg.trim().split("\n");

    let health = parseInt(input[0].split(" ")[0]);
    const numberOfMoves = parseInt(input[0].split(" ")[1]);
    const attacts = input[1].split(" ").map(n=>parseInt(n));

  	let count = 0;
  	let i = 0;
  	while(health > 0){
      count++
		if( i >= attacts.length){
        	i = 0;        	
        }
      
	    health = health - attacts[i];
      
            i++
    }
  
  
  	if(count > numberOfMoves){
    	console.log("No");
    }else{
    	console.log("Yes");
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 16716
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  int l=0,r=N+1;
  string T;
  puts("0");
  fflush(stdout);
  cin>>T;
  if(T=="Vacant")return 0;
  while(r-l>1){
    int n=(l+r)/2;
    cout<<n<<endl;
    fflush(stdout);
    string S;
    cin>>S;
    if(S=="Vacant")return 0;
    if((S!=T && (n-l)%2==1) || (S==T && (n-l)%2==0)){
      l=n;
      T=S;
    }
    else r=n;
  }
  cout<<l<<endl;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
	long long n; cin >> n;
	long long a[n], sum[n] = {};
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(i == 0) sum[i] = a[i];
		else sum[i] += sum[i-1] + a[i];
	}

	long long ans = 0;
	for (int i = 0; i < n-1; i++)
	{
		long long tmp = a[i] * ((sum[n-1] - sum[i]) % mod) % mod;
		ans = (ans + tmp) % mod;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

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

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

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    int k;
    cin>>s;
    cin>>k;

    vector<string> v;

    REP(i,s.size()){
        REP(j,min(5,(int)s.size()))
            v.emplace_back(s.substr(i,j+1));
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)), v.end());

    //DEBUG_VEC(v);
    
    cout << v[k-1] << endl;
    return 0;
}

Measured memory_bytes: 1660
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 1000010

int main()
{
	int n , m;
	cin >>n >>m;
	m/=1000;
	for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            for(int l = 0;l<=n-i-j;l++){
                if(l*10+j*5+i==m&&(i+j+l==n))
                    return cout<<l <<" "<<j <<" "<<i<<endl,0;
            }
        }
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	int k, x;
	cin >> k >> x;

	printf("%s", k * 500 >= x ? "Yes" : "No");

	return 0;
}



Measured memory_bytes: 3760
#include <iostream>
#include <string>

using namespace std;

int str_count(string s, char c)
{
    int count = 0;
    for (int i = 0; i < 4; i++) {
        if (s[i] == c) count++;
    }
    return count;
}
int main()
{
    string S;

    cin >> S;
    cout << str_count(S, '+') - str_count(S, '-') << endl;
}

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

#define ll long long
#define mx 2005
#define mod 1000000007

int n,m,ii,k;
int ar[mx];
char ch[mx];

ll dp[mx];

ll func(int val)
{
    if(val==0)return 1;
    ll &re=dp[val];
    if(re!=-1)return re;
    re=0;
    for(int i=3;i<=n;i++)
    {
        if(val>=i)
        {
            re+=func(val-i);
            re%=mod;
        }
        else break;
    }
    return re;
}

int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n);
    printf("%lld",func(n));

    return 0;
}



Measured memory_bytes: 3836
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


public class Main{
	
	public static Vec init(Vec v){
		int sx=v.x.get(0);
		int sy=v.y.get(0);
		
		for(int i=0;i<v.x.size();i++){
			v.x.set(i,v.x.get(i)-sx);
			v.y.set(i,v.y.get(i)-sy);
			
		}
		
		return v;
	}
	
	public static Vec roll(Vec v){
		for(int i=0;i<v.x.size();i++){
			int vx=v.x.get(i);
			int vy=v.y.get(i);
			v.x.set(i,-vy);
			v.y.set(i,vx);
			
		}
		return v;
	}
	
	public static void check(Vec v1,Vec v2,int num,int row){
		
		for(int i=0;i<4;i++){
			v2=roll(v2);
			//debug!!
			
			/*if(row==4&&num==4){
				System.out.println(v1);
				System.out.println(v2);
				System.out.println("===");
				
			}*/
			
			if(comp(v1,v2)){
				System.out.println(num);
				break;
			}
		}
	}
	
	
	public static boolean comp(Vec v1,Vec v2){
		if(v1.x.size()!=v2.x.size()) return false;
		for(int i=0;i<v2.x.size();i++){
			if((v1.x.get(i)!=v2.x.get(i))||(v1.y.get(i)!=v2.y.get(i))){
				return false; 
			}
		}
		return true;
	}
	
	public static Vec reverseVec(Vec v){
		Collections.reverse(v.x);
		Collections.reverse(v.y);
		return v;
		
		
	}
	
	
	
	
	public static void Solve(){
		int n,nodeN;
		Scanner stdin =new Scanner(System.in);
		ArrayList<Integer> px;
		ArrayList<Integer> py;
		ArrayList<Integer> x;
		ArrayList<Integer> y;
		
		
		int row=0;
		while(true){
			n=stdin.nextInt();
			row++;
			
			if(n==0) break;
				Vec v=null;
				for(int i=0;i<n+1;i++){
					ArrayList<Integer> ans=new ArrayList<Integer>();
					//if(i==2) break;
					if(i==0){
						nodeN=stdin.nextInt();
						px=new ArrayList<Integer>();
						py=new ArrayList<Integer>();
						
						for(int j=0;j<nodeN;j++){
							px.add(stdin.nextInt());
							py.add(stdin.nextInt());
						}
						
						v=new Vec(px,py);
						//System.out.println("init:"+v);
					}else{
						nodeN=stdin.nextInt();
						x=new ArrayList<Integer>();
						y=new ArrayList<Integer>();
						for(int j=0;j<nodeN;j++){
							x.add(stdin.nextInt());
							y.add(stdin.nextInt());
							
						}
						Vec v2=new Vec(x,y);
						//System.out.println(i+" "+v2);
						//??????
						v=init(v);
						v2=init(v2);
						check(v,v2,i,row);
						reverseVec(v2);
						v2=init(v2);
						check(v,v2,i,row);
						
						
					}
					
				}
				
				System.out.println("+++++");
				
				
			}
		}
	
	public static void main(String args[]){
		Main m =new Main();
		m.Solve();
	}
	
}

class Vec{
	ArrayList<Integer> x;
	ArrayList<Integer> y;
	public Vec(ArrayList<Integer> x,ArrayList<Integer>y){
		this.x=x;
		this.y=y;
		
	}
	public String toString(){
		return this.x.toString()+this.y.toString();
	}
}

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

int main() {
  string S;
  cin >>S; //S=yyyy/mm/dd
  if(S.at(5)=='1'){
    cout <<"TBD" <<endl;
    return 0;
  }
  else{
    if(S.at(6)=='1'){
      cout <<"Heisei" <<endl;
      return 0;
    }
    else if(S.at(6)=='2'){
      cout <<"Heisei" <<endl;
      return 0;
    }
    else if(S.at(6)=='3'){
      cout <<"Heisei" <<endl;
      return 0;
    }
    else if(S.at(6)=='4'){
      cout <<"Heisei" <<endl;
      return 0;
    }
  }
  cout <<"TBD" <<endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
exist=[0 for i in range(13)]
for i in l:
  exist[i]+=1
if exist[0]>=1 or exist[-1]>=2 or max(exist)>=3:print(0)
else:
  single=[]
  stand=[]
  if exist[-1]==1:single.append(12)
  for i in range(1,12):
    if exist[i]==1:
      single.append(i)
    if exist[i]==2:
      stand.append(i)
      stand.append(24-i)
  m=len(single)
  def getstatus(num):
    L=[]
    for i in range(m)[::-1]:
      if num//(2**i)==1:
        L.append(single[i])
      else:
        L.append(24-single[i])
      num%=2**i
    return L
  def dif(LIST):
    ret=100
    for i in range(len(LIST)-1):
      if LIST[i+1]-LIST[i]<ret:ret=LIST[i+1]-LIST[i]
    return ret
  ans=0
  for i in range(2**m):
    if dif(sorted([0]+getstatus(i)+stand+[24]))>ans:ans=dif(sorted([0]+getstatus(i)+stand+[24]))
  print(ans)

Measured memory_bytes: 39536
from math import sqrt
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for j in range(n):
    for i in range(j):
        xi = x[i]
        xj = x[j]
        m = 0
        for k in range(d):
            m += abs(xi[k] - xj[k])**2
        ans += sqrt(m).is_integer()
print(ans)


Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, x: usize, m: usize);
    if x == 0 {
        println!("{}", 0);
        return;
    }
    let mut al = vec![m; m];
    let mut cur = x;
    let mut ak = m;
    let mut i = 0;
    let next = |x| (x * x) % m;
    loop {
        al[cur] = i;
        let ncur = next(cur);
        if al[ncur] != m {
            ak = ncur;
            break;
        }
        cur = ncur;
        i += 1;
    }
    let l = i - al[ak] + 1;
    let k = al[ak];

    let mut dp = vec![0; m];
    let mut n = n;
    let mut cur = x;
    while cur != ak {
        dp[cur] = 1;
        n -= 1;
        cur = next(cur);
    }

    let nl = (n - k) / l;
    loop {
        dp[cur] = nl;
        n -= nl;
        cur = next(cur);
        if cur == ak {
            break;
        }
    }
    while n > 0 {
        dp[cur] += 1;
        n -= 1;
        cur = next(cur);
    }

    let mut ret = 0;
    for (i, &v) in dp.iter().enumerate() {
        ret += i * v;
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 3640
<?php
//??????????????\???
$up=1;
$south=2;
$east=3;
$west=4;
$north=5;
$down=6;
$ans=1;
$tmp;
$count=0;
//?????§??§5???????????????????????????????????????
while($count<5){
    //??????????????°??????????????????
    $stdin=trim(fgets(STDIN));
    //??????????????°???0??????break
    if($stdin==0){
        break;
    }
    if($stdin<=10000){
        //??????????????°???????????????
        for($j=0;$j<$stdin;$j++){
            $diceRoll=trim(fgets(STDIN));
            //??????????????§??????????????????
            switch($diceRoll){
                case"North":
                    $tmp=$up;
                    $up=$south;
                    $south=$down;
                    $down=$north;
                    $north=$tmp;
                    break;
                case"South":
                    $tmp=$up;
                    $up=$north;
                    $north=$down;
                    $down=$south;
                    $south=$tmp;
                    break;
                case"West":
                    $tmp=$up;
                    $up=$east;
                    $east=$down;
                    $down=$west;
                    $west=$tmp;
                    break;
                case"East":
                    $tmp=$up;
                    $up=$west;
                    $west=$down;
                    $down=$east;
                    $east=$tmp;
                    break;
                case"Right":
                    $tmp=$south;
                    $south=$east;
                    $east=$north;
                    $north=$west;
                    $west=$tmp;
                    break;
                case"Left":
                    $tmp=$south;
                    $south=$west;
                    $west=$north;
                    $north=$east;
                    $east=$tmp;
                    break;
                default:
            }
            //??????????????????
            $ans+=$up;
        }
        //????????????
        echo $ans."\n";
        //?????????
        $up=1;
        $south=2;
        $east=3;
        $west=4;
        $north=5;
        $down=6;
        $ans=1;
        //????????????????????°????????????
        $count++;
    }
}

Measured memory_bytes: 15464
N = int(input())

while(True):
    tho = N//1000
    hun = (N%1000)//100
    ten = (N%100)//10
    one = N%10
    if tho ==0:
        if hun ==ten and ten ==one:
            break
        else:
            N += 1
    else:
        if tho==hun and hun==ten and ten==one:
            break
        else:
            N += 1

print(N)

Measured memory_bytes: 2940