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

using namespace std;

set<pair<int, int> > S;
vector<int> Adj[100005];

int N, M;
int x[100005], y[100005], NUM[100005];
int check[100005];
vector<int> V;

int dp[100005];

int main(void) {

	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> x[i] >> y[i];
		Adj[x[i]].push_back(y[i]); NUM[y[i]]++;
	}

	for (int i = 1; i <= N; i++) {
		pair<int, int> P(NUM[i], i);
		S.insert(P);
	}

	while (S.size()) {
		//cout << "S.size()= " << S.size() << endl;
		auto it = S.begin();
		V.push_back((*it).second);
		int I = (*it).second; check[I] = 1;
		S.erase(it);

		for (int j = 0; j < (int)Adj[I].size(); j++) {
			int U = Adj[I][j];
			if (check[U] != 0) { continue; }
			S.erase(pair<int, int>(NUM[U], U));
			NUM[U]--;
			S.insert(pair<int, int>(NUM[U], U));
		}

	}

/*	for (int i = 0; i < (int)V.size(); i++){
	cout << V[i] << " ";
}*/
//cout << endl;

dp[V[0]] = 0;
 
for (int i = 0; i < (int)V.size(); i++) {
	int I = V[i];
	for (int u = 0; u < (int)Adj[I].size(); u++) {
		int K = Adj[I][u];
		dp[K] = max(dp[K], dp[I] + 1);
	}
}

int ans = 0;
for (int i = 1; i <= N; i++) {
	ans = max(ans, dp[i]);
}

cout << ans << endl;

/*for (int i = 1; i <= N; i++) {
	cout << "dp[" << i << "]= " << dp[i] << endl;
}*/

	//system("pause");
	return 0;
}

Measured memory_bytes: 12924
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9+5;
const ll INF=1e18+5;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a,b,M,m;
  cin >> n >> a >> b;
  m=max(0,a+b-n);
  M=min(a,b);
  cout << M << " " << m << endl;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, a, b = map(int, input().split())

k = n // (a + b)
if (n - k * (a + b)) > a:
    ans = a * (k + 1)
else:
    ans = a * k + (n - k * (a + b))

print(ans) 

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
struct work{
	ll A,B;
};
bool cmp(struct work a,struct work b){
	return a.B<b.B;
}
int main(void){
	int N;cin >> N;
	struct work work[N];
	for(int i=0;i<N;i++){
		cin >> work[i].A >> work[i].B;
	}
	sort(work,work+N,cmp);
	ll cur = 0;
	for(int i=0;i<N;i++){
		if(cur>work[i].B|| cur + work[i].A > work[i].B){
			cout << "No" << endl;
			return 0;
		}
		cur += work[i].A;
	}
	cout << "Yes" << endl;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define pb push_back
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}

int a[maxn];
vector<int> t;
int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
//    ios_base::sync_with_stdio(0);
    init();
    int n,m; cin >> n >>m;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
    sort(a,a+m);
    for (int i = 1; i < m; i++) t.pb(a[i] - a[i - 1]);
    sort(t.begin(), t.end());
    if (n >= m) puts("0");
    else {
        int cnt = 0;
        for (int i = 0; i < m - n; i++) {
            cnt += t[i];
        }
        cout << cnt << endl;
    }





    return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9
#define vint vector<int>

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int a[20];
int x[20][20];
int y[20][20];

int bit_counter(int x) {
    if(x == 0) return 0;
    return bit_counter(x >> 1) + (x & 1);
}

int main(){
    int n;
    cin >> n;
    vint array(n);
    REP(i, 0, n){
        cin >> array[i];
    }
    std::vector<size_t> indices(array.size());
    std::iota(indices.begin(), indices.end(), 0);

    // ソートする。
    std::sort(indices.begin(), indices.end(), [&array](size_t i1, size_t i2) {
        return array[i1] < array[i2];
    });

    for (auto v : indices)
        std::cout << v+1 << " ";
    std::cout << std::endl;
}

