akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define ll long long
#define fm_t  ll t;cin>>t;while(t--)
#define fr(i,a,b) for( ll i=a;i<b;i++)
#define fr1(i,n,a) for( ll i=n-1;i>=a;i--)
#define sz(x) (ll)(x).size()
#define all(v)  (v).begin(), (v).end()
#define Sort(x) sort(x.begin(),x.end())
#define ms(a) memset(a,0,sizeof(a))
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
const ll mod = 998244353;
#define Mod 1000000007

#define inf 1e18
#define ld long double
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll >
#define pi pair<ll, ll>
#define ppi pair<pair<ll, ll>, ll>
#define ump unordered_map<ll,ll>
#define pri priority_queue< pair<ll,ll> , vector< pair<ll,ll> >, greater< pair<ll,ll> > >
void ingraph(vl graph[], ll m){ll x, y;fr(i,0,m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)

//setprecision(10)
//greater<int>()
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}


ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll modinv(ll a){
    return modpower(a,mod-2);
} 

ll dp[3001][3001][2];

ll solve(ll a[],ll l,ll h,ll p)
{
  if(l>h)
    return 0;
  if(dp[l][h][p]!=-1)
    return dp[l][h][p];
  ll ans=0;
  if(p==0)
  {
    ans+=max(a[l]+solve(a,l+1,h,1),a[h]+solve(a,l,h-1,1));
  }
  else
  {
      ans+=min(solve(a,l+1,h,0),solve(a,l,h-1,0));
  }
  //cout<<l<<" "<<h<<" "<<ans<<endl;
  return dp[l][h][p]=ans;
}

     
int main()
{
      
  fast;
  ll n;
  cin>>n;
  ll a[n];
  ll sum=0;
  fr(i,0,n)
  {
    cin>>a[i];
    sum+=a[i];
  }
  for(ll i=0;i<3001;i++)
  {
    for(ll j=0;j<3001;j++)
    {
      dp[i][j][0]=-1;
      dp[i][j][1]=-1;
    }
  }
  ll mn=solve(a,0,n-1,0);
  cout<<2*mn-sum<<endl;

    
//cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
return 0;
}

Measured memory_bytes: 144572
#include <cstdio>
#include <cstring>

