akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  vi v(n);
  REP(i,n)cin>>v[i];
  sort(ALL(v));
  puts(v.back()<accumulate(v.begin(),v.end()-1,0) ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int n;
  cin >> n;
  int a = n / 100;
  int b = n % 100;
  if (0 < a && a < 13) {
    if (0 < b && b < 13) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  else {
    if (0 < b && b < 13) cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }
}

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

#define mod 1000000007
#define pi 2 * acos(0.0)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
void fun()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

/* DON'T LIMIT YOUR CHALLENGES, CHALLENGE YOUR LIMITS */
void solve()
{
    int n, w;
    cin >> n >> w;

    vector<int> wt(n), val(n);

    for (int i = 0; i < n; i++)
        cin >> wt[i] >> val[i];
    vector<int> dp(w + 1, 0);
    for (int i = 0; i < n; i++)
    {
        for (int j = w; j >= wt[i]; j--)
        {
            dp[j] = max(dp[j], val[i] + dp[j - wt[i]]);
        }
    }

    cout << dp[w];
}

signed main()
{
    fun();
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3972
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a < in.txt > out.txt
*/

//  io
#include <iostream>
//#include <fineam> //http://www.cplusplus.com/reference/fineam/fineam/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
std::ifineam inFile("input.txt");
std::ofineam outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

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

    int n;
    cin >> n;

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

    int maxv = 0;
    int cnt = 0;

    for (int i = 0; i < n - 1; i++)
    {
        if (arr[i] >= arr[i + 1])
        {
            cnt++;
        }
        else
        {
            maxv = max(maxv, cnt);
            cnt = 0;
        }
    }
    maxv = max(maxv, cnt);

    cout << maxv;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=2000;

int main() {
  ll n;
  cin >> n;
  map<string,ll> cnt;
  for(ll i=0;i<n;i++) {
    string s;
    cin >> s;
    cnt[s]++;
  }
  vector<string> a={"AC","WA","TLE","RE"};
  for(ll i=0;i<4;i++) {
    cout << a[i] << " x " << cnt[a[i]] << endl;
  }
}

Measured memory_bytes: 3632
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String str = sc.next();
	HashMap<Character, Integer> map = new HashMap<Character, Integer>();
	for(int i = 0; i<str.length(); i++) {
	    char c = str.charAt(i);
	    int cnt = (map.containsKey(c))?map.get(c):0;
	    map.put(c,cnt+1);
	}
	for(char c: map.keySet()) {
	    if(map.get(c)%2!=0) {
		System.out.println("No");
		return;
	    }
	}
	System.out.println("Yes");
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

typedef std::pair<std::string, int> P;

int n, q;
std::queue<P> que;
int tim;

int main()
{
    std::cin >> n >> q;
    rep( i, n )
    {
        std::string s;
        int t;

        std::cin >> s >> t;

        que.push( P( s, t ) );
    }

    while( !que.empty() )
    {
        P p = que.front(); que.pop();
       
        if( p.second <= q )
        {
            tim += p.second;

            std::cout << p.first << ' ' << tim << std::endl;

            continue;
        }

        tim += q;

        que.push( P( p.first, p.second-q ) );
    }

    return 0;
}

Measured memory_bytes: 6332
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main(){
  int n,p=1;
  cin>>n;
  map<int,int> m;
  for(int i=0,a;i<n;++i){
    cin>>a;
    if(++m[a]>2 || (m[a]==2 && a==0) || (n%2 == a%2))return cout<<0,0;
    if(m[a]==2)p=p*2%mod;
  }
  cout<<p;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	vector<ll> cnt(100001,0);
	set<int> st;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		st.insert(a[i]);
		cnt[a[i]]++;
	}
	ll even=0;
	for(ll i=1;i<=100000;i++)
	{
		if(cnt[i]>0 and cnt[i]%2==0)
			even++;
	}
	if(even%2==0)
	{
		cout<<st.size();
	}
	else
		cout<<st.size()-1;
	return;
}

int main()
{
	fast;
	ll q=1;
	// cin>>q;
	while(q--)
		solve();
	return 0;
}



Measured memory_bytes: 9476
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    w,h,x,y=map(int,input().split())
    if x==w/2 and y==h/2:
        print(w*h/2,1)
    else:
        print(w*h/2,0)

if __name__=='__main__':
    main()

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

using namespace std;
const int N = 1e5 + 6;
int cnt[N];

int main() {
  int n;
  scanf("%d", &n);
  vector< int > v;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  bool ok = 0;
  int ans = n;
  for (int i = 0; i < v.size(); i++) {
    int x = v[i];
    // cerr << x << " " << cnt[x] << endl;
    while (cnt[x] >= 3) {
      cnt[x] -= 2;
      ans -= 2;
    }
    if (cnt[x] > 1) {
      if (ok) {
        ok = 0;
        ans -= 2;
      }
      else
        ok = 1;
    }
    // cerr << ans << endl;
  }
  if (ok)
    ans -= 2;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7;
const double PI = acos(-1);

bool isprime[1000100]={};
vector<int> primos;

void sieve(){
    isprime[0] = isprime[1] = true;
    primos.push_back(2);
    for (int i=3; i<1010; i+=2){
        if (!isprime[i]){
            primos.push_back(i);
            for (int j=i*i, k = (i << 1); j<=1000100; j+= k){
                isprime[j] = true;
            }
        }
    }

    for (int i=1011; i<1000100; i+=2){
        if (!isprime[i]) primos.push_back(i);
    }
}
 
 
int main (){
    ll n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;

    string t, v[100100];
    cin >> t;

    for (int i=0; i<n; i++){
        v[i%k]+=t[i];
    }

    ll ans = 0;

    for (int i=0; i<k; i++){
        // cout << v[i] << endl;
        char last = v[i][0];
        for (int j=0; j<(int)v[i].size(); j++){
            int val;
            char c = v[i][j];
            if (c == 'p') val = s;
            if (c == 'r') val = p;
            if (c == 's') val = r;

            ans += val;
            if (j > 0 and c == last) {
                ans-=val;
                last = '.';
            }
            else last = c;
        }
    }

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

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    if ( s.length() <= k )
    {
        cout<<s<<endl;
    }
    else
    {
       string ans = s.substr(0,k);

        ans += "...";
        cout<<ans<<endl; 
    }
    
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



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

int main()
{
    int h, w;
    char m[100][100];
    bool b[100][100];

    while( cin >> h >> w )
    {
        if( h == 0 && w == 0 )
            break;

        for( int i = 0; i < h; i++ )
            for( int j = 0; j < w; j++ )
            {
                m[i][j] = '.';
                b[i][j] = false;
            }
        for( int i = 0; i < h; i++ )
            for( int j = 0; j < w; j++ )
                cin >> m[i][j];

        int i = 0, j = 0;
        while( m[i][j] != '.' && b[i][j] != true )
        {
            b[i][j] = true;
            if( m[i][j] == '>' )
                j++;
            else if( m[i][j] == '<' )
                j--;
            else if( m[i][j] == '^' )
                i--;
            else if( m[i][j] == 'v' )
                i++;
            else;
        }
        if( b[i][j] == false )
            cout << j << " " << i << endl;
        else
            cout << "LOOP" << endl;
    }    

    return 0;
}


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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int maxn = 1e5 + 5;
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

set<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	set<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.insert(i);
	}
	return primes;
}
set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		// int count = 0;
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}

