akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			Map<String, Integer>[] supers = new Map[n];
			for (int i = 0; i < n; i++)
				supers[i] = new HashMap<String, Integer>();
			Map<String, Integer> min = new HashMap<String, Integer>();
			for (int i = 0; i < n; i++) {
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					String name = scanner.next();
					int value = scanner.nextInt();
					supers[i].put(name, value);
					if (!min.containsKey(name) || min.get(name) > value)
						min.put(name, value);
				}
			}
			int q = scanner.nextInt();
			String[] name = new String[q];
			for (int i = 0; i < q; i++)
				name[i] = scanner.next();
			int m = scanner.nextInt();
			int[][] ad = new int[n + 1][n + 1];
			while (m-- > 0) {
				int s = scanner.nextInt();
				int t = scanner.nextInt();
				int d = scanner.nextInt();
				ad[s][t] = ad[t][s] = d;
			}
			int sum = 0;
			for (int i = 0; i < q; i++) {
				if (!min.containsKey(name[i])) {
					System.out.println("impossible");
					continue loop;
				}
				sum += min.get(name[i]);
			}
			int[][] dp = new int[n + 1][1 << q];
			for (int[] dp1 : dp)
				Arrays.fill(dp1, 1 << 20);
			PriorityQueue<Point> pq = new PriorityQueue<Point>();
			pq.offer(new Point(0, 0, 0));
			int ans = 0;
			while (!pq.isEmpty()) {
				Point p = pq.poll();
				int t = p.t;
				int cost = p.cost;
				int bit = p.bit;
				if (t == 0 && bit == (1 << q) - 1) {
					ans = cost;
					break;
				}
				if (dp[t][bit] < cost)
					continue;
				dp[t][bit] = cost;
				if (t > 0)
					for (int i = 0; i < q; i++)
						if (supers[t - 1].containsKey(name[i])
								&& supers[t - 1].get(name[i]).equals(
										min.get(name[i])))
							bit |= 1 << i;
				for (int i = 0; i < n + 1; i++) {
					if (ad[t][i] == 0)
						continue;
					pq.offer(new Point(i, cost + ad[t][i], bit));

				}
			}
			System.out.println(sum + " " + ans);
		}
	}

	class Point implements Comparable<Point> {
		int t, cost, bit;

		@Override
		public String toString() {
			return "Point [t=" + t + ", cost=" + cost + ", bit=" + bit + "]";
		}

		public Point(int t, int cost, int bit) {
			super();
			this.t = t;
			this.cost = cost;
			this.bit = bit;
		}

		public Point(int t, int cost) {
			super();
			this.t = t;
			this.cost = cost;
		}

		@Override
		public int compareTo(Point o) {
			if (cost == o.cost)
				return o.bit - bit;
			return cost - o.cost;
		}
	}
}

Measured memory_bytes: 28376
#include<stdio.h>

void s(int x,int y);
void m(int x,int y);
void l(int x,int y);


int f[10][10];


int main(void){
int i,j,x,y,c,d,max;

for(i=0;i<10;i++){
	for(j=0;j<10;j++){
		f[i][j]=0;
	}
}
while(scanf("%d,%d,%d",&x,&y,&d)!= EOF){
switch(d){
case 1:s(x,y);break;
case 2:m(x,y);break;
case 3:l(x,y);break;
	}
}
c=0;max=f[0][0];
for(i=0;i<10;i++){
	for(j=0;j<10;j++){
			if(f[i][j]==0){c++;};
			if(max<=f[i][j]){max=f[i][j];}
	}
}
printf("%d\n%d\n",c,max);

	return 0;
}

void s(int x,int y){
	f[x][y]=f[x][y]+1;
	if(x>=1){f[x-1][y]=f[x-1][y]+1;}
	if(x<=8){f[x+1][y]=f[x+1][y]+1;}
	if(y>=1){f[x][y-1]=f[x][y-1]+1;}
	if(y<=8){f[x][y+1]=f[x][y+1]+1;}
}

