akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  ll K;
  cin >> N >> K;
  ll A;
  vector<ll> B;
  vector<ll> C;
  ll z = 0;
  for (int i = 0; i < N; i++) {
    cin >> A;
    if (A == 0)
      z++;
    else if (A < 0)
      B.push_back(A);
    else
      C.push_back(A);
  }
  ll nb = B.size();
  ll nc = C.size();
  ll f0 = nb * nc;
  ll f1 = f0 + z * (nb + nc) + (z * (z - 1)) / 2;
  sort(B.begin(), B.end());
  if (K <= f0) {
    sort(C.begin(), C.end(), greater<ll>());
    ll l = -1e18 - 1ll;
    ll r = 0;
    while (r - l > 1) {
      ll m = (l + r) / 2;
      ll sum = 0;
      int j = nb;
      for (int i = 0; i < nc; i++) {
        j = upper_bound(B.begin(), B.begin() + j, m / C[i] - (m % C[i] ? 1 : 0))
            - B.begin();
//        while (j < nc && B[i] * C[j] <= m)
//          j++;
        if (j == 0)
          break;
//        cout << i << " " << j << " " << m << endl;
        sum += j;
      }
      //cout << sum << " " << m << "\n";
      if (sum < K)
        l = m;
      else
        r = m;
    }
    cout << r << "\n";
  } else if (K <= f1) {
    cout << "0\n";
  } else {
    sort(C.begin(), C.end());
    ll l = 0;
    ll r = 1e18 + 1ll;
    while (r - l > 1) {
      ll m = (l + r) / 2;
      ll sum = f1;
      int j = nb - 1;
      for (int i = 0; i < nb - 1; i++) {
        while (j >= 0 && B[i] * B[j] <= m)
          j--;
        sum += min((int) nb - j - 1, (int) nb - i - 1);
      }

      j = 0;
      for (int i = nc - 1; i >= 1; i--) {
        while (j < nc && C[i] * C[j] <= m)
          j++;
        sum += min(i, j);
      }
      // cout << sum << " " << m << "\n";
      if (sum < K)
        l = m;
      else
        r = m;
    }
    cout << r << "\n";
  }
  return 0;
}


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

using namespace std;

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

    vector<vector<int>> adj(n);
    vector<int> deg(n,0);
    vector<int> path(n,0);

    for(int i = 0; i < m; i++) {
        int n1, n2;
        cin >> n1 >> n2;
        n1--; n2--;
        adj[n1].push_back(n2);
        deg[n2]++;
    }

    queue<int> q;
    for(int i = 0; i < n; i++) {
        if(deg[i] == 0) q.push(i);
    }

    int best = 0;

    while(!q.empty()) {
        int curr = q.front();
        q.pop();

        best = max(best, path[curr]);

        for(auto next : adj[curr]) {
            path[next] = max(path[next],path[curr]+1);
            deg[next]--;
            if(deg[next] == 0) {
                q.push(next);
            }
        }
    }

    cout << best << endl;
}


Measured memory_bytes: 6528
def search(field, xs, ys, n, q, c, r):
    if r == 0:
        return field
    for i in range(n):
        if xs[i] >= q:
            continue
        can_vertical = i < n - 1 and xs[i + 1] < q
        for j in range(n):
            if ys[j] >= q:
                continue
            if field[i][j] != 0:
                continue
            if can_vertical and field[i + 1][j] == 0:
                field[i][j] = field[i + 1][j] = c
                xs[i] += 1
                xs[i + 1] += 1
                ys[j] += 1
                result = search(field, xs, ys, n, q, c + 1, r - 1)
                if result is not None:
                    return result
                field[i][j] = field[i + 1][j] = 0
                xs[i] -= 1
                xs[i + 1] -= 1
                ys[j] -= 1
            if j < n - 1 and ys[j + 1] < q and field[i][j + 1] == 0:
                field[i][j] = field[i][j + 1] = c
                xs[i] += 1
                ys[j] += 1
                ys[j + 1] += 1
                result = search(field, xs, ys, n, q, c + 1, r - 1)
                if result is not None:
                    return result
                field[i][j] = field[i][j + 1] = 0
                xs[i] -= 1
                ys[j] -= 1
                ys[j + 1] -= 1
    return None


def search_main(n, q=3):
    print(n, q)
    field = [[0] * n for _ in range(n)]
    xs = [0] * n
    ys = [0] * n
    remain = n * 2 * q // 3
    result = search(field, xs, ys, n, q, 1, remain)
    if result is None:
        print(None)
    else:
        for row in result:
            print(' '.join('{:02d}'.format(x) for x in row))


