akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll x,cost;
};
int main() {

	char s1,s2,s3;
	cin>>s1>>s2>>s3;
	int f=0;
	if(s1!=s2)f=1;
	if(s2!=s3)f=1;
	if(f==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  vector<int> cnt(26, 0);
  static char s[222222];
  scanf("%s", s);
  int len = strlen(s);
  REP(i, len) cnt[s[i]-'a']++;

  llint ret = 0;
  REP(i, 26) ret += cnt[i] * 1LL * (len - cnt[i]);
  ret /= 2;
  ret++;
  
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

map<char,int> sm[100010];
map<map<char,int>,int> smm;


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

    ll X = 0;
    for (int i=0;i<N;i++) {
        string s;
        cin >> s;
        for (int j=0;j<s.size();j++) {
            sm[i][s[j]] = sm[i][s[j]]+1;
        }
        X += smm[sm[i]];
        smm[sm[i]] = smm[sm[i]]+1;
    }

    cout << X << endl;
    return 0;
}


Measured memory_bytes: 93312
#include<bits/stdc++.h>
using namespace std;
int w,h;
int a[1000][1000];
int dx[8]={1,1,0,-1,-1,-1,0,1},dy[8]={0,1,1,1,0,-1,-1,-1};
void DFS(int x,int y){
    a[y][x]=0;
    for(int i=0;i<8;i++){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx>=0 && nx<w && ny>=0 && ny<h && a[ny][nx]==1){
            DFS(nx,ny);
        }
    }
}
int main(void){
    int cnt;
    while(1){
        cnt=0;
        cin>>w>>h;
        if(w==0 && h==0){
            return 0;
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>a[i][j];
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(a[i][j]==1){
                    cnt++;
                    DFS(j,i);
                }
            }
        }
        cout<<cnt<<endl;
    }
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	double sm = 0.0;
	rep(i, n){
		double x;
		string u;
		cin >>x >>u;
		if(u =="BTC") sm += x * 380000.0;
		else sm += x;
	}
	
	printf("%.10f\n", sm);
	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>


using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


char inv(const char& a) {
    if (a == 'S') return 'W';
    return 'S';
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    string s;
    cin >> s;

    string ans[4];
    ans[0] = "SS";
    ans[1] = "SW";
    ans[2] = "WS";
    ans[3] = "WW";

    REP(i, N) {
        REP(j, 4) {
            if (ans[j][i+1] == 'S') {
                if (s[i] == 'o') ans[j] += ans[j][i];
                else ans[j] += inv(ans[j][i]);
            } else {
                if (s[i] == 'o') ans[j] += inv(ans[j][i]);
                else ans[j] += ans[j][i];
            }
        }
    }

    bool flag = true;
    REP(i, 4) {
        if(ans[i][1] != ans[i][N+1] || ans[i][0] != ans[i][N]) continue;
        flag = false;
        cout << string(ans[i].begin() + 1, ans[i].end() - 1) << endl;
        break;
    }

    if (flag) {
       cout << -1 << endl;
    }
    
}


Measured memory_bytes: 1152
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

struct state {
	int h;
	int w;
	long long ans1 = 2;
	long long ans2 = 0;
	
	state() {}
	state(int h, int w) : h(h), w(w) {}
};

int n, m = 1000000007;
int h[100];

long long powmod(long long x, long long y) {
	long long ans = 1;
	
	while (y > 0) {
		if (y & 1) ans = ans * x % m;
		x = x * x % m;
		y >>= 1;
	}
	
	return ans;
}

long long mod_inverse(long long a, long long m) {
    long long b = m, x = 1, y = 0;
    
    while (b) {
        long long t = a / b;
        
        a -= t * b;
        x -= t * y;
        
        swap(a, b);
        swap(x, y);
    }
    
    return (m + x % m) % m;
}

long long solve() {
	int i, j;
	long long ans = 1;
	vector <state> v;
	
	v.push_back(state(0, 1));
	
	for (i = 0; i < n; i++) {
		v.push_back(state(h[i], 1));
	}
	
	v.push_back(state(0, 1));
	
	while (v.size() > 3) {
		int x = 0;
		
		for (i = 0; i < v.size(); i++) {
			if (v[i].h > v[x].h) x = i;
		}
		
		if (v[x].h == v[x + 1].h) {
			long long tmp1, tmp2;
			
			tmp1 = v[x].ans1 * v[x + 1].ans1 % m * mod_inverse(2, m) % m;
			tmp2 = ((v[x].ans1 + v[x].ans2) * (v[x + 1].ans1 + v[x + 1].ans2) - tmp1 + m) % m;
			
			v[x].ans1 = tmp1;
			v[x].ans2 = tmp2;
			v[x].w += v[x + 1].w;
			v.erase(v.begin() + x + 1);
		} else {
			int h = v[x].h - max(v[x - 1].h, v[x + 1].h);
			
			if (v[x].w == 1) {
				ans = ans * powmod(2, h) % m;
			} else {
				v[x].ans1 = v[x].ans1 * powmod(2, h) % m;
			}
			
			v[x].h -= h;
		}
	}
	
	return ans * (v[1].ans1 * powmod(2, v[1].h - 1) % m + v[1].ans2) % m;
}

