akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define FOR(i,a,n) for(i = a;i<n;++i)
#define ROF(i,a,n) for(i = n-1;i>=a;--i)
using namespace std;

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);

    int k,i;
    cin>>k;
    vector<int> a(k);
    FOR(i,0,k) cin>>a[i];
    ll lcur = 2,rcur = 2;
    ll l,r;
    if(a[k-1] == 2){
        ROF(i,1,k){
            l = lcur,r = rcur + a[i] - 1;

            ll lmul = ((l - 1)/a[i-1] + 1)*a[i-1];
            ll rmul = ((r)/a[i-1])*a[i-1];
            //cout<<a[i]<<" "<<lcur<<" "<<rcur<<endl;
            if(lmul <= r){
                lcur = lmul;
            }
            else{
                lcur = -1;
                break;
            }
            if(rmul >= l){
                rcur = rmul;
            }
            else{
                rcur = -1;
                break;
            }
        }

        if(lcur == -1 || rcur == -1){
            cout<<-1;
        }
        else{
            cout<<lcur<<" "<<rcur + a[0] - 1;
        }
    }else{
        cout<<-1;
    }


    return 0;
}


Measured memory_bytes: 640
#include <queue>
#include <iostream>
#include <string.h>
using namespace std;

int main() {
  while (1) {
    string str, left, right;
    int m, h;

    cin >> str;
    if (str == "-") {
      return 0;
    }

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      left = str.substr(0, h);
      right = str.substr(h, str.length() - h);
      str = right + left;
    }
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <stdlib.h>
using namespace std;

#define CARD_NUM_MAX 100000
#define CARD_VAL_MAX 100000

bool is_uniq(int a[], int n) {
  for(int i=0; i<n; i++) {
    if(a[i] > 1) return false;
  }
  return true;
}

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

int main() {
  int n;
  int a[CARD_VAL_MAX+1];
  for(int i=0; i<CARD_VAL_MAX+1; i++) {
    a[i] = 0;
  }

  cin >> n;
  for(int i=0; i<n; i++) {
    int val;
    cin >> val;
    a[val]++;
  }

  int dup = dups(a, CARD_VAL_MAX+1);
  int left = n;
  if(dup % 2 == 0) left = n - dup;
  else left = n - dup - 1;

  cout << left << endl;
}
// ダブってるやつが二組あればその中から3枚を選ぶ
// ダブってるやつが一組しかなければ、ダブったやつが最低値か最大値になるようにとって捨てる

// [1, 1, 1, 1, 2, 2, 2, 3, 3, 5, 6, 6, 8, 8, 11]
// 3 2 1 1 1


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

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

    vector<int> v(N);
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        v.at(a - 1) = i + 1;
    }
    for(int i = 0; i < N; i++){
        cout << v.at(i) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int N,M;
vector<ll> S;
vector<ll> T;

ll dp[2020][2020];

void add(ll &a,ll b){
  a=b%MOD;
  a=(a+MOD)%MOD;
}

int main(){
  cin>>N>>M;
  S.resize(N);
  T.resize(M);
  for(int i=0;i<N;i++) cin>>S[i];
  for(int i=0;i<M;i++) cin>>T[i];

  for(int i=0;i<=N;i++) dp[i][0]=1;
  for(int j=0;j<=M;j++) dp[0][j]=1;
  dp[0][0]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      if(S[i]==T[j]){
        ll z=dp[i+1][j]+dp[i][j+1]-dp[i][j];
        z=(z+MOD)%MOD;
        z=(z+dp[i][j])%MOD;        
        add(dp[i+1][j+1],z);
      }else{
        ll z=dp[i+1][j]+dp[i][j+1]-dp[i][j];
        z=(z+MOD)%MOD;
        add(dp[i+1][j+1],z);
      }
    }
  }

  cout<<dp[N][M]<<endl;

  return 0;
}


Measured memory_bytes: 31872
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

