akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Here your code !

n = input()

A = []
for i in range(n):
    A.append(raw_input().split())

buil1 = [[0 for i in range(10)] for j in range(3)]
buil2 = [[0 for i in range(10)] for j in range(3)]
buil3 = [[0 for i in range(10)] for j in range(3)]
buil4 = [[0 for i in range(10)] for j in range(3)]

b = []
f = []
r = []
v = []

for i in range(n):
    b.append(int(A[i][0]))
    f.append(int(A[i][1]))
    r.append(int(A[i][2]))
    v.append(int(A[i][3]))
for i in range(n) :   
    if b[i] == 1:
         buil1[f[i]-1][r[i]-1] += v[i]
    elif b[i] == 2:
         buil2[f[i]-1][r[i]-1] += v[i]
    elif b[i] == 3:
         buil3[f[i]-1][r[i]-1] += v[i]
    elif b[i] == 4:
         buil4[f[i]-1][r[i]-1] += v[i]

                    
                        
for i in range(3):
    print"",
    for j in range(10):
        if j == 9 :
            print buil1[i][j]
        else :
            print buil1[i][j],
    
    
print"#"*20
for i in range(3):
    print"",
    for j in range(10):
        if j == 9 :
            print buil2[i][j]
        else :
            print buil2[i][j],
    
print"#"*20    
for i in range(3):
    print"",
    for j in range(10):
        if j == 9 :
            print buil3[i][j]
        else :
            print buil3[i][j],
    
print"#"*20    
for i in range(3):
    print"",
    for j in range(10):
        if j == 9 :
            print buil4[i][j]
        else :
            print buil4[i][j],
            
                        
    
                    

Measured memory_bytes: 6512
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int g(LL x)
{
  int res = 0;
  while (x > 0)
  {
    ++res;
    x /= 10;
  }
  return res;
}

int f(LL a,LL b)
{
  return max(g(a),g(b));
}

long long n;

int main()
{
  scanf("%lld",&n);
  int risan = INF;
  for (LL i = 1; i * i <= n; ++i) if (n % i == 0)
  {
    MIN(risan,f(i,n/i));
  }
  printf("%d\n",risan);
  return 0;
}










Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    String res = new String("NG");

    for (int i = a; i <= b; i++) {
      if (i % k == 0) {
        res = new String("OK");
        break;
      }
    }
    System.out.println(res);
    sc.close();
  }
}

Measured memory_bytes: 35776
n,m = map(int,input().split())
h = list(map(int, input().split()))
tmp=[0]*n
for _ in range(m):
    a,b=map(int, input().split())
    tmp[a-1]=max(tmp[a-1],h[b-1])
    tmp[b-1]=max(tmp[b-1],h[a-1])
ans=0
for i in range(n):
    if h[i]>tmp[i]:
        ans+=1

print(ans)

Measured memory_bytes: 20136
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 100000
vector<int> G[MAX];
int id[MAX],pa[MAX],dp[MAX],used[MAX];
void dfs(int v,int d){
  dp[v]=d;
  for(int i=0;i<(int)G[v].size();i++){
    dfs(G[v][i],d+1);
    pa[G[v][i]]=v;
  }
}
signed main(){
  int n;
  cin>>n;
  for(int i=0,k;i<n;i++){
    cin>>id[i]>>k;
    G[id[i]].resize(k);
    for(int j=0;j<k;j++){
      cin>>G[id[i]][j];
      used[G[id[i]][j]]=1;
    }
  }
  memset(pa,-1,sizeof(pa));
  for(int i=0;i<n;i++){
    if(!used[i]) dfs(i,0);
  }
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<pa[i]<<", depth = "<<dp[i];
    if(pa[i]<0) cout<<", root, [";
    else if(!G[i].size()) cout<<", leaf, [";
    else cout<<", internal node, [";
    for(int j=0;j<(int)G[i].size();j++){
      if(j) cout<<", ";
      cout<<G[i][j];
    }
    cout<<"]"<<endl;
  }
  return 0;
}




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

int main(){
    int N;cin>>N;
    vector<int>A(N);
    vector<int>B(N,0);
    for(int i=0;i<N-1;i++){
        cin>>A[i];
        A[i]--;
    }
    for(int i=0;i<N-1;i++){
        B[A[i]]+=1;
    }
    for(int i=0;i<N;i++){
        cout<<B[i]<<endl;
    }


}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;
 
int main() {
  ll N; cin >> N;
  string ans = "";

  while(N>0){
    N--;
    ans += 'a' + (N%26);
    N /= 26;
  }

  reverse(ALL(ans));
  cout << ans << endl;
}

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