Measured memory_bytes: 2048
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<iterator>
#define ll long long
#define mod 1000000007
#define inf 100000000000000
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,w;
	cin>>n>>w;
	vector<pair<int, int> > items;
	int i,j;
	ll totval=0;
	for(i=0; i<n; i++)
	{
		int weight, value;
		cin>>weight>>value;
		items.push_back(make_pair(weight,value));
		totval+=value;
	}
	ll dp[n][totval+1];
	for(i=0; i<n; i++)
	{
		for(j=0; j<=totval; j++)
		{
			dp[i][j]=inf;
		}
	}
	for(i=0; i<n; i++)
	{
		dp[i][0]=0;
	}
	for(j=1; j<=totval; j++)
	{
		if(items[0].second==j)
		{
			dp[0][j]=items[0].first;
		}
	}
	for(i=1; i<n; i++)
	{
		for(j=1; j<=totval; j++)
		{
			if(items[i].second>j)
			{
				dp[i][j]=dp[i-1][j];
			}
			else
			{
				if(dp[i-1][j-items[i].second]!=inf)
				{
					dp[i][j]=min(dp[i-1][j], dp[i-1][j-items[i].second]+items[i].first);
				}
				else
				{
					dp[i][j]=dp[i-1][j];
				}
			}
		}
	}
	for(j=totval; j>=0; j--)
	{
		if(dp[n-1][j]<=w)
		{
			cout<<j<<"\n";
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	int n,k; cin >> n >> k;
	
	//cout << "test" << endl;
	
	long double P=0;
	
	for(int i=1;i<=n;i++){
		long double p=1;
		int j=i;
		
		//cout << "test" << endl;
		
		while(1){
			if(j>=k){
				P+=p;
				//cout << p << endl;
				break;
			}
			j*=2;
			p/=2;
			
			
			//cout << j << ":" << k << endl;
		}
	}
	P/=n;
	
	
	
	cout << setprecision(10) << P << "\n";
	
	return 0;
}


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

int h[100010];

int main(void){
	int n, k, ans=0;
	cin >> n >> k;
	for(int i=0; i<n; i++) cin >> h[i];
	sort(h, h+n);
	for(int i=0; i<=n-k; i++){
		int x = h[i+k-1] - h[i];
		if(i==0 || ans>x) ans = x;
	}
	cout << ans << endl;
}

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

#define rep(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fill(x,v) memset(x,v,sizeof(x))
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x <<": " << x << endl
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef long double C;
typedef pair<ll, ull> dato;

const int MAX = 1e6+5;
const ll MOD = 1e9+7;
const ll p = 59;

ll pot1[MAX];
ull pot2[MAX];
ll h11[MAX];
ull h12[MAX];

vi adj[MAX], inv[MAX];
bool visited[MAX], visited2[MAX];
stack<int> pila;
bool can = true;

void pre(){
    pot1[0] = 1;
    pot2[0] = 1;
    rep(i,1,MAX){
        pot1[i] = (pot1[i-1]*p)%MOD;
        pot2[i] = pot2[i-1]*p;
    }
}

void toposort(int node){
    visited[node] = true;
    rep(i,0,adj[node].size()){
        int x = adj[node][i];
        if(!visited[x])
            toposort(x);
    }
    pila.push(node);
}

void ciclo(int node){
    visited[node] = true;
    rep(i,0,inv[node].size()){
        int x = inv[node][i];
        if(!visited[x])
            can = false;
    }
}

ll longest(int node){
    visited2[node] = true;
    rep(i,0,adj[node].size()){
        int x = adj[node][i];
        if(!visited2[x])
            return longest(x) + 1; 
    }
    return 0;
}


int main(){
    fastio;
    pre();
    string s,t;
    cin >> s >> t;
    ll cantMax = s.size() + t.size() + 2;
    ll h1 = 0;
    ull h2 = 0;
    rep(i,0,t.size()){
        h1 = (h1 + ((t[i]-'a' + 1)*pot1[i])%MOD)%MOD;
        h2 = (h2 + ((t[i]-'a' + 1)*pot2[i]));
    }
    h1 = (h1 * pot1[cantMax - t.size() + 1])%MOD;
    h2 = (h2 * pot2[cantMax - t.size() + 1]);
    string a;
    h11[0] = 0;
    h12[0] = 0;
    rep(i,0,cantMax){
        a.pb(s[i%(s.size())]);
        h11[i+1] = (h11[i] + ((s[i%(s.size())]-'a' + 1)*pot1[i])%MOD)%MOD;
        h12[i+1] = (h12[i] + ((s[i%(s.size())]-'a' + 1)*pot2[i])); 
    }
    ll aux1;
    ull aux2;
    int u,v;
    rep(i,0,s.size()){
        aux1 = (h11[i+t.size()] - h11[i] + MOD)%MOD;
        aux1 = (aux1 * pot1[cantMax-i-t.size()+1])%MOD;
        aux2 = (h12[i+t.size()] - h12[i]);
        aux2 = (aux2 * pot2[cantMax-i-t.size()+1]);
        if(aux1 == h1 && aux2 == h2){
            u = i;
            v = (i+t.size())%s.size();
            adj[u].pb(v);
            inv[v].pb(u);
            if(u == v) can = false;
        }
    }

    fill(visited, 0);
    rep(i,0,s.size()){
        if(!visited[i])
            toposort(i);
    }
    fill(visited, 0);
    fill(visited2, 0);
    ll rpta = -1;
    while(pila.size()){
        int curr = pila.top();
        pila.pop();
        ciclo(curr);
        if(can) rpta = max(rpta, longest(curr));
        else break;
    }
    if(can) cout << rpta << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 141840
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    c=a+b;
    if(a%3==0)
        cout<<"Possible";
    else if(b%3==0)
        cout<<"Possible";
    else if(c%3==0)
        cout<<"Possible";
    else
        cout<<"Impossible";
    return 0;
}


Measured memory_bytes: 3592
//#define DEB1 //input from input.txt
//#define NDEBUG
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <cassert>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);i--)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);i++)
#define RNG(i,start,fin) for(int i=(start);i<(fin);i++)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/* 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}

