akhauriyash/Code-Regression huggingface dataset:
import sys
 
def main():
    def input():return sys.stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split(" ")))
 
    mod = 10**9+7
    res = 0

    S = sum(A)
    S2 = sum(map(lambda x: x**2, A))
    print((S**2-S2) // 2 % mod)
if __name__ == "__main__":
    main()

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

int dist(int a, int n){
	return min((a+n+n)%n,(n+n+n-a)%n);
}
int main(){
	string a, b;
	cin >> a >> b;
	int n = a.size();
	int ok = 0;
	int oka = 1;
	for(int i = 0; i < n; i++){
		if(b[i] == '1') ok = 1;
		if(a[i] != b[i]) oka = 0;
	}

	if(!ok){
		if(oka){
			cout << 0 << endl;
			return 0;
		}
		cout << -1 << endl;
		return 0;
	}
	map<int,int> vis;
	int nvis = 0;
	for(int i = 0; i < n; i++){
		vis[i] = 0;
		if(a[i] == '0'){
			vis[i] = 1000000;
			nvis++;
		}
	}
	int e = 0;
	int ans = 1000000;
	vector<int> oks, oke;
	for(int s = 0; s < n; s++){
		// using [s,e) ok
		while(nvis < n || e <= s){
			for(int i = 0; i < n; i++){
				nvis -= (vis[(i+e)%n] > 0);
				vis[(i+e)%n] += (b[i] == '1');
				nvis += (vis[(i+e)%n] > 0);
			}
			e++;
		}
		/*for(int e2 = e; e2 <= s + n + 2; e2++){
			oks.push_back(s);
			oke.push_back(e2-1);
		}*/
			oks.push_back(s);
			oke.push_back(e-1);			
		//cout << s << " " << e << " " << p << endl;
		for(int i = 0; i < n; i++){
			nvis -= (vis[(i+s)%n] > 0);
			vis[(i+s)%n] -= (b[i] == '1');
			nvis += (vis[(i+s)%n] > 0);
		}
	}
	int diff[n];
	for(int s = 0; s < n; s++){
		diff[s] = 0;
		for(int i = 0; i < n; i++){
			if(a[(i+s) % n] != b[i]) diff[s]++;
		}
	}

	for(int c = 0; c < oks.size(); c++){
		int zs = oks[c];
		int ze = oke[c];
		//cout << s << " " << ze << endl;
		for(int z2 = 0; z2 < n; z2++){
			int p = dist(ze%n,n) + (ze-zs) + dist(zs-z2,n) + diff[z2%n];
			int q = dist(zs%n,n) + (ze-zs) + dist(ze-z2,n) + diff[z2%n];
			ans = min(ans, min(p,q));
		}

	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 998244353;
#pragma GCC optimize("Ofast")
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define sz(x) ((int)(x).size())

ll l, r;

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

    cin >> l >> r;
    ll ans = inf;
    for(ll i = l; i <= min(l+2019, r); i++){
        for(ll j = i+1; j <= min(i+2019, r); j++){
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=Integer.parseInt(sc.next());
		int K=Integer.parseInt(sc.next());
		System.out.println((int)Math.ceil((double)(N-K)/(K-1))+1);
		sc.close();
	}
}
	


Measured memory_bytes: 23764
#include <iostream>

using namespace std;

const int N = 100;

char grid [N][N];

int main () {
  ios::sync_with_stdio(false);

  int a, b;
  cin >> a >> b;

  for (int i = 0; i < N / 2; i++) {
    for (int j = 0; j < N; j++) {
      grid[i][j] = '.';
    }
  }

  for (int i = N / 2; i < N; i++) {
    for (int j = 0; j < N; j++) {
      grid[i][j] = '#';
    }
  }

  a--;
  b--;
  
  for (int i = 0; i < N / 2 - 1; i += 2) {
    for (int j = 0; j < N; j += 2) {
      if (b > 0) {
        grid[i][j] = '#';
        b--;
      }
    }
  }

  for (int i = N / 2 + 1; i < N; i += 2) {
    for (int j = 0; j < N; j += 2) {
      if (a > 0) {
        grid[i][j] = '.';
        a--;
      }
    }
  }

  cout << N << " " << N << endl;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cout << grid[i][j];
    }
    cout << '\n';
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int k;
	cin >>k;
	int count =0;
	int count2 =0;
	for (int i =1; i <=k; i++) {
		if (i %2 ==0) count++;
		else count2++;
	}
	cout << count * count2 << endl;
	return 0;
}


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

int main() {
  int n,a,b;
  cin >> n >> a >> b;
 int c=min(a,b);
  int d;
  if(a+b>=n){
     d=a+b-n;
  }
  else {
    d=0;
  }
  cout << c << " " << d << endl;
}
  

Measured memory_bytes: 256
n = input()
k = int(input())
l = len(n)
dp = [[[0,0] for j in range(5)] for i in range(l+1)]
dp[0][0][1] = 1
for i in range(l):
  for j in range(k+1):
    dp[i+1][j+1][0] += 9 * dp[i][j][0]
    dp[i+1][j  ][0] += dp[i][j][0]
    if n[i] == '0':
      dp[i+1][j  ][1] = dp[i][j][1]
    else:
      dp[i+1][j  ][0] += dp[i][j][1]
      dp[i+1][j+1][0] += (int(n[i]) - 1)*dp[i][j][1]
      dp[i+1][j+1][1] += dp[i][j][1]
print(dp[l][k][1] + dp[l][k][0] )
  

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (s.length() % 2 == 0) {
			if (s.charAt(0) == s.charAt(s.length() - 1)) {
				System.out.println("First");
			} else {
				System.out.println("Second");
			}
		} else {
			if (s.charAt(0) == s.charAt(s.length() - 1)) {
				System.out.println("Second");
			} else {
				System.out.println("First");
			}
		}

	}
}


