akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 1};
int dx[]={1, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

struct code{
    char c[100];
    int length;
};

code memo[100][100];
char mat[100][100];
int w,h;

bool codecmp(code a,code b){
    if(a.length < b.length)
        return true;

    if(a.length == b.length && a.length > 0 && strcmp(a.c,b.c) < 0)
        return true;
    return false;
}

code search(int nowy,int nowx){

    if(memo[nowy][nowx].length >= 0)
        return memo[nowy][nowx];
    code a[2];
    for(int i = 0;i < 2;i++){
        int x = nowx + dx[i],y = nowy + dy[i];
        if(x >= 0 && x < w && y >= 0 && y < h && mat[y][x] >=  '0' && mat[y][x] <= '9'){
            a[i] = search(y,x);
        }
        else{
            a[i].c[0] = '\0';
            a[i].length = 0;
        }
    }

    if(codecmp(a[0],a[1]))
            a[0] = a[1];

    memo[nowy][nowx].c[0] = mat[nowy][nowx];
    for(int i = 0;i <= a[0].length;i++)
        memo[nowy][nowx].c[i + 1] = a[0].c[i];
    memo[nowy][nowx].length = a[0].length + 1;
    return memo[nowy][nowx];
}


int main(){
    while(1){
        scanf("%d%d",&w,&h);

        if(w == 0 && h == 0)
            break;

        for(int i = 0;i < h;i++)
            scanf("%s",&mat[i][0]);

        for(int i = 0;i <  100;i++)
            for(int j = 0;j < 100;j++)
                memo[i][j].length = -1;

        code a,maxi;
        maxi.c[0] = '\0';maxi.length = 0;
        for(int i = 0;i < h;i++){
            for(int j = 0;j < w;j++){
                if(mat[i][j] > '0' && mat[i][j] <= '9'){
                    a = search(i,j);
                    if(codecmp(maxi,a))
                        maxi = a;
                }
            }
        }
        printf("%s\n",maxi.c);
    }
}

Measured memory_bytes: 4216
#include <iostream>

using namespace std;

bool eratosthenes[1000000];

int main()
{
	for (int i=0; i<1000000; i++) eratosthenes[i] = true;		
	eratosthenes[0] = eratosthenes[1] = false;
	
		for (int i=2; i<1000000; i++) {
		if (!eratosthenes[i]) continue;
		for (int j=2; i*j<1000000; j++) eratosthenes[i*j] = false;
	}
	
	int n;
	while (cin >> n) {
	
		int count = 0;
		for (int i=0; i<=n; i++) {
			if(eratosthenes[i]) count++;
		}
		
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define all(v) v.begin(), v.end() // sort(all(array))
#define INF 1000000000
#define mod 1000000007
#define EPS 0.0001
using namespace std;
using ll = long long;
using vi = vector<int>; //vi array(要素数, 初期値)
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値))
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;

int main() {
    int h, w, k; cin >> h >> w >> k;
    vs masu(h);
    rep(i, h) cin >> masu[i];

    int ans = 0;
    rep(mask_h, 1 << h) rep(mask_w, 1 << w) {
        int cnt = 0;
        rep(i, h) rep(j, w) {
            if (mask_h & (1 << i) || mask_w & (1 << j)) {
                continue;
            }
            if (masu[i][j] == '#') {
                cnt++;
            }
        }
        if (cnt == k) {
            ans++;
        }
    } 
    cout << ans << endl;
}

Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

int main() {
    uint64_t N;
    string S;
    cin >> N >> S;
    if (N % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    uint64_t n = N / 2;
    for (int i = 0; i < n; i++) {
        if (S[i] != S[n + i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 0x3f3f3f3f;
const int N = 100+10;

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(false); cout.tie(false);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll ans = 0; int cnt = 1;
    for(int i = 1; i < n; ++i) {
        if(s[i-1] == s[i]) cnt++;
        else {
            ans += cnt-1;
            cnt = 1;
        }
    }
    if(cnt) ans += cnt-1;
    int p = 1, t1 = 0, tmp = k;
    while(p < n && s[p] == s[p-1]) p++;
    if(p < n) {
        char ch = s[p];
        bool flag = false;
        for(int i = p; i < n; ++i) {
            if(s[i] != ch && !flag && k) {
                t1 += 2;
                --k;
                flag = true;
            }
            if(s[i] == ch) flag = false;
        }
        if(!flag && k) t1++;
    }
    cout << ans+t1 << endl;
	return 0;
}


Measured memory_bytes: 512
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		HashMap<Integer,Integer> map=new HashMap<>();
		long ans=0;
		for(int i=1;i<=n;i++)
		{
			int a=nextInt();
			ans+=map.getOrDefault(a-i,0);
			map.put(-i-a,map.getOrDefault(-i-a,0)+1);
		}
		out.println(ans);
	}

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

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 65368
// kid_kb //
	
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ull unsigned long long int
#define lower(str) transform(str.begin(),str.end(),str.begin(),::tolower);
#define upper(str) transform(str.begin(),str.end(),str.begin(),::toupper);
#define mod 1000000007
#define SORT(vec) sort(vec.begin(),vec.end());
#define pb push_back
#define csb __builtin_popcount
#define msb(n) (ll)(log2(n))
#define DIG(n) floor(log10(n))+1
#define kb ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ptr(arr) for(auto i:arr)cout<<i<<" ";
#define ptr2(vec) for(auto i:vec){for(auto j: i){cout<<j<<" ";}cout<<endl;}
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mem(a,val) memset(a,val,sizeof(a))
//cout<<fixed<<setprecision(8)<<endl;
ll fastpower(ll n,ll p,ll m)
{
   if(p==0)
       return 1;
    
    ll t=fastpower(n,p/2,m);
    ll ans=(t*t)%m;
    
    if(p%2!=0)
    {
        ans=(ans * n%m)%m;
    }
    return ans;
}
void solve(){
	ll n;
	cin>>n;
	if(n==1){cout<<0<<endl;return;}
	else if(n==2){cout<<2<<endl;return;}

// 	ll ans=(n*(n-1))%mod;
// 	ll temp=fastpower(10,n-2,mod)%mod;
// 	ans=(ans*temp)%mod;
    ll a=fastpower(10,n,mod);
    ll b=fastpower(9,n,mod);
     ll c=fastpower(8,n,mod);
    ll ans=(a-(2*b)%mod+c%mod+mod)%mod;
	cout<<ans<<endl;

}
int main()
{
	kb
	ll t;
	t=1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i ,a, n) for (long long int i=a;i<=n;i++)
#define pb  push_back
#define mp make_pair
#define fp first
#define sp second
#define be(v) v.begin(),v.end()
typedef long long ll;
typedef vector<ll> vi ;
typedef vector<pair<ll , ll > >  vpi ;
const int ma1=3e5+5;
string no="NO",yes="YES";
#define MOD 1000000007
int max_char=26;
ll dp[100005][3]={0};
vector<ll> v;
int main()
{
      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    while(t--)
    {
        ll n,m;
        cin>>n;
        ll a[n];
        ll b[n];
        ll c[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i]>>c[i];
        }
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];
        for(int i=1;i<n;i++)
        {
            dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
        }
        cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    }
    return 0;
}
















Measured memory_bytes: 8352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  string s; cin >> s;
  int n = (int)(s.size());
  vector<int> a(n);
  int cnt = 1;
  char now = s[0];
  int prev = 0;
  for(int i=1;i<n;++i) {
    if(s[i] == now) {
      cnt++;
    } else if(now == 'R') {
      a[i-1] += cnt/2 + cnt%2;
      a[i] += cnt/2;
      now = s[i];
      cnt = 1;
      prev = i;
    } else {
      a[prev] += cnt/2 + cnt%2;
      a[prev-1] += cnt/2;
      now = s[i];
      cnt = 1;
    }
  }
  a[prev] += cnt/2 + cnt%2;
  a[prev-1] += cnt/2;
  printv(a);
}


Measured memory_bytes: 1024
//https://atcoder.jp/contests/dp/tasks/dp_g
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int maxx=1e5+5;
vector<int> edges[maxx];
int indegree[maxx];// the no of edges going to 'b'

int dist[maxx];
bool visited[maxx];

void dfs(int a){
    visited[a]=true;
    for(int b:edges[a]){
        //Do not use visited[b]== true or false it will make algo false
        dist[b]=max(dist[b],dist[a]+1);
        --indegree[b];
        // indegree is 0 then only not negative or positive
        if(indegree[b]==0){
            dfs(b);
        }
    }
}

int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    while(m--){
        int a,b;
        scanf("%d%d",&a,&b);
        // directed graph
        edges[a].push_back(b);
        ++indegree[b];
    }
    // since graph is disconnected
    for(int i=1;i<=n;++i){
        if(!visited[i] && indegree[i]==0){
            dfs(i);
        }
    }

    int answer=0;
    for(int i=1;i<=n;++i)
        answer=max(answer,dist[i]);
    printf("%d\n",answer);
    return 0;
}


