akhauriyash/Code-Regression huggingface dataset:
import copy
def comb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
b=copy.deepcopy(a)
b.sort()
x=0
s=[]
for i in range(1,n+1):
  if b[i-1]==b[i]:
    x=b[i]
for i in range(n+1):
  if a[i]==x:
    s.append(i)
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, n + 2 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for k in range(1,n+2):
  print((comb(n+1,k,mod)-comb(n-s[1]+s[0],k-1,mod))%mod)


Measured memory_bytes: 98736
#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() {
  long N;
  cin >> N;
  map<string, int> S;
  rep(i,N){
    string s;
    cin >> s;
    S[s]++;
  }
  int mx = 0;
  for(auto p :S)
    mx=max(mx, p.second);
  for(auto p:S){
    if(p.second==mx){
      cout << p.first << endl;
    }
  }
}

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

int main(){
  string s;
  getline(cin, s);
  // cout << s.length() << endl;
  for (int i = 0; i < s.length(); i++){
    if (s[i] >= 65 && s[i] <= 90){
      s[i] += 32;
    }else if(s[i] >= 97 && s[i] <= 122){
      s[i] -= 32;
    }
    cout << s[i];
  }
  cout << endl;
}


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

int main(){

    int n,x,square=0;
    cin>>n;
    for (int i = 0; i < n; i++){
        cin >>x;
        if ( (i+1)%2 == 1 && x%2 == 1 )
            square++;
    }
    cout << square <<endl;


}

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

using namespace std;

typedef long long LL;

const int nmax = 100010; const LL mod = 1000003;

LL N,M,a[nmax*3],sol,ans;

int main(void){
   int i,j,x,y,T,lg,z,t,e;
//   freopen("txt.in","r",stdin);
//   freopen("txt.out","w",stdout);
   ios::sync_with_stdio(false);
   cin >> N;
   for(i = 1; i <= N*3; ++i)
      cin >> a[i];
   sort(a+1,a+N*3+1);
   sol = N;
   for(i = 3*N-1;i-1>0&&sol;i-=2,--sol)
      ans+=a[i];
   cout << ans << '\n';
    return 0;
}


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

int main(){
    string S, T;
    cin >> S >> T;
    int A, B;
    cin >> A >> B;
    string U;
    cin >> U;

    if (S == U){
        cout << A-1 << " " << B << endl;
    } else{
        cout << A << " " << B-1 << endl;
    }
    return 0;
}


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

namespace Lsk {
#define _auto_ template <typename T>

// fast io
#define writesp(x) (write(x), putchar(' '))
#define writeln(x) (write(x), putchar('\n'))
_auto_ inline void read(T &x) {
	x = 0; bool sgn = false; char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (sgn = true), ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	if(sgn) x = -x;
}
_auto_ inline void write(T x) {
	if(x < 0) putchar('-'), x = -x;
	static char buf[40]; int o = 0;
	for(x; x > 9; x /= 10, ++o) buf[o] = x % 10 + '0'; buf[o] = x + '0';
	for(o; ~o; --o) putchar(buf[o]);
	return;
}

// cmin / cmax / swap
_auto_ inline void cmin(T &u, const T v) { if(u > v) u = v; }
_auto_ inline void cmax(T &u, const T v) { if(u < v) u = v; }
_auto_ inline T min(const T u, const T v) { return u < v ? u : v; }
_auto_ inline T max(const T u, const T v) { return u > v ? u : v; }
_auto_ inline void swap(T &u, T &v) { T tmp(u); u = v, v = tmp; }

// math
const int mod = 998244353, mod_2 = 1996488706;
//const int mod = 1000000007, mod_2 = 2000000014;
//const int mod = 1000000009, mod_2 = 2000000018;
_auto_ inline T abs(T x) { return x > 0 ? x : -x; }
_auto_ inline T gcd(T u, T v) {	return v ? gcd(v, u % v) : u; }
_auto_ inline T Mod(T u) { return u >= mod_2 ? u % mod : (u > mod ? u - mod : u); }
_auto_ inline T inmod(T u) { return u >= mod ? u - mod : (u < 0 ? u + mod : u); }
inline long long fpm(long long base, long long mi) {
	long long res = 1;
	while(mi) {
		if(mi & 1) res = Mod(res * base);
		base = Mod(base * base), mi >>= 1;
	}
	return res;
}

} using namespace Lsk;
#define N 200005
using std :: sort;

