akhauriyash/Code-Regression huggingface dataset:
/* ex9_2
   reo012 */

#include <stdio.h>
#include <stdlib.h>

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//リストにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    //元のリストの前に追加する
    new->elem = elem;
    new->next = *first;
    *first = new;
    return;
}

//リストからデータを削除する
void pop(node **first){
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return;
}

int main(void){
    char input_s[100001];
    int i, count=0;
    //最初のノードの指す先
    node *first = NULL;

    //入力
    scanf("%s", input_s);

    //入力された文字列の情報をリストに順に追加
    //ただし、i-1回目に追加されたキューブがi回目のキューブと異なるなら、i-1回目をリストから削除
    for(i=0; input_s[i]!='\0'; i++){
        if(first==NULL || input_s[i]==first->elem){ //最初のキューブ・一個前と同じキューブ
            push(&first, input_s[i]);   //リストに追加
        }else{  //一個前のキューブと異なるとき
            pop(&first);    //一個前のキューブ（リストの先頭にある）を削除
            count += 2;     //countを2増やす
        }
    }
    //答えのcountを出力
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 4956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,X;
  cin>>A>>B>>C>>X;
  
  int count=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(500*i+100*j+50*k==X)count++;
      }
    }
  }
  cout<<count<<endl;
}

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

int main(){
  int n; cin >> n;
  int k; cin >> k;
  vector<int> v(n, 0);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int hi = v[k-1] - v[0];
  for(int i = 0; i < n-k+1; i++){
    int res = v[k-1+i] - v[i];
    if(res < hi){hi = res;}
   // cout << hi << endl;
  }
  cout << hi << endl;
}




Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;
int a,b,c,x,n,maxi,mini,i,v[10],nrblank,nrmin,l,open,closed;
char s[500];

