akhauriyash/Code-Regression huggingface dataset:
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;



public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		TreeMap<Integer, Integer> map = new TreeMap<>();
		for (int i=0;i<n;i++) {
			int a = sc.nextInt();
			int x = map.containsKey(a) ? map.get(a) : 0;

			map.put(a, x+1);
		}

		for (int i=0;i<m;i++) {
			int b = sc.nextInt();
			int c = sc.nextInt();

			int pos = map.firstKey();
			while (b>0 && pos<c) {
				int d = map.get(pos);
				if (b>=d) {
					
					map.remove(pos);
					int x = map.containsKey(c) ? map.get(c) : 0;
					map.put(c, x+d);
					pos=map.higherKey(pos);
					b-=d;
				} else {
					
					map.put(pos, d-b);
					int x = map.containsKey(c) ? map.get(c) : 0;
					map.put(c, x+b);
					
					b=0;
				}
			}
		}
		
		long ans = 0;
		
		for (Map.Entry<Integer, Integer> e : map.entrySet()) {
			ans += (long)e.getKey() * (long)e.getValue();
		}

		System.out.println(ans);
	}
}






Measured memory_bytes: 102180
#include <iostream>
using namespace std;
int main(){

int i,x,n;
cin>>n;

for(i=1; i<=n; i++){
x=i;

if(x%3==0){
cout<<" "<<i;
continue;
}

while(x!=0){
if(x%10==3){
cout<<" "<<i;
break;
}
x/=10;
}

}
cout<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define ll long long
#define lf double
#define E complex<lf>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pa pair<int,int>
#define pb push_back
#define ms(x,y) memset(x,y,sizeof(x))
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mod 1000000007
#define N 100010
using namespace std;
inline ll read() {
	ll x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int n,a[N];
int main() {
	n=read();
	for (int i=1; i<=n; i++) a[i]=read();
	int ans=0;
	for (int i=1; i<=n; i++) {
		if (a[i]==i) {
			ans++;
			if (a[i+1]==i+1) i++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}
long long a[100005] = {0};

int main(void){
    long long n, k;
    long long ai, b;
    long long cnt = 0;
    scanf("%lld %lld", &n, &k);
    for (int i = 0; i < n; i++){
        scanf("%lld %lld", &ai, &b);
        a[ai] += b;
    }

    for (int i = 1; i <= 100000; i++){
        cnt += a[i];
        if (cnt >= k){
            printf("%d\n", i);
            return 0;
        }
    }

    return 0;

}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

typedef long long ll;
int d[100001];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL);
	int n; cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		ll x; cin >> x; d[x] += 1;
		sum += x;
	}
	int q; cin >> q;
	while (q--) {
		int a, b; cin >> a >> b;
		sum -= (ll)d[a] * a;
		sum += (ll)d[a] * b;
		d[b] += d[a];
		d[a] = 0;
		cout << sum << '\n';
	}







}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define rep(i,x) for(int i=0; i<(int) (x); i++)
#define PI 3.14159265359
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> d;
	d.resize(k);
	set<int> a;
	int x;
	rep(i,k)
	{
		cin >> d[i];
		rep(j,d[i])
		{
			cin >> x;
			a.insert(x);
		}
	}
	cout << n-a.size();

	//////////////////////////////////
	//--------end--------
	//
	return 0;
}


Measured memory_bytes: 3632
let MOD = 1000000007L

let modadd (x : int64) (y : int64) = (x + y) % MOD

let modsub (x : int64) (y : int64) = (x + MOD - y) % MOD

let modmul (x : int64) (y : int64) = ((x % MOD) * (y % MOD)) % MOD

let modpow2 (x : int64) = x * x

let rec modpow (x : int64) (y : int64) =
    if y = 0L then 1L
    elif y = 1L then x % MOD
    elif y % 2L = 0L then modpow2 (modpow x (y / 2L)) % MOD
    else modmul x (modpow2 (modpow x (y / 2L))) % MOD

let N = stdin.ReadLine() |> int64

modadd (modsub (modsub (modpow 10L N) (modpow 9L N)) (modpow 9L N)) (modpow 8L N) |> stdout.WriteLine

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

int main()
{
  string S;
  cin >> S;
  int64_t N = S.size();
  int64_t ans = N * (N - 1) / 2 + 1;
  map<char, int64_t> mp;
  for (int i = 0; i < N; i++)
  {
    mp[S.at(i)]++;
  }
  for (auto it = mp.begin(); it != mp.end(); it++)
  {
    ans -= (it->second) * ((it->second) - 1) / 2;
  }
  cout << ans << endl;
}

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

int main(){
  string s;
  cin >> s;
  int c=0,d=0;
  for(int i=0,l=s.size();i<l;i++){
    if((i%2==0&&s.at(i)!='0')||(i%2==1&&s.at(i)!='1'))
      c++;
    if((i%2==0&&s.at(i)!='1')||(i%2==1&&s.at(i)!='0'))
      d++;
  }
  cout << min(c,d) << endl;
  return 0;
}

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

using namespace std;

