akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main() {
    int n,a[100],i,j,suma=0,sumb=0;
    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n-1;i++) {
        for(j=n-1;j>i;j--){
            if(a[j-1]<a[j]){
                int temp=a[j];
                a[j]=a[j-1];
                a[j-1]=temp;
            }
        }
    }
            
    for(i=0;i<n;i++){
        if(i%2==0){suma+=a[i];}
        else sumb+=a[i];
    }
    printf("%d\n",suma-sumb);
    return 0;
}


Measured memory_bytes: 128
def ispalindrome(str): return 1 if str == str[::-1] else 0
s=input()
n=len(s)
if ispalindrome(s)==1:
    x = int((n-1)/2)
    y = int((n+3)/2)
    sx = s[:x]
    sy = s[y-1:]

    if ispalindrome(sx)!=1:
        print('No')
        exit()
    if ispalindrome(sy)!=1:
        print('No')
        exit()
    else:
        print('Yes')
        exit()
else:
    print('No')

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

int main()
{
	int W, H;
	int x, y, r;

	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	W -= r, H -= r;
	if (r <= x && x <= W && r <= y && y <= H) printf("Yes\n");
	else printf("No\n");
	return 0;
}



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

int main() {
  int N, Y;
  cin >> N >> Y;
  
  int x = -1;
  int y = -1;
  int z = -1;
  
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      int k = N - i - j;
      if (Y - 10000 * i - 5000 * j == 1000 * k && k >= 0) {
        x = i;
        y = j;
        z = k;
        break;
      }
    }
  }
  
  cout << x << " " << y << " " << z << " " << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long X = Math.abs(sc.nextLong());
        long K = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;
        if(D >= X) {
            if (K % 2 == 0) {
                ans = X;
            } else {
                ans = Math.abs(X - D);
            }

        } else {
            if(X / D > K){
                ans = X - (D * K);
            } else {
                if((K - (X/D)) % 2 == 0){
                    ans = X - (X/D * D);
                } else {
                    ans = Math.abs(X - (X/D * D) -D);
                }
            }
        }


        System.out.println(ans);

    }

}




Measured memory_bytes: 35780
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n),b(n),c(n);
    for(lint&x:a)std::cin>>x;
    for(lint&x:b)std::cin>>x;
    for(lint&x:c)std::cin>>x;
    std::sort(a.begin(),a.end());
    std::sort(b.begin(),b.end());
    std::sort(c.begin(),c.end());
    lint ans=0;
    for(lint i=0,j=0,k=0;j<n;j++){
        for(;i<n&&a.at(i)<b.at(j);i++);
        for(;k<n&&c.at(k)<=b.at(j);k++);
        ans+=i*(n-k);
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 2560
import Foundation
var o = 0
let arr=readLine()!.split{$0==" "}.map{Int(String($0))!}
let n=arr[0]
let a=arr[1]
var arr2=readLine()!.split{$0==" "}.map{Int(String($0))!}
arr2.sort()
for i in 0..<a {
   o += arr2[i]
}
print(o)

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

void test_case(){
    
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    int a[3][3];
    rng(i, 0,3)
		rng(j, 0, 3)
			cin >> a[i][j];
    
    int n;
    cin >> n;
    
    int bing[3][3] ={};
    set<int> num;
    int te;
    rng(i, 0,n){
		cin >> te;
		num.insert(te);
	}
	
	rng(i, 0,3){
		rng(j, 0, 3){
			if( num.count(a[i][j]))
				bing[i][j] = 1;
		}
	}
	string flag = "No";
	for(int i = 0; i < 3; i++){
		if(bing[i][0]*bing[i][1]*bing[i][2] ==1)
				flag = "Yes";
	}
	for(int i = 0; i < 3; i++){
		if(bing[0][i]*bing[1][i]*bing[2][i] ==1)
				flag = "Yes";
	}
	if(bing[0][0]*bing[1][1]*bing[2][2] == 1)
		flag = "Yes";
	if(bing[0][2]*bing[1][1]*bing[2][0] == 1)
		flag = "Yes";	
	
    cout<<flag<<endl;
	return 0;
}






Measured memory_bytes: 256
# coding=utf-8
import math


if __name__ == '__main__':
    n = int(input())
    for i in range(n):
        x1, y1, x2, y2, x3, y3 = map(float, input().split())
        points_list = [[x1, y1], [x2, y2], [x3, y3]]
        points_list.sort()

        if points_list[0][0] == points_list[1][0]:
            py = (points_list[0][1] + points_list[1][1])/2
            if points_list[2][1] == points_list[0][1]:
                px = (points_list[0][0] + points_list[2][0])/2
            else:
                a2_s = (points_list[2][1] - points_list[0][1])/(points_list[2][0] - points_list[0][0])
                a2 = -1/a2_s
                m13x = (points_list[0][0] + points_list[2][0])/2
                m13y = (points_list[0][1] + points_list[2][1])/2
                b2 = m13y - a2*m13x
                px = (py - b2)/a2
        elif points_list[1][0] == points_list[2][0]:
            py = (points_list[1][1] + points_list[2][1])/2
            if points_list[2][1] == points_list[0][1]:
                px = (points_list[0][0]+points_list[2][0])/2
            else:
                a2_s = (points_list[2][1] - points_list[0][1])/(points_list[2][0] - points_list[0][0])
                a2 = -1/a2_s
                m13x = (points_list[0][0] + points_list[2][0])/2
                m13y = (points_list[0][1] + points_list[2][1])/2
                b2 = m13y - a2*m13x
                px = (py - b2)/a2
        elif points_list[0][1] == points_list[1][1]:
            px = (points_list[0][0] + points_list[1][0])/2
            a2_s = (points_list[2][1] - points_list[0][1]) / (points_list[2][0] - points_list[0][0])
            a2 = -1 / a2_s
            m13x = (points_list[0][0] + points_list[2][0]) / 2
            m13y = (points_list[0][1] + points_list[2][1]) / 2
            b2 = m13y - a2 * m13x
            py = a2*px + b2
        elif points_list[0][1] == points_list[2][1]:
            px = (points_list[0][0] + points_list[2][0])/2
            a1_s = (points_list[1][1] - points_list[0][1]) / (points_list[1][0] - points_list[0][0])
            a1 = -1 / a1_s
            m12x = (points_list[0][0] + points_list[1][0]) / 2
            m12y = (points_list[0][1] + points_list[1][1]) / 2
            b1 = m12y - a1 * m12x
            py = a1 * px + b1
        else:
            a1_s = (points_list[1][1] - points_list[0][1])/(points_list[1][0] - points_list[0][0])
            a1 = -1/a1_s
            a2_s = (points_list[2][1] - points_list[0][1])/(points_list[2][0] - points_list[0][0])
            a2 = -1/a2_s
            m12x = (points_list[0][0] + points_list[1][0]) / 2
            m12y = (points_list[0][1] + points_list[1][1]) / 2
            m13x = (points_list[0][0] + points_list[2][0]) / 2
            m13y = (points_list[0][1] + points_list[2][1]) / 2
            b1 = m12y - a1 * m12x
            b2 = m13y - a2 * m13x
            px = (b2 - b1)/(a1 - a2)
            py = a1*px + b1
        r = math.sqrt(math.pow((px-points_list[0][0]), 2) + math.pow((py-points_list[0][1]), 2))
        print('{0:.3f} {1:.3f} {2:.3f}'.format(px, py, r))

Measured memory_bytes: 5716
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    int n,c=0;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    rrep(i,n-2) {
        vector<int> b = {a[i-1],a[i],a[i+1]};
        sort(ALL(b));
        if(b[1]==a[i]) c++;
        }
    cout<<c<<endl;
    return 0;
}

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