using namespace std;

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int L;
	cin >> L;

	long double edge = (long double) L / 3.0;
	cout << setprecision(10) << fixed;
	cout << edge*edge*edge;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  lol ans = 0, nasu = 0;
  rep(i, s.size()){
    if(s[i] == 'W'){
      ans += nasu;
    } else {
      nasu ++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 720
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
struct edge { int to, cap, rev; };
int h, w, match[210];
char a;
vector<edge> vec[210];
bool used[210];
int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	for (edge& e : vec[v]) {
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				vec[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
signed main() {
	cin >> h >> w;
	int s1, s2, t1, t2;
	REP(i, h) {
		REP(j, w) {
			cin >> a;
			if (a == 'o') {
				vec[i].push_back({ h + j, 1,vec[h + j].size() });
				vec[h + j].push_back({ i, 1,vec[i].size() - 1 });
			}
			if (a == 'S') {
				s1 = i; s2 = h + j;
			}
			if (a == 'T') {
				t1 = i; t2 = h + j;
			}
		}
	}
	if (s1 == t1 || s1 == t2 || s2 == t1 || s2 == t2) {
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	while (true) {
		memset(used, 0, sizeof(used));
		int f = dfs(s1, t1, INF);
		if (!f)break;
		ans += f;
	}
	while (true) {
		memset(used, 0, sizeof(used));
		int f = dfs(s1, t2, INF);
		if (!f)break;
		ans += f;
	}
	while (true) {
		memset(used, 0, sizeof(used));
		int f = dfs(s2, t1, INF);
		if (!f)break;
		ans += f;
	}
	while (true) {
		memset(used, 0, sizeof(used));
		int f = dfs(s2, t2, INF);
		if (!f)break;
		ans += f;
	}
	cout << ans << endl;
}

Measured memory_bytes: 896
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end
def na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
def haf(h,w)
  if(h%2==0 or w%2 == 0)
    return [h*w/2,h*w/2]
  end
  if(h > w)
    return [h/2*w,(h+1)/2*w]
  else
    return [w/2*h,(w+1)/2*h]
  end
end
h,w = inp
samax = 9999999999
(1..(h-1)).each do |hh|
  tab = haf(h-hh,w)
  me = hh*w
  drf = [me,tab[0],tab[1]].max - [me,tab[0],tab[1]].min 
  samax = drf if(drf < samax)
end
(1..(w-1)).each do |ww|
  tab = haf(h,w-ww)
  me = h*ww
  drf = [me,tab[0],tab[1]].max - [me,tab[0],tab[1]].min 
  samax = drf if(drf < samax)
end
p samax
=begin
=end

Measured memory_bytes: 1916
package main

import "fmt"

func main() {
	var k, t int
	fmt.Scan(&k, &t)
	a := make([]int, t)
	t1 := 0
	for i := 0; i < t; i++ {
		fmt.Scan(&a[i])
		if t1 < a[i] {
			t1 = a[i]
		}
	}

	ans := (t1 - 1) - (k - t1)
	if ans < 0 {
		ans = 0
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    import core.stdc.stdlib;
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}

void main()
{
    auto A = scanElem;
  writeln(A/3);
}


Measured memory_bytes: 256
package main

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

func main() {
	var (
		In    = strings.Split(ReadLine(), " ")
		ab, _ = strconv.ParseFloat(In[0]+In[1], 64)
	)

	sq := math.Sqrt(ab)

	//整数か判定
	if float64(int(sq)) != sq {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}

}

/////////////////////////////////////////

func fln(format string, elements ...interface{}) {
	fmt.Printf(format+"\n", elements...)
}

var BufReader = bufio.NewReaderSize(os.Stdin, 1e6)

func ReadLine() string {
	a, _, _ := BufReader.ReadLine()
	return string(a)
}

func ReadLineInt() (result []int) {
	in := strings.Split(ReadLine(), " ")
	result = make([]int, 0, 2)
	for _, v := range in {
		t, _ := strconv.Atoi(v)
		result = append(result, t)
	}
	return
}

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

int r[]={-1,0,0,1}, l[]={0,1,-1,0};
int func(int a[10][10], int x, int y){
	if(a[x][y] != 1)return 0;
	a[x][y] = 0;
	for(int i = 0;i < 4;i++){
		for(int j = 1;j <= 3;j++){
			int xx = r[i]*j+x, yy = l[i]*j+y;
			if(0<xx&&xx<9&&0<yy&&yy<9)func(a, xx, yy);
		}
	}
}

int main(){
	string s;
	int n, x, y, sum, a[10][10];
	cin >> n;
	for(sum = 1;sum <= n;sum++){
		getline(cin, s);
		fill((int*)a, (int*)(a+10), -1);
		for(int i = 1;i <= 8;i++){
			cin >> s;
			for(int j = 1;j <= 8;j++)a[i][j] = s[j-1]-'0';
		}
		cin >> y >> x;
		func(a, x, y);
		
		cout << "Data " << sum << ":" << endl;
		for(int i = 1;i <= 8;i++){
			for(int j = 1;j <= 8;j++)cout << a[i][j];
			cout << endl;
		}
	}
	return 0;
}

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

int main() {

  long long  int N, K;
  cin >> N >> K;

  while(N>K) {
    N %= K;
  }

  while(N>K-N) {
    N=K-N;
  }
  
  cout << N << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out





int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int i,n,C;
    cin>>n>>C;
    int s,t,c;
    vector<int> v(1000000,0),w(1000000,0);
    rep(i,n){
        cin>>s>>t>>c;
        v[s]++;
        v[t+1]--;
    }
    for(i=1;i<w.size();i++){
        w[i]=w[i-1]+v[i];
    }
    int ans=0;
    for(i=0;i<w.size();i++){
        ans=max(ans,w[i]);
    }
    fin(min(ans,C));
//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<P,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll dp[3003][3003]={};
int n;
ll a[3003];
ll reg(int m,int s){
	if(dp[m][s]!=INF)return dp[m][s];
	if(s==n)return 0;
	ll res;
	if(s%2==0){
		res=max(a[m]+reg(m+1,s+1),a[m+n-s-1]+reg(m,s+1));
	}else{
		res=min(-a[m]+reg(m+1,s+1),-a[m+n-s-1]+reg(m,s+1));
	}
	return dp[m][s]=res;
}

int main() {
	cin>>n;
	rep(i,0,n+1){
		rep(j,0,n+1)dp[i][j]=INF;
	}
	rep(i,0,n)cin>>a[i];
	cout<<reg(0,0)<<endl;
	return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MOD = ((int)1e9)+7;
const int INF = (int)(1e9)+(int)(1e7);
const ll INFL = (ll)(1e17);
const double EPS = 1e-8;
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;

    if(a==b)cout << "Yes" << endl;
    else cout << "No" << endl;
    

}

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

int main() {
  int a,b;
  int kekka = 1;
  int cnt = 0;
  bool chk = true;
  
  cin >> a >> b;
  
  while(chk == true){
    // 超えていたら終了
    if(kekka >= b){
      chk = false;
      continue;
    }
    
    kekka = kekka + a - 1;
    cnt++;
  }
  
  cout << cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

struct BIT {
    int n;
    vector<ll> bit;
    BIT(int sz) { 
        n=1; while(n < sz) n*=2;
        bit.assign(n+1, 0); 
    }
    void update(int i, ll w) {
        for(int x=i+1; x<(int)bit.size(); x += x&-x) bit[x] += w;
    }
    // [0,i]
    ll query(int i) {
        ll ret = 0;
        for(int x=i+1; x>0; x -= x&-x) ret += bit[x];
        return ret;
    }
    // 合計がw以上の最小の位置
    int lower_bound(ll w) {
        int x = 0;
        for(int k=n; k>0; k>>=1) {
            if(x+k <= n && bit[x+k] < w) {
                w -= bit[x+k];
                x += k;
            }
        }
        return x;
    }
};

int main(void) {
    string s;
    cin >> s;
    const ll n = s.size();

    vector<ll> cnt(26);
    REP(i, n) cnt[s[i]-'a']++;

    ll ki = 0;
    REP(i, 26) if(cnt[i]%2) ki++;
    if(ki>=2) {
        cout << -1 << endl;
        return 0;
    }

    char mid = '?';
    string t = "";
    vector<ll> idx(26);
    REP(i, n) {
        if(cnt[s[i]-'a']%2 && idx[s[i]-'a'] == cnt[s[i]-'a']/2) {
            mid = s[i];
        } else if(idx[s[i]-'a'] < cnt[s[i]-'a']/2) {
            t += s[i]; 
        }
        idx[s[i]-'a']++;
    }
    string ans = t;
    if(n%2) ans += mid;
    reverse(ALL(t));
    ans += t;

    dump(ans);

    vector<ll> trans(n);
    vector<vector<ll>> pos(26);
    REP(i, n) pos[s[i]-'a'].push_back(i);
    idx.assign(26, 0);
    REP(i, n) {
        trans[pos[ans[i]-'a'][idx[ans[i]-'a']]] = i;
        idx[ans[i]-'a']++;
    }

    dump(trans);

    ll ret = 0;
    BIT bit(n);
    REP(i, n) {
        ret += i - bit.query(trans[i]);
        bit.update(trans[i], 1);
    }
    cout << ret << endl;

    return 0;
}

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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  int ave = round((double)accumulate(a.begin(), a.end(), 0) / N);
  ll res = 0;
  for(int i = 0; i < N; i++){
    res += (a[i] - ave) * (a[i] - ave);
  }
  cout << res << endl;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int X;
  
  X = (a * b) % 2;

	if (X == 0) {
    cout << "Even" << endl;
    }
	else {
      cout << "Odd" << endl;
    }
}

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

/// <summary>
/// todo:
/// https://atcoder.jp/contests/abc158/tasks/abc158_c
/// </summary>

namespace ABC_Training
{
    public class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ');
            var a = int.Parse(ab[0]);
            var b = int.Parse(ab[1]);
            var ans = -1;
            foreach (var x in Enumerable.Range(1, 1250))
            {
                var c = Math.Floor(x * 0.08);
                var d = Math.Floor(x * 0.1);
                if (a == c && b == d)
                {
                    ans = x;
                    break;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

#define MAXN 1001
#define INF 0x3f3f3f3f
typedef long long LL;

int n, x[MAXN];
int f[MAXN][5001], g[5001];
bool flag = true;
vector< int > adj[MAXN];

void Init()
{
    memset(f, 0x3f, sizeof(f));
    int i, v;
    scanf("%d", &n);
    for(i = 2; i <= n; ++i){
        scanf("%d", &v);
        adj[v].push_back(i);
    }
    for(i = 1; i <= n; ++i)
        scanf("%d", x + i);
}

void DFS(int u)
{
    f[u][0] = 0;
    for(auto &v: adj[u]){
        DFS(v);
        for(int i = 0; i <= x[u]; ++i) g[i] = INF;
        for(int i = 0; i <= x[u]; ++i){
            if(f[u][i] == INF)  continue;
            if(i + x[v] <= x[u])
                g[i + x[v]] = min(g[i + x[v]], f[u][i] + f[v][x[v]]);
            if(i + f[v][x[v]] <= x[u])
                g[i + f[v][x[v]]] = min(g[i + f[v][v[x]]], f[u][i] + v[x]);
        }
        for(int i = 0; i <= x[u]; ++i) f[u][i] = g[i];
    }
    for(int i = 0; i < x[u]; ++i) f[u][x[u]] = min(f[u][x[u]], f[u][i]);
    if(f[u][x[u]] == INF) flag = false;
}


int main()
{
    Init();
    DFS(1);
    printf("%s\n", flag ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 19840
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Main{
	static final Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream INS(int n){return REPS(n).map(i->getInt());}
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int n=getInt(),m=getInt();
		List<Integer>st=INS(n).boxed().collect(Collectors.toList());

		for(int k=1;k<=m;++k){
			for(int i=0;i<n-1;++i) {
				if(st.get(i)%k>st.get(i+1)%k)
					Collections.swap(st,i,i+1);
			}
		}
		
		st.forEach(System.out::println);
	}
}

Measured memory_bytes: 32488
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;
using P = pair<int64,int64>;

vector<vector<int>> grouping(const int& sep, const int& w, const vector<string>& s) {
    int h = __builtin_popcount(sep) + 1;
    vector<vector<int>> res(h, vector<int>(w,0));
    for (int i=0; i<w; i++) {
        int g = 0;
        for (int j=0; j<s.size(); j++) {
            res[g][i] += (s[j][i] == '1');
            if (sep>>j & 1) g++;
        }
    }
    return res;
}

int main() {
    int64 h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for (int64 i=0; i<h; i++) cin >> s[i];

    int64 ans = LONG_MAX;

    for (int64 i=0; i<(1<<(h-1)); i++) {
        int group = __builtin_popcount(i) + 1;

        // グループ毎に縦向きに計算しておく
        vector<vector<int>> gsum = grouping(i, w, s);

        int64 cnt = group - 1;
        vector<int> count(group);
        for (int j=0; j<w; j++) {
            for (int g=0; g<group; g++) {
                // 1列足して k より大きくなるならそもそもこの横分割はダメ
                if (gsum[g][j] > k) {
                    cnt = INT_MAX;
                    goto LOOP_EXIT;
                }

                // 1列足して k より大きくなるなら，ここで分割（和をリセット）
                if (count[g] + gsum[g][j] > k) {
                    cnt++;
                    for (int g=0; g<group; g++) count[g] = 0;
                    break;
                }
            }

            // グループ毎に計算しておく
            for (int g=0; g<group; g++) count[g] += gsum[g][j];
        }

        LOOP_EXIT:
        ans = min(ans, cnt);
    }

    cout << ans << endl;
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int plan1 = n * a;
  
  if (plan1 > b) {
    cout << b << endl;
  } else {
    cout << plan1 << endl;
  }

}

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

#define INF 1234567890
#define ll long long
#define MOD 998244353

int N, Q;
ll pw[270000], V[10][270000];
ll seg[530000], lazy[530000];

void Propagate(int n, int l, int r)
{
	if (lazy[n] != -1)
	{
		if (l != r)
		{
			lazy[n<<1] = lazy[n];
			lazy[n<<1|1] = lazy[n];
		}
		seg[n] = V[lazy[n]][r-l+1];
		lazy[n] = -1;
	}
}

ll Update(int L, int R, int val, int n, int l, int r)
{
	Propagate(n, l, r);
	if (r < L || R < l) return seg[n];
	if (L <= l && r <= R)
	{
		lazy[n] = val;
		Propagate(n, l, r);
		return seg[n];
	}
	int mid = l+r>>1;
	ll le = Update(L, R, val, n<<1, l, mid);
	ll ri = Update(L, R, val, n<<1|1, mid+1, r);
	return seg[n] = (le*pw[r-mid]+ri)%MOD;
}

int main()
{
	memset(lazy, -1, sizeof(lazy));

	pw[0] = 1;
	for(int i=1; i<270000; i++)
	{
		pw[i] = pw[i-1] * 10 % MOD;
		for(int k=0; k<10; k++)
		{
			V[k][i] = (V[k][i-1]*10 + k) % MOD;
			// V[9][3] = 999
		}
	}

	scanf("%d %d", &N, &Q);
	Update(1, N, 1, 1, 1, N);
	while(Q--)
	{
		int L, R, D;
		scanf("%d %d %d", &L, &R, &D);
		Update(L, R, D, 1, 1, N);
		printf("%lld\n", seg[1]);
	}
	return 0;
}

Measured memory_bytes: 35272
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
using namespace std;

int main() {
  int n;
  cin>>n;
  fr(i,0,101) {
    fr(j,0,101) {
      if(4*i+7*j==n) {
        cout<<"Yes";
        return 0;
      }
    }
  }
  cout<<"No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

signed main()
{
    int N,X; cin>>N>>X;

    int ans=0;
    REP(i,N){
        int x; cin>>x;
        ans=gcd(ans,abs(x-X));
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
fun main(args: Array<String>) {

    val N = readLine()!!.toInt()
    val S = readLine()!!

    var ans = 1
    for (i in 0 until N) {
        if (i == N - 1) break
        if (S[i] != S[i + 1]) ans++
    }

    println(ans)
}

Measured memory_bytes: 34364
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin>>N;
    vector<long> stick(N);

    for(auto &x:stick){
        cin>>x;

    }

    sort(stick.rbegin(),stick.rend());

    vector<long> wh;
    long check=stick[0];
    for(int i=1;i<N;++i){
        if(check==stick[i]){
            wh.emplace_back(check);
            check=0;
        }else{
            check=stick[i];
        }
        if(wh.size()==2){
            break;
        }    
    }
    if(wh.size()<2){
        cout<<0<<endl;
        return 0;
    }
    cout<<wh[0]*wh[1]<<endl;

    return 0;
}




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

int main()
{
    string a, b, c;
    cin>>a>>b>>c;

    auto f = [&](string x, string y)
    {
        set<int> S;
        for (int d=-(int)y.size()+1; d<=(int)x.size()-1; d++)
        {
            bool ok = true;
            for (int i=max(0, d); i<(int)min(x.size(), y.size()+d); i++)
                if (x[i]!='?' && y[i-d]!='?' && x[i]!=y[i-d])
                    ok = false;
            if (ok)
                S.insert(d);
        }
        return S;
    };

    set<int> ab = f(a, b);
    set<int> ac = f(a, c);
    set<int> bc = f(b, c);
    int an = (int)a.size();
    int bn = (int)b.size();
    int cn = (int)c.size();

    int ans = an+bn+cn;
    for (int d1=-bn-cn; d1<=an+cn; d1++)
        if (d1<=-bn || an<=d1 || ab.count(d1)>0)
            for (int d2=-bn-cn; d2<=an+bn; d2++)
                if ((d2<=-cn || an<=d2 || ac.count(d2)>0) &&
                    (d2-d1<=-cn || bn<=d2-d1 || bc.count(d2-d1)>0))
                    ans = min(ans, max({an, d1+bn, d2+cn})-min({0, d1, d2}));
    cout<<ans<<endl;
}


Measured memory_bytes: 512
def gen_graph(input_list):
    graph = {}

    for item in input_list:
        if not item[0] in graph:
            graph[item[0]] = {}
        if not item[1] in graph:
            graph[item[1]] = {}
        graph[item[0]][item[1]] = item[2]
        graph[item[1]][item[0]] = item[2]

    return graph


def get_lowest_cost_vertex(costs, processed):
    lowest_cost = float("inf")
    lowest_cost_node = None
    for node in costs:
        cost = costs[node]
        if cost < lowest_cost and node not in processed:
            lowest_cost = cost
            lowest_cost_node = node
    return lowest_cost_node


def get_best_routes(graph, start):
    costs = {}
    parents = {}
    processed = []

    costs[start] = 0
    parents[start] = None
    processed.append(start)

    for item in graph[start].keys():
        costs[item] = graph[start][item]
        parents[item] = start

    for item in graph.keys():
        if not (item in costs.keys() or item == start):
            costs[item] = float("inf")
            parents[item] = None

    node = get_lowest_cost_vertex(costs, processed)

    while node is not None:
        cost = costs[node]
        neighbors = graph[node]

        for n in neighbors.keys():
            new_cost = cost + neighbors[n]
            if costs[n] > new_cost:
                costs[n] = new_cost
                parents[n] = node
        processed.append(node)
        node = get_lowest_cost_vertex(costs, processed)

    routes = []
    for item in graph.keys():
        if item != start:
            route = []
            route.append(item)
            parent = parents[item]
            while 1:
                route.append(parent)
                if parent == start:
                    break
                parent = parents[parent]
            route.reverse()
            routes.append(route)
    return routes


def main(vertex_count, input_list):
    graph = gen_graph(input_list)

    routes = []
    for start in range(1, vertex_count+1):
        for route in get_best_routes(graph, start):
            routes.append(route)

    route_sides = []
    for route in routes:
        for i, vertex in enumerate(route):
            if i == len(route)-1:
                break
            route_side = [route[i], route[i+1]]
            route_side_sorted = sorted(route_side)
            if not route_side_sorted in route_sides:
                route_sides.append(route_side_sorted)

    sides = []
    for item in input_list:
        side = [item[0], item[1]]
        side_sorted = sorted(side)
        sides.append(side_sorted)

    count = 0
    for side in sides:
        if not side in route_sides:
            count += 1

    return count


if __name__ == "__main__":
    input_1 = input()
    vertex_count, sides_count = list(map(int, input_1.split()))
    input_list = []
    for _ in range(sides_count):
        vertex_1, vertex_2, distance = list(map(int, input().split()))
        input_list.append((vertex_1, vertex_2, distance))
    print(main(vertex_count, input_list))


Measured memory_bytes: 51036
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
using namespace std;


int main()
{
  ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  ll n;
  cin>>n;
  cout<<a[n-1]<<endl;
}


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

ll solve(){
    ll n,x,d;
    cin >> n >> x >> d;
    if (d == 0) {
        return x == 0 ? 1 : n+1;
    }
    if (d < 0) {
        x = -x;
        d = -d;
    }
    map<ll, vector<pair<ll,ll>>> seg;
    for (ll k = 0; k <= n; k++) {
        seg[k*x % d].push_back({
            k*x + d*(k-1)*k/2,
            k*x + d*(2*n-k-1)*k/2
        });
    }
    ll res = 0;
    for (auto itr : seg) {
        vector<pair<ll,ll>> &v = itr.second;
        sort(all(v));
        ll l = v[0].first;
        ll r = v[0].second;
        rep1(i, (int)v.size()-1) {
            if (r < v[i].first) {
                res += (r-l)/d+1;
                l = v[i].first;
                r = v[i].second;
            } else {
                r = max(r, v[i].second);
            }
        }
        res += (r-l)/d+1;
    }
    return res;
}

int main(void){
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 22144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    vvin c(3,vin(3));
    rep(i,3)rep(j,3)cin>>c[i][j];
    if(c[0][0]-c[1][0]==c[0][1]-c[1][1]&&c[0][1]-c[1][1]==c[0][2]-c[1][2]&&
    c[1][0]-c[2][0]==c[1][1]-c[2][1]&&c[1][1]-c[2][1]==c[1][2]-c[2][2]&&
    c[0][0]-c[0][1]==c[1][0]-c[1][1]&&c[1][0]-c[1][1]==c[2][0]-c[2][1]&&
    c[0][1]-c[0][2]==c[1][1]-c[1][2]&&c[1][1]-c[1][2]==c[2][1]-c[2][2])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3588
from itertools import zip_longest

if __name__ == '__main__':

	int(input())
	A = list(map(int,input().split()))
	int(input())
	B = list(map(int,input().split()))

	win = 0
	for a,b in zip_longest(A,B,fillvalue=-1):
		if a < b:
			win = 1
			break
		elif a > b:
			win = 0
			break

	print(win)



Measured memory_bytes: 5776
#include<iostream>
#include<cstdio>
using namespace std;
const int N=505;
const int MOD=1000000007;
int n,m;
int c[N];
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
long long fac[N],inv[N];
void init(int n=500)
{
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%MOD;
	inv[n]=ksm(fac[n],MOD-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=inv[i]*i%MOD;
	return;
}
long long C(int n,int m)
{
	if(m>n) return 0;
	else return fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}
long long f[N][N][N];
int main()
{
	init();
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		c[x]++;
	}
	f[m+1][0][0]=1;
	for(int i=m;i>=1;i--)
		for(int j=0;j<=m;j++)
			for(int k=i*j;k<=m;k++)
			{
				long long mul=ksm(k-(i-1)*j,c[i])%MOD;
				for(int l=0;l<=min(j,k/i);l++)
					f[i][j][k]=(f[i][j][k]+f[i+1][j-l][k-i*l]*inv[l]%MOD*mul%MOD)%MOD;
			}
	long long ans=0;
	for(int j=0;j<=m;j++)
		for(int k=j;k<=m;k++)
		{
			long long res=C(m-k+1,j)*fac[j]%MOD*f[1][j][k]%MOD;
			if((m-k)&1) ans=(ans-res+MOD)%MOD;
			else ans=(ans+res)%MOD;
		}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 20368
a,b=map(int,input().split())

def prime(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n=n//i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

print(len(list(set(prime(a)).intersection(set(prime(b)))))+1)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
bool s[55555];

void sosuu(int n){
  memset(s,true,sizeof(s));
  s[0] = s[1] = false;
  for(int i = 2; i*i <= n; i++){
    if(!s[i]) continue;
    for(int j = i*2; j <= n; j += i){
      s[j] = false;
    }
  }
}

int main(void)
{
  sosuu(50005);
  while(1){
    int n;
    cin >> n;
    if(!n) break;

    int ret = 0;
    for(int i = 2; i <= n / 2; i++){
      if(s[i] && s[n-i]) ret++;
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1220
from math import ceil

N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]

def enough(t):
    cnt = 0
    
    for hp in h:
        cnt += ceil(max(0, (hp - B * t)/(A-B)))
        
    if cnt <= t:
        return True
    else:
        return False

high = ceil(max(h) / B)
low = 0

while high - low > 0:
    mid = (high + low) // 2
    if enough(mid):
        high = mid
    else:
        low = mid + 1

print(low)

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

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    bool win = false;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] % 2 == 1) win = true;
    }
    if(win){
        cout << "first" << endl;
    }else{
        cout << "second" << endl;
    }
    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
 
  char c;
  int i;
  cin >> c;

  
  if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u'){
   
      cout << "vowel" << endl;
    }else {
   
      cout << "consonant" << endl;
  }
  
     
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 200001
typedef long long ll;

int a[N];
int main()
{
    int n, ans = 0;
    int i, j;
    scanf("%d", &n);
    for(i = 0; i < n; i++) 
    {
        scanf("%d", &a[i]);
        ans ^= a[i];
    }
    for(i = 0; i < n; i++)
        printf("%d ", ans^a[i]);

    return 0;
}

Measured memory_bytes: 3204
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let n: i64 = get();
    let a: i64 = get();
    let b: i64 = get();
    let b = b - a;
    if n == 1 {
        println!("{}", if b == 0 { 1 } else { 0 });
    } else {
        println!("{}", if b >= 0 { b * (n - 2) + 1 } else { 0 });
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long> vll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpll;

#define F first
#define S second
#define PB push_back
#define MP make_pair

int main() {
    ll n, k, t = 0LL;
    cin >> n >> k;
    n = n + 1LL;

    while (k <= n) {
        t += (n - k) * k + 1;
        t %= 1000000007LL;
        k++;
    }

    cout << t << "\n";

    return 0;
}


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


int main(){
  int n,m;
  cin>>n>>m;
  int a[100][100];
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++) cin>>a[i][j];

  int b[100];
  for(int i=0;i<m;i++) cin>>b[i];
  int c[100] = {};
  for(int i=0;i<n;i++)
   for(int j=0;j<m;j++) c[i] += a[i][j] * b[j];
 
 for(int i=0;i<n;i++) cout<<c[i]<<endl;

 return 0;
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b; cin >> a >> b;
    string s; cin >> s;

    bool jud = true;

    if(s[a] != '-') jud = false;

    rep(i,a+b+1){
        if(i == a) continue;

        if(!('0' <= s[i] && s[i] <= '9')) jud = false;
    }

    if(jud)  cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

	for (int i = 1; i <= x; ++i) {
		if (i * (i + 1) >= 2 * x) {
			dunk(i);
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s int
	fmt.Scan(&s)

	v := int(1e9)
	x := (v - s%v) % v
	y := (s + x) / v
	fmt.Printf("0 0 1000000000 1 %d %d\n", x, y)
}

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

int main() {
	// your code goes here
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n,r;
	cin>>n>>r;
	if(n>=10)
	cout<<r;
	else
	{
	    cout<<r+(100*(10-n));
	}
	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/
#include <bits/stdc++.h>

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

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

vector<vector<int>> dp;
char solve(const string& s, int& r, int& c, int target) {
    if (r > 0 && dp[r - 1][c] == target) {
        r -= 1;
        return solve(s, r, c, target);
    } else if (c > 0 && dp[r][c - 1] == target) {
        c -= 1;
        return solve(s, r, c, target);
    } else {
        return s[c-1];
    }
}

int main() {
    string s, t;
    cin >> s >> t;
    int rows = s.length() + 1;
    int cols = t.length() + 1;

    dp.resize(rows, vector<int>(cols, 0));

    for (int i = 0; i < rows - 1; i++) {
        for (int j = 0; j < cols - 1; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }

    // rep(i, rows) {
    //     rep(j, cols) { printf("%d ", dp[i][j]); }
    //     cout << endl;
    // }
    // cout << endl;

    int r = rows - 1;
    int c = cols - 1;
    int target;
    string ans;

    target = dp[r][c];
    while (target > 0) {
        char ch = solve(t, r, c, target);
        ans += ch;
        target -= 1;
        r -= 1;
        c -= 1;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35584
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();

    let mut x: usize = 1;
    let mut a: usize = 0;
    let mut b: usize = 0;
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let v: Vec<usize> = s.trim().split(' ').map(|x| x.parse().unwrap()).collect();
        let mut y = v[0] + v[1];
        let mut i: usize = std::cmp::max(x/y, std::cmp::max(a/v[0], b/v[1]));
        while y*i < x || v[0]*i < a || v[1]*i <b {i += 1;}
        x = y*i;
        a = v[0]*i; b = v[1]*i;
    }
    println!("{}", x);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    string S;
    cin >> S;
    i32 min = N + 1;
    i32 r = 0, w = 0;
    for (i32 i = 0; i < N; i++) {
        if (S[i] == 'W') w++;
        else if (S[i] == 'R') r++;
    }
    if (w == N || r == N) {
        cout << 0 << endl;
        return;
    }
    r = 0; w = 0;
    for (i32 i = 0; i < N; i++) {
        if (S[i] == 'R') r++;
    }
    for (i32 sep = 0; sep < N; sep++) {
        if (S[sep] == 'W') w++;
        else if (S[sep] == 'R') r--;
        if (min > max(r, w)) min = max(r, w);
    }
    cout << min << endl;
}


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

int main() {
	int a,b;
	cin >> a >> b;
	if(a < b){
		cout << "a < b" << endl;
	}
	else if(a > b){
		cout << "a > b" << endl;
	}
	else{
		cout << "a == b" << endl;
	}
	return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

using namespace std;
using ll = long long;
using ii = pair<int,int>;

constexpr int MAXN = 5 + 200000;

ll solve(ll a, ll b, ll x) {
  return ((a*x)/b) - (a*(x/b));
}

ll n,a,b;
ll solve(const vector<ll>& v) {
  ll ans = 0LL;
  for (auto x : v) {
    if (x >= 0 && x <= n) {
      ans = max(ans, solve(a,b,x));
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> a >> b >> n;
  ll k = (n/b)*b;
  cout << solve({n, k, k-1}) << '\n';
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int H, W;
    cin >> H >> W;
    string C[100];
    for (int i = 0; i < H; i++) {
        cin >> C[i];
    }
    for (int i = 0; i < H; i++) {
        cout << C[i] << endl;
        cout << C[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256