long calc_gcd(long num1, long num2) {
  long greater = max(num1, num2);
  long less = min(num1, num2);
  long remainder = greater % less;

  if(remainder == 0) {
    return less;
  }

  return calc_gcd(less, remainder);
}


int main() {
  long num1, num2;

  while(cin >> num1 >> num2) {
    long gcd = calc_gcd(num1, num2);

    cout << gcd << ' ' << num1 * num2 /gcd << endl;
  }
}


Measured memory_bytes: 3104
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#define f first
#define s second
#define fore(i,a,b) for(lli i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
#define deb(x) cout << #x": " << (x) << endl;

int main(){ _
    lli n,x,t;
    cin >> n >> x >> t;
    lli aprox=0;
    lli time=0;
    for(aprox=0; aprox<n; aprox+=x)
    {
      time+=t;
    }
    cout << time <<ENDL;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;


int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n, a, b; cin >> n >> a >> b;
    cout << ((b-a)%2 == 0 ? "Alice":"Borys");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string x="Possible\n",y="Impossible\n";
int main() {
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)
    cout<<x;
    else cout<<y;
    return 0;
}

Measured memory_bytes: 256
n, x, y = int(input()), list(map(int, input().split())), list(map(int, input().split()))
d = tuple(map(lambda x, y:abs(x - y), x, y))
print(sum(d))
print(sum(map(pow, d, [2]*n))**0.5)
print(sum(map(pow, d, [3]*n))**(1/3))
print(max(d))

Measured memory_bytes: 7808
function Main(input) {
  input = input.trim()
  input = input.split(" ");
  if(hoge(input[1])==hoge(input[0])){
  console.log("Yes")
  }else{
  console.log("No")
  }
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));
function hoge(n){
if(n==1||n==3|n==5||n==7||n==8||n==10||n==12) return 1;
  else if(n==2) return 3;
  else return 2;
}


Measured memory_bytes: 11468
#include<stdio.h>
#include<stdlib.h>
 
#define NMAX 2000001
 
int n;
int A[NMAX],B[NMAX],C[NMAX];
 
void CountingSort(int k);
 
int main(void){
  int i,k;
 
  scanf("%d",&n);
 
  k=0;
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
    if(k <= A[i]) k=A[i];
  }
 
  CountingSort(k);
 
  for(i=0; i<n; i++){
    if(i==n-1) printf("%d\n",B[i]);
    else printf("%d ",B[i]);
    }
 
  return 0;
}
 
void CountingSort(int k){
  int i,j;
 
  for(i=0; i<=k; i++) C[i]=0;
 
  for(j=0; j<n; j++)C[A[j]]=C[A[j]]+1;
 
  for(i=1; i<=k; i++) C[i]+=C[i-1];
 
  for(j=n-1; j>=0; j--){
    B[C[A[j]]-1] = A[j];
    C[A[j]] = C[A[j]]-1;
  }
 
}

Measured memory_bytes: 17892
#include<stdio.h>
#include<string.h>
#define A 100005

typedef struct p{
    char name[100];
    int t;
}P;

P Q[A];
int a,b,c;

void enqueue(P x){
    Q[b]=x;
    b=(b+1)%A;
}

P dequeue(){
    P x=Q[a];
    a=(a+1)%A;
    return  x;
}

int min(int d,int e){return d<e ? d:e;}

int main(){
    int f=0,g;
    int i,j;
    P u;
    scanf("%d %d",&c,&j);
    
    for(i=1;i<=c;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
}
a=1;
b=c+1;

while(a!=b){
    u = dequeue();
    g=min(j,u.t);
    u.t-=g;
    f+=g;
    if(u.t>0)enqueue(u);
    else{
        printf("%s %d\n" ,u.name,f);
    }
}
return 0;
}


Measured memory_bytes: 11884
import math
N = int(input()) - 1
CSF = [list(map(int, input().split())) for _ in range(N)]

def station(time, i):
    if i == N:
        print(time)
        return
    c, s, f = CSF[i]
    nextTime = s + c if time <= s else math.ceil(time / f) * f + c
    station(nextTime, i+1)

for i in range(N):
    station(0, i)
print(0)

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define en '\n'
#define fs first
#define sd second

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, m;
    cin >> n >> m;
    ll x;
    cin >> x;
    vector<vector<ll>> b(n, vector<ll> (m+1));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m+1; ++j){
            cin >> b[i][j];
        }
    }
    ll res = INT64_MAX;
    for(ll k = 0; k < (1ll<<n) ; ++k){
        vector<ll> sb(m+1, 0);
        for(int i = 0; i < n; ++i){
            if(k&(1ll<<i)){
                for(int j = 0; j < m+1; ++j){
                    sb[j] += b[i][j];
                }
            }
        }
        bool st = true;
        for(int i = 1; i < m+1 and st; ++i){
            if(sb[i] < x){
                st = false;
            }
        }
        if(st) { res = min(res, sb[0]);}
    }
    cout << (res == INT64_MAX ? -1 : res) << en;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    lint n;std::cin>>n;
    lint T=0,X=0,Y=0;
    while(n--){
        lint t,x,y;std::cin>>t>>x>>y;
        lint d=std::abs(X-x)+std::abs(Y-y);
        if((t-T)%2!=d%2||t-T<d){
            std::cout<<"No"<<'\n';
            return 0;
        }
        T=t,X=x,Y=y;
    }
    std::cout<<"Yes"<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 2;

