akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A,B,C,D,E,F,G,H,L,M,N,P,Q,R,W,X,Y,Z;
string S,T;
vector<ll> V(100007);

int main(){
  cin >> A >> B;
  cout << (A-1)/B +1 << endl;
}

Measured memory_bytes: 1536
import sys

while True:
    try:
        input = raw_input()
        for i in range(0, 26):
            str = ""
            for c in input:
                if c.isalpha():
                    c = chr(ord(c) + i)
                    if ord(c) > ord('z'):
                        c = chr(ord('a') - ord('z') + ord(c) - 1)
                str += c
            for word in ["this", "that", "the"]:
                if (str.find(word) != -1):
                    print str
                    break
    except EOFError:
        break

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


int main()
{
	double a, b, c, C, pi, s, l, h;
	cin >> a >> b >> C;

	pi = acos(-1);
	C = C / 180 * pi;
	s = a * b * sin(C) / 2;
	c = sqrt(a*a + b * b - 2 * a*b*cos(C));
	l = a + b + c;
	h = b * sin(C);
	printf("%lf\n%lf\n%lf\n", s, l, h);
    return 0;
}



Measured memory_bytes: 3452
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int k = sc.nextInt();
			int s = sc.nextInt();

			int ans = 0;
			for (int a = 0; a <= k; a++) {
				if (a == s) {
					ans++;
					break;
				}
				int bc  = (int) Math.ceil((double) (s - a) / 2);
				if (bc <= k) {
					for (int b = 0; b <= k; b++) {
						if (s - a - b >= 0 && s - a - b <= k) {
							ans++;
						}
					}
				}
			}

			System.out.println(ans);

		} finally {
			sc.close();
		}
	}
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(a, b);
    if (a == 1) {
        if(b==0) {
            cout << " 1 1 0 0 " ;
        } else
          cout << -1;
      return 0;
    } else 
    if (b < pow(2, a)) {
        rep(i, pow(2, a)) {
            if (i == b) continue;
            cout << i << " ";
        }
        cout << b << " ";
        for (int i = pow(2, a)-1; i >= 0; i--) {
            if (i == b) continue;
            cout << i << " ";
        }
        cout << b << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%2==1&&b%2==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		int sum = 0;
		for(int i = 0; i < N; i++) {
			if(i % 2 == 0) sum += a[N - 1 - i];
			else sum -= a[N - 1 - i];
		}
		System.out.println(sum);
	}
}

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

