akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main(){
    ll N, K; cin >> N >> K;
    if(N == K){cout << 0;}
    else{
        if(N > K){
            N = N%K;
        }
        ll ans = min(N, abs(N-K));
        cout << ans;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
int main() {
    string s;int k;
    cin>>k>>s;
    if (s.size()<=k)
    {
        /* code */
        cout<<s<<endl;
    }
    else
    {
        REP(i,k){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    
    
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define IOS                \
  ios::sync_with_stdio(0); \
  cin.tie(0);              \
  cout.tie(0);
#define int long long
const unsigned int M = 1000000007;
using namespace std;
int32_t main()
{
  IOS int n, m, k;
  cin >> n >> m >> k;
  int a[n + 1] = {0}, b[m + 1] = {0};
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    a[i] += a[i - 1];
  }
  for (int i = 1; i <= m; i++)
  {
    cin >> b[i];
    b[i] += b[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= n; i++)
  {
    if (a[i] > k)
      break;
    int l = 0, r = m;
    int idx = 0;
    while (l <= r)
    {
      int mid = (l + r) / 2;
      if (k - a[i] == b[mid])
      {
        idx = mid;
        break;
      }
      else if (k - a[i] > b[mid])
      {
        l = mid + 1;
      }
      else
      {
        idx = mid - 1;
        r = mid - 1;
      }
    }
    ans = max(ans, i + idx);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 10;
int a[maxn], k;
int main(void) {
    std::ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    while(cin >> k) {
        for(int i = 0; i < k; ++i) cin >> a[i];
        ll l0 = 2LL, r0 = 2LL;
        for(int i = k - 1; i >= 0; --i) {
            if(r0 < l0) break;
            if(l0 % a[i]) l0 = (l0 / a[i]) * a[i] + a[i];
            r0 = (r0 / a[i] + 1LL) * a[i] - 1LL;
        }
        if(l0 <= r0) cout << l0 << ' ' << r0 << endl;
        else cout << -1 << endl;
    }
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int x[5], ans;
    
    rep(i, 5){
        scanf("%d", &x[i]);
        if (x[i]==0) {
            ans=i+1;
        }
    }
    
    printf("%d", ans);
    
    return 0;
}



Measured memory_bytes: 1684
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
const int inf = 0x3f3f3f;
int main()
{
    int a[20];
    bool vis[20];
    memset(vis,0,sizeof(vis));
    for(int i = 1 ; i <= 10 ; i++)
        scanf("%d",&a[i]);
    for(int k = 1 ; k <= 3 ; k++)
    {
        int maxx = -inf ,t;
        for(int i = 1 ; i <= 10 ; i++)
        {
            if(!vis[i] && maxx < a[i])
            {
                maxx = a[i];
                t = i;
            }
        }
        vis[t] = 1;
        printf("%d\n",maxx);
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <unordered_set>

int main(){
    int n;
    std::string s;
    std::cin >> n;
    std::unordered_set<std::string> set;
    for(int i = 0; i < n; i++){
        std::cin >> s;
        set.insert(s);
    }
    std::cout << set.size() << std::endl;
}


Measured memory_bytes: 17792
import java.util.ArrayList;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int K = scn.nextInt();
		int[] arr = new int[K];
		for (int i = 0; i < K; i++) {
			arr[i] = scn.nextInt();
		}
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 0; i < K; i++) {
			list.add(arr[i]);
		}
		int ans = N;
		while (true) {
			if (Val(ans, list, K)) {
				System.out.println(ans);
				break;
			}
			ans = ans + 1;
		}
	}
	public static boolean Val(int N, ArrayList<Integer> list, int K) {
		int temp = N;
		while (temp != 0) {
			int a = temp % 10;
			temp /= 10;
			if (list.contains(a)) {
				return false;
			}
		}
		return true;
	}

}


Measured memory_bytes: 27280
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
  
  char st1[1000001],st2[1000001];
  int n,des[1000001],pos[1000001],cnt;

  int main(){
//    freopen("game.in","r",stdin);
	  
  	scanf("%d",&n);
  	scanf("%s",st1+1);scanf("%s",st2+1);
  	if(strcmp(st1+1,st2+1)==0) {printf("0\n"); return 0;}
  	int po=n;
  	for (int i=n,j=n;i;i=j-1,j=i){
  	  while (st2[j-1]==st2[i]) j--;
  	  po=min(po,j);
	  while (po&&st1[po]!=st2[i]) po--;
	  if (!po){printf("-1\n");return(0);}
	  des[po]=i;
	}
	
	int ans=0,lastans=0;
	for (int i=n;i>=1;i--) if (des[i]){
	  	lastans++;
	  	pos[++cnt]=i;
	  	while (lastans){
	  	  int t=cnt-(lastans-1),tpo;
	  	  if (t<=0) tpo=n-(lastans-1);else tpo=pos[t]-(lastans-1);
	  	  if (tpo<des[i]) break;
	  	  lastans--;
		}
		ans=max(ans,lastans);
	  }
	printf("%d\n",ans);
  }

Measured memory_bytes: 9984
import java.io.IOException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		for(int i = 0; i < 7; i++){
			System.out.println(sc.nextInt() - sc.nextInt());
		}
		
	}

}

Measured memory_bytes: 17364
#include<iostream>
#include<string>

using namespace std;

bool sample(string s){
  string t(s.rbegin(),s.rend());
  if(s==t) return true;
  else return false;
}
int main()
{
  string s;
  cin >> s;
  int n = s.size();
  if(sample(s) && sample(s.substr(0,(n-1)/2)) && sample(s.substr((n+1)/2))){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[111];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=n;i>=1;i--){
    cout<<a[i];
    if(i!=1) cout<<' ';
  }
  cout<<endl;
  return(0);
}



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

#def f(x):
#    if x == 1:
#        return 1
#    else:
#        return f(x-1) + x

[N, K] = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]

max_index = 0
now_sum = sum(P[:K])
max_sum = now_sum
for i in range(1, len(P)-(K-1)):
    now_sum -= P[i-1]
    now_sum += P[i+K-1]
    #sum_P = sum(P[i:i+K])
    if now_sum > max_sum:
        max_sum = now_sum
        max_index = i

#print(max_sum)
#print(max_index)

# 隣接したK個のリスト
kk = P[max_index:max_index+K]

# kの期待値を計算
max_kk = max(kk)
dp = [0]
for i in range(1, max_kk+1):
    dp.append(dp[i-1] + i)
#print(dp)

ans = 0
for k in kk:
    ans += dp[k]/k

print(ans)

Measured memory_bytes: 24548
str=list(input())
n=int(input())
for i in range(n):
    a=input().split()
    s=int(a[1]);f=int(a[2])+1
    str1=str[s:f]
    if a[0]=='replace':
        ar=list(a[3])
        str[s:f]=ar
    elif a[0]=='print':
        ans=''.join(str1)
        print(ans)
    else:
        str2=str1[::-1]
        str[s:f]=str2


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  int p[51];
  cin >> N;
  for(int i=0; i<N; i++) {
    int tmp;
    cin >> tmp; tmp--;
    p[i] = tmp;
  }
  bool tf = true;

  int cnt = 0;
  int fwi;
  for(int i=0; i<N; i++){
    if(p[i] != i){
//      cout << "in: " << i << endl;
      if(cnt == 0){
        fwi = i;
        cnt++;
      }else if(cnt == 1){
//      cout << "cnt == 1, in: " << i << endl;        
        if(fwi == p[i]){
        }else{
          cnt++;
        }
      }
    }
    
    if(cnt >= 2){
      tf = false;
      break;
    }
  }
  if(tf){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// AOJ 1235: Life Line
// 2017.10.22 bal4u@uu

#include <stdio.h>
#include <string.h>

int que[100][2], top;
int map[10][10]; int n;
int mk[10][10];
int zero[46][2], sz;
int mv[6][2] = {{-1,-1},{-1,0},{0,-1},{0,1},{1,0},{1,1}};

int calc(int r0, int c0, int num)
{
	int i, r, c, r2, c2, v;

	top = 0;
	memset(mk, 0, sizeof(mk));
	for (i = 0; i < sz; i++) {
		r = zero[i][0], c = zero[i][1];
		if (map[r][c] == 0) {
			mk[r][c] = 1, que[top][0] = r, que[top++][1] = c;
		}
	}
	while (top) {
		r = que[--top][0], c = que[top][1];
		for (i = 0; i < 6; i++) {
			r2 = r + mv[i][0], c2 = c + mv[i][1];
			if (r2 < 1 || r2 > n || c2 < 1 || c2 > r2 || mk[r2][c2]) continue;
			if (map[r][c] == 0 || map[r2][c2] == map[r][c]) {
				mk[r2][c2] = 1;
				que[top][0] = r2, que[top++][1] = c2;
			}
		}
	}
	for (v = 0, r = 1; r <= n; r++) for (c = 1; c <= r; c++) if (!mk[r][c]) {
		if (map[r][c] == num) v--; else v++;
	}
	return v;
}

int main()
{
	int c, i, j, k, v, ans;

	while (scanf("%d%d", &n, &c) && n > 0) {
		for (sz = 0, i = 1; i <= n; i++) for (j = 1; j <= i; j++) {
			scanf("%d", &v), map[i][j] = v;
			if (!v) zero[sz][0] = i, zero[sz++][1] = j;
		}
		for (ans = -0x7ffffff, k = 0; k < sz; k++) {
			i = zero[k][0], j = zero[k][1];
			map[i][j] = c;
			if ((v = calc(i, j, c)) > ans) ans = v;
			map[i][j] = 0;
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

typedef long long ll;
ll n, a, b;

int main() {
    scanf("%lld %lld %lld", &n, &a, &b);
    if (a > b) printf("0\n"), exit(0);
    if (n == 1 && a ^ b) printf("0\n"), exit(0);
    ll l = b + (n - 1) * a;
    ll r = a + (n - 1) * b;
    printf("%lld\n", r - l + 1);
    return 0;
}

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

const int MAXN = 51;

char A[MAXN][MAXN];
char B[MAXN][MAXN];

int main(){
    ios_base::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	assert(M <= N);
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++)
			cin >> A[i][j];

	for (int i = 1; i <= M; i++)
		for (int j = 1; j <= M; j++)
			cin >> B[i][j];
			
	for (int i = 1; i <= N - M + 1; i++){
		for (int j = 1; j <= N - M + 1; j++){
			bool ok = true;
			for (int p = i; p < i + M; p++){
				for (int q = j; q < j + M; q++){
					if (A[p][q] != B[p - i + 1][q - j + 1]){
						ok = false; break;
					}
				} 
			}
			if (ok){
				cout << "Yes"; return 0;
			}
		}
	}
	cout << "No";
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        if (n < 1 || n > 100) return;

        var numbers = Array.ConvertAll(Console.ReadLine().Split(' '),
            new Converter<string, int>(int.Parse)).Where(v => v <= 1000 && v >= 1 && v % 2 == 0);

        if (numbers.All(v => v % 3 == 0 || v % 5 == 0))
            Console.WriteLine("APPROVED");
        else
            Console.WriteLine("DENIED");
    }
}

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

using namespace __gnu_pbds;
using namespace std;
#define INF 1000000000000000000ll
#define DIM 100007
#define pll pair<long long, long long>
#define ll long long
#define try cout<<"good"<<endl
#define ld long double
#define fi first
#define se second
#define pb push_back


typedef  pair<  pair<long long, long long>, long long> ppll;
ll n,m,c,x,x2,y2,k,e,h,a1,a2,w,a3,y,z,a4,a5,a6,a7,last,dist,LL,timer,start,finish,maxmask,newmax,reslast,tests;
string s1;
ll l,r;

ld d1,d2,d3;
vector <ll> a;
ll mas[300007];
ll mas1[300007];
ld dp[307][307][307];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a7;
        if(a7==1)a4++;
        if(a7==2)a5++;
        if(a7==3)a6++;
    }
    for(int l=0;l<=a6;l++){
        for(int j=0;j<=n-l;j++){
            for(int i=0;i<=n-l-j;i++){
                d1=0;
                d2=0;
                d3=0;
                if(i==0&&j==0&&l==0){
                    continue;
                }
                if(i==1&&j==0&&l==0){
                    dp[1][0][0]=n;
                }else{
                    if(i>0)
                    d1=(ld)i/(ld)(i+l+j)*dp[i-1][j][l];
                    if(j>0)
                    d2=(ld)j/(ld)(i+l+j)*dp[i+1][j-1][l];
                    if(l>0)
                    d3=(ld)l/(ld)(i+l+j)*dp[i][j+1][l-1];
                    dp[i][j][l]=(d1+d2+d3)+((ld)n/(ld)(i+l+j));
                }
                //cout<<i<<' '<<j<<' '<<l<<endl;
                //cout<<d1<<' '<<d2<<' '<<d3<<endl;
                //cout<<fixed<<setprecision(5)<<dp[i][j][l]<<endl;
            }
        }
    }
    cout<<fixed<<setprecision(10)<<dp[a4][a5][a6]<<endl;
    return 0;
}


Measured memory_bytes: 442624
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	int n,a[100] = {0};

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

	int cnt[8] = {0};
	int ram = 0;

	for(int i = 0; i < n; i++)
	{
		if (a[i]<=399)
		{
			cnt[0]++;
		}else if (a[i]<=799)
		{
			cnt[1]++;
		}else if (a[i]<=1199)
		{
			cnt[2]++;
		}else if (a[i]<=1599)
		{
			cnt[3]++;
		}else if (a[i]<=1999)
		{
			cnt[4]++;
		}else if (a[i]<=2399)
		{
			cnt[5]++;
		}else if (a[i]<=2799)
		{
			cnt[6]++;
		}else if (a[i]<=3199)
		{
			cnt[7]++;
		}else
		{
			ram++;
		}
	}


	int sol = 0;
	for(int i = 0; i < 8; i++)
	{
		if (cnt[i] != 0)
		{
			sol++;
		}
	}

	if (ram == 0)
	{
		printf("%d %d\n", sol,sol);
	}else
	{
		if (sol == 0)
		{
			printf("%d %d\n", 1,ram);
		}else
		{
			printf("%d %d\n", sol,sol+ram);
		}
	}


	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;





signed main() {
	int N; cin >> N;
	
	vector<int> A(N - 1);
	rep(i, N - 1) {
		cin >> A.at(i);
		A.at(i)--;
	}

	vector<int> res(N);

	rep(i, N-1) {
		res.at(A.at(i))++;
	}

	rep(i, N) cout << res.at(i) << endl;

}

Measured memory_bytes: 6424
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
//const int mod = 998244353;
const int mod = (int)1e9 + 7, inf = (int)1e16;
const string sp = " ";
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = max(a, b);
		return true;
	}
	return false;
}
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = min(a, b);
		return true;
	}
	return false;
}
struct use {
	int a, b, c, d;
};

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans= fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

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