void m(int x,int y){
	s(x,y);
	if(x>=1&&y>=1){f[x-1][y-1]=f[x-1][y-1]+1;}
	if(x<=8&&y>=1){f[x+1][y-1]=f[x+1][y-1]+1;}
	if(x>=1&&y<=8){f[x-1][y+1]=f[x-1][y+1]+1;}
	if(x<=8&&y<=8){f[x+1][y+1]=f[x+1][y+1]+1;}
}

void l(int x,int y){
	m(x,y);
	if(x>=2){f[x-2][y]=f[x-2][y]+1;}
	if(x<=7){f[x+2][y]=f[x+2][y]+1;}
	if(y>=2){f[x][y-2]=f[x][y-2]+1;}
	if(y<=7){f[x][y+2]=f[x][y+2]+1;}
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	int aw=100*a,as=0;
	rep(x,100)rep(y,100)rep(z,100)rep(w,100){
		int water=100*(a*x+b*y);
		int sugar=c*z+d*w;
		if(water+sugar>f) continue;
		if(sugar>(a*x+b*y)*e) continue;
		if(sugar*(aw+as)>as*(water+sugar)){
			aw=water,as=sugar;
		}
	}
	cout<<aw+as<<' '<<as<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

template <class... T>
void out(T ...a) {
  for(auto v: {a...}) {
    cout << v << " ";
  }
  cout << endl;
}

int main(){
  int in(a, b) out((a + b + 1) / 2);
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    var total = 0L
    for (x in 1..1000000) {
        if (n % x == 0L) {
            val m = n / x - 1
            if (m <= 1 ||x >= m) break
            total += m
        }
    }
    println(total)
}


Measured memory_bytes: 31580
H,W=list(map(int,input().split()))
S=[]
for h in range(H):
    S.append(list(input()))

for h in range(H):
    for w in range(W):
        count=0
        if S[h][w]=='#':
            continue
        # left_up
        if w!=0 and h!=0 and S[h-1][w-1]=='#':
            count+=1
        # Left
        if w!=0 and S[h][w-1]=='#':
            count+=1
        # Left_down
        if w!=0 and h!=H-1 and S[h+1][w-1]=='#':
            count+=1
        # Up
        if h!=0 and S[h-1][w]=='#':
            count+=1
        # Right_up
        if h!=0 and w!=W-1 and S[h-1][w+1]=='#':
            count+=1
        # Right
        if w!=W-1 and S[h][w+1]=='#':
            count+=1
        # Right_down
        if w!=W-1 and h!=H-1 and S[h+1][w+1]=='#':
            count+=1
        # Down
        if h!=H-1 and S[h+1][w]=='#':
            count+=1
        
        S[h][w]=str(count)

for h in range(H):
    print("".join(S[h]))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>

using cd = complex<double>;
const double PI = acos(-1);

void fft(vector<cd> &a, bool invert)
{
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++)
    {
        a0[i] = a[2 * i];
        a1[i] = a[2 * i + 1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++)
    {
        a[i] = a0[i] + w * a1[i];
        a[i + n / 2] = a0[i] - w * a1[i];
        if (invert)
        {
            a[i] /= 2;
            a[i + n / 2] /= 2;
        }
        w *= wn;
    }
}

vector<long long> multiply(vector<long long int> const &a, vector<long long int> const &b)
{
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<long long int> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

const int N = 1e+5 + 5;
int n;
long long int m;
long long int a[N];

int main()
{
    cin >> n >> m;
    int t = 0, g = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> t;
        a[t]++;
        g = max(t, g);
    }
    vector<long long int> A, B;
    for (int i = 0; i <= g; i++)
    {
        A.push_back(a[i]);
        B.push_back(a[i]);
    }
    vector<long long int> C = multiply(A, B);
    long long int ans = 0;
    long long int i = 0;
    for (long long int j = C.size() - 1; j >= 0; j--)
    {
        i += C[j];
        if (i >= m)
        {
            ans += j * max(C[j]-(i-m), 0LL);
            break;
        }
        ans += (j)*C[j];
        // j++;
    }
    cout << ans;
}

Measured memory_bytes: 20268
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll a,b,c;

int main(){
	cin>>a>>b>>c;
	if(c-a-b>0&&4*a*b<(c-a-b)*(c-a-b)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int mod=998244353;
const int N=300005;
char ch[N];
ll ans=1,dp[8];
map<char,int> M;
ll ksm(ll a,int b){
	int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
int main(){
	M['R']=0; M['G']=1; M['B']=2;
	int n=read();
	scanf("%s",ch+1);
	dp[0]=1;
	For(i,1,3*n){
		int x=M[ch[i]];
		Rep(j,6,0)if(dp[j]&&(j&(1<<x))==0){
			ans=ans*dp[j]%mod;
			if(j)dp[j]--; dp[j|(1<<x)]++;
			break;
		}
	}
	For(i,1,n)ans=ans*i%mod;
	cout<<ans<<endl;
}
/*
RGRBGB

*/

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  cout << min(B / A, C) << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int main () {
	ll a[5], i, n;
	ll m = 1;
	ll ret;
	
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] ;
	
	for ( i = 0 ; i < 5 ; i++ ) {
		if ( a[i] != i+ 1 ) {
			cout << i+ 1 << endl;
			return 0;
		}
	}
		
	return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 100
#define INF (1<<21)

int n, stage[MAX][MAX];

void dijkstra(){
  int i, minv;
  int mincost[MAX], flag[MAX];

  for(i = 0; i < n; i++){
    mincost[i] = INF;
    flag[i] = 0;
  }

  mincost[0] = 0;
  flag[0] = 1;

  while(1){
    minv = INF;
    int u = -1;
    for(i = 0; i < n; i++){
      if(minv > mincost[i] && flag[i] != 2){
	u = i;
	minv = mincost[i];
      }
    }
    if(u == -1) break;
    flag[u] = 2;
    for(i = 0; i < n; i++){
      if(flag[i] != 2 && stage[u][i] != INF){
	if(mincost[i] > mincost[u] + stage[u][i]){
	  mincost[i] = mincost[u] + stage[u][i];
	  flag[i] = 1;
	}
      }
    }
  }
  for(i = 0; i < n; i++){
    if(mincost[i] == INF) printf("%d %d\n", i, -1);
    else printf("%d %d\n", i, mincost[i]);
  }
}

int main(){
  int i, j;
  int k, c, u, v;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      stage[i][j] = INF;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d %d", &u, &k);
    for(j= 0; j < k; j++){
      scanf("%d %d", &v, &c);
      stage[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 2052
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def fctr1(n):
    f = list()
    r = int((n+1)**0.5)
    for i in range(2, r+1):
        if n % i == 0:
            c = 0
            while n % i == 0:
                c += 1
                n //= i
            f.append((i, c))
    if n > 1:
        f.append((n, 1))
    return f

n = ni()
l = fctr1(n)
res = 0
for x, c in l:
    t = 1
    while (t + 1) * (t + 2) // 2 <= c:
        t += 1
    res += t
print(res)


Measured memory_bytes: 9496
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //Compute c1 = new Compute();//calc

        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();

        //input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long b[]=new long[n-1];
        for (int i=0;i<n-1;++i) b[i]=sc.nextLong();

        long ans[]=new long[n];
        for (int i=n-1;i>0;--i)
        {
            if (i==n-1)
            {
                ans[i]=b[i-1];
            }else
            {
                if (b[i-1]>b[i])
                {
                    long tmp= Math.min(b[i-1],b[i]);
                    ans[i]=tmp;
                }else
                {
                    long tmp=Math.min(b[i-1],b[i]);
                    ans[i]=tmp;
                }
            }
        }

        ans[0]=Math.max(ans[1],b[0]);

        //System.out.println(Arrays.toString(ans));
        long aa=0;
        for (int i=0;i<ans.length;++i)
        {
            aa+=ans[i];
        }
        System.out.println(aa);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int m=1e9+7;
using ll=long long;
void rec(vector<int>&seg,vector<int>v,int pos,int tl,int tr){
     if(tl==tr){
         seg[pos]=v[tl];
         return ;
     }
     int mid=(tl+tr)/2;
     rec(seg,v,2*pos+1,tl,mid);
     rec(seg,v,2*pos+2,mid+1,tr);
     seg[pos]=seg[2*pos+1]+seg[2*pos+2];
     // cout<<pos<<" "<<seg[pos]<<endl;
}
int find(vector<int>&seg,int pos,int tl,int tr,int l,int r){
     // cout<<tl<<" "<<tr<<" "<<l<<" "<<r<<endl;
     if(l>r){
          return 0;
     }
     if(l==tl&&r==tr){
          return seg[pos];
     }
     int mid=(tl+tr)/2;
     return find(seg,2*pos+1,tl,mid,l,min(r,mid))
               +find(seg,2*pos+2,mid+1,tr,max(mid+1,l),r);
}
int main(){
     int n,k;
     cin>>n>>k;
     vector<int>a(n,0);
     bool dp[k+1][2];
     for(int i=0;i<=k;i++){
          dp[i][0]=false;
          dp[i][1]=false;
     }
     for(int i=0;i<n;i++){
          cin>>a[i];
          dp[a[i]][0]=true;
          dp[a[i]][1]=true;
          // cout<<dp[a[i]][1]<<endl;
     }
     
     
     for(int i=1;i<=k;i++){
          for(int j=0;j<n;j++){
               dp[i][0]=dp[i][0]||((i-a[j]>=0)?(!(dp[i-a[j]][1])):false);
               dp[i][1]=dp[i][1]||((i-a[j])>=0?(!(dp[i-a[j]][0])):false);
               
          }
          // cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<i<<" "<<endl;
          
     }
     if(dp[k][0]){
          cout<<"First"<<endl;
          return 0;
     }
     cout<<"Second"<<endl;
     
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
 
using namespace std;
 
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
 
typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;
 
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}
 
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}
 
mt19937 rnd(time(NULL));
 
const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);
 
const int N = 100 * 1000 + 13;
 
int n, m;
vector<int> g[N];
 
bool read () {
	if (scanf("%d%d", &n, &m) != 2)
		return false;
	forn(i, n)
		g[i].clear();
	forn(i, m){
		int v, u;
		scanf("%d%d", &v, &u);
		--v, --u;
		g[v].pb(u);
		g[u].pb(v);
	}
	return true;
}
 
int used[N];
vector<pair<int, pt>> ans;
vector<int> q[N];
 
void dfs(int v, int p) {
	used[v] = 1;
	for (int to : g[v]) {
		if (to == p) continue;
		if (used[to] == 1) q[v].pb(to);
		else if (used[to] == 0) dfs(to, v);
	}
	while (sz(q[v]) > 1) {
		int u1 = q[v].back();
		q[v].pop_back();
		int u2 = q[v].back();
		q[v].pop_back();
		ans.pb(mp(u1, mp(v, u2)));
	}
	if (sz(q[v]) == 1 && p != -1) {
		ans.pb(mp(p, mp(v, q[v].back())));
	} else if (p != -1) {
		q[p].pb(v);
	}	
	used[v] = 2;
}
 
void solve() {
    if (m % 2) {
        printf("-1\n");
        return;
    }
	ans.clear();
	memset(used, 0, sizeof(used));
	forn(i, n) q[i].clear();
	forn(i, n) if (used[i] == 0)
		dfs(i, -1);
    if (sz(ans) != m / 2) {
        printf("-1\n");
        return;
    }
	forn(i, sz(ans)) {
        printf("%d %d\n", ans[i].y.x + 1, ans[i].x + 1);
        printf("%d %d\n", ans[i].y.x + 1, ans[i].y.y + 1);
    }
}
 
int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
    	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;
 
#ifdef _DEBUG
	while(read()) {	
#else
	if (read()){
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif
 
	}
}


Measured memory_bytes: 17976
import numpy as np
 
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
ans=0
for i in range(N):
    A = np.array(list(map(int, input().split())))
    if sum(A*B)+C>0:
        ans=ans+1
print(ans)

Measured memory_bytes: 12504
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b = inpl()
if b%a == 0:
    print(a+b)
else:
    print(b-a)

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

int main()
{
    int N, M, ac_num=0, wa_num=0;
    cin >> N >> M;
    vector<int> ac(200000);
    vector<int> wa(200000);
    for (int i = 0; i < 200000;i++){
        ac.at(i) = 0;
        wa.at(i) = 0;
    }
    for (int i = 0; i < M;i++){
        int p;
        string s;
        cin >> p >> s;
        if(ac.at(p)==1){
            continue;
        }
        if(s=="AC"){
            ac.at(p) = 1;
            ac_num++;
            wa_num += wa.at(p);
        }
        else if(s=="WA"){
            wa.at(p)++;
            
        }
    }
    cout << ac_num << " " << wa_num << endl;
}

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

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

	ll  N;
	ll a[4];
	for(int i = 0; i < 4; i++) {
		cin >> a[i];
	}
	cin >> N;
	N *= 4;

	ll ans = 1LL << 60;
	for(int i = 1; i < 1 << 4; i++) {
		ll rem = N, sum = 0;
		for(int j = 3; j >= 0; j--) {
			if((i >> j & 1) == 0) continue;
			ll t = rem / (1 << j);
			sum += t * a[j];
			rem -= t * (1 << j);
		}
		if(rem == 0) ans = min(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int a,b;
    cin>>a>>b;
    int cnt=0, soc=1;
    while(soc<b){
        soc--;
        soc += a;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a, n,b, s=1,k=0;

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

    for(int i=n-1; i>=1; i--)
    {
        for(int j=0; j<=i-1; j++)
        {
            if(ar[i]>=ar[j])
            {
                continue;
            }
            k++;
            break;
        }
        if(k==0)
        {
            s++;

        }
        else{
            k=0;
        }

    }
    cout<<s<<endl;
}


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

vector<vector<int>> T;
vector<long> v;

void in(long k) {
	if (k == -1)
		return;
	else {
		in(T[k][0]);
		cout << " " << v[k];
		in(T[k][1]);
		return;
	}
}

void pre(long k) {
	if (k == -1)
		return;
	else {
		cout << " " << v[k];
		pre(T[k][0]);
		pre(T[k][1]);
		return;
	}
}

int main()
{
	string s;
	long n = 0, t = 0;

	cin >> n;

	T.assign(n, { -1, -1});
	v.assign(n, -2000000001);

	for (long i = 0; i < n; i++) {
		cin >> s;

		if (s == "insert") {
			cin >> v[t];

			long y = -1, x = 0;

			while (x != -1) {
				int m = 1;
				y = x;
				if (v[t] < v[x])
					m = 0;
				x = T[x][m];
			}

			int s = 1;

			if (i > 0 && y != -1) {
				if (v[t] < v[y])
					s = 0;
				T[y][s] = t;
			}
			t++;
		}
		else if (s == "print") {
			in(0);
			cout << endl;
			pre(0);
			cout << endl;
		}
		else if (s == "find") {
			long w = 0;
			cin >> w;
			
			long x = 0;

			while (x != -1) {
				int m = 1;
				if (w == v[x])
					break;
				else if (w < v[x])
					m = 0;
				x = T[x][m];
			}

			if(x != -1)
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 33860
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type DisjointSet struct {
	rank []int
	P    []int
}

func newDisjointSet(size int) *DisjointSet {
	rank := make([]int, size)
	P := make([]int, size)
	dj := &DisjointSet{rank, P}
	dj.initDisjointSet()
	return dj
}

func (dj *DisjointSet) initDisjointSet() {
	for i := 0; i < len(dj.P); i++ {
		dj.makeSet(i)
	}
}

func (dj *DisjointSet) makeSet(x int) {
	dj.P[x] = x
	dj.rank[x] = 0
}

func (dj *DisjointSet) same(x, y int) bool {
	return dj.findSet(x) == dj.findSet(y)
}

func (dj *DisjointSet) findSet(x int) int {
	if x != dj.P[x] {
		dj.P[x] = dj.findSet(dj.P[x])
	}
	return dj.P[x]
}

func (dj *DisjointSet) unite(x, y int) {
	dj.link(dj.findSet(x), dj.findSet(y))
}

func (dj *DisjointSet) link(x, y int) {
	if dj.rank[x] > dj.rank[y] {
		dj.P[y] = x
	} else {
		dj.P[x] = y
		if dj.rank[x] == dj.rank[y] {
			dj.rank[y]++
		}
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)
	q := nextInt(sc)

	dj := newDisjointSet(n)

	for i := 0; i < q; i++ {
		c := nextInt(sc)
		x := nextInt(sc)
		y := nextInt(sc)

		if c == 0 {
			dj.unite(x, y)
		} else {
			if same := dj.same(x, y); same {
				fmt.Println(1)
			} else {
				fmt.Println(0)
			}
		}
	}
}



Measured memory_bytes: 2372
import math
from decimal import *

arr = []
n = int(input())
for _ in range(n):
    arr.append(list(map(int, input().split())))
dp = [[0 for i in range(3)] for i in range(n)]
dp[0][0] = arr[0][0]
dp[0][1] = arr[0][1]
dp[0][2] = arr[0][2]
for i in range(1, n):
    for j in range(3):
        for x in range(3):
            if(x!= j):
                dp[i][j] = max(arr[i][j]+ dp[i-1][x], dp[i][j])
ans = max(dp[n-1][0], dp[n-1][1], dp[n-1][2])
print(ans)

Measured memory_bytes: 107624
n,y=map(int,input().split())
y=y/1000
b=y//10
D=[]
for i in range(int(b+1)):
	for z in range(int(((y-10*i)//5)+1)):
		if 4*z+9*i==y-n and n-z-i>=0:
			print(str(i)+" "+str(z)+" "+str(n-z-i))		
			exit()
            
		
if len(D)==0:
	print("-1 -1 -1")
else:
	print(D[0])


Measured memory_bytes: 3060
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let k = Scanf.scanf "%d\n" (fun k -> k) in
  Array.make n (fun x -> min (2 * x) (x + k))
  |> Array.fold_left (fun x f -> f x) 1
  |> Printf.printf "%d\n"

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

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

    rep(i,s.size()) {
        s[i] = (s[i] - 'A' + n) % 26 + 'A';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////
ll a[100005];
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      ll n,m;
      cin>>n>>m;
      ll lmin,rmin;
      cin>>lmin>>rmin;
      for(int i=2;i<=m;i++)
      {
          ll l,r;
          cin>>l>>r;
          if((l<lmin && r<lmin) || (l>rmin && r>rmin))
          return cout<<0,0;
            lmin=max(lmin,l);
            rmin=min(r,rmin);
      }
      cout<<rmin-lmin+1;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int input, hour, minutes, second, hour2, minutes2;
	scanf("%d",&input);

	hour = input / 3600;
	hour2 = input % 3600;
	minutes = hour2 / 60;
	minutes2 = hour2 % 60;
	second = minutes2;
	printf("%d:%d:%d\n", hour, minutes, second);
	return 0;

}

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

const int N = 2e5 + 10;
#define LL long long
const LL Mod = 998244353;
int n, k;
LL f[N];
LL sum[N];
int l[N], r[N];
LL calc(int i, int j) {
    int s = std::max(1, i - r[j]);
    int t = std::max(0, i - l[j]);
    //std::cout<<s<<' '<<t<<'\n';
    return (sum[t] - sum[s - 1]) % Mod;
}
int main() {
    std::cin >> n >> k;
    for (int i = 1; i <= k; ++i) {
        std::cin >> l[i] >> r[i];
    }
    f[1] = 1;
    sum[1] = 1;
    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= k; ++j) {
            f[i] += calc(i, j);
            f[i]%=Mod;
        }
        //std::cout<<f[i]<<"sadf\n";
        sum[i] = (sum[i - 1] + f[i]) % Mod;
    }
    std::cout << (f[n] + Mod) % Mod << '\n';
    return 0;
}

Measured memory_bytes: 6768
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
const int INF = 1001001001;
 
int a[12][12];
 
int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }
 
  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    string s;
    cin>>s;
    if(s.length() == 2) cout<<s;
    else{
        reverse(all(s));
        cout<<s;
    }
    return 0;
}

Measured memory_bytes: 768
n,m = map(int,input().split())

a = [0] * (n+2)
dp = [0] * (n+2)
mod = 1000000007

for i in range(m):
	num = int(input())
	a[num] = 1

dp[0]=1

for i in range(0,n):
	if a[i] == 1:
		continue
	dp[i] = dp[i]%mod
	dp[i+1] += dp[i]
	dp[i+2] += dp[i]

print(dp[n]%mod)

Measured memory_bytes: 13580
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(ll factor[],ll n){
    ll a = 2;
    bool flag = false;
    for(int p = 2;p*p <= n;p++){
        while(n%p == 0){
            n/=p;
            factor[p]++;
        }
    }
    if(n!=1)  factor[n]++; //prime num
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

void solve(void){
    int n;
    cin >> n;
    int a[n],b[n];
    int ans=0;
    rep(i,0,n) cin >> a[i];
    rep(i,0,n){
        cin >> b[i];
        ans += max(0,a[i]-b[i]); 
    }
    cout << ans <<endl;


    
}

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<string, int> mp;
#define ll long long

int main() {
    int n;
    int a[100];
  cin>>n;
    int c = 0;
    int ans = 0;
    bool jg=false;
    int cc;
    rep(i, n) {
        cin >> a[i];
        ans += a[i];
       
    }
  sort(a,a+n);
  rep(i,n){
     if (a[i] % 2 == 1 && jg == false) {
            cc = a[i];
            jg = true;
        }
  }

    if (ans % 2 == 0)cout << ans / 2 << endl;
    else cout << (ans - cc) / 2 << endl;
    return 0;
}


Measured memory_bytes: 3148
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

using namespace std;

int main(){
	int i, j, k;
	string s;

	cin >> s;

	if (s.length() == 2) {
		cout << s << endl;
	}
	else if(s.length()==3){
		cout << s[2] << s[1] << s[0] << endl;
	}




	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define print(x) cout << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s, t;
  cin >> s >> t;
  vi is[26];
  int n = sz(s);
  rep(i, n) is[s[i] - 'a'].push_back(i);
  rep(i, n) is[s[i] - 'a'].push_back(i + n);
  int m = sz(t);
  ll ans = 0, j = 0;
  rep(i, m) {
    if (!sz(is[t[i] - 'a'])) {
      cout << -1 << endl;
      return 0;
    }
    j = *lower_bound(rng(is[t[i] - 'a']), j) + 1;
	if(j >=n){
		j -=n;
		ans+=n;
	}
  }
  ans+=  j;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4644
#include <iostream>
#include <queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while (!q.empty()) {
        u = q.front(); q.pop();
        for (int v = 0; v < n; v++) {
            if (M[u][v] == 0) continue;
            if (d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}

int main() {
    int u, k, v;

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

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    bfs(0);

    return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<math.h>
using namespace std;

bool judge(int n){
    if(n==2) return true;
    for(int i=2;i<int(sqrt(n))+1;i++){
        if(0==n%i) return false;
    }
    return true;
}

int main(){
    int n,i,k=0;
    int ans=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>k;
        ans+=judge(k);
    }
    cout<<ans<<endl;
    return 0;
}



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

const int N = 105;

int n;
int b[N], a[N];

int main() {
 	cin >> n;
 	for (int i = 1; i < n; i++) cin >> b[i];
 	int ans = b[1];
 	a[1] = b[1];
 	for (int i = 2; i < n; i++) {
 		a[i] = min(b[i], b[i - 1]);
 		ans += a[i];
	}
	a[n] = b[n - 1];
	ans += a[n];
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  int n, y;
  cin >> n >> y;
  for(int i = 0; i <= n; i++){
    for(int k = 0; k <= n; k++){
      if(i + k > n) break;
      int s = n - i - k;
      if(i * 10000 + k * 5000 + s * 1000 == y){
        cout << i << " " << k << " " << s << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 256
def solve(n, l):
    target = sum([l + i for i in range(n)])
    best = 10**10
    ans = 0
    for i in range(n):
        d = abs(l + i)
        if best > d:
            best = d
            ans = target - l - i
    return ans

n, l = map(int, input().split())
print(solve(n, l))

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

using namespace std;
typedef long long ll;

ll n, a, b;
vector<ll> h;

bool solve(ll m) {
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if (h[i] <= b * m) continue;
        cnt += (h[i] - b * m + a - b - 1) / (a - b);
    }
    return cnt <= m;
}

int main(void) {
    cin >> n >> a >> b;
    h.resize(n);

    ll maxh = -1;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        maxh = max(maxh, h[i]);
    }
    
    ll l = 0, r = (maxh + b - 1) / b + 1;
    while (l < r) {
        ll m = (l + r) / 2;
        if (solve(m)) r = m;
        else l = m + 1;
    }
    cout << l << endl;

    return 0;
}

Measured memory_bytes: 1024
x = input()
n = int(x)

s = ''
for i in range(1, n+1):
    x = i
    if x % 3 == 0:
        s += ' ' + str(i)
    else:
        while x != 0:
            if x % 10 == 3:
                s += ' ' + str(i)
                break
            x = int(x / 10)
print(s)


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

using namespace std;

int main () {

    int n;
    cin >> n;
    vector<int> costs(n);
    vector<int> dp(n);
    for (int i = 0; i < n; ++i) {
        cin >> costs[i];
    }
    for (int i = 0; i < n; ++i) {
        if (i-1 < 0) {
            dp[i] = 0;
        } else if (i-2 < 0) {
            dp[i] = abs(costs[i]-costs[i-1]);
        } else {
            dp[i] = min(dp[i-1]+abs(costs[i]-costs[i-1]), dp[i-2]+abs(costs[i]-costs[i-2]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { 
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); // i の各桁の和
    if (sum >= A && sum <= B) { //  i の各桁の和が A 以上 B 以下かどうか
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <queue>
#include <utility>
#include <numeric>
 
using namespace std;
 
int parent[100001];
unordered_set<int> blue[100001], red[100001];
queue<pair<int, int>> q;
 
int getRoot(int x) {
	return x == parent[x] ? x : parent[x] = getRoot(parent[x]);
}
 
void print(const unordered_set<int> &m) {
	for (auto &&x: m) cerr << x << ' ';
	cerr << endl;
}
 
int main() {
	int n;
 
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		blue[a].insert(b);
		blue[b].insert(a);
	}
 
	for (int i = 1; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		red[a].insert(b);
		red[b].insert(a);
		if (blue[a].find(b) != blue[a].end())
			q.emplace(a, b);
	}
 
	iota(parent + 1, parent + n + 1, 1);
 
	int cnt = 0;
	while (!q.empty()) {
		++cnt;
 
		auto p = q.front();
		q.pop();
 
		int x = getRoot(p.first), y = getRoot(p.second);
 
		if (blue[x].size() + red[x].size() < blue[y].size() + red[y].size()) swap(x, y);
		parent[y] = x;
 
		blue[x].erase(y);
		blue[y].erase(x);
		red[x].erase(y);
		red[y].erase(x);
		
		for (auto &&dest: blue[y]) {
			if (red[x].find(dest) != red[x].end()) q.emplace(x, dest);
		}
 
		for (auto &&dest: red[y]) {
			if (blue[x].find(dest) != blue[x].end()) q.emplace(x, dest);
			red[x].insert(dest);
			red[dest].erase(y);
			red[dest].insert(x);
		}
		red[y].clear();

		for (auto &&dest: blue[y]) {
			blue[x].insert(dest);
			blue[dest].erase(y);
			blue[dest].insert(x);
		}
		blue[y].clear();
	}
 
	if (cnt == n - 1) cout << "YES" << endl; else cout << "NO" << endl;
 
	return 0;
}

Measured memory_bytes: 33816
#include<iostream>
#include<string>

using namespace std;

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

int main(){
    long int n, a, b;
    cin >> n >> a >> b;
    long int num = a + b;
    long int delta = n % num;
    long int ans;
    if (delta > a){
        ans = (n / num) * a + a;
    }else{
        ans = (n / num) * a + delta;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n,x;
  cin>>n>>x;

  vector<ll> l(n);

  rep(i,n) cin>>l[i];

  ll d=0;
  ll ans=1;

  rep(i,n){
    d+=l[i];
    if( d<=x ) ans++;
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>


int main(void) {
    int a[3] = {};
    int input1 = 0;
    int input2 = 0;
    scanf("%d", &input1);
    scanf("%d", &input2);
    a[input1-1] = 1;
    a[input2-1] = 1;
    for(int i=0; i<3; ++i) {
        if(a[i] == 0) {
            printf("%d\n", i+1);
        }
    }
    return 0;
}

Measured memory_bytes: 128