def solve(n):
    if n <= 2:
        print(-1)
        return
    if n == 3:
        print('aab\nc.b\ncdd')
        return
    field = [['.'] * n for _ in range(n)]
    r = n % 4
    repeat = [n, n - 5, n - 6, n - 7]
    for i in range(0, repeat[r], 4):
        field[i + 0][i:i + 4] = list('aacd')
        field[i + 1][i:i + 4] = list('bbcd')
        field[i + 2][i:i + 4] = list('efgg')
        field[i + 3][i:i + 4] = list('efhh')

    if r == 1:
        field[n - 5][n - 5:n] = list('abc..')
        field[n - 4][n - 5:n] = list('abc..')
        field[n - 3][n - 5:n] = list('deeff')
        field[n - 2][n - 5:n] = list('d.ghh')
        field[n - 1][n - 5:n] = list('iigjj')
    elif r == 2:
        field[n - 6][n - 6:n] = list('abc...')
        field[n - 5][n - 6:n] = list('abc...')
        field[n - 4][n - 6:n] = list('d.eeff')
        field[n - 3][n - 6:n] = list('dghh..')
        field[n - 2][n - 6:n] = list('.g.ijj')
        field[n - 1][n - 6:n] = list('kk.ill')
    elif r == 3:
        field[n - 7][n - 7:n] = list('abc....')
        field[n - 6][n - 7:n] = list('abc....')
        field[n - 5][n - 7:n] = list('def....')
        field[n - 4][n - 7:n] = list('def....')
        field[n - 3][n - 7:n] = list('g..hhii')
        field[n - 2][n - 7:n] = list('g..jjkk')
        field[n - 1][n - 7:n] = list('.llmmnn')

    print('\n'.join(map(''.join, field)))


# search_main(4)
# search_main(5)
# search_main(6)
# search_main(7)
n = int(input())
solve(n)


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

int main(){
	
	int x, y, z;
	cin >> x >> y >> z;
	int t;
	t = x;
	x = y;
	y = t;
	t = x;
	x = z;
	z = t;
	cout << x << " " << y << " " << z;
	return 0;
}

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

using namespace std;

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

int main(){
    long N,K;
    cin>>N>>K;
    long a,b,c;
    a=N/K;
    b=N-a*K;
    c=(a+1)*K-N;
    long d=min(N,b);
    cout<<min(d,c)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n;
  int a[30000];
  scanf("%d", &n);
  for(int x = 1;x <= 98; x++){
    for(int y = 1;y<=x && y <= 140 -x;y++){
      for(int z = 1;z<=y;z++){
        a[(x+y+z)*(x+y+z) - x*y - x*z - y*z - 1] += 6;
        if(x == y || x == z || y == z){
          a[(x+y+z)*(x+y+z) - x*y - x*z - y*z - 1] -= 3;
          if(x == y && y == z)
            a[(x+y+z)*(x+y+z) - x*y - x*z - y*z - 1] -= 2;
        }
      }
    }
  }
  for(int i = 0; i < n; i++){
    printf("%d\n", a[i]);
  }
  
  return 0;
}

Measured memory_bytes: 1788
#include<stdio.h>
int main()
{
	int a,b,c,i,temp=0;
	scanf("%d%d%d",&a,&b,&c);
	for(i=a;i<b+1;i++)
	{
		if(c%i==0)
		{
			temp++;
		}
	}
	printf("%d\n",temp);
	return 0;
}

Measured memory_bytes: 596
# import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

input()
a_list = [int(s) for s in input().split()]

N = len(a_list)
min_last_hp = 10**10

f = min(a_list)
a_list.remove(f)

for i in a_list:
    last_hp = gcd(f, i)
    if last_hp < min_last_hp:
        min_last_hp = last_hp

s = min(a_list)
kouho=gcd(f,s)
if kouho < min_last_hp:
    print(kouho)
else:
    print(min_last_hp)


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<pair<pair<int,int>, int>> city(M);
  vector<pair<int, int>> ans(M);
  
  for (int i = 0; i < M; i++) {
    int P, Y;
    cin >> P >> Y;
    pair<int, int> p = make_pair(P,Y);
    city[i] = make_pair(p, i);
    
    pair<int, int> q = make_pair(P, 0); // 0 は適当な数
    ans[i] = q; // 市i の 所属する県だけチェックしておく．
  }

  sort(city.begin(), city.end());
  
  int lower = 1;
  vector<pair<int,int>> junban(M);
  
  for (int i = 0; i < M; i++) {
     if (city[i].first.first == city[i+1].first.first) {
      ans[city[i].second].second = lower;
      lower++;
     } else {
      pair<int, int> q = make_pair(city[i].second, lower);
      ans[city[i].second].second = lower;
      lower = 1;
     }
      
  }
  for (int i = 0; i < M; i++) {
    printf("%06d", ans[i].first);
    printf("%06d", ans[i].second);
    cout << endl;
      
      
  }
  
  
}

