akhauriyash/Code-Regression huggingface dataset:
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846



// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
// int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
// int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
// int x2[]={-2,-2,-1,-1,+1,+1,+2,+2};
// int y2[]={-1,+1,-2,+2,-2,+2,-1,+1};
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
      
      ll n,d;cin>>n>>d;
      int ans=0;
      f(i,0,n)
      {
        ll x,y;cin>>x>>y;
        if((x*x+(y*y))<=(d*d))
        ans++;
      }
      cout<<ans;
      
    }    
} 

Measured memory_bytes: 3640
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    int N, X;
    cin >> N >> X;

    vector<int> ms(N);
    for (int i = 0; i < N; i++) {
        cin >> ms[i];
    }
    sort(ms.begin(), ms.end());

    int cnt = 0;
    int rem = X;
    for (auto &m : ms) {
        rem -= m;
        cnt++;
    }

    while (rem - ms[0] >= 0) {
        rem -= ms[0];
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

using namespace std;

int main()
{
    int n, a, ans = 0;
    int v[21];
    cin >> n;

    for(int i = 0; i < n; i++)
        cin >> v[i];
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        if(v[i] - a > 0)
            ans += (v[i] - a);
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
  ll a,b,n; cin >> a >> b >> n;

  ll x = b-1;
  if(n<b-1) x = n;
  ll ans = floor(a*(x%b)/b);

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


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

#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

#define ll long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vvi vector<vi > 
#define vii vector<pii >

pii operator+(pii a, pii b)
{
    return {a.fi+b.fi,a.se+b.se};
}
pll operator+(pll a, pll b)
{
    return {a.fi+b.fi,a.se+b.se};
}
std::ostream& operator<<(std::ostream& out,pii a)
{
    out<<a.fi<<" "<<a.se<<endl;
    return out;
}
std::ostream& operator<<(std::ostream& out,pll a)
{
    out<<a.fi<<" "<<a.se<<endl;
    return out;
}
std::istream& operator>>(std::istream& in,pii &a)
{
    in>>a.fi>>a.se;
    return in;
}
std::istream& operator>>(std::istream& in,pll &a)
{
    in>>a.fi>>a.se;
    return in;
}

using namespace std;

int main()
{
    FAST;
    int n,W;
    cin>>n>>W;
    int w[n],v[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>w[i]>>v[i];
    }
    ll dp[n+1][W+1];
    for (int i = 0; i <=W; ++i)
    {
        dp[0][i]=0;
    }
    for (int i = 1; i < n+1; ++i)
    {
        for (int j = 0; j < W+1; ++j)
        {
            if(w[i-1]>j)
            {
                dp[i][j]=dp[i-1][j];
            }else{
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
            }
        }
    }
    cout<<dp[n][W];

}

Measured memory_bytes: 79232
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;
int rui(int a, int b) {
    if(b == 0) {
        return 1;
    }
    return rui(a, b - 1) * a;
}
int main() {
    long long N;
    cin >> N;
    long long sum = 0;
    rep(i, 1, N + 1) {
        if(i % 5 != 0 && i % 3 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] time = new int[n];
		for (int i = 0; i < time.length; i++) {
			time[i] = sc.nextInt();
		}
		
		int m = sc.nextInt();
		int[][] drink = new int[m][2];
		for (int i = 0; i < drink.length; i++) {
			drink[i][0] = sc.nextInt();
			drink[i][1] = sc.nextInt();
		}
		
		for (int i = 0; i < drink.length; i++) {
			int ans = 0;
			for (int j = 0; j < time.length; j++) {
				if (j == drink[i][0] - 1) {
					ans += drink[i][1];
					continue;
				}
				ans += time[j];
			}
			System.out.println(ans);
		}
		
	}
}

Measured memory_bytes: 25300
i,j,c,b,v,u,D[10000];main(N,K,T,U,V,L,x){
	scanf("%d%d%d%d%d%d",&N,&K,&T,&U,&V,&L);
	for(;i<N;i++)scanf("%d",&x),D[x]=1;
	for(;j<L;j++){
		if((c+=D[j])>K||(c&&!b))c--,b=T*V;
		b?v++,b--:u++;
	}
	printf("%f\n",1.*v/V+1.*u/U);
exit(0);}

Measured memory_bytes: 668
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n == 0)break;
			
			for(int i = 0; i < n; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			
			if((a==100||b==100||c==100)||(a+b>=180)||(a+b+c>=240)){
                System.out.println("A");
            }else if((a+b+c>=210)||(a+b+c>=150&&(a>=80||b>=80))){
                System.out.println("B");
            }else{
               System.out. println("C");
			}
		}
		}}}

