akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

N=int(input())
cnt=defaultdict(int)
for i in range(N):
    ai=input()
    cnt[ai]+=1
count=0
ans=[]
for idx, val in cnt.items():
    if count<val:
        count=val
        ans=[]
        ans.append(idx)
    elif count==val:
        ans.append(idx)
ans = sorted(ans)
for i in ans:
    print(i)

Measured memory_bytes: 33372
#include <map>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <sstream>
#include <vector>
#include <stack>
#include <utility>
#include <math.h>
using namespace std;

typedef long ll;

ll gcd(ll a, ll b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	ll N;
	ll A[100010];

	cin >> N;
	for (ll i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	//入力完了

	//N-1回互除法つかう
	ll tmp = A[0];
	for (ll i = 0; i < N - 1; i++)
	{
		tmp = gcd(A[i + 1], tmp);
	}

	cout << tmp << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    string s;
    cin>>s;
    REP(i,5){
        cout<<s[i];
    }
    cout<<' ';
    for(int i=6;i<13;i++){
        cout<<s[i];
    }
    cout<<' ';
    for(int i=14;i<19;i++){
        cout<<s[i];
    }
    cout<<' ';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N; cin>>N;
  int score=0,ex_s=10000;
  for(int i=0;i<N;i++){
    int a; cin>>a;
    score+=a;
    if(a%10!=0) ex_s=min(ex_s,a);
  }
  if(score%10==0){
    if(ex_s==10000) score=0;
    else score-=ex_s;
  }
  cout<<score<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define gcd __gcd
#define lcm(a, b) ((a) * (b) / gcd((a), b))
#define all(x) x.begin(), x.end()
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define fastio() ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0)
#define endl '\n'

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;

template <class T> inline T RD(T &a) {T x; cin >> x; return a = x;}

const int maxn = 1e5 + 69, mod = 1e9 + 7;

signed main()
{
//	freopen("TEXT.inp", "r", stdin); freopen("TEXT.out", "w", stdout);
	fastio();

	int n; cin >> n;
	for (int i = 1; i <= 9; i++) {
        if (n % i == 0 && n / i <= 9) {
            cout <<"Yes";
            return 0;
        }
	}
	cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXSIZE = 1e2+7;
int num[MAXSIZE];
int n;
int bubbleSort(){
	bool flag = 1;
	int cnt = 0;
	while(flag){
		flag = 0;
		for(int j = n-1; j >= 1; j--){
			if(num[j] < num[j-1]){
				swap(num[j],num[j-1]);
				cnt++;
				flag = 1;
			}
		}
	}
	return cnt;
}
int main(){
	while(~scanf("%d",&n)){
		memset(num,0,sizeof(num));
		for(int i = 0; i < n; i++){
			scanf("%d",num+i);
		}
		int cnt = bubbleSort();
		for(int i = 0; i < n; i++){
			if(i) printf(" ");
			printf("%d", num[i]);
		}
		printf("\n");
		printf("%d\n", cnt);
	}
	return 0;
}


Measured memory_bytes: 3224
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Result struct {
	elems []int
	count int
}

func calcG(length int) ([]int, error) {
	if length <= 0 {
		err := fmt.Errorf("illegal length: %d\n", length)
		return nil, err
	}
	n := length - 1
	g := []int{}
	for n > 1 {
		g = append(g, n)
		n = n / 2
	}
	g = append(g, 1)
	return g, nil
}

func insertionSort(elems []int, g int) Result {
	n := len(elems)
	count := 0
	for i := g - 1; i < n; i++ {
		v := elems[i]
		vi := i
		for j := i - g; j >= 0; j = j - g {
			if elems[j] > v {
				elems[j+g] = elems[j]
				vi = j
				count++
			} else {
				break
			}
		}
		elems[vi] = v
	}
	return Result{elems, count}
}

func shellSort(elems []int) (Result, []int) {
	g, _ := calcG(len(elems))
	count := 0
	for _, v := range g {
		result := insertionSort(elems, v)
		count += result.count
		elems = result.elems
	}
	return Result{elems, count}, g
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	elems := make([]int, n)
	for i := 0; i < len(elems); i++ {
		x, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		elems[i] = x
	}

	result, g := shellSort(elems)

	fmt.Println(len(g))
	fmt.Println(strings.Join(isToAs(g), " "))
	fmt.Println(result.count)
	for _, v := range result.elems {
		fmt.Println(v)
	}
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func isToAs(is []int) []string {
	as := make([]string, len(is))
	for i := 0; i < len(as); i++ {
		as[i] = strconv.Itoa(is[i])
	}
	return as
}



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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
ll n;
cin>>n;
ll N=n;
int count=0;
while(n>0){
  count+=n%10;
n/=10;
}
if(N%count==0){
  cout<<"Yes"<<endl;
}else
{
  cout<<"No"<<endl;
}


  return 0;
}


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

int main()
{
  string s, t;
  cin >> s >> t;
  vector<i64> pos[26];
  i64 ssize = s.size(), tsize = t.size();
  for (i64 i = 0; i < ssize; i++)
    pos[s[i] - 'a'].push_back(i);
  for (i64 i = 0; i < tsize; i++)
    if (pos[t[i] - 'a'].size() == 0)
    {
      cout << -1 << endl;
      return 0;
    }
  i64 ans = -1, l = 0;
  for (i64 i = 0; i < tsize; i++)
  {
    i64 c = t[i] - 'a';
    i64 it = upper_bound(pos[c].begin(), pos[c].end(), ans) - pos[c].begin();
    if (it == (i64)pos[c].size())
    {
      ans = pos[c][0];
      l++;
    }
    else
      ans = pos[c][it];
  }
  cout << l * ssize + ans + 1 << endl;
  return 0;
}


Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007

struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int depth(int r) {

    }
};

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(m), b(m);
    UnionFind tr(n);
    rep(i, m) {
        cin >> a[i] >> b[i];
    }

    for(int i = 0;i < m; i++) {
        if(!tr.same(a[i]-1, b[i]-1)) {
          tr.unite(a[i]-1, b[i]-1);
        }
    }

    int ans = 0;
    set<int> na;
    std::vector<int> h;
    for(int i = 0;i < n; i++) {
        h.push_back(tr.root(i));
        na.insert(tr.root(i));
    }

    sort(all(h));
    for(auto itr = na.begin(); itr != na.end(); itr++) {
        int num = upper_bound(all(h), *itr)-lower_bound(all(h), *itr);

        ans = max(ans, num);
    }

    cout << ans << endl;

}