Measured memory_bytes: 4224
A,B,C,K = map(int,input().split())

xa = min(A,K)
K1 = K -xa
if K1 == 0:
  print(K)
else:
	xb = min(B,K1)
	K2 = K1 -xb
	if K2 == 0:
  		print(A)
	else:
   		print(A-K2)

Measured memory_bytes: 9172
n, m  = map(int, input().split())
a_b = []

for i in range(n):
    a_b.append(list(map(int, input().split())))

a_b.sort()

res = 0
counter = 0
for i in range(n):
    counter = min(m, a_b[i][1])
    m -= counter
    res += counter * a_b[i][0]
    if m == 0:
        break
print(res)

Measured memory_bytes: 27304
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string.h>
#include<algorithm>
#include<functional>
using namespace std;

int main(void){

	int A, B, C;
	cin >> A >> B >> C;

	int go=0, nana=0;

	if (A == 5)go++;
	else if (A == 7)nana++;

	if (B == 5)go++;
	else if (B == 7)nana++;

	if (C == 5)go++;
	else if (C == 7)nana++;


	if (go == 2 && nana == 1)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof a)
#define MAX 100005
using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans[4]={a*c,a*d,b*c,b*d};
    sort(ans,ans+4);
    cout<<ans[3];
}

Measured memory_bytes: 3640
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3,tune=native")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define ull unsigned long long
#define y1 asjdlfaskavslbcjasndscf
#define endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter vector< int >::iterator
#define iter1 multiset<int>::iterator
#define int long long
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

const int N=1e7+7;
const int inf=1e18+1e9;
const int mod=998244353;
const ld eps=1e-9;

//const int MAX_MEM=1e8;
//int mpos=0;
//char mem[MAX_MEM];
//
//inline void * operator new(size_t n){
//    char *res=mem+mpos;
//    mpos+=n;
//    assert(mpos<=MAX_MEM);
//    return (void*)res;
//}
//
//inline void operator delete(void *) {}

main ()
{
    ios;
    string s;
    int k;
    cin>>s>>k;
    vector< pair<int,int> >a;
    int cur=0;
    for (int i=0;i<s.size();++i){
        if (i && s[i]!=s[i-1]){
            a.pb({s[i-1],cur});
            cur=1;
        }
        else {
            ++cur;
        }
    }
    a.pb({s.back(),cur});
    if (a.size()==1){
        int ans=(int)s.size()*k;
        cout<<ans/2<<endl;
        exit(0);
    }
    if (a[0].ff!=a.back().ff){
        int res=0;
        for (int i=0;i<a.size();++i){
            res+=a[i].ss/2;
        }
        int ans=res*k;
        cout<<ans<<endl;
    }
    else {
        int res=0;
        for (int i=1;i<(int)a.size()-1;++i){
            res+=a[i].ss/2;
        }
        int f=a[0].ss+a.back().ss;
        int ans=res*k+(k-1)*(f/2);
        ans+=a[0].ss/2+a.back().ss/2;
        cout<<ans<<endl;
    }
}


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

using ll=long long;
const ll z=0;
const ll INF=2*pow(10,9);