class B {
	string a, b;
	int x;
public:
	void solve()
	{
		cin >> a >> b;
		a += b;

		x = stoi(a);

		if (x == (pow((int)sqrt(x), 2))) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int num[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();

        System.out.println(num[a - 1]);
    }
}


Measured memory_bytes: 22356
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<cstring>
#include<time.h>
#include<math.h>
#include<algorithm>
#define ll long long
#define maxn 2005
#define inf 0x3f3f3f3f
using namespace std;
int n,w[maxn],head[maxn],k,root;
int f[maxn],si[maxn],sum[maxn];
char s[maxn];
struct  eage
{
	int v,last;
}e[maxn<<1];

int read()
{
	int num,sign=1;
	char c;
	while((c=getchar())<'0'||c>'9')
		if(c=='-')sign=-1;
	num=c-'0';
	while(((c=getchar())>='0'&&c<='9'))
		num=(num<<1)+(num<<3)+c-'0';
	return num*sign;
}

inline void addeage(int u,int v)
{
	e[++k].last=head[u];
	e[k].v=v;
	head[u]=k;
}

void dfs(int u,int fa)
{
	si[u]=0;
	if(w[u])si[u]=1;
	sum[u]=0;
	int maxson=0,maxid;
	for(register int i=head[u];i;i=e[i].last)
	{
		int v=e[i].v;
		if(v==fa)continue;
		dfs(v,u);
		si[u]+=si[v];
		sum[u]+=(sum[v]+si[v]);
		if(sum[v]+si[v]>maxson)
		{
			maxson=sum[v]+si[v];
			maxid=v;
		}
	}
	if(sum[u]-maxson>=maxson)f[u]=sum[u]/2;
	else f[u]=sum[u]-maxson+min(f[maxid],maxson-sum[u]/2);
}

int main()
{
	n=read();
	for(register int i=1;i<=n;++i)
	{
		char x=getchar();
		if(x=='1')w[i]=1;
	}
	for(register int u,v,i=1;i<n;++i)
	{
		u=read(),v=read();
		addeage(u,v);
		addeage(v,u);
	}
	int ans=inf;
	for(register int i=1;i<=n;++i)
	{
		root=i;
		dfs(root,0);
		if(!(sum[root]%2)&&f[root]==sum[root]/2)ans=min(ans,f[root]);
	}
	printf("%d\n",ans==inf?ans=-1:ans);
	return 0;
}

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

using namespace std;

typedef long long ll;

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

    if(a >= b && a >= c){
        cout << 10*a+b+c << endl;
    }
    else if(b >= a && b >= c){
        cout << 10*b+a+c << endl;
    }
    else{
        cout << 10*c+a+b << endl;
    }

    return 0;
}

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

int main(){
    int n; int ans=0; int i=0; int k=0;
    cin >> n;
    int h[n];
    while(i<n){
        cin >> h[i++];
    }

for(int j=n-1; j>=1; j--){
      if(h[j] < h[j-1]){
        if(h[j-1] - h[j] != 1){
            ans = -1;
            break;
        }else{
            h[j-1] -= 1;
        }
    }
}

if(ans == -1) cout << "No" << endl;
else cout << "Yes" << endl;

return 0;
}

Measured memory_bytes: 640
N,M = list(map(int,input().split(" ")))
INF = -(10 ** 20)
graph = [ INF for _ in range(N + 1)]
edges = []
for _ in range(M):
    a,b,c = list(map(int,input().split(" ")))
    edges.append((a,b,c))

graph[1] = 0
for i in range(2 * N): #ループがなければ更新は N - 1回 以降行われない
    for edge in edges:
        fr,to,point = edge
        if graph[fr] + point >  graph[to] and  graph[fr] != INF:
            graph[to] = graph[fr] + point
            if to == N and i > N:
                print("inf")
                exit()

print(graph[-1])






Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

int main() {
	int n;
    cin >> n;
    vector <long long> t(n,0);
    vector <long long> a(n,0);
    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        t.at(i)=x;
        a.at(i)=y;
    }
    for(int i=0;i<n-1;i++){
        long long tt,aa;
        tt=(t.at(i)-1)/t.at(i+1)+1;
        aa=(a.at(i)-1)/a.at(i+1)+1;
        long long tmp=max(tt,aa);
        t.at(i+1)*=tmp;
        a.at(i+1)*=tmp;
    }
    cout << t.at(n-1)+a.at(n-1) << endl;



	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	bool ok=true;
	int mx=h[0]-1;
	for(int i=1;i<n;i++){
		if(mx<h[i]){
			h[i]--;
			mx=h[i];
		}
		else if(mx>h[i]){
			ok=false;
			break;
		}
	}
	if(ok){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 640
N, D = map(int, input().split())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))

import math

def get_dist(ary1, ary2):
	tot = 0
	for i in range(len(ary1)):
		tot += (ary1[i] - ary2[i]) ** 2
	return math.sqrt(tot)

cnt = 0
for i in range(N):
	for j in range(i + 1, N):
		_ = get_dist(X[i], X[j])
		if _ == int(_):
			cnt += 1
			
print(cnt)

Measured memory_bytes: 3064
N, M = map(int, input().split())
SC = [tuple(map(int, input().split())) for i in range(M)]

for i in range(10**N):
    ans = str(i)
    if len(ans) != N:
        continue
    if all(ans[si-1] == str(ci) for si, ci in SC ):
        print(ans)
        exit()

print(-1)


