akhauriyash/Code-Regression huggingface dataset:
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns     #-}
{-# LANGUAGE TypeApplications #-}
import           Control.Exception     (assert)
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8 as BS
import           Data.Char             (isSpace)
import           Data.Int              (Int64)
import           Data.List             (unfoldr)
import           Data.Ratio
import qualified Test.QuickCheck       as QC

-- comb2 n = n * (n - 1) `quot` 2 without undue overflow
-- n even: comb2 n = (n `quot` 2) * (n - 1)
-- n odd: comb2 n = n * (n `quot` 2)
comb2 :: (Integral a, Bits a) => a -> a
comb2 n = (n `shiftR` 1) * ((n - 1) .|. 1)

-- floorSum n m a b
-- Assumptions:
-- * n: non-negative, m: positive
-- * a and b can be negative, or >= m
floorSum :: Int64 -> Int64 -> Int64 -> Int64 -> Int64
floorSum !n !m !a !b
  | assert (n >= 0 && m > 0) False = undefined
  | a < 0 = floorSum_positive 0 n m (- a) (b + a * (n - 1))
  | otherwise = floorSum_positive 0 n m a b
  where
    -- Invariants:
    -- * n: non-negative, m: positive, a: non-negative
    -- * 0 <= n <= m
    floorSum_positive :: Int64 -> Int64 -> Int64 -> Int64 -> Int64 -> Int64
    floorSum_positive !acc !n !m !a !b
      | n == 0 = acc
      | otherwise =
        let m2 = m `quot` 2
            (q, a') = (a + m2) `quotRem` m
            (a'',b'') = if a' < m2 then
                          (m2 - a', b - (m2 - a') * (n - 1))
                        else
                          (a' - m2, b)
            (q', b''') = b'' `divMod` m
            t = (a'' * (n - 1) + b''') `div` m
            -- t <= (m * (m - 1) + m) `div` m = m
        in floorSum_positive (acc + q * comb2 n + n * (q' + t)) t a'' m (b''' - m * t)

floorSum_naive :: Int64 -> Int64 -> Int64 -> Int64 -> Integer
floorSum_naive n m a b = sum [ floor ((toInteger a * toInteger i + toInteger b) % toInteger m) | i <- [0..n-1] ]

main = do
  t <- readLn @Int
  replicateM_ t $ do
    [n,m,a,b] <- map fromIntegral . unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    print $ floorSum n m a b

prop_comb2 :: Integer -> QC.Property
prop_comb2 n = comb2 n QC.=== n * (n - 1) `quot` 2

prop_floorSum :: QC.NonNegative (QC.Small Int64) -> QC.Positive Int64 -> Int64 -> Int64 -> QC.Property
prop_floorSum (QC.NonNegative (QC.Small n)) (QC.Positive m) a b = QC.within (100 * 1000) $ toInteger (floorSum n m a b) QC.=== floorSum_naive n m a b

prop_floorSum_r :: QC.Property
prop_floorSum_r = QC.forAllShrink (QC.choose (1, 10^4)) QC.shrink $ \n -> n >= 1 QC.==>
  QC.forAllShrink (QC.choose (1, 10^9)) QC.shrink $ \m -> m >= 1 QC.==>
  QC.forAllShrink (QC.choose (0, m - 1)) QC.shrink $ \a ->
  QC.forAllShrink (QC.choose (0, m - 1)) QC.shrink $ \b ->
  QC.within (100 * 1000 {- 100ms -}) $ toInteger (floorSum n m a b) QC.=== floorSum_naive n m a b


Measured memory_bytes: 5040
#include<bits/stdc++.h>
using namespace std;
const int _=1e5+5,yl=1e9+7;
void inc(int &x,int y){x+=y;if(x>=yl)x-=yl;}
long long  n,ans,F[26];string s;

int main(){
	cin>>n>>s;ans=1;
	for(int i=0;i<n;++i)F[s[i]-'a']++;
	for(int i=0;i<26;++i)ans=ans*(F[i]+1)%yl;
	--ans;cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int n;
int main() {
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int count = 0;
    bool enter = false;
    int m = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = m; j < n; j++) {
            if (a[j] == i) {
                enter = true;
                m = j+1;
                count++;
                break;
            }
            if (j == n - 1) {
                goto OUT;
            }
        }
    }
    OUT:
    if (!enter) {
        cout << "-1" << endl;
    } else {
        cout << n - count << endl;
    }
}

//前から順番に1, 2, 3と見つけていくことができればいい
//この時一番長くなるようにすればいい


Measured memory_bytes: 1024
N = int(input())
LIST = list(map(int, input().split()))
LIST.sort()
Bob = 0
Alice = 0

while True:
    if len(LIST) == 0:
        break
    Alice = Alice + LIST.pop()
    if len(LIST) == 0:
        break
    Bob = Bob + LIST.pop()

print(Alice - Bob)

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

int main(){
    string str;cin>>str;
    vector<char>a;
    for(int i=0;i<str.size();i++)a.push_back(str[i]);
    int t;cin>>t;
    bool reversed=0;
    while(t--){
        int b;cin>>b;
        if(b==1){
            reversed=!reversed;
        }else{
            int d;cin>>d;
            char e;cin>>e;
            if(d==1){
                if(reversed)a.push_back(e);
                else a.insert(a.begin(),e);
            }else{
                if(reversed)a.insert(a.begin(),e);
                else a.push_back(e);
            }
        }
    }
    if(!reversed){
        for(int i=0;i<a.size();i++)cout<<a[i];
    }else{
        for(int i=0;i<a.size();i++)cout<<a[a.size()-i-1];
    }
}


Measured memory_bytes: 1144
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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 nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n;
  ll allxor = 0;
  vl num(n);
  
  rep(i,n){
    cin >> num[i];
    allxor = (allxor ^ num[i]);
  }
  
  bool ans  = true;
  rep(i,n){
    if((allxor ^ num[i]) != num[i]){
      ans = false;
    }
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
}

Measured memory_bytes: 3996
#include <iostream>
#include <limits.h>

long long int abs(long long int x)
{
	if (x < 0)
		return -x;
	else
		return x;
}

int main()
{
	int k, n;
	std::cin >> n >> k;
	
	long long int x[60], y[60];
	for (int i = 0; i < n; ++i)
	{
		std::cin >> x[i] >> y[i];
		x[i] += 1000000000;
		y[i] += 1000000000;
	}
	
	long long int max = LLONG_MAX;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			for (int ii = 0; ii < n; ++ii)
			{
				for (int jj = 0; jj < n; ++jj)
				{
					long long int left = std::min(std::min(x[i], x[j]), std::min(x[ii], x[jj])),
								  right = std::max(std::max(x[i], x[j]), std::max(x[ii], x[jj])),
								  top = std::max(std::max(y[i], y[j]), std::max(y[ii], y[jj])),
								  bottom = std::min(std::min(y[i], y[j]), std::min(y[ii], y[jj]));
					
					int count = 0;
					bool flag = false;
					for (int c = 0; c < n; ++c)
					{
						if (x[c] >= left && x[c] <= right && y[c] >= bottom && y[c] <= top)
							++count;
						
						if (count >= k)
						{
							flag = true;
							break;
						}
					}
					
					if (flag)
					{
						long long int value = abs(left - right) * abs(top - bottom);
						
						if (value < max)
							max = value;
					}
				}
			}
		}
	}
	
	std::cout << max;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 5e5 + 10;
