akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main() {
	vector<int> v1;
	vector<int> v2;
	int h;
	int w;
	bool IsInput = true;

	while (IsInput) {
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}
		v1.push_back(h);
		v2.push_back(w);
	}
	
	for(int i = 0; i < v1.size();i++){
		for (int j = 0; j < v1[i];j++) {
			for (int k = 0; k < v2[i]; k++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


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

string N;
ll dp[1010101][2];

int main() {
    cin >> N;
    reverse(N.begin(), N.end());

    int n = N.size();
    rep(i, n+1) rep(d, 2) dp[i][d] = 1e12;
    dp[0][0] = 0;
    rep(i, n) rep(d, 2) {
        if (dp[i][d] != 1e12) {
            int c = N[i] - '0' + d;
            dp[i+1][0] = min(dp[i+1][0], dp[i][d] + c);
            dp[i+1][1] = min(dp[i+1][1], dp[i][d] + 10 - c);
        }
    }

    cout << min(dp[n][0], dp[n][1] + 1) << endl;
}


Measured memory_bytes: 17028
use proconio::input;
use num::integer::gcd;
use itertools::Itertools;
fn main() {
    input! {
        k: i128,
    };
    let sum =|x|{(1+x)*x/2};
    let mut ans:i128 =sum(k);
    for (i,j)in (1..=k).tuple_combinations(){
        ans+=gcd(i,j)*6;
    };
    for (i,j,l)in (1..=k).tuple_combinations(){
        let tmp=gcd(i,j);
        ans+=gcd(tmp,l)*6;
    };
    println!("{}",ans);
}


Measured memory_bytes: 2132
#!/usr/bin/env python3
import sys
n, y = map(int, input().split())

for i in range(n + 1):
    for j in range(n + 1):
        k = n - i - j
        if (k < 0) or (i + j + k != n):
            continue

        if (i * 10000) + (j * 5000) + ((k) * 1000) == y:
            print(i, j, k)
            sys.exit()

print(-1, -1, -1)

Measured memory_bytes: 9108
MOD = 10**9 + 7
N = int(input())
C = [int(input()) for _ in range(N)]

L = [-1]*(2*10**5+10)
dp = [-1]*(2*10**5+10)
dp[0] = 1

for i in range(N):
    if L[C[i]] == -1:
        dp[i+1] = dp[i]
    elif C[i] == C[i-1]:
        dp[i+1] = dp[i]
    else:
        dp[i+1] = dp[i]+dp[L[C[i]]]
    dp[i+1] %= MOD
    L[C[i]] = i+1
print(dp[N])


Measured memory_bytes: 91232
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
using ll =long long;
using namespace std;


int n;
ll s[500000];
ll c=0;

void merge(ll array[],ll left,ll mid,ll right){
    ll n1=mid-left;
    ll n2=right-mid;
    vector<ll> L(n1+1),R(n2+1);
    rep(i,n1){
        L[i]=array[left+i];
    }
    L[n1]=1000000001;
    rep(i,n2){
        R[i]=array[mid+i];
    }
    R[n2]=1000000001;
    ll i=0;
    ll j=0;
    for(ll k=left;k<right;k++){
        if(L[i]<=R[j]){
            array[k]=L[i];
            i++;
        }else{
            array[k]=R[j];
            j++;
        }
    }
    c+=i+j;
}

void mergeSort(ll array[],ll left,ll right){
    if(left+1<right){
        ll mid=(left+right)/2;
        mergeSort(array,left,mid);
        mergeSort(array,mid,right);
        merge(array,left,mid,right);
    }
}

int main(){
    cin>>n;
    rep(i,n){
        cin>>s[i];
    }
    mergeSort(s,0,n);
    rep(i,n-1){
        cout<<s[i]<<" ";
    }
    cout<<s[n-1]<<endl;
    cout<<c<<endl;
}


Measured memory_bytes: 10512
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

int main() {
    int q1, b, c1, c2, q2;
    while ( cin >> q1 && q1 ) {
        cin >> b >> c1 >> c2 >> q2;
        bool flag2 = true;
        for ( int i = q2; i >= 1; -- i ) {
            bool flag = false;
            int t = 0;
            for ( int j = 0; i * c1 + j * c2 <= b; ++ j ) {
                if ( i + j >= q1 ) {
                    t = j;
                    flag = true;
                }
            }
            if ( flag ) {
                cout << i << " " << t << endl;
                flag2 = false;
                break;
            }
        }
        if ( flag2 ) {
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pb push_back
#define PI 3.14159265358979323846264338327950L
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define f(i, a, n) for (int i = a; i < n; i++)
using namespace std;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int r; cin>>r;
    cout<<2*PI*r;

    return 0;
}

Measured memory_bytes: 3788
/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

int n ;
pair<int,int> arr[N] ;
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d%d",&arr[i].second,&arr[i].first);
    }
    sort(arr,arr+n);
    long long cur = 0 ;
    for(int i=0;i<n;++i){
        cur += arr[i].second ;
        if(cur > arr[i].first) return cout << "No",0 ;
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 1792
//B - Roller Coaster
#include <stdio.h>

int main(void){
    int n, k, i, rideRCoaster=0;
    scanf("%d %d", &n, &k);
    int h[100000]={0};
    for(i=0; i<n; i++) scanf("%d", &h[i]);

    for(i=0; i<n; i++){
        if(h[i]>=k) rideRCoaster++;
    }
    printf("%d\n", rideRCoaster);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}

signed main(){
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    string s;
    cin >> s;
    if (s == "A")
        cout << "T" << endl;
    else if (s == "T")
        cout << "A" << endl;
    else if (s == "G")
        cout << "C" << endl;
    else
        cout << "G" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<int> memo(1000000, INT_MAX);
void solve(){
	int n, k; cin>>n>>k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}

	memo[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		for(int j=i+1;j<=i+k;j++){
			if(j<n){
				memo[j] = min(memo[j], memo[i]+abs(a[i]-a[j]));
			}
		}
	}
	cout<<memo[n-1]<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // ll t; cin>>t;
    // while(t--)
    solve();
    return 0;
}


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

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

using namespace std;

const int INF=1e9+1;

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> c(n);
	rep(i,n) scanf("%d",&c[i]);

	vector<int> dp(n,INF);
	dp[0]=0;
	rep(i,n) for(int d=1;d<=k;d++) if(i+d<n) dp[i+d]=min(dp[i+d],dp[i]+abs(c[i+d]-c[i]));
	printf("%d\n",dp[n-1]);

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
int main()
{
    int n;
    ll ans=0;
    cin>>n;
    vector<int> a(n+1);
    for(int i=0;i<n+1;i++) cin>>a[i];
    for(int i=0;i<n;i++)
    {
        int x,dt;
        cin>>x;
        dt=min(a[i],x);
        a[i]-=dt,x-=dt,ans+=dt;
        dt=min(a[i+1],x);
        a[i+1]-=dt,ans+=dt;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

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

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1000000007;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; assert(scanf("%lld", &x) == 1); return x;}
ld fin(){double x; assert(scanf("%lf", &x) == 1); return x;}
char yuyushiki[1000010]; string stin(){assert(scanf("%s", yuyushiki) == 1); return yuyushiki;}

// head

int main(){

  ll n = in();
  ll a = 1;
  REP(i, n){
    a = a * (i + 1);
    a %= MOD;
  }
  cout << a << endl;

  return 0;
}


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

using namespace std;

struct Edge {
	int from, to;
	string spell;
};

int main(){
	while(true){
		int n, a, s, g;
		cin >> n >> a >> s >> g;
		if(n == 0 && a == 0 && s == 0 && g == 0){ break; }
		vector<Edge> edges(a);
		for(int i = 0; i < a; ++i){
			cin >> edges[i].from >> edges[i].to >> edges[i].spell;
		}
		bool valid = true;
		vector<string> strongest(n, string("\x7f"));
		strongest[g] = "";
		for(int i = 0; i < 7 * n; ++i){
			for(int j = 0; j < a; ++j){
				const Edge &e = edges[j];
				if(strongest[e.to] == "\x7f"){ continue; }
				string q = e.spell + strongest[e.to];
				if(strongest[e.from] > q){
					strongest[e.from] = q;
					if(e.from == s && i >= 6 * n){ valid = false; }
				}
			}
		}
		if(strongest[s] == "\x7f"){ valid = false; }
		cout << (valid ? strongest[s] : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 1488
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;

ll a, b, c, d;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c >> d;
    cout << max({(a * c), (b * d), (a * d), (b * c)});
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    string S, T;
    cin >> S >> T;
    int c = 0;
    REP(i, 3) {
        if (S[i] == T[i]) c++;
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
def factrize(x):
    # 試し割りによるxの素因数分解
    f = {}
    tmp = x
    i = 2
    while i**2 <= tmp:
        cnt = 0
        while tmp % i == 0:
            cnt += 1
            tmp = tmp // i
        if cnt > 0:
            f[i] = cnt
        i += 1
    if tmp != 1 or f == {}:
        f[tmp] = 1
    return f


n = int(input())
f = factrize(n)
ans = 1
for p in f:
    ans *= p**(f[p] - 1) * (p - 1)
print(ans)



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

bool check(int a, int b, int c)
{
	if (a + b <= c || a + c <= b || b + c <= a || a == b || b == c || a == c)
		return 0;
	else
		return 1;
}

int main()
{

	int n; cin >> n;
	vector<int> arr(n);
	for (int i=0; i<n; i++)
		cin >> arr[i];

	if (n < 3)
	{
		cout<<"0\n";
		return 0;
	}

	int ans = 0;
	for (int i=0; i<n-2; i++)
		for (int j=i+1; j<n-1; j++)
			for (int k=j+1; k<n; k++)
				if (check(arr[i],arr[j],arr[k]))
					ans++;
	
	cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        var H = new HashSet<int>();
        int N = cin.nextint;
        for (int i = 0; i < N; i++)
        {
            H.Add(cin.nextint);
        }
        WriteLine(H.Count);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

void fnInput(int& rnNumK)
{
  cin >> rnNumK;
}

int fnGcdGet(int nPos, vector<int>& rvnNum)
{
  if (nPos == rvnNum.size()) return rvnNum[0];

  int nDividend = max(rvnNum[0], rvnNum[nPos]);
  int nDivisor  = min(rvnNum[0], rvnNum[nPos]);

  while ( nDividend % nDivisor )
  {
    int nMod = nDividend % nDivisor;
    nDividend = nDivisor;
    nDivisor  = nMod;
  }

  rvnNum[0] = nDivisor;
  return fnGcdGet(nPos + 1, rvnNum);
}
  
int fnSumGcdTuples(int nNumK)
{
  int nSumGcd = 0;

  for (int i = 1; i <= nNumK; i++)
    for (int j = 1; j <= nNumK; j++)
      for (int k = 1; k <= nNumK; k++)
      {
        vector<int> vnNum = {i, j, k};     // 要素 0 番目 GCD 格納
        nSumGcd += fnGcdGet(1, vnNum);
      }

  return nSumGcd;
}
  
int main()
{
  int nNumK;

  fnInput(nNumK);
  cout << fnSumGcdTuples(nNumK) << endl;

  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M,P;
    cin >> N >> M >> P;
    while(N){
        int cnt = 0,x,all = 0;
        rep(i,0,N){
            cin >> x;
            all += x;
            if(i == (M-1))cnt = x;
        }
        int sum = all * 100;
        sum -= sum * P / 100;
        if(cnt)cout << sum / cnt << endl;
        else   cout << 0 << endl;
        cin >> N >> M >> P;
    }
}


Measured memory_bytes: 3044
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static BigInteger GetInteger() { return BigInteger.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace AtCoder.D
{
    public class Program
    {
        public static BigInteger H { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            H = CR.GetInteger();

            BigInteger count = 0;
            BigInteger dif = 1;
            while (H != 1)
            {
                count += dif;
                dif *= 2;

                H = (BigInteger)Math.Floor((decimal)(H / 2));
            }

            count += dif;

            return count;
        }
    }
}


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

int main(){
	int x,n,a,b = 0,cont= 0;
	scanf("%d %d",&n,&x);
	for(int i = 0;i < n;++i){
		scanf("%d",&a);
		b += a;
		if(b <= x)
			++cont;
	}
	printf("%d\n",cont+1);

	return 0;
}

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

 int main(){ 

 int ab, bc, ca, a,ans;
 double b;

 cin >> ab >> bc >> ca;


 a = abs(ab);
 b = abs(bc);


 ans = a * ( b / 2);

 cout << ans << endl;

 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<vector<int>> g(n, vector<int>(n, -1));
   rep(i, 0, n) {
      int a;
      cin >> a;
      rep(j, 0, a) {
         int x, y;
         cin >> x >> y;
         x--;
         g[i][x] = y;
      }
   }
   int ans = 0;
   rep(i, 0, 1 << n) {
      bool isfalse = false;
      rep(j, 0, n) {
         if (i >> j & 1) {
            rep(k, 0, n) {
               if (g[j][k] == -1) continue;
               if (g[j][k] != ((i >> k) & 1)) isfalse = true;
            }
         }
      }
      if (!isfalse) ans = max(ans, __builtin_popcount(i));
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e9

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

string text;
ll ans, cnt[26];

int main()
{
	cin >> text;
	ll n = text.size();
	ans=n*(n-1)/2;
	for(int i = 0; i < n; i++){
		cnt[text[i]-'a']++;
	}
	for(int i = 0; i < 26; i++){
		ans-=cnt[i]*(cnt[i]-1)/2;
	}
	cout << ans+1;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define NOT_FOUND 0
int A[10000];
int n;
int linearSearch(int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key){
    i++;
    if(i==n){
      return NOT_FOUND;
    }
  }
  return 1;
}
int main(){
  int i,key,a,cnt=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&key);
    if(linearSearch(key)) cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2044
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

const int MAXN = 1001024;

// 結果を格納する変数
int prime[MAXN]; // n 以下の素数のうち i 番目の素数
bool is_prime[MAXN]; // 整数 i が素数であるかどうか

int sieve(int n) {
    int res = 0;
    fill(is_prime, is_prime + MAXN, true);
    is_prime[0] = is_prime[1] = false; // 0 と 1 は素数ではない。
    for(int i = 2; i <= n; ++i) {
        if(!is_prime[i]) continue;
        prime[res++] = i;
        for(int j = 2 * i; j <= n; j += i) is_prime[j] = false; // 素数 i の倍数は素数ではない (ふるい(篩)にかける)
    }
    return res;
}

signed main(){
    
    int res = sieve(1000000);
    int n = 100010;
    vector<int> a(n + 1, 0);
    for(int i = 1; i <= n; i += 2){
        if(is_prime[i] && is_prime[(i + 1) / 2]) a[i] = 1;
    }

    for(int i = 1; i <= n; i++) a[i] += a[i - 1];

    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        cout << a[r] - a[l - 1] << endl;
    }
    return 0;
}



Measured memory_bytes: 2944
#include<iostream>
using namespace std;
int main(){
  int n,d[5000];
  int sum,max;
  while(cin>>n){
    if(n==0)break;
    max=-100001;
    for(int i=0;i<n;i++){
      cin>>d[i];
    }
    for(int i=0;i<n;i++){
      sum=0;
      for(int j=i;j<n;j++){
	sum+=d[j];
	if(sum>max){
	  max=sum;
	}
      }
    }
    cout<<max<<endl;
  }
  return 0;
}

Measured memory_bytes: 1180
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
      	String num = sc.nextLine();
		String[] data = line.split(" ");
      	String[] num2 = num.split(" ");
      	Integer sum = 0;
      	for(int i = 0; i < Integer.parseInt(data[1]); i++){
          sum += Integer.parseInt(num2[i]);
        }
		Integer nokori = Integer.parseInt(data[0]) - sum;
      if(nokori < 0){
        System.out.println(-1);
      }else{
        System.out.println(nokori);
      }
	}
}

Measured memory_bytes: 38392
/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cerr << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> PII;

int N, M;

int UF[110000];
int dis[110000];
pair<int, int> FIND(int a) {
  if (UF[a] < 0) return {a, 0};
  pair<int, int> par = FIND(UF[a]);
  dis[a] += par.second;
  UF[a] = par.first;
  return {par.first, dis[a]};
}


bool check(int l, int r, int d) {
  pair<int, int> L = FIND(l);
  pair<int, int> R = FIND(r);
  if (L.first == R.first) {
    if (L.second + d != R.second) {
      return false;
    } else {
      return true;
    }
  }
  UF[R.first] = L.first;
  dis[R.first] = d + L.second - R.second;
  return true;
}

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

    cin >> N >> M;

    REP(i, N) {
      UF[i] = -1;
    }
    REP(i, M) {
      int l, r, d;
      cin >> l >> r >> d;
      l--; r--;

      bool res = check(l, r, d);
      if (!res) {
        cout << "No" << endl;
        return 0;
      }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1024
array = gets.chomp.split(" ")
H = array[0].to_i
W = array[1].to_i

gyou_array = []
next_array = []
retu_array = []
final_array = []

gyou_tobasu = []
retu_tobasu = []

H.times{|item|
  gyou_array << gets.chomp.split("")
}

gyou_array.each_with_index {|item, idx|
  gyou_tobasu << idx.to_i unless item.include?("#")
}

gyou_array.each_with_index{|item, idx|
  next if gyou_tobasu.include?(idx)
  next_array << item
}

retu_array = next_array.transpose
retu_array.each_with_index {|jtem, jdx|
  retu_tobasu << jdx.to_i unless jtem.include?("#")
}

retu_array.each_with_index{|jtem, jdx|
  next if retu_tobasu.include?(jdx)
  final_array << jtem
}

final_array.transpose.each_with_index{|ltem, ldx|
  ltem.each_with_index{|ltem, ldx|
    print(ltem)
  }
  puts("")
}

Measured memory_bytes: 2684
program scoring
    implicit none
    integer(8)::D,C(26),last(26),i,j
    integer(8),allocatable::S(:,:),T(:),V(:)
    read*,D,C
    allocate(S(26,D))
    allocate(T(D))
    allocate(V(D))
    read*,S,T
    V=0
    last=0

    do i=1,D
        if(i==1)then
            V(i)=V(i)
        else
            V(i)=V(i-1)
        end if
        V(i)=V(i)+S(T(i),i)
        last(T(i))=i
        do j=1,26
            V(i)=V(i)-C(j)*(i-last(j))
        end do
    end do

    do i=1,D
        print'(i0)',V(i)
    end do
end program scoring

Measured memory_bytes: 3016
#include <iostream>
#include <algorithm>

using namespace std;
int main() {
	int N;
	cin >> N;
	int A[N];
	int count = 0;
	for(int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	for(int i = 0; i < N; i++){
		for(int j = N - 1; j > i; j--){
			if(A[j-1] > A[j])
			{
				int temp = A[j];
				A[j] = A[j-1];
				A[j-1] = temp;
				count++;
			}
		}
	}
	for(int j = 0; j < N - 1; j++)
	{
		cout << A[j] << " ";
	}
	cout << A[N-1] << endl;
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int d, n;
    cin >> d >> n;
    cout << int(pow(100, d) * (n == 100 ? n+1:n)) << endl;
    return 0;
}




Measured memory_bytes: 384
#include<iostream>
#include<functional>
#include<algorithm>
#include<vector>
#include<queue>
#define LL long long
#define TT std::tuple<int,int,int>
int D[110][110];
int INF = 10000000;
std::vector<TT> E;
int ans;
int main() {
	int N, M;
	std::cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			if (i == j)D[i][j] = 0;
			else D[i][j] = INF;
		}
	}
	for (int i = 0; i < M; i++) {
		int a, b, c;
		std::cin >> a >> b >> c;
		D[a][b] = c;
		D[b][a] = c;
		E.push_back(TT{ a,b,c });
	}
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				D[i][j] = std::min(D[i][j], D[i][k] + D[k][j]);
			}
		}
	}
	for (auto u : E) {
		int a, b, c;
		std::tie(a, b, c) = u;
		for (int i = 1; i <= N; i++) {
			if (D[i][a] + c == D[i][b] || D[i][b] + c == D[i][a])break;
			if (i == N)ans++;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

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

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

int main(void) {
    long long a, b, x;
    cin >> a >> b >> x;
    a = a - 1;

    long long fa = 0, fb = 0;
    if (a >= 0) {
        fa = a / x + 1;
    }
    if (b >= 0) {
        fb = b / x + 1;
    }

    cout << fb - fa << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL);
#define fr(i,a,b)  for(int i=a;i<=b;i++)
#define rf(j,b,a)  for(int j=b;j>=a;j--)
#define frr(k,a,b) for(int k=a;k<=b;k++)
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define ss second
#define ff first

using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
#define E 2000 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
     if(a.first==b.first)
     {
     return (a.second < b.second); 
     }
     else
     {
       return (a.first > b.first); 
     }
     
} 
bool sortin(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
     return (a.second < b.second);   
} 
signed main()
{   
  IOS

string s,t;
cin>>s;
cin>>t;
int s1 = s.size();
int t1 = t.size();
int dp[s1+1][t1+1];
for(int i=0;i<=s1;i++)
{
  for(int j=0;j<=t1;j++)
{
if(i==0||j==0)
{
  dp[i][j]=0;
  continue;
}
if(s[i-1]==t[j-1])
{
  dp[i][j]= 1 + dp[i-1][j-1];
}
else
{   
  dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
}
int tmp1=s1;
int tmp2=t1;
string ans;
while(tmp2>=1&&tmp1>=1)
{
if(s[tmp1-1]==t[tmp2-1])
{
ans = s[tmp1-1] + ans;
tmp2--;
tmp1--;
}
else if(dp[tmp1][tmp2]==dp[tmp1-1][tmp2])
{
tmp1--;
}
else
{
  tmp2--;
}
}
cout<<ans<<endl;
}




 

Measured memory_bytes: 74064
#include<stdio.h>
int main()
{
	int n,p;
	while(scanf("%d%d",&n,&p),n)
	{
		int i,a[50]={0},m=p;
		for(i=0;a[i]-p;i=(i+1)%n)
		{
			if(m)a[i]++,m--;
			else m=a[i],a[i]=0;
		}
		printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 756
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
#define MAX_M 100005

int n,m;
int x[MAX_M],y[MAX_M],w[MAX_M];

vector<int> G[MAX_N];
vector<int> g[MAX_N];

vector<int> group[MAX_N];
int id[MAX_N];
bool visited[MAX_N];
vector<int> vd;

int dp[MAX_N];

bool dfs(int pos,int prev,int root){
  id[pos]=root;
  visited[pos]=true;
  group[root].push_back(pos);
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    if(to==prev)continue;
    if(i&&to==G[pos][i-1])return true;
    if(visited[to])return true;
    if(dfs(to,pos,root))return true;
  }
  return false;
}

bool check(){
  memset(visited,false,sizeof(visited));
  for(int i=0;i<n;i++){
    if(visited[i])continue;
    if( dfs(i,-1,i) )return true;
  }

  vector< int > deg(n);
  vector< vector<int> > graph(n);
  
  for(int i=0;i<m;i++){
    if(w[i]==1){
      int X=id[ x[i] ];
      int Y=id[ y[i] ];
      if(X==Y)return true;
      graph[X].push_back(Y);
      deg[Y]++;
    }
  }

  queue<int> Q;
  for(int i=0;i<n;i++)
    if(deg[i]==0&&id[i]==i)
      Q.push(i);

  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    vd.push_back(pos);
    for(int to:graph[pos]){
      deg[to]--;
      if(deg[to]==0)Q.push(to);
    }
  }
  
  for(int i=0;i<n;i++)
    if(deg[i]>0)return true;
  
  return false;
}

int d[MAX_N];

void init(int root){
  root=id[root];
  for(int pos:group[root])
    d[pos]=-1;
}

void bfs(int S){
  init(S);
  queue<int> Q;
  Q.push(S);
  d[S]=0;
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    for(int to:G[pos]){
      if(d[to]!=-1)continue;
      d[to]=d[pos]+1;
      Q.push(to);
    }
  }
}

int solve(int S,int &ans){
  bfs(S);
  int res=S;
  for(int pos:group[id[S]]){
    if(d[pos]+dp[pos]>d[res]+dp[res])res=pos;
    ans=max(ans,d[pos]+dp[S]);
    for(int to:g[pos])dp[to]=max(dp[to],d[pos]+dp[S]+1);
  }
  return res;
}

  /*
  int res=0;
  bfs(root);
  int maxm=-1,maxmid;
  for(int pos:group[root])
    if(d[pos]+dp[pos]>maxm)maxm=d[pos]+dp[pos],maxmid=pos;
  
  bfs(maxmid);
  update(root,dp[maxmid]);
  for(int pos:group[root])res=max(res,d[pos]+dp[maxmid]);
  
  maxm=-1;
  for(int pos:group[root])
    if(d[pos]+dp[pos]>maxm)maxm=d[pos]+dp[pos],maxmid=pos;

  bfs(maxmid);
  update(root,dp[maxmid]);
  for(int pos:group[root])res=max(res,d[pos]+dp[maxmid]);
  
  return res;
  */


int main(){
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d %d %d",&x[i],&y[i],&w[i]);
    x[i]--,y[i]--;
    if(w[i]==1){
      g[x[i]].push_back(y[i]);
    }
    if(w[i]==2){
      G[x[i]].push_back(y[i]);
      G[y[i]].push_back(x[i]);
    }
  }
  
  if( check() ){
    printf("Infinite\n");
    return 0;
  }

  int ans=0;
  for(int root : vd ){
    if(root!=id[root])continue;
    solve( solve( solve(root,ans) , ans ) , ans);
  }
  printf("%d\n",ans);  
  return 0;
}

Measured memory_bytes: 23632
n = int(input())
a = [int(x) for x in input().split()]
boolean = True
count = 0

while boolean:
  for i in range(n):
    if a[i] % 2 != 0:
      boolean = False
    else:
      a[i] = a[i] / 2
  if boolean:
    count += 1

print(count)

Measured memory_bytes: 9112
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
    string S;

    for(int i=0;i<6;i++){
        S[i] = '0';
    }
    
    cin >> S;

    int a = 0;
    for(int i=0;i<6;i++){
        if(S[i] == '1'){
            a = a + 1;
        }
    }
    cout << a << endl;
    return 0;

}

Measured memory_bytes: 256
/* Ajay Jadhav */
#include <bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

const int N=2e5+5;
int dp[N][3];
string s;
int n;
int f(int i,char c)
{
    if(i>=n) return 0;
    int ind=-1;
    if(c=='A') ind=0;
    else if(c=='P') ind=1;
    else ind=2;
    if(dp[i][ind]!=-1)
        return dp[i][ind];
    int& ans=dp[i][ind];
    ans=0;
    if(s[i]=='D')
    {
        if(c=='P')
            ans=2+f(i+1,'D');
        else
            ans=1+f(i+1,'D');
    }
    else if(s[i]=='P')
        ans=max(ans,f(i+1,'P'));
    else
    {
        int ans1=0;
        int ans2=0;
        // set D or P. 2 options for D
        ans1=1+(c=='P')+f(i+1,'D');
        ans2=f(i+1,'P');
        if(ans1>=ans2)
            s[i]='D';
        else
            s[i]='P';
        ans=max(ans1,ans2);
    }
    return ans;
}

void solve()
{
    cin>>s;
    n=sz(s);
    memset(dp,-1,sizeof dp);
    f(0,'A');
    cout<<s;
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 18620
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>


using namespace std;
typedef long long ll;

int main(){
	ll n;
	cin  >> n;
	ll a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	ll ans = 0;
	ll cnt = 1;
	for(int i = 0; i < n; i++){
		if(a[i] == cnt){
			cnt++;
			ans++;
		}
	}
	if(ans == 0) cout << -1 << endl;
	else cout << n - ans  << endl;
}

Measured memory_bytes: 1792
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def comb(n, k):
    if n % 2 == 0:
        return n / 2 * (n - 1)
    else:
        return (n - 1) / 2 * n


N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
uf = UnionFind(N)
ans = deque()
ans.appendleft(int(comb(N, 2)))
for i in range(M - 1, 0, -1):
    size1 = uf.size(AB[i][0] - 1)
    size2 = uf.size(AB[i][1] - 1)
    if size1 == N:
        ans.appendleft(0)
    elif uf.same(AB[i][0] - 1, AB[i][1] - 1):
        ans.appendleft(ans[0])
    else:
        uf.union(AB[i][0] - 1, AB[i][1] - 1)
        size3 = uf.size(AB[i][0] - 1)
        if size1 + size2 == 2:
            ans.appendleft(ans[0] - 1)
        elif size1 == 1:
            ans.appendleft(ans[0] - (int(comb(size3, 2)) - int(comb(size2, 2))))
        elif size2 == 1:
            ans.appendleft(ans[0] - (int(comb(size3, 2)) - int(comb(size1, 2))))
        else:
            ans.appendleft(ans[0] - (int(comb(size3, 2)) - int(comb(size1, 2)) - int(comb(size2, 2))))
for i in ans:
    print(i)


Measured memory_bytes: 149080
import Text.Printf

main :: IO ()
main = do
  x <- readLn
  let (a, b) = solve x
  printf "%d %d\n" a b

solve :: Int -> (Int, Int)
solve x = head [ (a, b) | a <- [-118..119], b <- [-119..118], a ^ 5 - b ^ 5 == x ]


Measured memory_bytes: 3976
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

#define MAXV 100000000

int N, M, X;
int C[12];
int A[12][12];
bool state[12];

ll search(int cur)
{
    if (cur == N) {
        ll u[M];
        ll cost = 0;
        REP(i, M) u[i] = 0;
        REP(i, N) {
            if (state[i]) {
                cost += C[i];
                REP(j, M) {
                    u[j] += A[i][j];
                }
            }
        }
        bool f = true;
        REP(i, M) {
            if (u[i] < X) {
                f = false;
                break;
            }
        }
        if (f) return cost;
        else return -1;
    }
    else {
        state[cur] = true;
        ll s1 = search(cur + 1);
        state[cur] = false;
        ll s2 = search(cur + 1);
        if (s1 == -1 && s2 == -1) {
            return -1;
        }
        else if (s1 == -1 && s2 != -1) {
            return s2;
        }
        else if (s1 != -1 && s2 == -1) {
            return s1;
        }
        else {
            return min(s1, s2);
        }
    }
}



int main(int argc, char **argv)
{
    cin >> N >> M >> X;
    REP(i, N) {
        cin >> C[i];
        REP(j, M) {
            cin >> A[i][j];
        }
    }

    cout << search(0) << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s;
    cin >> s;

    for (char c : s) {
        cout << 'x';
    }

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

Measured memory_bytes: 888
s = input()
a = len(s)
ans = 0
for i in range(1 << (a-1)):
    su = []
    st = -1
    for j in range(a-1):
        if (i>>j)&1 == 1:
            if st == -1:
                b = int(s[:j+1])
            else:
                b = int(s[st+1:j+1])
            su.append(b)
            st = j
    else:
        if st == -1:
            su.append(int(s))
        else:
            su.append(int(s[st+1:]))
    #print(su)
    ans += sum(su)
print(ans)


Measured memory_bytes: 3064
from itertools import permutations

n = int(input())
itr = permutations([i for i in range(1, n+1)])
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

for i, tpl in enumerate(itr):
    if tpl == p:
        val1 = i
    if tpl == q:
        val2 = i

print(abs(val1-val2))

Measured memory_bytes: 9096
d,g = map(int,input().split())
li = []
for i in range(1,d+1):
	p,c = map(int,input().split())
	li.append([p,i*100*p+c])
ans = 10**5
for i in range(2**d):
	s = t = u =0
	for j in range(d):
		if 1&(i>>j):
			s += li[j][1]
			u += li[j][0]
		else:
			t = max(t,j+1)
	if g <= s:
		ans = min(ans,u)
	elif g <= s + t*100*(li[t-1][0]-1):
		u -= (g-s)//-(100*t)
		ans = min(ans,u)
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n; string s,t; cin >> n >> s >> t;
    REP(i,n*2){
        if(i%2==0) cout << s[i/2];
        else cout << t[i/2];
    }
    cout << endl;

    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

int n, k;
int a[2222];

int main() {
    scanf("%d%d", &n, &k);
    forn(i, n) {
        scanf("%d", a + i);
    }
    int x = 0;
    forn(i, n) forn(j, i) {
        if (a[i] < a[j]) {
            ++x;
        }
    }
    int y = 0;
    forn(i, n) forn(j, n) {
        if (a[i] < a[j]) {
            ++y;
        }
    }
    int ans = ((LL)x * k % MOD + (LL)y * k % MOD * (k - 1) % MOD * (MOD / 2 + 1) % MOD) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n=0,i=0,j=0,tmp=0;
  int a[300]={'\0'};
  int alice=0,bob=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  	scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
    	if(a[j]>a[i]){
     	 	tmp=a[i];
      		a[i]=a[j];
      		a[j]=tmp;
   	 	}
    }
  }

  for(i=0;i<n;i++){
    if(i%2==0){
      alice=alice+a[i];
    }
    else{
      bob=bob+a[i];
    }
  }
    
  printf("%d",alice-bob);
  return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<int> vh(n);
  for (int i = 0; i < n; ++i) {
    cin >> vh[i];
  }

  vector<vector<int>> t(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    t[a].push_back(vh[b]);
    t[b].push_back(vh[a]);
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    sort(t[i].begin(), t[i].end());
    auto it = lower_bound(t[i].begin(), t[i].end(), vh[i]);
    if (it == t[i].end()) {
      ans++;
    }
  }

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

Measured memory_bytes: 8804
#include <bits/stdc++.h>
using namespace std;
long long n,k;
long long ans=0;
const int maxn = 2e5+5; 
const int P = 1e9+7;
int main(){
	cin >> n >> k;
	for (long long i=k,mini,maxi;i<=n+1;i++){
		mini = maxi = 0;
		mini = (i-1)*i/2; 
		maxi = (2*n-i+1)*i/2;
		ans += (maxi-mini+1);
		ans %= P;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>

int G[110][110]={};
int d[110];
int f[110];

int cnt = 0;

void dfs(int i, int n)
{
  int j;

  d[i] = ++cnt;
  for(j = 1;j <= n;j++){
    if(G[i][j] != 1) continue;
    else G[i][j] = 0;
    
    if(d[j] == 0) dfs(j, n);
  }
  f[i] = ++cnt;
}

int main()
{
  int n;
  int i,j;
  int u,k,v;
  
  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d%d", &u, &k);

    for(j = 0;j < k;j++){
      scanf("%d", &v);
      G[u][v] = 1;
    }
  }

  for(i = 1;i <= n;i++)
    if(d[i] == 0) dfs(i, n);

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



Measured memory_bytes: 2052
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var [e,y] = input.trim().split(" ").map(Number);
var mtsh = "MTSH".split("");
if(e==0){
   if(y>=1868 && y<=1911){e=1;y-=1868}
   else if(y>=1912 && y<=1925){e=2;y-=1912}
   else if(y>=1926 && y<=1988){e=3;y-=1926}
   else if(y>=1989 && y<=2016){e=4;y-=1989}
   console.log(mtsh[e-1] + (y+1));
}
else if(e==1)console.log(1868 + y - 1);
else if(e==2)console.log(1912 + y - 1);
else if(e==3)console.log(1926 + y - 1);
else if(e==4)console.log(1989 + y - 1);


Measured memory_bytes: 15156