int n, x;
LL a[N];
LL ans;

int main()
{
	//File("");
	n = gi <int> (), x = gi <int> ();
	for (int i = 1; i <= n; i+=1) a[i] = gi <LL> ();
	if (a[1] > x) ans += a[1] - x, a[1] = x;
	for (int i = 2; i <= n; i+=1)
	{
		if (a[i] + a[i - 1] <= x) continue;
		ans += a[i] + a[i - 1] - x, a[i] = x - a[i - 1];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4580
while True:
    w, h = map(int, input().split())
    if w == 0: break
    goal = (w,h)
    vart = []
    hori = []
    for i in range(2*h-1):
        if i % 2 == 0:
            vart.append(list(map(int, input().split())))
        else:
            hori.append(list(map(int, input().split())))
    node = [[0 for i in range(h)] for i in range(w)]
    queue = [(0,0)]
    while queue:
        p = queue.pop(0)
        x, y = p[0], p[1]
        node[x][y] += 1
        if y-1 >= 0 and hori[y-1][x] == 0 and node[x][y-1] == 0:
            node[x][y-1] = node[x][y]
            queue.append((x,y-1))
        if y+1 < h and hori[y][x] == 0 and node[x][y+1] == 0:
            node[x][y+1] = node[x][y]
            queue.append((x,y+1))
        if x-1 >= 0 and vart[y][x-1] == 0 and node[x-1][y] == 0:
            node[x-1][y] = node[x][y]
            queue.append((x-1,y))
        if x+1 < w and vart[y][x] == 0 and node[x+1][y] == 0:
            node[x+1][y] = node[x][y]
            queue.append((x+1,y))
    print(node[goal[0]-1][goal[1]-1])

Measured memory_bytes: 6792
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, P[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> P[i];

	int mi = inf;
	int ans = 0;
	rep(i, 0, N) {
		chmin(mi, P[i]);
		if (mi == P[i]) ans++;
	}
	cout << ans << endl;
}







Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
int count2=0,flag=0,v=0,count=0;
string s;
cin>>s;
for(int i=0;i<s.length();i++){
    if(count2>1){
        flag++;
        break;
    }
    if(s[0]!='A'){
        flag++;
        break;
    }
    if(s[i]=='C'&&i!=1&&i!=s.length()){
        count2++;
        v=i;
    }
    if(s[1]=='C'||s[s.length()-1]=='C'){
        flag++;
        break;
    }
    if(islower(s[i])&&i!=0&&i!=v){
        count++;

    }
}

if(flag==0&&count==s.length()-2&&count2==1){
    cout<<"AC";
}
else{ cout<<"WA";}
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
data = [[] for _ in range(n)]
for i in range(m):
    p, y = map(int, input().split())
    data[p - 1].append([y, i])

ans = [None] * m
for i in  range(n):
    data[i].sort()
    for j in range(len(data[i])):
        y, k = data[i][j]
        ans[k] = '0' * (6 - len(str(i + 1))) + str(i + 1) + '0' * (6 - len(str(j + 1))) + str(j + 1)

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 39088
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007

using namespace std;

int main()
{
    IOS
    int n;
    cin>>n;
    cout<<(n-2)*180<<"\n";
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"math/big"
)

func main() {
	solve()
}

func solve() {
	var n, d int
	fmt.Scan(&n)
	sum := 0
	res := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&d)
		sum += d
		res -= d * d
	}
	res += sum * sum
	fmt.Print(res / 2)
}

func max(x int, y ...int) int {
	res := float64(x)
	for _, z := range y {
		res = math.Max(res, float64(z))
	}
	return int(res)
}

func min(x int, y ...int) int {
	res := float64(x)
	for _, z := range y {
		res = math.Min(res, float64(z))
	}
	return int(res)
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

func sqrt(x int) int {
	return int(math.Sqrt(float64(x)))
}

func int2Int(x int) big.Int {
	var res big.Int
	res.SetInt64(int64(x))
	return res
}


Measured memory_bytes: 640
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!.map { it.toChar() } as MutableList
    var count = 0

    for ((s1, s2) in s.subList(0, n-1).zip(s.subList(1, n))) {
        if (s1 == 'R' && s2 == 'L' && s[0] == 'L') {
            count += 1
        }

        if (s1 == 'L' && s2 == 'R' && s[0] == 'R') {
            count += 1
        }
    }

    if (s[0] == s[n-1]) {
        println(
                when {
                    (k >= count) -> n - 1
                    else -> n - 1 - (2 * (count - k))
                }
        )
    } else {
        println(
                when {
                    (k - 1 >= count) -> n - 1
                    else -> n - 2 - (2 * (count - k))
                }
        )
    }
}

Measured memory_bytes: 42556
import sys

rl = sys.stdin.readline