int n;
int a[N], f[N];
long long K;

inline bool check(long long mid) {
	long long res = 0;
	for(int i = 1; i <= n; ++i) {
		long long to = mid / f[i];
		if(to < a[i]) res += a[i] - to;	
	}
	return res <= K;
}

int main() {
	read(n), read(K);
	for(int i = 1; i <= n; ++i) read(a[i]);
	for(int i = 1; i <= n; ++i) read(f[i]);
	
	sort(a + 1, a + 1 + n);
	sort(f + 1, f + 1 + n, std :: greater<long long>());
	
	long long l = 0, r = 1e12, mid, minp = 1e18;
	while(l <= r) {
		mid = l + r >> 1;
		//writesp(l), writeln(r);
		if(check(mid)) {
			cmin(minp, mid);
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	
	writeln(minp);
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#include<string.h>
int a,s,d[501],f[501],g[501],h,j,i,k,q=2100000000;
char z[501][501];
int main(void)
{	
	scanf("%d %d",&a,&s);
	for(i=0;i<a;i++)	scanf("%s",z[i]);
	for(i=0;i<a;i++){
		d[i]=0;
		f[i]=0;
		g[i]=0;
	}
	for(i=0;i<a;i++){
		for(j=0;j<s;j++){
			if(z[i][j]!='W')	d[i]++;
			if(z[i][j]!='R')	f[i]++;
			if(z[i][j]!='B')	g[i]++;
		}
	//	printf("%d  %d %d %d\n",i,d[i],f[i],g[i]);
	}
	for(i=1;i<a-1;i++){
		for(j=a-1;j>1;j--){
			h=0;
			if(i<j){
				for(k=0;k<i;k++)	h+=d[k];
				for(k=i;k<j;k++)	h+=g[k];
				for(k=j;k<a;k++)	h+=f[k];
				if(q>h)	q=h;
			//		printf("%d %d\n",q,h);
			}

		}
	}
	printf("%d\n",q);
	return 0;
}

Measured memory_bytes: 2700
S = input().rstrip()
T = input().rstrip()
mn = len(T)
for i in range(len(S) - len(T) + 1):
	n = 0
	for j in range(len(T)):
		if S[i + j] != T[j]:
			n += 1

	if n < mn:
		mn = n

print(mn)


Measured memory_bytes: 9096
#include <iostream>
#define FOR0(var, max) for (ui var = 0; var < max; ++var)

using namespace std;

using ui = unsigned int;
using uc = unsigned char;

const static ui NMAX = 100;
static ui N;
static ui Bi[NMAX];

int main(int ac, char **av) {
  cin >> N;
  FOR0(i, N - 1) {
    cin >> Bi[i];
  }
  ui res = 0;
  res += Bi[0];
  FOR0(_i, N - 1) {
    ui i = _i + 1;
    res += min(Bi[i - 1], Bi[i]);
  }
  res += Bi[N - 2];
  cout << res << endl;
  return 0;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;




int main() {

	int n;
	cin >> n;

	VI a(n), b(n);
	REP(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}

	sort(ALL(b));

	VLL cnt(200005, 0);


	REP(i, n) {
		cnt[b[i]]++;
	}

	ll ans = 0;
	REP(i, n + 2) {
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}


	REP(i, n) {

	
		ll an = ans;

		an -= cnt[a[i]] * (cnt[a[i]] - 1) / 2;
		an += (cnt[a[i]] - 1)*(cnt[a[i]] - 2) / 2;
		cout << an << endl;



	}





}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char *argv[])
{
	VL a(4);
	cin >> a;
	cout << (a[0] - a[2]) * (a[1] - a[3]) << endl;
	return 0;
}


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

int main() {
  ll h,w;
  cin >> h >> w;
  ll n;
  cin >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  vector<vector<ll>> maze(h,vector<ll>(w));
  ll th=0,tw=0;
  for(ll i=0;i<n;i++) {
    while(a[i]) {
      maze[th][tw]=i+1;
      if(th%2==0) {
        if(tw<w-1) {
          tw++;
        }
        else {
          th++;
        }
      }
      else {
        if(tw>0) {
          tw--;
        }
        else {
          th++;
        }
      }
      a[i]--;
    }
  }
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      if(j!=0) {
        cout << ' ';
      }
      cout << maze[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 512
S=input()
if len(S)%2 != 0:
    print('No')
else:
    x = 0
    for i in range(len(S)):
        if i%2 == 0:
            if S[i] != 'h':
                x = x +1
        else:
            if S[i] != 'i':
                x = x+1
    if x==0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
int factorial(int n) {
	return n == 0 ? 1 : n * factorial(n - 1);
}
int main() {
	while (true) {
		int m, n, k, d; std::cin >> m >> n >> k >> d; if (m == 0 && n == 0) break;
		std::vector<int> calories(m); for (auto& c : calories) std::cin >> c;
		std::vector<std::vector<int>> distances(m + n + 2, std::vector<int>(m + n + 2, INT_MAX));
		for (auto i = 0; i < d; ++i) {
			std::string s, t; int e; std::cin >> s >> t >> e;
			int from = -1, to = -1;
			switch (s.front()) {
			case 'H': from = n + m; break;
			case 'D': from = n + m + 1; break;
			case 'C': from = std::stoi(s.substr(1)) - 1; break;
			case 'L': from = std::stoi(s.substr(1)) + m - 1; break;
			default: break;
			}
			switch (t.front()) {
			case 'H': to = n + m; break;
			case 'D': to = n + m + 1; break;
			case 'C': to = std::stoi(t.substr(1)) - 1; break;
			case 'L': to = std::stoi(t.substr(1)) + m - 1; break;
			default: break;
			}
			distances[from][to] = distances[to][from] = std::min(distances[from][to], e * k);
		}
		for (auto i = 0; i < distances.size(); ++i) distances[i][i] = 0;
		for (auto k = m; k < distances.size(); ++k) {
			for (auto i = 0; i < distances.size(); ++i) if (distances[i][k] != INT_MAX) {
				for (auto j = 0; j < distances.size(); ++j) if (distances[k][j] != INT_MAX) {
					distances[i][j] = std::min(distances[i][j], distances[i][k] + distances[k][j]);
				}
			}
		}
		int min_calory = distances[n + m][n + m + 1];
		std::vector<int> cake_shops(m); std::iota(cake_shops.begin(), cake_shops.end(), 0);
		for (auto _i = factorial(m); _i > 0; --_i) {
			int prev = n + m;
			int distance = 0;
			for (auto i = 0; i < m; ++i) if (distances[prev][cake_shops[i]] != INT_MAX) {
				distance += distances[prev][cake_shops[i]] - calories[cake_shops[i]];
				prev = cake_shops[i];
				if (distances[prev][n + m + 1] != INT_MAX) min_calory = std::min(min_calory, distance + distances[prev][n + m + 1]);
			}
			std::next_permutation(cake_shops.begin(), cake_shops.end());
		}
		std::cout << min_calory << std::endl;
	}
}



Measured memory_bytes: 3112
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	for i := 0; i < len(s); i++ {
		if s == t {
			fmt.Println("Yes")
			return
		}
		s = s[len(s)-1:] + s[:len(s)-1]
	}
	fmt.Println("No")
}


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

const ll INF = 1LL << 60;
const ll MOD = 2019;

string S;
int main() {
    cin >> S;
    reverse(S.begin(), S.end());

    map<ll, ll> mp;
    mp[0] = 1;

    ll ten = 1;
    ll num = 0;
    rep(i, S.size()) {
        ll target = S[i] - '0';
        num += target * ten;
        num %= MOD;
        mp[num]++;
        ten *= 10;
        ten %= 2019;
    }

    // 組み合わせを求める
    ll ans = 0;
    for (auto v : mp) {
        // cout << v.first << " " << v.second << endl;
        ll tmp = v.second * (v.second - 1) / 2;
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3736
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
queries = list(list(map(int, input().split())) for _ in range(Q))

dic = dict()
s = 0
for i in range(N):
    s += A[i]
    if A[i] not in dic:
        dic[A[i]] = 1
    else:
        dic[A[i]] += 1
        
for q in range(Q):
    query = queries[q]
    if query[0] in dic:
        num = dic[query[0]]
        s -= num*query[0]
        dic.pop(query[0])
        if query[1] not in dic:
            dic[query[1]] = num
        else:
            dic[query[1]] += num
        s += num*query[1]
    print(s)

Measured memory_bytes: 37380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

struct DJset {
	vi parent, rank, size;

	DJset(int n) : parent(n), rank(n, 1), size(n, 1) {
		rep(i,0,n) {
			parent[i] = i;
		}
	}

	int find(int i) {
		if(i == parent[i]) return i;
		return parent[i] = find(parent[i]);
	}

	void merge(int u, int v) {
		u = find(u); v = find(v);
		if(u == v) return;
		if(rank[u] > rank[v]) swap(u, v);
		parent[u] = v;
		if(rank[u] == rank[v]) ++rank[v];
		size[v] += size[u];
	}
};

// 

const int INF = 1000000050;
int n;
vi l;
vi r;
vector<pii> v;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	l.resize(n); 
	r.resize(n);
	v.resize(n);
	rep(i,0,n) {
		cin >> l[i] >> r[i];
		r[i]++;
	}

	int p = -1;
	int pidx;
	int q = 1000000001;
	int qidx;

	rep(i,0,n) {
		if(l[i] > p) {
			p = l[i];
			pidx = i;
		}
		if(r[i] < q) {
			q = r[i];
			qidx = i;
		}
	}

	int ret = 0;
	rep(i,0,n) {
		if(i == pidx || i == qidx) {
			continue;
		}
		if(r[i] - l[i] > ret) {
			ret = r[i] - l[i];
		}
	}

	ret += max(0, q - p);

	rep(i,0,n) {
		int a = max(r[i] - p, 0);
		int b = max(q - l[i], 0);
		v[i] = mp(a, -b);
	}
	sort(all(v));

	int w = INF;
	rep(i,0,n) {
		if(i) {
			ret = max(ret, w + v[i].F);
		}
		w = min(w, -v[i].S);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1792
n=int(input())
#l=[]
j=0
for i in range(n):
    #l.append(list(map(int,input().split())))
    #一旦全部受け取ってから操作しなくてもよい
    #読み取るー操作をした方が処理量も少なくて済む
    l=list(map(int,input().split()))
    if l[1]+l[2]>l[0] or (l[0]+l[1]+l[2])%2!=0:
        print("No")
        j=1
        break
if j==0:
    print("Yes")    

Measured memory_bytes: 3060
import java.io.*;
import java.util.StringTokenizer;

import java.util.Arrays;
public class Main {

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();
        long K = fs.nextLong();
        int[] A = new int[N];

        for (int i = 0;i < N; ++i) {
            A[i] = fs.nextInt() - 1;
        }


        boolean[] visited = new boolean[N];
        int[] lengths = new int[N];
        Pair p = dfs(0, lengths, visited, A);

        int lengthToStart = lengths[p.a];
        int cycleStart = p.a;
        int cycleLength = p.b;

//        System.out.println(lengthToStart);
//        System.out.println(cycleStart);
//        System.out.println(cycleLength);

        if (K > lengthToStart) {
            K -= lengthToStart;
            K = K % cycleLength;
            K += lengthToStart;
        }

        Arrays.fill(visited, false);
        System.out.println(traverse(K, A, visited, 0) + 1);

    }

    private static int traverse(long steps, int[] A, boolean[] visited, int start) {
        if (steps == 0) {
            return start;
        }

        if (visited[start]) {
            return -1;
        }

        visited[start] = true;
        return traverse(steps - 1, A, visited, A[start]);
    }

    private static Pair dfs(int start, int[] lengths, boolean[] visited, int[] a) {
        visited[start] = true;

        if (visited[a[start]]) {
            return new Pair(a[start], lengths[start] - lengths[a[start]] + 1);
        }

        lengths[a[start]] = lengths[start] + 1;

        return dfs(a[start], lengths, visited, a);
    }

    private static class Pair {
        int a;
        int b;

        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
    }
}


Measured memory_bytes: 72352
#!/usr/bin/env python3

num = int(input())
alf = ['a','b','c','d','e','f','g','h','i','j','k']
def dfs(s, mx_idx):
    if len(s) == num:
        print(s)
        return
    for i in range(mx_idx+1):
        if i == mx_idx:
            dfs(s+alf[i], mx_idx+1)
        else:
            dfs(s+alf[i], mx_idx)

dfs('', 0)

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
struct MyException : exception {};

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  auto getHeight = [&](int& i) -> int {
    int j = i + 1;
    while (j < N && A.at(j-1) + 1 == A.at(j)) j++;
    if (j < N && A.at(j) > A.at(j-1) + 1) throw MyException();
    i = j;
    return A.at(j-1);
  };

  ll ans = 0;
  try {
    if (A.at(0) > 0) throw MyException();
    int i = 0;
    while (i < N) {
      ll h = getHeight(i);
      ans += h;
    }
  } catch (MyException& e) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    ll a[328] = {}, d[328][328] = {}, z = 328ll * mod;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) d[i][j] = 328ll * mod;
    d[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            for (int l = i - 1; l >= 0 && j - i + l + 1 >= 0; l--) {
                d[i][j] = min(d[i][j], d[l][j - i + l + 1] + max(0ll, a[i] - a[l]));
            }
        }
    }
    for (int i = 0; i <= n; i++) {
        //for (int j = 0; j <= i; j++) cout << d[i][j] << ' '; cout << '\n';
    }
    for (int i = 0; i <= n; i++) if (k - n + i >= 0) z = min(z, d[i][k - n + i]);
    cout << z;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    REP(i, n - 2) {
        if (s.at(i) == 'A' && s.at(i + 1) == 'B' && s.at(i + 2) == 'C') ans++;
    }
    MSG(ans)
}


Measured memory_bytes: 256
<?php
  $s = trim(fgets(STDIN));
  $count = 0;
  for($i=0; $i<strlen($s)-1; $i++){
    if($s[$i] == $s[$i+1]){
      if($s[$i+1]){
        $s[$i+1] = 0;
      }else{
        $s[$i+1] = 1;
      }
      $count++;
    }  
  }
  echo $count."\n";

Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a /g* b ;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
int  GetDigit(T num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};


int main()
{
    int N, K;
    cin >> N >> K;
    vector<vector<int> > h(N);

    int M = N * (N - 1) / 2 - K;
    if(M<N-1){
        cout << -1 << endl;
    }else{
        int idx = 1;
        cout << M << endl;
        REP(idx, 1, N)
        {
            REP(j,idx+1,N+1){
                cout << idx << " " << j << endl;
                M--;
                if(M==0){
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 100010;

struct Node {
	ll d; int id;
	
	Node() {}
	Node(ll d, int x):d(d), id(x) {}

	friend bool operator < (Node a, Node b) { return a.d < b.d; }
}d[MAXN];

int sz[MAXN];
int u[MAXN];
int v[MAXN];

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri;
	for(int i = 1; i <= n; i++) d[i] = Node(rl, i), sz[i] = 1;
	sort(d + 1, d + 1 + n);
	ll dis = 0, N = 0;
	for(int i = n; i > 1; i--) {
		int p = lower_bound(d + 1, d + 1 + n, Node(d[i].d - n + (sz[i] << 1), 0)) - d;
		if(d[p].d != d[i].d - n + (sz[i] << 1)) return puts("-1"), 0;
		sz[p] += sz[i], ++N, u[N] = d[i].id, v[N] = d[p].id, dis += sz[i];
	}
	if(dis != d[1].d) puts("-1");
	else
		for(int i = 1; i <= N; i++)
			printf("%d %d\n", u[i], v[i]);
	return 0;
}

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

// headers {{{
using namespace std;
// using namespace rel_ops;
 
const double pi=acos(-1.0);
const double eps=1e-11;
const int INF=0x7FFFFFFF;
template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}
template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline bool bit(T a, int b) {return (a>>b)&1;}
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(long long n) { return __builtin_popcountll(n); }
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define eb(args...) emplace_back(args)
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ff first
#define ss second
#define sz(g) int(g.size())
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
#ifdef LOCAL
#define dout cerr 
void out() { dout << endl; }
template<typename A, typename... B> void out(A a, B... b) { dout << ' ' << a; out(b...); }
#define dbg(args...) dout << __LINE__ << ":(" << #args << ") -> ", out(args)
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
constexpr bool local = true;
#else
#define dbg(...)
#define dout if(true);else cerr
#define out(...)
#define show(...)
constexpr bool local = false;
#endif
// }}}

int main() {
    string s;
    while (cin >> s) {
        cout << s.substr(0, 3) << endl;
    }
    return 0;

}



Measured memory_bytes: 3600
#![allow(unused_imports)]

mod pcl {

}




fn is_good(s: &str) -> bool {
    let b = s.as_bytes();
    let l = s.len();
    if l <= 1 {
        true
    } else if b[0] != b[l - 1] {
        false
    } else {
        is_good(&s[1..(l - 1)])
    }
    
    
    
    
    
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s = s.trim();

    
    
    

    let n = s.len();
    if is_good(&s) && is_good(&s[..((n - 1) / 2)]) && is_good(&s[((n + 1) / 2)..]) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
X = int(input())
def isprime(n): # N<=10^7のとき最速の素数判定法だが,10^18ほどになると実行時間10sくらいになるためMiller_Rabinを使うべし
    import math as ma
    if n == 2 or n == 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    for i in range(6, (int(ma.sqrt(n))+1) + 1, 6):
        if n % (i-1) == 0 or n % (i+1) == 0: # ∀p∈P, p = 6n±1
            return False
    return True
while True:
    if isprime(X):
        print(X)
        break
    X += 1



Measured memory_bytes: 38256
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
import random
sys.setrecursionlimit(4100000)


D = int(input())
C = list(map(int,input().split()))

S = []
for i in range(D):
    tmp = list(map(int,input().split()))
    S.append(tmp)


class Schejule:

    def __init__(self, sche):
        self.base = sche
        self.last = [0] * 26
        self.y = 0

    def get_score(self):
        self.y = 0
        for d in range(D):
            self.y += S[d][self.base[d]]

        for d in range(D):
            self.last[self.base[d]] = d + 1

            for j in range(26):
                self.y -= C[j] * (d+1 - self.last[j])

    def change_one(self, day, to):

        org = self.base[day]

        # 差分
        div = 0

        # その日の満足度の変化
        div += S[day][to] - S[day][org]

        # 損失
        org_loss = 0
        cha_loss = 0

        org_last = 0
        cha_last = 0
        for d in range(D):
            if self.base[d] == org:
                org_last = d + 1
            elif self.base[d] == to:
                cha_last = d + 1

            org_loss +=  C[org] * (d+1 - org_last)
            cha_loss +=  C[to ] * (d+1 - cha_last)

        def_loss = cha_loss + org_loss


        org_loss = 0
        cha_loss = 0

        org_last = 0
        cha_last = 0
        for d in range(D):
            if d != day:
                if self.base[d] == org:
                    org_last = d + 1
                elif self.base[d] == to:
                    cha_last = d + 1
            else:
                cha_last = d+1

            org_loss +=  C[org] * (d+1 - org_last)
            cha_loss +=  C[to ] * (d+1 - cha_last)

        aft_loss = cha_loss + org_loss


        # 全体の差分
        div -= aft_loss - def_loss

        if div > 0 or random.randint(0, 9) >= 7:
            next_plan = self.base
            next_plan[day] = to

            sche_next = Schejule(next_plan)
            sche_next.y = self.y + div

            return sche_next
        else:
            return self



T = [0] * D

for i in range(D):
    max_day = 0
    for j in range(26):
        if S[i][max_day] < S[i][j]:
            max_day = j
    T[i] = max_day


sche_base = Schejule(T)
sche_base.get_score()


best_score = sche_base.y
best_set = T

#print(sche_base.y)

#print(*sche_base.base)

for i in range(1000):
    d = random.randint(0, D - 1)
    t = random.randint(0, 26 - 1)

    sche_base  = sche_base.change_one(d, t)

    if best_score < sche_base.y:
        best_score = sche_base.y
        best_set = sche_base.base
    #print(*sche_base.base)

    #print(sche_base.y)

for i in range(D):
    print(sche_base.base[i] + 1)


#print(best_score)









Measured memory_bytes: 11088
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string ans;
    if(a+b == c || a == b+c || a+c == b) ans = "Yes";
    else ans = "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    string s, t;
    int a, b;
    cin >> s >> t >> a >> b;
    string u;
    cin >> u;
    if(s == u) {
        a--;
    }
    if(t == u) {
        b--;
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF ((int)1<<50)
signed main(){
    int n;
    cin>>n;
    vector<int> vec;
    vector<int> sum;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        vec.push_back(t);
        if(i)sum.push_back(sum[sum.size()-1]+t);
        else sum.push_back(t);
    }
    int ans=INF;
    for(int i=0;i<sum.size()-1;i++){
        ans=min(ans,abs(sum[sum.size()-1]-2*sum[i]));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

ll func(ll x) {
	if (x == 1) return 1;
	return ((x % MOD) * (func(x - 1) % MOD)) % MOD;
}

void solve() {
	ll n, m;
	cin >> n >> m;
	if (n == m) {
		ll x = func(n);
		cout << (((x * x) % MOD) * 2) % MOD << endl;
	} else if (abs(n - m) == 1) {
		ll mn = min(n, m);
		ll mx = max(n, m);
		ll x = func(mn);
		cout << (((x * x) % MOD) * mx) % MOD << endl;
	} else {
		cout << 0 << endl;
	}
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 5120
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
   
public class Main {
    boolean[] dictionary = new boolean[268435456];
    public static void main(String[] args) throws IOException {
//    	long l = System.currentTimeMillis();
        new Main().exec();
//    	long l2 = System.currentTimeMillis();
//    	System.out.println(l2 - l);
    }
      
    public void exec() throws IOException {
        InputUtil in = new InputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        for(int i=0; i<n; i++) {
        	String cmd = in.br.readLine();
        	if(cmd.charAt(0)=='i'){
        		insert(cmd.substring(7));
        	}else{
        		out.println(find(cmd.substring(5))?"yes":"no");
        	}
        }
        out.flush();
    }
    
    private void insert(String str) {
    	int key = convertKey(str);
		dictionary[key] = true;
    }

    private boolean find(String str) {
    	int key = convertKey(str);
		return dictionary[key];
    }
    
    private int convertKey(String str) {
    	int len = str.length();
    	int key = (len<<2);
    	for(int i=0; i<len; i++) {
    		switch(str.charAt(i)){
    		case 'A':
    			key|=1;
    			break;
    		case 'G':
    			key|=2;
    			break;
    		case 'C':
    			key|=3;
    		}
    		key <<= 2;
    	}
    	return key;
    }
}

class InputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
    	return br.readLine().split(delim);
    }
    
    public int nextInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }

}

Measured memory_bytes: 339656
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  ll K;
  cin >> N >> K;
  vector<int> A(N);
  cin >> A;
  for (int i = 0; i < N; i++) A[i]--;
  vector<int> vec;
  int cur = 0;
  vector<int> used(N, -1);
  int loop = -1;
  int length = -1;
  for (int i = 0; i < 2 * N; i++) {
    if (used[cur] != -1) {
      loop = used[cur];
      length = i - loop;
      break;
    }
    vec.push_back(cur);
    used[cur] = i;
    cur = A[cur];
  }
  if (K < vec.size()) {
    cout << vec[K] + 1 << endl;
  } else {
    cout << vec[(K - loop) % length + loop] + 1 << endl;
  }
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 5816
#include <queue>
#include <limits>
#include <vector>
#include <iostream>
using namespace std;
struct edge {
	int to, cost, w;
	edge() : to(0), cost(0), w(0) {};
	edge(int to_, int cost_, int w_ = 0) : to(to_), cost(cost_), w(w_) {};
};
bool operator<(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
template<class Type>
std::vector<Type> shortest_path_dijkstra(std::vector<std::vector<edge> > &G, int s) {
	std::priority_queue<edge> que; que.push(edge(s, 0));
	std::vector<Type> ret(G.size(), std::numeric_limits<Type>::max()); ret[s] = 0;
	while (!que.empty()) {
		edge u = que.top(); que.pop();
		for (edge e : G[u.to]) {
			if (ret[e.to] > ret[u.to] + e.cost) {
				ret[e.to] = ret[u.to] + e.cost;
				que.push(edge(e.to, -ret[e.to]));
			}
		}
	}
	return ret;
}
int N, M, p, q, r, s;
int main() {
	while (scanf("%d%d", &N, &M), N) {
		vector<vector<edge> > G(N);
		for (int i = 0; i < M; i++) {
			scanf("%d%d%d%d", &p, &q, &r, &s); p--, q--;
			G[p].push_back(edge(q, r, s));
			G[q].push_back(edge(p, r, s));
		}
		vector<int> dist = shortest_path_dijkstra<int>(G, 0);
		vector<int> ret(N, 1999999999);
		for (int i = 0; i < N; i++) {
			for (edge e : G[i]) {
				if (dist[e.to] - dist[i] == e.cost) {
					ret[e.to] = min(ret[e.to], e.w);
				}
			}
		}
		int sum = 0;
		for (int i = 1; i < N; i++) sum += ret[i];
		printf("%d\n", sum);
	}
	return 0;
}

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

int main()
{
  // 整数の入力                                                                                                        
  int N, K;
  cin >> N >> K;

  int h[N];
  for(int i=0; i<N; i++)
    cin >> h[i];

  int ans = 0;

  for(int i=0; i<N; i++){
    if(h[i] >= K)
      ans++;
  }

  // 出力                                                                                                              
  cout << ans << endl;
  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 100;
const int MAX_M = 100;
int n, m;
int s[MAX_N];
int t[MAX_M];

int main()
{
  while(cin >> n >> m, n){
    int rt, rh;
    int taro = 0;
    int hanako = 0;
    int res = INF;
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    rep(i, n) taro += s[i];
    rep(i, m) hanako += t[i];

    rep(i, n) rep(j, m) if(taro - s[i] + t[j] == hanako - t[j] + s[i]){
      if(minup(res, s[i] + t[j])){
        rt = s[i];
        rh = t[j];
      }
    }

    if(res < INF) cout << rt << " " << rh << endl;
    else puts("-1");
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,i;
	string s;
	cin>>a>>s;
	if(s.size()<=a)
	{
		cout<<s;
		return 0;
	}
	else
	{
		for(i=0;i<a;i++)
			cout<<s[i];
		cout<<"...";
	}
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<int> p(n + 1);
  for(int i = 0; i < n; i++){
    cin >> p[i] >> p[i + 1];
  }
  vector<vector<int> > m(n + 1, vector<int>(n + 1));
  for(int i = 1; i <= n; i++) m[i][i] = 0;
  for(int i = 2; i <= n; i++){
    for(int j = 1; j <= n - i + 1; j++){
      int t = 1000000000;
      for(int k = j; k <= j + i - 2; k++){
        t = min(m[j][k] + m[k + 1][j + i - 1] + p[j - 1] * p[k] * p[j + i - 1], t);
      }
      m[j][j + i - 1] = t;
    }
  }
  cout << m[1][n] << endl;
  return;
}

int main(){
  solve();
  return 0;
}



Measured memory_bytes: 3196
#include <stdio.h>
/*
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0026
 *
 */
/* prints the number of cells whose density value is 0 */
/* print the maximum value of density. */


int paper[200];

int coor(int x, int y){
  return x*14+y;
}

void small(int x, int y){
  paper[coor(x, y)]+=1;
  paper[coor(x+1, y)]+=1;
  paper[coor(x, y+1)]+=1;
  paper[coor(x-1, y)]+=1;
  paper[coor(x, y-1)]+=1;
}

void midium(int x, int y){
  paper[coor(x, y)]+=1;
  paper[coor(x+1, y)]+=1;
  paper[coor(x, y+1)]+=1;
  paper[coor(x-1, y)]+=1;
  paper[coor(x, y-1)]+=1;
  paper[coor(x+1, y+1)]+=1;
  paper[coor(x+1, y-1)]+=1;
  paper[coor(x-1, y+1)]+=1;
  paper[coor(x-1, y-1)]+=1;
}

void large(int x, int y){
  midium(x, y);
  paper[coor(x+2, y)]+=1;
  paper[coor(x, y+2)]+=1;
  paper[coor(x-2, y)]+=1;
  paper[coor(x, y-2)]+=1;
}


int main(){
  int x, y, size;
  int max_density;
  int filled;
  int i,j;

  for(i=0;i<14;i++){
    for(j=0;j<14;j++){
      paper[coor(i, j)] = 0;
    }
  }

  while(scanf("%d,%d,%d", &x, &y, &size)==3){
    switch(size){
    case 1:
      small(x+2, y+2);
      break;
    case 2:
      midium(x+2, y+2);
      break;
    case 3:
      large(x+2, y+2);
      break;
    default:
      break;
    }
  }
  filled = 0;
  max_density = 0;
  for(i=2;i<12;i++){
    for(j=2;j<12;j++){
      if(paper[coor(i, j)]){
        filled += 1;
        if(paper[coor(i, j)] > max_density)
          max_density = paper[coor(i, j)];
      }
    }
  }
  printf("%d\n", 100-filled);
  printf("%d\n", max_density);
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;

int N, L[1111], MAX,SUM;

signed main()
{
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> L[i];
		if (MAX < L[i]) {
			MAX = L[i];
		}
		SUM += L[i];
	}
	if (SUM <= MAX *2) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	//system("pause");

    return 0;
}

Measured memory_bytes: 256