int main() {
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++) scanf("%d", &h[i]);
	
	printf("%lld\n", solve());
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define MOD (ll)1e9+7
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

const ll N=(ll)2e5+5;
ll dp[N];
ll arr[N];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    ll sum=arr[1];
    for(int i=2;i<=n;i++){
        if(i&1){
            sum+=arr[i];
            dp[i]=max(dp[i-1],dp[i-2]+arr[i]);
        }else{
            dp[i]=max(sum,dp[i-2]+arr[i]);
        }
    }
    cout<<dp[n]<<"\n";
}


Measured memory_bytes: 6732
import sys
sys.setrecursionlimit(1000000)

n, m = map(int, input().split())
g = [[] for _  in range(n)]
for _ in range(m):
  x, y = map(int, input().split())
  x, y = x -1, y-1
  g[x].append(y)  

# dp[v]: ノードvを起点にしたときの、Gの有効パスの長さの最大値
dp = [-1]*n
def rec(v):
  if dp[v] != -1:
    return dp[v]
  else:
    res = 0
    for u in g[v]:
      res = max(res, rec(u)+1)
    dp[v] = res
    return dp[v]
  
for i in range(n):
  rec(i)
print(max(dp))

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

int main() {
    
    int K;
    char S[100];
    scanf("%d",&K);
    scanf("%s",S);
    
    long len = strlen(S);
    
    if (len <= K){
        printf("%s\n",S);
    }else{
        for (int i = 0;i < K;i++){
            printf("%c",S[i]);
        }
        printf("...\n");
    }
    
    return 0;
}


Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace  std ;
using db  = double;
using ll  = long long;
using ull = unsigned long long; 
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
#define s(x) ((int)(x).size())
#define deb(x) cout<<(x)<<endl
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl
int main()
{
	string S;
	cin >> S;
	if(S=="SSS") deb(0);
	else if(S=="RRS" || S=="SRR") deb(2);
	else if(S=="RRR") deb(3);
	else deb(1);
	
	
}



Measured memory_bytes: 3620
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

mod = 10**9 + 7

A.sort(reverse=True)
B.sort(reverse=True)
A.append(N*M + 1)
B.append(N*M + 1)

space = 0
A_used = 0
B_used = 0
ans = 1
for i in range(M * N, 0, -1):
    if i == A[0]:
        if i == B[0]:
            space += (A_used + B_used)
            A_used += 1
            B_used += 1
            del A[0]
            del B[0]
        else:
            space += (B_used - 1)
            A_used += 1
            del A[0]
            ans = (ans * B_used) % mod
    elif i == B[0]:
        space += (A_used - 1)
        B_used += 1
        del B[0]
        ans = (ans * A_used) % mod
    else:
        ans = (ans * space) % mod
        space -= 1
        if space < 0:
            break

print(ans % mod)

Measured memory_bytes: 3188
import java.util.*;
public class Main {
	static long mod = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		System.out.println(solve());
	}
	static long[][] dp1, dp2; 
	static int n, k, m;
	static long solve(){
		m = (int) Math.sqrt(n);
		dp1 = new long[k][m+1];
		dp2 = new long[k][m+1];
		for(int r = k-1; r >= 0; r--){
			if(r == k-1){
				for(int t = 1; t <= m; t++){
					dp1[r][t] = t;
				}
				for(int _t = m; _t >= 1; _t--){
					int t = n / _t;
					dp2[r][_t] = t;
				}
			}
			else{
				for(int t = 1; t <= m; t++){
					long res = ((t > 1 ? get(r, t-1) : 0) + get(r+1, n / t)) % mod;
					put(r, t, res);
				}
				for(int _t = m; _t >= 1; _t--){
					int t = n / _t;
					
					int c = n / t;
					int a = n / (c + 1);
					long res = (get(r, a) + ((t - a) * get(r+1, c)) % mod) % mod;
					put(r, t, res);
				}
			}
		}
		return get(0, n);
	}
	static long get(int r, int t){
		if(t <= m) return dp1[r][t];
		else return dp2[r][n / t];
	}
	static void put(int r, int t, long val){
		if(t <= m) dp1[r][t] = val;
		else dp2[r][n / t] = val;
	}
}
//100 10
//554261130



