akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

 class Graphs {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graphs() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for(i = 0; i < totalVertex; i ++) {
			ifSettled[i] = false;
			for(j = 0; j < totalVertex; j ++) {
				adjMatrix[i][j] = adjWeight[i][j] = 0;
			}
		}
		int u, v;
		for(i = 0; i < totalVertex; i ++) {
			u = in.nextInt();
			int degree = in.nextInt();
			for(j = 0; j < degree; j ++) {
				v = in.nextInt(); 
				adjMatrix[u][v] = 1;
				adjWeight[u][v] = in.nextInt();
			}	
		}
		in.close();
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {
		int[] distance = new int[totalVertex];
		distance[0] = 0;
		
		for(int i = 1; i < totalVertex; i++) {
			distance[i] = Integer.MAX_VALUE;
		}//for
		int currentNode = getUnsettledNearest(distance);
		
		while(currentNode!= -1) {
			LinkedList<Integer> neighborsOfCurrentNode = getUnsettledNeighbors(currentNode);
			ifSettled[currentNode]= true;
			
			for(Integer neighbor : neighborsOfCurrentNode) {
				distance[neighbor] = Math.min(distance[neighbor], distance[currentNode] + getWeight(currentNode, neighbor));
			} 
			
			
		
			currentNode = getUnsettledNearest(distance);
		}//while
	
		
		
		
			
			
	
		return distance;
	}//dijkstra
}

public class Main  {
	public static void main(String[] argv) {
		Graphs g = new Graphs();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			System.out.println(i + " " + dist[i]);
		}
	}
}


Measured memory_bytes: 40280
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
const int maxn = 2e5 +5;
const int inf = 1e9 + 1;
const ll llinf = 1e18 + 5;
int n , a[maxn];
int x;
ll s[maxn];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
    cin >> n >> x;
    ll res = LLONG_MAX;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i];
        s[i] = a[i] + s[i - 1];
    }
    vector<int> delta;delta.pb(5);
    for(int i = 2 ; i <= n ; ++i){
        delta.pb(i * 2 + 1);
    }
    for(int i = 1 ; i <= n ; ++i){
        int now = n;
        ll tmp = 0;
        for(int c : delta){
            function<ll(ll , ll )> Mul = [&](ll x , ll y){
                if(llinf / y < x)return llinf;
                return x * y;
            };
            if(now > i){
                tmp += Mul((s[now] - s[now - i]) , c);
            }else tmp += Mul((s[now]) , c);
            tmp = min(tmp,llinf);
            now -= i;
            if(now <= 0)break;
        }
        res = min(res , tmp + (ll)(n + i) * x);
    }
    cout << res;
}



Measured memory_bytes: 3704
#include<stdio.h>

int main(void){

int m,n,ai,min,max;

long sum; scanf("%d",&n);

for(m=0;m<n;m++){

scanf("%d",&ai);

if(m==0){

min=ai; max=ai; sum=ai;

}

else{

if(ai<min){

min=ai;

}

if(max<ai){

max=ai;

}

sum+=(long)ai;

}

}

printf("%d %d %ld\n",min,max,sum);

return 0;

}

Measured memory_bytes: 600
#include<iostream>
#include<utility>
#include<map>
#include<vector>
#include<set>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long int 
int main()
{
	ll n,x,t,a;
	cin>>n>>x>>t;
	if(n%x==0)
		a=n/x;
	else
		a=(n/x)+1;
	cout<<a*t<<endl;
	return 0;
}

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

int main() {
    int n,sum,pred=-1;
    cin >> n;
    vector <int> va;
    vector <int> vb;
    vector <int> vc;
    for (int i=0; i<n; i++)
    {
        int a;
        cin >> a;
        va.push_back(a);
    }
    for (int i=0; i<n; i++)
    {
        int b;
        cin >> b;
        vb.push_back(b);
    }
    for (int i=0; i<n-1; i++)
    {
        int c;
        cin >> c;
        vc.push_back(c);
    }
    sum = 0;
    for (int i=0; i<n; i++)
    {
        sum += vb[va[i]-1];
        if (pred+1 == va[i])
            sum += vc[pred-1];
        pred = va[i];
    }
    cout << sum;   
    return 0;
}

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

using namespace std;

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

int main()
{
    int a, b, tmp, uc;
    vector<int> v;
    cin >> a >> b;

    for (int i = 0; i < a; i++)
    {
        cin >> tmp;
        v.push_back(abs(tmp - b));
    }
    if (a == 1)
    {
        cout << v[0];
    }
    else
    {
        for (int i = 0; i < a; i++)
        {
            uc = i == 0 ? gcd(v[0], v[1]) : gcd(uc, v[i]);
        }
        cout << uc;
    }
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
int dp(int i,int last);
int n;
int a[9][100009],memo[100009][9];

int main(){
  memset(memo,-1,sizeof(memo));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin>>a[j][i];
    }
  }
  cout<<dp(0,5)<<endl;
  return(0);
}

int dp(int i,int last){
  int rec=0;
  if(memo[i][last]!=-1)return memo[i][last];
  if(i==n)return 0;
  for(int j=0;j<3;j++){
    if(last!=j){
      rec=max(rec,dp(i+1,j)+a[j][i]);
    }
  }
  return memo[i][last]=rec;
}


