akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++);
using ll=long long;
int  main(){
int N;
cin>>N;
vector<int>data(N);
 for(int i=0; i<N; i++){
     cin>>data.at(i);
 }
 sort(data.begin(),data.end());
double answer=data.at(0);
for(int i=1; i<N; i++){
answer=double(answer+data.at(i))/2;
}
cout<<answer<<endl;
 }


Measured memory_bytes: 256
ans :: [Int] -> [String]
ans x = 
  let z = zip [1..] x
  in
    map (\(a,b) -> "Case " ++ show(a) ++ ": " ++ show(b)) z
    
main = do
  c <- getContents
  let l = map read $ lines c :: [Int]
      i = takeWhile (/=0) l
      o = ans i

  mapM_ putStrLn o

Measured memory_bytes: 5044
#N = int(input())
#J,K = map(int,input().split())
#A = list(map(int(input().split())))
#A = [list(map(int(input().split()))) for _ in range(N)]
#for i in range():

#N = int(input())
#J,K = map(int,input().split())
#A = list(map(int(input().split())))
#A = [list(map(int(input().split()))) for _ in range(N)]
#for i in range():

A,B,C,K = map(int,input().split())

S = A + B 
if K > S:
    print(A - (K-S))
else:
    if K < A:
        print(K)
    else:
        print(A)


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int start = max(a, c);
  int end = min(b, d);
  if(start > end) cout << 0 << endl;
  else cout << end - start << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 0; --i)
#define repBX(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    string S;
    cin >> S;
    int ans = 0;
    rep(i,S.size()/2){
        if(S[i]!=S[S.size()-1-i])ans ++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
import math

l = raw_input().split()
N = int(l[0])

def calc(N):
    sum = 0
    for i in range(int(math.sqrt(N))):
        r = i + 1
        q = r
        m = (N - r)/q
        if N - m*q == r and m > q:
            sum += m
            # print(m, q)
    return sum

#for i in range(100):
#    print('N={}'.format(i + 1))
#    calc(i + 1)

print(calc(N))


Measured memory_bytes: 34436
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    string s;
    cin>>n>>s>>k;
    k--;
    rep(i,n){
        if(s[i]==s[k])cout<<s[i];
        else cout<<"*";
    }
    cout<<endl;
}

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

using namespace std;

void solve()
{
	int n, k;
	cin >> n >> k;
	cout << (n - 2) / (k - 1) + 1 << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S1 = input()
S2 = input()
patterns = []
flag = False
for i in range(N):
    if S1[i] == S2[i]:
        patterns.append('row')
    elif flag is False:
        patterns.append('column')
        flag = True
    else:
        flag = False

if patterns[0] == 'row':
    count = 3
else:
    count = 6
for i in range(1, len(patterns)):
    prev = patterns[i-1]
    current = patterns[i]
    if prev == 'row':
        if current == 'row':
            count *= 2
        else:
            count *= 2
    else: # column
        if current == 'row':
            count *= 1
        else:
            count *= 3
print(count % (10**9  + 7))

Measured memory_bytes: 3064
while True:
    s=input()
    if s==("-"):
        break
    else:
        x=int(input())
        L=list(s)
        for i in range(x):
            y=int(input())
            
            for j in range(y):
                z=L[0]
                del L[0]
                L.append(z)
        t="".join(L)
        print(t)


Measured memory_bytes: 5596
#include <stdio.h>
typedef long long ll;

ll abs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll i, j, k, n, ans = 10e15;
  scanf("%lld", &n);
  ll sum[n];
  for(i = 0; i < n; ++i) {
    scanf("%lld", &sum[i]);
    if(i) sum[i] += sum[i - 1];
  }
  for(i = 0; i < n - 1; ++i) {
    if(abs(2 * sum[i] - sum[n - 1]) < ans) ans = abs(2 * sum[i] - sum[n - 1]);
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a>k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
}


Measured memory_bytes: 256
import sys
from functools import reduce
from operator import add


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)


def main():
    n = _i()
    a = list(sorted(_ia()))
    r = a[0]
    for ai in a[1:]:
        r = gcd(r, ai)
        if r == 1:
            break
    else:
        return "not coprime"

    N = 10 ** 6 + 1
    f = [False] * N
    p = []
    k = {ai: 1 for ai in a}
    for i in range(2, N):
        if f[i]:
            continue
        p.append(i)

        tmp = 0
        if k.get(i) is not None:
            tmp += 1
        for j in range(2*i, N, i):
            f[j] = True
            if k.get(j) is not None:
                tmp += 1
                if tmp > 1:
                    return "setwise coprime"
    else:
        return "pairwise coprime"


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 228528
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int A, B, x;
	while(scanf("%d%d", &A, &B)!=EOF)
	{
		x=1;
		for(int i=1; i<=A; i++)
			{
				if(x<B)
					x=x*2;
			    else 
				    x=x+B;
			}
		printf("%d\n", x);
	}
	return 0;
}

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