int power(int x, unsigned int y, int p)
{
	int res = 1;

	x = x % p;

	if (x == 0) return 0;
	;
	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;

		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;

}


// Graph------------------------------------------------------------------------


int32_t main()
{
	FIO;
	// c_p_c();
	// --------------------------------------------------
	// Never GIVE UP !!!!
	int n;
	cin >> n;
	vi v(n);
	int s = 0;
	for (int&x : v)
	{
		cin >> x;
		s += x;
	}
	int ans = 0;
	for (int x : v)
	{
		int sum = (s - x) % mod;
		ans += (x * sum);
		ans %= mod;
		s -= x;
	}
	cout << ans << endl;

}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,a,b;
  cin >> x >> a >> b;
  cout << (x-a)%b << endl;
}


Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));
for($i = 0; $i < $n; $i++){
    $map[] = intval(fgets(STDIN));
}
$current = 0;
$count = 0;
while(true){
    $prev = $current;
    if($map[$current] == -1)break;
    $current = $map[$current] - 1;
    $map[$prev] = -1;
    $count++;
    if($current == 1){
        echo $count;
        exit;
    }
}
echo -1;

Measured memory_bytes: 11256
import java.util.Scanner;

public class Main {
	public static void main(String[] age){
		Scanner G = new Scanner(System.in);
		String imput = G.nextLine();
		String[] imputarray = imput.split(" ");
		StringBuilder sb = new StringBuilder();
		double a = Integer.parseInt(imputarray[0]);
		double b = Integer.parseInt(imputarray[1]);
		double c = a/b;
		double d = a%b;
		int f = (int)c;
		int g = (int)d;
		double e = a/b;
		String reale = String.format("%.5f", e);
		sb.append(Integer.toString(f)).append(" ").append(Integer.toString(g)).append(" ").append(reale);
		System.out.println(sb);
	}
}