int main(){
    long long N, K;
    cin >> N >> K;

    if(N <= abs(N - K)){
        cout << N << endl;
        return 0;
    }else{
        long long tmp = N;
        tmp = tmp % K;
        while(tmp > abs(tmp - K)){
            tmp = abs(tmp - K);
        }
        cout << tmp << endl;
    }

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

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

//#include "rubo.h"
//#define mp make_pair
//#define pb push_back
#define in int
#define ll long long
#define vc vector
#define SQ(j) (j)*(j)
//#define x first
//#define y second

//#define ld long double
#define dbl  long double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt, ...) (0)
//#define HOME
//#define y0 ngacaleiebinvoaeu
//#define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp

#define db(x) cout << #x << " = " << x << endl
#define dbCont(x) cout << #x << ": "; for(auto shun: x) cout << shun << ' '; cout << endl;

typedef long double ld;

using namespace std;


const int N = 100*1000+5;


int n,m;
vector<int> g[N];
int dp[N];

int used[N];
vector<int> order;
void dfs(int v){
    used[v] = 1;
    for(int to : g[v]){
        if(!used[to]){
            dfs(to);
        }
    }

    order.push_back(v);
}

int main() {
    cin >> n >> m;
    loop(i,m){
        int x,y;
        cin >> x >> y;
        x--,y--;
        g[x].push_back(y);
    }

    for(int i =0 ; i < n; i++){
        if(!used[i]){
            dfs(i);
        }
    }
    reverse(all(order));

//    dbCont(order);


    int res = 0;
    for(int i = 0; i < n; i++){
        for(int to : g[order[i]]){
            dp[to] = max(dp[to], dp[order[i]]+1);

            res = max(res,dp[to]);
        }
    }
    cout << res << endl;

    return 0;
}


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

using i64 = int64_t;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> cake(h, vector<char>(w));
    vector<vector<int>> ans(h, vector<int>(w, 0));
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin >> cake[i][j];
        }
    }
    int num = 1;
    for(int j=0;j<w;++j){
        for(int i=0;i<h;++i){
            if(ans[i][j] != 0)continue;
            if(cake[i][j] == '#'){
                int idx = i;
                while(idx >= 0 && ans[idx][j] == 0){
                    ans[idx][j] = num;
                    idx--;
                }
                idx = i+1;
                while(idx < h && ans[idx][j] == 0 && cake[idx][j] == '.'){
                    ans[idx][j] = num;
                    idx++;
                }
                num++;
            }
        }
    }
    for(int j=0;j<w-1;++j){
        for(int i=0;i<h;++i){
            if(ans[i][j+1] == 0)ans[i][j+1] = ans[i][j];
        }
    }
    for(int j=w-1;j>0;--j){
        for(int i=0;i<h;++i){
            if(ans[i][j-1] == 0)ans[i][j-1] = ans[i][j];
        }
    }

    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(j)cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 1280
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    int n,l;
    cin >> n>> l;
    int ans=-1;
    vec a(n);
    rep(i,n){
        cin >> a[i];
        if(i>=1&&a[i-1]+a[i]>=l){
            ans=i;
        }
    }
    if(ans==-1){
        cout<<"Impossible"<<endl;
    }else{
        cout<<"Possible"<<endl;
        rep(i,ans-1){  
            cout<<i+1<<endl;
        }
        Rreps(i,n-1,ans-1){
            cout<<i+1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3980
def main
  n,m = gets.chomp.split(" ").map(&:to_i)
  ss = []
  ks = []
  m.times do
    k, *s = gets.chomp.split(" ").map(&:to_i)
    ks.push k
    ss.push s
  end
  ps = gets.chomp.split(" ").map(&:to_i)

  ans = 0
  [0, 1].repeated_permutation(n) do |combination|
    flg = true
    (0...m).each do |i|
      cnt = 0
      ss[i].each do |s|
        cnt += combination[s-1]
      end
      if cnt % 2 != ps[i]
        flg = false
        break
      end
    end
    ans += 1 if flg == true
  end
  puts ans
end

main



Measured memory_bytes: 14268
n = int(input())
W = []
flag = True
for i in range(n):
    w = input()
    if w in W:
        flag = False
    if i > 0 and W[i-1][-1] != w[0]:
        flag = False
    W.append(w)

if flag:
    print('Yes')
else:
    print('No')

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

int main()
{
    int a;
    while(cin>>a)
    {
        int a1=a/1000,a2=a/100%10,a3=a/10%10,a4=a%10;
        if(a1==a2&&a1==a3)
            cout<<"Yes"<<endl;
        else if(a2==a3&&a2==a4)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(){
    long n;
    long k;
    long q;
    long a[112345];

    scanf("%ld %ld %ld", &n, &k, &q);
    for(long i=0; i < q; i++){
        scanf("%ld", a + i);
    }

    long score[112345];
    for(long i=0; i < n; i++){
        score[i] = k - q;
    }

    for(long i=0; i < q; i++){
        score[a[i] - 1]++;
    }

    for(long i=0; i < n; i++){
        if(score[i] > 0){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }
    return 0;
}

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

int main(void){
    int n, x[110], y[110], h[110], ans[110], hei = 0;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> x[i] >> y[i] >> h[i];
        ans[i] = -1;
    }
    for(int i=0;i<101;++i){
        for(int j=0;j<101;++j){
            for(int k=0;k<n;++k){
                if(h[k]==0) continue;
                hei = h[k] + abs(i-x[k]) + abs(j-y[k]);
                break;
            }
            int nflg = 1;
            for(int k=0;k<n;++k){
                if(max(hei - abs(x[k]-i) - abs(y[k]-j), 0) != h[k]){
                    nflg = 0;
                    break;
                }
            }
            if(nflg){
                cout << i << " " << j << " " << hei << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

int main(){
    string s;
    cin >> s;
    long long int cnt=1;
    char cur=s[0];
    int i=1;
    while(1){
        if(s[i]!=cur){
            cur=s[i];
            cnt++;
            i++;
            if(i==s.length()){
                break;
            }
        }
        else{
            if(i==s.length()-1){
                break;
            }
            else if(i==s.length()-2){
                cnt++;
                break;
            }
            else{
                cur=s[i+2];
                i+=3;
                cnt+=2;
                if(i==s.length()){
                    break;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007
int n,m,imsi;
main()
{
    scanf("%d %d",&n,&m);
    imsi=m+n;
    if(n-m>imsi) imsi=n-m;
    if(n*m>imsi) imsi=n*m;
    printf("%d",imsi);
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
 {

	int a,b;



	while(1){

		scanf("%d %d",&a, &b);



		if( a == 0 && b ==0){

			break;

		}
	if(a<b){
		printf("%d %d\n",a,b);
	}
	else{
		printf("%d %d\n",b,a);
	

	}

	}
	return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int s;
  cin >> s;
  map<ll,bool> t;
  ll tmp = s;
  t[s] = true;
  for (int i = 2; ; ++i) {
    if (tmp % 2 == 0) {
      tmp = tmp / 2;
    } else {
      tmp = 3 * tmp + 1;
    }
    if (t[tmp]) {
      cout << i << endl;
      return 0;
    } else {
      t[tmp] = true;
    }
  }
}


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

int main(){
    int T[101][101],r,c;
    
    cin>>r>>c;
    for (int i=0;i<r;i++)
        for (int j=0;j<c;j++) cin>>T[i][j];
        
    for (int i=0;i<=r;i++) T[i][c]=0;
    for (int j=0;j<=c;j++) T[r][j]=0;
    
    for (int i=0;i<r;i++){
        for (int j=0;j<c;j++){
            T[i][c]+=T[i][j];
            T[r][j]+=T[i][j];
            T[r][c]+=T[i][j];
            
        }
    }
    for (int i=0;i<=r;i++){
        for (int j=0;j<=c;j++){
            if (j) cout<<" ";
            cout<<T[i][j];
        }
        cout<<endl;
    }
    
    return 0;
    
    
    
}


Measured memory_bytes: 3112
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(6, [3, 4, 5]), 2)

    def test_2(self):
        self.assertEqual(think(9, [3, 3, 3, 3]), 4)


def solve():
    x, l = read()
    result = think(x, l)
    write(result)


def read():
    n, x = read_int(2)
    return x, read_int(n)


def read_int(n):
    return read_type(int, n)


def read_float(n):
    return read_type(float, n)


def read_type(t, n):
    return list(map(lambda x: t(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(x, l):
    count = 1
    s = 0
    for e in l:
        s += e
        if s > x:
            break
        count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

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

using namespace std;

int main(){
	int n, WW;
	cin>>n>>WW;
	vector<long long> dp(WW + 1);
	vector<int> w(n);
	vector<long long> v(n);
	for(int i = 0; i < n; i++) cin>>w[i]>>v[i];
	for(int i = 0; i <= WW; i++){
		dp[i] = 0;
		if (w[n - 1] <= i) dp[i] = v[n - 1];
	}
	vector<long long> dp_copy(WW + 1);
	
	for(int k = n - 2; k >= 0; k--){
		dp_copy = dp;
		for(int i = 0; i <= WW; i++){
			if (i >= w[k]) dp_copy[i] = max(dp[i], dp[ i - w[k]] + v[k]);
		}
		dp = dp_copy;
	}
	cout<<dp[WW]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c;
	cout<<max({10*a+b+c,10*b+a+c,10*c+a+b});





	cout<<endl;
} 


Measured memory_bytes: 256
n=int(input())
s=input()
dic={}
cntr=0
cntg=0
cntb=0
for i in range(n):
    if s[i]=="R":
        dic[i]="R"
        cntr+=1
    if s[i]=="G":
        dic[i]="G"
        cntg+=1
    if s[i]=="B":
        dic[i]="B"
        cntb+=1

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1 and dic[i]!= dic[j]:
            if dic[i]!=dic[2*j-i] and dic[j]!=dic[2*j-i]:
                cnt+=1
print(cntr*cntg*cntb-cnt)

        

Measured memory_bytes: 68256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}



int main() {
  string s,r,l;
  cin >> s;
  int q;
  cin >> q;
  int ok=1;
  rep(i,q) {
      int a;
      cin >> a;
      if(a==1) {
          if(ok==1) ok=2;
          else ok=1;
          continue;
      }
      int f;
      char c;
      cin >> f >> c;
      if(f==ok) l+=c;
      else r+=c;
  }
  reverse(l.begin(),l.end());
  s=l+s+r;
  if(ok==2) reverse(s.begin(),s.end());
  pt(s);
  return 0;
}


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

int main() {
  string S;
  cin >>S;
  vector<char> N={S.at(0), S.at(1), S.at(2)};
  sort(N.begin(),N.end());
  if(N.at(0)!='a'){
    cout <<"No" <<endl;
    return 0;
  }
  if(N.at(1)!='b'){
    cout <<"No" <<endl;
    return 0;
  }
  if(N.at(2)!='c'){
    cout <<"No" <<endl;
    return 0;
  }
  cout <<"Yes" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a > b)
	{
		a = b;
	}
	if(c > d)
	{
		c = d;
	}
	printf("%d\n",a + c);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int N,H[100005],M=0;
int main() {
    cin >> N;
    for(int i=1; i<=N; i++) {
        cin >> H[i];
        if(H[i] < M) {
            cout << "No" << endl;
            return 0;
        }
        M = max(M, H[i]-1);
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;


int main()
{
    string str1, str2;
    map<char, char> mp, mp2;

    cin >> str1 >> str2;

    // str1 : key
    // str2 : value
    for (int i = 0; i < (int)str1.length(); i++) {
        auto itr = mp.find(str1[i]);
        if (itr != mp.end()) {
            if (itr->second != str2[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        
        auto itr2 = mp2.find(str2[i]);
        if (itr2 != mp2.end()) {
            if (itr2->second != str1[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        

        mp[str1[i]] = str2[i];
        mp2[str2[i]] = str1[i];
    }
    
    cout << "Yes" << endl;

    return 0;   
}

Measured memory_bytes: 776
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    vector<int> v(n);
    int sum=0;
    rep(i,n){
        cin>>v[i];
        sum+=v[i];
    }

   // sort(v.begin(),v.end());
    vector<int> v1(n+1);
    v1[0]=0;

    rep(i,n){
        v1[i+1]=v[i]+v1[i];
       // cout<<v1[i+1]<<endl;
    }
    int ans=MOD;

    for(int i=1;i<v1.size();i++){
        int k=sum-v1[i];
        if(abs(v1[i]-k)<ans){
            ans=abs(v1[i]-k);
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
inf = 10**15
import itertools
n,m,r = map(int,input().split())
city = list(map(int,input().split()))


dist = [[inf for i in range(n)] for i in range(n)]

#まず距離を初期化(入力に従う)
for i in range(m):
    ak,bk,ck = map(int,input().split())
    dist[ak-1][bk-1]  =ck
    dist[bk-1][ak-1]  =ck

for a in range(n):
    for b in range(n):
        for c in range(n):
            dist[b][c] = min(dist[b][c],dist[b][a]+dist[a][c])

#print(dist)

ans = inf
for v in itertools.permutations(city):
    cost = 0
    for i in range(len(v)-1):
        cost += dist[v[i]-1][v[i+1]-1]
    #print(v,cost)
    ans = min(ans,cost)

print(ans)


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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 1000005;
char store[maxn][10];
int main() {
	int n; scanf("%d", &n);
	vector<vector<char>> strings(n);
	forn(i, n) {
		scanf("%s", store[i]);
		for(auto a : store[i])
			strings[i].pb(a);
		sort(all(strings[i]));
	}
	sort(all(strings));	
	ll count = 1; ll total = 0;
	for(int i = 1; i < n; i++) {
		bool ok = (strings[i] == strings[i - 1]);
		if(ok) {
			total += count;
			count++;
		}
		else {
			count = 1;
		}
	}
	printf("%lld", total);
				 
		
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <algorithm>
#include <string> 
#include <math.h>
#include <vector>
#define rep(i,n) for(int i=0; i< int(n); i++)
using namespace std;



int main(){
	int n, x, m[101];
	cin >> n >> x;
	int s = 0, M = 1001001001;
	rep(i,n) {
		cin >> m[i];
		s += m[i];
		if(m[i] < M) M = m[i];
	}
	int ans = n +(x-s)/M;
	cout << ans << endl;

} 



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

# 隣接リスト
l = [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a-=1
    b-=1
    l[a].append(b)
    l[b].append(a)

# 二部グラフ判定
nibu = True
stack = [0]
col = [-1 for i in range(n)]
col[0]=0
while stack:
    p = stack.pop()
    for x in l[p]:
        if col[x]==-1:
            stack.append(x)
            if col[p]==0:
                col[x]=1
            else:
                col[x]=0
        else:
            if col[x]==col[p]:
                nibu = False
                break
    if not nibu:
        break

if nibu:
    print(col.count(1)*col.count(0)-m)
else:
    print(n*(n-1)//2-m)


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

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

int N, M;
int X[100000], Y[100000];

int num[100000], red[100000];

int main(){
  int i, j, k;
  int res;

  reader(&N,&M);
  rep(i,M) reader(X+i,Y+i), X[i]--, Y[i]--;

  rep(i,N) num[i] = 1, red[i] = 0;
  red[0] = 1;

  rep(i,M){
    num[X[i]]--;
    num[Y[i]]++;

    if(red[X[i]]){
      red[Y[i]] = 1;
      if(num[X[i]]==0) red[X[i]] = 0;
    }
  }

  res = 0;
  rep(i,N) res += red[i];
  writerLn(res);

  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN	 100
int N[MAXN+5],n;
int C(int a){
	int sum=0;
	for(int i=1;i<=n;i++)
		sum+=(a-N[i])*(a-N[i]);
	return sum;
}
int main(){
	int m1=0,m2,m3;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&N[i]),m1+=N[i];
	sort(N+1,N+n+1);
	m1/=n,m2=m1+1,m3=m1-1;
	printf("%d",min(C(m1),min(C(m2),C(m3))));
}

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

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

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

  string s, t; cin >> s >> t;
  for(int i = s.size()-t.size(); i >= 0; i--) {
    string ans = s;
    bool flag = true;
    rep(j, t.size()) {
      if(ans[i+j] == '?') ans[i+j] = t[j];
      if(ans[i+j] != t[j]) {
        flag = false;
        break;
      }
    }
    if(flag) {
      rep(k, ans.size()) {
        if(ans[k] == '?') ans[k] = 'a';
      }
      cout << ans << '\n';
      return 0;
    }
  }

  cout << "UNRESTORABLE" << '\n';
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    rep(i,n+1) {
        int x = i*108/100;
        if(x==n) { cout << i << endl; return 0;}
    }
    cout << ":(" << endl;
    return 0;
}

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

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << max({a * 10 + b + c, a + b * 10 + c, a + b + c * 10}) << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main {
    static final int MAX = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[][] w = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                w[i][j] = MAX;
            }
        }
        for (int i = 0; i < n; i++) {
            int u = sc.nextInt();
            int k = sc.nextInt();
            
            for (int j = 0; j < k; j++) {
                int v = sc.nextInt();
                int c = sc.nextInt();
                w[u][v] = c == -1 ? MAX : c;
            }
        }
        
        // cost from start point
        int[] d = new int[n];
        for (int i = 0; i < n; i++) {
            d[i] = MAX;
        }
        // スタートノード自身への最短距離（最小コスト）は 0. 
        // 全く移動しないで済むので，これは明らかに最適 (負のコストを持つエッジが一つでも存在すると，この推論が成り立たない. ダイクストラ法は「全てのエッジのコストが 0 以上であること」が条件.)
        d[0] = 0;
        boolean[] used = new boolean[n];
            
        // 確定ノードをピックアップすることができなくなるまで（＝変化がなくなるまで）以下のループを繰り返す：
        while (true) {
            // まだ確定されていないノードのうち，最小の値を持つノードを見つけ，確定ノードとする（確定フラグを立てる）。
            int minCost = MAX;
            int next = -1;
            for (int i = 0; i < n; i++) {
                if (d[i] < minCost && !used[i]) {
                    next = i;
                    minCost = d[i];
                }
            }
            if (next == -1) break;
            used[next] = true;
            
            // 確定ノードからの伸びているエッジをそれぞれチェックし，「確定ノードまでのコスト＋エッジのコスト」を計算し，そのノードの現在値よりも小さければ更新する
            for (int v = 0; v < n; v++) {
                if (!used[v] && w[next][v] != MAX) {
                    d[v] = Math.min(d[v], d[next] + w[next][v]);
                }
            }
            
        }
        for (int i = 0; i < n; i++) {
            System.out.println(i + " " + d[i]);
        }
    }
}



Measured memory_bytes: 40028
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);

	static void solve() {
		int L = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		out.println(L - max(A / C + min(1, A % C), B / D + min(1, B % D)));
		out.flush();
	}

	public static void main(String[] args) {
		solve();
	}

	static int max(int a, int b) {
		return a < b ? b : a;
	}

	static int min(int a, int b) {
		return a < b ? a : b;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 24148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=505;
int a[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int sum=0;
  int n,k;
  cin>>n>>k;
  rep(i,1,n+1)
    {
      cin>>a[i];
      sum+=a[i];
    }
  int sq=sqrt(sum);
  vi divs;
  rep(i,1,sq+1)
    {
      if(sum%i==0)
	{
	  divs.pb(i);
	  if(i*i!=sum) divs.pb(sum/i);
	}
    }
  sort(all(divs));
  int ans=-1;
  for(int x:divs)
    {
      vi b;
      ll tot=0;
      rep(i,1,n+1)
	b.pb(a[i]%x),tot+=(a[i]%x);
      sort(all(b));
      ll st=0;
      bool ok=false;
      rep(i,0,n)
	{
	  tot-=b[i]; st+=b[i];
	  ll curr=max((ll)(n-i-1)*x-tot,st);
	  if(curr<=k) ok=true;
	}
      if(ok) ans=x;
    }
  cout<<ans<<endl;
  return 0 ;
}


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

int main() {
	int a[2], b[2];
	cin >> a[0] >> a[1] >> b[0] >> b[1];
	sort(a, a + 2);
	sort(b, b + 2);
	cout << a[0] + b[0] << endl;
}

Measured memory_bytes: 256
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    def stoidx(s):
        if s == 'AB':
            return (0, 1)
        elif s == 'BC':
            return (1, 2)
        else:
            return (0, 2)


    def answer(ans):
        print('Yes')
        for a in ans:
            print(a)

    def add_answer(x):
        if s[x[0]] > s[x[1]]:
            s[x[0]] -= 1
            s[x[1]] += 1
            ans.append(abc[x[1]])
        else:
            s[x[0]] += 1
            s[x[1]] -= 1
            ans.append(abc[x[0]])
        
    n, *s = map(int, input().split())
    sl = []
    for _ in range(n):
        sl.append(stoidx(input()))
    abc = 'ABC'
    ans = []
    if sum(s) == 0:
        print('No')
        return

    elif sum(s) == 1:
        for x in sl:
            if s[x[0]] == 0 and s[x[1]] == 0:
                print('No')
                return
            add_answer(x)

    else:
        for i, x in enumerate(sl):
            if s[x[0]] == 0 and s[x[1]] == 0:
                print('No')
                return
                
            if i < n-1 and s[x[0]] == 1 and s[x[1]] == 1:
                nx = sl[i+1]
                if x != nx and sum(s)==2:
                    if x[0] in nx:
                        s[x[0]] += 1
                        s[x[1]] -= 1
                        ans.append(abc[x[0]])
                    else:
                        s[x[0]] -= 1
                        s[x[1]] += 1
                        ans.append(abc[x[1]])
                    continue
            add_answer(x)
    answer(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10640
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
//#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
#define int long long

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
/*
#pragma comment(linker, "/STACK: 20000000005")
*/


using namespace std;

const int N = 1000005, MOD = 1e9 + 7;
int M = 1e8;

string S;
int n;
int a[N];
int sum;
int ok;

main()
{
    ios_base::sync_with_stdio(0);
    cin >> n;
    cin >> S;
    n--;
    for (int i = 0; i <= n; i++){
        a[i] = S[i] - '1';
        if ((i & n) == i)
            sum += a[i];
        if (a[i] == 1)
            ok = 1;
    }
    if (ok == 0){
        sum /= 2;
        sum %= 2;
        sum *= 2;
        cout << sum << endl;
        return 0;
    }
    if (sum % 2 == 1){
        cout << 1 << endl;
        return 0;
    }
    cout << 0 << endl;
    return 0;
}


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

const ll mod = 1000000007;

ll c(int n, vector<ll> a) {
  vector<ll> sum(n);
  sum[0] = a[0];
  sum[0] %= mod;
  for(int i=1;i<n;i++) {
    sum[i] = sum[i-1] + a[i];
    // sum[i] %= mod;
  }
  ll ans = 0;
  for(int i=0;i<n-1;i++) {
    ans += ((a[i] * ((sum[n-1] - sum[i]) % mod)) % mod);
    ans %= mod;
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  cout << c(n, a);
}

Measured memory_bytes: 7920
#include<bits/stdc++.h>
using namespace std;
#define TRACE
#define M 1000000007
#define oo 1000000000000000007
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define pb push_back
#define M6 5000009
#define M5 500009
#define pi 3.14159265
#define epsilon 1e-6

ll n,m,A[M5];
ll prime[M6];
void sieve(){
    for(int i=2;i<M6;i++) prime[i]=1;
    for(int i=2;i*i<M6;i++){
        if(prime[i]==0) continue;
        for(int j=i*2;j<M6;j+=i) prime[j]=0;
    }
}

ll power(ll x,ll n,ll m){
    ll res=1;
    while(n>0){
        if(n&1) res=(res*x)%m;
        n/=2;
        x=(x*x)%m;
    }
    return res;
}
ll fac[M5];
ll nCr(ll n, ll r) {
    return (((fac[n]*power(fac[r],M-2,M))%M)*power(fac[n-r],M-2,M))%M;
}
int  main()
{
    ios_base::sync_with_stdio (0), cin.tie (0);
    //sieve();

    ll tc=1,t=0,i,j,k,a,b,c;
    //cin>>tc;
    while(t++<tc){
        string s;
        cin>>s>>n;
        ll ans=0,c=1;
        std::vector<ll> v;
        for(i=1;i<s.size();i++) {
            if(s[i]==s[i-1] ) c++;
            else {
                v.pb(c);
                a+=c/2;
                c=1;
            }
        }
        v.pb(c);
        a+=c/2;
        //for(auto u:v) cout<<u<<" "; cout<<"\n";
        if(s[0]==s[s.size()-1]) {
            if(v.size()==1) ans=(n*s.size())/2;
            else {
                for(i=1;i<v.size()-1;i++) ans+=v[i]/2;
                ans=ans*n; //cout<<ans<<" ";
                ans+=v[0]/2;  //cout<<ans<<" ";

                ans+=((v[0]+v[v.size()-1])/2)*(n-1); //cout<<ans<<" ";
                ans+=v[v.size()-1]/2;
            }
        }
        else ans=a*n;
        cout<<ans;
    }
    return 0;
}

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

class Program {
  enum Kind {
    S, H, C, D
  }

  static void Main(string[] args) {

    var sc = new Scanner();
    int N = sc.NextInt();
    bool[,] have = new bool[4, 13];
    for(int i = 0; i < N; i++) {
      Kind k;
      string s = sc.Next();
      if(s == "S") k = Kind.S;
      else if(s == "H") k = Kind.H;
      else if(s == "C") k = Kind.C;
      else k = Kind.D;
      int j = sc.NextInt();
      j--;
      have[(int)k, j] = true;
    }

    for(int i = 0; i < 13; i++) {
      if(have[0, i] == false) Console.WriteLine("S " + (i + 1));
    }
    for(int i = 0; i < 13; i++) {
      if(have[1, i] == false) Console.WriteLine("H " + (i + 1));
    }
    for(int i = 0; i < 13; i++) {
      if(have[2, i] == false) Console.WriteLine("C " + (i + 1));
    }
    for(int i = 0; i < 13; i++) {
      if(have[3, i] == false) Console.WriteLine("D " + (i + 1));
    }
  }

  class Scanner {
    string[] inp;
    int ptr;

    public Scanner() {
      inp = new string[0];
      ptr = 0;
    }

    private void Fetch() {
      if (ptr >= inp.Length) {
        inp = Console.ReadLine().Split(' ');
        ptr = 0;
      }
    }

    public int NextInt() {
      Fetch();
      return int.Parse(inp[ptr++]);
    }

    public string Next() {
      Fetch();
      return inp[ptr++];
    }

    public double NextDouble() {
      Fetch();
      return double.Parse(inp[ptr++]);
    }
  }

}

Measured memory_bytes: 5628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            int iK = sS.Length;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            switch (iK)
            {
                case 1:
                    iOut = iN;
                    break;
                case 2:
                    iOut = 9;
                    break;
                case 3:
                    iOut = iN - 100 + 1 + 9;
                    break;
                case 4:
                    iOut = 909;
                    break;
                case 5:
                    iOut = iN - 10000 + 1 + 909;
                    break;
                case 6:
                    iOut = 90909;
                    break;
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;

int main(){
	long long N,P;
	cin>>N>>P;
	if(N==1){
		cout<<P<<endl;
		return 0;
	}
	if(N>=40){
		cout<<1<<endl;
		return 0;
	}
	long long ans = 1;
	for(long long i=2;i<P;i++){
		long long k = 1;
		for(int j=0;j<N;j++){
			k*=i;
			if(k>P)break;
		}
		if(k>P)break;
		while(true){
			if(P%k==0){
				ans*=i;
				P/=k;
			}
			else{
				break;
			}
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
n,t=map(int,input().split())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
c=[]
flag=False
for i in range(n):
    if l[i][1]<=t:
        flag=True
        c.append(l[i][0])
    else:
        pass
if flag:
    print(min(c))
else:
    print("TLE")


Measured memory_bytes: 3060
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

char s[maxn];

inline bool jud(int l,int r)
{
	for(int i=l,j=r;i<=j;i++,j--) if(s[i]!=s[j]) return false;
	return true;
}

int main()
{
	scanf("%s",s+1); int len=strlen(s+1);
	if(jud(1,len)&&jud(1,(len-1)/2)&&jud((len+3)/2,len)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
long long dsc(const void *a, const void *b) {
  return *(long long *)b - *(long long *)a;
}
int main(){
    long long i,n,k,ans=0,h[200020]={};
    scanf("%lld %lld",&n,&k);
    for(i=0; i<n; i++){
        scanf("%lld",&h[i]);
        ans+=h[i];
    }
    qsort(h,n,sizeof(long long),dsc);
    for(i=0; i<k; i++){
        ans-=h[i];
    }
    printf("%lld",ans);
    return 0;
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  string S;
  cin >> S;
  int cnt = 0;
  int maxx = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] != 'A' &&S[i] != 'C' &&S[i] != 'G'&&S[i] != 'T' ){
      if(cnt > maxx){
        maxx = cnt;
      }
      cnt = 0;
    } else{
      cnt++;
    }
  }
  cout << max(maxx, cnt) <<endl;
}


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

namespace ITP1_4_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] data = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            double quotient = (double)data[0] / data[1];
            int surplus = data[0] % data[1];
            Console.WriteLine((int)quotient + " " + surplus + " " + quotient.ToString("f5"));
        }
    }
}

Measured memory_bytes: 9712
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 998244353
typedef long long ll;

using namespace std;

#define Nmax 300010
class Cmod{
private:
    ll fact[Nmax],inv[Nmax],invfact[Nmax];
public:
    void Init(){
	inv[1]=fact[0]=invfact[0]=1;
	for(int i=1;i<Nmax;i++){
	    fact[i]=fact[i-1]*i%mod;
	    if(i>1)inv[i]=mod-mod/i*inv[mod%i]%mod;
	    invfact[i]=invfact[i-1]*inv[i]%mod;
	}
    }
    ll C(int n,int k){
	return fact[n]*invfact[k]%mod*invfact[n-k]%mod;
    }
};

int main(){
    class Cmod cmod;cmod.Init();
    
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    ll ans=0;
    for(ll i=0;i<=n;i++){
	ll j=k-(a*i);
	if(j%b>0||j<0)continue;
	j/=b;
	if(j<0||n<j)continue;
	ans+=cmod.C(n,i)*cmod.C(n,j);
	//cout<<"#"<<i<<" "<<j<<endl;
	ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7296