const int inf = 0x7ffffff;

void solve()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << c<<" " << a<<" " << b << "\n";


}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 256
#include <stdio.h>

struct a{
    char mark;
    int value;
};

void BubbleSort(struct a b[], int n) {
    
    int i, j, t1;
    char t2;
    
    for (i = 0; i < n; ++i) {
        for (j = n-1; j >= i+1; --j) {
            if(b[j].value < b[j-1].value) {
                t1 = b[j].value;
                b[j].value = b[j-1].value;
                b[j-1].value = t1;
                t2 = b[j].mark;
                b[j].mark = b[j-1].mark;
                b[j-1].mark = t2;
            }
        }
    }
}

void SelectionSort(struct a s[], int n) {
    
    int i, minj, j, t1;
    char t2;
    for (i = 0; i < n; ++i){
        minj = i;
        for (j = i; j < n; ++j) {
            if (s[j].value < s[minj].value) minj = j;
        }
        t1 = s[i].value;
        s[i].value = s[minj].value;
        s[minj].value = t1;
        t2 = s[i].mark;
        s[i].mark = s[minj].mark;
        s[minj].mark = t2;
    }
}

int main() {
    int n, i, t1;
    char t2;
    struct a b[36];
    struct a s[36];
    
    scanf("%d", &n);
    
    for (i = 0; i < n; ++i) {
        scanf("%c",&t2);
        scanf("%c%d", &b[i].mark, &b[i].value);
        s[i].value = b[i].value;
        s[i].mark = b[i].mark;
    }
    
    BubbleSort(b,n);
    
    for (i = 0; i < n; ++i) {
        printf("%c%d", b[i].mark, b[i].value);
        if (i != n-1) {
            putchar(' ');
        }
        else{
            putchar('\n');
        }
    }
    
    printf("Stable\n");
    
    SelectionSort(s, n);
    
    for (i = 0; i < n; ++i) {
        printf("%c%d", s[i].mark, s[i].value);
        if (i != n-1) {
            putchar(' ');
        }
        else{
            putchar('\n');
        }
    }
    
    t1 = 0;
    for (i = 0; i < n; ++i) {
        if (b[i].mark != s[i].mark) {
            t1 = 1;
            break;
        }
    }
    
    if (t1 == 0) {
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }
    
    return 0;
}

