akhauriyash/Code-Regression huggingface dataset:
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
int grid[3005][3005][5];
int a[3005][3005];
int n,m,k;
const int inf=1e18;
int dp(int i,int j,int cnt){
	if(i>n || j>m || cnt>=4)
		return -inf;
	if(i==n && j==m){
		int add=(a[i][j]!=0);
		if(cnt+add<=3)
			return a[i][j];
		return 0;
	}
	int &res=grid[i][j][cnt];
	if(res!=-1)	return res;
	res=-inf;
	int add=(a[i][j]!=0);
	if(add){
		res=max(res,a[i][j]+dp(i,j+1,cnt+add));
		res=max(res,dp(i,j+1,cnt));
		if(cnt+add<=3)
			res=max(res,a[i][j]+dp(i+1,j,0));
		res=max(res,dp(i+1,j,0));
	}
	else{
		res=max(res,dp(i+1,j,0));
		res=max(res,dp(i,j+1,cnt));
	}
	return res;
	
}
int solve()
{
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			for(int k=0;k<5;k++)
				grid[i][j][k]=-1;
		}
	}
	for(int i=1;i<=k;i++){
		int l,r,c;
		cin>>l>>r>>c;
		a[l][r]=c;
	}
	int ans=dp(1,1,0);
	cout<<ans<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}

Measured memory_bytes: 426908
import sys
S = input()
N = len(S)

if S != S[::-1]:
    print('No')
    sys.exit()