int main()
{
    cin>>n;
    cin>>s;
    l=strlen(s);
    open=0; closed=0;
    for(i=0;i<l;i++)
    {
        if(s[i]=='(')
        {
            open++;
        }
        else
        {
            if(open>0) open--;
            else closed++;
        }
    }
    for(i=1;i<=closed;i++) cout<<'(';
    cout<<s;
    for(i=1;i<=open;i++) cout<<')';
    cout<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
 
struct edge{
    int v;
    string cost;
    edge(int v_, string cost_){
        v = v_; cost = cost_;
    }
};
bool operator<(const edge& a, const edge& b){
    return a.cost > b.cost;
}
const int MAX_V = 40;
const int MAX_E = 400;
// dp[v][l] := テゥツ?づァツつケ v, テヲツ鳴?・ツュツ療・ツ按療」ツ?ョテゥツ閉キテ」ツ??l テ」ツ?ョテ」ツ?ィテ」ツ?催」ツ?ョテヲツ慊?・ツシツキテ」ツ?ョテ・ツ堕ェテヲツ鳴?
string dp[MAX_V][500];
vector<edge> G[MAX_V];
int n, a, s, g;
 
void add_edge(int u, int v, string cost){
    G[u].push_back( edge(v, cost) );
}
 
void dfs(int v, vector<bool>& visited){
    visited[v] = true;
    for(int i=0 ; i < G[v].size() ; i++ ){
        int to = G[v][i].v;
        if( !visited[to] ){
            dfs(to, visited);
        }
    }
}
 
bool is_exist(){
    vector<bool> visited(n, false);
    dfs(s, visited);
    if( !visited[g] ) return false;
     
    return true;
}
 
string solve(){
    for(int i=0 ; i < MAX_V ; i++ ){
        fill(dp[i], dp[i] + 500, "~");
    }
    int N = 6 * (n - 1); 
    dp[s][0] = "";
    priority_queue<edge> q;
    q.push( edge(s, "") );
     
    string res = "~";
    while( !q.empty() ){
        int v = q.top().v;
        string cost = q.top().cost;
        int l = cost.size();
        q.pop();
         
        if( v == g ){
            res = min(res, cost);
            break;
        }
         
        for(int i=0 ; i < G[v].size() ; i++ ){
            int to = G[v][i].v;
            string add_cost = G[v][i].cost;
            string next_cost = cost + add_cost;
            int l_ = next_cost.size();
            if( 500 <= next_cost.size() ){
                continue;
            }
            if( next_cost < dp[to][l_] ){
                dp[to][l_] = next_cost;
                q.push( edge(to, dp[to][l_]) );
            }
        }
    }
    for(int i=N ; i < 500 ; i++ ){
        if( dp[g][i].size() == i ) return "~";
    }
    return res;
}
 
int main(){
    while( cin >> n >> a >> s >> g, n ){
        for(int i=0 ; i < MAX_V ; i++ ) G[i].clear();    
         
        for(int i=0 ; i < a ; i++ ){
            int x, y;
            string lab;
            cin >> x >> y >> lab;
            add_edge(x, y, lab);
        }
        if( !is_exist() ){
            cout << "NO" << endl;
        }else{
            string ans = solve();
            if( ans == "~" ) ans = "NO";
            cout << ans << endl;
        }
    }
}

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

using namespace std;
typedef long long LL;

int main(){
  int Q;
  cin >> Q;
  vector<int> l(Q), r(Q);
  rep(i,Q) cin >> l[i] >> r[i];
  int num[100010]={0};
  for(int N=3; N<=100000; N+=2){
    bool primeflag=true;
    for(int j=2; j*j<=N; j++){
      if(N%j==0){
        primeflag=false;
        break;
      }
    }
    for(int j=2; j*j<=(N+1)/2; j++){
      if((N+1)/2%j==0){
        primeflag=false;
        break;
      }
    }
    num[N]=num[N-2];
    if(primeflag) num[N]++;
  }
  rep(i,Q){
    if(l[i]==1) cout << num[r[i]] << endl;
    else cout << num[r[i]]-num[l[i]-2] << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
    public static void main (String args[]) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int R[] = new int[n];
	int max = (int)Math.pow(10,10)*(-1),min;
	for(int i = 0;i < n;i++){
	    R[i] = sc.nextInt();
	}
	min = R[0];
	for(int j = 1;j < n;j++){	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	}
       	System.out.println(max);
    }
}






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

int main(void){
	int n, x;
	vector<int> l;

	cin >> n >> x;
	l.resize(n + 1);
	for (int i = 0; i < n; i++){
		cin >> l[i];
	}

	int ans, d;
	ans = 0;
	d = 0;
	while (d <= x){
		d += l[ans];
		ans++;
		if (ans == n + 1)break;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){


    double N;  cin >> N;
    double count = 0;
    for(int i = 1 ; i <= N ; i++)
      if(i % 2 == 1)  count += 1;

    SCOUT(count / N) << endl;

    return 0;
}


Measured memory_bytes: 256
s=j=0
a=[];
b=[];
d=[];
for i,x in enumerate(input()):
    if x=='\\':a+=[i]
    elif x=='/' and a:
        j=a.pop()
        c=i-j;s+=c
        while b and b[-1]>j:c+=d.pop();b.pop()
        b+=[j];d+=[c]
print(s)
print(len(b),*(d))



Measured memory_bytes: 6252
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j;
	char a[5][5];
	for(i=0;i<3;i++){
		scanf("%s",a[i]);
	}
	printf("%c%c%c",a[0][0],a[1][1],a[2][2]);
	return 0;
}

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


signed main()
{
  int N;
  int a[500001];

  cin >> N;

  int sum = 0;
  Rep(i, N) {
    cin >> a[i];
    sum += a[i];
  }

  sum -= a[0];
  int tmp = a[0];
  int ans = INF;
  for ( int i = 1; i < N; i++ ) {
    ans = min(ans, abs(tmp - sum));
    tmp += a[i];
    sum -= a[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
const ll MOD = 1e9 + 7;

ll power(int x, int y) {
    if (y == 0) return 0;
    if (y == 1) return x;
    ll p = power(x, y >> 1);
    if (y & 1) return p * p % MOD * x % MOD;
    else return p * p % MOD;
}

int main() {
    int N;
    cin >> N;
    ll ans = power(10, N) - 2 * power(9, N) + power(8, N);
    cout << (ans + 2 * MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e6 + 5;

int main(){
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    ll d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    ll a,b,k;
    cin >> a >> b >> k;
    cout << max(0LL, a - k) << " " << max(0LL, min(b, a + b - k)) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val k = sc.nextInt()
    val s = sc.next()
    println(problem168b(k, s))
}

fun problem168b(k: Int, s: String): String {
    if (s.length <= k) return s
    return s.take(k) + "..."
}

Measured memory_bytes: 37756
# D

N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

ans = sum(p[0:K])
ans_tmp = ans
for i in range(K, N):
#    print(p)
#    print(-p[i-K] + p[K])
    ans_tmp = ans_tmp - p[i-K] + p[i]
#    print(ans_tmp)
    ans = max(ans, ans_tmp)

ans = (ans+K)/2

print(ans)

Measured memory_bytes: 24812
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  ll x;
  cin>>x;
  ll ans = 1e15;
  ll best;
  for(ll base=1;base<=100;base++){
  	for(ll power=2;power<=50;power++){
  		if(abs(x-pow(base,power))<ans&&pow(base,power)<=x){
  			ans=abs(x-pow(base,power));
  			best=pow(base,power);
  		}
  	}
  }
  cout<<best<<endl;
}









Measured memory_bytes: 640
using System;
using System.Linq;

namespace AtCoderContestScheduling
{
    class Program
    {
        static void Main(string[] args)
        {
            const int n_contest = 26;
            int D = GetInt();
            var c = GetIntArray();
            var s = new int[D][];
            for(int i = 0; i < D; i++)
            {
                s[i] = GetIntArray();
            }
            int sumC = 0;
            for(int i = 0; i < n_contest; i++)
            {
                sumC += c[i];
            }

            var decrement = new int[n_contest];
            int[] contest = new int[D];
            int[] second = new int[D];
            int cost = sumC;
            int score = 0;
            for(int i = 0; i < D; i++)
            {
                int max_eval = int.MinValue;
                for (int j = 0; j < n_contest; j++)
                {
                    decrement[j] += c[j];
                    if (max_eval < decrement[j] + s[i][j])
                    {
                        max_eval = decrement[j] + s[i][j];
                        second[i] = contest[i];
                        contest[i] = j;
                    }
                }
                cost -= decrement[contest[i]];
                decrement[contest[i]] = 0;
                score += s[i][contest[i]] - cost;
                cost += sumC;
            }
            int m = 0;
            while(m < D)
            {
                int temp = score;
                temp += s[m][second[m]] - s[m][contest[m]] + (c[second[m]] - c[contest[m]]) * (D - m);
                if (temp > score)
                {
                    (second[m], contest[m]) = Swap(contest[m], second[m]);
                    score = temp;
                    m = 0;
                }
                m++;
            }
            
            //Console.WriteLine(score);
            foreach (var item in contest)
            {
                Console.WriteLine(item + 1);
            }

        }

        public static (int a, int b) Swap(int a, int b) => (b, a);
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray();
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray();

    }
}


Measured memory_bytes: 28920
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

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

    int n;
    string s,ans;
    cin >> n >> s;

    for (int i=0;i<=s.length()-1;i++)
    {
        int a=int(s[i]);
        a=a+n;
        if (a>90)
        {
            a=a-90;
            a=a+64;
        }
        ans=ans+char(a);
    }

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


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    long long n, m, l;
    cin >>n >>m >>l;
    int A[n][m] ;
    int B[m][l] ;
    long long  C[n][l] ={};
    for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            cin >> A[i][j];
        }
    }for (int i=0; i<m; i++){
        for (int j=0; j<l; j++){
            cin >> B[i][j];
        }
    }for(int i=0; i<n; i++){
        for (int j=0; j<l; j++){
            for(int k=0; k<m; k++){
                C[i][j] += A[i][k]*B[k][j];
            }
            
        }  
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            cout<<C[i][j];
            if(j!=l-1){
                cout<<" ";
            
            }else{
                cout<<endl;
            }
        }
    }
    return 0;
}




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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back

const int maxn = 1e5 + 4;

int n, m, G;
vector<int> has[maxn], adj[maxn];
int a[maxn], val[maxn], vs[maxn];

void dfs(int u) {
  if (vs[u]) return;
  vs[u] = 1;
  has[G].pb(a[u]);
  val[u] = G;
  for (auto v : adj[u]) {
    dfs(v);
  }
}

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

  rep(i, 0, n) cin >> a[i];
  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    adj[x].pb(y);
    adj[y].pb(x);
  }

  int ans = 0;
  rep(i, 0, n) {
    if (!vs[i]) {
      G++;
      dfs(i);
      for (auto u : has[G]) {
        if (val[u - 1] == G) {
          ans++;
        }
      }
    }
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 11900
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
string s;
int main()
{
	cin>>s;
	cout<<s[0]<<s.size()-2<<s[s.size()-1];
	
	return 0;
}

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

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題155
            //Console.WriteLine("test");


            int n = int.Parse(Console.ReadLine());

            long[] l = new long[n];

            string[] line = Console.ReadLine().Split(' ');

            int ans = 0;

            for (int i = 0; i < n; i++)
            {
                l[i] = long.Parse(line[i]);
                //Console.WriteLine(l[i]);
            }

            for (int i = 0; i < n - 2; i++)
            {
                for (int j = i + 1; j < n - 1; j++)
                {


                    if (l[i] == l[j])
                    {
                        continue;
                    }

                    for (int k = j + 1; k < n; k++)
                    {
                        //Console.Write(l[i] + " ");
                        //Console.Write(l[j] + " ");
                        //Console.Write(l[k] + " ");

                        //Console.WriteLine(" ");

                        if (l[j] == l[k] || l[i] == l[k])
                        {
                            continue;
                        }

                        if (l[i] < l[j] + l[k] && l[i] > Math.Abs(l[j] - l[k]))
                            ans++;
                    }
                }
            }

            Console.WriteLine(ans);
        }

    }





    
}