struct card
{
    char suit;
    int value;
};

void selection(struct card a[], int n)
{
    for(int i=0;i<n;i++)
    {
        int mini = i;
        for(int j=i+1;j<n;j++)
        {
            if(a[j].value<a[mini].value)
            {
                mini = j;
            }
        }
        card t = a[mini];
        a[mini] = a[i];
        a[i] = t;
    }
}

void bubble(struct card a[], int n)
{
    for(int i=0;i<n;i++)
    {
        for(int j=n-1;j>i;j--)
        {
            if(a[j].value<a[j-1].value)
            {
                card t = a[j];
                a[j] = a[j-1];
                a[j-1] = t;
            }
        }
    }
}

void print(struct card a[], int n)
{
    for(int i=0;i<n;i++)
    {
        if(i>0) cout<<" ";
        cout<<a[i].suit<<a[i].value;
    }
    cout<<endl;
}

bool isStable(struct card c1[], struct card c2[], int n)
{
    for(int i=0;i<n;i++)
    {
        if(c1[i].suit!=c2[i].suit) return 0;
    }
    return 1;
}

int main()
{
    int n;
    cin>>n;
    card c1[100], c2[100];
    for(int i=0;i<n;i++)
    {
        cin>>c1[i].suit>>c1[i].value;
        c2[i] = c1[i];
    }
    bubble(c1, n);
    selection(c2, n);
    print(c1, n);
    cout<<"Stable"<<endl;
    print(c2, n);
    if(isStable(c1, c2, n)) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;

    return 0;
}



