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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX



int n,a,b;

signed main() {
    cin >> n >> a >> b;
    --n, --a, --b;
    if (abs(a-b)%2) {
        int ans1,ans2;
        ans1 += min(a,b);
        ans1 += abs(a-b)/2+1;
        ans2 += min(n-a,n-b);
        ans2 += abs(a-b)/2+1;
        cout << min(ans1,ans2) << endl;
    }
    else cout << abs(a-b)/2 << endl;
}


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

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> k(M);
    vector<vector<int>> s;
    s.assign(M,vector<int>());
    for ( int i = 0; i < M; ++i){
        cin >> k.at(i);
        for ( int j = 0; j < k.at(i); ++j){
            int x;
            cin >> x;
            --x;
            s[i].push_back(x);
        }
    }
    vector<int> p(M);
    for ( int i = 0; i < M; ++i){
        cin >> p.at(i);
    }
    
    vector<vector<int>> S;
    S.assign((1<<N),vector<int>());
    for ( int i = 0; i < (1<<N); ++i){
        //cout << i ;
        for ( int j = 0; j < N; ++j){
            if ( i & (1<<j) ){
                S[i].push_back(j);
                //cout << j;
            }
        }
        //cout << endl;
    }
    
    int ans = 0;
    // switch の on off で全探索
    for ( int i = 0; i < (1<<N); ++i){
        // それぞれの電球について調べる
        int on_num = 0;
        for ( int j = 0; j < M; ++j){
            int sum = 0;
            for ( int l = 0; l < k.at(j); ++l){
                for ( int m : S[i] ){
                    //cout << "ijsm " << i << " " << j << " " << s[j][l] << " " << m << endl;
                    if ( s[j][l] == m ) {
                        ++sum;
                    }
                }
            }
            //cout << i << " " << j << " " << sum << endl;
            if ( sum % 2 == p[j] ) {
                ++on_num;
            }
            //cout << on_num << endl;
        }
        if ( on_num == M ){
            ++ans;
        }
        //cout << "ans " << ans << endl;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<vector<pii>> xy(n);
    REP(i, n){
        int a;
        cin >> a;
        REP(j, a){
            int x, y;
            cin >> x >> y;
            x--;
            xy[i].push_back({x, y});
        }
    }

    int ans = 0;
    for(int bit = (1<<n)-1;bit>=0;bit--){
        int num = 0;
        REP(i, n){
            if((bit>>i)&1) num++;
        }

        bool ok = true;
        REP(i, n){
            int b = (bit>>i)&1;
            if(b == 0)
                continue;
            REP(j, xy[i].size()){
                int b2 = (bit >> xy[i][j].first) & 1;
                if(xy[i][j].second == 1 && b2 != b)
                    ok = false;
                if(xy[i][j].second == 0 && b2 == b)
                    ok = false;
            }
        }
        if(ok){
            ans = max(ans, num);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  int p;
  string s;
  map<int, bool> tf;
  map<int, int> cnt;
  for ( int i = 0; i < m; i++){
    cin >> p >> s;
    if ( s == "AC"){
      tf[p] = true;
    } else if ( !tf[p]) {
      tf[p] = false;
      cnt[p]++;
    }
  }

  int ac = 0,  wa = 0;
  for ( map<int, bool>::iterator it = tf.begin(); it != tf.end(); it++){
    if ( it->second){
      ac++;
      wa += cnt[it->first];
    }
  }
  cout << ac << " " << wa << endl;

  return 0;
}

Measured memory_bytes: 9600
//Not so Diverse

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    rep(i,0,n)cin>>a[i];
    vector<ll>t(200001,0);
    rep(i,0,n)t[a[i]]++;
    sort(range(t),greater<int>());
    ll ans=0;
    rep(i,0,k)ans+=t[i];
    cout<<n-ans<<nnn;    
    return 0;
}

Measured memory_bytes: 3328
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
data = [0] * n
for ai in A:
  ai -= 1
  data[ai] += 1
for di in data:
  print(di)

Measured memory_bytes: 92816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool dfs(int st,int par,vector<vector<int> >&adj,vector<int>&p,vector<int>&h,vector<int>&g,vector<int>&b){
    bool ans=true;
    int flag=0;
    int x,y;
    for(int j=0;j<adj[st].size();j++){
        if(adj[st][j]!=par){
        //cout<<adj[st][j]<<" "<<par<<" "<<st<<endl;
            flag=1;
            ans=ans&dfs(adj[st][j],st,adj,p,h,g,b);
            g[st]+=g[adj[st][j]];
            b[st]+=b[adj[st][j]];
            p[st]+=p[adj[st][j]];
        }
    }
    if(flag==0){
        if(abs(h[st])>p[st]){
        	//cout<<st<<endl;
        	return false;
		}
        else {
            g[st]=(p[st]+h[st])/2;
            b[st]=(p[st]-h[st])/2;
            //cout<<st<<" "<<p[st]<<" "<<h[st]<<" "<<g[st]<<" "<<b[st]<<endl;
            if(g[st]+b[st]==p[st])
            return true;
            else return false;
        }
    }
    else{
        int x=(p[st]+h[st])/2;
        int y=(p[st]-h[st])/2;
        //cout<<st<<" "<<p[st]<<" "<<h[st]<<" "<<g[st]<<" "<<b[st]<<" "<<ans<<endl;
        if(x<0||y<0||(x+y)!=p[st]||(x-y)!=h[st]||abs(h[st])>p[st]||x<g[st])return ans&false;
        else {
        	g[st]=x;
        	b[st]=y;
        	return ans&true;
		}
    }
}

int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    int w=0,r=0;
    for(int i=0;i<k;i++)if(s[i]=='W')w++;else r++;
    int  ans=min(w,r);
    int cnt=0;
    for(int i=0;i<r;i++)if(s[i]=='W')cnt++;
    cout<<min(ans,cnt)<<endl;
}


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