Measured memory_bytes: 9728
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>


signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n,m;
  cin >> n >> m;
  map<ll, ll> cost_number;
  rep(i,n){
    ll a,b;cin >> a >> b;
    cost_number[a] += b;
  }
  ll cost = 0;
  ll left_number = m;
  for(pl i:cost_number){
    left_number -= i.S;
    if(left_number < 0){
      cost += i.F*(i.S+left_number);
      break;
    }
    cost += i.F*i.S;
  }
  cout << cost << endl;
  ret;
}


Measured memory_bytes: 9868
using System;
using System.Linq;
using System.Collections.Generic;

public class colon
{
    public static void Main(string[] args)
    {
        //入力内容　複数
        string[] input = Console.ReadLine().Split(' ');

        //数字
        double A = int.Parse(input[0]);
        double B = int.Parse(input[1]);
        double H = double.Parse(input[2]);
        double M = double.Parse(input[3]);
        double ansans;

        if (H / 12 >= M / 60)
        {
            ansans = (A * A) + (B * B) - 2 * A * B * Math.Cos(2 * Math.PI * ((H+M/60)/12 - M / 60));

            Console.WriteLine(Math.Sqrt(ansans));
        }
        else
        {
            ansans = (A * A) + (B * B) - 2 * A * B * Math.Cos(2 * Math.PI * (M / 60- (H + M / 60) / 12));
            Console.WriteLine(Math.Sqrt(ansans));
        }
    }
}