Measured memory_bytes: 13840
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    string s;
    cin >> s;
    rep(i,4){
        cout << s[i];
    }
    cout << " ";
    rep(i,8){
        cout << s[i+4];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
  //解説を見てまねした
	int N;
	//vector<int> x<N>, y<N> h<N>;
	cin >> N;
	vector<int> x(N), y(N),h(N);
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	int MAX = 100;
	for (int posY=0; posY <= MAX; posY++) {
		for (int posX = 0; posX <= MAX; posX++) {
			int needH = -1;

			for (int i = 0; i < N; i++) {
				if (h[i] > 0) {
					int tmp = h[i] + abs(posY - y[i]) + abs(posX - x[i]);
					if (needH == -1) {
						needH =tmp;
					}
					else {
						if (needH != tmp) {
							needH = -2;
							break;
						}
					}
				}
			}
			if (needH == -2) {
				continue;
			}
			for (int i = 0; i < N; i++) {
				if (h[i] == 0) {
					int dist = abs(posY - y[i]) + abs(posX - x[i]);
					if (needH > dist) {
						needH = -2;
						break;
					}
				}
			}
			if (needH == -2) {
				continue;
			}
			cout << posX << " " << posY << " " << needH << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
const main = (input) => {
  const [s, t] = input.trim().split('\n')
  let ans = Infinity

  for (let x=0; x <= s.length-t.length; x++) {
    let count = 0
    for (let tx=x, y=0; y<t.length; tx++, y++) if (s[tx] !== t[y]) count++
    ans = Math.min(ans, count)
  }

  return console.log(ans)
}
process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 32584
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  for(int i = 1;i <= N;i++){
    if(i%2 == 1)cnt++;
  }
  double wariai = 0.0;
  wariai = 1.0*cnt/N;
  cout << wariai <<endl;
}


Measured memory_bytes: 256
S = str(input())
N = len(S)

def dfs(i, f):
    if i == N - 1:
        return sum(list(map(int, f.split("+"))))

    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    return dfs(i + 1, f + S[i + 1]) + \
           dfs(i + 1, f + "+" + S[i + 1])


print(dfs(0, S[0]))


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

int main(){

  
  while(1){
    
    
    string s, t; cin >> s;
    if(s == ".") break;
    cin >> t;
    string s_other, t_other;
    vector<string> s_string;
    vector<string> t_string;

    int idx = 0;
    int s_len = (int)s.size();
    int t_len = (int)t.size();

    
    int s_idx = 0;
    int t_idx = 0;
    

    while(idx < s_len){
      
      if(s[idx] != '"') s_other = s_other + s[idx];
      else{
	
	s_other = s_other + '/';
	string tmp;
	idx++;
	while(s[idx] != '"'){
	  tmp = tmp + s[idx];
	  idx++;
	}
	
	s_string.push_back(tmp);
      }

      idx++;
    }
    
    idx = 0;
    
    while(idx < t_len){

      

      if(t[idx] != '"') t_other = t_other + t[idx];
      else{

	t_other = t_other + '/';
	string tmp;
	idx++;
	while(t[idx] != '"'){
	  tmp = tmp + t[idx];
	  idx++;
	}
	
	t_string.push_back(tmp);
      }
      
      idx++;
    }
    
    if(s_other != t_other) cout << "DIFFERENT" << endl;
    else if(s_string.size() != t_string.size()) cout << "DIFFERENT" << endl;
    else{

      int diff = 0;
      for(int i = 0; i < (int)s_string.size(); i++){
	if(s_string[i] != t_string[i]) diff++;
      }

      if(diff >= 2) cout << "DIFFERENT" << endl;
      else if(diff == 1) cout << "CLOSE" << endl;
      else cout << "IDENTICAL" << endl;
    }

  }
    
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define R(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

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

    int64 n;
    cin >> n;
    switch (n) {
        case 0: cout << 1 << endl; return 0;
        case 1: cout << 2 << endl; return 0;
        case 2: cout << 1 << endl; return 0;
        default: cout << 0 << endl; return 0;
    }
}



Measured memory_bytes: 3164
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  int32_t hour = (24 + H2 - H1) % 24;
  int32_t minute = M2 - M1;
  int32_t total = 60 * hour + minute;
  cout << (total - K) << endl;
  return 0;
}


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

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

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pii> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a.begin(), a.end());
	set<int> occur;
	ll answer = 0;
	for(const auto& p : a){
		const ll c = p.second;
		auto it = occur.lower_bound(p.second);
		ll l = 0, r = (it == occur.end() ? n : *it);
		if(it != occur.begin()){ l = *(--it) + 1; }
		answer += (c - l + 1) * (r - c) * p.first;
		occur.insert(p.second);
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 11264
s_list = list(input())

# 左半分と右半分で違う文字の個数 = 変更必要な文字数
count = 0
harf = int(len(s_list) // 2)
for i in range(harf):
  if s_list[i] != s_list[len(s_list)-i-1]:
    count += 1
print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}
 
ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}


void solve(long long A, long long B){
    if(A <= 8 && B <= 8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    d=int(readline())
    c=list(map(int, readline().rstrip().split()))
    s=[0]*d
    for i in range(d):
        s[i]=list(map(int, readline().rstrip().split()))

    last=[-1]*26
    for i in range(d):
        maxx=-999999999999
        memo=0
        for j in range(26):
            ccc=(i-last[j])*c[j]
            if (s[i][j]+ccc) > maxx:
                maxx=(s[i][j]-ccc)
                memo=j
        print(memo+1)
        last[memo]=i
    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------


Measured memory_bytes: 16360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=23;
const ll INF=1LL<<60;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M;cin>>N>>M;
        if(N+M==0) break;
        vector<int> maxi(N),mini(N);
        
        for(int i=0;i<M;i++){
            int S;cin>>S;
            int k;cin>>k;
            for(int j=0;j<k;j++){
                int a;cin>>a;
                a--;
                maxi[a]+=S;
                if(k==1) mini[a]+=S;
            }
        }
        
        int ans=0;
        
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(i==j) continue;
                
                ans=max(ans,maxi[i]-mini[j]+1);
            }
        }
        
        cout<<ans<<endl;
        
    }
    
    
}