int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

int n, w, cnt, ans;
int a, b, c, d;
vector<P>v[4];
P p[101];
vector<use>u;
signed main() {
	scanf("%lld %lld", &n, &w);
	rep(i, n) {
		int a, b;
		scanf("%lld %lld", &a, &b);
		p[i] = P(a, b);
	}
	sort(p, p + n);
	a = p[0].first;
	rep(i, n) {
		v[cnt].push_back(p[i]);
		if (i < n - 1 && p[i].first != p[i + 1].first) {
			cnt++;
			if (cnt == 1) b = p[i + 1].first;
			else if (cnt == 2) c = p[i + 1].first;
			else d = p[i + 1].first;
		}
	}
	rep(i, 4) {
		sort(all(v[i]), greater<P>());
	}
	rep(i, v[0].size() + 1) {
		rep(j, v[1].size() + 1) {
			rep(k, v[2].size() + 1) {
				rep(l, v[3].size() + 1) {
					if (i * a + j * b + k * c + l * d <= w) {
						u.push_back({ i,j,k,l });
					}
				}
			}
		}
	}
	for (use u1 : u) {
		cnt = 0;
		rep(i, u1.a) cnt += v[0][i].second;
		rep(i, u1.b) cnt += v[1][i].second;
		rep(i, u1.c) cnt += v[2][i].second;
		rep(i, u1.d) cnt += v[3][i].second;
		chmax(ans, cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 9840
#include <cstdio>
#include <cstdlib>
#include <string>
#include <set>

using namespace std;

int
main (
  int   argc,
  char *argv[ ]
  )
{
  set<string> lis;
  int st = 0;
  int n, m;

  scanf ( "%d", &n );
  while ( n-- )
  {
    char s[ 11 ];

    scanf ( " %s", s );
    lis.insert ( s );
  }

  scanf ( "%d", &m );
  while ( m-- )
  {
    char s[ 11 ];

    scanf ( " %s", s );
    if ( lis.find ( s ) == lis.end ( ) )
    {
      printf ( "Unknown %s\n", s );
    }
    else
    {
      printf ( "%s by %s\n", ( st ? "Closed" : "Opened" ), s );
      st = !st;
    }
  }

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 1096
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n, m;
    cin >> n >> m;
    int x = 1, y = 1;
    int gap = 1;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
    {
        if(x < m+1-x)
        {
            cout << x << " " << m + 1 - x << endl;
            x++;
        }
        else{
            cout << m + y << " " << 2 * m + 2 - y << endl;
            y++;
        }
    }

    return 0;
}

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

long long power(long long A,long long B,long long M){
    if(B==0){
        return 1;
    }
    else if(B%2==0){
        long long s=power(A,B/2,M);
        return (s*s)%M;
    }
    else{
        return ((A%M)*power(A,B-1,M))%M;
    }
}

int main(){
    ll N,M,K;
    cin>>N>>M>>K;
    vector<ll>MM(K+1);
    for(ll i=0;i<K+1;i++){
        MM[i]=power(M-1,N-i-1,MOD);
    }
    vector<long long>comb(K+1);
    comb.at(0)=1;
    for(long long i=1;i<K+1;i++){
        comb.at(i)=(((comb.at(i-1)*power(i,MOD-2,MOD))%MOD)*((N-i)%MOD))%MOD;
    }
    ll sum=0;
    rep(i,K+1){
        sum=(sum+((((M%MOD)*MM[i])%MOD)*(comb[i])%MOD))%MOD;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 6244
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

N,M = (int(x) for x in input().split())
m = 0
for x in make_divisors(M):
    if M // x >= N:
        m = max(m,x)
print(m)

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,m;cin>>n>>m;
  vector<ll>h(n);
  rep(i, n)cin>>h[i];
  vector<bool>g(n);
  rep(i, n)g[i] = true;
  rep(i, m){
    int a,b;cin>>a>>b; a--;b--;
    if(h[a]>h[b])g[b] = false;
    else if(h[b]>h[a])g[a] = false;
    if(h[a]==h[b]){
      g[a] = g[b] = false;
    }
  }

  int result = 0;
  rep(i, n)if(g[i])result++;

  cout << result << endl;

  return 0;
}

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

using namespace std;

int main()
{
  int n, m, sum = 0; cin >> n >> m;
  for(int i = 0; i < m; i++)
  {
    int a; cin >> a;
    sum += a;
  }
  if(sum > n) cout << -1;
  else cout << n - sum;

  return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main()
{
	int n,i,j,cnt,cnt2,a[1000],b[1000];
	cnt=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]%2==0){
			b[cnt]=a[i];
			cnt++;
		}
	}
	for(i=0;i<cnt;i++){
		cnt2=0;
		if(b[i]%3!=0){
			cnt2++;
		}
		if(b[i]%5!=0){
			cnt2++;
		}
		if(cnt2>=2) break;
	}
	if(cnt2>=2){
		printf("DENIED\n");
	}
	else printf("APPROVED\n");
	return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vll = vector<long long>;
using vvll = vector<vll>;

int main(){
  ll N,A,B,C,D;
  cin>>N>>A>>B>>C>>D;
  string S;
  cin>>S;
  for(ll i=A+1;i<max(C,D);i++){
    if(S.at(i-2)=='#'&&S.at(i-1)=='#'){
      cout<<"No"<<endl;
      return 0;
    }
  }
  if(C<D){
    cout<<"Yes"<<endl;
    return 0;
  }else{
    for(ll i=B;i<D+1;i++){
      if(S.at(i-2)=='.'&&S.at(i-1)=='.'&&S.at(i)=='.'){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}


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

#define dbg(x...) do { cout << "\033[32;1m" << #x <<" -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<class T, class... Ts> void err(const T& arg,const Ts&... args) { cout << arg << " "; err(args...); }

typedef long double db;
const db eps = 1e-8;
const db pi = acosl(-1.0);

int sgn(db x) {if(fabs(x) < eps) return 0; return x < 0 ? -1 : 1;}

struct Point{
    db x, y;
    Point(){}
    Point(db x, db y) : x(x), y(y){}
    void input(){cin >> x >> y;}
    Point operator + (const Point &b) const{
        return Point(x + b.x, y + b.y);
    }
    Point operator - (const Point &b) const {
        return Point(x - b.x, y - b.y);
    }
    db operator ^ (const Point &b) const{
        return x * b.y - y * b.x;
    }
    db operator * (const Point &b) const{
        return x * b.x + y * b.y;
    }
    Point operator * (const db &k) const{
        return Point(x * k, y * k);
    }
    Point operator / (const db &k) const{
        return Point(x / k, y / k);
    }
    db len(){
        return sqrtl(x * x + y * y);
    }
    db distance(Point p) {
        return (*this-p).len();
    }
};
struct Line{
    Point s, e;
    Line(){}
    Line(Point s, Point e) : s(s), e(e){}
    void input() {s.input(); e.input();}

    int getCrossTypeofSeg(Line v){
        int d1 = sgn((e - s) ^ (v.s - s));  //v.s 在 线段的哪一侧
        int d2 = sgn((e - s) ^ (v.e - s));  //v.e 在 线段的哪一侧
        int d3 = sgn((v.e - v.s) ^ (s - v.s));  
        int d4 = sgn((v.e - v.s) ^ (e - v.s));
        if((d1^d2) == -2 && (d3^d4) == -2) return 2; // 跨立实验满足 一个是-1一个是1

        // 1. v.s在线段上 || v.e 在线段上 || s 在另外一条线段上 || e在另外一条线段上
        return (d1 == 0 &&  sgn((v.s - s) * (v.s - e)) <= 0) ||
            (d2 == 0 && sgn((v.e - s) * (v.e - e)) <= 0) ||
            (d3 == 0 && sgn((s - v.s) * (s - v.e)) <= 0) || 
            (d4 == 0 && sgn((e - v.s) * (e - v.e)) <= 0);
    }

    db getDisPointToLine(Point p) {
        return fabs(((p-s)^(e-s))/(e-s).len());
    }

    db getDisPointToSeg(Point p) {
        if(sgn((e-s) * (p-s)) < 0 || sgn((s - e) * (p - e)) < 0) return min(s.distance(p), e.distance(p));
        return getDisPointToLine(p);
    }
    db getDisSegToSeg(Line v) {
        return min(min(getDisPointToSeg(v.s), getDisPointToSeg(v.e)), min(v.getDisPointToSeg(s), v.getDisPointToSeg(e)));
    }
}l1, l2;

int main(){
#ifndef ONLINE_JUDGE
// freopen("i.in","r",stdin);
//  freopen("o.out","w",stdout);
#endif
    int T;scanf("%d", &T);
    while(T--){
        l1.input(); l2.input();
        db res = 0;
        if(l1.getCrossTypeofSeg(l2) > 0) res = 0;
        else res = l1.getDisSegToSeg(l2);
        cout << fixed << setprecision(10) << res  <<endl;
    }

    return 0;
}


Measured memory_bytes: 3392
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define MAXN 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n,k,h[MAXN],dp[MAXN];

// dp[i] = i. tasa minimum kac maliyetle gliriz.

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> h[i];

	dp[1] = 0;
	for (int i = 2; i <= n; i++)
	{
		dp[i] = inf;
		for (int j = 1; j <= k; j++) {
			if(i-j <= 0) break;
				dp[i] = min(dp[i],abs(h[i]-h[i-j]) + dp[i-j]);
		}
		// cout << i << " " << dp[i] << endl;
	}

	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        long A;


        try (Scanner sc = new Scanner(System.in)) {
            A = sc.nextLong();
        }

        long sqr = (long) Math.sqrt(A);
        long result = 0;
        for (long i = sqr; i >  0; i--) {
            if(A % i == 0){
                result = (i) + (A/i) -2;
                break;
            }
        }
        System.out.println(result);


    }


}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(10);
	string s;
	cin>>s;
	if(s[1]=='B')
	cout<<"ARC";
	else
	cout<<"ABC";
	return 0;
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int,input().split()))
from collections import deque
d = {}
X = deque()
for i in range(N):
    x = A[i]
    if x not in d:
        d[x] = 1
        X.appendleft(x)
    else:
        d[x] += 1
ans = 0
from collections import deque
Y=deque()
while X:
    x = X.popleft()
    a = d[x]
    if a%2 == 0:
        ans += a-2
        Y.appendleft(x)
    else:
        ans += a-1

n = len(Y)
ans += ((n+1)//2)*2
print(N-ans)

Measured memory_bytes: 18528
a = input()
first = int(a[:2])
second = int(a[2:])

if first <= 12 and 0 < first:
    F = 'M'
else:
    F = 'Y'

if second <= 12 and 0 < second:
    S = 'M'
else:
    S = 'Y'

b = F + S
if b == "YM":
    print("YYMM")
elif b == 'MY':
    print('MMYY')
elif b == 'MM':
    print("AMBIGUOUS")
else:
    print('NA')



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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;



int main(void) {
	int n;
	int v;
	int j;

	cin >> n;
	vector<int>a(n);
	FOR(i, 0, n-1) {
		cin >> a[i];
	}
	FOR(i, 0, n - 2) {
		cout << a[i] << " ";
	}
	cout << a[n - 1] << endl;
	FOR(i, 1, n - 1) {
		v = a[i];
		j = i - 1;
		
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		FOR(i, 0, n - 2) {
			cout << a[i] << " ";
		}
		cout << a[n - 1] << endl;
	}


	return 0;
}



Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int main(){
  int n,i,ans;cin >> n;ans = 0;
  int a[n];
  for(i=0;i<n;i++) cin >> a[i];
  for(i=0;i<n;i++){
    if (a[a[i]-1]-1 == i) ans += 1;
  }
  cout << ans/2 << endl;
}


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

int main(){
  char a;
  cin >> a;

  if(a== 'A'|| a=='B'|| a=='C'|| a=='D'|| a=='E'|| a=='F'|| a=='G' || a=='H'|| a=='I'|| a=='J' || a=='K' || a=='L'|| a=='M'|| a=='N'|| a=='O'|| a=='P'|| a=='Q'|| a=='R'|| a=='S'|| a=='T'|| a=='U'|| a=='W'|| a=='X'|| a=='Y'|| a=='Z'){
    cout << 'A' << endl;
  }
  else{
    cout << 'a' << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <cstdio>
#include <float.h>
#include <ctype.h>
 using namespace std;
 int main(void) {
	 int a, b, c, d, e, ans,ansA,ansB,ansC,ansD;
	 scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
	 if (a <= b && a <= c) {
		 if (d <= e) {
			 ans = a + d;
		 }
		 else {
			 ans = a + e;
		 }
	 }
	 if (b <= a && b <= c) {
		 if (d <= e) {
			 ans = b + d;
		 }
		 else {
			 ans = b + e;
		 }
	 }
	 if (c <= a && c <= b) {
		 if (d <= e) {
			 ans = c + d;
		 }
		 else {
			 ans = c + e;
		 }
	 }
	 ans = ans - 50;
	 printf("%d\n", ans);
	 return 0;
 }
 



Measured memory_bytes: 3212
# coding=utf-8


def solve_gcd(number1: int, number2: int) -> int:
    two_list = [number1, number2]
    two_list.sort()
    if two_list[1] % two_list[0] == 0:
        return two_list[0]
    r = two_list[1] % two_list[0]
    return solve_gcd(two_list[0], r)


def solve_lcm(number1: int, number2: int, number3: int) -> int:
    return number1*number2//number3


if __name__ == '__main__':
    while True:
        try:
            a, b = map(int, input().split())
        except EOFError:
            break
        gcd = solve_gcd(a, b)
        lcm = solve_lcm(a, b, gcd)
        print(gcd, lcm)

Measured memory_bytes: 5596
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } }
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

vector<vector<LL> > dp(1010, vector<LL>(1010));
LL H, W;
vector<vector<char> > grid(1010, vector<char>(1010, '#'));

int main(void) {
	cin >> H >> W;

	dp[1][1] = 1;

	for (LL i = 1; i <= H; i++) {
		string tmp;
		cin >> tmp;

		for (LL j = 1; j <= W; j++) {
			grid[i][j] = tmp[j - 1];
		}
	}
	
	for (LL i = 1; i <= H; i++) {
		for (LL j = 1; j <= W; j++) {
			if (grid[i + 1][j] == '.') {
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j] %= MOD;
			}

			if (grid[i][j + 1] == '.') {
				dp[i][j + 1] += dp[i][j];
				dp[i][j + 1] %= MOD;
			}
		}
	}

	cout << dp[H][W] << endl;

	return 0;
}

Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())
 
int main() {
    char X;
  	cin >> X;
    if(X=='A' || X=='B'|| X=='C'|| X=='D'|| X=='E'|| X=='F'|| X=='G'|| X=='H'|| X=='I'||
       X=='G'|| X=='K'|| X=='L'|| X=='M'|| X=='N'|| X=='O'|| X=='P'|| X=='Q'|| X=='R'||
       X=='S'|| X=='T'|| X=='U'|| X=='V'|| X=='W'|| X=='X'|| X=='Y'|| X=='Z'){
    cout << "A" <<endl;
    }
    else{
    cout << "a" <<endl;
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define fr(x,y) for(int x=0;x<y;x++)
using namespace std;
int main() 
{
	int n,k,c;
	cin>>n>>k>>c;
	string s;
	cin>>s;
	bool* start=new bool[n],* end=new bool[n];
	int count = 0;
	fr(i,n) 
	{
		start[i]=end[i]=false;
	}
	fr(i,n)
	{
		if(s[i]=='x') continue;
		count++;
		start[i]=true;
		i=i+c;
		if(count>k) return 0;
	}
	count=0;
	for(int i=n-1;i>=0;i--) 
	{
		if(s[i]=='x') continue;
		end[i]=true;
		count++;
		i=i-c;
		if(count>k) return 0;
	}
	fr(i,n)
	{
		if (end[i]==true && start[i]==true) cout<<i+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 2180
#include<iostream>
using namespace std;
int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	for(int i=0;i<ty-sy;i++){
		cout<<'U';
	}
	for(int i=0;i<tx-sx;i++){
		cout<<'R';
	}
	for(int i=0;i<ty-sy;i++){
		cout<<'D';
	}
	for(int i=0;i<tx-sx;i++){
		cout<<'L';
	}
	cout<<"LU";
	for(int i=0;i<ty-sy;i++){
		cout<<'U';
	}
	for(int i=0;i<tx-sx;i++){
		cout<<'R';
	}
	cout<<"RDRD";
	for(int i=0;i<ty-sy;i++){
		cout<<'D';
	}
	for(int i=0;i<tx-sx;i++){
		cout<<'L';
	}
	cout<<"LU";
	return 0;
}

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


class SegmentTree:
    def __init__(self, N, func, I):
        self.N = N
        self.sz = 2**(N-1).bit_length()
        self.func = func
        self.I = I
        self.seg = [I] * (self.sz * 2)

    def assign(self, k, x):
        self.seg[k + self.sz] = x

    def build(self):
        for i in reversed(range(1, self.sz)):
            self.seg[i] = self.func(self.seg[i + i], self.seg[i + i + 1])

    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k >>= 1
            self.seg[k] = self.func(self.seg[k + k], self.seg[k + k + 1])

    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        if b == self.N:
            b = self.sz + self.sz
        else:
            b += self.sz
        while a < b:
            if a & 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b & 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a >>= 1
            b >>= 1
        return self.func(L, R)


def main():
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    N = int(readline())
    L = map(int, readline().split())
    seg = SegmentTree(N, gcd, 0)
    for i, n in enumerate(L):
        seg.assign(i, n)
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans, gcd(seg.query(0, i), seg.query(i+1, N)))
    print(ans)


main()

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

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    register int x = 0, flag = 1;
    register char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}

inline long long readlong() {
	register long long x = 0, flag = 1;
	register char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong

int A, B;
int main() {
	cin >> A >> B;
	int ans = 0;
	for (ans = 0; ans <= 10000; ans++) {
		double k = ans * 1.0;
		int tmp = floor((0.1 * k));
		if (tmp != B) continue;
		tmp = floor((0.08 * k));
		if (tmp != A) continue;
		printf("%d\n", ans); return 0;
	}
	printf("-1"); return 0;
}


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

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m, k;
  cin >> n >> m >> k;

  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> sa(n+1, 0);
  vector<ll> sb(m+1, 0);
  rep(i, n ) { sa[i + 1] = sa[i] + a[i]; }
  rep(i, m ) { sb[i + 1] = sb[i] + b[i]; }
  ll ans = 0;
  rep(i, n+1) {
    ll t = k - sa[i];
    if (t >= 0) {
      auto it = upper_bound(sb.begin(), sb.end(), t);
      int j = distance(sb.begin(), it) - 1;
      ll num = (ll)(i) + (ll)(j);
      ans = max(ans, num);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9484
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s,t;
  cin >> s >> t;
  vector<int> p[26];
  rep(i,s.size()){
    p[s[i]-'a'].push_back(i);
  }
  ll ind = 0;
  int ss = s.size();
  rep(i,t.size()){
    int c = t[i]-'a';
    if(p[c].empty()){
      cout << -1 << endl;
      return 0;
    }
    auto it = lower_bound(p[c].begin(),p[c].end(),ind%ss);
    if(it==p[c].end()){
      ind = (ind + ss - 1)/ss * ss + p[c][0] + 1;
    }
    else ind = ind/ss*ss + *it + 1;
  }
  cout << ind << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    if(b < n*a){
        cout << b << endl;
        return 0;
    }
    else{
        cout << n*a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
    char s[3];
    int ans = 0;
    scanf("%s",s);

    if(strcmp(s,"SUN") == 0){
        ans = 7;
    }else if(strcmp(s,"MON") == 0){
        ans = 6;
    }else if(strcmp(s,"TUE") == 0){
        ans = 5;
    }else if(strcmp(s,"WED") == 0){
        ans = 4;
    }else if(strcmp(s,"THU") == 0){
        ans = 3;
    }else if(strcmp(s,"FRI") == 0){
        ans = 2;
    }else if(strcmp(s,"SAT") == 0){
        ans = 1;
    }

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

// gcd
int gcd(int n, int m) {
  if(n < m) swap(n, m);
  if(m == 1) return 1;
  else if(m == 0) return n;
  else return gcd(m, n%m);
}

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

signed main() {
  int A, B, C, D; cin >> A >> B >> C >> D;
  
  int E = lcm(C, D);

  int c = B/C - (A-1)/C;
  int d = B/D - (A-1)/D;
  int e = B/E - (A-1)/E;
  
  cout << (B-A+1) - (c+d-e) << endl;
  
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
white_mostleft=0
white_mostright=w
white_mostup=h
white_mostdown=0

for _ in range(n):
    x,y,a=map(int,input().split())
    if(a==1 and white_mostleft < x):
        white_mostleft=x
    elif(a==2 and white_mostright > x):
        white_mostright=x
    elif(a==3 and white_mostup > h-y):
        white_mostup = h-y
    elif(a==4 and white_mostdown < h-y):
        white_mostdown = h-y

ans=max(0,white_mostright-white_mostleft) * max(0,white_mostup-white_mostdown)
print(ans)


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

int main() {
    int r=1000;
    string S,t;
    cin >> S;

    rep(i,S.size()-2) {
        t = S.substr(i,3);
        int x = stoi(t);
        r = min(r, abs(x-753));
    }

    cout << r << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int x, a, b, ans;
	scanf("%d %d %d", &x, &a, &b);
	if(abs(x-a) > abs(x-b))	
		printf("B\n");
	else 
		printf("A\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

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

    int dp0[n+1], dp1[n+1];
    fill(dp1, dp1+n+1, 1e9+1);
    dp0[0] = 0, dp1[0] = 0;
    int maxl = 0;
    for (int i = 1; i <= n; i++) {
        dp0[i] = upper_bound(dp1, dp1+maxl+1, a[i]) - dp1;
        maxl = max(maxl, dp0[i]);
        dp1[dp0[i]] = min(dp1[dp0[i]], a[i]);
    }

    cout << maxl << endl;

    return 0;
}


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

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

    map<ll, ll> L;
    map<ll, ll> R;
    set<int> A;

    rep(i, n) {
        int a;
        cin >> a;
        L[i+a]++;
        R[i-a]++;
        A.insert(i+a);
        A.insert(i-a);
    }

    ll ans = 0;
    for (auto v : A) {
        auto itL = L.find(v);
        auto itR = R.find(v);
        if (itL == L.end() || itR == R.end()) continue;

        ans += itL->second * itR->second;
    }

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


Measured memory_bytes: 43700
#include<iostream>
#include<vector>
using namespace std;
 
int F(int n){
  if(n % 2 == 0){
    return n / 2;
  }
  else{
    return n * 3 + 1;
  }
}
 
int main(){
  int s;
  cin >> s;
  vector<int> vct;
  vct.push_back(s);
  int i = 1;
  while(true){
    vct.push_back(F(vct[i - 1]));
    for(int checkI = 0; checkI < i; ++checkI){
      if(vct[checkI] == vct[i]){
        goto outWhile;
      }
    }
    ++i;
  }
  outWhile:
  cout << i + 1 << endl;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
S = input()
ans = deque(S)


while S.find("()") != -1:
    S = S.replace("()","")

for i in range(len(S)):
    if S[i] == ")":
        ans.appendleft("(")
    elif S[i] == "(":
        ans.append(")")
print("".join(ans))


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>

using namespace std;

int n, ans;
int v[100010];
string s;

void tap(int x)
{
	if (x == 2) {
		int c=0;
		for(int i=1; i < n; i++) {
			if(v[i] == 1) {
				if(s[i] == 'o')
					v[i+1] = v[i-1];
				if(s[i] == 'x') {
					if(v[i-1] == 1)
						v[i+1] = 2;
					if(v[i-1] == 2)
						v[i+1] = 1;
				}
			}
			if(v[i] == 2) {
				if(s[i] == 'o') {
					if(v[i-1] == 1)
						v[i+1] = 2;
					if(v[i-1] == 2)
						v[i+1] = 1;
				}
				if(s[i] == 'x')
					v[i+1] = v[i-1];
			}
		}
		for(int i=0; i < n; i++) {
			int a = i-1, b = i+1;
			if(a == -1)
				a = n-1;
			if(b == n)
				b = 0;
			
			if(v[i] == 1) {
				if(s[i] == 'o' && v[a] != v[b])
					c = 1;
				if(s[i] == 'x' && v[a] == v[b])
					c = 1;
			}
			if(v[i] == 2) {
				if(s[i] == 'o' && v[a] == v[b])
					c = 1;
				if(s[i] == 'x' && v[a] != v[b])
					c = 1;
			}
		}
		
		if(c == 0) {
			for(int i=0; i < n; i++) {
				if(v[i] == 1)
					cout << "S";
				else
					cout << "W";
			}
			exit(0);
		}
		return;		
	}
	
	for(int i=1; i <= 2; i++) {
		v[x] = i;
		tap(x+1);
	}
}

int main()
{
	cin >> n >> s;
	
	tap(0);
	cout << -1;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

const ll contest = 26;

int main(){
    ll d, csum = 0; cin >> d;
    vector<ll> c(contest);
    vector<vector<ll>> s(d, vector<ll>(contest));
    rep(i, contest){
        cin >> c[i];
        csum += c[i];
    }
    rep(i, d) rep(j, contest) cin >> s[i][j];
    vector<ll> last(contest, 0);
    rep(i, d){
        ll maxx = 0, tt = 1;
        rep(t, contest){
            ll score = s[i][t];
            last[t] = i+1;
            rep(j, contest){
                if(t == j) continue;
                score -= c[j]*((i+1)-last[j]);
            }
            if(score > maxx){
                tt = t;
                maxx = score;
            }
        }
        cout << tt+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3716
#include<stdio.h>

int main(void){
  int n,m,x,s,i;
  int cnta=0,cntb=0;
  scanf("%d %d %d",&n,&m,&x);
  
  for(i=0;i<m;i++){
    scanf("%d",&s);
    if(x>s) cnta++;
    if(x<s) cntb++;
  }
  
  if(cnta>=cntb){
    printf("%d\n",cntb);
  }else{
    printf("%d\n",cnta);
  }
  
  return 0;
}

Measured memory_bytes: 128