Measured memory_bytes: 81520
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define fre
#define DEBUG
using namespace std;
int main()
{
    int x1, x2, y1, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    printf("%d %d %d %d\n", x2 + y1 - y2, y2 + x2 - x1, x1 + y1 - y2, y1 + x2 - x1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    ll sum=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
        sum+=arr[i]*arr[j];
    cout<<sum<<endl;

    return 0;
}


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

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=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main()
{
  int h, w; cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));
  REP(i, h) {
    REP(j, w) {
      cin >> a.at(i).at(j);
    }
  }

  REP(i, h) {
    int cnt_w = 0;
    REP(j, w) {
      if (a.at(i).at(j) == '.') cnt_w++;
    }
    if (cnt_w == w) REP(j, w) a.at(i).at(j) = '0';
  }

  REP(j, w) {
    int cnt_h = 0;
    REP(i, h) {
      if (a.at(i).at(j) == '.' || a.at(i).at(j) == '0') cnt_h++;
    }
    if (cnt_h == h) REP(i, h) a.at(i).at(j) = '0';
  }

  REP(i, h) {
    stringstream ss;
    REP(j, w) {
      char elem = a.at(i).at(j);
      if (elem != '0') ss << elem;
    }
    if (ss.str().size() != 0) cout << ss.str() << endl;
  }
  return 0;
}


Measured memory_bytes: 384
n = int(input())

g = [[-1 for j in range(n)] for i in range(n)]

for i in range(n):
	a = int(input())
	for _ in range(a):
		x, y = map(int, input().split())
		g[i][x-1] = y

ans = 0
for s in range(2**n):
	ok = True
	for i in range(n):
		if (s>>i&1) == 1:
			for j in range(n):
				if g[i][j] == -1: continue
				if (s>>j&1) != g[i][j]: ok = False
	if ok:
		#print("s = ", s)
		t = 0
		x = s
		while x > 0:
			t += x%2
			x //= 2
		ans = max(ans, t)

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}

void swap(int *p, int *q) {
	int tmp;
	tmp = *p;
	*p = *q;
	*q = tmp;
}

int main(void) {

	while (1) {
		int N, M, i, j;
		int D[10000], P[10000] = {};
		scanf("%d %d", &N, &M);
		if (N == 0 && M == 0)break;
		/*?????????????????????*/
		for (i = 0; i < N; i++) {
			scanf("%d %d", &D[i], &P[i]);
		}

		for (i = 0; i < N - 1; i++) {
			for (j = N - 1; j > i; j--) {
				if (P[j] < P[j - 1]) {
					swap(&P[j], &P[j - 1]);
					swap(&D[j], &D[j - 1]);
				}
			}
		}

		i = N - 1;
		while (M > 0) {

			if (D[i] < M) {
				M -= D[i];
				D[i] = 0;
				i--;
			}
			else {
				D[i] -= M;
				M = 0;
			}

		}

		int ans = 0;
		for (i = 0; i < N; i++) {
			ans += D[i] * P[i];
		}
		printf("%d\n", ans);
	}
	return 0;



}

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

