akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, c): (usize, usize) = read();
    let mut color_cost_table: Vec<Vec<i32>> = vec![];
    for i in 0..c {
        color_cost_table.push(readnc());
    }

    let mut total_by_mod = [0, 0, 0];
    let mut color_counter_by_mod: [Vec<i32>; 3] = [
        vec![0; c], vec![0; c], vec![0; c]
    ];

    for i in 0..n {
        let row: Vec<usize> = readnc();
        for j in 0..n {
            let m = (i+j)%3;
            color_counter_by_mod[m][row[j]-1] += 1;
            total_by_mod[m] += 1;
        }
    }

    let mut best_cost = 500 * 500 * 1000 + 100;
    for c0 in 0..c {
        for c1 in 0..c {
            for c2 in 0..c {
                if c0 == c1 || c1 == c2 || c0 == c2 {
                    continue
                }

                let mut total_cost = 0;
                for (i, &color) in [c0, c1, c2].iter().enumerate() {
                    for from_color in 0..c {
                        if from_color == color {
                            continue;
                        }
                        total_cost += color_counter_by_mod[i][from_color] * color_cost_table[from_color][color];
                    }
                }
                best_cost = min(best_cost, total_cost);
            }
        }
    }

    println!("{}", best_cost);
}


Measured memory_bytes: 4352
<?php
// Your code here!
list($x,$n) = explode(" ", trim(fgets(STDIN)));
$line = explode(" ", trim(fgets(STDIN)));

$mm = 1;
while(true){
    if(!in_array($x, $line)){
        echo $x;
        exit;
    }
    
    $y = abs($x - $mm);
    $yy = abs($x + $mm);
    if(!in_array($y, $line)){
        echo $y;
        exit;
    }
    if(!in_array($yy, $line)){
        echo $yy;
        exit;
    }
    $mm++;
}


?>


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

#define REP(i,x,y) for(ll i=x; i<=y; i++)
#define BIT(t) ((long long 1) << t)
#define PER(i,y,x) for(ll i=y; i>=x; i--)
#define SIZE(v) ll(v.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
typedef long long ll;

bool f(ll n,vvll& g, vector<pair<ll,ll>>& v){
    vll color(n+3, -1);
    REP(i,1,n){
        if(color[i] == -1){
            queue<ll> qu;
            qu.push(i);
            color[i] = 0;
            ll z[2] = {1,0};
            while(!qu.empty()){
                ll cur = qu.front();
                qu.pop();
                for(auto nex:g[cur]){
                    if(color[nex] == color[cur]){
                        return true;
                    }else if(color[nex] == -1){
                        color[nex] = (color[cur] + 1) %2;
                        z[color[nex]]++;
                        qu.push(nex);
                    }
                }
            }
            v.push_back({z[0], z[1]});
        }
    }
    return false;
} 

ll fct(ll n, vector<pair<ll,ll>>& v){
    bitset<703> b = 1;
    for(auto c:v){
        ll s = c.first; ll t = c.second;
        b = (b << s) | (b << t);
    }
    ll ans = 1e18;
    REP(i,0,n){
        if(b[i]){
            ll tmp = i * (i-1) / 2 + (n-i) * (n-i-1) / 2;
            ans = min(ans, tmp);           

        }
    }
    return ans;
}


int main(){
    ll n, m;
    cin >> n >> m;
    vvll gg(n+3, vll(n+3, 0));
    REP(i,1,m){
        ll a,b;
        cin >> a >> b;
        gg[b][a] = gg[a][b] = 1;
    }
    vvll g(n + 3, vll());  
    REP(i,1,n){
        REP(j,i+1,n){
            if(gg[i][j] == 0){
                g[i].push_back(j);
                g[j].push_back(i);
            }
        }
    }
    vector<pair<ll,ll>> v; 
    if(f(n, g, v)){
        cout << -1 << endl;
        return 0;
    }
    ll ans = fct(n, v);
    cout << ans << endl;
}

Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define maxn 3010
#define int long long
using namespace std;

int dp[maxn];

int a,b,c,d;