Measured memory_bytes: 27552
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
long long C[505][505],dp[505][505],sum[505][505],dp2[505];
int main(){
	int n,k;
	long long m;
	cin>>n>>k>>m;
//	cout<<"haha";
	for(int i=0;i<=n+5;i++){
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++) {
			C[i][j]=C[i-1][j-1]+C[i-1][j];
			if(C[i][j]>=m) C[i][j]-=m; 
		}
	}
	for(int i=0;i<=k;i++) dp[1][i]=1;
	for(int i=k;i>=0;i--) sum[1][i]=dp[1][i]+sum[1][i+1];
	
	for(int i=2;i<=n+1;i++){
	//	cout<<"ha";
		for(int j=0;j<=k;j++){
			for(int kk=1;kk<i;kk++){
				dp[i][j]=(dp[i][j]+dp[i-kk][j]*sum[kk][j+1]%m*C[i-2][kk-1]%m)%m;
			}
		}
		for(int j=k;j>=0;j--){
			sum[i][j]=dp[i][j]+sum[i][j+1];
			if(sum[i][j]>=m) sum[i][j]-=m;
		}
	}
	dp2[1]=sum[1][1];
	for(int i=2;i<=n;i++){
		dp2[i]=sum[i][1];
		for(int j=1;j<i;j++){
			dp2[i]=(dp2[i]+dp2[i-j]*sum[j][1]%m*C[i-1][j-1])%m;
		}
	}