int main(void)
{
	int arr[1000],arr2[1000],n,i,j,c,k;
	i = 0;
	j = 0;
	while(scanf("%d",&n) != EOF){
		if(n == 0){
			arr2[i] = arr[j-1];
			printf("%d\n",arr[j-1]);
			j = j - 1;
			i = i + 1;
		}else{
			arr[j] = n;
			j = j + 1;
		}
		/*if(j == 0){
			break;
		}*/
	}
	//for(k = 0; k < i; k++){
	//	printf("%d\n",arr2[k]);
	//}
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
	ll x;
	scanf("%lld", &x);
	ll now = 100, ans = 0;
	while (now < x) {
		ans++;
		now += now / 100;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3824
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#define maxn 100005
using namespace std;
priority_queue <int> q;
vector <int> G[maxn];
int read(){
    int cnt = 0;
    char ch = getchar();
    while (ch < '0' || '9' < ch)
        ch = getchar();
    while ('0' <= ch && ch <= '9'){
        cnt = cnt * 10 + ch - '0';
        ch = getchar();
    }
    return cnt;
}
int main(){
    int n = read(), m = read();
    for (int i = 1; i <= n; ++ i){
        int a = read(), b = read();
        if (a <= m)
            G[m - a + 1].push_back(b);
    }
    int ans = 0;
    for (int i = m; i; -- i){
        for (int j = 0; j < G[i].size(); ++ j)
            q.push(G[i][j]);
        if (q.size()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5632
n = int(input())
t, a = map(int, input().split())
lst = [int(i) for i in input().split()]

gap = 10000
for i in range(n):
    tx = t - lst[i] * 0.006
    abtx = abs(tx-a)
    if abtx < gap:
        gap = abtx
        ans = i+1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    rep(i, N) rep(j, D) cin >> X[i][j];
    int ans = 0;

    rep(i, N) rep(j, i) {
        int S = 0;
        rep(d, D) S += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d]);
        int sqrtS = sqrt(S);
        if (S == sqrtS * sqrtS) ++ans;
    }
    cout << ans << endl;
}

  
  

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

typedef long long int llint;

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

  int a, b, c;

  for(int i = 0; i <= n; i++) {
    for(int j = 0; j <= n - i; j++) {
      
      a = i;
      b = j;
      c = n - i - j;

      if(10000 * a + 5000 * b + 1000 * c == y) {
	cout<< a << ' ' << b << ' ' << c <<endl;
	return 0;
      }
      
    }
  }
  
  cout<< "-1 -1 -1" <<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int i,j,k,n,y[15][15],a,x,c[15],m;
 
   scanf("%d",&n);
   for (i=0;i<n;i++) {
      scanf("%d",&a);
      for (j=0;j<n;j++) y[i][j]=-1;
      for (j=0;j<a;j++) {
         scanf("%d %d",&x,&k);
         y[i][x-1]=k;
      }
      c[i]=0;
   }
   c[n]=0;m=0;
   while (c[n]==0) {
      for (i=0;i<n;i++) {
         if (c[i]==1) {
            for (j=0;j<n;j++)
               if (y[i][j]>=0 && c[j]!=y[i][j]) break;
            if (j<n) break;
         }
      }
      if (i==n) { 
         for (i=j=0;i<n;i++) 
            if (c[i]==1) j++;
        if (j>m) m=j;
      }
      c[0]++;
      for (i=0;c[i]>1;i++) {
          c[i]=0;
         c[i+1]++;
      }
   }
   printf("%d\n",m);
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int N,X;
int arr[300000];
ll sum[300000];
ll ans;
ll f(int K){
    ll ret = (ll)N*X+(ll)K*X;
    int cnt = 1;
    for(int i=N;i>0;i-=K){
        int e = i;
        int s = max(1,i-K+1);
        ret+=(sum[e]-sum[s-1])*(cnt==1?5:cnt*2+1);
        if(K!=1&&ret>ans) break;
        cnt++;
    }
    return ret;
}
int main(){
    scanf("%d %d",&N,&X);
    for(int i=1;i<=N;i++){
        scanf("%d",arr+i);
    }
    for(int i=1;i<=N;i++){
        sum[i]= sum[i-1] + arr[i];
    }
    ans = f(1);
    for(int i=1;i<=N;i++){
        ans = min(ans,f(i));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }
  ll ans = 0;
  
  for(ll i=1;i<n;i++){
     if(a[i-1]>a[i]){
       ans = ans + a[i-1] - a[i];
       a[i] = a[i-1];
     }
  }
 cout<<ans<<endl;
}

Measured memory_bytes: 5188
S = input()

front = int(S[:2])
back = int(S[2:])

if (front==0) and (back==0):
    print("NA")
elif (front==0) and (back <= 12):
    print("YYMM")
elif (front <= 12) and (back==0):
    print("MMYY")
elif (front <= 12 and front!=0) and (back <= 12 and back!=0):
    print("AMBIGUOUS")
elif (front > 12) and (back <= 12 and back!= 0):
    print("YYMM")
elif (front <= 12 and front!=0) and (back > 12):
    print("MMYY")
else :
    print("NA")

Measured memory_bytes: 3064
using System;

namespace ABC068B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int res = 1;

            while (res <= N)
            {
                res <<= 1;
            }

            Console.WriteLine(res >> 1);
        }
    }
}


Measured memory_bytes: 13140
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))
cumsum_a = a.cumsum()
sum_a = cumsum_a[-1]
ans = 2 * 10**9

for i in range(n-1):
    ans = min(ans, abs(sum_a - 2*cumsum_a[i]))

print(ans)