Measured memory_bytes: 26284
x1, y1, x2, y2 = gets.chomp.split(' ').map(&:to_i)
x3 = x2 + y1 - y2
y3 = y2 + x2 - x1
x4 = x3 + x1 - x2
y4 = y3 + y1 - y2
puts "#{x3} #{y3} #{x4} #{y4}"


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int N,M,X;
int C[12],A[12][12];
int main()
{
	cin>>N>>M>>X;
	for(int i=0;i<N;i++)
	{
		cin>>C[i];
		for(int j=0;j<M;j++)cin>>A[i][j];
	}
	int ans=1e8;
	for(int i=0;i<1<<N;i++){int now[12]={};int sum=0;for(int j=0;j<N;j++)if(i>>j&1){sum+=C[j];for(int k=0;k<M;k++)now[k]+=A[j][k];}bool flag=true;for(int j=0;j<M;j++)if(now[j]<X)flag=false;if(flag&&ans>sum)ans=sum;}
	cout<<(ans>1e7?-1:ans)<<endl;
}



Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		out(ni() * ni() % 2 == 0 ? "Even" : "Odd");

	}

	/*
	 * 以下メソッド集
	 */

	public static int[] kousokusoinnsuubunkaihairetsu(int a) {
		int[] d = new int[a];
		for (int i = 0; i < a; i++) {
			d[i] = i;
		}
		for (int i = 2; i * i < a; i++) {
			for (int j = i * i; j < a; j += i) {
				if (d[j] == j)
					d[j] = i;
			}

		}

		return d;
	}

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

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

	static int gcd(int a, int b) {

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

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int w;
	int d;

	XY(int h, int w, int d) {
		this.h = h;
		this.w = w;
		this.d = d;
	}
}

class NE {

	int n;
	int e;

	NE(int n, int e) {
		this.n = n;
		this.e = e;
	}
}

Measured memory_bytes: 35840
N,M=map(int,input().split())
shop=[]
for _ in range(N):
    a=list(map(int,input().split()))
    shop.append(a)
shop.sort(key=lambda x: x[0])
cnt=0
p=0
i=0

while cnt<M:
    a=shop[i][0]
    b=shop[i][1]
    cnt+=b
    p+=a*b
    i+=1
su=cnt-M

a = shop[i-1][0]
p-=a*su
print(p)


Measured memory_bytes: 29024
#include <bits/stdc++.h>
 
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define int long long
struct IoSetup {
IoSetup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
}IoSetup;
static const signed int SMOD = 1000000007;
 
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}
 
int n;
 
vector<int> edge[100100];
 
int dp[100100][5];
 
void dfs(int u, int pr) {
dp[u][0] = dp[u][1] = 1;
for(int i = 0; i < edge[u].size(); i++) {
int v = edge[u][i];
if(v == pr) continue;
dfs(v, u);
dp[u][0] = dp[u][0] * (dp[v][0]+dp[v][1]) % SMOD;
dp[u][1] = dp[u][1] * dp[v][0] % SMOD;
}
}
 
signed main() {
 
cin >> n;
 
for(int i = 0; i < n-1; i++) {
int a, b;
cin >> a >> b;
edge[a].bash(b);
edge[b].bash(a);
}
 
dfs(1, 0);
 
cout << (dp[1][0] + dp[1][1]) % SMOD << endl;
 
 
 
return 0;
}

Measured memory_bytes: 16640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> dis(n,0);
  rep(i,n-1) {
    dis[i] = abs(a[i] - a[i+1]);
  }
  dis[n-1] = abs(a[n-1] - k) + a[0];
  ll ans = 0;
  ll ma=0;
  rep(i, n) {
    ans += dis[i];
    ma = max(ma, dis[i]);
  }
  ans -= ma;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <math.h>

#define mp                  make_pair
#define F                   first
#define S                   second
#define pb                  push_back
#define FOR(i,j,n)          for(int i=j;i<n;i++)
#define F0R(i,j,n)          for(int i=j;i<=n;i++)
#define RFOR(i,j,n)         for(int i=n-1;i>=j;i--)
#define RF0R(i,j,n)         for(int i=n;i>=j;i--)
#define FOREACH(x,v)        for(auto x:v)
#define ITFOR(it,v)         for(v::iterator it =v.begin();it!=v.end();++it)
#define __in_arr__(a,j,n)   FOR(i,j,n)cin >> a[i];
#define __out_arr__(a,j,n)  FOR(i,j,n)cout << a[i];
#define LOG                 cout << "[ !" << __LINE__ << "L ] " << endl;
#define PLOG(x)             cout << "[ !" << __LINE__ << "L ] " \<<x<<endl;