//	cout<<dp2[n];
	cout<<dp[n+1][0];
}

Measured memory_bytes: 4608
"""
author : halo2halo
date : 2, Feb, 2020
"""

import sys
import itertools

import numpy as np

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

a, b, x = map(int, readline().split())

print(b // x - (a + x - 1) // x + 1)


Measured memory_bytes: 12428
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace AtCoder {

    class MainClass {

        public static void Main(string[] args) {

            var array = Console.ReadLine().Split(' ');
            var h = int.Parse(array[0]);
            var a = int.Parse(array[1]);

            var count = 0;

            while(h > 0) {

                h -= a;
                count++;

            }

            Console.WriteLine(count);


        }

        

    }
}


Measured memory_bytes: 27484
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
deque<char> d;
int main()
{
    //IOS;
    string s;
    cin >> s;
    for(auto c : s) d.push_back(c);
    int cnt = 0;
    int n;
    cin >> n;
    while (n--)
    {
        int t;
        cin >> t;
        if (t == 1)
            ++cnt;
        else
        {
            int f;
            char c;
            cin >> f;
            cin >> c;
            if (f == 1)
            {
                if (cnt % 2 == 0)
                {
                    d.push_front(c);
                }
                else
                {
                    d.push_back(c);
                }
            }
            else
            {
                if (cnt % 2 == 0)
                {
                    d.push_back(c);
                }
                else
                {
                    d.push_front(c);
                }
            }
        }
    }
    if (cnt & 1)
    {
        reverse(d.begin(), d.end());
    }
    for (int i = 0; i < d.size(); i++)
    {
        cout << d.at(i);
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n, a, b;

	cin >> n >> a >> b;

    Out(min(n * a, b));
	
	return 0;
}


Measured memory_bytes: 256
c = [[int(i) for i in input().split()] for _ in range(3)]
x = 0
for i in range(2):
    if c[0][i] - c[0][i + 1] == c[1][i] - c[1][i + 1] == c[2][i] - c[2][i + 1]:
        x += 1
for i in range(2):
    if c[i][0] - c[i + 1][0] == c[i][1] - c[i + 1][1] == c[i][2] - c[i + 1][2]:
        x += 1
if x == 4:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int arr[55];
int main()
{
    int n, k;
    cin >> n >> k;
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    int R = min(n, k);
    int ans = 0;
    for(int i=0; i<=R; i++)
    {
        for(int j=0; j<=R; j++)
        {
            if(i+j > R)
            {
                break;
            }

            vector<int> negg;
            int sum = 0;
            for(int a=0; a<i; a++)
            {
                sum += arr[a];
                if(arr[a] < 0)
                {
                    negg.push_back(arr[a]);
                }
            }

            for(int b = 0; b<j; b++)
            {
                sum += arr[n - b - 1];
                if(arr[n-b-1] < 0)
                {
                    negg.push_back(arr[n-b-1]);
                }
            }

            ans = max(ans, sum);
            sort(negg.begin(), negg.end());
            for(int c =0; c < negg.size() && c + i + j < k; c++)
            {
                sum -= negg[c];
                ans = max(ans, sum);
            }
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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



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




int main() {

	ll N, M;
	cin >> N;
	vector<string> s(N + 1);

	repn(i, N) cin >> s[i];

	cin >> M;
	vector<string> t(M + 1);
	repn(i, M) cin >> t[i];

	ll ans = 0;

	repn(i, N) {
		ll v = 0;
		repn(j, N) if (s[i] == s[j]) { v++; }
		repn(j, M) if (s[i] == t[j]) { v--; }

		ans = max(v, ans);
	}

	cout << ans;


	system("PAUSE");

}


Measured memory_bytes: 504
#include <iostream>
#include <algorithm> // max(),min()
#include <cstdlib>  // abs() for integer
using namespace std;

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



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

llint a, b, Q;
llint s[100005], t[100005];

llint getLS(llint x)
{
	llint p = upper_bound(s, s+a, x) - s;
	if(p == 0) return -inf;
	else return s[p-1];
}
llint getLT(llint x)
{
	llint p = upper_bound(t, t+b, x) - t;
	if(p == 0) return -inf;
	else return t[p-1];
}

llint getRS(llint x)
{
	llint p = lower_bound(s, s+a, x) - s;
	if(p == a) return inf;
	else return s[p];
}
llint getRT(llint x)
{
	llint p = lower_bound(t, t+b, x) - t;
	if(p == b) return inf;
	else return t[p];
}

int main(void)
{
	cin >> a >> b >> Q;
	for(int i = 0; i < a; i++) cin >> s[i];
	for(int i = 0; i < b; i++) cin >> t[i];
	
	llint x;
	for(int q = 0; q < Q; q++){
		cin >> x;
		
		llint ans = abs(x-getLS(x)) + abs(getLS(x)-getLT(x));
		ans = min(ans, abs(x-getLS(x)) + abs(getLS(x)-getRT(x)));
		ans = min(ans, abs(x-getRS(x)) + abs(getRS(x)-getLT(x)));
		ans = min(ans, abs(x-getRS(x)) + abs(getRS(x)-getRT(x)));
		
		ans = min(ans, abs(x-getLT(x)) + abs(getLT(x)-getLS(x)));
		ans = min(ans, abs(x-getLT(x)) + abs(getLT(x)-getRS(x)));
		ans = min(ans, abs(x-getRT(x)) + abs(getRT(x)-getLS(x)));
		ans = min(ans, abs(x-getRT(x)) + abs(getRT(x)-getRS(x)));
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
	long long n, k;
	cin >> n >> k;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		A[i]--;
	}
	int a, b;
	vector<int> x(n);
	vector<int> order(n, -1);
	for (int i = 0, y = 0; ; i++) {
		if (order[y] != -1) {
			a = order[y];
			b = i;
			break;
		}
		order[y] = i;
		x[i] = y;
		y = A[y];
	}
	const int t = b - a;

	int ans;
	if (k < a) ans = x[k] + 1;
	else {
		k -= a;
		ans = x[a + k % t] + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5224
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define SIZE 100001
typedef long long ll;
int n,h[SIZE],ans=0,a,b;

int roundup(int a, int b){
  return (a+b-1)/b;
}

bool check(int mid){
  ll count=0;
  REP(i,n) if((ll)h[i]>(ll)b*(ll)mid) count+=(ll)roundup(h[i]-b*mid,a-b);
  if(count<=(ll)mid) return true;
  else return false;
}

int binary_search(){
  int lb=0,ub=1e9,mid;
  while(ub-lb>1){
    mid=(lb+ub)/2;
    (check(mid)?ub:lb)=mid;
  }
  return ub;
}

int main(){
  cin>>n>>a>>b;
  REP(i,n) cin>>h[i];
  cout<<binary_search();
}


Measured memory_bytes: 3996
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


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

	int cnt = (s[0] == '1') + (s[1] == '1') + (s[2] == '1');
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
int main () {
  int w,h,x,y;
  scanf ("%d %d %d %d",&w,&h,&x,&y);
  printf ("%.12Lf %d\n",(ld)w * (ld)h / 2,x + x == w && y + y == h);
  return 0;
}


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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=200005;
const LL INF=1e18;
int n,X;
int a[N];
LL f(int x){
	LL ans=(LL)X*x;
	int c=0,v=5,t=2;
	Fod(i,n,1){
		ans+=(LL)a[i]*v;
		if ((++c)==x)
			c=0,v=t*2+1,t++;
	}
	return ans;
}
int main(){
	n=read(),X=read();
	For(i,1,n)
		a[i]=read();
	LL ans=INF;
	int L=1,R=n;
	while (L+6<=R){
		int Lmid=(L*2+R)/3;
		int Rmid=(R*2+L)/3;
		LL fL=f(Lmid);
		LL fR=f(Rmid);
		ans=min(ans,fL);
		ans=min(ans,fR);
		if (fL>fR)
			L=Lmid;
		else
			R=Rmid;
	}
	For(i,L,R)
		ans=min(ans,f(i));
	ans+=(LL)X*n;
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    int b[n - 1];
    int a[n];
    REP(i, n - 1)
    {
        cin >> b[i];
    }
    a[0] = b[0];
    a[1] = b[0];

    rep(i, 1, n - 1)
    {
        a[i] = min(b[i], a[i]);
        a[i + 1] = b[i];
    }

    long long ans = 0;
    REP(i, n)
    {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


public class Main {
    static Scanner s = new Scanner(System.in);
    static int[] prime = new int[200000];
    static ArrayList<Integer> ans =new ArrayList<Integer>();

    public static void main(String[] args) {
        calcPrime();
        while (true) {
            int N=s.nextInt();
            int P = s.nextInt();
            if(N==-1) break;

            ans.clear();
            int count=0;
            int[] prime2 =new int[P];
            for (int i=N+1;count<P;i++){
                if(prime[i] ==0)continue;
                prime2[count]=i;
                count++;
            }

            for (int i=0;i<P;i++){
                for(int j=i;j<P;j++){
                    ans.add(prime2[i] + prime2[j]);
                }
            }
            Collections.sort(ans);
            System.out.println(ans.get(P-1));
        }
    }
    static void calcPrime(){
        for(int i=0;i<200000;i++)
            prime[i]=i;
        prime[1]=0;

        for(int i=2;i<200000;i++){
            for (int j=2;j<=Math.sqrt(i);j++){
                if(i%j==0){
                    prime[i]=0;
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 65900
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

n = inp()
c = input()
cntR = 0
for i in range(n):
    if c[i] == 'R':
        cntR += 1
ans = cntR
for i in range(cntR):
    if c[i] == 'R':
        ans -= 1
print(ans)


# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)


Measured memory_bytes: 9496
def myAnswer(D:int, N:int) -> int:
   if(N == 100):
      return 100**D * (N + 1 )
   else:
      return 100**D * N


def modelAnswer():
   tmp=1
def main():
   D,N =map(int,input().split())
   print(myAnswer(D,N))
if __name__ == '__main__':
   main()

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

int64_t split(int target, int n) {
  int64_t result = 1;
  rep(i,target) {
    result *= n;
    result = result % Q;
  }
  return result;
}

int main() {
  //input
  int N;
  cin >> N;
  vector<int> D(N,0);
  rep(i,N) {
    cin >> D.at(i);
  }
  //calc & output  
  int firstD = D.at(0);
  if ( firstD != 0 ) {
    cout << 0 << endl;
    return 0;
  }
  int DD;
  map<int,int> group;
  int max = -1;
  rep(i,N) {
    DD = D.at(i);
    if ( group.count(DD) ) {
      group[DD]++;
    }
    else {
      group[DD] = 1;
    }
    if ( DD > max ) {
      max = DD;
    }
  }
  int cur = group[0];
  int64_t answer = 0;
  if ( cur != 1 ) {
    answer = 0;
  }
  else {
    answer = cur;
    int pre = cur;
    for(int layer = 1; layer <= max; layer++) {
      cur = group[layer];
//      cout << layer << " --> " << cur << endl;
      if ( cur == 0 ) {
        answer = 0;
        break;
      }
      int64_t layer_n = split(cur, pre);
      layer_n = layer_n % Q;
      answer = answer * layer_n;
      answer = answer % Q;
      pre = cur;
    }
  }
  //output
  answer = answer % Q;
  cout << answer << endl;
}


Measured memory_bytes: 5376
def snaketoy(n , k , l):

    ans = 0
    l.sort(reverse=True)
    ans = int(sum(l[:k]))

    return ans

def main():
    n , k = map(int , input().split())
    l = list(map(int , input().split()))
    print(snaketoy(n , k , l))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))

#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                                          "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                                          "--eval" "(push :child-sbcl *features*)"
                                          "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))

(defparameter +mod+ (+ (expt 10 9) 7))

(defun mod+(&rest exp)
  (reduce (lambda (a b)
            (mod (+ a b) +mod+))
          exp))

(defun mod-(&rest exp)
  (reducce (lambda (a b)
             (mod (- a b) +mod+))
           exp))

(defun mod*(&rest exp)
  (reduce (lambda (a b)
            (mod (* a b) +mod+))
          exp))

(defun modpow (x y);x^y
  (if (zerop y) 1
      (mod* (if (oddp y) x 1)
            (modpow (mod* x x) (ash y -1)))))

(defun modinv (x)
  (modpow x (- +mod+ 2)))

(defun mod/(&rest exp)
  (reduce (lambda (a b)
            (mod (* a (modinv b)) +mod+))
          exp))

(defparameter N_MAX 200010)

(defvar factorial-memo (make-array N_MAX :initial-element nil))
(defvar factorial-inv-memo (make-array N_MAX :initial-element nil))
(defun factorial (x)
  (if (<= x 1) 1
      (if (aref factorial-memo x)
          (aref factorial-memo x)
          (setf (aref factorial-memo x) (mod* x (factorial (1- x)))))))

(defun factorial-inv (x)
  (if (= x (1- N_MAX))
      (modinv (factorial x))
      (if (aref factorial-inv-memo x)
          (aref factorial-inv-memo x)
          (setf (aref factorial-inv-memo x) (mod* (1+ x) (factorial-inv (1+ x)))))))

(defun combination (a b)
  (mod* (factorial a) (factorial-inv b) (factorial-inv (- a b))))

(defun main (n a b c)
  (let*
      ((need-one-win (mod/ 100 (- 100 c)))
       (win-a-p (mod/ a (+ a b)))
       (win-b-p (mod/ b (+ a b)))
       (ans 0)
       (pow-a-p (modpow win-a-p n))
       (pow-b-p (modpow win-b-p n))
       (sum-a-p 1)
       (sum-b-p 1))
    (dotimes (i n)
      (let* ((turn (+ n i))
             (way (combination (1- turn) i)))
        (setf ans (mod+ ans
                        (mod* turn need-one-win way
                              pow-a-p
                              sum-b-p)))
        (setf ans (mod+ ans
                        (mod* turn need-one-win way
                              pow-b-p
                              sum-a-p)))
        (setf sum-a-p (mod* sum-a-p win-a-p))
        (setf sum-b-p (mod* sum-b-p win-b-p))))
    (write ans)))


(main (read) (read) (read) (read))


Measured memory_bytes: 80952
def gcd(a, b):
	while b!= 0:
		a, b = b, a%b
	return a

def gcd_many(x):
	x = sorted(x)
	y = x[0]
	for i in range(1, len(x)):
		y = gcd(y, x[i])
	return y


n, x = [int(el) for el in input().split(' ')]
Y = [abs(int(el) - x) for el in input().split(' ')]
print(gcd_many(Y))


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

using namespace std;

typedef long long int ll;
#define pb push_back
#define fst first
#define snd second

int main()
{
	int h, w;
	cin >> h >> w;
	if(w == 1 || h == 1)
	{
		cout << "1\n";
	}
	else
	{
		cout << (ll)(ceil(w/2.0)*ceil(h/2.0) + (w - ceil(w/2.0))*(h/2))<< "\n";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int n;
cin>>n;
int t=0,x=0,y=0,a,b,c;
bool f=true;
for(int i=0;i<n;i++)
{
	cin>>a>>b>>c;
	if(a-t-abs(b-x)-abs(c-y)>=0&&(a-t-abs(b-x)-abs(c-y))%2==0)
	{
		x=b;
		y=c;
		t=a;
	}
	else
	{
		f=false;
		break;
	}
}
if(f)
cout<<"Yes";
else
cout<<"No";
return 0;	
}

Measured memory_bytes: 256
#include <iostream>

int main(){
  int W, H, N;
  int a[100]={0}, b[100]={0}, c[100]={0};

  std::cin >> W >> H >> N;

  int minx=W, miny=H, maxx=0, maxy=0;

  for(int i= 0; i < N; i++){
    std::cin >> a[i] >> b[i] >> c[i];
    if(c[i] == 1 && maxx < a[i]) maxx = a[i];
    if(c[i] == 2 && minx > a[i]) minx = a[i];
    if(c[i] == 3 && maxy < b[i]) maxy = b[i];
    if(c[i] == 4 && miny > b[i]) miny = b[i];
  }

  int tate, yoko;
  yoko = minx-maxx;
  tate = miny-maxy;

  if(tate <= 0) tate = 0;
  if(yoko <= 0) yoko = 0;

  std::cout << tate*yoko << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  int ans = (1000 - N % 1000) % 1000;
  cout << ans << '\n';  
  return 0;
}

Measured memory_bytes: 3620
use std::io;

fn main() {
    let mut sec = String::new();
    io::stdin().read_line(&mut sec).unwrap();
    let sec: i32 = sec.trim().parse().unwrap();
    let (h, m, s) = (sec / 3600, (sec / 60) % 60, sec % 60);
    println!("{}:{}:{}", h, m, s);
}



Measured memory_bytes: 5032
x,y = map(int,input().split())
M = 10**9+7

def pow(a,b,M):
    if b == 0:
        return 1
    else:
        if b % 2 == 0:
            return pow((a**2)%M,b//2,M) % M
        else:
            return (a * pow((a**2)%M,b//2,M)) % M

def inv(a,M):
    return pow(a,M-2,M)

def comb(n,k,M):
    nume,deno = 1,1
    for i in range(1,k+1):
        deno = (deno * (n-i+1)) % M
        nume = (nume * i) % M
    return (deno * inv(nume,M)) % M

if (x+y) % 3 != 0 or (2*x < y or 2*y < x):
    print(0)
else:
    mov = (x+y)//3
    x,y = x-mov,y-mov
    print(comb(mov,x,M))


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

 int main() 
    {
    	int n;
    	cin>>n;
    	int arr[n];
    	for(int i=0;i<n;i++)
    	 cin>>arr[i];
    	 int dp[n];
    	 
    	
    	dp[0]=0;
    	dp[1]=abs(arr[1]-arr[0]);
    	
    	for(int i=2;i<n;i++)
    	  dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));
    	

    	
    	cout<<dp[n-1];
    	
    }

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	k := getNextInt(scanner)
	q := getNextInt(scanner)
	aa := make(AA, n)
	for i := 0; i < n; i++ {
		aa[i].a = getNextInt(scanner)
		aa[i].i = i
	}

	sort.Sort(aa)

	hp := &IntHeap{}

	heap.Init(hp)

	temp := make([]int, n)
	min := math.MaxInt32
	for i := 0; i < n-q+1; i++ {
		for j := 0; j < n; j++ {
			temp[aa[j].i] = aa[j].a
		}
		for j := 0; j < i; j++ {
			heap.Push(hp, aa[j].i)
		}
		heap.Push(hp, n)
		prev := 0
		ans := make([]int, 0)
		for hp.Len() > 0 {
			p := heap.Pop(hp).(int)
			if p-prev < k {
				prev = p + 1
				continue
			}
			sort.Ints(temp[prev:p])
			for j := prev; j < p-k+1; j++ {
				ans = append(ans, temp[j])
			}
			prev = p + 1
		}
		if len(ans) < q {
			continue
		}
		sort.Ints(ans)
		if min > ans[q-1]-ans[0] {
			min = ans[q-1] - ans[0]
		}
	}

	fmt.Fprintln(writer, min)

	writer.Flush()
}

type A struct {
	a, i int
}

type AA []A

func (a AA) Len() int           { return len(a) }
func (a AA) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a AA) Less(i, j int) bool { return a[i].a < a[j].a }

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 7700
#include<cstdio>
using namespace std;
int main()
{
	int a, b, c, d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a > b)printf("%d\n", b * c + (a - b) * d);
	else printf("%d\n", a * c);
}

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

const int N = 2e5 + 1000;

int n, m;
std::pair<int, int> edge[N];

void init() {
	std::cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		edge[i] = std::make_pair(u, v);
	}
}

void work() {
	static int tmp[N];

	std::memset(tmp, 0, sizeof(tmp));
	for (int i = 1; i <= m; i++) {
		if (edge[i].first == 1) {
			tmp[edge[i].second]++;
		}
		if (edge[i].second == n) {
			tmp[edge[i].first]++;
		}
	}
	if ((*std::max_element(tmp + 1, tmp + n + 1)) == 2) {
		std::cout << "POSSIBLE" << std::endl;
	} else {
		std::cout << "IMPOSSIBLE" << std::endl;
	}
}

int main() {
	init();
	work();

	return 0;
}


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

const int MAXN = 1e5 + 10, P = 1e9 + 7;

int n;

int head[MAXN], cnt;
struct edge { int nxt, to; } e[MAXN << 1];
void add(int u, int v) { e[++cnt].nxt = head[u], e[cnt].to = v, head[u] = cnt; }

int f[MAXN][2];

void dfs(int u, int fa) {
    f[u][0] = f[u][1] = 1;
    for (int i = head[u], v; i; i = e[i].nxt) {
        v = e[i].to;
        if (v == fa) continue;
        dfs(v, u);
        f[u][0] = 1ll * f[u][0] * ((f[v][0] + f[v][1]) % P) % P;
        f[u][1] = 1ll * f[u][1] * f[v][0] % P;
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1, u, v; i < n; ++i) {
        scanf("%d %d", &u, &v);
        add(u, v), add(v, u);
    }
    dfs(1, 0);
    printf("%d\n", (0ll + f[1][1] + f[1][0]) % P);
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void) {
	int N, M, X, Y;
	bool war;
	
	cin >> N >> M >> X >> Y;
	vector<int> x(N);
	vector<int> y(M);
	
	for (int i=0; i<N; i++)cin >> x[i];
	for (int i=0; i<M; i++)cin >> y[i];
	
	int maxX = *max_element(x.begin(), x.end());
	int minY = *min_element(y.begin(), y.end());
	if (maxX < minY) {
		if (minY > X && minY <= Y) {
			war = false;
		} else {
			war = true;
		}
	} else {
		war = true;
	}
	
	printf(war ? "War" : "No War");
	
	return 0;
}

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

A = s[:a]
con = s[a]
B = s[-b:]

flg = True
num = [str(x) for x in range(10)]
num = set(num)

for x in A:
    if x not in num:
        flg = False

for x in B:
    if x not in num:
        flg = False

if con != "-":
    flg = False

print("Yes" if flg else "No")

Measured memory_bytes: 9192