akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"
#include <iostream>
using namespace std;

void trace(int A[], int N)
{
    for (int i = 0; i < N; i++ )
    {
       if (i > 0)
           cout << " ";
       cout << A[i];
    }
    cout << "\n";
}

void insertionSort(int A[], int N)
{
    int j, i, v;
    for (i = 1; i < N; i++)
    {
        v = A[i];
        j = i - 1;
        while ( j >= 0 && A[j] > v)
        {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A, N);
    }
}

int bubbleSort(int A[], int N)
{
    int sw = 0;
    bool flag = 1;
    for (int i = 0; flag; i++)
    {
        flag = 0;
        for (int j = N - 1; j >= i + 1; j--)
        {
            if (A[j] < A[j - 1])
            {
                // 隣接要素を交換する
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int selectionSort(int A[], int N)
{
    int t, sw = 0, minj;
    for (int i = 0; i < N - 1; i++)
    {
        minj = i;
        for (int j = i; j < N; j++)
        {
            if (A[j] < A[minj]) minj = j;
        }
        t = A[i];
        A[i] = A[minj];
        A[minj] = t;
        if (i != minj)
            sw++;
    }
    return sw;
}

int main()
{
    int A[1000], N, sw;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    sw = selectionSort(A, N);

        for (int i = 0; i < N; i++)
        {
            if (i) cout << " ";
            cout << A[i];
        }
    cout << endl;
    cout << sw << endl;

    return 0;
}


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

using namespace std;

#define ft first
#define sd second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL)
#define inp freopen("code.in", "r+", stdin)
#define out freopen("code.out", "w+", stdout)
#define debug(os, var)                                     \
    (os) << "DBG: " << __FILE__ << "(" << __LINE__ << ") " \
         << #var << " = [" << (var) << "]" << endl

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long int ll;

int main()
{
    boost;
    //inp;
    string st;
    cin >> st;
    if (*(st.end() - 1) == 's')
        st += "es";
    else
        st += "s";
    cout << st << endl;
      
}

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

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i,N) cin >> S[i];
    vector<int> C(4);
    rep(i,N){
        if(S[i] == "AC") C[0]++;
        if(S[i] == "WA") C[1]++;   
        if(S[i] == "TLE") C[2]++;
        if(S[i] == "RE") C[3]++;   
    }
    cout << "AC x " << C[0] << endl;
    cout << "WA x " << C[1] << endl;
    cout << "TLE x " << C[2] << endl;
    cout << "RE x " << C[3] << endl;
}

Measured memory_bytes: 6420
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 100000
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

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

  int n;
  cin >> n;
  ll a[n], b[n];
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];

  vector< pair< ll, pll > > v(n);
  for(int i = 0; i < n; i++){
    v[i] = make_pair(a[i] + b[i], make_pair(a[i], b[i]));
  }
  sort(v.begin(), v.end(), greater< pair< ll, pll > >());

  ll t_sum = 0, a_sum = 0;
  for(int i = 0; i < n; i++){
    if(i % 2 == 0) t_sum += v[i].second.first;
    else a_sum += v[i].second.second;
  }

  cout << (t_sum - a_sum) << endl;

  return 0;
}


Measured memory_bytes: 4224
import math

def main():
    k = int(input())
    mod = 7
    cnt = 1

    for i in range(k):
        if mod % k == 0:
            break
        cnt += 1
        mod = (mod * 10 + 7) % k
    if mod % k == 0:
        print(cnt)
    else:
        print(-1)

main()  

Measured memory_bytes: 9120
/* abc_170_a */

#include<stdio.h>

int main()
{
  int x[5];
  int i;
  for (i=0;i<5;i++){
    scanf("%d",&x[i]);
  }
  for (i=0;i<5;i++){
    if(x[i]==0) printf("%d\n",i+1);
  }
  return 0;
}


Measured memory_bytes: 1648
Module A
  
  Sub main()
  
'  Set Console = New Console
  
    Dim N As Long
    Dim i As Long
    Dim RD As String
    Dim SD() As String
    Dim tnow As Long
    Dim xnow As Long
    Dim ynow As Long
    Dim tfut As Long
    Dim xfut As Long
    Dim yfut As Long
    Dim dist As Long
    Dim elap As Long
    
    Dim ans As String
    
    tnow = 0
    xnow = 0
    ynow = 0
    
    N = Console.Readline()
    For i = 1 To N
        RD = Console.Readline()
        SD = Split(RD, " ")
        tfut = clng(SD(0))
        xfut = clng(SD(1))
        yfut = clng(SD(2))
    
        elap = tfut - tnow
        dist = System.Math.abs(xnow - xfut) + System.Math.abs(ynow - yfut)
    
        If elap < dist Then
            ans = "No"
            Exit For
        End If
    
        If ((elap - dist) Mod 2) = 1 Then
            ans = "No"
            Exit For
        End If
        
        tnow = tfut
        xnow = xfut
        ynow = yfut
  Next    

   
	  If ans = "" Then
	    ans = "Yes"
	  End If
  
	  Console.Writeline(ans)
  
  End Sub

End module	


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

int main()
{
    int N, res=0;
    string S;
    cin >> N >> S;
    for(int n=0; n<N-2; n++){
        if(S[n] == 'A' && S[n+1] == 'B' && S[n+2] == 'C'){
            res++;
        }
    }
    cout << res << endl;
	return 0;
}
 

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

int dp[4040][4040];