int32_t main(){
	cin >> a >> b >> c >> d;
	int ans = 0;
	for(int i = 0; i*a <= d; i++)
		for(int j = 0; j*b <= d+a*i; j++){
			int x = d - i*a- j*b;
			if(x >= 0 && x % c == 0)
				ans++;
		}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
mini, maxi, K_ban = map(int, input().split())

if (maxi - mini + 1 <= 2 * K_ban):
    ans = [i for i in range(mini, maxi + 1)]

else:
    left = [i for i in range(mini, mini + K_ban)]
    right = [i for i in range(maxi - K_ban + 1, maxi + 1)]
    
    ans = left + right
    

[print(n) for n in ans]

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

using namespace std;

 

int main(){

    int m,f,r,s;

    char G;

    while(1){

        cin>>m>>f>>r;

        if(m==-1&&f==-1&&r==-1)break;

        s=m+f;

        if((m==-1)||(f==-1)){

            G='F';

        }else if(s>=80){

            G='A';

        }else if((s>=65)&&(s<80)){

            G='B';

        }else if((s>=50)&&(s<65)){

            G='C';

        }else if((s>=30)&&(s<50)){

            if(r>=50){

                G='C';

            }else{

                G='D';

            }

        }else if(s<30){

            G='F';

        }

        cout<<G<<endl;

    }

    return(0);

}

Measured memory_bytes: 3096
object Main extends App {
	val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val tp1 = Array.fill(n)(1)
	val tp2 = Array.fill(n)(0)

	tp2(0) = 1

	for(i<-0 until m){
		val Array(a, b) = scala.io.StdIn.readLine.split(" ").map(_.toInt - 1)

		if(tp1(a) != 0){
			tp1(a) -= 1
			tp1(b) += 1

			if(tp2(a) != 0){
				if(tp1(a) != 0){
					tp2(b) = 1
				}else{
					tp2(a) = 0
					tp2(b) = 1
				}
			}

		}
	}

	println(tp2.sum)
	
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int64> A(3);
	REP(i, 3) cin >> A[i];
	sort(all(A));
	if (A[0] == A[1] && A[1] != A[2]) {
	  cout << "Yes" << endl;
	} else if (A[0] != A[1] && A[1] == A[2]) {
	  cout << "Yes" << endl;
	} else {
	  cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>










int n,mn,mx,a[60];



void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(i==1||a[mn]>a[i])
		{
			mn=i;
		}
		if(i==1||a[mx]<a[i])
		{
			mx=i;
		}
	}
	if(a[mn]+a[mx]>=0)
	{
		cout<<(2*n)-1<<"\n";
		for(int i=1;i<=n;i++)cout<<mx<<" "<<i<<"\n";
		for(int i=2;i<=n;i++)cout<<i-1<<" "<<i<<"\n";
	}
	else
	{
		cout<<(2*n)-1<<"\n";
		for(int i=1;i<=n;i++)cout<<mn<<" "<<i<<"\n";
		for(int i=n-1;i>=1;i--)cout<<i+1<<" "<<i<<"\n";
	}
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<class T>
void show_1d_vector(const vector<T> &v){
    for(auto v1: v) {
        cout << v1 << " ";
    }
    cout << endl;
}
int main(){
    ll n, c;
    cin >> n >> c;
    vector<ll> x(n),v(n);
    vector<ll> cv(n,0),anticv(n,0);
    vector<ll> cvm(n,0),anticvm(n,0);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> v[i];
    }
    cv[0] = v[0];
    anticv[0] = v[n-1];
    for(int i = 1; i < n; i++){
        cv[i] = cv[i-1] + v[i];
        anticv[i] = anticv[i-1] + v[n-1-i];
    }
    for(int i = 0; i < n; i++){
        cv[i] -= x[i];
        anticv[i] -= c-x[n-1-i];
    }
    cvm[0] = cv[0]; anticvm[0] = anticv[0];
    for(int i = 1; i < n; i++){
        cvm[i] = max(cvm[i-1],cv[i]);
        anticvm[i] = max(anticvm[i-1],anticv[i]);
    }

    ll cv_idx = -1, cv_max = -1;
    ll acv_idx = -1, acv_max = -1;
    for(int i = 0; i < n; i++){
        if(cv_max < cv[i]){
            cv_max = cv[i];
            cv_idx = i;
        }
        if(acv_max < anticv[i]){
            acv_max = anticv[i];
            acv_idx = i;
        }
    }
    ll ans = max(cv_max, acv_max);

    if(cv_idx == -1 && acv_idx == -1){
        cout << "0" << endl;
        return 0;
    }

    ll t;
    for(int i = 0; i < n-1; i++){
        t = anticv[i] - (c-x[n-1-i]) + cvm[n-2-i];
        ans = max(ans, t);
    }
    for(int i = 0; i < n-1; i++){
        t = cv[i] - (x[i]) + anticvm[n-2-i];
        ans = max(ans, t);
    }


    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 4992
n = int(input())
a = list(map(int, input().split()))

i = 1
j = 0
c = a[0]
ans = n
num = 0

while i <= n-1:
    if c ^ a[i] == c + a[i]:
        c = c ^ a[i]
        num += 1
        ans += num
        i += 1
    else:
        c = c & ~a[j]
        j += 1
        num -= 1

print(ans)


Measured memory_bytes: 24840
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
	char S[10]; cin >> S;

	if (!strcmp(S, "MON")) printf("6\n");
	else if (!strcmp(S, "TUE")) printf("5\n");
	else if (!strcmp(S, "WED")) printf("4\n");
	else if (!strcmp(S, "THU")) printf("3\n");
	else if (!strcmp(S, "FRI")) printf("2\n");
	else if (!strcmp(S, "SAT")) printf("1\n");
	else printf("7\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(k,nu)    for(int i=k; i<nu;  i++)
#define rep2(k,n)   for(int j=k; j<n;  j++)
#define size_a(array) sizeof(array) / sizeof(array[0])
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define ll long long
#define pb pop_back
template<typename T> inline void chMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
const double PI = acos(-1);


int main(){
    int n; cin >> n;
    ll ans=0;
    rep(1,n+1){
        if(i%3==0 || i%5==0){
            continue;
        }
        ans += i;
    }
    cout << ans << endl;
    return 0;
}
/*

*/


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

const int DIM = 1e5 + 5;


int main(void) {
    ios::sync_with_stdio(false);
    
    int x, a, b;
    cin >> x >> a >> b;
    
    if (abs(x - a) < abs(x - b))
        cout << "A";
    else
        cout << "B";
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>

using namespace std;

map<long int,int> mp;

int main(){
    int n;
    int a;
    int flag=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        mp[a] ++;
        if(mp[a] > 1){
            flag = 1;
            break;
        }
    }
    if(flag) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;

}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};
    for(int i = 0; i < H; i++) cin >> S[i];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S[i][j] == '.'){
                int cnt = 0;
            for(int k = 0; k < 8; k++){
                int nx = i + dx[k], ny = j + dy[k];
                if(0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] == '#'){
                    cnt++;
                }
            }
            S[i][j] = '0' + cnt;
            }
        }
    }
    for(int i = 0; i < H; i++) cout << S[i] << endl;
}

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