Measured memory_bytes: 49240
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		long mod = 1000000007;
		string[] input = Console.ReadLine().Split(' ');
		int h = int.Parse(input[0]);
		int w = int.Parse(input[1]);
    int k = int.Parse(input[2]);
		long[,] dp = new long[h+1,w];//見た行数と何列目にいるか
    dp[0,0] = 1;

    if(w > 1)
    {
      for(int i = 1; i <= h; i++)
      {
        for(int j = 0; j < w; j++)
        {
          for(int x = 0; x < Math.Pow(2,w-1); x++)
          {
            List<int> rowMemo = BinaryToNum(w-1,x);
            bool rowContinue = false;
            for(int y = 1; y < w-1; y++)
            {
              if(rowMemo[y-1] + rowMemo[y] == 2) rowContinue = true;
            }
            if(rowContinue) continue;

            if(j == 0)
            {
              if(rowMemo[j] == 1) dp[i,j] += dp[i-1,j+1];
              else dp[i,j] += dp[i-1,j];
            }else if(j == w-1)
            {
              if(rowMemo[j-1] == 1) dp[i,j] += dp[i-1,j-1];
              else dp[i,j] += dp[i-1,j];
            }else
            {
              if(rowMemo[j] == 1) dp[i,j] += dp[i-1,j+1];
              else if(rowMemo[j-1] == 1) dp[i,j] += dp[i-1,j-1];
              else dp[i,j] += dp[i-1,j];
            }
            dp[i,j] %= mod;
          }
          //Console.WriteLine(i+" "+j+" "+dp[i,j]);
        }
      }
      Console.WriteLine(dp[h,k-1]);
    }else Console.WriteLine(1);
    
	}

  static List<int> FactorialToNum(int n, int num)
  {//n個の数を並べ替えた方法をリストに直す。
  //n=1でnum=0なら{0}。 n=2でnum=0なら{0,1}、num=1なら{1,0}
    List<int> answersNum = new List<int>();
    List<int> answers = new List<int>();
    List<int> answersRest = new List<int>();
    int rest = 1;
    for(int i = 2; i < n; i++)
    {
      rest *= i;
    }
    
    for(int i = n-1; i > 0; i--)
    {
      answersNum.Add(num/rest);
      num %= rest;
      rest /= i;
    }
    answersNum.Add(0);

    for(int i = 0; i < n; i++)
    {
      answersRest.Add(i);
    }
    for(int i = 0; i < n; i++)
    {
      answers.Add(answersRest[answersNum[i]]);
      answersRest.RemoveAt(answersNum[i]);
    }
    
    return answers;
  }

  static List<int> BinaryToNum(int n, int num)
  {//2進数でn桁の数numをリストに直す。
  //n=2でnum=0なら{0,0}、num=1なら{0,1}、num=2なら{1,0}。
    List<int> answers = new List<int>();
    int rest = 1;
    for(int i = 0; i < n-1; i++)
    {
      rest *= 2;
    }
    
    for(int i = 0; i < n; i++)
    {
      answers.Add(num/rest);
      num %= rest;
      rest /= 2;
    }
    
    return answers;
  }  
  
}

Measured memory_bytes: 15312
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


int N, M, Q;
ll ans = 0;
vector<vector<int>> query;

void dfs(vector<int> a){
    if(a.size() == N){
        ll tmp = 0;
        rep(i, Q){
            if(a[query[i][1] - 1] - a[query[i][0] - 1] == query[i][2]) tmp += query[i][3];
        }
        ans = max(ans, tmp);
        return;
    }
    for(int i = a.back(); i <= M; i++){
        a.push_back(i);
        dfs(a);
        a.pop_back();
    }
}

int main(){
    cin >> N >> M >> Q;
    query.assign(Q, vector<int>(4, 0));
    rep(i, Q) cin >> query[i][0] >> query[i][1] >> query[i][2] >> query[i][3];

    rep(i, M){
        vector<int> mat;
        mat.push_back(i + 1);
        dfs(mat);
    }
    cout << ans << endl;
}

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

int N;
int A[100000];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

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

	map<int, int> m1, m2;
	set<int> same;
	vector<int> ans;
	for(int i = 0; i < N; i++){
		set<int> s;
		m1[A[i]]++;
		m2[A[N - 1 - i]]++;
		s.insert(A[i]);
		s.insert(A[N - 1 - i]);
		for(auto a : s){
			if(same.count(a)) same.erase(a);
		}
		for(auto a : s){
			if(m1.count(a) && m2.count(a) && m1[a] == m2[a]){
				same.insert(a);
			}
		}
		if(same.size() == m1.size()){
			ans.push_back(i + 1);
		}
	}

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