Measured memory_bytes: 14208
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		long INF = 100000000000000l;
		Scanner sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E = sc.nextInt();
		int r = sc.nextInt();
		int[]s = new int[E];
		int[]t = new int[E];
		long[]c = new long[E];
		for(int i = 0; i < E; i++) {
			s[i] = sc.nextInt();
			t[i] = sc.nextInt();
			c[i] = sc.nextLong();
		}
		sc.close();
		long[] d = dijkstra(V, r, s, t, c, false);
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < V; i++) {
			if(d[i] == INF) {
				sb.append("INF");
			}else {
				sb.append(d[i]);
			}
			sb.append("\n");
		}
		System.out.print(sb.toString());
	}
	public static long[] dijkstra(int N, int t, int[] from, int[] to, long[] cost, boolean flag) {
		final int WHITE = 0;
	    final int GRAY = 1;
	    final int BLACK = 2;
	    final long INF = 100000000000000l;
		long[] d = new long[N];
		int[] color = new int[N];
		@SuppressWarnings("unchecked")
		ArrayList<Node>[] adj = new ArrayList[N];
		for(int i = 0; i < N; i++) {
			d[i] = INF;
			color[i] = WHITE;
			adj[i] = new ArrayList<Node>();
		}
		int E = from.length;
		for(int i = 0; i < E; i++) {
			adj[from[i]].add(new Node(to[i], cost[i]));
			if(flag)adj[to[i]].add(new Node(from[i], cost[i]));

		}
		Queue<Node> pq = new PriorityQueue<Node>(new MyComparator());
		d[t] = 0;
		pq.add(new Node(t, 0l));
		while(!pq.isEmpty()) {
			Node f = pq.poll();
			int u = f.id;
			color[u] = BLACK;
			if(d[u] < f.cost) continue;
			for(int j = 0; j < adj[u].size(); j++) {
				int v = adj[u].get(j).id;
				if(color[v] == BLACK) continue;
				if(d[v] > d[u] + adj[u].get(j).cost) {
					d[v] = d[u] + adj[u].get(j).cost;
					pq.add(new Node(v, d[v]));
					color[v] = GRAY;
				}
			}
		}
		return d;
	}
	static class Node{
		int id;
		long cost;
		public Node(int id, long cost) {
			this.id = id;
			this.cost = cost;
		}
	}
	static class MyComparator implements Comparator<Node>{
		@Override
        public int compare(Node v1, Node v2) {
			if(v1.cost < v2.cost) {
				return -1;
			}else if(v1.cost == v2.cost) {
				return 0;
			}else {
				return 1;
			}
		}
	}
}


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

ll MOD = 1000000007;

