akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n,m,ans;
    cin >> n >> m;
    ans=1900*m+100*(n-m);
    for (ll i=0;i<m;i++)ans*=2;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

template <class T> using Tree = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool a) {
    return a ? "T" : "F";
}

string to_string(const char* s) {
    return to_string((string) s);
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define X first
#define Y second

using ll = long long;
using ld = long double;

int k;
string s;
set <string> st;

void add(string x) {
    for (int i = 1; i <= k; ++i) {
        st.insert(x.substr(0, i));
    }
}

void run() {
    cin >> s;
    cin >> k;
    int n = s.length();
    for (int i = 0; i < n; ++i) {
        add(s.substr(i));
    }
    
    for (int i = 0; i < k - 1; ++i) {
        st.erase(st.begin());
    }
    cout << *st.begin() << endl;

}

int main() {
    run();
    return 0;
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	string a,b,c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>x[20],y[20];
int n;
int js(int x){
	int ans=0;
	while(x){
		ans+=(x&1);
		x>>=1;
	}
	return ans;
}
bool check(int X){
	int temp[20]={0};
	for(int i=1;i<=n;i++){
		if((X>>(i-1))&1)temp[i]=1;
		else temp[i]=0;
	}
	for(int i=1;i<=n;i++){
		if(temp[i]){
			int siz=x[i].size();
			for(int j=0;j<siz;j++){
				int id=x[i][j];
				if((temp[id]^y[i][j])==1)return 0;
			}
		}
	}
	return 1;
}
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int m;
		scanf("%d",&m);
		while(m--){
			int a,b;
			scanf("%d%d",&a,&b);
			x[i].push_back(a);y[i].push_back(b);
		}
	}
	int mx=(1<<n);
	int ans=0;
	for(int i=0;i<mx;i++){
		if(check(i)){
			ans=max(ans,js(i));
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ld long double

using namespace std;

const int MIN = 1e3 + 2;
const int MXN = 1e5 + 3;
const int INF = 1e9 + 7;
const ll LINF = 1e18 + 15;
const double EPS = 1e-9;

int ans = 0;
int id;
int sum;
int n;

int main(){
	cin >> n;
	for (int i = 1;; i++){
		if (ans + i == n){
			ans += i;
			id = i;
			break;
		}
		if (ans + i > n){
			id = i;
			break;
		}
		ans += i;
	}
	if (ans == n){
		for (int i = 1; i <= id; i++){
			cout << i << " ";
		}
		return 0;
	}
	for (int i = 1; i <= id; i++){	
		if (n - ans == id - i)
			continue;
		cout << i << " ";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
int a[114514];
int b[114514];
#define mod 1e9+7
signed main(){
	int n,m;
	cin>>n>>m;
	rep(0,i,m){
		cin>>a[i];
	}	
	b[0]=1;
	b[1]=1;
	rep(2,i,111111){
		b[i]=b[i-1]+b[i-2];
		b[i]=b[i]%1000000007;
	}
	if(m==0){
		c(b[n])
		return 0;
	}		
	int sum=b[a[0]-1];
	rep(1,i,m){
		sum=sum*b[a[i]-a[i-1]-2];
		sum=sum%1000000007;
		if(a[i]-a[i-1]==1){
			cout<<0<<endl;
			return 0;
		}	
	}
	sum=sum*(b[n-1-a[m-1]]);
	sum=sum%1000000007;
	c(sum)
}	

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)

int arr[100000+50000],n;

int dp[150000];

int ans(int ind)
{
    if(ind==n)return 0;
    if(ind>n)return MOD*MOD;

    if(dp[ind]>-1)return dp[ind];

    dp[ind]=min(abs(arr[ind]-arr[ind+1])+ans(ind+1),abs(arr[ind]-arr[ind+2])+ans(ind+2));
    return dp[ind];
}

signed main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    st(dp,-1);
    forn(i,1,n)cin>>arr[i];

    cout<<ans(1);

    

     
     




     return 0;

}

//       g++ -g c2.cpp ; ./a.exe

Measured memory_bytes: 3840
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
        long ans = 0;
        if(a >= b || k < a) ans = k + 1;
        else{
            long x = k + 1;
            ans = a;
            k -= a-1;
            while(k > 1){
                ans += b - a;
                k -= 2;
            }
            if(k == 1) ans++;
            ans = Math.max(ans, x);
        }
        System.out.println(ans);
    }
}
 

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;



int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll N, s, t; scanf("%lld %lld %lld", &N, &s, &t);
	vector<ll> ds(N + 5), dt(N + 5);
	for (ll i = 1; i <= N; i++) {
		if (i == s) continue;
		cout << "? " << s << " " << i << endl;
		ll x; scanf("%lld", &x);
		ds[i] = x;
	}
	for (ll i = 1; i <= N; i++) {
		if (i == t) continue;
		cout << "? " << t << " " << i << endl;
		ll x; scanf("%lld", &x);
		dt[i] = x;
	}
	vector<pair<ll, ll>> v;
	for (ll i = 1; i <= N; i++) {
		if (i == s || i == t) continue;
		if (ds[i] + dt[i] == ds[t]) {
			v.emplace_back(ds[i], i);
		}
	}
	sort(v.begin(), v.end());
	vector<ll> res;
	if(v.size() > 0 ) res.push_back(v[0].second);
	for (ll i = 1; i < v.size(); i++) {
		cout << "? " << res.back() << " " << v[i].second << endl;
		ll x; scanf("%lld", &x);
		if (ds[res.back()] + x == ds[v[i].second]) {
			res.push_back(v[i].second);
		}
	}
	cout << "! " << s;
	for (ll i = 0; i < res.size(); i++) {
		cout << " " << res[i];
	}
	cout << " " << t << endl;
	return 0;
}


