akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string S;
ll ans = 0;

int main() {
	cin >> S;
	rep(i, (sz(S) + 1) / 2) {
		if (S[i] != S[sz(S) - 1 - i])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    string s, t;
    int z = 1003;
    cin >> s >> t;
    for (int i = 0; i <= (int)s.length() - (int)t.length(); i++) {
        int c = 0;
        for (int j = 0; j < t.length(); j++) if (t[j] != s[j + i]) c++;
        z = min(z, c);
    }
    cout << z;
}


Measured memory_bytes: 3656
use std::cmp;

fn main(){
  let vt: Vec<usize> = read_vec();
  let a = vt[0];
  let b = vt[1];
  let c = vt[2];
  let d = vt[3];
  let e = vt[4];
  let f = vt[5];

  let mut vs: Vec<usize> = vec![0; 3000];

  for i in c .. 3000 {
    vs[i] = c + vs[i-c];
  }

  for i in d .. 3000 {
    vs[i] = cmp::max(vs[i], vs[i-d] + d);
  }

  let mut i: usize = 0;
  let mut j: usize = 1;
  let mut mw: usize = 100 * a;
  let mut ms: usize = 0;

  while 100 * a * i <= f {
    while 100 * a * i + 100 * b * j <= f {
      let w = 100 * a * i + 100 * b * j;
      let s = vs[cmp::min(e * w / 100, f - w)];
      if ms * (w + s) < s * (mw + ms) {
        ms = s;
        mw = w;
      }
      j += 1;
    }
    i += 1;
    j = 0;
  }
  
  println!("{} {}", ms + mw, ms);
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
#include <ctime>
#include <bitset>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 99824353 //1000000007
#define N 200005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;}
template<typename U> U gcd(U a, U b){
    if(a == 0)return b;
    if(b == 0)return a;
    if(a >= b)return gcd(a % b, b);
    else return gcd(a, b % a);
}
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}
int pow(int a, ll b, int c){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % c;
        a = 1LL * a * a % c;
        b >>= 1;
    }
    return ans;
}

unordered_map<ll, ll> dp;
int a[3] = {2, 3, 5}, b[4];
const ll INF = 1e18;
ll solve(ll n){
  if(n == 1)return 0;
  if(dp.count(n))return dp[n];
  ll ret = INF;
  if (n-1 <= ret / b[3]) Min(ret, (n-1) * b[3]);
  rep(i, -4, 5) {
    ll m = n + i;
    if(m <= 0)continue;
    rep(j, 0, 3) {
      if (m % a[j] == 0 && m / a[j] < n) Min(ret, 1LL * abs(i) * b[3] + solve(m/a[j]) + b[j]); 
    }
  }
  return dp[n] = ret;
}
int main() {
  int ca = 0, T, i, j, k, m, K;
  scanf("%d", &T);
  ll n;
  while(T--){
    scanf("%lld", &n);
    rep(i, 0, 4)scanf("%d", &b[i]);
    dp.clear();
    ll ans = solve(n) + b[3];
    rep(i, 1, 5) {
      Min(ans, solve(n + i) + b[3] + 1LL * i * b[3]);  
    }
    printf("%lld\n", ans);
  }
}


Measured memory_bytes: 5180
#include <iostream>
#define ll long long
using namespace std;

int main() {
    ll a, b, c, d;
    cin >> a ;
    if(a%100 <= 12 && a%100 > 0 && a / 100 <= 12 && a / 100 > 0) cout << "AMBIGUOUS" << endl;
    else if(a%100 <= 12 && a%100 > 0) cout << "YYMM" << endl;
    else if(a/100 <= 12 && a / 100 > 0) cout << "MMYY" << endl;
    else cout << "NA" << endl;
    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int total_h = h2 - h1, total_m = m2 - m1;
	total_m += (total_h * 60);
	total_m -= k;
	cout << total_m << '\n';
	
	return 0;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
	int N;
	cin>>N;
	vector<int>A(N);
	vector<int>B(N);
	int ans=0;
	for(int i=0;i<N;i++)cin>>A[i]>>B[i];
	rev(i,N){
		A[i]+=ans;
		if(A[i]%B[i]==0)continue;
		ans+=B[i]-A[i]%B[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4848
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;

#define MAX 256

int f(int z){
	if (z < 10)return 1;
	return 1 + f(z / 10);
}

int main(void){
	
	int ans[200];
	for (long i = 0; i < 200; i++){
		ans[i] = 0;
	}

	long a, b;
	long i = 0;

	while (scanf("%ld%ld", &a, &b) != EOF){
		ans[i] = f(a + b);
		i++;
	}

	for (int j = 0; j < i; j++){
		printf("%d\n", ans[j]);
	}

	return 0;
}

Measured memory_bytes: 3080
#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++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

ll a, b, c;

int main(){
    L(a,b,c);
    ll ans = 0;
    for(int i = 0; i < 10000000; i++){
        if(a%2==1||b%2==1||c%2==1){
            cout << ans << endl;
            return 0;
        }
        ll x = a, y = b, z = c;
        a = (y+z)/2;
        b = (x+z)/2;
        c = (x+y)/2;
        ans++;
    }
    cout << -1 << endl;
}
































Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    cout << 1.0*w*h/2.0 << endl;
    if (2*x==w&&2*y==h)
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
S=input()
T=input()
N=len(S)
n=len(T)
ans=[]
for i in range(N-n+1):
    for j in range(n):
        if S[i+j]!=T[j] and S[i+j]!='?':
            break
    else:
        s=[]
        for j in range(i):
            if S[j]=='?':
                s.append('a')
            else:
                s.append(S[j])
        for j in range(i,i+n):
            s.append(T[j-i])
        for j in range(i+n,N):
            if S[j]=='?':
                s.append('a')
            else:
                s.append(S[j])
        ans.append(''.join(s))

if len(ans)==0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])


Measured memory_bytes: 9096
#include <stdio.h>

int compose(int n, int m)
{
    int i, fenzi=1, fenmu=1;

    if( n>=m )
    {
         for(i=0; i<m; i++)
        {
            fenzi *= n-i;
            fenmu *= i+1;
        }
        return fenzi/fenmu;
    }
    else
        return 0;
}
int main(void)
{
    int n, m;

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

    printf("%d", compose(n, 2)+compose(m, 2));

    return 0;
}


Measured memory_bytes: 128
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
import collections, heapq, itertools, bisect
import math, fractions
import sys, copy

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline().rstrip())
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline().rstrip())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()
    S = [input() for _ in range(N)]
    print(f'AC x {S.count("AC")}')
    print(f'WA x {S.count("WA")}')
    print(f'TLE x {S.count("TLE")}')
    print(f'RE x {S.count("RE")}')