ll pow (ll a, ll n) {
    ll res = 1;
    ll count = a;
    while (n) {
        if (n & 1) res = res * count % MOD;
        n /= 2;
        count = count * count % MOD;
    }
    return res;
}

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> sub(k+1,0);
    sub[k] = 1;
    for (ll i = k-1; i >= 1; i--) {
        ll num = k / i;
        sub[i] = pow(num, n);
        for (ll j = i * 2; j <= k; j += i) {
            sub[i] -= sub[j];
            if (sub[i] < 0) sub[i] += MOD;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= k; i++) { ans += i * sub[i]; ans %= MOD; }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
long gcd(long a,long b)
{
	if (a%b==0)
	{
		return(b);
    }
	else
	{
		return(gcd(b,a%b));
    }
}
int main() {
  long A,B,C,D,E,sum;
  cin>>A>>B>>C>>D;
  E=gcd(C,D);
  E=C*D/E;
  sum=0;
  sum=B/C+B/D-B/E-((A-1)/C+(A-1)/D-(A-1)/E);
  cout<<(B-A+1-sum)<<endl;
}

Measured memory_bytes: 256
import sys;

def init(n_):
    length = 1;
    while(length < n_):
        length*=2
    element=[0]*(2*length-1)
    for i in range(2*length-1):
        element[i] = initial
    return element,length

def update(k,a,element):
    k+=n-1
    element[k]=a
    while(k > 0):
        k = (int)((k-1)/2)
        element[k] = min(element[k*2+1],element[k*2+2])

def findmin(a, b):
    return findquery(a,b+1,0,0,n)

def findquery(a, b, k, l, r):
    if(r <= a or b <= l):
        return initial
    if(a <= l and r <= b):
        return element[k]

    vl = findquery(a,b,k*2+1,l,(int)((l+r)/2+0.5))
    vr = findquery(a,b,k*2+2,(int)((l+r)/2),r)
    return min(vl,vr)

n,q = map(int, input().split());

initial = pow(2,31)-1
element,n = init(n)

for i in range(q):
    query,key,value = map(int, input().split());
    if(query == 0):
        update(key,value,element)
    else :
        print(findmin(key,value))


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/*************************************************************************************/

const ll maxn=2e5+1,mod=1e9+7;



int main(){
    sync
  //  file();
   	int n,k;
   	cin>>n>>k;
   	vector<ll> dp(k+1);
   	dp[0] = 1;
   	forn(i,n){
   		int x;
   		cin>>x;
   		vector<int> fake(k+2);
   		for(int j=0;j<=k;++j){
   			int l = j+1;
   			int r = j+min(x,k-j)+1;
   			if(l<r&&l<=k){
   				fake[l]+=dp[j];
   				fake[l]%=mod;
   				fake[r]-=dp[j];
   				fake[r]+=mod;
   				fake[r]%=mod;
   			
   			}
   		}
   		ll pre = 0;
   		fore(lel,0,k){
   			pre+=fake[lel];
   			pre%=mod;
   			dp[lel]+=pre;
   			dp[lel]%=mod;
   		}
   	}
   	cout<<dp[k]<<endl;

	return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
const int N = 1e9+10;

int main()
{
    _SAD()
    int n,k;
    cin>>n>>k;
    int cnt=0;
    for(int i=1;i<=n;i+=2)
    {
		cnt++;
	}
	if(cnt>=k)
	{
		cout<<"YES"<<nl;
	}
	else
	{
		cout<<"NO"<<nl;
	}
    return 0;
}


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

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

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

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

int main(){
  string s;cin>>s;
  int ans =0;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()-i-1])ans++;
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	
	//1324 start
	
	int [][] field;
	int [] maxheight;
	int wid = 5;
	int height = 5000;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			field = new int[height][wid];
			maxheight = new int[wid];
			for(int i = 0; i < n; i++){
				int d = sc.nextInt();
				int p = sc.nextInt();
				int q = sc.nextInt();
				fall(d,p,q-1);
				//disp();
			}
			int ans = count();
			System.out.println(ans);
		}
	}
	private void disp() {
		for(int i = height - 1; i >= 0; i--){
			for(int j = 0; j < wid; j++){
				System.out.printf("%2d ",field[i][j]);
			}
			System.out.println();
		}
		debug(maxheight);
		System.out.println();
		
	}
	private void fall(int dir, int len, int pos) {
		if(dir == 1){
			int nowmaxheight = 0;
			for(int i = 0; i < len; i++){
				nowmaxheight = Math.max(maxheight[pos + i], nowmaxheight);
			}
			
			for(int i = 0; i < len; i++){
				field[nowmaxheight][pos + i] = 1;
				maxheight[pos + i] = nowmaxheight + 1;
			}
		}
		else{
			for(int i = 0; i < len; i++){
				field[maxheight[pos] + i][pos] = 1;
			}
			maxheight[pos] += len;
		}
		erase();
	}
	private void erase() {
		int nowmaxheight = 0;
		for(int i = 0; i < wid; i++){
			nowmaxheight = Math.max(maxheight[i], nowmaxheight);
		}
		for(int i = 0; i < nowmaxheight; i++){
			boolean flg = true;
			for(int j = 0; j < wid; j++){
				if(field[i][j] == 0){
					flg = false;
					break;
				}
			}
			if(flg){
				for(int j = 0; j < wid; j++){
					field[i][j] = -1;
				}
			}
		}
		Arrays.fill(maxheight, 0);
		for(int i = 0; i < wid; i++){
			int ind = 0;
			for(int j = 0; j < height; j++){
				if(field[j][i] == -1){
					
				}
				else{
					field[ind++][i] = field[j][i];
				}
			}
			for(;ind < height; ind++){
				field[ind][i] = 0;
			}
			for(int j = height -1 ; j >= 0; j--){
				if(field[j][i] == 1){
					maxheight[i] = j + 1;
					break;
				}
			}
		}
	}
	private int count() {
		int c = 0;
		for(int i = 0; i < height; i++){
			for(int j = 0; j < wid; j++){
				if(field[i][j] == 1){
					c++;
				}
			}
		}
		return c;
	}
	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 28440
#include <iostream>
using namespace std;
class Dice{
public:
    int n1,n2,n3,n4,n5,n6;
     
    void East(){
        int t = n1;
        n1 = n4;
        n4 = n6;
        n6 = n3;
        n3 = t;
    }
    void West(){
        int t = n1;
        n1 = n3;
        n3 = n6;
        n6 = n4;
        n4 = t;
    }
    void South(){
        int t=n1;
        n1 = n5;
        n5 = n6;
        n6 = n2;
        n2 = t;
    }
    void North(){
        int t=n1;
        n1 = n2;
        n2 = n6;
        n6 = n5;
        n5 = t;
    }
    void Rotation(){
        int t=n2;
        n2 = n3;
        n3 = n5;
        n5 = n4;
        n4 = t;
    }
};
 
int main(){
    Dice d[100];
    int n;
     
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>d[i].n1>>d[i].n2>>d[i].n3>>d[i].n4>>d[i].n5>>d[i].n6;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(j==i)continue;
            for(int k=0; k<6; k++){
                if(k==4){
                    d[i].East();
                }
                if(k==5){
                d[i].East();
                d[i].East();
                }
                for(int l=0; l<4; l++){
                    d[i].Rotation();
                    if(d[i].n1==d[j].n1 && d[i].n2==d[j].n2 && d[i].n3==d[j].n3 &&
                       d[i].n4==d[j].n4 && d[i].n5==d[j].n5 && d[i].n6==d[j].n6){
                        cout<<"No"<<endl;
                        return 0;
                    }
                }
            }
             
        }
         
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1160
K = int(input())
A,B = list(map(int, input().split()))
num = K
flag = 0
while(flag==0):
  if(A<=num and num<=B):
    flag = 1
    break
  num += K
  if(num>B):
    break
