akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define For(i,a,b) for(long long (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll M = 1000000007;
const ll MOD_9 = 998244353;

vector<char> boin = {'a','i','u','e','o'};
vector<char> alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

vector<ll> fac(200001); //n!(mod M)
vector<ll> ifac(200001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0;i < 200000;i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    int N,K;
    cin >> N >> K;
    vector<ll> A(N);
    vector<ll> sum(N+1);
    //vector<ll> ncr(N+1);
    sum[0] = 0;
    Rep(i,N)cin >> A[i];
    sort(All(A));
    Rep(i,N){
        sum[i+1] = sum[i] + A[i];
        sum[i+1] %= M; 
    }
    ll ans = 0;
    ll cnt = 0;
    if(K == 1);
    else{
        For(i,K-2,N-1){
            ll add = (sum[N]-sum[i+1]-sum[N-i-1])*comb(i,K-2);
            add %= M;
            ans += add;
            ans %= M;
        }
    }
    //cout << cnt << endl;
    cout << ans << endl;
    //cin >> N;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
const int maxn=2e5+50;
int N;
int a[maxn];
int an[maxn];
int head[maxn];
int root[maxn];
map<int,int> f[maxn];
struct edge
{
	int to,nex;
	edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
inline void addedge(int u,int v)
{
	G.push_back(edge(v,head[u])),head[u]=G.size()-1;
	G.push_back(edge(u,head[v])),head[v]=G.size()-1;
}
int dp(int u,int x,int fa)
{
	if(f[u].count(x)) return f[u][x];
	f[u][x]=0;
	for(int i=head[u];~i;i=G[i].nex)
	{
		int v=G[i].to;
		if(v!=fa)
		{
			if(v<=x) f[u][x]+=dp(v,x,u)+1;
		}
	}
	return f[u][x];
}
void dfs(int u,int fa)
{
	for(int i=head[u];~i;i=G[i].nex)
	{
		int v=G[i].to;
		if(v!=fa)
		{
			a[v]=max(a[u],u); 
			dfs(v,u);
		}
	}
	if(u==1) return;
	if(u>a[fa]) an[u]=dp(u,a[u],fa)+1;
	else an[u]=dp(u,a[u],fa)-dp(u,a[fa],fa);
}
void pushdown(int u,int fa)
{
	for(int i=head[u];~i;i=G[i].nex)
	{
		int v=G[i].to;
		if(v!=fa)
		{
			an[v]+=an[u];
			pushdown(v,u);
		}
	}
}
void solve()
{
	dfs(1,-1);
	pushdown(1,-1);
}
int main()
{
	scanf("%d",&N);
	memset(head,-1,sizeof(head));
	for(int i=1;i<N;++i)
	{
		int u,v; scanf("%d%d",&u,&v);
		addedge(u,v);
	}
	solve();
	for(int i=2;i<=N;++i)
	{
		if(i!=2) printf(" ");
		printf("%d",an[i]);
	}
	printf("\n");
	return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

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

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

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue< pair< int, int > > que;
  for(int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    que.emplace(-a, b);
  }
  int64 ret = 0;
  while(M > 0) {
    auto p = que.top();
    que.pop();
    ret -= 1LL * min(M, p.second) * p.first;
    M -= p.second;
  }
  cout << ret << endl;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
const int mod=998244353;
inline int dec(int x){return x<0?x+mod:x;}
inline int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}return ans;
}
int fac[10000010],inv[10000010];
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	fac[0]=1;
	int n=read(),ans=power(3,n);
	for(int i=1;i<=n;i++)fac[i]=1LL*fac[i-1]*i%mod;inv[n]=power(fac[n],mod-2);
	for(int i=n;i>=1;i--)inv[i-1]=1LL*inv[i]*i%mod;
	for(int i=n/2+1;i<=n;i++)ans=dec(ans-2LL*inv[i]*power(2,n-i)%mod*inv[n-i]%mod*fac[n]%mod);
	pr2(ans);
	return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
//long long…2^64-1 = 9223372036854775807まで

void _main() {
	int N;
	cin >> N;
	string ans = "NO";

	vector<int> P(N);
	vector<int> P2(N);
	rep(i, 0, N) {
		cin >> P[i];
		P2[i] = P[i];
	}

	sort(P2.begin(), P2.end());

	int count = 0;
	//違うところが「無し」か「２つ」ならYES
	rep(i, 0, N) {
		if (P[i] != P2[i]) count++;
	}
	if (count == 0 || count == 2) ans =  "YES";

	cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int min(int a[], int n);

int min(int a[], int n){
        int j,i;
        i=0;
        for (j=1;j<n;j++){
        if (a[i]>a[j]){
                i = j;
        }}
        return i;
}        

int main(){
        int n, i, t;
        float s;
        s = 0;
        cin >> n;
        int a[n];
        int k[n];
        for (i=0;i<n;i++){
                cin >> a[i];
        }
        for (i=0;i<n;i++){
                t = min(a,n);
                k[i] = a[t];
                a[t] = 9999;
        }
        s = (double)(k[0] + k[1]) / 2.0;
        if (n!=2){
        for (i=2; i<n;i++){
                s = ( s + (double)k[i]) / 2.0;
        }}
        cout << s;
}


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

int main() {
	int n;
	cin>>n;
	vector<int> v, dp(n, 0);
	int temp;
	for(int i=0;i<n;i++) {
		cin>>temp;
		v.push_back(temp);
	}
	if(n==1) {
		cout<<0<<endl;
		return 0;
	} else if(n==2) {
		cout<<abs(v[1]-v[0])<<endl;
		return 0;
	}
	dp[0] = 0;
	dp[1] = abs(v[0]-v[1]);
	for(int i=2;i<n;i++) {
		dp[i] = min(abs(v[i] - v[i-2]) + dp[i-2], abs(v[i]-v[i-1]) + dp[i-1]);
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define mod (int)(1e9 + 7) 
int main() 
{ 
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll l,r;
    cin>>l>>r;
    if((l-1)/2019 != (r-1)/2019)
    {
        cout<<0;
        return 0;
    }
    else
    {
        l=l%2019,r=r%2019;
        ll ans=2018;
        for(ll i=l;i<=r;i++)
        {
            for(ll j=i+1;j<=r;j++)
            ans=min(ans,(i*j)%2019);
        }
        cout<<ans;
    }
    return 0;
} 


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

void print(void);
void reverse(void);
void replace(void);

char str[1000];
int a, b;

int main(){
    int i, q;
    char tmp[20];
    scanf("%s%d", str, &q);
    for(i=0; i<q; i++){
        scanf("%s%d%d", tmp, &a, &b);
        if(!strcmp(tmp, "print")) print();
        else if(!strcmp(tmp, "reverse")) reverse();
        else if(!strcmp(tmp, "replace")) replace();
    }
    return 0;
}

void print(void){
    int i;
    for(i=a; i<=b; i++) printf("%c", str[i]);
    printf("\n");
}

void reverse(void){
    int i, j;
    char c;
    for(i=a, j=b; i<j; i++, j--){
        c = str[i];
        str[i] = str[j];
        str[j] = c;
    }
}

void replace(void){
    int i;
    char c;
    for(i=a; i<=b; i++){
        scanf(" %c", &c);
        str[i] = c;
    }
}

Measured memory_bytes: 572
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

signed main() {
	int a, b;

	cin >> a >> b;
	int k;
	cin >> k;

	int c = 1;
	for(int i = 100; ; i--) {
		if (a % i == 0 && b % i == 0) {
			if (c == k) {
				cout << i << endl;
				return 0;
			}
			c++;
		}
	}



	return 0;
}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, i;
    cin >> N >> i;
    cout << N-i+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define js ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using ll=long long;
using namespace std;
signed main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ss[4];
    ss[0]=a*c;
    ss[1]=a*d;
    ss[2]=b*c;
    ss[3]=b*d;
    sort(ss,ss+4);
    cout<<ss[3];
    



    return 0;
}

Measured memory_bytes: 3640
# include <cstdio>

int main() {
  long long int x,i,sum = 100; scanf("%lld",&x);
  for(i = 0;;i++) {
    sum *= 1.01;
    if( sum >= x ) { break; }
  }
  printf("%lld\n",i+1);
  return 0;
}

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

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

  int x = 0;
  
  for(int i = 0; i < n;i++){
    int l,r;
    cin >>l >>r;
    
    x = x + (r - l)+1;
  }
  
  cout << x <<endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
  int a = 0, i = 0;
  char S[200000] = {0}, T[200000] = {0};
  scanf("%s%s", S, T);
  while (T[i]) {
    if (S[i]!=T[i]) {
      a = a + 1;
    }
    i++;
  }
  printf("%d", a);
  return 0;
}

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

int main(){
  string s;
  cin >> s;

  int l = s.size();
  int cnt = 0;
  rep(i, l/2){
    if(s[i] != s[l-1-i]){
      cnt++;
    }
  }

  cout << cnt << endl;

}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=100005;
int n,k;
int a[N];
int main(){
	n=read(),k=read();
	For(i,1,n)
		a[i]=read();
	sort(a+1,a+n+1);
	int g=a[1];
	For(i,1,n)
		g=__gcd(g,a[i]);
	if (k<=a[n]&&(a[n]-k)%g==0)	
		puts("POSSIBLE");
	else
		puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s; cin >> s;
  reverse(ALL(s));
  s = s + '0';
  lint n = s.size();

  vector<vector<lint>> dp(n + 1, vector<lint> (2, INF));
  dp[0][0] = 0LL;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 2; j++) {
      lint num = (lint)(s[i] - '0');
      { // ぴったりを払う
      lint cost = num;
      if(j == 1) cost++;
      lint nj = 0;
      if(j != 1 or num != 9) dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + cost);
      }
      {
      // 0 にして繰り上げ
      lint cost = (10 - j - num);
      // cerr << "0 にして繰り上げ:" << i << " " << num << " " << cost << endl;
      lint nj = 1;
      dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + cost);
      }
    }
  }
  
  /*
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j < 2; j++) {
      cerr << dp[i][j] << " ";
    }
    cerr << endl;
  }*/
  
  cout << dp[n][0] << endl;
  return 0;
}