Measured memory_bytes: 14188
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
#include <math.h>

int main() {
  int x;
  scanf("%d", &x);
  int max = 1;
  for (int i=2; i<=sqrt((double) x); i++) {
    int n = i;
    while (n*i <= x) n *= i;
    max = (max < n) ? n : max;
  }
  printf("%d\n", max);
  return 0;
}


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

#define MAX 16777216

using namespace std;

bool dic[16777216];

int getStrNum(string str){
	int sum = 0, p=1;
	for(int i=0;i<str.size();++i){
		if(str[i] == 'A')sum += 1*p;
		else if(str[i] == 'C')sum += 2*p;
		else if(str[i] == 'G')sum += 3*p;
		else if(str[i] == 'T')sum += 4*p;
		p*=4;
	}
	return sum;
}

int main(){
	int n, i;
	cin >> n;
	
	string siji, _str;
	for(i=0;i<n;++i){
		cin >> siji >> _str;
		if(siji[0] == 'i'){
			dic[getStrNum(_str)]=true;
		}else{
			if(dic[getStrNum(_str)])cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4528
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

ll memo[2100][2100];

int main()
{
  ll N, x; cin >> N >> x;
  vector<ll> a(N);
  REP(i, N) cin >> a[i];

  REP(k, N) {
    REP(i, N) {
      memo[k][i] = a[(N - (i - k)) % N];
    }
  }
  REP(k, N - 1) {
    REP(i, N) {
      memo[k + 1][i] = min(memo[k + 1][i], memo[k][i]);
    }
  }

  ll ans = LLINF;
  REP(k, N) {
    ll cost = 0;
    REP(i, N) cost += memo[k][i];
    ans = min(ans, cost + k*x);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 33024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * Differential Pulse Code Modulation
 */
public class Main {

	static final int INF = 1 << 29;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int N, M;
			N = parseInt(line.substring(0, line.indexOf(' ')));
			M = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((N | M) == 0) break;

			int[] C = new int[M];
			for (int i = 0; i < M; i++) C[i] = parseInt(br.readLine());

			//
			int[][] dp = new int[N + 1][256];
			for (int i = 0; i < dp.length; i++) {
				Arrays.fill(dp[i], INF);
			}

			dp[0][128] = 0;

			for (int n = 1; n <= N; n++) {
				int x = parseInt(br.readLine());
				for (int i = 0; i < 256; i++) {
					for (int m = 0; m < M; m++) {
						int _x = i + C[m];
						if (255 < _x) _x = 255;
						if (_x < 0) _x = 0;
						int cost = (_x - x) * (_x - x);
						dp[n][_x] = Math.min(dp[n][_x], dp[n - 1][i] + cost);
					}
				}
			}

			int min = INF;

			for (int i = 0; i < 256; i++) {
				min = Math.min(min, dp[N][i]);
			}

			System.out.println(min);

		}
	}
}

Measured memory_bytes: 74004
S = input()
if S[0] == 'A':
    S = 'a' + S[1:]
    if S[2:-1].count('C') == 1:
        S = S[:S.index('C')] + 'c' + S[S.index('C')+1:]
        if S.islower():
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")


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

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

Measured memory_bytes: 3604
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        Dice dice = new Dice();
        int[] A = {1, 2, 3};

        for (int i=0; i<6; i++) {
            dice.d[i] = sc.nextInt();
        }
        sc.nextLine();

        String com = sc.nextLine();

        for (int i=0; i<com.length(); i++) {
            A = dice.Roll(com.substring(i, i+1), A[0], A[1], A[2]);
            //System.out.println(dice.d[A[0]-1]);
            //System.out.println(A[0]);
        }

        System.out.println(dice.d[A[0]-1]);
        //System.out.println(A[0]);

    }
}

class Dice {
    int[] d = new int[6];

    public int[] Roll(String com, int x, int y, int z) {
        int R[] = new int[3];
        if (com.equals("S")) {
            R[0] = 7 - y;
            R[1] = x;
            R[2] = z;
            return R;
        }
        else if (com.equals("N")) {
            R[0] = y;
            R[1] = 7 - x;
            R[2] = z;
            return R;
        }
        else if (com.equals("W")) {
            R[0] = z;
            R[1] = y;
            R[2] = 7 - x;
            return R;
        }
        else if (com.equals("E")) {
            R[0] = 7 - z;
            R[1] = y;
            R[2] = x;
            return R;
        }
        return R;
    }

}


Measured memory_bytes: 26360
#include <iostream>
using namespace std;
int main (void) {
    int a;
    int b;
    string s;

    cin >> a >> b;
    cin >> s;

    if (s.size() != a + b + 1) {
        cout << "No" << endl;
        return 0;
    }

    if (s[a] != '-') {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < s.size(); i++) {
        if (i == a) continue;
        if (!('0' <= s[i] && s[i] <= '9')) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define N 1005
#define M 1000000007
#define mod 998244353
using namespace std;

int main()
{
    __

    int x,y,z;
    
    cin >> x >> y >> z;
    
    cout << z << ' ' << x << ' ' << y << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+5;
int n, m;
struct Tree {
    int ls, rs, val; 
}tre[maxn*80];
int idx = 0, root[maxn];
int build(int l, int r) {
    int nod = ++idx;
    tre[nod].val = 0;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    tre[nod].ls = build(l, mid);
    tre[nod].rs = build(mid+1, r);
    return nod;
}

int update(int pre, int l, int r, int pos, int v) {
    int nod = ++idx;
    tre[nod] = tre[pre]; tre[nod].val += v;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    if (pos <= mid) tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
    else tre[nod].rs = update(tre[pre].rs, mid+1, r, pos, v);
    return nod;
}

int query(int id, int l, int r, int pos) {
    if (l == r) return tre[id].val;
    int mid = (l + r) >> 1;
    if (pos <= mid) {
        return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
    }
    else return query(tre[id].rs, mid+1, r, pos);
}

int a[maxn], vis[maxn];
void solve() {
    scanf("%d%d", &n,&m);
    for (int i = 1 ; i <= n ; i ++) {
        scanf("%d", a+i);
    }
    root[0] = build(1, n);    
    for (int i = 1 ; i <= n ; i ++) {
        if (!vis[a[i]])
            root[i] = update(root[i-1], 1, n, i, 1);
        else {
            int t = update(root[i-1], 1, n, vis[a[i]], -1);
            root[i] = update(t, 1, n, i, 1);
        }
        vis[a[i]] = i;
    }
    while (m--) {
        int l, r; scanf("%d%d", &l, &r);
        int tmp = query(root[r], 1, n, l);
        printf("%d\n", tmp);
    }
}

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

Measured memory_bytes: 252892
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define V vector<int>
int N, K;
V d;
int n[10000];
int p[10000];

int pwr(int x, int l)
{
    int a = 1;
    for (int i = 1; i < 50; i++) {
        if ((l & (1ll << (i - 1)))) {
            a *= p[i];
            a %= MOD;
        }
    }
    return a;
}
void solve()
{
    p[0] = 1;
    p[1] = K;
    for (int i = 2; i < 50; i++) {
        p[i] = (p[i - 1] * p[i - 1]) % MOD;
    }
    for (int i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            d.pb(i);
            if (i * i != N) {
                d.pb(N / i);
            }
        }
    }
    sort(all(d));
    for (int i = 0; i < (int)d.size(); i++) {
        n[i] = pwr(K, (d[i] + 1) / 2);
        for (int j = 0; j < i; j++) {
            if (d[i] % d[j] == 0) {
                n[i] -= n[j];
                n[i] %= MOD;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < (int)d.size(); i++) {
        if (d[i] % 2) {
            ans += n[i] * d[i];
            ans %= MOD;
        } else {
            ans += n[i] * (d[i] / 2);
            ans %= MOD;
        }
    }
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
}

signed main()
{
    cin >> N >> K;
    solve();
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <cstdio>
#include <cmath>
#define EPS 1e-7
using namespace std;

int main(){
  int n,k,t,u,v,l;
  int a;
  queue<int> q;

  cin >>n>>k>>t>>u>>v>>l;
  while( n-- ){
    cin >> a; q.push( a );
  }

  double time=0.0, now=0.0;
  double disV = v*t;
  int have=0;
  while( now<l ){
    if( have==0 ){
      if( q.empty() ){
	time += (l-now)/(double)u;
	break;
      }else{
	a=q.front(); q.pop(); have++;
	time += (a-now)/(double)u;
	now=a;
      }
    }else{
      have--;
      if( l-now < disV || fabs(l-now-disV)<EPS ){
	time += (l-now)/(double)v;
	break;
      }else{
       double move = t*v;
       while( !q.empty() &&
	   ( now+move>q.front() || fabs(now+move-q.front())<EPS ) ){
	 have++;
	 if( have>k ){
	   move = q.front()-now; q.pop();
	   break;
	 }
	 q.pop();
       }
       now += move;
       time += move/(double)v;
      }
    }
  }
  printf("%.10lf\n",time);

  return 0;
}

Measured memory_bytes: 1232
import java.util.*;


class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        Map<String, Integer> dic = new TreeMap<>();
        int N = sc.nextInt();
        sc.nextLine();

        Set<Integer> s = new HashSet<>();

        for (int i = 0; i < N; i++) {
            int tmp = sc.nextInt();
            if (s.contains(tmp)) {
                System.out.println("NO");
                System.exit(0);
            } else {
                s.add(tmp);
            }
        }
        System.out.println("YES");
    }
}


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

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

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

    long min = a[0];
    for (int j = 0; j < n; j++) {
        if (min >= a[j]) {
            min = a[j];
        } 
    }

    long max = a[0];
    for (int k = 0; k < n; k++) {
        if (max <= a[k]) {
            max = a[k];
        } 
    }

   long sum = 0;
    for (int l = 0; l < n; l++) {
        sum += a[l];
    }
    
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3164
using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] strarr = Console.ReadLine().Split(' ');
                int n = int.Parse(strarr[0]);
                int x = int.Parse(strarr[1]);
                int count = 0;
                if (n + x != 0)
                {
                    for (int i = 1; i <= n; i++)
                    {
                        for (int j = i + 1; j <= n; j++)
                        {
                            if (i == j)
                            {
                                j++;
                            }
                            for (int k = j + 1; k <= n; k++)
                            {
                                if (i + j + k == x)
                                {
                                    count++;
                                }
                            }
                        }
                    }
                    Console.WriteLine(count);
                }
                else
                {
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 9060
S = input()
c = len(S)
if c % 2 == 0:
    A1 = S[:c//2]
    A2 = S[c//2:]
    A2 = A2[::-1]
else:
    A1 = S[:c//2]
    A2 = S[c//2+1:]
    A2 = A2[::-1]

ans = 0
for i in range(len(A1)):
    if A1[i] != A2[i]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
	ll N, K;
	cin >> N >> K;

	vector<int> kbi(61);
	ll temp = K;
	int idm = 0;
	for (int i = 0; temp > 0; i++) {
		kbi[i] = temp % 2;
		temp /= 2;
		idm = i;
	}

	vector<int> asum(61);
	for (int i = 0; i < N; i++) {
		ll a;
		cin >> a;
		
		for (int j = 0; a > 0; j++) {
			asum[j] += a % 2;
			a /= 2;
		}
	}

	ll ans = 0;
	ll twos = pow(2, 60);

	bool flag = false;
	for (int i = 60; i >= 0; i--) {
		int zeros = N - asum[i];
		if (asum[i] >= zeros) {
			if (kbi[i] == 1) flag = true;
			ans += asum[i] * twos;
		}
		else {
			if (flag || i == idm&&kbi[i]||kbi[i])
				ans += zeros * twos;
			else
				ans += asum[i] * twos;
		}
		twos /= 2;
	}

	cout << ans << endl;
}


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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (a <= c && c <= b && b <= d) {
    cout << b - c << endl;
  } else if (c <= a && a <= d && d <= b) {
    cout << d - a << endl;
  } else if (a <= c && d <= b) {
    cout << d - c << endl;
  } else if (c <= a && b <= d) {
    cout << b - a << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,Q=map(int,input().split())
ans=[0]*N
ki=[[] for _ in range(N)]
for i in range(N-1):
 a,b=map(int,input().split())
 ki[a-1].append(b-1)
 ki[b-1].append(a-1)
for i in range(Q):
 p,q=map(int,input().split())
 ans[p-1]+=q
# dfs
from collections import deque
stack =deque([0])
visited = ["False"] * N
while stack:
 ne = stack.popleft()
 if visited[ne] == "False":
  visited[ne] = "True"
  for j in ki[ne]:
   if visited[j] == "False":
    ans[j]+=ans[ne]
    stack.append(j)
print(*ans)


Measured memory_bytes: 56160
import itertools
import math

n = int(input())
l = []
for _ in range(n):
    x, y = map(int, input().split())
    l.append((x,y))

def d(a, b):
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5

ans = 0

for v in itertools.permutations(l):
    s = 0
    for i in range(n-1):
        s += d(v[i], v[i+1])
    ans += s

print(ans / math.factorial(n))

Measured memory_bytes: 9348
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
while True:
    cnt=0
    for i in range(n):
        b=B[(i-1)%n]+B[(i+1)%n]
        if 0<b<B[i] and A[i]<B[i]:
            tmp=(B[i]-A[i])//b
            cnt+=tmp
            B[i]-=tmp*b
    if cnt:
        ans+=cnt
    else:
        break
print(ans if A==B else -1)

Measured memory_bytes: 118904
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def bfs():
    que = deque([0])
    c[0] = 1
    while que:
        v = que.popleft()
        for w in g[v]:
            if c[w] == 1:
                continue
            c[w] = 1
            que.append(w)

n, m  = MAP()
g = [[] for i in range(n)]
a = [0]*m
b = [0]*m
for i in range(m):
    a[i], b[i] = MAP()
    a[i] -= 1
    b[i] -= 1
    g[a[i]].append(b[i])
    g[b[i]].append(a[i])

ans = 0
for i in range(m):
    g[a[i]].remove(b[i])
    g[b[i]].remove(a[i])
    c = [0]*n
    bfs()
    for j in range(n):
        if c[j] == 0:
            ans += 1
            break
    g[a[i]].append(b[i])
    g[b[i]].append(a[i])

print(ans)

Measured memory_bytes: 10312
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if (A == B && B == C) {
			if (A != 1) {
				System.out.println(-1);
				return;
			}
		}

		int count = 0;
		while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
			count++;
			int tmpA = A / 2;
			int tmpB = B / 2;
			int tmpC = C / 2;

			A = tmpB + tmpC;
			B = tmpA + tmpC;
			C = tmpA + tmpB;
		}

		System.out.println(count);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b, int[] c) throws IOException {
			if (a.length != b.length || b.length != c.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
				c[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 22996
h,w,m = map(int, input().split())
bh = []
bw = []
l_num = [0]*h
c_num = [0]*w
for i in range(m):
    i1, i2 = map(int, input().split())
    bh.append(i1)
    bw.append(i2)
    l_num[i1-1] = l_num[i1-1] + 1
    c_num[i2-1] = c_num[i2-1] + 1

#print(l_num,c_num)

max_l_num = max(l_num)
max_c_num = max(c_num)
l_candi = [i for i, v in enumerate(l_num) if v == max_l_num]
c_candi = [i for i, v in enumerate(c_num) if v == max_c_num]

#print(l_candi,c_candi)

t = 0
for k in range(m):
    if l_num[bh[k]-1] == max_l_num and c_num[bw[k]-1] == max_c_num:
        t = t + 1

if t < len(l_candi)*len(c_candi):
    print(max_l_num+max_c_num)
else:
    print(max_l_num+max_c_num-1)

Measured memory_bytes: 61176
s = input()
RLSegment = [] # tuple (number of R, number of L)
isRNow = True
isLNow = False
rCount = 0
lCount = 0
for elem in s:
    if isRNow and elem == "R":
        rCount += 1
    elif isRNow and elem == "L":
        isRNow = False
        isLNow = True
        lCount = 1
    elif isLNow and elem == "L":
        lCount += 1
    else:
        RLSegment.append((rCount,lCount))
        isRNow = True
        isLNow = False 
        rCount = 1
        lCount = 0
RLSegment.append((rCount,lCount))

indexAns = 0
ans = []
for elem in RLSegment:
    endRCount = elem[0] // 2 + elem[0] % 2 + elem[1] // 2
    endLCount = elem[0] // 2 + elem[1] // 2 + elem[1] % 2
    for i in range(indexAns,indexAns + elem[0] - 1):
        ans.append('0')
    ans.append(str(endRCount))
    ans.append(str(endLCount))
    for i in range(indexAns + elem[0] + 1,indexAns + elem[0] + elem[1]):
        ans.append('0')
    indexAns += elem[0] + elem[1]
print(' '.join(ans))

Measured memory_bytes: 82688
// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

inline void ckmin(int &a, int b) {
  if (a > b) a = b;
}
inline void ckmax(int &a, int b) {
  if (a < b) a = b;
}

const int N = 2005;
int n, x, y;
vector <int> adj[N];
void add(int u, int v) { adj[u].push_back(v); }
int dep[N], f[N][20];
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  f[u][0] = fa;
  for (rint i = 1; i < 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  for (auto v: adj[u]) {
    if (v == fa) continue;
    dfs(v, u);
  } 
} 
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (rint i = 19; i >= 0; i--) {
    if (dep[u] - (1 << i) >= dep[v]) {
      u = f[u][i];
    }
  }
  if (u == v) return u;
  for (rint i = 19; i >= 0; i--) {
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  }
  return f[u][0];
}
int dist(int x, int y) {
  return dep[x] + dep[y] - 2 * dep[lca(x, y)];
}

int ans[N];
int main() {
  scanf("%d%d%d", &n, &x, &y);
  for (rint i = 1; i < n; i++) {
    add(i, i + 1);
  }
  dfs(1, 0);
  for (rint i = 1; i <= n; i++) {
    for (rint j = i + 1; j <= n; j++) {
      int dis = dist(i, j);
      dis = min(dis, dist(i, x) + 1 + dist(y, j));
      dis = min(dis, dist(i, y) + 1 + dist(x, j));
      //printf("(%d, %d): %d\n", i, j, dis);
      ans[dis]++;
    }
  }
  for (rint k = 1; k <= n - 1; k++) {
    printf("%d\n", ans[k]);
  }
}
 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const uint64_t seed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937_64 rnd(seed);
const int MOD = 998244353;

#ifdef VIPJML_LOCAL
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << "{";
    for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << *vi;
    }
    os << "}";
    return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const vector<pair<A, B>> &v)
{
    os << "{";
    for (typename vector<pair<A, B>>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << '(' << vi->first << " " << vi->second << ")";
    }
    os << "}";
    return os;
}

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

void solve()
{
    int k;
    cin >> k;
    string res;
    for (int i = 0; i < k; i++)
        res += "ACL";
    cout << res << "\n";
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    int T = 1;
    //cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve();
    }
    cout.flush();
    return 0;
}


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[100009]={};

string cmp(string a, string b){
  if(a.size() > b.size()){
    return a;
  }
  else if(a.size() < b.size()){
    return b;
  }
  else{
    return max(a, b);
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  REP(i, M){
    cin >> A[i];
  }
  REP(i, 100009){
    dp[i] = "*";
  }
  dp[0] = "";
  REP(i, N-1){
    if(dp[i] == "*") continue;
    REP(j, M){
      if(i+cost[A[j]] > N) continue;
      dp[i+cost[A[j]]] = cmp(dp[i+cost[A[j]]], dp[i]+to_string(A[j]));
    }
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 37888
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int a[M+7];
int n;

 main()

{
    fast
    cin>>n;
    f(i,1,n)
    {
        cin>>a[i];
    }
    reverse(a+1,a+n+1);
    int pl=2,pr=2,l,r;
    f(i,1,n)
    {
        int ymx=(pr/a[i])*a[i];
        int ymn=((pl+a[i]-1)/a[i])*a[i];
        if(!(ymx>=pl && ymx<=pr) || !(ymn>=pl && ymn<=pr))
        {
            cout<<"-1"<<endl;
            return  0;
        }
        l=ymn;
        r=ymx+a[i]-1;
        pl=l;
        pr=r;
    }
    cout<<l<<" "<<r<<endl;
    return 0;

}













Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int N[100];
	int n;
	
	int i;
	
	int max = 0;
	
	for(i = 0;i < 100;i++){
		N[i] = 0;
	}
	
	while(scanf("%d",&n) != EOF){
		N[n]++;
	}
	
	for(i = 0;i < 100;i++){
		if(N[i] > max){
			max = N[i];
		}
	}
	
	for(i = 0;i < 100;i++){
		if(N[i] == max){
			printf("%d\n",i);
		}
	}
	
	return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    odds = [a for a in a_list if a % 2 == 1]
    if len(odds) % 2 == 1:
        print("NO")
    else:
        print("YES")

if __name__ == '__main__':
    main()


Measured memory_bytes: 58608
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()

a = T + T
ok = False
for i in range(len(S)):
    ok |= a[i:len(S)+i] == S

if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 22332
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	N int
)

func main() {
	readVariables()
	var answer int
	rem := N % 1000
	if rem != 0 {
		answer = 1000 - rem
	}
	fmt.Println(answer)
}

func readVariables() {
	N = nextInt()

}

/* Template */

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt returns minimum argument
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt returns maximum argument
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt returns |x| for x
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow calculates integer power with modulo operation
//if modulo <= 1, it powers w/o module operation
//if base < 0, return value might be negative too.
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 1804
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-7
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

struct Po {
	ld x;
	ld y;
};

ld dist(Po p, Po q) {
	return sqrt(pow(p.x-q.x,2)+pow(p.y-q.y,2));
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(1) {
		ll n;
		cin>>n;
		if(n==0) break;
		vector<Po> p(n);
		REP(i,n) cin>>p[i].x>>p[i].y;
		ll ans=1;
		REP(i,n) {
			FOR(j,i+1,n) {
				ld d=dist(p[i],p[j]);
				//cout<<i<<" "<<j<<":"<<d<<endl;
				if(d>2) continue;
				Po diff; diff.x=p[j].x-p[i].x; diff.y=p[j].y-p[i].y;
				diff.x/=d; diff.y/=d;
				ld th=acos(d/2);
				//cout<<th<<endl;
				Po c1=p[i],c2=p[i];
				c1.x+=cos(th)*diff.x-sin(th)*diff.y;
				c1.y+=sin(th)*diff.x+cos(th)*diff.y;
				c2.x+=cos(-th)*diff.x-sin(-th)*diff.y;
				c2.y+=sin(-th)*diff.x+cos(-th)*diff.y;
				//cout<<c1.x<<" "<<c1.y<<" "<<dist(p[i],c1)<<" "<<dist(p[j],c1)<<endl;
				//cout<<c2.x<<" "<<c2.y<<" "<<dist(p[i],c2)<<" "<<dist(p[j],c2)<<endl;
				ll cnt1=0,cnt2=0;
				REP(k,n) {
					if(dist(p[k],c1)<=1+EPS) cnt1++;
					if(dist(p[k],c2)<=1+EPS) cnt2++;
				}
				ans=max({ans,cnt1,cnt2});
			}
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3476
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
#include <queue>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head
 
 const int N=101000;
 int n,m,od,a[N];
int main() {
	scanf("%d%d",&m,&n);
	rep(i,0,n) scanf("%d",a+i),od+=a[i]%2;
	if (od>2) puts("Impossible");
	else {
		sort(a,a+n,[&](int p,int q){ return p%2>q%2; });
		rotate(a,a+1,a+n);
		rep(i,0,n) printf("%d ",a[i]); puts("");
		if (n==1) a[n++]=0;
		a[0]--; a[n-1]++;
		if (a[0]==0) { rep(i,0,n-1) a[i]=a[i+1]; --n;}
		printf("%d\n",n);
		rep(i,0,n) printf("%d ",a[i]); puts("");
	}
}

Measured memory_bytes: 128
function Main(input) {
  input.trim();
  input = input.split("\n");
  var N = input[0];
  input.shift();
  var arr = arr1dto2d(input);
  var sum = 0;
  for(var p=0;p<N;p++){
    var mem = arr[p];
    var ato = mem[0];
    arr[p][0] -= mem[1];
    arr[p][1] += ato;
  }
  arr.sort(function(a,b){return(a[1] - b[1]);});
  var P = -900000000000;
  for(var i=0;i<N;i++){
    if(P<=arr[i][0]){
      sum++;
      P = arr[i][1];
    }
  }
  console.log(sum);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}


Measured memory_bytes: 39412
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int N; cin >> N&&N;) {
		map<int, pair<int, int>> mp;
		mp[0] = make_pair(250, 250);
		vector<vector<int>> a(500, vector<int>(500, -1));
		a[250][250] = 0;
		vector<int> n(N), d(N); rep(i, 1, N) {
			cin >> n[i] >> d[i];
			int x = mp[n[i]].first;
			int y = mp[n[i]].second;
			if (d[i] == 0) {
				a[x - 1][y] = i;
				mp[i] = make_pair(x - 1, y);
			}
			if (d[i] == 1) {
				a[x][y - 1] = i;
				mp[i] = make_pair(x, y - 1);
			}
			if (d[i] == 2) {
				a[x + 1][y] = i;
				mp[i] = make_pair(x + 1, y);
			}
			if (d[i] == 3) {
				a[x][y + 1] = i;
				mp[i] = make_pair(x, y + 1);
			}
		}
		int W = 0, H = 0;
		int w = INF, h = INF;
		rep(i, 0, 500) {
			rep(j, 0, 500) {
				if (a[i][j] != -1) {
					w = min(w, i);
					W = max(W, i);
					h = min(h, j);
					H = max(H, j);
				}
			}
		}
		cout << W - w + 1 << " " << H - h + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <set>

#define PI 3.1415926535897

typedef long long ll;

using namespace std;

int main() {
	ll n, m;
	cin >> n >> m;
	ll* h = new ll[n + 1];
	bool* f = new bool[n + 1];
	h[0] = 0;
	f[0] = false;
	for (int i = 1; i < n + 1; i++) {
		cin >> h[i];
		f[i] = true;
	}

	int count = 0;
	ll a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		if (h[a] > h[b]) {
			f[b] = false;
		}
		else if (h[a] < h[b]) {
			f[a] = false;
		}
		else {
			f[a] = false;
			f[b] = false;
		}
	}

	for (int i = 0; i < n + 1; i++) {
		if (f[i]) {
			count++;
		}
	}
	cout << count;
}

Measured memory_bytes: 4504
w = list(input())
ch = []

for i in w:
    if i not in ch:
        ch.append(i)

ans = 0
for j in ch:
    if w.count(j) % 2 != 0:
        ans += 1
        break

if ans == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8900
import java.util.Scanner;

class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a,b,ms,ns;
a=sc.nextInt();
b=sc.nextInt();
ms=a*b;
ns=a*2+b*2;
System.out.println(ms + " " + ns);
}
}



Measured memory_bytes: 26076
// 答えを見た
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;

int flush(queue<int>& q) {
    int ans = 0;
    while (!q.empty()) {
        int a = q.front();
        q.pop();
        ans += a;
    }

    return ans / 2;
}

signed main() {
    int N;

    cin >> N;

    vector<int> As(N);
    REP(i, N) {
        cin >> As.at(i);
    }

    int ans = 0;

    // 0になるまで見ていく
    queue<int> q;
    REP(i, N) {
        int a = As.at(i);
        if (a == 0) {
            ans += flush(q);
        } else {
            q.push(a);
        }
    }

    ans += flush(q);

    cout << ans << endl;
}


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

base = list(range(N, 0, -1))
if A < B:
    tmp = A
    A = B
    B = tmp
    base.reverse()

if (N - 1) // B + 1 <= A <= N - B + 1:
    possible = 1
else:
    possible = 0

if possible:
    split = [A]
    N_left = N - A
    for i in range(B-1, 0, -1):
        split.append((N_left - 1) // i + 1 + split[-1])
        N_left -= (N_left - 1) // i + 1

    split.insert(0, 0)
    ans = []
    for i in range(1, len(split)):
        rev = base[split[i-1]:split[i]]
        rev.reverse()
        ans.extend(rev)
    print(" ".join(map(str, ans)))
else:
    print(-1)


Measured memory_bytes: 106004