if(flag==0):
  print("NG")
else:
  print("OK")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}

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

  string s; cin >> s;
  int n = s.size();

  vector<int> cnt(n+1);
  REP(i,n) cnt[i+1] = cnt[i] + (s[i] == 'W' ? 1 : 0);

  int white = count(ALL(s), 'W');

  LLI ans = 0;

  REP(i,n){
    if(s[i] == 'B')
      ans += white - cnt[i];
  }

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


Measured memory_bytes: 1428
# coding=utf-8


num = int(input())
b_list = list(map(int,input().split(" ")))
a_list = []

for i in range(num):
	n = num -i
	while n != 0:
		if b_list[n-1] == n:
			val = b_list.pop(n-1)
			a_list.insert(0,val)
			break
		else:
			n -= 1
if len(a_list) == num:
	for w in a_list:
		print(w)
else:
	print("-1")


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

int main()
{
  int n;
  cin >> n;
  int a[n];
  int b[n];
  int c[n-1];
  for(int i = 0; i < n; ++i)
    cin >> a[i];
  
  for(int i = 0; i < n; ++i)
    cin >> b[i];
  
  for(int i = 0; i < n-1; ++i)
    cin >> c[i];
  
  int cost = b[a[0]-1];
  for(int i = 1; i < n; ++i)
  {
  	if(a[i]-a[i-1] == 1)
    {
      cost += b[a[i]-1] + c[a[i-1]-1];
    }
    else
    {
      cost += b[a[i]-1];
    }
  }
  cout << cost;
}

Measured memory_bytes: 256
def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n = NextInt()
da = [NextIntList() for i in range(n)]
cnt, ans = 0, 0
for i in range(n):
    if(da[i][0] == da[i][1]):
        cnt += 1
    else:
        cnt = 0
    ans = max(ans, cnt)
if ans >= 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9148
# -*- coding: utf-8 -*-
n = int(input())
a=list(map(int, input().split()))

#ソートして配列番号を持ってくる
b = {}
for index,x in enumerate(a):
    b[x] = index

ans = sorted(b.items(), key=lambda x: x[0])
for k,v in ans:
     print(str(v+1)+" ",end="")


Measured memory_bytes: 25500
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int N, K;
	int h[100000];
	int count = 0;

	scanf("%d %d", &N,&K);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &h[i]);
		if (h[i] >= K)
			count++;
	}

	printf("%d", count);

	return 0;
}
	

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <bitset>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

ll calc(ll val) {
    if(val % 2 == 0) {
        if(val/2%2 == 1) {
            return val^1;
        }
        else {
            return val;
        }
    }
    else {
        if((val+1)/2%2 == 1) {
            return 1;
        }
        else {
            return 0;
        }
    }

}