template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}

template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/

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




/*
constant values
*/

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

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


// Main program
void solve(){
    int N;
    int X[10];
    int Y[10];
    int cnt = 0;
    cin >> N;
    REP(i,N){
        cin >> X[i] >> Y[i];
    }
    double sum = 0 ;
    double dist = 0;
    CREP(i,0,N-2){
        CREP(j,i+1,N-1){
            dist = sqrt( pow( (X[i]-X[j]),2) + pow((Y[i]-Y[j]),2) );
            cerr << dist << endl;
            sum += dist;
            ++cnt;
        }
    }
    double ans;
    ans = sum/cnt *(N-1) ;
    cerr << cnt << endl;
    cout << fixed << setprecision(10) << ans << endl;
    return;
}



// ----------------------------------------------
int main(){

#ifdef DEB1
    cout << "DEBUG MODE"  << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf()); //for debug
#endif

    int T=1; 

    for (int i = 0; i < T; ++i) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
ll inf = 1000000000 + 7;

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

ll max(ll a, ll b) {
	if (a < b) {
		return b;
	}
	else
		return a;

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




ll pow(ll a, ll b) {


	if (b == 0) return 1;

	if (a % 2 == 1) {
		a * pow(a, b - 1);
	}
	else {
		ll ret = pow(a, b / 2);
		return ret * ret;
	}
}





ll dp[100005];
int main() {
	ll N, C;
	
	cin >> N;


	dp[1] = 1;

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

		dp[i] = dp[i - 1] + 1;
		
		C = 6;

		while (i - C >= 0) {

			dp[i] = min(dp[i - C] + 1, dp[i]);
			C = C * 6;
		}

		C = 9;

		while (i - C >= 0) {
			dp[i] = min(dp[i - C] + 1, dp[i]);
			C = C * 9;
		}
		


	}




	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
	char a;
	cin >> a;
	if (a >= 'a' && a <= 'z') cout << 'a';
	else cout << 'A';
}


Measured memory_bytes: 3580
#include <stdio.h>

int main()
{
  char s[3];
  int a = 0, b = 0, c = 0;

  scanf("%s\n", s);
  
  if(s[0] == 'a') a++;
  if(s[0] == 'b') b++;
  if(s[0] == 'c') c++;

  if(s[1] == 'a') a++;
  if(s[1] == 'b') b++;
  if(s[1] == 'c') c++;

  if(s[2] == 'a') a++;
  if(s[2] == 'b') b++;
  if(s[2] == 'c') c++;

  if(a == 1 && b == 1 && c == 1) {
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF=1e9;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    ll a,b,x;
    cin>>a>>b>>x;
    ll ans;
    if(0<a){
     ans=b/x-(a-1)/x;
    }
    else ans=b/x+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
    It is time for a counter-attack
*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
using namespace std;
typedef long long ll;
const ll N=2e5+10,M=2e5+1,mod=1e9+7;
const ll OO=1e16;
#define scan(A,n) for (int i=0;i<n;++i) cin>>A[i];
#define pb push_back
#define bg begin
#define des(A,n) sort(A,A+n);reverse(A,A+n)
#define en end
#define f first
#define s second
#define bs binary_search
#define fill2(A, x) for(int i=0;i<N;++i) for(int j=0;j<N;++j) A[i][j]=x;
#define set2(A, x) fill(A,A+N,x);
#define scan2(A, n, m) for(int i=0;i<n;++i) for(int j=0;j<m;++j) cin >> A[i][j];
#define set(A, x) memset(A, x, sizeof(A))
#define print(A, x) for (int i=0;i<x;++i) cout<<A[i]<< " ";
#define pii pair<int, int>
#define pll pair<ll, ll>
#define low lower_bound
#define high upper_bound
#define bits(x) __builtin_popcountll(x)
#define sz size
#define cl clear
#define all(A) A.bg(), A.en()
#define REPEAT main()
#define dig(n) log10(n)+1;
#define vi vector<int>
#define vl vector<ll>
int n,m,x,A[20][20];
int main(){
    cin>>n>>m>>x;
    for(int i=0;i<n;++i){
        for(int j=0;j<m+1;++j){
            cin>>A[i][j];
        }
    }
    ll ans=10000000000;
    for(int msk=0;msk<(1<<n);++msk){
        int skill[20]={0};
        ll cur=0;
        for(int i=0;i<n;++i){
            if(msk&(1<<i)){
                cur+=A[i][0];
                for(int j=1;j<m+1;++j){
                    skill[j-1]+=A[i][j];
                }
            }
        }
        int cnt=0;
        for(int i=0;i<m;++i){
            if(skill[i]>=x){
                ++cnt;
            }
        }
        if(cnt==m){
            ans=min(ans,cur);
        }
    }
    if(ans==10000000000) cout<<-1<<"\n";
    else cout<<ans<<"\n";
}

Measured memory_bytes: 3592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20180305_AOJ
{
    class ALDS1_4A
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                //int n = int.Parse(line);
                int[] S = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                Console.ReadLine();
                int[] T = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

                int count = 0;
                foreach (var v in T)
                {
                    if (Array.FindIndex(S, x => x == v) >= 0)
                    {
                        count++;
                    }
                }

                Console.WriteLine(count);
            }
        }
    }
}