int main() {
  int K,N;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  sort(h.begin(),h.end());
  int ans=INF;
  for(int i=0;i<=N-K;i++){
    int a=h[i+K-1]-h[i];
    ans=min(ans,a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
A,B=tuple(int(i) for i in input().split(" "))
err=lambda X:abs(int(X*0.08)-A)+abs(int(X*0.10)-B)
rg=[int(A/0.08),int(B/0.10)]
rg.sort()
rg[0]-=int(1/0.08)
rg[1]+=int(1/0.08)
solv=[X for X in range(*rg) if err(X)==0]
solv.sort()
if(len(solv)==0):
    print("-1")
else:
    print(solv[0])


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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    
    sort(d.begin(),d.end());

    cout << d[n/2] - d[n/2-1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

bool solve(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];

  long tot = accumulate(all(v), 0L);
  long mx = *max_element(all(v));

  return tot - mx > mx;
}

int main(){
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
//DavitMarg//
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iterator>
#include <ctype.h>
#include <cassert>
#include <unordered_map>
#include <time.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
int n;
LL a[404],pr[404],dp[404][404];

LL sum(int l, int r)
{
	return pr[r] - pr[l - 1];
}

void dfs(int l,int r)
{
	if (l == r)
		dp[l][r] = 0;
	if (dp[l][r] != -1)
		return;
	dp[l][r] = mod * mod;
	for (int i = l; i < r; i++)
	{
		dfs(l, i);
		dfs(i + 1, r);
		dp[l][r] = min(sum(l, r) + dp[l][i] + dp[i + 1][r], dp[l][r]);
	}
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		pr[i] = pr[i - 1] + a[i];
	}
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n; j++)
			dp[i][j] = -1;
	sort(a + 1, a + 1 + n);
	dfs(1,n);
	cout << dp[1][n] << endl;
	return 0;
}

/*
5 4
0 1 0 1 0

4 3
0 1 0 1

*/

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

const ll mod = 1e9 + 7;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
   // cin >> T;
    T = 1;
    for(int cs = 1; cs <= T; cs++)
    {
        int n,m,k;
        cin >> n >> m >> k;
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= m; j++){
                if(i * (m - j) + j * (n - i) == k){
                    cout << "Yes\n";
                    return 0;
                }
            }
        }
        cout << "No\n";
        return 0;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


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

using namespace std;

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

   vector<float> a(N);
   float sum=0;

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

      cin >> a[i];
      sum += 1/a[i];

   }

   cout << 1/sum << endl;

   return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		long K=sc.nextLong();
		long[] ito=new long[N];
		long nagasa=0;
		for(int i=0; i<N; i++) {
			ito[i]=sc.nextLong();
		}
		int counter=-1;
		for(int i=0; i<N-1; i++) {
			if(ito[i]+ito[i+1]>=K) {
				counter=i;
				break;
			}
		}
		if(counter==-1) {
			pl("Impossible");
		}
		else {
			pl("Possible");
			for(int i=0; i<counter; i++) {
				pl(i+1);
			}
			for(int i=N-1; i>counter; i--) {
				pl(i);
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


Measured memory_bytes: 61000
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

    class MainClass
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
                        return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }
        public static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            var s = Console.ReadLine();
            var k = Read();
            
            int memo = 0;
            for(int i = 0; i < s.Length; i++)
            {
                if (s[i] != '1')
                {
                    memo = i;      
                    break;
                }
            }
         
            if (k-1 < memo)
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(s[memo]);
            }
            


                Console.Out.Flush();
        }
    }



Measured memory_bytes: 13140
#include <stdio.h>
int main(void) {
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0) break;	
		int i,x[n],y[n],h[n],w[n],v[n];;
		for(i=0;i<n;i++){
			scanf("%d %d %d %d",&x[i],&y[i],&h[i],&w[i]);
			v[i]=x[i]+y[i]+h[i];
		}
		int a=0,b=0,c=0,d=0,e=0,f=0;
		for(i=0;i<n;i++){
			if(v[i]<=60&&w[i]<=2){
				a++;
			}
			else if(v[i]<=80&&w[i]<=5){
				b++;
			}
			else if(v[i]<=100&&w[i]<=10){
				c++;
			}
			else if(v[i]<=120&&w[i]<=15){
				d++;
			}
			else if(v[i]<=140&&w[i]<=20){
				e++;
			}
			else if(v[i]<=160&&w[i]<=25){
				f++;
			}
		}
		printf("%d\n",(a*600)+(b*800)+(c*1000)+(d*1200)+(e*1400)+(f*1600));
	}
	return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

string s[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string t;
    cin >> t;
    cout << 7 - (find(s, s+7, t)-s);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define WHILE 0
#define GRAY 1
#define BLACK 2
int G[MAX+1][MAX+1],vt[MAX+1],f[MAX+1];
int col[MAX+1];
int time=0,n;



void visit(int i){
  int u;
  col[i] = GRAY;
  vt[i] = ++time;

  for(u=1; u<=n; u++){
    if(G[i][u] == 0)continue;
    if(col[u] == WHILE){
      visit(u);
    }
  }
  col[i] = BLACK;
  f[i] = ++time;
}


void finish(){
  int i;
  time=0;
  for(i=1; i<=n; i++){
    if(col[i] == WHILE)visit(i);
  }
}

int main(){
  int i,j,l,len,num,k;

  for(i=0; i<MAX+1; i++){
    for(j=0; j<MAX+1; j++){
      G[i][j]=0;
    }
    col[i] = WHILE;
  }
  //表に入れる  
  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d %d",&len,&num);
    for(l=0; l<num; l++){
      scanf("%d",&k);
      for(j=1; j<=n; j++){
	if(k==j)G[len][j]=1;
      }
    }
  }

  //探索
  finish();
  
  //出力  
  for(i=1; i<=n; i++){
    printf("%d %d %d\n",i,vt[i],f[i]);
  }
  
  return 0;
}



Measured memory_bytes: 2052
#include <stdio.h>
//#include <stdlib.h>

int divisor(int x){
  int i;
  int result = 1;
  for(i = 0; i < x; i++){
    result *= 2;
  }
  return result;
}