Measured memory_bytes: 4672
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repk(i,k,n) for (ll i = k; i <= (int)(n); i++)
#define MAX 10000
typedef long long ll;

using namespace std;


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

    if(N==1){
        cout << 0 << endl;
    }
    else if(N==2){
        cout << 1 << endl;
    }
    else{
        cout << N*(N-1)/2 << endl;
    }
    

    return 0;
}

Measured memory_bytes: 504
from itertools import permutations
from math import factorial
N = int(input())
X, Y = zip(*tuple(map(int, input().split()) for _ in range(N)))


def dist(x, xx, y, yy):
    return ((x - xx) ** 2 + (y - yy) ** 2) ** 0.5


d = 0
for p in permutations(range(N)):
    tmp = 0
    for s, t in zip(p, p[1:]):
        x = X[s]
        y = Y[s]
        xx = X[t]
        yy = Y[t]
        tmp += dist(x, xx, y, yy)
    d += tmp

print(d/factorial(N))

Measured memory_bytes: 3064
import heapq
N, M = map(int, input().split())
A = sorted(list(map(lambda x:-int(x), input().split())))
heapq.heapify(A)
for _ in range(M):
    a = -heapq.heappop(A)
    heapq.heappush(A, -(a//2))
print(-sum(A))


Measured memory_bytes: 65816
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
char S[12];
char out[2<<20];
int outsz,Slen;
main()
{
	int N,K;
	scanf("%d%d ",&N,&K);
	gets(S);
	Slen=strlen(S);
	S[Slen++]='\n';
	for(int i=0;i<K;i++)
	{
		memcpy(out+i*Slen,S,Slen);
	}
	outsz=K*Slen;
	N-=K;
	for(int i=0;i<N;i++)
	{
		out[outsz+i*2]='7';
		out[outsz+i*2+1]='\n';
	}
	write(1,out,outsz+N*2);
}

Measured memory_bytes: 2304
#include <stdio.h>

#define MAX 100

int main() {
  int n, i, j, flag, tmp, cnt = 0;
  int array[MAX];

  scanf("%d\n", &n);
  i = 0;
  while ((scanf("%d", &array[i])) != EOF) {
    i++;
  }

  flag = 1;
  i = 0;
  while (flag) {
    flag = 0;
    for (j = n-1; j >= i+1; j--) {
      if (array[j] < array[j-1]) {
        tmp = array[j];
        array[j] = array[j-1];
        array[j-1] = tmp;
        flag = 1;
        cnt++;
      }
    }
    i++;
  }

  for (i = 0; i < n; i++) {
    if (i == n-1) {
      printf("%d\n", array[i]);
      break;
    }
    printf("%d ", array[i]);
  }
  printf("%d\n", cnt);

  return 0;
}

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

struct UnionFind{
    vector<int> par;
    
    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }
    
    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }
    
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    
    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    
    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    ll N,M;
    cin>>N>>M;
    vector<int> A(M),B(M);
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
        A[i]--;
        B[i]--;
    }
    
    UnionFind uf(N);
    ll cur=N*(N-1)/2;
    vector<ll> res;
    for(int i=0;i<M;i++){
        res.push_back(cur);
        int a=A[M-1-i],b=B[M-1-i];
        if(uf.issame(a,b)) continue;
        
        ll sa=uf.size(a), sb=uf.size(b);
        cur-=sa*sb;
        uf.merge(a,b);
    }
    reverse(res.begin(),res.end());
    for(int i=0;i<res.size();i++) cout<<res[i]<<endl;
}