Measured memory_bytes: 10268
N,M=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
mod=10**9+7

X=0
for i in range(N):
    X+=((i)*x[i]-(N-i-1)*x[i])
    X%=mod
Y=0
for i in range(M):
    Y+=((i)*y[i]-(M-i-1)*y[i])
    Y%=mod
print(X*Y%mod)

Measured memory_bytes: 24436
#include <bits/stdc++.h>
#include <regex>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  bool flag = true;
  for (int i(0);i<s.size();i++){
    if (i%2==0){
      if (s[i]=='L') flag=false;
    }else{
      if (s[i]=='R') flag=false;
    }
  }
  cout << (flag? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int x; cin >> x;
    cout << x / 500 * 1000 + x % 500 / 5 * 5 << '\n';
}


Measured memory_bytes: 888
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a) < sum(b):
    print(-1)
    exit(0)
ans = 0
tarinai = 0
yobun = []
for i in range(n):
    if a[i] < b[i]:
        ans += 1    
        tarinai += b[i] - a[i]
    elif a[i] > b[i]:
        yobun.append(a[i] - b[i])
if ans == 0:
    print(0)
    exit(0)
yobun.sort(reverse=True) 
m = len(yobun)
total = 0
for i in range(m):  
    total += yobun[i]
    if total >= tarinai:
        ans += i + 1
        break
print(ans)


Measured memory_bytes: 24288
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef struct _XY {
	int x;
	int y;
} XY;

XY figure[][4] = {
	{{1, 0}, {0, 1}, {1, 1}}, // A
	{{0, 1}, {0, 2}, {0, 3}}, // B
	{{1, 0}, {2, 0}, {3, 0}}, // C
	{{0, 1}, {-1, 1}, {-1, 2}}, // D
	{{1, 0}, {1, 1}, {2, 1}}, // E
	{{0, 1}, {1, 1}, {1, 2}}, // F
	{{1, 0}, {0, 1}, {-1, 1}}, // G
};

string name[7] = {"A", "B", "C", "D", "E", "F", "G"};
int main() {
	int math[8][8];
	char c;
	while (1) {
		memset(math, 0, sizeof(math));
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				c = getchar();
				math[i][j] = c - '0';
			}
			c = getchar();
		}

//		for (int i = 0; i < 8; i++) {
//			for (int j = 0; j < 8; j++) {
//				cout << math[i][j];
//			}
//			cout << endl;
//		}

		XY p;
		for (int i = 0; i < 8; i++) {
			for (int j = 0; j < 8; j++) {
				if (math[i][j] == 1) {
					p.x = j;
					p.y = i;
					goto END;
				}
			}
		}

END:
		for (int i = 0; i < 7; i++) {
			if (math[p.y + figure[i][0].y][p.x + figure[i][0].x] == 1 &&
				math[p.y + figure[i][1].y][p.x + figure[i][1].x] == 1 &&
				math[p.y + figure[i][2].y][p.x + figure[i][2].x] == 1 ) {
				cout << name[i] << endl;
				break;
			}
		}

		c = getchar();
		if (c == EOF)
			break;
	}
	return 0;
}

Measured memory_bytes: 1156
package main

import (
	"fmt"
	"sort"
)

