akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x) {
    ostringstream sout;
    sout << x;
    return sout.str();
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
template <class T>
inline T max_V(vector<T> &vec) {
    auto maxVal = vec[0];
    for (const auto &i : vec)
        if (i > maxVal) maxVal = i;
    return maxVal;
}
template <class T>
inline size_t max_I(vector<T> &vec) {
    size_t maxIndex = 0;
    for (size_t i = 0; i != vec.size(); ++i)
        if (vec[i] > vec[maxIndex]) maxIndex = i;
    return maxIndex;
}

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
constexpr double EPS = 1e-10;
constexpr double PI = 3.141592653589793;

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

int main() {
    int n, l; cin >> n >> l;
    VI a(n); REP (i, n) cin >> a[i];

    VI wa(n - 1);
    REP(i, n - 1) wa[i] = a[i] + a[i + 1];
    auto max_i = max_I(wa);
    ++max_i;
    --n;

    if (wa[max_i - 1] < l) {
        cout << "Impossible\n";
    }
    else {
        cout << "Possible\n";
        if (max_i >= 2)
            FOR(i, 1, max_i) cout << i << "\n";
        if (n - max_i >= 1)
            for (size_t i = n; i != max_i; --i) cout << i << "\n";
        cout << max_i  << "\n";
    }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rdv(type, v, n) vector<type> v(n); rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) vector<vector<type>>(h, vector<type>(w)) v; rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
typedef long long ll;
void solve();
signed main() {ios::sync_with_stdio(false); cin.tie(0);
  cout << fixed; cout.precision(12); solve(); return 0;}
template<typename T> void prv(vector<T> v) {rep(__ii, 0, sz(v)) {if (__ii) cout << ' '; cout << v[__ii];} cout << '\n';} 
template<typename T> void prm(vector<vector<T>> v) {rep(__ii, 0, sz(v)) {rep(__jj, 0, v[__ii].size()) {if (__jj) cout << ' '; cout << v[__ii][__jj];} cout << '\n';}}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void pr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void pr(const Head& head, const Tail&... tail) {cout << head << ' '; pr(tail...);}
template<typename... T> void err(const T&... cod) {pr(cod...); exit(0);}

void solve() {
  rd(int, n);
  rdv(int, a, n);
  vector<int> ans(n);
  int z = 0;
  rep(i, 0, n) {
    if (i % 2 == 0) z += a[i];
    else z -= a[i];
  }
  ans[0] = z;
  rep(j, 1, n) ans[j] = 2 * (a[j - 1] - ans[j - 1] / 2);
  prv(ans);\
}

Measured memory_bytes: 2560
//
//  main.cpp
//  B
//
//  Created by 黄宇凡 on 2017/5/6.
//  Copyright © 2017年 黄宇凡. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

int N,M;
const int maxn = 1e5 + 5;
int a[maxn],b[maxn];
int deg[maxn];
int vis[maxn];
vector<int> G[maxn];
void dfs(int u){
    vis[u]++;
    for(int i = 0;i < G[u].size();i++){
        int v = G[u][i];
        if(vis[v] < deg[v]){
            dfs(v);
        }
    }
}

int main(int argc, const char * argv[]) {
    cin >> N >> M;
    for(int i = 1;i <= M;i++){
        scanf("%d%d",&a[i],&b[i]);
        deg[a[i]]++,deg[b[i]]++;
    }
    for(int i = 1;i <= N;i++){
        if(deg[i] & 1){
            cout << "NO" << endl;
            return 0;
        }
        deg[i] /= 2;
    }
    
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 3712
N=int(input())
s=[c=="x" for c in input()]
ans = [0]*N
end = False
for c0 in (0,1):
    ans[0] = c0
    for cN in (0,1):
        ans[-1] = cN
        for i,c in enumerate(s[:-2]):
            ans[i+1] = ans[i-1] ^ (ans[i]^c)
        end = (ans[-1]==ans[-3]^(ans[-2]^s[-2])) and (ans[0]==ans[-2]^(ans[-1]^s[-1]))
        if end:break
    if end:break
if end:print("".join(["SW"[a] for a in ans]))
else:print(-1)

Measured memory_bytes: 5532
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
int N,M,x,y;

P sub(P p,P q){
	return P(q.first-p.first,q.second-p.second);
}

bool direction(P p1,P q1,P p2,P q2){
	return sub(p1,q1)==sub(p2,q2);
}

bool same(vector<P> a,vector<P> b){
	if((int)a.size()!=(int)b.size()) return false;
	int n = a.size();
	for(int i=0;i<=4;i++){
		for(int j=0;j<n;j++){
			int x = b[j].first,y = b[j].second;
			b[j] = P(-y,x);
		}
		bool judge = true;
		for(int j=0;j<n-1;j++){
			if(!direction(a[j],a[j+1],b[j],b[j+1])) judge = false;
		}
		if(judge) return true;
		reverse(b.begin(),b.end());
		judge = true;
		for(int j=0;j<n-1;j++){
			if(!direction(a[j],a[j+1],b[j],b[j+1])) judge = false;
		}
		if(judge) return true;
	}
	return false;
}

int main(){
	while(cin >> N && N>0){
		vector<vector<P>> v(N+1);
		for(int i=0;i<=N;i++){
			cin >> M;
			for(int j=0;j<M;j++){
				cin >> x >> y;
				v[i].push_back(P(x,y));			
			}
		}
		for(int i=1;i<=N;i++){
			if(same(v[0],v[i])) cout << i << endl;
		}
		cout << "+++++" << endl;
	}
}


Measured memory_bytes: 3020
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	ll N,M;
	cin >> N >> M;
	ll ans=2;
  	if(abs(N-M) == 1) ans=1;
	if(abs(N-M) >= 2) ans=0; 
	else{
		while(N > 0){
			ans *= N;
          	ans %= MOD;
			N--;
		}
		while(M > 0){
			ans *= M;
          	ans %= MOD;
			M--;
		}
	}
	cout << ans%MOD << endl;
	
	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    class key
    {
        public char word = 'A';
        public char hand = 'A';
    }

    class Program
    {
        static void Main(string[] args)
        {
            string QWERTY = "qwertasdfgzxcvbyuiophjklnm";
            key[] keyboard = new key[26];
            string input;
            char nowhand;
            int result = 0;


            for(int a = 0;a<26;a++)
            {
                keyboard[a] = new key();
                keyboard[a].word = QWERTY[a];
                if(a<15)
                {
                    keyboard[a].hand = 'L';
                }
                else
                {
                    keyboard[a].hand = 'R';
                }
            }

            for(;;)
            {
                input = Console.ReadLine();

                if(input == "#")
                {
                    break;
                }

                result = -1;
                nowhand = 'A';
                

                for(int a = 0;a<input.Length;a++)
                {
                    for(int b = 0;b<26;b++)
                    {
                        if(input[a] == keyboard[b].word)
                        {
                            if(nowhand != keyboard[b].hand)
                            {
                                nowhand = keyboard[b].hand;
                                result++;
                            }
                            break;
                        }
                    }
                }

                Console.WriteLine(result);
            }
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  int a,b;
  cin >> a >> b;
  if(a == 2 && b == 100){
    cout << "1010000";
  }else if(b == 100){
    cout << (int)(b + 1) * pow(100,a);
  }else{
    cout << b;
    for(int i = 0 ; i < a ;i++){
      cout << "00";
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

int sortInsertionG(int *a,size_t n,int g){
  /*gはインターバル*/
  int i,j,temp,cnt=0;
  for (i=g;i<n;i++){
    temp=a[i];
    j=i-g;
    while (j>=0&&a[j]>temp){
      a[j+g]=a[j];
      j-=g;
      cnt++;
    }
    a[j+g]=temp;
  }
  return cnt;
}
int main(){
  int i,cnt=0,n;
  std::cin>>n;
  int m=std::log(2*n+1.0)/std::log(3.0);
  int a[n],g[m];
  for (i=0;i<n;i++)std::cin>>a[i];
  std::cout << m << '\n';
  for (i = 0; i < m; i++)g[i]=(std::pow(3,m-i)-1)/2;
  for (i=0;i<m;i++){
    if (i)std::cout<<' ';
    std::cout<<g[i];
  }
  std::cout << '\n';
  for (i = 0; i < m; i++) {
    cnt+=sortInsertionG(a,n,g[i]);
  }
  std::cout << cnt << '\n';
  for (i = 0; i < n; i++)std::cout << a[i] << '\n';

}



Measured memory_bytes: 7228
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cctype>

#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i,l,n) for(int (i)=(int)(l);(i)<(int)(n);(i)++)
#define d_arr(arr, h, w) rep(i,(h) ){ cout << "["; rep(j,(w) ) { cout << (arr)[i][j] << ", "; } cout << "]" << endl;}

typedef pair<int ,int> P;

/*
1: . , ! ? (スペース)
2: a b c
3: d e f
4: g h i
5: j k l
6: m n o
7: p q r s
8: t u v
9: w x y z
0: 確定ボタン
 */

string a[]   = {".,!? ",
                "abc",
                "def",
                "ghi",
                "jkl",
                "mno",
                "pqrs",
                "tuv",
                "wxyz"};


int main()
{
    int n;
    int index;
    int count=0;
    string s;
    int loop;
    cin >> loop;
    rep(i, loop)
    {
        string s;
        cin >> s;
        rep(j, s.size() )
        {
            string st;
            st[0] = s[j];
            n = atoi( &st[0] );
            if( n == 0 && count == 0) { continue; }
            else if( n == 0 ) 
            { 
                cout << a[index - 1][(count - 1) % a[index - 1].size() ];  
                count = 0;
            }
            else
            {
                index = n;
                count++;
            }
        }
        cout << endl;
    }
    //if ( count > 0 ) { cout << a[index - 1][(count - 1) % 9]; count = 0; }
}

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

const int INF=2000000000; 

int cnt;

void merge(int *A,int l,int mid,int r){
    int n1=mid-l;
    int n2=r-mid;
    int L[n1+1],R[n2+1];
    for(int i=0;i<n1;i++) L[i]=A[l+i];
    for(int i=0;i<n2;i++) R[i]=A[mid +i];
    L[n1]=INF;
    R[n2]=INF;
    int i=0,j=0;
    for(int k=l;k<r;k++){
        cnt++;
        if(L[i]<=R[j]) A[k]=L[i++];
        else A[k]=R[j++];
    }
}

void mergesort(int *A,int l,int r){
    if(l+1<r){
        int mid=(l+r)/2;
        mergesort(A,l,mid);
        mergesort(A,mid,r);
        merge(A,l,mid,r);
    }
}

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    mergesort(a,0,n);
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i!=n-1)cout<<' ';
        else cout<<endl;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 7028
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class Main {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int m=scan.nextInt();
            int[] arr=new int[n];
            boolean[] ans=new boolean[n];
            for(int i=0;i<n;i++){
                arr[i]=scan.nextInt();
            }
            for(int i=0;i<m;i++){
                int u=scan.nextInt()-1;
                int v=scan.nextInt()-1;
                if(arr[u]<=arr[v]){
                    ans[u]=true;
                }if(arr[v]<=arr[u]){
                    ans[v]=true;
                }
            }
            int v=0;
            for(int i=0;i<n;i++){
                if(!ans[i]){
                    v++;
                }
            }
            out.println(v);
        }
        out.flush();
        out.close();
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

}


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

int main() {
  int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++) cin>>L[i];
  sort(L.begin(),L.end());
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      for(int k=j+1;k<N;k++){
        if(L[i]+L[j]>L[k]) ans++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long int ll;
using namespace std;
vector<vector<int> > edge;
vector<bool> visit;

void dfs(int v) {
    if(visit[v]) return;
    visit[v] = true;
    for(int i=0; i<edge[v].size(); ++i) {
        dfs(edge[v][i]);
    }
}

int main(void) {
    int N, M;
    int K, L;
    cin >> N >> M;
    edge.resize(N+M);
    REP(i, N) {
        cin >> K;
        edge[i].resize(K);
        REP(j, K) {
            cin >> L;
            L = N+L-1;
            edge[i][j] = L;
            edge[L].push_back(i);
        }
    }
    visit.resize(N+M);
    dfs(0);
    REP(i, N) {
        if(!visit[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 8440
#define N 100

#include <stdio.h>

int main(){
  int i,j,key,A[N],n;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }  
  
  for(i=1;i<n;i++){

    for(j=0;j<n;j++){
      printf("%d",A[j]);
      if(j!=n-1) printf(" ");
    }
    printf("\n");
    
    key=A[i];
    j=i-1;
    
    while(j>=0 && A[j]>key){
      A[j+1]=A[j];
      j--;
      A[j+1]=key;
    }

  }
  
  for(j=0;j<n;j++){
    printf("%d",A[j]);
    if(j!=n-1) printf(" ");
  }
  printf("\n");  
  
}
    
    



Measured memory_bytes: 2068
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

char m[6][7];
int main(void){
	int h=nextint();
	int w=nextint();
	int k=nextint();
	for(int i=0; i<h; i++){
		nextstr(m[i]);
	}
	int ans=0;
	for(int ki=0; ki<(1<<h); ki++){
		for(int kj=0; kj<(1<<w); kj++){
			int s=0;
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					if(m[i][j]=='#' && (ki&(1<<i))==0 && (kj&(1<<j))==0) s++;
				}
			}
			if(s==k) ans++;
		}
	}
	printf("%d\n", ans);
}


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

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

    for(int i=1; i <= N; i++) {
        if(i % 3 == 0) {
            cout << " " << i;
            continue;
        }
        if(i % 10 == 3) {
            cout << " " << i;
            continue;
        }
        tmp = i;
        while(tmp / 10 != 0) {
            if(((tmp / 10) % 10) == 3) {
                cout << " " << i;
                break;
            }
            tmp /= 10;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3084
#include <iostream>

using namespace std;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    int cnt = 0;
    for (int i = 0; i <= 100; i++) {
        if (A <= i && i < B && C <= i && i < D) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 8)

n, m = map(int, input().split())
MOD = 1000000007

traps = {}
for i in range(m):
    t = int(input())
    traps[t] = 1

mem = {}

def f(k):
    if k in mem:
        return mem[k]

    if k >= n:
        return 0
    if k == n - 1:
        return 1
    if k == n - 2:
        if n - 1 in traps:
            return 1
        else:
            return 2

    res = 0
    if k + 1 not in traps:
        res += f(k + 1)
    if k + 2 not in traps:
        res += f(k + 2)
    mem[k] = res

    return res % MOD

print(f(0))

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

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;

 #define rep(i, a, b) for (int i=a; i<(b); i++)
    
 #define sz(x) (int)(x).size()
 #define mp make_pair
 #define pb push_back
 #define f first
 #define s second
 #define lb lower_bound
 #define ub upper_bound
 #define all(x) x.begin(), x.end()
 

 #define trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
 #define PI 3.14159265358979323846264338327950L
const int MOD = 1000000007;
const char nl = '\n';
 
int main() 
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll x,k,d;cin>>x>>k>>d;

    ll res = x%d;

    if(k>=(abs(x-res)/d))
    {
        k-=(abs(x-res)/d);

        if(k%2 == 0)
        {
            cout<<abs(res);
        }
        else cout<<abs(abs(res)-d);
    }
    else
    {
        cout<<min(abs(x-k*d),abs(x+k*d));
    }

}


Measured memory_bytes: 3640
from collections import deque

n = int(input())
graph = [[] for _ in range(n)]
for i in range(n):
    graph[i] += list(map(lambda x: x - 1, list(map(int, input().split()))[2:]))

visited = [-1] * n
que = deque()
# 頂点0を入れておく
que.append(0)
visited[0] = 0
cnt = 0

while que:
    v = que.popleft()
    for nv in graph[v]:
        if not visited[nv] == -1:
            continue
        visited[nv] = visited[v] + 1
        que.append(nv)

for v, d in enumerate(visited, 1):
    print(v, d)


Measured memory_bytes: 6036
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
ll n,k,a[102];
ll dp[102][100002];
ll noofcandies(ll ind,ll can)
{
	if(can==0)
		return 1;
	else if(ind==-1 || can<0)
	{
		return 0;
	}
	if(dp[ind][can]!=-1)
		return dp[ind][can];
	ll ans=0;
	// for (int i = 0; i <=min(a[ind],can) ; ++i)
	// {
	// 	ans=ans%M+noofcandies(ind-1,can-i)%M;
	// 	ans=ans%M;
	// }
	ans=ans%M+(noofcandies(ind-1,can)%M-noofcandies(ind-1,can-a[ind]-1)%M+M)%M;
	ans=ans%M+noofcandies(ind,can-1)%M;
	ans=ans%M;
	dp[ind][can]=ans;
	return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    for (int i = 0; i <=100; ++i)
    {
    	for (int j = 0; j <=100000 ; ++j)
    	{
    		dp[i][j]=-1;
    	}
    }
    cout<<noofcandies(n-1,k)<<'\n';

}


Measured memory_bytes: 83840
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int length = scanner.nextInt();
        String inputString = scanner.next();
        int counter = 0;
        int index = 0;
        while (index != -1) {
            index = inputString.indexOf("ABC", index);
            if (index != -1) {
                counter++;
                index++;
            }
        }
        System.out.println(counter);
    }
}


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

using namespace std;
int main()
{
    int n;
    cin>>n;

    vector<int> v;

    int tmp;
    for(int i=0; i<n; i++)
    {
        cin>>tmp;

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

    }

    return 0;
}


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int Q,a,b,s[100001],t[100001];
int f(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return 0;
    }
    t[n]=1;
    if(t[(n+1)/2]==1)return 1;
    else return 0;
}
int main(void){
    cin>>Q;
    t[2]=1;
    for(int i=3;i<=100000;i+=2){
        s[i]=f(i);
    }
    for(int i=0;i<100000;i++){
        s[i+1]+=s[i];
    }
    while(Q--){
        cin>>a>>b;
        cout<<s[b]-s[a-1]<<endl;
    }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


int main(int argc, char const *argv[])
{
	int a, b; cin >> a >> b;
	if (b % a == 0) printf("%d\n", a + b);
	else printf("%d\n", b - a);
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 1e5 + 5;

typedef long long ll;

int n, x;

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

      for(int i = 0; i <= n; i ++){
            for(int j = 0; j + i <= n; j ++){
                  int k = n - (j + i);
                  int sum = i * 10000 + j * 5000 + k * 1000;
                  if(sum == x){
                        cout << i << " " << j << " " << k << endl;
                        return 0;
                  }
            }
      }

      cout << "-1 -1 -1";
}


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

int main() {
  string N;
  cin >> N;
  if(N[0]==N[1]&&N[1]==N[2]){
    cout << "Yes" << endl;
  }
  else if(N[1]==N[2]&&N[2]==N[3]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
S = list(input())
str = 'abcdefghijklmnopqrstuvwxyz'
ans = list('abcdefghijklmnopqrstuvwxyz')
for s in str:
  if (s in S):
    ans.remove(s)

ans.sort()
if len(ans) == 0:
  print('None')
else:
  print(ans[0])


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main(){

	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<fixed<<setprecision(6)<<(a*b)/2.0<<" ";
	if(a%2==0&&a/2==c&&b%2==0&&b/2==d){
		cout<<1<<endl;
	}
	else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int h = x/3600;
		int m = x%3600/60;
		int s = x%60;

		System.out.println(h + ":" + m + ":" + s);

		sc.close();
	}
}


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

int main() {
	int n, m;
	cin >> n >> m;
	int tage[100], tokuten[100];
	for (int i = 0; i < m; i++) {
		cin >> tage[i];
	}

	for (int i = 0; i < n; i++) {
		tokuten[i] = 0;
	}

	for (int j = 0; j < m; j++) {
		for (int i = 0; i < n; i++) {
			int simei;
			cin >> simei;
			if (simei == tage[j]) {
				tokuten[i]++;
			} else {
				tokuten[tage[j]-1]++;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << tokuten[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
/*
 *  Author: mizo0203
 *  Problem: 0001
 *  Status: Accepted
 *  Submission Date: 2012/04/15 01:49:02
 *
 *  方策：クイックソートを行う．
 *  C言語の標準ライブラリ<stdlib.h>にもqsort()という
 *  クイックソートを行う関数があるが，扱いにくいためC++の
 *  標準ライブラリ<algorithm>のsort()を使用する．
 */
#include <stdio.h>
#include <algorithm> // sort()を使うのに必要

// C++のライブラリを使用するのに必要
using namespace std;

int h[10];

void input() {
  int i;

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

int main() {
  int i;

  input();
  sort(h, h + 10);
  for (i = 0; i < 3; i++)
    printf("%d\n", h[9 - i]);

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

unordered_map<int, int> s;
int a[200010];
int n, x;

inline void work() {
    cin >> n;
    LL ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ans += s[a[i]]++;
    }
    for (int i = 0; i < n; ++i) {
        cout << ans - s[a[i]] + 1 << "\n";
    }
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 7932
MOD = 10 ** 9 + 7
N, K, *A = map(int, open(0).read().split())
A.sort()

fact = [1, 1]
fact_inv = [1, 1]
inv = [0, 1]
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    fact_inv.append((fact_inv[-1] * inv[-1]) % MOD)


def cmb(n, r):
    if r < 0 or n < r:
        return 0
    r = min(r, n - r)
    return fact[n] * fact_inv[r] * fact_inv[n - r] % MOD


def solve():
    ans = 0
    for i in range(N):
        num = cmb(i, K - 1) % MOD
        ans += num * A[i] % MOD
        ans -= num * A[N - i - 1] % MOD
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 19180
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

right = 0
left = 0
for i in range(X, N+1):
    if i in A:
        right += 1

for i in range(X, 0, -1):
    if i in A:
        left += 1

print(min(left, right))

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

int main(){
	int a,b,c;
	int ans;
	bool flg;
	int cnt=0;
	
	while(cin>>a>>b){
		cnt++;flg=false;
		//-----test-----
		if(cnt==150) break;
		//--------------
		c=a+b;
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define F first
#define S second
#define INF 3000000000
#define inf -10000000
#define pb push_back
#define forr(i,p,n) for(int i=p;i<n;i++)
#define mpk make_pair
#define upb(a,s) upper_bound(a.begin(),a.end(),s)
#define lwb(a,s) lower_bound(a.begin(),a.end(),s)
#define D(x) cout << #x " = " << (x) << endl
#define mem(a,val) memset(a,val,sizeof a)
#define ulti(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" "
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
//priority_queue<ll> pq;
string s,s1;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie();
    ll a,b,c,d,n,t,m,k;
    while(cin>>a>>b){
      if(a<b){
	forr(i,0,b){
	  cout<<a;
	}
	cout<<endl;
      }
      else{
	forr(i,0,a){
	  cout<<b;
	}
	cout<<endl;
      }
    }
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b;
  rep(i, n) cin >> a[i];
  for(int i = n-1; i >=0; i-=2) {
    b.push_back(a[i]);
  }
  if (n % 2) {
    for(int i = 1; i < n; i+=2) {
      b.push_back(a[i]);
    }
  } else {
    for(int i = 0; i < n; i+=2) {
      b.push_back(a[i]);
    }
  }
  rep(i,n) {
    printf("%lld%c", b[i], (i == n-1)?'\n':' ');
  }
  return 0;
}


Measured memory_bytes: 5488
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main(){
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];

	int min_jumps[max(n,k)];
	min_jumps[0] = 0;
    for(int i = 1;i<k;i++)
	    min_jumps[i] = abs(arr[0]-arr[i]);
	for(int i=k;i<n;i++){
		min_jumps[i] = INT_MAX;
		// cout << min_jumps[i] << " " << i << " " << abs(arr[i]-arr[i-1])+min_jumps[i-1] << endl;
		for(int j=1; j<=k; j++){
            if(min_jumps[i] > abs(arr[i]-arr[i-j])+min_jumps[i-j])
                min_jumps[i] = abs(arr[i]-arr[i-j])+min_jumps[i-j];
        }

	}
	// for(int i =0; i<n;i++)
	cout << min_jumps[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>

const int MN = 100005;

int N, M;
std::vector<int> G[MN];
int vis[MN], A[MN], B[MN], C, D;

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1, x, y; i <= M; ++i) {
		scanf("%d%d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	A[C = 1] = 1;
	B[D = 1] = 1;
	vis[1] = 1;
	while (1) {
		int u = A[C], w = 0;
		for (int v : G[u]) if (!vis[v]) w = v;
		if (!w) break;
		vis[w] = 1, A[++C] = w;
	}
	while (1) {
		int u = B[D], w = 0;
		for (int v : G[u]) if (!vis[v]) w = v;
		if (!w) break;
		vis[w] = 1, B[++D] = w;
	}
	printf("%d\n", C + D - 1);
	for (int i = C; i >= 2; --i) printf("%d ", A[i]);
	for (int i = 1; i <= D; ++i) printf("%d%c", B[i], " \n"[i == D]);
	return 0;
}

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

int main(){
  string s;
  int k;
  cin >> s >> k;
  for(int i = 0;i < k;i++){
    if(s[i] != '1' ){
      cout << s[i] << endl;
      return 0;
    }
  }

  cout << 1 << endl;

  return 0;
}



Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<vector<int>> d(c, vector<int>(c));
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> d[i][j];
		}
	}

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

	vector<vector<int>> cost(3, vector<int>(c));
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				cost[(j+k) % 3][i] += d[a[j][k]][i];
			}
		}
	}

	int res = INF;
	for (int c1 = 0; c1 < c; c1++) {
		for (int c2 = 0; c2 < c; c2++) {
			for (int c3 = 0; c3 < c; c3++) {
				if (c1==c2 || c2==c3||c1==c3)continue;
				int cnt = 0;

				cnt += cost[0][c1];
				cnt += cost[1][c2];
				cnt += cost[2][c3];

				res = min(res, cnt);
			}

		}

	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,strt,end) for(long long i = strt;i < end;i++)


int main(){
    string s,t;
    cin >> s >> t;
    string fS = t.substr(0,s.length());
    int a = s.length() + 1;
    int b = t.length();
    if(fS == s && a == b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    //--------------
    return 0;
}

Measured memory_bytes: 3628
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var N = input[0];
  	var i = 1;
  	var j = 0;
  	while(i <= N){
      	if(tmp[i - 1] != i){
        	j = j + 1; 
        }
    	i = i + 1; 
    }
  	if(j <= 2){
    	var s = "YES";
    } else var s = "NO";
	console.log('%s',s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int mod=1e9+7;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

inline int fpow(int x,int t){
	int ans=1;
	for(; t; x=(lint)x*x%mod,t>>=1){
		if(t&1) ans=(lint)ans*x%mod;
	}
	return ans;
}

int main(){
	int q=nxi(),ans=0;
	for(int i=1,j=0,cc=1,cf=10,ci=1,fi=10,sum=0; i<1e8; (++i==fi)?++ci,fi*=10:0){
		while(sum<q){
			if(++j==cf) ++cc,cf*=10;
			sum+=cc;
		}
		ans+=sum==q;
		sum-=ci;
	}
	for(int i=9; i<=q; ++i){
		if(q%i>=q/i) continue;
		if(q%i==0){
			ans=(ans+fpow(10,i)-fpow(10,i-1)-q/i+1)%mod;
			ans=(ans-1)%mod;
		}
		//printf("%d: %d\n",i,(q/i-q%i-1)/(i+1)+1);
		ans=(ans+(q/i-q%i-1)/(i+1)+1)%mod;
	}
	printf("%d\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define n 300000
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
struct edge{
	int to, weight;
};
void solve();
int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}
vector<edge> V[n + 50];
int a, b, c, d, e, f;
int arr[n + 50], arr1[n + 50], arr2[n + 50];
string str, str1, str2;

void solve()
{
	int arr[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	cin >> a >> b;
	if(b == arr[a]) cout << "1";
	else			cout << "0";
}


Measured memory_bytes: 8704
#include <stdio.h>
#include <algorithm>

using namespace std;

typedef long long lint;
typedef pair<lint, int> pli;

#define MAXN 200005

const lint LINF = 1e9;
lint X[MAXN], Y[MAXN];
pli d[2 * MAXN];
int cnt[MAXN];
int col;

int main() {
	int N;
	lint ans;

	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%lld%lld", X + i, Y + i);

	lint rmn = LINF, rmx = 0, bmn = LINF, bmx = 0;
	for(int i = 0; i < N; i++) {
		if(X[i] > Y[i]) swap(X[i], Y[i]);
		rmn = min(rmn, X[i]);
		rmx = max(rmx, X[i]);
		bmn = min(bmn, Y[i]);
		bmx = max(bmx, Y[i]);
	}
	ans = (rmx - rmn) * (bmx - bmn);
	for(int i = 0; i < N; i++) {
		d[i * 2] = make_pair(X[i], i);
		d[i * 2 + 1] = make_pair(Y[i], i);
	}

	sort(d, d + 2 * N);
	int s = 0, e = 0;
	while(true) {
		while(e < 2 * N && col < N)
			if(cnt[d[e++].second]++ == 0) col++;
		if(col < N) break;
		//printf("s = %d, e = %d\n", s, e);
		ans = min((d[N * 2- 1].first - d[0].first) * (d[e - 1].first - d[s].first), ans);
		if(cnt[d[s++].second]-- == 1) col--;
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N; ll sum=0;
    int A[N]; rep(i,N) {cin >> A[i]; sum+=A[i];}
    sort(A,A+N);
    cout << A[0] <<" "<< A[N-1] <<" "<< sum << endl;


    return 0;
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 1e6 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
 
void solve(){
    int n, m;
    cin >> n >> m;
    ll sum = 0;
    for(int i = 1; i <= m; ++i) {
        ll x;
        cin >> x;
        sum += x;
    }
    cout << max(-1ll, n - sum);
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 3652
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;
            int[] s = new int[n];
            int min=100000,MAX=0,sum=0,ave=0;
            for(int i=0;i<n;i++){
                s[i] = sc.nextInt();
                if(min>s[i])min = s[i];
                if(MAX<s[i])MAX = s[i];
                sum+=s[i];
            }
            ave = (sum - min - MAX) / (n-2);
            System.out.println(ave);
        }
    }
}



Measured memory_bytes: 28432
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
    }
    let mut i = 1;
    while i * i <= n {
        i +=1;
    }
    println!("{}", (i - 1) * (i - 1));
}

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

typedef long long ll;
typedef vector<int> vi;

#define PB push_back
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    optimize();
    int n,cnt=0;
    cin>>n;
    int arr[n][2];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i][0]>>arr[i][1];
    }
    for(int i=0;i<n;i++)
    {
        if(arr[i][0] == arr[i][1])
        {
            cnt++;
        }
        else
        {
            if(cnt>=3)
                break;
            else
                cnt=0;
        }
    }
    if(cnt>=3)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3648
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
void scan(Args...)(ref Args args) {
    string[] ss = readln.split;
    foreach (i, ref arg ; args)
        arg = ss[i].parse!int;
}


uint MOD = 10^^9 + 7;
pragma(inline)
long mul(long x, long y) {
    return (x * (y % MOD)) % MOD;
}

long[] f;
void make_table(int n) {
    f = new long[n+1];
    f[0] = f[1] = 1;
    foreach (i ; 2..n+1)
        f[i] = mul(i, f[i-1]);
}

long powmod(S,T,U)(S x, T n, U MOD) {
    long r = 1;
    while (n>0) {
        if (n&1) r = mul(r, x);
        x = mul(x,x);
        n >>= 1;
    }
    return r;
}

long mod_inv(ulong x) {
    return powmod(x, MOD - 2, MOD);
}

long comb(long n, long r) {
    if (n - r < 0 || n < 0 || r < 0) return 0;
    return mul(mul(f[n], f[r].mod_inv), f[n - r].mod_inv);
}

void main() {
    int n, k;
    scan(n, k);
    make_table(2010);
    foreach (i; 1..k+1) {
        long x = mul(comb(n-k+1, i), comb(k-1, i-1));
        writeln(x);
    }
}


Measured memory_bytes: 256
def c_Otoshidama_N(N, Y):
    yen = Y // 1000
    # yukichi,higuchi,noguchiはそれぞれ、1万円札、5千円札、千円札の枚数(モデルの名字)
    for yukichi in range(0, 2001):
        # 10*yukichi + 5*higuchi + noguchi = yen と
        # yukichi + higuchi + noguchi = N について、yukichiを決めたときの連立方程式の解
        tmp1 = (yen - N - 9 * yukichi)
        tmp2 = (5 * N - yen + 5 * yukichi)
        if tmp1 % 4 == 0 and tmp2 % 4 == 0:
            higuchi = tmp1 // 4
            noguchi = tmp2 // 4
            if higuchi >= 0 and noguchi >= 0:
                return '{} {} {}'.format(yukichi, higuchi, noguchi)
    # どの組み合わせでも条件を満たさなかった
    return '-1 -1 -1'

N,Y=[int(i) for i in input().split()]
print(c_Otoshidama_N(N, Y))

Measured memory_bytes: 3060
s = list(input())

s1 = s[:len(s)//2]
s2 = s[-(-len(s)//2):][::-1]

cnt = 0
for i in range(len(s1)):
    if s1[i] != s2[i]:
        s1[i] = s2[i]
        cnt += 1

print(cnt)

Measured memory_bytes: 9112
f(x){scanf("%d",x);}a[100],l,r,p,n;main(c){for(;f(&r),l=r;printf("%d\n",c)){for(;c=l;)f(a+--l);for(f(&n);l<r&&!++c|a[p=l+r>>1]-n;)a[p]<n?r=p:(l=p+1);}exit(0);}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

var a, b, c, d, e, f int
var x, y int
var maxNoudo float64 = -1.0
var dp [][]bool = make([][]bool, 3000)

func dfs(A, B int) {
	tot := A + B
	if tot > f {
		return
	}
	if dp[A][B] {
		return
	}
	dp[A][B] = true

	var noudo float64 = float64(100*B) / float64(tot)
	if noudo > maxNoudo {
		maxNoudo = noudo
		x, y = A, B
	}

	dfs(A+100*a, B)
	dfs(A+100*b, B)
	if A*e >= 100*(B+c) {
		dfs(A, B+c)
	}
	if A*e >= 100*(B+d) {
		dfs(A, B+d)
	}
	return
}

func __init() {
	for i := range dp {
		dp[i] = make([]bool, 3000)
	}
}

func main() {
	fmt.Scan(&a, &b, &c, &d, &e, &f)
	__init()
	dfs(0, 0)
	fmt.Println(x+y, y)
}

Measured memory_bytes: 10624