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

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ii> llii;

const int Maxn = 52;
const int Maxl = 22;
const int Maxm = Maxn * Maxl;
const ll Inf = 9000000000000000000ll;

int n;
string S[Maxn];
int C[Maxn];
int len;
ii P[Maxm];
int my[Maxn][Maxl];
ll dist[Maxm][Maxm];
priority_queue <llii> Q;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> S[i] >> C[i];
        for (int j = 0; j < S[i].length(); j++) {
            my[i][j] = len;
            P[len] = ii(i, j);
            len++;
        }
    }
    fill((ll*)dist, (ll*)dist + Maxm * Maxm, Inf);
    for (int i = 0; i < n; i++)
        for (int j = 0; j + 1 < S[i].length(); j++) if (S[i][j] == S[i][j + 1]) {
            ii v = ii(my[i][j], my[i][j + 1]);
            ll cost = C[i];
            dist[v.first][v.second] = cost;
            Q.push(llii(-cost, v));
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) if (S[i][int(S[i].length()) - 1] == S[j][0]) {
            ii v = ii(my[i][int(S[i].length()) - 1], my[j][0]);
            ll cost = C[i] + C[j];
            dist[v.first][v.second] = cost;
            Q.push(llii(-cost, v));
        }
    for (int i = 0; i < len; i++) {
        dist[i][i] = C[P[i].first];
        Q.push(llii(-C[P[i].first], ii(i, i)));
    }
    while (!Q.empty()) {
        ii v = Q.top().second;
        ll d = -Q.top().first; Q.pop();
        if (dist[v.first][v.second] != d) continue;
        if (P[v.first].second == 0 && P[v.second].second + 1 == S[P[v.second].first].length()) {
            cout << d << endl;
            return 0;
        }
        if (P[v.first].second == 0) {
            char nd = S[P[v.second].first][P[v.second].second + 1];
            for (int i = 0; i < n; i++) if (S[i][int(S[i].length()) - 1] == nd) {
                ll cand = d + C[i];
                ii u = ii(my[i][int(S[i].length()) - 1], v.second + 1);
                if (cand < dist[u.first][u.second]) {
                    dist[u.first][u.second] = cand;
                    Q.push(llii(-cand, u));
                }
            }
        } else if (P[v.second].second + 1 == S[P[v.second].first].length()) {
            char nd = S[P[v.first].first][P[v.first].second - 1];
            for (int i = 0; i < n; i++) if (S[i][0] == nd) {
                ll cand = d + C[i];
                ii u = ii(v.first - 1, my[i][0]);
                if (cand < dist[u.first][u.second]) {
                    dist[u.first][u.second] = cand;
                    Q.push(llii(-cand, u));
                }
            }
        } else {
            char nd1 = S[P[v.first].first][P[v.first].second - 1];
            char nd2 = S[P[v.second].first][P[v.second].second + 1];
            if (nd1 == nd2) {
                ii u = ii(v.first - 1, v.second + 1);
                if (d < dist[u.first][u.second]) {
                    dist[u.first][u.second] = d;
                    Q.push(llii(-d, u));
                }
            }
        }
    }
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 13896
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] arr = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            arr[i] = sc.nextInt();
            arr[i] += arr[i - 1];
        }
        Arrays.sort(arr);
        long count = 1;
        long total = 0;
        long prev = arr[0];
        for (int i = 1; i <= n; i++) {
            if (prev == arr[i]) {
                count++;
            } else {
                prev = arr[i];
                total += count * (count - 1) / 2;
                count = 1;
            }
        }
        total += count * (count - 1) / 2;
       System.out.println(total);
    }
}


Measured memory_bytes: 81340
#include<bits/stdc++.h>
#include<climits>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int              long long
#define umapii           unordered_map<int,int>
#define pqmaxi           priority_queue<int>
#define pqmini           priority_queue<int,vector<int>,greater<int>>
#define arr(type,a,n)    type* a = new type[n];
#define ff               first
#define ss               second
#define pb               push_back
#define w(t)             int t;cin>>t;while(t--)
#define popb             pop_back
#define mod              pow(10,9)+7;
#define mapii            map<int,int>
#define mp               make_pair
#define vint             vector<int>
#define presesion        fixed<<presesion(y)<<x
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>pbds;
int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	char c;
	cin >> c;
	int x = c;
	if (x >= 65 && x <= 90) {
		cout << 'A' << endl;
	} else {
		cout << 'a' << endl;
	}

}


Measured memory_bytes: 3608
use std::io;       
     