Measured memory_bytes: 1796
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

mod2 = 0
odd = 0
mod0 = 0

for ai in a:
    if ai%4 == 0:
        mod0 += 1
    elif ai%2 == 0:
        mod2 = 1
    else:
        odd += 1
        
odd += mod2


if mod0 >= (odd-1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14168
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String s = scanner.next();
    String ans = "";
    if (s.equals("A")) {
      ans = "T";
    } else if (s.equals("T")) {
      ans = "A";
    } else if (s.equals("G")) {
      ans = "C";
    } else if (s.equals("C")) {
      ans = "G";
    }
    System.out.println(ans);

  }

}


Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int n,m;
  
  while(cin >> n >> m,n+m){
    int a[n][m];
    bool w[n][m];
    REP(i,n){
      REP(j,m){
	w[i][j] = true;
      }
    }
    int b;
    cin >> b;
    REP(i,b){
      int t,y;
      cin >> t >> y;
      w[t-1][y-1] = false;
      a[t-1][y-1] = 0;
    }
    a[0][0] = 1;
    for(int i = 1;i < n;i++){
      if(w[i][0] == true){
	if(a[i-1][0] != 0){
	  a[i][0] = a[i-1][0];
	}
	else{
	  a[i][0] = 0;
	}
      }
    }
    for(int i = 1;i < m;i++){
      if(w[0][i] == true){
	if(a[0][i-1] != 0)
	  a[0][i] = a[0][i-1];
	else
	  a[0][i] = 0;
      }
    }
    
    for(int i = 1;i < m;i++){
      for(int j = 1;j < n;j++){
	if(w[j][i] == true){
	  a[j][i] = a[j-1][i] + a[j][i-1];
	  //cout << a[j][i] << endl;
	}
	
	
      }
    }
    cout << a[n-1][m-1] << endl;
  }
  /*REP(i,m){
    REP(j,n){
      cout << a[j][i] << "  ";
    }
    cout << endl;
    }*/
  /*REP(i,n)
    cout << a[i][0] << endl;
  cout << endl;
  REP(i,m){
    cout << a[0][i] << endl;
  }
  */
  return 0;
}

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

int main(){
  int N,Q;
  cin >> N >> Q;
  
  string S;
  cin >> S;
  
  vector<int> t(N);
  if(S[0]=='A' && S[1]=='C') t[1]=1;
  for(int i=1; i<N-1; i++){
    if(S[i]=='A' && S[i+1]=='C'){
      t[i+1]=t[i]+1;
    }else{
      t[i+1]=t[i];
    }
  }
  
  vector<int> l(Q);
  vector<int> r(Q);
  
  for(int i=0; i<Q; i++){
    cin >> l[i] >> r[i];
  }
  
  for(int i=0; i<Q; i++){
    cout << t[r[i]-1] - t[l[i]-1] << endl;
  }
}

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

class Program
{
    static void Main(string[] args)
    {
        var T = sc.ReadDouble();
        var X = sc.ReadDouble();
        var ans = T / X;
        Console.WriteLine(ans);
    }
    static int MOD = (int)1e9 + 7;
    static int INF = (int)1e7 + 1;
    static long LINF = (long)1e13 + 1;
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}

class Debug
{
    public static void Dump<T>(T[,] array)
    {
#if !DEBUG
        return;
#endif
        Console.WriteLine();
        var h = array.GetLength(0);
        var w = array.GetLength(1);

        for (int r = 0; r < h; r++)
        {
            for (int c = 0; c < w; c++)
            {
                Console.Write(array[r, c]);
                Console.Write(" ");
            }
            Console.WriteLine();
        }
        Console.WriteLine();
    }
    public static void Dump<T>(T[] array)
    {
#if !DEBUG
        return;
#endif
        Console.WriteLine();
        Console.WriteLine(string.Join(" ", array));
        Console.WriteLine();
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
Int const INF = 1e9;

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

    int n,a,b; cin>>n>>a>>b;
    cout<<min(b,a*n)<<'\n';
}

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

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)round(x))<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