def solve():
    _ = int(rl())
    a = list(map(int, rl().split()))
    
    ans = 10 ** 10
    for i in range(-100, 101):
        tmp = 0
        for ai in a:
            tmp += (ai - i) ** 2
        ans = min(ans, tmp)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif
#define mp make_pair

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


ll dp[110][2];

int main(){
	int n;
	cin >> n;
	vector<string> s(2);
	rep(i, 2) cin >> s[i];
	if(n == 1) {
		cout << 3 << endl;
		return 0;
	}
	int idx;
	if(s[0][0] != s[1][0]) {
		dp[1][1] = 6LL;
		idx = 2;
	}
	else {
		dp[0][0] = 3LL;
		idx = 1;
	}
	REP(i, idx, n) {
		if(s[1][i] == s[0][i]) {
			dp[i][0] = (dp[i-1][1] + dp[i-1][0]*2LL) %MOD;
		}
		else {
			dp[i+1][1] = (dp[i-1][0]*2LL + dp[i-1][1]*3LL) % MOD;
			i++;
		}
	}
	
	if(s[0][n-1] == s[1][n-1]) {
		cout << dp[n-1][0] << endl;
	}
	else {
		cout << dp[n-1][1] << endl;
	}
	
}


Measured memory_bytes: 256
n = int(input())

d = [10 * [0] for _ in range(10)]

ans = 0
for i in range(1, n+1):
    s = str(i)
    if s[0] == "0" or s[-1] == "0": continue
    d[int(s[0])][int(s[-1])] += 1

for i in range(1, 10):
    for j in range(1, 10):
        ans += d[i][j] * d[j][i]
                  
print(ans)


Measured memory_bytes: 40428
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean happy = false;
		int breaking = 0;
		int next = 1;

		for(int i=0; i<N; i++){
			int a = sc.nextInt();
			if(a==next){
				next++;
				happy = true;
			}else{
				breaking++;
			}
		}
		if(happy==true){
			System.out.println(breaking);
		}else{
			System.out.println("-1");
		}
    }
}


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

signed main(void)
{
	int a, b, x;
	cin >> a >> b >> x;
	if (x >= a && x <= a + b) 
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}


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

struct Point{int x, y;};

class Cube{
    public:
    char C[3];
    Cube(){ C[0] = 'W'; C[1] = 'R'; C[2] = 'B';}
    void setEmpty(){ C[0] = 'E';}
    void rotate(int d){
        if ( d % 2 == 0 ) swap(C[0], C[2]);
        else swap(C[0], C[1]);
    }
};

char target[3][3];

class Puzzle{
    public:
    Cube cubes[3][3];
    Point empty;
    int manhattanDist;
     
    Puzzle(){
        for ( int y = 0; y < 3; y++ ){
            for ( int x = 0; x < 3; x++ ) cubes[y][x] = Cube();
        }
    }

    void setEmpty( int y, int x ){
        empty.x = x; empty.y = y;
        cubes[y][x].setEmpty();
    }

    void setmanhattanDist(){
        manhattanDist = 0;
        for ( int y = 0; y < 3; y++ ){
            for ( int x = 0; x < 3; x++ ){
                if ( cubes[y][x].C[0] != target[y][x] ) manhattanDist++;
            }
        }
    }

    void upDate( int y, int x, int d ){
        if ( target[y][x] != cubes[y][x].C[0] ) manhattanDist += d;
    }
};

int ix, iy, tx, ty, limit;
Puzzle u;
static const int dy[4] = {0, -1, 0, 1};
static const int dx[4] = {1, 0, -1, 0};


bool dfs( int depth, int pre, int seq ){
    if ( depth + u.manhattanDist-1 > limit ) return false;
    if ( u.manhattanDist == 0 ) return true;

    int x, y, nx, ny;

    y = u.empty.y;
    x = u.empty.x;

    Puzzle tmp = u;

    for ( int d = 0; d < 4; d++ ){
        if ( pre != -1 && d == (pre+2)%4 ) continue;
        ny = y + dy[d];
        nx = x + dx[d];
        if ( ny < 0 || nx < 0 || 3 <= nx || 3 <= ny ) continue;

        u = tmp;

        u.upDate(ny, nx, -1);
        u.upDate(y, x, -1);

        u.cubes[ny][nx].rotate(d);
        u.cubes[y][x] = u.cubes[ny][nx];
        u.setEmpty(ny, nx);

        u.upDate(ny, nx, 1);
        u.upDate(y, x, 1);

        if ( dfs( depth+1, d, seq) ) return true;
    }

    return false;
}

void compute(){
    Puzzle initial = Puzzle();
    initial.setEmpty(iy, ix);
    initial.setmanhattanDist();
    int start = initial.manhattanDist -1;
    while( start % 3 != 0 ) start--;
    for ( limit = start; limit <= 30; limit+=3 ){
        u = initial;
        if ( dfs(  0, -1, 0 ) ) {
            if ( limit == 0 ) {cout << 0 << endl; return;}
            limit -= 2;
            u = initial;
            if ( dfs(0, -1, 0 ) ) {
                cout << limit << endl;
            } else {
                 limit++;
                u = initial;
                if ( dfs(0, -1, 0) ) cout << limit << endl;
                else cout << limit + 1 << endl;
            }
            return;
        }
    }
    cout << -1 << endl;
}