if __name__ == '__main__':
    main()

Measured memory_bytes: 83500
//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;

//#define pb push_back
//#define mp make_pair
//
//#define F first
//#define S second

typedef long long ll;

#define rept(_i,iv,n,type) for(type _i=(type)(iv);_i<(type)(n);++_i)
//#define repi(_i,iv,n) rept(_i,iv,n,int)
//#define repl(_i,iv,n) rept(_i,iv,n,ll)

#define rept0(_i,n,type) rept(_i,0,n,type)
#define repi0(_i,n) rept(_i,0,n,int)
#define repl0(_i,n) rept(_i,0,n,ll)

//#define repst(_i,iv,n,type) for(type _i=iv;_i<=(type)(n);++_i)
//#define repsi1(_i,n) repst(_i,1,n,int)

#define REPT(_i,iv,_l,n,type) for(type _i=(type)(iv),_l=(type)(n);_i<_l;++_i)
//#define REPI(_i,iv,_l,n) REPT(_i,iv,_l,n,int)
//#define REPL(_i,iv,_l,n) REPT(_i,iv,_l,n,ll)
//
#define REPT0(_i,_l,n,type) REPT(_i,0,_l,n,type)
#define REPI0(_i,_l,n) REPT(_i,0,_l,n,int)
#define REPL0(_i,_l,n) REPT(_i,0,_l,n,ll)


//#define rrept(_i,x,e,type) for(type _i=((type)(x)-1);_i>=e;--_i)
//
//#define rrept0(_i,x,type) rrept(_i,x,0,type)
//
//#define RREPT(_i,x,_e,e,type) for(type _i=((type)(x)-1),_e=(type)(e);_i>=_e;--_i)
//
//#define RREPT0(_i,x,_e,type) RREPT(_i,x,_e,0,type)
//
//#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;


//typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef vector<ll> vll;
//typedef vector<vll > vvll;

#define mod99 998244353