int main(){
  int N;
  scanf("%d",&N);
  int a[N];
  int i;
  for(i = 0; i < N; i++){
    a[i] = i + 1;
  }
  int answer;
  int count = 0;
  i = 0;
  for(i = 0; i < N; i++){
    int j = 1;
    while((a[i]%divisor(j)) == 0){
      j++;
    }
    if(count <= j - 1){
      count = j - 1;
      answer = a[i];
    }
  }

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

Measured memory_bytes: 128
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(int argc, const char * argv[]) {
    int N; cin >> N;
    vector<int> SA1(N), SA2(N);
    for (int i = 0; i < N; i++) {
        int a1; cin >> a1;
        SA1[i] = (i == 0) ? a1 : SA1[i-1] + a1;
    }
    for (int i = 0; i < N; i++) {
        int a2; cin >> a2;
        SA2[i] = (i == 0) ? a2 : SA2[i-1] + a2;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, SA1[i] + SA2[N-1] - (i == 0 ? 0 : SA2[i-1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  int n,m; cin >> n >> m;
  vi a(m), b(m), c(m);
  int dist[n][n];
  rep(i, n) rep(j, n){
    if(i == j) dist[i][j] = 0;
    else dist[i][j] = 1e9;
  }
  rep(i, m){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }

  rep(k, n) rep(i, n) rep(j, n) chmin(dist[i][j], dist[i][k] + dist[k][j]);

  int ans = 0;
  rep(i, m){
    bool ok = true;
    rep(s, n){
      if(dist[s][a[i]] + c[i] == dist[s][b[i]]) ok = false;
    }
    if(ok) ans++;
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 256
import std;

void main() {
  int N; long M;
  scan(N, M);
  auto a = readln.split.to!(long[]).map!(x => x % M).array;
  
  long[long] cnt;
  cnt[0] = 1;
  long rem;
  long ans;
  
  foreach (i; 0 .. N) {
    rem = (rem + a[i]) % M;
    if (rem in cnt) ans += cnt[rem];
    cnt[rem]++;
  }
  
  writeln(ans);
}
  


void scan(T...)(ref T args) {
    auto line = readln.split; // @suppress(dscanner.suspicious.unmodified)
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}
 
void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
 
bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}
 
bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args)
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    return isChanged;
}
 
void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define pb push_back
#define ins insert

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }
/*
struct Edge {
  int to;
  ll w;
};
*/
struct Edge {
  int s,t;
  ll w;
  bool operator < ( const Edge &e ) const {
    if( w != e.w ) return w < e.w;
    if( s != e.s ) return s < e.s;
    return t < e.t;
  }
};
#define MAX 100010

ll need[MAX],sum[MAX], ans[MAX];
int par[MAX];
int find(int x) {
  if( x == par[x] ) return x;
  return par[x] = find(par[x]);
}
void unite(int x,int y) {
  x = find(x), y = find(y);
  if( x != y ) par[x] = y;
}

const bool debug = 0;///////////////////////////////////

int V,E;
ll X[MAX];
void compute() {

}

int main() {
  cin >> V >> E;
  rep(i,V) par[i] = i;
  rep(i,V) cin >> X[i];
  vector<Edge> es;
  rep(i,E) {
    int s,t,w;
    cin >> s >> t >> w;
    --s, -- t;
    es.push_back((Edge){s,t,w});
  }
  sort(ALL(es));
  // sum = sum of vetetex weight
  // need = max edge weight
  rep(i,V) need[i] = 0, ans[i] = 0;
  rep(i,V) sum[i] = X[i];
  map<int,int> es_size;
  rep(i,(int)es.size()) {
    int s = es[i].s, t = es[i].t;
    ll w = es[i].w;
    if( debug ) {
      cout << "[" << i << "] " << s << "," << t << " w = " << w << endl;
      cout << "  find(" << s << ") = " << find(s) << endl;
      cout << "  find(" << t << ") = " << find(t) << endl;
    }
    
    if( find(s) != find(t) ) {
      ll tmp = sum[find(s)] + sum[find(t)];
      ll maxi = max(max(need[find(s)],need[find(t)]),w);
      ll new_size = es_size[find(s)] + es_size[find(t)] + 1;
      //ll ans_maxi = max(ans[find(s)],ans[find(t)]);
      ll ans_maxi = ans[find(s)]+ans[find(t)];
      if( debug ) {
	cout << "  sum of vertex weight = " << tmp << endl;
	cout << "  max edge weight = " << maxi << endl;
	cout << "  edge num = " << new_size << endl;
	cout << "  ans maxi = " << ans_maxi << endl;
      }
      
      unite(s,t);
      es_size[find(s)] = new_size;
      sum[find(s)] = tmp;
      need[find(s)] = max(need[find(s)],maxi);
      need[find(s)] = max(need[find(s)],w);
      ans[find(s)] = max(ans[find(s)],ans_maxi);
    } else {
      need[find(s)] = max(need[find(s)],w);
      ++es_size[find(s)];
    }
    if( need[find(s)] <= sum[find(s)] ) {
      if( debug ) {
	cout << "  ok! " << need[find(s)] << " <= " << sum[find(s)] << endl;
	cout << "  ans[" << i << "] (" << ans[i] << ") ?= " << es_size[find(s)] << endl;
      }
      ans[find(s)] = max(ans[find(s)],(ll)es_size[find(s)]);
    }
  }
  set<int> gs;
  rep(i,V) gs.insert(find(i));
  ll maxi = 0;
  if(debug){
  rep(i,V) {
    cout << i << " : " << ans[i] << endl;
  }
  }
  for(auto v : gs) {
    if( debug ) {
      cout << "  ?? v = " << v << endl;
    }
    maxi += ans[v];
  }
  if( debug ) {
    cout << "FINALLY! " << maxi << endl;
  }
  cout << E - maxi << endl;
  
  compute();
  return 0;
}


Measured memory_bytes: 10480
s = input()
n = len(s)
cnt1 = cnt2 = 0
for i in range(n):
    if i % 2:
        if s[i] == '1':
            cnt1 += 1
        else:
            cnt2 += 1
    else:
        if s[i] == '0':
            cnt1 += 1
        else:
            cnt2 += 1
print(min(cnt1, cnt2))

Measured memory_bytes: 3188
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;
	auto Q = RD;
	auto s = new long[](A);
	auto t = new long[](B);
	auto x = new long[](Q);
	foreach (i; 0..A)
	{
		s[i] = RD;
	}
	foreach (i; 0..B)
	{
		t[i] = RD;
	}
	foreach (i; 0..Q)
	{
		x[i] = RD;
	}

	foreach (i; 0..Q)
	{
		auto sl = assumeSorted(s).lowerBound(x[i]);
		auto tl = assumeSorted(t).lowerBound(x[i]);
		auto sr = assumeSorted(s).upperBound(x[i]);
		auto tr = assumeSorted(t).upperBound(x[i]);
		long l1, l2, r1, r2;
		if (!sl.empty)
			l1 = sl.back;
		if (!tl.empty)
			l2 = tl.back;
		if (!sr.empty)
			r1 = sr.front;
		if (!tr.empty)
			r2 = tr.front;
		
		long ans1 = long.max, ans2 = long.max, ans3 = long.max, ans4 = long.max;
		if (l1 != 0 && l2 != 0)
			ans1 = x[i] - min(l1, l2);
		if (r1 != 0 && r2 != 0)
			ans2 = max(r1, r2) - x[i];
		if (l1 != 0 && r2 != 0)
		{
			auto d1 = x[i] - l1;
			auto d2 = r2 - x[i];
			ans3 = min(d1, d2) * 2 + max(d1, d2);
		}
		if (r1 != 0 && l2 != 0)
		{
			auto d1 = x[i] - l2;
			auto d2 = r1 - x[i];
			ans4 = min(d1, d2) * 2 + max(d1, d2);
		}
		writeln(min(ans1, ans2, ans3, ans4));
	}
	
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 5756
#include<bits/stdc++.h>
using namespace std;const int X=1e6;int N,a,b,i,V[X],f[X];pair<int, int>R[X];main(){cin>>N;for(;i<N;i++){cin>>a>>b;R[i]={a,a+b};}sort(R,R+N);V[N]=1;for(;i--;){for(a=i+1;a<N&&R[a].first<R[i].second;a=f[a]);V[i]=(V[i+1]+V[f[i]=a])%998244353;}cout<<*V;}

Measured memory_bytes: 9984
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) 
{	
	char w[100];
	scanf("%s", w);
	
	/* a to z corresponds to ACSII 97 to 122 */
	int alphabet = 123, asciiVal;
	int arr[alphabet];
	
	/* initialize arr[] to 0 */
	for (int i = 0; i < alphabet; i++) {
		arr[i] = 0;
	}
	
	/* increment corresponding ACSII values */
	for (int i = 0; w[i] != '\0'; i++) {
		asciiVal = w[i];
		arr[asciiVal]++;
	}
	
	for (int i = 0; i < alphabet; i++) {
		if (arr[i] % 2 != 0) {
			printf("No\n");
			return 0;
		}
	}
	
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        sb.append(s);
        sb.reverse();
        s = sb.toString();
//        char[] s = sc.next().toCharArray();

        String[] arr = {"maerd", "remaerd", "esare", "resare"};

//        System.out.println(s);

        int idx = 0;

        out:
        while (idx < s.length()) {
            int cnt = 0;
            for (int i=0; i<4; i++) {
                if (s.substring(idx, Math.min(idx+8, s.length())).startsWith(arr[i])) {
                    idx += arr[i].length();
//                    s = s.replace(arr[i], "");
//                    System.out.println(s);
                    continue out;
                }
                cnt++;
            }
            if (cnt == 4) {
                System.out.println("NO");
                return;
            }
        }

        System.out.println("YES");


    }

}