Measured memory_bytes: 28468
#pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize ("Ofast")
        #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
         
         
        #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;
        }
        #define PI 3.14159265
     int32_t main()
        {
            IOS
      
        int n;
        cin>>n;
        int ans=1e15;
        for(int i=1;i<=sqrt(n);++i)
        {
            if(n%i==0)
            {
                int a=n/i;
                int b=i;
                if(a>b)
                    swap(a,b);
                ans=min(ans,a-1+b-1);
            }
        }
        cout<<ans;
        }

Measured memory_bytes: 256
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 2e3+5;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//ll powmod(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;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}

int main()
{
   int n;
   cin>>n;
   int arr[n];
   for(int i=0;i<n;i++) cin>>arr[i];
   int ag[n],bg[n];
   for(int i=0;i<n;i++)
   {
       if(!i) ag[i]=arr[i];
       else ag[i]=__gcd(arr[i],ag[i-1]);
   }
   bg[n-1]=arr[n-1];
   for(int i=n-2;i>=0;i--)
   {
       bg[i]=__gcd(arr[i],bg[i+1]);
   }
   int ans=max({ag[n-2],bg[1],bg[0]});
   for(int i=1;i<n-1;i++)
   {
       ans=max(ans,__gcd(ag[i-1],bg[i+1]));
   }
   cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

struct edge {
  ll to, cost;
};
vector<vector<edge> > edges;

vector<ll> dist;
bool bellman_ford(int n, int s) {
  dist = vector<ll>(n, INF);
  dist[s] = 0;
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < edges[v].size(); k++) {
        edge e = edges[v][k];
        if (dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
          if (i == n - 1 && e.to == n - 1) {
            return true;
          }
        }
      }
    }
  }
  return false;
}