int t[102];

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

  int n, x;

  while (cin >> n >> x) {
    for (int i = 0; i < n; i++) {
      cin >> t[i];
      x -= t[i];
    }
    sort(t, t + n);

    int ans = n + x / t[0];

    cout << ans << endl;
  }
}


Measured memory_bytes: 256
void main() {
	auto N = ri, K = ri, X = ri, Y = ri;
	if(N <= K) {
		writeln(N*X);
		return;
	} else {
		writeln(K*X + (N-K)*Y);
		return;
	}
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>
using namespace std;
int read()
{
	char ch=getchar();
	int num=0,flus=1;
	while(ch<'0'||ch>'9')
	{if(ch=='-') flus=-flus;ch=getchar();}
	while(ch>='0'&&ch<='9')
	{num=num*10+ch-'0';ch=getchar();}
	return num*flus;
}
long long int _gcd(long long int a,long long int b)
{
	if(b==0) return a;
	else return _gcd(b,a%b);
}
int main(void)
{
	//freopen("working.in","r",stdin);
	//freopen("working.out","w",stdout);
	long long int a,b;
	cin>>a>>b;
	cout<<a*b/_gcd(a,b)<<endl;
	return 0;
}
//	freopen("working.in","r",stdin);
//	freopen("working.out","w",stdout);

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, c, a[N], b[N];
int main()
{
	int i;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%lld %lld", &a[i], &b[i]);
	for (i = n - 1; i >= 0; i--) {
		a[i] += c;
		c += (a[i] + b[i] - 1) / b[i] * b[i] - a[i];
	}
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  string a,b,c;
  cin >> a;
  
  if(a.length()<4){
  	cout << "No" <<endl;
    return 0;
  }
  if(a.substr(0,4)=="YAKI"){
  	cout << "Yes" <<endl;  
  }else{

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


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char *argv[])
{
  int i, j, n;
  int cnt[6];
  double height;

  for(i=0; i<6; i++){
    cnt[i] = 0;
  }

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%lf", &height);
    if(height >= 185.0) cnt[5]++;
    else if(height >= 180.0) cnt[4]++;
    else if(height >= 175.0) cnt[3]++;
    else if(height >= 170.0) cnt[2]++;
    else if(height >= 165.0) cnt[1]++;
    else cnt[0]++;
  } 

  for(i=0; i<6; i++){
    printf("%d:", (i+1));
    for(j=0; j<cnt[i]; j++){
      printf("*");
    }
    printf("\n");
  }


  return 0;
}

Measured memory_bytes: 640
n = int(input())
x = list(map(int, input().split()))
ans = float('inf')
energy = []

for i in range(1, 101):
    for j in x:
        energy.append((j - i) ** 2)
    sum_energy = sum(energy)
    if sum_energy < ans:
        ans = sum_energy
    energy = []

print(ans)

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

const int NUM = 7368800;
int flg[NUM];

int main(){
    
    for(int n, m; cin >> n >> m, n;){
        for(int i = 0; i < NUM; i++)flg[i] = 0;
        for(int i = 0; i < m; i++){
            for(int j = n; j < NUM; j += n)flg[j] = 1;
            for(;flg[n];n++);
        }
        cout << n << endl;
    }

    return 0;
}



Measured memory_bytes: 31868
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    long int const mod = 1000000007;
    string l;
    cin >> l;
    long int n = l.size();
    long int dp[n][2];
    dp[0][0] = 2;
    dp[0][1] = 1;
    rep(i, n - 1){
        if (l[i+1] == '1'){
            dp[i+1][0] = dp[i][0] * 2;
            dp[i+1][0] %= mod;
            dp[i+1][1] = dp[i][0] * 1 + dp[i][1] * 3;
            dp[i+1][1] %= mod;
        }else{
            dp[i+1][0] = dp[i][0];
            dp[i+1][0] %= mod;
            dp[i+1][1] = dp[i][1] * 3;
            dp[i+1][1] %= mod;
        }
    }
    long int ans = dp[n-1][0] + dp[n-1][1];
    ans %= mod;
    cout << ans << endl;
}


Measured memory_bytes: 2048
main = do
  n <- readLn
  s <- getLine
  if (solve n s)
  then putStrLn "Yes"
  else putStrLn "No"