int main(int argc, const char * argv[]) {
    int N,M;
    cin>>N>>M;
    vi a(N,-1);
    bool noFlg=false;
    repi0(i, M){
        int s,c;
        cin>>s>>c;
        if(noFlg){
            continue;
        }
        --s;
        if(a[s]==-1){
            if(s==0&&N!=1&&c==0){
                noFlg=true;
            }
            a[s]=c;
        }else{
            if(a[s]!=c){
                noFlg=true;
            }
        }
    }
    if(noFlg){
        cout<<-1<<endl;
    }else{
        int ans=0;
        for(int i=0;i<N;++i){
            ans*=10;
            if(a[i]==-1){
                if(i==0&&N!=1){
                    ans+=1;
                }
            }else{
                ans+=a[i];
            }
        }
        cout<<ans<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
#define MAXN 100010
#define ll long long
using namespace std;

struct Trie{
	int id[2];
	int t;
	Trie(){
		id[0] = id[1] = -1;
		t = 0;
	}
} trie[MAXN];
int k = 1;
ll L;
ll ans = 0;

void add(int t){
	if(t > L) return ;
	ll x = L - t + 1;
	//cout << x << " : ";
	for(int j = 60; j >= 0; j--){
		if((1LL << j) > x)
			continue;
		if((1LL << j) == x)
		{
			ans ^= (1LL << (j));
			//cout << (1LL << (j)) << "\n";
			return;
		}
		else x -= (1LL << j);
	}
}
void dfs(int u){
	if(trie[u].id[0] == -1){
		add(trie[u].t+1);
	}
	else dfs(trie[u].id[0]);
	
	if(trie[u].id[1] == -1){
		add(trie[u].t+1);
	}
	else dfs(trie[u].id[1]);
}

int val[MAXN];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	/*
	val[0] = 0;
	for(int i = 1; i < 60; i++){
		set<int> mex;
		mex.insert(0);
		int xo = 0;
		for(int j = i-1; j >= 1; j--){
			xo ^= val[j];
			mex.insert(xo);
		}
		int l;
		for(l = 0; mex.count(l) != 0; l++);
		val[i] = l;
		cout << "val[" << i << "] = " << val[i] << "\n";
	}
	*/
	int N;
	cin >> N >> L;
	string s;
	for(int i =0; i < N; i++){
		cin >> s;
		int pos = 0;
		for(int j = 0; j < s.size(); j++){
			if(trie[pos].id[s[j] - '0'] == -1){
				trie[pos].id[s[j] - '0'] = k++;
				trie[k-1].t = trie[pos].t + 1;
			}
			pos = trie[pos].id[s[j] - '0'];
		}
	}

	dfs(0);
	if(ans) cout << "Alice\n";
	else cout << "Bob\n";
	return 0;
}

Measured memory_bytes: 2384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 200005
#define M 1000005
int read(){
    int w=0,f=1;
    char c=' ';
    while(c<'0'||c>'9')c=getchar(),f=c=='-'?-1:f;
    while(c>='0'&&c<='9')w=w*10+c-48,c=getchar();
    return w*f;
}
const int mod=998244353;
int pown(int a,int b){
    int res=1,ans=a%mod;
    while(b){
        if(b&1)res=res*ans%mod;
        ans=ans*ans%mod;
        b>>=1;
    }
    return res;
}
int n,q,pri[M],mu[M],w[M],cnt,a[N],g[M],inv[M],ans;
bool vis[M];
void work(int x,int y){
    ans=(ans-g[x]*g[x]%mod*w[x])%mod;
    g[x]=(g[x]+y)%mod;
    ans=(ans+g[x]*g[x]%mod*w[x])%mod;
}
void calc(int x,int y){
    int t=sqrt(x);
    for(int i=1;i<=t;i++)
        if(x%i==0){
            work(i,x*y);
            if(x/i!=i)work(x/i,x*y);
        }
}
void init(){
    mu[1]=1;
    for(int i=2;i<M;i++){
        if(!vis[i])pri[++cnt]=i,mu[i]=-1;
        for(int j=1;j<=cnt&&i*pri[j]<M;j++){
            vis[i*pri[j]]=1;
            if(i%pri[j])mu[i*pri[j]]=-mu[i];
            else{
                mu[i*pri[j]]=0;
                break;
            }
        }
    }
    for(int i=1;i<M;i++)
        inv[i]=pown(i,mod-2);
    for(int i=1;i<M;i++)
        for(int j=1;i*j<M;j++)
            w[i*j]=(w[i*j]+mu[i]*inv[j])%mod;
}
signed main(){
    n=read();
    for(int i=1;i<=n;i++)
        a[i]=read();
    init();
    for(int i=1;i<=n;i++)
        calc(a[i],1);
    for(int i=1;i<=n;i++)
    	ans=(ans-a[i])%mod;
    printf("%lld\n",(ans*inv[2]%mod+mod)%mod);
    return 0;
}

Measured memory_bytes: 38032
N = int(input())
S = [0]*N
for i in range(N):
    S[i] = input()

from collections import defaultdict
 
counter = defaultdict(int)
 
for x in S:
    counter[x] += 1

X = max(counter.values())
s = set(S)
ans=[]
for i in s:
    if counter[i] == X:
        ans.append(i)

for i in sorted(ans):
    print(i)

Measured memory_bytes: 47072
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e9;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}
long long digits(long long m) {
    long long cnt = 0;
    while (m) {
        cnt++;
        m /= 10;
    }
    return cnt;
}

int main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    vector<pair<int, int>> printerino(N);
    for (int i = 1; i < N; i++) {
        int x, y;
        cin >> x >> y;
        x--;y--;
        G[x].push_back(y);
        G[y].push_back(x);
        printerino[i] = make_pair(x, y);
    }
    int K = 0;

    map<pair<int, int>, int> I;
    vector<int> cs(N, 0);

    vector<bool> visited(N);
    queue<int> Q;
    Q.emplace(0);
    visited[0] = true;
    while (!Q.empty()) {
        int v = Q.front();Q.pop();
        if (K < G[v].size()) K = G[v].size();
        int cur = 1;
        for (auto u : G[v]) {
            if (visited[u]) continue;
            if (cur == cs[v]) cur++;
            I[make_pair(v, u)] = cur;
            I[make_pair(u, v)] = cur;
            cs[u] = cur;
            cur++;
            Q.emplace(u);
            visited[u] = true;
        }
    }
    cout << K << "\n";
    for (int i = 1; i < N; i++) {
        cout << I[printerino[i]] << "\n";
    }
    return 0;
}