int main(int argc, const char * argv[]) {
  ll N, M, a, b, c;
  cin >> N >> M;
  edges = vector<vector<edge> >(N, vector<edge>());
  for (int i = 0; i < M; i++) {
    cin >> a >> b >> c;
    a--, b--;
    edges[a].push_back((edge){ b, -c });
  }
  if (bellman_ford(N, 0)) {
    cout << "inf" << endl;
  } else {
    cout << -dist[N - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int dim=pow(2,m);
	cout<<(n-m)*100*dim+1900*m*dim<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
ll x,b[100100],l[100100],u[100100],df=0ll;
vector<int> v;

ll comp(int i, int j){
	ll p,q;
	p = (x-b[i])*u[i]+b[i]*l[i];
	q = (x-b[j])*u[j]+b[j]*l[j];
	return p>q;
}

bool judge(ll p){
	int i;
	ll q,r,tmp=df,d=-INFLL,c,qv;
	q = p/x; r = p%x;
	for(i=0; i<q; ++i){
		tmp += (x-b[v[i]])*u[v[i]]+b[v[i]]*l[v[i]];
	}
	qv = (x-b[v[q]])*u[v[q]]+b[v[q]]*l[v[q]];
	for(i=0; i<n; ++i){
		c = min(r,b[v[i]])*l[v[i]]+max(r-b[v[i]],0ll)*u[v[i]];
		if(i<q){
			c -= (x-b[v[i]])*u[v[i]]+b[v[i]]*l[v[i]];
			d = max(d,tmp+qv+c);
		}else{
			d = max(d,tmp+c);
		}
	}
	return (d>=0ll);
}

int main(void){
	int i;
	ll ok=0ll,ng,mid;
	cin >> n >> x;
	for(i=0; i<n; ++i){
		v.push_back(i);
		cin >> b[i] >> l[i] >> u[i];
		df -= b[i]*l[i];
		ok += b[i];
	}
	sort(v.begin(),v.end(),comp);
	ng = 0ll;
	while(ok-ng>1){
		mid = (ok+ng)>>1;
		if(judge(mid)){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	cout << ok << endl;
	return 0;
}


Measured memory_bytes: 3064
N, K = map(int, input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))

maxscore = -(10 ** 18)

for st in range(N):
	cumsum = [0]
	now = st
	while(P[now] != st):
		now = P[now]
		cumsum.append(cumsum[-1] + C[now])
	cumsum.append(cumsum[-1] + C[st])
	
	m = len(cumsum) - 1
	loopsum = cumsum[-1]
	
	if loopsum < 0:
		maxscore = max(maxscore, max(cumsum[1:min(K + 1, m + 1)]))
		continue
	
	score = (K // m - 1) * loopsum
	extended_cumsum = cumsum + [cumsum[i] + loopsum for i in range(1, K % m + 1)]
	score += max(extended_cumsum)
	maxscore = max(maxscore, score)
print(maxscore)

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

struct dice {
    int l, r, f, b, d, u;
    dice() {}
    dice(int l, int r, int f, int b, int d, int u):
        l(l), r(r), f(f), b(b), d(d), u(u) {}

    dice rot_right() {
        return dice(d, u, f, b, r, l);
    }

    dice rot_left() {
        return dice(u, d, f, b, l, r);
    }

    dice rot_front() {
        return dice(l, r, u, d, f, b);
    }

    dice rot_back() {
        return dice(l, r, d, u, b, f);
    }
};

using PR = int;
using MAP_t = map<PR, int>;

int encode(int x, int y) { return 3000 * x + y; }

int N;
MAP_t boards[1 << 15];
int scores[1 << 15];

int merge(int idx1, int idx2, MAP_t& dest) {
    dest = boards[idx1];
    int res_v = scores[idx1];

    for (const pair<PR, int>& itr : boards[idx2]) {
        if (dest[itr.first] == 0) {
            res_v += itr.second;
            dest[itr.first] = itr.second;
        }
    }

    return res_v;
}

int solve() {
    MAP_t trg;

    for (int n = 1; n < (1 << N); ++n) {
        for (int i = 0; i < N; ++i) {
            if ((n & (1 << i)) == 0) continue;
            int m = n ^ (1 << i);

            int sc = merge(m, (1 << i), trg);
            if (sc > scores[n]) {
                boards[n] = trg;
                scores[n] = sc;
            }
        }
    }

    return scores[(1 << N) - 1];
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    while (true) {
        cin >> N; if (N == 0) break;
        fill(scores, scores + (1 << N), 0);
        for (int i = 0; i < N; ++i) boards[1 << i].clear();
        for (int i = 0; i < N; ++i) {
            int x, y; dice d; string p;
            cin >> x >> y >> d.l >> d.r >> d.f >> d.b >> d.d >> d.u;

            x += 1000; y += 1000;

            int idx = 1 << i;
            int sc = 0;

            boards[idx][encode(x, y)] = d.d;
            sc += d.d;

            cin >> p;
            for (char ch : p) {
                if (ch == 'L') {
                    --x;
                    d = d.rot_left();
                } else if (ch == 'R') {
                    ++x;
                    d = d.rot_right();
                } else if (ch == 'B') {
                    ++y;
                    d = d.rot_back();
                } else {
                    --y;
                    d = d.rot_front();
                }
                PR key = encode(x, y);
                sc += d.d - boards[idx][key];
                boards[idx][key] = d.d;
            }
            scores[idx] = sc;
        }
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 235184
# coding: utf-8
import sys
sysread = sys.stdin.readline
def run():
    S = input()
    mods = [[] for _ in range(2019)]
    mods[0].append(0)

    tmp = 0
    tmp10 = 1
    for i in range(1, len(S)+1):
        if i == 1:
            tmp10 = 1
        else:
            tmp10 = (tmp10 * 10) % 2019
        tmp = (tmp10* int(S[-i]) + tmp)% 2019
        mods[tmp].append(i)

    count = 0
    for ns in mods:
        l = len(ns)
        count += l * (l-1) // 2
    print(count)

if __name__ == "__main__":
    run()

Measured memory_bytes: 17632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;

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

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<a*b/gcd(a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, k;
  cin >> a >> b;
  k=(a+b)/2/*+(a+b)%2*/;
  if(a-k==-(b-k)){
    cout << k << endl;
  } else{
    cout << "IMPOSSIBLE" <<endl;
  }
}

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

int main(){
  int64_t n;
  cin >> n;
  bool flag = false;
  while(!flag){
    bool primeflag = true;
    for(int i = 2;i <= sqrt(n);i++){
      if(n % i == 0){
        primeflag = false;
        break;
      }
    }
    if(primeflag){
      break;
    }else{
      n++;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def main():
    X = int(input())
    for i in range(X, 100004):
        if is_prime(i):
            print(i)
            break

if __name__ == '__main__': main()

Measured memory_bytes: 3060
import sys

n,y = map(int,input().split())

if y // 10000 > n:
	print("-1 -1 -1")
	sys.exit()

for i in reversed(range(y//10000 + 1)):
	n -= i
	y -= 10000 * i
	if 10000 * i + 5000 * (n-i) < y:
		break
	for j in reversed(range(y//5000 + 1)):
		n -= j
		y -= 5000 * j
		for k in reversed(range(y//1000 + 1)):
			n -= k
			y -= 1000 * k
			if y == 0 and n == 0:
				print(i,j,k)
				sys.exit()
			else:
				n += k
				y += 1000 * k
				break
		n += j
		y += 5000 * j
	n += i
	y += 10000 * i

print("-1 -1 -1")


Measured memory_bytes: 41480
#include "stdio.h"
#include "algorithm"

int n,x;
long long oper;
int a[100005];

int main(){
	scanf("%d%d%d",&n,&x,&a[0]);
	for(int i = 1; i < n; i++){
		scanf("%d",&a[i]);
		if(a[i]+a[i-1]>x){
			const int ch = std::min(a[i],a[i]+a[i-1]-x);
			oper += ch;
			a[i] -= ch;
		}

		if(a[i-1]>x){
			oper += a[i-1]-x;
			a[i-1] -= a[i-1]-x;
		}
	}
	printf("%lld\n",oper);
}

Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

using Pair = pair<int, int>;
using lint = long long;

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

//const int mod = 1e9 + 7;
const int mod = 998244353;

template <typename T>
vector<T> make_v(size_t a) {
  return vector<T>(a);
}

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i, k) cin >> l[i] >> r[i];
  vector<lint> dp(n,0), sum(n,0);
  dp[0] = 1;
  sum[0] = 1;
  for (int i = 1; i < n; i++) {
    rep(j, k) {
      if (i - l[j] < 0)
        continue;
      else if ((i - r[j] <= 0)) {
        dp[i] += sum[i - l[j]];
        dp[i] %= mod;
      } else {
        dp[i] += sum[i - l[j]] - sum[i - r[j] - 1];
        dp[i] %= mod;
        dp[i] += mod;
        dp[i] %= mod;
      }
    }
    sum[i] = sum[i - 1] + dp[i];
    sum[i] %= mod;
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 6420
#include<iostream>
using namespace std;
int gcd(int a, int b)
{
	int c = a%b;
	if (c == 0) return b;
	else return gcd(b, c);
}
int main()
{
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 3108
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let x: i128 = s.trim().parse().unwrap();

    'outer: for i in -10000i128..=10000 {
        //for j in -10000i128..=10000 {
        let mut l: i128 = -10000;
        let mut r: i128 = 10000;
        let mut m: i128;
        while l < r {
            m = (l + r) / 2;
            let t = i.pow(5) - m.pow(5);
            if t == x {
                println!("{} {}", i, m);

                break 'outer;
            } else if m == r || m == l {
                break;
            } else if t < x {
                r = m;
            } else {
                l = m;
            }
        }
    }
}


Measured memory_bytes: 2128
#include <stdio.h>

int main( void ) {
	int i, n;

	scanf( "%d", &n );

	while ( n-- ) {
		int a, b, c;

		scanf( "%d %d %d", &a, &b, &c );
		if ( a * a + b * b == c * c || b * b + c * c == a * a || c * c + a * a == b * b )
			puts( "YES" );
		else
			puts( "NO" );
	}

	return 0;
}

Measured memory_bytes: 580
#define _CRT_SECURE_NO_WARNINGS 1

#include <cstdio>
#include <vector>
using namespace std;
int main()
{
	long long n;
	while (scanf("%Ld\n", &n), n) {
		vector<pair<long long, long long> > v;
		for (long long i = 0; i < n; i++) {
			long long p, q, r, f = 1;
			scanf("%Ld %Ld %Ld\n", &p, &q, &r);
			for (long long j = 0; j < v.size(); j++) {
				if (v[j].first == p) {
					f = 0;
					v[j].second += q * r;
				}
			}
			if (f) {
				pair<long long, long long> pa(p, q * r);
				v.push_back(pa);
			}

		}
		long long g = 1;
		for (long long i = 0; i < v.size(); i++) {
			if (1000000 <= v[i].second) {
				g = 0;
				printf("%Ld\n", v[i].first);
			}
		}
		if (g) puts("NA");
	}
	return 0;
}

Measured memory_bytes: 1080
from sys import setrecursionlimit
setrecursionlimit(200000)

H, W = map( int, input().split() )
S = [ list( input() ) for _ in range(H) ]


isVisited = [ [False]*W for _ in range(H) ]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
# (i, j) から行けるペアの数
def dfs( x, y ):
    isVisited[x][y] = True
    numBlack, numWhite = 0, 0
    if S[x][y] == '#': numBlack = 1
    else:              numWhite = 1
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx and nx < H and 0 <= ny and ny < W and not isVisited[nx][ny]:
            if S[x][y] != S[nx][ny]:
                tmpB, tmpW = dfs( nx, ny )
                numBlack += tmpB
                numWhite += tmpW
    return numBlack, numWhite

ans = 0
for i in range(H):
    for j in range(W):
        if not isVisited[i][j]: 
            numBlack, numWhite = dfs( i, j )
            ans += numBlack * numWhite

print( ans )

Measured memory_bytes: 160868
# 以下を参考にした：
# https://atcoder.jp/contests/abc163/submissions/12170593

# ----------
# n=int(input())
# c=list(map(int,input().split()))
# g=[[] for _ in range(n+1)]
# ----------
# n->@n
# c->@color
# ----------

@n = gets.to_i
@colors = gets.split.map(&:to_i)
@colors.unshift 0 # 先頭はダミー

# ----------
# for _ in range(n-1):
#     s,t=map(int, input().split())
#     s-=1
#     t-=1
#     g[s].append(t)
#     g[t].append(s)
# ----------
# g->@adj
# ----------

# 隣接情報
@adj = (1+@n).times.map{Array.new} # 先頭はダミー
(@n-1).times do
  a, b = gets.split.map(&:to_i)
  @adj[a].push b
  @adj[b].push a
end

# ----------
# ans=[0]*(n+1)
# ----------

# 何の情報？
@ans = Array.new(@n+1, 0)

# ----------
# def sum(n):return n*(n+1)//2
# ----------

def sum(n)
  n*(n+1)/2
end

# ----------
# # 部分木のサイズと、「色iを封鎖したときに到達できない頂点の個数」を持つ辞書を返す
# def dfs(v,p):
#     ret=defaultdict(int)
#     size=1
#     for vv in g[v]:
#         if vv==p:
#             continue
#         ss,d=dfs(vv,v)
#         size+=ss
#         ans[c[v]]+=sum(ss-d[c[v]])
#         
#         # マージテク
#         if len(ret)<len(d):
#             ret,d=d,ret
#         for vvv in d:
#             ret[vvv]+=d[vvv]
#     ret[c[v]]=size
#     return size,ret
# 
# ----------
# v->node
# p->parent
# ----------

# nodeを根とする部分木のサイズと、色iを封鎖したときに到達できない頂点の個数のハッシュを返す
def dfs(node, parent)
  size = 1
  unreach = Hash.new(0)
  node_color = @colors[node]

  @adj[node].each do |child|
    if child != parent
      sub_size, sub_unreach = dfs(child, node)
      size += sub_size
      @ans[node_color] += sum(sub_size - sub_unreach[node_color])

      # サイズが大きい方を使い回す
      if unreach.size < sub_unreach.size
        unreach, sub_unreach = [sub_unreach, unreach]
      end
      sub_unreach.each do |color, value|
        unreach[color] += value
      end
    end
  end

  unreach[node_color] = size
  [size, unreach]
end

# ----------
# _,ret=dfs(0,-1)
# for i in range(1,n+1):
#     print(sum(n)-ans[i]-sum(n-ret[i]))
# ----------

_, ret = dfs(1, 0)
(1..@n).each do |i|
  puts sum(@n) - @ans[i] - sum(@n-ret[i])
end


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

#define ll long long
ll n, p;

int main()
{
	while (scanf("%lld%lld", &n, &p) != EOF) 
	{
		if (n == 1)
		{
			printf("%lld\n", p); 
			continue; 
		}
		ll res = 1;
		for (ll i = 2; i * i <= p; ++i)  
		{	
			ll tmp = 0; 
			while (p % i == 0) 
			{
				++tmp;
				p /= i; 
			}
			while (tmp >= n)
			{
				tmp -= n;
				res *= i;
			}
		}
		printf("%lld\n", res);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
#define ll long long
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> L(N + 2);
	vector<pair<int, int>> v(N + 2, { 1,1 });
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		cin >> L[i];
		if (i == 1) L[i - 1] = L[i];
		if (i == N) L[N + 1] = L[N];
	}
	for (int i = 2; i <= N;i++) {
		if (L[i] != L[i - 1]) { 
			v[i].first = v[i - 1].first + 1; 
			ans = max(ans, v[i].first);
		}
	}
	for (int i = N - 1; i >= 1; i--) {
		if (L[i] != L[i + 1]) {
			v[i].second = v[i + 1].second + 1;
			ans = max(ans, v[i].second);
		}
	}
	v[0].first = 0; v[N + 1].second = 0;

	int l = 1, r = 1;
	while (true) {
		if (L[r] == L[r + 1]) {
			if ((r - l + 1) % 2 == 1) {
				if (L[l] == L[r]) {
					ans = max(ans, v[l - 1].first + (r - l + 1) + v[r + 1].second);
				}
			}
			else {
				if (L[l] != L[r]) {
					ans = max(ans, v[l - 1].first + (r - l + 1) + v[r + 1].second);
				}
			}
			l = r + 1;
		}
		r++;
		if (r == N) {
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4160
n = int(input())

words = [list(map(str,input())) for i in range(n)]

common_chr = [[] for i in range(n)]

for i in range(len(words[0])):
    common_chr[0].append(words[0][i])

for i in range(1,n):
    for j in range(len(words[i])):
        if words[i][j] in common_chr[i-1]:
            if common_chr[i-1].count(words[i][j]) > common_chr[i].count(words[i][j]):
                common_chr[i].append(words[i][j])

print(''.join(sorted(common_chr[-1])))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
const int Inf = 100100100;
const double EPS = 1e-9;
 
int main()
{
    int n,m,maxl=0;
    int minr = Inf;
    cin >> n >> m;
    
    int l[m],r[m];
    for (int i=0;i<m;++i) {
        cin >> l[i] >> r[i];
        maxl = max(maxl, l[i]);
        minr = min(minr, r[i]);
    }
    int ans = minr - maxl + 1;
    ans = max(ans, 0);
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[30][200000], a[200000], b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<Edge>>vec;
vector<edge>ed;
vector<LL>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m;
	if (m > 20) {
		cout << 0 << endl;
		return 0;
	}
	rep(i, n+1)dp[0][i] = 1;
	rep(i, m) {
		for (LL j = 1; j <= n; j++) {
			for (LL k = 2; k <= n; k++) {
				if (j*k > n)break;
				dp[i + 1][j*k] += dp[i][j];
			}
		}
	}
	rep(i, n)ans += dp[m-1][i+1];
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 18672
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 100110
#define inf 1001000100
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pi pair<int ,int>
#define pii pair <pi,pi>
using namespace std;
int arr[nax];
int brr[nax];
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int n;
  sd(n);
  for(int i = 1; i <=  n; i++)
  {
    sd(arr[i]);
    brr[i] = i;
  }
  int cnt = 0;
  for(int i = 1; i<= n; i++)
  {
    if(arr[i] == i)
    {
        swap(arr[i],arr[i+1]);
        ++cnt;
    }
  }
  cout<< cnt << '\n';
  return 0;
}   

Measured memory_bytes: 1024
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,q;
    cin>>n>>k>>q;
    VII s(n+1,k);
    for(int i=0;i<q;++i)
    {
        int x;
        cin>>x;
        s[x]++;
    }
    for(int i=1;i<=n;++i)
    {
        if(s[i]-q>0)
        cout<<"Yes\n";

        else cout<<"No\n";
    }


    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long arr[]=new long[100001];
        long sum = 0;

        for(int i=0; i<n; i++) {
            int a = sc.nextInt();
            arr[a] += 1;
            sum += a;
        }

        int q = sc.nextInt();

        int[] bArr = new int[q];
        int[] cArr = new int[q];
        for(int i=0; i<q; i++) {
            bArr[i] = sc.nextInt();
            cArr[i] = sc.nextInt();
        }

        for(int i=0; i<q; i++) {
            int b = bArr[i];
            int c = cArr[i];
            long count = arr[b];
            arr[b]=0;
            arr[c]+=count;
            sum += (c-b)*count;
            System.out.print(sum);
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 60924
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  vector<int> A(N);
  ll ans = 0;
  ll M = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (M < A.at(i)) {
      M = A.at(i);
    }
    else {
      ans += (M - A.at(i));
    }
  }
  cout << ans << endl;
    
    
}
  
  
  

Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; string s; cin >> n >> s;
    int ans = 0;
    rep(i,0,n){
        vector<int> z = z_algorithm(s.substr(i,s.size()-i));
        debug(s.substr(i,n-i),z);
        rep(j,1,z.size()){
            chmax(ans,min(z[j],j));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
n = gets.chomp.to_i
card = Hash.new(){0}
n.times do
  card[gets.chomp] += 1
end

m = gets.chomp.to_i
m.times do
  card[gets.chomp] -= 1
end

maxv = card.values.max
puts maxv > 0 ? maxv : "0"

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<set>
#include<unordered_map>
using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

		int n;
		cin>>n;
		int a[n];
		for(int i = 0;i<n;i++){
			cin>>a[i];
		}
		int c = 1;
		int k = 0;
		for(int i = 0;i<n;i++){
		
			if(a[i] ==c){
				c++;
				k++;
			}
		}
		if(k==0){
			cout<<-1;
			return 0;
		}
		cout<<(n-k);




}



Measured memory_bytes: 4360
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC081A_PlacingMarbles
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int count = 0;
            for(int i = 0; i < s.Length; i++)
            {
                if (s[i] == '1')
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    int N , M;
    cin >> N >> M;
    int a[N], b[N];
    int c[M], d[M];
    int res[N];

    for(int i = 0; i <N; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i <M; i++){
        cin >> c[i] >> d[i];
    }

    for(int i = 0; i < N; i++){
        int min_cost = INT32_MAX;
        for(int j = 0; j < M; j++){
            int cost = abs(a[i] - c[j]) + abs(b[i] - d[j]);

            if(cost < min_cost){
                min_cost = cost;
                res[i] = j + 1;
            }
        }
    }

    for(int i = 0; i <N; i++){
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= putStrLn . unwords . fmap show . solve 

solve :: [Int] -> [Int]
solve [n, y]
    | r > 10000 || r < 1000 = [-1, -1, -1]
    | m == 0 && r == 1000 = [0, 0, n]
    | m == 0 && r == 5000 = [0, n, 0]
    | m == 0 && r == 10000 = [n, 0, 0]
    | null res = [-1, -1, -1]
    | otherwise = head res
    where
        (r, m) = y `divMod` n
        res = calc n y

calc :: Int -> Int -> [[Int]]
calc n v = [[x, y, n - x - y] | x <- [0..n], y <- [0..(n - x)], v == 10000 * x + 5000 * y + 1000 * (n - x - y)]

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)

Measured memory_bytes: 636
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    // '+' -> '-' -> '+' -> … のとき
    ll sum = 0;
    ll ans1 = 0;
    rep(i, n) {
        sum += a[i];
        if(i%2 == 1) {
            if(sum <= 0) {
                ans1 += 1 - sum;
                sum = 1;
            }
        }
        else {
            if(sum >= 0) {
                ans1 += 1 + sum;
                sum = -1;
            }
        }
    }

    // '-' -> '+' -> '-' -> … のとき
    sum = 0;
    ll ans2 = 0;
    rep(i, n) {
        sum += a[i];
        if(i%2 == 1) {
            if(sum >= 0) {
                ans2 += 1 + sum;
                sum = -1;
            }
        }
        else {
            if(sum <= 0) {
                ans2 += 1 - sum;
                sum = 1;
            }
        }
    }

    out(min(ans1, ans2));
    re0;
}

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

int main()
{
	int n, m, l;
	cin >> n >> m >> l;
	long gyoretsu0[100][100];
	long gyoretsu1[100][100];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> gyoretsu0[i][j];
		}
	}
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < l; j++)
		{
			cin >> gyoretsu1[i][j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l - 1; j++)
		{
			long sum = 0;
			for (int c = 0; c < m; c++)
			{
				sum += gyoretsu0[i][c] * gyoretsu1[c][j];
			}
			cout << sum << " ";
		}
		long sum = 0;
		int j = l - 1;
		for (int c = 0; c < m; c++)
		{
			sum += gyoretsu0[i][c] * gyoretsu1[c][j];
		}
		cout << sum << endl;
	}
}


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

string a, b, c;

int main() {
    cin >> a >> b >> c;

    cout << char(a[0] - 'a' + 'A') << char(b[0] - 'a' + 'A') << char(c[0] - 'a' + 'A') << endl;

    return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;


int main(){
	string s;
	int k;
	cin >> s >> k;
	int n = s.size()-1;
	int N = n;
	ll ans = 0;
	/*rip(i,k,0){
		ans *= (n-i)*9;
		ans /= i+1;
	}
	cout << ans << endl;*/
	while(n > -1 && k > 0){
		if(s[N-n] == '0'){
			n--;
			continue;
		}
		ll add = s[N - n] -'0'-1;
		rip(i,k-1,0){
			add *= (n-i)*9;
			add /= i+1;
		}
		//cout << n MM k MM add << endl;
		ans += add;
		add = 1;
		rip(i,k,0){
			add *= (n-i)*9;
			add/=i+1;
		}
		ans += add;
		k--;
		n--;
	}
	if(k==0) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
import bisect

n=int(input())
l=list(map(int, input().split()))
count=0
l.sort()


for i in range(n):
    for j in range(i+1,n):
        k=l[i]+l[j]-1
        index = bisect.bisect_right(l,k,lo=j+1)
        count+=index-j-1
        

print(count)
            
            








    




Measured memory_bytes: 43996