akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int count = 0;
        for (int i = 0; i < S.length(); i++) {
        	count += S.charAt(i) == T.charAt(i) ? 1 : 0;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 23892
def resolve():
    N = int(input())
    K = int(input())
    X = int(input())
    Y = int(input())
    xdays = min(N, K)
    ydays = max(N-K, 0)
    print(X*xdays+Y*ydays)
    
    


if '__main__' == __name__:
    resolve()

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

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const int maxn = 2e6 + 10;
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

string s[maxn];

int main()
{
	int n, l;
	scanf("%d%d", &n, &l);
	for (int i = 1; i <= n; ++i)
		cin >> s[i];
	sort(s+1, s+n+1);
	for (int i = 1; i <= n; ++i)
		cout << s[i];
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int a, b, ans;
int main(){
	scanf("%d%d", &a, &b);
	for(ans = 1; ans < 1200; ans++) if(ans * 108 / 100 - ans == a && ans * 11 / 10 - ans == b) break;
	printf("%d\n", ans == 1200 ? -1 : ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <map>
//#include <set>
//#include <list>
//#include <cmath>
//#include <ctime>
//#include <deque>
//#include <queue>
//#include <stack>
//#include <string>
//#include <bitset>
//#include <cstdio>
//#include <limits>
//#include <vector>
//#include <climits>
//#include <cstring>
//#include <cstdlib>
//#include <fstream>
//#include <numeric>
//#include <sstream>
//#include <iomanip>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>

using namespace std;

#define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define PI 3.141592653589793238462643383279502884
#define MAX 1000100
#define mod 1000000007
#define EPS 1E-9
#define int long long
#define endl "\n"

int fix(int cur, int m)
{
    return ((cur%m) + m) % m;
}

int fast_power(int x, int y,int m)
{
    if (y == 0)
        return 1;
    int temp = fast_power(x, y / 2, m) ;
    temp = (temp*temp)% m;
    if (y % 2 != 0)
        temp = (temp*x)% m;
    return temp;

}


int32_t main()
{
    //freopen("D:/Important Files/Cocktail/SOLVE/TestLib/testcases/input/input11.txt", "r", stdin);
   // freopen("D:/Important Files/Cocktail/SOLVE/TestLib/testcases/output/output11.txt", "w", stdout);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.tie(0);

    int n;
    cin >> n;
    int x;
    for(int i=0;i<n;i++)
    {
        cin >> x;
        if(x%2==0)
        {
            if(x%3==0 || x%5==0)
                continue;
            else
                return cout << "DENIED" << endl,0;
        }
    }
    cout << "APPROVED" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;


int main()
{
    string s;
    int k;
    cin>>s>>k;
    if(s.length()==1){
        cout<<k/2<<endl;
        return 0;
    }
    ll cnt=1,ans=0;
    bool judge=true;
    rep(i,s.length()){
        if(s[i]==s[i+1])cnt++;
        else{
            ans+=cnt/2;
            cnt=1;
            if(i<s.length()-1)judge=false;
        }
    }
    if(judge){
        ll l=s.length();
        //cout<<(l*k)<<endl;
        cout<<(l*k)/2<<endl;
        return 0;
    }
    ans=ans*k;
    
    if(s[0]==s[s.length()-1]){
        int a=0,b=0;
        for(;;a++)if(s[a]!=s[a+1])break;
        for(int i=s.length()-1;;i--)if(s[i-1]!=s[i])break;else b++;
        a++;b++;
        //cout<<a<<" "<<b <<endl;
        ans-=(a/2+b/2-(a+b)/2)*(k-1);
    }
    cout<<ans<<endl;

    return 0; 
}


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

int main(){
  string s, t;
  cin >> s >> t;

  s = s + s;
  bool f = false;

  for(int i = 0; i < s.size() - t.size() + 1; i++){
    for(int j = 0; j < t.size(); j++){
      if(s[i + j] == t[j]){ f = true; }
      else if(s[i + j] != t[j]){
        f = false;
        break;  
        }
    }
    if(f){ break; }
  }
  if(f){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}


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

int main() {
  int n;cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  ll ans=0,cnt=0;
  rep(i,n){
     cnt=max(cnt,a[i]);
    ans+=cnt-a[i];
  }
  cout<<ans<<endl;
}

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

int main() {

int A,B;
cin >> A >> B;

if (A == 1 && B == 2) {
cout << 3 << endl;
}

if (A == 2 && B == 1) {
cout << 3 << endl;
}

if (A == 1 && B == 3) {
cout << 2 << endl;
}

if (A == 3 && B == 1) {
cout << 2 << endl;
}

if (A == 2 && B == 3) {
cout << 1 << endl;
}

if (A == 3 && B == 2) {
cout << 1 << endl;
}

}


Measured memory_bytes: 256
import math
#c = n! / (r! * (n - r)!)
def com(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, A, B=map(int,input().strip().split(' '))
v=list(map(int, input().strip().split(' ')))

v.sort(reverse=True)

anum=0
onum=0
for i in range(N):
    if v[i]==v[A-1]:
        anum+=1
    elif v[i]>v[A-1]:
        onum+=1
    if v[i]<v[A-1]:
        break
ans=0
if v[0]==v[A-1]:
    for i in range(A,min(B,anum)+1):
        ans+=com(anum,i)
#    print('aaa')
else:
    ans+=com(anum,A-onum)
    
print(sum(v[:A])/A)
print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> ans;
long long k, x, y;
bool swaped, x_fliped, y_fliped;
int type;
void out() {
  cout << ans.size() << endl;
  for (auto i : ans) cout << i.first << " " << i.second << '\n';
  exit(0);
}
void check_possibility() {
  if (k % 2 == 0 && (x + y) % 2 == 1) {
    cout << -1 << endl;
    exit(0);
  }
}
void restore() {
  if (swaped) for (auto& i : ans) swap(i.first, i.second);
  if (x_fliped) for (auto& i : ans) i.first *= -1;
  if (y_fliped) for (auto& i : ans) i.second *= -1;
}
void normalize() {
  if (x < 0) x *= -1, x_fliped = true;
  if (y < 0) y *= -1, y_fliped = true;
  if (x < y) swap(x, y), swaped = true;
}
long long get_steps() {
  if (k > x + y) {
    if ((x + y) % 2 == 0) {
      type = 1;
      return 2;
    } else {
      type = 3;
    }
  } else {
    long long res = (k + x + y - 1) / k;
    if ((k * res) % 2 != (x + y) % 2) res++;
    type = 1;
    return res;
  }
}
void build_1(long long steps) {
  long long extra = -(steps * k - x - y) / 2;
  //cerr << extra << endl;
  long long cur_x = 0, cur_y = 0;
  while (cur_y > extra) {
    long long dy = min(k, abs(extra - cur_y));
    long long dx = k - dy;
    cur_x += dx;
    cur_y -= dy;
    ans.emplace_back(cur_x, cur_y);
  }
  while (cur_x < x) {
    long long dx = min(k, abs(x - cur_x));
    long long dy = k - dx;
    cur_x += dx;
    cur_y += dy;
    ans.emplace_back(cur_x, cur_y);
  }
  while (cur_y < y) {
    long long dy = min(k, abs(y - cur_y));
    long long dx = k - dy;
    cur_x += dx;
    cur_y += dy;
    ans.emplace_back(cur_x, cur_y);
  }
}
void build_2() {
  ans.emplace_back(x, -(k - x));
  ans.emplace_back(x + (k + x - y) / 2, -(k - x) + k - (k + x - y) / 2);
  ans.emplace_back(x, y);
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> k >> x >> y;
  normalize();
  check_possibility(); 
  long long steps = get_steps();
  if (type == 1) build_1(steps);
  else build_2();
  //cerr << steps << " " << type << endl;
  restore();
  out();
  return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}

void deb_p(pii p) { printf("pair = %d %d\n", p.fi, p.se); }
void deb_i(int i) { printf("i = %d\n", i); }
void deb_v(vector<int> v) {
  printf("v = ");
  for (auto i : v) printf("%d ", i);
  printf("\n");
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int a, b;
  cin >> a >> b;
  out((a + b) % 24);
}
int main(void) { solve(); }

Measured memory_bytes: 3640
package main

import (
	"fmt"
)

func main() {
	var n,x,m int
  	fmt.Scan(&n,&x)
  	
  min := 1000;
  sum := 0;
  for i := 0; i < n; i++ {
    fmt.Scan(&m)
    //fmt.Println("m=",m)
    sum += m
    if min > m {
    	min = m
    }
  }
  x -= sum
  cnt := n
  cnt += x / min
  fmt.Println(cnt)
}

Measured memory_bytes: 512
import std.stdio, std.string,std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.container, std.datetime;

void main() {
  auto N = readln.chomp.to!int;
  auto a = readln.split.to!(long[]);
  auto po = a.sum.to!double / N;
  auto u = cast(int)po.ceil;
  auto v = cast(int)po.floor;
  auto pe = a.map!(a => (a - u)^^2).array.sum;
  auto pa = a.map!(a => (a - v)^^2).array.sum;
  writeln(min(pe, pa));
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    score = [0] * N
    for i in range(M):
        a = H[A[i] - 1]
        b = H[B[i] - 1]

        score[A[i] - 1] = max(score[A[i] - 1], b)
        score[B[i] - 1] = max(score[B[i] - 1], a)

    count = 0
    for i in range(N):
        if H[i] > score[i]:
            count += 1

    print(count)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, H, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 22820
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=200005,maxl=1000005;
struct node { node *dad,*son[26]; int cnt[26]; } tree[maxl],*root;
int n,cur=-1,len[maxn],cnt[26];
LL ans;
bool boo[26];
string S[maxn];
node *New(node *dad)
{
	cur++;
	tree[cur].dad=dad;
	return tree+cur;
}
int main()
{
	scanf("%d",&n);
	root=New(NULL);
	for (int i=1;i<=n;i++)
	{
		cin>>S[i];
		len[i]=S[i].size();
		node *u=root;
		for (int j=len[i]-1,num;j>=0;j--)
		{
			num=S[i][j]-97;
			if (!u->son[num]) u->son[num]=New(u);
			u=u->son[num];
		}
		for (int j=0;j<26;j++) cnt[j]=boo[j]=0;
		for (int j=0,num;j<len[i];j++)
		{
			num=S[i][j]-97;
			if (!boo[num]) cnt[num]++,boo[num]=true;
			for (int k=0;k<26;k++) u->cnt[k]+=cnt[k];
			u=u->dad;
		}
		for (int k=0;k<26;k++) u->cnt[k]+=cnt[k];
	}
	for (int i=1;i<=n;i++)
	{
		node *u=root;
		for (int j=len[i]-1;j>=1;j--) u=u->son[S[i][j]-97];
		for (int j=0,num=S[i][0]-97;j<26;j++)
			if (u->son[j]) ans+=u->son[j]->cnt[num];
	}
	printf("%lld\n",ans-n);
	return 0;
}


Measured memory_bytes: 323452
#include<bits/stdc++.h>
#include<vector>
#define ll long long
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-6;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
const ll mod=1e9+7;
#define maxn 300005
int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll cc=a+b;
	ll v=n/cc;
	v*=a;
	ll ccc=n%cc;
	v+=min(ccc,a);
	cout<<v<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  int m = n;
  int sum = 0;
  while(m != 0){
    sum += m%10;
    m/= 10;
  }
  if(n%sum) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let L = v[1];
	let mut s:Vec<String> = Vec::new();
	for i in 0..n {
		let mut buf = String::new();
		io::stdin().read_line(&mut buf).expect("");
		s.push(buf.trim().to_string());
	}
	s.sort();
	for st in s {
		print!("{}", st);
	}
	println!("");
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 300500;

bool ok[N];
int n, p[N], pos[N];

inline void no() {
	cout << "No";
	exit(0);
}

inline void check(int l, int r) {
	int last1 = 0, last2 = 0;
	for (int i = l; i <= r; i += 2) {
		if (p[i] < l || r < p[i])
			no();
		if (pos[p[i]] < p[i]) {
			if (last1 >= p[i])
				no();
			last1 = p[i];
		}
		else {
			if (last2 >= p[i])
				no();
			last2 = p[i];
		}
	}
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> p[i];
		ok[i] = (p[i] == i);
		pos[p[i]] = i;
	}

	for (int i = 1; i <= n; i++) {
		if (ok[i]) continue;
		int j = i;
		while (j + 2 <= n && ok[j + 1] && !ok[j + 2])
			j += 2;
		if (i == j)
			no();
		check(i, j);
		i = j;
	}

	cout << "Yes";
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
 
int main(){
int A,B,C;
cin>>A>>B>>C;
if(A==B){
    cout<<C<<endl;
}
else if(A==C){
    cout<<B<<endl;
}
else{
    cout<<A<<endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, D, X;
  cin >> N >> D >> X;
  int SUM = 0;
  rep(i, N) {
    int A;
    cin >> A;
    SUM += ((D - 1) / A) + 1;
  }
  cout << X + SUM << endl;
  return 0;
}

Measured memory_bytes: 3648
package main

import "fmt"

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)
	ss := make([]string, n)
	for i := range ss {
		fmt.Scan(&ss[i])
	}

	cnt_ab := 0
	for _, s := range ss {
		for i := 0; i < len(s)-1; i++ {
			if s[i:i+2] == "AB" {
				cnt_ab++
			}
		}
	}

	cnt_last_a := 0
	for _, s := range ss {
		if s[len(s)-1] == 'A' {
			cnt_last_a++
		}
	}

	cnt_first_b := 0
	for _, s := range ss {
		if s[0] == 'B' {
			cnt_first_b++
		}
	}

	cnt_first_b_and_last_a := 0
	for _, s := range ss {
		if s[len(s)-1] == 'A' && s[0] == 'B' {
			cnt_first_b_and_last_a++
		}
	}

	ans := cnt_ab
	if cnt_first_b_and_last_a > 0 {
		ans += cnt_first_b_and_last_a - 1
		cnt_first_b -= cnt_first_b_and_last_a
		cnt_last_a -= cnt_first_b_and_last_a
		if cnt_last_a > 0 {
			ans++
			cnt_last_a--
		}
		if cnt_first_b > 0 {
			ans++
			cnt_first_b--
		}
		ans += min(cnt_first_b, cnt_last_a)
	} else {
		ans += min(cnt_first_b, cnt_last_a)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
    int a,b;
    cin>>a>>b;
    if(a<=5) cout<<0<<endl;
    else if(a<=12) cout<<b/2<<endl;
    else cout<<b<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    ll a,b;
    scanf("%lld%lld", &a, &b);

    if(a%b==0) {
        printf("-1\n");
    }
    else {
        printf("%lld\n", a);
    }
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0; i < 3; i++) 
    if(S.at(i) == 'o')
      count++;
  cout << 700 + 100 * count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i, n) {
        if (a[i] % 2 == 1 && i % 2 == 0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3588
#include<stdio.h>
void swap (int *x,int *y){
  int t;
  t = *x;
  *x = *y;
  *y = t;
}
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a > b) swap(&a,&b);
  if(a > c) swap(&a,&c);
  if(b > c) swap(&b,&c);

  printf("%d",c - a);

  return 0;
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl;

const double pi = 3.14159;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	
	int ref[n+1] = { 0 };
	int x;
	for(int i=0 ; i<n-1 ; ++i){
		cin >> x;
		ref[x]++;
	}
	
	for(int i=1 ; i<=n ; ++i)cout << ref[i] << endl;
}


Measured memory_bytes: 4436
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int mn=100100100;
    int ans=0;
    for(int i=0;i<n;i++){
        if(p[i]<mn){
            ++ans;
            mn=p[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 
#include <atcoder/all>

typedef long long ll;
typedef unsigned long long ull;
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;
using namespace atcoder;

void solve()
{
    int n, m;
    scanf("%d%d", &n, &m);
    dsu d(n);
    int i;
    for (i = 0; i < m; i++) {
        int a, b;
        scanf("%d%d", &a, &b); a--; b--;
        d.merge(a, b);
    }
    vector<vector<int>> g=d.groups();
    printf("%d\n", (int)g.size()-1);

    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 9100
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    ll n,mm;
    std::cin >> n>>mm;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    UnionFind uf(n);
    
    for (int i = 0; i < mm; i++) {
        ll x,y;
        std::cin >> x>>y;
        
        uf.merge(x,y);
    }
    map<ll,priority_queue<ll,vector<ll>,greater<ll>>> m;
    for (int i = 0; i < n; i++) {
        m[uf.root(i)].push(a[i]);
    }
    ll size = m.size();
    if(size==1){
        std::cout << 0 << std::endl;
        return 0;
    }
    if( (size-1)*2 >n  ){
        std::cout << "Impossible" << std::endl;
        return 0;
    }
    
    ll ans = 0;
    priority_queue<ll,vector<ll>,greater<ll>> rem;
    for (auto e : m) {
        ans += e.second.top();
        e.second.pop();
        while(!e.second.empty()){
            rem.push(e.second.top());
            e.second.pop();
        }
    }
    for (int i = 0; i < size-2; i++) {
        ans += rem.top();rem.pop();
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 12416
n = int(input())
X = list(map(float,input().split()))
Y = list(map(float,input().split()))
D = [abs(X[i]-Y[i]) for i in range(len(X))]
print(sum(D))
print((sum([ele**2 for ele in D]))**(1/2))
print((sum([ele**3 for ele in D]))**(1/3))
print(max(D))


Measured memory_bytes: 5672
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}


int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0; i<N; i++) cin >> S[i];

  bool ans = true;
  map<string, int> mp;
  mp[S[0]]++;
  for(int i=1; i<N; i++){
    if(mp[S[i]] != 0) ans = false;
    if(S[i-1].back() != S[i][0]) ans = false;
    mp[S[i]]++;
  }

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

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

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const int mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	//sort(a.begin(),a.end());
	int x, y, z;
	cin >> x >> y >> z;
	int a;
	a = x; x = y; y = a;
	a = x; x = z; z = a;
	cout << x << " " << y << " " << z;
	return 0; 
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string sa,sb,sc;
    cin>>sa>>sb>>sc;
    auto itr_a=sa.begin();
    auto itr_b=sb.begin();
    auto itr_c=sc.begin();
    auto now=itr_a;
    int flag_b=0;
    int flag_c=0;
    while (itr_a!=sa.end()&&itr_b!=sb.end()&&itr_c!=sc.end()) {
        if (*now=='a') {
            itr_a++;
            now=itr_a;
        } else if (*now=='b') {
            if (flag_b==0) {
                now=itr_b;
                flag_b=1;
            } else {
                itr_b++;
                now=itr_b;
            }
        } else {
            if (flag_c==0) {
                now=itr_c;
                flag_c=1;
            } else {
                itr_c++;
                now=itr_c;
            }
        }
    }
    if (itr_a==sa.end()) {
        cout<<"A"<<endl;
    } else if (itr_b==sb.end()) {
        cout<<"B"<<endl;
    } else {
        cout<<"C"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

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

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

int main(void) {
    int n, m;
    string s, t;
    cin >> n >> m >> s >> t;

    ll l = lcm(n, m);

    ll nn = l/n, mm = l/m;
    ll d = lcm(nn, mm);

    ll li = 0;
    while(li < l) {
        // cout << s[li/nn] << "  " << t[li/mm] << endl;
        if(s[li/nn] != t[li/mm]) {
            cout << -1 << endl;
            return 0;
        }
        li += d;
    }
    cout << l << endl;
}



Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
    char S[3];
    scanf("%c%c%c%c",&S[0],&S[1],&S[2],&S[3]);
    int x = 0;
    for(int i = 0;i<4;i++) {
        if(S[i] == '+') {
            x++;
        } else if(S[i] == '-') {
            x--;
        }
    }
    printf("%d\n ",x);

}

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

using namespace std;

long long root(long long x, vector<long long>& par) {
	if (par[x] < 0) return x;
	return par[x] = root(par[x], par);
}

long long size(long long x, vector<long long>& par) {
	return -par[root(x, par)];
}

int main() {
	long long N, M;
	cin >> N >> M;
	vector<pair<long long, long long>> E(M);
	for (long long i = 0; i < M; i++) cin >> E[i].first >> E[i].second;
	vector<long long> Ans(M);
	vector<long long> par(N, -1);
	Ans[M - 1] = N * (N - 1) / 2;
	for (long long i = M - 1; i >= 1; i--) {
		long long a = E[i].first, b = E[i].second;
		Ans[i - 1] = Ans[i];
		long long ra = root(a - 1, par);
		long long rb = root(b - 1, par);
		if (ra != rb) {
			Ans[i - 1] -= size(a - 1, par) * size(b - 1, par);
			par[rb] += par[ra];
			par[ra] = rb;
		}
	}
	for (long long a : Ans) cout << a << endl;
}


Measured memory_bytes: 6376
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    vec[i] = s[i] - 'a';
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    bitset<26> a, b, c;
    for (int j = 0; j <= i; j++) {
      a.set(vec[j]);
    }
    for (int j = i+1; j < n; j++) {
      b.set(vec[j]);
    }
    c = a&b;
    int m = c.count();
    ans = max(ans, m);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rgi register int
using namespace std;
string a;
int k,book=-2147483;
int main()
{
	ios::sync_with_stdio(false);
	cin>>a;
	int len=a.length();
	for(rgi i=0;i<len;++i)
	{
		if(a[i]==a[i+1]&&book<i-2)
		{
			book=i,++i;
			//cout<<i<<" ";
		}
		++k;
	}
	cout<<k<<endl;
	return 0;
}

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

int main(){
    long L,R;cin>>L>>R;
    if(R-L>=2019){
        cout<<0<<endl;
        return 0;
    }
    long mini=2020;
    for(long i=L;i<=R;i++){
        for(long j=i+1;j<=R;j++){
            mini=min(mini,((i%2019)*(j%2019))%2019);
        }
    }
    cout<<mini<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define all(arr) (arr).begin(), (arr).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1ll << 59;
constexpr ll MOD = 1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

/*<ここから>***********************************************************/

template <typename T>
const int binarySearch(vector<T> arr, const int first, const int last, T val) {
	if (first >= last) return first;
	const int ptr = first + (last - first) / 2;
	if (arr[ptr] == val) return ptr;
	if (val < arr[ptr]) return binarySearch(arr, first, ptr, val);
	else return binarySearch(arr, ptr + 1, last, val);
}

int main()
{
	int N;
	cin >> N;
	vi A(N), B(N), C(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	rep(i, N) cin >> C[i];

	sort(all(A));
	sort(all(B));
	sort(all(C));

	ll ans = 0;
	rep(i, N) {
		ll a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
		ll c = N - (upper_bound(C.begin(), C.end(), B[i]) - C.begin());
		ans += a * c;
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// --------------------------------------------------------------------------

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // vector<int> era(10'000'000,0);
  // era[0] = era[1] = 1;
  // for(int i=2; i<10'000'000; i++){
  //   if(era[i] == 0){
  //     for(int j=i+i; j<10'000'000; j+=i){
  //       era[j] = 1;
  //     }
  //   }
  // }
  // vector<int> prime;
  // for(int i=2; i<1'000'000; i++){
  //   if(era[i] == 0){
  //     prime.emplace_back(i);
  //   }
  // }
  // for(int i=0; i<5; i++) cout << prime[i] << "\n";
  // cout << prime.size() << "\n";
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i=0; i<N; i++) cin >> A[i];
  vector<int> cnt(1100100,0);
  bool can = true;
  for(int i=0; i<N; i++){
    for(ll j=1; j*j<=A[i]; j++){
      if(A[i]%j == 0){
        if(j != 1){
          cnt[j]++;
        }
        if(cnt[j]>=2){
          can = false;
          break;
        }
        if(A[i]/j != j && A[i]/j != 1){
          cnt[A[i]/j]++;
          if(cnt[A[i]/j]>=2){
            can = false;
            break;
          }
        }
      }
    }
    if(!can) break;
  }
  if(can){
    cout << "pairwise coprime" << "\n";
    return 0;
  }
  int now = A[0];
  for(int i=1; i<N; i++){
    now = gcd(now,A[i]);
  }
  if(now == 1){
    cout << "setwise coprime\n";
  }else{
    cout << "not coprime\n";
  }
  return 0;
}


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

int main ( ) {
    int N;
    cin >> N;
    
    if (N%1110<10 || N%1000%111==0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
    


Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
#include<sstream>
using namespace std;
typedef long long ll;

struct Data
{
	int score, num;
	bool operator < (const Data a) const
	{
		return (score == a.score) ? num < a.num : score > a.score;
	}
};

int main(){
	int M;
	while(cin >> M, M)
	{
		Data s[40];
		for(int i = 0; i < M; i++)
		{
			cin >> s[i].num;
			s[i].score = 0;
			queue<int> latte;

			for(int j = 1; j <= 10; j++)
			{
				int pin[2] = {};
				for(int k = 0; k < 2; k++)
				{
					cin >> pin[k];
					int size = latte.size();
					for(int l = 0; l < size; l++)
					{
						if(latte.front() == 2) latte.push(1);
						latte.pop();
						s[i].score += pin[k];
					}
					if(j < 10 && pin[k] == 10) break;
				}
				s[i].score += pin[0] + pin[1];
				if(j == 10 && pin[0] + pin[1] >= 10)
				{
					cin >> pin[0];
					s[i].score += pin[0];
				}
				if(j == 10) break;
				if(pin[0] == 10) latte.push(2);
				else if(pin[0] + pin[1] == 10) latte.push(1);
			}
		}
		sort(s, s + M);
		for(int i = 0; i < M; i++)
		{
			printf("%d %d\n", s[i].num, s[i].score);
		}
	}
	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;


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

    ll n;
    cin>>n;
    pll vector[n];
    for(ll i=0;i<n;i++)
    {
        cin>>vector[i].first>>vector[i].second;
    }
    ll val;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            if(atan2(vector[i].first,vector[i].second)>atan2(vector[j].first,vector[j].second))
            {
                swap(vector[i],vector[j]);
            }
        }
    }
    double res=0.0000;
    double store;
    double xsum,ysum;
    ll curridx;
    for(ll len=1;len<=n;len++)
    {
        for(ll j=0;j<n;j++)
        {
            xsum=0;
            ysum=0;
            curridx=j;
            for(ll k=0;k<len;k++)
            {
                xsum+=vector[curridx].first;
                ysum+=vector[curridx].second;
                curridx=(curridx+1);
                if(curridx>=n)
                {
                    curridx-=n;
                }
            }
            store=double(xsum*xsum);
            store+=(double)(ysum*ysum);
            store=sqrt(store);
            if(res<=store)
            {
                res=store;
            }
        }
    }
    cout<<fixed<<setprecision(12)<<res;
    return 0;
}

Measured memory_bytes: 512
from math import ceil
from itertools import permutations


def main():
    length = int(input())
    numbers = [int(input()) for _ in range(length)]
    numbers.sort()
    number_pair = []
    for i in range(ceil(length / 2) - 1):
        number_pair.append([numbers[i], numbers[-i - 1]])
    number_pair.sort(key=lambda x: x[1])
    side = [numbers[length // 2]]
    if length % 2 == 0:
        side.append(numbers[length // 2 - 1])
    else:
        side.append(-1)
    answer = 0
    if 2 < length:
        for left_side, right_side in permutations(side):
            large_first = 0
            small_first = 0
            for i in range(len(number_pair)):
                if i == 0 and left_side != -1:
                    large_first += abs(left_side - number_pair[i][1])
                    small_first += abs(left_side - number_pair[i][0])
                if i == len(number_pair) - 1 and right_side != -1:
                    large_first += abs(right_side - number_pair[i][0])
                    small_first += abs(right_side - number_pair[i][1])
                if 0 < i:
                    large_first += abs(number_pair[i][1] - number_pair[i - 1][0])
                    small_first += abs(number_pair[i][0] - number_pair[i - 1][1])
                large_first += abs(number_pair[i][0] - number_pair[i][1])
                small_first += abs(number_pair[i][0] - number_pair[i][1])
            answer = max(answer, large_first, small_first)
    else:
        answer = abs(numbers[0] - numbers[1])
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 13032
n = int(input())
a = sorted(list(map(int, input().split())))
MA = (max(a) + 1)
ans = [0] * MA

for i in range(n):
    for j in range(a[i],MA,a[i]):
        ans[j] += 1
print(sum(ans[i]==1 for i in a))

Measured memory_bytes: 117208
#include<bits/stdc++.h>
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define pb(a) push_back(a)
#define bigPrime 1000000007
using namespace std;

int main()
{   
    fip;   
    ll n,l,i,sum=0,a;
    cin>>n>>l;
    if(l>=0)
    {
        a=l;
        reptUsual(n-1)
        {            
            sum+=(++a);
        }
    }
    else
    {
        a=l;
        if((n+l)>0)
        {
            reptUsual(n)
            {
                sum+=(a++);
            }
        }
        else
        {
            reptUsual(n-1)
            {
                sum+=(a++);
            }
        }
    }
    cout<<sum;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int a, b, h;
  cin >> a >> b >> h;
  int ans = (a + b) * h / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
    int n,t,x,y;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&t,&x,&y);
        if(x+y>t)//不用绕，使出吃奶的劲儿都到不了
        {
            printf("No\n");
            return 0;
        }
        if((x+y)%2==0&&t%2==1)//如果最优路径与时间的积偶不一，一定到不了
        {
            printf("No\n");
            return 0;
        }
        if((x+y)%2==1&&t%2==0)//同理
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");//因为如果No就都return 0了，所以剩下一定是Yes。
    return 0;
}


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

#define fi first
#define se second

const int N = 200100;

using namespace std;

int n;
long long a[N];
vector < int > v[N];

void dfs(int x, int p)
{
        if(v[x].size() == 1){
                return;
        }
        long long X = 0, mx = 0;
        for(int y: v[x]){
                if(y == p){
                        continue;
                }
                dfs(y, x);
                X += a[y];
                mx = max(mx, a[y]);
        }
        long long A = 2 * a[x] - X;
        if(A < 0 || A > X || (X - A) % 2 || X - mx < (X - A) / 2){
                cout << "NO" << "\n";
                exit(0);
        }
        a[x] = A;
}

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = 1, x, y; i < n; i++){
                cin >> x >> y;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        if(n == 2){
                cout << (a[1] == a[2] ? "YES" : "NO") << "\n";
                return 0;
        }
        int r = 1;
        while(v[r].size() == 1){
                r += 1;
        }
        dfs(r, r);
        if(a[r]){
                cout << "NO" << "\n";
                return 0;
        }

        cout << "YES" << "\n";
}


Measured memory_bytes: 16256