akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n,k;
vector<int>v;
double EPS=1e-9;
double pre[200010],a[200010],sieve[1000001];

int main()
{

double n,m,sum=0,c=0;
cin>>n>>m;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    sum+=a[i];
}
for(int i=0;i<n;i++)
{
    if(a[i]>=sum/(4*m))c++;
}
if(c>=m)cout<<"Yes";
else cout<<"No";
return 0;
}


Measured memory_bytes: 2304
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int odds = (n + 1) / 2;
    int evens = n - odds;

    cout << odds * evens << '\n';


    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll k;
  cin>>k;

  ll cnt=0;
  ll rem=0;
  ll power=7;
  while(true){
    cnt++;
    rem=(rem+power)%k;
    if(rem==0)
      break;

    power=power*10%k;
    if(power==0 || cnt>=1e6+1){
      cnt=-1;
      break;
    }
  }

  cout<<cnt<<endl;
}



Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <cassert>

#include <utility>
using namespace std;

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

void Main()
{
	int W, a, b;
	cin >> W >> a >> b;

	if (a > b)
	{
		swap(a, b);
	}
	
	if (b <= a+W)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << b-(a+W) << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

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

using namespace std;

const int Maxn = 1e2+7;
const int Maxv = 1e5+7;
const int V = 1e5;

int n, W;
long long dp[Maxv];

int main()
{
    cin >> n >> W;
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    for(int i = 1, wi, vi; i <= n; ++i)
    {
        cin >> wi >> vi;
        for(int j = V; j >= vi; --j)
            dp[j] = min(dp[j], dp[j-vi]+wi);
    }
    for(int i = V; i >= 0; --i)
        if(dp[i] <= W)
            return printf("%d\n", i)&0;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define debug cout<<"****************"<<endl
using namespace std;
typedef long long ll;
inline void ju() {
	freopen("***.in","r",stdin);
	freopen("***.out","w",stdout);
}
inline ll rd() {
	ll x=0,f=1; char c=getchar();
	while((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if(c=='-') f=-1,c=getchar();
	while(c>='0'&&c<='9') {
		x=(x<<3)+(x<<1)+c-'0';
		c=getchar();
	}
	return x*f;
}
int a[110];
int main() {
	int n=rd();
	for(int i=1;i<=n;++i) a[i]=rd();
	sort(a+1,a+n+1);
	printf("%d\n",a[n]-a[1]);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int c = 0;

		for(int i = 0; i < n; i++) {
			if(k <= sc.nextInt()) c++;
		}

		System.out.println(c);
	}
}

Measured memory_bytes: 57256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define pb push_back
#define fi first
#define se second
#define Mod 1000000007


int main(){
    ll i,j,k;
    ll n;
    cin>>n;
    long double a[n],b[n];
    for(i=0;i<n;i++){
        ll x;
        cin>>x;
        a[i]=x;
        b[i]=x;
    }

    ll r[n],l[n];
    r[n-1]=0;
    ll r1[n],l1[n];

    stack<ll> s1;

    for(i=n-2;i>=0;i--){
        r[i]=r[i+1];
        if(a[i]<a[i+1]){
            ll w=a[i],w1=a[i+1];
            while(w<=w1){
                w*=4;
                if(w<=w1) s1.push(i);
            }
        }

        while (a[i]>a[i+1]){
            if(!s1.empty()) {
                r[i]+=2*(s1.top()-i);
                s1.pop();
            }
            else r[i]+=2*(n-i-1);
            a[i+1]*=4;
        }
    }
        
    
    stack<ll> s2;

    
    l[0]=1;
    for(i=1;i<n;i++){
        l[i]=l[i-1]+1;
        ll w1=b[i],w2=b[i-1];
        if(w1<=w2){
            while(w1<=w2){
            w1*=4;
            if(w1<=w2) s2.push(i);
            }
        }
        else {
        while (w1>w2){
            if(!s2.empty()) {
                l[i]+=2*(i-s2.top());
                s2.pop();
            }
            else l[i]+=2*i;
            w2*=4;
        }
        }
    }

    ll ans=1e18;
    for(i=1;i<n;i++){
        if(ans>l[i-1]+r[i]) ans=l[i-1]+r[i];
    }
    if(ans>l[n-1]) ans=l[n-1];
    if(ans>r[0]) ans=r[0];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9600
/* 

И пусть меня погубит, то к чему я
Бегу, не жалея ног.
И если мне суждено сгореть на восходе,
Я буду идти вперёд.

*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

const bool dbg_flg = 0;
#define debug(x) if (dbg_flg) cerr << #x << ' ' << x << '\n'
#define debug_pair(x) if (dbg_flg) cerr << #x << ' ' << x.F << ' ' << x.S << '\n' 

const int inf = 1e9 + 7;
const int MAXN = 1e6 + 5;


int n;
ll a[MAXN];
map<ll, bool> was;

void solve() {
	cin >> n;

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

	for (int i = 1; i <= n; i++) {
		if (was[a[i]]) {
			cout << "NO";
			return;
		}
		was[a[i]] = 1;
	}


	cout << "YES";
}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define ll long long
#define LIM 1000
using namespace std;
int main() {
  string s, festival = "FESTIVAL";
  cin >> s;
  cout << s.erase(s.size() - festival.size(), s.size()) << endl;
  return 0;
}


Measured memory_bytes: 256
[N,K]=list(map(int, input().split()))
h=list(map(int, input().split()))

dp=[[0 for i in range(K+1)] for j in range(N)]

for i in range (1,min(N,K)):
    for j in range (0,i):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:i])

for i in range (K,N):
    for j in range (0,K):
        dp[i][j]=dp[i-j-1][K]+abs(h[i-j-1]-h[i])
    dp[i][K]=min(dp[i][0:K])

print(dp[N-1][K])

Measured memory_bytes: 130700
#include"iostream"
#include"fstream"
#include"stack"
#include"string"

using namespace std;

int main(){

	//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1173&lang=jp

	ifstream fin;
	ofstream fout;

	fin.open("input.txt");
	fout.open("output.txt");

	//http://www.cppll.jp/cppreference/cppstack_details.html
	//empty()関数は現在のスタックが空の時にtrueを返し、そうでないときはfalseを返す 

	string a;

	stack<char> s;
	bool yes = true;

	while (true){
		yes = true;

		getline(cin, a);

//		cout << a << endl;

//		if (a[0] == ' ')
//			cout << "ファーーーwww" << endl;
		if (a[0] == '.')break;

		for (int i = 0; i < 100; i++){
			if (a[i] == '(' || a[i] == '['){
				s.push(a[i]);
				yes = false;
			}
			if (a[i] == ')'){
				if (!s.empty()){
					if (s.top() == '('){
						yes = true;
						s.pop();
					}
					else {
						yes = false;
						break;
					}
				}
				else {
					yes = false;
					break;
				}
			}
			if (a[i] == ']'){
				if (!s.empty()){
					if (s.top() == '['){
						yes = true;
						s.pop();
					}
					else {
						yes = false;
						break;
					}
				}
				else {
					yes = false;
					break;
				}
			}
			//			if (!s.empty())
			//				cout << a[i] << "  :  " << s.top() << "  :  " << yes << endl;
			//			else cout << "topエラー" << endl;
			if (a[i] == '.')break;
		}
		if (!s.empty())yes = false;
		while (!s.empty())s.pop();
		if (yes == true){
//			cout << "yes" << endl;
			fout << "yes" << endl;
		}
		else{
//			cout << "no" << endl;
			fout << "no" << endl;
		}
	}
	return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;

    unordered_map<char, char> m1;
    unordered_map<char, char> m2;
    for (int i = 0; i < t.length(); i++) {
        if (m1.count(t.at(i)) != 0 && m1[t.at(i)] != s.at(i)) {
            cout << "No" << endl;
            return 0;
        }
        m1[t.at(i)] = s.at(i);

        if (m2.count(s.at(i)) != 0 && m2[s.at(i)] != t.at(i)) {
            cout << "No" << endl;
            return 0;
        }
        m2[s.at(i)] = t.at(i);
    }

    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

const int MAXN = 1e5 + 5;
const int inf = 1e9;

int a[MAXN], b[MAXN], c[MAXN], DP[MAXN][3], n;

int main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i] >> c[i];
	DP[0][0] = a[0];
	DP[0][1] = b[0];
	DP[0][2] = c[0];
	
	for(int i = 1; i < n; i++)
	{
		DP[i][0] = a[i] + max(DP[i - 1][1], DP[i - 1][2]);
		DP[i][1] = b[i] + max(DP[i - 1][0], DP[i - 1][2]);
		DP[i][2] = c[i] + max(DP[i - 1][0], DP[i - 1][1]);
	}
	cout << max(DP[n - 1][1], max(DP[n - 1][2], DP[n - 1][0]));
	return 0;
}

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

int cnt=0;

int A[1000000];
vector<int> G;
void insertionSort(int A[],int  n, int g){
   
   int v,j;
    for(int i=g;i<n;++i){
        v=A[i];
        j=i-g;
        while(j>=0 && A[j]>v){
            A[j+g]=A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=v;
    }
}
  
  void shellSort(int A[],int n){
      cnt=0;
      int h=1;
      
      while(h<=n){
          G.push_back(h);
          h=3*h+1;
      }
      
      for(int i=G.size()-1;i>=0;--i)
        insertionSort(A,n,G[i]);
      
  }
  
  main(){
      int n;
      cin>>n;
      for(int i=0;i<n;++i)cin>>A[i];
      shellSort(A,n);
      cout<<G.size()<<endl;
       for(int i=G.size()-1;i>=0;--i)
        { cout<<G[i];
         if(i)cout<<" ";
        }
        cout<<endl;
        cout<<cnt<<endl;
          for(int i=0;i<n;++i)
          cout<<A[i]<<endl;
  }


Measured memory_bytes: 7068
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;
    long long int pawer = 1;
    long long int e     = 1000000007;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        pawer = (pawer * i) % e;
    }

    cout << pawer << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main()
{
 while(1){
  int a;
  scanf("%d",&a);
 if(a==0) return 0;
  a=1000-a;
  printf("%d\n",a/500+(a/100)%5+(a/50)%2+(a/10)%5+(a/5)%2+a%5);
 }
}

Measured memory_bytes: 1028
#include <stdio.h>
int main(void){
char s[2];
  scanf("%c",&s);
  if(s[0]=='a'||s[0]=='e'||s[0]=='i'||s[0]=='u'||s[0]=='o'){printf("vowel");}
  else{printf("consonant");}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n;
  cin >> n;
  vi v(n);
  rep(i, n) cin >> v[i];
  sort(all(v));
  out(*(v.end() - 1) - *v.begin());
}
int main(void) { solve(); }

Measured memory_bytes: 3560
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード
ll n,tmp;




int main() {
	cin >> n;
	tmp = n % 10;
	if (tmp == 3) cout << "bon" << endl;
	else if (tmp == 0 || tmp == 1 || tmp == 6 || tmp == 8) cout << "pon" << endl;
	else cout << "hon" << endl;


	return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    int N = inputValue();
    vector<int> d;
    inputVector(&d, N);
    sort(d.begin(), d.end());
    int rslt = d[N/2] - d[N/2-1];
    if(d[N/2] == d[N/2-1])
    {
      rslt = 0;
    }

    cout << rslt << endl;
    
    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
    str S; cin>>S;
    ll ans=0;
    rep1(i,S.size()-1){
        if(S[i]==S[i-1]){S[i]=(char)((1-(ll)(S[i]-'0'))+'0');ans++;}
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()

using namespace std;



int main() {
    int n;
    cin>>n;
    vector<int>h(n);
    rep(i,n)cin>>h[i];

    vector<int>dp(n);
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        if(i>1)dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 3936
import heapq
N=int(input())
a=list(map(int,input().split()))
l=[None]*(N+1)
r=[None]*(N+1)
h=a[:N]
s=sum(h)
heapq.heapify(h)
l[0]=s
for i in range(N):
    heapq.heappush(h,a[i+N])
    s+=a[i+N]-heapq.heappop(h)
    l[i+1]=s
h=list(map(lambda x:-x,a[2*N:]))
heapq.heapify(h)
s=sum(h)
r[-1]=s
for i in range(N):
    heapq.heappush(h,-a[-N-i-1])
    s+=-a[-N-i-1]-heapq.heappop(h)
    r[-i-2]=s
a=l[0]+r[0]
for i in range(1,N+1):
    if a<l[i]+r[i]:
        a=l[i]+r[i]
print(a)

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

void solve()
{
    int n;
    scanf(" %d", &n);

    vector<int> a(n+1),b(n+1);
    int suma=0,sumb=0;
    rep(i,n+1)
    {
        scanf(" %d", &a[i]);
        suma+=a[i];
    }
    rep(i,n+1)
    {
        scanf(" %d", &b[i]);
        sumb+=b[i];
    }

    // ??????
    if(suma!=n || sumb!=n)
    {
        printf("NO\n");
        return;
    }

    int edges=0;
    rep(i,n+1) edges += i*(a[i]-b[i]);

    if(edges!=0)
    {
        printf("NO\n");
        return;
    }

    int in[50],out[50];

    int idx=0;
    rep(i,n)
    {
        while(idx<=n && a[idx]==0) ++idx;

        in[i] = idx;
        --a[idx];
    }

    idx=0;
    rep(i,n)
    {
        while(idx<=n && b[idx]==0) ++idx;

        out[i] = idx;
        --b[idx];
    }
    reverse(out,out+n);

    priority_queue<pi> que;
    rep(i,n)if(in[i]>0) que.push(pi(in[i],i));

    int e[50][50]={};
    rep(i,n)
    {
        vector<pi> poped;

        rep(j,out[i])
        {
            pi v=que.top();
            que.pop();

            int to=v.se;
            e[i][to]=1;
        
            --v.fi;
            if(v.fi>0) poped.pb(v);
        }

        rep(j,poped.size()) que.push(poped[j]);
    }

    // output
    printf("YES\n");
    rep(i,n)
    {
        rep(j,n)
        {
            if(j) printf(" ");
            printf("%d", e[i][j]);
        }
        printf("\n");
    }
}

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

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a+b > c+d) cout << "Left" << endl;
    else if (a+b < c+d) cout << "Right" << endl;
    else cout << "Balanced" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a[35],i,j,n;
	a[1]=1;a[2]=2;a[3]=4;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=4;i<=n;i++)
			a[i]=a[i-1]+a[i-2]+a[i-3];
		printf("%d\n",a[n]/365/10+1);
	}
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	vector<int> arr(n);
	
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int ans = 0;
	for (int i = 0; i < n -1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (ans < abs(arr[i] - arr[j]))
				ans = abs(arr[i] - arr[j]);
		}
	}
	cout << ans << endl;
}

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



int main() {
    int h, w, k;
    cin >> h >> w >> k;
    
    vector<vector<char>> c(h,vector<char>(w));
    rep(i,h) rep(j,w) cin >> c[i][j];
    
    int ans = 0;
    rep(is,1<<h) rep(js,1<<w) {
        int cnt = 0;
        rep(i,h) rep(j,w) {
            if(is>>i & 1)
                continue;
            else if(js>>j & 1)
                continue;
            else if(c[i][j] == '#')
                cnt++;
        }
        if(cnt == k)
            ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}





Measured memory_bytes: 3616
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    dn = list(map(int, args[1].split()))

    s = 0
    for i in range(n):
        for j in range(i+1, n):
            s += dn[i] * dn[j]

    return str(s)


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))


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

const long long MOD = 1000000007;
vector<int> G[100005];
long long ans;
int K;

void dfs(int u,int p,int c, int K) {
	ans = (ans * c) % MOD;
	
	c = K - 1 - (p != -1);
	
	for (int i = 0; i < G[u].size(); i++) {
        int w = G[u][i];
        if (w == p)continue;
		dfs(w, u, c, K);
		c--;
	}
}

int main(){
	int N, K;
	cin >> N >> K;
    ans = 1;
	for(int i = 0; i < N - 1; i++) {
        int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}

	dfs(0, -1, K, K);

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11520
#include<iostream>
using namespace std;
int main(){
  int a,b,n;
  cin>>n>>a>>b;
  int count=0;
  int sum=0;
  int i;
  for(int j=1;j<=n;j++){
    i=j;
    sum=0;
  sum+=i%10;
  i/=10;
  sum+=i%10;
  i/=10;
  sum+=i%10;
  i/=10;
  sum+=i%10;
    i/=10;
    sum+=i;
    if(sum>=a&&sum<=b){
      count+=j;
    }
  }
  cout <<count;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define int long long

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    string s;

    cin >> n >> s;

    ll res = 1;
    int num[30];

    memset(num, 0, sizeof(num));

    REP(i, n)
    num[s[i] - 'a']++;

    REP(i, 26)
    {
        res *= (num[i] + 1);
        res %= MOD;
    }

    cout << res - 1 << endl;

    return 0;
}

Measured memory_bytes: 512
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
C = [input() for _ in range(H)]
for i in range(H):
    print(C[i])
    print(C[i])


Measured memory_bytes: 27152
N=int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
n=0
for i in range(N):
    n+=B[i]
    if i!=0:
        if A[i]-A[i-1]==1:
            n+=C[A[i]-2]

print(n)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  ll n;
  cin>>s>>n;
  ll dp[105][4][2];
  
  memset(dp,0,sizeof(dp));
  dp[0][0][0]=1;
  rep(i,sz(s)){
    rep(j,4){
      rep(z,2){
        rep(u,10){
          ll nd=s[i]-'0';
          ll ni=i+1,nj=j,nz=z;
          if(nz==0&&nd<u) continue;
          if(nz==0&&nd>u) nz=1;
          if(u!=0)nj++;
          if(nj>3) continue;
          dp[ni][nj][nz]+=dp[i][j][z];
        }
      }
    }
  }
  COUT(dp[sz(s)][n][1]+dp[sz(s)][n][0]);
}
      

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll arr[200005] ;
unordered_map <ll, ll> mp ;

int main()
{
    ll n, cnt = 0, limit, flag = 0 ;
    cin >> n ;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &arr[i]) ;
        mp[arr[i]]++ ;
    }
    for (int i = 0; i < n; i++) {
        flag = 0 ;
        mp[arr[i]]-- ;
        for (int j = 1; j * j <= arr[i]; j++) {
            if (arr[i] % j == 0) {
                if (mp[j] > 0 or mp[arr[i] / j] > 0) {
                    flag = 1 ;
                    break ;
                }
            }
        }
        if (!flag)  cnt++ ;
        mp[arr[i]]++ ;
    }
    cout << cnt ;


    return 0 ;
}


Measured memory_bytes: 33468
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n, a, b; cin >> n >> a >> b;
    cout << min(a*n, b) << endl;
}

Measured memory_bytes: 256
if __name__ == "__main__":
    N = int(input())
    cnt = 0
    for _ in range(N):
        d1, d2 = map(int, input().split())
        if d1 == d2:
            cnt += 1
            if cnt == 3:
                print("Yes")
                exit()
        else:
            cnt = 0
    print("No")


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

int main(){
    string SS,S,T;

    cin >> S >> T;
    /*
    bool flag = false;
    rep(i,SS.size()){
        if(flag){
            cout << SS[i];
        }
        if(SS[i] == ' '){
            flag = true;
        }
    }
    rep(i,SS.size()){
        if(flag){
            cout << SS[i];
        }
        if(SS[i] == ' '){
            flag = false;
            break;
        }
    }
    cout << SS;
    */
    cout << T << S << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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 = 1e9;
const long long LINF = 1e18;

bool isMatch(const string& S, int start, const string& T) {
    for (size_t i = 0; i < T.size(); i++) {
        if (start + i >= S.size()) {
            return false;
        }

        if ((S[start + i] != '?') && (S[start + i] != T[i])) {
            return false;
        }
    }
    return true;
}

int main() {
    string S, T;
    cin >> S;
    cin >> T;

    for (int i = S.size() - 1; i >= 0; i--) {
        // cout << "i: " << i << endl;
        if (isMatch(S, i, T)) {
            for (size_t j = 0; j < T.size(); j++) {
                S[i + j] = T[j];
            }


            for (size_t j = 0; j < S.size(); j++) {
                if (S[j] == '?') {
                    S[j] = 'a';
                }
            }

            cout << S << endl;
            return 0;
        }
    }

    cout << "UNRESTORABLE" << endl;

    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
#include<iomanip>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(a, b) make_pair(a, b)
#define mt(a,b,c) make_tuple(a,b,c)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
#define pb push_back
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = (int)2e5+7;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int mod = (int)1e9 + 7;

const int mod1 = (int)1e9 + 9;
const int mod2 = 998244353;
const int mod3 = (int)1e6+3;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

ll fact[N];
ll power(ll x, ll y) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % mod;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % mod; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll n) 
{ 
    return power(n, mod-2); 
} 
  
 
ll nCrModPFermat(ll n, ll r) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
    return (fact[n]* modInverse(fact[r]) % mod * 
            modInverse(fact[n-r]) % mod) % mod; 
}
void initiate(){
    fact[0]=1;
    int i;
	//FIX here
    rep(i,1,N){
        fact[i]=(fact[i-1]*i)%mod;
    }
}




int main()
{   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    initiate();
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=power(2,n)-1;
	ll del=1;
	rep(i,0,a){
		del=(del*(n-i))%mod;
	}
	del=(del*modInverse(fact[a]))%mod;
	ans=(ans-del)%mod;
	del=1;
	rep(i,0,b){
		del=(del*(n-i))%mod;
	}
	del=(del*modInverse(fact[b]))%mod;
	ans=(ans-del)%mod;
	ans=(ans+mod)%mod;
	cout<<ans;

	


             
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
    #define F first
    #define S second
    using ll = long long;
    const ll mod = 1000000007;
    const ll infi = 1000000000000000;
    const ll md = 998244353;
    using namespace std;
    using vl = vector<ll>;
    using pll =  pair<ll,ll>;
     
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        string s,t;
        int ls,lt;
        cin>>s>>t;
        ls = s.size(); lt = t.size();
        vl a[26];
        for(int i=0;i<ls;i++){
            a[s[i]-'a'].push_back(i);
        }
        ll len=0,lst=-1,ans=0;
        for(int i=0;i<lt;i++){
            if(a[t[i]-'a'].size()==0) {
                cout<<-1;
                return 0;
            }
        }
       for(int i=0;i<t.size();i++){
            int indx = t[i]-'a';
            if( upper_bound(a[indx].begin(),a[indx].end(), lst )==a[indx].end()){
                ans+=ls;
                lst = *(upper_bound(a[indx].begin(),a[indx].end(), -1 ));
            }
            else{
                 lst = *(upper_bound(a[indx].begin(),a[indx].end(), lst )) ;
            }
        }
        if(lst!=-1)
        ans+=(lst+1);
        cout<<ans;
        return 0;
    } 

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

int main(){

  int n, a;
  deque<int> dp;

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    if(i % 2 == (n-1) % 2) dp.push_front(a);
    else dp.push_back(a);
  }
  for(int i = 0; i < n; i++){
    cout << dp[i] << ((i == n-1) ? "\n" : " ");
  }
  return 0;
}


Measured memory_bytes: 2944
while 1:
    list1=input().split('"')
    if list1[0]==".":
        break
    list2=input().split('"')
     
    cnt1=0
    cnt2=0
    flag=0
     
    if len(list1)!=len(list2):
        print("DIFFERENT")
    else:
        i=0
        while i<len(list1):
            if list1[i]==list2[i]:
                cnt1+=1
            elif i%2==0:
                print("DIFFERENT")
                flag=1
                break
            else:
                cnt2+=1
                if cnt2>1:
                    print("DIFFERENT")
                    break
            i+=1
                 
        if flag==0 and cnt2==1:
            print("CLOSE")
        if cnt1==len(list1):
            print("IDENTICAL")



Measured memory_bytes: 5580
#include "bits/stdc++.h"
using namespace std;
int main() {
	long k,a,b = 0;
	cin >> k >> a >> b;
	long long ans = 1;

	if(k == 1 || b - a < 2){
		ans += k;
	}else{
		while(ans < a){
			ans++;
			k--;
		}
		while(k > 0){
			if(k > 1){
				ans += b-a;
				k -= 2;
			}else{
				ans++;
				k--;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
auto cmx = [](auto& x, auto y){ if (x<y) { x=y; return true; } return false; };
auto cmn = [](auto& x, auto y){ if (x>y) { x=y; return true; } return false; };
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n;
    std::cin >> n;
    u32 min = 1000, max = 0;
    while (n--) {
        u32 x;
        std::cin >> x;
        cmn(min, x);
        cmx(max, x);
    }
    std::cout << max - min << '\n';
}


Measured memory_bytes: 256
#  --*-coding:utf-8-*--


def genTree(N, E):
    E2 = [set() for _ in range(N+1)]
    for u, v, w in E:
        E2[u].add((v, w))
        E2[v].add((u, w))

    V = [None]*(N+1)
    Q = [1]

    while len(Q) > 0:
        q = Q.pop()
        s = list(filter(lambda x: V[x[0]] == None, E2[q]))

        V[q] = s
        Q.extend(map(lambda x: x[0], s))

    return V


def main():
    N = int(input())
    E = [tuple(map(int, input().split())) for _ in range(N-1)]

    V = genTree(N, E)
    X = [None]*(N+1)

    X[1] = 0
    Q = [1]
    
    while len(Q) > 0:
        q = Q.pop()
        x = X[q]

        for u, w in V[q]:
            X[u] = (x + w)%2

        Q.extend(map(lambda x: x[0], V[q]))

    for x in X[1:]:
        print(x)

        

if __name__ == '__main__':
    main()


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

using namespace std;
//15min
const int N = 55;

const int mod = 1e9+7;

long long s;

long long l(long long    x){
    int cnt = 0;
    while(x){
        cnt++;
        x /= 10;
    }
    return cnt;
}

long long get(int msk){
    long long sum = 0;
    long long sofar = 0;


    long long idx = 0;
    long long tmp = s;
    long long ten = 1;
    //cout << msk << ": ";
    while(tmp){
        sum = (tmp % 10) * ten + sum;
        ten *= 10;
        if(msk & (1 << idx)){
            //cout << sum << " ";
            sofar += sum;
            sum = 0;
            ten = 1;
        }
        idx ++;
        tmp /= 10;
    }
    sofar += sum;
    //cout << sum << "\n";
    return sofar;
}

int main(){
    cin >> s;
    if(s <= 9){
        cout << s << "\n";
        return 0;
    }
    int lg10 = log10(s);
    long long ans = s;
    for(int i = 1; i < (1 << lg10); i++){
        ans += get(i);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3808
n = 50
a = []
n.times{|i|
  a << i
}

k = gets.to_i
b = k / n
c = k % n

a.map!{|t|t+b}
c.times{|i|
  n.times{|j|
    if i==j
      a[j]+=n
    else
      a[j]-=1
    end
  }
}

p n
puts a*' '

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long li;

li Solve(li a, li b) {
  if (a < b) swap(a, b);
  if (a == b) return a;
  li x = (a - 1) / b;
  return x * 2 * b + Solve(b, a - x * b);
}

int main(void) {
  li n, x;
  scanf("%lld %lld\n", &n, &x);
  li ans = n + Solve(x, n - x);
  printf("%lld\n" ,ans);
}


Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
    public static String function(int [][]arr){
        for(int i = 0; i < arr.length - 2; i++){
          if(arr[i][0] == arr[i][1] && arr[i + 1][0] == arr[i + 1][1] && arr[i + 2][0] == arr[i +  2][1])
            return "Yes";
        }
      return "No";
    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
	    try{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		int T= Integer.parseInt(reader.readLine());
        int [][]arr = new int[T][2];
		for(int i = 0; i < T; i++){
		    String []str=reader.readLine().split(" ");
		    arr[i][0]=Integer.parseInt(str[0]);
		    arr[i][1]=Integer.parseInt(str[1]);
		}
        System.out.println(function(arr));
	    }
	    catch( Exception e){
	        return ;
	    }
	}
}

Measured memory_bytes: 32776
#include<stdio.h>
	int main(){
	int N,K,X,Y,t;
	scanf("%d %d %d %d", &N,&K,&X,&Y);
	if(N <= K){
	t = N * X;
	printf("%d\n",t );
	}
	if(N>K){t = K * X + (N-K) * Y;
	printf("%d\n",t );
		}
	return  0;
		}

Measured memory_bytes: 128
x,k,d=map(int,input().split())
#print(x,k,d)

x=abs(x)#正方向スタートで考える
if x-d*k >= 0:#一方向にのみ動かして済むとき
    ans=abs(x-d*k)
else:#往復運動するとき
    k_dash=x//d
    R=x-k_dash*d
    L=R-d

    if (k-k_dash)%2 == 0:#移動できる残り回数を調べる 0:左側 1:右側
        ans=abs(R)
    else:
        ans=abs(L)

print(ans)

Measured memory_bytes: 61916
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 != 0) {
            count++;
        }
    }

    if (count % 2 == 0) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO"  << std::endl;
    }
    return 0;
}

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

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

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

    int n; cin>>n;

    int ans=0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                int gc = gcd(i,j);
                gc = gcd(gc, k);
                ans += gc;
            }
        }
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;
import java.util.HashMap;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextLong();
		long[] a=new long[n];
		HashMap<Long,Integer> map=new HashMap<>();
		long ans = 0;
		a[0]=sc.nextLong();
		for(int i = 1; i<n; i++){
			 a[i] = sc.nextLong()+a[i-1];
		}
		for(int i = 0; i<n; i++){
			if(map.containsKey(a[i]%m)){
				map.put(a[i]%m,map.get(a[i]%m)+1);
			}else{
				map.put(a[i]%m,1);
			}
		}
		for(long i:map.keySet()){
			long q=map.get(i);
			if(i==0){
				ans+=q;
			}
			ans+=(q*(q-1))/2;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 62176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  string s;
  cin >> s;
  for(char c : s) {
    cout << 'x';
  }
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
int d;
int c[30]={};
int s[370][30];
int calc(vector<int>const& t,vector<vector<int>>& last_list){
  int res=0;
  vector<int> last(30,0);
  rep1(i,d){
    res+=s[i][t[i]];
    last[t[i]]=i;
    last_list[i]=last;
    int buf=0;
    rep1(j,26){
      buf+=c[j]*(i-last[j]);
    }
    res-=buf;
    //cout<<res<<"\n";
  }
  return res;
}
int change(int nd,int nq,int& res,vector<int>& t,vector<vector<int>>& last_list){
  int flag_t=false;
  int flag_q=false;
  int x=t[nd];
  t[nd]=0;
  res+=s[nd][nq];res-=s[nd][x];
  for(int i=nd;i<=d;++i){
    if(flag_t&&flag_q)break;
    if(t[i]==x||flag_t)flag_t=true;
    else{
      res+=c[x]*(i-last_list[i][x]);
      last_list[i][x]=last_list[i-1][x];
      res-=c[x]*(i-last_list[i][x]);
    }
    if(t[i]==nq||flag_q)flag_q=true;
    else{
      res+=c[nq]*(i-last_list[i][nq]);
      last_list[i][nq]=nd;
      res-=c[nq]*(i-last_list[i][nq]);
    }
  }
  t[nd]=nq;
  return res;
}
vector<int> greedy(int d){
  vector<int> res(d+1,0);
  vector<int> last(30,0);
  rep1(i,d){
    int mx=-inf;
    int mx_ind=0;
    rep1(j,26){
      int tmp=s[i][j];
      rep1(k,26){
        if(k==j)continue;
        tmp-=c[k]*(i-last[k]);
      }
      if(mx<tmp){
        mx=tmp;
        mx_ind=j;
      }
    }
    last[mx_ind]=i;
    res[i]=mx_ind;
  }
  return res;
}
signed main(){
  cin>>d;
  rep1(i,26)cin>>c[i];
  rep1(i,d){
    rep1(j,26)cin>>s[i][j];
  }
  vector<int> t=greedy(d);
  vector<vector<int>> last_list(d+1,vector<int>(30,0));
  int res=calc(t,last_list);
  rep1(i,d){
    cout<<t[i]<<"\n";
  }
  return 0;
}
/*
int m;cin>>m;
  vector<int> bres(m);
  rep(i,m){
    int d,q;cin>>d>>q;
    bres[i]=change(d,q,res,t,last_list);
  }
  rep(i,m){
    cout<<bres[i]<<"\n";
  }
  */

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int op[2005], n, k;
int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", op + i);
    sort(op + 1, op + n + 1);
    int ans = 0;
    for (int i = 1; i <= k; i++) ans += op[i];
    printf("%d", ans);
    return 0;
}

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