using namespace std;

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

const int MAXN = 210;
const int INF = 5e9+10;
vii g[MAXN];
int dis[MAXN][MAXN];
int ro[MAXN];
int tmp[MAXN];

int brute_force(int x,bool*mark,int n,int ans,int prev) {
    if(x> n)
        return ans;
    int a = INF;
    FOR(i,0,n) {
        if(mark[i]) continue;
        mark[i] = true;
        a = min(a,brute_force(x+1,mark,n,ans+dis[ro[i]][prev],ro[i]));
        mark[i] = false;
    }
    return a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,m,r;
    cin >> n >> m >> r;
    FOR(i,0,r)
        cin >> ro[i];
    FOR(i,0,m) {
        int x,y,z;
        cin >> x >> y >> z;
        g[x].pb(mp(y,z));
        g[y].pb(mp(x,z));
    }
    F0R(i,1,n) { 
        fill(tmp,tmp+1+n,INF);
        tmp[i] = 0;
        FOR(j,0,n) {
            int mn = INF,pos = 0;
            F0R(k,1,n)
                if(tmp[k]>-1 && tmp[k] < mn)
                    mn = tmp[k],pos = k;
            if(!pos)break;
            dis[i][pos] = tmp[pos];
            tmp[pos] = -1;
            for(auto w : g[pos])
                tmp[w.F] = min(tmp[w.F],w.S+dis[i][pos]);
        }
    }
    bool mark[9];
    fill(mark,mark+9,false);
    cout << brute_force(1,&mark[0],r,0,0) << endl;
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cmath>

#define int long long

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

int x;

signed main(){
	x=read();
	for(int i=-1000;i<=1000;++i)
	for(int j=-1000;j<=1000;++j)
	if(pow(i,5)-pow(j,5)==x){
		printf("%lld %lld\n",i,j);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 2472
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int dollar = scn.nextInt();
        int cake =4;
        int donut=7;
        int outFlag=0;
        for(int i=0;i<26;i++){
            for(int j=0;;j++){
                int total = cake*i+donut*j;
                if(total==dollar){
                    outFlag++;
                    break;
                }else if(total>dollar){
                    break;
                }
            }
        }
        if(outFlag>0){
            System.out.println("Yes");
        }else{
            System.out.print("No");
        }

    }
}

Measured memory_bytes: 22868
n=int(input())
A=list(map(int,input().split()))
sum_A=sum(A)

if n==0 and A[0]==1:print(1);exit()
if n==0 and A[0]==0:print(-1);exit()
if A[0]!=0:print(-1);exit()

flag=0
ans,point=[1],1
for i in range(1,n+1):
    if point<=0 or sum_A<=0:print(-1);exit()
    if flag==0:
        point *=2
    if point>=sum_A:
        point=sum_A
        flag=1
    ans.append(point)
    point -=A[i]
    sum_A -=A[i]
if sum_A!=0 or point!=0:print(-1);exit()
print(sum(ans))

Measured memory_bytes: 83540
#include <cstdio>
#include <iostream>

using namespace std;

int n_ALDS14D, k_ALDS14D;

//5 3
//8
//1
//7
//3
//9

bool checkWeight(int W[], int p) {

	int j = 0;
	for (int i = 0; i < k_ALDS14D; ++i) {
		int w = 0;
		while (w + W[j] <= p) {
			w += W[j];
			++j;
			if (j == n_ALDS14D) {
				return true;
			}
		}
	}
	return false;
}

int main() {
	int MAX_WEIGHT = 1000000000;
	int W[100000];

	scanf("%d", &n_ALDS14D);
	scanf("%d", &k_ALDS14D);

	for (int i = 0; i < n_ALDS14D; ++i) {
		scanf("%d", &W[i]);
	}

	int P = 0;

	int left = 0;
	int right = MAX_WEIGHT;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (checkWeight(W, mid)) {
			P = mid;
			right = mid;
		} else {
			left = mid + 1;
		}
	}

	cout << P << endl;

	return 0;
}

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

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

	int h, w;
	cin >> h >> w;

	vector<string> grid(h);
	for(int i=0; i<h; ++i)
		cin >> grid[i];

	string s = string(w, '.');
	for(int i=1; i<h-1; ++i){
		if(grid[i-1] == s && grid[i] == s && grid[i+1] == s){
			grid.erase(grid.begin() + i);
			-- i;
			-- h;
		}
	}

	int ret = 0;
	for(;;){
		bool ok = true;
		for(int i=0; i<h; ++i){
			for(int j=0; j<w; ++j){
				if(grid[i][j] != '.')
					continue;

				map<char, pair<int, int> > m;

				for(int k=0; k<4; ++k){
					int y = i;
					int x = j;
					while(y >= 0 && y < h && x >= 0 && x < w && grid[y][x] == '.'){
						y += dy[k];
						x += dx[k];
					}
					if(y >= 0 && y < h && x >= 0 && x < w){
						char c = grid[y][x];
						if(m.find(c) != m.end()){
							grid[y][x] = '.';
							grid[m[c].first][m[c].second] = '.';
							ret += 2;
							ok = false;
						}else{
							m[c] = make_pair(y, x);
						}
					}
				}
			}
		}
		if(ok)
			break;
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll A[100000];
string op[100000];
ll dp[100000][3];
int main() {
	int N;
	cin >> N;
	cin >> A[0];
	for (int i = 1; i < N; i++) {
		cin >> op[i - 1];
		cin >> A[i];
	}
	fill((ll*)dp, (ll*)(dp + N), -(1LL << 60));
	dp[0][0] = A[0];
	for (int i = 0; i + 1 < N; i++) {
		for (int j = 0; j <= 2; j++) {
			if (dp[i][j] == -(1LL << 60)) continue;
			for (int k = 0; k <= j; k++) {
				if (op[i] == "+") {
					dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + A[i + 1] * (k % 2 == 0 ? 1 : -1));
				}
				else if (k <= 1) {
					dp[i + 1][k + 1] = max(dp[i + 1][k + 1], dp[i][j] + A[i + 1] * (k % 2 == 0 ? -1 : 1));
				}
			}
		}
	}
	ll ans = max(dp[N - 1][0], dp[N - 1][1]);
	ans = max(ans, dp[N - 1][2]);
	cout << ans << endl;
}