Measured memory_bytes: 10644
N = int(input())
S = [list(map(int, list(input()))) for i in range(N)]

# 奇数長のループがあるかどうかをチェック
node_to_idx = {}
visited = [False] * N
def dfs(node, par, n):
  global node_to_idx
  res = True
  for i, s in enumerate(S[node]):
    if s and i != par:
      if i in node_to_idx:
        idx = node_to_idx[i]
        if (n - idx) % 2:
          res *= False
        else:
          res *= True
      else:
        if visited[i]:
          continue
        visited[i] = True
        node_to_idx[i] = n
        res *= dfs(i, node, n+1)
  return res

node_to_idx[0] = 0
visited[0] = True
res = dfs(0, -1, 1)
if res:
  from scipy.sparse.csgraph import floyd_warshall
  import numpy as np
  dist = floyd_warshall(S).astype(int)
  print(dist.max() + 1)
else:
  print(-1)

Measured memory_bytes: 14812
import sys
from itertools import accumulate
N, C = [int(i) for i in sys.stdin.readline().split()]
ls = {j : [0 for i in range(2*10**5)] for j in range(1,C+1)}
for i in range(N):
    s, t, c = [int(i) for i in sys.stdin.readline().split()]
    ls[c][s] += 1
    ls[c][t+1] -= 1

res = [0 for i in range(2*10**5)]
for _c in range(1, C+1):
    for i, j in enumerate(accumulate(ls[_c])):
        res[i] += min(1,j)
print(max(res))

Measured memory_bytes: 133676
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int a, b;
    cin >> a >> b;
    vbool ans(3, true);
    ans[a-1] = false;
    ans[b-1] = false;

    rep(i, 3) if (ans[i]) cout << i+1 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = [INT() for _ in range(N)]

B = sorted(A,reverse = True)
max_a = B[0]
second_a = B[1]

for a in A:
	if a != max_a: print(max_a)
	else: print(second_a)

Measured memory_bytes: 59344
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

struct W
{
    ll b, e;
    ll p;
};
bool operator<(W x, W y)
{
    return x.p < y.p;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<W> w(n);
    forn(i, n) cin >> w[i].b >> w[i].e >> w[i].p, w[i].b -= w[i].p, w[i].e -= w[i].p;
    sort(allele(w));

    vector<pair<ll, ll>> D(q);
    forn(i, q) cin >> D[i].fi, D[i].se = i;
    set<pair<ll, ll>> d(allele(D));

    vector<ll> ans(q, -1);
    forn(i, n)
    {
        auto it = d.lower_bound(make_pair(w[i].b, 0LL));
        while (it != d.end())
        {
            if ((*it).fi >= w[i].e)
                break;
            if (ans[(*it).se] == -1)
                ans[(*it).se] = w[i].p, it = d.erase(it);
            else
                it++;
        }
    }
    forn(i, q) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 23808
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    //cout << "Hello world!" << endl;
    ll t,i,j,k,m,n,a,b;
    cin>>a>>b;
    if(a>8||b>8)
    {
        cout<<":(";
    }
    else
    {
        cout<<"Yay!";
    }
    return 0;
}


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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FOR(i, 1, n+1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

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

	ll ans = 0, cnt = 0, num = 0;
	rep(i, s.length()){
		if(s[i] == '<'){
			if(i && s[i-1] == '>'){
				cnt = 0;
			}
			ans += ++cnt;
		}else{
			if(i && s[i-1] == '<'){
				num = cnt;
				cnt = 0;
			}
			if(cnt < num) ans += cnt++;
			else ans += ++cnt;
		}
	}

	co(ans);

	return 0;
}


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

int main(void){
        int n, ans = 50000000;
        cin >> n;
        vector<int> x(n);
        for(int i = 0; i < n; i++) cin >> x[i];
        for(int p = 1; p <= 100; p++){
                int temp = 0;
                for(int elem : x){
                        temp += (p - elem) * (p - elem);
                }
                ans = min(ans, temp);
        }
        cout << ans << endl;
	return 0;
}


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