int main()
{
  string a, b;
  while (cin >> a >> b){
    memset(dp, 0, sizeof(dp));

    int max_n = 0;
    for (int i = 0; i < a.size(); i++){
      for (int j = 0; j < b.size(); j++){
        if (i * j == 0){
          dp[i][j] = a[i] == b[j];
          continue;
        }
        if (a[i] == b[j]) dp[i][j] = 1 + dp[i - 1][j - 1];
      }
    }

    for (int i = 0; i < a.size(); i++){
      for (int j = 0; j < b.size(); j++){
        max_n = max(max_n, dp[i][j]);
      }
    }

    cout << max_n << endl;
  }
}

Measured memory_bytes: 66756
def resolve():
    # 整数 1 つ
    N = int(input())
    # 整数複数個
    T, A = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    H = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    min_sub=100000
    min_ind=0
    for i in range(N):
        t = abs((T - H[i] * 0.006) - A)
        if t < min_sub:
            min_sub = t
            min_ind = i+1

    print(min_ind)



resolve()

Measured memory_bytes: 38384
def func(n):
	return n*(n+1)//2

def parent_search(a):
	if parent[a] == a:
		return a
	parent[a] = parent_search(parent[a])
	return parent[a]

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]

ans = [n*(n-1)//2]
parent = [i for i in range(n)]
size = [1]*n
rank = [0]*n
connection = 0

for a,b in ab[:0:-1]:
	# print(a,b)
	a,b = a-1,b-1
	p_a = parent_search(a)
	p_b = parent_search(b)
	if p_a != p_b:
		connection -= (func(size[p_a]) + func(size[p_b]))
		connection += func(size[p_a] + size[p_b])
		if rank[p_a] < rank[p_b]:
			size[p_b] += size[p_a]
			parent[p_a] = p_b
		else:
			size[p_a] += size[p_b]
			parent[p_b] = p_a
			if rank[p_a] == rank[p_b]:
				rank[p_a] += 1
	ans.append(ans[0]-connection)

for a in ans[::-1]:
	print(a)

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

int main()
{
  ll x;
  cin >> x;
  ll y;
  cin >> y;
  ll z;
  cin >> z;
  swap(x, y);
  swap(x, z);
  printf("%lld %lld %lld\n", x, y, z);

  return 0;
}


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

namespace IO
{
char gc()
{
#ifdef FREAD
	static char buf[1<<21], *P1 = buf, *P2 = buf;
	if(P1 == P2)
	{
		P1 = buf;
		P2 = buf + fread(buf, 1, 1<<21, stdin);
		if(P1 == P2) return EOF;
	}
	return *(P1++);
#else
	return getchar();
#endif
}
template<typename Tp> bool get1(Tp &x)
{
	bool neg = 0;
	char c = gc();
	while( c != EOF && (c < '0' || c > '9') && c != '-' ) c = gc();
	if(c == '-') c = gc(), neg = 1;
	if(c == EOF) return false;
	x = 0;
	for(; c>='0' && c<='9'; c = gc()) x = x*10 + c - '0';
	if(neg) x = -x;
	return true;
}
template<typename Tp> void printendl(Tp x)
{
	if(x<0)putchar('-'),x=-x;
	static short a[40], sz;
	sz = 0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
	puts("");
}
} // namespace IO
using IO::get1;
using IO::printendl;
#define get2(x,y) get1(x) && get1(y)
#define get3(x,y,z) get2(x,y) && get1(z)
#define get4(x,y,z,w) get3(x,y,z) && get1(w)
#define pb push_back
#define mp std::make_pair
#define ff first
#define ss second
typedef long long LL;
typedef unsigned long long uLL;
typedef std::pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const LL Linf = 1ll<<61;

const int maxn = 211;
char s[maxn][maxn];
int n, m, dp[maxn][maxn];
int main()
{
	get2(n, m);
	for(int i=1; i<=n; i++) scanf("%s", s[i]+1);
	memset(dp, inf, sizeof(dp));
	dp[1][1] = (s[1][1] == '#');
	for(int i=1; i<=n; i++) for(int j=1; j<=m; j++)
	{
		if(i == 1 && j == 1) continue;
		if(i > 1) dp[i][j] = std::min(dp[i][j], dp[i-1][j] + (s[i-1][j] == '.' && s[i][j] == '#'));
		if(j > 1) dp[i][j] = std::min(dp[i][j], dp[i][j-1] + (s[i][j-1] == '.' && s[i][j] == '#'));
	}
	printendl(dp[n][m]);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include <cstdlib>
using namespace std;
int main()
{
 int n,temp,temp1;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++){
     cin>>a[i];
     }
     temp=abs(a[0]-a[1]);
     for(int j=0;j<n;j++){
         for(int k=0;k<n;k++){
         temp1=abs(a[j]-a[k]);
         if(temp<temp1)
         temp=temp1;
        }
     }
    cout<<temp<<endl;
return 0;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e16;
const int N = 3e3 + 5;

LL a[ N ];
LL dp[ N ][ N ];

LL solve(int l, int r) {
  if (l > r) return 0;
  if (dp[l][r] != -INF) return dp[l][r];
  LL ret = -INF;
  ret = max(ret, a[l] - solve(l + 1, r));
  ret = max(ret, a[r] - solve(l, r - 1));
  return dp[l][r] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = -INF;
    }
  }
  cout << solve(1, n) << endl;
  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(long long i=j;i<(n);++i)
#define bk(i,j,n)   for(long long i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define srt(x) sort(x.begin(),x.end());
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

ll dp[105][100005];

int main()
{
    run;
    ll n;
    cin>>n;
    ll w;
    cin>>w;
    ll wt[n],val[n];
    fr(i,0,n)
    {
        cin>>wt[i]>>val[i];
    }
    fr(i,1,n+1)
    {
        fr(j,1,w+1)
        {
            if(wt[i-1]>j)
            {
                dp[i][j]=dp[i-1][j];
            }else
            {
                dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-wt[i-1]]);

            }
        }
    }
    cout<<dp[n][w];





}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    Int n;
    vector<Int> d;
    cin >> n;
    for(Int i=0; i<n; i++){
        cin >> tmpi;
        d.push_back(tmpi);
    }

    sort(d.begin(), d.end());
    Int len = d.size();
    Int cl = d[len/2-1];
    Int cr = d[len/2];

    cout << cr-cl << endl;

    return 0;
}