int main() {
    long long a, b, c;cin>>a>>b>>c;
    if( a%2 ==0 || b%2 ==0 || c%2==0) cout<<0<<endl;
    else cout<<min( min(a*b, b*c), a*c)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int X;
    cin >> X;
    for (int i = 1; ; ++i) {
        int tmp = 0;
        rep(j, i + 1) {
            tmp += j;
        }
        if (tmp >= X) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b;
  if(a <= 5)
    cout << 0 << endl;
  if(a >= 6 && a <= 12)
    cout << b / 2 << endl;
  if(a >= 13)
    cout << b << endl;

}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
s = [str(input()) for _ in range(n)]
count = [0]*5
# M A R C H
for i in range(n):
    if s[i][0] == "M":
        count[0] += 1
    elif s[i][0] == "A":
        count[1] += 1
    elif s[i][0] == "R":
        count[2] += 1
    elif s[i][0] == "C":
        count[3] += 1
    elif s[i][0] == "H":
        count[4] += 1
ans = 0
ans += count[0]*count[1]*count[2]
ans += count[0]*count[1]*count[3]
ans += count[0]*count[1]*count[4]
ans += count[0]*count[2]*count[3]
ans += count[0]*count[2]*count[4]
ans += count[0]*count[3]*count[4]
ans += count[1]*count[2]*count[3]
ans += count[1]*count[2]*count[4]
ans += count[1]*count[3]*count[4]
ans += count[2]*count[3]*count[4]
print(ans)

Measured memory_bytes: 16496
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int P = sc.nextInt();
	    int Q = sc.nextInt();
	    int R = sc.nextInt();
	    sc.close();
	    
	    System.out.println(Math.min(Math.min(P+Q, P+R), Q+R));

	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vector<double> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];

  double f = 1;
  rrep(i,n) f *= i;

  vector<int> v;
  rep(i,n) v.push_back(i);

  double sum = 0;
  do {
    rep(i,n-1) {
      double tmp = 0;
      tmp += (x[v[i]] - x[v[i+1]])*(x[v[i]] - x[v[i+1]]);
      tmp += (y[v[i]] - y[v[i+1]])*(y[v[i]] - y[v[i+1]]);
      sum += sqrt(tmp);
    }
  } while (next_permutation(v.begin(), v.end()));

  double ans = sum/f;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int cost[10][10];
int N;
int nTown;

static const int INT_MAX = 1e6;

void init() {
	fill(cost[0], &cost[9][10], INT_MAX);
	for (int i = 0; i < 10; i++) {
		cost[i][i] = 0;
	}
	nTown = -1;
}

void solve() {
	for (int k = 0; k < nTown; k++) {
		for (int i = 0; i < nTown; i++) {
			for (int j = 0; j < nTown; j++) {
				cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
			}
		}
	}
	int mn = INT_MAX, idx = -1;
	for (int t = 0; t < nTown; t++) {
		int sum = 0;
		for (int i = 0; i < nTown; i++) {
			sum += cost[t][i];
		}
		if (sum < mn) {
			idx = t, mn = sum;
		}
	}
	printf("%d %d\n", idx, mn);
}