Measured memory_bytes: 3064
import java.util.Iterator;
//BFS find the short path for all nodes
/*
 * BFS(s): 
   toVisit = {s} //toVisit is a queue
   while toVisit is not empty:
       u = toVisit.dequeue()
       for u's every unvisited neighbor v:
	  toVisit.enqueue(v)
          dist[v] = ?? //complete it to solve the shortest path problem
 */
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1; //we need 0123 not 1234
			int degree = in.nextInt(); //degree 2 number
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) { //degree: how many edges we have point to the node/number
				int idx2 = in.nextInt() - 1; //coz every node -1
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	
	public void BFS() {
		int [] visited = new int[totalVertex];
		int [] path = new int[totalVertex];
		for(int y=0;y<totalVertex;y++) {
			visited[y] = 0;   //table visit all 0
			path[y] = -1; //set a large number
		}
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(0);
		visited[0]=1; //bug
		path[0]=0;//bug
		while(!q.isEmpty()) {
			int x = q.poll();  //current parent
			LinkedList<Integer> nb = adjList.get(x);
			Iterator<Integer> it = nb.iterator();
			while(it.hasNext()) {
				int t = it.next();
				if(visited[t]==0) {
					if (path[x]==-1) path[x]=0;
					path[t] = path[x]+1; //parent +1
					visited[t] = 1;
					q.add(t); //add
				}
			}
		}
		for (int s=0;s<totalVertex;s++) {
			System.out.println(s+1 + " " + path[s]);
		}
	}
}

public class Main {
	public static void main(String[] args) {
		Graph g = new Graph();
		g.loadAdjList();
		g.BFS();
	}

}



Measured memory_bytes: 28460
N, M = map(int, input().split())
s = [map(int,input().split()) for i in range(N)]
c = [list(map(int,input().split())) for i in range(M)]
for x1, y1 in s:
    m = float('inf')
    mi = 0
    for i,(x2, y2) in enumerate(c):
        if m > abs(x1-x2) + abs(y1-y2):
            m = abs(x1-x2) + abs(y1-y2)
            mi = i+1
    print(mi)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

ll N;
vector<ll> D;
vector<ll> DD;
map<ll,ll> Dcount;