func main(){
	var s string
	fmt.Scan(&s)
	var K int
	fmt.Scan(&K)
	sli := []string{}
	l := len(s)
	for i:=0; i<l; i++ {
		ch := true
		for x := range sli {
			if string(sli[x]) == string(s[i]){
				ch = false
			}
		}
		if ch {
			sli = append(sli, string(s[i]))
		}

		tmp := string(s[i])
		for n:=i+1; n<l; n++ {
			tmp += string(s[n])
			if len(tmp) > K {
				break
			}
			ch = true
			for x := range sli {
				if string(sli[x]) == tmp{
					ch = false
				}
			}
			if ch {
				sli = append(sli, tmp)
			}
		}
	}

	sort.Strings(sli)
	fmt.Println(sli[K-1])
}


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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int main() {
	int cnt = 1;
	while (1) {
		int in;
		cin >> in;
		if (in == 0)
			break;
		cout << "Case " << cnt << ": " << in << endl;
		cnt++;
	}
	return 0;
}


Measured memory_bytes: 3008
# -*- coding:utf-8 -*-
#入力
n = int(input())
s = input()

if n == 1:
	flag = 0
else:
	for i in range(n):
		if (s[:i] == s[i:]):
			print("Yes")
			flag = 1
			exit()
		else:
			flag = 0

if flag == 0 :
	print("No")

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string T="Yes";
    string S,S1;
    cin>>S;
    for(int i=0;i<S.length();++i){
        S1=S.substr(i,1);
        if(!(((i+1)%2==1 &&("R"==S1))||((i+1)%2==0 && S1=="L")|| (S1=="U") || (S1=="D"))){
            T="No";
        }
    }
    cout<<T<<endl;
}


Measured memory_bytes: 256
H, W = map(int, input().split())

A = [list(input()) for _  in range(H)]
h = set()
w = set()

for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            h.add(i)
            w.add(j)

for i in h:
    for j in w:
        print(A[i][j], end="")
    print()

