akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwe
#define y1 onyetvwe
#define x2 onyette
#define y2 ugmewuben
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int main()
{
	LL n,a,b,c,d;
	scan(n),scan(a,b),scan(c,d);
	if(a>b)
		swap(a,b);
	LL l,r;
	bool ans=false;
	for(int i=1;i<=n;i++)
	{
		if(i==1)
		{
			l=a,r=a;
		}
		else
		{
			if(r<b)
				l+=c,r+=d;
			else
				r-=c,l-=d;
		}
		if(l<=b&&b<=r)
		{
			//cout<<"pernah"<<endl;
			//cout<<"pada "<<i<<" l "<<l<<" r "<<r<<" b "<<endl;
			if(((n-i)%2==0))
				ans=true;
			else
			{
				LL kali=(n-i)/2;
				l-=(d-c)*kali;
				r+=(d-c)*kali;
				if(((l+c)<=b&&b<=(r+d))||((l-d)<=b&&b<=(r-c)))
					ans=true;
			}
			break;
		}
	}
	//cout<<"endingnya "<<l<<" "<<r<<endl;
	if(ans)	
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		String[] s = S.split("");
		int ans = 753;
		
		for(int i = 0; i <= s.length - 3; i++) {
			int data = Integer.valueOf(s[i] +
					s[i+1] + s[i+2]);
			int a = Math.abs(753 - data);
			ans = Math.min(ans, a);
		}
		System.out.println(ans);
	
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  if (n == 2) {
    cout << 1 << endl;
  } else {
    set <ll> s;
    for (ll i = 1; i*i <= n-1; i++) {
      if ((n-1)%i == 0) {
        s.insert(i);
        if (i != (n-1)/i) s.insert((n-1)/i);
      }
    }
    vector <ll> v;
    for (ll i = 1; i*i <= n; i++) {
      if (n%i == 0) {
        v.push_back(i);
        if (i != n/i) v.push_back(n/i);
      }
    }
    rep(i, v.size()) {
      ll tmp = n;
      if (v.at(i) == 1) continue;
      while (tmp%v.at(i) == 0) {
        tmp /= v.at(i);
      }
      if (tmp >= v.at(i)) {
        tmp %= v.at(i);
      }
      if (tmp == 1) {
        s.insert(v.at(i));
      }
    }
    s.erase(1);
    cout << s.size() << endl;
  }
}

Measured memory_bytes: 384
N,K = map(int,input().split())

import numpy as np
blacks = np.zeros((2*K,2*K), dtype=int)

offset = 0

for _ in range(N):
  x,y,c = input().split()
  x,y = int(x),int(y)
  x %= 2*K
  y %= 2*K
  if c == 'B':
    blacks[x,y] += 1
  else:
    blacks[x,y] -= 1
    offset += 1

m = np.zeros((3*K,2*K),dtype=int)
m[:2*K,:] = blacks
m[2*K:,:] = blacks[:K,:]

np.cumsum(m,axis=0, out=m)

m = m[K:,:] - m[:2*K,:]

n = np.zeros((2*K,3*K),dtype=int)
n[:,:2*K] = m
n[:,2*K:] = m[:,:K]

np.cumsum(n,axis=1, out=n)
n = n[:,K:] - n[:,:2*K]

m = np.zeros((3*K,3*K),dtype=int)
m[:2*K,:2*K] = n
m[2*K:,:2*K] = n[:K,:]
m[:2*K,2*K:] = n[:,:K]
m[2*K:,2*K:] = n[:K,:K]

m = m[:2*K,:2*K] + m[K:,K:]
m = m.max()

print(m+offset)

Measured memory_bytes: 176652
N = int(input())
D = []
for _ in range(N):
    D.append(list(map(int, input().split())))

max_cnt = 0
cnt = 0
for x, y in D:
    if x == y:
        cnt += 1
        max_cnt = max(max_cnt, cnt)
    else:
        cnt = 0
