akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

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

    private Scanner scan = new Scanner(System.in);
    private final static long MOD = 1000_000_007L;
    private final int N;
    private final String S1;
    private final String S2;

    public Main() {
	N = Integer.parseInt(scan.next());
	S1 = scan.next();
	S2 = scan.next();

	scan.close();
    }

    public final void answer() {
	long ans = 1;
	Type present = null;
	Type previous = null;

	int index = 0;
	if(N > 1) {
	    previous = classify(index);
	    switch(previous) {
		case HOR:
		    ans = 6;
		    index += 2;
		    break;
		case VER:
		    ans = 3;
		    index++;
		    break;
	    }
	} else {
	    ans = 3;
	    index++;
	}

	for (; index < N; index++) {
	    if(index == N-1) {
		switch(previous) {
		    case HOR:
			break;
		    case VER:
			ans = ans * 2 % MOD;
			break;
		}
	    } else {
		present = classify(index);
		switch(present) {
		    case HOR:
			switch(previous) {
			    case HOR:
				ans = ans * 3 % MOD;
				break;
			    case VER:
				ans = ans * 2 % MOD;
				break;
			}
			index++;
			break;
		    case VER:
			switch(previous) {
			    case HOR:
				break;
			    case VER:
				ans = ans * 2 % MOD;
				break;
			}
			break;
		}
	    }

	    previous = present;
	}
	System.out.println(ans);
    }

    private Type classify(int index) {
	return S1.charAt(index) == S1.charAt(index+1) ? Type.HOR : Type.VER;
    }

    private static enum Type {
	VER,
	HOR,
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int main(){
  int N;
  cin >> N;
  int a[N];
  int b[N];
  int c[N];
  rep(i,N){
    cin >> a[i];
  }
  rep(i,N){
    cin >> b[i];
  }
  rep(i,N-1){
    cin >> c[i];
  }
  int ans = 0;
  rep(i,N){
    ans+=b[a[i]-1];
    if(a[i] + 1 == a[i+1]) ans += c[a[i]-1];
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18

int main()
{
    llong N, K;
    cin >> N >> K;
    if (N < K) {
        llong Nmin1 = abs(N - K);
        // int ans = min(N, Nmin1);
        llong ans;
        if (N < Nmin1) ans = N;
        else ans = Nmin1;
        cout << ans << endl;
        return 0;
    }
    llong Nmin1 = N % K;
    llong Nmin2 = abs(Nmin1 - K);
    llong ans;
    if (Nmin1 < Nmin2) ans = Nmin1;
    else ans = Nmin2;
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#define M 1000000
using namespace std;

int main() {
    int s = 0;
    cin >> s;

    int A[M + 10];
    A[0] = s;
    int m = 0;
    for (int i = 1; i < M + 10 && m == 0; i++) {
        if (A[i - 1] % 2 == 0) A[i] = A[i - 1] / 2;
        else A[i] = 3 * A[i - 1] + 1;

        for (int j = 0; j < i && m == 0; j++) {
            if (A[j] == A[i]) m = i + 1;
        }
    }

    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 1e5 + 100, OO = 100, T = 10, M = 100, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
int a[N];

int32_t main() {
	use_fast;
    string s; 
	cin >> s;
    vector<int> cnt(4, 0);
    for(int i = 0; i < (int)s.size(); i++) {
        if(s[i] == 'N') 
			cnt[0]++;
        if(s[i] == 'S') 
			cnt[1]++;
        if(s[i] == 'W') 
			cnt[2]++;
        if(s[i] == 'E') 
			cnt[3]++;
    }
    if(cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0 && cnt[3] > 0) 
        return cout << "Yes" << endl, 0;
    if(cnt[0] > 0 && cnt[1] > 0 && cnt[2] == 0 && cnt[3] == 0) 
        return cout << "Yes" << endl, 0;
    if(cnt[0] == 0 && cnt[1] == 0 && cnt[2] > 0 && cnt[3] > 0) 
        return cout << "Yes" << endl, 0;
       
    cout << "No" << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



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

int main() {
	// your code goes here
	string S;
	cin >> S;
	
	for(int i=0;i<S.size();i++){
		if(S[i]==',') S[i]=' ';
	}
	cout << S;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#define lli long long int

int main(void)
{
	char s[102];
	scanf("%s", s);

	int i = 0;
	while (s[i] != '\0')
	{
		s[i] = 'x';
		i++;
	}
	printf("%s", s);
	return(0);
}



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

int main() {
  string S;
  cin >> S;
  int ans = 700;
  FOR(i, 0, 3) {
    if (S[i] == 'o') {
      ans += 100;
    }
  }
  cout << ans << endl;

return 0;
}

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

int main(){
    int a[]={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};
    int k;
    cin>>k;
    printf("%d\n", a[k-1]);
    return 0;
    }


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

using namespace std;

#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)

struct Point{
    double x,y;

    Point(){}
    Point(double x,double y) : x(x),y(y) {}

    Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
    Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
    Point operator * (const double &k)const{ return Point(x*k,y*k); }
};

double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }

struct Segment{
    Point s,t;
    Segment(){}
    Segment(Point s,Point t) : s(s),t(t) {}
};

typedef Point Vector;

bool isOrthogonalSS(const Segment &s1,const Segment &s2){
    Vector a = s1.t-s1.s;
    Vector b = s2.t-s2.s;
    return equal(dot(a,b),0);
}

bool isParallelSS(const Segment &s1,const Segment &s2){
    Vector a = s1.t-s1.s;
    Vector b = s2.t-s2.s;
    return equal(cross(a,b),0);
}

int main(){
    int Q;
    Segment s1,s2;
    cin >> Q;
    while(Q--){
        cin >> s1.s.x >> s1.s.y >> s1.t.x >> s1.t.y;
        cin >> s2.s.x >> s2.s.y >> s2.t.x >> s2.t.y;
        if(isParallelSS(s1,s2)){
            cout << 2 << endl;
        }else if(isOrthogonalSS(s1,s2)){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;
}

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

const int N = 1e3L + 11;
int a[N], b[N], f[N][N];

void upd(int &x, int y) { if(x > y) x = y; }

int main() {
	ios :: sync_with_stdio(0);
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= m; i ++) cin >> b[i];

	memset(f, 0x3f, sizeof f); f[0][0] = 0;
	for(int i = 0; i <= n; i ++)
		for(int j = 1; j <= m; j ++) {
			upd(f[i][j], f[i][j - 1]);
			if(i) upd(f[i][j], f[i - 1][j - 1] + a[i] * b[j]);
		}
	cout << *min_element(f[n], f[n] + m + 1) << '\n';
}

Measured memory_bytes: 7176
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<Edge>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

struct Edge{
    int v, w;
    Edge(){}
    Edge(int v0, int w0){
        v = v0;
        w = w0;
    }
};

int main(){
    int N;
    cin >> N;
    Graph G(N);
    rep(i, N - 1){
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        w %= 2;

        Edge e(v, w);
        G[u].push_back(e);

        e.v = u;
        G[v].push_back(e);
    }

    vector<int> color(N, -1);
    queue<int> que;
    que.push(0);
    color[0] = 0;

    while(!que.empty()){
        int u = que.front();
        que.pop();
        for(Edge e : G[u]){
            if(color[e.v] != -1) continue;
            color[e.v] = (color[u] + e.w) % 2;
            que.push(e.v);
        }
    }

    for(int i : color){
        cout << i << endl;
    }
}

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

void printArray(vector<int> A)
{
    for(int i = 0; i < A.size(); i++)
    {
        cout<<A[i]<<" ";
    }
    cout<<endl;
}

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

    vector<int> ht(n);
    vector<int> dp(n);

    for(int i = 0; i < n; i++)
    {
        int tmp;
        cin>>tmp;
        ht[i] = tmp;
    }

    dp[0] = 0;
    // dp[1] = abs( ht[1] - ht[0] );

    for(int i = 1;  i < n; i++)
    {
        dp[i] = dp[i-1] + abs(ht[i] - ht[i-1]);
        for(int j = i-2; j >= max(i-k, 0); j--)
        {
            dp[i] = min( dp[i], dp[j] + abs( ht[i] - ht[j] ) );
        }
    }
    // printArray(dp);
    cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1024
S = list(input())

left = int(''.join(S[0:2]))
right = int(''.join(S[2:4]))

if (left > 0 and left < 13) and (right > 0 and right < 13):
  print('AMBIGUOUS')
elif left >= 0 and (right > 0 and right < 13):
  print('YYMM')
elif (left > 0 and left < 13) and right >= 0:
  print('MMYY')
else:
  print('NA')
  

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string S;
  cin >> S;
  rep(i,S.size()) cout << "x";
  cout << endl;
  return 0;
}

Measured memory_bytes: 3120
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		while(true) {
			String line = sc.nextLine();
			if(line.equals("END OF INPUT")) break;

			ArrayList<Integer> al = new ArrayList<Integer>();

			for(int i = 0; i < line.length(); i++) {
				int p = 0;
				while(i + p != line.length() && line.charAt(i + p) != ' ') p++;
				al.add(p);
				i += p;
			}
			for(int n : al) {
				System.out.print(n);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
# https://atcoder.jp/contests/abc149/tasks/abc149_b


A, B, K = gets.split.map(&:to_i)

a, b = (
  if K >= A + B
    [0, 0]
  elsif K >= A
    [0, B + A - K]
  else
    [A - K, B]
  end
)
puts "#{a} #{b}"


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  int c;
  cin >> a >> b;
  c=a+b;
  if(c%2==0)
    cout << c/2 << endl;
  else
    cout << (c/2)+1 << endl;
}

    
    
  
  

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

using ll=long long;

int main() {
  int N; cin >>N;
  vector<int> a(N);
  rep(i,0,N) {
    cin >>a[i];
  }
  int b=accumulate(a.begin(),a.end(),0);
  int ans=0;
  int c=INT_MAX;
  rep(i,0,N) {
    int d=abs(N*a[i]-b);
    if (d<c) {
      c=d;
      ans=i;
    }
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3624
s = input()
a = 'AKIHABARA'
a = list(a)
idxs = [0, 4, 6, 8]
for i in range(2**4):
    for j in range(4):
        a[idxs[j]] = 'A' if i>>j&1 else ''
        if s==''.join(a):
            print('YES')
            exit(0)
print('NO')

Measured memory_bytes: 9072
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;

int main() {
  long long X;
  cin >> X;
  long long tmp = 100;
  int cnt = 0;
  while(true) {
    long long p = tmp / 100;
    // tmp = floor(tmp);
    cnt++;
    if(tmp >= X - p) {
      cout << cnt << endl;
      break;
    }
    tmp += p;
  }
  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	while (b) {
		int r = a % b; a = b; b = r;
	}
	return a;
}
void solve() {
	int n; cin >> n;
	vector<int> a(n);
	vector<int> le(n);
	rep(i, n)cin >> a[i];
	int g = 0;
	rep(i, n) {
		le[i] = g;
		g = gcd(g, a[i]);
	}
	int ans = 0;
	int ri = 0;
	per(i, n) {
		ans = max(ans,gcd(le[i], ri));
		ri = gcd(ri, a[i]);
	}
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

Measured memory_bytes: 1024
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,m = m()

if m == 1 or 2*n-1 == m:
    print("No")
else:
    print("Yes")
    if n == 2:
        ans = [1,2,3]
        for i in range(2*n-1):
            print(ans[i])
    else:
        if m == 2:
            a = [3,2,1,4]
            ans = [i + 5 for i in range(n-2)] + a + [i + n+3 for i in range(n-3)]
        else:
            a = [m-1,m,m+1,m-2]
            i = 0
            ans = []
            for j in range(2*n-4):
                i += 1
                if j == n-2:
                    ans += a
                    i -= 1
                else:
                    if i == m-2:
                        i += 4
                    ans.append(i)
        for i in range(2*n-1):
            print(ans[i])





Measured memory_bytes: 52720
#include "bits/stdc++.h"
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target ("avx,avx2")

using namespace std;

using ll = long long;
#define all(x) begin(x), end(x)

void solve(){

}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for(int i{}; i<n-2; ++i){
		int a,b; cin >> a >> b;
		if(a==b){
			cin >> a >> b;
			i++;
			if(a==b){
				cin >> a >> b;
				i++;
				if(a==b){
					cout << "Yes" << "\n";
					return 0;
				}
			}
		}
	}

	cout << "No" << "\n";

}


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

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

void run(void){
  int n;
  scanf("%d",&n);
  int a[100000];
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  qsort(a,n,sizeof(int),cmp);

  int x,y;
  x=y=0;
  for(i=n-1;i-1>=0;i--){
    if(a[i]==a[i-1]){
      x=a[i];
      break;
    }
  }
  for(i=i-2;i-1>=0;i--){
    if(a[i]==a[i-1]){
      y=a[i];
      break;
    }
  }
  printf("%lld\n",(int64)x*y);
  return;
}

int main(void){
  run();
  return 0;
}


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

signed main(){

  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;

  int ans = n+1;
  int l=0,r=0;
  set<int> st;
  map<int,int> mp;
  for(;l<n;++l){
    bool f = (r<n)&&(st.size()!=k);
    while(f){
      if(a[r]<=k)st.emplace(a[r]);
      mp[a[r]]++;
      r++;
      f = (r<n)&&(st.size()!=k);
    }
    if(st.size()==k){
      ans = min(ans,r-l);
    }
    mp[a[l]]--;
    if(mp[a[l]]==0)st.erase(a[l]);
  }
  cout<<(ans==n+1?0:ans)<<endl;

}


Measured memory_bytes: 12512
/*In the name of ALLAH, Most Gracious, Most Merciful*/
#include<bits/stdc++.h>

#define ll                      long long int
#define ull                     unsigned long long int
#define PI                      2*acos(0.0)
#define sqr(x)                  (x)*(x)
#define EPS                     10E-10
#define MOD                     1000000007
#define longlimit               92233720368547758
#define infinity                (1<<28)
#define bitcount                __builtin_popcount
#define pb(a)                   emplace_back(a)
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define gcd(a, b)               __gcd(a,b)
#define lcm(a, b)               ((a)*(b))/gcd(a,b)
#define watch(x)                cout << (#x) << " is " << (x) << endl
#define all(a)                  (a.begin()),(a.end())
#define UNIQUE(X)               (X).erase(unique(all(X)),(X).end())
#define DELETE(X)               (X).erase (remove (all(X)),(X).end())
#define SORT_UNIQUE(c)          (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
using namespace std;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ull n,k,rem,t;
    cin>>n>>k;
    rem=n%k;
    t=k-rem;
    cout<<min(rem,t);

}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;

    vector<int> ans(n, -1);

    for(int i = 0; i < m; i++){
        int s, c; cin >> s >> c;

        if(ans[s-1] != -1 && ans[s-1] != c){
            cout << "-1" << endl;
            return 0;
        }

        if(n > 1 && s == 1 && c== 0){
            cout << "-1" << endl;
            return 0;
        }

        ans[s-1] = c;
    }

    if(n==1){
        if(ans[0] == -1) cout << "0";
        else cout << ans[0];
    } else {
        for(int i = 0; i < n; i++){
            if(ans[i] == -1){
                if(i == 0) ans[i] = 1;
                else ans[i] = 0;
            }
            cout << ans[i];
        }
    }
    
    cout << endl;

    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

/*int dp[1000][1000];

void f(int i, int j){
    if(dp[i][j] != 0) return;
    for(int k = 1; k * 2 <= i; k++){
        f(i - 2 * k, j + k);
        if(dp[i - 2 * k][j + k] == -1){
            dp[i][j] = 1;
            return;
        }
    }
    for(int k = 1; k * 2 <= j; k++){
        f(i + k, j - 2 * k);
        if(dp[i + k][j - 2 * k] == -1){
            dp[i][j] = 1;
            return;
        }
    }
    dp[i][j] = -1;
    return;
}*/

int main() {
    //cout.precision(10);
    /*dp[0][0] = -1;
    dp[1][0] = -1;
    dp[0][1] = -1;
    dp[1][1] = -1;
    for(int i = 0; i <= 10; i++){
        for(int j = 0; j <= 10; j++){
            f(i, j);
        }
    }
    for(int i = 0; i <= 10; i++){
        for(int j = 0; j <= 10; j++){
            cout << dp[i][j] << " " ;
        }
        cout << endl;
    }*/
    ll x, y;
    cin >> x >> y;
    if(abs(x - y) <= 1) cout << "Brown" << endl;
    else cout << "Alice" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,d,ans;
	cin >> n >> d >> ans;
	rep(i,0,n){
		int a;
		cin >> a;
		ans += (d-1)/a + 1;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
int S [512345];
int main() {
    int N;
    int left =212345 , right = left +1;
    cin >> N;
    vector<int> A(N);
    
    rep(i, 0, N){
        cin >> A[i];
    }
    rep(i, 0, N){
        if (i%2 == (N-1)%2){
            S[left--] = A[i];
        } else {
            S[right++] = A[i];
        }
    }
    for(int i = left+1; i<right; i++){
        cout << S[i] << " ";
    }
    
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  long long N, K;
  cin >> N >> K;
  long long count = N / K;
  long long ans = abs(N - count * K);
  ans = min(ans, abs(N - (count - 1) * K));
  ans = min(ans, abs(N - (count + 1) * K));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  f               first
#define  s               second
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"\n";
#define  deb2(a,b)       cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD        =  1e+9 + 7;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

ll n, a[N];
string s;


void MAIN(int tc){
      cin>>n;
      cout<<(n^1);
}

int main(){
    ios:: sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr);
    cout<<fixed; cout<<setprecision(10);

    int test_cases = 1;
    //cin>>test_cases;
    for(int i = 1; i <= test_cases; i++){
        MAIN(i);
    }
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        double a = s.nextDouble();
        double b = s.nextDouble();
        double x = s.nextDouble() / a;
        double S = a * b;
        double h;
        if (x <= S/2) {
            h = x / b * 2.0D;
            System.out.println(90 - Math.toDegrees(Math.atan2(h,b)));
        } else {
            h = (S-x) / a * 2.0D;
            System.out.println(Math.toDegrees(Math.atan2(h,a)));
        }
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
const int max_N=1e5+10;
ll N,M;
bool visited[200010];
vector<int> edge[200010];


void dfs(int start)
{
  visited[start]=true;
  //cout << "Now : " <<start << endl; 
  for(int i=0;i<int(edge[start].size());i++)
    {
      if(visited[edge[start][i]]) continue;
      else
	{
	  dfs(edge[start][i]);
	}
    }
  return;
}

int main(void)
{
  memset(visited,false,sizeof(visited));
  cin >> N >> M;
  for (int i = 1; i <= N; ++i)
    {
      ll lannum;
      ll language;
      cin >> lannum;
      for (int j= 0; j < lannum; ++j)
	{
	  cin >> language;
	  edge[i].push_back(language+100000);
	  edge[language+100000].push_back(i);
	}
    }
  dfs(1);
  for(int i=1;i<=N;i++)
    {
      if(!visited[i])
	{
	  cout << "NO" << endl;
	  return 0;
	}
    }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 8960
def solve():
  N = int(input())
  k = 1
  while N>pow(26,k):
    N -= pow(26,k)
    k += 1
  ans = ''
  N -= 1
  for i in range(k,0,-1):
    if i>1:
      ans += chr(ord('a')+N//pow(26,i-1))
    else:
      ans += chr(ord('a')+N%pow(26,i))
    N%=pow(26,i-1)
  return ans
print(solve())

Measured memory_bytes: 9164
import sys

def gcd(a,b):
	temp = a
	if a<b:
		a=b
		b=temp
	if b==0:
		return a
	c = a%b
	return gcd(b,c)


line = sys.stdin.readline().strip().split(" ")
A = int(line[0])
B = int(line[1])

print(gcd(A,B))

Measured memory_bytes: 6440
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))
    lc= 10**6

    for i in range(N):
        c = T - H[i] * 0.006
        if abs(A-c)<lc:
            lc=abs(A-c)
            n= i

    print(n+1)




if __name__ == "__main__":
    main()


Measured memory_bytes: 62380
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iostream>
#include <numeric>
#include <random>
#include <set>
#include <unordered_set>
#include <vector>
#include <list>
#include <functional>

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

using namespace std;

#define LOCAL 1

#if LOCAL
#define pv(val) cerr << #val << " = " << (val) << endl
#define pvn(name, val) cerr << name << " = " << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#else
#define pv(val)
#define pvn(name, val)
#define pl
#endif

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
    if (vec.empty()) {
        os << "{}";
    }
    else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
    if (arr.empty()) {
        os << "{}";
    }
    else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U> const& p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T, class U>
pair<T, U> operator+(pair<T, U> const& lhs, pair<T, U> const& rhs) {
    return { lhs.first + rhs.first, lhs.second + rhs.second };
}

template<class T, class U>
pair<T, U> operator-(pair<T, U> const& lhs, pair<T, U> const& rhs) {
    return { lhs.first - rhs.first, lhs.second - rhs.second };
}

template<class T, class U>
U lowerBound(function<T(U)> f, T const& val, U l, U r) {
    while (l < r) {
        auto m = l + (r - l) / 2;
        auto fm = f(m);
        if (fm < val) {
            l = m;
        }
        else {
            r = m;
        }

    }
}

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};


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

    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int ans = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            ans = max(ans, abs(A[i] - A[j]));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		String s = sc.next();
		
		System.out.println( s.substring(0,K-1)+s.substring(K-1, K).toLowerCase()+s.substring(K,N));
	}
}


Measured memory_bytes: 22228
///17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define pb          push_back
#define MP          make_pair
#define int         long long
#define ll          long long
#define inf         0x3f3f3f3f
#define MOD         1000000007
#define ld          long double
#define eb          emplace_back
#define pii         pair<int,int>
#define ull         unsigned long long
#define all(v)      v.begin(), v.end()
#define f(i,x,n)    for(int i=x;i<n;i++)
#define fr(i,x,n)   for(int i=x;i>=n;i--)
#define fastio      ios::sync_with_stdio(false)

#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define debug(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl

void IO() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
int solve(int val) {
	int x = (sqrt(1 + 8 * val) - 1) / 2;
	return x;
}
int32_t main() {
    //IO();
    fastio;
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n; cin >> n;
    int res = 0;
    for (int i = 2; i * i <= n; i++) {
    	int cnt = 0;
    	while (n % i == 0) {
    		n /= i;
    		cnt++;
    	}
    	if (cnt) {
    		res += solve(cnt);
    	}
    }
    if (n > 1) {
    	res++;
    }
    cout << res << endl;
    

    return 0;
}


Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin  >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    if (n%2==1) {
        int medi = (n+1)/2-1;
        cout << (b[medi]-a[medi]+1) << endl;
    } else {
        int medi1 = n/2-1;
        int medi2 = n/2;
        
        int minm = (a[medi1]+a[medi2]);
        int maxm = (b[medi1]+b[medi2]);
        cout << (maxm-minm+1) << endl;
    }
    return 0;
}

Measured memory_bytes: 4848
S = input()
N = len(S)
a = 0
b = 0
ans = 0
for i in range(0,N,2):
    if S[i] == '0':
        a += 1
    else:
        b += 1
for i in range(1,N,2):
    if S[i] == '1':
        a += 1
    else:
        b += 1
c = max(a,b)
if c == a:
    for i in range(0,N,2):
        if S[i] != '0':
            ans += 1
    for i in range(1,N,2):
        if S[i] != '1':
            ans += 1
else:
    for i in range(0,N,2):
        if S[i] == '0':
            ans += 1
    for i in range(1,N,2):
        if S[i] == '1':
            ans += 1
print(ans)

Measured memory_bytes: 9144
n = int(input())
alphabet = list('abcdefghijklmnopqrstuvwxyz')
ans = [100]*26

for i in range(n):
  S = list(input())
  tmp = [0]*26
  for j in range(len(S)):
    for k in range(26):
      if(S[j] == alphabet[k]): tmp[k] += 1
  for j in range(26):
    if(ans[j] > tmp[j]): ans[j] = tmp[j]
   
ans_str = ''
for i in range(26):
  for j in range(ans[i]):
    ans_str += alphabet[i]
print(ans_str)

Measured memory_bytes: 3064
abcd = input()
answers =[]

for i in range(2**3):
    a = int(abcd[0])
    b = int(abcd[1])
    c = int(abcd[2])
    d = int(abcd[3])
    plus_minus = [1,1,1]
    for j in range(3):
        if (i >> j)& 1:
            plus_minus[j] = -1
    ans = a + b*plus_minus[0] + c*plus_minus[1] + d*plus_minus[2]
    if ans == 7:
        pmw =[]
        for j in range(3):
            if plus_minus[j] == -1:
                pmw.append("-")
            else:
                pmw.append("+")
        print(str(a)+pmw[0]+str(b)+pmw[1]+str(c)+pmw[2]+str(d)+"=7")
        break
        

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

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define var auto
#define MOD 1000000007


typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;


int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin) ;
    char c; cin>>c;
    cout<<(c=='a'||c=='e'||c=='i' || c=='o' || c=='u'? "vowel":"consonant");
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

public class OrdinaryNumber {
    public static void Main(string[] argc){
        int length = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int[] arr = input.Select(x => int.Parse(x) ).ToArray();

        int count = CountSecondarySmall(arr, length);
        Console.WriteLine(count);
    }

    public static int CountSecondarySmall(int[] numArr, int length){
        int count=0;
        for(int i=2; i<length; i++){
            int first = numArr[i-2];
            int second = numArr[i-1];
            int third = numArr[i];
            bool isSecondIsCenter = (first < second && second < third ) || (third < second && second < first);
            if (isSecondIsCenter) count++;
        }
        return count;
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

int main(){
    string s;cin>>s;
    s+='z';
    int N=s.size();
    int i=0;ll ans=0;
    while(i<N){
        while(s[i]!='A' && i<N) i++;
        int count=0;
        while(i<N){
            if(s[i]=='A'){
                count++;
                i++;
            }
            else if(s[i]=='B' && s[i+1]=='C'){
                ans+=count;
                i+=2;
            }
            else break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
S = input()
T = input()

ans = "z" * 100
for i in range(len(S) - len(T) + 1):
    s = list(S)
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
        s[i+j] = T[j]
    else:
        s = "".join(s).replace("?", "a")
        if s < ans:
            ans = s
if ans == "z" * 100:
    print("UNRESTORABLE")
else:
    print(ans)

Measured memory_bytes: 3064
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;

ll arr[200001];
ll cnt[200001];
ll ans[200001];

vector< int64_t > divisor(int64_t n) {
	vector< int64_t > ret;
	for (int64_t i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}

int main() {
	cin >> N;
	rep(i, N) {
		cin >> arr[i + 1];
		cnt[i + 1] = 0;
	}
	ll count = 0;
	for (int i = N; i > 0; i--) {
		if ((arr[i] == 1) ^ (cnt[i] % 2 == 1)) {
			ans[i] = 1;
			count++;
			auto vec = divisor(i);
			rep(i, vec.size()) {
				cnt[vec[i]]++;
			}
		}
	}
	cout << count << endl;
	rep(i, N) {
		if (ans[i + 1] == 1) cout << i + 1 << " ";
	}
}


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

#define ll long long

using namespace std;

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

	vector<ll> v(n);

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

	vector<ll> dp(n);
	dp[0] = 0;

	for(int i = 1; i < n; i++){
		ll minm = 1e10;
		for(int j = 1; j <= k; j++){
			if(j > i)
				break;
			minm = min(minm, dp[i-j] + abs(v[i] - v[i-j]));
		}
		dp[i] = minm;
	}

	cout << dp[n-1] << "\n";
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<std::string> s)
{
    ll ans = 0;
    map<string, ll> pairs;
    for (size_t i = 0; i < N; i++)
    {
        string tmp = s[i];
        SORT(tmp);
        pairs[tmp]++;
    }

    for (auto &&i : pairs)
    {
        ans += (i.second * (i.second - 1)) / 2;
    }
    cout << ans << endl;
}
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<std::string> s(N);
    for (int i = 0; i < N; i++)
    {
        std::cin >> s[i];
    }
    solve(N, std::move(s));
    return 0;
}


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

int main(){
  int k, a, b;
  cin >> k;
  std::cin >> a >> b;
  int c = a/k;
  int count = k*(c+1);
  if (count <= b) {
    std::cout << "OK" << '\n';
  }
  else if(c*k == a){
    std::cout << "OK" << '\n';
  }
  else{
    std::cout << "NG" << '\n';
  }
  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main()
{
  int a,b,i,kisu=0,count=0;
  scanf("%d %d",&a,&b);
  if((a+b)%2==1)i=(a+b)/2+1;
  else i=(a+b)/2;
  printf("%d",i);
  return 0;
}


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

mt19937::result_type seed = chrono::steady_clock::now().time_since_epoch().count();
auto rng = std::bind(std::uniform_real_distribution<double>(0,1), mt19937(seed));

#define watch(x) cout << (#x) << " = " << (x) << endl
#define PI double(2 * acos(0.0))
#define LL long long
#define MOD 1000000007
#define PB push_back 
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define PPIII pair < pair <int, int> , int>
#define PIPII pair < int, pair <int, int> >

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long n, w;
    cin >> n >> w;
    long long array[n][2];
    for(int i = 0; i < n; i++)  {
        cin >> array[i][0] >> array[i][1];
    }
    LL dp[w + 1][n];
    for(int i = 0 ; i < n; i++) {
        dp[0][i] = 0;
    }
    for(int i = 0; i <= w; i++) {
        if(i >= array[0][0]) {
            dp[i][0] = array[0][1];
        }
        else    {
            dp[i][0] = 0;
        }
    }
    for(int i = 1; i <= w; i++) {
        for(int j = 1; j < n; j++)  {
            dp[i][j] = dp[i][j - 1];
            if(i >= array[j][0])    {
                dp[i][j] = max(dp[i][j], dp[i - array[j][0]][j - 1] + array[j][1]);
            }
        }
    }
    /*for(int i = 0; i <= w; i++) {
        for(int j = 0; j < n; j++)  {
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }*/
    cout << dp[w][n - 1];
    return 0;
}


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

void print_array(int A[], int N) {
  for(int i = 0; i < N-1; ++i) {
    std::cout << A[i] << " ";
  }
  std::cout << A[N-1] << std::endl;
  return;
}

int count;

void selectionSort(int A[], int N) {
  for(int i = 0; i < N; ++i) {
    int minj = i;
    for(int j = i; j < N; ++j) {
      if( A[j] < A[minj] ) {
        minj = j;
      }
    }
    if( A[i] != A[minj] ) {
      std::swap(A[i], A[minj]);
      count += 1;
    }
  }
  return;
}


int main(void) {

  int N;
  int A[128];

  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }

  selectionSort(A, N);
  print_array(A, N);
  std::cout << count << std::endl;
  
  return 0;
}

Measured memory_bytes: 1164
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);
//a=atoi(S.c_str());
//S=to_string(a);
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<max(c-a+b,0)<<endl;
}

Measured memory_bytes: 256
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [n] = input[0].split(" ").map((x: number): number => +x);
const [s] = input[1].split(" ").map((x: string): string => x);
const [k] = input[2].split(" ").map((x: number): number => +x);

const v = s[k-1];
const out = Array(n).fill().reduce((acc, current, i, a)=>{
  if(s[i] === v){
    return acc + v
  }
  return acc+'*'
}, '');

console.log(out)


Measured memory_bytes: 7372
#include <stdio.h>
#include <math.h>

int main(){
	int a, b, c, x, p;
	//double x, p;
	scanf("%i %i %i", &a, &b, &c);
	p=(a+b+c)/2;
	x=p*(p-a)*(p-b)*(p-c);
	x=sqrt(x);
	printf("%i\n", x);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
int gcd(int x, int y) {
    int r;
    while (y > 0) {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
/* main */
int main(){
    int K;
    cin >> K;
    int ans = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                ans += gcd(i, gcd(j, k));
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3636