bool input(){
    cin >> ix >> iy;
    if ( ix == 0 && iy == 0 ) return false;
    ix--; iy--;
    for ( int y = 0; y < 3; y++ ){
        for ( int x = 0; x < 3; x++ ){
            cin >> target[y][x];
            if ( target[y][x] == 'E' ){ tx = x; ty = y; }
        }
     }
     return true;
}

 main(){
     while(input()) compute();
 }

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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

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

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream&os, const pair<t,u>&p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream&operator <<(ostream&os,const vc<t>&v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class t>
void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

const int inf=LLONG_MAX/3;

//edit below

int waf(int n,int s,vc<pi> lr){
	sort(all(lr));
	int cur=0,ans=0,head=0;
	while(cur<s-1){
		int nx=cur;
		while(head<n&&lr[head].a<=cur)
			chmax(nx,lr[head++].b);
		cur=nx;
		ans++;
	}
	return ans;
}
int relka(int n,int s,vc<pi> lr){
	vi p(s),q(s);
	for(auto w:lr){
		p[w.b]++;
		q[w.a]++;
	}
	rep(i,s-1)p[i+1]+=p[i];
	per(i,s-1)q[i]+=q[i+1];
	dmp(p);
	dmp(q);
	int ans=0;
	rep(i,s-1)chmax(ans,p[i]+q[i+1]);
	return ans;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n,l;cin>>n>>l;
	vc<pi> lr(n);
	rep(i,n)cin>>lr[i].a>>lr[i].b;
	vi pos;
	for(auto w:lr){
		pos.pb(w.a);
		pos.pb(w.b);
	}
	mkuni(pos);
	for(auto&w:lr){
		w.a=lower_bound(all(pos),w.a)-pos.bg;
		w.b=lower_bound(all(pos),w.b)-pos.bg;
	}
	dmp(lr);
	int x=waf(n,pos.size(),lr);
	int y=relka(n,pos.size(),lr);
	cout<<x<<" "<<y+1<<endl;
}



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

ll C2(ll k){
    ll cnt = 0;
    while(k % 2 == 0){
        cnt++;
        k /= 2;
    }
    return cnt;
}

map<long long, int> prime_factor(long long n){
    map< long long, int> ret;

    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            ret[i]++;
            n /= i;
        }
    }

    if( n != 1) ret[n] = 1;
    return ret;
}

int main(){
    ll N, M; cin >> N >> M;
    vector<ll > A(N);
    rep(i, 0, N) cin >> A[i];
    int x = 0;
    
    rep(i, 0, N){
        if(i == 0) x = C2(A[i]);
        else{
            if(x != C2(A[i])){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    
    map<ll, int> mp;
    ll lcm = 1;
    lcm = A[0];
    rep(i, 1, N){
        lcm = lcm * A[i] / __gcd(lcm, A[i]);
    }
    lcm /= 2;
    //cout << lcm << endl;
    cout << M  / lcm  - M / (lcm * 2) << endl;

    


}

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

int main(){
	long long int x;
	long long int c;
	cin >> x;

	c = x / 11 * 2;

	if(x % 11 == 0)
		c += 0;
	else if(x % 11 <= 6)
		c += 1;
	else
		c += 2;

	

 	cout << c << endl;

 	return 0;
}

Measured memory_bytes: 256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



int main() {

	ll N;
	cin >> N;
	vll A(N);
	rep(i, N) cin >> A[i];
	sort(all(A));
	cout << A.back() - A[0] << endl;
}

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

using namespace std;
#define pi 3.14159265358979
int main()
{

      int n, m;
      int x, sum=0;
      cin >> n >> m;
      for(int i=1;i<=m;i++)
      {
          cin >> x;
          sum=sum+x;
      }
      int ans=n-sum;
      if(ans<0)
      {
          cout << -1 << endl;
      }
      else

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


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

using namespace std;
typedef long long ll;

int n;
ll A[100005];
ll B[65];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    ll sum = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
        sum ^= A[i];
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 60; j--; ) {
            if ((sum >> j) & 1) {
                if ((A[i] >> j) & 1) {
                    A[i] ^= 1ll << j;
                }
            }
        }
        for (int j = 60; j--; ) {
            if ((A[i] >> j) & 1) {
                if (B[j] == 0) {
                    B[j] = A[i];
                    break;
                }
                else {
                    A[i] ^= B[j];
                }
            }
        }
    }
    ll x = 0;
    for (int i = 60; i--; ) {
        x = max(x, x ^ B[i]);
    }
    cout << (x + (x ^ sum));
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
using namespace std;
const int MAX = 100005;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main(){
  ll a,b,q;
  cin >> a >> b >> q;
  vector<ll> s(a),t(b),x(q);
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
  rep(i,q) cin >> x[i];
  const ll INF = 1e13;

  s.emplace(s.begin(),-INF);
  s.emplace(s.begin(),-INF*2);
  s.emplace_back(INF);
  s.emplace_back(INF*2);
  
  t.emplace(t.begin(),-INF);
  t.emplace(t.begin(),-INF*2);
  t.emplace_back(INF);
  t.emplace_back(INF*2);

  rep(i,q){
    ll u=upper_bound(s.begin(),s.end(),x[i])-s.begin();
    ll v=upper_bound(t.begin(),t.end(),x[i])-t.begin();
    
    ll res=INF;
    for(int j=-1;j<=1;j++){
      for(int k=-1;k<=1;k++){
        chmin(res,abs(s[u+j]-x[i])+abs(t[v+k]-s[u+j]));
        chmin(res,abs(t[v+k]-x[i])+abs(s[u+j]-t[v+k]));
      }
    }
    cout << res << endl;
  }
  return 0;
}



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

using namespace std;
template<typename T> void in(T &x) { x = 0; bool neg = false; register T c = getchar(); if (c == '-')neg = true, c = getchar(); while ((c < 48) || (c > 57))c = getchar(); for (; c < 48 || c > 57; c = getchar()); for (; c > 47 && c < 58; c = getchar())x = (x << 3) + (x << 1) + (c & 15); if (neg) x *= -1; }
template<typename T> void out(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); }
template<typename T> void outln(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); putchar('\n'); }
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define fastIO ios_base::sync_with_stdio(false); cin.tie(false);
#define ll long long 
#define f1(_x)for (int i = 0; i < _x; ++i)
#define fr(_x)for (int i = _x; i >0; i--)
#define f2(_x,_y)for (int i = _x; i < _y; ++i)
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi; typedef vector<string> vs; typedef vector<bool> vb; vector<long long>vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;

