akhauriyash/Code-Regression huggingface dataset:
/*#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
*/

/*
ID: febrian3 
LANG: C++11 
PROB: task 
*/

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(x) cerr<<#x<<": "<<(x)<<'\n'
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f;
const ll nax = 0;
string a, b;
int mins=inf;

int main(){
		/*freopen("filename.in","r",stdin); 
		freopen("filename.out","w",stdout);*/ 
		IOS	
		cin >> a >> b;
		int c=a.length(), d=b.length();
		for(int i=0;i+d-1<c;++i){
			int cur=0, tmp=i;
			for(int j=0;j<d;++j){
				if(a[tmp]==b[j]) cur++;
				tmp++;
			}
			mins=min(mins, d-cur);
		}
		cout << mins << '\n';
	}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
char a[105], b[105];
int main()
{
    scanf("%s%s", a, b);
    if (strlen(a) > strlen(b)) printf("GREATER\n");
    else if (strlen(a) < strlen(b)) printf("LESS\n");
    else {
        if (strcmp(a, b) > 0) printf("GREATER\n");
        else if (strcmp(a, b) < 0) printf("LESS\n");
        else printf("EQUAL\n");
    }
    return 0;
}


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

// ------ graph ------ //
using Weight = long long;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator[](int v) { return adj[v]; }
    const Edges operator[](int v) const { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;
using UnweightedGraph = vector<vector<int>>;

// ------ Diameter of a tree ------ //
namespace Double_Sweep {
    using Result = pair<Weight, int>;
    Result visit(const Graph &g, int u, int p = -1) {
        Result r(0, u);
        for (Edge e: g[u]) if (e.dst != p) {
            Result t = visit(g, e.dst, u);
            t.first += e.weight;
            if (r.first < t.first) r = t;
        }
        return r;
    }
    Weight diameter(const Graph &g) {
        Result u = visit(g, 0);
        Result v = visit(g, u.second);
        return v.first;
    }
};

int main() {
    int n; cin >> n;
    Graph G(n);
    while (--n) {
        int s, t, w; cin >> s >> t >> w;
        G.add_edge(s, t, w);
    }
    cout << Double_Sweep::diameter(G) << endl;
}


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

int main(int argc, const char * argv[]) {
    int a,b,c,d=0,e=0,num;
    cin>>a>>b;
    num=b;
    
    while(num!=0){
        num /= 10;
        d++;
    }
    c=a*pow(10,d)+b;
    
    for(int i=0;i*i<=c;i++){
        if(i*i==c){
            e=1;
            break;
    }
    }
    if(e==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {
    int n, k;
    long long count = 0;
    cin >> n >> k;
    vector<long long> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    if (n <= k) {
        cout << "0" << endl;
        return 0;
    }
    sort (h.begin(), h.end());
    for (int i = 0; i < k; i++) {
        h.pop_back();
    }
    for (int i = 0; i < h.size(); i++) {
        count += h.at(i);
    }
    cout << count << endl;
}


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

#define ll long long int
#define str string
#define sec .second

ll MOD = 1000000007,INFL = 1ll << 60,INF = 1 << 30;
ll A[100][100] = {};
ll X[1000000] = {};
ll rui[100002] = {},ruin[100002] = {};
int dy[]={0, 0, 1, -1},dx[]={1, -1, 0, 0};
vector <ll> v;
ll a = 0,b = 0,c = 0,n = 0,sum = 0, max = INF,mi=-1;
pair<str,ll> S[1000];
bool an = false,bn = false;

int findDigits(int n) {
        int i = 0;
        while (n > 0) {

                X[i] = n%10;
                n /= 10;
                i++;
        }
        return i;
}


int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        //Code Line
cin >> n;
cout << (n - 2) * 180 << endl;


  //Code Line
        return 0;
}


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

using namespace std;

int main(void) {
	
	int s;
	cin >>s;
	
	int a[100000],i=0,j,m=0;
	while (1) {
		if (i==0) {
			a[i]=s;
		} else {
			if (a[i-1]%2==0) {
				a[i]=a[i-1]/2;
			} else {
				a[i]=3*a[i-1]+1;
			}
			for (j=0 ; j<i ; j++) {
				if (a[i]==a[j]) {
					m=i+1;
					break;
				}
			}
		}
		if (m>0) break;
		i++;
	}
	
	cout <<m <<endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int count_fox_number(ll a, ll b){
  if(a < 2) a = 2;
  if(!(a < b)) return 0;
  int ans = b - a;
  bool prime_small[1000100] = {};
  //for(int i = 2; (ll) i * i < b; i++) prime_small[i] = true;
  int cnt_pow[1000100];
  REP(i, b - a) cnt_pow[i] = INF;
  for(int i = 2; (ll)i * i < b; i++){
    if(!prime_small[i]){
      for(int j = 2 * i; (ll) j * j < b; j += i) prime_small[j] = true;
      for(ll j = max(2LL, (a + i - 1)/i) * i; j < b; j += i){
        if(cnt_pow[j - a] == -1) continue;
        ll t = j;
        int cnt = 0;
        while(t % i == 0){
          t /= i;
          cnt++;
        }
        assert(cnt != 0);
        if(cnt_pow[j - a] < cnt){
          cnt_pow[j - a] = -1;
          ans--;
        }else{
          cnt_pow[j - a] = cnt;
        }
      }
    }
  }
  return ans;
}

int main(){
  ll a, b;
  while(cin>>a>>b){
    cout<<count_fox_number(a - b, a + b + 1)<<endl;
  }
  return 0;
}

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

class Program {
    static void Main() {
        Scanner cin = new Scanner();
        int N = cin.Int();
        int M = cin.Int();
        var P = new int[M];
        var Y = new int[M];
        for (int i = 0; i < M; i++) {
            P[i] = cin.Int();
            Y[i] = cin.Int();
        }

        var info = new List<Info>();
        for (int i = 0; i < M; i++) {
            info.Add(new Info { Prep = P[i], Year = Y[i] });
        }

        foreach (var prep in info.GroupBy(x => x.Prep)) {
            int x = 1;
            foreach (var year in prep.OrderBy(y => y.Year)) {
                year.ans = year.Prep.ToString("D6") + x.ToString("D6");
                x++;
            }
        }

        foreach (var x in info) {
            Console.WriteLine(x.ans);
        }
        Console.ReadLine();
    }
}

class Info {
    public int Prep { get; set; }
    public int Year { get; set; }
    public string ans { get; set; }
}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 38792
/*
CF ID: Ankit717
LANG: C++
*/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define mod 1000000007
#define maxn 200005
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb push_back
#define pf push_front
#define nl cout << "\n";

const ll INF=1e9L+5;
 
struct Data{
	ll p;
	ll h;
};

void ini(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pll &a,pll &b){
	if(a.first==b.first){
		return a.second>b.second;
	}else{
		return a.first<b.first;
	}
}

// vector<pll> adj[maxn];
// vector<ll> par;
// vector<bool> vis;

ll gcd(ll a,ll b){
    while(a!=0){
        ll temp=a;
        a = b % a;
        b = temp;
    }

    return b;
}

// bool prime[maxn],near[maxn];
// void sieve(){
// 	f(i,0,maxn+1){
// 		prime[i]=true;
// 	}
// 	prime[0]=falsrime[1]=false;
// 	for(ll i=2;i*i<=maxn;i++){
// 		if(prime[i]){
// 			for(j=i*i;j<=maxn;j+=i){
// 				prime[j]=false;
// 			}
// 		}
// 	}
// }

ll x[24]={1,-1,0,0,1,1,-1,-1,2,2,-2,-2,0,0,-2,2,2,2,-1,1,-2,-2,-1,1};
ll y[24]={0,0,1,-1,1,-1,1,-1,2,-2,2,-2,2,-2,0,0,-1,1,2,2,-1,1,-2,-2};

void solve(){
	ll h,w;
	cin >> h >> w;

	ll ch,cw;
	cin >> ch >> cw;
	ch--;cw--;
	
	ll dh,dw;
	cin >> dh >> dw;
	dh--;dw--;
	
	string s[h];
	f(i,0,h){
		cin >> s[i];
	}


	ll dis[h][w];
	//memset(dis,INF,sizeof(dis));

	f(i,0,h){
		f(j,0,w){
			dis[i][j]=INF;
			//cout << dis[i][j]<<" ";
		}
	}


	deque<pll> q;
	q.pf({ch,cw});
	dis[ch][cw]=0;
	pll p;

	while(!q.empty()){
		p=q.front();
		q.pop_front();

		ll lx=p.first,ly=p.second;
		for(ll i=0;i<4;i++){
			if(lx+x[i]<h && ly+y[i]<w && lx+x[i]>=0 && ly+y[i]>=0){
				if(dis[lx][ly]<dis[lx+x[i]][ly+y[i]] && s[lx+x[i]][ly+y[i]]=='.'){
					q.pf({lx+x[i],ly+y[i]});
					dis[lx+x[i]][ly+y[i]]=dis[lx][ly];
				}
			}
			
		}

		for(ll i=4;i<24;i++){
			if(lx+x[i]<h && ly+y[i]<w && lx+x[i]>=0 && ly+y[i]>=0){
				if(dis[lx][ly]+1<dis[lx+x[i]][ly+y[i]] && s[lx+x[i]][ly+y[i]]=='.'){
					q.pb({lx+x[i],ly+y[i]});
					dis[lx+x[i]][ly+y[i]]=dis[lx][ly]+1;
				}
			}
			
		}

	}

	if(dis[dh][dw]!=INF && s[dh][dw]!='#'){
		cout << dis[dh][dw];
	}else{
		cout << -1;
	}
}	

int main(){
	ini();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
    
	// ll t;
	// cin >> t;
	// f(i,0,t){
		solve();
	//}
}


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

using namespace std;

long long N, A, B;

int main(){
    cin >> N >> A >> B;
    
    if(A>B){
        cout << 0 << endl;
        return 0;
    }
    if(N==1){
        if(A==B) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    
    long long max, min;
    min = (N-1)*A + B;
    max = A + (N-1)*B;
    cout << max-min+1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common
#import math
#import sympy

N = int(input())
#H,W,K= map(int,input().split())
A = list(map(int,input().split()))
#S = str(input())
#T = str(input())
A.sort(reverse=True)
ans=0
num=0
c=1
for i in range(N-1):
    ans+=A[num]
    #print(ans)
    c+=1
    if c==2:
        num+=1
        c=0
print(ans)


Measured memory_bytes: 31524
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll n, k ;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    
    if (n <= k) {
        put(0);
        return 0;
    }

    sort(all(h));

    ll sum = 0;
    rep(i, h.size() - k) sum += h[i];
    put(sum);
    
    return 0;
}

Measured memory_bytes: 4740
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n, a;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        a = sc.nextInt();
        solve();
    }

    void solve() {
        int remain = n % 500;
        if (a >= remain) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 23124
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace Vertial
{
    class Program
    {
        static void Main(string[] args)
        {
            var NMQ = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var N = NMQ[0]-1;
            var M = NMQ[1]-1;
          Console.WriteLine(N*M);
        }
   }
}


Measured memory_bytes: 11220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int sx = scan.nextInt();
		int sy = scan.nextInt();
		int tx = scan.nextInt();
		int ty = scan.nextInt();
        int up = ty - sy;
        int right = tx - sx;
		for(int i= 0;i<up;i++) {
			System.out.print("U");
		}
		for(int i= 0;i<right;i++) {
			System.out.print("R");
		}
		for(int i= 0;i<up;i++) {
			System.out.print("D");
		}
		for(int i= 0;i<right;i++) {
			System.out.print("L");
		}
		System.out.print("L");
		for(int i= 0;i<up+1;i++) {
			System.out.print("U");
		}
		for(int i= 0;i<right+1;i++) {
			System.out.print("R");
		}
		System.out.print("D");
		System.out.print("R");
		for(int i= 0;i<up+1;i++) {
			System.out.print("D");
		}
		for(int i= 0;i<right+1;i++) {
			System.out.print("L");
		}
		System.out.print("U");
	}

}


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

int main(){
	char s[3],a,b,c;
	a = 0;
	b = 0;
	c = 0;
	cin >> s;

	for(int i = 0;i < 3;i++){
		switch(s[i]){
			case 'a':
				a = 1;
				break;
			case 'b':
				b = 1;
				break;
			case 'c':
				c = 1;
				break;
		}
	}

	if(a*b*c){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;

const int N = 100010;

int h[N], e[N], ne[N];
int idx, n;
int deg[N];
int dist[N];
queue<int> temp;
vector<int> res;

void add(int a, int b){
    e[idx] = b;
    ne[idx] = h[a];
    h[a] = idx ++;
    deg[b] ++;
}

void topsort(){
    for(int i = 1; i <= n; i ++){
        if (deg[i] == 0) temp.push(i);
    }
    while(!temp.empty()){
        int node= temp.front();
        temp.pop();
        res.push_back(node);
        for(int j = h[node]; j != -1; j = ne[j]){
            dist[e[j]] = max(dist[e[j]], dist[node] + 1);
            if (--deg[e[j]] == 0) temp.push(e[j]);
        }
    }
}

int main(){
    memset(h, -1, sizeof h);
    int m;
    int a, b;
    cin >> n >> m;
    while (m --){
        cin >> a >> b;
        add(a, b);
    }
    topsort();
    int res = 0;
    for(int i = 1; i <= n; i ++) {
        res = max(res, dist[i]);    
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3016
import Data.Array.IO
import Control.Monad

type Memo = IOUArray Int Int

main = do
  n <- readLn :: IO Int
  table <- newArray (1, n) 0 :: IO Memo
  writeArray table 1 2
  prime table 1 n [i | i <- [3..n], odd i == True]
  pList <- filter (/=0) <$> getElems table
  count <- newArray (1, length pList) 0 :: IO Memo
  foldM (divisor pList 1) count [2..n]
  cList <- map (+1) . filter (/=0) <$> getElems count
  if n == 1 then print 1
            else print $ foldl1 (\x y -> mod (x * y) $ 10^9+7) cList

count :: [Int] -> Int -> Int
count nums n = length $ filter ((==0) . mod n) nums

prime :: Memo -> Int -> Int -> [Int] -> IO Memo
prime table pn n []     = return table
prime table pn n x@(i:is) = do
  if i^2 <= n
    then do
      writeArray table (pn+1) i
      let is' = filter ((/=0) . flip mod i) is
      prime table (pn+1) n is'
    else do
      let len = length x
          idx = [pn+1..pn+len]
      prime' $ zip idx x
      return table
            where prime' :: [(Int, Int)] -> IO Memo
                  prime' [] = return table
                  prime' ((i, n):ss) = do
                    writeArray table i n
                    prime' ss

divisor :: [Int] -> Int -> Memo -> Int -> IO Memo
divisor [] _ memo _ = return memo
divisor _  _ memo 1 = return memo
divisor p  i memo n
  | mod n (p !! (i-1)) == 0 = do
    c <- readArray memo i
    writeArray memo i $ c + 1
    divisor p 1 memo $ div n (p !! (i-1))
  | otherwise    = divisor p (i+1) memo n


Measured memory_bytes: 1020
W, H, N = map(int, input().split())
zahyo = [list(map(int, input().split())) for _ in range(N)]
grid = [["w" for __ in range(W)] for ___ in range(H)]


def paint(h=range(H), w=range(W)):
    for i in h:
        for j in w:
            grid[i][j] = "b"


for xya in zahyo:
    if xya[2] == 1:
        paint(w=range(xya[0]))
    elif xya[2] == 2:
        paint(w=range(xya[0], W))
    elif xya[2] == 3:
        paint(h=range(xya[1]))
    elif xya[2] == 4:
        paint(h=range(xya[1], H))
print(sum(grid, []).count("w"))


Measured memory_bytes: 3392
#!/usr/bin/env python3


def solve(N, ss):
    d = dict()
    for s in ss:
        s = ''.join(sorted(s))
        if s in d:
            d[s] += 1
        else:
            d[s] = 1

    ans = 0
    for s, num in d.items():
        if num >= 2:
            ans += (num * (num-1)) // 2

    return ans


if __name__ == '__main__':
    N = int(input())
    ss = [input() for _ in range(N)]

    ans = solve(N, ss)

    print(ans)


Measured memory_bytes: 24980
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  for (i64 i = 0; i <= 50000; i++)
    if ((i64)(i * 1.08) == n)
    {
      cout << i << endl;
      return 0;
    }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}


int i_gcd(int a, int b);
int i_gcd(int a, int b) {
	if (!b)return a;
	return i_gcd(b, a % b);
}
int i_lcm(int a, int b);
int i_lcm(int a, int b) {
	return (a * b) / i_gcd(a, b);
}

// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}

//同じものの最初の文字をNULLにして降順
int _sort(const void* a, const void* b);
int _sort(const void* a, const void* b) {
	char rc;

	rc = strcmp((char*)b, (char*)a);
	if (rc == 0) {
		*(char*)a = 0x00;
		return(1);
	}
	return(rc);
}


#pragma endregion


// 060 B - Choose Integers
#define MAX 100000
int main(void) {
	ll a,b,c,i=1,mod=-1,fmod;

	scanf("%lld %lld %lld", &a,&b,&c);
	fmod = a % b;

	while (1) {
		mod = (a * i) % b;
		if (mod == c) {
			printf("YES\n"); break;
		}
		if (mod == fmod && i!=1) {
			printf("NO\n"); break;
		}
		i++;
	}

	return 0;
}






Measured memory_bytes: 2056
#include <iostream>
#include <algorithm>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

std::string a, b;

int main()
{
  std::cin >> a >> b;

  std::string s, t;

  rep( i, b[0]-'0' )
    s += a;
  
  rep( i, a[0]-'0' )
    t += b;

  std::cout << std::min(s,t) << std::endl;

  return 0;
}

Measured memory_bytes: 256
S = input()

if S == "SUN":
    print(7)
elif S =="MON":
    print(6)
elif S =="TUE":
    print(5)
elif S =="WED":
    print(4)
elif S =="THU":
    print(3)
elif S =="FRI":
    print(2)
elif S =="SAT":
    print(1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
// 287644PV
#define FIXED_FLOAT(x) std::fixed <<std::setprecision(6)<<(x)
const int mod = 1000000007;

void addSelf(int&x, int y)
{
    x+= y;
    if(x >= mod)
        x-=mod;
}
void subSelf(int&x, int y)
{
    x -= y;
    if(x < 0)
        x += mod;
}

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

int64_t power(int base, int expo)
{
    int64_t sol = 1;
    for (int i = 0; i <expo ; ++i) {
        sol *= base;
    }
    return sol;
}

bool compare1(pair<int,int> i,pair<int,int> j) // 1 < i < n
{
    return i.second < j.second;
}

bool compare2(pair<int,int> i, pair<int,int> j) //n > n-i > 1
{
    return i.first > j.first;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    int out = 0;
    for (auto x: s) {
        out += x -'0';
    }
    if(stoi(s) % out == 0)
        cout << "Yes";
    else
        cout << "No";
return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

ll m, n, k;
vl x, y, a;
vector<vector<pll>> adj;
ll C = 0;
vl comp, h;
bool ok = true;

void dfs(ll i, ll x) {
	comp[i] = C;
	h[i] = x;
	for (auto e: adj[i]) {
		if (comp[e.yy] == -1) dfs(e.yy,x + e.xx);
		else if (h[e.yy] != x + e.xx) ok = false;
	}
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> m >> n >> k;
	
	x.resize(k), y.resize(k), a.resize(k);
	FOR(i,0,k) cin >> x[i] >> y[i] >> a[i], x[i]--, y[i]--;

	adj.resize(m+n);
	FOR(i,0,k) adj[x[i]].eb(a[i],m+y[i]), adj[m+y[i]].eb(-a[i],x[i]);
	comp.resize(m+n,-1), h.resize(m+n,0);//, dx.resize(m+n), dy.resize(m+n);
	FOR(i,0,m+n) if (comp[i] == -1) dfs(i,0), C++;
	
	vl chx(C,oo), chy(C,oo);
	FOR(i,0,m) chx[comp[i]] = min(chx[comp[i]],-h[i]);
	FOR(i,m,m+n) chy[comp[i]] = min(chy[comp[i]],h[i]);
	
	FOR(c,0,C) if (chx[c] + chy[c] < 0) ok = false;

	cout << (ok ? "Yes" : "No") << endl;

}



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

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

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> deg(n,-1);
  rep(i,n) {
    cout << "lst " << i << endl;
    int v,tmp;
    cin >> v;
    deg[i] = v;
    rep(j,v) cin >> tmp;
  }
  int ans = 0;
  rep(i,n) {
    assert(deg[i]!=-1);
    if( deg[i] ) {
      ans += ( deg[i] * (deg[i]-1) );
    }
  }
  cout << "ans " << ans << endl;
}

Measured memory_bytes: 1280
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#define int ll
//#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
#define PI 3.141592653589

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
using pld = pair <ld, ld>;

template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}

template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}

template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}

inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
}

signed main()
{
    Start();
    int n;
    cin >> n;
    vector <int> a(n);
    cin >> a;
    vector <int> ans;
    for (int i = 0; i < n; ++i)
    {
        int pos = -1;
        for (int j = 0; j < a.size(); ++j)
        {
            if (a[j] == j + 1)
                pos = j;
        }
        if (pos == -1)
            break;
        ans.pb(pos + 1);
        a.erase(a.begin() + pos);
    }
    reverse(all(ans));
    if (a.size())
        cout << -1;
    else
        for (auto &i : ans)
            cout << i << endl;
    return 0;
}



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

int main (void) {
    int     i;
    char    s[200001];
    int     q;
    int     t, f;
    char    c;
    char    prefix_[200001], suffix_[200001];
    char    *prefix = prefix_, *suffix = suffix_;
    char    *tmp_c;
    int     tmp_d;
    int     prefix_len = 0, suffix_len = 0;
    int     order = 1;

    scanf("%s%d", s, &q);

    for ( i=0; i<q; i++ ) {
        scanf("%d", &t);
        if ( t == 1 ) {
            order *= -1;
            tmp_c = prefix;
            prefix = suffix;
            suffix = tmp_c;
            tmp_d = prefix_len;
            prefix_len = suffix_len;
            suffix_len = tmp_d;
        }
        else {
            scanf("%d %c", &f, &c);
            if ( f == 1 ) {
                prefix[prefix_len] = c;
                prefix_len++;
            }
            else {
                suffix[suffix_len] = c;
                suffix_len++;
            }
        }
    }

    prefix[prefix_len] = '\0';
    suffix[suffix_len] = '\0';

    for ( i=strlen(prefix)-1; i>=0; i-- )
        printf("%c", prefix[i]);
    if ( order == 1 ) {
        printf("%s", s);
    }
    else {
        for ( i=strlen(s)-1; i>=0; i-- )
            printf("%c", s[i]);
    }
    printf("%s\n", suffix);
    return EXIT_SUCCESS;
}



Measured memory_bytes: 768
L = input()

N = len(L)
mod = int(1e9 + 7)

# 桁DP
# a+b <= N 確定
dp1 = [0] * N
# a+b <= N 未確定
dp2 = [0] * N

# L[0] == 1なので、初期値が決まる（はず）
dp1[0] = 1 # (A0,B0) = (0,0)
dp2[0] = 2 # (A0,B0) = (0,1), (1,0)

for i in range(1,N):
  dp1[i] += dp1[i-1] * 3 # (1,1)以外の3パターン
  dp1[i] %= mod
  if L[i] == '1':
    dp1[i] += dp2[i-1] # (0,0)
    dp2[i] += dp2[i-1] * 2 # (1,0),(0,1)
  else:
    # L[i] == '0'
    dp2[i] += dp2[i-1] # (0,0)
  dp1[i] %= mod
  dp2[i] %= mod
  
print((dp1[N-1] + dp2[N-1]) % mod)

Measured memory_bytes: 68604
// garnab27
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
ll modex(ll a,ll b,ll p){ll res=1;a%=p;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b>>=1;}return res;}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
 
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);cout.tie(NULL);	
 
	double r;
	cin>>r;

	r = 2*acos(-1)*r;

	cout<<fixed<<setprecision(2)<<r;
 
 
	return 0;
}