Measured memory_bytes: 8832
import java.util.*;
import java.math.BigInteger;
 
public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();

        List<Long> list = new ArrayList<Long>();
        for (int i = 0; i < n; i++) {
            long a = scan.nextLong();
            list.add(a);
        }

        Collections.sort(list);//System.out.println(list);
        // listの先頭が0だったら、0を出力して即終了
        if (list.get(0) == 0) {
            System.out.println(0);
            return;
        }

        /*
        * 1. BigIntegerクラスを用いて、オーバーフローが起きないようにする。
        BigInteger ans = BigInteger.ONE;
        boolean isOver = false;
        for (int i = 0; i < n; i++) {
            ans = ans.multiply(BigInteger.valueOf(list.get(i)));
            if (ans.compareTo(BigInteger.valueOf(1000000000000000000l)) > 0) {
                isOver = true;
                break;
            }
        } 
        

        if (isOver) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
        */


        // 2. multiplyExactメソッド（オーバーフローすると例外送出）を利用する方法。
        long ans = 1l;
        boolean isOver = false;
        try {
            for (int i = 0; i < n; i++) {
                long a = list.get(i);
                ans = Math.multiplyExact(ans, a);
                if (ans > 1000000000000000000l) {
                    isOver = true;
                    break;
                }
            } 
        } catch (ArithmeticException e) {
            isOver = true;
        }
        
        if (isOver) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
        
        /* 
        * 3. オーバーフローすると、負の数や0になる可能性があることを考慮して場合わけする。
        long ans = 1l;
        for (int i = 0; i < n; i++) {
            long a = list.get(i);
            ans *= a;
            if (ans > 1000000000000000000l || ans <= 0) {
                break;
            }
        }
        if (ans > 1000000000000000000l || ans <= 0) {
            //System.out.println(ans);
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
        */
        
        /*
        * 公式の模範解答を真似たけど、WA
        long ans = 1l;
        boolean isOver = false;
        for (int i = 0; i < n; i++) {
            long a = list.get(i);            
            if (Math.floor(10E+18 / ans) <= a) {
                isOver = true;
                break;
            } else {
                ans *= a;
            }
        }
        if (isOver) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
        */

    }
}

Measured memory_bytes: 61240
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio;
    string s,s2,s3;
    int a,b,x,c,count=0;
    cin>>a>>b>>c>>x;
    if((abs(a-b)<=x && abs(b-c)<=x) || abs(a-c)<=x){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return(0);
}

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