Measured memory_bytes: 3136
#include<iostream>
int main() {
  int a,d,e;
  while(1){
    std::cin>>a>>d>>e;
    e+=a+d;
    if(e==0)break;
    int p[e];
    for(a=0;a<e;a++)p[a]=2;
    std::cin>>d;
    int s[4][d];
    for(a=0;a<d;a++)std::cin>>s[0][a]>>s[1][a]>>s[2][a]>>s[3][a];
    for(a=0;a<d;a++)
      if(s[3][a]==1)p[s[0][a]-1]=1,p[s[1][a]-1]=1,p[s[2][a]-1]=1;
    for(a=0;a<d;a++){
      if((p[s[0][a]-1]==1)&&(p[s[1][a]-1]==1)&&(p[s[2][a]-1]!=1)) p[s[2][a]-1]=0;
      if((p[s[0][a]-1]==1)&&(p[s[2][a]-1]==1)&&(p[s[1][a]-1]!=1)) p[s[1][a]-1]=0;
      if((p[s[2][a]-1]==1)&&(p[s[1][a]-1]==1)&&(p[s[0][a]-1]!=1)) p[s[0][a]-1]=0;
    }
    for(a=0;a<e;a++) std::cout<<p[a]<<"\n";
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    
    int a, b, C;
    cin >> a >> b >> C;
    
    double rad = C* acos(-1)/180;
    
    double S = a*b*sin(rad)/2;
    double c = sqrt(a*a + b*b - 2*a*b*cos(rad));
    double L = a + b + c;
    double h = b*sin(rad);
    
    printf("%f %f %f\n", S, L, h);
    
    return 0;
    
}


Measured memory_bytes: 3452
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;

int dig(string s,int& i){
  int tmp=0;
  tmp+=s[i]-'0';
  for(int j=i+1;isdigit(s[j]);j++,i++){
    tmp*=10;
    tmp+=s[j]-'0';
  }
  return tmp;
}

int main(){
  string s;
  int sum=0;
  while(cin>>s){
    rep(i,s.size()){
      if(isdigit(s[i]))sum+=dig(s,i);
    }
  }
  cout<<sum<<endl;
}

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

#define mod (1000000007)
#define MAXN (1010)

int n, m;
int a[MAXN], b[MAXN], cnt[MAXN * MAXN];
int x[MAXN * MAXN], y[MAXN * MAXN];
int mat[MAXN][MAXN];

int main() {
    scanf("%d%d", &n, &m);
    bool flag = true;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        if (x[a[i]]) flag = false;
        x[a[i]] = i;
    }
    for (int i = 1; i <= m; ++i) {
        scanf("%d", b + i);
        if (y[b[i]]) flag = false;
        y[b[i]] = i;
    }
    int ans = 1;
    int prex = 0, prey = 0;
    int cntx = 0, cnty = 0;
    for (int i = n * m; i; --i) {
        if (x[i] && y[i]) {
            mat[x[i]][y[i]] = i;
            ++cntx;
            ++cnty;
            prex = x[i];
            prey = y[i];
        } else if (x[i]) {
            if (!cnty) flag = false;
            mat[x[i]][prey] = i;
            ++cntx;
            prex = x[i];
            ans = 1ll * ans * cnty % mod;
        } else if (y[i]) {
            if (!cntx) flag = false;
            mat[prex][y[i]] = i;
            ++cnty;
            prey = y[i];
            ans = 1ll * ans * cntx % mod;
        }
    }

    if (!flag) {
        puts("0");
        return 0;
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (mat[i][j]) continue;
            ++cnt[std::min(a[i], b[j])];
        }
    }
    int now = 0;
    for (int i = n * m; i; --i) {
        if (x[i] || y[i]) {
            now += cnt[i];
            continue;
        }
        ans = 1ll * ans * (now + cnt[i]) % mod;
        now += cnt[i] - 1;
        if (now < 0) {
            puts("0");
            return 0;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 8320
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
using namespace std;

const double pi=4*atan(1.0);


int main() {
	int N;
	cin>>N;
	vector<int> arr(2*N);
	for(auto& val:arr){
		cin>>val;
	}

	sort(begin(arr),end(arr));

	int ans=0;
	for(int i=0;i<2*N;i+=2){
		ans+=arr[i];
	}
	cout<<ans<<endl;
	//system("pause");
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, a, b;
ii x[N], y[N];
priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> que;
int root[N];
ll ans;

int findr(int x) {
    if (x == root[x]) return root[x];
    return root[x] = findr(root[x]);
}

bool unionr(int p1, int p2) {
    int r1 = findr(p1);
    int r2 = findr(p2);
    if (r1 == r2) return false;
    root[r1] = r2;
    return true;
}

int main() {
    cin >> n;
    iota(root, root + n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a >> b;
        x[i] = {a, i};
        y[i] = {b, i};
    }
    sort(x, x + n);
    sort(y, y + n);
    for (int i = 1; i < n; ++i) {
        int d = x[i].first - x[i - 1].first;
        que.push({d, x[i].second, x[i - 1].second});
    }
    for (int i = 1; i < n; ++i) {
        int d = y[i].first - y[i - 1].first;
        que.push({d, y[i].second, y[i - 1].second});
    }
    int cnt = 1;
    while (cnt != n) {
        auto v = que.top();
        que.pop();
        int d = v[0], p1 = v[1], p2 = v[2];
        if (unionr(p1, p2)) {
            ans += d;
            ++cnt;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 16200
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		double[] arr = new double[N];
		Arrays.setAll(arr, i -> Double.parseDouble(sc.next()));

		double ans = 0;
		for(double a : arr) {
			ans += 1/a;
		}
		System.out.println(1/ans);
	}
}

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


int a[505][505];

struct P {
	int a, b, c, d;
};

int main () {
	int R, C;
	cin >> R >> C;

	for (int i = 0; i < R; i++)
	{
		for (int j = 0; j < C; j++)
		{
			cin >> a[i][j];
		}
	}

	vector<P> output;

	for (int i = 0; i < R; i++)
	{
		for (int j = 0; j < C; j++)
		{
			if (a[i][j] % 2 == 1 && a[i][j] > 0)
			{
				// greedily move.
				if (j < C-1) {
					a[i][j]--;
					a[i][j+1]++;

					output.push_back((P){i, j, i, j+1});
					//cout << i << " " << j << " " << i << " " << j+1 << endl;
				}
				else if (i < R-1) {
					a[i][j]--;
					a[i+1][j]++;
					output.push_back((P){i, j, i+1, j});
					//cout << i << " " << j << " " << i+1 << " " << j << endl;
				}
			}
		}
	}

	cout << output.size() << endl;
	for (P& p : output)
	{
		cout << p.a+1 << " " << p.b+1 << " " << p.c+1 << " " << p.d+1 << endl;
	}
}

/*
0 1
1 0
*/

Measured memory_bytes: 5232
N, x = map(int, input().split())
list_a = [int(x) for x in input().split()]

list_a.sort()
total = sum(list_a)
if x < list_a[0] :
    print(0)
    exit()
if x > total :
    print(len(list_a)-1)
    exit()
ans = 0

for i in range(N) :
    if list_a[i] <= x :
        x -= list_a[i]
        ans += 1

print(ans)


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

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    vector<vector<int>> s(D, vector<int>(26));
    rep(i, 26) cin >> c[i];
    rep(i, D) {
        rep(j, 26) { cin >> s[i][j]; }
    }

    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();

    vector<int> t(D);
    ll v = 0;
    vector<vector<ll>> Cost(D, vector<ll>(26, 0));
    rep(i, 26) Cost[0][i] = c[i];
    rep(i, D) {
        vector<ll> X(26);
        rep(j, 26) X[j] = s[i][j] + Cost[i][j];
        auto it = max_element(X.begin(), X.end());
        int index = it - X.begin();
        t[i] = index;
        Cost[i][index] = 0;
        v += s[i][index];
        rep(j, 26) {
            v -= Cost[i][j];
            if(i + 1 < D)
                Cost[i + 1][j] = Cost[i][j] + c[j];
        }
    }
    // rep(i, D) cout << t[i] + 1 << endl;

    end = chrono::system_clock::now();
    auto elapsed =
        std::chrono::duration_cast<std::chrono::milliseconds>(end - start)
            .count();
    srand(time(NULL));
    while(elapsed < 1900) {
        int d, q;
        d = rand() % D;
        q = rand() % 26;
        vector<vector<ll>> Cost2 = Cost;
        ll v2 = v;
        int x = d + 1;
        v2 += s[d][q] - s[d][t[d]];
        v2 += Cost2[d][q];
        Cost2[d][q] = 0;
        while(x < D && t[x] != q) {
            v2 += Cost2[x][q];
            Cost2[x][q] = Cost2[x - 1][q] + c[q];
            v2 -= Cost2[x][q];
            x++;
        }

        x = d + 1;
        int y = t[d];
        if(d == 0) {
            Cost2[d][y] = c[y];
            v2 -= Cost2[d][y];
        } else {
            Cost2[d][y] = Cost2[d - 1][y] + c[y];
            v2 -= Cost2[d][y];
        }
        while(x < D && t[x] != y) {
            v2 += Cost2[x][y];
            Cost2[x][y] = Cost2[x - 1][y] + c[y];
            v2 -= Cost2[x][y];
            x++;
        }
        if(v < v2) {
            t[d] = q;
            Cost = Cost2;
            v = v2;
        }
        end = chrono::system_clock::now();
        elapsed =
            chrono::duration_cast<chrono::milliseconds>(end - start).count();
        // cout << v << endl;
    }
    rep(i, D) cout << t[i] + 1 << endl;
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1000000 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

int n;

void work()
{
    LL a, b;
    cin >>a >>b;
    LL g = __gcd(a, b);

    cout <<a * b / g <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


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

#define MP make_pair

using namespace std;

typedef long long ll;

string S, Sr;
int N;
map<pair<string, string>, ll> mp;
string red, blue;
ll ans;

void dfs(ll a) {
	if(a == N) {
		mp[MP(red, blue)]++;
		return ;
	}
	red += S[a];
	dfs(a + 1);
	red.pop_back();
	blue += S[a];
	dfs(a + 1);
	blue.pop_back();
}

void dfs2(ll a) {
	if(a == N) {
		ans += mp[MP(blue, red)];
		return ;
	}
	red += Sr[a];
	dfs2(a + 1);
	red.pop_back();
	blue += Sr[a];
	dfs2(a + 1);
	blue.pop_back();
}

int main()
{
	cin >> N;
	cin >> S;
	Sr = S;
	reverse(Sr.begin(), Sr.end());
	red = blue = "";
	dfs(0);
	red = blue = "";
	dfs2(0);
	cout << ans << endl;
}


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

using namespace std;

int main(void){
    int x, y;
    cin >> x >> y;
    
    for (int turu = 0; turu <= x; turu++){
        int kame = x - turu;
        
        if (2 * turu + 4 * kame == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cmath>
#define EPS 1e-10

double add(double a,double b){
	if(fabs(a+b)<EPS*(fabs(a)+fabs(b)))return 0.0;
	return a+b;
}

struct P{
	double x,y,z;
	P(){}
	P(double xx,double yy,double zz){
		x=xx;
		y=yy;
		z=zz;
	}
	P operator +(P p){
		return P(add(x,p.x),add(y,p.y),add(z,p.z));
	}
	P operator -(P p){
		return P(add(x,-p.x),add(y,-p.y),add(z,-p.z));
	}
	P operator *(double d){
		return P(x*d,y*d,z*d);
	}
	double dot(P p){
		return add(add(x*p.x,y*p.y),z*p.z);
	}
};

double dist(P p){
	return sqrt(p.x*p.x+p.y*p.y+p.z*p.z);
}

int n,q;
P s[51],g[51];
P b[51];
double r[51];
long long l[51];

int main(void){
	scanf("%d %d",&n,&q);
	for(int i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lld",&b[i].x,&b[i].y,&b[i].z,&r[i],&l[i]);
	}
	for(int i=0;i<q;i++){
		scanf("%lf %lf %lf",&s[i].x,&s[i].y,&s[i].z);
		scanf("%lf %lf %lf",&g[i].x,&g[i].y,&g[i].z);
		long long res=0;
		P v=g[i]-s[i];
		for(int j=0;j<n;j++){
			P c=b[j]-s[i];
			if(v.dot(c)<0){
				if(r[j]+EPS>=dist(c))res+=l[j];
			}else{
				if(v.dot(c)>dist(v)*dist(v)){
					if(dist(g[i]-b[j])<=r[j]+EPS)res+=l[j];
				}else{
					double len=dist(c)*dist(c)-(v.dot(c)*v.dot(c))/(dist(v)*dist(v));
					if(len<=r[j]*r[j]+EPS)res+=l[j];
				}
			}
		}
		printf("%lld\n",res);
	}
	return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main(){
  int l; cin >> l;
  int a[l];
  REP(i, l) cin >> a[i];

  vector<vector<ll>> dp(l+1, vector<ll>(5, 0));
  dp[0][0] = 0;
  REP(i, l){
    dp[i+1][0] = dp[i][0] + a[i];
    dp[i+1][1] = min({dp[i][0], dp[i][1]}) + (a[i] == 0? 2: (a[i] & 1));
    dp[i+1][2] = min({dp[i][0], dp[i][1], dp[i][2]}) + (a[i] % 2 == 0);
    dp[i+1][3] = min({dp[i][0], dp[i][1], dp[i][2], dp[i][3]}) + (a[i] == 0? 2: (a[i] & 1));
    dp[i+1][4] = min({dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4]}) + a[i];
  }

  cout << *min_element(dp[l].begin(), dp[l].end()) << endl;

  return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
int main(void){
    int n;
    std::cin >> n;
    std::string str;
    std::vector<int> r, g, b;

    long long int ans;
    
    std::cin >> str;
    for(int i = 0; i < n; i++){
        if(str[i] == 'R'){
            r.push_back(i);
        }else if(str[i] == 'G'){
            g.push_back(i);
        }else{
            b.push_back(i);
        }
    }

    ans = r.size() * g.size() * b.size();
    //std::cout << ans << std::endl;
    int cnt = 0;
    std::set<char> tmp;
    for(int i = 0; i < n; i++){
        int gap = 1;

        while(i+2*gap < n){
            tmp.insert(str[i]);
            tmp.insert(str[i+gap]);
            tmp.insert(str[i+2*gap]);
            if(tmp.size() == 3){
                cnt++;
            }

            tmp.clear();
            gap++;
        }
    }
    ans = ans - cnt;

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<string>
std::string S;
#define LL long long
LL ans;
LL mod = 1e9 + 7;
LL D[4][100010];
LL Q;
LL K[4];
int main() {
	std::cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '?') {
			Q++;
			D[3][i]++;
		}
		else D[S[i] - 'A'][i]++;
		for (int j = 0; j < 4; j++) {
			D[j][i + 1] += D[j][i];
		}
	}
	K[0] = 1;
	for (int i = 0; i < Q - 3; i++) {
		K[0] *= 3;
		K[0] %= mod;
	}
	K[1] = (Q - 2 > 0 ? 3 : 1) * K[0];
	K[1] %= mod;
	K[2] = (Q - 1 > 0 ? 3 : 1) * K[1];
	K[2] %= mod;
	K[3] = (Q > 0 ? 3 : 1) * K[2];
	K[3] %= mod;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'B') {
			ans += (D[0][i - 1])*(D[2][S.size() - 1] - D[2][i])*K[3];
			ans %= mod;
			ans += (D[0][i - 1])*(D[3][S.size() - 1] - D[3][i])*K[2];
			ans %= mod;
			ans += (D[3][i - 1])*(D[2][S.size() - 1] - D[2][i])*K[2];
			ans %= mod;
			ans += (D[3][i - 1])*(D[3][S.size() - 1] - D[3][i])*K[1];
			ans %= mod;
		}
		if (S[i] == '?') {
			ans += (D[0][i - 1])*(D[2][S.size() - 1] - D[2][i])*K[2];
			ans %= mod;
			ans += (D[0][i - 1])*(D[3][S.size() - 1] - D[3][i])*K[1];
			ans %= mod;
			ans += (D[3][i - 1])*(D[2][S.size() - 1] - D[2][i])*K[1];
			ans %= mod;
			ans += (D[3][i - 1])*(D[3][S.size() - 1] - D[3][i])*K[0];
			ans %= mod;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int inf = 1e9;

int main() {
  int h, w, K; cin >> h >> w >> K;
  vector< vector<long long int> > dp(h+1, vector<long long int> (w+1, 0));
  dp[0][0] = 1;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {

      for(int k=0; k<(1<<(w-1)); k++) {
        bool f = true;
        for(int l=0; l<w-2; l++) {
          if( ((k >> l) & 1) && (k >> (l+1) & 1) ) {
            f = false;
          }
        }
        if(f) {
          if(j >= 1 && ( (k >> (j-1)) & 1 )) {
            dp[i+1][j-1] += dp[i][j];
            dp[i+1][j-1] %= mod;
          }else if(j <= w-2 && ((k >> j) & 1)) {
            dp[i+1][j+1] += dp[i][j];
            dp[i+1][j+1] %= mod;
          }else{
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= mod;
          }
        }
      }

    }
  }
  cout << dp[h][K-1] << endl;
  return 0;
}


//EOF


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
template <class T> using V = vector<T>;
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

/*--------------------------------------------------------------------------------

--------------------------------------------------------------------------------*/

int main(){
    ll n; cin >> n;
    ll cnt = 0;
    bool f = false;
    rep(i, 0, n){
        ll a, b;
        cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
        if(cnt == 3){
            f = true;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<long long int>
#define vc vector<char>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i = (a); i < (n); i++)
#define fi(i,a,n) for(i = (a); i <= (n); i++)
#define F first
#define S second

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

    ll a,b;
    cin>>a>>b;
    ll c = 3*a + b;

    cout<<c/2<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <unordered_set>
using namespace std;
const double eps = 1e-6;
const int N = 1e6 + 5;
typedef long long ll;
int s[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    if(k % 7 == 0) k /= 7;
    ll t = 1;
    int i = 1;
    while(true) {
        if(t % k == 0) {
            printf("%d\n", i);
            return 0;
        }
        i++;
        t = t*10 + 1;
        t = t % k;
        if(s[t]) {
            puts("-1");
            return 0;
        }
        s[t] = 1;
    }
    return 0;
}

Measured memory_bytes: 7072
#include <stdio.h>

int main(void) {
    int H,W,i,j;
    for(;scanf("%d%d",&H,&W),W;puts(""))
        for(i=0;i<H;i++)
            for(j=0;j<W;j++)
                printf("%c%s",!((i%2+j%2)%2)?'#':'.',j==W-1?"\n":"");
    return 0;
}


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

using namespace std;

enum Face
{
	TOP = 0,
	FRONT = 1,
	RIGHT = 2,
	LEFT = 3,
	BACK = 4,
	BOTTOM = 5,
};

void roll(vector<int> &f, string cmd)
{
	int tmp;
	for (int i = 0; i < cmd.size(); i++)
	{
		switch (cmd[i])
		{
		case 'E':
			tmp = f[TOP];
			f[TOP] = f[LEFT];
			f[LEFT] = f[BOTTOM];
			f[BOTTOM] = f[RIGHT];
			f[RIGHT] = tmp;
			break;
		case 'N':
			tmp = f[TOP];
			f[TOP] = f[FRONT];
			f[FRONT] = f[BOTTOM];
			f[BOTTOM] = f[BACK];
			f[BACK] = tmp;
			break;
		case 'S':
			tmp = f[TOP];
			f[TOP] = f[BACK];
			f[BACK] = f[BOTTOM];
			f[BOTTOM] = f[FRONT];
			f[FRONT] = tmp;
			break;
		case 'W':
			tmp = f[TOP];
			f[TOP] = f[RIGHT];
			f[RIGHT] = f[BOTTOM];
			f[BOTTOM] = f[LEFT];
			f[LEFT] = tmp;
			break;
		default:
			break;
		}
	}
}

int main()
{
	vector<int> f(6);
	int q;
	int top_init, front_init;
	int top, front;
	for (int i = 0; i < 6; i++)
	{
		cin >> f[i];
		if (i == TOP)
		{
			top_init = f[i];
		}
		else if (i == FRONT)
		{
			front_init = f[i];
		}
	}
	cin >> q;
	vector<int> res(q);
	for (int i = 0; i < q; i++)
	{
		cin >> top >> front;
		if (top != f[TOP])
		{
			if (top == f[FRONT])
			{
				roll(f, "N");
			}
			else if (top == f[RIGHT])
			{
				roll(f, "W");
			}
			else if (top == f[LEFT])
			{
				roll(f, "E");
			}
			else if (top == f[BACK])
			{
				roll(f, "S");
			}
			else if (top == f[BOTTOM])
			{
				roll(f, "NN");
			}
		}
		if (front == f[FRONT])
		{
			res[i] = f[RIGHT];
		}
		else if (front == f[RIGHT])
		{
			roll(f, "WSE");
			res[i] = f[RIGHT];
		}
		else if (front == f[LEFT])
		{
			roll(f, "ESW");
			res[i] = f[RIGHT];
		}
		else if (front == f[BACK])
		{
			roll(f, "WSSE");
			res[i] = f[RIGHT];
		}
	}
	for (int i = 0; i < q; i++)
	{
		cout << res[i] << endl;
	}
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int n;
int a[100010];

int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	sort(a,a+n);
	int cnt=unique(a,a+n)-a;
	cout<<cnt-(cnt+1)%2<<endl;
    return 0; 
}

Measured memory_bytes: 640
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
using namespace std; 
int main()
{
	int n, k; 
	cin >> n >> k; 
	vector<int> h(n);
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
	}
	
	int x = 1000000000;
	sort(h.begin(), h.end()); 
	for (int i = 0; i+k-1<h.size(); i++)
	{
		x = min(h.at(i+(k-1))- h.at(i),x);
	}
	cout << x << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
int R=1,C=1,H[2000010]={0};
int N[2000010]={2100000000};
//ヒープに入れる
void hin(int a){
  int i=C++;
  for(N[R]=a;a>N[H[i/2]];i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//ヒープから最小値を取り出す
int hout(){
  int rt=H[1],nt=1,i=0,k=H[--C];
  while(nt-i){
    H[i=nt]=k;
    if(i*2  <C&&N[  k  ]<N[H[i*2  ]])H[i]=H[nt=i*2  ];
    if(i*2+1<C&&N[H[nt]]<N[H[i*2+1]])H[i]=H[nt=i*2+1];
  }
  return rt;
}
void prih(){
  int i,j=0;
  for(i=0;i<C;i++){
    if(i==1<<j){
      printf("\n");
      j++;
    }
    printf("%d ",N[H[i]]);
  }
  printf("\n");
}
int main(){
  int a;
  char s[1000];
  while(scanf("%s",s),s[2]-'d'){
    if(s[0]=='i'){
      scanf("%d",&a);
      hin(a);
    }
    else printf("%d\n",N[hout()]);
    //prih();printf("\n");
  }    
  return 0;
}

Measured memory_bytes: 10932
b = input()

if b[:7] == "2019/01":
  print("Heisei")
elif b[:7] == "2019/02":
  print("Heisei")
elif b[:7] == "2019/03":
  print("Heisei")
elif b[:7] == "2019/04":
  print("Heisei")
else:
  print("TBD")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  if(a==1||a==2||a==3||a==5||a==6||a==9||a==10||a==13||a==17){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
    
  
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+7;
int s[maxn];
int f[maxn];
int main(){
    int n,k,a,b;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    int sum=0;
    while(k--){
        cin>>a>>b;
        if(a==1) s[sum++]=b;
        else if(b==n) f[a]=1;
    }
    bool flag=0;
    for(int i=0;i<sum;i++){
        if(f[s[i]]){
            flag=1;
            break;
        }
    }
    if(flag) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 1408
H, W = map(int, input().split())
H_0 = H % 2
W_0 = W % 2
x = 0
if (H == 1) or (W == 1):
  x = 1
elif (H_0 * W_0) == 1:
  x = (H * W + 1) / 2
else:
  x = H * W / 2
x = int(x)
print(x)
 

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            // write your code here
            int N = in.nextInt();
            long[] a = new long[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - (i + 1);
            }

            Arrays.sort(a);
            long b = a[N / 2];

            long sum = 0;
            for (int i = 0; i < N; i++) {
                sum += Math.abs(a[i] - b);
            }

            out.println(sum);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

Measured memory_bytes: 46648
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll V[N], C[N];
    REP(i, 0, N) {
        cin >> V[i];
    }
    REP(i, 0, N) {
        cin >> C[i];
    }
    ll ans = 0;
    REP(i, 0, N) {
        ans += max((ll)0, V[i] - C[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
     
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;				\
								 c>0?i<b:							\
								 i>b;								\
								 i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif
     
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }
     
//.....................
const int MAX = (int)2e5 + 5;
     
vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}
     
template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

void solve();

signed main() {
	cout << fixed << setprecision(20);
	solve();
	while(true) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}

class Mycin {
	bool flag = true;
public:
	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
	operator bool() {return flag;}
} mycin;

class Mycout {
public:
	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
	Mycout& operator << (const char c) {printf("%c", c); return *this;}
	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
} mycout;

#define cin mycin
#define cout mycout
#define endl '\n'


int H, W;
string a[105];

void solve() {
	cin >> H >> W;
	rep(i, H) cin >> a[i];

	rep(j, W + 2) cout << '#';
	cout << endl;

	rep(i, H) cout << '#' + a[i] + '#' << endl;

	rep(j, W + 2) cout << '#';
	cout << endl;
} 


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

int main(){

  string a, r;
  int h_cnt = 0, b_cnt = 0;

  while(1){
    cin >> a >> r;
    if(a == "0" && r == "0") return 0;

    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
          if(a[i] == r[j] && i == j){
            h_cnt++;
          }else if(a[i] == r[j]){
            b_cnt++;
          }
      }
    }

    cout << h_cnt << " " << b_cnt << endl;
    h_cnt = 0;
    b_cnt = 0;
  }
}

Measured memory_bytes: 3108
import collections as c

h,w,m = map(int,input().split())
x = []
y = []
z = set([])
for i in range(m):
    s,t = map(int,input().split())
    x.append(s)
    y.append(t)
    z.add(tuple([s,t]))
a = c.Counter(x)
b = c.Counter(y)
a = a.most_common()
b = b.most_common()
c = []
d = []
e = a[0][1]
f = b[0][1]

for sa in a:
    if sa[1] == e:
        c.append(sa[0])
    else:
        break
for sb in b:
    if sb[1] == f:
        d.append(sb[0])
    else:
        break

fl = 0
ans = e+f-1
for s in c:
    for t in d:
        if tuple([s,t]) not in z:
            fl = 1
            ans += 1
            break
    if fl == 1:
        break
    
print(ans)


Measured memory_bytes: 119388
#include<cstdio>
int a[200001],b[200001];
int main() {
	int n,m,i;
	scanf("%d%d",&n,&m);
	for(i=1; i<=m; i++) {
		int st,ed;
		scanf("%d%d",&st,&ed);
		if(st==1)a[ed]=1;
		if(ed==n)b[st]=1;
	}
	for(i=1; i<=m; i++)
		if(a[i]&&b[i]) {
			printf("POSSIBLE\n");
			return 0;
		}
	printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;

int main() {
 vector<int> A(3);
 cin>>A.at(0)>>A.at(1)>>A.at(2);
 
 sort(A.begin(),A.end());
int a=abs(A.at(0)-A.at(1));
int b=abs(A.at(2)-A.at(1));
ce(a+b);
}

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

#define SIZE 200000

using namespace std;

int main() {
    long long int i,j,k,n,M,K,Q,X;
  //  long long int A[100][100];
string S,T;
   cin >> S >> T;

   n = S.length();

  if (T.length() != (n+1))
    cout << "No" << endl;
  else {
  long encore;
  encore = 1;
  for (i=0;(i<n) && encore;i++)
    if (S[i] != T[i])
      encore = 0;
  if (encore)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}
  return 0;

}


Measured memory_bytes: 3624
def solve():
    day = [
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday',
        'Sunday',
        'Monday',
        'Tuesday',
    ]
    
    days_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    days_total = []
    for i in range(len(days_month)):
        days_total.append(sum(days_month[0:i]))
    
    while True:
        mm, dd = map(int, input().split())
        if mm == 0 and dd == 0:
            break
        
        numd = days_total[mm - 1]
        total = numd + dd
        idx = total % len(day)
        
        print(day[idx])
    

if __name__ == "__main__":
    solve()



Measured memory_bytes: 5604
a,b,c=map(int, input().split())
d=0
while d<10**5:
    if a%2==1 or b%2==1 or c%2==1:break
    a,b,c=b/2+c/2,a/2+c/2,a/2+b/2
    d+=1
else:d=-1
print(d)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <set>

using namespace std;

struct Input {
	string a, b;
	int time;
	Input(string _a, string _b, int _t) : a(_a), b(_b), time(_t) {}
};

struct Edge {
	int to;
	int time;
	Edge(int _t, int _ti) : to(_t), time(_ti) {}
};

bool operator > (const Edge& e1, const Edge& e2) {
	if (e1.time > e2.time) return true;
	return false;
}

int n, m;
int INF = (int)1e9;

map<string, int> id;

vector<Input> inputs;
vector< vector<Edge> > G;

int dist[550];

int dks(int s, int t) {
	fill(dist, dist + 550, INF);
	
	priority_queue<Edge, vector<Edge>, greater<Edge> > que;
	que.push(Edge(s, 0));
	dist[s] = 0;
	
	while (!que.empty()) {
		Edge e1 = que.top(); que.pop();
		
		for (int i = 0; i < G[e1.to].size(); i++) {
			Edge e2 = G[e1.to][i];
			
			if (dist[e2.to] > e1.time + e2.time) {
				dist[e2.to] = e1.time + e2.time;
				que.push(Edge(e2.to, e1.time + e2.time));
			}
		}
	}
	
	return dist[t];
}

int main() {
	while (1) {
		cin >> n >> m; if (n == 0 && m == 0) break;
		
		string s, p, g; cin >> s >> p >> g;
		
		inputs.clear();
		set<string> names;
		for (int i = 0; i < m; i++) {
			string a, b;
			int d, t;
			cin >> a >> b >> d >> t;
			
			inputs.push_back(Input(a, b, d / 40 + t));
			
			names.insert(a);
			names.insert(b);
		}
		
		id.clear();
		set<string>::iterator it;
		int ids = 0;
		for (it = names.begin(); it != names.end(); it++) {
			id[(*it)] = ids;
			ids++;
		}
		
		G.assign(ids, vector<Edge>());
		for (int i = 0; i < m; i++) {
			Input inp = inputs[i];
			int a = id[inp.a], b = id[inp.b];
			G[a].push_back(Edge(b, inp.time));
			G[b].push_back(Edge(a, inp.time));
		}
		
		int tsp = dks(id[s], id[p]);
		int tpg = dks(id[p], id[g]);
		cout << (tsp + tpg) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2016
#include <bits/stdc++.h>
using namespace std;
#define ff(i,s,n) for(int i=s;i<n;i++)
#define fr(i,s,n) for(int i=n-1;i>=s;i--)
#define llu long long int
const int mod=1000000007;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int x;
	cin>>x;
	if(x==0)	cout<<1;
	else cout <<0;
	return 0;
}


//1
//7 2
//3 5 4 5 1 1 1


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
int main()
{
    //入力
    int n, m;
    std::cin >> n >> m;
    std::vector<int> k(m);
    std::vector<std::vector<int>> s(m);
    std::vector<int> num(m);
    for (int i = 0; i < m; i++)
    {
        std::cin >> k[i];
        for (int j = 0; j < k[i]; j++)
        {
            int a;
            std::cin >> a;
            s[i].push_back(a);
        }
    }

    std::vector<int> p(m);
    for (int i = 0; i < m; i++)
    {
        std::cin >> p[i];
    }
 /* for(int i=0;i<m;i++){
    std::cout<<k[i]<<std::endl;
    for(int j=0;j<s[i].size();j++){
      std::cout<<s[i][j]<<" ";
    }
    std::cout<<std::endl;
    std::cout<<p[i]<<std::endl;
  }*/
    int count = 0;
    int ans = 0;
  int on=0;
    //解答

    for (int bit = 0; bit < (1 << n); bit++){
        count = 0;
      on=0;
            for (int i = 0; i < m; i++){
              on=0;
              //std::cout<<on<<std::endl;
              for(int j=0;j<s[i].size();j++){
                int b=s[i][j]-1;
                if (bit & (1 << b)){
                  on++;
                }
              }
                if (on % 2 == p[i])count++;
            }
        if (count == m)
            ans++;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 3600