T = S[:(N-1)//2]

if T != T[::-1]:
    print('No')
    sys.exit()

U = S[(N+3)//2-1:]

if U != U[::-1]:
    print('No')
    sys.exit()

print('Yes')


Measured memory_bytes: 38256
#include <stdio.h>

int main(void){

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long min = 10000000000;
  long max = 0;
  for (long i = 0; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
    }
    if (a[i] > max) {
      max = a[i];
    }
  }
  printf("%ld\n", max-min);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = 1e14;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;

signed main() {
    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
}


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

int main() {
  // read inputs
  long N, A, B, C, D;
  scanf("%ld %ld %ld %ld %ld", &N, &A, &B, &C, &D);

  // solve
  if (D + C == 0) {
    if (B - A == 0) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  } else {
    const long k = (B - A + (N - 1) * D) / (D + C);
    if (k >= 0 && k <= N - 1 && B - A <= k * D - (N - 1 - k) * C) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
#define pb push_back
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin >> n;
    REP(i, n + 1) {
        if (i % 4 == 0 && (n - i) % 7 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



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

a, b, k = map(int, read().split())

A = [i for i in range(a, min((a + k), b+1))]
B = [i for i in range(max((b - k + 1), a), b+1)]
print(*sorted(set(A+B)), sep='\n')


Measured memory_bytes: 9216
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

const static sl XMAX = 100000;

static sl X;

static bool dp[XMAX];

void solve(void) {
  dp[0] = true;
  FORi(i, 1, 100) {
    dp[i] = false;
  }
  dp[100] = true;
  dp[101] = true;
  dp[102] = true;
  dp[103] = true;
  dp[104] = true;
  dp[105] = true;
  FORi(i, 106, X + 1) {
    dp[i] = dp[i - 100] || dp[i - 101] || dp[i - 102] || dp[i - 103] || dp[i - 104] || dp[i - 105];
  }
  cout << (dp[X] ? 1 : 0) << endl;
}

int main(void) {
  cin >> X;
  solve();
  return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n, k;

int main() {
	
	cin >> n >> k;
	intt ans = 0;
	for (int b = k + 1; b <= n; b ++) {
		int x = n / b, m = n % b;
		ans += 1LL * x * (b - k);
		if (m >= k) ans += m - k + 1;
	}
	if (!k) ans -= n;
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int K;

    scanf("%d",&K);

    char s[3*K + 1];

    for(int i = 1; i <= K; i++){
        s[3*i - 3] = 'A';
        s[3*i - 2] = 'C';
        s[3*i - 1] = 'L';
    }
    s[3*K] = '\0';

    printf("%s\n",s);


 return 0;   
}

Measured memory_bytes: 1616
a = list(map(int,input()))
h = []

for i in range(1,2**3):
    total = a[0]
    h.clear()
    for j in range(3):
        if ((i >> j) & 1):
            total += a[j+1]
            h.append('+')
        else:
            total -= a[j+1]
            h.append('-')
    if total == 7:
        break
for i in range(3):
    print(str(a[i])+h[i],end="")
print(str(a[3])+"=7")


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

using namespace std;

int main()
{
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    int i[3] = {0, 0, 0};
    int t = 0;
    while (i[t] < s[t].size()) {
        int next = s[t][i[t]] - 'a';
        ++i[t];
        t = next;
    }
    cout << "ABC"[t] << endl;

    return 0;
}

Measured memory_bytes: 256
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
int dp[1024][100005];
void solve()
{
    ll n;
    cin>>n;
    ll wt[n+1];
    ll val[n+1];
    for(int i=1;i<=n;i++)
        cin>>val[i]>>wt[i];
    ll q;
    cin>>q;
    for(int i=1;i<min(n+1,1024);i++)
    {
        if(i==1)
        {
            for(int j=wt[i];j<=100000;j++)
                dp[i][j]=val[i];
            continue;
        }
        int par=i/2;
        for(int j=1;j<=100000;j++)
        {
            if(wt[i]>j)
                dp[i][j]=dp[par][j];
            else
                dp[i][j]=max(dp[par][j],dp[par][j-wt[i]]+val[i]);
        }
    }
    while(q--)
    {
        int v,W;
        cin>>v>>W;
        if(v<1024)
        {
            cout<<dp[v][W]<<'\n';
            continue;
        }
        vi anc;
        while(v>=1024)
        {
            anc.pb(v);
            v/=2;
        }
        int res=anc.size();
        int ans=0;
        for(int i=0;i<(1<<res);i++)
        {
            int sumval=0,sumwt=0;
            for(int j=0;j<res;j++)
            {
                if((i&(1<<j))!=0)
                {
                    sumval+=val[anc[j]];
                    sumwt+=wt[anc[j]];
                }
            }
            if(sumwt>W)
                continue;
            ans=max(ans,sumval+dp[v][W-sumwt]);
        }
        cout<<ans<<'\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

int main(){

	int n;
	scanf("%d", &n);
	

	for(int i = 0; i < 3; ++i){
		if(n%10 == 7){
			printf("Yes");
			return 0;
		}
		n/=10;
	}
	printf("No");
	return 0;

}

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

int main(){
	int y, m, d;
	char c;
	cin >> y >> c >> m >> c >> d;
	if(y > 2020 || y == 2019 && m >= 5)
		cout << "TBD" << endl;
	else
		cout << "Heisei" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int n, x, i, j, k;
  int count=0;

  while(1){
  scanf ("%d %d",&n, &x);

  if(n==0 && x==0){
    break;
  }
  count = 0;

  for (i=1; i<=n-2; i++){
    for (j=i+1; j<=n-1; j++){
      for (k=j+1; k<=n; k++){
        if (i+j+k==x)
          count++;
      }
    }
  }
  printf("%d\n", count);
  }

  return 0;
}


  

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
int n,a[310][310];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	long long ans=0;
	for (int i=1;i<n;i++)
	{
		for (int j=i+1;j<=n;j++)
		{
			bool f=true;
			for (int k=1;k<=n;k++)
			{
				if (k==i || k==j)
				{
					continue;
				}
				if (a[i][k]+a[k][j]<a[i][j])
				{
					puts("-1");
					return 0;
				}
				if (a[i][k]+a[k][j]==a[i][j])
				{
					f=false;
				}
			}
			if (f)
			{
				ans+=a[i][j];
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 640
/*

 Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
#define MOD1 1e18
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
typedef long double ld;
const ll inf=(1LL<<60)-1;
const ll mxn=1e5;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
long long ans,a[100005];
ll mod(ll x)
{
    ll res=x%MOD;
    while(res<0)
        res+=MOD;
    return res;
}
ll bigmod(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n&1)
            res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
void solve()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ll n;
    cin>>n;
    ll ans=mod(bigmod(10,n)-bigmod(9,n)-bigmod(9,n)+bigmod(8,n));
    ans=(ans+MOD)%MOD;
    cout<<ans<<endl;
}
int main()
{
    IOS;
    //ll t;
    //cin>>t;
    // while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 1e5 + 9;
const int MAX_Q = 1e5 + 9;
std::string S,T;
int q;
int a[MAX_Q], b[MAX_Q], c[MAX_Q], d[MAX_Q];

int acS[MAX_N], acT[MAX_N];

int main(int argc, char **argv) {
    std::cin >> S;
    std::cin >> T;
    std::cin >> q;

    for (int i = 1; i <= q; i++) {
        std::cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    acS[0] = 0;
    for (int i = 1; i <= S.size(); i++) {
        acS[i] = acS[i-1] + (S[i-1] - 'A') + 1;
        //std::cout << acS[i] << " ";
    }
    //std::cout << std::endl;

    acT[0] = 0;
    for (int i = 1; i <= T.size(); i++) {
        acT[i] = acT[i-1] + (T[i-1] - 'A') + 1;
        //std::cout << acT[i] << " ";
    }
    //std::cout << std::endl;

    for (int i = 1; i <= q; i++) {
        if ((acS[b[i]] - acS[a[i]-1]) % 3 == (acT[d[i]] - acT[c[i]-1]) % 3) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
using namespace std;
int main()
{
  int i,j,k,l,n,c=0;
  while(cin >> n)
{
  c=0;
  for(i=0;i<=9;i++){
   for(j=0;j<=9;j++){
    for(k=0;k<=9;k++){
     for(l=0;l<=9;l++){
        if(i+j+k+l == n)
           c++;
         }
        }
       }
      }
  cout << c << endl;
}
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int d, n;
    cin >> d >> n;
    int ans;
    if(d == 0)
        if(n != 100)
            ans = n;
        else
            ans = 101;
    else if(d == 1)
        if(n != 100)
            ans = n * 100;
        else
            ans = 10100;
    else
        if(n != 100)
            ans = n * 10000;
        else
            ans = 1010000;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    static int mod = (int) 1e9 + 7;
    static int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
    static int INF = Integer.MAX_VALUE/2;

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);

        //Queue<int[]> q = new ArrayDeque<int[]>();
        Integer n = new Integer(scan.nextInt());
        Integer k = new Integer(scan.nextInt());
        ArrayList<Integer> p = new ArrayList<Integer>();

        for(int i=0;i<n;i++) p.add(scan.nextInt());
    
        //Collections.sort(a);

        int max = 0;
        int pos = 0;
        int bef_sum = 0;

        for(int i=0;i<k;i++) bef_sum += p.get(i);

        for(int i=1;i<n-k+1;i++){
            bef_sum -= p.get(i-1);
            bef_sum += p.get(i+k-1);
            if(max < bef_sum){
                pos = i;
                max = bef_sum;
            }
        }

        double e = 0.0;
        for(int i=pos;i<pos+k;i++){
            double sum = 0.0;
            for(int j=1;j<=p.get(i);j++) sum += j;
            e += sum / p.get(i);
        }

        System.out.println(e);
    }

    static int factorial(int n){
        if(n == 0){
          return 1;
        }
        return n * factorial(n-1);
    }


}

Measured memory_bytes: 81984
#include<stdio.h>
#include<stdlib.h>//llabs関数
int main(void){
  long long n,k;
  scanf("%lld%lld",&n,&k);
  if(n==0){
    printf("0");
    return 0;
  }
   if(n%k==0){
    printf("0");
    return 0;
  }
  if(n<k&&k-n>=n){
    printf("%lld",n);
    return 0;
  }
  if(n<k){
    long long w=n;
    n=k;
    k=w;
  }
  n=n-(n/k)*k;
  if(n>llabs(n-k))printf("%lld",llabs(n-k));
  else printf("%lld",n);
  
         return 0;
}

Measured memory_bytes: 128
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


class UnionFind:
    def __init__(self, size=None, nodes=None):
        """
        size か nodes どっちか指定。
        nodes は set、size は list を使う。
        set の最悪計算量は O(N) なので size 指定のほうが若干速い
        :param int size:
        :param collections.Iterable nodes:
        """
        assert size is not None or nodes is not None
        if size is not None:
            self._parents = [i for i in range(size)]
            self._ranks = [0 for _ in range(size)]
            self._sizes = [1 for _ in range(size)]
        else:
            self._parents = {k: k for k in nodes}
            self._ranks = {k: 0 for k in nodes}
            self._sizes = {k: 1 for k in nodes}

    def unite(self, x, y):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        :return:
        """
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        # rank が小さい方が下
        if self._ranks[x] > self._ranks[y]:
            # x が root
            self._parents[y] = x
            self._sizes[x] += self._sizes[y]
        else:
            # y が root
            self._parents[x] = y
            self._sizes[y] += self._sizes[x]
            if self._ranks[x] == self._ranks[y]:
                self._ranks[y] += 1

    def find(self, x):
        """
        x が属する木の root
        :param x:
        :return:
        """
        if self._parents[x] == x:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        :return:
        """
        return self._sizes[self.find(x)]


N = int(sys.stdin.readline())
X, Y = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(N)]))

min_x = min(X)
min_y = min(Y)
max_x = max(X)
max_y = max(Y)

coo = {}
for i, (x, y) in enumerate(zip(X, Y)):
    coo[(x, y)] = i

ans = N
for i, j in itertools.combinations(range(N), r=2):
    x1, x2 = X[i], X[j]
    y1, y2 = Y[i], Y[j]
    p = x1 - x2
    q = y1 - y2

    uf = UnionFind(size=N)
    for k in range(N):
        x, y = X[k], Y[k]
        if (x + p, y + q) in coo:
            uf.unite(k, coo[(x + p, y + q)])
        if (x - p, y - q) in coo:
            uf.unite(k, coo[(x - p, y - q)])
    roots = set()
    for k in range(N):
        roots.add(uf.find(k))
    ans = min(len(roots), ans)
print(ans)


Measured memory_bytes: 80236
#include <bits/stdc++.h>
using namespace std;
int count(int a,string s) {
	if(s=="Female") return 2*(a%2)-1;
	else if(s=="Male") return (2*(a%2)-1)*(-1);
	else return 0;
}

int main() {
  int N,j;
  cin>>N;
  cout<<0<<endl;
  string l,h;
  int right=N;
  int left=0;  
  cin>>l;

  for(j=0;j<20;j++){
	int half=(left+right)/2;
	cout<<half<<endl;
	cin>>h;
  if(count(left,l)==count(half,h)) {
	left=half;
	l=h;
  }
  else right=half;
  }
  return 0;
}    

Measured memory_bytes: 852
#include<iostream>
using namespace std;
int main(){
  int P1[15],P2[15],tmp;
  for(int i=0;i<10;i++){
    cin >> P1[i];
  }
  for(int i=0;i<10;i++){
    cin >> P2[i];
  }
  for(int i=0;i<9;i++){
    for(int j=9;j>i;j--){
      if(P1[j]>P1[j-1]){
	tmp=P1[j];
	P1[j]=P1[j-1];
	P1[j-1]=tmp;
      }
      if(P2[j]>P2[j-1]){
	tmp=P2[j];
	P2[j]=P2[j-1];
	P2[j-1]=tmp;
      }
    }
  }
  cout << P1[0]+P1[1]+P1[2] << " " << P2[0]+P2[1]+P2[2] << endl;
}

Measured memory_bytes: 1164
//#include <ext/pb_ds/assoc_container.hpp> 
     //#include <ext/pb_ds/tree_policy.hpp> 
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    #include <cstring>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <set>
    #include <map>
    #include <valarray>
    #include <iterator>
    #include <functional>
    #include <limits>
    #include <algorithm>
    #include <numeric>
    #include <cmath>
    #include <cassert>
    #include <unordered_map>
    #include <unordered_set>
    #include <stack>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define trace(x) cerr << #x << ": " << x << " " << endl;
     
    typedef int64_t ll;
     
    #define endl '\n'
    #define int ll
    ll mod=1e9+7;
    ll mod1=1e9+5;
     
    ll power(ll a,ll b)
    {
        if(b==0) return 1;
        else if(b%2==0)
            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
    }
     
   //  using namespace __gnu_pbds;
     //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
    //find_by_order(k)  returns iterator to kth element starting from 0;
    //order_of_key(k) returns count of elements strictly smaller than k;
    //erase,insert same as normal set
  

    int32_t main()
    {
        IOS
    
        int n,a,b;
        cin>>n>>a>>b;
        int temp=power(2,n)-1;
        temp+=mod;
        temp%=mod;
        int x=1;
        for(int i=0;i<=a-1;i++)
        {
            x=x*(n-i);
            x%=mod;
            x=x*power(i+1,mod-2);
            x%=mod;
        }
        int y=1;
        for(int i=0;i<=b-1;i++)
        {
            y=y*(n-i);
            y%=mod;
            y=y*power(i+1,mod-2);
            y%=mod;
        }
        temp-=x;
        temp+=mod;
        temp%=mod;
        temp-=y;
        temp+=mod;
        temp%=mod;
        cout<<temp<<endl;

    }       

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

int main() {
  string S;
  cin >> S;
  if(S == "Sunny"){
    cout << "Cloudy" << endl;
  }
  else if(S == "Cloudy"){
    cout << "Rainy" << endl;
  }
  else cout << "Sunny" << endl;
}


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n, m, x;
  cin >> n >> m >> x;

  ll a;
  ll l = 0, r = 0;
  REP(i, m) {
    cin >> a;
    if (a < x) {
      l++;
    } else {
      r++;
    }
  }
  cout << min(l, r) << "\n";
}

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

int main(){    
  long long a,b,c,k;
  cin >> a >> b >> c >> k;
  if(k < a) cout << k << endl;
  else if(a <= k && k <= a+b) cout << a << endl;
  else if(k > a+b)cout << a-(k-a-b) << endl;
}


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

#define MOD 1000000007

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

  vi a, b;
  rep(i, n)
  {
    ll _a;
    cin >> _a;
    a.push_back(_a);
  }

  rep(i, m)
  {
    ll _b;
    cin >> _b;
    b.push_back(_b);
  }

  int ans = 0;

  ll a_k = 0;
  int a_index = -1;

  ll b_k = 0;
  int b_index = -1;

  // b読める分だけ読む
  while(b_index + 1 < m && b_k + b[b_index + 1] <= k) {
    b_index++;
    b_k += b[b_index];
  }

  ans = b_index + 1;

  while(a_index + 1 < a.size())
  // for (int i = 0; i < n; i++)
  {
    a_index++;
    a_k += a[a_index];

    // bを減らす
    while (a_k + b_k > k && b_index >= 0)
    {
      b_k -= b[b_index];
      b_index--;
    }

    if (a_k + b_k > k) {
      break;
    }
    ans = max(ans, a_index + b_index + 2);
  }

  cout << ans << endl;
}


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

using namespace std;

int main() {
	int n, k;
	int ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		ans += min(2 * a, (k - a) * 2);
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>
using ll = long long;
using namespace std;


int main() {
    int N, K;
    int ans = 0;
  	string S;
    cin >> N >> K >> S;
	for(int i = 0; i < N-1; i++){
      if(S[i] == S[i+1]){
        ans++;
      }
    }
  	ans += 2*K;
  	cout << min(N-1, ans) << endl;
  	return 0;
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))

m = 10**9
n = 0
abs_sum = 0
for i in range(N):
    a = A[i]
    b = abs(a)
    m = min(m, b)
    abs_sum += b
    if a < 0:
        n += 1

if m == 0:
    print(abs_sum)
elif n%2 == 0:
    print(abs_sum)
else:
    print(abs_sum-2*m)

Measured memory_bytes: 14260
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
           while (scanner.hasNext()){
               String s = scanner.next();
               if (s.equals("-")){
                   break;
               }
               int m = scanner.nextInt();
               String shuffle = "";
               for (int i = 0; i < m; i++) {
                   int h = scanner.nextInt();
                   String a = s.substring(0,h);
                   String b = s.substring(h,s.length());
                   s = b+a;
               }
               System.out.println(s);

           }

        } catch (Exception e) {

        } finally {

        }

    }
}




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

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    if ((B-A)%2==0) {
        cout << (B-A)/2 << endl;
    } else {
        long long ans;
        ans = min(A-1, N-B) + 1 + (B-A-1)/2;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>
using namespace std;
   
  
   
int main(){
   
    int n; 
    int r[1000],w[1000];
    int sum_r=0,sum_w=0,idx=0;
    while(scanf("%d",&n),n){
         
        sum_r=sum_w=idx=0;
        for(int i=0;i<n;i++){
            scanf("%d %d",&r[i],&w[i]);
            sum_r+=r[i];
            sum_w+=w[i];
            if(r[idx]<r[i]) idx=i;
        }
  
        int r0=r[idx],r=sum_r-r0;
        w[idx]=0;
 
        if(r0 <= r){
            cout<<sum_r+sum_w<<endl;
        }else{
  
            int res=2*r0;
            //vector<vector<bool> > dp(1001,vector<bool>(1000,false));
  
			bool dp[1001][1000]={};
            dp[0][0]=true;
            for(int i=0;i<n;i++){
                for(int j=0;j<1000;j++){
                    if(dp[i][j]){
                        dp[i+1][j]=true; 
                        if(j+w[i]<1000)
                            dp[i+1][j+w[i]]=true; 
                    }
                }
            }
  
            int opt=r0-r;
            while(!dp[n][opt]) opt--;
  
            res+=sum_w-opt;
            printf("%d\n",res);
  
  
  
        }
          
          
    }
}

Measured memory_bytes: 4256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

void cout_vec(vector<int> &vec){
    for(int i=0; i<40; i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

void cout_mat(vector<vector<int>> &mat){
    for(int i=0; i<mat.size(); i++){
        vector<int> vec = mat[i];
        cout_vec(mat[i]);
    }
}

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

    vector<vector<long long> > dp(N+1,vector<long long>(50*50+1,0));
    dp[0][0]=1;
    int sum_=0;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        for(int j=i; j>=0; j--){
            for(int k=0; k<=sum_; k++){
                dp[j+1][k+x]+=dp[j][k];
            }
        }
        sum_+=x;
    }
    long long ans=0;
    for(int i=1; i<=N; i++){
        ans+=dp[i][i*A];
    }
    cout << ans << endl;

    //cout_mat(dp);
}

Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    cout << 3 * n * n << "\n";
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
string a[64];
int main(){
    ans = 700;
    string s;
    cin >> s;
    rep(i, s.size()){
        if(s[i] == 'o')
            ans += 100;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def li():
    return list(map(int, input().split()))
def mi():
    return map(int, input().split())
def ii():
    return int(input())

N = ii()
S = input()

current = 0
maxx = 0
for s in S:
    if s == "I":
        current += 1
    else:
        current -= 1
    maxx = max(maxx, current)

print(maxx)

Measured memory_bytes: 3060
import math

n = int(input())

flag = False

if n == 1:
    print('Yes')
    print(2)
    print(1, 1)
    print(1, 1)
    

    

else:
    for i in range(int(math.sqrt(2*n)+1)):
        if i * (i + 1) == 2 * n:
            k = i
            flag = True
            break
    if flag:
        print('Yes')
        print(k + 1)
        lll = []
        mem = 1
        for j in range(k+1):
            s = []
            
            for l in range(k):
                if l >= j:
                    s.append(mem)
                    mem += 1
                else:
                    s.append(lll[l][j-1])

            lll.append(s)
            print(k, ' '.join(map(str, s)))


    else:
        print('No')



Measured memory_bytes: 8968
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int main()
{
    int i, j, k;
    int n, t, m;
    cin >> s+1;
    int len = 0;
    len = strlen(s+1);
    int ans = 0;
    int ji = 0;
    s[0] = '0';
    for(i = len; i >= 1; i--) {
        int l = s[i]-'0'+ji;
        if(l == 10) {ji = 1; continue;}
        if(l > 5) {
            ans += 10-l;
            ji = 1;
        }
        else if(l == 5 && s[i-1]-'0' >= 5) {
            ans += 5;
            ji = 1;
        }
        else ans += l, ji = 0;
    }
    if(ji) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
#[allow(dead_code)]
fn main() {
    let (m, d) = i::u2();
    let mut ans = 0;
    for i in 1..m + 1 {
        for j in 2..d + 1 {
            let k = j / 10;
            let l = j % 10;
            if k < 2 || l < 2 {
                continue;
            }
            if i == k * l {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
n, a, b = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

mod = 10 ** 9 + 7

def comb(n, m, mod = 10 ** 9 + 7):
    numerator = 1
    denominator = 1
    for i in range(1, m + 1):
        numerator = numerator * (n - i + 1) % mod
        denominator = denominator * i % mod
    d_inv = pow(denominator, mod - 2, mod)
    return numerator * d_inv % mod

cmb_n_a = comb(n, a)
cmb_n_b = comb(n, b)

print((pow(2, n, mod) - 1 - cmb_n_a - cmb_n_b) % mod)

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int	A = sc.nextInt(),B=sc.nextInt(),C=sc.nextInt();
		int[] array = new int[B];
		for(int i=0;i<100;i++) {
			if((A*(i+1))%B==C) {
				System.out.println("YES");
				break;
			}else {
				if(array[(A*(i+1))%B]==1) {
					System.out.println("NO");
					break;
				}
				array[(A*(i+1))%B] = 1;
			}
		}
	}
	public static int sample() {
		return 1;
	}

}


Measured memory_bytes: 22868
/*
  AOJ 2187
  Title:card game
  @kankichi573
*/
#include <stdio.h>
#include <limits.h>

int fact(int n)
{
  if(n==1)
    return(1);
  else
    return(n*fact(n-1));
}

int compare(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int next_perm(int a[],int n)
{
  int i,j,p,min_,min_p,wk;

  if(a[n-2]<a[n-1])
    {
	wk=a[n-1];
	a[n-1]=a[n-2];
	a[n-2]=wk;
	return(-1);
    }


  for(i=n-1;i>=1;i--)
    if(a[i]>a[i-1])
      {
	p=a[i-1];
	min_=INT_MAX;
	for(j=i;j<n;j++)
	  if(a[j] > p && min_ > a[j])
	    {
	      min_=a[j];
	      min_p=j;
	    }
	wk=a[min_p];
	a[min_p]=a[i-1];
	a[i-1]=wk;
	qsort(&a[i],n-i,sizeof(int),compare);
        return(-1);
      }
 
  return(0);
}

int hantei(int cards[2][9])
{
  int g=0,j=0,i;

  for(i=0;i<9;i++)
    if(cards[0][i]>cards[1][i])
      g+=cards[0][i]+cards[1][i];
    else
      j+=cards[0][i]+cards[1][i];
  return(g>j);
}

main()
{
  int N,i,j,cnt,cnt_g;
  int cards[2][9];

  scanf("%d",&N);
  while(N--)
    {
      for(i=0;i<2;i++)
	for(j=0;j<9;j++)
	  scanf("%d",&cards[i][j]);
      cnt=cnt_g=0;
      qsort(&cards[0][0],9,sizeof(int),compare);
      do
	{
	  if(hantei(cards))
	    cnt_g++;
	  cnt++;
	}
      while(next_perm(&cards[0][0],9));
      printf("%0.5lf %0.5lf\n",(double)cnt_g/(double)cnt,
	     (double)(cnt-cnt_g)/(double)cnt);
    }
  return(0);
}

Measured memory_bytes: 644
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m,k = inpm()
a = [0] + inpl()
b = [0] + inpl()
aa = [0]
bb = [0]
for i in range(1,len(a)):
  aa.append(a[i] + aa[i-1])
for i in range(1,len(b)):
  bb.append(b[i] + bb[i-1])

ans = 0
for i in range(n+1):
    zan = k - aa[i]
    if zan < 0:
        break
    bcnt = bisect.bisect(bb,zan)
    ans = max(ans,i+bcnt-1)

print(ans)

Measured memory_bytes: 69936
#include <stdio.h>

#define MAX_N 1000000

int isPrime[ MAX_N + 1 ];

int main( void ) {
	int i, j, a, d, n, fig;

	isPrime[ 0 ] = isPrime[ 1 ] = 0;
	for ( i = 2; i <= MAX_N; i++ )
		isPrime[ i ] = 1;

	for ( i = 4; i <= MAX_N; i += 2 )
		isPrime[ i ] = 0;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	for ( ; scanf( "%d %d %d", &a, &d, &n ), a; printf( "%d\n", fig - d ) )
		for ( fig = a; n; fig += d )
			if ( isPrime[ fig ] )
				n--;

	return 0;
}

Measured memory_bytes: 4504
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define pb  push_back
#define mp make_pair
#define ll long long
#define pr pair<int, int> 
#define vpr vector<pr> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define all(n) n.begin(),n.end()
#define Test printf("Case %d: ",tc++);
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
const int mod = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

int solve() 
{
	//happy coding

	ll n,m;
	cin>> n>> m;
	ll wt[n+1],val[n+1];
	for(ll i=0;i<n;i++){
		cin>>wt[i]>>val[i];
	}


	ll dp[n+1][m+1];
	memset(dp,0,sizeof dp);
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=m;j++){
			if(j>=wt[i-1]){
				//dp[i][j] = max(dp[i-1][j-wt[i-1]]+val[i-1],dp[i-1][j]);
				dp[i][j] = max(dp[i-1][j-wt[i-1]]+val[i-1],dp[i-1][j]);
			}else {
				dp[i][j] = dp[i-1][j];
			}
			//cout<<dp[i][j]<<" ";
		}//cout<<endl;
	}
	cout<<dp[n][m]<<endl;
	
	//cout<<cnt<<endl;

	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

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

using namespace std;

int main(){

  int n;
  cin>>n;
  
  vector<int> v(n),temp(n);
  
  for(int i = 0; i < n ; i++) { cin>>v[i]; temp[i]=v[i];}
  
  sort(v.begin(), v.end());
  
  for(int i =0 ; i < n; i++) {
    if(temp[i] != v[n-1]) cout<<v[n-1]<<endl;
    else cout<< v[n-2]<<endl;
  }
}

Measured memory_bytes: 3200
include Math
while true
  n = gets.to_i
  break if n==0

  s = 2*n
  x = 2  
  ptn = 0
  while x<sqrt(s)
    if s%x == 0
      k2 = s/x-x+1
      ptn += 1 if k2>0 && k2%2==0
    end
    x += 1
  end

  puts ptn
end

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

int main()
{
    int k, s, count;
    cin >> k >> s;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s - x - y;
            if (0 <= z && z <= k) count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

int main(){
    int h, a;
    cin >> h >> a;
    if (h%a==0) cout << h / a << endl;
    else cout << h / a + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>

using namespace std;


int main(){

	int n;
	cin >> n;

	long int sum=1;

	for(int i=n; i>0 ; i--){
		sum *= i;
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
    int n;
    int x=0,ans=0;
    scanf("%d",&n);
    char s[n];
    scanf("%s",s);
    for (int i=0;i<=n; ++i)
    {  
        if(s[i]=='I')++x;
        else --x;
        
        if(ans<x)ans=x;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, H: "List[int]", A: "List[int]", B: "List[int]"):
    mh = [-1] * N
    for a, b in zip(A, B):
        mh[a-1] = max(mh[a-1], H[b-1])
        mh[b-1] = max(mh[b-1], H[a-1])
    ans = 0
    for h, mhh in zip(H, mh):
        if h > mhh:
            ans += 1
    return ans


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    print(solve(N, M, H, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 22896
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;

vector<ll> vec;
ll n;
ll t;

int main(){
	while(cin>>n,n){
		vec.clear();
		ll res=0;
		rep(i,n){
			cin>>t;
			vec.PB(t);
		}


		//2 3 4 6 9
		//2 5 9 15
		sort(ALL(vec));
		// rep(i,n) cout<<vec[i]<<endl;
		rep(i,n){
			if(i) vec[i]+=vec[i-1];
		}
		rep(i,n-1) res+=vec[i];
		cout<<res<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 1340
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


long long proba(long long a, long long b, long long k)
{
    long long c;
    c = a / k;
    
    bool flag = false;
    
    while(1)
    {
        if (c * k >= a && c * k <= b)
        {
            //return c * k;
            flag = true;
            break;
        } else if (c * k <= b)
        {
            c++;
        } else if (c * k > b) {
            break;
        }
    }
    if(flag == true) return c;
    else return 0;
}

int main(int argc, const char * argv[]) {

    long long a, b, n, max = 0, mn;
    
    long long ex;
    
    cin >> a >> b >> n;
    long long ans = 0;
    
    mn = min(b-1, n);
//
//    for(long long i=0; i<=mn; i++)
//    {
//
//         ans = (long long)(a * i / b) - a * (long long)(i / b);
//
//        //cout << ans << endl;
//        if (ans > max) max = ans;
//        else if (ans < max) break;
//    }
    
    ans = (long long)(a * mn / b) - a * (long long)(mn / b);

    
    cout << ans << endl;
    
    
}


Measured memory_bytes: 3588