int main(){
    vector<set<int>> island(200002, set<int>());
    int N, M;
    int a, b;
    bool flag = false;

    cin >> N >> M;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        island[a].insert(b);
        island[b].insert(a);
    }

    set<int> start = island[1];
    for(auto s: start){
        if(island[s].find(N) != island[s].end()){
            flag = true;
        }
    }

    if(flag){
        cout << "POSSIBLE" << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 33024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

ll n ;
string s = "Aabcdefghij";
string t = "a";
void func(ll cnt, string a){
    ll MAX = 1;
    for(ll i = 0; i < a.length(); i++){
        char d = a[i];
        ll e = d-96;
        MAX = max(MAX, e);
    }
    if(cnt < n){
        for(ll i = 1; i <= MAX+1; i++){
            string c = a + s[i];
            func(cnt+1, c);
        }
    }
    if(cnt == n)
        cout << a << endl;
}

int main(void){
    cin >> n;
    func(1, t);
    return 0;
}


Measured memory_bytes: 1536
w,b = gets.split.map(&:to_i)

if w == 1 && b == 1
  puts "1 2",".#"; exit
end

w0,b0 = w,b
if b0 > 1
  w -= 1
end
if w0 > 1
  b -= 1
end

puts "#{((w-1)/50 + 1)*2 + ((b-1)/50 + 1)*2} 100"
while w > 0
  k = [w, 50].min
  puts (".#" * k) + ("##" * (50-k))
  puts "##" * 50
  w -= 50
end
while b > 0
  k = [b, 50].min
  puts ".." * 50
  puts (".#" * k) + (".." * (50-k))
  b -= 50
end



Measured memory_bytes: 1788
#include <cstdio>
#include <vector>
#include <cstring>
#include <functional>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <queue>
#include <assert.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <complex>
#include <numeric>
#include <map>
#include <time.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<int,ull> piu;
typedef pair<ull,ull> puu;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pii,ll> ppl;
typedef pair<ll,pii> plp;
typedef pair<ll,pll> plP;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<double,int> pdi;
typedef pair<int,double> pid;
typedef pair<double,pii> pdp;
typedef pair<double,double> pdd;
typedef pair<pdd,double> pd3;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
#define repn(i,a,n) for (int (i) = (a); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SORT(x) sort((x).begin(),(x).end())
#define SORTN(x,n) sort((x),(x)+(n))
#define ERASE(x) (x).erase(unique((x).begin(),(x).end()),(x).end())
#define COUNT(x,c) count((x).begin(),(x).end(),(c))
#define REMOVE(x,c) (x).erase(remove((x).begin(),(x).end(),(c)),(x).end())
#define REVERSE(x) reverse((x).begin(),(x).end())
#define FORIT(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))-(x).begin()
#define lb(x,a) lower_bound((x).begin(),(x).end(),(a))
#define LBN(x,a,n) lower_bound((x),(x)+(n),(a))-(x)
#define lbN(x,a,n) lower_bound((x),(x)+(n),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))-(x).begin()
#define ub(x,a) upper_bound((x).begin(),(x).end(),(a))
#define BS(x,a) binary_search((x).begin(),(x).end(),(a))
#define BS2(x,n,a) binary_search((x),(x)+(n),(a))
#define NB(x) (((x)&~((x)+((x)&-(x))))/((x)&-(x))>>1)|((x)+((x)&-(x)))
#define NP(x) next_permutation((x).begin(),(x).end())
#define MM(x,p) memset((x),(p),sizeof(x))
#define SQ(x) (x)*(x)
#define SC(c1,c2) strcmp(c1,c2)==0
#define mp make_pair
#define INF (1<<29)
#define INFL (1LL<<61)
#define fi first
#define se second
#define EPS 1e-9
#define MOD 1000000007
#define MIN(x,a) x=min(x,a)
#define MAX(x,a) x=max(x,a)
#define madd(x,a) x=(x+a)%MOD
#define msub(x,a) x=(x+MOD-a)%MOD
#define OUTPUT(x) rep(__,x.size())printf("%d%c",x[__],__+1==x.size()?'\n':' ')

string s;

int main()
{
	cin>>s;int c=0;
	rep(i,s.size())c+=s[i]=='1';
	printf("%d\n",c);
}

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

int main(){
  string str;
  cin >> str;

  int l = str.size();

  vector<char> vec;
  for(int i = 0; i < l; i ++){
    vec.push_back(str.at(i));
  }

  int count = 0;
  vector<int> vec_count;

  for (int i = 0; i < l; i ++){
    if(vec.at(i) == 'A' || vec.at(i) == 'C') count ++;
    else if(vec.at(i) == 'G' || vec.at(i) == 'T') count ++;
    else {
      vec_count.push_back(count);
      count = 0;
      continue;
    }
  }

  vec_count.push_back(count);

  sort(vec_count.begin(),vec_count.end());
  reverse(vec_count.begin(),vec_count.end());

  cout << vec_count.at(0)<<endl;
  
}

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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if (a*b % 2 == 0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
int n, a[100000][3], dp[100000][4];
int calc(int i, int prev) {
	if (i == n) return 0;
	if (dp[i][prev] != -1) return dp[i][prev];
	int res = 0;
	for (int j = 0; j < 3; j++) {
		if (j == prev) continue;
		res = max(res, calc(i + 1, j) + a[i][j]);
	}
	return dp[i][prev] = res;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]);
	}
	memset(dp, -1, sizeof(dp));
	int ans = calc(0, 3);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 9216