if max_cnt >= 3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9172
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N; cin >> N;
    if (N % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll M = N;
    ll count = 0;
    while (M >= 5) {
        count += ((M / 5LL) / 2LL);
        M /= 5LL;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
// practice with Dukkha, coached by rainboy
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 200000;

int aa[N], bb[N];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> aa[i] >> bb[i];
	sort(aa, aa + n);
	sort(bb, bb + n);
	int a, b;
	if (n % 2) {
		a = aa[n / 2];
		b = bb[n / 2];
	} else {
		a = aa[n / 2 - 1] + aa[n / 2];
		b = bb[n / 2 - 1] + bb[n / 2];
	}
	cout << b - a + 1 << '\n';
	return 0;
}


Measured memory_bytes: 5100
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<queue>

using namespace std;

#if 0
所用時間:

感想:

#endif

int N;
int D[101] = {};
int mat[101][101] = {}; //mat[Y][X]

void solve();

int main(){
    cin >> N;

    for(int i = 0; i < N; ++i){
        int u, k;
        cin >> u >> k;
        for(int j = 0; j < k; ++j){
        int buff;
        cin >> buff;
        //cout << "Buff: " << buff << endl; 
        mat[u][buff] += 1;
        }
    }

    // for(int i = 1; i <= N; ++i){
    //     for(int j = 1; j <= N; ++j){
    //         if(j==N) cout << mat[i][j];
    //         else cout << mat[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    solve();
}

void solve(){
    queue<int> Q;

    for(int i = 1; i <= N; ++i) D[i]--;

    D[1] = 0;

    Q.push(1);

    while(!Q.empty()){
        int cur = Q.front();
        Q.pop();

        for(int dst = 1; dst <= N; ++dst){
            if((D[dst] < 0) && ( mat[cur][dst] == 1)){
                D[dst] = D[cur] + 1;
                Q.push(dst);
            }
        }
    }

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


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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

N, M = MAP()
S = input()
T = input()

lcm = lcm_base(N, M)
# 何文字毎に文字が指定されるか
N_gap = lcm // N
M_gap = lcm // M
# 1文字ずつ全て確認することはない
for i in range(0, lcm, lcm//gcd(N, M)):
    # 文字の一致を確認する
    if S[i//N_gap] != T[i//M_gap]:
        print(-1)
        exit()
print(lcm)


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

int main() {
    int x[5];
    for (int i = 0; i < 5; i++) cin >> x[i];

    for (int i = 0; i < 5; i++) {
        if (x[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string.h>
using namespace std;

int main() {
  int a,b;
  cin>>a>>b;
  if(a<=b || a<=2*b)
   cout<<0;
   	else cout<<a-2*b;
   	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    if (x < y) {
        swap(a,b);
        swap(x,y);
    }
    /*
    int sh = 0;
    if (a > 2 * c) {
        sh = 2 * a;
    }
    if (b > 2 * c) {
        sh = max(2 * b, sh);
    }
    */
    int ans = 100000 * 5000 * 2;
    REP(i,0,x+1) {
        int tmp = c * 2 * i + a * max(x - i, 0) + b * max(y - i, 0);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	string s;
	map<char, int> ex;
	ex['I'] = 1; ex['V'] = 5; ex['X'] = 10; ex['L'] = 50; 
	ex['C'] = 100; ex['D'] = 500; ex['M'] = 1000;
	
	while(cin >> s)
	{
		int sum = 0;
		for(int i = 0; i < s.size()-1; i++)
		{
			char now = s[i], next = s[i+1];

			if(ex[now] < ex[next])
			{
				sum -= ex[now];
			}
			else
			{
				sum += ex[now]; 
			}
		}
		sum += ex[s[s.size()-1]];
		cout << sum << endl;
	}
}

Measured memory_bytes: 1184
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n;
int main(){
	int i = 1;
	scanf("%d", &n);
	while(i * (i + 1) / 2 < n) i++;
	printf("%d\n", i);
	return 0;
}


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

using namespace std;
typedef long long LL;
const int N = 2e5+7;

int a[N];
bool cmp(int a,int b){
	return a > b;
}

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1,cmp);
	LL ans=0;
	if(n&1) {
		n = n/2+1;
		for(int i=1;i<=n;i++) ans+=a[i];
		ans = ans*2-a[1]-a[n];
	}else {
		n = n/2;
		for(int i=1;i<=n;i++) ans+=a[i];
		ans = ans*2-a[1];
	}
	cout<<ans<<endl;
	return 0;
 } 

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

const int mod = 998244353;

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

    bool ok = true;
    int cnt[n];
    for (int i = 0; i < n; i++) cnt[i] = 0;
    int m = 0;
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        if (i == 0 && d != 0) ok = false;
        cnt[d]++;
        m = max(m, d);
    }

    if (cnt[0] != 1) ok = false;
    
    if (!ok) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j < cnt[i]; j++) {
            ans = ans * cnt[i - 1] % mod;
        }
    }

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

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <stack>
#define pb push_back
#include <functional>
#include <vector>
#include <queue>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
using namespace std;
int x[25];
vector<int> t;
int main()
{
	int a;
	scanf("%d",&a);
	x[4]=a%10;
	a/=10;
	x[3]=a%10;
	a/=10;
	x[2]=a%10;
	a/=10;
	x[1]=a%10;
	int fg=0;
	//cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl;
	rep(i,0,9){
		int ans = x[1];
		int cnt=2;
		t.clear();
		rep(j,0,3){
			//de(j);
//			dd((1<<j));
			if(i&(1<<j)) {
				ans+=x[cnt];
				t.pb(1);
			}
			else {
				ans-=x[cnt];
				t.pb(0);
			}
			cnt++;
		}
//		de(ans);
		if(ans==7) break;
	}
	int fi=1;
	rep(i,1,5){
		printf("%d",x[i]);
		if(i==4) break;
		printf("%c",t[i-1]==1?'+':'-');
	}
	printf("=7\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.rbegin(), v.rend());
  int a = 0, b = 0;
  rep(i, n) {
    if (i%2)
      b += v[i];
    else
      a += v[i];
  }
  cout << a-b << endl;
  return 0;
}

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

int topN(int n) {
  while (n >= 10) n /= 10;
  return n;
}

int botN(int n) {
  return n % 10;
}

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

  vector<vector<int>> X(10, vector<int>(10, 0));
  rep(i, N + 1) {
    X[topN(i)][botN(i)]++;
  }

  long long ans = 0;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      ans += X[i][j] * X[j][i];
    }
  }

  cout << ans << endl;
}

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

int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(k>=n)
        cout<<n*x;
    else
        cout<<k*x+(n-k)*y;
    return 0;
}

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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int m, k;

bool read() {
    if (!(cin >> m >> k))
        return false;

    return true;
}

void solve() {
    if (m == 1) {
        if (k == 0)
            cout << "0 0 1 1\n";
        else
            cout << "-1\n";

        return ;
    }

    if (k >= (1 << m)) {
        cout << "-1\n";
        return ;
    }

    for (int i = 0; i < (1 << m); ++i)
        if (i != k)
            cout << i << ' ';

    cout << k << ' ';

    for (int i = (1 << m) - 1; i >= 0; --i)
        if (i != k)
            cout << i << ' ';

    cout << k << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 1792
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    A, B = map(int, input().split())
    if A >= 13:
        print(B)
    elif 6 <= A <= 12:
        print(B // 2)
    else:
        print(0)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<double, int> P;

int main(){
  int N;
  int casenum = 1;
  while(cin>>N && N){
    printf("%d ", casenum++);
    map<double, vector<P> > eventx;
    map<double, vector<P> > delx;
    set<double> searchx;
    REP(i, N){
      double x, y, d;
      cin>>x>>y>>d;
      searchx.insert(x - d);
      searchx.insert(x + d);
      eventx[x - d].push_back(P(y - d, 1));
      eventx[x - d].push_back(P(y + d, -1));
      delx[x + d].push_back(P(y - d, 1));
      delx[x + d].push_back(P(y + d, -1));
    }
    vector<P> evs;
    //set<P> evs;
    double bfx = 0;
    double bfy = 0;
    double ans = 0;
    FORIT(sx, searchx){
      ans += (*sx - bfx) * bfy;
      if(eventx.count(*sx)){
        FORIT(it, eventx[*sx]) evs.push_back(*it);
      }
      if(delx.count(*sx)){
        FORIT(it, delx[*sx]){
          vector<P>::iterator findit = find(evs.begin(), evs.end(), *it);
          assert(findit != evs.end());
          evs.erase(findit);
        }
      }
      sort(evs.begin(), evs.end());
      bfx = *sx;
      bfy = 0;
      int cnt = 0;
      double ty = 0;
      FORIT(event, evs){
        if(cnt > 0){
          bfy += abs(event->first - ty);
        }
        ty = event->first;
        cnt += event->second;
      }
    }
    printf("%.2lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    H,W = mis()
    S = tuple(input() for _ in range(H))
    reached = set()
    q = deque()
    ans = 0
    def check():
        nonlocal ans
        while q:
            x, y, d = q.popleft()
            for nx, ny in ((x-1, y),(x+1, y),(x, y-1),(x, y+1)):
                if 0 <= nx < W and 0 <= ny < H and S[ny][nx]=='.' and (nx, ny) not in reached:
                    q.append((nx, ny, d+1))
                    reached.add((nx, ny))
                    ans = max(ans, d+1)
    for x in range(W):
        for y in range(H):
            if S[y][x] == '#':
                continue
            q.append((x, y, 0))
            reached.add((x, y))
            check()
            reached.clear()
    print(ans)

main()


Measured memory_bytes: 5556
#include <iostream>
  #include <complex>
  #include <vector>
  #include <string>
  #include <algorithm>
  #include <cstdio>
  #include <numeric>
  #include <cstring>
  #include <ctime>
  #include <cstdlib>
  #include <set>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <list>
  #include <cmath>
  #include <bitset>
  #include <cassert>
  #include <queue>
  #include <stack>
  #include <deque>
 #include <iomanip>

  using namespace std;
   

//abcdefghijklmnopqrstuvwxyz
//ABCDEFGHIJKLMNOPQRSTUVWXYZ
  typedef long long ll;
  typedef long double lld;
  typedef string str;
  typedef unsigned long long ull;
  ll INF = INT_MAX;
  // ll mod = 998244353;
  lld PI = 3.141592653;

// const int N = 2e5 + 5;

// int a[N];
// int n,k;



// void solve(){

// string s;
// cin>>s;


// }
 


  int main()
  {
      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
      
   int x,n;
   cin>>x>>n;
   set<int> a;
   for (int i = 0;i<n;i++){int k; cin>>k; a.insert(k);}
    if (!a.count(x)){
      cout<<x<<"\n";
      return 0;
    }
    int up = x+1, down = x-1;
    while (a.count(up) && a.count(down)){
      up++;
      down--;
    }
    if (!a.count(down)){
      cout<<down<<endl;
    }else{
      cout<<up<<endl;
    }


}



Measured memory_bytes: 3148
#include <stdio.h>
int main(void){
    int x, gohyaku, go;
    scanf("%d\n", &x);
    
    gohyaku = x / 500;
    x -= 500*gohyaku;
    go = x / 5;
    
    printf("%d\n", gohyaku*1000 + go*5);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
   int S, h, m, s, a;
   cin>> S;
   h = S / 3600;
   a = S / 60;
   m = a % 60;
   s = S % 60;
   
   cout<< h << ":" << m << ":" << s << endl;
   
}   



Measured memory_bytes: 3136
#include <stdio.h>
#include <math.h>

#define EPS 1e-9

int main(void) {
	const double PI = atan(1) * 4;
	int a, b, x;
	double menseki;
	if (scanf("%d%d%d", &a, &b, &x) != 3) return 1;
	menseki = (double)x / a;
	if (a * b + EPS >= menseki * 2) {
		/* 三角形 */
		printf("%.15f\n", atan2(b, menseki * 2 / b) * 180 / PI);
	} else {
		/* 台形 */
		double zyoutei = 2 * menseki / a - b;
		printf("%.15f\n", atan2(b - zyoutei, a) * 180 / PI);
	}
	return 0;
}


Measured memory_bytes: 256
n,c,k=map(int,input().split())
t=[]
for _ in range(n):
  t.append(int(input()))
t=sorted(t)
i=0
ans=1
a=1
j=1
while j<=n-1:
  if t[i]+k>=t[j] and a<c:
    j=j+1
    a+=1
  else:
    ans+=1
    i=j
    j=j+1
    a=1
print(ans)

Measured memory_bytes: 8280
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
string s;
cin>>s;
string ans="No";
for(int i=0;i<3;i++)
{
if(s[i]!=s[0])
{
ans="Yes";
}
}
cout<<ans;
}



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


  int main()
  {
    long long int a,b,k;
    cin>>a>>b;
    for(int i=1;i<=b;i++)
    {
        if((a*i)%b==0)
        {
            cout<<a*i<<"\n";
            break;
        }
    }
  }


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

using namespace std;
typedef long long ll;

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

	bool flag = false;
	int cnt = 0;

	for(int i = 0; i < n - 1; i++){
		if(s[i] == s[i + 1]){
			flag = true;
		}else{
			flag = false;
		}
		if(flag == false){
			cnt++;
		}
	}

	cout << cnt + 1 << endl;
}

Measured memory_bytes: 512
n=int(input())
dp = [[[[0 for i in range(4)]for i in range(4)]for i in range(4)]for i in range(n)]
mod=10**9+7
for i in range(4):
    dp[0][0][0][i]=1

for i in range(n-1):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for st in range(4):
                    if i>=1:
                        if k==0 and l==1 and st==2:continue
                        if k==0 and l==2 and st==1:continue
                        if k==1 and l==0 and st==2:continue
                    if i>=2:
                        if j==0 and k==1 and st==2:continue
                        if j==0 and l==1 and st==2:continue
                    dp[i+1][k][l][st] = (dp[i+1][k][l][st]+dp[i][j][k][l])%mod


sum=0
for j in range(4):
    for k in range(4):
        for l in range(4):
            sum = (sum+dp[n-1][j][k][l])%mod

#print(*dp[n-1],sep="\n")
print(sum)


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

typedef long long ll;
#define pb push_back
#define mp make_pair
#define pii pair <int,int>
#define in insert
#define X first
#define Y second
#define frn front
#define bc back
#define rep(i,a,b)for (ll (i) = (a); (i) < b(); ++(i))
#define _ << " " <<
#define sz(x) (int)x.size()
#define all(a) (a).begin(),(a).end()

using namespace std;

const int N = 1e5 + 2;
const double PI = 3.14;
const int MOD = 1e7 + 7;

vector <int> p;

int n,a,sol;

int main ()	{
	cin >>n;
	for (int i = 0; i < n; ++i)
	{
		cin >>a;
		p.pb(a);
	}
	for (int i = 0; i < n; ++i)
	{
		if (i+1 == p[i]){
			swap(p[i],p[i+1]);
			sol++;
		}
	}
	cout <<sol<<endl;
	return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[60];
int q[60];
int r[60];
int dp[52][52][10][10];
int bval[52][10][10];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d%d%d",p+i,q+i,r+i);
	for(int i=0;i<52;i++)for(int j=0;j<52;j++)for(int k=0;k<10;k++)
		for(int l=0;l<10;l++)
		dp[i][j][k][l]=-999999999;
	for(int i=0;i<52;i++)for(int j=0;j<10;j++)for(int k=0;k<10;k++)
		bval[i][j][k]=-999999999;
	for(int i=0;i<52;i++){
		for(int j=0;j<=8;j++)for(int k=0;k<=8;k++){
			for(int l=0;l<=j;l++)for(int m=0;m<=k;m++){
				if(l==0&&m==0)continue;
				if(l+m>8)continue;
				bval[i][j][k]=max(bval[i][j][k],p[i]*l+q[i]*m);
			}
			bval[i][j][k]=max(bval[i][j][k],r[i]);
		}
	}
	for(int i=0;i<=min(8,b);i++){
		dp[0][b-i][i][0]=0;
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<=b;j++)for(int k=0;k<=8;k++)for(int l=0;l<=8;l++){
			if(dp[i][j][k][l]<-99999999)continue;
			for(int m=0;m<=min(8,j);m++){
				dp[i+1][j-m][m][k]=max(dp[i+1][j-m][m][k],dp[i][j][k][l]+bval[i][k][l]);
			}
		}
	}
	int ret=-999999999;
	for(int i=0;i<=b;i++){
		for(int k=0;k<=8;k++)for(int l=0;l<=8;l++)
			ret=max(ret,dp[a][i][k][l]);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 2104
//Dragon_warrior7(IITK)
// #pragma GCC optimize("O0") 
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define vll vector<ll>
#define rub cerr << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define Lets_be_precise cout<<fixed<<setprecision(10)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
inline void read(vector<ll> &v);
inline ll max(ll a,ll b);
inline ll min(ll a,ll b);
inline ll gcd(ll a ,ll b);
void storepowers(int n,vector<int> &a);
#define debug false
ll ans;
vector<pair<pll,pll>> vect;
void rec(vll &v)
{
if(v.size()==n)
{
    ll temp=0;
    for(int i=0;i<vect.size();i++)
    {
        ll val=v[vect[i].fi.se-1]-v[vect[i].fi.fi-1];
        if(val==vect[i].se.fi)
        temp+=vect[i].se.se;
    }
    ans=max(ans,temp);
    return;
}
if(v.size()==0)
{
    for(int start=1;start<=m;start++)
    {
        v.pb(start);
        rec(v);
        v.pop_back();
    }
}
else
{
    for(int start=v.back();start<=m;start++)
    {
        v.pb(start);
        rec(v);
        v.pop_back();
    }
}
return ;
}
//#define cerr if(false)cerr//uncomment to remove cerr from program...
void solveforthiscase(const int & test)
{if(debug)cout<<"Case #"<<test<<':'<<'\n';
int q;
cin>>n>>m>>q;
ll a,b,c,d;
for(int i=0;i<q;i++)
{cin>>a>>b>>c>>d;vect.pb({{a,b},{c,d}});}
vector<ll> v;
rec(v);
cout<<ans;
if(debug)cout<<'\n';
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	Lets_be_precise;
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
 	//cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}
void storepowers(int n,vector<int> &a)
{
    a.resize(n+1);
    a[0]=1;
    for(int i=1;i<=n;i++)
    a[i]=a[i-1]*2;
    return ;
}
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
inline void read(vector<ll> &v)
{for (int i = 0; i < v.size(); i++)cin>>v[i];}


Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 105;

int n;
int x[MAXN], y[MAXN], h[MAXN];

int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &x[i], &y[i], &h[i]);
  }

  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      int curH = -1;
      int mx = 2 * 1e9;
      bool good = true;
      for (int i = 0; i < n; i++) {
        if (h[i] != 0) {
          int cur = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
          if (curH == -1) {
            curH = cur;
          } else {
            if (cur != curH) {
              good = false;
            }
          }
        } else {
          mx = min(mx, abs(cx - x[i]) + abs(cy - y[i]));
        }
      }
      if (good && curH != -1 && curH <= mx) {
        cout << cx << " " << cy << " " << curH << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
import math
N, D = list(map(int,input().split()))

x = [list(map(int, input().split())) for _ in range(N)]


ans = 0

for i in range(N):
    for j in range(i+1, N):
        s = 0
        for k in range(D):
            s += (x[i][k] - x[j][k]) ** 2

        if math.sqrt(s) == int(math.sqrt(s)):
            ans += 1
print(ans)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define N 200005 
using namespace std;
int n, m, i, j, k, ans;
char s[N], t[N];
int main(){
	scanf("%s\n%s", s, t);
	n = strlen(s);
	for(i=0; i<=n; i++){
		if(s[i] != t[i]) ans++;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 4092
def modz( x, n):
    a = x / n
    return x - a*n

if __name__ == "__main__":

    n = int(raw_input())

    s = ""
    i = 1

    while True:
        # print "i:{0}".format(i)
        x = i;
        if modz(x , 3) == 0:
            s += " " + str(i)
        else:
            ex = 0
            while True:
                if modz(x , 10) == 3:
                    s += " " + str(i)
                    ex = 1
                    break
                x /= 10
                if x == 0:
                    ex = 1
                    break

        if (i+1) > n:
            i += 1
            break
        i += 1

    print s

Measured memory_bytes: 4240
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    int cnt=0;
    for(int i=0;i<a.size();i++){
        if(a[i]=='C')
            cnt=1;
        if(a[i]=='F'&&cnt==1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from bisect import bisect_left

MOD = 10**9 + 7

N,M = map(int,readline().split())
X = list(map(int,readline().split()))
Y = list(map(int,readline().split()))

L = []; R = []
for x in X:
    i = bisect_left(Y,x) # 右出口
    if i in [0,M]:
        continue
    y0,y1 = Y[i-1:i+1]
    L.append(y0-x); R.append(y1-x)

# 座圧
Rtoi = {x:i for i,x in enumerate(sorted(set(R)),1)}
R = [Rtoi[r] for r in R]

if len(R) == 0:
    print(1)
    exit()

"""
・計算方法
・これをやるために実際にはBITを使う
dp = [0] * (max(R)+1)
for _,r in sorted(set(zip(L,R)),reverse=True):
    dp[r] += 1 + sum(dp[1:r]) #これをやるために BIT で dp を持つ
answer=1+sum(dp)
print(answer)
"""

class BIT():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        
    def get_sum(self,i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i

dp = BIT(max_n=max(R))
for _,r in sorted(set(zip(L,R)),reverse=True):
    x = dp.get_sum(r-1) + 1; x %= MOD
    dp.add(r,x)
answer=1+dp.get_sum(max(R))
answer %= MOD
print(answer)

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

#define ll long long
#define endl "\n"

const ll MOD = 1e9+7;
const int mx = 100005;
vector <ll> factorial(mx);

ll power(ll a, ll b){
    
    ll res = 1;
    while (b){
        if (b%2) res = (res*a);
        if (res >= MOD) res %= MOD;
        b /= 2;
        a  = (a*a);
        if (a >= MOD) a %= MOD;
    }

    return res;
}

ll inverse(ll a){
    return power(a, MOD-2);
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    ll ans = 1;
    r = min(r, n - r);
    ll one = factorial[n];
    ll two = inverse(factorial[r]);
    ll three = inverse(factorial[n-r]);
    ans = (one * two)%MOD;
    ans = (ans * three)%MOD;

    return ans;
}

int main ()
{

	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define int ll
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);

    factorial[0] = 1;
    for (int i=1; i<mx; i++){
        factorial[i] = factorial[i-1]*i;
        if (factorial[i] >= MOD) factorial[i] %= MOD;
    }

    // for (int i=1; i<=10; i++){
    //     int a, b;
    //     cin >> a >> b;
    //     cerr << nCr(a, b) << endl;
    // }

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

    vector <int> numbers(n);
    for (int i=0; i<n; i++) cin >> numbers[i];
    sort(numbers.rbegin(), numbers.rend());

    int ans = 0;
    for (int i=0; i<n; i++){
        cerr << numbers[i] << " ";
        if (i+1 < k){
            ans = (ans + nCr(n-i-1, k-1)*numbers[i])%MOD;
            //cerr << n-i-1 << " " << nCr(n-i-1, k-1) << " first" << endl;
        }
        else if (i+k > n){
            ans = (ans - nCr(i, k-1)*numbers[i] + MOD)%MOD;
            //cerr << i << " " << nCr(i, k-1) << " second" << endl;
        }
        else{
            ans = (ans + nCr(n-i-1, k-1)*numbers[i] - nCr(i, k-1)*numbers[i] + MOD)%MOD;
            //cerr << n-i-1 << " " << nCr(n-i-1, k-1) << " " << i << " " << nCr(i, k-1) << " third" << endl;
        }
        //cerr << ans << endl;
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 4764
#include<iostream>
#include<vector>
#include<set>
#include<string>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    vector<string> v = {"ABC"};
    string str;
    cin >> str;
    v.push_back(str);
    for(auto i:v)
    cout<<i;
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int d = a / b;
		int r = a % b;
		BigDecimal biga = BigDecimal.valueOf(a);
		BigDecimal bigb = BigDecimal.valueOf(b);
		BigDecimal f = biga.divide(bigb, 5, BigDecimal.ROUND_HALF_UP);
		
		System.out.println(d + " " + r + " " + f);
	}

}

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

char c[102][102];

int mx, my;

void dfs(int x, int y){
    if(x < 0 || y < 0 || x >= mx || y >= my){
        return;
    }
    if(c[x][y] == '0'){
        return;
    }
    c[x][y] = '0';
    dfs(x+1, y);
    dfs(x+1, y+2);
    dfs(x+1, y-2);
    dfs(x-1, y);
    dfs(x-1, y+2);
    dfs(x-1, y-2);
    dfs(x, y+2);
    dfs(x, y-2);
    return;
}

int main(){
    int W, H, cnt = 0;
    scanf("%d %d\n", &W, &H);
    while(W != 0 || H != 0){
        mx = H;
        my = 2 * W;
        for(int k = 0; k < H; k++){
            cin.getline(c[k], sizeof(c[k]));
        }
        for(int i = 0; i < H; i++){
            for(int j = 0; j < 2 * W; j++){
                if(c[i][j] == '1'){
                    cnt++;
                    dfs(i, j);
                }
            }
        }
        cout << cnt << endl;
        scanf("%d %d\n", &W, &H);
        cnt = 0;
    }
}



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

int main(){
  long long A,B,C,X,Y;
  cin >>A>>B>>C>>X>>Y;
  
  if(X>=Y){
    if(A+B<2*C){
      cout<< X*A+Y*B<<endl;
      return 0;
    }
    if(A>=2*C){
      cout <<X*2*C<<endl;
      return 0;
    }
    cout<<Y*2*C+(X-Y)*A<<endl;
    return 0;
  }
  
   if(A+B<2*C){
      cout<< X*A+Y*B<<endl;
      return 0;
    }
    if(B>=2*C){
      cout <<Y*2*C<<endl;
      return 0;
    }
    cout<<X*2*C+(Y-X)*B<<endl;
    return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> count(N);
  rep(i, M){
    int a, b;
    cin >> a >> b;
    count[a-1] += 1;
    count[b-1] += 1;
  }
  
  rep(i, count.size()){
    cout << count[i] << endl;
  }
}


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

void call(int n) {
    int i;

    for(i=1; i<=n; i++) {
	if(i % 3 == 0 || i % 10 == 3) {
	    cout << " " << i;
	} else {
	    int x = i;
	    while(x > 10) {
		x /= 10;
		if(x % 10 == 3) {
		    cout << " " << i;
		    break;
		}
	    }
	}
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    call(n);
    return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll dp[51][51][3001];
int main() {
	int n, k;
	cin >> n >> k;
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k <= (i + 1) * (i + 1); k++) {
				(dp[i + 1][j][k + 2 * j] += (2 * j + 1)*dp[i][j][k] % MOD) %= MOD;
				if (j >= 1) (dp[i + 1][j - 1][k + 2 * (j - 1)] += j * j*dp[i][j][k] % MOD) %= MOD;
				(dp[i + 1][j + 1][k + 2 * (j + 1)] += dp[i][j][k]) %= MOD;
			}
		}
	}
	cout << dp[n][0][k] << endl;
}


Measured memory_bytes: 59264
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    ab = []
    
    for _ in range(N):
        a,b = inputMap()
        ab.append((a,b))
        
    ab.sort()
    tmp = K
    
    for i, val in enumerate(ab):
        a,b = val
        tmp -= b
        if tmp <= 0:
            print(a)
            sys.exit()
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 56920
$stdin.each do |input|
  a, b = input.split.map(&:to_i)
  q = ""
  r = []
  i, j = 0, 0
  loop do
    _q, _r = a.divmod b
    q << _q.to_s
    case
    when _r == 0
      break
    when j = r.index(_r)
      break
    else
      r << _r
      i += 1
      a = _r * 10
    end
  end
  puts q[1..-1]
  if j
    puts " "*j + "^"*(i - j)
  end
end

Measured memory_bytes: 6100
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int N, W;
	cin >> N >> W;
	vi v(N), w(N);
	rep(i, N) cin >> v[i] >> w[i];
	vector<vi> dp(N+1, vi(W+1));
	for(int i = 1; i <= N; i++) {
		for(int j = 1; j <= W; j++) {
			dp[i][j] = dp[i-1][j];
			if(j - w[i-1] >= 0) dp[i][j] = max(dp[i-1][j-w[i-1]] + v[i-1], dp[i][j]);
		}
	}
	cout << dp[N][W] << endl;
}



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

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
#define vecout(v,n) for(int i=0; i<n; i++)cout<<v[i]<<" "; cout<<endl;

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}




signed main() {
	int n, m, a, b, ans = 0;
	cin >> n >> m;
	vector<int>vec1(n);
	vector<int>vec2(n);
	vecin(vec1);
	rep(i, m) {
		cin >> a >> b;
		if (vec1[a - 1] == vec1[b - 1]) {
			vec2[a - 1] = 1;
			vec2[b - 1] = 1;
		}
		else if (vec1[a - 1] > vec1[b - 1]) {
			vec2[b - 1] = 1;
		}
		else {
			vec2[a - 1] = 1;
		}
	}
	rep(i, n) {
		if (vec2[i] == 0) {
			ans++;
		}
	}
	cout << ans << endl;
}



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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int n;
	cin >> n;
	string s;
	map<string, int> mp;
	for(int i = 0; i < n; ++i){
		cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}

	long long res = 0;
	for(pair<string, int> x : mp){
		res += (x.second) * 1LL * (x.second - 1) / 2;
	}

	cout << res;
    return 0;
}


Measured memory_bytes: 11264
object Main {
  def main(args: Array[String]): Unit = {
    import java.util.Scanner
    val sc = new Scanner(System.in)
    val x, y = sc.nextInt()
    val area = x * y
    val perimeter = (x + y) * 2
    println(area.toString + " " + perimeter.toString)

  }

}

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

using namespace std;

int n,x,hoge,an=400000;
char s[330000];

int main() {
    cin >> n >> s;
    for (x=0 ; x<n ; x++) if (s[x] == 'E') hoge++;

    an = hoge;

    for (x=0 ; x<n ; x++) {
        if (s[x] == 'E') hoge--;
        if (s[x] == 'W') hoge++;
        if (hoge < an) an = hoge;
    }
    cout << an << "\n";
}


Measured memory_bytes: 512
//ABC149 B

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = s; i < (int)(n); i++)
const lint mod = 1000000007;


lint ans = 0;
lint a,b,k;


int main() {
  cin >> a >> b >> k;
  
  if(a <= k){
    if(b <= k-a){
      a = 0;
      b = 0;
    }
    else{
      b -= k-a;
      a = 0;
    }
  }
  else{
    a -= k;
  }

  printf("%lld %lld\n",a,b);
}


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

#define MAX_N 2200

int dp[MAX_N][MAX_N][2];
string S,T;int a,b,g,h,maxn;

int main(){
	cin>>a>>b;
	cin>>S>>T;
	while(S.size()!=MAX_N){S+=' ';}
	while(T.size()!=MAX_N){T+=' ';}
	g=max(a,b);
	h=min(17,min(a,b));
	for(int i=0;i<=h;i++){
		for(int j=0;j<=g;j++){
			for(int k=0;k<=g;k++){
				if(S[j]=='I'){
					dp[j][k][0]=max(dp[j][k][0],1);
					if(S[j+1]=='O'){dp[j+1][k][0]=max(dp[j+1][k][0],dp[j][k][0]+1);}
					if(T[k]=='O'){dp[k][j+1][1]=max(dp[k][j+1][1],dp[j][k][0]+1);}
				}
				else if(S[j]=='O'){
					if(S[j+1]=='I'){dp[j+1][k][0]=max(dp[j+1][k][0],dp[j][k][0]+1);}
					if(T[k]=='I'){dp[k][j+1][1]=max(dp[k][j+1][1],dp[j][k][0]+1);}
				}
				if(T[k]=='I'){
					dp[k][j][1]=max(dp[k][j][1],1);
					if(T[k+1]=='O'){dp[k+1][j][1]=max(dp[k+1][j][1],dp[k][j][1]+1);}
					if(S[j]=='O'){dp[j][k+1][0]=max(dp[j][k+1][0],dp[k][j][1]+1);}
				}
				else if(T[k]=='O'){
					if(T[k+1]=='I'){dp[k+1][j][1]=max(dp[k+1][j][1],dp[k][j][1]+1);}
					if(S[j]=='I'){dp[j][k+1][0]=max(dp[j][k+1][0],dp[k][j][1]+1);}
				}
			}
		}
	}
	for(int i=0;i<MAX_N;i++){
		for(int j=0;j<MAX_N;j++){
			if(dp[i][j][0]%2==1){
				maxn=max(maxn,dp[i][j][0]);
			}
			if(dp[i][j][1]%2==1){
				maxn=max(maxn,dp[i][j][1]);
			}
		}
	}
	cout<<maxn<<endl;
	return 0;
}

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

int sum(int n){
  int ans=0;
  while(n>0){
    ans+=n%10;
    n/=10;
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  int ans=1e9;
  for(int i=1;i<n;i++){
    ans=min(ans,sum(i)+sum(n-i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256