Measured memory_bytes: 3800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) {
			if(y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else if(x == 4 || x == 6 || x == 9 || x == 11) {
			if(y == 4 || y == 6 || y == 9 || y == 11) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else if(x == 2){
			if(y == 2) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
		scan.close();

	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<deque>
typedef long long lint;
using namespace std;

int main()
{
	int n,a;
	deque<int> deq;
	string ans="";
	
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> a;
		if(i%2==0)
			deq.push_back(a);
		else 
			deq.push_front(a);
	}
	if(n%2==0)
	{
		for(auto itr=deq.begin();itr!=deq.end();++itr)
			ans+=(to_string(*itr)+" ");
	}
	else
	{
		for(auto itr=deq.rbegin();itr!=deq.rend();++itr)
			ans+=(to_string(*itr)+" ");
	}
	
	for(int i=0;i<ans.size()-1;i++)
		cout << ans[i];
	cout << endl;
	return 0;
}


Measured memory_bytes: 5124
#include <algorithm>
#include<iostream>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

#define INF 10000*1000*10
#define INF2 10000*1000
using namespace std;
using Graph = vector<vector<int>>;
vector<bool> seen;

struct Edge{
  long from;
  long to;
  long cost;
};

void dfs(const Graph &g,int v){
  seen[v]= true;
  //cout << v << endl;
  for(auto next_v : g[v]){
    if(seen[next_v]) continue;
    dfs(g,next_v);
  }
}

int main(){
  long ii,jj,kk;
  vector<int> ret;
  long v,e,s;


  cin >> v >> e >> s;
  Graph g(v);
  vector<Edge> edges;
  //edges.resize(e);

  for(ii=0;ii<e;ii++){

    Edge edg ;
    cin >> edg.from >> edg.to >> edg.cost;
    g[edg.from].push_back(edg.to);
    edges.push_back(edg);
  }

  seen.assign(v,false);
  dfs(g,s);
  for(ii=0;ii<v;ii++){
    //cout << seen[ii] << endl;
  }
  vector<long> costs;
  costs.resize(v);
  for(ii=0;ii<v;ii++){
    costs[ii] = INF;
  }

  costs[s] = 0;
  //fill(costs,costs+v,INF);
  //for(ii=0;ii<edges.size();ii++){
  //  Edge edg = edges[ii];
  //  //cout << "from:"  << edg.from << "to:" << edg.to << "cost:" << edg.cost << endl;
  //}

  bool loopFlg = false;
  for(ii=0;ii<v;ii++){
    for(jj=0;jj<e;jj++){
      Edge edg = edges[jj];

      if(costs[edg.to] > costs[edg.from] + edg.cost){
        costs[edg.to] = costs[edg.from] + edg.cost;
        //cout << "ii" << ii << "jj" << jj << endl;
        if(ii == v-1 && seen[edg.to] == true){
          //cout << "negative loop" << endl;
          loopFlg = true;
        }
      }
    }
  }
  bool notReachFlg = false;
  long notCnt = 0;

  for(ii=0;ii<v;ii++){
    if(costs[ii] > INF2){
      notCnt++;
    }
  }
  

  if(notCnt != (v-1) && loopFlg){
    cout << "NEGATIVE CYCLE" << endl;
  }
  else{
    
    for(ii=0;ii<v;ii++){
      if(costs[ii] > INF2){
        cout << "INF" << endl;
      }
      else{
        cout << costs[ii] << endl;
      }
    }
    
  }
}



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

const int mod=1000000007;
int n,m,a[100010],ans,nw;

struct mat
{
	int a[3][3];
	mat operator *(mat A)
	{
		mat B; memset(B.a,0,sizeof(B.a));
		for (int i=0; i<3; i++)
			for (int j=0; j<3; j++) if (a[i][j])
				for (int k=0; k<3; k++)
					B.a[i][k]=(B.a[i][k]+1ll*a[i][j]*A.a[j][k])%mod;
		return B;
	}
}A,B,T;

mat quickmi(mat A,int n)
{
	mat T;
	for (int i=0; i<3; i++) 
		for (int j=0; j<3; j++) T.a[i][j]=(i==j);
	while (n)
	{
		if (n&1) T=(T*A);
		n>>=1;
		if (n) A=(A*A);
	}
	return T;
}

int main()
{
	scanf("%d%d",&n,&m),ans=0,nw=1;
	for (int i=1; i<=m; i++) scanf("%d",&a[i]);
	A.a[0][1]=A.a[0][2]=A.a[2][2]=A.a[1][1]=A.a[2][0]=A.a[2][1]=1;
	A.a[0][0]=A.a[1][0]=2,A.a[1][2]=0;
	for (int i=0; i<3; i++)
		for (int j=0; j<3; j++) T.a[i][j]=(i==j),B.a[i][j]=A.a[i][j]-(i==0);
	for (int i=1; i<=m; i++)
	{
		T=((T*quickmi(A,a[i]-nw))*B);
		nw=a[i]+1;
	}
	T=(T*quickmi(A,n-nw));
	for (int i=0; i<3; i++) ans=(ans+T.a[i][0])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
s=input()

r=-1
idx=0
LS=len(s)
st=(LS+1)//2

while True:
    if idx>=len(s)+r:
        break
    if s[idx]==s[r]:
        idx+=1
        r-=1
    elif s[idx]=="x" and s[r]!="x":
        LS+=1
        idx+=1
    elif s[idx]!="x" and s[r]=="x":
        LS+=1
        r-=1
    else:
        print(-1)
        exit()


print(LS-len(s))



Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll H, W, K;
    cin >> H >> W >> K;
    ll S[15][1005];
    rep(i, H){
        string s;
        cin >> s;
        rep(j, len(s)) S[i][j] = s[j] - '0';
    }

    ll ans = 1e18;
    rep(i, 1 << (H-1)){
        bitset<10> x(i);
        string X = x.to_string();
        reverse(ALL(X));

        vector<ll> v(10,0);
        ll sum = 0;
        rep(j, H - 1) sum += X[j] == '1';

        rep(j, W){
            ll now = 0, smx = 0, vmx = 0;
            vector<ll> s(10, 0);
            rep(k, H){
                s[now] += S[k][j];
                v[now] += S[k][j];
                smx = max(smx, s[now]);
                vmx = max(vmx, v[now]);
                if (X[k] == '1') ++now;
            }
            if(smx > K){
                sum = 1e18;
                break;
            }
            if(vmx > K){
                v = s;
                ++sum;
            }
        }
        ans = min(ans, sum);
    }

    print(ans);

    return 0;
}

Measured memory_bytes: 384
# ABC073D - joisino's travel
from heapq import heappop, heappush
from itertools import permutations

inf = 1 << 30

def dijkstra(source: int, edges: "List[Tuple[int, int]]") -> "List[int]":
    """
    Compute the distance of the shortest path from V_source to each vertex.

    Args:
        source: V_source
        edges: Edges info
    Returns:
        dist: A list of distance from V_source
    """
    edges_count = len(edges)
    dist = [inf] * edges_count
    dist[source] = 0
    undetermined = edges_count - 1  # V_0 is determined in 1-idx graph
    queue = [(0, source)]
    while queue:
        cost, v = heappop(queue)
        if cost > dist[v]:
            continue
        for next_cost, u in edges[v]:
            if cost + next_cost < dist[u]:
                dist[u] = cost + next_cost
                heappush(queue, (dist[u], u))
        undetermined -= 1
        if not undetermined:
            break
    return dist  # There may be no path from V_source to some vertices.

def main():
    N, M, R, *RABC = map(int, open(0).read().split())
    visit, ABC = RABC[:R], RABC[R:]
    edges = [[] for _ in range(N + 1)]
    for v, u, cost in zip(*[iter(ABC)] * 3):
        edges[v].append((cost, u)), edges[u].append((cost, v))
    dist = {v: dijkstra(v, edges) for v in visit}
    ans = inf
    for perm in permutations(visit):
        cur = sum(dist[v][u] for v, u in zip(perm, perm[1:]))
        ans = min(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 56632
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,a,b;cin >> n >> a >> b;
    if(a>b)puts("0");
    else if(a!=b&&n==1) puts("0");
    else {
        cout << (n-2)*(b-a)+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

const int MOD = 1000000007;
const int INF = 1 << 30;

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

    vi r(n, 0), l(n, 0);

    int c = 0;
    rep(i, n) {
        if (s[i] == 'R') {
            c++;
        }
        else {
            r[i] = c;
            c = 0;
        }
    }

    c = 0;
    rep(i, n) {
        if (s[n-1-i] == 'L') {
            c++;
        }
        else {
            l[n-1-i] = c;
            c = 0;
        }
    }

    vi res(n, 0);
    rep(i, n) res[i] = l[i] + r[i];

    rep(i, n) {
        if (res[i] > 0) {
            res[i] = 1 + (r[i+1]-1)/2 + (l[i]/2);
            res[i+1] = 1 + (l[i]-1)/2 + (r[i+1]/2);
            i++;
        }
    }

    rep(i, n) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
const int MAX = 1100000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
    LL n;
    cin>>n;
    LL ans=0;
    //全通り計算
    LL k=n;
    LL x=2;
    LL r=1;
    while(k>1){
        if(k%2==0){x=x*x;k=k/2;}
        else{r=r*x;x=x*x;k=(k-1)/2;}
        x=x%MOD;r=r%MOD;
    }
    ans=(x*r-1)%MOD;
    //引く分の計算
    LL a,b;
    cin>>a>>b;
    LL ya=1;
    LL yb=1;
    for(int i=0;i<a;i++){
        ya=ya*(n-i);
        ya=ya%MOD;
    }
    ya=ya*finv[a];
    ya=ya%MOD;
    for(int i=0;i<b;i++){
        yb=yb*(n-i);
        yb=yb%MOD;
    }
    yb=yb*finv[b];
    yb=yb%MOD;
    ans=ans+MOD-ya+MOD-yb;
    ans=ans%MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 25984
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n, greater<ll>());
    ll b = a[1];
    for(ll i = 1; i < n; i++){
        if(a[i]*2>=a[0] && a[i+1]*2<=a[0]){
            if(a[0]-a[i]>=a[i+1])
                b = a[i];
            if(a[0]-a[i]<a[i+1])
                b = a[i+1];
        }
    }
    cout << a[0] << " " << b << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(ll i=a;i<=(ll)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll a, b, k;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> a >> b >> k;
    if (a+k-1 >= b-k+1) {
        erep(i, a, b) 
            cout << i << endl;
    } else {
        erep(i, a, a+k-1) 
            cout << i  << endl;
        erep(i, b-k+1, b) 
            cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s = input()
l = list(s)
N = len(s)
n = len(s)
ans = 0

if len(set(s)) == 1:
    print(0)
    exit()

for ll in l:
    S = s
    n = N
    while n > 0:
        tmp = ''
        for i in range(n - 1):
            if S[i] == ll or S[i + 1] == ll:
                tmp += ll
            else:
                tmp += S[i]
        if len(set(tmp)) == 1:
            ans = max(ans, len(tmp))
            break
        n -= 1
        S = tmp

print(N - ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
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 INF = 1LL<<60;
const int MAX = 16;
int N;
vector<long long> A;

vector<vector<long long>> calc(const vector<long long> &a, int offset = 0) {
    vector<vector<long long>> dp(N+1, vector<long long>(MAX, INF));
    for (int j = 0; j < MAX; ++j) dp[0][j] = 0, dp[1][j] = j*2 + offset;
    for (int i = 1; i < N; ++i) {
        long long s = a[N-i-1];
        for (int j = 0; j < MAX; ++j) {
            long long t = a[N-i];
            int need = 0;
            while (s > t) ++need, t *= 4;
            long long add = 0;
            if (need >= MAX) {
                add = (need - MAX + 1) * i * 2;        
                need = MAX-1;
            }
            chmin(dp[i+1][j], dp[i][need] + j * 2 + add + offset);
            s *= 4;
        }
    }
    return dp;
}

long long solve() {
    const auto &right = calc(A);
    reverse(A.begin(), A.end());
    const auto &left = calc(A, 1);
    long long res = INF;
    for (int i = 0; i <= N; ++i) chmin(res, left[i][0] + right[N-i][0]);
    return res;
}

int main() {
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 67456
A=list(map(int, input().split()))
indexs=[[0,1,2],[0,2,1],[1,0,2],[1,2,0],[2,0,1],[2,1,0]]
n=[]
for i in range(6):
  n.append(abs(A[indexs[i][0]]-A[indexs[i][1]])+abs(A[indexs[i][1]]-A[indexs[i][2]]))
  
print(min(n))

Measured memory_bytes: 3064
r, g, b, n = map(int, input().split())
cnt = 0
for i in range(n+1):
    for j in range(n+1):
        if ((n - (r*(i) + g*(j))) >= 0) and ((n - (r*(i) + g*(j))) % b == 0):
            cnt += 1
            #print(i)
            #print(j)
print(cnt)

Measured memory_bytes: 41196