Measured memory_bytes: 3264
#include<bits/stdc++.h>
#define int long long
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int32_t main()
{
    FastIO;
    int n;
    cin>>n;
    string s;
    set<string>str;
    int a;
    map<pair<string,int>,int>m;
    map<string,vector<int>>v;
    vector<int>vect;
    for(int i=1;i<=n;++i)
    {
        cin>>s>>a;
        m[make_pair(s,a)]=i;
        str.insert(s);
        v[s].push_back(a);
    }
    //sort(str.begin(),str.end());
    int c=-1;
    for(auto st:str)
    {
        c=INT_MAX;
        vect=v[st];
        sort(vect.begin(),vect.end(),greater<int>());
        for(int j=0;j<vect.size();++j)
        {
            cout<<m[make_pair(st,vect[j])]<<endl;
            //cout<<str[i]<<" "<<vect[j]<<" ";
        }
        vect.clear();
        //cout<<endl;
    }
    

}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int n;cin>>n;
    int cnt[11][11]={};
    for(int i=1;i<=n;i++){
        string s=to_string(i);
        int siz=s.size();
        cnt[s[0]-'0'][s[siz-1]-'0']++;
    }
    ll ans=0;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            ans+=cnt[i][j]*cnt[j][i];
        }
    }

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


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=1e2+10;
const int Wmax=1e5+10;
int n,W,w[N],v[N];
ll dp[Wmax];
int main(){
	scanf("%d%d",&n,&W);
	for(register int i=1;i<=n;i++)
		scanf("%d%d",&w[i],&v[i]);
	for(register int i=1;i<=n;i++)
		for(register int j=W;j>=w[i];j--)
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
	printf("%lld\n",dp[W]);
	return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <algorithm>
#include <limits.h>
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
const int maxV=1e5;
using namespace std;
const int N=1e9+1;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; long long int W; cin>>n>>W;
    int w[n]; int v[n];
    for(int i=0;i<n;i++) {cin>>w[i]>>v[i];}

    long long int f[n+1][maxV+1];

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=maxV;j++)
        {
            f[i][j]=0;
        }
    }

    for(int i=0;i<=n;i++) f[i][0]=0;

    for(int i=1;i<=maxV;i++) f[0][i]=N;


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

                    f[i][vk] = f[i - 1][vk];
                    if(vk-v[i-1]>=0) {
                        f[i][vk] = min(f[i][vk], f[i - 1][vk - v[i - 1]] + w[i - 1]);
                    }
                }
            }


            // min weight max value

    for(int vk=maxV;vk>=0;vk--)
    {
        if(f[n][vk]<=W){cout<<vk<<"\n"; break;}
    }


    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n;

    k = 0;

    for(int i=0;i<n;i++){
        cin>>A[i];
        k = max(k,A[i]);
    }

    for(int i=0;i<n;i++){
        cur = min(A[i],k-A[i]);
        if(cur>mx){
            mx = cur;
            idx = i;
        }
    }

    if(!mx)cout<<k<<" "<<0<<"\n";
    else cout<<k<<" "<<A[idx]<<"\n";

    return 0;
}


