akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		String[] s = new String[N];
		for (int i = 0; i < N; i++) {
			s[i] = sc.next();
		}

		int M = sc.nextInt();
		String[] t = new String[M];
		for (int i = 0; i < M; i++) {
			t[i] = sc.next();
		}

		sc.close();

		Map<String, Long> ss = Arrays.stream(s)
				.collect(Collectors.groupingBy(w -> w, Collectors.counting()));

		Map<String, Long> tt = Arrays.stream(t)
				.collect(Collectors.groupingBy(w -> w, Collectors.counting()));

		Set<String> keys = new HashSet<>();
		keys.addAll(ss.keySet());
		keys.addAll(tt.keySet());

		int ans = 0;

		for (String k : keys) {
			Long sv = ss.get(k);
			if (sv == null)
				sv = 0L;
			Long tv = tt.get(k);
			if (tv == null)
				tv = 0L;

			ans = Math.max(ans, (int) (sv - tv));

		}

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 28876
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
using namespace std;
typedef long long ll;

void dfs(int curr, vector<vector<int>>& v,
	vector<bool>& visited, int &cnt) {
	if (visited[curr]) return;
	visited[curr] = true;
	cnt++;
	for (int i = 0; i < v[curr].size(); i++) {
		dfs(v[curr][i], v, visited, cnt);
	}
}

int main() {

	int N, M;
	cin >> N >> M;

	vector<vector<int>> v(N + 1);

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}

	vector<bool> visited(N + 1);
	  
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int cnt = 0;
		dfs(i, v, visited, cnt);
		ans = max(ans, cnt);
	}

	cout << ans << endl;
}


Measured memory_bytes: 23488
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

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

Measured memory_bytes: 19164
def main():
    N, M, K = map(int, input().split())

    editorial(N, M, K)

def editorial(N, M, K):
    for k in range(N+1):
        for l in range(M+1):
            # 黒の面積
            # 選択行数 * (列 - 選択列数)
            x = k * (M - l) + (N - k) * l
            if x == K:
                print("Yes")
                return

    print("No")

    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n;cin >> n;
    vector<LL> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(RALL(l));
    LL 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[j] == l[k] || l[i] == l[k]) continue;
                if(l[i] < l[j] + l[k]) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  int ans = C - (A - B);

  if(ans > 0) cout << ans << endl;
  else cout << "0" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///



int main()
{
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vi v(n);
	REP(i, n) cin >> v[i];
	sort(ALL(v), greater<int>());
	int p[101] = {};
	int s = 0;
	REP(i, n)
	{
		s += v[i];
		p[i] = (s + c) / (a + b*(i + 1));
	}
	cout << *max_element(ALL(p))<< endl;
	return 0;
}

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

int main()
{
	std::string s;
	std::cin >> s;
	long buf, result;
	result = 0;
	buf = 0;
	for (unsigned int i = 0; i < s.size(); i++)
	{

		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
		{
			buf++;
			if (result < buf)
			{
				result = buf;
			}
		}
		else
		{
			buf = 0;
		}
		
	}
	std::cout << result << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
   int a, b, c, area;

   scanf("%d %d %d", &a, &b, &c);
   if((a >= 1) && (a <= 100) && (b >= 1) && (b <= 100) && (c >= 1) && (c <= 100)) {
      if((a >= b) && (a >= c)) {
         area = (b * c) / 2;
      }
      else if((b > a) && (b > c)) {
         area = (a * c) / 2;
      }
      else {
         area = (a * b) / 2;
      }
      
      printf("%d\n", area);
   }
   

   return 0;
}



Measured memory_bytes: 128
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n, l = MII()
    ss = [IS() for _ in range(n)]
    ss.sort()
    print(''.join(ss))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int a[20],vis[100010];