int main() {
    ll num; cin >> num;
  	
  	ll ans = 0;
    bool isAll9 = true;
  	while(num >= 1) {
 	 if(num < 10) {
       ans += num;
       if(!isAll9) ans--;
     } else {
       if(num % 10 != 9) isAll9 = false;
       ans += 9;
     }
      
     num /= 10; 
    }
  
    cout << ans << endl;

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld; 


#define F first
#define S second
#define pob pop_back
#define pb push_back
#define Time()	cerr << clock() * 1000 / CLOCKS_PER_SEC << "ms\n"
#define show(x)	cerr << #x << " = " << (x) << '\n'
#define inf 1e14
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define Test int T;cin>>T;while(T--)
#define vec vector<ll> 
#define REP(i,j,k) for(int i=(j);(i)<(k);(i)++)

int main(){
	ll n,k;
	cin>>n>>k;
	ll ans= n%k;
	if(abs(k-ans) < ans)
	cout<<abs(k-ans);
	else cout<<ans;
	
	
	

}


Measured memory_bytes: 256
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var K = one[0];
	var X = one[1];
	var output = [];
	for(var i = X - K + 1; i <= X + K - 1; i++){
		output.push(i);
	}
	myout(myconv(output,8));
}


Measured memory_bytes: 30296
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int m = cin.ReadInt;
            if (n == m)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
             
            // 解答はココに書く
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++){
    ans = ans +  int(s.at(i))-48;
  }
  if (ans%9==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3716
n, k = map(int, input().split())
p = list(map(int, input().split()))
q = [(x+1)/2 for x in p]
cur = sum(q[:k])
ans = cur
for i in range(k, n):
	cur = cur - q[i-k] + q[i]
	ans = max(ans, cur)
print(ans)

Measured memory_bytes: 77448
#include <iostream>
#include <math.h>
#include <cstring>
using namespace std;

int main(){
  int64_t n;
  
  cin >> n;
  
  int64_t aa[n];
  int64_t a;
  int64_t tmp;
  int64_t cc[n];
  memset(cc, 0, sizeof cc);
  int64_t count = 1;
  int64_t four = 4;
  for(int64_t i = 0; i < n; i++){
    cin >> a;
    cc[a]++;
    
    if(a == 0){
     count = count*(four-cc[a]); 
    }
    else{
      //tmp = cc[a-1] > 4-cc[a] ? (cc[a-1]-cc[a]+1) : cc[a-1];
      tmp = cc[a-1] -cc[a]+1;
      count = count*tmp; 
    }
    if(count > 1000000007){
     count = (int64_t)count%1000000007; 
    }
    //cout << a << " " << cc[a] << " " << count << endl;
  }
  cout << count%1000000007;
  
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int n,sum=0;
	scanf("%d",&n);
	int x;
	scanf("%d",&x);
	for(int i=1;i<=n;i++)
	{
		int y;
		scanf("%d",&y);
		if(x>y)
		{
			if(x-y>y)
				sum=sum+y*2;
			else
				sum=sum+(x-y)*2;
		}
		else
		{
			sum=sum+(y-x)*2;
		}
	}
	printf("%d\n",sum);
	
	return 0;
 } 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long ll;
typedef long double ld;

int  main()
{
	long n, a, b; cin >> n >> a >> b;
	long r = n - 2;

	long ans = 0;
	// if (r <= (b - a + 1))
	ans = (b*r) - (a*r) + 1;
	if (ans > 0)
		cout << ans << endl;
	else
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <math.h>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll; 

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	ll res=0;
	while(1){
		ll sum=0;
		for(int i=0;i<n;i++){
			sum+=a[i]/n;
		}
		if(sum==0)break;
		res+=sum;
		for(int i=0;i<n;i++){
			a[i]=(a[i]%n)+(sum-a[i]/n);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
N=int(input())
S=input()
E=[0]*N
W=[0]*N
if S[0]=="E":
    E[0]=1
else:
    W[0]=1
for i in range(N):
    if S[i]=="E":
        E[i]=E[i-1]+1
        W[i]=W[i-1]
    else:
        E[i]=E[i-1]
        W[i]=W[i-1]+1
ans=E[-1]-E[0]
for i in range(1,N):
    num=W[i-1]+E[-1]-E[i]
    ans=min(ans,num)
print(ans)


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 1e6+5;
string s;
ll n , m , cnt[N] , x[N] , y[N] , mod=1e9+7;

int mul(int a, int b)
{
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (1ll * a * b) % mod;
}

int add(int a, int b)
{
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return (a + b) % mod;
}

int main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m;
    for(int i=1; i<=n; i++)
        cin >> x[i];
    for(int i=1; i<=m; i++)
        cin >> y[i];

    sort(x+1 , x+n+1);
    sort(y+1 , y+m+1);

    vector<ll> v,v2;
    for(int i=1; i<n; i++)
        v.push_back(add(x[i+1],-x[i]));
    for(int i=1; i<m; i++)
        v2.push_back(add(y[i+1],-y[i]));

    ll sum=0 , sum2=0 , p=(int)v.size() , st=(int)v.size();

    for(int i=0; i<v.size(); i++)
    {
        sum = add(sum , mul(v[i] , st));
        p = add(p , -2);
        st = add(st , p);
    }

    p=(int)v2.size() , st=(int)v2.size();
    for(int i=0; i<v2.size(); i++)
    {
        sum2 = add(sum2 , mul(v2[i] , st));
        p = add(p , -2);
        st = add(st , p);
    }

    cout << mul(sum,sum2) << '\n';
//
    return 0;
}

Measured memory_bytes: 7412
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    int ans=IINF;
    for(char c='a';c<='z';c++){
        bool abc=1;
        for(int i=0;i<s.length();i++){
            if(s[i]!=c){
                abc=0;
                break;
            }
        }
        if(abc==1){
            cout<<0<<endl;
            return 0;
        }
        string is=s;
        int cnt=0;
        string pre;
        while(1){
            string ss;
            ss.resize(is.length()-1);
            for(int i=0;i<is.length()-1;i++){
                if(is[i]==c||is[i+1]==c)
                    ss[i]=c;
                else
                    ss[i]='0';
            }
            cnt++;
            //cout<<ss<<endl;
            bool abc=1;
            for(int i=0;i<ss.length();i++){
                if(ss[i]!=c){
                    abc=0;
                    break;
                }
            }
            if(abc==1){
                chmin(ans,cnt);
                break;
            }
            is=ss;
            if(ss=="a")break;
        }
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------
/*
int n;cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)
    cin>>a[i];
*/


Measured memory_bytes: 256
n, m = map(int, input().split())

dp = [0] * (n+1)
broken = [0] * (n+1)

for i in range(m):
    broken[int(input())] = 1

dp[0] = 1

if broken[1] == 1:
    dp[1] = 0
else:
    dp[1] = 1

if n == 1:
    print(dp[n])
    exit()
else:
    for i in range(2, n+1):
        if broken[i] == 1:
            continue
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % 1000000007
            
print(dp[n])

Measured memory_bytes: 7668
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

void dfs(int v,int p,ll d, vector<ll> &depth, vector<vector<pair<int,ll>>> &tree){
  depth[v]=d;
  for(auto &e : tree[v]){
    if(e.first==p)continue;
    dfs(e.first,v,d+e.second,depth,tree);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<vector<pair<int,ll>>> tree(N);
  vector<ll> depth(N);
  for(int i=0;i<N-1;i++){
    int a,b,c;cin>>a>>b>>c;a--;b--;
    tree[a].push_back(make_pair(b,c));
    tree[b].push_back(make_pair(a,c));
  }
  int Q,K;cin>>Q>>K;K--;

  dfs(K,-1,0,depth,tree);
  for(int i=0;i<Q;i++){
    int x,y;cin>>x>>y;x--;y--;
    cout<<depth[x]+depth[y]<<endl;
  }
}


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

int main(){
  int64_t N;
  cin >> N;
  
  vector<int64_t> Luc(87);
  
  for (int i = 0; i < 87; i++) {
    if (i == 0) {
      Luc.at(i) = 2;
    } else if (i == 1) {
      Luc.at(i) = 1;
    } else {
      Luc.at(i) = Luc.at(i-1) + Luc.at(i-2);
    }
  }
  
  cout << Luc.at(N) << endl;
}

Measured memory_bytes: 764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]	data = null;
		while((data = parseData())!= null) {
			result(data);
		}
	}

	private static void result(int[] data) {
		String	div = String.valueOf((double)data[0] / (double)data[1]);
		int		dot = div.indexOf('.');
		int		sum = 0;
		int		len = 0;

		if (dot != -1) {
			div = div.substring(dot + 1);
			len = Math.min(data[2], div.length());
			for (int n = 0; n < len; n++) {
				sum += div.charAt(n) - '0';
			}
		}
		
		System.out.println(sum);
	}

	private static int[] parseData() {
		int[]		data  = null;
		String		stdin = parseStdin();
		String[]	line  = null;

		if (stdin != null) {
			line = stdin.split(" ");
			data = new int[3];

			for (int n = 0; n < data.length; n++) {
				data[n] = Integer.parseInt(line[n]);
			}
		}

		return data;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 16980
/*input
10
1 3776 3776 8848 8848 8848 8848 8848 8848 8848
8848 8848 8848 8848 8848 8848 8848 8848 3776 5
*/
#include <stdio.h>
#include <algorithm>
#define int unsigned long long
#define For(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N = 200001;
const long long base = 1000000007;
int T[N], A[N],n;
signed main(){
	scanf("%lld", &n);
	int ans = 1;
	For(i,1,n) scanf("%lld", &T[i]);
	For(i,1,n) scanf("%lld", &A[i]);
	For(i,1,n){
		if (T[i] != T[i-1] && A[i+1] != A[i]) { ans *= (T[i] == A[i]); continue; }
		else if (T[i] != T[i-1] || A[i+1] != A[i]) {
			if ((T[i] != T[i-1] && A[i] < T[i]) || (A[i+1] != A[i] && T[i] < A[i]) ) ans = 0; 
			continue;
 		}
		//printf("%d %d %d\n", i, T[i], A[i]);
		ans = (ans * (min (T[i], A[i])) ) % base; 
	}
	printf("%lld", ans);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
    int n;
    while(scanf("%d",&n),n) {
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        int ans=1<<30;
        for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) {
            ans=min(ans,abs(a[i]-a[j]));
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
long long N;
int main(void)
{
	cin >> N;
	for (long long i = (long long)sqrt(N); i > 0; i--)
	{
		if (N % i == 0)
		{
			cout << i + N / i - 2 << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
s = gets.to_i

fac = [1, 1]
finv = [1, 1]
inv = [nil, 1]
(2..s).each do |i|
  fac[i] = fac[i-1] * i % MOD
  inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD
  finv[i] = finv[i-1] * inv[i] % MOD
end

com = ->(n, k) { fac[n] * finv[n - k] % MOD * finv[k] % MOD }

p (1..s/3).sum { |n| com.(s - 2 * n - 1, n - 1) } % MOD

Measured memory_bytes: 14316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

int main(){
    string yes = "YES", no = "NO";    
    ll N;
    cin >> N;
    ll A[N], cnt[N], sum = 0, K, n = N*(N+1)/2;
    rep(i, N){
        cin >> A[i];
        sum += A[i];
    }
    if(sum%n != 0){
        cout << no << endl;
        exit(0);
    }
    K = sum/n;
    rep(i, N){
        ll j = (i+1)%N;
        ll s = A[i]-A[j]+K;
        if(s < 0){
            cout << no << endl;
            exit(0);
        }
        elif(s%N != 0){
            cout << no << endl;
            exit(0);
        }
        else cnt[i] = s/N;
    }
    ll S = 0;
    rep(i, N) S += cnt[i];
    if(S == K) cout << yes << endl;
    else cout << no << endl;
}

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

int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += min(x.at(i) * 2, abs(k - x.at(i)) * 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main (void){
  long long N;
  scanf("%lld",&N);
  long long A,B;
  scanf("%lld%lld",&A,&B);
  if(N%(A+B)==0){
    printf("%lld\n",N/(A+B)*A);
  }else{
    if(N%(A+B)<=A){
      printf("%lld",N/(A+B)*A+(N%(A+B)));
    }else if((N%(A+B)>A)){
      printf("%lld",N/(A+B)*A+A);
    }
  }
    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    ll N, dp[101][4][4][4];
    rep(i, 101) rep(j, 4) rep(k, 4) rep(l, 4) dp[i][j][k][l] = 0;
    rep(i, 4) rep(j, 4) rep(k, 4) rep(l, 4) dp[i][j][k][l] = 1;
    dp[3][0][2][1] = 0;
    dp[3][2][0][1] = 0;
    dp[3][0][1][2] = 0;
    cin >> N;
    for (int i = 4; i <= N; i++) {
        rep(j, 4) {
            rep(k, 4) {
                rep(l, 4) {
                    if (j == 0 && k == 1 && l == 2) continue;
                    if (j == 0 && k == 2 && l == 1) continue;
                    if (j == 2 && k == 0 && l == 1) continue;
                    rep(m, 4) {
                        if (m == 0 && k == 2 && l == 1) continue;
                        if (m == 0 && j == 2 && l == 1) continue;
                        dp[i][j][k][l] += dp[i - 1][m][j][k];
                        dp[i][j][k][l] %= MOD;
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(i, 4) rep(j, 4) rep(k, 4) ans = (ans + dp[N][i][j][k]) % MOD;
    cout << ans << "\n";
}

Measured memory_bytes: 256
using System;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var ans = new int[n];
        ans[1] = Math.Abs(h[0] - h[1]);
        for (int i = 2; i < n; i++)
        {
            ans[i] = Math.Min(Math.Abs(h[i - 2] - h[i]) + ans[i - 2], Math.Abs(h[i - 1] - h[i] )+ ans[i - 1]);
        }
        Console.WriteLine(ans[n-1]);
    }
}



Measured memory_bytes: 16864
#include <iostream>
#include <string>
#include <algorithm>

//answer3 function
void display(const char& ch) {
	std::cout << ch;
}

int main(){
	std::string str;
	std::cin >> str;
	
	//answer1
	for(auto it = str.crbegin(); it != str.crend(); ++it){
		std::cout << *it;
	}
	
	
	//answer2
	//std::for_each(str.crbegin(), str.crend(), [](const char& ch){ std::cout << ch; });
	
	//answer3
	//std::for_each(str.crbegin(), str.crend(), display);
	
	std::cout << std::endl;
	
	return 0;
}

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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;

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

  int N;
  cin >> N;

  int x = N * 100 / 108;
  if(x * 108 / 100 == N) {
    cout << x << endl;
  } else if (++x * 108 / 100 == N) {
    cout << x << endl;
  } else {
    cout << ":(" << endl;
  }

  return 0;
}


Measured memory_bytes: 3656
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

X,A,B = I()
if X >= B:
    print('delicious')
elif X+A >= B:
    print('safe')
else:
    print('dangerous')

Measured memory_bytes: 9888
use proconio::input;

fn main() {
    input! {
        n: usize,
    }

    let mut ans = n;

    for i in 0..=n {
        let mut count = 0;
        let mut t = i;
        while t > 0 {
            count += t % 6;
            t /= 6;
        }
        t = n - i;
        while t > 0 {
            count += t % 9;
            t /= 9;
        }
        if ans > count {
            ans = count;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 2148
/*
  Contest 108

  Rakesh Kumar --> 27/09/2020
 */

#include <bits/stdc++.h>

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

    int k = 0;
    std::cin >> k;
    const int t = k >> 1;
    if (k & 1)
        std::cout << t * (t + 1) << std::endl;
    else
        std::cout << t * t << std::endl;

    return 0;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C078
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]), M = int.Parse(s[1]);
            int k = (int)Math.Pow(2, M);
            int x = k * (1900 * M + 100 * (N - M));
            Console.WriteLine(x);
        }
    }
}


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

int main()
{    
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<bool> hash(pow(10,9)+1);

    for(ll data : a)
    {
        if(hash[data] != false)
        {
            cout << "NO" <<endl;
            return 0;
        }
        hash[data] = true;
    }
    cout << "YES" << endl;

}

Measured memory_bytes: 123904
N = int(input())
B = [int(b) for b in input().split()]
lenB = len(B)
Ans = [None] * N
while lenB > 0:
    for i in reversed(range(lenB)):
        if i+1 == B[i]:
            Ans[lenB-1] = B[i]
            del B[i]
            lenB -= 1
            break
    else:
        print(-1)
        break
else:
    for a in Ans:
        print(a)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int cmp(const void *a,const void *b){
	return *(int *)b-*(int *)a;
}
int main(void){
	int n,m,p[1000],i,sum;
	while(1){
		scanf("%d %d",&n,&m);
		if(!(n+m))
			break;
		sum=0;
		memset(p,0,sizeof(p));
		for(i=0;i<n;i++){
			scanf("%d",&p[i]);
		}
		qsort(p,n,sizeof(int),cmp);
		for(i=0;i<n;i++){
			if((i+1)%m)
				sum+=p[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

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

	string S = to_string(n);

	for (int i = 0; i < 3; i++) {
		if (S[i] == '1') {
			cout << 9;
		}
		else if (S[i] == '9') {
			cout << 1;
		}
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
double a;
double cnt;
double ans;
int main(){
	cin >> a;
	for(int i = 1; i <= a; i++)
		if(i % 2 != 0) cnt++;
	ans = cnt / a;
	printf("%lf\n",ans);
}

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


//a^n (mod m)
const long long mod = 1000003;
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

ll f[2000200];

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

    int q;
    cin>>q;

    f[0]=1;
    for(int i=1;i<2000200;i++){
        f[i] = f[i-1]*i;
        f[i]%=mod; 
    }

    while(q--){
        ll x,d,n;
        cin>>x>>d>>n;

        if(d==0){
            ll t = modpow(x,n);
            cout<<t<<"\n";
            continue;
        }

        ll xd = x*modinv(d) + mod -1;
        xd%=mod;

        if(n>=mod){
            cout<<0<<"\n";
            continue;
        }

        ll ans = modpow(d,n);

        ans *= (f[xd+n]*modinv(f[xd]))%mod;

        ans%=mod;

        cout<<ans<<"\n";
    }


}


Measured memory_bytes: 16512
from math import gcd
N, M = map(int, input().split())
S = input()
T = input()
G = gcd(N, M)

# SとTがXの同じ部分を参照する際、それらが等しくなければならない
for i in range(G):
    # N/GやM/Gは必ず整数になるが、intにするために//で演算
    if S[i * N // G] != T[i * M // G]:
        print(-1)
        exit()

# 最小公倍数、lcm(N,M)は用意されていない
# 同様にintにするため//で演算
l = N * M // G
print(l)


Measured memory_bytes: 9220
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
#print(X)
Y = [0 for i in range(len(X)-1)]
for i in range(len(X)-1):
    Y[i] = X[i+1] - X[i]
Y.sort()
Y.reverse()
sumY = sum(Y)
summax = sum(Y[:N-1])
print(sumY - summax)



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

int main() {
  string S;
  cin >> S;

  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  }

  if (S == "Cloudy") {
    cout << "Rainy" << endl;
  }

  if (S == "Rainy") {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
using System;
 
namespace PrintRectangle
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            while (true) {
                string[] tmp = Console.ReadLine ().Split (" ".ToCharArray ());
                int height, Wide;
 
                height = int.Parse (tmp [0]);
                Wide = int.Parse (tmp [1]);
                if (height == 0 && Wide == 0)
                    break;
 
                for (int i = 1; i <= height; i++) {
                    for (int j = 1; j <= Wide; j++) {
                        Console.Write ((i == 1 || i == height ||j == 1||j==Wide)? "#":".");
                    }
                    Console.Write ("\n");
                }
                Console.Write ("\n");
            }
        }
    }
}
 

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

typedef long long ll;

int h, w;
char t;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> h >> w;
    for (int i = 0; i < w + 2; ++i) {
        cout << "#";
    }
    cout << endl;
    for (int i = 0; i < h; ++i) {
        cout << "#";
        for (int j = 0; j < w; ++j) {
            cin >> t;
            cout << t;
        }
        cout << "#" << endl;
    }
    for (int i = 0; i < w + 2; ++i) {
        cout << "#";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3608
use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{stdin, Read};
use std::os::raw::{c_double, c_float};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<usize>();
    let mut a = (0..n).map(|_| read::<f64>()).collect::<Vec<_>>();
    let s = a.iter().map(|&x| 1.0 / x).sum::<f64>();
    println!("{}", 1.0 / s)
}


Measured memory_bytes: 4352
gets.to_i.times do
    side = gets.split.map(&:to_i)
    isRight = false
    0.upto(2) do |i|
        if side[i]**2 + side[(i+1)%3]**2 == side[(i+2)%3]**2 then
            isRight = true
        end
    end
    puts isRight ? "YES" : "NO"
end

Measured memory_bytes: 8796
#include<bits/stdc++.h>
using namespace std;
const int maxn=50+5;
const int mod=1e9+7;
long long dp[maxn][maxn*2][maxn*2];
int a[maxn<<1],n;
inline int calc(int i){return (a[i]!=a[i-1])+(a[2*n-i]!=a[2*n-i+1]);}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++)scanf("%d",&a[i]);
	sort(a+1,a+n*2);
	dp[n][1][1]=1;
	for(int i=n;i>=2;i--)
	{
		int lim=calc(i);
		for(int j=0;j<=2*n;j++)
		for(int k=0;k<=j;k++)
		{
			if(dp[i][j][k]==0)continue;
			for(int p=1;p<=j;p++)
			{
				if(p<=k)dp[i-1][j+lim-(k-p)][p-1+(a[i]!=a[i-1])]+=dp[i][j][k],dp[i-1][j+lim-(k-p)][p-1+(a[i]!=a[i-1])]%=mod;
				else if(p==k+1)dp[i-1][j+lim][k+(a[i]!=a[i-1])]+=dp[i][j][k],dp[i-1][j+lim][k+(a[i]!=a[i-1])]%=mod;
				else dp[i-1][j+lim-(p-2-k)][k+1+(a[i]!=a[i-1])]+=dp[i][j][k],dp[i-1][j+lim-(p-2-k)][k+1+(a[i]!=a[i-1])]%=mod;
			}
		}	
	}
	long long ans=0;
	for(int j=0;j<=2*n;j++)
	for(int k=0;k<=j;k++)ans+=dp[1][j][k]*1LL*j%mod,ans%=mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 3840
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b = map(int, readline().split())
print("Yes" if a != 2 and b != 2 else "No")


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a < 1 || a > 9 || b < 1 || b > 9) {
            System.out.println(-1);
            return;
        }
        System.out.println(a * b);
    }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
const long long INFL=1LL << 60;
const long long INF=1<<29;

int main() {
    int N;
    cin >>N;
    int ans=0;
    vector<int> V(N);
    vector<int> C(N);
    for(int i=0;i<N;i++){
        cin >>V[i];
    }
    for(int j=0;j<N;j++){
        cin >>C[j];
    }
    for(int k=0;k<N;k++){
        if(V[k]-C[k]>0) ans+=V[k]-C[k];
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int A, B, M; cin >> A >> B >> M;
	int a[A], b[B];
	for(int i = 0; i < A; i++) cin >> a[i];
	for(int i = 0; i < B; i++) cin >> b[i];
	int x[M], y[M], c[M];
	for (int i = 0; i < M; i++)
	{
		cin >> x[i] >> y[i] >> c[i];
		x[i]--; y[i]--;
	}
	int mina = *min_element(a, a + A), minb = *min_element(b, b + B);
	int res = mina + minb;
	for (int i = 0; i < M; i++)
	{
		res = min(res, a[x[i]] + b[y[i]] - c[i]);
	}
	
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int a, b;
	cin >> a >> b;
	if (a > 8 || b > 8) cout << ":(\n";
	else cout << "Yay!\n";
}

Measured memory_bytes: 256