Measured memory_bytes: 3444
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//何枚持っているか
		int N =sc.nextInt();
		//各餅の直径
		int d[] = new int[N];
		for(int i = 0;i < N;i++) {
			d[i] = sc.nextInt();
		}
		//大きい順に並び替え
		int max;
		for(int i = 0;i < N;i++) {
			for(int j = i;j < N;j++) {
				if(d[i] < d[j]) {
					max = d[i];
					d[i] = d[j];
					d[j] = max;
				}
			}
		}
		//何段重ねにできるか(一段は確実にできる)
		int count = 1;
		//大きさの比較
		int mochi = d[0];
		for(int i = 1;i < N;i++) {
			if(mochi > d[i]) {
				mochi = d[i];
				count++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <cstdlib>
#define ll long long
#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define MX 100010
using namespace std;

string S;

int main(){

        int ans=0;
        int max=0;
        bool start=false;
        cin >> S;
        FOR(i,0,S.length()){
                if(S[i] == 'A' || S[i] == 'G' || S[i] == 'T' || S[i] == 'C'){
                        ans++;
                        start=true;
                }else{
                        if(start){
                                if(max < ans){
                                        max = ans;
                                }
                                ans=0;
                                start=false;
                        }
                }
        }
        if(start){
                if(max < ans){
                        max = ans;
                }
        }
        cout << max << endl;
       
        return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  int c;
  cin >> n >> m >> c;
  for (int i = 0; i < m; ++i) cin >> a[i];
  int ans = 0;
  while (n--) {
    int s = 0;
    for (int i = 0; i < m; ++i) {
      int x;
      cin >> x;
      s += x * a[i];
    }
    if (s + c > 0) ++ans;
  }
  cout << ans;
  return 0;
}



Measured memory_bytes: 3660
#include <stdio.h>
int main(void) {
    int num,ta,tb,sca,scb,i;
    while (1) {
        scanf("%d\n",&num);
        if (num==0) break;
        sca=0,scb=0;
        for (i=0; i<num; i++) {
            scanf("%d %d\n",&ta,&tb);
            if (ta>tb) {
                sca+=ta+tb;
            } else if (ta<tb) {
                scb+=ta+tb;
            } else {
                sca+=ta;
                scb+=tb;
            }
        }
        printf("%d %d\n",sca,scb);
    }
    return 0;
}

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

int search(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while( A[i] != key ) i++;
    return i != n;
}

int main(){
    int i, n, A[10000 + 1], q, key, sum = 0;
    
    cin >> n;
    for( i = 0; i < n; i++) cin >> A[i];
    
    cin >> q;
    for(i = 0; i < q; i++){
        cin >> key;
        if( search(A, n, key)) sum++;
    }
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3124
A, B, C, D = [i for i in input()]
fml = ""
ans = ""
for i in range(2**3):
    fml = A + "-" + B + "-" + C + "-" + D
    for j in range(3):
        if i >> j & 1:
            fml = fml[:2*j+1] + "+" + fml[2*j+2:]
    if eval(fml) == 7:
        ans = fml + "=7"
        break
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int  N;
  cin >> N;
  
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin >> X.at(i);
  }
  
  sort(X.begin(),X.end());
  
  int size=X.at(N-1)+1; //Xの最大値+1
  
    
  vector<int> Ans(size);
  
  for(int p=1; p<size; p++){
    
    int S=0; //座標pにおける合計
    
    for(int i=0; i<N; i++){
      S+=pow(X.at(i)-p,2);
    }

    Ans.at(p) = S;
    
  }
  
  sort(Ans.begin(),Ans.end());
  
  cout << Ans.at(1) << endl;
  
}



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

int main() {
    string X; cin >> X;
    int cntS = 0;
    int over = 0;
    for (char x : X) {
        if (x == 'S') {
            cntS++;
        } else {
            if (cntS) {
                cntS--;
            } else {
                over++;
            }
        }
    }
    cout << over + cntS << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
 	int i,j,k;
 	int len;
 	int key;
 	
 	scanf("%d",&len);
 	int A[len];
 	
 	for(i=0;i<len;i++)
 		scanf("%d",&A[i]);
 		
 	for(i=0;i<len;i++){
 	    printf("%d",A[i]);
 	    if(i!=len-1) printf(" ");
 	}
 	printf("\n");

 	for(i=1;i<len;i++){
 		key = A[i];
 		j = i-1;
 		while (j>=0 && A[j]>key){
 			A[j+1] = A[j];
 			j--;
		}
		A[j+1] = key; 
		
		for(k=0;k<len;k++){
			printf("%d",A[k]);
			if(k!=len-1) printf(" ");
		}
		//if(i!=len)	
		printf("\n");
	}
	
	return 0;
}
 	
 
 


Measured memory_bytes: 2104
a,b,k = map(int,input().split())
flag = True
for _ in range(k):
    if flag:
        if a%2==1:
            a-=1
        a = a//2
        b += a
        flag=False
    else:
        if b%2==1:
            b-=1
        b = b//2
        a += b
        flag=True
print(a,b)


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

class Combination{
	private:
		const static long long MOD = 1e9+7;
		const static long long MAX = 510000;
		vector<long long> fact;
		vector<long long> finv;
		vector<long long> inv;
	public:
		Combination() : fact(MAX),finv(MAX),inv(MAX){ //n,k <=10^7くらいまで
			fact[0] = fact[1] = 1;
			finv[0] = finv[1] = 1;
			inv[1] = 1;
			for(int i=2;i<MAX;i++){
				fact[i] = fact[i-1] * i % MOD;
				inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
				finv[i] = finv[i-1] * inv[i] % MOD;
			}
		}

		long long nCk(long long n,long long k){
			if(n<k) return 0;
			if(n<0 || k<0) return 0;
			return fact[n] * (finv[k] * finv[n-k] % MOD) % MOD;
		}

		vector<long long> com; //n固定で n<=10^9, k <= 10^7
		void nCbigk(long long n){
			com.push_back(1);
            com.push_back(n);
            for(long long i=2;i<200010;i++){
                com.push_back((com[i-1] * (n-(i-1)) % MOD) * inv[i] % MOD);
            }
		}

};


#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n,m; cin >> n >> m;
    Combination C;
    ll ans=0;
    if(n>1) ans+= C.nCk(n,2);
    if(m>1) ans+= C.nCk(m,2);
    cout << ans << endl;


}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int MN = 520;
const int MA = MN/2;
const int MP = 10000;
vl pr;
vl md;
bitset<MP> bs;
ll mat[MN][MN];
void pre() {
	for(int i=2;i<MP;i++) {
		if(!bs[i]) {
			if(i >= MN) {
				pr.push_back(i);
			}
			for(int j=2;j*i<MP;j++) {
				bs.set(i*j);
			}
		}
	}
	for(int i=0;i<MN;i++) {
		md.push_back(i+1);
	}
	for(int i=0;i<500;i++) {
		for(int j=0;j<500;j++) {
			ll da = j-i;
			ll db = j+i;
			da += MN;
			ll go;
			if((db&1)) {
				go = pr[da/2]*pr[(da+1)/2]*md[db/2]*md[(db+1)/2]*2+1;
			} else {
				go = pr[da/2]*md[db/2]*2;
			}
			mat[i][j] = go;
		}
	}
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	pre();
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			if(j > 0) {cout << " ";}
			cout << mat[i][j];
		}
		cout << '\n';
	}
}


