akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(ll i=(a);i<=(b);i++)
#define repi(i,n) fori(i,0,(n)-1)
#define forr(i,a,b) for(ll i=(b);i>=(a);i--)
#define repr(i,n) forr(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
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;}

void solve(ll n, string s){
    ll ans=0;
    repi(i,n-2){
        if(s.substr(i,3)=="ABC")ans++;
    }
    cout<<ans<<endl;
}

int main(){
    ll n;
    scanf("%lld",&n);
    string s;
    cin >> s;
    solve(n, s);
    return 0;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'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'};
//vc Alp ={'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'};
//cout<<""<<endl;
int main(){
 int A,B;cin>>A>>B;
  if(A==B)cout<<"Draw"<<endl;
  else if(A>B&& B!=1)cout<<"Alice"<<endl;
  else if(A>B &&B==1)cout<<"Bob"<<endl;
  else if(A<B &&A!=1)cout<<"Bob"<<endl;
  else if(A<B &&A==1)cout<<"Alice"<<endl;
}   





Measured memory_bytes: 256
n,a,b = map(int, input().split())
if (b-a)%2 == 0:
    print((b-a)//2)
else:
    if n-b < a-1:
        print(n-b + (b-a+1)//2)
    else:
        print(a-1 + (b-a+1)//2)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
 
int main()
{
    int n;
    cin>>n;
    int dist[n+10];
    for(int i=0; i<n+10; i++) dist[i] = 10000000;
    deque<int> dq;
    dq.push_front(1);
    dist[1] = 0;
    while(!dq.empty()){
        int u = dq.front();
        dq.pop_front();
        if(u==0) break;
        int v = (u+1)%n;
        if(dist[v]>dist[u]+1 && u!= v){
            dist[v] = dist[u] + 1;
            dq.push_back(v);
        }
        v = (u*10)%n;
        if(dist[v]>dist[u] && u!= v){
            dist[v] = dist[u];
            dq.push_front(v);
        }
    }
    cout<<dist[0] + 1<<endl;
    return 0;
}

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

int main() {
    int t = 1;
    while(t--) {
        int d, t, s;
        cin>>d>>t>>s;
        if(t * s >= d) {
            cout<<"Yes";
        } else {
            cout<<"No";
        }
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<long long> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
 {  fast();
	int t, n, k;
	t=1;
    ll a,v,b,w,time;
	string s;
	while(t--) {
	    cin >> a >>v;
      cin>> b >>w;
      cin>>time;
      if(a==b)cout<<"YES"<<endl;
      else if(v==w&&a!=b)cout<<"NO"<<endl;
	  else  if(ceil((double)labs(b-a)/(double)(v-w))<=time&&(v-w>0))cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
	    
	  
	}}

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

int main()
{
  int h,w;
 
  for( ; ; ){
    cin >> h >> w;
    if(h==0 || w==0) break;
    
    for(int i=0;i<h;i++){
      
      if(i==0 && i==h-1){
	cout << "#";
      }
      for(int j=0;j<w;j++){
	if(j==0 || j==w-1){
	  cout << "#";
	}else if(i==0 || i==h-1){
	  cout << "#";
	}else{
	    cout << ".";
	} 
      }
      cout << endl;  
    } 
    cout << endl;   
  }  
  return 0;
} 

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){ 
        cin >> H >> W;
        if(H==0 && W==0)break;
            for( int i = 0; i < H; i++ ){
                for( int j = 0; j < W; j++ ){
                    cout << "#";
                }cout << endl;
            }cout << endl;
    }return 0;
}


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


public class Main{
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = sc.nextInt();
        int K = sc.nextInt();
        Integer[] A = new Integer[N+1];
        Arrays.fill(A,0);
        for(int i=0;i<N;i++){
            A[sc.nextInt()]++;
        }
        Arrays.sort(A,Comparator.reverseOrder());
        int result = 0;
        for(int i=K;i<=N;i++){
            result += A[i];
        }



        out.println(result);

        out.flush();
    }

}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 27872
K = int(input())

r = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(r[K-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
 
int main(){
  string s;
  cin>>s;
  int n=s.size();
  rep(i,n){
    if(s[i]=='7'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3628
n = int(input())
a = list(map(int,input().split()))
dp = [0 for _ in range(n)]
dp[1] = abs(a[1]-a[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
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();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int ret = 0;
		for(int i=0; i<N; i++){
			if (i<K){
				ret = ret+X;
			}
			else {
				ret = ret+Y;
			}
		}





		System.out.println(ret);


	}
}


Measured memory_bytes: 9940
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>

#define inf 0x3f3f3f3f

#define lc k << 1
#define rc k << 1 | 1

using namespace std;

typedef long long ll;

int n, p;
char s[300005], t[300005];
int main(){
	
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; i ++){
		if(s[i] != 'x') t[++p] = s[i];
	}
	if(p == 0){
		printf("0\n");
		return 0;
	}
	for(int i = 1; i <= p / 2; i ++){
		if(t[i] != t[p - i + 1]) {
			printf("-1\n");
			return 0;
		}
	}
	int ans = 0;
	int t = 1;
	int p1 = 1, p2 = n;
	if(p % 2 == 0){
		while(t <= p / 2){
			int r1 = p1, r2 = p2;
			while(s[p1] == 'x') p1++;
			while(s[p2] == 'x') p2--;
			int t1 = p1 - r1, t2 = r2 - p2;
			ans += max(t1, t2) - min(t1, t2);
			t++; p1++; p2--;
		}
	}
	if(p % 2 == 1){
		while(t <= p / 2 + 1){
			int r1 = p1, r2 = p2;
			while(s[p1] == 'x') p1++;
			while(s[p2] == 'x') p2--;
			int t1 = p1 - r1, t2 = r2 - p2;
			ans += max(t1, t2) - min(t1, t2);
			t++; p1++; p2--;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

ll a[105]/*weight*/, v[105]/*value*/;
ll dp[105][100005], n, w;
const ll INF = 1e18+5;

int main() {
    cin>>n>>w; ll value = 0;
    for(ll i = 1; i <= n; ++i){
        cin>>a[i]>>v[i]; value += v[i];
    }
    for(ll i = 2; i <= n; i++){fill(dp[i], dp[i] + value + 1, INF);}
    for(ll i = 1; i <= n; ++i){
        for(ll j = value; j >= 0; --j){
            ll temp = INF;
            if(j + v[i] <= value){temp = dp[i-1][j+v[i]];}
            dp[i][j] = min(dp[i-1][j] + a[i], temp);
        }
    }
    ll ans = 0;
    for(ll i = 0; i <= value; i++){
        if(dp[n][i] <= w){
            ans = max(i, ans);
        }
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 79360
def count_prime(num)
  res = 0

  while num % 2 == 0
    res += 1
    num /= 2
  end

  res
end

n = gets.to_i
as = gets.split.map(&:to_i).select(&:even?)

puts as.inject(0) { |r, a| r + count_prime(a) }


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

int n;
const int maxn = 105;

vector<int> G[maxn];

typedef unsigned long long ull;

int u[maxn], v[maxn];
int dep[maxn];
int son[maxn];

void dfs(int u, int fa, int d){
    dep[u] = d; 
    int sons = 0;
    for(auto v : G[u]){
        if(v == fa)
            continue;
        sons++;
        dfs(v, u, d + 1);
    }
    son[d] = max(sons, son[d]);
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i < n;i++){
        cin >> u[i] >> v[i];
        G[u[i]].push_back(v[i]);
        G[v[i]].push_back(u[i]);
    }
    ull col = (1ULL << 63), leaf = (1ULL << 63);
    for(int i = 1;i < 2 * n;i++){
        memset(son, 0, sizeof(son));
        memset(dep, 0, sizeof(dep));
        if(i <= n){
            dfs(i, i, 1);
        }else{
            dfs(u[i - n], v[i - n], 1);
            dfs(v[i - n], u[i - n], 1);
        }
        ull mxd = *max_element(dep + 1, dep + n + 1);    
        ull tmp;
        if(i <= n){
            tmp = 1;
        }else{
            tmp = 2;
        }
        bool overflow = false;
        for(int j = 1;j < mxd;j++){
            if(tmp >= (1ULL << 63) / son[j]){
                overflow = true;
                break;
            }else{
                tmp *= son[j];
            }
        }
        if(overflow)
            continue;
        if(mxd < col){
            col = mxd;
            leaf = tmp;
        }else if(mxd == col){
            leaf = min(tmp, leaf);
        }
    }
    cout << col << " " << leaf << endl;
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

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

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

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N;
	cin >> N;
	N %= 10;
	if (N == 3) {
		cout << "bon" << endl;
	} else if (N == 0 || N == 1 || N == 6 || N == 8) {
		cout << "pon" << endl;
	} else {
		cout << "hon" << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <ctype.h>

int main()
{
 char str[1200];
 char c;
 int i=0;
 while(1)
 {
  scanf("%c",&c);
  if(c== '\n' || c =='\0')
   break;
  if(isupper(c))
    str[i]=tolower(c);
  else
  {
     str[i]=toupper(c);
  }
  i++;
 }
 str[i] = '\0';
 printf("%s\n", str);
 return 0;
}

Measured memory_bytes: 528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int b[n] = {};
    rep(i, n) {
        int a;
        cin >> a;
        if (n % 2 == 0) {
            if (i % 2 == 0) {
                b[(n / 2) + i / 2] = a;
            } else {
                b[(n / 2) - (i + 1) / 2] = a;
            }
        } else {
            if (i % 2 == 0) {
                b[(n / 2) - i / 2] = a;
            } else {
                b[(n / 2) + (i + 1) / 2] = a;
            }
        }
    }

    rep(i, n) {
        cout << b[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long double ans = 5000;
    vector<long double>x(n + 3), y(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> y[i];
    }
    long double ef = 0.00000001;
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            long double curx = (x[i] + x[j])/2, cury = (y[i] + y[j])/2;
            long double r = sqrt((curx - x[j]) * (curx - x[j]) + (cury - y[j]) * (cury - y[j]));
            int cnt = 0;
            for(int k = 1; k <= n; k++){
                long double r1 = sqrt((curx - x[k]) * (curx - x[k]) + (cury - y[k]) * (cury - y[k]));
                if(r1 <= r + ef){
                    cnt++;
                }
            }
            if(cnt == n){
                ans = min(ans, r);
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            for(int k = j + 1; k <= n; k++){
                long double d = 2 * (x[i] * (y[j] - y[k]) + x[j] * (y[k] - y[i]) + x[k] * (y[i] - y[j]));
                long double curx = ((x[i] * x[i] + y[i] * y[i]) * (y[j] - y[k]) + (x[j] * x[j] + y[j] * y[j]) * (y[k] - y[i]) + (x[k] * x[k] + y[k] * y[k]) * (y[i] - y[j]))/d;
                long double cury = ((x[i] * x[i] + y[i] * y[i]) * (x[k] - x[j]) + (x[j] * x[j] + y[j] * y[j]) * (x[i] - x[k]) + (x[k] * x[k] + y[k] * y[k]) * (x[j] - x[i]))/d;
                long double r = sqrt((curx - x[i]) * (curx - x[i]) + (cury - y[i]) * (cury - y[i]));
                int cnt = 0;
                for(int p = 1; p <= n; p++){
                    long double r1 = sqrt((curx - x[p]) * (curx - x[p]) + (cury - y[p]) * (cury - y[p]));
                    if(r1 <= r + ef){
                        cnt++;
                    }
                }
                if(cnt == n){
                    ans = min(ans, r);
                }
            }
        }
    }
    cout << setprecision(12) << ans;
    return 0;
}

Measured memory_bytes: 3796
sa = input()
sb = input()
sc = input()

ended = False
winner = ''
next_turn = 'a'
while not ended:
    if next_turn == 'a':
        if len(sa) == 0:
            ended = True
            winner = 'A'
        else:
            next_turn = sa[0]
            sa = sa[1:]
    elif next_turn == 'b':
        if len(sb) == 0:
            ended = True
            winner = 'B'
        else:
            next_turn = sb[0]
            sb = sb[1:]
    elif next_turn == 'c':
        if len(sc) == 0:
            ended = True
            winner = 'C'
        else:
            next_turn = sc[0]
            sc = sc[1:]
print(winner)


Measured memory_bytes: 9004
n = int(input())
nums = list(map(int, input().split()))

l = nums[0]
r = sum(nums[1:])
min_dif = abs(l - r)
for i in range(1, len(nums)):
	l += nums[i]
	r -= nums[i]
	min_dif = min(min_dif, abs(l - r))

print(min_dif)

Measured memory_bytes: 26024
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1e5 + 5;
int n, b[N];
char s[N];

int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    if (s[1] == '0' || s[n] == '1' || s[n - 1] == '0') return puts("-1"), 0;
    for (int i = 2; i < n - 1; ++i) if (s[i] != s[n - i]) return puts("-1"), 0;
    for (int i = 2, x = 1; i <= n; ++i) {
        printf("%d %d\n", x, i);
        if (s[i - 1] == '1') x = i;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
#define mem(a,b) memset(a,b,sizeof(a))
int n,m;
char ch[110][110];
int l[110],r[110];
int main(){
	int i,j,t;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%s",ch[i]);
	}
	mem(l,0);mem(r,0);
	for(i=0;i<n;i++){
		int flag=1;
		for(j=0;j<m;j++){
			if(ch[i][j]=='#'){
				flag=0;break;
			}
		}
		if(flag) l[i]=1;
	}
	for(j=0;j<m;j++){
		int flag=1;
		for(i=0;i<n;i++){
			if(ch[i][j]=='#'){
				flag=0;break;
			}
		}
		if(flag) r[j]=1;
	}
	int flag=0;
	for(i=0;i<n;i++){
		flag=0;
		for(j=0;j<m;j++){
			if(!l[i]&&!r[j]){
				flag=1;
				printf("%c",ch[i][j]);
			}
		}
		if(flag)
			printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
# 解説AC
# 参考1: https://drken1215.hatenablog.com/entry/2019/09/29/103500
# 参考2: https://www.slideshare.net/chokudai/wap-atcoder4


n, m = map(int, input().split())
A, B, C = [], [], []
for _ in range(m):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    c = list(map(int, input().split()))
    now = 0
    for i in range(b-1, -1, -1):
        now += 2**(c[i]-1)
    C.append(now)

INF = 10**9
DP = [[INF for _ in range(2**n)] for _ in range(m+1)]
DP[0][0] = 0

for i in range(m):
    for j in range(2**n):
        c = C[i]
        # 鍵を使用しない
        DP[i+1][j] = min(DP[i][j], DP[i+1][j])
        # 鍵を使用する
        nex = j | c
        DP[i+1][nex] = min(DP[i+1][nex], DP[i][j]+A[i])

ans = 10**9
for i in range(m):
    ans = min(DP[i][-1], ans)

if ans == 10**9:
    ans = -1

print(ans)

Measured memory_bytes: 80472
// https://atcoder.jp/contests/abc134/tasks/abc134_d

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#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 ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

inline int read() {
    int out = 0, fh = 1;
    char jp = getchar();
    while ((jp > '9' || jp < '0') && jp != '-')
        jp = getchar();
    if (jp == '-')
        fh = -1, jp = getchar();
    while (jp >= '0' && jp <= '9')
        out = out * 10 + jp - '0', jp = getchar();
    return out * fh;
}

int a[200001];
bool b[200001];
int main() {
    int n, ans = 0;
    n = read();
    for (int i = 1; i <= n; i++) {
        a[i] = read();
    }
    for (int i = n; i >= 1; i--) {
        int x = a[i];
        for (int j = i << 1; j <= n; j += i) {
            x ^= b[j];
        }
        b[i] = x;
        if (x)
            ans++;
    }
    cout << ans << '\n';
    for (int i = 1; i <= n; i++) {
        if (b[i]) {
            cout << i << ' ';
        }
    }

    return 0;
}


Measured memory_bytes: 1920
from collections import Counter, defaultdict, deque

N, X, Y = map(int, input().split())

d = defaultdict(set)
for i in range(N-1):
    d[i].add(i+1)
    d[i+1].add(i)
d[X-1].add(Y-1)
d[Y-1].add(X-1)


cost = [[N]*N for _ in range(N)]

q = deque()

for i in range(N):
    q.append((i, 0))
    cost[i][i] = 0

    while q:
        u, st = q.popleft()

        for v in d[u]:
            if v != u and cost[i][v] > st+1:
                cost[i][v] = st+1
                q.append((v, st+1))

res = Counter()
for i, c in enumerate(cost):
    res += Counter(c[:i])

for i in range(N - 1):
    print(res[i + 1])

Measured memory_bytes: 121820
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>


int main()
{
    // std::cout << std::fixed << std::setprecision(10);
    int s; std::cin >> s;
    int up2 = (s - s%100) / 100, dw2 = s%100;
    
    if((up2 > 12 || up2==0) && (dw2 <= 12 && dw2!=0)) std::cout << "YYMM" << std::endl;
    else if((up2 <= 12 && up2!=0) && (dw2 > 12 || dw2==0)) std::cout << "MMYY" << std::endl;
    else if((dw2!=0 && dw2 <= 12) && (up2!=0 && up2 <= 12)) std::cout << "AMBIGUOUS" << std::endl;
    else std::cout << "NA" << std::endl;
    
    return 0;
}

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

#define ll long long int
#define mod 1000000007

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;

const int inf = 1e9;

void mins(int& a,int b){
	a=min(a,b);
}

int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	vector<ll> dp(n),pre(n);

	dp[0]=0;
	dp[1]=max(a[0],a[1]);
	if(n<3){
		cout<<dp[n-1]<<"\n";
		return 0;
	}
	
	dp[2]=max(dp[1],a[2]);
	pre[0]=a[0];
	pre[2]=pre[0]+a[2];
	
	for(int i=3;i<n;i++){
		if(i&1){
			dp[i]=max(a[i]+dp[i-2],a[i-1]+pre[i-3]);
		}
		else{
			dp[i]=max(a[i]+dp[i-2],a[i-1]+dp[i-3]);
			pre[i]=pre[i-2]+a[i];
		}
	}
	
    cout<<dp[n-1]<<"\n";			
}





Measured memory_bytes: 7968
n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|n| n.to_i}

alice=0
bob=0

while a.empty?.!
  max=a.max
  alice+=max
  a.delete_at(a.find_index(max))
  break if a.empty?
  max=a.max
  bob+=max
  a.delete_at(a.find_index(max))
end

puts alice-bob

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

const int PRIME_SIZE = 2000000;
int psize;
bool bprime[PRIME_SIZE+1];
int prime[PRIME_SIZE+1];
int Eratosthenes(int n) {
  psize = 0;
  memset(bprime, true, sizeof(bprime));
  bprime[0] = bprime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (!bprime[i]) { continue; }
    prime[psize++] = i;
    for (int j = i + i; j <= n; j += i) {
      bprime[j] = false;
    }
  }
  return psize;
}


ll a, b;
ll l, r;
bool ok[1000100];
ll mul(ll lhs, ll rhs) {
  if (lhs * rhs / rhs != lhs) { lhs = 1LL << 60; }
  else { lhs *= rhs; }
  return lhs;
}

int main() {
  Eratosthenes(900000);
  while (scanf("%lld %lld", &a, &b) > 0) {
    MEMSET(ok, true);
    if (a + b <= 1) {
      printf("0\n");
      continue;
    }
    l = max(2LL, a - b);
    r = max(2LL, a + b);
    ll ans = r - l + 1;
    REP(j, psize) {
      ll jprod = mul(prime[j], prime[j]);
      if (jprod > r) { break; }
      REP(i, j) {
        ll prod = mul(prime[i], jprod);
        if (prod > r) { break; }
        while (prod <= r) {
          ll value = (l + prod - 1) / prod * prod;
          while (value <= r) {
            if (ok[value - l] && value / prod % prime[i] != 0) {
              ok[value - l] = false;
              ans--;
            }
            value += prod;
          }
          prod = mul(prod, mul(prime[i], prime[j]));
        }
      }
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
int main() {
    string s;
    int k;
    cin >> k >>s;
    if(s.size() <= k)cout << s << endl;
    else cout << s.substr(0,k) << "..." << endl;

}


Measured memory_bytes: 3628
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF (1<<29)

int main(){
    int n;
    cin>>n;
    vector<long long> ryu(n+1);
    ryu[0]=2;
    ryu[1]=1;

    int i=2;
    while(i<=n){
        ryu[i]=ryu[i-2]+ryu[i-1];
        i++;
    }
    cout<<ryu[n]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
	int q;
	cin >> q;
	vector<int> ans(q);
	for(int i = 0;i < q;i++){
		string s,t;
		cin >> s >> t;
		int n = s.size();
		int m = t.size();

		vector<vector<int>> dp(n+1,vector<int>(m+1,0));

		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				if(s[i] == t[j]){
					dp[i+1][j+1] = max({dp[i][j+1],dp[i+1][j],dp[i][j]+1});
				}
				else{
					dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);    
				}
			}
		}
		ans[i] = dp[n][m];
	}

	for(int a:ans)cout << a << endl;
}



Measured memory_bytes: 6768
#include <iostream>

using namespace std;

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

    int digit_sum = 0;
    for (int i = 0; i < X.size(); ++i) {
        digit_sum += X[i] - '0';
    }

    if (stoi(X) % digit_sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


ll a[300030];
ll Left[3000030], Right[300030];
int main() {
	int N;
	cin >> N;
	REP(i, 3 * N) {
		cin >> a[i];
	}


	ll left = 0;
	priority_queue<ll, vector<ll>, greater<ll>> minpq;
	REP(i, N) {
		left += a[i];
		minpq.push(a[i]);
	}
	Left[N-1] = left;
	FOR(i, N, 2*N) {
		minpq.push(a[i]);
		Left[i] =Left[i-1]+ a[i];
		ll c = minpq.top();
		minpq.pop();
		Left[i]-= c;
	}


	ll right = 0;
	priority_queue<ll> maxpq;
	FORR(i, 3*N - 1, 2*N) {
		right += a[i];
		maxpq.push(a[i]);
	}
	Right[2 * N] = right;
	FORR(i, 2*N - 1, N-1) {
		Right[i] =Right[i+1]+ a[i];
		maxpq.push(a[i]);
		ll c = maxpq.top();
		maxpq.pop();
		Right[i] -= c;
	}

	ll ans = -9999999999999999;
	FOR(i,N, 2 * N+1) {
		ans = max(ans, (Left[i - 1] - Right[i]));
	}
	cout << ans << endl;
}


Measured memory_bytes: 8308
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i + 2 < (int) s.size(); i++) {
    if (s.substr(i, 3) == "ABC") ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*                        _
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                   ____/`---'\____
                  /  \\|     |//  \
                 / \\||| /:\ |||// \
                / _||||| -:- |||||- \
               |   | \\\ \-/ /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
            ____'. .'  /--.--\  `. .'_____
          /"" '<  `.___\_<|>_/___.' >' "" \
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
          `-.____`.___ \_____/___.-`___.-'
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.    IIT PATNA    ADITI GOEL IS LOVE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// while(scanf("%d",&n)!=EOF)

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <bits/stdc++.h>
#define ii int64_t
#define lli long long int
#define li long int
#define vi vector<int64_t>
#define mii unordered_map<int64_t,int64_t>
#define nl cout<<"\n"
#define deb(x) cout<<"\nhi"<<x<<"\n"
#define mod 1000000007
ii n,t,i,j,k,l,x,y,z,cnt=0,sum=0,mx=-1,mn=INT_MAX;
bool f,f1,f2;
using namespace std;
int main()
{fio;
    cin>>k>>n;
    ii a[n];
    cin>>a[0];
    for(i=1;i<n;i++){cin>>a[i];mx=max(mx,a[i]-a[i-1]);}
    mx=max(mx,k-a[n-1]+a[0]);
    
    cout<<k-mx;
    

    
    
    
    
}



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

#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double

using namespace std;

const int MAXN = 1001 * 1001 , MOD = 1e9 + 7 ; 

map<int,int> cnt ; 

int32_t main() 
{
	ios::sync_with_stdio(0) ; 
	cin.tie(0) ;
	int n , x ; 
	cin >> n ; 
	for(int i = 0 ; i < n ; i ++ ) cin >> x , cnt[x] ++ ; 
	cin >> n ; 
	for(int i = 0 ; i < n ; i ++ ) 
	{
		cin >> x ; 
		cnt[x] -- ; 
		if(cnt[x]<0) return cout << "NO" << endl , 0 ; 
	}
	cout << "YES" << endl ; 
}

Measured memory_bytes: 9728
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//chmaxs chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long N, long long A, long long B, std::vector<long long> X){
    LL ans =0;
    for(int i=0; i < N-1; i++){
        ans += min((X[i+1]-X[i])*A, B);
    }cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    std::vector<long long> X(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
    }
    solve(N, A, B, std::move(X));
    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 501;
int n,m;
void add(int &a,int b){
  a += b;
  if(a > m)
    a -= m;
}
void sub(int &a,int b){
  a -= b;
  if(a < 0)
    a += m;
}
int mul(int a,int b){
  return a * b % m;
}
int kw(int x){
  return x * x;
}
int mi[MAX],ma[MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> m;
  R(i,n*2){
    while(kw(mi[i]) + kw(i) < kw(n))mi[i]++;
    while(kw(ma[i]) + kw(i) <= kw(2 * n))ma[i]++;
    mini(ma[i],n*2);
    debug(mi[i],ma[i]);
  }
  int res = 0;
  R(zle,n + 1){
    debug(zle);
    vector<int> dp(zle + 1);
    dp[0] = 1;
    int i = 0, j = n;
    while(i < n || j < 2 * n){
      vector<int> ak(zle+1);
      if(i != n && (j == 2 * n || mi[i] > ma[j])){
        R(k, zle + 1){
          add(ak[k], mul(dp[k], ma[i] - n - (n - i - 1 + k)));
          if(k != zle)
            add(ak[k+1], mul(dp[k], mi[i] - (2 * n - j) - (zle - k - 1)));
        }
        i++;
      }else{
        R(k, zle + 1)
          ak[k] = mul(dp[k], ma[j] - (2 * n - j - 1) - (zle - k));
        j++;
      }
      swap(ak,dp);
     // debug(i,j,dp);
    }
    if(zle & 1){
      sub(res, dp[zle]);
    }else{
      add(res, dp[zle]);
    }
  }
  cout << res << "\n";
}


Measured memory_bytes: 256
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N, X, Y;
    cin >> N >> X >> Y;

    vector<vector<int>> g(N);

    for (int i = 0; i < N - 1; i++) {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }

    X--, Y--;
    g[X].push_back(Y);
    g[Y].push_back(X);

    vector<int> dist(N);

    for (int i = 0; i < N; i++) {
        queue<int> Q;
        vector<int> seen(N, -1);
        seen[i] = 0;

        for (Q.push(i); !Q.empty();) {
            auto el = Q.front();
            Q.pop();

            for (auto v : g[el]) if (seen[v] == -1) {
                seen[v] = seen[el] + 1;
                dist[seen[v]]++;
                Q.push(v);
            }
        }
    }

    for (int i = 1; i < N; i++)
        cout << dist[i] / 2 << "\n";

    return 0;
}


Measured memory_bytes: 384
import numpy as np
n = int(input())
A = np.array(list(map(int, input().split())))
A -= 1

ans = 0
seen = [0] * n
for i, ai in enumerate(A):
    if seen[i]:
        continue
    seen[i] = 1
    if A[ai] == i:
        ans += 1
        seen[ai] = 1

print(ans)


Measured memory_bytes: 23384
// ------------------------------------
// Date:2018/ 2/24
// Problem:AGC 005 STring a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

using ll = long long;

#define MOD 1000000007

int main()
{
  int cnt,sCnt,tCnt;
  string s;
  bool lastch = false;
  cnt = sCnt = tCnt = 0;
  cin >> s;
  REP(i,s.size()) {
    if (s[i] == 'S') {
      ++sCnt;
    }
    if (s[i] == 'T') {
      ++tCnt;
      if (sCnt > 0) {
        --sCnt;
        --tCnt;
      }
    }
  }
  
  cout << sCnt+tCnt << endl;
  return 0;
}



Measured memory_bytes: 640
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define DEBUG 1
#define ll         long long
#define REP(i, n) for (long long i = 0; i < (n); i++) 
const int MOD = 1000000007;

//10 100
//7 10 4 5 9 3 6 8 2 1

//高橋くんは、 4-9 か 3-8を行う
//どちらかわからないので、青木くんは9と8のコストを下げる

//右から見ていって、最大の差を求めればよい
//最大の差を求めた後は、

int main(){
    int N,T;
    cin >> N >> T;
    vector <int> a(N);
    REP(i,N)cin >> a[i];

    //(左から見ていって)現状の最小値.0で0番目から0番目までみた
    vector<int> be_min(N,MOD);
    for(int i = 0; i < N; ++i)
    {
        if(i == 0)be_min[i] = a[i];
        else
        {
            be_min[i] = min(a[i], be_min[i-1]);
        }
    }
    //(右から見ていって)現状の最大値.0でN-1番目から0番目までみた
    vector<int> be_max(N);
    for(int i = N-1; i >= 0; --i)
    {
        if(i == N-1)be_max[i] = a[i];
        else
        {
            be_max[i] = max(a[i], be_max[i+1]);
        }
    }
    //差の最大
    int sa_max = 0;
    for(int i = 0; i < N; ++i)
    {
        sa_max = max(sa_max, be_max[i] - a[i]);
    }


    int res = 0;
    for(int i = 0; i < N; ++i)
    {
        if(a[i] - be_min[i] == sa_max)++res;
    }

    cout << res << endl;
    return 0;

}

Measured memory_bytes: 1408
import Control.Applicative
import Data.Maybe

main :: IO ()
main = do
    [a,b,c,d] <- map (read . pure) <$> getLine :: IO [Int]
    let a0 = if a + b + c + d == 7 then Just (show a++"+"++show b++"+"++show c++"+"++show d) else Nothing
    let a1 = if a + b + c - d == 7 then Just (show a++"+"++show b++"+"++show c++"-"++show d) else Nothing
    let a2 = if a + b - c + d == 7 then Just (show a++"+"++show b++"-"++show c++"+"++show d) else Nothing
    let a3 = if a + b - c - d == 7 then Just (show a++"+"++show b++"-"++show c++"-"++show d) else Nothing
    let a4 = if a - b + c + d == 7 then Just (show a++"-"++show b++"+"++show c++"+"++show d) else Nothing
    let a5 = if a - b + c - d == 7 then Just (show a++"-"++show b++"+"++show c++"-"++show d) else Nothing
    let a6 = if a - b - c + d == 7 then Just (show a++"-"++show b++"-"++show c++"+"++show d) else Nothing
    let a7 = if a - b - c - d == 7 then Just (show a++"-"++show b++"-"++show c++"-"++show d) else Nothing
    putStrLn $ fromJust (a0<|>a1<|>a2<|>a3<|>a4<|>a5<|>a6<|>a7) ++ "=7"

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

int main() {
    int a;
    scanf("%d", &a);
    switch (a % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        printf("hon");
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        printf("pon");
        break;
    case 3:
        printf("bon");
        break;
    }
    return 0;
}

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

using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    string answer;
    if (a-b == b-c) {
        answer = "YES";
    } else {
        answer = "NO";
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

char s[1000];
char t[1000];

int main()
{
  int i,j,ns,nt,b1;
  scanf("%s%s",s,t);
  ns=strlen(s);
  nt=strlen(t);
  if (ns!=nt)
  {
    printf("No\n");
    return 0;
  }
  for (i=0;i<ns;i++)
  {
    for (j=ns;j>0;j--)
      s[j]=s[j-1];
    s[0]=s[ns];
    s[ns]='\0';
    b1=1;
    for (j=0;j<ns;j++)
      if (s[j]!=t[j]) b1=0;
    if (b1==1)
    {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    
    vector<int> v(5);
    for(auto& el: v) cin >> el;
    auto it = find(v.begin(), v.end(), 0);
	cout << it - v.begin() + 1 << "\n";
	return 0;
}


Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n[4];
    cin>>n[0]>>n[1]>>n[2]>>n[3];
    sort(n,n+4);
    if(n[0]==1&&n[1]==4&&n[2]==7&&n[3]==9){
        cout<<"YES"<<endl;
    }else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256