Measured memory_bytes: 1400
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc121_a.cpp
 * time   : Fri May  1 16:11:55 2020
 * quest  : A - White Cells
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H - h) * (W - w) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;

int main(){
    int A, B;
    std::cin >> A >> B;
    if(A >= 13){
        std::cout << B << "\n";
    }else if(A >= 6){
        std::cout << B/2 << "\n";
    }else{
        std::cout << 0 << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];} 
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";} cout<<endl;
#define S second
#define F first
#define SZ(x) (int)x.size()
typedef long long ll;
const int  MOD = 1e9 + 7;
const int  N = 1e6 + 7;

void solve(){
    int h , w , n;
    cin>>h>>w>>n;
    if(w > h) swap(w , h);

    cout<<(n + h - 1) / h <<endl;
}

int main(){
    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
    int t = 1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

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

long long int A, B, C;

int main(){
    cin >> A >> B >> C;
    if((A % 2) * (B % 2) * (C % 2) == 0){
        cout << 0 << endl;
    }else{
        if(A >= B && A >= C){
            cout << B * C << endl;
        }else if(B >= A && B >= C){
            cout << A * C << endl;
        }else{
            cout << A * B << endl;
        }
    }
    return 0;
}


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

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = long.Parse(_[0]);
            var m = long.Parse(_[1]);

            var d = new Dictionary<long,long>();
            for(var i = 0; i < n; i++){
                var __ = Console.ReadLine().Split();
                var a = long.Parse(__[0]);
                var b = long.Parse(__[1]);
                if(d.ContainsKey(a)){
                    d[a] += b;
                }else{
                    d.Add(a, b);
                }
            }

            BigInteger p = 0;
            foreach(var item in d.OrderBy(x => x.Key)){
                if(m <= 0){
                    break;
                }

                if(m - item.Value >= 0){
                    p += (item.Key * item.Value);
                    m -= item.Value;
                }else{
                    p += (item.Key * m);
                    m = 0;
                }
            }

            Console.WriteLine(p);
        }
    }
}


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


int main(){
	string s;
	int k,u,p,c;
	k=u=p=c=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='K')k++;
		else if(s[i]=='U')u++;
		else if(s[i]=='P')p++;
		else if(s[i]=='C')c++;
	}
	cout<<min(min(k,u),min(p,c))<<endl;
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
char mp[1010][1010];
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int n,m;
int ha(int x,int y){
	return x*m+y;
}
int judge(int x,int y){
	if(x>=0 && x<n && y>=0 && y<m && mp[x][y]=='.'){
		return 1;
	}
	return 0;
}
queue<int> q,qq;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%s",mp[i]);
		for(int j=0;j<m;j++){
			if(mp[i][j]=='#'){
				q.push(ha(i,j));
				qq.push(1);
			}
		}
	}
	int ans=0;
	while(!q.empty()){
		int tmp=q.front();
		q.pop();
		int x=tmp/m,y=tmp%m;
		int th=qq.front();
		qq.pop();
		ans=th;
		for(int i=0;i<4;i++){
			int tx=x+dx[i],ty=y+dy[i];
			if(judge(tx,ty)){
				mp[tx][ty]='#';
				q.push(ha(tx,ty));
				qq.push(th+1);
			}
		}
	}
	printf("%d\n",ans-1);
	return 0;
}


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

const int N = 100000 + 10;
const int Mod = 1e9 + 7;
const int D = 3;

struct Vector {
	int a[D];
	int &operator[]( int i ) { return a[i]; }
	const int &operator[]( int i ) const { return a[i]; }
};
struct Matrix {
	int a[D][D];
	void zero(){
		memset( a, 0, sizeof(a) );
	}
	void unit(){
		memset( a, 0, sizeof(a) );
		for( int i = 0; i < D; i++ ) a[i][i] = 1;
	}
	int * operator[]( int i ) { return a[i]; }
	const int * operator[]( int i ) const { return a[i]; }
};
Matrix operator*( const Matrix &r, const Matrix &s ) {
	Matrix rt;
	for( int i = 0; i < D; i++ )
		for( int j = 0; j < D; j++ ) {
			rt[i][j] = 0;
			for( int k = 0; k < D; k++ )
				rt[i][j] = int((rt[i][j] + 1LL * r[i][k] * s[k][j]) % Mod);
		}
	return rt;
}
Vector operator*( const Matrix &r, const Vector &s ) {
	Vector rt;
	for( int i = 0; i < D; i++ ) {
		rt[i] = 0;
		for( int k = 0; k < D; k++ )
			rt[i] = int((rt[i] + 1LL * r[i][k] * s[k]) % Mod);
	}
	return rt;
}