int main() {
  
  int N;
  cin >> N;
  
  int p[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  
  sort(p, p+N, greater<int>());
  
  int ans = p[0]/2;
  
  for (int i = 1; i < N; i++) {
    ans += p[i];
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int cnt = 0;
		for (int i = 1; i < s.length; i++) {
			if (s[i] != s[i - 1]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 25684
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a[200005],tot[200005],ans[200005];
signed main(){
	int n,start=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		tot[a[i]]++;
	}
	for(int i=1;i<=200000;i++)
	    start=start+(tot[i]*tot[i]-tot[i])/2;
	for(int i=1;i<=200000;i++)
	    ans[i]=start-(tot[i]-1);
	for(int i=1;i<=n;i++)
	    cout<<ans[a[i]]<<endl;
	return 0;
}

Measured memory_bytes: 6912
import copy
class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = N
        self.func = copy.deepcopy(func)
        self.I = I
        self.seg = [I for i in range(self.sz * 2)]
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])
 
    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)

def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    from fractions import gcd
    N = int(readline())
    m = map(int,read().split())
    seg = SegmentTree(N , gcd , 0)
    for i in range(N):
        seg.assign(i , next(m))
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()

Measured memory_bytes: 82340
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  //cin.tie(0);	
  // ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int nex=2;
  int num=sqrt(n);
  int nn=n-1;
  int nnn=n;
  int ans=0;
  if(n==2){cout<<1<<endl;return 0;}
  else if(n==3){cout<<2<<endl;return 0;}
  else ans=1;
  //if(n%2==1) ans=0;
  // vector<int> p;
  while(num>=nex){
    if(n%nex==0){
      //p.push_back(nex);
      int xx=n;
      int cnt=0;
      while(xx%nex==0){xx/=nex;cnt++;}
      if(xx%nex == 1) ans++;
    }
    nex++;
  }
  // p.push_back(n);
  
  nex=2;
  num=sqrt(nn);
  int cnt=1;
  while(num>=nex){
    int x=1;
    if(nn%nex==0){
      //int xx=nn;
      x=1;	 
      while(nn%nex==0){nn/=nex;x++;}
    }
    cnt*=x;
    nex+=2;
    if(nex%2==0) nex--;
  }
  if(nn!=1){
    if(cnt==1) cnt=2;
    else cnt*=2;
  }
  //cout<<cnt<<endl;
  cnt--;
  //cout<<'a'<<endl;
  ans+=cnt;
  
 
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define pii pair<int,int>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(10)
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long mod = 1000000007;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();

    int sum = 0;
    for(int bit = 0;bit < (1 << n-1);++bit){
        string t;
        t += s[0];
        rep(i,n-1){
            if(bit & (1 << i)){
                sum += stoll(t);
                t = "";
            }
            t += s[i+1];
        }
        sum += stoll(t);
    }    
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            System.out.println(N % f(N) == 0 ? "Yes" : "No");
        }
    }

    private static int f(int n) {
        int sum = 0;
        for (; n > 0;) {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
}


Measured memory_bytes: 27076
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<tuple>
#include<iomanip>
using namespace std;
#define endl               '\n'
#define gap                ' '
#define MAX                LLONG_MAX
#define MIN                LLONG_MIN
#define min3(a,b,c)        min(a, min(b, c))
#define max3(a,b,c)        max(a, max(b, c))
#define MOD                1000000007
#define PI                 3.1415926535897932384626433832795
#define nps                string::npos
#define int                int64_t
#define double             long double
#define vi                 vector<int>
#define di                 deque<int>
#define si                 set<int>
#define vpii               vector<pair<int,int>>
#define dpii               deque<pair<int,int>>
#define pi                 pair<int,int>
#define pub                push_back
#define puf                push_front
#define pob                pop_back
#define pof                pop_front
#define all(a)             (a).begin(),(a).end()
#define rall(a)            (a).rbegin(),(a).rend()
#define rep(i, s, n)       for(int i = s; i < n; ++i)
#define repe(i, s, n)      for(int i = s; i <= n; ++i)
#define repr(i, n, s)      for(int i = n; i >= s; --i)
#define read(a)            for(auto& x : a) cin >> x
#define speak(a)           for(auto x : a) cout << x << ' '
#define work(x, a)         for(auto& x : a)
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main() {
    ios_base::sync_with_stdio (false);
    cin.tie (0);
    int a, b, c, ans = 0;
    cin >> a >> b >> c;
    repe (i, a, b) {
        if (i % c == 0) {
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3492
#include<iostream>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int MOD = 1000000007;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long 
int n,m,x;
vector<vector<int>>adj;
int findans(vector<int>row,vector<int>col){
    int ret=0;
    set<int>st1;
    set<int>st2;
    for(auto p:row)st1.insert(p);
    for(auto p:col)st2.insert(p);
    vector<vector<int>>adj2;
    adj2=adj;
    // for(int i=0;i<row.size();i++){
    //    for(int j=0;j<m;j++)adj2[row[i]][j]=0;
    // }
    // for(int i=0;i<col.size();i++){
    //     for(int j=0;j<n;j++)adj2[j][col[i]]=0;
    // }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(st1.count(i)==0&&st2.count(j)==0&&adj[i][j]==1)ret++;
        }
    }
    if(ret==x){
       
        
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<m;j++){
    //         cout<<adj2[i][j];
    //     }
    //     cout<<endl;
    // }
    }
    return ret;

    
}
signed main() 
{
    cin>>n>>m>>x;
    int res=0;
    for(int i=0;i<n;i++){
        vector<int>v1;
        for(int j=0;j<m;j++){
            char a;
            cin>>a;
            if(a=='#')
            v1.push_back(1);
            else v1.push_back(0);
        }
        adj.push_back(v1);
    }

    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<(1<<m);j++){
            vector<int>row;
            vector<int>col;
           for(int k=0;k<n;k++){
            if(i&(1<<k))row.push_back(k);
           }
           for(int k=0;k<m;k++){
            if(j&(1<<k))col.push_back(k);
           }
            // if(row.size()==0)cout<<"row : nonee"<<endl;
            // else {
            //     for(auto p:row)cout<<p<<" ";
            //         cout<<endl;
            // }
            // if(col.size()==0)cout<<"col : nonee"<<endl;
            // else {
            //     for(auto p:col)cout<<p<<" ";
            //         cout<<endl;
            // }
            // cout<<endl;
            

           if(findans(row,col)==x)res++;
           
        }
    }
    cout<<res;
    return 0; 
} 

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

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

  int i, j;
  int count_div = 0; //約数の数
  int count_ans = 0; //正の約数をちょうど8個もつような整数の数
  for(i=1; i<=N; i+=2){
    for(j=1; j<=N; j+=2)
      if(i%j == 0)
	count_div++;
    if(count_div == 8)
      count_ans++;
    count_div = 0;
  }

  cout << count_ans << endl;
    
  return 0;
}