Measured memory_bytes: 5712
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main(){
 ll h,w;
 ll mod = 1e9 + 7;
 cin >> h >> w;
 vector <string> v(h);
 for(ll i = 0;i < h;i++) cin >> v[i];
 vector <vector <ll>> noOfways(h + 1,vector <ll>(w + 1,0));
 noOfways[0][1] = 1;
 for(ll i = 1;i <= h;i++){
     for(ll j = 1;j <= w;j++){
         if(v[i-1][j-1] == '.'){
             noOfways[i][j] = noOfways[i - 1][j] + noOfways[i][j - 1];
             noOfways[i][j] %= mod;
         }
     }
 }
 cout << noOfways[h][w];
 return 0;
}

Measured memory_bytes: 9216
words = "1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51"
word_list = words.split(",")
k = input()
k = int(k)
print(word_list[k-1])

Measured memory_bytes: 2940
//TLE

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const long N=100000;

int main(){
	long n, w, h;
	long tate[N+1], yoko[N+1];
	
	memset(tate, 0, sizeof(tate));
	memset(yoko, 0, sizeof(yoko));
	
	scanf(" %ld %ld %ld", &n, &w, &h);
	
	for(long i=0; i<n; ++i){
		long x, y, z;
		scanf(" %ld %ld %ld", &x, &y, &z);
		
		//tate direct
		long ta=x-z+1, tb=x+z;
		if(ta<1) ta=1;
		if(tb>w) tb=w;
		tate[ta]++;
		tate[tb+1]--;
		
		//yoko direct
		long ya=y-z+1, yb=y+z;
		if(ya<1) ya=1;
		if(yb>h) yb=h;
		yoko[ya]++;
		yoko[yb+1]--;
	}
	
	for(long i=0; i<=w; ++i) tate[i+1]+=tate[i];
	for(long i=0; i<=h; ++i) yoko[i+1]+=yoko[i];
	
	/*
	for(long i=0; i<=w; ++i) printf("tate[%ld]=%d\n", i, tate[i]);
	for(long i=0; i<=h; ++i) printf("yoko[%ld]=%d\n", i, yoko[i]);
	*/
	
	bool ans=true;
	for(long i=1; i<=w; ++i){
		if(tate[i]<=0){
			ans=false;
			break;	
		}	
	}
	
	if(!ans){
		ans=true;
		for(long i=1; i<=h; ++i){
			if(yoko[i]<=0){
				ans=false;
				break;	
			}	
		}
	}
	if(ans) printf("Yes\n");
	else printf("No\n");
	
}

Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;