Measured memory_bytes: 640
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
using namespace std;

typedef long long lint;

const int M = 300000000;

int main(){
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> visit(r);
    for(int i = 0 ; i < r ; i++){
        cin >> visit[i];
        visit[i]--;
    }
    sort(visit.begin(), visit.end());
    vector< vector<int> > dis(n);
    for(int i = 0 ; i < n ; i++){
        dis[i].resize(n, M);
        dis[i][i] = 0;
    }
    for(int i = 0 ; i < m ; i++){
        int a, b, c;
        cin >> a >> b >> c;
        dis[a-1][b-1] = c;
        dis[b-1][a-1] = c;
    }
    for(int i = 0 ; i < r ; i++){
        vector<bool> done(n, false);
        done[visit[i]] = true;
        int tmp = visit[i];
        bool flag = true;
        while(flag){
            for(int j = 0 ; j < n ; j++){
                if(!done[j]){
                    dis[visit[i]][j] = min(dis[visit[i]][j], dis[visit[i]][tmp] + dis[tmp][j]);
                }
            }
            int t = M;
            flag = false;
            for(int j = 0 ; j < n ; j++){
                if(!done[j]){
                    flag = true;
                    if(t > dis[visit[i]][j]){
                        t = dis[visit[i]][j];
                        tmp = j;
                    }
                }
            }
            done[tmp] = true;
        }
    }
    int ans = M;
    do{
        int cnt = 0;
        for(int i = 0 ; i < r - 1 ; i++){
            cnt += dis[visit[i]][visit[i+1]];
        }
        ans = min(ans, cnt);
    }while(next_permutation(visit.begin(), visit.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
ans=1
for i in range(N):
    if A[i] == 0:
        ans = 0
for i in range(N):
    ans = ans * A[i]
    if ans>1000000000000000000:
        ans = -1
        break
print(ans)

Measured memory_bytes: 84524
#include <iostream>
    using namespace std;
     
    int N, M, Q, p[509][509];
    int main() {
        ios::sync_with_stdio(0);
    	cin >> N >> M >> Q;
    	for (int i = 1; i <= M; i++) { int L, R; cin >> L >> R; p[L][R]++; }
    	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) p[i][j] += p[i][j - 1]; }
    	for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) p[i][j] += p[i - 1][j]; }
     
    	for (int i = 1; i <= Q; i++) {
    		int L, R; cin >> L >> R;
    		cout << p[R][R] + p[L - 1][L - 1] - p[L - 1][R] - p[R][L - 1] << endl;
    	}
    	return 0;
    }

Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	ll n, k, ans=0;
	cin >> n >> k;
	if(k%2==0){
		ans+=((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k);
	}
	ans+=(n/k)*(n/k)*(n/k);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
const int MAXN = 1000100;

int dp[MAXN];

int main()
{
    dp[0] = 0;
    for (int i = 1; i < MAXN; i++)
    {
        dp[i] = dp[i-1] + 1;
        for (int x = 6; x <= i; x *= 6)
            dp[i] = min (dp[i], dp[i-x] + 1);
        for (int x = 9; x <= i; x *= 9)
            dp[i] = min (dp[i], dp[i-x] + 1);
    }

    int N; cin >> N;
    cout << dp[N] << "\n";
}

Measured memory_bytes: 4096
N,M,Q = map(int,input().split())
abcd_array = []
for i in range(Q):
    abcd = list(map(int,input().split()))
    abcd_array.append(abcd)
max_point = 0
for a in range(1,M+1):
    for b in range(a,M+1):
        for c in range(b,M+1):
            for d in range(c,M+1):
                for e in range(d,M+1):
                    for f in range(e,M+1):
                        for g in range(f,M+1):
                            for h in range(g,M+1):
                                for i in range(h,M+1):
                                    As = [1,a,b,c,d,e,f,g,h,i]
                                    point = 0
                                    for j in range(Q):
                                        if As[abcd_array[j][1]-1] - As[abcd_array[j][0]-1] == abcd_array[j][2]:
                                            point += abcd_array[j][3]
                                        if j == Q-1 and max_point < point:
                                            max_point = point
print(max_point)


Measured memory_bytes: 76444
#include <cstdio>

using namespace std;
int n,i,z;
long long x,y,Min,s[200004];
int main()
{
    scanf ("%d", &n);
    s[0]=0LL;
    for (i=1;i<=n;i++)
    {
        scanf ("%d", &z);
        s[i]=(0LL)+s[i-1]+z;
    }
    Min=(1LL)*20000000000000001;
    for (i=1;i<=(n-1);i++)
    {
        x=(0LL)+s[i];
        y=(0LL)+s[n]-s[i];
        if ((x<y) && (((0LL)+y-x)<Min))
            Min=(0LL)+y-x;
        else if ((x>=y) && (((0LL)+x-y)<Min))
            Min=(0LL)+x-y;
    }
    printf ("%lld\n", Min);
    return 0;
}


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

int main() {
  string s;
  int k;
  cin >> s >> k;
  ll ans = 0;
  if(s == string(s.size(), s[0])){
    cout << s.size() * k / 2 << endl;
    return 0;
  }
  ll cnt1 = 0;
  ll cnt2 = 0;
  string tmp = s + s;
  rep(i, s.size()-1){
    if(s[i] == s[i+1]) s[i+ 1] = '&',cnt1++;
  }
  rep(i, tmp.size() -1){
    if(tmp[i] == tmp[i+1]) tmp[i+1] = '&',cnt2++;
  }
  cout << cnt1 + (cnt2 - cnt1) * (k - 1) << endl;
}

Measured memory_bytes: 3568
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        a: [i64; n+1],
    }
    if n == 0 {
        if a[0] == 0 {
            println!("0",);
        } else if a[0] == 1 {
            println!("1");
        } else {
            println!("-1");
        }
        return;
    }
    if a[0] != 0 {
        println!("-1");
        return;
    }
    let mut back = vec![0; n + 2];
    for i in (0..n).rev() {
        back[i] = back[i + 1] + a[i + 1];
    }
    let mut res = 0;
    let mut node = 1;
    for i in 0..n + 1 {
        // println!("{} {}", i, node);

        res += node;
        node -= a[i];
        if node < 0 {
            println!("-1");
            return;
        }
        if node * 2 <= back[i] {
            node *= 2;
        } else if node <= back[i] {
            node = back[i];
        } else {
            println!("-1");
            return;
        }
    }
    // println!("{:?}", back);
    println!("{}", res);
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