int main() {
	while (scanf("%d ", &N) != EOF) {
		if (N == 0) {
			return 0;
		}
		init();
		for (int i = 0; i < N; i++) {
			int a, b, c;
			scanf("%d %d %d ", &a, &b, &c);
			cost[a][b] = c;
			cost[b][a] = c;
			nTown = max(a, max(b, nTown));
		}
		nTown++;
		solve();
	}	
}

Measured memory_bytes: 0
// D - Practical Skill Test
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);++i)

int main(){
	int H,W,D; cin>>H>>W>>D;

	int MAX = H * W;
	vi HH(MAX), WW(MAX), DD(MAX);

	rp(h, H) rp(w, W){ int a; cin>>a; HH[a-1] = h; WW[a-1] = w; }

	for(int now=D; now<MAX; ++now){
		int pre = now - D;
		DD[now] = DD[pre] + abs(HH[pre] - HH[now]) + abs(WW[pre] - WW[now]);
	}

	int Q; cin>>Q;
	while(Q--){ int l,r; cin>>l>>r; cout<< DD[r-1] - DD[l-1] <<endl; }
}

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

const long long int NIL = -1;

struct Mobile {
    long long int weight;
    int left, right;
    int left_child, right_child;
    Mobile(int l, int r, int lc, int rc) :weight(NIL), left(l), right(r), left_child(lc), right_child(rc) {}
};

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

long long int lcm(long long int a, long long int b) {
    return a * b / gcd(a, b);
}

long long int weight(vector<Mobile>& mobile, int n) {
    if(n == NIL) return 1;
    if(mobile[n].weight != NIL) return mobile[n].weight;
    int left_weight = weight(mobile, mobile[n].left_child);
    int right_weight = weight(mobile, mobile[n].right_child);
    if(left_weight * mobile[n].right != right_weight * mobile[n].left) {
        long long int d = lcm(left_weight * mobile[n].left, right_weight * mobile[n].right);
        left_weight = d / mobile[n].left;
        right_weight = d / mobile[n].right;
    }
    return mobile[n].weight = left_weight + right_weight;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<Mobile> mobile;
        for(int i = 0; i < n; ++i) {
            int p, q, r, b;
            cin >> p >> q >> r >> b;
            int d = gcd(p, q);
            p /= d;
            q /= d;
            --r;
            --b;
            mobile.push_back(Mobile(p, q, r, b));
        }
        long long int answer = 0;
        for(int i = 0; i < n; ++i) answer = max(answer, weight(mobile, i));
        cout << answer << endl;
    }
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    int ret = 0;
    int cnt = 0;
    for(int i = 0;i < N;i++) {
        if(vec.at(i) == i + 1) {
            cnt++;
        }
        else {
            if(cnt == 0) {
                ret = ret;
            }
            else {
                ret += (cnt + 1) / 2;
            }
            cnt = 0;
        }
    }
    if(cnt == 0) {
        ret = ret;
    }
    else {
        ret += (cnt + 1) / 2;
    }
    cnt = 0;
    cout << ret << endl;
}

Measured memory_bytes: 640
function main()
    N = parse(Int, readline())
    A = map(x -> parse(Int, x), split(readline()))

    res = 0

    while true
        exist_odd = false
        for i = 1:N
            if A[i] % 2 != 0
                exist_odd = true
            end
        end

        if exist_odd
            break
        end

        for i = 1:N 
            A[i] /= 2
        end

        res += 1
    end

    println(res)
end

main()

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