int main() {
    ll a, b;
    cin >> a >> b;
    ll ac, bc;
    ac = calc(a-1);
    bc = calc(b);
    ll ans = 0;
    ans ^= ac;
    ans ^= bc;
    cout << ans << endl; 
    return 0;
    /*
    if(a % 2 == 1) {
        ans ^= a;
        a++;
    }
    if(b % 2 == 0) {
        ans ^= b;
        b--;
    }
    if((b-a+1)/2 % 2 == 1) ans ^= 1;
    cout << ans << endl;
    return 0;
    */
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";

        int const N = 1e6 + 10;
        set<int> st[N];

        int32_t main()
        {
            tani_nachi_ke  
            
            int n;
            cin >> n;
            int a[n];
        
            int gcd = 0;

            int spf[N];
            for(int i = 1; i < N; i++)
                spf[i] = i;
            for(int i = 4; i < N; i+=2)
            {
                spf[i] = 2;
            }

            for(int i = 3; i * i < N; i++)
            {
                if(spf[i] == i)
                {
                    for(int j = i*i; j < N; j+=i)
                    {
                        if(spf[j] == j)
                            spf[j] = i;
                    }
                }
            }


            for(int i = 2; i < N; i++)
            {
                int x = i;
                while(x != 1)
                {
                    st[i].insert(spf[x]);
                    x /= spf[x];
                }
                if(x != 1)
                    st[i].insert(x);
            }

            set<int> cur;
            bool ok = 1;
            for(int i = 0; i < n; i++)
            {
               
                cin >> a[i];
                gcd = __gcd(gcd, a[i]);
                int x = a[i];
                if(!ok)
                    continue;
                for(auto &it: st[a[i]])
                {
                    if(cur.find(it) != cur.end())
                    {
                        ok = 0;
                        break;
                    }
                    else
                        cur.insert(it);
                }

            }

            if(ok)
            {
                cout << "pairwise coprime\n";
            }
            else
            {
                if(gcd == 1)
                    cout << "setwise coprime\n";
                else
                    cout << "not coprime\n";
            }





           return 0;
        }
          

Measured memory_bytes: 199888
n,m,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
ans = "War"
for Z in range(X+1,Y+1):
    if max(x) < Z and min(y) >= Z:
        ans = "No War"
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    int n;
    cin >> n;
    
    int ans = -1;
    for (double i = 0; i <= n; i++)
    {
        double c = i * 1.08;
        if ((int)floor(c) == n) ans = (int)i;
    }
    
    if (ans != -1)
    {
        cout << ans << endl;
    }
    else
    {
        cout << ":(" << endl;
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
using namespace std;

int n,k,same,sum = 0;
string fig[11];
bool ju[11];
set <string> chk; 

void rec(int idx,string con){
  if(idx == k){
    if(chk.find(con) == chk.end()) chk.insert(con); 
    return;
  }
  for(int i=0;i<n;i++){
    if(ju[i]){
      ju[i] = false;
      rec(idx+1,con+fig[i]);
      ju[i] = true;
    }
  }
}


int main(){
  while(cin >> n >> k,n||k){
    memset(ju,true,sizeof(ju));
    for(int i=0;i<n;i++) cin >> fig[i];
    for(int i=0;i<n;i++){
      ju[i] = false;
      rec(1,fig[i]);
      ju[i] = true;
    }
    cout << chk.size() << endl;
    chk.clear();
  }
}

Measured memory_bytes: 1456
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sca=new Scanner(System.in);
		//System.out.println(Integer.toBinaryString(4));
	//	System.out.println((1+200000)*100000);
		while(sca.hasNext()){
			int n=sca.nextInt();
			int ai[]=new int[n+1];
			for(int i=1;i<=n;i++){
				ai[i]=sca.nextInt();
			}
			String be="00000000000000000000000";
			//System.out.println(be.length());
			int of=0;
			int st=1;
			long sum=0;
			for(int i=1;i<=n;i++){
				String t=Integer.toBinaryString(ai[i]);
				int l=be.length()-1;
				int r=t.length()-1;
				while(l>=0&&r>=0){
					if(be.charAt(l)=='1'&&t.charAt(r)=='1'){
						while(true){
						of-=ai[st];
						st++;
						be=Integer.toBinaryString(of);
						 l=be.length()-1;
						 r=t.length()-1;
						 int flag=0;
						 while(l>=0&&r>=0){
							 if(be.charAt(l)=='1'&&t.charAt(r)=='1'){
								 flag=1;
								 break;
							 }
							 l--;
							 r--;
						 }
						 if(flag==0)break;
						}
						break;
					}
					l--;
					r--;
				}
				of+=ai[i];
				be=Integer.toBinaryString(of);
				sum+=(i-st+1);
			}
			System.out.println(sum);
			
		}
	}

}


Measured memory_bytes: 93404
import Data.List

ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))

f a b = sum $ map abs $ zipWith (-) a [b+1..]

diff a b = f a (b+1) - f a b

calc a = let b = ibsearch ((>=0) . diff a) (maximum a, minimum a - length a - 1) in f a b

main = getLine >> getLine >>= print . calc . map read . words


Measured memory_bytes: 72060
n = int(input())
s = [int(input()) for _ in range(n)]
s.sort()
min = 0
for i in range(n):
	if s[i]%10 != 0:
		min = s[i]
		break
sum = sum(s)
if sum%10!=0:
	print(sum)
elif min==0:
	print("0")
else:
	print(sum-min)

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

int main()
{  
  int n,i;
  cin >> n;
  if(n%2==0){
    n/=2;
    char s[n+1];
    char e;
    for(i=0;i<n;++i){
      cin >> s[i];
    }
    for(i=0;i<n;++i){
      cin >> e;
      if(s[i]!=e){
        cout << "No" << endl;
        return 0;
      }
    }
  }else{
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a=0,b=0;
	scanf("%d %d",&a,&b);
	if(a < b) printf("a < b\n");
if(a > b) printf("a > b\n");
if(a == b) printf("a == b\n");
	return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <vector>
#include <map>

using namespace std;

void selection_sort(vector< pair<int,char> >& a) {
	int nos = 0;
	int minj,size = a.size();
	for (int i = 0; i < size; ++i) {
		minj = i;
		for (int j = i; j < size; ++j) {
			if (a[j].first < a[minj].first) {
				minj = j;
			}
		}
		swap(a[i],a[minj]);
	}
	return;
}

void bubble_sort(vector< pair<int,char> >& a) {
	int size = a.size();
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = size-1; i > 0; --i) {
			if (a[i].first < a[i-1].first) {
				swap(a[i].first,a[i-1].first);
				swap(a[i].second,a[i-1].second);
				flag = true;
			}
		}
	}
	return;
}