char str[100010];
int main()
{
  int len, i, res = 0x3f3f3f3f, now;
  scanf("%s", str);
  len = strlen(str);
  
  now = 0;
  for(i = 0; i < len; i++){
    if(str[i] - '0' == i % 2) now++;
  }
  if(now < res) res = now;
  
  now = 0;
  for(i = 0; i < len; i++){
    if(str[i] - '0' != i % 2) now++;
  }
  if(now < res) res = now;
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
int a;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> a;
	cout << a + a*a + a*a*a << endl;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

int f(int X)
{
    int digits = 0;
    while(X > 0)
    {
        digits += X % 10;
        X /= 10;
    }
    return digits;
}

bool isHarshad(int X)
{
    return X % f(X) == 0;
}

void solve()
{
    int N; cin >> N;
    if(isHarshad(N)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys 
from collections import Counter,deque,defaultdict
from itertools import combinations,permutations,accumulate
from bisect import bisect_left,bisect
sys.setrecursionlimit(10**6)
INF = 10**9+7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
cnt = 0
tmp = A[0]
for i in range(1,N):
    if tmp > A[i]:
        cnt += tmp-A[i]
        A[i]=tmp
    tmp = A[i]
print(cnt)

Measured memory_bytes: 103020
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forv(i, v) forn(i, v.size())
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

int main() {
#ifdef NEREVAR_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, m;
    cin >> n >> m;
    vs a(n);
    forn(i, n) {
        cin >> a[i];
    }
    
    vs b[2];
    b[0] = b[1] = a;
    
    forn(j, m) {
        b[0][0][j] = '#';
        b[1][n - 1][j] = '#';
    }
    
    for (int j = 0; j < m; j += 2) {
        forn(i, n - 1) {
            b[0][i][j] = '#';
        }
    }
    for (int j = 1; j < m; j += 2) {
        for (int i = 1; i < n; i++) {
            b[1][i][j] = '#';
        }
    }
    
    forn(k, 2) {
        forn(i, n) {
            puts(b[k][i].c_str());
        }
        if (k == 0) cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<deque>
#include<string>
#include<map>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>

using namespace std;

int main() {
	long long  n, ans = 0, sum = 0; cin >> n;
	map<long long , long long > mp;
	mp[0] += 1;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		sum += a;
		ans += mp[sum];
		mp[sum] += 1;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    int n, m; cin>>n>>m;
    vector <int> data(100010);
    for(int i=0;i<m;i++){
        int a; cin>>a;
        data[a] =1;
    }
    vector <ll> dp(100010);
     dp[0] = 1;
    for(int i=0;i<n;i++){
        if(data[i+1]==0)
        dp[i+1] += dp[i];
        if(data[i+2]==0)
        dp[i+2] += dp[i];
        dp[i+1] =dp[i+1]% 1000000007;
        dp[i+2] =dp[i+2]% 1000000007;
    }
    cout<<dp[n]%1000000007<<endl;
}


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

int main(){
    string s;
    cin >> s;
    if((s[0] == s[1] && s[1] == s[2])
        || (s[1] == s[2] && s[2] == s[3])){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

int main() {
  int a[3];
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  sort(a, a+3);
  int ans = a[2]*10+a[1]+a[0];
  //printf("%d %d %d", a[0], a[1], a[2]);
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

long long int a[200000] = { 0 };

int main(void) {
	int N;
	long long int sum = 0, x = 0, ans = 0;

	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &a[i]);
		sum += a[i];
	}

	for (int i = 0; i < N - 1; i++) {
		x += a[i];
		long long int rem = sum - 2 * x;
		if (i == 0) {
			if (rem >= 0) ans = rem;
			else ans = -rem;
		}
		else {
			if (rem >= 0) {
				if (rem < ans) ans = rem;
			}
			else {
				if (-rem < ans) ans = -rem;
			}
		}
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 1664
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int x;
    cin>>x;
    int g=__gcd(x, 360ll);
    int l=(360*x)/g;
    cout<<l/x;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << (x) << ", "
#define de(x) cout << #x << " = " << (x) << "\n"
#define endl "\n"

//-----
vi v[30];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	string s; cin >> s;
	rep(l, 1, 3) {
		rep(i, 0, sz(s) - l) if (s[i] == s[i + l]) {
			cout << i + 1 << " " << i + 1 + l;
			return 0;
		}
	}
	cout << "-1 -1" << endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int		A = scan.nextInt();
		int		B = scan.nextInt();
		int		temp;
		long     C = A;
				C *= B;

		while ((temp = A%B) != 0) {
			A = B;
			B = temp;
		}
			System.out.println((C/B));
	}
}


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

int main(){
  int n, m, l;
  cin >> n >> m >> l;
  vector< vector<int> > a(n, vector<int>(m));
  vector< vector<int> > b(m, vector<int>(l));
  vector< vector<long long> > c(n, vector<long long>(l));

  int tmp;
  for (int i = 0; i < n; i++){
    for(int v = 0; v < m; v++){
      cin >> tmp;
      a[i][v] = tmp;
    }
  }
  
  for (int i = 0; i < m; i++){
    for(int v = 0; v < l; v++){
      cin >> tmp;
      b[i][v] = tmp;
    }
  }
  // for (int i = 0; i < m; i++){
  //   for (int v = 0; v < l; v++){
  //     if(v == l - 1){
  //       cout << b[i][v] << endl;
  //     }else{
  //       cout << b[i][v] << " ";
  //     }
  //   }
  // }
  for (int i = 0; i < n; i++){
    for (int v = 0; v < l; v++){
      for (int s = 0; s < m; s++){
        c[i][v] += a[i][s]*b[s][v];
      }
    }
  }

  for (int i = 0; i < n; i++){
    for (int v = 0; v < l; v++){
      if(v == l - 1){
        cout << c[i][v] << endl;
      }else{
        cout << c[i][v] << " ";
      }
    }
  }
}


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

int main(){
  int n;
  cin>>n;
  vector<double> a(n);
  double ave=0;
  for(int i=0; i<n; i++){
    cin>>a.at(i);
    ave+=a.at(i);
  }
  ave/=n;
  if(abs(ave-floor(ave))>=abs(ave-ceil(ave)))ave=ceil(ave);
  else ave=floor(ave);

  int ans=0;
  for(int i=0; i<n; i++)ans+=pow(a.at(i)-ave, 2);
  cout<<ans<<endl;
  
}

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

int main(){
  string s;
  while(1){
    getline(cin,s);
    if(s.size()==1&&s[0]=='.')break;
    string tmp;
    bool ok=true;
    for(int i=0;i<s.size();i++){
      if(s[i]=='(')tmp.push_back('(');
      if(s[i]=='[')tmp.push_back('[');

      if(s[i]==')'&&tmp[tmp.size()-1]=='('){
	tmp.pop_back();
      }else if(s[i]==')'&&(tmp[tmp.size()-1]=='['||tmp.size()==0)){
	ok=false;
	break;
      }

      if(s[i]==']'&&tmp[tmp.size()-1]=='['){
	tmp.pop_back();
      }else if(s[i]==']'&&(tmp[tmp.size()-1]=='('||tmp.size()==0)){
	ok=false;
	break;
      }
    }
    if(ok&&tmp.size()==0)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
const int N = 3e5 + 233;
int n, m, pro[N], sz[N];

int main(void) {
	read(n); read(m);
	pro[1] = true;
	rep (i, n) sz[i] = 1;
	rep (i, m) {
		int x, y;
		read(x); read(y);
		if (pro[x]) pro[y] = 1;
		sz[x]--; sz[y]++;
		if (!sz[x]) pro[x] = 0;
	}
	int ans = 0;
	rep (i, n) ans += pro[i];
	cout << ans << "\n";
}
				


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<pii> a(n);
	int Lmax = 1, Rmin = 1e9, max_len = 0;
	for (int i = 0; i < n; i++) {
		int L, R;
		cin >> L >> R;
		R++;
		a[i] = {L, R};
		Lmax = max(Lmax, L);
		Rmin = min(Rmin, R);
		max_len = max(max_len, R - L);
	}
	vector<pii> b(n);
	for (int i = 0; i < n; i++) {
		b[i] = {max(a[i].second - Lmax, 0), - max(Rmin - a[i].first, 0)};
	}
	sort(b.begin(), b.end());
	ll ans = 0LL + max(Rmin - Lmax, 0) + max_len;
	int minb = 1e9;
	for (int i = 0; i < n; i++) { 
		if (i > 0)
			ans = max(ans, 0LL + b[i].first + minb);
		minb = min(minb, - b[i].second);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>

const int INF = 1000000009;
const long LINF = 1123456789012345678;

long n;
long a, b, c, d;
long dif;

int main(){
	scanf("%ld %ld %ld %ld %ld", &n, &a, &b, &c, &d);
	dif = b - a;
	for(int x = 0, y = 1-n; x < n; x++, y++){
		long min = std::min(x*c + y*d, y*c + x*d);
		long max = std::max(x*c + y*d, y*c + x*d);
		if(min <= dif && dif <= max){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

''' ???????????? '''

# pop???push??¨??????????????????????????????????????????????????¨??£??\????????????????????????
# ?¨??????????O(1)


operators = {"+": lambda x, y: x + y,
             "-": lambda x, y: x - y,
             "*": lambda x, y: x * y,
             "/": lambda x, y: x / y}


def compute(A):
    stack = []

    for i in range(len(A)):
        # ?????????
        if isinstance(A[i], str):
            op_right = stack.pop()
            op_left = stack.pop()
            # ?¨???????????????????????????????
            stack.append(operators[A[i]](op_left, op_right))

        # ???????????????
        if isinstance(A[i], int):
            stack.append(A[i])

    return stack[-1]

if __name__ == '__main__':
    A = list(input().split())
    # A = list("1 2 + 3 4 - *".split())

    for i in range(len(A)):
        if not A[i] in ['+', '-', '*', '/']:
            A[i] = int(A[i])

    print(compute(A))

Measured memory_bytes: 7696
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			//System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start();
			//Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			//int x = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int k = vs[0];
			int n = vs[1];
			int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int tmp = a[0] + (k - a[n - 1]);
			for (int i = 1; i < n; i++) {
				tmp = Math.Max(tmp, a[i] - a[i - 1]);
			}
			Console.WriteLine(k - tmp);


			//Console.Out.Flush();
			//System.Diagnostics.Debug.WriteLine(sw.Elapsed);
		}
	}
}

Measured memory_bytes: 34780
#include <bits/stdc++.h>
#define MAX 300005
using namespace std;


int a[MAX];
int t[5 * MAX];

int get(int lo, int hi, int idx, int qs, int qe) {
  if (qe < lo || hi < qs) return 0;
  if (qs <= lo && hi <= qe) return t[idx];

  int mid = (lo + hi) >> 1;
  int right = (idx + 1) << 1;
  return max(get(lo, mid, right - 1, qs, qe), get(mid + 1, hi, right, qs, qe));
}

void update(int lo, int hi, int idx, int ui, int val) {
  if (ui < lo || hi < ui) return;
  if (lo == hi) { t[idx] = val; return; }

  int mid = (lo + hi) >> 1;
  int right = (idx + 1) << 1;
  update(lo, mid, right - 1, ui, val);
  update(mid + 1, hi, right, ui, val);
  t[idx] = max(t[right - 1], t[right]);
}

int main() {
  int k, m, n;
  scanf("%d%d", &n, &k);
  m = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    m = max(m, a[i]);
  }

  m++;
  memset(t, 0, sizeof(int) * (5 * m));

  for (int i = n - 1; i >= 0; i--) {
    int lo = max(0, a[i] - k);
    int hi = min(m - 1, a[i] + k);
    int c = get(0, m - 1, 0, lo, hi);
    update(0, m - 1, 0, a[i], c + 1);
  }

  printf("%d\n", get(0, m - 1, 0, 0, m - 1));
}


Measured memory_bytes: 10852
// atcoder/abc074/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    const int N = 300 + 1;
    static lli g[N][N];
    static lli h[N][N];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> g[i][j];
        h[i][j] = g[i][j];
      }
    }
    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          if (i == j) continue;
          if (i == k) continue;
          if (j == k) continue;
          if (g[i][k] + g[k][j] == g[i][j]) {
            h[i][j] = 0;
          }
        }
      }
    }

    lli sum = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        sum += h[i][j];
        if (h[i][j] == 0) h[i][j] = (1LL << 60);
      }
    }
    for (int i = 0; i < n; ++i) {
      h[i][i] = 0;
    }
    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          setmin(h[i][j], h[i][k] + h[k][j]);
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (g[i][j] != h[i][j]) sum = -2;
      }
    }

    cout << sum / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