int a[200];
int main() {	
	int n, i = 0, sum = 0; in(n); int x = 2 * n; while (x--) { cin >> a[i++]; }
	sort(a, a + i);
	for (int j = i-2; j >-1; j-=2)
	{
		sum += a[j];
	}
	out(sum);

}


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

using namespace std;



int main() {
	int A, B;
	int num;
	int count = 0;
	bool flag = true;
	vector<int> digit;

	cin >> A >> B;

	for (int i = A; i <= B; i++) {
		num = i;
		digit = {};
		flag = true;
		
		while (num > 0) {
			digit.push_back(num%10);
			num /= 10;
		}


		for (int j = 0; j < digit.size()/2+1; j++) {
			if (digit.at(j) != digit.at(digit.size() - 1 - j)) {
				flag = false;
				break;
			}
		}

		if (flag == true) {
			count++;
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=1e3+50;

struct node{int from,to,day;};
queue<node>q;
queue<int>A[maxn];
int n,tmp;
bool vis[maxn];

int main(){
    cin>>n;
    FOR(i,1,n){
        FOR(j,1,n-1){
            scanf("%d",&tmp);
            A[i].push(tmp);
        }
    }
    FOR(i,1,n){
        int u=A[i].front(),v=A[u].front();
        if(vis[u]||vis[v])continue;
        if(v==i)q.push(node{u,v,1}),vis[u]=vis[v]=1;
    }
    int ans=0;
    while(!q.empty()){
        int u=q.front().from,v=q.front().to,w=q.front().day;
        ans=max(ans,w);
        A[u].pop(),A[v].pop(),q.pop();
        int x=-1,y=-1;
        if(!A[u].empty())x=A[u].front();
        if(!A[v].empty())y=A[v].front();
        if(x!=-1){
            if(A[x].front()==u){
                q.push(node{u,x,w+1});
            }
        }
        if(y!=-1){
            if(A[y].front()==v){
                q.push(node{v,y,w+1});
            }
        }
    }
    bool ok=false;
    for(int i=1;i<=n;i++){
        if(!A[i].empty())ok=true;
    }
    if(ok)puts("-1");
    else cout<<ans<<endl;
}


Measured memory_bytes: 4736
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <list>
#include <cstdlib>
#include <bitset>
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], * p1 = buf, * p2 = buf;
// #define int long long
#define lowbit(x) (x&(-x))
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define pb push_back
typedef unsigned long long ull;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
#define bug puts("BUG");
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-6;
inline ll nextint() {
	int sign = 1; char c = getchar();ll x = 0;
	while (c > '9' || c < '0') { if (c == '-')sign = -1; c = getchar(); }
	while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	return x *= sign;
}
#ifdef LOCAL
    FILE* __input=freopen("input.txt","r",stdin);
    // FILE* __output=freopen("output.txt","w",stdout);
#endif
using namespace std;
const int maxn = 1e6 + 10;
int Prime[maxn],tot;
bool notPrime[maxn];
ll mu[maxn];
ll T[maxn], S[maxn];
ll cnt[maxn];
ll inv2 = 499122177;
void init()
{
	mu[1] = 1;
	for (ll i = 2; i < maxn; ++i)
	{
		if(!notPrime[i])
		{
			Prime[tot++] = i;
			mu[i] = -1;
		}
		for (int j = 0; j < tot && i * Prime[j] < maxn; ++j)
		{
			notPrime[i * Prime[j]] = 1;
			if(i%Prime[j]==0){
				mu[i * Prime[j]] = 0;
				break;
			}
			mu[i * Prime[j]] = -mu[i];
		}
	}
}

void getT()
{
	for (int i = 1; i < maxn; ++i)
	{
		for (ll j = 1; i * j <= 1e6; ++j)
		{
			T[j] += i * cnt[i * j] % mod;
			if (T[j] >= mod)
				T[j] -= mod;
			S[i * j] += i * mu[i] % mod;
			S[i * j] = (S[i * j] + mod) % mod;
		}
	}
}

int main()
{
	init();
	int n = nextint();
	ll res = 0;
	for (int i = 0; i < n; ++i)
	{
		ll x = nextint();
		cnt[x]++;
		res -= x;
		if (res < 0)
			res += mod;
	}
	getT();
	for (int i = 1; i <= 1e6; ++i)
	{
		res += i * S[i] % mod * T[i] % mod * T[i] % mod;
		res %= mod;
	}
	printf("%lld\n", res * inv2 % mod);
}

Measured memory_bytes: 36228
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main() {

	int a = 0, b = 0, c = 0, x;

	while ( ~scanf( "%d", &x ) ) {

		if ( x > a )
			c = b, b = a, a = x;
		else if ( x > b )
			c = b, b = x;
		else if ( x > c )
			c = x;
	}

	printf( "%d\n%d\n%d\n", a, b, c );

	return 0;
}

Measured memory_bytes: 1188
void mD(char C, int *D) {
  switch (C) {
    int t;
  case 'N':
    t = D[0]; D[0] = D[1]; D[1] = D[5]; D[5] = D[4]; D[4] = t;
    break;
  case 'S':
    t = D[0]; D[0] = D[4]; D[4] = D[5]; D[5] = D[1]; D[1] = t;
    break;
  case 'E':
    t = D[0]; D[0] = D[3]; D[3] = D[5]; D[5] = D[2]; D[2] = t;
    break;
  case 'W':
    t = D[0]; D[0] = D[2]; D[2] = D[5]; D[5] = D[3]; D[3] = t;
    break;
  }
  return;
}

int main(void) {
  int D[6], d, Q, q;
  char C[]={'N','N','E','E'}; int c;
  for(d=0;d<6;d++)
    scanf("%d",&D[d]);
  scanf("%d",&Q);
  for (q=0;q<Q;q++) {
    int t,f;
    scanf("%d %d\n",&t,&f);
    for (c=0;D[0] != t;c++)
      mD(C[c], D);
    while(D[1] != f) {
      int t;
      t = D[1]; D[1] = D[2]; D[2] = D[4]; D[4] = D[3]; D[3] = t;
    }
    printf("%d\n", D[2]);
  }
  return 0;
}


Measured memory_bytes: 2040
#include<stdio.h>

int main(void)
{
	char c;
  	int a = 0, b = 0, t = 0;
  	
  	while(1) {
     	scanf("%c", &c);
      	if(c != '0' && c != '1') break;
      	c = c - '0';
      	if(c == t) {
         	a++; 
        } else {
         	b++; 
        }
      	t ^= 1;
    }
  
  	if(a < b) printf("%d", a);
  	else printf("%d", b);
  
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll q, a, b;
ll calc(ll a, ll b){
  if(a > b) swap(a, b);
  ll r = a*2-2, p = a*b-1, q;
  ll c = 0, d = 1e9;
  while(d-c>1){
    q = (c+d)/2;
    (q*q<=p ? c : d) = q;
  }
  q = c;
  if(b<=a+1) return r;
  r += (q-a)*2+1;
  if(q==p/q) r--;
  return r;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> q;
  FOR(_, 0, q){
    ll a, b;
    cin >> a >> b;
    cout << calc(a, b) << endl;
  }
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=0
if 0 in a:
    for i in a:ans+=abs(i)
    print(ans)
else:
    cnt=0
    ai=[]
    for i in a:
        if i<0:cnt+=1
        ai.append(abs(i))
    print(sum(ai)-min(ai)*2*(cnt%2))

Measured memory_bytes: 14412
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] sl = new String[2];
        int a = sc.nextInt();
        int b = sc.nextInt();
        Arrays.fill(sl,"");
        for(int i = 0; i < b; i++){
            sl[0] += a;
        }
        for(int i = 0; i < a; i++){
            sl[1] += b;
        }
        Arrays.sort(sl);
        System.out.println(sl[0]);
    }
}
 

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  long long int n,ans=1;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    ans*=i;
    ans%=(1000000000+7);
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,x,y;
long long dp[100001][2];
vector<int>a[100005];
void dfs(long long u,long long v)
{
	for(int i=0;i<a[u].size();i++)
	{
		if(a[u][i]!=v)
		{
			dfs(a[u][i],u);
			dp[u][0]=(dp[u][0]*(dp[a[u][i]][0]+dp[a[u][i]][1]))%mod;
			dp[u][1]=(dp[a[u][i]][0]*dp[u][1])%mod;
		}
	}
}
signed main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{ 
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	for(int i=1;i<=n;i++) dp[i][0]=dp[i][1]=1;
	dfs(1,1);
	cout<<(dp[1][1]+dp[1][0])%mod;
}

Measured memory_bytes: 14208
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Queue;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int q = sc.nextInt();
			ArrayList<Queue<Integer>> S = new ArrayList<Queue<Integer>>();
			for(int i=0;i<n;i++) {
				S.add(new ArrayDeque<>());
			}

			for(int i=0;i<q;i++) {
				int query = sc.nextInt();
				int t = sc.nextInt();
				switch(query) {
				case 0:
					S.get(t).add(sc.nextInt());
					break;
				case 1:
					if(S.get(t).size()>0)
						System.out.println(S.get(t).peek());
					break;
				case 2:
					if(S.get(t).size()>0)
						S.get(t).poll();
					break;
				}
			}
		}
	}
}


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


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

	int N;
	ll i,x,y;
	int k,l;
	int ans=0;
	int ctr=0;

	cin >> N;
	for(i=1;i<1e6;i++){
		for(k=1;k<1e6;k++){
			if(i*k > N-1) break;
			if(i*k <= N-1) ans++;
		}
	}



	cout << ans << endl;

	return 0;
}



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