lli up(lli a,lli b){
	if(a%b)return a/b + 1;
	else return a/b;
}

bool range(lli a,lli b,lli c){
	return a<=c && c<=b;
}

signed main(){

	lli k;
	cin>>k;
	vector<lli> a;
	a.push_back(1);
	REP(i,0,k){
		lli tmp;
		cin>>tmp;
		a.push_back(tmp);
	}

	lli jmin=2,jmax=2;

	for(lli i=k;i>0;i--){
		lli now = a[i];
		lli nextmax = (jmax/now+1)*now - 1;
		lli nextmin = up(jmin,now)*now;
		if(DEBUG)cout<<"nextmin="<<nextmin<<" nextmax="<<nextmax<<endl;

		/*nextMax,nextMinの間のlli next=a[i-1]の倍数があるかどうか*/
		lli next = a[i-1];
		lli sugestNextMax = nextmax/next*next;
		lli sugestNextMin = up(nextmin,next)*next;
		if(DEBUG)cout<<"suggestNextMin="<<sugestNextMin<<" sugestNextMax="<<sugestNextMax<<endl;
		if(range(nextmin,nextmax,sugestNextMin) == false){
			sugestNextMin = -1;
		}
		if(range(nextmin,nextmax,sugestNextMax) == false){
			sugestNextMax = -1;
		}
		if(sugestNextMax == -1 && sugestNextMin == -1){
			cout<<-1<<endl;
			return 0;
		}
		if(sugestNextMin == -1){
			sugestNextMin = sugestNextMax;
		}
		if(sugestNextMax == -1){
			sugestNextMax = sugestNextMin;
		}
		jmin = sugestNextMin;
		jmax = sugestNextMax;
	}
	cout<<jmin<<" "<<jmax<<endl;

	return 0;
}

Measured memory_bytes: 1400
import std.stdio, std.string, std.array, std.conv;

struct Dice6 {
    int[string] dice6;
    int[] _dice6 = new int[6];

    this(int[] _dice6) {
        dice6["top"] = _dice6[0];
        dice6["front"] = _dice6[1];
        dice6["right"] = _dice6[2];
        dice6["left"] = _dice6[3];
        dice6["back"] = _dice6[4];
        dice6["bottom"] = _dice6[5];
    }

    void roll(char c) {
        int tmp = dice6["top"];
        if (c == 'E') {
            dice6["top"] = dice6["left"];
            dice6["left"] = dice6["bottom"];
            dice6["bottom"] = dice6["right"];
            dice6["right"] = tmp;
        } else if (c == 'N') {
            dice6["top"] = dice6["front"];
            dice6["front"] = dice6["bottom"];
            dice6["bottom"] = dice6["back"];
            dice6["back"] = tmp;
        } else if (c == 'S') {
            dice6["top"] = dice6["back"];
            dice6["back"] = dice6["bottom"];
            dice6["bottom"] = dice6["front"];
            dice6["front"] = tmp;
        } else {
            dice6["top"] = dice6["right"];
            dice6["right"] = dice6["bottom"];
            dice6["bottom"] = dice6["left"];
            dice6["left"] = tmp;
        }
    }

    void clockwise() {
        int tmp = dice6["front"];
        dice6["front"] = dice6["right"];
        dice6["right"] = dice6["back"];
        dice6["back"] = dice6["left"];
        dice6["left"] = tmp;
    }