Measured memory_bytes: 55900
from bisect import bisect_left
import sys
input = sys.stdin.buffer.readline


n = int(input())
li1 = [0]
li2 = list(map(int, input().split()))
li = li1+li2
count = 0
li.sort()
for i in range(1, n-1):
    for j in range(1, n):
        if j>i:
            k = bisect_left(li, li[i]+li[j])
            if k - j -1> 0:
                count += k - j - 1
print(count)
            

Measured memory_bytes: 43356
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int x;
  cin >> x;
  cout << (x >= 30 ? "Yes" : "No");
}
#endif


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <stdio.h>
#include <cmath>
#include <limits.h>
using namespace std;

typedef long long ll;

#define min(a, b) (((a) < (b))? (a):(b))
#define max(a, b) (((a) > (b))? (a):(b))
#define REP(i, a, n) for(int i=(a); i<(n); ++i)
#define rep(i, n) REP(i, 0, (n))
#define square(a) (a)*(a)
#define pb push_back


int main(void) {
    int h,w;
    cin >> h >>w;
    
    string board[50];
    
    rep(i,h) cin >> board[i];
    
    int dx[8] = {1,0,-1,0,1,-1,-1,1};
    int dy[8] = {0,1,0,-1,1,1,-1,-1};
    
    rep(i,h){
        rep(j,w){
            if(board[i][j] == '#') continue;
            
            int ans = 0;
            rep(k,8){
                const int ni = i + dy[k];
                const int nj = j + dx[k];
                
                if(ni<0 or h<=ni) continue;
                if(nj<0 or w<=nj) continue;
                if(board[ni][nj] == '#') ans++;
            }
            
            board[i][j] = char(ans + '0');
        }
    }
    
    rep(i,h) cout << board[i] << endl;
    
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> adjlist(N, vector<int>());
    for (int i=0; i<M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    vector<int> route(N, -1);
    queue<int> que;
    que.push(0);
    while (!que.empty()) {
        int room = que.front(); que.pop();
        for (int neig: adjlist[room]) {
            if (route[neig] != -1) continue;
            route[neig] = room;
            que.push(neig);
        }
    }
    for (int i=1; i<N; i++) {
        if (route[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i=1; i<N; i++) {
        cout << route[i] + 1 << endl;
    }
}

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

int main(){

    int N;
    cin >> N;

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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

ll power(ll x,ll y){
	ll t=1;
	while(y>0){
		if(y%2) y-=1,t=t*x%mod;
		else y/=2,x=x*x%mod;
	}
return t;
}

char s[N];
int ans[N];

int main(){
	int n,check;
	scanf("%d",&n);
	scanf("%s",s);
	REP(i,4){
		ans[0]=i%2;
		ans[1]=i/2;
		if (s[0]=='o'){
			if (!ans[0]) check=ans[1];
			else check=1-ans[1];
		} else{
			if (!ans[0]) check=1-ans[1];
			else check=ans[1];			
		}
		REPP(j,2,n){
			if (!ans[j-1]){
				if (s[j-1]=='o') ans[j]=ans[j-2];
				else ans[j]=1-ans[j-2];
			} else{
				if (s[j-1]=='o') ans[j]=1-ans[j-2];
				else ans[j]=ans[j-2];			
			}
		}
		if (ans[n-1]!=check) continue;
		if (((s[n-1]=='o'&&!ans[n-1])||(s[n-1]=='x'&&ans[n-1]))&&ans[n-2]!=ans[0]) continue;
		if (((s[n-1]=='o'&&ans[n-1])||(s[n-1]=='x'&&!ans[n-1]))&&ans[n-2]==ans[0]) continue;
		REP(j,n) if (ans[j]) printf("W"); else printf("S");
		printf("\n");
		return 0;
	}
	printf("-1\n");
	return 0;
}

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

namespace AtCoderBiginnerContest179
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = int.Parse(Console.ReadLine());
			var target = input % 2 == 0 ? input / 2 - 1 : input / 2;

			var count = 0;
			for (var i = 1; i <= target; i++)
			{
				if(input % i == 0)
				{
					count += input / i - 1;
				}
				else
				{
					count += input / i;

				}
			}

			count += input - target - 1;

			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 27528
import math
n,a,b=map(int,input().split())
v=list(map(int,input().split()))

# n,a,b=3,2,2
# v=[2,2,2]

v.sort(reverse=True)
am=0
for i in v[:a]:
    am+=i
maxv=am/a
B=v[a-1]
count=0
k=0
if v[0]==B:
    flag=0
else:
    flag=1

if flag==0:
    for i in range(n):
        if v[i]==B:
            k=i+1
            break
    k1=k
    while  k1<n+1 and v[k1-1]==B:
        count+=1
        k1+=1

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    i=a-k+1 #Bを含める数
    ans=0
    while i<b-k+2 and i<count+1:
        ans+=combinations_count(count,i)
        i+=1


    print(maxv)
    print(ans)

else:
    for i in range(n):
        if v[i]==B:
            k=i+1
            break
    k1=k
    while  k1<n+1 and v[k1-1]==B:
        count+=1
        k1+=1

    def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    i=a-k+1 #Bを含める数
    ans=combinations_count(count,i)
    print(maxv)
    print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();


    void Solve()
    {
        int N = cin.Nextint;
        long K = cin.Nextint;
        var A = cin.Scanint;
        var ans = int.MaxValue;
        int l = 0;
        int r = 0;

        var B = new int[K + 1];
        var remain = (1 + K) * K / 2;
        while (l < N)
        {
            while (r < N)
            {
                if (A[r] <= K)
                {
                    if (B[A[r]] == 0)
                    {
                        remain -= A[r];
                    }
                    B[A[r]]++;
                }
                if (remain == 0)
                {
                    break;
                }
                r++;
            }
            //WriteLine($"l={l},r={r}");
            if (r == N)
            {
                break;
            }

            while (l <= r)
            {
                if (A[l] <= K)
                {
                    B[A[l]]--;
                    if (B[A[l]] == 0)
                    {
                        ans = Math.Min(ans, r - l + 1);
                        remain += A[l];
                        break;
                    }
                }
                l++;
            }
            l++;
            r++;
        }
        Console.WriteLine(ans == int.MaxValue ? 0 : ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return Console.ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}


Measured memory_bytes: 16812
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    CIN(K);
    int ins = 1;
    for(int a = 0;a < N;a++){
        ins += min(ins,K);
    }
    COUT(ins);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<double> a;
  for (int i=0; i<n; i++) {
    int v;
    cin >> v;
    a.push_back(v);
  }
  double x,y;
  for (int i=0; i<n; i++) {
    x = 1/a[i];
    y += x;
  }
  double ans = 1/y;
  cout << ans << endl;
}

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

using namespace std;

int main()
{
    int n,i,j,ar[14];
    cin>>n;
    ar[0]=0;
    ar[1]=1;
    ar[2]=2;
    ar[3]=4;
    ar[4]=6;
    ar[5]=16;
    ar[6]=12;
    ar[7]=64;
    ar[8]=24;
    ar[9]=36;
    ar[10]=48;
    ar[11]=1024;
    ar[12]=60;
    cout<<ar[n]<<endl;


    return 0;

}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main()
{
    while(cin>>n)
    {
        int sum=0;
        ll m=n;
        while(m)
        {
            sum+=m%10;
            m/=10;
        }
        if(n%sum==0)
            puts("Yes");
        else
            puts("No");
    }

}

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

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

    int ans=0;
    for(int i=0; i<n; i++){
        if(N[i] == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3540
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	var num = input[0];
  
    array = {
      'SUN': 7,
      'MON': 6,
      'TUE': 5,
      'WED': 4,
      'THU': 3,
      'FRI': 2,
      'SAT': 1,
    }; 	
  
	//出力
	console.log(array[num]);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7624
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
ll d[200005];
ll t[200005];
int main() {
	int n,m;
	cin >> n ;
	map<int, int>mpa,mpb;
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	cin >> m;
	ll sum = 0;
	for (int j = 0; j < m; j++) {
		cin >> t[j];
	}
	for (int i = 0; i < n; i++) {
		mpa[d[i]]++;
	}
	for (int j = 0; j < m; j++) {
		mpb[t[j]]++;
	}

	for (int i = 0; i < m; i++) {
		int x = t[i];
		if (mpb[x] > mpa[x]) {
			cout << "NO" << endl;
			return 0;
		}
	}
	

	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll  powFac(ll a,ll b,ll m)
{
  ll temp1=1, ans=1;
  if(a<0)temp1=0;
  else {
  for(ll i=1;i<=a;i++)temp1=temp1*i%m;
}
   while(b>0)
   {
    if(b&1)ans=ans*temp1%m;
    temp1=temp1*temp1%m;
    b>>=1;
   }
 return ans;
} 




int main()
{
   
    ll i,j,n,k,flag=0,temp1=0,count=0,temp3=0,m=1000000007;
   cin>>n>>k;

  while(n>0)
  {
    n/=k;
    count++;
  }

  cout<<count<<endl;

 return 0;
  }

Measured memory_bytes: 256
h, w = (int(i) for i in input().split())
a = [input() for i in range(h)]

black_mark_row = set()
black_mark_col = set()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            black_mark_row.add(i)
            black_mark_col.add(j)

for i in range(h):
    flag_line = False
    for j in range(w):
        if i in black_mark_row and j in black_mark_col:
            print(a[i][j],sep="",end="")
            flag_line = True
    if flag_line:
        print()

Measured memory_bytes: 43484
import java.util.*;
import java.io.*;

class Main {
  public static void main(String[] args) throws Exception{
    try (Scanner sc = new Scanner(System.in)){
      String S = sc.next();
      if (S.charAt(0) != 'A'){
        System.out.println("WA");
        return;
      }
      String sub = S.substring(2, S.length()-1);
      int count = 0;
      for (int i = 0; i < sub.length(); i++) {
        if (sub.charAt(i) == 'C') count++;
      }
      if (count != 1) {
        System.out.println("WA");
        return;
      }
      S = S.replace("A", "");
      S = S.replace("C", "");
      for (int i = 0; i < S.length(); i++) {
        if (Character.isUpperCase(S.charAt(i))) {
          System.out.println("WA");
          return;
        }
      }
      System.out.println("AC");
    }
  }
}


Measured memory_bytes: 22740
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let mut v: Vec<i64> = read_vec();
    let n = v[0] as usize;
    let k = v[1];
    let mut a = vec![0; n];
    for i in 0..n {
        a[i] = read::<i64>();
    }
    let a = a.iter().map(|&num| num - k).collect::<Vec<_>>();
    let mut sums = vec![-k; n + 1];
    for i in 1..n + 1 {
        sums[i] = sums[i - 1] + a[i - 1];
    }

    let indexes = argsort(&sums).iter().map(|&x| x).collect::<Vec<_>>();
    let mut c = vec![0; n + 1];
    for i in 0..n + 1 {
        c[indexes[i]] = n + 1 - i;
    }

    let mut bt = BinaryIndexTree::new(indexes.len());
    let mut ans = 0;
    for i in 0..indexes.len() {
        ans += i - bt.sum(c[i]) as usize;
        bt.add(c[i] as usize, 1);
    }
    println!("{:?}", ans);
}

fn argsort<T: std::cmp::Ord + std::marker::Copy>(v: &Vec<T>) -> Vec<usize> {
    let mut sort_v = Vec::new();
    for i in 0..v.len() {
        sort_v.push((v[i], i));
    }
    sort_v.sort();
    sort_v.iter().map(|x| x.1).collect::<Vec<usize>>()
}

struct BinaryIndexTree {
    bit: Vec<i64>,
    n: usize,
}

impl BinaryIndexTree {
    fn new(n: usize) -> BinaryIndexTree {
        BinaryIndexTree {
            bit: vec![0; n + 1],
            n: n,
        }
    }

    fn sum(&self, i: usize) -> i64 {
        assert!(i > 0);
        let mut i = i;
        let mut s = 0i64;
        while i > 0 {
            s += self.bit[i];
            i -= (i as i64 & -(i as i64)) as usize;
        }
        s
    }

    fn add(&mut self, i: usize, x: i64) {
        assert!(i > 0);
        let mut i = i;
        while i <= self.n {
            self.bit[i as usize] += x;
            i += (i as i64 & -(i as i64)) as usize;
        }
    }
}


Measured memory_bytes: 17520
n,q=map(int,input().split())
l=list(input())
p=[]
for i in range(q):
    p.append(list(map(str,input().split())))

def solve(x):
    cs=l[x]
    ci=x
    for s,rl in p:
        if cs==s:
            if rl=='L':
                ci-=1
            else:
                ci+=1
        if ci==-1:
            return -1
        if ci==n:
            return 1
        cs=l[ci]
    return 0
        
ok=n
ng=0
while ok-ng>1:
    m=(ok+ng)//2
    s=solve(m)
    if s==-1:
        ng=m
    else:
        ok=m
ansL=ok
ok=n
ng=0
while ok-ng>1:
    m=(ok+ng)//2
    s=solve(m)
    if s==1:
        ok=m
    else:
        ng=m
ansR=ng
#print(ansR,ansL)
print(ansR-ansL+1)

Measured memory_bytes: 123928
def run(N, M, X, Y, x, y):
    x.append(X)
    y.append(Y)
    max_x = max(x)
    min_y = min(y)
    if max_x < min_y:
        ret = 'No War'
    else:
        ret = 'War'
    return ret


def main():
    N, M, X, Y = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    print(run(N, M, X, Y, x, y))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926

typedef long long int ll;

ll chk[55];
ll num[55];
ll num2[55];
//ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
//priority_queue<long long int> pq;
//stack<int> stk;
//vector<pair<ll,ll>> vint;
//vector<ll> vtime;
deque<ll> deq[55];
//list<int> li;
//set<int> sint;
set<ll> sll;
//map<ll,ll> mp;

void dfs(int);

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3,range;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    a=a1=a2=a3=a4=a5=a6=0;
    //float f,g,h;
    //string s,s1;
    //char now,pre,c;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>a1>>a2;
        num[i]=a1;num2[i]=a2;
    }
    /*for(i=0;i<m;i++)
    {
        for(j=0;j<=n;j++) deq[j].clear();
        for(j=0;j<m;j++)
        {
            if(i==j) continue;
            deq[num[j]].push_back(num2[j]);
            deq[num2[j]].push_back(num[j]);
        }
        for(j=1;j<=n;j++)
        {
            cout<<j<<"->";
            for(k=0;k<deq[j].size();k++)
                cout<<deq[j][k]<<" ";
            cout<<endl;
        }
    }*/
    for(i=0;i<m;i++)
    {
        sll.clear();
        for(j=0;j<=n;j++)
        {
            if(j!=0) sll.insert(j);
            deq[j].clear();
            chk[j]=0;
        }
        for(j=0;j<m;j++)
        {
            if(i==j) continue;
            deq[num[j]].push_back(num2[j]);
            deq[num2[j]].push_back(num[j]);
        }
        dfs(1);
        if(sll.size()==0)
        {
            sum++;
        }
    }
    cout<<m-sum;
    return 0;
}

void dfs(int n)
{
    if(sll.find(n)!=sll.end()) sll.erase(n);
    if(sll.size()==0||chk[n]==1) return;
    chk[n]=1;
    for(int i=0;i<deq[n].size();i++)
        dfs(deq[n][i]);
}




Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long[] array = new long[5];
		for (int i = 0; i < array.length; i++) {
			array[i] = sc.nextLong();
		}
		Arrays.sort(array);

		long sum = 0;
		if (n % array[0] == 0) {
			sum = 4 + n / array[0];

		} else {
			sum = 5 + n / array[0];
		}

		System.out.println(sum);
	}
}


Measured memory_bytes: 23892
#!/usr/bin/env python3

from sys import stdin, stdout
 
def input():
    return stdin.readline().strip()

H, W = input().split()
H = int(H)
W = int(W)

Cx, Cy = input().split()
Cx = int(Cx)
Cy = int(Cy)

Dx, Dy = input().split()
Dx = int(Dx)
Dy = int(Dy)

matrix = []

for _ in range(H):
    row = list(input())
    matrix += [row]

# print("reading done")

from collections import deque


visited = set()

def bfs(x, y, label):
    global visited
    worklist = deque([(x, y)])
    while len(worklist):
        (x, y) = worklist.popleft()
        matrix[x][y] = label
        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            new_x, new_y = x+dx, y+dy
            if 0 <= new_x < H and 0 <= new_y < W and matrix[new_x][new_y] == '.' and (new_x, new_y) not in visited:
                worklist.append((new_x, new_y))
                visited.add((new_x, new_y))
    
# for row in matrix:
#     print(''.join(map(str, row)))

curr_label = 0
for x in range(0, H):
    for y in range(0, W):
        if matrix[x][y] == '.':
            bfs(x, y, curr_label)
            curr_label += 1

# for row in matrix:
#     print(''.join(map(str, row)))

# print("cc done")

neighbours = []

for _ in range(0, curr_label):
    neighbours += [set()]

for x in range(H):
    for y in range(W):
        u = matrix[x][y]
        if u == '#': continue
        for dx in [-2, -1, 0, 1, 2]:
            for dy in [-2, -1, 0, 1, 2]:
                new_x = x + dx
                new_y = y + dy

                if 0 <= new_x < H and 0 <= new_y < W and matrix[new_x][new_y] != '#':
                    v = matrix[new_x][new_y]
                    if u == v: continue

                    neighbours[u].add(v)
                    neighbours[v].add(u)

Cx -= 1
Cy -= 1

Dx -= 1
Dy -= 1

source = matrix[Cx][Cy]
target = matrix[Dx][Dy]

import sys

if source == '#' or target == '#':
    print(-1)
    sys.exit(0)

visited = set([source])
frontier = set([source])

if target in frontier:
    print(0)
    sys.exit(0)

# print(neighbours, source, target)

count = 1
while len(frontier):
    next_frontier = set()
    for u in frontier:
        for v in neighbours[u]:
            if v not in visited:
                visited.add(v)
                next_frontier.add(v)
    if target in next_frontier:
        print(count)
        count += 1
        sys.exit(0)

    count += 1
    frontier = next_frontier

print(-1)


Measured memory_bytes: 206344
from collections import Counter
from sys import stdin
n = int(stdin.readline().rstrip())
vl = [int(_) for _ in stdin.readline().rstrip().split()]
odds=Counter(vl[0::2]).most_common()
evens=Counter(vl[1::2]).most_common()
odd_f = odds[0]
even_f = evens[0]
if odd_f != even_f:
    print(n-odd_f[1]-even_f[1])
else:
    try:
        odd_se = odds[1]
    except:
        odd_se = [0,0]
    try:
        even_se = evens[1]
    except:
        even_se = [1,0]
    print(n - max(odd_f[1]+even_se[1], odd_se[1]+even_f[1]))

Measured memory_bytes: 20572
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll a,b,k,c;
  c=0;
  cin >> a >> b >> k;
  per(i,200){
    if(a%i==0&&b%i==0)c++;
    if(c==k){
      printf("%lld",i);
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

    vector<int> x(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }

    int output = 1e9;
    for (int i = 0; i < N - K + 1; i++) {
        int tmp;
        if (x[i] >= 0) {
            tmp = x[i + K - 1];
        } else if (x[i] < 0) {
            if (x[i + K - 1] > 0) {
                tmp = min(-x[i] * 2 + x[i + K - 1], -x[i] + x[i + K - 1] * 2);
            } else if (i == N - K) {
                tmp = -x[i] + x[i + K];
            } else {
                tmp = 1e9;
            }
        }
        if (tmp < output) {
            output = tmp;
        }
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
void err() {
  cout << -1 << endl;
  exit(0);
}
void dfs (int crr, int dpt, vector<vector<int>>& grh, long long& cnt) {
  cnt += dpt;
  for (int nxt : grh[crr]) {
    dfs(nxt, dpt + 1, grh, cnt);
  }
}
int main() {
  int n;
  cin >> n;
  vector<long long> d(n);
  map<long long, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    mp[d[i]] = i;
  }
  sort(d.begin(), d.end());
  vector<long long> sz(n, 1);
  vector<vector<int>> grh(n);
  for (auto it = d.rbegin(); next(it) != d.rend(); it++) {
    auto i = mp.rbegin()->second;
    long long wnt = *it - n + 2 * sz[i];
    if (mp.find(wnt) == mp.end()) err();
    auto p = mp[wnt];
    grh[p].push_back(i);
    sz[p] += sz[i];
    mp.erase(--mp.end());
  }
  long long cnt = 0;
  int rt = mp[d[0]];
  dfs(rt, 0, grh, cnt);
  if (d[0] != cnt) err();
  for (int crr = 0; crr < n; crr++) {
    for (int nxt : grh[crr]) {
      cout << crr + 1 << ' ' << nxt + 1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=200005;
const int maxlen=1000005;
const int kcz=998244353;
struct HasH
{
    // int l;
    ull val1;
    // ll val2;
    HasH(/*int l=0,*/ull val1=0/*,ll val2=0*/):/*l(l),*/val1(val1)/*,val2(val2)*/ { }
    inline bool operator <(const HasH &h) const
    {
        return /*(l!=h.l)?l<h.l:((val1!=h.val1)?val1<h.val1:(val2<h.val2))*/(val1<h.val1);
    }
    inline HasH operator +(const char &ch) const
    {
        return HasH(/*l+1,*/val1*47+ch-'a'+3/*,(val2*39+ch-'a'+7)%kcz*/);
    }
    // inline void print() { printf("%d %llu %lld\n",l,val1,val2); }
}suf[maxlen];
char temp[maxlen];
string s[maxn];
int n,id[maxn],len[maxn],pre[maxlen],cnt[26][maxlen],tot;
map<HasH,ll> ma;
inline bool cmp(int x,int y) { return len[x]<len[y]; }
int main()
{
    register int i,j,k,t;
    ll ans=0;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%s",temp),s[i]=temp,len[i]=s[i].size(),id[i]=i;
    sort(id,id+n,cmp);
    ma.clear();
    tot=0;
    memset(cnt,0,sizeof(cnt));
    for(i=n-1;i>=0;i--)
    {
#define i id[i]
        suf[len[i]]=HasH();
        for(j=len[i]-1;j>=0;j--)
            suf[j]=suf[j+1]+s[i][j];
        for(j=0,pre[0]=0;j<len[i];j++)
            pre[j+1]=pre[j]|(1<<(s[i][j]-'a'));
        if(ma.count(suf[1])) ans+=cnt[s[i][0]-'a'][ma[suf[1]]];
        // suf[0].print();
        // printf("%s %lld\n",s[i].c_str(),cnt[suf[0]]);
        for(j=0;j<=len[i];j++)
        {
            if(pre[j] && !ma.count(suf[j]))
                t=ma[suf[j]]=++tot;
            else t=ma[suf[j]];
            for(k=0;k<26;k++)
                if((pre[j]>>k)&1)
                    cnt[k][t]++;
        }
            //         cnt[suf[j]+(k+'a')]+=1;//(suf[j]+(k+'a')).print();
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 186440
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

#define TRACE(x) std::cout << #x << " = " << x << "\n"
#define _ << " _ " <<

using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int X;
  cin >> X;

  int Y = 360 / __gcd(X, 360);
  cout << Y << "\n";

  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>0&&b>0)cout<<"Positive"<<endl;
    if(a<0&&b>0)cout<<"Zero"<<endl;
    if(a<0&&b<0){
        if((b-a)%2==0)cout<<"Negative"<<endl;
        if((b-a)%2==1)cout<<"Positive"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
def max_common(n, s):
    maximum = 0
    for i in range(1, n):
        set_left = set(s[:i])
        set_right = set(s[i:])
        maximum = max(maximum, len(set_left.intersection(set_right)))
    return maximum


if __name__ == '__main__':
    n = int(input())
    s = input()
    print(max_common(n, s))

Measured memory_bytes: 3060