int main() {
	string s;
	cin >> s;
	if(s == "AAA" || s == "BBB") cout << "No" << endl;
	else cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)

ans = 0
sum = 0
l = 0
r = 0
while (l < n && r < n) do
    if l == r 
        sum += a[l]
        ans += 1 # (r-l+1)
        r += 1
    else
        if (sum | a[r]) == (sum + a[r])
            sum += a[r]
            ans += (r-l+1)
            r += 1
        else
            sum -= a[l]
            l += 1
        end
    end
end

puts ans


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

int main()
{
	int N, K;
	cin >> N >> K;
	int trash;
	for (int i = 0; i < N; i++) {
		cin >> trash;
	}
	
	for (int i = 0; i < N; i++) {
		int cover = (K - 1) * i + 1; 
		if (cover >= N) {
			cout << i << endl;
			break;
		}
	}
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;
int main(){
    int n,ans=1,temp;
    scanf("%d",&n);
    if(!(n&1)){
        n>>=1;
        temp=1;
        while(!(n&1)){
            n>>=1;
            temp<<=1;
        }
        ans=temp;
    }
    for(int i=3;i*i<=n;i+=2){
        if(n%i==0){
            temp=i-1;
            n/=i;
            while(n%i==0){
                n/=i;
                temp*=i;
            }
            ans*=temp;
        }
    }
    if(n!=1)ans*=n-1;
    printf("%d\n",ans);
}


Measured memory_bytes: 2764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x=0):x((x%mod+mod)%mod){}
	mint operator-() const { return mint(-x);}
	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);
		return res-=a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
		return a;
	}
	
	// for prime mod
	mint inv() const {
		return pow(mod-2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res/=a;
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n+3);
	rep(i, m) {
		int tmp;
		cin >> tmp;
		a[tmp] = 1; 
	}
	vector<mint> dp(n+3);
	dp[0] = 1;
	rep(i, n+1) {
		if(!a[i+1]) {
			dp[i+1] += dp[i];
		}
		if(!a[i+2]) {
			dp[i+2] += dp[i];
		}
	}
	cout << dp[n].x << endl;
	// rep(i, n+1) cout << dp[i].x << endl;
	
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
//#include <set>
//#include <map>
//#include <ctime>
#include <cmath>
#include <iomanip>
//#include <cstdio>
using namespace std;
/*************************************************************************************/
const int Inf = 2147483647;
const char w = '\n';
int ii( ){ int x; cin >> x; return x; }
struct d; bool comd( d& a, d& b ); 
typedef vector<d> vd;
typedef vector<int> vi;
typedef long long int ll;
void Faster( ){ ios_base::sync_with_stdio( false );	cin.tie( nullptr ); }
void iv( vi& p ){ for( int x: p ) cin >> x; }
void pv( vi& p ){ for( int x: p ) cout << x << ' '; cout << w; }
void sa( vi& p ){ sort( p.begin(), p.end() ); }
void sa( vd& p ){ sort( p.begin(), p.end(), comd ); }
void sd( vi& p ){ sort( p.begin(), p.end(), [](int a, int b){ return a > b; } ); }
/*************************************************************************************/

struct d{
	int ft;
	int sd;
};
bool comd( d& a, d& b ){
	return true;
}
string Disol( ){
	return "Yes";
	return "No";
}

int main( ){
	Faster( );
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double pai = acos( -1.0 );
	double B = pai * m / 30.0;
	double A = pai * h / 6.0 + B / 12;
	
	double ans = sqrt( a*a + b*b - 2*a*b*cos( A - B ) );
	cout << setprecision(20) << fixed;
	cout << ans << w;
	return 0;
}

// 29-05-2020
// Grandmaster Template 12
// kafiulshabbir@phystech.edu

Measured memory_bytes: 4220
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;
ll x,s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>x;
    s=(x/500)*1000;
    x=x%500;
    s=s+(x/5)*5;
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 768