int main(void) {
	int n;
	cin >> n;
	vector< pair<int,char> > b(n),s(n),ss(n);
	vector< vector<char> > data(9);
	for (int i = 0; i < n; ++i) {
		cin >> b[i].second;
		cin >> b[i].first;
		s[i].first = b[i].first;
		s[i].second = b[i].second;
		data[b[i].first-1].push_back(b[i].second);
	}
	int ind = 0;
	for (int i = 0; i < 9; ++i) {
		for (int j = 0; j < data[i].size(); ++j) {
			ss[ind].first = i+1;
			ss[ind].second = data[i][j];
			++ind;
		}
	}

	bubble_sort(b);
	bool bis = true;
	for (int i = 0; i < n; ++i) {
		cout << b[i].second << b[i].first;
		if (b[i] != ss[i]) {
			bis = false;
		}
		if (i < n-1) {
			cout << " ";
		}
	}
	cout << endl;
	if (bis) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
	selection_sort(s);
	bool sis = true;
	for (int i = 0; i < n; ++i) {
		cout << s[i].second << s[i].first;
		if (s[i] != ss[i]) {
			sis = false;
		}
		if (i < n-1) {
			cout << " ";
		}
	}
	cout << endl;
	if (sis) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
	return 0;
}



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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int n; cin >> n;
    int a[n]; rep(i,0,n) cin >> a[i];

    sort(a,a+n);
    ll ans = 0;
    priority_queue<int> pq;
    pq.push(a[n-2]);
    ans+=a[n-1];
    pq.push(a[n-2]);
    rep(i,2,n){
        int f = pq.top();
        pq.pop();

        ans += f;
        pq.push(a[n-1-i]);
        pq.push(a[n-1-i]);
    }
    cout << ans << "\n";
}

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

// input
int A, B, C;


void input() {
    cin >> A >> B >> C;
}


int main() {
    input();
    string ans;
    if (A <= C && C <= B) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 3636
import math

H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

res = [[0]*W for i in range(H)]
cur = [0, 0]

for i, ai in enumerate(a):
    while ai > 0:
        res[cur[0]][cur[1]] = (i + 1)
        if cur[1] % 2 == 0:
            if cur[0] == (H-1):
                cur[1] += 1
            else:
                cur[0] += 1
        else:
            if cur[0] == 0:
                cur[1] += 1
            else:
                cur[0] -= 1
        ai -= 1

str_n = int(math.log10(N)) + 2

for i in range(H):
    for j in range(W):
        print(str(res[i][j]).ljust(str_n), end="")
    print("")

Measured memory_bytes: 75416
#include <iostream>

using namespace std;

int main(void){
  int i,j,temp,a[3];
  
  for(i=0;i<3;i++)  cin >> a[i];
  for(i=0;i<2;i++){
    for(j=0;j<2-i;j++){
      if(a[j]>a[j+1]){
        temp=a[j];
        a[j]=a[j+1];
        a[j+1]=temp;
      }
    }
  }

  cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
}

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

using namespace std;
vector<int> a;
vector<long long> v;
int w;
int n;

long long knapsack()
{
    long long K[n+1][w+1];

    // Build table K[][] in bottom up manner
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            if (i==0 || j==0)
                K[i][j] = 0;
            else if (v[i-1] <= j)
                K[i][j] = max(a[i-1] + K[i-1][j-v[i-1]],  K[i-1][j]);
            else
                K[i][j] = K[i-1][j];
        }
    }

    return K[n][w];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long x, y;
    cin >> n >> w;
    for(int i = 0; i < n; i++)
    {
        cin >> x >> y;
        v.push_back(x);
        a.push_back(y);
    }
    cout<<knapsack();

}


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

int main() {
  int n; cin >>n;
  vector<long> a(n);
  long sum = 0;
  for (int i=0; i<n; i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  
  long bufsum=0;
  long minsub=2000000000;
  long bufsub;
  for (int i=0; i<n-1; i++){
    bufsum += a.at(i);
    if (bufsum<=sum/2){ bufsub = (sum-bufsum)-bufsum;}
    else{ bufsub = bufsum-(sum-bufsum);}
    minsub = min(minsub, bufsub);
  }
  cout <<minsub <<endl;
}


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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int turn = 0;
    while (true) {
        if (turn == 0) {
            if (A == 1 && B == 2) {
                cout << "Borys" << endl;
                return 0;
            } else if (A == 1) {
                A++;
            } else if (B == A + 1) {
                A--;
            } else if ((B - A) % 2 == 0) {
                A++;
            } else {
                A--;
            }
            turn = 1;
        } else {
            if (A == N - 1 && B == N) {
                cout << "Alice" << endl;
                return 0;
            } else if (B == N) {
                B--;
            } else if (A == B - 1) {
                B++;
            } else if ((B - A) % 2 == 0) {
                B--;
            } else {
                B++;
            }
            turn = 0;
        }
    }
}