fn main() {    
    let n: u32 = read().parse().unwrap();        
    let ans = ((n - (n / 2)) as f32 / n as f32);    
    println!("{}",ans);    
}                          
                           
     
fn read() -> String{    
    let mut s = String::new();    
    io::stdin().read_line(&mut s).ok();    
    s.trim().parse().ok().unwrap()    
}    


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

int main() {
    ios::sync_with_stdio(0);cin.tie(NULL); cout.tie(NULL);
    
    
    ll x,y;
    cin>>x>>y;
    if(2*x<=y&&4*x>=y&&y%2==0)cout<<"Yes";
    else cout<<"No";
    
    
    
    return 0;
}

Measured memory_bytes: 3648
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int donuts = sc.nextInt();
    int powder = sc.nextInt();
    int count = donuts;
    int[] powderOfDonuts = new int[donuts];
    for (int i = 0; i < donuts; i++) {
      powderOfDonuts[i] = sc.nextInt();
      powder -=  powderOfDonuts[i];
    }
    Arrays.sort(powderOfDonuts);
    while(powder >= powderOfDonuts[0]) {
      powder -= powderOfDonuts[0];
      count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 22356
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long h;
	scanf("%lld",&h);
	long long i=0,j=1;
	while(h>0)
	{
		if(h==1)
		{
			i+=j;
			break;
		}
		else
		{
			h/=2;
			i+=j;
			j*=2;
		}
	} 
	printf("%lld\n",i);
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    while(n>0){
        n-=1000;
    }
    if(n<0)
        cout <<  -n << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_T = 10000;

/* typedef */

/* global variables */

int ys[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n, a, b, c, x;
    cin >> n >> a >> b >> c >> x;
    if (n == 0) break;

    for (int i = 0; i < n; i++) cin >> ys[i];
    
    int min_t = -1;
    int k = 0;
    
    for (int t = 0; t <= MAX_T; t++) {
      if (x == ys[k]) k++;
      if (k >= n) {
	min_t = t;
	break;
      }

      x = (a * x + b) % c;
    }

    cout << min_t << endl;
  }

  return 0;
}

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