    int surface(string dir) {
        int result;
        if (dir == "top") {
            result = dice6["top"];
        } else if (dir == "front") {
            result = dice6["front"];
        } else if (dir == "right") {
            result = dice6["right"];
        } else if (dir == "left") {
            result = dice6["left"];
        } else if (dir == "back") {
            result = dice6["back"];
        } else {
            result = dice6["bottom"];
        }
        return result;
    }

    int right(int[] x) {
        if (x[0] == dice6["front"]) roll('N');
        if (x[0] == dice6["back"]) roll('S');
        while (x[0] != dice6["top"]) roll('E');
        while (x[1] != dice6["front"]) clockwise;
        return dice6["right"];
    }
}

void main() {
    int[] _dice = readln.chomp.split.to!(int[]);
    int q = readln.chomp.to!int;
    foreach (i; 0 .. q) {
        Dice6 dice = Dice6(_dice);
        int[] tmp = readln.chomp.split.to!(int[]);
        dice.right(tmp).writeln;
    }
}


Measured memory_bytes: 2468
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);  
    int n = sc.nextInt();
    int m = sc.nextInt();
    int x[] = new int[n+1];
    int y[] = new int[m+1];
    x[0] = sc.nextInt();
    y[0] = sc.nextInt();
 
    for(int i=1;i<=n;i++){
      x[i] = sc.nextInt();
    }
    for(int i=1;i<=m;i++){
      y[i] = sc.nextInt();
    }
    Arrays.sort(x);
    Arrays.sort(y);
    if(x[x.length-1]<y[0])
      System.out.println("No War");
    else
      System.out.println("War");
  }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;

int main() {
  int x, y;
  scanf("%d", &x);
  scanf("%d", &y);

  bool isPossible = true;
  if (y < 2 * x) isPossible = false;
  if (4 * x < y) isPossible = false;
  if (y % 2 != 0) isPossible = false;

  if (isPossible) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	vector<int> a(3);
	for(int i=0;i<3;i++)cin>>a[i];
	sort(a.begin(),a.end());
	cout<<a[0]+a[1]<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  string S;
  cin >> S;
  int len = S.size();
  reverse(S.begin(), S.end());
  ll dp[len+10][13];
  ll MOD = 1e9+7;
  // dp[i][r]: 下i桁まで見た時のあまりrになる場合の数
  // if(S[i] == '?') dp[i][r] = dp[i-1][
  for(int i=0; i<len+10; i++){
    for(int j=0; j<13; j++){
      dp[i][j] = 0;
    }
  }
  
  int dig = 1; // 桁数（基数）
  dp[0][0] = 1;
  for(int i=0; i<len; i++){
    dig %= 13;
    if(S[i] == '?'){
      for(int j=0; j<10; j++){      
        for(int r=0; r<13; r++){
//          if(dp[i][r] == 0) continue;          
//          cout << (j*dig%13 + r)%13 << endl;
          dp[i+1][(j*dig%13 + r)%13] += dp[i][r];
          dp[i+1][(j*dig%13 + r)%13] %= MOD;
        }   
      } 
    }else{
      int a = (char) (S[i]-'0');
      for(int r=0; r<13; r++){
        dp[i+1][(a*dig%13 + r)%13] += dp[i][r];
        dp[i+1][(a*dig%13 + r)%13] %= MOD;
//        cout << dp[i+1][a*dig%13 + r] << " ";
//        cout << dp[i][r] << " ";
      }
    }
    dig *= 10;
  }
  /*
  for(int j=0; j<len+1; j++){
    for(int i=0; i < 13; i++){
      cout << dp[j][i] << " ";
    }
    cout << endl;
  }
  */

  cout << dp[len][5] << endl;
  return 0;
}

Measured memory_bytes: 10624
n = int(input())
s = [pow(26, i) for i in range(20)]
s[0] = 0
for i in range(20-1):
    s[i+1] += s[i]

for i in range(1,20):
    if n > s[i]:
        continue
    else:
        n = n - s[i-1] - 1
        ans = ''
        for j in range(1,i+1):
            idx = n // pow(26, i-j)
            ans += chr(0x61 + idx)
            n -= idx * pow(26, i-j)
        print(ans)
        break

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