int n;
int bfs()
{
    int i,j,k;
    queue<int> q;
    memset(vis,0,sizeof(vis));
    vis[0]=1;
    q.push(0);
    while(!q.empty())
    {
        k=q.front();
        q.pop();
        if(k==n)
            return vis[k]-1;
        for(i=0;i<12;i++)
        {
            j=k+a[i];
            if(j<=n&&vis[j]==0)
            {
                vis[j]=vis[k]+1;
                q.push(j);
            }
        }
    }
}
int main()
{
    int i,j,k;
    a[0]=1;
    for(i=1;i<7;i++)
        a[i]=a[i-1]*6;
    a[7]=9;
    for(i=8;i<12;i++)
        a[i]=a[i-1]*9;
    scanf("%d",&n);
    printf("%d\n",bfs());
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, K, R, S, P;
string T;

int main() {
  cin >> N >> K >> R >> S >> P >> T;

  unordered_map<char, int> score;
  score['r'] = P;
  score['s'] = R;
  score['p'] = S;
  unordered_map<char, char> enemy;
  enemy['r'] = 'p';
  enemy['p'] = 's';
  enemy['s'] = 'r';

  ll ans = 0;
  rep(i, K) {
    char h = '?';
    for (int j = i; j < N; j += K) {
      if (h == enemy[T[j]]) {
        if (j + K < N) h = T[j + K];
      } else {
        h = enemy[T[j]];
        ans += score[T[j]];
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define LL long int


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

    int sum = accumulate(a.begin(),a.end(),0);

    int sum_odd = 0;

    for(int i = 1; i < n; i += 2) sum_odd += a[i];

    int x = sum - 2 * sum_odd;

    for(int i = 0; i < n; ++i){
        cout << x << " ";

        x = 2 * a[i] - x;
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <stack>
#include <string>
#include <deque>
#include <map>

using namespace std;


int main() {
    string  s;
    string t;
    cin >> s;
    cin >> t;
    cout << t + s << endl;
    return 0;
}

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

        final long N = sc.nextLong();
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        long AB = A + B;
        long num = N / AB;
        long amari = N % AB;

        long sum = num * A;
        if(amari >= A)
            sum += A;
        else    
            sum += amari;
        System.out.println(sum);
    }

}


Measured memory_bytes: 21844
N, M = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(M)]

c = {ab[i][1] for i in range(M) if ab[i][0] == 1}
d = {ab[i][0] for i in range(M) if ab[i][1] == N}

if c & d :
    print("POSSIBLE")
else :
    print("IMPOSSIBLE")


Measured memory_bytes: 59512
#include<stdio.h>
int  nyan_int(const void *a, const void *b)
{
    return *(double*)a - *(double*)b;
}

int main(){
	int N;
    int L[55];
    double K[55];
	double ans = 0.0;
	scanf("%d", &N);
	for (int a = 0; a < N;a++){
		scanf("%d", &L[a]);
      K[a]=L[a]*1.0;
	}
	qsort(K, N, sizeof(double), nyan_int);

	for (int b = 0; b < N - 2;b++){
		K[b+1] = (K[b+1] + K[b])/2;
	}
  ans=(K[N-1]+K[N-2])*0.5;
	printf("%f", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define INF 99999999
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

vector<int> cnt(string s){
    vector<int> ret(26);
    
    REP(i,s.size())
        ret[int(s[i])-int('a')]++;
    
    return ret;
}

int main(void){
    
    int n;
    cin >> n;
    string s;
    vector<int> res(26);
    
    REP(i,26)
        res[i] = INF;
    
    REP(i,n){
        cin >> s;
        vector<int> ret = cnt(s);
        
        REP(j,26)
            res[j] = min(res[j],ret[j]);
    }
    
    REP(i,26){
        if( res[i] != INF && res[i] != 0 ){
            REP(j,res[i]){
                cout << (char)(i+int('a'));
            }
        }
    }
    cout << endl;
    
    
    
    return 0;
}


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

int main() {
    string s;
    string t;
    cin >> s >> t;
    if(s.length()+1 != t.length()){
        cout << "No" << endl;
        return 0;
    }else{
        rep(i, s.length()){
            if(s[i] != t[i]){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    return 0;
}

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

int main()
{
    int n,alice=0,bob=0;
    cin>>n;
    int ara[n+5];
    for(int i=0; i<n; i++){
        scanf("%d",&ara[i]);
    }
    sort(ara,ara+n);
    int f=1;
    for(int i=n-1; i>=0; i--){
        if(f)alice+=ara[i],f=0;
        else bob+=ara[i],f=1;
    }
    cout<<(alice-bob);
    return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

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

    vector<int> v(n);

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

    vector<bool> dp(k + 1);
    dp[0] = false;

    for(int i = 1; i < k + 1; ++i) {
        for(int x: v) {
            if(i - x < 0)
                continue;

            if(!dp[i - x]) {
                dp[i] = true;
                break;
            }
        }
    }

    if(dp[k])
        cout << "First" << endl;
    else
        cout << "Second" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;


int main() {
    int64_t n,k;
    ios::sync_with_stdio(false);
    cin>>n>>k;
    vector<int> A(n);
    copy_n(istream_iterator<int>(cin), n, A.begin());
    vector<int> v(N,-1);
    int cur=0,cnt=0;
    while(true){
        cur=A[cur]-1;
        cnt++;
        if(v[cur]!=-1) break;
        if(cnt==k) break;
        v[cur]=cnt;
    }
    k-=v[cur];
    k%=(cnt-v[cur]);

    for(int i=0;i<k;++i){
        cur=A[cur]-1;
    }
    printf("%d\n",cur+1);

    return 0;
}

Measured memory_bytes: 8012
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<float.h>

int main(){
	long long ans=0;
	int n;
	int k;
	std::vector<long long> aList;
	std::vector<long long> cumSum;
	std::vector<long long> aEnum;

	std::cin>>n>>k;

	aList.resize(n);
	cumSum.resize(n);
	aEnum.resize(n*(n+1)/2);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	cumSum[0]= aList[0];
	for(int i=1; i<n; i++)
		cumSum[i]= cumSum[i-1]+ aList[i];

	for(int i=0; i<n; i++)
		aEnum[i]= cumSum[i];

	int offset=0;
	for(int i=0; i<n-1; i++){
		offset+= (i+1);

		for(int j=i+1; j<n; j++)
			aEnum[(i+1)*n+j- offset]= cumSum[j]-cumSum[i];
	}

	std::stable_sort(aEnum.begin(), aEnum.end(), [](long long x, long long y){return x>y;});

	long long num= aEnum[0];
	int maxDeg= 0;

	while(1){
		num= num/2;

		if(num>0)
			maxDeg+=1;
		else
			break;
	}

	std::vector<long long> cand;
	std::vector<long long> cand2;

	std::copy(aEnum.begin(), aEnum.end(), std::back_inserter(cand));

	long long bit1=1;
	while(cand.size()>=k && maxDeg>=0){	
		for(int i=0; i<cand.size(); i++){
			if(cand[i] & (bit1<<maxDeg))
				cand2.push_back(cand[i]);
		}

		if(cand2.size()>=k){
			long long tmp=1;
			for(int i=0; i<maxDeg; i++)
				tmp*=2;

			ans+= tmp;
			cand.clear();
			std::copy(cand2.begin(), cand2.end(), std::back_inserter(cand));
		}

		cand2.clear();
		maxDeg--;
	}

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

	std::cout<<ans<<std::endl;

	return 0;

}

Measured memory_bytes: 12312
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		if(x >= 30 ) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}

Measured memory_bytes: 35732
#include <stdio.h>
#include <string.h>
 
char str[110];
int i,j,k,l,m,n;
int n,e,s,w,un,up;
int a[7],b[7], qu[25],qf[25],ufl[25];
int t;
 
void input() {
  for(i=0;i<6;i++){
    scanf("%d",&a[i+1]);
    b[i+1] = a[i+1];
  }
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++) {
    scanf("%d %d",&qu[i],&qf[i]);
  }
}
 
void N() {
  t = a[1];
  a[1] = a[2];
  a[2] = a[6];
  a[6] = a[5];
  a[5] = t;
}
 
void S() {
  t = a[1];
  a[1] = a[5];
  a[5] = a[6];
  a[6] = a[2];
  a[2] = t;
}
 
void E() {
  t = a[1];
  a[1] = a[4];
  a[4] = a[6];
  a[6] = a[3];
  a[3] = t;
}
 
void W() {
  t = a[1];
  a[1] = a[3];
  a[3] = a[6];
  a[6] = a[4];
  a[4] = t;
}
 
void UF() {
 
  if(qu[k] == a[1]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[5]) strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
  }  else if(qu[k] == a[2]) {  
    if(qf[k] == a[3])  strcpy( str, "NWS");
    else if(qf[k] == a[1] ) strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    N();
  } else if(qu[k] == a[3]){ 
     
    if(qf[k] == a[6])  strcpy( str, "NWS");
    else if(qf[k] == a[5])  strcpy(str ,"NEES");
    else if(qf[k] == a[1]) strcpy(str,"NES");
    W();
  } else if(qu[k] == a[4]) {
    if(qf[k] == a[1]) strcpy( str, "NWS");
    if(qf[k] == a[5])  strcpy(str ,"NEES");
    if(qf[k] == a[6]) strcpy(str,"NES");
    E();
  } else if(qu[k] == a[5]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[6])  strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    S();
  } else if(qu[k] == a[6]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[2])  strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    N();
    N();
  }
 
 
}
 
void reset() {
  strcpy(str , "");
  for(i=1;i<=6;i++){
    a[i] = b[i];
  }
}
 
 
void output() {
 
  printf("%d\n",a[3]);
}
 
void IF() {
 
 
  for(i=0;i<strlen(str);i++) {
 
    if(str[i] == 'N') N();
    else if(str[i] == 'S') S();
    else if(str[i] == 'W') W();
    else if(str[i] == 'E') E();
  }
}
 
int main() {
 
  k = 0;
 
  input();
 
  for(j=0;j<n;j++) {
    UF();
     
    IF();
 
    output();
 
    reset();
    k = k + 1;
 
  }
 
 
  return 0;
}


Measured memory_bytes: 2088
# Union Find 木
def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    parent[j] += parent[i]
    parent[i] = j


N, M = map(int, input().split())
ab = [[int(c) - 1 for c in input().split()] for _ in range(M)]

result = 0
for i in range(M):
    parent = [-1] * N
    for j in range(M):
        if j == i:
            continue
        unite(parent, ab[j][0], ab[j][1])
    if len([i for i in parent if i < 0]) != 1:
        result += 1
print(result)

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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

int n;
char g3[3][3] = {
  {0, 1, 1},
  {1, 0, 0},
  {1, 0, 0}
}, g4[4][4] = {
  {1, 2, 3, 3},
  {1, 2, 1, 1},
  {3, 3, 2, 3},
  {1, 1, 2, 3}
}, g5[5][5] = {
  {2, 3, 3, 2, 2},
  {2, 0, 1, 1, 3},
  {3, 1, 0, 0, 3},
  {3, 1, 0, 0, 2},
  {2, 2, 3, 3, 2}
}, g7[7][7] = {
  {1, 2, 2, 0, 0, 2, 2},
  {1, 0, 0, 2, 2, 0, 1},
  {0, 1, 0, 3, 3, 0, 1},
  {0, 1, 3, 0, 0, 1, 0},
  {1, 0, 3, 0, 0, 1, 0},
  {1, 0, 2, 2, 0, 0, 1},
  {2, 2, 0, 0, 2, 2, 1}
}, r[1100][1100];

char itc(int v) {
  return v == 0 ? '.' : ('a' + v);
}

void place3(int i, int j) {
  for (int k = 0; k < 3; k++)
    for (int l = 0; l < 3; l++)
      r[i + k][j + l] = itc(g3[k][l]);
}

void place4(int i, int j) {
  for (int k = 0; k < 4; k++)
    for (int l = 0; l < 4; l++)
      r[i + k][j + l] = itc(g4[k][l]);
}

void place5(int i, int j) {
  for (int k = 0; k < 5; k++)
    for (int l = 0; l < 5; l++)
      r[i + k][j + l] = itc(g5[k][l]);
}

void place7(int i, int j) {
  for (int k = 0; k < 7; k++)
    for (int l = 0; l < 7; l++)
      r[i + k][j + l] = itc(g7[k][l]);
}

void place9(int i, int j) {
  for (int k = 0; k < 9; k += 3)
    for (int l = 0; l < 9; l += 3)
      place3(i + k, j + l);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  if (n == 2) {
    cout << -1 << "\n";
    return 0;
  }
  if (n % 3 == 0) {
    for (int i = 0; i < n; i += 3)
        place3(i, i);
  } else {
    for (int i = n - 9; i >= 4; i -= 9)
        place9(i, i);
    if (n % 9 == 1)
      place5(0, 0), place5(5, 5);
    else if (n % 9 == 2)
      place4(0, 0), place7(4, 4);
    else if (n % 9 == 4)
      place4(0, 0);
    else if (n % 9 == 5)
      place5(0, 0);
    else if (n % 9 == 7)
      place7(0, 0);
    else if (n % 9 == 8)
      place4(0, 0), place4(4, 4);
  }
  for (int i = 0; i < n; i++, cout << "\n")
    for (int j = 0; j < n; j++)
      cout << (r[i][j] == 0 ? '.' : r[i][j]);
}


Measured memory_bytes: 2304
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007LL;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
llint LBI(vector<int>&ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint UBI(vector<int>&ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;cin>>a>>b;
	if(b==100){b++;}
	cout<<b;
	while(a--){cout<<"00";}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll LL_MAX=LLONG_MAX;
struct In{
    template<typename T>
    operator T(){
        T x;
        cin >> x;
        return x;
    }
};

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

template <typename T>
void out(T x){
    cout << x << endl;
}

int main(){
    In in;
    int n=in,k=in;
    out<int>(k*pow((double)(k-1),n-1));
}







Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int N = 100;
struct Card{
    char suit,value;
};

void trace(struct Card A[], int n){
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}
void BubbleSort(struct Card A[], int n){
    int i,j;
    for(i = 0; i < n; i++){
        for(j = n-1; j >= i; j--){
            if(A[j].value < A[j-1].value){
                Card t = A[j];
                A[j] = A[j-1];
                A[j-1] = t;
            }
        }
    }
}
void SelectionSort(struct Card A[], int n){
    int i,j,minj;
    for(i = 0; i < n; i++){
        minj = i;
        for(j = i; j < n; j++){
            if(A[j].value < A[minj].value){
                minj = j;
            }
        }
        Card t = A[i];
        A[i] = A[minj];
        A[minj] = t;
    }
}
bool isStable(struct Card A1[], struct Card A2[], int n){
    for(int i = 0; i < n; i++){
        if(A1[i].suit != A2[i].suit) return false;
    }
    return true;
}
int main(){
    int n;
    Card C1[N], C2[N];
    char ch;

    cin >> n;    
    for(int i = 0; i < n; i++) 
        cin >> C1[i].suit >> C1[i].value;
    for(int i = 0; i < n; i++)
        C2[i] = C1[i];
    
    BubbleSort(C1,n);
    SelectionSort(C2,n);

    trace(C1, n);
    cout << "Stable" << endl;
    trace(C2, n);
    if( isStable(C1, C2, n) ){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
}

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

int main()
{
	int N,K,T,L; double U,V;
	cin>>N>>K>>T>>U>>V>>L;

	int pos[202]; pos[0]=0; pos[N+1]=L;
	for(int i=1; i<=N; i++) cin>>pos[i];

	int stock=0;
	int a_pos=0;
	double ans=0;

	for(int i=1; i<=N+1; i++,stock++)
	{
		while(a_pos<pos[i] && stock)
		{
			a_pos += V*T;
			stock--;
		}

		if(a_pos<pos[i])
		{
			ans += (a_pos-pos[i-1])/V + (pos[i]-a_pos)/U;
			a_pos = pos[i];
		}
		else
		{
			ans += (pos[i]-pos[i-1])/V;
			if(stock>=K)
			{
				a_pos = pos[i] + V*T;
				stock=K-1;
			}
		}
	}

	cout.precision(9);
	cout << fixed << ans << endl;
}

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

using namespace std;
typedef long long ll;

const int M = 1e9 + 7;

ll qpow(ll x, ll p) {
    ll res = 1;
    while (p) {
        if (p & 1) res = res * x % M;
        p >>= 1;
        x = x * x % M;
    }
    return res;
}

ll divide(ll x, ll y) {
    return x * qpow(y, M - 2) % M;
}

int main() {
    int k;
    string s;
    cin >> k >> s;
    vector<ll> pw25(k + 1), pw26(k + 1);
    pw25[0] = 1, pw26[0] = 1;
    for (int i = 1; i <= k; i++) {
        pw25[i] = pw25[i - 1] * 25 % M;
        pw26[i] = pw26[i - 1] * 26 % M;
    }
    int l = s.size(), n = l + k;
    ll comb = 1, ans = 0;
    for (int i = l - 1; i < n; i++) {
        ans = (ans + (comb * pw25[i + 1 - l] % M) * pw26[n - i - 1]) % M;
        comb = comb * divide(i + 1, i + 2 - l) % M;
    }
    cout << ans << "\n";
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 int s,w;
  cin >> s>>w;
 if(w>=s)cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3620
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Set<Integer> set = new HashSet<>();
        set.add(sc.nextInt());
        set.add(sc.nextInt());
        set.add(sc.nextInt());
        System.out.println(set.size());
        
    }

}

Measured memory_bytes: 21588
//Jai Shree Krishna
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
void display(vector<int> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}
ll dx[8] = {0,1,0,-1,1,1,-1,-1};
ll dy[8] = {1,0,-1,0,1,-1,1,-1};

//Never giving in, fighting to the end
vector<ll>v1;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("/Users/ashish/Desktop/B-large-practice.in.txt", "r", stdin);
    //freopen("/Users/ashish/Desktop/A-large-practice.out.txt", "w", stdout);
    
    ll n;
    cin>>n;
    loop2(i, (3*n))
    {
        ll x;
        cin>>x;
        v1.push_back(x);
    }
    ll ans = 0;
    //cout<<v1.size()<<endl;
    sort(v1.begin(),v1.end());
    reverse(v1.begin(), v1.end());
    ll cnt = 0 ;
    for(ll j = 1;j<v1.size()&&cnt<n;j+=2)
    {
        ans+=v1[j];
        cnt+=1;
    }
    cout<<ans<<endl;
    
    return 0;
}





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

using namespace std;

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

main(){
  int n,x;
  scanf("%d %d",&n,&x);
  vector<int> arr;
  int num;
  cin >> num;
  int val = abs(x - num);
  for(int i=1;i<n;++i){
    scanf("%d",&num);
    val = gcd(val,abs(num-x));
  }

  cout << val << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# C - Go Home
# 標準入力の取得
X = int(input())

# 1, 2, 3・・・と足していったときに、最初に|X|以上となったときの回数
i = 0
sum_i = 0
while sum_i < abs(X):
    i += 1
    sum_i += i

print(i)

Measured memory_bytes: 2940
K = int(input())
a = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[K])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
  double t,a,m=10000,h;
  int n,c=0;
  cin>>n>>t>>a;
  for(int i=0;i<n;i++){
    cin>>h;
    if(m>abs(a-(t-h*0.006))){
      m=abs(a-(t-h*0.006));
      c=i+1;
    }
  }
  cout<<c;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int N, M, A, i;

    scanf("%d%d", &N, &M);
    for(i=0; i<M; i++){
        scanf("%d", &A);
        N -= A;
    }
    
    if(N < 0)
        N = -1;
    printf("%d\n", N);

    return 0;
}


Measured memory_bytes: 1732
#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 <iterator>
#include <numeric>
#include <bitset>
#include <cassert>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	ll N, P;
	cin >> N >> P;
	ll i = 2, gcd = 1;
	ll count;

	if (N == 1) {
		cout << P;
		return 0;
	}
	while (pow(i, 2) <= P) {
		count = 0;
		while (true) {
			if (P % i == 0) {
				count++;
				P /= i;
			}
			else {
				gcd *= ll(pow(i, (count / N)));
				break;
			}
		}

		if (i == 2) {
			i++;
		}
		else {
			i += 2;
		}

	}
	cout << gcd;
	return 0;
}


Measured memory_bytes: 256
AB = [[int(_) for _ in input().split()] for i in range(3)]

cs = [0] * 4

for a, b in AB:
    cs[a - 1] += 1
    cs[b - 1] += 1

cs.sort()

if cs == [1, 1, 2, 2]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
H, W = map(int,input().split())
c = [["#"]*(W+2) for _ in range(H+2)]
dots = 0
for y in range(H):
    c[y+1] = "#",*list(input()),"#" 
    dots += c[y+1].count(".")
inf = H*W
m = [[inf]*W for _ in range(H)]
m[0][0] = 0
drs = [[-1,0],[1,0],[0,-1],[0,1]]

s = 0
yx = [[1, 1]]
notgoal = True
while notgoal and yx:
    yx2 = []
    s += 1
    for y,x in yx:
        for dy, dx in drs:
            x2 = x+dx
            y2 = y+dy
            if c[y2][x2] == "." and m[y2-1][x2-1] == inf:
                m[y2-1][x2-1] = s
                if (y2,x2) == (H,W):
                    notgoal = False
                else:
                    yx2.append([y2, x2])
    yx = yx2

if notgoal:
    print("-1")
else:
    print(dots-s-1)

Measured memory_bytes: 9256
#include <stdio.h>
#include <iostream>
using namespace std;

int main()
{
	double minv, v=0.0, y=0.0;
	double t, high = 0.0;
	int f=1;

	while (cin >> minv)
	{
		high = 0;
		t = minv / 9.8;
		y = 4.9 * t * t;
		for (f = 0; high <= y; f++)
		{
			high = f * 5 - 5;
		}
		if (high != y) f--;
		cout << f << endl;
	}
	return 0;
}


Measured memory_bytes: 3164
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)


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


int main(){
	int w,h;
	cin>>h>>w;
	vector<vector<char> > grid(h,vector<char>(w));
	char aa;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>aa;
			grid[i][j] = aa;
		}
	}
	int mod = 1e9 + 7;
	vector<vector<int> > dp(h,vector<int>(w,0));
	dp[0][0] = 1;
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			dp[i][j] = (grid[i][j]!='#' && i!=0 && j!=0)? dp[i-1][j] + dp[i][j-1] : dp[i][j];
			dp[i][j] = (grid[i][j]!='#' && i!=0 && j==0) ? dp[i-1][j] : dp[i][j];
			dp[i][j] = (grid[i][j]!='#' && i==0 && j!=0)? dp[i][j-1] : dp[i][j];
			dp[i][j] = dp[i][j]%mod;
		}
	}
	//cout<<endl<<endl;
	//for(int i=0;i<h;i++){
		//for(int j=0;j<w;j++){
			//cout<<grid[i][j]<<" ";
		//}
		//cout<<endl;
	//}
	//for(int i=0;i<h;i++){5
		//for(int j=0;j<w;j++){
			//cout<<dp[i][j]<<" ";
		//}
		//cout<<endl;
	//}
	cout<<dp[h-1][w-1]%mod;
	
	return 0;
	
	
	
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e9 + 5;
const int MAXM = 2e5 + 5;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EXP = 1e-8;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int flag = 0;
    int tmp;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        if (tmp % 2 == 0)
        {
            if (tmp % 3 != 0 && tmp % 5 != 0)
                flag = 1;
        }
    }
    if (flag)
        cout << "DENIED";
    else
        cout << "APPROVED";
}


Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9