int main() {
	string s;
	int a=0,b=0;
	
	while(cin>>s){
		if(s[0]=='0')break;
		
		for(int i=0;i<s.size();i++){
			if(s[i]=='A'){
				a+=1;
			}else if(s[i]=='B'){
				b+=1;
			}
		}
		
		if(s[s.size()-1]=='A'){
			
			if(a+b>=20){
				cout<<(a+b)/2+1<<" "<<(a+b)/2-1<<endl;
			}else{
				cout<<11<<" "<<a+b-11<<endl;
			}
			
		}else{
			
			if(a+b>=20){
				cout<<(a+b)/2-1<<" "<<(a+b)/2+1<<endl;
				}else{
				cout<<a+b-11<<" "<<11<<endl;
			}
			
		}
		a=0;
		b=0;
	}
	
	
	return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,x;
	cin>>a>>b>>x;
	long long p,q;
	if(a%x==0)p=a/x;
	else p=a/x+1;
	q=b/x;
	cout<<q-p+1<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

x = int(input())
#b = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]


if 400 <= x <= 599:
    print('8')
if 600 <= x <= 799:
    print('7')
if 800 <= x <= 999:
    print('6')
if 1000 <= x <= 1199:
    print('5')
if 1200 <= x <= 1399:
    print('4')
if 1400 <= x <= 1599:
    print('3')
if 1600 <= x <= 1799:
    print('2')
if 1800 <= x <= 1999:
    print('1')

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

int main()
{
 int n,x;
  cin>>n>>x;
  vector<int> v(n),p;
  for(int &i: v) cin>>i;
  p.push_back(0);
  for(int i=0;i<n;i++) p.push_back(p.back()+v[i]);
  
  int ans=0;
  for(auto i:p) if(i<=x) ans++;
  cout<<ans<<"\n";
  
  return 0;
}

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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e9+9;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[1000];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n;
    scanf("%d",&n);
    int sum1=0,sum2=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(i!=n-1){
            sum1+=a[i];
        }else{
            sum2+=a[i];
        }
    }
    int mn =OO;
    for(int i=n-2;i>=0;i--){
        mn=min(mn,abs(sum2-sum1));
        sum1-=a[i];
        sum2+=a[i];
    }
    printf("%d",mn);
    return 0;
}

Measured memory_bytes: 256
# bit全探索問題

N,M,X = map(int,input().split())
items = [list(map(int,input().split())) for _ in range(N)]
ans = -1
for i in range(1 << N):
    total = [0]*(M+1)
    for j in range(N):  
        if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
            total = [x + y for (x, y) in zip(total, items[j])]
    # print(total)
    if all( k >= X for k in total[1:]) == True:
        if ans == -1:
            ans = total[0]
        else:
            ans = min(ans,total[0]) 
print(ans)



Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
long long n;
void input(vector < long long > &inp)
{
    for (long long i=0;i<n;i++)
        cin>>inp[i];
}
long long comput(vector < long long > a,vector < long long > b,vector < long long > c)
{
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    long long i,ans=0;
    for (i=0;i<n;i++)
    {
        vector < long long >::iterator it1=lower_bound(a.begin(),a.end(),b[i]),it2=upper_bound(c.begin(),c.end(),b[i]);
        long long len1=it1-a.begin(),len2=it2-c.begin();
        ans+=len1*(n-len2);
    }
    return ans;
}
void solve()
{
    vector < long long > a(n),b(n),c(n);
    input(a);input(b);input(c);
    cout<<comput(a,b,c)<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  int count = 1;
  int deg = X;
  while (deg != 0)
  {
    deg += X;
    deg %= 360;
    count++;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
bool cmp(long long int x,long long int y)
{
   return x>y;
}
int main(void)
{
   long long int t,n,m,k,x,y,a=0,w=0,r=0,tl=0;
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   priority_queue< long long int,vector<long long int>,greater<long long int> > lpq;
   priority_queue< pair<long long int,long long int>,vector< pair<long long int,long long int> >,greater< pair <long long int,long long int> > > plpq;
   string s;
   cin>>t;
   while(t--)
   {
      cin>>s;
      if(s[0]=='A')
         a++;
      else if(s[0]=='W')
         w++;
      else if(s[0]=='R')
         r++;
      else if(s[0]=='T')
         tl++;
   }
   cout<<"AC x "<<a<<endl;
   cout<<"WA x "<<w<<endl;
   cout<<"TLE x "<<tl<<endl;
   cout<<"RE x "<<r<<endl;
   return 0;
}


Measured memory_bytes: 3632
import math

x, y = map(int, input().split(' '))
r = 0
x_comb = 0
y_comb = 0

if x <= 1:
    pass
else:
    x_comb = math.factorial(x)//(2 * math.factorial(x-2))

if y <= 1:
    pass
else:
    y_comb = math.factorial(y)//(2 * math.factorial(y-2))

print(x_comb+y_comb)


Measured memory_bytes: 3060
import math
n=int(input())
x=[float(i) for i in input().split()]
y=[float(i) for i in input().split()]
z=[float(0)for i in range(len(x))]
count=0.0
for i in range(len(x)):
    z[i]=abs(x[i]-y[i])
    count=count+abs(x[i]-y[i])
print("%.5f"%count)
count=0.0
for i in range(len(x)):
    count=count+abs(x[i]-y[i])*abs(x[i]-y[i])
print("%.5f"%math.sqrt(count))
count=0.0
for i in range(len(x)):
    count=count+abs(x[i]-y[i])*abs(x[i]-y[i])*abs(x[i]-y[i])
print("%.5f"%math.pow(count,(1.0/3.0)))
print("%.5f"%max(z))

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N;
    string S,T;
    cin >> N >> S >> T;

    for(int i = 0;i < N;i++){
        cout << S.at(i) << T.at(i);
    }
    cout << endl;

}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> D(K);
    rep(i,K)cin>>D[i];

    while(1){
        string S=to_string(N);
        bool ok=true;
        rep(digit,S.length()){
            int d=S[digit]-'0';
            rep(k,K){
                if(d==D[k]){
                    ok=false;
                }
            }
            if(!ok)break;
        }
        if(ok){
            cout<<N<<endl;
            break;
        }
        N++;
    }

    return 0;
}