int main(){
  int x;
  int n, k;
  cin >> n >> k;
  int d[k];
  int ans[n]={0};
  for(int i=0;i<k;i++){
    cin >> d[i];
    for(int j=0;j<d[i];j++){
      cin >> x;
      ans[x-1]+=1;
    }
  }
  int count=0 ;
  for(int i=0;i<n;i++){
    if(ans[i]==0) count+=1;
  }
  cout << count << endl;
}

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

using namespace std;

int main()
{
    int a,b;
    cin >>a>>b;
    // cout << fixed<<setprecision(6)<<r*r*M_PI<< " " <<fixed<<setprecision(6)<< 2*r*M_PI << endl;
    cout << a/b << " " << a%b << " ";
    double c=a;
    double d=b;
    cout << fixed<<setprecision(5)<<c/d<<endl;
    return(0);
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
int main() {
    int K, A, B;
    cin >> K >> A >> B ;
    for (int i = 1; i<1000; ++i){
        if (K*i>=A && K*i<=B) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}

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

int N;
int a[2][100];
int m[2][100];

int main(void){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a[0][i];
  }
  for(int i = 0; i < N; i++){
    cin >> a[1][i];
  }
  m[0][0] = a[0][0];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 2; j++){
      for(int k = 0; k < N; k++){
	int J = max(j - 1, 0);
	int K = max(k - 1, 0);
	if(m[j][k] == 0){
	  m[j][k] = a[j][k] + max(m[J][k], m[j][K]);
	}
      }
    }
  }

  cout << m[1][N-1] << endl;
}


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