def solve(string):
    n, *a = map(int, string.split())
    a = sorted([_a - i - 1 for i, _a in enumerate(a)])
    median = a[len(a) // 2]
    return str(sum([abs(_a - median) for _a in a]))


if __name__ == '__main__':
    print(solve("\n".join([input(), input()])))


Measured memory_bytes: 28048
#include <iostream>
using namespace std;
typedef long long ll;
const int N=60;

int n;
int d[N];

int main()
{
	cin>>n;
	for(int i=1; i<=n; i++) cin>>d[i];
	int sum=0;
	for(int i=1; i<=n; i++)
		for(int j=i+1; j<=n; j++)
			sum+=d[i]*d[j];
	
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

bool comp(pair<long long, long long> a, pair<long long, long long> b){
    return (a.second+a.first > b.second+b.first) || ((a.second+a.first >= b.second+b.first) && a.first>b.first);
}
int main(void){
    int n;
    cin >> n;
    long long sum=0,j,turn=1;
    vector< pair<long long, long long> > a(n);
    for(int i=0; i<n; i++){
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(),a.end(),comp);
    for(int i=0; i<n; i++){
        j=i;
        while(j+1<n && a[j+1].first+a[j+1].second==a[i].first+a[i].second){
            j++;
        }
        for(int k=0; i+k<=j-k; k++){
            if(i+k==j-k){
                if(turn==1)sum+=a[i+k].first;
                else sum-=a[j-k].second;
                turn*=-1;
            }else sum+=a[i+k].first-a[j-k].second;
        }
        i=j;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
typedef std::pair<ll, ll> pr;
int s[maxn][2], c[maxn][2];
int n;
std::vector<pr> v[maxn];
inline void dfs(int x, ll o) {
	if(!*s[x]) return void(v[x] = {{0, 0}});
	dfs(s[x][0], o), dfs(s[x][1], o);
	std::vector<pr> & v0 = v[s[x][0]], & v1 = v[s[x][1]], vc;
	for(pr&i : v0) i.first += c[x][0], i.second += c[x][0];
	for(pr&i : v1) i.first += c[x][1], i.second += c[x][1];
	const auto cmp = [](const pr & x, const pr & y) { return x.second > y.second; };
	for(pr&i : v0) {
		auto it = std::lower_bound(v1.begin(), v1.end(), pr(0, o - i.second), cmp);
		if(it != v1.end()) vc.push_back(pr(i.first, it -> first));
	}
	int idx = vc.size();
	for(pr&i : v1) {
		auto it = std::lower_bound(v0.begin(), v0.end(), pr(0, o - i.second), cmp);
		if(it != v0.end()) vc.push_back(pr(i.first, it -> first));
	}
	std::inplace_merge(vc.begin(), vc.begin() + idx, vc.end()); v[x].clear(); 
	for(pr&i:vc) if(v[x].empty() || i.second < v[x].back().second) v[x].push_back(i);
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 2;i <= n;++i) {
		int f, v;
		cin >> f >> v;
		if(*s[f]) s[f][1] = i, c[f][1] = v;
		else s[f][0] = i, c[f][0] = v;
	}
	ll l = -1,r = 1e12;
	for(;l + 1 != r;) {
		ll mid = l + r >> 1;
		dfs(1, mid);
		if(v[1].size()) r = mid;
		else l = mid;
	}
	cout << r << '\n';
}


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

int main(int argc, char const *argv[]) {
    int K, X, num_max = 1000000;
    cin >> K >> X;

    int max, min;
    
    if (X+K-1 < num_max) {
        max = X+K-1;
    } else {
        max = num_max;
    }

    if (X-K+1 > -num_max) {
        min = X-K+1;
    } else {
        min = -num_max;
    }

    for (int i = min; i <= max; i++) {
        if (i != max) {
            cout << i << ' ';
        }
        else {
            cout << i << endl;
        }
    }

    return 0;
}


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

int main(){
	int K, S, i, j, k, ans = 0;
	scanf("%d%d", &K, &S);
	for(i = 0; i <= K; i++){
		for(j = 0; j <= K; j++){
			k = S - i - j;
			if(0 <= k && k <= K){
				ans++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    string str;
    cin>>str;
    bool n=str.find("N")!=string::npos;
    bool w=str.find("W")!=string::npos;
    bool e=str.find("E")!=string::npos;
    bool s=str.find("S")!=string::npos;
    bool can1=(n==s); // N もしくは Sが両方存在するのか
    bool can2=(w==e); // W もしくは Eが両方存在するのか
    if(can1 == true && can2==true){cout<<"Yes"<<endl;}
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3600
//| #######################|
//|  ADARSH SINGH KUSHWAHA |
//| ###################### | 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Bahut_tej ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frb(i, a, b) for(ll i = a - 1; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define mp map<ll,ll>
#define v vector<ll>
#define srt(v) sort(v.begin(),v.end())
#define mod 1000000007 
#define max 1000001
bool prime[max];
void seive(){
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(int i=2;i*i<=max;i++){
        if(prime[i]){
            for(int j=i*i;j<=max;j+=i){
                prime[j]=false;
            }
        }
    }
}
void solve(){
    int n,x,t,k;
    cin>>n>>x>>t;
    if(n%x==0){
        k=n/x;
    }else{
        k=(n/x)+1;
    }
    cout<<k*t<<endl;
}
int main() {
    Bahut_tej;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif  
        //int t;
        //cin>>t;
        //while(t--){
            solve();
        //}
        return 0;
    }

Measured memory_bytes: 3648
# ABC053D
import collections

N = int(input())
A = list(map(int, input().split()))
a = collections.Counter(A)
a = a.most_common()
cnt = 0
for i in range(len(a)):
    if a[i][1] % 2 == 0:
        cnt += 1
if cnt % 2 == 0:
    print(len(a))
else:
    print(len(a) - 1)

Measured memory_bytes: 21980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

ll N;
 
int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,0,n) cin >> d[i];
    sort(d.begin(), d.end());
    cout << d[(n+1)/2] - d[(n+1)/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
from collections import deque
H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh, Dw = map(int, input().split())
Dh -= 1
Dw -= 1
S = []
for _ in range(H):
    S.append(input())
P = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            P[i][j] = -1
P[Ch][Cw] = 1
P[Dh][Dw] = 100
yudlr = [0, 0, 1, -1]
xudlr = [1, -1, 0, 0]
D = deque()
Q = deque()
Q.append([Ch, Cw])
c = 0
while len(Q) > 0 or len(D) > 0:
    while len(Q) > 0:
        q = Q.popleft()
        y, x = q[0], q[1]
        for i in range(4):
            y1 = y + yudlr[i]
            x1 = x + xudlr[i]
            if y1 < 0 or y1 >= H or x1 < 0 or x1 >= W:
                continue
            if P[y1][x1] == 100:
                print(c)
                sys.exit()
            if P[y1][x1] == -1 and P[y][x] == 1:
                D.append([y, x])
                P[y][x] = 2
                continue
            if P[y1][x1] != 0:
                continue
            Q.append([y1, x1])
            P[y1][x1] = 1
    c += 1
    while len(D) > 0:
        d = D.popleft()
        y, x = d[0], d[1]
        for i in range(-2, 3):
            for j in range(-2, 3):
                y1 = y + i
                x1 = x + j
                if y1 < 0 or y1 >= H or x1 < 0 or x1 >= W:
                    continue
                if P[y1][x1] == 100:
                    print(c)
                    sys.exit()
                if P[y1][x1] != 0:
                    continue
                Q.append([y1, x1])
                P[y1][x1] = 1
print(-1)

Measured memory_bytes: 92824
<?php
  $ac=0;
  $wa=0;
  $tle=0;
  $re=0;
  fscanf(STDIN,"%d",$N);
  for($h=0;$h<$N;$h++){
    fscanf(STDIN,"%s",$s);
    if($s=="AC")$ac++;
    elseif($s=="WA")$wa++;
    elseif($s=="TLE")$tle++;
    elseif($s=="RE")$re++;
  }
  
  echo "AC x ".$ac."\n";
  echo "WA x ".$wa."\n";
  echo "TLE x ".$tle."\n";
  echo "RE x ".$re."\n";

Measured memory_bytes: 16132