//a=97,z=122

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll, int> ii;
typedef pair <ii,int> iii;

const ll inf = 1e17;
const ll mod = 1e9 + 7;
const int N = 200005;

void solve(){
	int n;
	cin >> n;
	multiset<int> st;
	vi v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	sort(v.rbegin(), v.rend());
	st.insert(v[0]);
	ll ans = 0;
	for(int i = 1; i < n; i++){
		int el = *st.rbegin();
		ans += el;
		st.erase(st.lower_bound(el));
		int put = min(el, v[i]);
		st.insert(put);
		st.insert(put);
	}
	cout << ans << endl;
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 13528
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a[15];
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{
    cin>>n;
    cin>>s;

    // n=sz(s);
    fo(i,n)
        a[s[i]-'0'].pb(i);

    lli ans=0;

    fo(i,1000)
    {

        // dbg(i,i/100,(i/10)%10,i%10);

        j=-1;
        x=i/100;
        auto jt=upper_bound(all(a[x]),j);
        if(jt==a[x].end())
            continue;
        dbg(i,j);
        j=*jt;
        x=(i/10)%10;
        jt=upper_bound(all(a[x]),j);
        if(jt==a[x].end())
            continue;

        dbg(i,j);
        j=*jt;
        x=i%10;
        jt=upper_bound(all(a[x]),j);
        if(jt==a[x].end())
            continue;

        dbg(i,j);
        ans++;
    }

    cout<<ans<<endl;

}   aryanc403();
    return 0;
}

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