Measured memory_bytes: 27940
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,sum;
ll a[3009];
ll dp[3009][3009][9];
ll bt(int l,int r,int z){
    if(l > r) return 0;
    ll &ret = dp[l][r][z];
    if(ret != -1) return ret;
    ll x = bt(l+1,r,1-z);
    ll y = bt(l,r-1,1-z);
    if(!z){
        x += a[l],y += a[r];
        ret = max(x,y);
    }
    else ret = min(x,y);
    return ret;
}
int main(){
    fast,cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i],sum += a[i];
    }
    memset(dp,-1,sizeof(dp));
    ll x = bt(0,n-1,0);
    ll y = sum - x;
    cout<<x-y<<endl;
}


Measured memory_bytes: 637056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n;
    cin >> n;
    // 全部 mod5 = k であるような素数ならok
    vector<int> primes;
    vector<bool> isP(55556);
    for(int i=0; i<=55555; i++){
        isP[i] = true;
    }
    isP[0] = false;
    isP[1] = false;

    for(int i=2; i<=55555; i++){
        if(isP[i] == true){
            for(int j=i; j<=55555; j+=i){
                isP[j] = false;
            }
            if(i % 5 == 2){
                primes.push_back(i);
            }
        }
    }

    for(int i=0; i<n; i++){
        cout << primes[i] << " ";
    }
    return 0;
}

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