int n, m;
int sep[N];
long long f[N];

Matrix mpow( Matrix a, int b ) {
	Matrix rt;
	for( rt.unit(); b; b>>=1,a=a*a )
		if( b & 1 ) rt = rt * a;
	return rt;
}

int main() {
	Matrix T1, T2;
	T1.zero(), T2.zero();
	T1[0][0] = T1[0][1] = T1[2][1] = 2;
	T1[0][2] = T1[1][0] = T1[1][1] = T1[2][0] = T1[2][2] = 1;
	T2[0][0] = T2[1][0] = T2[1][1] = T2[2][0] = T2[2][2] = 1;
	T2[2][1] = 2;
	Vector cur;
	cur[0] = 1;
	cur[1] = cur[2] = 0;

	scanf( "%d%d", &n, &m );
	for( int i = 1; i <= m; i++ )  {
		scanf( "%d", sep + i );
	}
	int last = 0;
	for( int i = 1; i <= m; i++ ) {
		cur = mpow(T1,sep[i] - last - 1) * cur;
		cur = T2 * cur;
		last = sep[i];
	}
	cur = mpow(T1,n - last - 1) * cur;
	int ans = int((0LL + cur[0] + cur[1] * 2 + cur[2]) % Mod);
	printf( "%d\n", ans );
}





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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