using namespace std;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<pair<int, int>> xs(n);
    int res = h;
    for (int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        xs[i] = {x, y};
    }
    sort(xs.begin(), xs.end());
    int diff = 1;
    for (auto p: xs) {
        if (p.second <= p.first - diff) {
            cout << p.first - 1 << endl;
            goto end;
        } else if (p.second == p.first - diff + 1) {
            diff += 1;
        }
    }
    cout << res << endl;
end:
    return 0;
}



Measured memory_bytes: 1792
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // 重りの数
    int n = sc.nextInt();
    // 重りたち
    int weights[] = new int[n];
    for(int idx=0; idx<n; idx++){
      weights[idx] = sc.nextInt();
    }
    
    // 前後に分けて足していく
    int s1 = 0, s2 = 0;
    int num = 0;
    int right = 0;
    int left = 0;
    while(true){
      /*
      // 残り2個
      if(n - num == 2){
        s1 + weights[left] + 
      }
      // 残り1個
      if(n - num == 1){
        if(s1 > s2){
          s1 += weights[left];
        }
        break;
      }
      */
      
      // 両側から取る
      if(s1 <= s2){
        s1 += weights[left];
        left ++;
        num ++;
      }
      if(num >= n){
        break;
      }
      if(s2 <= s1){
        s2 += weights[n - 1 - right];
        right ++;
        num ++;
      }
      if(num >= n){
        break;
      }
    }
    
    
    // 出力
    if(s1 > s2){
      System.out.println(s1 - s2);   
    }else{
      System.out.println(s2 - s1);   
    }
  }
}


Measured memory_bytes: 21972
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st  = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        
        long ans=0;

        for (int i=1; i<=N; i++) {
            long Y = (long)Math.floor(N/i);
            ans+=(Y)*(Y+1)*i/2;
        }

        System.out.println(ans);

    }

}

Measured memory_bytes: 33020