Measured memory_bytes: 4468
#include<cstdio>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;static char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int n,ans,a[100005];
int main(void){
	register int i;
	n=read();
	for(i=1;i<=n;++i)
		a[i]=read();
	for(i=1;i<=n;++i)
		if(a[i]==i)++ans,++i;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000000 + 7;
int main(){
    ll N, K; cin >> N >> K;
    ll ans = 0;
    for (ll i = K; i <= N+1; i++)
    {
        ll mi = (i-1) * i / 2;
        ll ma = (2*N-i+1) * i / 2;
        //cout << ma << " " << mi << endl;
        ma++;
        mi %= mod;
        ma %= mod;
        ma -= mi;
        if(ma<0) ma+=mod;
        ans += ma;
        ans %= mod;  
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3624
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int K;
  cin >> K;
  string S;
  cin >> S;
  const int N = K + S.length();
  constexpr int kMod = 1000000007;
  auto modpow = [&](long long a, int b) {
  	long long r = 1;
  	for (; b > 0; b /= 2) {
  		if (b % 2) r = r * a % kMod;
  		a = a * a % kMod;
  	}
  	return r;
  };
  auto inv = [&](int a) { return modpow(a, kMod - 2); };
  vector<long long> fact(N + 1, 1);
  for (int i = 0; i < N; ++i) fact[i + 1] = fact[i] * (i + 1) % kMod;
  auto c = [&](int n, int r){
  	return fact[n] * inv(fact[n-r] * fact[r] % kMod) % kMod;
  };
  int ans = 0;
  for (int i = 0; i <= K; ++i) {
  	ans += modpow(26, i) * c(N-i-1, N-K-1) % kMod * modpow(25, K-i) % kMod;
  	ans %= kMod;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 19832
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

ct = 0
for i in range(1, n+1):
    if len(str(i)) % 2 == 1:
        ct += 1
print(ct)


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

int main(){
  int n;
  while(cin >> n, n){
    for(int i=0; i<n; ++i){
      int m,e,j;
      cin >> m >> e >> j;
      if(m == 100 || e == 100 || j == 100){
        cout << "A" << endl;
      }else if((m + e)/2 >= 90){
        cout << "A" << endl;
      }else if((m + e + j)/3 >= 80){
        cout << "A" << endl;
      }else if((m + e + j)/3 >= 70){
        cout << "B" << endl;
      }else if((m + e + j)/3 >= 50){
        if(e >= 80 || m >=80){
          cout << "B" << endl;
        }else{
        cout << "C" << endl;
      }
      }else{
        cout << "C" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3060
<?php
$data = trim(fgets(STDIN));
$data = str_split( $data );

$a = 0;
$b = 0;
foreach( $data as $val )
{
  if( $val == 0 ) { $a++; }
  else			  { $b++; }
}

$result = min( $a, $b )*2;
echo $result;

Measured memory_bytes: 10744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

vector<vector<ll>> table;
string A, B;
ll dfs(ll ai, ll bi) {
  if (table[ai][bi] != -1) return table[ai][bi];

  ll score = 0;
  if (ai < A.size() && bi < B.size() && A[ai] == B[bi])
    return table[ai][bi] = dfs(ai + 1, bi + 1) + 1;
  if (ai < A.size()) score = max(score, dfs(ai + 1, bi));
  if (bi < B.size()) score = max(score, dfs(ai, bi + 1));
  return table[ai][bi] = score;
}

int main() {
  ll input(n);
  REP (i, n) {
    table = vector<vector<ll>>(1000 + 1, vector<ll>(1000 + 1, -1));
    string input(a, b); A = a; B = b;
    cout << dfs(0, 0) << endl;
  }
}



Measured memory_bytes: 18768
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()

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;
}
template<class T>inline int cmp(vector<T>&v,T &a){
	return lower_bound(all(v),a)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,A[200005];
signed main(){
	cin>>N;
	rep(i,N)cin>>A[i];
	sort(A,A+N,greater<>());
	int ans=A[0];
	for(int i=2;i<N;i++)ans+=A[i/2];
	cout<<ans<<endl;
}

Measured memory_bytes: 5208
#include<iostream>
#include<math.h>
using namespace std;
#define MAX  1000
#define SENTINEL  2000000000

int cnt;
int A[MAX], L[MAX/2 + 2], R[MAX/2 + 2];

void Merge(int A[], int n, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++)
    {
        cnt++;
        if (L[i] <= R[j])
        {
            A[k] = L[i++];
        }
        else
        {
            A[k] = R[j++];
        }
    }
}

void MSort(int A[], int n, int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        MSort(A, n, left, mid);
        MSort(A, n, mid, right);
        Merge(A, n, left, mid, right);
    }
}

int main()
{
    int N, S, s, v;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    MSort(A, N, 0, N);
    S = 0;
    s = 0;
    for (int i = 0; i < N; i = i + 2)
    {
        S = S + A[i];
    }
    for (int i = 1; i < N; i = i + 2)
    {
        s = s + A[i];
    }
    v = abs(S- s);
    cout << v << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define NUMBER 10000
int main(void)
{
	int  i, num;
	long a[NUMBER];
	scanf("%d", &num);
	for(i = 0; i < num; i++) {
    		scanf("%ld ", &a[i]);
	}

	long min, max, sum;
	min = max = sum = a[0];
	for(i = 1; i < num; i++) {
    		if(a[i] > max) {
	    		max = a[i];
    		}
    		if(a[i] < min) {
    			min = a[i];
    		}
    		sum += a[i];
	}
	printf("%ld %ld %ld\n", min, max, sum);
	return 0;
}


Measured memory_bytes: 2124
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def main():
    N = int(input())

    ans = 0
    for i in range(1,N+1):
        if len(str(i)) % 2 == 1:
            ans += 1

    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
d={}
for i in range(int(input())+1):
  for j in d:
    while i>1 and i%j<1:
      d[j]+=1
      i//=j
  if i>1:
    d[i]=2
a=1
for v in d.values():
  a=a*v%(10**9+7)
print(a)

Measured memory_bytes: 2940
//
//  main.cpp
//   1D Reversi
//
//  Created by Oracle on 2020/1/11.
//  Copyright © 2020 Sam. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;
int main() {
    int ans=0;
    char a[100001];
    gets(a);
    for (int i=0;i<strlen(a)-1;i++){
        if (a[i]!=a[i+1]) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
struct data{int to,next,wi;}e[maxn*2];
int head[maxn];
int cnt=0;
int du[maxn];
queue<int> q;
bool vis[maxn];
void ins(int u,int v,int ww)
{
	e[++cnt].to=v;
	e[cnt].next=head[u];
	e[cnt].wi=ww;
	head[u]=cnt;
}
int n,m;
int dis[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		ins(x,y,z);
		du[y]++;
	}
	for(int i=1;i<=n;i++)dis[i]=1e9+10;
	for(int s=1;s<=n;s++)
	{
		if(du[s]==0)
		{
			dis[s]=0;
			vis[s]=1;
			q.push(s);
			while(!q.empty())
			{
				int x=q.front();
				q.pop();
				for(int i=head[x];i;i=e[i].next)
				{
					int u=e[i].to;
					if(vis[u]==1&&dis[u]!=dis[x]+e[i].wi&&du[x]!=0)
					{
						puts("No");
						return 0;
					}
					if(vis[u]==0)
					{
						vis[u]=1;
						dis[u]=min(dis[u],dis[x]+e[i].wi);
						q.push(u);
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++)if(vis[i]==0){puts("No");return 0;}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
int main(){
  int a,b,A,B,t=-1;
  scanf("%d %d",&a,&b);
  A=12.5*a;
  if(a%2==1){
    A++;
  }
  for(int i=0;i<12;i++){
     B=A/10;
    if(B==b){
      t=A;
      break;
    }
    A++;
  }
  if(a%2==0){
    B=A/10;
    if(B==b){
      t=A;
    }
  }
  printf("%d",t);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

set<int> st1, st2;
vector<bool> vis;
vector<vector<int>> G;
vector<int> p;

void dfs(int s){
    if(vis[s]) return;
    vis[s] = true;
    st1.insert(s);
    st2.insert(p[s]);
    for(int t : G[s])
        dfs(t);
}

int main(){
    int N, M;
    cin >> N >> M;
    p.resize(N);
    G.resize(N);
    vis.resize(N, false);
    for(int i=0; i<N; i++){
        cin >> p[i];
        p[i]--;
    }

    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    int ans = 0;
    for(int i=0; i<N; i++){
        if(!vis[i]){
            st1.clear(); st2.clear();
            dfs(i);
            set<int> result;
            set_intersection(st1.begin(), st1.end(), st2.begin(), st2.end(),
                    inserter(result, result.end()));
            ans += result.size();
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23168
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  for (int i = 0; i < x; ++i) cin >> a[i];
  for (int i = 0; i < y; ++i) cin >> b[i];
  for (int i = 0; i < z; ++i) cin >> c[i];
  vector<ll> ab;
  for (int i = 0; i < x; ++i) {
    for (int j = 0; j < y; ++j) {
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(ab.begin(), ab.end());
  reverse(ab.begin(), ab.end());
  ab.resize(min(k, (int)ab.size()));
  vector<ll> abc;
  for (int i = 0; i < ab.size(); ++i) {
    for (int j = 0; j < z; ++j) {
      abc.push_back(ab[i] + c[j]);
    }
  }
  sort(abc.begin(), abc.end());
  reverse(abc.begin(), abc.end());
  for (int i = 0; i < k; ++i) {
    cout << abc[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 43368
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll A,B,V,W,T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
    ll dist = abs(B - A);
    ll diff = V-W;
    cerr << dist << ":" << diff << endl;
    if(diff <= 0)
    {
        cout << "NO" << endl;
        return 0;
    }

    double time = 1.0* dist / diff;
    if(time <= T) cout << "YES" << endl;
    else cout << "NO" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3688
n = int(input())

a = 'abcdefghijklmnopqrstuvwxyz'
d = []
for i in range(n):
    tmp = dict()
    for c in a:
        tmp[c] = 0
    d.append(tmp)

for i in range(n):
    s = input()
    for c in s:
        d[i][c]+=1

res = ""
for c in a:
    res += c*min([d[i][c] for i in range(n)])
print(res)




Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String str;
        int i,j,sum;
        int[] num = new int[2];
        int[][] a;
        int[] b;
        str = scan.nextLine();
        String[] x = str.split(" ", 0);
        num[0] = Integer.valueOf(x[0]);
        num[1] = Integer.valueOf(x[1]);
        a = new int[num[0]][num[1]];
        b = new int[num[1]];
        for(i = 0; i < num[0]; i++){
            str = scan.nextLine();
            x = str.split(" ", 0);
            for(j = 0; j < num[1]; j++){
                a[i][j] = Integer.valueOf(x[j]);
            }
        }
        for(j = 0; j < num[1]; j++){
            str = scan.nextLine();
            b[j] = Integer.valueOf(str);
        }
        sum = 0;
        for(i = 0; i < num[0]; i++){
            for(j = 0; j < num[1]; j++){
                sum += a[i][j] * b[j];
            }
            System.out.println(sum);
            sum = 0;
        }
        
        scan.close();
    }
}


Measured memory_bytes: 29920
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 567;
int A[MAXN];

bool check(int N, int K, int ans) {
     int sum = 0;
     vector<int> V;
     for (int i = 0; i < N; i++) {
         int tmp = A[i] % ans;
         if (tmp == 0) continue;
         sum += (tmp);
         V.push_back(ans - tmp);
     }
     sum /= ans;
     int cur = 0;
     sort(V.begin(), V.end());
     for (int i = 0; i < sum; i++) {
         cur += V[i];
     }
     //printf("ans = %d sum = %d cur = %d\n", ans, sum, cur);
     return cur <= K;
}

int main() {
    int N, K;
    int sum = 0;
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        sum += A[i];
    }
    int ans = 1;
    for (LL i = 1; i * i <= sum; i++) {
        if (sum % i) continue;
        if (check(N, K, i)) ans = max(ans, (int)i);
        if (check(N, K, sum / i)) ans = max(ans, (int)(sum / i));
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
# A - Grouping
def main():
    x, y = map(int, input().split())
    g_a = [1, 3 , 5, 7, 8, 10, 12]
    g_b = [4, 6, 9, 11]
    g_c = [2]

    if x in g_a and y in g_a:
        print('Yes')
    elif x in g_b and y in g_b:
        print('Yes')
    elif x in g_c and y in g_c:
        print('Yes')
    else:
        print('No')

if __name__ ==  "__main__":
    main()

Measured memory_bytes: 8968
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	cout<<x+y/2<<endl;
}


Measured memory_bytes: 256
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
void main()
{
    immutable k = readln.chomp.to!size_t;
    auto s = readln.chomp;
    if (k < s.length)
        return "%s...".writefln(s[0..k]);
    else
        return s.writeln;
}


Measured memory_bytes: 2844
N = int(input())
A = list(map(int, input().split()))

S = [0]

sum = 0
for a in A:
    sum += a
    S.append(sum)

import collections

S_count = collections.Counter(S)

ans = 0
from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

for k, v in S_count.items():
    if v >= 2:
        ans += cmb(v, 2)
print(ans)

Measured memory_bytes: 113100
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int v[n],c[n];
    for(int i=0; i<n; i++)
        scanf("%d", &v[i]);

    for(int i=0; i<n; i++)
        scanf("%d", &c[i]);
    int count=0;


    for(int i=0; i<n; i++){
        if(v[i]>c[i])
            count+=v[i]-c[i];
    }

    printf("%d\n", count);
    return 0;
}

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

int main()
{
  int n;
  string s;
  int ans;
  cin >> n >> s;

  rep(i, n) {
    if (s.substr(i, 3) == "ABC") {
      ans++;
    }
  }

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


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

using namespace std;

int ans = 0, ansk = 0;

void d(int a, int b, int c, int deep)
{
	if (a == b && b == c) {
		if (ans == 0 || ans > deep + ansk) {
			ans = deep + ansk;
			return;
		}
	}
	if (deep == 10)return;

	deep++;

	d(a + 1, b + 1, c, deep);
	d(a + 1, b, c + 1, deep);
	d(a, b + 1, c + 1, deep);
	d(a + 2, b, c, deep);
	d(a, b + 2, c, deep);
	d(a, b, c + 2, deep);
}

int main()
{
	int A, B, C;

	cin >> A >> B >> C;

	int m = max(A, max(B, C));

	for (int i = 0; i < 50; i++) {
		if (m >= A + 2) {
			A += 2;
			ansk++;
		}
		if (m >= B + 2) {
			B += 2;
			ansk++;
		}
		if (m >= C + 2) {
			C += 2;
			ansk++;
		}
	}

	d(A, B, C, 0);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
x=-1
y=-1
z=-1
flag=0
N,Y=map(int,input().split())
for i in range(Y//10000+1):
  if i > N:
    continue
  else:
    a=Y-10000*i
    for j in range(a//5000+1):
      if i+j>N:
        continue
      else:
        b=a-5000*j
        if b/1000+i+j==N:
          x=i
          y=j
          z=b//1000
          flag=1
          break
        else:
          continue
    
    if flag:
      break
print(x,y,z)

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
  int a,b,sum;
  
  scanf("%d" ,&a);
  scanf("%d" ,&b);
  
  a -= 1;
  b -= 1;
  
  sum = a*b;
  
  printf("%d", sum);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N, A, B;
  cin >> N >> A >> B;

  ll ans = A * (N / (A + B)) + min(A, N % (A + B));
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	string s, t; cin >> s >> t;
	int ans = 0;
	for( int i = n; i >= 1; --i ){
		if( s.substr(n-i, i) == t.substr(0,i) ){
			ans = max(ans, i);
		}
	}
	cout << 2*n - ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int a,b;
  cin>>a>>b;
  int ans = max(a-2*b, 0);
  cout<<ans<<endl;
  return 0;
}


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

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	double r;
	cin >> r;
	cout << 2 * r * 3.14159265358979323846;
}

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

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";

int A, B, C, D, E, F;
vector<int> water(3001, 0);
vector<int> sugar(3001, 0);

int main() {

    cin >> A >> B >> C >> D >> E >> F;

    for (int i = 0; 100 * A * i <= F; i++) {
        for (int j = 0; 100 * A * i + 100 * B * j <= F; j++) {
            water[100 * A * i + 100 * B * j] = 1;
        }
    }

    for (int i = 0; C * i <= F; i++) {
        for (int j = 0; C * i + D * j <= F; j++) {
            sugar[C * i + D * j] = 1;
        }
    }

    int tempW = 0, tempS = 0;

    for (int w = 0; w <= F; w += 100) {
        if (water[w] == 0) continue;
        for (int s = 0; w + s <= F; s++) {
            if (sugar[s] == 0) continue;
            if ( s <= w / 100 * E  && w + s <= F ) {
                if ( (tempW == 0 && tempS == 0) || s * (tempW + tempS) >= tempS * (w + s) ) {
                    tempW = w;
                    tempS = s;
                }
            }
        }
    }

    cout << (tempW + tempS) << " " << tempS << "\n";
    return 0;
}

Measured memory_bytes: 256