int main(){
  vector<int> ABC(3);
  repeat(i,3) cin >>ABC[i];
  
  sort(ABC.begin(),ABC.end());
  
  int ans = 10*ABC[2] + ABC[0] + ABC[1];
  cout <<ans<< 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(v) v.begin(), v.end()

int main(){
    int N,M;
    cin >> N >> M;
    vector<set<int>> hen(N+1);
    int a,b;
    rep(i,M){
        cin >> a >> b;
        hen.at(a).insert(b);
        hen.at(b).insert(a);
    }
    vector<int> junretsu;
    rep(i,N-1){
        junretsu.push_back(i+2);
    }
    int cnt=0;
    do{
        bool fl = false;
        int tmp = 1;
        rep(i,N-1){
            if(hen.at(tmp).count(junretsu.at(i))){
                tmp = junretsu.at(i);
            }else{
                fl = true;
                break;
            }
        }
        if(fl) continue;
        cnt++;
    }while( next_permutation(junretsu.begin(),junretsu.end()) );
    cout << cnt << endl;
}   

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

int DP[18][17];
int field[18][17];
int x,y;

int main(){
	while(true){
		cin >> x >> y;
		if(!x && !y)
			return 0;
		
		for(int i=1; i<=y; i++)
			for(int k=1; k<=x; k++)
				cin >> field[i][k];
		for(int i=1; i<=x; i++){
			field[y+1][i] = 0;
			field[y+2][i] = 0;
		}
		
		for(int i=1; i<=y+2; i++)
			for(int k=0; k<=x+1; k++){
				DP[i][k]=0;
				if(i==1 && k>0 && k<=x)
					if(field[i][k] == 0)
						DP[i][k] = 1;
			}
		
		for(int i=2; i<=y; i++){
			for(int k=1; k<=x; k++){
				if(field[i][k] == 0)
					DP[i][k] += DP[i-1][k-1] + DP[i-1][k] + DP[i-1][k+1];
				else if(field[i][k] == 2){
					int n = i+2;
					while(true){
						if(field[n][k] == 0){
							DP[n][k] += DP[i-1][k];
							break;
						}else if(field[n][k] == 1)
							break;
						else
							n+=2;
					}
				}
			}
		}
		
		int ans=0;
		for(int i=y; i<=y+2; i++)
			for(int k=1; k<=x; k++)
				ans += DP[i][k];
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
n, m = map(int, input().split())
l = list(map(int, input().split()))
dp = [10**5] * (n+1)
dp[0] = 0
for i in range(len(l)):
    m = l[i]
    for j in range(m,n+1):
        dp[j] = min(dp[j-m]+1, dp[j])
print(dp[n])


Measured memory_bytes: 7512
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int n, m, k;
  cin>>n>>m>>k;
  FOR (a, 0, m) {
    FOR (b, 0, n) {
      if (k == a * n + b * m - 2 * a * b) {
        cout<<"Yes\n";
        return 0;
      }
    }
  }
  cout<<"No\n";

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 256
n, m, q = list(map(int, input().split()))
from collections import deque
ans = 0
def calc(seq):
    score = 0
    for a, b, c, d in req:
        if seq[b-1] - seq[a-1] == c:
            score+= d
    return score
req = [list(map(int, input().split())) for i in range(q)]

que = deque()

for h in range(1, m+1):
    que.append([h])

while que:
    seq = que.popleft()
    if len(seq) == n:
        score = calc(seq)
        ans = max(ans, score)
    else:
        for i in range(seq[-1], m+1):
            seq_next = seq + [i]
            que.append(seq_next)

print(ans)

Measured memory_bytes: 107524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
    ll n,w;
    cin >> n >> w;
    ll we[n],va[n];
    for (ll i = 0; i < n; i++) cin >> we[i] >> va[i];
    ll dp[n + 1][w + 1];
    for (ll i = 0; i < w + 1; i++) dp[0][i] = 0;
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < w + 1;j++){
            if (j >= we[i]) dp[i + 1][j] = max(dp[i][j - we[i]] + va[i], dp[i][j]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }
    cout << dp[n][w] << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> d1(n), d2(n);

    for(int i = 0; i < n; ++i)
        cin >> d1[i] >> d2[i];

    bool res = false;
    for(int i = 0; i < n - 2; ++i)
    {
        if(d1[i] == d2[i] && d1[i + 1] == d2[i + 1] && d1[i + 2] == d2[i + 2])
            res = true;
    }

    cout << (res ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 3628
import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.ST
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  [n,x] <- readInts
  when ((n,x) /= (0,0)) $ do
    print $ solve n x
    main

solve :: Int -> Int -> Int
solve n x = length [ (a,b,c) 
                   | a <- [1..n], b <- [a+1..n], c <- [b+1..n]
                   , a + b + c == x
                   ]



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int a, b, c, d, e;
	cin>> a >> b >> c >> d >> e;

	if(a==0) cout<< "1" << endl;
	if(b==0) cout<< "2" << endl;
	if(c==0) cout<< "3" << endl;
	if(d==0) cout<< "4" << endl;
	if(e==0) cout<< "5" << endl;
 
	return 0;
}

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

int main(void){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    if(k>=a){
        ans+=a;
        k-=a;
        if(k>=b){
            k-=b;
            if(k>=c){
                ans-=c;
                cout<<ans<<endl;
            }else{
                ans-=k;
                cout<<ans<<endl;
            }
        }else{
            cout<<ans<<endl;
            return 0;
        }
    }else{
        cout<<k<<endl;
        return 0;
    }

}

Measured memory_bytes: 3536
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int n;
int m;
int ar[N];
int pos[N];
int parent[N];

int getP(int u){
    if(parent[u] == u)
        return u;
    return parent[u] = getP(parent[u]);
}

void join(int u , int v){
    u = getP(u);
    v = getP(v);
    parent[v] = u;
}

int main(){
    scanf("%d%d" , &n , &m);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
        pos[ar[i]] = i;
        parent[i] = i;
    }
    for(int i = 1; i <= m; i++){
        int u , v;
        scanf("%d%d" , &u , &v);
        join(u , v);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += getP(pos[ar[i]]) == getP(ar[i]);
    }
    printf("%d\n" , ans);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 10000;
int n,a[N];
int main()
{
	int sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	double av=1.0*sum/n;
	double ss=1000;
	int id=-1;
	for(int i=1;i<=n;i++)
	{
		double cf=abs(a[i]*1.0-av);
		if(cf<ss)
		{
			ss=cf;
			id=i;
		}
	}
	cout<<id-1<<endl;
}

Measured memory_bytes: 256
#include<cstdio>

const int maxn=100005;
int a[maxn];

int main() {
	int n;
	while(~scanf("%d",&n)) {
		int cnt1=0,cnt2=0,cnt3=0;
		for(int i=0;i<n;i++) {
			scanf("%d",a+i); 
			if(a[i]%4==0) cnt1++;
			else if(a[i]%2==0) cnt2++;
			else cnt3++;
		}
		if(cnt1+1<cnt3||(cnt1+1==cnt3&&cnt2)) printf("No\n");
		else printf("Yes\n");
	}
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define int long long
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int t[17][17];

int dp[1 << 16 + 2];

signed main()
{
    int N;
    
    while (cin >> N, N) {
        rep(i, N) rep(j, N + 1) cin >> t[i][j];

        for (int i = 0; i < (1 << N); ++i) dp[i] = inf;

        dp[0] = 0;

        for (int i = 0; i < (1 << N); ++i) {
            vector<int> bits;

            bits.PB(0);
            rep(j, N) if (i & (1 << j)) bits.PB(j + 1);

            for (int j = 0; j < N; ++j) {
                if (i & (1 << j)) continue;
                int bit = i | (1 << j);

                int mi = inf;
                rep(k, bits.size()) chmin(mi, t[j][bits[k]]);

                chmin(dp[bit], dp[i] + mi);
            }
        }

        cout << dp[(1 << N) - 1] << endl;
    }
}

Measured memory_bytes: 1732
n,m=map(int,input().split())
h=[0]+list(map(int,input().split()))
edge=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)
ans=0
for i in range(1,n+1):
    if h[i]>max([h[j] for j in edge[i]]+[0]):
        ans+=1
print(ans)

Measured memory_bytes: 30592
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

int main() {
    int n; string a, b, c;
    cin >> n >> a >> b >> c;
    int ans = 0;
    FOR (i, 0, n) {
        if (a[i] == b[i] && b[i] == c[i])
            continue;
        if (a[i] == b[i] || b[i] == c[i] || a[i] == c[i])
            ans++;
        else ans += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 2104
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int TC = sc.nextInt();
		for (int tc = 0; tc < TC; tc++) {
			int n = sc.nextInt(), k = sc.nextInt(), p = sc.nextInt();
			int[] dif = new int[n - 1];
			for (int i = 0; i < n - 1; i++) {
				int c = sc.nextInt();
				dif[i] = c - p;
				p = c;
			}
			sort(dif);
			long res = 0;
			for (int i = 0; i < n - k; i++) res += dif[i];
			System.out.println(res);
		}
	}	
}

Measured memory_bytes: 14000
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=[0]
b=[0]

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

ANS=[0]
idx=m

for i in range(n+1):
    x=k-a[i]
    if x<0:
        break
    while b[idx]>x:
        idx-=1
    ANS.append(i+idx)
print(max(ANS))

Measured memory_bytes: 148160
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<int> to[200005];

int main()
{
    int x;
    cin >> x;
    for(int b = 0; b <= 1000; b++){
        for(int a = -1000; a <= 1000; a++){
            if(pow(a, 5) - pow(-b, 5) == x){
                cout << a << " " << -b << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 8788
import Control.Monad
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV

main=B.interact $ B.pack.g.take 2.B.lines

g [s,t]=mk "" (ls-1) (lt-1) where
    ls = B.length s
    lt = B.length t
    rd si ti = (aa V.! si) UV.! ti
    mk as si ti
        | si<0 || ti<0 = as
        | B.index s si == B.index t ti = mk (B.index s si : as) (si-1) (ti-1)
        | rd (si+1) ti > rd si (ti+1) = mk as si (ti-1)
        | otherwise = mk as (si-1) ti
    aa :: V.Vector (UV.Vector Int)
    aa = V.constructN (ls+1) mi where
        mi vi | i==0 = UV.replicate (lt+1) 0 | otherwise = UV.constructN (lt+1) mj where
            i = V.length vi
            mj vij |j==0 = 0 | otherwise = if B.index s (i-1) == B.index t (j-1)
                then 1 + V.last vi UV.! (j-1)
                else max (UV.last vij) (V.last vi UV.! j)
                where j = UV.length vij


Measured memory_bytes: 76156
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N,M,X = map(int, input().split())		# 5 7 2
CA = [list(map(int, input().split())) for _ in range(N)]		#=> [[1, 0], [2, 10], [3, 210], [4, 3210]]

A=[]
C=[]
for n in range(N):
	A.append(CA[n][1:])
	C.append(CA[n][0])

B=[0]*M

for n in range(N):
	for m in range(M):
		B[m] += A[n][m]

#p(CA)
#p(A)
#p(C)
#p(B)

if min(B) < X:
	print(-1)
	exit(0)

# 直積 product
# デカルト積。for ループの入れ子をせずに全パターンを網羅するときに便利。
from itertools import product
L = list( product([0,1], repeat=N) )

#p(L)

from operator import add

ans = sum(C)
for l in L:
	sumA = [0]*M
	sumC = 0
	for i,x in enumerate(l):
		if x==0: continue
		sumA = map(add, sumA, A[i])
		sumC += C[i]
		
	if min(sumA) < X: continue
	
	ans = min(ans, sumC)

print(ans)



Measured memory_bytes: 9740
let first = readLine()!.split(separator: " ")
let N = Int(first[0])!
let M = Int(first[1])!
let heights: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
var graph: [Set<Int>] = .init(repeating: Set<Int>(), count: N)
for _ in 0..<M {
  let read = readLine()!.split(separator: " ")
  let source = Int(read[0])!
  let dest = Int(read[1])!
  graph[source - 1].insert(dest - 1)
  graph[dest - 1].insert(source - 1)
}

var count = 0
for i in 0..<N {
  var result = true
  for nei in graph[i] {
    if heights[i] <= heights[nei] {
      result = false
      break
    }
  }
  if result {
    count += 1
  }
}
print(count)



Measured memory_bytes: 20216
class UnionFind:
    def __init__(self,size):
        self.L = [{'parent':i,'rank':0} for i in range(size)]

    def find(self,x):
        if self.L[x]['parent'] != x:
            self.L[x]['parent'] = self.find(self.L[x]['parent'])
        return self.L[x]['parent']

    def union(self,x,y):
        x_root = self.find(x)
        y_root = self.find(y)
        if x_root == y_root:
            return
        if self.L[x_root]['rank'] < self.L[y_root]['rank']:
            x_root,y_root = y_root,x_root

        self.L[y_root]['parent'] = x_root
        if self.L[x_root]['rank'] == self.L[y_root]['rank']:
            self.L[x_root]['rank'] += 1
    
    def __str__(self):
        return str([i['parent'] for i in self.L])

if __name__ == '__main__':
    N,M = map(int,input().split())
    P = list(map(int,input().split()))
    graph = UnionFind(N)
    for i in [None]*M:
        x,y = map(int,input().split())
        graph.union(x-1,y-1)
    count = 0
    for i,v in enumerate(P):
        if graph.find(i) == graph.find(v-1):
            count += 1
    print(count)

Measured memory_bytes: 41444
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    s64 cnt[10][10];
    rep (i, 10) rep (j, 10) cnt[i][j] = 0;
    rep (i, n + 1)
    {
        string s = to_string(i);
        ++cnt[s[0] - '0'][i % 10];
    }

    int ans = 0;
    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            ans += cnt[i][j] * cnt[j][i];
        }
    }

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



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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

int visited[20][20];

// Paste snippets here!!
void init(){
  rep(i,20){rep(j,20){ visited[i][j]=0; }}
}
ll far_dist(vector<string> &maze, int h, int w, int num_roads){
  init();
  int H = maze.size();
  int W = maze[0].size();
  queue<tuple<int,int,int>> q;
  q.push(make_tuple(h,w,0));
  visited[h][w] = 1;
  int i, j, d; int steps = 0;
  while(!q.empty()){
    tie(i,j,d) = q.front(); q.pop();
    rep(k,4){
      int x = i+dx[k]; int y = j+dy[k];
      if(inside(H,W,x,y) && maze[x][y]=='.' && visited[x][y]==0){
        q.push(make_tuple(x,y,d+1));
        visited[x][y] = 1;
      }
    }
  }
  return d;
}
//

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  // Failed to predict input format
  int H, W;
  cin >> H >> W;
  vector<string> maze;
  rep(h,H){
    string line; cin >> line;
    maze.push_back(line);
  }
  ll ret = 0;
  int num_roads = 0;
  rep(h,H) rep(w,W) if(maze[h][w]=='.') num_roads++;
  rep(h,H){
    rep(w,W){
      if(maze[h][w]=='.'){
        ret = max(ret, far_dist(maze,h,w, num_roads));
      }
    }
  }
  cout << ret << endl;
  return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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 int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

void fail(){
  cout << 0 << endl;
  exit(0);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  if(b<a || n==0 || n==1&&a!=b) fail();
  if(n==1&&a==b){
    cout<<1<<endl;
    return 0;
  }
  cout<<(b-a)*(n-2)+1<<endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    b:usize,
    }
    println!("{}",if a+b==15{"+"}else if a*b==15{"*"}else{"x"})
}

Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,sum=0;
	cin>>n;
	long long int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int x=0;
	for(long long int i=0;i<n;i++)
	{
		//for(long long int j=i+1;j<n;j++)
	//	{
		//	if(i<j)
		//	{
		sum = (sum +((long long int )a[i]*x))%1000000007;
		x = (x+a[i])%1000000007;
			
	//	}
	//}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 5132
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    cout << N / 3 << endl;
}


Measured memory_bytes: 256
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef SHUBHAM107
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD) {
	a %= m; ll res = 1; while (b) {if (b & 1)res = res * a % m; a = a * a % m; b >>= 1;}
	return res;
}
ll bpow(ll a, ll b) {ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a) {return modpow(a, MOD - 2, MOD);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}

const int mxN = 2e5 + 5;
void solve() {
	ll x;
	cin >> x;
	double ans = 100;
	int years = 0;
	while(ans < x){
		years++;
		ans *= 1.01;
		ans = floor(ans);
	}
	cout << years;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef SHUBHAM107
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}


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

int64_t solve(int N, const vector<int> &perm){
  using coord= int;
  constexpr char block= '#';
  constexpr char vacant= '.';
  const vector<pair<int,int>> diff= {make_pair(0,-1), make_pair(-1,0), make_pair(1,0), make_pair(0,1) }; // 探索方向

  vector<string> board(N, string(N, block));
  vector<vector<int>> dist(N, vector<int>(N));
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      dist.at(i).at(j)= min(min(i, N-1-i), min(j, N-1-j));
    }
  }

  int64_t ans= 0;
  for(size_t i=0; i<perm.size(); i++){
    int s= perm.at(i);
    int s_x= s/ N;
    int s_y= s% N;

    ans+= dist.at(s_x).at(s_y);
    board.at(s_x).at(s_y)= vacant;

    deque<coord> bfs;
    bfs.push_front(s);
    while( !bfs.empty() ){
      coord p= bfs.front();
      bfs.pop_front();
      int x= p/ N;
      int y= p% N;

      for(auto& [dx,dy]:diff){
        if(x+dx <= -1 || x+dx >= N || y+dy <= -1 || y+dy >= N){ continue; }
        else if(board.at(x).at(y)!=block){
          if(dist.at(x+dx).at(y+dy) > dist.at(x).at(y)){
            dist.at(x+dx).at(y+dy)= dist.at(x).at(y);
            bfs.push_front((x+dx)*N+ y+dy);
          }
        }
        else if(board.at(x).at(y)==block){
          if(dist.at(x+dx).at(y+dy) > dist.at(x).at(y)+ 1){
            dist.at(x+dx).at(y+dy)= dist.at(x).at(y)+ 1;
            bfs.push_front((x+dx)*N+ y+dy);
          }
        }
      }
    }
  }

  return ans;
}

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

  vector<int> perm(N*N);
  for(size_t i=0; i<perm.size(); i++){
    cin >> perm.at(i);
    perm.at(i)--; // 1-indexed -> 0-indexed
  }

  int64_t ans= solve(N, perm);

  cout << ans << endl;
}

Measured memory_bytes: 6024
#include<iostream>
#include<cstdio>
#include<cstring>

int dis(int a,int b)
{
	int ret;
	if(a<b)
	{
		int d=b-a;
		ret=d/2;
		d%=2;
		ret+=d*2;
	}
	else 
	{
		int d=a-b;
		ret=d;
	}
	return ret;
}

int main()
{
	int a,b,c,ans=12312321;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=-100;i<=100;i++)
		ans=std::min(ans,dis(a,i)+dis(b,i)+dis(c,i));
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

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

    int a; cin >> a;
    string s; cin >> s;

    if(a >=3200) cout << s << endl;
    else cout << "red" << endl;
        

    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 1000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    ll I,O,T,J,L,S,Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;
    //実はI,O,J,Lだけで良い
    ll ret = O * 2;
    ll ret2 = 0;
    ret2 = max(ret2,ret + I / 2 * 4 + J / 2 * 4 + L / 2 * 4);
    if(I > 0 && J > 0 && L > 0) {
        ret2 = max(ret2,ret + 6 + (I - 1) / 2 * 4 + (J - 1) / 2 * 4 + (L - 1) / 2 * 4);
    }
    cout << ret2 / 2 << endl;
}

Measured memory_bytes: 3584