int main() {
    long long t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    long long p = (a1 - b1) * t1, q = (a2 - b2) * t2;
    if (p > 0) {
        p *= -1;
        q *= -1;
    }

    if (p + q < 0) cout << 0 << endl;
    else if (p + q == 0) cout << "infinity" << endl;
    else {
        if (-p % (p + q) == 0) cout << -p / (p + q) * 2 << endl;
        else cout << 1 + -p / (p + q) * 2 << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static int dfs(int deep, int N, int M, int[] A, int Q, int[] as, int[] bs, int[] cs, int[] ds) {
		if(deep >= N) {
			int result = 0;
			
			for(int i = 0; i < Q; i++) {
				final int a = as[i];
				final int b = bs[i];
				final int c = cs[i];
				final int d = ds[i];
				
				if(A[b] - A[a] == c) {
					result += d;
				}
			}
			
			return result;
		}else {
			int answer = 0;
			for(int i = deep == 0 ? 1 : A[deep - 1]; i <= M; i++) {
				A[deep] = i;
				answer = Math.max(answer, dfs(deep + 1, N, M, A, Q, as, bs, cs, ds));
			}
			
			return answer;
		}
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			final int Q = sc.nextInt();
			
			int[] as = new int[Q];
			int[] bs = new int[Q];
			int[] cs = new int[Q];
			int[] ds = new int[Q];
			
			for(int i = 0; i < Q; i++) {
				as[i] = sc.nextInt() - 1;
				bs[i] = sc.nextInt() - 1;
				cs[i] = sc.nextInt();
				ds[i] = sc.nextInt();
			}
			
			System.out.println(dfs(0, N, M, new int[N], Q, as, bs, cs, ds));
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 34180
#深さ優先探索
N, M = map(int,input().split())
graph = [[] for j in range(N)]
for i in range(M):
  a, b = map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
judge = [False]*N
judge[0] = True

def dfs(v,judge):#vは今いる場所
  if all(judge):
    return 1
  res = 0
  for nv in graph[v]:#vと隣り合っている場所
    if judge[nv]:#すでに探索済み
      continue #if文の初めに戻る
    judge[nv] = True
    res += dfs(nv,judge)
    judge[nv] = False
  return res
print(dfs(0,judge))


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
	int H,W;
	while (1)
	{
		cin>>H>>W;
		if(H==0 && W==0)
			break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%2!=0){
			       if(j%2!=0){
					   cout<<"#";
				   }
				   else
					   cout<<".";
				}
				else{
					if(j%2==0)
						cout<<"#";
					else
						cout<<".";
				}
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s;
    cin >> s;
    int n = SZ(s);
    string t = s;
    sort(ALL(t));
    uni(t);
    if(SZ(t) == 1){
        cout << 0;
        return 0;
    }
    int ans = INT_MAX;
    for(auto &c : t){
        string res = s;
        int op = 0;
        while(1){
            string yo;
            op++;
            for(int i = 0; i + 1 < SZ(res); i++){
                char ff = res[i];
                char ss = res[i + 1];
                if(ff != c && ss != c){
                    yo += ss;
                }else{
                    yo += c;
                }
            }
            set<char> d;
            for(auto &x : yo){
                d.insert(x);
            }
            if(SZ(d) == 1){
                ans = min(ans, op);
                break;
            }
            res.clear();
            res = yo;
        }
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define ull unsigned long long
#define inf 1010000000
#define infll 1010000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define cbn(x,y) ((ll)fac[x]*inv[y]%mod*inv[(x)-(y)]%mod)
#define mod 1000000007
using namespace std;

int read(); ll readll();

int ksm(int x,ll y){
	int z=1; for (; y; y>>=1,x=(ll)x*x%mod) if (y&1) z=(ll)z*x%mod;
	return z;	
}
int gcd(int x,int y){ return y?gcd(y,x%y):x; }
int calc(int m,int n){
	ll ans=(ll)ksm(2,m)+ksm(2,n)+ksm(2,gcd(m,n))-3;
	return ans%mod;
}
int main(){
	int m,n,T;
	scanf("%d%d%d",&m,&n,&T);
	printf("%d\n",ksm(calc(m/gcd(m,T),n/gcd(n,T)),(ll)gcd(m,T)*gcd(n,T)));
	return 0;
}

int read(){
	int x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
ll readll(){
	ll x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n, m=0, s=0;
	int i;
	for(i=0;i<4;i++){
		scanf("%d", &n);
		s+=n;
	}
	m=s/60;
	s%=60;
	printf("%d\n%d\n", m, s);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>

const long long MOD = 1000000007;

int main(){
  int n,k;
  int ans=0,my=0;
  cin >> n;
  vector<P> a(n),b(n);
  vector<bool> aa(n,true);

  rep(i,n) cin >> a.at(i).first >> a.at(i).second;
  rep(i,n) cin >> b.at(i).first >> b.at(i).second;
 
  sort(b.begin(),b.end());
  
  rep(i,n){
    my=-1;
    k=-1;
    rep(j,n){
      if(aa.at(j)){
        if(a.at(j).first < b.at(i).first && a.at(j).second < b.at(i).second){
          if(a.at(j).second > my){ 
            my=a.at(j).second;
            k=j;
          }
        }
      }
    }
    if(k!=-1){
      aa.at(k)=false;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("-O2")

#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 IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 2e5 + 5;

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

int getless(ordered_set &os, int R, int index)
{
	return os.order_of_key({R, index});
}

multiset<int> minset,maxset;
int minsz=0, maxsz=0, median=0;
int minsum=0, maxsum=0;

inline int extractmax()
{
	auto val=*maxset.begin();
	maxset.erase(maxset.begin());
	maxsum-=val;
	--maxsz;
	return val;
}

inline int extractmin()
{
	auto val=*(--minset.end());
	minset.erase(--minset.end());
	minsum-=val;
	--minsz;
	return val;
}

inline void insertmax(int k)
{
	++maxsz;
	maxset.insert(k);
	maxsum+=k;
}

inline void insertmin(int k)
{
	++minsz;
	minset.insert(k);
	minsum+=k;
}

inline int mintop()
{
	assert(minsz>0);
	return *(--minset.end());
}

inline int minbottom()
{
	assert(minsz>0);
	return *minset.begin();
}

inline int maxtop()
{
	assert(maxsz>0);
	return *(--maxset.end());
}

inline int maxbottom()
{
	assert(maxsz>0);
	return *(maxset.begin());
}

inline int deletemax(int k)
{
	--maxsz;
	auto it=maxset.find(k);
	assert(it!=maxset.end());
	maxset.erase(it);
	maxsum-=k;
}

inline int deletemin(int k)
{
	--minsz;
	auto it=minset.find(k);
	assert(it!=minset.end());
	minset.erase(it);
	minsum-=k;
}

void rearrange()
{
	if(minsz<maxsz)
	{
		int k = extractmax();
		insertmin(k);
	}
	else if(minsz-maxsz <= 1) 
		return;
	else
	{
		int k=extractmin();
		insertmax(k);
	}
}

void insert(int k)
{
	if(k>median) insertmax(k);
	else insertmin(k);
	rearrange();
	median = mintop();
}

ordered_set os1;
map<int, int> m;
int ans = 0;

int32_t main()
{
	IOS;
	int q;
	cin >> q;
	while(q--)
	{
		int type;
		cin >> type;
		if(type == 1)
		{
			int a, b;
			cin >> a >> b;
			insert(a);
			os1.insert({a, m[a]++});
			ans += b;
		}
		else
		{
			int curans = ans;
			int sz = os1.size();
			pair<int, int> answer = *os1.find_by_order((sz - 1) / 2);
			cout << answer.first << " ";
			int baseans = ans;
			baseans += (maxsum + median * 1LL * (minsz-maxsz) - minsum);
			cout << baseans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 22144
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n, k;
string s;



int main()
{
	vector<int> A(3);
	rep(i, 3)
		cin >> A[i];
	cin >> k;
	int sum = A[0] + A[1] + A[2];
	rep(i, k)
	{
		sum += *max_element(all(A)); *max_element(all(A))= *max_element(all(A)) * 2;
	}

		cout <<sum << endl;
}


Measured memory_bytes: 256
//made by Sert
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 34;
const int N = (int)1e6 + 34;

typedef long long ll;

void solve() {
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b);
}

int main() {
#ifdef SERT
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    solve();
    solve();
    //solve();
    //solve();
#endif
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
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; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
 
int main(){
    int n, m;
    cin >> n >> m;
    vector<string>a(n), b(m);
    rep(i, 0, n)cin >> a[i];
    rep(i, 0, m)cin >> b[i];
    for(int i=0; i+m-1<n; i++){
        for(int j=0; j+m-1<n; j++){
            bool p = true;
            rep(k, i, i+m){
                rep(l, j, j+m){
                    if(a[k][l]!=b[k-i][l-j])p = false;
                }
            }
            if(p){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3560
N, Q = [int(_) for _ in input().split()]
S = '.' + input() + '.'
TD = [input().split() for _ in range(Q)]


def check(x):
    for t, d in TD:
        if S[x] == t:
            if d == 'L':
                x -= 1
            else:
                x += 1
    if x == 0:
        return -1
    elif x == N + 1:
        return 1
    else:
        return 0


#to_left_end
ok = 0
ng = N + 1

while ng - ok > 1:
    mid = (ok + ng) // 2
    if check(mid) == -1:
        ok = mid
    else:
        ng = mid
l = ok

#to_right_end
ok = N + 1
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if check(mid) == 1:
        ok = mid
    else:
        ng = mid
r = ng
print(r - l)

# https://img.atcoder.jp/exawizards2019/editorial.pdf


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

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

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

	long N;
	cin >> N;

	long D[N];
	rep(i,N)
		cin >> D[i];

	sort(D, D+N);

	long center = N / 2;

	cout << D[center] - D[center-1] << endl;

	return 0;
}



Measured memory_bytes: 1024
/*            AUTHOR - SHIVAM GUPTA
                       Jalpaiguri Govt. Engg College             */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<ll> ve[100005];
ll dp[3005][3005],z;
ll a[3005]={0};
const ll inf=-1e18;

ll memo(ll l, ll r)
{
    if(l==r)
    return a[l];
    if(dp[l][r]!=inf)
    return dp[l][r];
    dp[l][r]=max( a[l]-memo(l+1,r), a[r]-memo(l,r-1) );
    return dp[l][r];
}

void solve()
{
    vector<ll> v;        vector<pair <ll,ll>> vp;
    map<ll,ll> mp;       set<ll> st;        multiset<ll> mst;
    ll n=0,m=0,i=0,j=0,k=0,c=0,l=0,r=0,p=0,q=0,x=0,y=0,z=0,flag=0,sum=0;
    
    string s,t;
    cin>>n;
    for(i=0;i<n+4;i++)
        for(j=0;j<n+4;j++)
            dp[i][j]=inf;
    for(i=1;i<=n;i++)
    cin>>a[i];
    cout<<memo(1,n)<<endl;
    
}
bool imp=false;int main()
{
    fio;
    int t=1;
    if(imp)
	cin>>t;
	ll j=t;
    while(t--){
    // cout<<"Case #"<<j-t<<": ";
    solve();}
    return 0;
}

Measured memory_bytes: 73344
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
// #define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 220000;
int a[MAXN],b[MAXN],k,n;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> k;
  // n = 100000;
  // k = 100000;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    // a[i] = 0;
  }
  while(k--){
    for(int i=1;i<=n;i++){
      int l = max(1,i-a[i]);
      int r = min(n+1,i+a[i]);
      b[l]++;
      b[r+1]--;
    }
    for(int i=1;i<=n;i++){
      b[i] = b[i-1]+b[i];
    }
    int mn = n;
    for(int i=1;i<=n;i++){
      a[i] = b[i];
      mn = min(mn,a[i]);
      b[i] = 0;
    }
    if(mn>=n)break;
  }
  for(int i=1;i<=n;i++){
    cout << a[i] << " ";
  }
  cout << endl;
  
return 0;
}
///....


Measured memory_bytes: 5208
N = int(input())
D = list(map(int, input().split()))

M = max(D)
cnt = [0 for i in range(M + 1)]

for d in D:
    cnt[d] += 1

if D[0] != 0:
    print(0)
    exit()
if cnt[0] != 1 or 0 in cnt:
    print(0)
    exit()

res = 1
MOD = 998244353
for i in range(2, M + 1):
    res *= cnt[i - 1] ** cnt[i]
    res %= MOD

print(res)


Measured memory_bytes: 14396
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;
int main(void){
    const long long int mod=1000000007;
    long long int n,m,a[200005],plsum=0,misum=0,pl=0,mi=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        plsum+=a[i];
        misum+=a[i];
        if(plsum<=0&&i%2==0){pl+=1-plsum;plsum=1;}
        if(plsum>=0&&i%2==1){pl+=plsum+1;plsum=-1;}
        if(misum>=0&&i%2==0){mi+=1+misum;misum=-1;}
        if(misum<=0&&i%2==1){mi+=1-misum;misum=1;}
    }
    
    
    cout<<min(mi,pl);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_N 100000

signed main(){
	int n;
	cin >> n;
	int h[n + 2];
	REP(i,n){
		cin >> h[i];
	}
	vector<int> dp(n + 2, INF);
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

int main()
{
	int n;

	cin >> n;
	vector<int> x(n);
	vector<int> xs(n);
	for (int i = 0; i < n; i++)
	{
		cin >> x[i];
		xs[i] = x[i];
	}
	sort(xs.begin(), xs.end());

	int down = xs[n / 2 - 1];
	int up = xs[n / 2];
	for (int i = 0; i < n; i++)
	{
		if (x[i] <= down)
		{
			cout << up << endl;
		}
		else
		{
			cout << down << endl;
		}
	}

	return 0;
}


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

const int mxN = 1e4 + 5;
int dp[mxN], a[mxN], b[mxN];

int main() {
	int h, n;
	cin >> h >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i] >> b[i];
	memset(dp, 0x3F, sizeof dp);
	dp[0] = 0;
	for(int i = 1; i <= h; ++i) {
		for(int j = 1; j <= n; ++j) {
			if(a[j] > i)
				dp[i] = min(dp[i], b[j]);
			else
				dp[i] = min(b[j] + dp[i - a[j]], dp[i]);
		}
	}
	cout << dp[h];
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B;
    cin >> A >> B;

    cout << (A - B + 1) << endl;

    return 0;
}

Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,t=parseMap(split(readline()))
    time=parseMap(split(readline()))
    ans=0
    for i in 1:n-1
        ans+=min(t,time[i+1]-time[i])
    end
    println(ans+t)
end
main()

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}
template<class T>
void print_array(T a[],size_t n){
  cerr<<"array:";
  REP(n-1)cerr<<a[i]<<",";
  cerr<<a[n-1]<<endl;
}

int L;

int cnt_bit(unsigned int a){
  int res=0;
  while(a>0){a>>=1;res++;}
  return res;
}

int main(){
  ostringstream os;
  int c=0,h=0;
  cin>>L;
  L--;
  int bits=cnt_bit(L+1);
  c=bits;
  for (int i = 1; i < bits; i++) {
    os<<i<<" "<<i+1<<" "<<0<<endl;
    os<<i<<" "<<i+1<<" "<<(1<<(bits-i-1))<<endl;
    h+=2;
  }
  if(bits==cnt_bit(L)){
    L++;
    while(L!=0){
      int LL=L-(L&(-L));
      if(LL==0)break;
      os<<1<<" "<<bits+1-cnt_bit(LL^L)<<" "<<LL<<endl;
      h++;
      L=LL;
    }
  }
  cout<<c<<" "<<h<<endl;
  cout<<os.str();
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int x,n;
    cin >> x >> n;
    if(n==0){
        cout << x << endl;
        return 0;
    }
    vector<int> p(n);
    for(int i=0;i<n;i++) cin >> p[i];
    sort(p.begin(),p.end());
    for(int i=0;;i++){
        if(!binary_search(p.begin(),p.end(),x-i)){
            cout << x-i << endl;
            return 0;
        }
         if(!binary_search(p.begin(),p.end(),x+i)){
            cout << x+i << endl;
            return 0;
        }
    }
}

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

int main(int argc, char const *argv[]) {
  /* code */
  int N;
  std::cin >> N;

  if(N%2 == 0)
  {
    std::cout << N << '\n';
  }
  else{
    std::cout << N * 2 << '\n';
  }
  return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
const int N=1e5 + 5;

string s;

string substr(int i, int j)
{
	string str ="";
	int k;
	for(k=i;k<=j;k++)
	{
		str += s[k];
	}
	return str;
}

int check(string str)
{
	map<char,int> mp;
	int i;
	for(i=0;i<str.size();i++)
	{
		mp[str[i]]++;
	}
	for(i=0;i<str.size();i++)
	{
		if(mp[str[i]]>(str.size()/2))
			return 1;
	}
	return 0;
}

int32_t main()
{
	IOS;
	cin >> s;
	int n=s.size();
	int cur=2;
	int i=0;
	int j=0;
	int k=0;
	for(cur=2;cur<=min(n,5ll);cur++)
	{
		for(j=cur-1;j<n;j++)
		{
			string str= substr(j-cur+1,j);
			if(check(str)==1)
			{
				cout << j-cur+2 << " " << j+1 << endl;
				return 0;	
			}	
		}	
	}
	cout << "-1 -1 " << endl;
}


Measured memory_bytes: 512
SENTINEL = 2 ** 32
cnt = 0
def merge(A, left, mid, right):
    L = A[left:mid] + [SENTINEL]
    R = A[mid:right] + [SENTINEL]
    
    i = 0
    j = 0
    for k in range(left, right):
        global cnt
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

n = input()
A = list(map(int, input().split()))
merge_sort(A,0,len(A))
print(*A)
print(cnt)

Measured memory_bytes: 82152
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

priority_queue<Int, vector<Int>, greater<Int>> R;
priority_queue<Int> L;

int main(void) {
    int Q;
    cin>>Q;
    Int sum = 0;

    for(int i = 0;i < Q;i++) {
        int q;
        cin>>q;
        if(q == 1) { //update
            Int a,b;
            cin>>a>>b;
            sum += b;
            L.push(a);
            R.push(a);
            Int left = L.top();
            Int right = R.top();
            if(left > right) {
                L.pop();
                R.pop();
                L.push(right);
                R.push(left);
                sum += abs(left-right);
            }
        } else {
            cout<<L.top()<<" "<<sum<<endl;
        }
    }

    return 0;
}





Measured memory_bytes: 4588
eval"N,K="+`tr \\  ,`
*I=r=s=1,1
2.upto([N,K+x=y=1].min){|i|x=x*N*r%M=10**9+7
s+=x*y=y*r%M*N-=1
I<<r=M/i*-I[M%i]%M}
p s%M

Measured memory_bytes: 3728
import java.util.*;
import java.math.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int p = sc.nextInt();
    int pieces = A * 3;
    int applePie = (pieces + p ) / 2;
    System.out.println(applePie);
    


  }
}

Measured memory_bytes: 21972
x,y = map(int, input().split())

ans=0
if x==1 and y==1:
  ans+=400000

def get(i):
  if i==1:
    return 300000
  if i==2:
    return 200000
  if i==3:
    return 100000
  return 0

print(ans+get(x)+get(y))

Measured memory_bytes: 61220
def g(a, b):
    while b:
        a, b = b, a%b
    return a
n = int(input())
a = list(map(int, input().split()))
ans = a[0]*a[1]/g(a[0],a[1])
for i in a[2:]:
    ans = ans*i/g(ans,i)
print(int(ans))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
struct ufind {
    vector<int> par;
    vector<int> rank;
    vector<int> count;
    ufind(int n)
    {
        par.resize(n);
        rank.resize(n);
        count.resize(n);


        rep(i, n)
        {
            par[i] = i;
            rank[i] = 0;
            count[i] = 1;
        }
    }
    int find(int x)
    {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};
int main() {
    int n;cin >> n;
    vector<int>x(n),y(n);
    rep(i,n)cin >> x[i] >> y[i];
    map<int,map<int,bool>> b;
    rep(i,n)b[x[i]][y[i]] = true;

    map<int,vector<int>> xs;
    map<int,vector<int>> ys;
    int k = 1;
    map<lli,lli> mx,my;
    ufind uf( 2* n + 10);
    vector<vector<int>> ss(2 * n + 10);
    rep(i,n){
        xs[x[i]].push_back(i);
        ys[y[i]].push_back(i);
    }
    for(auto s:xs){
        int p = *s.second.begin();
        for(auto j:s.second){
            uf.unite(p,j);
        }
    }
    for(auto s:ys){
        int p = *s.second.begin();
        for(auto j:s.second){
            uf.unite(p,j);
        }
    }
    map<lli,pair<set<int>,set<int>> > an;
    rep(i,n){
        an[uf.find(i)].first.insert(x[i]);
        an[uf.find(i)].second.insert(y[i]);
    }
    vector<bool> f(2 * n + 10);
    vector<int> c(2 * n + 10);

    lli ans = 0;
    rep(i,n){
        c[uf.find(i)]++;
    }
    rep(i,n){
        int px = uf.find(i);
        if(f[px])continue;
        f[px] = true;
//        cout << an[px].first.size() << " " << an[px].second.size() << endl;
        ans += an[px].first.size() * an[px].second.size() - c[px];
    }
     cout << ans << endl;
}


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

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    ll h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    vector<vector<int>> vec(h, vector<int>(w,0));
    ll fi = 0;
    ll ki=0;
    
    rep(i,h){
        vector<int> pl;
        pl.push_back(-1);
        rep(j,w){if(s[i][j]=='#'){pl.push_back(j);}}
        pl[pl.size()-1] = w-1;
        rep(l,pl.size()-1){
            ki++;
            for(int wi=pl[l]+1;wi<=pl[l+1];wi++){
                for(int hi=fi;hi<=i;hi++){
                    vec[hi][wi]=ki;
                }
            }
        }
        if(pl.size()>1) fi = i+1;
    }
    if(fi>0){
        for (int i=fi;i<h;i++){
            rep(j,w){
                vec[i][j] = vec[fi-1][j];
            }
        }
    }
    
    rep(i,h){
        rep(j,w-1){
            cosp(vec[i][j]);
        }
        co(vec[i][w-1]);
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 10005;
struct E{
    int v,w,cost;
    E(int _v,int _w,int _cost)
    {
        v = _v;
        w = _w;
        cost = _cost;
    }
};

vector<E>g[maxn];
int n,m;
int dis[maxn],cost[maxn];
bool vis[maxn];
void spfa(int s)
{
    memset(dis,inf,sizeof(dis));
    memset(cost,inf,sizeof(cost));
    memset(vis,0,sizeof(vis));
    queue<int>q;
    dis[s] = 0;
    cost[s] = 0;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        vis[u]= 0;
        for(int i=0;i<(int)g[u].size();i++)
        {
            int v=g[u][i].v;
            int w=g[u][i].w;
            int c=g[u][i].cost;
            if(dis[v] > dis[u] + w)
            {
                dis[v] = dis[u] + w;
                cost[v] = c;
                if(!vis[v])
                {
                    q.push(v);
                    vis[v]=1;
                }
            }
            else if(dis[v] == dis[u] +w && cost[v]>c)
            {
                cost[v] = c;
                if(!vis[v])
                {
                    q.push(v);
                    vis[v]=1;
                }
            }
        }
    }

}
int main()
{
    while(~scanf("%d%d",&n,&m) && n)
    {
        for(int i=1;i<=n;i++) g[i].clear();
        while(m--)
        {
            int u,v,w,c;
            scanf("%d%d%d%d",&u,&v,&w,&c);
            g[u].push_back(E(v,w,c));
            g[v].push_back(E(u,w,c));
        }
        spfa(1);
        int ans=0;
        for(int i=1;i<=n;i++)
            ans+=cost[i];
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 4964
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, count = 0, i = 0;
    cin >> N;
    while(true) {
        int64_t j = i, sum = 0;
        bool T = false;
        set<int> S;
        for (int k = 0; j > 0; k++) {
            if (j % 4 == 0) {
                T = true;
                break;
            }
            int a = (j % 4) * 2 + 1;
            S.insert(j % 4);
            sum += pow(10, k) * a;
            j /= 4;

        }
        i++;
        if (T || S.size() != 3) {
            continue;
        }
        if (sum > N) {
            break;
        }
        count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#define mod 1e9+7
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a;
  vector<int> dp(1<<21);
  dp[0]=1;
  vector<vector<int>> listj(22);
  for(int k=0;k<(1<<(n));k++)
  {
    int j=0,tmp=k;
    while(tmp>0){j+=tmp%2;tmp/=2;}
    listj[j].push_back(k);
  }

  for(int i=1;i<n+1;i++)
  {
    for(int j=0;j<n;j++)
    {
      cin>>a;
      if(!a)continue;
      for(int k:listj[i-1])
      {
        if((k & (1<<j)))continue;
        int kn;
        kn=k+(1<<j);
        {
          dp[kn]+=dp[k];
          if(dp[kn]>=mod)dp[kn]-=mod;
        }
      }
    }


  }
  cout<<dp[(1<<n)-1]<<endl;

  return 0;

}


Measured memory_bytes: 18368
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n,m;
  while(true){
  cin>>n>>m;
  if(!n&&!m)break;
  vector<int> money(n);
  vector<string> bingo(n);
  vector<string> buy(m);
  for(int i=0;i<n;i++){
    cin>>bingo[i]>>money[i];
  }
  for(int i=0;i<m;i++){
    cin>>buy[i];
  }
  int sum = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      int k=0;
      for(k=0;k<8;k++){
	if(bingo[i][k]!='*' && bingo[i][k]!=buy[j][k])break;
      }
      if(k==8)
	sum+=money[i];
    }
  }
  cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 964
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int c[3][3];

int main(void)
{
    rep(i, 3)
    {
        rep(j, 3)
        {
            cin >> c[i][j];
        }
    }

    rep(i, 3)
    {
        int nx = (i + 1) % 3;

        int diff1 = c[i][0] - c[nx][0];
        int diff2 = c[i][1] - c[nx][1];
        int diff3 = c[i][2] - c[nx][2];

        if (diff1 != diff2 || diff2 != diff3 || diff3 != diff1)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    rep(i, 3)
    {
        int nx = (i + 1) % 3;

        int diff1 = c[0][i] - c[0][nx];
        int diff2 = c[1][i] - c[1][nx];
        int diff3 = c[2][i] - c[2][nx];

        if (diff1 != diff2 || diff2 != diff3 || diff3 != diff1)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import queue
while 1:
    w,h=map(int,input().split())
    if w==0:
        break
    field=[[0 for i in range(w*2-1)] for i in range(h*2-1)]
    dist=[[0 for i in range(w*2-1)] for i in range(h*2-1)]
    for i in range(h*2-1):
        if i%2==0:
            s=input().split()
            for j in range(len(s)):
                if s[j]=='1':
                    field[i][1+j*2]=1
    
        else:
            s=input().split()
            for j in range(len(s)):
                if s[j]=='1':
                    field[i][j*2]=1
    s=(0,0)
    g=(h*2-2,w*2-2)
    q=queue.Queue()
    q.put(s)
    while not q.empty():
        y,x=q.get()
        if g==(y,x):
            print(dist[g[0]][g[1]]+1)
            break
        if 0<=y+1<h*2-1 and 0<=x<w*2-1 and field[y+1][x]!=1 and dist[y+2][x]==0:
            dist[y+2][x]=dist[y][x]+1
            q.put((y+2,x))
        if 0<=y-1<h*2-1 and 0<=x<w*2-1 and field[y-1][x]!=1 and dist[y-2][x]==0:
            dist[y-2][x]=dist[y][x]+1
            q.put((y-2,x))
        if 0<=y<h*2-1 and 0<=x+1<w*2-1 and field[y][x+1]!=1 and dist[y][x+2]==0:
            dist[y][x+2]=dist[y][x]+1
            q.put((y,x+2))
        if 0<=y<h*2-1 and 0<=x-1<w*2-1 and field[y][x-1]!=1 and dist[y][x-2]==0:
            dist[y][x-2]=dist[y][x]+1
            q.put((y,x-2))
    else:
        print(0)
        
        


Measured memory_bytes: 7176
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,iimo1[201],iimo2[201],turu1[201],turu2[201],co1=0,co2=0;
    cin>>n;
    for(int i=0;i<n;i++)cin>>iimo1[i]>>iimo2[i];
    cin>>m;
    for(int i=0;i<m;i++)cin>>turu1[i]>>turu2[i];
    while(n!=co1||m!=co2){
        if(co1!=0||co2!=0)cout<<" ";
        if(iimo1[co1]>turu1[co2]||n==co1){
            cout<<turu1[co2]<<":";
            if(turu2[co2]<10)cout<<"0"<<turu2[co2];
            else cout<<turu2[co2];
            co2++;
        }
        else if(iimo1[co1]<turu1[co2]||m==co2){
            cout<<iimo1[co1]<<":";
            if(iimo2[co1]<10)cout<<"0"<<iimo2[co1];
            else cout<<iimo2[co1];
            co1++;
        }
        else if(iimo2[co1]>turu2[co2]){
            cout<<turu1[co2]<<":";
            if(turu2[co2]<10)cout<<"0"<<turu2[co2];
            else cout<<turu2[co2];
            co2++;
        }
        else if(iimo2[co1]<turu2[co2]){
            cout<<iimo1[co1]<<":";
            if(iimo2[co1]<10)cout<<"0"<<iimo2[co1];
            else cout<<iimo2[co1];
            co1++;
        }
        else{
            cout<<iimo1[co1]<<":";
            if(iimo2[co1]<10)cout<<"0"<<iimo2[co1];
            else cout<<iimo2[co1];
            co1++;
            co2++;
        }
    }
    cout<<endl;
}

Measured memory_bytes: 1168