int main(){
    int k, a, b;
    cin >> k >> a >> b;
    string ans = "NG";
    for(int i=a; i<=b; i++){
        if(i%k==0) ans = "OK";
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
const int N=250005;
const int base=20020415;
int n;char str[N];long long ans;
map<pair<int,int>,int>Map;
struct hash{
	int mod,pw[N],ipw[N],pos[N],val[N];
	int fastpow(int x,int y){
		int res=1;
		while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}
		return res;
	}
	int cal(int x){
		return x>0?pw[x]:ipw[-x];
	}
	void init(){
		pw[0]=ipw[0]=1;pw[1]=base;ipw[1]=fastpow(base,mod-2);
		for(int i=2;i<=n;++i){
			pw[i]=1ll*pw[i-1]*pw[1]%mod;
			ipw[i]=1ll*ipw[i-1]*ipw[1]%mod;
		}
		for(int i=1;i<=n;++i){
			if(str[i]=='+'){
				pos[i]=pos[i-1];
				val[i]=(val[i-1]+cal(pos[i]))%mod;
			}
			if(str[i]=='-'){
				pos[i]=pos[i-1];
				val[i]=(val[i-1]+mod-cal(pos[i]))%mod;
			}
			if(str[i]=='>'){
				pos[i]=pos[i-1]+1;
				val[i]=val[i-1];
			}
			if(str[i]=='<'){
				pos[i]=pos[i-1]-1;
				val[i]=val[i-1];
			}
		}
	}
	int get(int i){
		return (1ll*val[n]*cal(pos[i-1])+val[i-1])%mod;
	}
}S1,S2;
int main(){
	scanf("%d%s",&n,str+1);
	S1.mod=998244353;S1.init();
	S2.mod=998244853;S2.init();
	for(int i=1;i<=n;++i)++Map[{S1.val[i],S2.val[i]}];
	for(int i=1;i<=n;++i){
		int x=S1.get(i),y=S2.get(i);
		ans+=Map[{x,y}];--Map[{S1.val[i],S2.val[i]}];
	}
	printf("%lld\n",ans);
	return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int, int> p;

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

  if(n >= m){
    cout << 0 << endl;
    return 0;
  }

  sort(all(v));
  vector<int> tmp(m, 0);
  ll res = 0;

  for (int i = 1; i < m; i++) {
    tmp[i] = v[i] - v[i-1];
    res += tmp[i];
  }
  sort(rall(tmp));
  for (int i = 0; i < n-1; i++) {
    res -= tmp[i];
  }

  cout << res << endl;


}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		long m = saori.saori_hayami();
		Map<Integer,Long> num = new TreeMap<>();
		for(int i = 0;i < n;i++){
			int a = saori.saori_hayami();
			long b = saori.saori_hayami();
			if(num.containsKey(a)){
				long value = num.get(a);
				value += b;
				num.put(a, value);
			} else {
				num.put(a, b);
			}
		}
		long ans = 0;
		for(Integer key : num.keySet()){
			long value = num.get(key);
			if(m <= 0)break;
			if(value < m){
				m -= value;
				ans += (value*key);
			} else {
				ans += (m*key);
				m = 0;
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 29508
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		int n = b - a;

		int sum = 0;
		for (int i = 1; i <= n; i++) {
			sum += i;
		}

		System.out.println(sum - b);

		sc.close();
	}
}


Measured memory_bytes: 22612
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>

using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

ll n, k;
ll A[1000010];
ll F[1000010];

bool check(ll c){
  ll t = 0;
  rep(i,n)
    t += max(0LL, A[i] - c / F[i]);
  return t <= k;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> n >> k;
    rep(i,n) cin >> A[i];
    rep(i,n) cin >> F[i];
    sort(A, A+n);
    sort(F, F+n, greater<int>());

    ll l = -1, r = (ll)1e13;
    while(r - l > 1){
      ll m = (l + r) / 2;
      if(check(m)) r = m;
      else l = m;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 5888
#include<stdio.h>

int  main()
{
    long long int temp,num,res=0;
    scanf("%lld",&num);
    temp=num;
    while(num>9)
    {
        res+=num%10;
        num=num/10;
    }
    res+=num;
    if(temp%res==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		  Scanner sc = new Scanner(System.in);
	         
          String s = sc.next(); 
          
          if(s.equals("ABC")) {
        	  System.out.println("ARC");
          }else if(s.equals("ARC")) {
        	  System.out.println("ABC");
          }
	}

}

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

int main() {
  int A,B,answer,a,b,c;
  cin >> A >> B;

  a=0;
  b=0;
  c=0;
  
  a = A+B;
  b = A-B;
  c = A*B;
  
  answer = max(a,b);
  answer = max(answer,c);
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define SIZE 100333
#define MOD 100999
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;

ll n;

int main () {
	scanf("%lld",&n);	
	vector<ll> v(3*n);
	for(int i=0;i<3*n;i++)	scanf("%lld",&v[i]);
	sort(v.begin(), v.end());	

	ll sum = 0, idx = 3LL * n - 2LL, cnt = 0;
	while(1) {
		// printf("idx %lld\n",idx);
		sum += v[idx];
		cnt++;
		if(cnt == n)	break;
		idx-=2;
	}
	printf("%lld\n",sum);

}

Measured memory_bytes: 2560
n = int(input())
E = [[] for i in range(n)]
for i in range(n-1):
    ai,bi,ci = map(int, input().split( ))
    ai-=1;bi-=1
    E[ai].append((bi,ci))
    E[bi].append((ai,ci))

from collections import deque
Q = deque()

q,k = map(int, input().split( ))
k-=1
Q.append(k)
d = [-1]*n 
d[k] = 0
while Q:
    v = Q.popleft()
    for u,c in E[v]:
        if d[u]<0:
            d[u] = d[v]+c
            Q.append(u)

for _ in range(q):
    x,y = map(int, input().split( ))
    x-=1;y-=1
    print(d[x]+d[y])

Measured memory_bytes: 45716
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N;
    string S;
    cin >> N >> S;
    int cnt = 0;
    for (int i = 0; i < N - 2; i++) {
      if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
        cnt ++;
      }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int INF = 1e9 + 7;

int q1, b, q2;
double c1, c2;

int check(int x){
  if(x < 0 || x > q2) return -1;
  double p = (x / 100) * c1;
  if(p > b) return -1;
  int y = (b - p) / c2;
  y *= 100;
  if(x + y < q1) return -1;
  return y;
}
 
int main() {
  while(cin >>q1 && q1){
    cin >>b >>c1 >>c2 >>q2;
    q1 *= 100; q2 *= 100;
    int x = -1, y = -1, tmp;
    for(int i = 10000000; i >= 100; i -= 100) if((tmp = check(i)) != -1) { x = i; y = tmp; break; }
    if(x == -1) cout <<"NA" <<endl;
    else cout <<x / 100 <<" " <<y / 100 <<endl;
  }
  return 0;
}

Measured memory_bytes: 1228
//It’s never too late to become what you might have been....
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 100001

ll dp[2][51][2501],sum[51],a[51];
int main()
{
	boost1;boost2;
	ll i,j,n,A,ans=0,k;	
	cin>>n>>A;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}	
	dp[0][0][0]=1;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=i;j++)
		{
			for(k=0;k<=sum[i];k++)
			{
				dp[(i%2)][j][k]=dp[(i-1)%2][j][k];
				if(k-a[i]>=0 && j!=0)
				dp[(i%2)][j][k]+=dp[(i-1)%2][j-1][k-a[i]];
			}
		}
	}
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=sum[n];j++)
		{
			if(i==0)
			continue;
			if(j%i==0 && j/i==A)
			ans+=dp[(n%2)][i][j];
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;

int dx[]={1,1,1,1,1,2,2,2,3};
int dy[]={-2,-1,0,1,2,-1,0,1,0};

class State
{
public:
	int lx,ly,rx,ry,c,f;
	State(int lx, int ly, int rx, int ry, int c, int f)
		:lx(lx),ly(ly),rx(rx),ry(ry),c(c),f(f)
	{}

	bool operator<(const State& s) const
	{
		return c>s.c;
	}
};

bool v[30][60][2];

int main()
{
	int W,H;
	char f[80][80];
	while(cin >> W >> H, (W||H))
	{
		memset(v,0,sizeof(v));

		priority_queue<State> q;
		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		{
			cin >> f[j][i];
			if(f[j][i]=='S')
			{
				for(int k=0; k<2; k++)
					q.push(State(j,i,j,i,0,k));
			}
		}

		bool g=false;
		while(!q.empty())
		{
			State s=q.top(); q.pop();
			if(f[s.lx][s.ly]=='T' || f[s.rx][s.ry]=='T')
			{
				g=true;
				cout << s.c << endl;
				break;
			}

			if(s.f==0)
			{
				if(v[s.rx][s.ry][s.f]) continue;
				v[s.rx][s.ry][s.f]=1;
			}
			else
			{
				if(v[s.lx][s.ly][s.f]) continue;
				v[s.lx][s.ly][s.f]=1;
			}

			for(int i=0; i<9; i++)
			{
				if(s.f==0)
				{
					int tlx=s.rx-dx[i], tly=s.ry+dy[i];
					int tf=(s.f+1)%2;
					if(tlx<0||tly<0||tlx>=W||tly>=H) continue;
					if(f[tlx][tly]=='X') continue;
					if(v[tlx][tly][tf]) continue;

					int tc=s.c;
					if(isdigit(f[tlx][tly])) tc+=f[tlx][tly]-'0';

					q.push(State(tlx,tly,s.rx,s.ry,tc,tf));
				}
				if(s.f==1)
				{
					int tlx=s.lx+dx[i], tly=s.ly+dy[i];
					int tf=(s.f+1)%2;
					if(tlx<0||tly<0||tlx>=W||tly>=H) continue;
					if(f[tlx][tly]=='X') continue;
					if(v[tlx][tly][tf]) continue;

					int tc=s.c;
					if(isdigit(f[tlx][tly])) tc+=f[tlx][tly]-'0';

					q.push(State(s.rx,s.ry,tlx,tly,tc,tf));
				}
			}

		}

		if(!g) cout << -1 << endl;
		
	}

}

Measured memory_bytes: 0
n = input()
A = [0]
p = range(1, n)
a = [[0 for i in range(n)]for j in range(n)]

for i in range(n):
    a[i] = map(int, raw_input().split() )

l = 0

while p != []:
    a_min = 10000
    for i in A:
        for j in p:
            if 0 <= a[i][j] < a_min:
                a_min = a[i][j]
                add_A = j
    A.append(add_A)
    p.remove(add_A)
    l += a_min

print l

Measured memory_bytes: 6488
#include<bits/stdc++.h>//万能头 
using namespace std;
int main()//主程序 
{
	//本题思路：string两个数组，getline读入，while循环，一边循环一边输出 
    string a;//string a 
    string b;//string b
	getline(cin,a);//输入 a
	getline(cin,b);//输入 b 
	int x,y;//int两个数组求a，b的长度
	x=a.size();//x求a的长度 
	y=b.size();//y求b的长度  
	int s=0,f=0;//标记 :while里面暴力做标记 
	while(s!=x&&f!=y) //while
	{
		cout<<a[s]<<b[f]; //一边循环一边输出 
		s++;//加加 
		f++;//加加 
	} 
	if(y>x)
	{
		for(int i=x;i<y;i++)
		{
			cout<<b[i]; 
		} 
		return 0;
	} 
	if(x>y)
	{
		for(int i=y;i<x;i++)
		{
			cout<<a[i]; 
		} 
		return 0;
	} 
	if(y==x)
	{
		return 0;
	} 
    return 0;//退出 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
int main(void){
    int n,k,c;cin>>n>>k>>c;
    vector<char> s(n); rep(i,n) cin>>s[i];
    int ct=0;
    vector<int> l,r;
    ll cnt=0;
    rep(i,n){
        if(ct<=0&&s[i]=='o'&&cnt<k){
            l.push_back(i);
            ct=c;
            cnt++;
        }else{
            ct--;
        }
    }
    reverse(s.begin(),s.end());
    cnt=0;
    
    ct=0;
    rep(i,n){
        if(ct<=0&&s[i]=='o'&&cnt<k){
            r.push_back(n-i-1);
            ct=c;
            cnt++;
        }else{
            ct--;
        }
    }
    if(l.size()!=r.size()){
        //cout<<r.size()<<" "<<l.size()<<endl;
        return 0;
    }
    reverse(r.begin(),r.end());
    rep(i,r.size()){
        //cout<<r[i]<<" "<<l[i]<<endl;
        if(r[i]==l[i])cout<<r[i]+1<<endl;
    }
}

Measured memory_bytes: 3444
#include <iostream>
#include <cmath>
#include <cstdio>

int main(){
  int r, D, x;
  std::cin >> r >> D >> x;
  for(int i=1; i<=10; ++i){
    x = r*x - D;
    std::cout << x << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define N 1000123
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define pb emplace_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define oo 1000000123
#define mod 1000000007LL
#define M 10000123
 
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(0);
    string sa, sb;
    cin >> sa >> sb;
    int ans = 0;
    for(int i =0; i < sz(sa); ++i){
        if(sa[i] != sb[i]) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3804
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    s = [0] * n
    for i in range(n - 1):
        if a[i + 1] > a[i]:
            s[i + 1] = 1
        elif a[i + 1] == a[i]:
            continue
        else:
            s[i + 1] = -1
    #print(s)
    tak = 1000
    stock = 0
    for i in range(n - 1):
        if s[i + 1] == 1 and not stock:
            stock = tak // a[i]
            tak = tak % a[i]
        elif s[i + 1] == -1 and stock:
            tak += stock * a[i]
            stock = 0
    if s[-1] >= 0:
        tak += a[-1] * stock
    print(tak)


solve()


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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> vec;
  for(int i = 0 ; i < n ; i++) {
    int x;
    cin >> x;
    if(x & 1) continue;
    vec.push_back(x);
  }
  sort(vec.rbegin() , vec.rend());
  int ans = 0;
  for(int i = 0 ; i < vec.size() ; i++) {
    while(vec[i] % 2 == 0) {
      vec[i] /= 2;
      ans++;
    }
  } cout << ans << endl;
}


Measured memory_bytes: 384
using System;
class Program
{
	static void Main()
	{
	int[] a = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    int[] b = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    int[] c = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      int ok = 0;
      for(int i = -100; i <= 100; i++)
      {
       if(b[0] == a[0] + i && b[1] == a[1] + i && b[2] == a[2] + i) 
       {
         ok ++;
         break;
       }
      }
      for(int i = -100; i <= 100; i++)
      {
       if(c[0] == a[0] + i && c[1] == a[1] + i && c[2] == a[2] + i) 
       {
         ok ++;
         break;
       }
      }
	Console.WriteLine((ok == 2) ? "Yes" : "No");
	}
}

Measured memory_bytes: 13140
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
 
 
const ll INF = 1e18;
const ll N =(1e5+5);
const ll MOD = 1e9+7;
ll t[N];
ll a[N];
ll w[N];
ll w2[N];
ll sure[N];
ll sure2[N];
void solve(){
    ll n;
    cin >> n;
    for(int i =1;i<=n;i++){
        cin >> t[i];
    }
    for(int i =1;i<=n;i++){
        cin >> a[i];
    }
    if(a[1] != t[n]){
        cout << 0 << endl;
        return;
    }
    w[1] = 1;
    sure[1] = t[1];
    for(int i =2;i<=n;i++){
        sure[i]= -1;
        if(t[i] == t[i-1]) w[i] = t[i];
        else w[i] = 1,sure[i] = t[i];
    }
    w2[n] = 1;
    sure2[n]=a[n];
    for(int i = n-1;i>=1;i--){
        sure2[i] = -1;
        if(a[i] == a[i+1]) w2[i] = a[i];
        else w2[i] = 1,sure2[i] = a[i];
    }
    for(int i =1;i<=n;i++){
        if(sure[i] != -1){
            if(a[i] < sure[i]){
                cout << 0 << endl;
                return;
            }
        }

    }
    for(int i =n;i>=1;i--){
        if(sure2[i] != -1){
            if(t[i] < sure2[i]){
                cout << 0 << endl;
                return;
            }
        }
    }

    ll ans = 1;
    for(int i = 1;i<=n;i++){
        ans = (ans * min(w[i],w2[i]))%MOD;
    }
    cout << ans << endl;

}

signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    

 
     ll tt=1;   
    while(tt--){    
        solve();
    }    
}

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

#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <regex>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <queue>
#include <stack>
#include <set>
#include <unordered_map>
#include <unordered_set>


using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 998244353;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}



signed main() {

	int n;
   
	cin >> n;
	
	int ans = 0;
	
	int sum[100] = {};


	for(int i = 1; i <= n; i++) {

		sum[(to_string(i)[0]-'0')*10 + i%10]++;		
		
	}

	for(int i = 1; i <= n; i++) {
		ans += sum[(i%10)*10+(to_string(i)[0]-'0')];
	}

	cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256