class Program
{
	static void Main(string[] args)
	{			
		//文字列を読み込む
		string[] ballString = Console.ReadLine().Split(' ');
		string[] numString = Console.ReadLine().Split(' ');
		string chosen = Console.ReadLine();
		
		int A = int.Parse(numString[0]);
		int B = int.Parse(numString[1]);
		
		//答えをソート
		if(chosen == ballString[0]){
				A--;
		}else{
				B--;
		}
		
		//出力
		Console.WriteLine(A + " " + B);
	}
}



Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
    int N;
    int T;
    int S;
    cin >> N >> T >> S;
    if (T * S - N >= 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3060
from collections import defaultdict

N = int(input())
V = defaultdict(list)

for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

def dfs(source):
    dist = [-1]*(N+1)
    dist[source] = 0
    q = [source]
    while q:
        a = q.pop()
        for b in V[a]:
            if dist[b]!=-1:continue
            dist[b] = dist[a] + 1
            q.append(b)
    return dist

d1, d2 = dfs(1), dfs(N)
a = sum(d1[i]<=d2[i] for i in range(1, N+1))
print("Fennec" if a>N-a else "Snuke")


Measured memory_bytes: 34680
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
    long long N;
    cin>>N;
    long long ans = 1e13;

    for (long long i = 1; i <= N/i; ++i) {
        if (N%i==0){
            ans = min((i-1+(N/i-1)),ans);
        }

    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;





public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W,H,x,y,r;

		W = sc.nextInt();
		H = sc.nextInt();
		x = sc.nextInt();
		y = sc.nextInt();
		r = sc.nextInt();

		if ((x+r <= W) && (x - r >= 0) && (y + r <= H) && (y - r >= 0)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


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

int INF = 1001001001;

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;
}

int main() {
    int n, w;
    cin >> n >> w;
    vector<vector<ll>> dp(n+1, vector<ll>(100005));
    rep(i,n+1)rep(j,100005) dp[i][j] = INF;
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        for (int j = 0; j <= 100005; j++) {
            if (j - y >= 0) {
                chmin(dp[i+1][j], dp[i][j - y] + x);
            }
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    rep(i,100005) {
        if (dp[n][i] <= w) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 83204
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int a=0;
	int b=0;
	cin>>a>>b;
	if(500*a>=b)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = []
ans = float('inf')

for _ in range(n):
    h.append(int(input()))
h = sorted(h)

for i in range(n - k + 1):
    diff = h[i + k - 1] - h[i]
    ans = min(ans, diff)

print(ans)


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

int main(){

	int n,k;
	cin >> n >> k;

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

	vector<int> dp(n,INT_MAX);
	dp[n-1]=0;


	for(int i=n-2;i>=0;i--){
		for(int j=i+1;j<=i+k && j<n;j++){
			dp[i] = min(dp[i] , abs(a[i]-a[j])+dp[j]);
		}
	}

	cout << dp[0] << "\n";


	return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  //vector<int> ant(5);
  //cin >> ant.at(0) >> ant.at(1) >> ant.at(2) >> ant.at(3) >> ant.at(4) >> k;
  /*
  for(int i = 0; i < 5; i++)
    cin >> ant.at(i);
  
  int k = 0;
  cin >> k;
  
  bool ans = true;
  
  for(int i = 0; i < 5; i++) {
    if(ant.at(i+1) - ant.at(i) > k) 
      ans = false;
  }
  
  if (ans)
    cout << "Yay!" << endl;
  else 
    cout << ":(" << endl;
   */
  
  //cout << n << k << endl;
  if(k == 1) {
    cout << 0 << endl;
  }
  else 
    cout << n - k << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const ll MOD = 1e9 + 7;
const ll N = 2e5 + 5;
ll n, ans = 0, r = 0;
string s;
priority_queue<ll>pq;
int main()
{
    IOS;
    cin >> n >> s;
    for(ll i = 0; i < n; i++)
    {
        if(s[i] == 'R')
        {
            r++;
            pq.push(i);
        }
    }
    for(ll i = 0; i < n; i++)
    {
        if(s[i] == 'R')
        {
            r--;
            continue;
        }
        if(r > 0)
        {
            if(!pq.empty())
            {
                ll top = pq.top();
                pq.pop();
                if(top > i)
                    swap(s[i], s[top]);
            }
            ans++;
            r--;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5508
import itertools
F=list(map(int, input().split()))
s = [list(map(int,input().split())) for i in range(int(F[2]))]

# print(s)
flist=list(range(1,F[1]+1))
comb=list(itertools.combinations_with_replacement(flist,F[0]))
result=[0]*len(comb)
# print(comb)

for i,a in enumerate(comb):
    for row in s:
        if a[row[1]-1]-a[row[0]-1]==row[2]:
            result[i]+=row[3]

print(max(result))
# print(comb[result.index(max(result))])



Measured memory_bytes: 85472
#include <stdio.h>
#include <string.h>

int min(int ,int);
int main(){
	char S[1001],T[1001];
	
	scanf("%s",S);
	scanf("%s",T);
	
	int ans = strlen(T);
	
	for(int start = 0;start <= strlen(S) - strlen(T); start++){
		int diff = 0;
		for(int i = 0;i < strlen(T);i++){
			if(T[i] != S[start + i]){
				diff++;
			}
		}
		ans = min(ans,diff);
	}
	printf("%d\n",ans);
	return 0;
}

int min(int x,int y){
	if(x > y){
		x = y;
	}
	return x;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
int n, m, f[Maxn], num[Maxn], ans;
ll sum[Maxn];
struct str
{
	int a, b, val;
	bool operator<(str an) const
	{
		return val < an.val;
	}
} e[Maxn];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main()
{
	int u, v;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &sum[i]);
		f[i] = i;
	}
	for (int i = 1; i <= m; i++)
		scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].val);
	sort(e + 1, e + m + 1);
	for (int i = 1; i <= m; i++)
	{
		u = find(e[i].a);
		v = find(e[i].b);
		if (u != v)
		{
			num[u] += num[v];
			sum[u] += sum[v];
			f[v] = u;
		}
		num[u]++;
		if (sum[u] >= e[i].val)
		{
			ans += num[u];
			num[u] = 0;
		}
	}
	cout << m - ans << endl;
	return 0;
}


Measured memory_bytes: 2944
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

string S;

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

    int red = 0;
    rep(i, N) if (S[i] == '0') red++;

    int fin = max(N - red - red, red - N + red);

    write(N - fin);
}

Measured memory_bytes: 592
#include<stdio.h>

int main(){
	char str[3];
	scanf("%s",str);
	int flagA = 0;
  	int flagB = 0;
  	for(int i = 0;i<3;i++){
      if('A'==str[i]) flagA = 1;
  	  if('B'==str[i]) flagB = 1;
    }
  
  	if(flagA == 1 && flagB == 1) printf("Yes");
  	else printf("No");
return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
arr = []
count_arr = [0 for i in range(30)]

for i in range(N):
    arr.append(list(map(int, input().split())))

for i in range(N):
    K = arr[i][0]
    for j in range(1,K+1):
        count_arr[arr[i][j]-1] += 1

count = 0
for i in count_arr:
    if i == N:
        count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() 
{
   long int n,k=0;
   cin>>n;
   if(n%1000==0)
   cout<<"0"<<endl;
   else
   {
     while(n>k)
     k+=1000;
     cout<<k-n<<endl;
   }
}

Measured memory_bytes: 3648
#include <stdio.h>

int main()
{
	int A, B, K,r;
	scanf("%d %d %d", &A, &B, &K);
	
	int x = 0;
	int y[100];
	
	for(r=0; r<100; r++){
		y[r] = 0;
		}
	
	for(r=0; r<100; r++){
		if(A % (r+1) == 0 && B % (r+1) == 0){
			y[x] = r+1;
			x++;
		}
	}
	
		
	printf("%d", y[x-K]);
	
	return 0;
}

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

int main()
{
	int n, s = 0;
	cin >> n;
	for (int i = 1; n != 0; i++)
	{
		if (n % 10 == 2) ++s;
		n /= 10;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
import math
A,B,N = map(int, input().split())
c = 0
if B > N:
	c = (math.floor(A * N / B))-(A * (math.floor(N / B)))
elif B <= N:
	c = (math.floor(A * (B-1) / B))-(A * (math.floor((B - 1) / B)))
print(c)

Measured memory_bytes: 9012
N=int(input())
h=list(map(int,input().split()))

cost=[0,abs(h[0]-h[1])]

for i in range(N-2):
  i+=2
  c1=cost[i-2]+abs(h[i-2]-h[i])
  c2=cost[i-1]+abs(h[i-1]-h[i])
  cost.append(min([c1,c2]))

print(cost[-1])

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int x, y;

int main() {
	cin >> x >> y;
	int p[13] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
	if (p[x]==p[y]) cout << "Yes" << ln;
	else cout << "No" << ln;
}

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

using namespace std;
using ll =long long;
using db = double;

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; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
int main()
{
	cout << setprecision(10);
	ll n , x;
	cin >> n >> x;
	vector<ll> v(n);
	if(n==1){
		ll b;
		cin >> b;
		cout << abs(x-b)<<endl;
		return 0;
	}else{	

	rep(i,n){
		ll a ;
		cin >> a;
		v[i] = abs(a-x);
	}
	ll G = INF;
	rep(i,n-1){
		chmin(G,__gcd(v[i],v[i+1]));
	}
	cout << G << endl;
	}
}


Measured memory_bytes: 1024
#include <stdio.h>

typedef unsigned char   u1;
typedef unsigned short  u2;
typedef unsigned long   u4;
typedef signed char     s1;
typedef signed short    s2;
typedef signed long     s4;

#define IN_SIZE 4U
#define OUT_SIZE 10U

int main (void)
{
    u2 u2In;
    u2 u2Upper, u2Lower;
    const char *strOut;

    scanf("%d", &u2In);
    u2Upper = u2In / 100U;
    u2Lower = u2In - u2Upper * 100U;

    if (0U < u2Upper && u2Upper < 13U)
    {
        // MMYY?
        if (0U < u2Lower && u2Lower < 13U)
        {
            strOut = "AMBIGUOUS";
        }
        else
        {
            strOut = "MMYY";
        }
    }
    else
    {
        // YYMM?
        if (0U < u2Lower && u2Lower < 13U)
        {
            strOut = "YYMM";
        }
        else
        {
            strOut = "NA";
        }
    }

    printf("%s\n", strOut);

    return 0;
}

Measured memory_bytes: 128