char s[1000005];
int n,a[1000005],sum,mx[1000005],b[1000005];
int f(int x)
{
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='?')
        {
            if(mx[i]+(ans+1)*2<=x)ans++,b[i]=1;
            else b[i]=-1;
        }
        else if(s[i]=='1')b[i]=1;
        else b[i]=-1;
    }
    int anss=b[1];
    for(int i=2;i<=n;i++)b[i]+=b[i-1],anss=min(anss,b[i]);
    return min(anss,0);
}
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    for(int i=1;i<=n;i++)
        if(s[i]=='1')sum++,a[i]=a[i-1]+1;
        else sum--,a[i]=a[i-1]-1;
    mx[n]=a[n];
    for(int i=n-1;i>=1;i--)mx[i]=max(mx[i+1],a[i]);
    int z=max(mx[1],0);
    printf("%d",min(z-f(z),z+1-f(z+1)));
    return 0;
}

Measured memory_bytes: 16480
'''
pythonの再帰は10^5timesですら厳しい
import sys
sys.setrecursionlimit(10000000)

def dfs(v,p,G,c):
    for u in G[v]:
        if u!=p:
            c[u]+=c[v]
            dfs(u,v,G,c) 
'''

from collections import deque

N,Q = list(map(int,input().split()))

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

p=[0]*Q
x=[0]*Q
c=[0]*N
for i in range(Q):
    p,x = list(map(int,input().split()))
    p-=1
    c[p] += x