Measured memory_bytes: 256
s = input()

N = len(s)

flag=True
if s[N-1]=='1':
        flag=False
if s[0]=='0' or s[N-2]=='0':
        flag=False


for i in range(N//2):
        if s[i]!=s[N-i-2]:
                flag=False
                break

if flag:
        ans = []
        prev = 0
        for i in range(N//2):
                if s[i]=='1':
                        for j in range(prev,i):
                                ans.append([i+1,j+1])
                        prev = i
        
        for i in range(prev,N-1):
                ans.append([N,i+1])
        
        for a in ans:
                print(*a)
else:
        print(-1)

Measured memory_bytes: 57560
N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
D = [list(map(int,input().split())) for k in range(M)]
D = sorted(D, key = lambda x: -x[1])
D.append([10**9+1,-1])
t = 0
ans = 0
for k in range(N):
    if A[k] < D[t][1]:
        ans += D[t][1]
        D[t][0] -= 1
        if D[t][0] == 0:
            t += 1
    else:
        ans += A[k]

print(ans)


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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

int N, M, Q;
vector<int> A, B, C, D;
int ans;

void check(vector<int>& pat) {
    int cand = 0;
    REP(i, Q) {
        if(pat[B[i]-1] - pat[A[i]-1] == C[i]) {
            cand += D[i];
        }
    }
    chmax(ans, cand);
}

void dfs(vector<int> pat, int n) {
    pat.push_back(n);
    if(pat.size() == N) {
        check(pat);
        return;
    }

    int tail = pat[pat.size()-1];
    for(int i = tail; i <= M; ++i) {
        dfs(pat, i);
    }
}

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

    cin >> N >> M >> Q;
    A.resize(Q);
    B.resize(Q);
    C.resize(Q);
    D.resize(Q);
    REP(i, Q) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
    }

    dfs(vector<int>(), 1);

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1e18;
signed main(){
	int n,k;cin >> n >> k;
	vector<int> p(n),c(n);
	rep(i,n){
		cin >> p[i];
		p[i]--;
	}
	rep(i,n)cin >> c[i];
	int ret = -INF;
	{
		rep(s,n){
			int len = 0;
			int score = 0;
			int round = 0;
			// int move = 0;
			for(int g = s;len == 0|| g != s;g = p[g],len++)round += c[g];
			for(int g = s,move = 1;move == 1|| g != s;g = p[g],move++){
				score += c[g];
				if(move <= k){
					int tmp = score;
					if(round>0)tmp += ((k-move)/len)*round;
					ret = max(ret,tmp);
					// trace(s,g,tmp,round);
				}
		
			}
		}
		
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3668