Measured memory_bytes: 27588
#include <iostream>

using namespace std;

int k, n, a, b, pr, m;

int main () {
  cin >> k >> n;
  cin >> pr; b = pr;
  for (int i = 2; i <= n; i++) {
    cin >> a;              // [ideea de rezolvare] e
    m = max (m, a - b);    // (perimetru - distana maxima dintre doua case)
    b = a;
  }
  m = max (m, pr + k - b); // daca te intorci din casa (1) in casa (n)
  cout << k - m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll,pair<ll, ll> > P3;
const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(2e5) + 5;
const int MAX_V = 100005;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
int n;
ll a[MAX_N]{};
 
int main() {
    cin >> n;
    REP(i,n){
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    int li = 1, ri = 3;
    ll ans = LLINF;
    for(int i = 2; i < n-1;i++){
        ll lsum = a[i], rsum = a[n]-a[i];
        ll p=a[li],q=lsum-a[li] ,r = a[ri]-a[i],s = rsum-a[ri]+a[i];
        while(li<i-1 && abs(lsum - a[li+1]*2) < abs(p-q)){
            li++;
            p = a[li];
            q = lsum - p;
        }
        while(ri<n-1 && abs(rsum - (a[ri+1]-a[i])*2)<abs(r-s)){
            ri++;
            r = a[ri]-a[i];
            s = rsum - r;
        }
        ll mx = max(max(p,q),max(r,s)), mn = min(min(p,q),min(r,s));
        ans = min(ans,mx-mn);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
 
#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll int a,b;
		cin>>a>>b;
		for(ll int i=0;true;i++)
		{
			if(i*a+1-i>=b) 
			{
				cout<<i;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int r,c;
	while(1){
		cin >> r >> c;
		if(r==1&&c%2==1){
			cout << "no" << endl;
		}else if(r%2==1&&c==1){
			cout << "no" << endl;
		}else if(r==0&&c==0){
			break;
		}else if(r%2==1&&c%2==1){
			cout << "no" << endl;
		}else{
			cout << "yes" << endl;
		}
	}
}
		
		


Measured memory_bytes: 3092
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;

const int MAXN = 1234567;
char s[MAXN];
int k[87];

LL solve(int N, int K) {
   LL cntD = 0, cntM = 0, cur = 0, nrD = 0;
   LL ans = 0, sum = 0;
   while (cur < N && cur < K - 1) {
         char c = s[cur];
         if (c == 'D') {
            nrD++;
         } else if (c == 'M') {
            cntD += nrD;
            nrD = 0;
            cntM++;
            sum += cntD;
         } else if (c == 'C') {
            ans += sum;
         }
         cur++;
   }
   while (cur < N) {
         char ft = s[cur - K], bk = s[cur];
         if (ft == 'D') {
            sum -= cntM;
            if (cntM) cntD--;
            else nrD--;
         } else if (ft == 'M') {
            cntM--;
         }
         if (bk == 'C') {
            ans += sum;
         } else if (bk == 'M') {
            cntD += nrD;
            nrD = 0;
            cntM++;
            sum += cntD;
         } else if (bk == 'D') {
            nrD++;
         }
         cur++;
   }
   return ans;
}

int main() {
    int N, Q;
    scanf("%d", &N);
    scanf("%s", s);
    scanf("%d", &Q);
    for (int i = 0; i < Q; i++) scanf("%d", &k[i]);
    for (int i = 0; i < Q; i++) {
        printf("%lld\n", solve(N, k[i]));
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
int main() {
cout << fixed << setprecision(30);
  ll n,m;
  string s,t;
  cin4(n,m,s,t);
  ll l=lcm(n,m);
  ll x=gcd(n,m);
  ll u=n/x,v=m/x;
  bool check=true;
  loop(i,x){
    if(s[i*u]!=t[i*v])check=false;
  }
  if(check)putout(l);
  else putout(-1);
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int mod=1e9+7;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
		a[i]-=i+1;
	}
	sort(a.begin(), a.end());
	ll b=a[n/2], ans=0;
	for(int i=0; i<n; i++)
		ans += abs(a[i]-b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;
 
int32_t main(){
	double pi = acos(-1.0);
	int r;
	cin >> r;
	cout << fixed << setprecision(15) << 2.0 * pi * r;
 
	return 0;
}

Measured memory_bytes: 3780
def hojyu(a):
  if len(a)!=N:
    return "0"*(N-len(a))+a
  else:
    return a
S=input()
N=len(S)-1
R=list()
ans=0
for i in range(2**N):
  s=str(bin(i)[2:])
  s=hojyu(s)
  b=0
  mae=0
  for k in range(len(s)):
    if s[k]=="1":
      b+=int(S[mae:k+1])
      mae=k+1
  b+=int(S[mae:])
  ans+=b
print(ans)

Measured memory_bytes: 9236
#!/usr/bin/env python3

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors




K = int(input())

r = [1,2,3,4,5,6,7,8,9]
if K < 10:
    print(r[K-1])
    exit()
f = True
index = 10
cnt = 0
start = 0
while f==True:
    r_len = len(r)
    for i in range(start, r_len):
        s = str(r[i])
        migi = len(s)-1
        ix1 = str(int(s[migi])-1)
        ix2 = str(int(s[migi])+1)
        if int(ix1)>=0:
            r.append(int(s+ix1))
        r.append(int(s+s[migi]))
        if int(ix2)<=9:
            r.append(int(s+ix2))
    start = r_len
    if len(r) > 100000:
        f = False

r = sorted(r)
print(r[K-1])


Measured memory_bytes: 12560
from sys import exit
c = [list(map(int, input().split())) for _ in range(3)]
a = [None] * 3
b = [None] * 3
a[0] = 0
for j in range(3):
  b[j] = c[0][j] - a[0]
for i in range(1, 3):
  a[i] = c[i][0] - b[0]
for i in range(3):
  for j in range(3):
    if c[i][j] != a[i] + b[j]:
      print('No')
      exit()
print('Yes')


Measured memory_bytes: 3064
import java.util.stream.*;
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] ab = IntStream.range(0, m).mapToObj(i -> new int[] {scanner.nextInt(), scanner.nextInt()}).sorted(Comparator.comparingInt(a -> a[1])).toArray(int[][]::new);

        int ans = 0;
        for (int i = 0, l = -1; i < m; i++) {
            if (ab[i][0] > l) {
                l = ab[i][1] - 1;
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 96032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Main {
    public void solve(final BufferedReader stdin, final PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        Map<Integer, Long> d = Pattern.compile(" ")
                                      .splitAsStream(stdin.readLine())
                                      .map(Integer::valueOf)
                                      .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
        d.put(0, d.getOrDefault(0, 0L) + 1);

        List<List<Integer>> times = new ArrayList<>();
        times.add(new ArrayList<>());
        for (Entry<Integer, Long> e : d.entrySet()) {
            if (e.getValue() > 2) {
                stdout.println(0);
                return ;
            }

            if (e.getValue() == 1) {
                List<List<Integer>> temp = new ArrayList<>();
                for (List<Integer> time : times) {
                    List<Integer> time1 = new ArrayList<>(time);
                    List<Integer> time2 = new ArrayList<>(time);
                    time1.add(e.getKey());
                    time2.add(e.getKey() * -1);
                    temp.add(time1);
                    temp.add(time2);
                }
                times = temp;
            } else {
                // e.getValue() == 2
                for (List<Integer> time : times) {
                    time.add(e.getKey());
                    time.add(e.getKey() * -1);
                }
            }
        }

        int max = -1;
        for (List<Integer> time : times) {
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < time.size(); i++) {
                for (int j = i + 1; j < time.size(); j++) {
                    int x = Math.abs(time.get(i) - time.get(j));
                    int y = Math.min(x, 24 - x);
                    min = Math.min(min, y);
                }
            }
            max = Math.max(max, min);
        }

        stdout.println(max);
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 28500
import java.util.*;


class Main{
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    double d,t,s;
    d = 0; if(input.hasNextDouble())d = input.nextDouble();
    t = 0; if(input.hasNextDouble())t = input.nextDouble();
    s = 0; if(input.hasNextDouble())s = input.nextDouble();
    
    double speed = (double)d/t;
    //System.out.printf("%f %f\n",s,speed);
    if(speed<=s)System.out.println("Yes");
    else System.out.println("No");
    
    
    
    
    
  }
}

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

int main() {
  int N,T,A;
  cin>>N;
  cin>>T>>A;
  
  int h[1010];
  for(int i=0;i<N;i++){
    cin>>h[i];
  }
  
  int ans=0;
  double min=100000;
  for(int i=0;i<N;++i){
    double x=abs(A-(T-0.006*h[i]));
    if(x<min){
      min=x;
      ans=i+1;
    }
  }
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256