stack=deque([0])
parent = [-1]*N

while(stack):
    v = stack.pop()
    for u in G[v]:
        if u!=parent[v]:
            c[u]+=c[v]
            parent[u]=v
            stack.append(u)


ans = ' '.join([str(x) for x in c])

print(ans)

Measured memory_bytes: 124180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
typedef long long i64;
int main(){
    int r,g;
    cin >> r >> g;
    cout << g*2-r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void)
{
	bool flag;
	int n,k=0,a;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a;
		flag=false;
		for(int j=2;j*j<=a;j++){
			if(a%j==0){
				flag=true;
				break;
			}
		}
		if(flag==false) k+=1;
	}
	cout << k << endl;
	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
T Sum(vector<T> n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
ld Sum(vector<ld> n, ll a, ll b)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

void fYn(bool a)
{
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}
//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}
//累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//大文字->小文字(+32)
//少数はなるべく整数に

void Main()
{
  char s; cin >> s;
  if(s == 'S') fin("Cloudy")
  else if(s == 'C') fin("Rainy")
  else fin("Sunny")
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

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

const ll INF = ll(1e18)+1;
const ll MOD = ll(1e9)+7;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}



int main() {
  int K;

  cin >> K;

  int lunlun_num = 0;
  ll num = 0;

  ll lunlun_min = 0;
  ll lunlun_max = 0;
  ll lunlun_max_num = 0;

  string tmp_str = "";
  int tmp_min = 0;
  int tmp_max = 9;
  int tmp_num = 0;

  ll loop = 0;

  vector<ll> lunlun(K);


  for (int i = 0; i < 18; i++) {
  
    for (int j = 0; j < 9; j++) {

        lunlun_max_num = pow(3,i);

        tmp_str = to_string(j+1);
        for (int k = 0; k < i; k++) {
          tmp_min = ctoi(tmp_str.at(k)) - 1;
          if (tmp_min < 0) tmp_min = 0;          
          tmp_str = tmp_str + to_string(tmp_min);
        }


        num = stoll(tmp_str);
        lunlun.at(lunlun_num) = num;
        lunlun_num = lunlun_num + 1;


        for (ll k = 0; k < lunlun_max_num; k++) {

          if (lunlun_num >= K) break;

          if (i > 0) {

            for (int l = i-1; l >= 0; l--) {

              loop++;

              if (abs(ctoi(tmp_str.at(l+1))+1 - ctoi(tmp_str.at(l))) <= 1 && ctoi(tmp_str.at(l+1)) < 9) {
                
                tmp_str.replace(l+1, 1, to_string(ctoi(tmp_str.at(l+1))+1));

                num = stoll(tmp_str);
                lunlun.at(lunlun_num) = num;
                lunlun_num = lunlun_num + 1;

                break;

              } else {
                
                if (l > 0) {
                  if (abs(ctoi(tmp_str.at(l))+1 - ctoi(tmp_str.at(l-1))) <= 1 && ctoi(tmp_str.at(l)) < 9) {

                    tmp_str.replace(l, 1, to_string(ctoi(tmp_str.at(l))+1));

                    for (int n = l+1; n <= i; n++) {
                      tmp_min = ctoi(tmp_str.at(n-1)) - 1;
                      if (tmp_min < 0) tmp_min = 0; 

                      tmp_str.replace(n, 1, to_string(tmp_min));
                    }

                    num = stoll(tmp_str);
                    lunlun.at(lunlun_num) = num;
                    lunlun_num = lunlun_num + 1;

                    break;
                    
                  }
                }
                continue;
              }
              
            }
          }

        }
        
        
      if (lunlun_num >= K) break;

    }

    if (lunlun_num >= K) break;
    
  }
  
  cout << num << endl;

  
  
  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 
 
int main() {
  int N; cin>>N;
  bool ok = false;
  while (N>0) {
    int d=N%10;
    N/=10;
    if(d==7) ok =true;
  }
  puts(ok?"Yes":"No");
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int n,k,i,j,A[100000],cost[100000],mn;
int main(){
  cin>>n>>k;
  for(i=0;i<n;i++)
    cin>>A[i];
  cost[0]=0;
  for(i=1;i<n;i++){
    mn=INT_MAX;
    for(j=1;j<=k;j++){
      if(i-j>=0){
        mn=min(abs(A[i]-A[i-j])+cost[i-j],mn);}}
    cost[i]=mn;}
  cout<<cost[n-1];}

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

///--->>> CONTAINERS <<<---///
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vector< ll > >;
using vpi = vector<pair<ll,ll> >;
using pi = pair<ll,ll>;
using st = set<ll>;
using stk = stack<ll>;
using kiwi = queue<ll>;
using pkiwi = priority_queue<ll>;
using mp = map<ll,ll>;
using ump = unordered_map<ll,ll>;

///--->>> MACROS<<<---///
const ll mx = 3e5+123;
#define MOD 1000000007
#define REP(i,n) for (ll i=1;i<=n;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

///--->>>OPTIMIZE<<<---///
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

///--->>> DEBUGGER<<<---///
#define dbg(args...) do {cerr<<#args<<" : "; diraf(args); } while(0)
void diraf ()  {        cerr << endl;}
template < typename T, typename ... hello>void diraf( T arg, const hello &... rest) {cerr<<arg<< ' ';diraf(rest...);}

int main(){
    fastio;
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    ///cout<<fixed<<setprecision(20);
    ll n; cin>>n;
    if(n==0)
        cout<<1<<endl;
    else if(n==1)
        cout<<0<<endl;

return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val N = readLong()
    for (h in 1 until 3500) {
        for (n in 1 until 3500) {
            val tmp = 4 * h * n - N * h - N * n
            val tmp2 = N * h * n
            if (tmp > 0L && tmp2 % tmp == 0L) {
                val w = tmp2 / tmp
                out.println("$h $n $w")
                return
            }
        }
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 34332
/**
 *    author:  abhishekvtangod
 *    created: 
**/
// #undef _GLIBCXX_DEBUG
// #undef _ABHI
#include<bits/stdc++.h>
using namespace std; 

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// oset<pair<ll,ll>> indexed_set;

#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;

void debug_out() { cerr << "]" << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << H << ", ";
  debug_out(T...);
}

#ifdef _GLIBCXX_DEBUG
#define debug(x...) cerr << "[" << #x << "]:[", debug_out(x)
#else
#define debug(...) 42
#endif

// struct HASH{
//   size_t operator()(const pair<int,int>&x)const{
//     return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
//   }
// };


void solve(){
	int n,w;
	cin >> n >> w;
	vector<ll> val(n);
	vector<ll> wt(n);
	for(int i = 0; i < n; i++){
		cin >> wt[i] >> val[i];
	}
	ll dp[w+1][n+1];
	memset(dp,0,sizeof(dp));

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

				debug(val[j-1],j);
			}
		}
	}
	// for(auto &u: dp){
	// 	for(auto i: u){
	// 		cout << i << " ";
	// 	}
	// 	cout << endl;
	// }
	cout << dp[w][n] << endl;

}


int main()
{   
	IOS;

 	#ifdef _ABHI
		freopen("C:\\Users\\Thangod\\Desktop\\zAbhi\\input.txt", "r", stdin);
		freopen("C:\\Users\\Thangod\\Desktop\\zAbhi\\output.txt", "w", stdout);
	#endif 

	// ll t;cin>>t;
	// while(t--){
		solve();
	// }

    return 0;
}

Measured memory_bytes: 82480
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

int N;


int main(){
  cin >> N;
  char S[N];
  for(int i=0;i<N;i++){
    cin >> S[i];
  }
  bool m = true;
  if (N%2!=0) m=false;
  for(int j=0;j<N/2;j++){
    if(S[j]!=S[j+N/2]){
      m=false;
      break;
    }
  }
  if(m) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 888
using System;

class Program
{
    public static void Main()
    {
        string str = Console.ReadLine();
        int q = int.Parse(Console.ReadLine());
        for (int i = 0; i < q; ++i)
        {
            string[] o = Console.ReadLine().Split(' ');
            int a = int.Parse(o[1]), b = int.Parse(o[2]);
            switch (o[0])
            {
                case "print":
                    Console.WriteLine(str.Substring(a, b - a + 1));
                    break;
                case "reverse":
                    char[] sub = str.Substring(a, b - a + 1).ToCharArray();
                    Array.Reverse(sub);
                    str = str.Remove(a, b - a + 1).Insert(a, new string(sub));
                    break;
                case "replace":
                    str = str.Remove(a, b - a + 1).Insert(a, o[3]);
                    break;
            }
        }
    }
}


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

map<ll,int> facs;
void factor(ll i) {
    for (ll j = 2; j*j <= i; j++) {
        if (i % j == 0) {
            while (i % j == 0) {
                i /= j;
                facs[j]++;
            }
            factor(i);
            return;
        }
    }
    if (i > 1) {
        facs[i]++;
    }
}

ll expo(ll a, ll n) {
    ll res = 1;
    for (int i = 0; i < n; i++) {
        res *= a;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll N, P; cin >> N >> P;
    factor(P);
    ll ans = 1;
    for (auto p: facs) {
        ll r = p.second / N;        
        ans *= expo(p.first,r);
    }
    cout << ans << '\n';


    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int flg[1000000];
int main(void)
{
	int n,cnt;
	int i,j;
	while(scanf("%d",&n)!=EOF){
		cnt=0;
		for(i=2;i<=n;i++){
			flg[i]=1;
		}
		for(i=2;i*i<=n;i++){
			if(flg[i]==1){
				for(j=2;i*j<=n;j++){
					flg[i*j]=0;
				}
			}
		}
		/*for(i=2;i<=n;i++){
			if(flg[i]==1)printf("素数=%d\n",i);
		}*/
		for(i=2;i<=n;i++){
			if(flg[i]==1){
				cnt+=1;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}


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

long cnt = 0;


void sub(vector<long> &A, vector<long> &B, long i, long j){
    long d = A[i] - B[j];
    if (d >= 0){
        cnt += B[j];
        A[i] -= B[j];
        B[j] -= B[j];
    } else {
        cnt += A[i];
        B[j] -= A[i];
        A[i] -= A[i];
        if (i == j) sub(A, B, i+1, i);
    }            
}

int main(){
    long n;
    cin >> n;
    vector<long> A(n+1);
    vector<long> B(n);


    long i;
    for(i = 0; i < n+1; i++) cin >> A[i];
    for(i = 0; i < n; i++) cin >> B[i];

    for(i = 0; i < n; i++){
        sub(A, B, i, i);
    }

    cout << cnt << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll y[100010];
int main(){
    ll n, x;
    cin >> n >> x;
    rep(i, n) cin >> y[i];
    ll g = abs(y[0] - x);

    for(int i = 0; i < n-1; i++){
        g = __gcd(g, abs(y[i+1]-y[i]));
    }

    cout << g << endl;

    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int n;
	cin >> n;

	int ans = 1;

	while (ans * 2 <= n) {
		ans *= 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<string.h>
#include<math.h>
#define max(a,b) a<b?b:a
#define min(a,b) a<b?a:b
int X,Y,Z,V[4],E[100],A[100],n,e,a,i,j,k;
double dp[100][5001],r;

int main()
{
	for(;scanf("%d%d%d",&X,&Y,&Z),X;)
	{
		memset(E,0,sizeof(E));
		memset(A,0,sizeof(A));
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(i=0;i<X;i++)
			scanf("%d",&V[i]);
		for(i=0;i<Z;i++)
		{
			scanf("%d%d%d",&n,&e,&a);
			E[n]=e;
			A[n]=e==3?-a:a;
		}

		for(i=0;i<Y;i++)
			for(j=0;j<=5000;j++)
				for(k=0;k<X;k++)
				{
					int T=i+V[k];
					if(T>Y)
						dp[Y][j]+=dp[i][j]/X;
					else if(E[T]==1)
						dp[min(Y,T+A[T])][j]+=dp[i][j]/X;
					else
						dp[T][max(0,j+A[T])]+=dp[i][j]/X;
				}
		for(i=r=0;i<=5000;i++)
			r+=i*dp[Y][i];
		printf("%d\n",(int)r);
	}
	return 0;
}

Measured memory_bytes: 4516
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	static class Pair {
		int x, y;
		public Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Pair[] p = new Pair[m];
		for(int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			p[i] = new Pair(a, b);
		}
		// pをbiで昇順ソート
		Arrays.sort(p, new Comparator<Pair>() {
			@Override
			public int compare(Pair p1, Pair p2) {
				return p1.y - p2.y;
			}
		});
		int bridgeN = -1;
		int ans = 0;
		for(int i = 0; i < m; i++) {
			if(p[i].x > bridgeN) {
				bridgeN = p[i].y - 1;
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 88756
#include<iostream>
#include<cstdio>
#include<cstring>
#define M 1046527
#define NIL (-1)
#define L 14
using namespace std;
char H[M][L];
int getchar(char ch)
{
  if(ch == 'A')return 1;
  else if(ch == 'C')return 2;
  else if(ch == 'G')return 3;
  else if(ch == 'T')return 4;
  else return 0;
}
long long getkey(char str[])
{
  long long sum = 0,p = 1,i;
  for(i=  0;i<strlen(str);i++)
  {
    sum+=p*(getchar(str[i]));
    p*=5;
  }
  return sum;
}
int h1(int key){
  return key%M;
  }
int h2(int key)
{
  return 1+(key%(M-1));
}
int find (char str[])
{
  long long key,i,h;
  key = getkey(str);
  for(i = 0; ;i++)
  {
    h = (h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str) == 0)
       return 1;
    else if (strlen(H[h]) == 0)
     return 0;
  }
  return 0 ;
}
int insert(char str[])
{
  long long key,i,h;
  key = getkey(str);
  for(i = 0; ;i++)
  {
    h = (h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str) == 0)return 1;
     else if(strlen(H[h]) == 0)
         {
           strcpy(H[h],str);
           return 0;
         }
  }
  return 0;
}
int main ()
{
  int i,n,h;
  char str[L],com[9];
  for(i = 0;i<M;i++)
      H[i][0] ='\0';
scanf("%d",&n);
for(i = 0;i<n;i++)
{
  
  scanf("%s %s",com,str);
  if(com[0] == 'i'){
    insert(str);
  }else {
    if(find(str))
    {
      printf("yes\n");
    }else {
      printf("no\n");
      
    }
  }
}
  return 0 ;
}


Measured memory_bytes: 17448
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int X, A, B;
    cin >> X >> A >> B;
    X -= A;
    int Y = X / B;
    cout << X - Y * B << endl; 
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
  map<char,string> t;
  t[' '] = "101";
  t['\''] = "000000";
  t[','] = "000011";
  t['-'] = "10010001";
  t['.'] = "010001";
  t['?'] = "000001";
  t['A'] = "100101";
  t['B'] = "10011010";
  t['C'] = "0101";
  t['D'] = "0001";
  t['E'] = "110";
  t['F'] = "01001";
  t['G'] = "10011011";
  t['H'] = "010000";
  t['I'] = "0111";
  t['J'] = "10011000";
  t['K'] = "0110";
  t['L'] = "00100";
  t['M'] = "10011001";
  t['N'] = "10011110";
  t['O'] = "00101";
  t['P'] = "111";
  t['Q'] = "10011111";
  t['R'] = "1000";
  t['S'] = "00110";
  t['T'] = "00111";
  t['U'] = "10011100";
  t['V'] = "10011101";
  t['W'] = "000010";
  t['X'] = "10010010";
  t['Y'] = "10010011";
  t['Z'] = "10010000";
  map<string,char> t2;
  t2["00000"] = 'A';
  t2["00001"] = 'B';
  t2["00010"] = 'C';
  t2["00011"] = 'D';
  t2["00100"] = 'E';
  t2["00101"] = 'F';
  t2["00110"] = 'G';
  t2["00111"] = 'H';
  t2["01000"] = 'I';
  t2["01001"] = 'J';
  t2["01010"] = 'K';
  t2["01011"] = 'L';
  t2["01100"] = 'M';
  t2["01101"] = 'N';
  t2["01110"] = 'O';
  t2["01111"] = 'P';
  t2["10000"] = 'Q';
  t2["10001"] = 'R';
  t2["10010"] = 'S';
  t2["10011"] = 'T';
  t2["10100"] = 'U';
  t2["10101"] = 'V';
  t2["10110"] = 'W';
  t2["10111"] = 'X';
  t2["11000"] = 'Y';
  t2["11001"] = 'Z';
  t2["11010"] = ' ';
  t2["11011"] = '.';
  t2["11100"] = ',';
  t2["11101"] = '-';
  t2["11110"] = '\'';
  t2["11111"] = '?';
  string s;
  while(getline(cin,s)){
    string x;
    for(int i=0; i<s.size(); i++) x+=t[s[i]];
    for(;x.size()%5;) x+="0";
    for(int i=0; i<x.size(); i+=5) cout <<t2[x.substr(i,5)];
    cout <<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#
import sys
import math
import numpy as np
import itertools
# ひとつ入力
n = int(input())

# n行の複数列ある数値を二次元配列へ。x[n][?]
xy = [[int(i) for i in input().split()] for i in range(n)]

a=0

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        else:
            a += math.sqrt( (xy[i][0]-xy[j][0])*(xy[i][0]-xy[j][0]) + (xy[i][1]-xy[j][1])*(xy[i][1]-xy[j][1]) )

print(a/n)




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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

long long gcd(long long m, long long n) {

  if(n == 0)
    return m;
  return gcd(n, m % n);
} // gcd

long long lcm(long long m, long long n) {
  // 引数に０がある場合は０を返す
  if((0 == m) || (0 == n))
    return 0;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VLL a(n);
  rep(i, n) cin >> a[i];
  ll right[n];
  ll left[n];
  ll tmp = a[0];
  rep(i, n) {
    tmp = gcd(tmp, a[i]);
    left[i] = tmp;
  }
  tmp = a[n - 1];
  for(int i = n - 1; i >= 0; i--) {
    tmp = gcd(tmp, a[i]);
    right[i] = tmp;
  }
  ll ans = 0;
  rep(i, n) {
    if(i == 0) {
      chmax(ans, right[i + 1]);
    } else if(i == n - 1) {
      chmax(ans, left[i - 1]);
    } else {
      chmax(ans, gcd(left[i - 1], right[i + 1]));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   int A1,A2,A3;
   cin>>A1>>A2>>A3;
   vector<int>K={A1,A2,A3};
   sort(K.begin(),K.end());
   cout<<K[2]-K[0]<<endl;
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, d;
	cin >> n >> d;
	cout << (n + 2 * d) / (2 * d + 1);

	return 0;
}

Measured memory_bytes: 256