string cal(int i){
  string ret = "";
  while(i!=0){
    if(i%2==1) ret.pb('1');
    else ret.pb('0');
    i/=2;
  }

  while(ret.size()<N)ret+='0';

  return ret;
}

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

  cin >> N;
  rep(i,N){
    ll inp; cin >> inp;
    Dcount[inp]++;
    if(inp==0) {
      cout << "0" << endl;
      return 0;
    }
  }
  rep(i,13){
    if(Dcount[i]>2){
      cout <<"0" << endl;
      return 0;
    }
    if(Dcount[i]==2)
      DD.pb(i);
    
    if(Dcount[i]==1)
      D.pb(i);
  }

  N = D.size();
  ll ans = 0;
  ll num = 0;
  while(true){
    string check = cal(num);

    if(check.size()>N)break;

    vector<ll>temp;
    ll tempmin = 24;
    temp.pb(0);
    if(DD.size()!=0){
      rep(i,DD.size()){
	temp.pb(DD[i]);
	temp.pb(24-DD[i]);
      }
    }

    rep(i,N){
      if(check[i]=='1')temp.pb(D[i]);
      else
	temp.pb(24-D[i]); 
    }

    rep(i,temp.size()){
      rep(j,temp.size()){
	if(i==j)continue;
	else tempmin = min(min(abs(temp[i]-temp[j]),24-abs(temp[i]-temp[j]) ), tempmin);

      }
    }
    

    ans = max(ans, tempmin);
    num++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

S = list(map(int, input().replace('\n', '')))

N = len(S)
stack = []
cnt = 0
index = N - 1
while index > -1:
    if(len(stack) == 0):
        stack.append(S.pop())
        index -= 1
    else:
        if stack[-1] != S[index]:
            stack.pop()
            S.pop()
            index -= 1
            cnt += 2
        else:
            stack.append(S.pop())
            index -= 1
print(cnt)

Measured memory_bytes: 48476
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &ai: a) cin >> ai;
  ll sum = 0;
  ll cur_max = 0;
  for (auto ai: a) {
    cur_max = max(cur_max, ai);
    sum += cur_max - ai;
  }
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 4820
#include "bits/stdc++.h"
using namespace std;

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> g(h);
  for(int i=0;i<h;i++)cin>>g[i];
  int bl=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(g[i][j]=='#')bl++;
    }
  }

  queue<int> x;
  queue<int> y;
  queue<int> t;

  x.push(0);
  y.push(0);
  t.push(0);

  //g[0][0]='#';

  int ans=-1;

  while(!x.empty()&&!y.empty()&&!t.empty()){
    int fl=0;
    int dx=x.front();
    int dy=y.front();
    int dt=t.front();
    x.pop();
    y.pop();
    t.pop();
    g[dx][dy]='#';
    if(dx==h-1&&dy==w-1){
      ans=dt;
      break;
    }
    if(dx+1>-1&&dx+1<h&&dy>-1&&dy<w&&g[dx+1][dy]=='.'){
      x.push(dx+1);
      y.push(dy);
      t.push(dt+1);
      g[dx+1][dy]='#';
    }
    if(dx-1>-1&&dx-1<h&&dy>-1&&dy<w&&g[dx-1][dy]=='.'){
      x.push(dx-1);
      y.push(dy);
      t.push(dt+1);
      g[dx-1][dy]='#';
    }
    if(dx>-1&&dx<h&&dy+1>-1&&dy+1<w&&g[dx][dy+1]=='.'){
      x.push(dx);
      y.push(dy+1);
      t.push(dt+1);
      g[dx][dy+1]='#';
    }
    if(dx>-1&&dx<h&&dy-1>-1&&dy-1<w&&g[dx][dy-1]=='.'){
      x.push(dx);
      y.push(dy-1);
      t.push(dt+1);
      g[dx][dy-1]='#';
    }
  }

  if(ans==-1){
    cout<<-1<<endl;
  }else{
    cout<<h*w-bl-ans-1<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100000+50;
int A,B,C,X,Y;
long long p[maxn],q[maxn],r[maxn];
int main()
{
    scanf("%d %d %d %d %d",&X,&Y,&A,&B,&C);
    for(int i=1;i<=A;i++)
    {   
        int tp;
        scanf("%d",&tp);
        p[i]=tp;
    }
    for(int i=1;i<=B;i++)
    {   
        int tp;
        scanf("%d",&tp);
        q[i]=tp;
    }
    for(int i=1;i<=C;i++)
    {   
        int tp;
        scanf("%d",&tp);
        r[i]=tp;
    }
    sort(p+1,p+1+A);
    sort(q+1,q+1+B);
    sort(r+1,r+1+C);
    long long ans=0;
    for(int i=A-X+1;i<=A;i++) ans+=p[i];
    for(int i=B-Y+1;i<=B;i++) ans+=q[i];
    int now=C,nowi=A-X+1,nowj=B-Y+1;
    while(1)
    {   
        bool flag=0;
        if(nowi<=A&&nowj<=B)
        {
            if(p[nowi]<q[nowj]&&p[nowi]<r[now])
            {
                ans+=r[now]-p[nowi];
                nowi++;
                now--;
                flag=1;
            }
            else
            if(p[nowi]>=q[nowj]&&q[nowj]<r[now])
            {
                ans+=r[now]-q[nowj];
                nowj++;
                now--;
                flag=1;
            }
        } 
        else
        {
            if(nowi<=A)
            {
                if(p[nowi]<r[now])
                {
                    ans+=r[now]-p[nowi];
                    nowi++;
                    now--;
                    flag=1;
                }
            }
            else
            if(nowj<=B&&q[nowj]<r[now])
            {
                ans+=r[now]-q[nowj];
                nowj++;
                now--;
                flag=1;
            }
        }
        if(!flag) break;
        if(now==0||nowi>A&&nowj>B) break;
    }
    cout<<ans<<'\n';
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int m;
  cin>>m;
  cout<<(48-m)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
int max(int a, int b=0){
    if (a > b)
        return a;
    return b;
}
int f(int a){
    if (a < 0)
        return -a;
    return a;
}
int main(){
    int n;
    cin >> n;
    int x[100], y[100], h[100];
    for (int i = 0; i < n;i++)
        cin >> x[i] >> y[i] >> h[i];
    int Hi = 1;
    //for (int Hi=1; Hi < __INT32_MAX__;Hi++)
        for (int c_x=0; c_x <= 100; c_x++)
            for (int c_y=0; c_y <= 100; c_y++){
                bool find = true;
                vector<int> zero;
                for (int m=1, i = 0; i < n ; i++){
                    if (h[i] == 0)
                        zero.push_back(i);
                    
                    if ((m==0) && h[i] != 0)
                        if(h[i] != max(Hi - f(x[i] - c_x) - f(y[i] - c_y))){
                            find = false;
                            break;
                        }
                    if (m && h[i] != 0){
                        Hi = h[i] + f(x[i] - c_x) + f(y[i] - c_y);
                        m = false;
                    }
                }
                if (find) {
                    for(auto i:zero)
                        if(h[i] != max(Hi - f(x[i] - c_x) - f(y[i] - c_y))){
                            find = false;
                            break;
                    }
                }
                if (find){
                    cout << c_x << ' ' << c_y << ' ' << Hi;
                    return 0;
                }
            }
    return 0; 
}

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

 int main() {
   int N;
   ll t = 0;
   cin >> N;
   vector<pair<ll, ll>> BA(N);
   rep(i, N) cin >> BA.at(i).second >> BA.at(i).first;
   sort(BA.begin(), BA.end());

   string ans = "Yes";
   rep(i, N) {
     t += BA.at(i).second;
     if (BA.at(i).first < t) {
       ans = "No";
       break;
     }
   }

   cout << ans << endl;
 }


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <fstream>
#include <numeric>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(int argc, char **argv) {
  int a, b;
  long double tubo;
  const long double rate = 3.305785L;

  cin >> a >> b;
  tubo = a * b / rate;
  printf("%.6Lf\n", tubo);
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main( void )
{
	while ( 1 )
	{
		int n;
		cin >> n;
		if ( n == 0 )
			break;

		vector <int> id( n );
		vector <char> names( n );
		vector <int> wins( n, 0 );
		vector <int> loses( n, 0 );
		for ( int i = 0; i < n; i++ )
		{
			id[i] = i;
			cin >> names[i];

			for ( int j = 0; j < n - 1; j++ )
			{
				int s;
				cin >> s;
				if ( s == 0 )
					wins[i]++;
				else if ( s == 1 )
					loses[i]++;
			}
		}

		for ( int i = 0; i < n-1; i++ )
		{
			for ( int j = i+1; j < n; j++ )
			{
				if ( wins[i] < wins[j] )
				{
					swap( id[i], id[j] );
					swap( wins[i], wins[j] );
					swap( loses[i], loses[j] );
					swap( names[i], names[j] );
				}
				else if ( wins[i] == wins[j] )
				{
					if ( loses[i] > loses[j] )
					{
						swap( id[i], id[j] );
						swap( wins[i], wins[j] );
						swap( loses[i], loses[j] );
						swap( names[i], names[j] );
					}
					else if ( loses[i] == loses[j] )
					{
						if ( id[i] > id[j] )
						{
							swap( id[i], id[j] );
							swap( wins[i], wins[j] );
							swap( loses[i], loses[j] );
							swap( names[i], names[j] );
						}
					}
				}
			}
		}

		for ( int i = 0; i < n; i++ )
		{
			cout << names[i] << endl;
		}

	}
	return 0;
}

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

typedef long long int ll;

void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
#define fioe() fileioe()
#else
#define fioe() 1
#endif
//!

int main()
{
	GO
	//fioe();
	ll k,n;
	cin>>k>>n;
	ll arr[n+2];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}	
	ll ans=0;ll maxi=0;
	for(int i=0;i<n-1;i++){
		ans+=abs(arr[i]-arr[(i+1)%n]);
		maxi=max(maxi,abs(arr[i]-arr[(i+1)%n]));
		
	}
	ans+=abs(k-abs(arr[0]-arr[n-1]));
	maxi=max(maxi,abs(k-abs(arr[0]-arr[n-1])));
	cout<<ans-maxi<<endl;
	return 0;
}

Measured memory_bytes: 1792
# coding: utf-8

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]