Measured memory_bytes: 256
function main(i) {
  i = i.split(' ');
  if (Number(i[0]) === Number(i[1]) && Number(i[0]) === Number(i[2])) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <stdio.h>
#include <iostream>
 
int main(){
  char str;
  char ans[1];
  std::cin >> str;
  
  if (isupper(str)){
  	ans[0] = 'A';
  }else{
    ans[0] = 'a';
  }
  std::cout << ans[0] << "\n";
}

Measured memory_bytes: 3600
use itertools::izip;
use proconio::input;
fn main() {
    input! {
        s: String
    }
    let t = "CODEFESTIVAL2016";
    let mut res = 0;
    for (i, j) in izip!(s.chars(), t.chars()) {
        if i != j {
            res += 1;
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;

int main(void){
    int n;
    vector <int> a;
    deque <int> b;
    int x;
    
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        a.push_back(x);
    }
    
    b.push_back(a[0]);
    
    for(int i = 1; i < n; i++){
        if((i - 1) % 2 == n % 2){
            b.push_front(a[i]);
        }
        else{
            b.push_back(a[i]);
        }
    }
    
    for(int i = 0; i < b.size(); i++){
        cout << b[i] << " ";
    }
    
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int INF=1001001001;

int main() {
  int64_t N,A,B;
  cin>>N>>A>>B;
  int64_t ans=0;
  if(A%2==B%2){ans=abs(A-B)/2;}
  else{ans=min(A-1,N-B)+1+(B-A-1)/2;}
  cout<<ans<<endl;
  return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;
using vd = vector<ld>;

template<class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<class TIn, class TOut = null_type>
using order_tree = tree<TIn, TOut, less<TIn>, rb_tree_tag,
	tree_order_statistics_node_update>;
// .find_by_order(int r) and .order_of_key(TIn v)

constexpr int INF = 2000000010;
constexpr ll LLINF = 9000000000000000010LL;
constexpr ld PI = acos(-1);

void solve() {
	string S;
	cin >> S;
	ll b = 0, ans = 0LL;
	for (char c : S) {
		if (c == 'B') ++b; else ans += b;
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 720
using System;
using System.Text;

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

            for(int i = 0; i < l; i++)
            {
                string[] o = Console.ReadLine().Split(' ');
                int b = int.Parse(o[1]);
                int e = int.Parse(o[2]);
                int n = e - b + 1;
                string t = s.Substring(b, n);

                if ("replacereverse".Contains(o[0]))
                {
                    StringBuilder sb = new StringBuilder(s);

                    string _m;

                    if(o[0] == "reverse")
                    {
                        char[] _c = t.ToCharArray();
                        Array.Reverse(_c);
                        _m = new string(_c);
                    }
                    else
                    {
                        _m = o[3];
                    }
                    
                    sb.Replace(t, _m, b, n);
                    s = sb.ToString(); 
                }
                else
                {
                    Console.WriteLine(t);
                }
            }
        }
    }
}

Measured memory_bytes: 9860
const main = (input) => {
  const args = input.split('\n');
  const N = parseInt(args[0], 10),
        cards = args[1].split(' ').map(n => parseInt(n, 10));
  
  const aSum = 0,
        bSum = 0;
  
  cards.sort((a, b) => (a < b ? 1 : -1)).forEach((n, i) => {
    (i % 2 === 0)? aSum += n :bSum += n;
  });
  console.log(aSum - bSum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 1;
  REP(i, n) { cin >> a[i]; }
  sort(ALL(a));

  REP(i, n) {
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    if (a[i] >= (ll)(1e18) / ans + 1) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4052
#include <stdio.h>
int main(void) {

	int a, b;

	-1000 <= a, b <= 1000;
	
	scanf("%d %d\n", &a, &b);

	if(a == b){
		printf("a == b\n");
	}
	else if(a > b){
		printf("a > b\n");
	}
	else {
		printf("a < b\n");
	}

	return(0);

}


Measured memory_bytes: 2056
def taka():
    n = int(input())
    listofwords =[]
    for i in range(n):
        strTEMP = input()

        if i == 0:
            listofwords.append(strTEMP)
            continue
        else:
            if strTEMP in listofwords:
                return "No"
            else:
                cmp = listofwords[-1]
                if strTEMP[0] != cmp[-1]:
                    return "No"
                else:
                    listofwords.append(strTEMP)
    return "Yes"

print(taka())


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15)cout << "+" << endl;
	else if (a*b == 15)cout << "*" << endl;
	else cout << "x" << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 764
n, m, x = map(int, input().split())
c = [None for _ in range(n)]
a = [None for i in range(n)]
ans = None
for i in range(n):
    c[i], *ai = map(int, input().split())
    a[i] = list(ai)
for p in range(2 ** n):
    y = [0 for _ in range(m)]
    s = format(p, '0{:}b'.format(n))
    cp = 0
    for i, (si, ci) in enumerate(zip(s, c)):
        if si == '1':
            cp += ci
            for j in range(m):
                y[j] += a[i][j]
    for yj in y:
        if yj < x:
            break
    else:
        ans = cp if ans is None else min(ans, cp)
if ans is None:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e5 + 2;
const ll Mod = 1e9 + 7;

string s;
ll dp[N][15];

ll go(int pos, int rem){
	if(pos == sz(s)) return (rem == 5);
	ll &ans = dp[pos][rem];
	if(ans != -1) return ans;
	ans = 0;
	int lf = 0, rg = 9;
	if(s[pos] != '?') {
		lf = rg = int(s[pos] - '0');
	}
	for(int d = lf; d <= rg; ++ d){
		ans += go(pos + 1, (rem*10LL + d) % 13);
		if(ans >= Mod) ans -= Mod;
	}
	return ans;
}

int main(){
	fastio;
	cin >> s;
	memset(dp, -1, sizeof(dp));
	cout << go(0, 0) << endl;
	return 0;
}



Measured memory_bytes: 23308
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,m;
int main(){
	n=read(),m=read();
	printf("%d\n",n*(n-1)/2+m*(m-1)/2);
	return 0;
}


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

//nap no some
struct nap{
	vector<long long> v,w;
	long long N,W;
	vector< vector<long long> > dp;
	nap(long long n,long long wmax){
		N=n;W=wmax;
		v.resize(n);
		w.resize(n);
		vector<long long> wv(W+1,0);
		for(int i=0;i<n+1;++i){
			dp.push_back(wv);
		}
	}
	void calc(){
		for(int i=0;i<N;i++){
			for(int j=0;j<W+1;j++){
				if(j<w[i]){
					dp[i+1][j]=dp[i][j];
				}else{
					dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
				}
			}
		}
	}
	long long maxval(long long w){
		return dp[N][w];
	}
  
  
};
  
  
int main(){
	long long n,w;
	cin>>n>>w;
	nap na(n,w);
	for(int i=0;i<n;++i){
		cin>>na.v[i]>>na.w[i];
	}
	na.calc();
	cout<<na.maxval(w)<<endl;
	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int D,G;
  cin>>D>>G;
  vector<int>p(D),c(D);
  for(int i=0;i<D;i++)cin>>p[i]>>c[i];
  int bit=pow(2,D);
  int ans=INT_MAX;
  for(int i=0;i<bit;i++){
    ll sum=0;
    int count=0;
    for(int j=0;j<D;j++){
      if((i>>j)&1){
        sum+=100*(j+1)*p[j];
        sum+=c[j];
        count+=p[j];
      }
    }
    for(int j=D-1;j>=0;j--){
      if(sum>=G)break;
      if(!((i>>j)&1)){
        for(int k=0;k<p[j]-1;k++){
          if(sum>=G)break;
          sum+=100*(j+1);
          count++;
        }
      }
    }
    if(sum>=G)ans=min(ans,count);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
x=int(input())
m = 10**6
n=[0]*m
for i in range(2,m):
  if n[i] == 1: continue
  j = 2*i
  while j < m:
    n[j]=1
    j+=i
#print(n[:100])
for i in range(x,m):
  if n[i]==0:
    print(i)
    exit()


Measured memory_bytes: 16796
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
k = int(input())

ans = 0

for x in range(1,k+1):
    for y in range(1,k+1):
        xy = gcd(x,y)
        for z in range(1,k+1):
            ans += gcd(xy,z)

print(ans)


Measured memory_bytes: 70672
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<ll,int>P;

struct edge{
	int to;   //?????????
	int cost; //?????????
};

const int MAX_N = 100005;

int n,m,c;
ll d[MAX_N];
vector<edge> G[MAX_N];
set<int> K;
multimap<ll,int> mp;

void dijkstra(int s)
{
	priority_queue<P,vector<P>,greater<P> > que;
	d[s] = 0LL;
	que.push(P(0LL,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		vector<edge>::iterator it = G[v].begin();
		while(it != G[v].end()){
			if(d[it->to] > d[v] + it->cost){
				d[it->to] = d[v] + it->cost;
				que.push(P(d[it->to],it->to));
			}
			it++;
		}
	}
}

int main()
{
	ll esum = 0LL;
	scanf("%d%d%d",&n,&m,&c);
	rep(i,m){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		edge e1,e2;
		e1.to=y-1,e1.cost=z;
		e2.to=x-1,e2.cost=z;
		G[x-1].push_back(e1);
		G[y-1].push_back(e2);
		esum += z;
	}
	fill(d,d+n,(1LL << 60));
	dijkstra(0);
	rep(i,n){
		mp.emplace(d[i],i);
	}
	sort(d,d+n);
	int id=0;
	ll ans=(1LL << 60);
	while(id<n){
		auto p = mp.equal_range(d[id]);
		for(auto it=p.first;it!=p.second;++it){
			int u = it->second;
			rep(k,G[u].size()){
				if(K.find(G[u][k].to)!=K.end()){
					esum -= G[u][k].cost;
				}
			}
			K.insert(u);
		}
		ans = min(ans,c*d[id]+esum);
		id += (int)mp.count(d[id]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 23316
import sys
import time
st = time.perf_counter()
# ------------------------------

def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    pn = list(map(int, input().split()))
    if x not in pn:
        print(x)
        return
    for i in range(1, 1001001001):
        ls = []
        if x - i not in pn:
            ls.append(x-i)
        if x + i not in pn:
            ls.append(x+i)
        if ls:
            print(min(ls))
            return

main()
    
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 9164
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
 
using namespace std;
#define rep(i,j) for(int i = 0; i < (j); i++)
int main(){
    map< string, vector<int> > data;
    string str;
    int page;
    while(cin >> str >> page){
        data[str].push_back(page);
    }
    map< string, vector<int> >::iterator it = data.begin();
    while(it != data.end()){
        cout << (*it).first << endl;
        int len = (*it).second.size();
        if(len == 1)cout << (*it).second[0] << endl;
        else{
            sort((*it).second.begin(),(*it).second.end());
            rep(i,len-1){
                cout << (*it).second[i] << " ";
            }
            cout << (*it).second[len-1] << endl;
        }
        it++;
    }
    return 0;
}

Measured memory_bytes: 1244