vector<int> divi(int x){
    vector<int> ans;
    for(int i = 1; i <= sqrt(x); ++i){
        if(x % i == 0){
            ans.push_back(i);
            if(i != x / i) ans.push_back(x / i);
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int sum = accumulate(begin(a), end(a), 0);
    auto divisors = divi(sum);
    int ans = 0;
    for(auto && d : divisors){
        vector<int> b(n);
        for(int i = 0; i < n; ++i){
            b[i] = a[i] % d;
        }
        sort(begin(b), end(b), greater<int>());
        int sum = accumulate(begin(b), end(b), 0);
        int m = sum / d;
        if(d * m - accumulate(b.begin(), b.begin() + m, 0) <= k) ans = max(ans, d);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> st(n+1,0);
  st[0] = 1;
  for(int j = 3;j<=n;j++)
  {
  for(int i = j-3;i>=0;i--)
  {
    st[j] += st[i];
    st[j] = st[j] % 1000000007;
  }
  }
  cout<<st[n];
  return 0;
}

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

int main(){
    string s1,s2;
    cin >>s1 >>s2;
    int num=0;
    rep(i,s1.size()){
        if(s1.at(i)!=s2.at(i))
            num++;
    }
    
    cout <<num<<endl;
}



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

int main(){
 long long int h, w;
  cin>>h>>w;
  if(h == 1 || w == 1){
    cout<< 1 << endl;
  }
  else{
    cout<< (h*w)/2 + (h*w)%2 << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using ll = long long;
using namespace std;
int main(){
ll n;
cin>>n;
vector<ll> a(n);
for(ll i=0;i<n;i++) cin>>a[i];
ll ans=0,tmp=0;
while(1){
for(ll i=0;i<n;i++){
if(!(a[i]%2==0)){
  tmp=1;
  break;
}
a[i]/=2;
}
if(tmp==1)
break;
else
ans++;
}


cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 100000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* class */
class Edge {
public:
    int t, w;
    Edge() {}
    Edge(int t, int w): t(t), w(w) {}
};

/* global variables */
vector<int> d(MAX);
vector<Edge> G[MAX];
int n;

/* function */
void bfs(int s);
void solve();

/* main */
int main() {
    int s, t, w;
    cin >> n;
    for (int i = 0; i < n-1; i++) {
        cin >> s >> t >> w;
        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));
    }
    solve();
}

void bfs(int s) {
    for (int i = 0; i < n; i++) d[i] = INF;
    queue<int> Q;
    Q.push(s);
    d[s] = 0;
    int u;
    while (!Q.empty()) {
        u = Q.front(); Q.pop();
        for (auto e : G[u]) {
            if (d[e.t] == INF) {
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }
    }
}

void solve() {
    // Decide most far node from node 0
    bfs(0);
    int maxv = 0;
    int target = 0;
    for (int i = 0; i < n; i++) {
        if ( d[i] == INF) continue;
        if ( maxv < d[i] ) {
            maxv = d[i];
            target = i;
        }
    }

    // Decide most far node from target
    bfs(target);
    maxv = 0;
    for (int i = 0; i < n; i++) {
        if ( d[i] == INF) continue;
        maxv = max(maxv, d[i]);
    }

    cout << maxv << '\n';

}


Measured memory_bytes: 9708
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;

int n, x, a[N];
bool v[N];

void f(int p, int q) {
	a[n + p] = x + q;
	v[x + q] = 1;
}

int main()
{
	int i, j;
	cin >> n >> x;
	if (x == 1 || x == n * 2 - 1) {cout << "No"; return 0;}
	cout << "Yes\n";
	if (x != 2) f(-1, -1), f(0, 0), f(1, 1), f(2, -2);
	else f(-1, 1), f(0, 0), f(1, -1), f(2, 2);
	for (i = j = 1; i < 2 * n; i++) {
		if (!a[i]) {
			for (; v[j]; j++);
			a[i] = j++;
		}
		printf("%d\n", a[i]);
	}
    return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long ll;

ll N, K;
int A[200000 + 100];
int nxtsame[200000 + 100];

void printans(int from) {
	vector<int> ans;
	map<int, int> is_appear;
	for (int i = from; i < N; i++) {
		if (!is_appear[A[i]]) {
			is_appear[A[i]] = i + 1;
			ans.push_back(A[i]);
		}
		else {
			while (ans.size()) {
				if (ans.back() == A[i]) {
					ans.pop_back();
					is_appear[A[i]] = 0;
					break;
				}
				is_appear[ans.back()] = 0;
				ans.pop_back();
			}
		}
	}
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		nxtsame[i] = -1;
	}

	map<int, int> is_appear, first_appear;
	for (int i = 0; i < N; i++) {
		if (is_appear[A[i]] == 0) {
			is_appear[A[i]] = i + 1;//+1の下駄をはかせる
			first_appear[A[i]] = i + 1;
		}
		else {
			nxtsame[is_appear[A[i]] - 1] = i;
			is_appear[A[i]] = i + 1;
		}
	}
	for (int i = 0; i < N; i++)
		if (nxtsame[i] == -1) nxtsame[i] = first_appear[A[i]] - 1;

	vector<int> rotation;
	vector<bool> used(N + 100, false);
	int nowidx = 0;
	ll cycle_size = 0;
	while (true) {
		if (used[nowidx]) {
			cycle_size++;
			break;
		}
		rotation.push_back(nowidx);
		if (nowidx >= nxtsame[nowidx])cycle_size++;
		used[nowidx] = true;
		nowidx = (nxtsame[nowidx] + 1) % N;
	}
	
	ll amari = K % cycle_size;
	int cnt_cycle = 0;
	for (int i = 1; i < rotation.size(); i++) {
		if (rotation[i] <= rotation[i - 1] + 1)cnt_cycle++;
		if (cnt_cycle >= amari) {
			//print ans
			printans(rotation[i - 1]);
			return 0;
		}
	}
	printans(rotation.back());
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  string s;
  cin >> s;
  int month = stoi(s.substr(5, 2));
  if (month > 4) {
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e5 + 10;
 
int n, m, q, v[ N ], d[ N ], c[ N ], clr[ N ];
vector< int > nd[ N ];
set< pair< int, int > > st;

void go( int nowv, int nowd, int nowc ) {
  pair< int, int > now = { nowv, nowd };
  if ( st.count( now ) > 0 )
    return;
  st.insert( now );
  if ( !clr[ nowv ] )
    clr[ nowv ] = nowc;

  now = { nowv, nowd - 1 };
  if ( st.count( now ) == 0 && nowd - 1 >= 0 ) {
    go( nowv, nowd - 1, nowc );
    st.insert( now );
  }
  for ( int i = 0 ; i < nd[ nowv ].size() ; ++i ) {
    now = { nd[ nowv ][ i ], nowd - 1 };
    if ( st.count( now ) > 0 || nowd - 1 < 0 ) 
      continue;
    go( nd[ nowv ][ i ], nowd - 1, nowc );
    st.insert( now );
  }
}
 
int main() {
  scanf( "%d %d", &n, &m );
  for ( int i = 0 ; i < m ; ++i ) {
    int foo, bar;
    scanf( "%d %d", &foo, &bar );
    nd[ foo ].push_back( bar );
    nd[ bar ].push_back( foo );
  }
  scanf( "%d", &q );
  for ( int i = 0 ; i < q ; ++i )
    scanf( "%d %d %d", v + i, d + i, c + i );
  
	for ( int i = q - 1 ; i >= 0 ; --i )  
    go( v[ i ], d[ i ], c[ i ] );
 
  for ( int i = 1 ; i <= n ; ++i )
    printf( "%d\n", clr[ i ] );
}


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

int main() {
  int n;
  cin >> n;
  long long ans(0);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= n; ++k) {
        ans += gcd(gcd(i, j), k);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3636
N = int(input())

"""考え方
先頭と末尾の組み合わせごとに何個あるかをカウント。
掛け合わせ数を積み上げ
"""

# 先頭と末尾のパターンごとの個数を計上
com = [10*[0] for _ in range(10)]
for n in range(1,N+1):
  _ = str(n)
  if _[0] == '0' or _[-1] == '0':
    continue
  com[int(_[0])][int(_[-1])] += 1


# 掛け合わせ数を足しあげる
ans = 0
for x in range(10):
  for y in range(10):
    ans += com[x][y] * com[y][x] 

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll MOD = 1000000007;

int main(){
  string s;
  cin >> s;
  int N = s.size();

  ll pow3[100005];
  pow3[0] = 1;
  for(int i = 1; i < 100005; i++){
    pow3[i] = pow3[i - 1] * 3 % MOD;
  }

  ll pre = 1;
  int cnt = 0;
  for(int i = N - 1; i >= 0; i--){
    if(s[i] == '1'){
      pre = pow3[cnt] + pre * 2;
      pre %= MOD;
      cnt++;
    }
    else{
      cnt++;
    }
  }

  cout << pre << endl;
  return 0;

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int N;
int get_sum(int num){
	int re = 0;
	while(num > 0){
		re += num % 10;
		num /= 10;
	}
	return re;
}
int main(){
	scanf("%d",&N);
	int sum_min = INT_MAX;
	for(int i = 1; i < N; i++) sum_min = min(sum_min, get_sum(i) + get_sum(N - i));
	printf("%d\n",sum_min);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 100000
std::vector < std::pair <int,int> > G[MAXN+1];
int main(){
    FILE*fi,*fout;
    int i,n,m,nod,a,b,ist,sz;
    //fi=fopen("B.in" ,"r");
    //fout=fopen("B.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d %d " ,&n,&m);
    for(i=1;i<=m;i++){
       fscanf(fi,"%d %d " ,&a,&b);
       G[a].push_back(std::make_pair(b,i));
       G[b].push_back(std::make_pair(a,i));
    }
    i=1;
    while(i<=n&&G[i].size()%2==0)
      i++;
    if(i<=n)
      fprintf(fout,"NO\n");
    else
      fprintf(fout,"YES\n");
    //fclose(fi);
    //fclose(fout);
    return 0;
}


Measured memory_bytes: 6144
def main():
    n = int(input())
    ls = list(map(int, input().split()))
    ans = 1
    if 0 in ls:
        print(0)
        return
    for l in ls:
        ans *= l
        if (ans > 1000000000000000000):
            print(-1)
            return
    print(ans)
    return
if __name__ == '__main__':
    main()
    

Measured memory_bytes: 21476
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;


fn main() {
  let n = read::<i64>();
  let mut dist: HashMap<i64, i64> = HashMap::new();
  let mut ans = 0;

  for _ in 0..n {
    let a = read::<i64>();
    let current = dist.entry(a).or_insert(0);
    *current += 1;
  }

  for (k, v) in dist.iter() {
    if k < v {
      ans += v - k;
    } else if v < k {
      ans += *v;
    }
  }

  println!("{}", ans)
}



Measured memory_bytes: 12540
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
#include<functional>
using namespace std;
string s;
long long a[15][15];
long long a1[15];
long long ans;
int main()
{
	cin>>s;
	a[0][0]=(long long)1;
	a[0][1]=(long long)1;
	for(int i=2;i<s.size();i++)
		a[0][i]=a[0][i-1]*2;
	for(int i=1;i<s.size();i++)
	{
		a[i][i]=a[i-1][i-1]+a[i-1][i];
		for(int j=i+1;j<s.size();j++)
			a[i][j]=a[i-1][j];
	}
	a1[s.size()-1]=(long long)1;
	for(int i=s.size()-2;i>=0;i--)
		a1[i]=a1[i+1]*10;
	for(int i=0;i<s.size();i++)
	{
		long long ans1=0;
		for(int j=0;j<s.size();j++)
			ans1+=a1[j]*a[i][j];
		ans1*=s[i]-'0';
		ans+=ans1;
	}
	cout<<ans;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N+1);
  vector<int> B(N);
  long cnt=0;
  for(int j=0;j<N+1;j++){
    cin >> A.at(j);
  }
  for(int h=0;h<N;h++){
    cin >> B.at(h);
  }
  
  for(int i=(N-1);i>=0;i--){
    if(A.at(i+1)>=B.at(i)){
      cnt += B.at(i);
    }else{
      B.at(i) -= A.at(i+1);
      cnt += A.at(i+1);
      if(A.at(i)>=B.at(i)){
        A.at(i) -= B.at(i);
        cnt += B.at(i);
      }else{
        cnt += A.at(i);
        A.at(i) =0;
      }
    }
  }
  
    cout << cnt << endl;

}

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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<
#define int long long 

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

char a[2000][2000];

int dp[2000][2000];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>a[i][j];
	dp[1][1] = 1;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(a[i][j]!='#'&&!(i==1&&j==1))
				dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
	cout<<dp[h][w];
	return 0;
}

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

int main() {
  int n;
  cin >> n ;
  VI p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  int miss=0;
  for(int i=0;i<n;i++){
    if(p.at(i)!=i+1){
      miss++;
    }
  }
  if(miss==2 ||miss==0) cout <<"YES"<<endl;
  else cout <<"NO" << endl;
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
 
		if(a>=b){
		for(int i=0; i<a; i++){
			System.out.print(b);
        }
        }else{
		for(int i=0; i<b; i++){
			System.out.print(a);
      }
      }
}
}

Measured memory_bytes: 20948
#include <stdio.h>

#define N 999999

int set[999999];
int an[30];

int main(void)
{
	int i, j, nam;
	int ans = 0;
	
	set[0] = 1;
	
	for (i = 2; i < N; i++){
		if (set[i - 1] == 0){
			for (j = 2; i * j <= N; j++){
				set[(i * j) - 1] = 1;
			}
		}
	}
	
	for (i = 0; i < 30 && scanf("%d", &nam) != EOF; i++){
		for (j = 0; j < nam; j++){
			if (set[j] == 0){
				ans += 1;
			}
		}
		an[i] = ans;
		ans = 0;
	}
	
	for (j = 0; j < i; j++){
		printf("%d\n", an[j]);
	}
	
	return (0);
}

Measured memory_bytes: 4500
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, M = sc.nextInt()
    case class Job(after: Int, money: Int)
    val _JOB = new Array[Job](N)
    (0 until N) foreach { i =>
      val a, b = sc.nextInt()
      _JOB(i) = Job(a, b)
    }

    val JOB: Map[Int, Array[Job]] = _JOB.groupBy(M - _.after)
    // 1日後にもらえる場合, 3日目以前のどこでもやれる.
    // つまり(M - Bi)日以前のどこでもやれる.

    // Aの値が小さければ小さいほど自由度が高い.
    // 各バイト毎に, x日目までにやらないとだめ, という期限がある.
    // 後ろの日からどのアルバイトをすればいいか決めていく.

    var priorityQueue = scala.collection.mutable.PriorityQueue[Job]()(Ordering.by(_.money))
    var day = M - 1
    var MAX = 0
    while (day >= 0) {
      if (JOB.contains(day)) {
        val jobs = JOB(day)
        priorityQueue.enqueue(jobs: _*)
      }
      if (priorityQueue.nonEmpty) {
        MAX += priorityQueue.dequeue().money
      }
      day -= 1

    }
    println(MAX)
  }

}

Measured memory_bytes: 146488
import collections

n = int(input())
value = input().split()

odd = [int(value[i]) for i in range(n) if i % 2]
even = [int(value[i]) for i in range(n) if not i % 2]

odd_c = collections.Counter(odd)
even_c = collections.Counter(even)
# 出現数の多い順にリストをつくる
# 要素は値と出現頻度のペア（tuple）
freq_odd = odd_c.most_common()
freq_even = even_c.most_common()

if len(set(value)) == 1:  # valuleがすべて同じ数の場合（例外処理）
  freq = n // 2
elif freq_odd[0][0] != freq_even[0][0]:
  freq = freq_odd[0][1] + freq_even[0][1]
else:
  if len(freq_odd) == 1:
    freq = freq_odd[0][1] + freq_even[1][1]
  elif len(freq_even) == 1:
    freq = freq_odd[1][1] + freq_even[0][1]
  else:
    # 最頻値が一致してしまう場合、その次に出現数の多い要素を決め直す
    choice_a = freq_odd[0][1] + freq_even[1][1]
    choice_b = freq_odd[1][1] + freq_even[0][1]
    # 出現数の多いほど、書き直す部分は少なくて済む
    freq = max(choice_a, choice_b)

print(n - freq)

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

int main() {
    char s[4];
    char tmp1,tmp2;
    int flg1=0,flg2=0;
    for(int i=0;i<4;i++) cin>>s[i];
    tmp1=s[0];
    for(int i=1;i<4;i++) {
        if (s[i] != tmp1){
            tmp2=s[i];
            break;
        }
    }
    for(int i=0;i<4;i++){
        if(s[i]==tmp1) flg1++;
        else if(s[i]==tmp2) flg2++;
    }
    if(flg1==2&&flg2==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 1e6+5;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m,x;
    cin>>n>>m>>x;
    int ans = 1e15;
    int cost[n];
    vector<int> alg[n];
    for(int i=0;i<n;i++) {
        cin>>cost[i];
        vector<int> temp;
        int c;
        for(int i=0;i<m;i++) {
            cin>>c;
            temp.pb(c);
        }
        alg[i]=temp;
    }
    for(int i=0;i<(1<<n);i++) {
        vector<int> currsk(m, 0);
        int currcost = 0;
        for(int j=0;j<n;j++) {
            if(i&(1<<j)) {
                for(int i=0;i<m;i++) {
                    currsk[i]+=alg[j][i];
                }
                currcost+=cost[j];
            }
        }
        bool  f = 1;
        for(int i=0;i<m;i++) {
            if(currsk[i]<x) {
                f=0;
                break;
            }
        }
        if(f) {
            ans = min(ans, currcost);
        }
    }   

    if(ans < 1e10) {
        cout<<ans;
    }
    else {
        cout<<-1;
    }

    return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
int ma[1010][1010];
int cost[1010],a[1010]; 
int n,m;
void init(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++)
			ma[i][j]=ma[j][i]=inf;
		ma[i][i]=0;
	}
	memset(a,0,sizeof(a));
}
int prim(int s){
	int i,j;
	int k=0;
	for(i=1;i<=n;i++)
		cost[i]=ma[s][i];
	int sum=0;
	int mini;
	for(i=1;i<n;i++){
		mini=inf;
		for(j=1;j<=n;j++)
			if(cost[j]<mini&&cost[j]!=0){
				s=j;
				mini=cost[j];
			}
			sum+=mini;
			cost[s]=0;
			a[k++]=mini;
			for(j=1;j<=n;j++)
				if(cost[j]>ma[s][j]&&ma[s][j]!=0)
					cost[j]=ma[s][j];
	}
	sort(a,a+k);
	return a[k/2];
}
int main(){
	int from,to,cost;
	while(scanf("%d%d",&n,&m)&&(n+m)!=0){
		init();
		for(int i=1;i<=m;i++){
			scanf("%d%d%d",&from,&to,&cost);
			ma[from][to]=ma[to][from]=cost;
		}
		printf("%d\n",prim(1));
	}
	return 0;
}

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

int main(){
  // 1 2 3 ... と並んでいるかチェックする
  // 並んでいない箇所が0or2であれば、yes
  
  int N;
  cin >> N;
  int cnt = 0;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    if(tmp == i+1){
      //
    } else { 
      cnt += 1;
    }
  }
  if(cnt == 0 || cnt == 2 ){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i]; 
    sort(v.begin(), v.end(), [](int a, int b) {
        return a > b;
    });
    double ans = 0.0;
    for (int i = 0; i < n-1; ++i) ans += v[i] / pow(2, (i+1));
    ans += v[n-1] / pow(2, n-1);

    cout << ans << endl;
    return 0;

}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var kn = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var k = kn[0];
        var n = kn[1];
        var seqA = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var d = long.MaxValue;
        for (int i = 0; i < seqA.Length; ++i)
        {
            var x = k - (seqA[i] - seqA[(i - 1 + seqA.Length) % seqA.Length] + k) % k;
            d = Math.Min(d, x);
        }
        for (int i = 0; i < seqA.Length; ++i)
        {
            var x = k - (seqA[(i + 1) % seqA.Length] - seqA[i] + k) % k;
            d = Math.Min(d, x);
        }
        
        Console.WriteLine(d);
    }
}


Measured memory_bytes: 34396
# coding:utf-8
class Dice:
    def __init__(self):
        self.f = [0 for i in range(6)]
    def roll_z(self): self.roll(1,2,4,3)
    def roll_y(self): self.roll(0,2,5,3)
    def roll_x(self): self.roll(0,1,5,4)
    def roll(self,i,j,k,l):
        t = self.f[i]; self.f[i] = self.f[j]; self.f[j] = self.f[k]; self.f[k] = self.f[l]; self.f[l] = t
    def move(self,ch):
        if ch == 'E':
            for i in range(3):
                self.roll_y()
        if ch == 'W':
            self.roll_y()
        if ch == 'N':
            self.roll_x()
        if ch == 'S':
            for i in range(3):
                self.roll_x()
dice = Dice()
dice.f = map(int, raw_input().split())
com = raw_input()
for i in range(len(com)):
    dice.move(com[i])
print dice.f[0]



Measured memory_bytes: 4692
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    const int MAX_LOG_K = 62;
    
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    rep(i, N) --A[i];
    
    vector<vector<int>> tel(N, vector<int>(MAX_LOG_K));
    rep(i, N) tel[i][0] = A[i];
    REP(i, MAX_LOG_K) rep(j, N) {
        tel[j][i] = tel[tel[j][i - 1]][i - 1];
    }
    
    int ans = 0;
    rep(i, MAX_LOG_K) {
        if (K & (1LL << i)) ans = tel[ans][i];
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 58700
#include <stdio.h>

int main(){
    int n;
    int a[100000];
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        scanf("%d",&a[i]);
        // a[i]*=2;
    }

    int x=0;
    for(int i=0;i<n;i++)
    {
        if(i%2) x-=a[i];
        else x+=a[i];
    }
    x/=2;

    int b[100000];
    b[0]=x;
    for(int i=1;i<n;i++){
        b[i]=a[i-1]-b[i-1];
    }
    for(int i=0;i<n;i++) b[i]*=2;
    printf("%d",b[0]);
    for(int i=1;i<n;i++){
        printf(" %d",b[i]);
    }
    printf("\n");
}

Measured memory_bytes: 2048
N = int(input())
teki = input().split()
yusya = input().split()
i = 0
taoshita = 0

while i < N :
  if int(teki[i]) >= int(yusya[i]):
    a = int(yusya[i]) 
    b = 0
  else:
    a = int(teki[i])
    yusya[i] = int(yusya[i]) - int(teki[i])
    if int(teki[i+1]) >= yusya[i]:
      b = yusya[i]
      teki[i+1] = int(teki[i+1]) - yusya[i]
    else:
      b = int(teki[i+1])
      teki[i+1] = 0
  taoshita += a + b
  i += 1
  
print(taoshita)

Measured memory_bytes: 22040
# coding: utf-8
# Your code here!
a = input()
n = int(len(a))
amari = int(n) % 2
flag = str()
if n == 1:
    if a == "L":
        print("No")
        flag = "unko"
    else:
        pass
elif amari == 0:
    for i in range (1, (int(n) // 2)+1):
        if a[int(i) * 2 - 2] == "L":
            print("No")
            flag = "unko"
            break
        elif a[int(i) * 2 - 1] == "R":
            print("No")
            flag = "unko"
            break
        else:
            pass

elif amari == 1:
    for i in range (1, (int(n) // 2)+1):
        if a[int(i) * 2 - 2] == "L":
            print("No")
            flag = "unko"
            break
        elif a[int(i) * 2 - 1] == "R":
            print("No")
            flag = "unko"
            break
        else:
            pass
    if a[int(n) - 1] == "L" and flag == "":
        print("No")
        flag = "unko"
else:
    pass

if flag == "":
    print("Yes")


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int a, b;

  while(cin >> a >> b){
    int ans = -1;
    FORE(i,1,1000){
      if(floor(0.08 * i) == a and floor(0.1 * i) == b){
        ans = i;
        break;
      }
    }

    puts_all(ans);
  }


  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	ll n,l;
	cin>>n>>l;
	vector<pair<ll,ll> > v;
	rep(i,0,n){
		v.pb(mp(abs(l+i),l+i));
	}
	sort(all(v));
	ll ans = 0;
	rep(i,1,v.sz){
		ans += v[i].se;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * B - Product Max
 * 整数 a,b,c,d が与えられます。
 * a≤x≤b,c≤y≤d を満たす整数 x,y について、x×y の最大値はいくつですか。
 */
public class Main {

    public static void main( String[] args ) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long[] vals = {a * c, a * d, b * c, b * d};
        long max = vals[0];
        for ( int i = 1; i < vals.length; i++ ) {
            max = Math.max( max, vals[i] );
        }

        System.out.println( max );

        sc.close();
    }
}

Measured memory_bytes: 35640