int main(){
    string str;
    cin >> str;
    int s = 0;
    int e = str.size()-1;
    int ok = 1;

    int ans = 0;

    while(s <= e){
        if(s == e){
            break;
        }
        if(str[s] == str[e]){
            s++;
            e--;
            continue;
        }
        if(str[s] == 'x'){
            s++;
            ans++;
            continue;
        }
        if(str[e] == 'x'){
            e--;
            ans++;
            continue;
        }
        ok = 0;
        break;
    }
    if(ok == 0){
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

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

class Program
{
    static void Main(string[] args)
    {
        var x = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        if(x[0] == 0)
        {
            Console.WriteLine("1");
            return;
        }
        if (x[1] == 0)
        {
            Console.WriteLine("2");
            return;
        }
        if (x[2] == 0)
        {
            Console.WriteLine("3");
            return;
        }
        if (x[3] == 0)
        {
            Console.WriteLine("4");
            return;
        }
        if (x[4] == 0)
        {
            Console.WriteLine("5");
            return;
        }

    }
}

Measured memory_bytes: 28164
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val x = sc.nextInt()
    val c = Array(n) { 0 }
    val a = Array(n) { Array(m) { 0 } }
    for (i in 0 until n) {
        c[i] = sc.nextInt()
        for (j in 0 until m) {
            a[i][j] = sc.nextInt()
        }
    }
    var min = Int.MAX_VALUE
    for (i in 0 until 1.shl(n)) {
        val buy = Array(n) { false }
        for (j in 0 until n) {
            if ((1.shl(j) and i) != 0) {
                buy[j] = true
            }
        }
        var sum = 0
        val p = Array(m) { 0 }
        for (j in 0 until n) {
            if (buy[j]) {
                sum += c[j]
                for (k in 0 until m) {
                    p[k] += a[j][k]
                }
            }
        }
        if (p.all { it >= x }) {
            min = minOf(min, sum)
        }
    }
    println(if (min == Int.MAX_VALUE) -1 else min)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 42292
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP_[1000][31][31];
int H, W;

long long int DP(int t, int y, int x){
	if(y < 0 || x < 0 || y >= H || x >= W){
		return INF;
	}
	return DP_[t][y][x];
}

int main(){
	
	cin >> H >> W;
	
	long long int A[40][40];
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			cin >> A[i][j];
			for(int k = 0; k < 1000; k++){
				DP_[k][i][j] = INF;
			}
		}
	}
	
	DP_[0][0][0] = 0;
	long long int ans = INF;
	
	for(int t = 1; t < 1000; t++){
		for(int y = 0; y < H; y++){
			for(int x = 0; x < W; x++){
				long long int p1, p2;
				p1 = min(DP(t - 1, y - 1, x), DP(t - 1, y + 1, x));
				p2 = min(DP(t - 1, y, x - 1), DP(t - 1, y, x + 1));
				DP_[t][y][x] = min(p1, p2) + (2 * t - 1) * A[y][x];
			}
		}
		ans = min(ans, DP_[t][H - 1][W - 1]);
	}
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, T; cin >> n >> T;
    int from = 0;
    int until = T;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int t; cin >> t;
        if (i == n-1) {
            if (until < t) {
                sum += (until - from) + T;
            } else {
                sum += (t + T - from);
            }
            break;
        }
        if (until < t) {
            sum += (until - from);
            from = t;
        }
        until = t + T;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import Data.Array
import Data.List
import Data.List.Split

main :: IO ()
main = interact $ format . calc . map (map read . words) . tail . lines

calc :: [[Int]] -> [Int]
calc = elems . update (listArray (1,120) [0,0..])

update :: Array Int Int -> [[Int]] -> Array Int Int
update arr nss = accum (+) arr (map updInfo nss)
    where updInfo [b,f,r,v] = ((b-1)*30+(f-1)*10+r, v)

format :: [Int] -> String
format = intercalate sep . map unlines . chunksOf 3 . map ((' ' :) . unwords) . chunksOf 10 . map show
    where sep = replicate 20 '#' ++ "\n"


Measured memory_bytes: 4264
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<random>
#include<map>
using namespace std;
#define int long long
const long long mod = 1000000007;
typedef pair<int, int> P;

signed main() {
	int n, s; cin >> n >> s;
	int ans = 1145141919810;

	if (n == s) {//1桁
		cout << n + 1 << endl;
		return 0;
	}
	for (int i = 2; i*i <= n; i++) {//3桁以上
		int I = n;
		int sum = 0;
		while (I) {
			sum += I%i;
			I /= i;
		}
		if (sum == s) {
			cout << i << endl;
			return 0;
		}
	}

	for (int i = 1; i*i <= n; i++) {
		int a = i, b = s - i;//M進数でab
		if (b < 0)break;
		int m = (n - b) / a;
		if (a*m + b == n&&m>b&&m>a) {
			ans = min(ans, m);
		}
	}
	if (ans == 1145141919810)cout << -1 << endl;
	else cout << ans << endl;
	
}

Measured memory_bytes: 256
while True:
    try:
        s = input().rstrip()
    except:
        break
    win = None
    for i, j, k in ((0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6)):
        chk = s[i] + s[j] + s[k]
        if chk == "ooo":
            win = "o"
            break
        elif chk == "xxx":
            win = "x"
            break
    
    if win:
        print(win)
    else:
        print("d")
    
    
        


Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define mod 1000000007
int main(){
	int n;
	cin>>n;
	long long int a[n],asum=0,sum=0;
	rep(i,n){
		cin>>a[i];
		asum=(asum+a[i])%mod;
	}
	rep(i,n-1){
		asum=(asum-a[i])%mod;
		sum=(sum+(a[i]*asum)%mod)%mod;
	}
	if(sum<0)sum+=mod;
	cout << sum;
		
	return 0;
}


Measured memory_bytes: 5168
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#define endl "\n"
typedef long long int ll;
typedef unsigned long long int ull;
typedef float fl;
typedef short int si;
using namespace std;

void solve()
{   si a; cin >>a;
    a%=10; 
    switch(a)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon"; break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon"; break;
    case 3:
        cout << "bon"; break;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}


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

vector<vector<int > > adj;
vector<int> vis;
vector<int> modi;

int bc = 0;
int cs = 0;
void dfs(int u , int steps, int k){
	vis[u] = 1;
	if(vis[adj[u][0]]){
		bc = steps+1;
		cs = adj[u][0];
		return;
	}
	if(!vis[adj[u][0]])
		dfs(adj[u][0],steps+ 1, k);
	if(steps==k){
		cout << u+1 << endl;exit(0);
	}

}

int main(){
	long long int n,k;
	cin >> n >> k;
	adj = vector<vector<int > > (n);
	vis = vector<int> (n,0);
	for(int i =0;i<n;i++){
		int a;
		cin >> a;
		adj[i].push_back(a-1);
	}
	dfs(0,0,k);
	long long int msteps=k-bc;
	// start dfs from 0 for k times then see if

	vis.clear();
	vis = vector<int> (n,0);
	int u = cs;
	// cout << cs << " " << bc << endl;
	int steps = 0;
	while(!vis[u]){
		vis[u] = 1;
		modi.push_back(u);
		u = adj[u][0];

		steps++;
	}

	cout << modi[msteps%steps]+1 << endl;

}

Measured memory_bytes: 21592
#include <stdio.h>

int main(void){

	int x, i, n;

	scanf("%d", &x);	/* ???????????´??°n?????\??? */

	for(i=1; i<=x; i++) {
		if(i%3 == 0) printf(" %d", i); /* ??´??°i???3????????°?????????3???????????°?????´??????i????????? */

		else{
			n = i;

		while(n % 10 != 3 && n) {
			n /= 10;
		}

		if(n){
			printf(" %d", i);	/* ??\????????´??°n????????????????????????????????????????????????????????? */
		}
		}
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int , int> pi;

bool ispal(string s, int l, int r)
{
	bool y = true;
	while(l<r) {
		if(s[l++] != s[r--]) {
			y = false;
			break;
		}
	}
	return y;
}
	
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	int n = s.size();
	bool y = true;
	if(!ispal(s, 0, n-1))
		y = false;
	if(!ispal(s, 0, (n-2)/2))
		y = false;
	if(!ispal(s, (n+2)/2, n-1))
		y = false;
	if(y)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	
	return 0;
};


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	char w[101];
	scanf("%s", w);
	int a[26] = {};
	for (int i = 0; w[i] != '\0'; i++) {
		a[w[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (a[i] % 2) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 128
N = int(input())
S = str(input())

def judge(s,t):
    s = set(s)
    t = set(t)
    x = s & t
    return(len(x))


ans = 0
for i in range(1,N-1):
    ans = max(ans,judge(S[:i],S[i:]))
    
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    int N, K; cin >> N >> K;
    vector<int> V(N);
    for(int i = 0; i < N; i++) cin >> V[i];
    int p = 0;
    for(int i = 0; i < N; i++) p+=V[i];
    if(N<K){
        sort(V.begin(), V.end());
        for(int i = 0; i < min(K-N, N); i++) if(V[i] < 0)p-=V[i];
        cout << p << endl;
        return 0;
    }

    vector<int> l(N), r(N);
    l[0] = V[0];
    r[N-1] = V[N-1];
    for(int i = 1; i < N; i++) l[i] = l[i-1]+V[i];
    for(int i = N-2; i >= 0; i--) r[i] = r[i+1]+V[i];
    int ans = 0;
    for(int k = 0; k < K; k++){ //戻す回数
        int num = K-k; //取り出すかず
        if(k > num) break;
        int Max=0;
        //cout << 1 << endl;

        for(int i = 0; i < num+1; i++){
            vector<int> temp;
            int SUM = 0;
            for(int j = 0; j < num-i; j++) {temp.push_back(V[j]);SUM+=V[j];}
            for(int j = 0; j < i; j++) {temp.push_back(V[N-1-j]);SUM+=V[N-1-j];}
            sort(temp.begin(), temp.end());
            for(int j = 0; j < k; j++) if(temp[j]<0)SUM -= temp[j];
            Max = max(Max, SUM);
            //if(k == 1) for(auto x : temp) cout << x << " "; cout << endl;
            //cout << "k " << k << " sum " << SUM << endl;
        }
        ans = max(ans, Max);

    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int n = 0, m = 0;
    cin >> n >> m;
    vector<vector<int>> ship(n);
    int a = 0, b = 0;
    for (int i=0; i<m; i++) {
        cin >> a >> b;
        a--;
        b--;
        ship.at(a).push_back(b);
        ship.at(b).push_back(a);
    }
    for (int x : ship.at(0)) {
        for (int y : ship.at(x)) {
            if (y == n-1) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
#include <atcoder/math>
using namespace std;
using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N; cin >> N;
    if(N == 1){
        Out(1);
        return 0;
    }
    int ans = 2 * N;

    for(int k = 2; k * k <= 2 * N; k++) if((2 * N) % k == 0){
        int m0 = k, m1 = (2 * N) / k;
        auto res = crt(vec({0, m1 - 1}), vec({m0, m1}));
        if(res.fi > 0){
            chmin(ans, res.fi);
        }else{
            if(res.se > 0) chmin(ans, res.se);
        }
        res = crt(vec({m0 - 1, m1}), vec({m0, m1}));
        if(res.fi > 0){
            chmin(ans, res.fi);
        }else{
            if(res.se > 0) chmin(ans, res.se);
        }
    }
    Out(ans);

    return 0;
}


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

int main(){    
  ll N;
  string S;
  cin >> N >> S;
  ll n = N;
  for (int i = 0; i < N - 1; i++){
    if(S.at(i) == S.at(i + 1)) n--;
  }
  cout << n << endl;
}
    


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for (int k = 0; k < K; k++) {
    if (k % 2 == 0) {
      if (A % 2) A--;
      B += A / 2, A /= 2;
    } else {
      if (B % 2) B--;
      A += B / 2, B /= 2;
    }
  }
  cout << A << " " << B << "\n";
}

Measured memory_bytes: 3628
#include <vector>
#include <iostream>

using namespace std;

bool isBridge(vector<vector<bool>> origGraph, int a, int b) {
    vector<vector<bool>> graph;
    copy(origGraph.begin(), origGraph.end(), back_inserter(graph));
    graph[a][b] = graph[b][a] = false;

    for (int k = 0; k < graph.size(); k++) {
        for (int i = 0; i < graph.size(); i++) {
            for (int j = 0; j < graph.size(); j++) {
                if (graph[i][j]) {
                    continue;
                }
                if (graph[i][k] && graph[k][j]) {
                    graph[i][j] = graph[j][i] = true;
                }
            }
        }
    }

    for (int i = 0; i < graph.size(); i++) {
        for (int j = 0; j < graph.size(); j++) {
            if (!graph[i][j]) {
                return true;
            }
        }
    }
    return false;
}

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

    vector<vector<bool>> graph(N, vector<bool>(N));
    for (int i = 0; i < N; i++) {
        graph[i][i] = true;
    }

    vector<int> a(M), b(M);
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int count = 0;
    for (int i = 0; i < M; i++) {
        if (isBridge(graph, a[i], b[i])) {
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
int ans;
int B[10][10];
void Main(){
    int N = read(), M = read(), k;
    for (int i = 0; i < M; i++) {
        k = read();
        for (int j = 0; j < k; j++) {
            B[i][read()-1] = 1;
        }
    }
    int P[M];
    for (int i = 0; i < M; i++) {
        P[i] = read();
    }
    int lmt = 0;
    for (int i = 0; i < N; i++) {
        lmt = (lmt<<1)+1;
    }
    int tmp, match;
    for (int i = 0; i <= lmt; i++) {
        match = 0;
        for (int j = 0; j < M; j++) {
            tmp = 0;
            for (int k = 0; k < N; k++) {
                if (B[j][k] == 1 && (i>>k)%2 == 1) tmp = (tmp+1)%2;
            }
            if (tmp == P[j]) match++;
        }
        if (match == M) ans++;
    }
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
from collections import deque

n = int(input())
points = [0 for i in range(n)]

class Point:
    def __init__(self, number, arrow):
        self.number = number        
        self.arrow = arrow
        self.destination = []
        self.distance = -1
        self.hadSearched = False

for i in range(n):
    L = list(map(int, input().split()))
    points[i] = Point(i+1, L[1])
    if L[1] >= 1:
        points[i].destination = L[2:]

def bfs(coord):
    dq = deque()
    coord.hadSearched = True
    dq.appendleft((0, coord))

    while dq:
        steps, po = dq.pop()
        po.distance = steps

        if len(po.destination) > 0:
            for des in po.destination:
                if points[int(des)-1].hadSearched == False:
                    points[int(des)-1].hadSearched = True
                    dq.appendleft((steps+1, points[int(des)-1]))

bfs(points[0])

for i in range(n):
    print("{} {}".format(i+1, points[i].distance))


Measured memory_bytes: 6016