akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e9;
const ll mod=998244353;


int R[MX], G[MX], B[MX];

int main()
{
    FasterIO;

    int k; string s;
    cin>>k>>s;
    for(int i=0; i<k; i++)
    {
        if(s[i]=='R') R[i+1]=1+R[i], G[i+1]=G[i], B[i+1]=B[i];
        if(s[i]=='G') R[i+1]=R[i], G[i+1]=1+G[i], B[i+1]=B[i];
        if(s[i]=='B') R[i+1]=R[i], G[i+1]=G[i], B[i+1]=1+B[i];
    }
    ll sm=0;
    for(int i=1; i<=k; i++)
    {
        for(int j=i+1; j<=k; j++)
        {
            if(s[i-1]!=s[j-1])
            {
                if(s[i-1]=='R' && s[j-1]=='B' || s[i-1]=='B' && s[j-1]=='R') sm+=G[k]-G[j];
                if(s[i-1]=='G' && s[j-1]=='B' || s[i-1]=='B' && s[j-1]=='G') sm+=R[k]-R[j];
                if(s[i-1]=='R' && s[j-1]=='G' || s[i-1]=='G' && s[j-1]=='R') sm+=B[k]-B[j];
                if(j+(j-i)<=k && s[i-1]!=s[j+(j-i)-1] && s[j-1]!=s[j+(j-i)-1]) sm--;
            }
        }
    }
    cout<<sm<<endl;
    return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>
int main(void){
    int i,n;
    long max,min;
    long R2,R1,Rt;
    
    scanf("%d",&n);
    
    scanf("%ld",&R1);
    scanf("%ld",&R2);
    
    max=R2-R1;
    min=R1;
    Rt=R2;
    
    for(i=2; i<=n; i++){
        if(i!=2)scanf("%ld",&Rt);
        if(max < Rt-min) max=Rt-min;
        if(min > Rt) min=Rt;
    }
    
    printf("%ld\n",max);
    return 0;
}



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

int main(){
    int n;
    cin >> n;
    vector<int> h(n+10,0);
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    int ans = 0;
    int ma = 0;
    for(int i = 1; i <= n; i++){
        if(ma <= h[i]){
            ans++;
        }
        ma = max(ma,h[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,k;
    cin>>n>>k;
    ll a=0,b=0;
    double c=(double)k/2;
    for(int i=1; i<=n; ++i){
        if(i%k==0)a++;
        if(i%k==c)b++;
    }
    cout<<a*a*a+b*b*b<<endl;
}

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

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W; cin >> H >> W;
	int N; cin >> N;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
	}
	int k = 0;
	vector<vector<int>> c(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		rep(j, 0, W) {
			if (a[k] == 0) {
				k++;
			}
			c[i][j] = k+1;
			a[k]--;
		}
		i++;
		if (i == H)break;
		rrep(j, 0, W) {
			if (a[k] == 0) {
				k++;
			}
			c[i][j] = k+1;
			a[k]--;
		}
	}
	rep(i, 0, c.size()) {
		cout << c[i][0];
		rep(j, 1, c[i].size()) { cout << " " << c[i][j]; }
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
from math import sqrt,ceil
def resolve():
    N =int(input())
    table=[0]*(N+1)
    mx = ceil(sqrt(N))
    for x in range(1,mx):
        for y in range(1,mx):
            for z in range(1,mx):
                n = x**2 + y**2 +z**2 +x*y+y*z +z*x

                if n > N:
                    break
                table[n]+=1

    for i in table[1:]:
        print(i)

resolve()

Measured memory_bytes: 69124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int n;
int v[200005];
int dp[200005];
int f[200005];
vector<vector<int>> g;
void dfs(int p, int u, int r) {
    int ri = r;
    int pos = lower_bound(f+1, f+ri, v[p]) - f;
    int t = f[pos];
    f[pos] = v[p]; 
    if(pos==ri) ++ri;
    dp[p] = ri-1;
    for(auto i:g[p]) {
        if(i!=u)
        dfs(i, p, ri);
    }
    f[pos] = t;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    g.resize(n+1);
    for(int i=1;i<=n;i++) cin>>v[i];
    fill(dp,dp+n+2,inf);
    for(int i=1;i<n;i++) {
        int x, y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1, 0, 1);
    for(int i=1;i<=n;i++) cout<<dp[i]<<endl;
    return 0;
} 

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

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

    string n;
    cin >> n;

    string ans = "ARC";
    if(n == "ARC")ans = "ABC";
    else ans = "ARC";

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
//参考 http://drken1215.hatenablog.com/entry/2018/06/08/210000
#define MOD 1000000007
#define MAX 100005
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
    int n,blue;
    cin>>n>>blue;
    int red=n-blue;
    long long ans;
    COMinit();

    for(int i=1;i<=blue;i++){
        ans=COM(n-blue+1,i)*COM(blue-1,i-1)%MOD;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 2560
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;




int main(int argc, const char * argv[]) {
//    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int l = 0;
    for (int i = 0; i < n; ++i)
        if (s[i] == 'R') ++l;
        else if (s[i] == 'B') --l;
    cout << (l > 0 ? "Yes\n" : "No\n");
}



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

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> a(N), d(N);
  for (int i=0; i<N; i++){
    cin >> a[i];
    d[i] = abs(a[i]-X);
//    cout << i << ' ' << d[i] << endl;
  }
   
  int ans=d[0];;
  
  for (int i=1; i<N; i++){
    ans = gcd(ans, d[i]);
//    cout << i << ':' << ans << endl;
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 1024
#include<stdio.h>

int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

int main(void){
    int i,j,n,m,k,a[512][512],b,c,h,w,r=0,l,t;
    scanf("%d",&k);
    if(k==1){
      printf("1\n1\n");
      return 0;
    }
    n=ceil(k,2);
    if(n%2==1){n++;}
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        a[i][j]=((i+j)%n)+1;
        if(i%2){
          a[i][j]+=n;
        }
        if(a[i][j]>k){a[i][j]-=n;}
      }
    }
    printf("%d\n",n);
    for(i=0;i<n;i++){
      prarr(a[i],n);
    }
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  for(int k=2;k<=m;k++){
    for(int i=0;i<n-1;i++){
      if(a[i]%k>a[i+1]%k)swap(a[i],a[i+1]);
    }
  }
  for(int i=0;i<n;i++)cout<<a[i]<<endl;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	int n;
	long long a;
	long ans = 0;
	
	cin >> n;
	
	for(int i = 0; i < n; i ++ ){
		cin >> a;
		while(a % 2 == 0) {
			a = a / 2;
			ans++;
		}
	}
	
	cout << ans << endl;


	return 0;
}


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

int main(void) {
  vector<int> A(9);
  vector<bool> Bingo(9, false);
  for (int i = 0; i < 9; i++) {
    cin >> A[i];
  }
  int N;
  cin >> N;
  int b;
  for (int i = 0; i < N; i++) {
    cin >> b;
    for (int j = 0; j < 9; j++) {
      if (b == A[j]) {
        Bingo[j] = true;
      }
    }
  }

  if ((Bingo[0] == true && Bingo[1] == true && Bingo[2] == true) ||
      (Bingo[3] == true && Bingo[4] == true && Bingo[5] == true) ||
      (Bingo[6] == true && Bingo[7] == true && Bingo[8] == true) ||
      (Bingo[0] == true && Bingo[3] == true && Bingo[6] == true) ||
      (Bingo[1] == true && Bingo[4] == true && Bingo[7] == true) ||
      (Bingo[2] == true && Bingo[5] == true && Bingo[8] == true) ||
      (Bingo[0] == true && Bingo[4] == true && Bingo[8] == true) ||
      (Bingo[2] == true && Bingo[4] == true && Bingo[6] == true)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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; }
const ll MOD = 1e9+7;

ll A[100100][20];
int main(){
    string S;
    cin >> S;
    int N = S.length();

    A[0][0] = 1;
    for(int i = 0; i < N; i++){
        char c = S[i];
        if(c == '?'){
            REP(t,10){
                int x = t * pow(10, (N-i-1)%6);
                x %= 13;
                //cout << x << endl;
                REP(j,13){
                    A[i+1][(j+x)%13] += A[i][j];
                    A[i+1][(j+x)%13] %= MOD;
                }
            }
        }
        else{
            int x = c - '0';
            x *= pow(10, (N-i-1)%6);
            x %= 13;
            REP(j,13){
                A[i+1][(j+x)%13] += A[i][j];
                A[i+1][(j+x)%13] %= MOD;
            }
        }
    }

    //REP(i,N+1){
    //    REP(j,13){
    //        printf("%lld ", A[i][j]);
    //    }
    //    printf("\n");
    //}
    //printf("\n");

    ll ans = A[N][5];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 16128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n,k,q;
  int a[SIZE];
  vector<pair<int,int> > vec;
  
  scanf("%d%d%d", &n, &k, &q);

  for(int i=0;i<n;i++){
    scanf("%d", a+i);
    vec.push_back({a[i], i});
  }
  a[n] = -1;

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

  int ans = INF;
  
  for(int i=0;i<n-k+1;i++){
    vector<int> vec2,vec3;

    int l = 0, low = 0; 
    
    for(int j=0;j<=n;j++){
      if(a[j] >= vec[i].first){
        low++;
        vec2.push_back(a[j]);
      }else{
        int size = min((j-l)-k+1, low);

        sort(vec2.begin(), vec2.end());
        for(int p=0;p<size;p++) vec3.push_back(vec2[p]);
        vec2 = vector<int>();
        l = j+1;
        low = 0;
      }
    }
    
    if(vec3.size() >= q){
      sort(vec3.begin(), vec3.end());

      ans = min(ans, vec3[q-1] - vec[i].first);
    }
    
  }

 
  cout << ans << endl;
  
  return 0;
}



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

public class Hello{
    public static Scanner sc = new Scanner();
    public static void Main(){
        var s = sc.Next();

        for(var i = 0; i < s.Length; i = i + 2){
            Console.Write(s.Substring(i, 1));
        }
    }
}

public class Scanner{
    private string line;
    private string[] token;
    private int cursole = 0;
    
    public string ReadLine(){
        line = Console.ReadLine();
        token = line.Split(' ');
        cursole = 0;
        return line;    
    }
    
    public string Next(){
        if(token == null) ReadLine();
        if(token.Length <= cursole) ReadLine();
        var ret = token[cursole];
        ++cursole;
        return ret;
    }

    public IEnumerable<double> NextDoubleList(){
        return NextList().Select(s => Double.Parse(s));
    }

    public int NextInt(){return Int32.Parse(Next());}
    
    public long NextLong(){return Int64.Parse(Next());}

    public double NextDouble(){return Double.Parse(Next());}

    public IEnumerable<string> NextList(){
        ReadLine();
        cursole = Int32.MaxValue;
        return token;
    }
    
    public IEnumerable<int> NextIntList(){
        return NextList().Select(s => Int32.Parse(s));
    }
}

public static class Extension{
    public static IEnumerable<int> To(this int from, int to){
        return Enumerable.Range(from, to);
    }

    public static void Times(this int times, Action<int> action){
        0.To(times).ToList().ForEach(x => action(x));
    }
}

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

#define MAXN 100010
#define ll long long
#define mod 1000000007

using namespace std;

int n;
int a, b, c;

int main() {
	cin >> a>> b >> c;
	if (a + b + c >= 22) cout << "bust\n";
	else cout << "win\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int isprime(int);
 
int main(){
  int i, count=0, n, x;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x);
    if(isprime(x) == 0) count++;
    else continue;
  }
  printf("%d\n", count);
  return 0;
}
 
int isprime(int x){
  int i=3;
  if(x == 2) return 0;
   
  if(x < 2 || x % 2 == 0)return 1;
   
  while(i <= sqrt(x)){
    if (x % i == 0) return 1;
    i = i + 2;
      }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1LL << 32;
const int INF = 1e12;

signed main(){
	int t;
	cin >> t;
	rep(ij, 0, t){
		int a[9] = {}, b[8] = {}, k = 0, sum = 0;
		rep(i, 0, 9){
			scanf("%x", &a[i]);
		}
		rep(i, 0, 32){
			int tmp = 0;
			rep(j, 0, 8){
				if(a[j] & (1LL << i)) tmp++;
			}
			// cout << tmp % 2 << " " << !!(a[8] & (1LL << i)) << endl;
			int now = !!(a[8] & (1LL << i));
			if(sum & (1LL << i)) now = (now + 1) % 2;
			if(tmp % 2 == now){
				sum += tmp * (1LL << i);
				sum %= mod;
				//a[8] = (a[8] - tmp * (1LL << i) % mod + mod) % mod;
			}else{
				sum += (8 - tmp) * (1LL << i);
				sum %= mod;
				//a[8] = (a[8] - (8 - tmp) * (1LL << i) % mod + mod) % mod;
				k += (1LL << i);
			}
		}
		printf("%x\n", k);
	}
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main()
{
    int r, g;
    cin >> r >> g;
    int ans = 2 * g - r;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a[8][8];
	char v[8][8];
	int i,j;
	while(1){
	for(i = 0;i < 8;i++){
		for(j = 0;j < 8;j++){
			if(scanf(" %c",&v[i][j]) == EOF){
				return 0;
			}
			a[i][j] = v[i][j] - 48;
		}
	}
	for(i = 0;i < 8;i++){
		for(j = 0;j < 8;j++){
			if(a[i][j] == 1){
				if(a[i][j+1] == 1 && a[i+1][j] == 1 && a[i+1][j+1] == 1){
					printf("A\n");
					break;break;
				}
				else if(a[i+1][j] == 1 && a[i+2][j] == 1 && a[i+3][j] == 1){
					printf("B\n");
					break;break;
				}
				else if(a[i][j+1] == 1 && a[i][j+2] == 1 && a[i][j+3] == 1){
					printf("C\n");
					break;break;
				}
				/*else if(a[i+1][j] == 1 && a[i+1][j-1] == 1 && a[i+2][j-1] == 1){
					printf("D\n");
					break;break;
				}*/
				else if(a[i][j+1] == 1 && a[i+1][j+1] == 1 && a[i+1][j+2] == 1){
					printf("E\n");
					break;break;
				}
				else if(a[i+1][j] == 1 && a[i+1][j+1] == 1 && a[i+2][j+1] == 1){
					printf("F\n");
					break;break;
				}
				else if(a[i+1][j] == 1 && a[i+1][j-1] == 1 && a[i+2][j-1] == 1){
					printf("D\n");
					break;break;
				}
				else if(a[i][j+1] == 1 && a[i+1][j] == 1 && a[i+1][j-1] == 1){
					printf("G\n");
					break;break;
				}
			}
		}
	}
	}
	return 0;
}

Measured memory_bytes: 524
#include<stdio.h>

 int main(){
     int a,b,c,tmp;
     scanf("%d%d%d",&a,&b,&c);
     if(a>b){tmp;tmp=a;a=b;b=tmp;}
     if(b>c){tmp;tmp=b;b=c;c=tmp;}
     if(a>b){tmp;tmp=a;a=b;b=tmp;}

     printf("%d %d %d\n",a,b,c);
     return 0;
     }


Measured memory_bytes: 2088
#include<stdio.h>
#include<math.h>
  
int koch(double x1,double y1,double x2,double y2,int n){
 
  if(n==0){
    printf("%f %f\n",x2,y2);
    return 0;
  }
 
  double Ax,Ay,Bx,By,Cx,Cy;
  Ax=(x2-x1)/3+x1;
  Ay=(y2-y1)/3+y1;
  Bx=(x2-x1)*2/3+x1;
  By=(y2-y1)*2/3+y1;
  Cx=(cos(M_PI/3)*(Bx-Ax)-sin(M_PI/3)*(By-Ay))+Ax;
  Cy=(sin(M_PI/3)*(Bx-Ax)+cos(M_PI/3)*(By-Ay))+Ay;
  koch(x1, y1, Ax, Ay, n-1);
  koch(Ax, Ay, Cx, Cy, n-1);
  koch(Cx, Cy, Bx, By, n-1);
  koch(Bx, By, x2, y2, n-1);
    
}
 
 
int main(){
  int n;
  double x1=0,y1=0,x2=100,y2=0;
  scanf("%d",&n);
  printf("0.00000000 0.00000000\n");
  koch(x1,y1,x2,y2,n);
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
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 (b<a) {a=b; return 1;} return 0;}

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vi price(m);
    vi key(m);
    rep(i, m) {
        int b;
        cin >> price[i] >> b;
        int bit = 0;
        rep(j, b) {
            int c;
            cin >> c;
            c--;
            bit += 1<<c;
        }
        key[i] = bit;
    }
    vvi dp(m+1, vi(1<<n, INF));
    // dp[i+1][bit] = i番目までの鍵を使ってbitの部屋を開けるときの最小費用

    dp[0][0] = 0;
    rep(i, m) {
        rep(bit, 1<<n) { 
            chmin(dp[i+1][bit], dp[i][bit]);
            chmin(dp[i+1][bit|key[i]], dp[i][bit] + price[i]);
        }
    }
    if (dp[m][(1<<n)-1] == INF) cout << -1 << endl;
    else cout << dp[m][(1<<n)-1] << endl;
} 

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const ll INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (a < b) {
        ll x = a + v * t;
        ll y = b + w * t;
        if (y <= x) cout << "YES" << endl;
        else cout << "NO" << endl;
    } else {
        ll x = a - v * t;
        ll y = b - w * t;
        if (x <= y) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
N = int(input())

A = list(map(int,input().split()))

A.sort()

memo = [0]*N

for i in range(N):
    memo[i] = memo[i-1]+A[i]

for i in range(N-1,0,-1):
    if A[i] <= 2 * memo[i-1]:
        ans = i-1
    else:
        break
print(N-ans)

Measured memory_bytes: 86156
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()

typedef pair<int, int> Pii;
typedef vector<int> V;
typedef vector<vector<int> > VV;
typedef long long ll;
const int inf = 2e9;
const int mod = 1e9 + 7;


int main()
{
	vector<string> VS;
	string S;
	int N, L;
	cin >> N >> L;
	rep(i,0,N) {
		cin >> S;
		VS.pb(S);
	}

	sort(all(VS));
	for (auto s: VS) cout << s;
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,j,N,M,K;
  cin>>N>>M;
  K=max({N+M,N*M,N-M});
  cout <<K <<endl;
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<int>ans(N);
    for(int i = 0; i < N; i++) {
        ans[A[i]-1] = i+1;
    }
    for(int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}

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

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);

    for (int i = 0; i < m; i++){
        cin >> b.at(i);
    }

    int count = 0;
    for (int i = 0; i < n; i++){
        int point = 0;
        
        for (int j = 0; j < m; j++){
            int tmp;
            cin >> tmp;
            point += tmp * b.at(j);
        }

        point += c;
        if (point > 0){
            count++;
        }
    }

    cout << count << endl;
}

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

using namespace std;

int main(){
  int N; cin >> N;
  double res = 0.0;
  
  for(int i = 0; i < N; i++){ 
     double a; cin >> a; res += 1/a;}
  
  cout << fixed << setprecision(10) << 1 / res << endl; return 0;}


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

using namespace std;

int main(){
  int a,b;cin >> a >> b;
  if(a*b==15){
    cout << '*'<<endl;
  }else if(a+b==15){
    cout << '+'<<endl;
  }else{
    cout << 'x'<<endl;
  }
}

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

using namespace std;

#define SQR(x) ((x)*(x))

int main()
{
  int N, ax, ay, bx, by, X[1000], Y[1000], R[1000];

  while(scanf("%d", &N), N) {
    scanf("%d %d %d %d", &ax, &ay, &bx, &by);
    for(int i = 0; i < N; i++) {
      scanf("%d %d %d", &X[i], &Y[i], &R[i]);
    }
    vector< int > latte, malta;
    for(int i = 0; i < N; i++) {
      int dist1 = SQR(X[i] - ax) + SQR(Y[i] - ay);
      int dist2 = SQR(X[i] - bx) + SQR(Y[i] - by);
      bool isin1 = dist1 < SQR(R[i]);
      bool isin2 = dist2 < SQR(R[i]);
      if(isin1 == isin2) continue;
      if(isin1) latte.emplace_back(i);
      else malta.emplace_back(i);
    }

    int dp[1000];
    memset(dp, -1, sizeof(dp));

    auto check = [&](int u, int v) // u->v
    {
      if(R[u] <= R[v]) return (false);
      return (SQR(X[u] - X[v]) + SQR(Y[u] - Y[v]) < SQR(R[u] - R[v]));
    };

    function< int(int, vector< int > &) > rec = [&](int idx, vector< int > &sss)
    {
      if(~dp[idx]) return (dp[idx]);
      int ret = 0;
      for(auto &i : sss) if(check(idx, i)) ret = max(ret, rec(i, sss));
      return (dp[idx] = ret + 1);
    };

    int ret = 0;
    for(int i : latte) {
      for(int j : malta) {
        int dist = SQR(X[i] - X[j]) + SQR(Y[i] - Y[j]);
        if(dist <= SQR(R[i] + R[j])) continue;
        ret = max(ret, rec(i, latte) + rec(j, malta));
      }
    }
    for(int i : latte) ret = max(ret, rec(i, latte));
    for(int i : malta) ret = max(ret, rec(i, malta));
    printf("%d\n", ret);
  }
}

Measured memory_bytes: 3264
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long 
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int ar[200000],dp[200000],n;
int solve(int i)
{
    if(i-1==n||n==1||n==2)
    return dp[n];
    dp[i]=abs(ar[i]-ar[i-1])+dp[i-1];
    dp[i]=min(dp[i],abs(ar[i]-ar[i-2])+dp[i-2]);
    return solve(i+1);
}
int main()
{
    SYNC
    in(n);
    l(i,1,n+1)
    in(ar[i]);
    dp[1]=0;
    dp[2]=abs(ar[1]-ar[2]);
    o(solve(3));
}

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

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

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
 
char field[103][103];
int h, w;

void bfs(int y, int x, char fruit){
    if( x<0 || x>=w || y<0 || y>=h || fruit != field[y][x] || field[y][x] == 'a'){
        return;
    }
    field[y][x] = 'a';

    for(int i=0; i<4; i++){
        bfs(y+dy[i], x+dx[i], fruit);
    }
}

int main(void){
    while(cin >> h >> w && h+w!=0){
    	int ans=0;
	    for(int i=0; i<h; i++){
	        for(int j=0; j<w; j++){
	            cin >> field[i][j];
	        }
	    }
	    for(int i=0; i<h; i++){
	        for(int j=0; j<w; j++){
	            if(field[i][j] != 'a'){
	                bfs(i,j,field[i][j]);
	                ans++;
	            }
	        }
	    }
	    cout << ans << endl;
    }
    return 0;
}

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

int main(){
    int N; cin >> N;;
    P C[200100];

    bool flag=true;
    for(int i=0; i<N; i++){
        ll a, b ; cin >> a >> b;
        if(b<a) flag=false;
        C[i]=P(b,a);
    }
    //
    sort(C,C+N);
    ll now=0;

    for(int i=0; i<N; i++){
        ll x = C[i].first;
        ll y = C[i].second;
        if(now+y > x) {flag=false;}
        else{
            now +=y;
        }
    }

    if(!flag) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3328
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
if A == B:
  print("Yes")
  exit()
for i in range(N-M):
  for j in range(N-M):
    x = []
    for k in range(M):
      for l in range(M):
        x.append(A[i+k][j+l])
    if ''.join(x) == ''.join(B):
      print("Yes")
      exit()

print("No")

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }


string solve()
{
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    if (a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2)
        return "infinity";

    if (a1 * t1 + a2 * t2 < b1 * t1 + b2 * t2)
    {
        std::swap(a1, b1);
        std::swap(a2, b2);
    }

    if (a1 > b1) return "0";

    ll num = t1 * (b1 - a1);
    ll denom = (t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2);

    ll period = 2 * (num / denom);

    if (num % denom != 0)
        period++;

    return std::to_string(period);
}

int main()
{
    std::cout << solve() << std::endl;

    return 0;
}

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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define debp(a) cerr << #a << " => " <<"("<<a.fs<<", "<<a.sc<<") " << en;
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debpa(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	double a, b;
	cin >> a >> b;
	int x = a * b;
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5],B[MAXN+5],F[MAXN+5];

ll Solves(){
	
	ll n,m=0,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc(n);
	f1(i,n)sc(A[i]); reverse(A+1,A+1+n);
	for (int i=1; i<=n; i++) {
        F[i] = upper_bound(B+1, B+m+1, A[i]) - B;
        m = max(m, F[i]);
        B[F[i]] = A[i];
    }
    pr(m);
	

	re 0;
	// Hack it if you can :)
}

int main(){
//	INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 9216
lst = []
N, M = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
ans = 0
if (N < M):
  dis = [lst[i+1] - lst[i] for i in range(len(lst)-1)]
  dis.sort(reverse=True)
  ans = lst[-1] - lst[0] - sum(dis[:N-1])
print(ans)


Measured memory_bytes: 13968
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
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); }

//FUNCTION
void solve(void)
{
  string str;
  cin>>str;
  int K;
  cin>>K;
  int n = -1;
  int streak = 0;
  // reverse(ALL(str));
  
  for (int i = 0; i < str.size(); i++)
  {
    if(str[i] == '1')
    {
      streak++;
    }
    else
    {
      n = (str[i]-'0');
      break;
    }
  }
  // DEBUG(n);
  if(K <=streak)
  {
    cout<<1<<endl;
  }
  else
  {
    cout<<n<<endl;
  }
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 256
import re
import sys
from collections import *
from functools import lru_cache
from heapq import *
from itertools import *

INF=float('inf')

sys.setrecursionlimit(2**31-1)

rfs=lambda:rl().split()
ri=lambda:int(rl())
ris=lambda:list(map(int,rfs()))
rl=lambda:next(sys.stdin)
rrs=lambda:list(map(str.strip,sys.stdin))
rs=lambda:rl().strip()
rt=lambda:sys.stdin.read()
rg=lambda:list(map(list,rrs()))

def n4(i,j):
    return [
                (i-1,j),
        (i,j+1),        (i,j-1),
                (i+1,j),
    ]

def n8(i,j):
    return [
        (i-1,j-1),(i-1,j),(i-1,j+1),
        (  i,j-1),        (  i,j+1),
        (i+1,j-1),(i+1,j),(i+1,j+1),
    ]

inb=lambda i,j,m,n:0<=i<m and 0<=j<n

###########################################

N,a=ri(),ris()
a.sort(reverse=True)
print(sum(a[::2])-sum(a[1::2]))


Measured memory_bytes: 9868
r=[*?A..?Z]
x=Hash[(r+" .,-'?".chars).zip (0..31).map{|i|"%05b"%[i]}]
y=Hash["dggigggieedfigeiefiifdieffiigiii".bytes.map{|i|i-97}.zip("836$D4X-849<.C:+97,18:2;9:/05%&#".bytes.map{|c|c<51?c+109:c-51}).map{|a|"%0*b"%a}.zip" ',-.?".chars+r]
puts$<.map{|l|l.gsub(/./,x).gsub(/1(1.|0(1|0(0|1(1.#{z="..|0(1|0..)))"}))|0(1(1.|0(1|0(1|0.)))|0(1#{z}/,y).delete ?0}

Measured memory_bytes: 6120
# coding: utf-8
# Your code here!
N=int(input())
P=list(map(int,input().split()))

flag=True
for index,item in enumerate(P):
    #print(index,item)
    if index!=item-1:
        if flag:
            if P[item-1]==index+1:
                P[item-1]=item
                flag=False
            else:
                print("NO")
                exit()
        else:
            print("NO")
            exit()

print("YES")

Measured memory_bytes: 3060
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n[4];
    int a[4];rep(i,0,4)a[i]=false;
    rep(i,0,4){
        cin>>n[i];
        if(n[i]==1)a[0]++;
        if(n[i]==4)a[1]++;
        if(n[i]==7)a[2]++;
        if(n[i]==9)a[3]++;
    }
    rep(i,0,4){
        if(!a[i]){
            cout<<"NO"<<endl;return 0;
        }
    }
    cout<<"YES"<<endl;return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int k, a, b; cin >> k >> a >> b;
    bool ok = false;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) ok = true;
    }
    printf(ok?"OK\n":"NG\n");
}

Measured memory_bytes: 3652
import sys


x, y = map(int, input().split())

ret = abs(abs(y) - abs(x))

if x * y == 0:
  if x == 0:
    if y >= 0:
      pass
    else:
      ret += 1
  else:
    if x > 0:
      ret += 1
    else:
      pass
elif x * y > 0:
  if x > 0:
    if abs(x) > abs(y):
      ret += 2
    else:
      pass
  else:
    if abs(x) > abs(y):
      pass
    else:
      ret += 2
else:
  ret += 1
  
print(ret)

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

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s;
    cin>>s;
    int ans=0;
    for (int i=0;i<s.size()-1;i++){
        if (s[i]!=s[i+1]){
            ans++;
        }
    }cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a > b && a > c)	cout << b * c / 2;
	else if (b > a &&  b > c) cout << a * c / 2;
	else cout << a * b / 2;

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s


int main()
{
	int n, a, b, m[8];
	vector<pair<int, int>> v;
	while (1)
	{
		v.clear();
		cin >> n; if (n == 0) return 0;
		REP(i, n)
		{
			cin >> a;
			REP(j, 8) cin >> m[j];
			b = (m[0] + m[2] + m[4] + m[6]) * 60 + (m[1] + m[3] + m[5] + m[7]);
			v.push_back(make_pair(b, a));
		}
		sort(v.begin(), v.end());
		cout << v[0].second << endl << v[1].second << endl << v[n - 2].second << endl;
	}
	return 0;
}

Measured memory_bytes: 1304
R,G,B,N=list(map(int,input().split()))
ans=0
if 1<=R<=3000 and 1<=G<=3000 and 1<=B<=3000 and 1<=N<=3000:
	limR=N//R
	for r in range(limR+1)[::-1]:
		zanGB=N-r*R
		limG=zanGB//G
		for g in range(limG+1):
			zanB=zanGB-g*G
			if zanB%B==0:
				b=zanB//B
				ans+=1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define sp fixed<<setprecision
#define sz sizeof
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod2=998244353;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    map<pair<ll,ll>,ll>m;
    ll res=0;
    string s;
    for(int i=0;i<n;i++){
      cin>>s;
      //cout<<s<<"\n";
      ll cur=0;
      ll cnt=0;
      bool aftdot=false;
      for(int j=0;j<s.size();j++){
        if(s[j]=='.'){
          aftdot=true;
          continue;}
        if(aftdot==true)
          cnt++;
        cur*=10;
        cur+=(s[j]-'0');
      }
      for(int j=0;j<9-cnt;j++)
        cur*=10;
      ll y=cur;
      //cout<<y<<"\n";
      ll cnt2=0,cnt5=0;
      while(y%2==0){
        cnt2++;
        y/=2;
      }
      while(y%5==0){
        cnt5++;
        y/=5;
      }
      m[{cnt2,cnt5}]++;
      //cout<<cnt2<<" "<<cnt5<<"\n";
    }
    for(auto u1:m){
      for(auto u2:m){
        ll cnt10=min(u1.f.f+u2.f.f,u1.f.se+u2.f.se);
        if(cnt10>=18){
          if(u1.f!=u2.f)
          {
            res+=(u1.se*u2.se);
          }
          else{
            res+=(u1.se*(u1.se-1));
          }
        }
      }
    }
    res/=2;

    cout<<res;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<vector<ll>> grid;
vector<vector<bool>> visited;
ll H, W;

void dfs(ll i, ll j) {
    if (visited[i][j]) return;
    visited[i][j] = true;
    rep(d, 8) {
        ll y = i + ddx[d];
        ll x = j + ddy[d];
        if (0 <= x && x < W && 0 <= y && y < H && grid[y][x]) {
            dfs(y, x);
        }
    }
    return;
};

void solve() {
    while (true) {
        cin >> W >> H;
        if (W == 0 && H == 0) return;
        grid.assign(H, vector<ll>(W, 0));
        rep(i, H) {
            rep(j, W) {
                cin >> grid[i][j];
            }
        }
        ll ans = 0;
        visited.assign(H, vector<bool>(W, false));
        rep(i, H) {
            rep(j, W) {
               if (grid[i][j] && !visited[i][j])  {
                   ans++;
                   dfs(i, j);
               }
            }
        }
        cout << ans << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}



Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000007;
 
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int word=s.size();
  
  int count=0;
  for(int i=0; i<word; i++){
    if(s[i]=='E') count++;
  }
  
  int ans=10e9;
  int place=0;
  for(int i=0; i<word; i++){
   if(i>0 && s[i-1]=='E') count--;
   if(i>0 && s[i-1]=='W') count++;
   if(ans>count){
     ans=count;
     place=i;
   }
  }
  
  if(s[place]=='E') cout << ans-1 << endl;
  else cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 900
#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 << "\n";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <complex>
#include <cmath>

using namespace std;
const double eps = 1e-11;

typedef complex<double> xy_t;

double dotProduct(xy_t a, xy_t b){
	return (conj(a) * b).real();
}

double crossProduct(xy_t a, xy_t b){
	return (conj(a) * b).imag();
}

xy_t projection(xy_t p, xy_t b){
	return b*dotProduct(p,b)/norm(b);
}

int main (){
	int N;
	double X[4],Y[4];
	cin >> N;
	for(int t = 0; t < N; ++t){
		for(int i = 0; i < 4; ++i) cin >> X[i] >> Y[i];
		xy_t a[2] = {
			xy_t(X[0],Y[0]) - xy_t(X[1],Y[1]),
			xy_t(X[2],Y[2]) - xy_t(X[3],Y[3]),
		};
		cout << ((abs(crossProduct(a[0],a[1])) < eps) ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 1228