int main() {
	int height;
	std::vector<int> heights;

	while (std::cin >> height) {
		heights.push_back(height);
	}
	std::sort(heights.begin(), heights.end());
	std::reverse(heights.begin(), heights.end());
	for (int i = 0; i < 3; ++i) {
		std::cout << heights.at(i) << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

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

	/* 入力 */
	int n = scan.nextInt();

	/* 処理 */
	long ans = 1;
	for(int i = 1; i <= n; i++){
	    ans *= i;
	    ans %= (int)(Math.pow(10,9)+7);
	}

	/* 出力 */
	System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
int main(void){
int N,A,B,SUM;
  scanf("%d",&N);
if(N==1){
  printf("Hello World");
}else if(N>=2){
  scanf("%d",&A);
  scanf("%d",&B);
  SUM=A+B;
  printf("%d",SUM);
}
}

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

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

const int INF = 100000000;
const double PI=3.14159265358979323846;

int main () {
    int N, X, Y;

    cin >> N >> X >> Y;
    X--;
    Y--;
    int a[N];
    rep(i,0,N) {
        a[i] = i;
    }
    vector<vector<int>> dist(N,vector<int>(N,INF));
    rep(i,0,N-1) {
        rep(j,i+1,N) {
            int tmp1 = j-i;
            int tmp2 = max(i-X,X-i)+max(j-Y,Y-j) +1;
            int tmp3 = max(i-Y,Y-i)+max(j-X,X-j) +1;
            dist[i][j] = min(tmp1,min(tmp2,tmp3));
            
        }
    }
    int ans[N] = {};
    rep(i,0,N-1) {
        rep(j,i+1,N) {
            ans[dist[i][j]]++;
            //cout << dist[i][j] << " ";
        }
        //cout << endl;
        
    }

    rep(i,1,N) {
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 16000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		String s=sc.next();
		String t=sc.next();
		StringBuilder sb=new StringBuilder();
		int m=s.length();
		int n=t.length();
		int[][] len=new int[m+1][n+1];
		for(int i=0; i<=m; i++) {
			len[i][0]=0;
		}
		for(int j=0; j<=n; j++) {
			len[0][j]=0;
		}

		String source="";
		for(int i=1; i<=m; i++) {
			for(int j=1; j<=n; j++) {
				if(s.charAt(i-1)==t.charAt(j-1)) {
					len[i][j]=len[i-1][j-1]+1;
				}else {
					len[i][j]=Math.max(len[i][j-1], len[i-1][j]);
				}
			}
		}
		int h=m;
		int w=n;
		boolean yoko=false;
		while(true) {
			if(h==0 || w==0) {
				break;
			}
			if(!yoko && w>0 && len[h][w]-1==len[h][w-1]) {
				yoko=true;
			}
			else if(!yoko && w>0 && len[h][w]-1!=len[h][w-1]) {
				w--;
			}
			else if(!yoko && w==0) {
				yoko=true;
			}
			else if(yoko) {
				if(h>0 && len[h][w]-1==len[h-1][w]) {
					yoko=false;
					source=s.charAt(h-1)+source;
					h--;
				}
				else if(h>0 && len[h][w]-1!=len[h-1][w]) {
					h--;
				}
				else if(h==0) {
					yoko=false;
				}
			}
		}
		pl(source);
	}

	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 89236
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int h, n;
    cin >> h >> n;
    vector<int> dp(h + 10005, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        for(int j = 0; j <= h; ++j){
            if(dp[j] == INF)    continue;
            chmin(dp[j + a], dp[j] + b);
        }
    }
    int ans = INF;
    for(int i = h; i < h + 10005; ++i)  chmin(ans, dp[i]);
    cout << ans << endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i <= 10000; i++) {
    if (i * 8 / 100 == a && i * 10 / 100 == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}


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

using namespace std;

struct RequestObj {
	int begin, end, type;
};

int n, m;//???,???????????°
int k;//????????¨????????°
int time_table[100][100];
int cheap_table[100][100];
RequestObj request[200];


const int INF = 10000000;

int main() {
	while (cin >> n >> m, n * m) {

		for (int i = 0; i < m; i++)for (int j = 0; j < m; j++)time_table[i][j] = INF, cheap_table[i][j] = INF;
		
		for (int i = 0; i < n; i++) {
			int a, b;
			cin >> a >> b;
			cin >> cheap_table[a - 1][b - 1] >> time_table[a - 1][b - 1];
			cheap_table[b - 1][a - 1] = cheap_table[a - 1][b - 1];
			time_table[b - 1][a - 1] = time_table[a - 1][b - 1];
		}
		cin >> k;
		for (int i = 0; i < k; i++) {
			cin >> request[i].begin >> request[i].end >> request[i].type;
		}
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < m; k++) {
					if (cheap_table[j][i] + cheap_table[i][k] < cheap_table[j][k]) {
						cheap_table[j][k] = cheap_table[j][i] + cheap_table[i][k];
					}
				}
			}
		}

		for (int i = 0; i < m; i++) {
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < m; k++) {
					if (time_table[j][i] + time_table[i][k] < time_table[j][k]) {
						time_table[j][k] = time_table[j][i] + time_table[i][k];
					}
				}
			}
		}
		for (int i = 0; i < k; i++) {
			if (request[i].type == 0) {
				cout << cheap_table[request[i].begin - 1][request[i].end - 1] << endl;
			}
			else {
				cout << time_table[request[i].begin - 1][request[i].end - 1] << endl;
			}
		}

		for (int i = 0; i < m; i++)for (int j = 0; j < m; j++)time_table[i][j] = INF, cheap_table[i][j] = INF;

	}
	return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 2000000000;
const ll mod = 1000000007;
int c_num[200010], c_num2[200010];
ll ans[200010];

ll modpow(ll x, ll y){
	if(y == 1) return x;
	if(y % 2 == 0){
		ll aa = modpow(x, y/2);
		return aa*aa%mod;
	}else{
		return x*modpow(x, y-1)%mod;
	}
}

int main(){
	int N, X, Y; cin >> N >> X >> Y;
	vector<P> ball;
	vector<int> color[N+1];
	for(int i=0; i<N; i++){
		int c, w; cin >> c >> w;
		color[c].push_back(w);
		ball.push_back(P(w, c));
	}
	ll fact[N+1];
	fact[1] = 1;
	for(int i=2; i<N+1; i++) fact[i] = fact[i-1] * i % mod;
	for(int i=1; i<=N; i++){
		ll mi = INF, index;
		for(int j=0; j<color[i].size(); j++){
			if(mi > color[i][j]){ mi = color[i][j]; index = j; }
		}
		c_num[i] = 1;
		for(int j=0; j<color[i].size(); j++){
			if(mi + color[i][j] <= X && index != j) c_num[i]++;
		}
	}
	
	sort(ball.begin(), ball.end());
	ll m1 = ball[0].first, m2 = INF, c1 = ball[0].second;
	ans[c1] = 1;
	long long size = 1;
	for(int i=1; i<N; i++){
		if(ball[i].second != c1 && m2 == INF){
			m2 = ball[i].first;
		}
		if(ball[i].second == c1 && ball[i].first + m1 <= X){
			size++;
			ans[c1]++;
		}else if(ball[i].second != c1 && ball[i].first + m1 <= Y){
			c_num2[ball[i].second]++;
		}
	}
	for(int i=1; i<=N; i++){
		if(c_num2[i] != 0 && i != c1){
			size += max(c_num[i], c_num2[i]);
			ans[i] += max(c_num[i], c_num2[i]);
		}
	}
	for(int i=0; i<color[c1].size(); i++){
		if(color[c1][i] + m1 > X && color[c1][i] + m2 <= Y){
			size++;
			ans[c1]++;
		}
	}
	if(2*m1 > X && m1 + m2 <= Y){
		size--; ans[c1]--;
	}
	ll p = 1;
	for(int i=1; i<=N; i++){
		if(ans[i] != 0){
			p = p * fact[ans[i]] % mod;
		}
	}
	cout << fact[size] * modpow(p, mod-2) % mod << "\n";
	return 0;
}