solve :: Int -> String -> Bool
solve n s 
  | odd n = False
  | otherwise = let (t1, t2) = splitAt (n `div` 2) s in t1 == t2
    


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;


int main() {
    string s; cin >> s;
    if (s[2] == s[3] and s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

using namespace std;

void CheckSameString(string w, char *q, int *count)
{
	if (w.size() == strlen(q) && strncmp(w.c_str(), q, w.size()) == 0)
		(*count)++;
}

int main()
{
	string w, t;
	getline(cin, w);
	
	while (1) 
	{
		string buf;
		getline(cin, buf);
		t += (buf + "\n");
		//cout << "*" << buff << "*" << endl;
		if (buf == "END_OF_TEXT")
			break;
	}
	
	std::transform(w.begin(), w.end(), w.begin(), ::tolower);
	std::transform(t.begin(), t.end(), t.begin(), ::tolower);
	//cout << w << endl;
	//cout << t << endl;
	
	char *TOKEN = " \t\n";
	
	char buff[256];
	memset(buff, 0, sizeof(char) * 256);
	
	char *q = strtok((char *)t.c_str(), TOKEN);
	if (q == NULL)
		return -1;
	int count = 0;
	CheckSameString(w, q, &count);
	
	while (1)
	{
		q = strtok(NULL, TOKEN);
		if (q == NULL)
			break;
		
		CheckSameString(w, q, &count);
		
	}
	
	cout << count << endl;
	
	return 0;
}

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

/*掛け金の合計を求める*/
int Sum(const int* X, int size) {
  int sum = 0;
  for(int i = 0; i < size; i++) {
    sum += X[i];
  }
  return sum;
}

/*当選者に分配(比例)*/
int Devide(int d, const int *X, int M) {
  if(X[M] != 0) 
    return (int)(d / X[M]);
  else
    return 0;
}

int main() {
  int N; //競技者の数
  int M; //優勝者の番号
  int P; //控除率(百分率)
  vector<int> X; //掛け金
  int deduction; //掛け金-控除率

  while(1) {
    cin >> N >> M >> P;
    if(N == 0 && M == 0 && P == 0)
      break;
      
    for(int i = 0; i < N; i++) {
      int x;
      cin >> x;
      X.push_back(x);
    }
    
    deduction = Sum(&X.front(), X.size()) * (100-P); /*掛け金-控除率を求める*/
    cout << Devide(deduction, &X.front(), M-1) << endl;
    X.clear();
  }

}



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

int main(){

  int sx, sy, tx, ty;
  string ans = "";

  cin >> sx >> sy >> tx >> ty;

  int x = tx - sx;
  int y = ty - sy;

  for(int i = 0; i < y; i++) ans += "U";
  for(int i = 0; i < x; i++) ans += "R";
  for(int i = 0; i < y; i++) ans += "D";
  for(int i = 0; i < x; i++) ans += "L";
  ans += "L";
  for(int i = 0; i < y+1; i++) ans += "U";
  for(int i = 0; i < x+1; i++) ans += "R";
  ans += "DR";
  for(int i = 0; i < y+1; i++) ans += "D";
  for(int i = 0; i < x+1; i++) ans += "L";
  ans += "U";

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


Measured memory_bytes: 256
H,W = map(int,input().split())
S = []
for i in range(H):
    S.append(input())

k = [ [ 0 for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            k[i][j] = 0
        else:
            if j > 0:
                k[i][j] = k[i][j-1] + 1
            else:
                k[i][j] = 1

for i in range(H):
    t = 0
    for j in range(W):
        t = max(t,k[-i-1][-j-1])
        if S[-i-1][-j-1] == "#":
            t = 0
            continue
        k[-i-1][-j-1] = t


kk = [ [ 0 for i in range(W)] for j in range(H)]
for j in range(W):
    for i in range(H):
        if S[i][j] == "#":
            kk[i][j] = 0
        else:
            if i > 0:
                kk[i][j] = kk[i-1][j] + 1
            else:
                kk[i][j] = 1

for j in range(W):
    t = 0
    for i in range(H):
        t = max(t,kk[-i-1][-j-1])
        if S[-i-1][-j-1] == "#":
            t = 0
            continue
        kk[-i-1][-j-1] = t
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue

        ans = max(ans , k[i][j] + kk[i][j] - 1)
print(ans)


Measured memory_bytes: 127960
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;

const ll INF = 10e8;
const int maxN = 1<<18;

const int maxH = 1010; 
const int MOD = 1000000007;
const int maxK = 12;

char a[20]; 
bool check(int n,int m,int k)
{
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			if((n*m-k) == (n*j + m*i - 2*i*j))
				return true;
	return false;
}
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	if(check(n,m,k))
		puts("Yes");
	else
		puts("No");
	return 0;
}  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x,m;
    cin >> n >> x;
    int ans=n;
    vector<int> a_1;
    int q=0;
    for(int i=0;i<n;i++){
        cin >> m;
        a_1.push_back(m);
        q+=m;
    }
    x-=q;
    sort(a_1.begin(),a_1.end());
    ans+=x/a_1[0];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}

vector<Int> getNum(Int n, Int b){
  vector<Int> res;
  Int x = 1LL<<(n - 1);
  Int num = (b - 1) - ((1LL<<n) - b);
  while(x){
    if(abs(num + x) < abs(num - x)) num += x, res.push_back(-x);
    else num -= x, res.push_back(x);
    x /= 2;
  }
  reverse(res.begin(), res.end());
  return res;
}

string rev(string s){
  for(char &ch:s) ch = ch == 'L'? 'R':'L';
  return s;
}

string solve(Int n,Int a, Int b){
  a = (1LL<<n) - a + 1;
  Int height = (1LL<<n);
  string res;
  auto dir = getNum(n, b);
  for(Int x:dir){
    Int openL = -1;
    if(height / 2 >= a){ //lower
      if(x > 0) openL = 1;
      if(x < 0) openL = 0;
    }
    else{                //upper
      if(x > 0) openL = 0, a = height - a + 1, res = rev(res);
      if(x < 0) openL = 1, a = height - a + 1, res = rev(res);
    }
    assert(x != 0);
    res += openL? 'L':'R';
    height /= 2;
  }
  reverse(res.begin(), res.end());
  return res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(1){
    Int n, a, b;
    cin>>n>>a>>b;
    if(n == 0 && a == 0 && b == 0) return 0;
    string ans = solve(n, a, b);
    cout<<ans<<endl;
  }
  
  return 0;
}



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

#define MAX 1000

int main(void)
{
	int x, a, b;
	int d_a, d_b;

	scanf("%d %d %d%*c", &x, &a, &b);

	d_a = abs(x-a);
	d_b = abs(x-b);

	if(d_a > d_b) {
		printf("B");
	}
	else {
		printf("A");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define lli                             long long int
#define ull                             unsigned long long int
#define D                               double
#define Input(n)                        for(int i = 0; i < n; i++) cin >> a[i];                          
#define sqr(x)                          ((x)*(x))
#define ff                              first
#define sz                              size()
#define PB                              push_back
#define MP                              make_pair
#define CHR                             getchar()
#define NL                              printf("\n")
#define PI                              2.0*acos(0.0)
#define MEM(a,val)                      memset(a,val,sizeof(a))
#define timesave                        ios_base::sync_with_stdio(0); cin.tie(0)
#define debug                           printf("***** here here here here *****\n");
#define file_input                      freopen("A.in","r",stdin),freopen("A1.out","w",stdout)
using namespace std;

template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template<typename T>inline T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
template<typename T>inline T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}


long long Bigmod(long long base, long long power, long long MOD){long long ret=1;while(power){if(power & 1)ret=(ret*base)%MOD;base=(base*base)%MOD;power>>=1;}return ret;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
long long ModInverse(long long number, long long MOD){return Bigmod(number, MOD-2, MOD);}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }

const int M = 1e5 + 5;

 
                      ///*********************** Let`s start ***************************//

int main()
{
	timesave;
	
	
	lli k, l, r, x, y;
	
	cin >> k;
	
	lli a[k+5];
	
	for(int i = 0; i < k; i++){
		cin >> a[i];
	}
	if(a[k-1] != 2){
		cout << -1 << endl;
		return 0;
	}
	l = 2; r = 3;
	
	for(int i = k-2; i >= 0; i--){
		x = l/a[i]; y = r/a[i];
		if(x == 0) x = 1;
		else if(l%a[i] != 0) x++;
		
		
		if(x > y){
			cout << -1 << endl;
			return 0;
		}
		
		l = x*a[i]; r = (y*a[i])+a[i]-1;
		//cout << l << " " << r << endl;
	}
	
	cout << l << " " << r << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e7+5;
const long long inf=0x3f3f3f3f;
const long long mod=1e9+7;
long long n,m,a[maxn],b[maxn],cx[maxn],cy[maxn],px[maxn],py[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(px,-1,sizeof(px));
	memset(py,-1,sizeof(py));
	cin>>n>>m;
	for(long long i=1;i<=n;i++)
	{
		cin>>a[i];
		cx[a[i]]++;
		px[a[i]]=i;
	}
	for(long long i=1;i<=m;i++)
	{
		cin>>b[i];
		cy[b[i]]++;
		py[b[i]]=i;
	}
	for(long long i=1;i<=n*m;i++)
	{
		if(cx[i]>2||cy[i]>2)
		{
			cout<<"0"<<endl;
			return 0;
		}
	}
	long long nn=0,mm=0,ans=1,cnt=0;
	for(long long i=n;i>0;i--)
	{
		for(long long j=m;j>0;j--)
		{
			long long x=(i-1)*m+j;
			if(px[x]!=-1&&py[x]!=-1)
			{
				nn++;
				mm++;
				cnt++;
			}
			else if(px[x]!=-1)
			{
				if(!mm)
				{
					cout<<"0"<<endl;
					return 0;
				}
				nn++;
				cnt++;
				ans=ans*mm%mod;
			}
			else if(py[x]!=-1)
			{
				if(!nn)
				{
					cout<<"0"<<endl;
					return 0;
				}
				mm++;
				cnt++;
				ans=ans*nn%mod;
			}
			else
			{
				if(nn*mm-cnt==0)
				{
					cout<<"0"<<endl;
					return 0;
				}
				ans=ans*(nn*mm-cnt)%mod;
				cnt++;
			}
			if(nn>n||mm>m)
			{
				cout<<"0"<<endl;
				return 0;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 166144
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;

int gcd(int a, int b) {
    return b > 0 ? gcd(b, a % b) : a;
}
int main() {
    int  a, b;
    while (scanf("%d%d", &a, &b) != EOF) {
        printf("%d %d\n", gcd(a, b), a / gcd(a, b) * b);
    }

    return 0;


}

Measured memory_bytes: 1188
#include<stdio.h>
#include<string.h>
int main(void){
  int l,cnt=0,i,num,even=0;
  scanf("%d",&l);
  for(i=1;i<=l;i++){
    num=i;
    even=0;
    while(num>0){
      num/=10;
      even++;
    }
    if(even%2==0){
      i++;
      continue;
    }else{
      cnt++;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        String S = sc.next();
        
        if(S.length()<=K){
                System.out.println(S);            
        }else{
                System.out.println(S.substring(0,K) + "...");
            }      
	}
}

Measured memory_bytes: 38528
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
#include<fstream>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};
struct edge { int to, cost; };
int a[60];
int b[60];
signed main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	int sum = 0;
	rep(i, n) {
		if (a[i] != b[i])sum++;
	}
	if (sum < 3)cout << "YES" << endl;
	else cout << "NO" << endl;
}



Measured memory_bytes: 256
#C問題  
N,Q=map(int,input().split())
S=str(input())
Slist=list(S)
pile=[0 for i in range(N)]
for i in range(N-1):
    if i == 0:
        pass
    else:
        pile[i]=pile[i-1]
  
    if Slist[i] == "A" and Slist[i+1] == "C":
        pile[i]+=1
pile[-1]=pile[-2]
pile.insert(0,0)
for i in range(Q):
    l,r=map(int,input().split())
    print(pile[r-1]-pile[l-1])

Measured memory_bytes: 6976
let () =
  let w,h,x,y,r = Scanf.sscanf (read_line()) "%d %d %d %d %d" (fun a b c d e -> a, b, c, d, e) in
  print_string (if r <= x && x+r <= w && r <= y && y+r <= h then "Yes\n" else "No\n")
;;


Measured memory_bytes: 2272
from operator import itemgetter


def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = [[] for _ in range(M)]
    for i in range(M):
        BC[i] = list(map(int, input().split()))
    BC.sort(key=itemgetter(1), reverse=True)
    
    change = []
    for b, c in BC:
        change += [c for _ in range(b)]
        if N < len(change):
            break
    
    A += change
    A.sort()
    ans = sum(A[-N:])
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 36088
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (b-a == c-b ? "YES" : "NO") << endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/priority_queue.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define endl '\n'
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define ls t[root << 1]
#define rs t[root << 1 | 1]
#define tr t[root]
#define lowbit(x) x &(-x)
#define all(x) (x).begin(), (x).end()
#define sf(x) scanf("%d", &x)
#define pf(x) printf("%d", x)
#define debug(x) cout << x << endl
#define mod(x) (x % mod + mod) % mod

template <typename T>
void read(T &x)
{
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch))
    {
        if (ch == '-')
            f *= -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}

const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2e5 + 7;
const int maxm = 1e3 + 7;
const int mod = 1e9 + 7;

#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
int pre[maxn];
int siz[maxn];
int Find(int x)
{
    if (x == pre[x])
        return x;
    return pre[x] = Find(pre[x]);
}
int ans=1;
void join(int x, int y)
{
    int fx = Find(x), fy = Find(y);
    if (fx!=fy)
    {
        pre[fx]=fy;
        siz[fy]+=siz[fx];
        ans=max(ans,siz[fy]);
    }
}
int main()
{
    IO;
    for (int i = 1; i < maxn; ++i)
    {
        pre[i] = i;
        siz[i] = 1;
    }
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int x, y;
        cin >> x >> y;
        join(x, y);
    }
    cout<< ans << endl;
    return 0;
}


Measured memory_bytes: 5180
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d\n", 6 - a - b);
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool can(int t, int x, int y) {
  t = t - x - y;
  if (t < 0) {
    return false;
  } else if (t == 0) {
    return true;
  }
  if (t % 2 == 0) {
    return true;
  } else {
    return false;
  }
}
int main(void) {
  int N;
  cin >> N;
  int t[N], x[N], y[N];
  for (int i = 0; i < N; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  for (int j = 0; j < N; j++) {
    int lt = 0, lx = 0, ly = 0;
    if (can(t[j] - lt, x[j] - lx, y[j] - ly)) {
      continue;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  int n,m; cin >> n >> m;
  if(n==1 && m==0){
    cout << 0 << endl;
    return 0;
  }
  int ans[n];
  FOR(i,0,n-1) ans[i] = -1;
  int s[m],c[m];
  FOR(i,0,m-1){
    cin >> s[i] >> c[i];
    --s[i];
    if(s[i]>=n){
      cout << -1 << endl;
      return 0;
    }
    if(s[i]==0 && c[i]==0 && n!=1){
      cout << -1 << endl;
      return 0;
    }
    
    if(ans[s[i]]==-1 || ans[s[i]]==c[i]) ans[s[i]] = c[i];
    else{
      cout << -1 << endl;
      return 0;
    }
  }

  FOR(i,0,n-1){
    if(ans[i]==-1){
      if(i!=0) ans[i] = 0;
      else ans[i] = 1;
    }
  }

  FOR(i,0,n-1) cout << ans[i];
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    map<int,int> mp;
    int sum = 0;
    rep(i,n){
        int t;cin>>t;
        mp[i+1] = t;
        sum += t;
    }
    int m; cin>>m;
    vector<P> px(m);
    rep(i,m) {
        cin>>px[i].first>>px[i].second;
    }
    for(auto a : px){
        cout<<(sum-mp[a.first]+a.second)<<endl;
    }

}

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

int main(){
    int a,b,x,n;
    int l[10][10] = {};
    long long int result = 0;
    
    cin >> n;

    for(int i = 1; i <= n; i++){
        a = i % 10;
        x = i;
        while(x){
            b = x;
            x /= 10;
        }
        l[a][b]++;
    }

    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            result += l[i][j] * l[j][i];
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
string s;
long long ans;
char x='x';
void head_insert(){
    s.insert(s.begin(),x);
    ans++;
    return;
}

void back_insert(){
    s.insert(s.end(),x);//
    ans++;
    return;
}

void remove(){
    if(s.size()>1){
    s.erase(s.begin());
    s.erase(s.end()-1);
    }
    else{
        s.clear();
    }
    return;
}


int main(){
cin>>s;
ans=0;
while(!s.empty()){
    if(s.front()==s.back()){
        remove();
    }
    else if(s.front()==x){
        back_insert();
    }

    else if(s.back()==x){
        head_insert();
    }

    else{
        cout<<"-1"<<endl;
        return 0;
    }
}
cout<<ans<<endl;

 return 0;
}
/*
xabxa

2


ab

-1

a

0


oxxx

3

*/

Measured memory_bytes: 512
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextLong() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextDouble() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	for i, v := range a {
		if i > 0 {
			io.writer.WriteString(" ")
		}
		fmt.Fprintf(io.writer, "%v", v)
	}
	io.writer.WriteString("\n")
}

func (io *Io) Printfln(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format + "\n", a...)
}

func main() {
	io := NewIo()
	defer io.Flush()
	H := io.NextInt()
	_ = io.NextInt()
	for i := 0; i < H; i++ {
		line := io.NextLine()
		for k := 0; k < 2; k++ {
			io.Println(line)
		}
	}
}


Measured memory_bytes: 640