def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10

    return min(ret0, ret1, ret2, ret3)
print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#define ll long long

using namespace std;

int main() {
    int N;ll P, Q;
    ll now=0, ans,tmp;
    cin >> N >> P >> Q;
    vector<ll> vect(N); 
    vector<ll> dp(N,0),dp_old(N,0);
    for(int i=0; i< N; i++){
        cin >> tmp;
        vect[i] =  P*(Q-i) - tmp ;
        now+=tmp;
    }
    ans = now;
    sort(vect.begin(),vect.end(), greater<ll>());
    for(int i=0; i<N ; i++){
        now += vect[i] + 2*P*i;
        ans = max(ans,now);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 14412
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        label:
        var s = ReadLine();
        int b = 0;
        long result = 0;
        foreach(char c in s)
        {
            if (c == 'B') ++b;
            else result += b;
        }
        WriteLine(result);
    }
}


Measured memory_bytes: 11744
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int inf = 1<<30;
const int mod = 1e9+7;

ll f(P n) {
  string a, b;
  a = to_string(n.first);
  b = to_string(n.second);
  return max(a.size(), b.size());
}

int main() {
  ll N; cin >> N;
  vector<pair<ll, ll>> vec;
  for(ll i = 1; i*i <= N; i++) {
    if(N % i == 0) vec.push_back(P(i, N/i));
  }

  ll ans = 1e11;
  for(auto v: vec) {
    ans = min(ans, f(v));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct squ
{
	long long a,b,c,d;
	bool operator == (const squ &u) const
	{
		return (a==u.a && b==u.b && c==u.c && d==u.d);
	}
	bool operator < (const squ &u) const
	{
		if (a!=u.a) return a<u.a;
		if (b!=u.b) return b<u.b;
		if (c!=u.c) return c<u.c;
		return d<u.d;
	}
};
long long eqal(squ u,squ v)
{
	long long res=0;
	if (u==v) res++;
	if (u==(squ){v.b,v.c,v.d,v.a}) res++;
	if (u==(squ){v.c,v.d,v.a,v.b}) res++;
	if (u==(squ){v.d,v.a,v.b,v.c}) res++;
	return res;
}
long long n,x,y,z,w,lans,ans;
vector<squ> v;
map<squ,long long> mp;
int main()
{
	scanf("%lld",&n);
	for (long long i=1;i<=n;i++)
	{
		scanf("%lld%lld%lld%lld",&x,&y,&z,&w);
		for (long long j=0;j<v.size();j++)
		{
			squ cur=v[j],a1=(squ){x,w,cur.c,cur.b},a2=(squ){z,y,cur.a,cur.d},a3=(squ){y,x,cur.b,cur.a},a4=(squ){w,z,cur.d,cur.c};
			lans=mp[a1]-eqal(cur,a1);
			lans*=(mp[a2]-eqal(cur,a2)-eqal(a1,a2));
			lans*=(mp[a3]-eqal(cur,a3)-eqal(a1,a3)-eqal(a2,a3));
			lans*=(mp[a4]-eqal(cur,a4)-eqal(a1,a4)-eqal(a2,a4)-eqal(a3,a4));
			ans+=lans;
		}
		v.push_back((squ){x,y,z,w});v.push_back((squ){y,z,w,x});v.push_back((squ){z,w,x,y});v.push_back((squ){w,x,y,z});
		mp[(squ){x,y,z,w}]++;mp[(squ){y,z,w,x}]++;mp[(squ){z,w,x,y}]++;mp[(squ){w,x,y,z}]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 100224
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn insertion_sort(a: &mut Vec<u32>, g: usize) -> usize {
    let mut cnt = 0;
    let n = a.len();
    for i in g..n {
        let v = a[i];
        let mut j = i;
        while j >= g && a[j-g] > v {
            a[j] = a[j-g];
            cnt += 1;
            j -= g;
        }
        a[j] = v;
    }
    cnt
}

fn shell_sort(a: &mut Vec<u32>, g: &[usize]) -> usize {
    let mut cnt = 0;
    for &i in g.iter() {
        cnt += insertion_sort(a, i);
    }
    cnt
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n = sc.read();
    let mut a: Vec<u32> = sc.vec(n);

    let g = {
        let mut g = vec![];
        let mut x = 1;
        while x <= n {
            g.push(x);
            x = x*3 + 1;
        }
        g.reverse();
        g
    };
    let cnt = shell_sort(&mut a, &g);
    println!("{}", g.len());
    println!("{}", g.iter().join(" "));
    println!("{}", cnt);
    println!("{}", a.iter().join("\n"));
}



Measured memory_bytes: 62324
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#define bolt ios::sync_with_stdio(false)
#define ull unsigned long long
#define ll long long
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
using namespace std;

int main() {

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

	bolt;
	cin.tie(nullptr);
	cout.tie(nullptr);
	int a, b; cin >> a >> b; 
	for (int p = 1; p <= 10000000; p++) {
		double c = (p * 8) / 100; double d = (p * 10) / 100;
		if (c == a && d == b) {
			cout << p << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	

	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  
  ll x,n;cin>>x>>n;
  set<ll> se;
  rep(i,0,n){
    ll y;cin>>y;
    se.insert(y);
  }

  rep(i,0,200){
    if(!se.count(x-i)){
      cout<<x-i<<ENDL;
      return 0;
    }

    if(!se.count(x+i)){
      cout<<x+i<<ENDL;
      return 0;
    }
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
signed main(){
    
    
    int n,a[111111];
    cin>>n;
    int max=0,min=INF,ans;
    rep(i,n){
        cin>>a[i];
        max=std::max(max,a[i]);
    }
    rep(i,n){
        if(min>abs(max/2-a[i]) && max!=a[i]){
            min=abs(max/2-a[i]);
            ans=a[i];
        }
    }
    cout<<max<<" "<<ans<<endl;
    
	

}

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

bool contains(vector<int>& a, vector<int>& b) {
    for(int& i : b) {
        if(find(begin(a), end(a), i) == end(a)) return false;
    }
    return true;
}

int main() {
    int n;
    vector<int> p[100];
    vector<int> l;
    while(true) {
        cin >> n;
        if(n == 0) break;
        for(int i = 0; i < n; ++i) {
            int m; cin >> m;
            p[i].resize(m);
            for(int j = 0; j < m; ++j) {
                cin >> p[i][j];
                p[i][j];
            }
        }
        int k; cin >> k;
        l.resize(k);
        for(int i = 0; i < k; ++i) {
            cin >> l[i];
        }

        vector<int> ans = vector<int>();
        for(int i = 0; i < n; ++i) {
            if(contains(p[i], l)) {
                ans.push_back(i);
            }
        }
        cout << (ans.size() == 1 ? ans[0] + 1 : -1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1284
#coding: utf-8
class Scanner(object):
    """docstring for Scanner."""
    s = []
    idx = 0
    separater = ""

    def __init__(self, separater=" "):
        self.separater = separater

    def next(self):
        while self.idx >= len(self.s):
            st = input()
            while st == "":
                st = input()
            self.s = st.split(self.separater)
            self.idx = 0
        self.idx += 1
        return self.s[self.idx - 1]

    def next_int(self):
        return int(self.next())

    def next_float(self):
        return float(self.next())


sc = Scanner()
N = sc.next_int()
M = sc.next_int()
graph = []
for i in range(N):
    graph.append([])
for i in range(M):
    a = sc.next_int() - 1
    b = sc.next_int() - 1

    graph[a].append(b)
    graph[b].append(a)
successed = False

for neighbors in graph[N - 1]:
    for neighbor in graph[neighbors]:
        if neighbor == 0:
            successed = True

if successed:
    print("POSSIBLE")

else:
    print("IMPOSSIBLE")


Measured memory_bytes: 38324
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
#include<utility>
#include<queue>
#define MOD 998244353
using namespace std;
typedef long long ll;
int main(){
    ll n,d[100000],num[100000]={},ans=1LL;
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&d[i]);
        num[d[i]]++;
    }
    if(d[0]!=0||num[0]!=1){
        ans=0;
    }
    for(int i=1;i<n;i++){
        if(num[i]&&num[i-1]==0){
            ans=0LL;
        }
        for(int j=0;j<num[i];j++){
            ans*=num[i-1];
            ans%=MOD;
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 2424