Measured memory_bytes: 17644
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

## a, bを無向辺として，隣接リストを作成
N, Q = list(map(int, input().split()))
al = [[] for i in range(N)]

for i in range(N-1):
    a, b = list(map(int, input().split()))

    al[a-1].append(b-1)
    al[b-1].append(a-1)

visited = [0 for i in range(N)]
seen = [0 for i in range(N)]
score = [0 for i in range(N)]

for i in range(Q):
    p, x = map(int, input().split())
    score[p-1] += x

@functools.lru_cache(None)
def dfs_rec(u):
    visited[u] = 1
    for v in al[u]:
        if visited[v] == 0:
            score[v] += score[u]
            dfs_rec(v)

dfs_rec(0)

print(" ".join(map(str, score)))

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int stone[n];
    int cam[n];
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        stone[i]=a;
    }
    cam[0]=0;
    for(int i=1; i<n; i++){
        int c1=abs(stone[i]-stone[i-1])+cam[i-1];
        int c2=100000;
        if(i>1){
            c2=abs(stone[i]-stone[i-2])+cam[i-2];
        }
        cam[i]=min(c1,c2);
    }
    cout<<cam[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;


int main(){
	int a,b,c,d;
	std::cin >> a>>b>>c>>d;
	std::cout << max(a*b,c*d) << std::endl;
}


Measured memory_bytes: 256
#pragma once
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int N,M,tmp;
  cin >>N >>M;
  if (N < M) {
    tmp=N;
    N=M;
    M=tmp;
  }
  if ((N + M) % 2 == 1) {
    cout << "IMPOSSIBLE";
  } else {
    cout << (N+M)/2;
  }
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define pb push_back
#define lp(j, n)  for(int j=0; j<(int)(n); ++j)
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define sz(v)    ( (int)((v).size()) )
#define F first
#define S second
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int,string> > vpii;
typedef map<int, int> mii;
const ll N=1e5+5;
ll arr[N],A[N]  ;
bool visited[N]={};
int cnt[N]={};
bool f;
int main()
{
    ll a,b,k;
   cin>>a>>b>>k;
    for(ll i=a ; i<=b ; i++)
    {
        if(i<=a+k-1 || i>=b-k+1)
            cout<<i<<endl;
    }
go;
}


Measured memory_bytes: 256
n = 104729
a = Array.new(n){|i| i+1}
a[0] = 0
(2..n**(0.50)).each do |i|
  (2..(n/i)).each{|j| a[i*j-1] = 0} if a[i-1]>0
end
a.delete(0)

while (n=gets.to_i)>0
  p a[0..n-1].inject(:+)
end

Measured memory_bytes: 9244
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=400010;
int n,tt;
int head[N],to[N],nxt[N],f[N][18],v[N],fa[N],ls[N],rs[N],sz[N],ans[N];
struct Dat {
    int x,y,z;
    inline bool operator < (const Dat &A) const {return z<A.z;}
} g[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') ch=='-'?o=-1:0,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return o*x;
}
inline void dfs(int x,int fa) {
    f[x][0]=fa;
    for(int i=1;i<18;i++) f[x][i]=f[f[x][i-1]][i-1];
    if(x<=n) sz[x]=1;
    else dfs(ls[x],x),dfs(rs[x],x),sz[x]=sz[ls[x]]+sz[rs[x]];
}
inline int query(int x,int y) {
    for(int i=17;~i;i--)
	if(f[x][i]&&v[f[x][i]]<y) x=f[x][i];
    return sz[x];
}
inline void solve(int x,int fa,int s,int la) {
    if(fa>la) {
	if(x<fa) {
	    s+=query(x,fa);
	    if(x<la) s-=query(x,la);
	}
	else {
	    ++s;
	    for(int i=head[x];i;i=nxt[i])
		if(to[i]!=fa&&to[i]<fa) s+=query(to[i],fa);
	}
	la=fa;
    }
    else if(x>la) {
	++s;
	for(int i=head[x];i;i=nxt[i])
	    if(to[i]!=fa&&to[i]<la) s+=query(to[i],la);
    }
    ans[x]=s;
    for(int i=head[x];i;i=nxt[i])
	if(to[i]!=fa) solve(to[i],x,s,la);
}
inline int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
int main() {
    cin>>n;
    for(int i=1;i<n;i++) {
	int x=gi(),y=gi();
	g[i]=(Dat){x,y,max(x,y)};
	to[++tt]=y,nxt[tt]=head[x],head[x]=tt;
	to[++tt]=x,nxt[tt]=head[y],head[y]=tt;
    }
    sort(g+1,g+n);
    for(int i=1;i<=n;i++) fa[i]=i;
    for(int i=1;i<n;i++) {
	int x=find(g[i].x),y=find(g[i].y),z=i+n;
	fa[x]=fa[y]=fa[z]=z;
	ls[z]=x,rs[z]=y,v[z]=g[i].z;
    }
    dfs(n+n-1,0),solve(1,0,-1,0);
    for(int i=2;i<=n;i++) printf("%d ",ans[i]);
    return 0;
}

Measured memory_bytes: 53888
#include <stdio.h>
 
int main(void)
{
    int m, f, r,i;
    char c[] = "ABCDF";
 
    scanf("%d %d %d", &m, &f, &r);
 
    while (m >= 0 || f >= 0 || r >= 0) {
        i = m + f;
        i = (i < 80) + (i < 65) + (i < 50) + (i < 30);
 
        if (i == 3) i -= (r >= 50);
 
        if (m == -1 || f == -1)
            printf("%c\n", c[4]);
        else
            printf("%c\n", c[i]);
 
        scanf("%d %d %d", &m, &f, &r);
    }
 
    return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Y;
  cin >> N >> Y;
  FOR(x,0,N+1) {
    FOR(y,0,N+1) {
      if(x + y > N) continue;
      int z = N - x - y;
      int yen = 10000 * x + 5000 * y + 1000 * z;
      if(Y == yen) {
        cout << x << " " << y << " " << z << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

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

typedef long long ll;
const int N = 2e5 + 77;
const int mod = (int)1e9 + 7;

int main()
{
  int n, m, x, ans = 0, a[N] = {0}, p[N * 5] = {0};
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", a + i);
    p[a[i]]++;
  }
  for (int i = 1; i < N * 5; i++)
  {
    if (!p[i])
      continue;
    if (p[i] > 1)
      p[i] = 0;
    for (int j = i + i; j < N * 5; j += i)
    {
      p[j] = 0;
    }
  }
  for (int i = 1; i < N * 5; i++)
  {
    if (p[i])
      ++ans;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 8512
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n,a,b;
  cin >> n >> a >> b;
  if(a%2 == b % 2) {
    cout << abs(b-a) / 2 << endl;
    return 0;
  }
  long long dist = abs(b-a);
  long long must = min({a-1,b-1,n-a,n-b});
  cout << must + 1 + (dist - 1) / 2 << endl;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	if(a[0] == a[1]) cout << a[2] << endl;
	if(a[1] == a[2]) cout << a[0] << endl;
	if(a[0] == a[2]) cout << a[1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main() {
    int N,K;
    cin>>N>>K;
    ll ans=0ll;
    for (int i = K+1; i <= N; ++i) {
        int syo = N / i, amari = N % i;
        ans += (ll) syo * (i - K);
        if(K==0)ans+=(ll)max(amari,0);
        else ans += (ll) max(amari - K +1, 0);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
g = gets.chomp
a = g[0].to_i
b = [true, false]
c = 1
while b[(1 + a) ** -(a ** 2)]
        puts "Case " + c.to_s + ": " + g
        c += 1
        g = gets.chomp
        a = g[0].to_i
end

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

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

    vector<vector<vector<ll>>> dp(M+1, vector<vector<ll>>(N+1, vector<ll>(N+1, 0)));
    dp[0][N-1][1] = 1;
    for(int m=0;m<M;++m) {
        for(int x=0;x<N;++x) {
            for(int y=1;y<=N-x;++y) {
                if(!dp[m][x][y]) continue;
                if(x) (dp[m+1][x-1][y] += (dp[m][x][y] * x) % MOD) %= MOD;
                (dp[m+1][x][y] += (dp[m][x][y] * (N-x-y)) % MOD) %= MOD;
                (dp[m+1][x][N-x] += (dp[m][x][y] * y) % MOD) %= MOD;
            }
        }
    }

    cout << dp[M][0][N] << endl;
}


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

using namespace std;


int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    sort(a.rbegin(), a.rend());
    int x = -1, y = -1;
    for (int i = 0; i < n; ++i) {
        if (i + 1 < n && a[i] == a[i + 1]) {
            if (x == -1)
                x = a[i];
            else {
                y = a[i];
                break;
            }
            ++i;
        }
    }
    if (x == -1 || y == -1)
        printf("0");
    else 
        printf("%lld", x * 1ll * y);
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int n;
char buff[13][10];
int len[13];
int enc[13][10];
bool zero[10];
int assign[10];
int cnttmp;
int cnt;

int check(){
  int sum = 0;
  REP(i,n){
    int real = 0;
    REP(j,len[i]){
      int tmp = enc[i][j];
      real *= 10;
      real += assign[tmp];
    }

    if(i == n - 1)
      sum -= real;
    else
      sum += real;
  }

  return sum == 0 ? 1 : 0;
}

bool check1(){
  int sum = 0;
  REP(i,n-1){
    sum += assign[enc[i][len[i]-1]];
  }
  return sum % 10 == assign[enc[n-1][len[n-1]-1]];
}

int dfs(int flag, int rest){
  if(rest == 0) return check();
  if(cnttmp == cnt - rest)
    if(!check1()) return 0;
  int ret = 0;
  for(int i = (zero[cnt - rest] ? 0 : 1); i < 10; i++){
    if((flag & (1<<i)) != 0){
      assign[cnt - rest] = i;
      ret += dfs(flag ^ (1<<i), rest - 1);
    }
  }
  return ret;
}

int main(){
  while(scanf("%d", &n), n){
    int memo[256];
    cnt = 0;
    REP(i,256) memo[i] = -1;
    REP(i,10) zero[i] = true;
    REP(i,n){
      scanf("%s", buff[i]);
      len[i] = strlen(buff[i]);
    }

    REP(jj,13){
      REP(i,n) if(jj < len[i]){
	int j = len[i] - jj - 1;
	if(memo[buff[i][j]] == -1){
	  enc[i][j] = memo[buff[i][j]] = cnt++;
	}else{
	  enc[i][j] = memo[buff[i][j]];
	}
	if(j == 0 && len[i] != 1) zero[enc[i][j]] = false;
      }
      if(jj == 0)
	cnttmp = cnt;
    }

    //REP(i,n) { REP(j,len[i]) printf("%d", enc[i][j]); puts(""); }

    printf("%d\n", dfs((1<<10)-1, cnt));
  }

  return 0;
}

Measured memory_bytes: 884
#include <iostream>
#include <algorithm>
int main() {
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);
	std::cout.tie(0);

	int n;
	std::cin >> n;
	int arr[200];
	for (int i = 0; i < 2 * n; ++i) {
		std::cin >> arr[i];
	}
	std::sort(arr, arr + 2 * n);
	int res = 0;
	for (int i = 0; i < 2 * n; i += 2) {
		res += arr[i];
	}
	std::cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  int mx = 0;
  bool ok = true;
  FOR(i,0,N) {
    int h; cin >> h;
    if (mx - h >= 2) {
      ok = false;
    }
    mx = max(mx, h);
  }
  cout << (ok ? "Yes" : "No") << endl;
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(std::string s, std::string t) {
    vvi dp(3001, vi(3001, 0));
    int n = s.size(), m = t.size();
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i - 1] == t[j - 1])
                chmax(dp[i][j], dp[i - 1][j - 1] + 1);
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }

    string ans = "";
    int ix = n, iy = m;
    while (ix > 0 and iy > 0) {
        if (dp[ix][iy] == dp[ix][iy - 1])
            iy--;
        else if (dp[ix][iy] == dp[ix - 1][iy])
            ix--;
        else {
            ix--, iy--;
            ans.push_back(s[ix]);
        }
    }

    reverse(all(ans));
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    std::string s;
    std::cin >> s;
    std::string t;
    std::cin >> t;
    solve(s, t);
    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int32 n = s.size();
    for(int32 ans = (n-1)/2*2; ans > 0; ans -= 2){
        bool flg = true;
        REP(i,ans/2){
            if(s[i] != s[ans/2+i]){
                flg = false;
                break;
            }
        }
        if(flg){
            ANS(ans);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
     int cntAC = 0, cntWA = 0,cntTLE = 0, cntRE = 0;
    while(n--){
        string s;
        cin>>s;


            if(s== "AC")
                cntAC++;
            else if(s=="WA")
                cntWA++;
            else if(s=="TLE")
                cntTLE++;
            else
               cntRE++;
        }
    cout<<"AC x "<< cntAC<<"\n";
    cout<<"WA x "<<cntWA<<endl;
    cout<<"TLE x "<<cntTLE<<endl;
    cout<<"RE x "<< cntRE<<endl;
    return 0;
}


Measured memory_bytes: 3692
def deg2rad r
  r * Math::PI / 180
end

x = 0.0
y = 0.0
r = 90
loop do
  d, a = gets.split(?,).map(&:to_i)
  break if d==0 and a==0
  x += d * Math.cos(deg2rad(r))
  y += d * Math.sin(deg2rad(r))
  r -= a
end
puts [x,y].map(&:to_i)

Measured memory_bytes: 9060
N=int(input())
A=list(map(int,input().split()))

mod=10**9+7
ans=0

for i in range(60):
    a=0
    for x in A:
        if x>>i&1:
            a+=1
    ans+=a*(N-a)*pow(2,i,mod)
    ans%=mod

    
print(ans)


Measured memory_bytes: 122936
#include <iostream>
#include <string>
#include <array>

#define ALPHA 26

#define INPUT_LEN 12
#define INPUT_SIZE 2
#define DATA_SIZE (1 << (INPUT_LEN * INPUT_SIZE))

bool memo[INPUT_LEN][DATA_SIZE];

int encode(const std::string& dna, const std::array<int, ALPHA>& dna_map){
	const int length = dna.length();
	
	int code = 0;
	for(int i = length - 1; i >= 0; i--){
		code <<= INPUT_SIZE;
		code |= dna_map[dna[i] - 'A'];
	}
	
	return code;
}

int main(int argc, char* argv[]){
	std::array<int, ALPHA> dna_map;
	dna_map.fill(-1);
	dna_map['A' - 'A'] = 0;
	dna_map['C' - 'A'] = 1;
	dna_map['G' - 'A'] = 2;
	dna_map['T' - 'A'] = 3;

	int n;
	std::cin >> n;

	for(int i = 0; i < n; i++){
		std::string ops, dna;
		std::cin >> ops >> dna;

		const int code = encode(dna, dna_map);
		const int length = dna.length() - 1;

		if(ops == "insert"){ memo[length][code] = true; }
		else{ std::cout << (memo[length][code] ? "yes" : "no") << std::endl; }
	}
	
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int MAX = 1e6;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    COMinit();
    vector<ll> a(n);
    rep (i, n) cin >> a[i];
    sort(a.begin(), a.end());
    ll add = 0;
    rep (i, n) {
        if (i < k - 1) continue;
        add += ((COM(i, k - 1) % MOD) * a[i]) % MOD;
        add %= MOD;
    }
    ll sub = 0;
    rrep (i, n) {
        if (i > n - k) continue;
        sub += ((COM(n - i - 1, k - 1) % MOD) * a[i]) % MOD;
        sub %= MOD;
    }
    ll res = add - sub;
    if (res < 0) res += MOD;
    res %= MOD;
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 24448
#include <stdio.h>

long modpow(long a, long n, long mod){
	if (n == 0) {
		return 1;
	}
	long answer;
	if (n%2 == 0) {
		answer = modpow(a, n/2, mod);
		answer *= answer;
	} else {
		answer = modpow(a, n-1, mod);
		answer *= a;
	}
	answer %= mod;
	return answer;
}
long modCombination(long n, long r, long mod) {
  long answer;
  if (n-r < r) {
    r = n-r;
  }
  long nu = 1;
  long de = 1;
  for (long i = 1; i <= r; i++) {
    nu *= n+1-i;
    nu %= mod;
    de *= i;
    de %= mod;
  }
  answer = nu;
  answer *= modpow(de,mod-2,mod);
  answer %= mod;
  return answer;
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long mod = 1000000007;
  long ans = 0,rem;
  for (long len = 1; len <= n/3; len++) {
    rem = n-len*3;
    ans += modCombination(rem+len-1,len-1,mod);
    ans %= mod;
  }
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 1712
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
    ll n;
    cin>>n;
    map<pair<char,char>,ll> m;
    for(ll i=0; i<=n; i++){
        string s=to_string(i);
        if(s[s.size()-1]=='0') continue;
        m[make_pair(s[0],s[s.size()-1])]++;
    }
    int ans=0;
    for(ll i=0; i<=n; i++){
        string t=to_string(i);
        if(t[t.size()-1]=='0') continue;
        ans+=m[make_pair(t[t.size()-1],t[0])];
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
N = int(input())
X = [int(i) for i in input().split()]
X2 = sorted(X)
mapper = {}

for i in range(N//2) :
    if (X2[i] in mapper) :
        continue
    mapper[X2[i]] = X2[len(X2)//2]

for i in range(N//2,N) :
    if (X2[i] in mapper) :
        continue
    mapper[X2[i]] = X2[(len(X2)//2) - 1]

for x in X :
    print(mapper[x])

Measured memory_bytes: 34824
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

bool solve(int n){
    reps(i, 9){
        reps(j, 9){
            if(i * j == n){
                return true;
            }
        }
    }

    return false;
}

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

    int n;
    cin >> n;

    if(solve(n)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    cout << flush;

    return 0;
}

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

using namespace std;
typedef long long ll;

const int INF = 1e9;
const int MN = 2010;
int n, k, q;
int a[MN];

int solve(int lw) {
    vector<int> all, v;
    for (int i = 0; i <= n; i++) {
        if (i == n || a[i] < lw) {
            if (int(v.size()) >= k) {
                nth_element(v.begin(), v.begin() + int(v.size()) - k + 1, v.end());
                sort(v.begin(), v.end());
                for (int j = 0; j <= int(v.size()) - k; j++) {
                    all.push_back(v[j]);
                }
            }
            v.clear();
        } else {
            v.push_back(a[i]);
        }
    }
    if (int(all.size()) < q) {
        return INF;
    }
    nth_element(all.begin(), all.begin() + q, all.end());
    return *max_element(all.begin(), all.begin() + q) - *min_element(all.begin(), all.begin() + q);
}

int main() {
    scanf("%d %d %d", &n, &k, &q);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    int ans = INF;
    for (int i = 0; i < n; i++) {
        ans = min(ans, solve(a[i]));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
mod = 10**9 +7

divide = []
for a in A:
    tmp = []
    d = 2
    while d*d <= a:
        while a % d == 0:
            a //= d
            tmp.append(d)
        d += 1
    if a != 1:
        tmp.append(a)
    divide.append(Counter(tmp))

count = Counter([])
for d in divide:
    for k,v in d.items():
        if k not in count:
            count[k] = v
        else:
            count[k] = max(count[k],v)

LCM = 1
for k,v in count.items():
    LCM *= pow(k,v,mod)
    LCM %= mod

ans = 0
for a in A:
    ans += LCM*pow(a,mod-2,mod)
    ans %= mod
print(ans)

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

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()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    let mut s = it.next().unwrap().bytes();
    let ls: Vec<_> = s.by_ref().take(n).collect();
    let rs: Vec<_> = s.rev().collect();
    let count = |ls: Vec<u8>| {
        let mut lh = HashMap::new();
        for i in 0..=n {
            for il in (0usize..n).combinations(i) {
                let mut b = vec![];
                let mut a = vec![];
                for j in 0..n {
                    if il.contains(&j) {
                        a.push(ls[j])
                    } else {
                        b.push(ls[j])
                    }
                }
                let k = (a, b);
                *lh.entry(k).or_insert(0usize) += 1;
            }
        }
        lh
    };
    let lc = count(ls);
    let rc = count(rs);
    let mut ret = 0;
    for (k, &v) in lc.iter() {
        ret += v * *rc.get(k).unwrap_or(&0);
    }
    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: 105852
#include<iostream>

using namespace std;

int main(void)
{
  int n,m; cin>>n>>m;
  int a,r,sum=0;
  for(int i=0;i<m;i++){ cin>>a; sum+=a; }
  
  r=(n-sum)>=0?n-sum:-1;
  cout<<r<<endl;
  
  return 0;
}

Measured memory_bytes: 3636
#Coding:Utf-8

N,K=list(map(int, input().split()))
a=[int(input()) for i in range(N)]

a.sort()

min=a[N-1]-a[0]
for l in range(N-K+1):
    if min>a[l+K-1]-a[l]:
        min=a[l+K-1]-a[l]

print(min)


Measured memory_bytes: 7384
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double theta1 = h*30 + m*0.5;
    double theta2 = m*6;
    double theta = abs(theta1 - theta2);
    double ans = sqrt( a*a + b*b - 2*a*b*cos(M_PI* theta/180));
    fcout << ans << endl;

}



Measured memory_bytes: 4252