def solve(N, W, v, w):
    # dp[i][k]: 0~i?????????item????????????????????????????????????k??¨??????????????????????????´??????max value
    # return: max(dp[N-1][*])
    # dp[i][k] = max(dp[i-1][k], dp[i-1][k-w[i]] + v[i])
    # dp[i][0] = 0, dp[0][k] = 0(k<w[0]), v[0](otherwise)
    dp = array2d(N, W + 1)
    for k in range(0, W + 1):
        dp[0][k] = 0 if k < w[0] else v[0]
    for i in range(1, N):
        for k in range(0, W + 1):
            dp[i][k] = dp[i-1][k]
            if k - w[i] >= 0:
                dp[i][k] = max(dp[i][k], dp[i-1][k-w[i]] + v[i])
    return max(dp[-1])



def main():
    N, W = map(int, input().split())
    v = [None] * N
    w = [None] * N
    for i in range(N):
        v[i], w[i] = map(int, input().split())
    print(solve(N, W, v, w))

main()

Measured memory_bytes: 27512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

li ar[1000];

int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	li x;
	cin >> x;
	for(li i=0; i<=1000; i++)
	{
		ar[i] = i*i*i*i*i;
	}
	for(li i=0; i<=1000; i++)
	{
		for(li j=i-1; j>=0; j--)
		{
			if(ar[i]-ar[j]==x)
			{
				cout << i << " " << j;
				return 0;
			}
		}
	}
	for(li i=0; i<=1000; i++)
	{
		for(li j=i-1; j>=0; j--)
		{
			if(ar[i]+ar[j]==x)
			{
				cout << i << " " << -j;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3596
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

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

typedef long long ll;
typedef string str;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	string s;
	string t;
	cin >> s >> t;
	cout << t << s;
}


Measured memory_bytes: 256
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

struct E {
    double dist;
    int type; // 0: K++, 1: K--
}

void main() {
    const INF = 1e9;
    int N, K, T, U, V, L;
    scanf("%d %d %d %d %d %d\n", &N, &K, &T, &U, &V, &L);
    auto D = new double[N + 1];
    D[N] = L;
    foreach (i; 0 .. N) scanf("%lf\n", &D[i]);
    int rK = 0;
    int i = 0;
    double time = 0;
    double dist = 0;
    double ndist = INF; // 繝九Φ繧ク繝ウ蛻?ｌdistance
    bool fast = false;
    while (true) {
        //writeln([i, dist, ndist, time, rK]);
        if (!fast) {
            assert(rK == 0);
            time += (D[i] - dist) / U;
            dist = D[i];
            if (i == N) break;
            i++;
            fast = true;
            ndist = dist + V * T;
        } else if (D[i] < ndist) {
            time += (D[i] - dist) / V;
            dist = D[i];
            if (i == N) break;
            i++;
            if (rK == K) {
                ndist = dist + V * T;
            } else {
                rK++;
            }
        } else {
            time += (ndist - dist) / V;
            dist = ndist;
            if (rK == 0) {
                fast = false;
            } else {
                rK--;
                ndist = dist + V * T;
            }
        }
    }
    writefln("%.10f", time);
}

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

struct UnionFind{
    vector<int> par;
    vector<int> sizes;
    UnionFind(int n):par(n),sizes(n,1){ rep(i,n)par[i]=i; }

    //find root of x
    int find(int x){
        if(x!=par[x]) par[x] = find(par[x]);
        return par[x];
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }

    bool same(int x,int y){ return find(x) == find(y); }
    int size(int x){ return sizes[find(x)]; }
};

int main(void){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n+1);
    vector<int> p(n+1);
    p[0] = 0;
    rep1(i,n)cin>>p[i];
    rep(i,m){
        int x,y;
        cin>>x>>y;
        uf.unite(x,y);
    }
    int cnt = 0;
    rep1(i,n){
        if(uf.same(p[i],i)) cnt++;
    }
    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 1536
import sys
mod=10**9+7

N,M=map(int,input().split())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

alist.sort(reverse=True)
blist.sort(reverse=True)

for i in range(0,N-1):
  if alist[i]==alist[i+1]:
    print(0)
    sys.exit()
for i in range(0,M-1):
  if blist[i]==blist[i+1]:
    print(0)
    sys.exit()

alist.append(0)
blist.append(0)
    
answer=1
cnt_a=0
cnt_b=0
for i in reversed(range(1,N*M+1)):
  if alist[cnt_a]==i and blist[cnt_b]==i:
    cnt_a+=1
    cnt_b+=1
  elif alist[cnt_a]==i:
    cnt_a+=1
    answer*=cnt_b
    answer%=mod
  elif blist[cnt_b]==i:
    cnt_b+=1
    answer*=cnt_a
    answer%=mod
  else:
    answer*=(cnt_a*cnt_b-(N*M-i))
    answer%=mod
    
  if answer==0:
    break
    
print(answer)


Measured memory_bytes: 3188
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    int n, min;
    int count=1;
    cin >>n;
    vector<int> list(n);
    cin >> min;
    list[0] = min;
    FOR(i,1,n){
        cin >> list[i];
        if(min >= list[i]){
            count++;
            min = list[i];
        }
    }
    cout << count;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	//Arrays.sort(array, (a, b) -> Integer.compare(a[0], b[0]));
	
	public static void main(String[] args) {
		int n=scan.nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<n;i++)a[i]=scan.nextInt();
		a[0]=a[1];
		a[n]=a[n-1];
		int ans[]=new int[n];
		for(int i=0;i<n;i++) {
			ans[i]=min(a[i],a[i+1]);
		}
		int sum=0;
		for(int i=0;i<n;i++) {
			sum+=ans[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 23380
#from operator import itemgetter
from collections import Counter
N = int(input())
#N, M = map(int, input().split())
A = [int(input()) for i in range(N)]

answer = 0
C = Counter(A)
C_taple = C.most_common()

for i in C_taple:
    if i[1]%2!=0:
        answer += 1

print(answer)

Measured memory_bytes: 21368
#初期条件
K_N = list(map(int, input().split()))
A_line = list(map(int, input().split()))

#メイン実行部
length = []
for i in range(K_N[1] - 1):
  length.append(A_line[i + 1] - A_line[i])
else:
  length.append(K_N[0] - sum(length))

min_length = K_N[0] - max(length)
print(min_length)

Measured memory_bytes: 26420
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second


int main()
{
	ll n;scanf("%lld",&n);
	vector<ll> a(n);
	rep(i,n)scanf("%lld",&a[i]);
	ll ans1=0,ans2=0;
	ll total=0,flag=1;
	rep(i,n){
		flag*=-1;
		total+=a[i];
		if(total*flag<=0){
			ans1+=abs(total-flag);
			total=flag;
		}
	}
	total=0,flag=-1;
	rep(i,n){
		flag*=-1;
		total+=a[i];
		if(total*flag<=0){
			ans2+=abs(total-flag);
			total=flag;
		}
	}
	cout<<min(ans1,ans2)<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void debug() { std::cerr << '\n'; }
template <class H, class... T> void debug(H &&head, T &&... args) {
    std::cerr << head;
    sizeof...(args) == 0 ? std::cerr << "" : std::cerr << ' ';
    debug(std::forward<T>(args)...);
}
template <class T> void debug(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cerr << v[i];
        i == v.size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
    }
}
template <class T> void debug(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cerr << v[i][j];
            j == v[i].size() - 1 ? std::cerr << '\n' : std::cerr << ' ';
        }
    }
}

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

    int a, b, c;
    cin >> a >> b >> c;
    int ans;
    if (c <= a + b) {
        ans = c + b;
    } else {
        ans = 2 * b + a + 1;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include "math.h"
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ifor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long double ld;
typedef long long int lli;
typedef complex<double> P;
const double eps = 1e-11;
int vex[4] = {1, 0, -1, 0};
int vey[4] = {0, 1, 0, -1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
int main()
{
    int n;
    lli x[100005];
    lli a, b;
    cin >> n >> a >> b;
    rep(i, n) cin >> x[i];
    int cnt = 0;
    lli ans = 0;
    rep(i, n - 1)
    {
        lli y = x[i + 1] - x[i];
        if (a * y < b) {
            ans += a * y;
        } else {
            cnt++;
        }
    }
    ans += (cnt)*b;
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  vector<int> c(n+1);
  for(int i=0;i<=n;i++)c[i]=0;
  int y=0;
  int a[n];for(int i=0;i<n;i++){
    cin>>a[i];
    if(c[a[i]]==0)y++;
    c[a[i]]++;
  }
  int ans=0;
  sort(c.begin(),c.end());
  for(int i=n+1-y;;i++){
    if(y<=k){
      cout<<ans<<endl;
      return 0;
    }
    ans+=c[i];
    y--;
  }
}
  
  

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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  if (n % 2){
    cout << "No" << endl;
    return 0;
  }
  if (s.substr(0, n / 2) == s.substr(n / 2)){
    cout << "Yes";
  }else{
    cout << "No";
  }
  cout << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
H = list(map(int,input().split()))
dp = [10**9 for i in range(N+1)]
dp[1] = 0
for i in range(2,N+1):
    a = 10**9
    for j in range(1,K+1):
        if i - j - 1 < 0:
            continue
        x = H[i-1-j] - H[i-1]
        if x < 0:
            x = -x
        a = min(dp[i-j]+x,a)
    dp[i] = a
print(dp[N])

Measured memory_bytes: 56032
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
import numpy as np
# from copy import deepcopy
#from collections import deque
import numba

N = int(input())
P = np.array(list(map(int, sysread().split())))
#@numba.njit("void(i8,i8[:])")
@numba.njit
def run():
    seats = np.zeros((N,N), dtype=np.int16)
    seen = np.zeros((N,N), dtype=np.int8)  # there is a person : 1
    up, down = 0, N - 1
    dist = 0
    while True:
        seats[up, up:down+1] = dist
        seats[down, up:down+1] = dist
        seats[up:down+1, up] = dist
        seats[up:down+1, down] = dist
        up += 1
        down -= 1
        dist += 1
        if up > down:
            break

    ret = 0
    ###
    for i in range(N ** 2):
        # print(seats)
        cur_i, cur_j = (P[i] - 1) // N, (P[i] - 1) % N
        ret += seats[cur_i,cur_j]
        seen[cur_i,cur_j] = 1
        stack = [(cur_i, cur_j)]
        while stack:
            cur_i, cur_j = stack.pop()
            for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)):
                n_i = cur_i + i
                n_j = cur_j + j
                del_val = seats[cur_i, cur_j]
                if 0 <= n_i <= N - 1 and 0 <= n_j <= N - 1:
                    if seen[cur_i, cur_j] and del_val < seats[n_i, n_j]:
                        seats[n_i, n_j] = del_val
                        stack.append((n_i, n_j))
                    else:
                        if del_val + 1 < seats[n_i, n_j]:
                            seats[n_i, n_j] = del_val + 1
                            stack.append((n_i, n_j))

    print(ret)


if __name__ == "__main__":
    run()

Measured memory_bytes: 135092
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    ll n,m,ans=0;
    cin >> n >> m;
    vector<ll> x[m];
    ll p[m];
    for (ll i=0;i<m;i++){
        ll k;
        cin >> k;
        for (ll j=0;j<k;j++){
            ll y;
            cin >> y;
            x[i].push_back(y-1);
        }
    }
    for (ll i=0;i<m;i++){
        cin >> p[i];
    }
    for (ll bit=0;bit<(1LL<<n);bit++){
        bool flag=true;
        for (ll i=0;i<m;i++){
            ll c=0;
            for (ll j=0;j<x[i].size();j++){
                if (1LL<<x[i][j]&bit){
                    c++;
                }
            }
            if (c%2!=p[i]){
                flag=false;
                break;
            }
        }
        if (flag){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

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

   ll N,P;
   cin>>N>>P;
   if(N==1){
      cout<<P<<endl;
      return 0;
   }

   vector<bool>era(sqrt(P)+9,true);
   era[0] = era[1] = false;
   for(int i=2;i<sqrt(P)+5;i++){
      if(era[i]){
         for(int j=2*i;j<sqrt(P)+5;j+=i){
            era[j] = false;
         }
      }
   }

   vector<int>prime;
   for(int i=0;i<=sqrt(P)+10;i++){
      if(era[i])prime.push_back(i);
   }

   ll ans = 1;
   for(auto it : prime){
      ll c = 0;
      //cout<<it<<endl;
      while(P%it==0){
         c++;
         P/=it;
         if(c%N==0)ans*=it;
         //cout<<it<<endl;
      }
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 1020
#include<iostream>

using namespace std;

int main(void){
    int n,m,l,r;
    int left=1,right=n;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        if(l>left)left=l;
        if(r<right)right=r;
    }
    int num=right-left+1;
    if(num<0)num=0;
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
k = []
s = []
N, M = map(int, input().split())
for i in range(M):
    ki, *si = map(int, input().split())
    k.append(ki)
    s.append(si)
p = list(map(int, input().split()))

switch = []
for i in range(2**N):
    switch.append([0] + list(map(int, format(i, 'b').zfill(N)))[::-1])
switch = np.array(switch)

index = set()
for i, (ki, si) in enumerate(zip(k, s)):
    on = []
    for ind, state in enumerate(switch):
        if sum(state[si]) % 2 == p[i]:
            on.append(ind)
    if i == 0:
        index = set(on)
    else:
        index = index & set(on)
print(len(index))

Measured memory_bytes: 20368
#include <stdio.h>
int main()
{
	int H,W;
	while(scanf("%d%d",&H,&W)!=EOF&&H!=0)
	{
		for(int i=0;i<H;i++)
		{
			for(int j=0;j<W;j++)
				printf("#");
			printf("\n");
		}
		printf("\n");
	}	
	return 0;
}


Measured memory_bytes: 2108
from itertools import product
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]

ans = 0
for hp in product(range(2), repeat=H):
    for wp in product(range(2), repeat=W):
        cnt = 0
        for i in range(H):
            for j in range(W):
                if hp[i] and wp[j] and C[i][j] == "#":
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)


Measured memory_bytes: 68392
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main(){
	int n;
	string s;
	int ans=1;
	
	cin >> n >> s;
	
	for(int i=0;i<n-1;i++){
		if(s[i]!=s[i+1])ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int n;
int G[101][101];
int A[101];
int flag[101];
void mst(int s){
  int i;
  int nx=-1,ct=10000000;
  int a = 0;
  for(i=0;i<n;i++){
    if(G[s][i]==-1) continue;
    else if(G[s][i] < A[i] && flag[i]==0) A[i] = G[s][i];
  }
  
  for(i=1;i<n;i++){
    if(flag[i]==1) continue;
    else{
      if(ct > A[i]){
	a = 1;
	ct = A[i];
	nx = i;
      }
    }
  }
  
  if(a){
    flag[nx] = 1;
    mst(nx);
  }
  
}
int main(){
  
  int i,j;
  
  scanf("%d",&n);
  for(i=1;i<n;i++) A[i] = 100000000;
  for(i=0;i<n;i++)
    for(j=0;j<n;j++) scanf("%d",&G[i][j]);
  flag[0]=1;
  mst(0);
  int ans=0;
  for(i=0;i<n;i++){
    //printf("%d\n",A[i]);
    ans+=A[i];
  }
  printf("%d\n",ans);
  /*
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(G[i][j]==-1) printf(" 0");
      else printf("%2d",G[i][j]);
    }
    printf("\n");
  }
  */
  return 0;
}



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

int main(){

        int x, y, t;

        while(true){

                cin >> x >> y;

                if(x == 0 && y == 0){
                        break;
                }

                if(x > y){
                        t = x;
                        x = y;
                        y = t;
                }

                cout << x << " " << y << endl;
        }

        return 0;

}





Measured memory_bytes: 2968
#import numpy as np
N = int(input())
A = list(map(int, input().split()))
#A = np.array(A)
t = A[0]
for i in range(1,N):
    t *= A[i]
    if int(t) > 1e18:
        for j in range(i,N):
            if A[j] == 0:
                t = 0
        break
if int(t) <= 1e18:
    print(int(t))
else:
    print(-1)


Measured memory_bytes: 21708
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
    char a[3];
    int sum,i,j;
    cin>>a;
    sum=700;
    if(a[0]=='o')
    sum=sum+100;
    if(a[1]=='o')
    sum=sum+100;
     if(a[2]=='o')
    sum=sum+100;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void){
  char N[10];
  bool flag = false;
  int ans = 0;
  int s = 0;
  cin >> N;
  for(int i = 0;i <= 10; i++){
    if(N[i] == 'A' || N[i] == 'C' || N[i] == 'G' || N[i] == 'T'){
      flag = true;
      s++;
    }else if(flag){
      if(s > ans){
      ans = s;
      }
      s = 0;
      flag = false;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  string s; cin >> s;
  int i = 0, j = (int)s.size()-1;
  int ans = 0;
  while(i < j){
    if(s[i] == s[j]){
      i++;
      j--;
    }else{
      if(s[i] == 'x') i++;
      else if(s[j] == 'x') j--;
      else{
        cout << -1;
        return 0;
      }
      ans++;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3716