Measured memory_bytes: 22504
#include <bits/stdc++.h>
#define speed_demon; ios_base::sync_with_stdio(0);
#define ll long long
using namespace std;
int main(){
	speed_demon;
	ll n,m,k;
	cin>>n>>m>>k;
	if(n==m and k!=n and k!=m){
		cout<<"Yes";
	}
	else if(k==m and k!=n and n!=m){
		cout<<"Yes";
	}
	else if(n==k and k!=m and n!=m){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc045/tasks/arc061_a

int main() {
    string S; cin >> S;
    int len = S.length();

    ll ans = 0;
    for (int msk = 0; msk < 1 << (len-1); msk++) {

        ll num = S[0] - '0';
        for (int i = 0; i < len-1; i++) {
            if (msk & 1 << i) {
                ans += num;
                num = 0;
            }
            num = num * 10 + (S[i+1] - '0');
        }
        ans += num;
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
//#include <unordered_map>
//#include <unordered_set>
#include <stack>
#include <set>
#include <queue>
#include <list>

using namespace std;
map<unsigned int,unsigned int>ans;
map<unsigned int,unsigned int>::reverse_iterator it;
int main()
{
	unsigned int n,m,a,b;
	scanf("%d%d",&n,&m);
	ans[0]=0;
	while(n--)
	{
		scanf("%d%d",&a,&b);
		for(it=ans.rbegin();it!=ans.rend();++it)
		{
			unsigned int x=it->first;
			unsigned int y=it->second;
			if(x+a<=m)
				ans[x+a]=max(y+b,ans[x+a]);
			//cout<<x+a<<" "<<ans[x+a]<<endl;
		}
	}
	unsigned int ma=0;
	for(it=ans.rbegin();it!=ans.rend();++it)
	ma=max(ma,it->second);
	cout<<ma<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;
typedef vll::iterator vitr;


const lli max_range = 1000000000;
const lli min_range = -1000000000;

lli n;
mat p;
lli q;
vll s,t;

vll k;
vll ans;
vll min_p,max_p;

void init(){
    k = vll(n);
    for(lli i = 0;i < n;i++) k[i] = i;
}

void make(vitr from,vitr to,int d){
    if(from == to) return;
    sort(from,to,[d](lli a,lli b){
        return p[a][d] < p[b][d];
    });
    make(from,from+(to-from)/2,(d+1)%2);
    make(from+(to-from)/2+1,to,(d+1)%2);
}

bool contain(vll& a,vll& b,vll& s){
    for(lli i = 0;i < 2;i++){
        if(a[i] > s[i]) return false;
        if(b[i] < s[i]) return false;
    }
    return true;
}

void search(vll& s,vll& t,vll& a,vll& b,lli d,vitr from,vitr to){
    if(from == to) return;
    if(contain(s,t,a) && contain(s,t,b)){
        for(vitr itr = from;itr < to;itr++){
            ans.push_back(*itr);
        }
        return;
    }
    for(lli i = 0;i < 2;i++){
        if(a[i] > t[i]) return;
        if(b[i] < s[i]) return;
    }
    lli c = *(from+(to-from)/2);
    lli l = p[c][d];
    if(contain(s,t,p[c])) ans.push_back(c);
    swap(b[d],l);
    search(s,t,a,b,!d,from,from+(to-from)/2);
    swap(b[d],l);
    swap(a[d],l);
    search(s,t,a,b,!d,from+(to-from)/2+1,to);
    swap(a[d],l);
}


int main(){
    cin >> n;
    p = mat(n,vll(2));
    for(lli i = 0;i < n;i++) scanf("%lld %lld",&p[i][0],&p[i][1]);
    s = vll(2);t = vll(2);
    init();
    make(k.begin(),k.end(),0);
    min_p = vll(2,min_range);
    max_p = vll(2,max_range);
    cin >> q;
    for(lli i = 0;i < q;i++){
        cin >> s[0] >> t[0] >> s[1] >> t[1];
        ans = vll();
        search(s,t,min_p,max_p,0,k.begin(),k.end());
        sort(ans.begin(),ans.end());
        for(lli i = 0;i < ans.size();i++) printf("%lld\n",ans[i]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 33180
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int d,w;
  while(cin>>d>>w, d|w){
    vector<vector<int>> v(d,vector<int>(w));
    rep(i,d)rep(j,w) cin>>v[i][j];

    int ans = 0;
    rep(i,d)rep(j,w)repl(k,i+2,d)repl(l,j+2,w){
      int mn = INF;
      for(int x=j; x<=l; x++) mn = min(mn, v[i][x]);
      for(int x=j; x<=l; x++) mn = min(mn, v[k][x]);
      for(int x=i; x<=k; x++) mn = min(mn, v[x][j]);
      for(int x=i; x<=k; x++) mn = min(mn, v[x][l]);

      int tmp = 0;
      repl(ii,i+1,k)repl(jj,j+1,l){
        if(v[ii][jj]>=mn) tmp = -INF;
        else tmp += mn - v[ii][jj];
      }
      ans = max(ans, tmp);
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b)                                                           \
  for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define SUM(a) accumulate(all(a), int(0))
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

set<int> divisor(int n) { // O(√n)約数列挙
  set<int> res;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.insert(i);
      if (i * i != n)
        res.insert(n / i);
    }
  }
  // sort(res.begin(),res.end());
  return res;
}

bool kyoutuu(set<int> &a, set<int> &b) {
  for (auto x : a) {
    if (b.count(x))
      return true;
  }
  return false;
}

signed main() {
  int n;
  cin >> n;
  map<int, int> a;
  rep(i, n) {
    int x;
    cin >> x;
    a[x]++;
  }

  int ans = 0;
  for (auto p : a) {
    if (p.second == 1)
      ans++;
    if (p.second == 0)
      continue;
    for (int i = 2 * p.first; i <= 1000000; i += p.first) {
      if (a.count(i))
        a[i] = 0;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

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

    int ans = 1000000000;
    for (int i = 0; i < N; ++i) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            ans = min(ans, c);
        }
    }

    if (ans != 1000000000) {
        cout << ans << endl;
    } else {
        cout << "TLE" << endl;
    }
}

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

using namespace std;

int main() {
    string s;

    cin >> s;

    while (s.size() > 0) {
        s.pop_back();
        if (s.size() % 2 == 0) {
            int num = s.size() / 2;
            if (s.substr(0, num) == s.substr(num, s.size() - 1)) {
                cout << s.size() << endl;
                return 0;
            }
        }
    }
}

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()



int main() {
    int n;
    cin >> n;
    vector<vector<P>> p(n);
    rep (i, n) {
        int a;
        cin >> a;
        rep (j, a) {
            int x, y;
            cin >> x >> y;
            p[i].push_back(make_pair(--x, y));
        }
    }
    int ans = 0;
    rep (i, (1 << n)) {
        int flag = 0;
        int ctr = 0;
        rep (j, n) {
            if (i & (1 << j)) {
                ctr++;
                rep (k, p[j].size()) {
                    int x = p[j][k].first;
                    int y = p[j][k].second;
                    bool human = i & (1 << x);
                    if (human != y) {
                        flag = 1;
                    }
                }
            }
        }
        if (flag) {
            continue;
        } else {
            chmax(ans, ctr);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# keyenceが先頭にある場合と最後にある場合、それ以外は真ん中にある場合
s = input()
keyence = "keyence"
for i in range(len(keyence)):
    if s[: i + 1] == keyence[: i + 1] and s[-i + 1 :] == keyence[-i + 1]:
        print("YES")
        exit()
print("NO")


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

int G[252][252], M, N, masu[251];

int main() {
	while(cin >> M && M){
		cin >> N;
		for(int i = 1; i <= N; ++i)
			cin >> masu[i];
			
		for(int i = 0; i < 252; ++i)
			for(int j = 0; j < 252; ++j)
				G[i][j] = 0;
		
		for(int i = 0; i < N + 1; ++i){
			for(int j = 1; j <= M; ++j){
				if(i + j >= N + 1){
					G[i][N + 1] = 1;
				}
				else{
					int v = i + j + masu[i + j];
					if(v < 0)
						v = 0;
					else if(v > N + 1)
						v = N + 1;
					G[i][v] = 1;
				}
			}
		}

		for(int k = 0; k < N + 2; ++k){
			for(int i = 0; i < N + 2; ++i){
				for(int j = 0; j < N + 2; ++j){
					if(G[i][k] && G[k][j])
						G[i][j] = 1;
				}
			}
		}
		
		bool ok = G[0][N + 1];
		for(int i = 1; i < N + 1; ++i){
			if(G[0][i] && G[i][N + 1] == 0){
				ok = false;
				break;
			}
		}
		cout << (ok ? "OK" : "NG") << endl;
		
	}
	return 0;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
           int h,w;
           cin>>h>>w;
           string v,p;
           for(int i=0;i<w;i++)v.push_back('.');
    vector<string> a,b;
    for(int i=0;i<h;i++){
        cin>>p;
        if(p!=v)a.push_back(p);
    }
    v.clear();for(int i=0;i<a.size();i++)v.push_back('.');
    for(int i=0;i<w;i++){
        p.clear();
        for(int j=0;j<a.size();j++){
            p.push_back(a[j][i]);
        }
      if(v!=p) b.push_back(p);
    }
    for(int i=0;i<a.size();i++){
        for(int j=0;j<b.size();j++)cout<<b[j][i];
        cout<<endl;
    }

         return 0;

        }


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    using ll=long long;
    int main()
    {
       ios::sync_with_stdio(0);
       cin.tie(0);
       int k;
       cin>>k;
       string s;
       cin>>s;
       if(s.size()<=k)cout<<s;
       else
       cout<<s.substr(0,k)<<"...";
        return 0;
    }

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

int main(void){
  int N;
  cin >> N;
  int num = 0;

  for (int i = 1; i <= N; i += 2){
    int count = 0;
    for (int j = 1; j <= i; j++){
      if(i%j==0){
        count++;
      }
    }
    if(count==8){
      num++;
    }
  }
  cout << num << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0;i <n;i++)
int main(){
	int n,M; cin >> n>>M; vector<long long> m(n);
	vector<vector<long long>> a(3, vector<long long>(n));
	rep(i, n) cin >> a[0][i] >> a[1][i] >> a[2][i];
	long long int ans = 0, sum = 0;
	rep(i, 1 << 3) {
		sum = 0;
		rep(k, n) {
			m[k] = 0;
			rep(j, 3) {
				if (i&(1 << j)) m[k] -= a[j][k];
				else m[k] += a[j][k];
			}
		}sort(m.rbegin(), m.rend());
		rep(k, M) sum += m[k];
		ans = max(ans, sum);
	}cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int ar[100009][3];
void clr()
{
	int i,j;
	for(i=0; i<=100003; i++)
	{
		ar[i][0]=0;
		ar[i][1]=0;
	}
}
int main()
{
	 string st;
	 clr();
   int ac=0,wa=0,i,j,n,s,id;
   cin>>n>>s;
   for(i=1; i<=s; i++)
   {
      cin>>id>>st;
      if(ar[id][0]==0 && st=="WA") ar[id][1]++;
      if(ar[id][0]==0 && st=="AC") ar[id][0]=1;
   }

   for(i=0; i<=n; i++)
   {
   	 if(ar[i][0]==1)
   	 {
   	 	ac++;
   	 	wa+=ar[i][1];
   	 }
   }
   cout<<ac<<" "<<wa<<endl;
   return 0;
   
}

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

int main() {
    int n, l[10], a[3], ans=IINF;
    cin >> n;
    REP(i,3) cin >> a[i];
    REP(i,n) cin >> l[i];
    for(int i=0;i<(1<<2*n);i++){
        int sum[4]{}, cnt[4]{};
        for(int j=0;j<n;j++){
            sum[(i>>(j*2))%4]+=l[j];
            cnt[(i>>(j*2))%4]++;
        }
        if(cnt[0]>0 && cnt[1]>0 && cnt[2]>0){
            int tmp = 0;
            REP(j,3){
                tmp += abs(a[j]-sum[j]);
                tmp += (cnt[j]-1)*10;
            }
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var dp=[1,2,4];
for(var i=3;i<=31;i++){
   dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
}
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   console.log(Math.ceil(dp[n-1]/3650));
}

Measured memory_bytes: 7640
package main

import (
	"fmt"
	"math"
	"strings"
)

var n int
var t string

func main() {
	fmt.Scan(&n)
	S := make([][]string, n)

	for i := 0; i < n; i++ {
		S[i] = make([]string, 0, n)
		fmt.Scan(&t)
		S[i] = strings.Split(t, "")
	}

	ans := make(map[string]int)

	for i := 0; i < n; i++ {
		cnt := make(map[string]int)
		// S[i]に出現するアルファベットとその個数をカウント
		for j := 0; j < len(S[i]); j++ {
			cnt[S[i][j]]++
		}
		// 初回だけは，ansをS[0]と同等にする必要がある(そうじゃないと全部0になる)
		if i == 0 {
			ans = cnt
		}
		// 共通アルファベットの検索．最小値が解となる
		for key, _ := range ans {
			ans[key] = min(ans[key], cnt[key])
		}
	}

	var str string
	for _, x := range "abcdefghijklmnopqrstuvwxyz" {
		// 共通のアルファベットがあったら
		if ans[string(x)] != 0 {
			// 共通のアルファベット個数だけstrに文字を繋げる
			for i := 0; i < ans[string(x)]; i++ {
				str += string(x)
			}
		}
	}
	fmt.Println(str)
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy []si

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].s < a[j].s }


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

int main(){
  int64_t X;
  cin >> X;
  int64_t i=0,j=100;
  while(true){
    i++;
    j*=1.01;
    if(j>=X){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;

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

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

	ll dp[n][K+1];
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < K+1 and a[0] >= i; ++i)
		dp[0][i] = 1;

	for (int i = 1; i < n; ++i)
	{
		ll sum = 0;
		for (int j = 0; j <= K; ++j)
		{
			if(j-a[i]-1 >= 0)
				sum = (sum - dp[i-1][j-a[i]-1] + MOD)%MOD;
			sum = (sum + dp[i-1][j])%MOD;

			dp[i][j] = (dp[i][j] + sum)%MOD;
		}
	}
	
	cout << dp[n-1][K];
	return 0;
}

Measured memory_bytes: 78336
#include <stdio.h>

#define SIZE 750
#define NUM 750

int main()
{
	int i, N, Q, c[500001];
	scanf("%d %d", &N, &Q);
	for (i = 0; i < N; i++) scanf("%d", &(c[i]));
	
	int left[500001], right[500001], flag[500001] = {};
	for (i = 0; i < N; i++) {
		left[i] = -1;
		right[i] = N;
	}
	for (i = 0; i < N; i++) {
		if (flag[c[i]] != 0) {
			left[i] = flag[c[i]] - 1;
			right[flag[c[i]]-1] = i;
		}
		flag[c[i]] = i + 1;
	}
	
	int j, n = (N + SIZE - 1) / SIZE, block[NUM][NUM] = {}, count;
	for (i = 0; i < n; i++) {
		for (j = 1; j <= N; j++) flag[j] = 0;
		for (j = i * SIZE, count = 0; j < N; j++) {
			if (flag[c[j]] == 0) {
				flag[c[j]] = 1;
				count++;
			}
			if (j % SIZE == SIZE - 1) block[i][j/SIZE] = count;
		}
	}
	
	int q, l, r;
	for (q = 1; q <= Q; q++) {
		scanf("%d %d", &l, &r);
		l--;
		r--;
		if (l / SIZE == r / SIZE) {
			for (j = l, count = 0; j <= r; j++) if (left[j] < l) count++;
		} else {
			i = (r - SIZE + 1) / SIZE;
			count = block[(l+SIZE-1)/SIZE][i];
			for (j = l; j % SIZE != 0; j++) if (right[j] >= (i + 1) * SIZE) count++;
			for (j = (i + 1) * SIZE; j <= r; j++) if (left[j] < l) count++;
		}
		printf("%d\n", count);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 13624
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(int i = (int)(b); i < (int)(e); ++i)
#define RFOR(i, b, e) for(int i = (int)(e-1); i >= 0; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<int,int>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;

using namespace std;

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

	vector<ll> v(n);

	REP(i, n) {
		cin >> v[i];
	}

	RSORT(v);

	ll count = 0;
	ll t = 0;
	ll a = 0;
	REPC(x, v) {
		if (t == x) {
			++count;
			if (a != 0 && count == 1 || count == 3) {
				cout << x * a << endl;
				return 0;
			} else if(count == 1){
				a = x;
			}
		} else {
			count = 0;
		}
		t = x;
	}
	cout << 0 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  if (K > (N - 1) * (N - 2) / 2){
    cout << -1 << endl;
  } else {
    vector<pair<int, int>> E;
    for (int i = 1; i < N; i++){
      E.push_back(make_pair(1, i + 1));
    }
    K = (N - 1) * (N - 2) / 2 - K;
    for (int i = 2; i <= N; i++){
      for (int j = i + 1; j <= N; j++){
        if (K > 0){
          E.push_back(make_pair(i, j));
          K--;
        }
      }
    }
    int M = E.size();
    cout << M << endl;
    for (int i = 0; i < M; i++){
      cout << E[i].first << ' ' << E[i].second << endl;
    }
  }
}

Measured memory_bytes: 3716
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll nPr(ll n, ll r) {return (fact(n)/fact(n-r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000000;
// clang-format on

int N;
int lsn(int n) { return n % 10; }

int msn(int n) {
  int d = n;
  while (n >= 10) {
    d = n;
    n /= 10;
  }
  return n;
}

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

  map<int, map<int, int>> mp;
  for (int i = 1; i <= N; i++) {
    mp[lsn(i)][msn(i)]++;
  }

  ll ans = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ll m = (mp[i][j] * mp[j][i]);
      ans += (ll)m;
    }
  }
  cout << ans << endl;

  return 0;
}


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

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt" , "r" , stdin);
	// freopen("output.txt" , "w" , stdout);
	// #endif

	ll l,r;
	cin>>l>>r;
	if(l/2019!=r/2019)
		cout<<0<<endl;
	else
	{
		ll mn=INT_MAX;
		for(ll i=l;i<r;i++)
		{
			for(ll j=i+1;j<=r;j++)
			{
				mn=min(mn,(i*j)%2019);
			}
		}
		cout<<mn<<endl;
	}

	
	
}


Measured memory_bytes: 256
n=int(input())
s=list(input())


ans=(s.count("R"))*(s.count("G"))*(s.count("B"))

for i in range(n) :
    a=s[i]
    for j in range(i+1,n) :
        b=s[j]
        if 2*j-i>n-1 :
            break
        c=s[2*j-i]
        if (a!=b) and (b!=c) and (c!=a) :
            ans-=1

print(ans)

Measured memory_bytes: 9092
#include<iostream>
#include<stack>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))
#define N_MAX 100001
#define ll long long

//DP
int stepData[N_MAX];

//?????¨????????´???
int step=1;
queue<int> nowStep;
queue<int> nowStep2;
stack<int> nextStep;

//???????????¨??????
int N;
int p[N_MAX];


int main() {
	//??\?????¨?????????
	cin>>N;
	rep(i,N)stepData[i]=-1;
	rep(i,N)cin>>p[i];
	nowStep.push(0);
	
	//????????????????????§?????????
	while (stepData[N-1] == -1) {
		//??¨????????????6?????\???????????¨?????´??????
		while (nowStep.size() > 0) {
			//?????¨?????´???
			int here = nowStep.front();
			//cout<<"a: "<<here<<endl;
			FOR(i,1, 7){
				if(here+i<N)
					nowStep2.push(here + i);
			}
			nowStep.pop();
		}
		

		//??????????????????????????§????????¨???????????????
		while (nowStep2.size() > 0) {
			//?????¨?????´???
			int here=nowStep2.front();

			//????????\???????????£?????????????°???????????????°?????£??\?????????
			//??????????????´??????????????°??£??\
			//??????????????´??????????¬???????????????§p[here]=0??§?????????????¶????
			if (stepData[here] == -1) {
				stepData[here] = step;
				if(p[here]!=0){
					nowStep2.push(here + p[here]);
					//cout << "b: " << here << endl;
				    //cout << "d: " << here+p[here] << endl;
				}
				else {
					nowStep.push(here);
					//cout << "c: " << here << endl;
				}
			}
			nowStep2.pop();
		}
		step++;
	}

	cout<<stepData[N-1]<<endl;
	//cin>>N;
	return 0;
}

Measured memory_bytes: 3912
{-# LANGUAGE BangPatterns #-}

import Control.Applicative ((<$>))
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as BS
import Data.List (scanl', tails)

main :: IO ()
main = do
  n <- read <$> getLine
  s <- getLine
  print $ maximum
    $ zipWith (\ !gap !dropped -> min gap $ test s $ dropped)
       [1..n-1]
    $ tail $ tails s

test :: String -> String -> Int
test v1 v2
 = maximum
   $ scanl' (\ !l !b -> if b then l+1 else 0) (0::Int)
   $ zipWith (==) v1 v2


Measured memory_bytes: 1276
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static readonly long mod = 1000000007;
    static void Main()
    {
        var NM = ReadLine().Split().Select(int.Parse).ToArray();
        int N = NM[0];
        int M = NM[1];

        
        var broke = new bool[N + 1];
        for (int i = 0; i < M; i++)
        {
            var a = int.Parse(ReadLine());
            broke[a] = true;
        }
        var dp = new long[N + 1];
        dp[0] = 1;
        for (int i = 0; i < N; i++)
        {
            if (broke[i]) continue;
            dp[i + 1] += dp[i];
            dp[i + 1] %= mod;
            if (i < N - 1)
            {
                dp[i + 2] += dp[i];
                dp[i + 2] %= mod;
            }
        }
        WriteLine(dp[N]);
    }
}


Measured memory_bytes: 31468
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from collections import Counter
    N, K = MI()
    A = LI()
    c = Counter(A)
    c = [j for i, j in c.items()]
    c.sort()
    change_num = len(c) - K
    ans=0
    for C in c:
        if change_num <= 0:
            break
        ans += C
        change_num -= 1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 95688
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int count_two(int v) {
  int cnt = 0;
  while(v%2 == 0) {
    v /= 2;
    ++cnt;
  }
  return cnt;
}

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

LL lcm(LL a, LL b) {
  if ((a == 0) || (b == 0)) return 0;
  return ((a / gcd(a, b)) * b);
}

int main() {
  int N, M; std::cin >> N >> M;
  int a;
  std::cin >> a;
  int cnt_two = count_two(a);
  LL v_lcm = a/2;

  for (int i = 1; i < N; ++i) {
    std::cin >> a;
    if (cnt_two != count_two(a)) {
      std::cout << 0 << std::endl;
      return 0;
    }

    v_lcm = lcm(v_lcm, a/2);
  }

  std::cout << (M/v_lcm)-(M/(2*v_lcm)) << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
    int N, M; cin >> N >> M;
    vector<pair<ll, bool>> oka(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> oka[i].first;
        oka[i].second = true;
    }
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        if (oka[a].first >= oka[b].first)
            oka[b].second = false;
        if (oka[a].first <= oka[b].first)
            oka[a].second = false;
    }   
  
    int cnt = 0;
    for (int i = 1; i <= N; i++) {
        if (oka[i].second) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4844
def main():
    n = int(input())
    h = list(map(int, input().split()))
    dp = [float('inf')] * n
    dp[n-1] = 0
    dp[n-2] = abs(h[n-1] - h[n-2])
    for i in range(n-3, -1, -1):
        jump_one = dp[i+1] + abs(h[i+1] - h[i])
        jump_two = dp[i+2] + abs(h[i+2] - h[i])
        dp[i] = min(jump_one, jump_two)
    print(dp[0])


if __name__ == '__main__':
    main()

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

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

  int64_t seven = 7;
  int ans = 1;
  vector<bool> mods(k);
  while (true)
  {
    if (seven % k == 0)
    {
      cout << ans << endl;
      exit(0);
    }
    if (mods.at(seven % k))
    {
      break;
    }
    mods.at(seven % k) = true;
    seven %= k;
    seven = seven * 10 + 7;
    ans++;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 3724