akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
  def find(self, x):
    if(self.root[x] < 0):
      return x
    else:
      self.root[x] = self.find(self.root[x])
      return self.root[x]
  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if(x == y):
      return 
    elif(self.rnk[x] > self.rnk[y]):
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if(self.rnk[x] == self.rnk[y]):
        self.rnk[y] += 1
  def same(self, x, y):
    return self.find(x) == self.find(y)
n,k,l=map(int,input().split())
e=[[i]for i in range(n+1)]
ur=UnionFind(n)
ut=UnionFind(n)
for i in range(k):
  a,b=map(int,input().split())
  ur.unite(a,b)
for _ in range(l):
  a,b=map(int,input().split())
  ut.unite(a,b)
pair=[(ur.find(i),ut.find(i)) for i in range(1,n+1)]
c=Counter(pair)
ans=[c[i] for i in pair]
print(*ans)

Measured memory_bytes: 180624
def extgcd(a,b):
  r=[1,0,a]
  w=[0,1,b]
  while w[2]!=1:
    q=r[2]//w[2]
    r2=w
    w2=[r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
    r=r2
    w=w2
  return [w[0],w[1]]
def mod_inv(a,m):
  x=extgcd(a,m)[0]
  return (m+x%m)%m

def fact(n):
  fct=[]
  b,e=2,0
  while b*b<=n:
    while n%b==0:
      n=n//b
      e=e+1
    if e>0:
      fct.append((b,e))
    b,e=b+1,0
  if n>1:
    fct.append((n,1))
  return fct

n=int(input())
a=list(map(int,input().split()))
l=[0]*10**6
mod=10**9+7
for i in range(n):
  x=fact(a[i])
  for j in range(len(x)):
    l[x[j][0]]=max(l[x[j][0]],x[j][1])
lcm=1
for i in range(2,10**6):
  lcm*=(i**l[i])
  lcm%=mod
ans=0
for i in range(n):
  ans+=lcm*mod_inv(a[i],mod)
  ans%=mod
print(ans)

Measured memory_bytes: 54876
#include <stdio.h>

int n, q;
int A[20];

bool solve(int index, int target){
    if(target == 0){
        return true;
    }else if(target < 0){
        return false;
    }

    if(index == 0){
        if(target == A[0]){
            return true;
        }else{
            return false;
        }
    }

    if(solve(index - 1, target - A[index])){
        return true;
    }
    if(solve(index - 1, target)){
        return true;
    }
    return false;
}

int main(void){
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        int m;
        scanf("%d", &m);
        if(solve(n - 1, m)){
            printf("yes\n");
        }else{
            printf("no\n");
        }
    }

    return 0;
}



Measured memory_bytes: 2692
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(m);
    int sum = 0;
    rep(i, m){
        cin >> a.at(i);
        sum += a.at(i);
    }

    if(n>=sum){
        cout << n - sum << endl;
    }
    else{
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3640
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let bs = reads int
    let cs = List.rev bs

    if n = 2 then
        List.head cs * 2
    else
        List.pairwise cs
        |> List.sumBy (fun (x, y) -> min x y)
        |> fun x -> x + List.head cs + List.head bs
    |> printfn "%i"
    0

Measured memory_bytes: 14172
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main(){
    ll int H, ans=1, cnt=1;
    cin >> H;
    while(H > 1){
        H /= 2;
        ans += pow(2, cnt);
        cnt++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<math.h>
#define pi 3.141592654
#define d double
using namespace std;

int main()
{
    d a,b,h,m;
    cin>>a>>b>>h>>m;
    d ang1=pi*((h/6.0)+m/(30.0*12.0));
    d ang2=pi*(m/30.0);
    d ang=ang1-ang2;
    d res=sqrt((a*a)+(b*b)-(2*a*b*cos(ang)));
    //cout<<res<<endl;
    cout<<std::fixed;
    cout<<std::setprecision(10);
    cout<<res<<endl;;

}


Measured memory_bytes: 4160
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define endl '\n'


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        string s;
        in >> s;
        if (s[0] == s[1] and s[1] == s[2]) out << "No" << endl;
        else out << "Yes" << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

int main() {
  
  int N;
  cin >> N;
  
  vector<double> x(N);
  vector<string> y(N);
  
  double num = 0.0;
  double num2;
  
  for(int i = 0;i < N;++i){
    cin >> x[i] >> y[i];
  }
  
  for(int i = 0;i < N;++i){
    if(y[i] == "JPY"){
      num2 = x[i];
    }
    else{
      num2 = x[i] * 380000;
    }
  num = num2 + num;
  }
  
  cout << num << endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
S = [input() for i in range(H)]
dxy = [(0,1),(1,0),(0,-1),(-1,0)]
for y in range(H):
    for x in range(W):
        if S[y][x] == '.': continue
        for dx,dy in dxy:
            nx,ny = x+dx,y+dy
            if not 0 <= nx < W: continue
            if not 0 <= ny < H: continue
            if S[ny][nx] == '#': break
        else:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n;
int l, r;
int ans;
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> l >> r;
        ans += (r - l + 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
S=0
dic={}
for i in range(N):
  S+=A[i]
  S=S%M
  if(S not in dic):
    dic[S]=1
  else:
    dic[S]+=1
ans=0
#print(dic)
for k in dic.keys():
  #print(k)
  if(k!=0):
    ans+=dic[k]*(dic[k]-1)//2
  if(k==0):
    ans+=dic[k]+dic[k]*(dic[k]-1)//2
print(ans)

Measured memory_bytes: 14696
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    int x,a;cin >> x >> a;
    cout << (x<a ? 0 : 10) << endl;
    return 0;
}

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

typedef long long ll;
const int maxn = 500, dx[] = { 1, -1, 0, 0 }, dy[] = { 0, 0, 1, -1 };
int n, c[maxn + 3][maxn + 3], d[maxn + 3][maxn + 3], num[maxn << 2 | 3];
ll a[maxn + 3][maxn + 3];
bool b[maxn + 3][maxn + 3];

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

ll lcm(ll a, ll b) {
	if (!a || !b) return a + b;
	return a / gcd(a, b) * b;
}

int is_prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

bool valid(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= n;
}

void work(int n) {
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			b[i][j] = ~(i + j) & 1;
		}
	}
	int cur = 2;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (b[i][j]) {
				if (!num[i + j]) {
					while (!is_prime(cur)) cur++;
					num[i + j] = cur++;
				}
				c[i][j] = num[i + j];
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (b[i][j]) {
				if (!num[i - j + n * 3]) {
					while (!is_prime(cur)) cur++;
					num[i - j + n * 3] = cur++;
				}
				d[i][j] = num[i - j + n * 3];
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (b[i][j]) {
				a[i][j] = c[i][j] * d[i][j];
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (!b[i][j]) {
				for (int k = 0; k < 4; k++) {
					if (valid(i + dx[k], j + dy[k])) {
						a[i][j] = lcm(a[i][j], a[i + dx[k]][j + dy[k]]);
					}
				}
				a[i][j]++;
			}
		}
	}
}

int main() {
	scanf("%d", &n);
	if (n == 2) {
		puts("4 7");
		puts("23 10");
		return 0;
	}
	work(n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			printf("%lld%c", a[i][j], " \n"[j == n]);
		}
	}
	return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;++i){
    cin >> p[i];
  }
  int k=0;
  for(int i=0;i<n;++i){
    if(p[i] != i+1) {
      k++;
    }
  }
  if(k <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
//
//AtCoder Beginner Contest 178
//E
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> t1, t2;
    REP(i, n){
        ll x, y;
        cin >> x >> y;
        t1.push_back(x-y);
        t2.push_back(x+y);
    }
    sort(ALL(t1));
    sort(ALL(t2));
    cout << max(t1[n-1]-t1[0], t2[n-1]-t2[0]) << endl;
    return 0;
}


Measured memory_bytes: 4992
import Data.List

main :: IO ()
main = do
  getLine
  as <- map read . words <$> getLine
  print $ solve as 

solve :: [Int] -> Int
solve = solve' 0 0 . sortBy (flip compare)

solve' :: Int -> Int -> [Int] -> Int
solve' x y [] = x - y
solve' x y [a] = x + a - y
solve' x y (a:b:as) = solve' (x + a) (y + b) as


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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n;
	int mat[n][n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> mat[i][j];
		}
	}
	ll cost[(1<<n)];
	memset(cost, 0, sizeof(cost));
	for(int mask = 1; mask < (1<<n); mask++){
		for(int i = 0; i < n; i++){
			if(mask & (1<<i)){
				for(int j = i; j < n; j++){
					if(mask & (1<<j))
						cost[mask] += mat[i][j];	
				}
			}
		}	
	}
	
	ll dp[(1<<n)];
	memset(dp, 0, sizeof(dp));
	for(int mask = 1; mask < (1<<n); mask++){
		vector<int> subset;
		for(int i = 0; i < n; i++){
			if(mask & (1<<i)) subset.pb(i);
		}
		m = subset.size();
		for(int i = 0; i < (1<<m); i++){
			int submask = 0;
			for(int j = 0; j < m; j++) if(i & (1<<j)) submask |= (1<<(subset[j]));
			dp[mask] = max(dp[mask], dp[submask] + cost[mask^submask]);
		}
	}
	ll ans = dp[(1<<n) - 1];
	cout << ans << endl;
}

Measured memory_bytes: 1280
using System;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {
        public void Calc()
        {
            var K = int.Parse(Console.ReadLine());
            var AB = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

            Console.WriteLine(AB.Any(x => x % K == 0) || AB[0] / K != AB[1] / K ? "OK" : "NG");
        }
    }
}


Measured memory_bytes: 28300
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {
	int p[8];
	while (cin >> p[0] >> p[1] >> p[2] >> p[3] >> p[4] >> p[5] >> p[6] >> p[7]) {
		int jn[8][8] = { {1,2,1,2,1,4,1,4},{1,2,1,4,1,4,1,2} ,{1,4,1,2,1,2,1,4},{1,4,1,4,1,2,1,2},
		{2,1,2,1,4,1,4,1},{2,1,4,1,4,1,2,1},{4,1,2,1,2,1,4,1},{4,1,4,1,2,1,2,1} };

		int n = 5000000;
		int ans;

		for (int i = 0;i < 8;i++) {
			int a = 0;
			for (int j = 0;j < 8;j++) {
				a +=max(0,p[j]-jn[i][j]);//norenai
			}
			if (n > a) {
				ans = i;
				n = a;
			}
		}
		for (int i = 0;i < 8;i++) {
			cout << jn[ans][i];
			if (i != 7)cout << ' ';
		}
		cout << endl;
	}
	return 0;
}

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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

const int N = 5e5, A = 26;
typedef int T;
struct BIT { // ops O(lg n), [0, N-1]
    T d[N+1];
    void add(int i, T x){ for(++i; i <= N; i += i&-i) d[i] += x; }
    T sum(int i){ T r = 0; for(++i; i; i -= i&-i) r += d[i]; return r; }
    T sum(int l, int r){ return sum(r)-sum(l-1); }
} rmq[A];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    int n,q; string s; cin >> n >> s >> q;
    forn(i, n) rmq[int(s[i]-'a')].add(i, 1);
    while (q--) {
        int t,x,y; char c; cin >> t >> x, x--;
        if (t == 1) {
            cin >> c;
            rmq[int(s[x]-'a')].add(x, -1);
            s[x] = c;
            rmq[int(s[x]-'a')].add(x, 1);
        }
        else {
            cin >> y, y--;
            int r = 0;
            forn(i, A) r += rmq[i].sum(x, y) ? 1:0;
            cout << r << endl;
        }
    }
        
    return 0;
}


Measured memory_bytes: 51740
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] L = new int[N];
        for(int i = 0; i < N; i++){
            L[i] = sc.nextInt();
        }
        Arrays.sort(L);
        int sum = 0;
        for (int i = 0; i < N - 1; i++) {
            sum += L[i];
        }
        if(L[N - 1] < sum){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23380
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
ll s, n, m;
ll f(ll b, ll n) {
	return n < b ? n : f(b, n / b) + n % b;
}
int main() {
	cin >> n >> s; m = sqrt(n) + 1;
	if (s > n) return puts("-1"), 0;
	if (s == n) return printf("%lld\n", s + 1), 0;
	for (ll i = 2; i <= m; ++i)
		if (f(i, n) == s) return printf("%lld\n", i), 0;
	ll b, q, res = 1e11; n -= s;
	for (ll p = 1; p * p <= n; ++p) {
		if (n % p == 0 ) {
			b = n / p + 1; q = s - p;
			if (q >= 0 && b >= 2 && q < b && p < b)
				res = min(res, b);
		}
	} printf("%lld\n", res == 1e11 ? -1 : res);
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N, M; cin >> N >> M;
	for (int i = M / N;i>0; i--) {
		if (M % i == 0 && M / i >= N) {
			cout << i;
			return 0;
		}
	}
}

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

using namespace std;

int main () {
	int n,m;
	cin >> n >> m;
	vector<int> adj[200005];
	int vis[200005];
	memset (vis,0,sizeof(vis));
	for (int i=1;i<=m;i++) {
		int a,b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	queue<int> BFS;
	BFS.push(1);
	while (!BFS.empty()) {
		int cur=BFS.front();
		BFS.pop();
		for (int i=0;i<adj[cur].size();i++) {
			int next=adj[cur][i];
			if (vis[next]==0) {
				vis[next]=vis[cur]+1;
				BFS.push(next);
			}
		}
		if (vis[n]!=0) break;
	}
	if (vis[n]==2) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 13168
#include<stdio.h>
int main(void){
	int b[3];
	scanf("%d %d %d",&b[0],&b[1],&b[2]);
	if(b[0]==1&&b[1]==1) printf("Open\n");
	else if(b[2]==1) printf("Open\n");
	else printf("Close\n");
	return 0;
}


Measured memory_bytes: 2044
#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#include<queue>
using namespace std;
const int maxm = 3001;
const int maxn = 3105;
const int INF = 0x3ffffff;
struct Side{
	int to,next,w;
}side[maxm*2],side1[maxm*2];
int node1[maxn*2],top,top1,node[maxn];
void add_side(int u,int v,int w){
	side[top]=(Side){v,node[u],w};node[u]=top++;
}
 
void add_side1(int u,int v,int w){
	side1[top1]=(Side){v,node1[u],w};node1[u]=top1++;
	side1[top1]=(Side){u,node1[v],w};node1[v]=top1++;
}
int cap;
map<string,int>city;
int cnt1,cnt,start,end;
bool is1[maxn],is[maxn];
int get_id(string str){
	if(city.count(str)==0)city[str]=++cnt1;
	return city[str];
}
int dis[maxn][2001];
bool inqueue[maxn][2001];
queue<pair<int,int> >q;
int get_dis(){
	for(int i=1;i<=cnt;i++){
		for(int j=0;j<=cap;j++){
			inqueue[i][j]=false;
			dis[i][j]=INF;
		}
	}
	dis[start][cap]=0;
	pair<int,int>tmp=make_pair(start,cap);
	q.push(tmp);
	while(!q.empty()){
		tmp=q.front();q.pop();
		int u=tmp.first;
		int c=tmp.second;
		inqueue[u][c]=false;
		if(c!=cap&&is[u]){
			if(dis[u][c]<dis[u][cap]){
				dis[u][cap]=dis[u][c];
				if(!inqueue[u][cap]){
					inqueue[u][cap]=true;
					q.push(make_pair(u,cap));
				}
			}
		}
		for(int i=node[u];i!=-1;i=side[i].next){
			int v=side[i].to;
			int last=c-side[i].w;
			if(last<0)continue;
			if(dis[u][c]+side[i].w<dis[v][last]){
				dis[v][last]=dis[u][c]+side[i].w;
				if(!inqueue[v][last]){
					inqueue[v][last]=true;
					q.push(make_pair(v,last));
				}
			}
		}
	}
	int ans=INF;
	for(int i=0;i<=cap;i++){
		ans=min(ans,dis[end][i]);
	}
	return ans==INF?-1:ans;
}
bool vis[6001];
int id[maxn*2];
void dfs(int u){
	for(int i=node1[u];i!=-1;i=side1[i].next){
		int v=side1[i].to;
		if(!vis[v]){
			vis[v]=true;
			dfs(v);
		}
	}
}
int main(){
	int n,m;
	while(~scanf("%d%d%d",&m,&n,&cap)){
		if(m==0&&n==0&&cap==0)break;
		cap=cap*10;
		city.clear();
		top=0;
		cnt=0;
		cnt1=0;
		top1=0;
		memset(node,-1,sizeof(node));
		memset(node1,-1,sizeof(node1));
		memset(is,false,sizeof(is));
		memset(is1,false,sizeof(is1));
		memset(vis,false,sizeof(vis));
		string u,v;
		cin>>u>>v;
		start=get_id(u);
		end=get_id(v);
		for(int i=0;i<m;i++){
			cin>>u>>v;
			int w;
			scanf("%d",&w);
			int x=get_id(u);
			int y=get_id(v);
			add_side1(x,y,w);
		}
		for(int i=0;i<n;i++){
			cin>>u;
			is1[get_id(u)]=true;
		}
		vis[start]=true;
		dfs(start);
		if(!vis[end])printf("-1\n");
		else{
			for(int i=1;i<=cnt1;i++){
				if(!vis[i])continue;
				id[i]=++cnt;
			}
			for(int u=1;u<=cnt1;u++){
				if(!vis[u])continue;
				for(int i=node1[u];i!=-1;i=side1[i].next){
					int v=side1[i].to;
					if(!vis[v])continue;
					add_side(id[u],id[v],side1[i].w);
				}
			}
			for(int i=1;i<=cnt1;i++){
				if(vis[i]&&is1[i])is[id[i]]=true;
			}
			start=id[start];
			end=id[end];
			printf("%d\n",get_dis());
		}
	}
}



Measured memory_bytes: 41204
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int n;

void dfs(string s, int a) {
  if (s.length() == n)
    cout << s << endl;
  else {
    for (char c = 'a'; c <= 'a' + a; ++c) {
      if (c != 'a' + a)
        dfs(s + c, a);
      else
        dfs(s + c, a + 1);
    }
  }
}

int main() {
  cin >> n;
  dfs("", 0);
  return 0;
}


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

using namespace std;

int main(){
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  
  sort(a,a+3);
  
  cout<<a[0]+a[1]+a[2]*10<<endl;
  
  return 0;
}

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

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

  if (N.at(0) == '7' || N.at(1) =='7' || N.at(2) == '7') {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
// AOJ 1551: A White Wall
// 2019.2.21 bal4u

#include <stdio.h>
#include <stdlib.h>

int wall[102];

int cmp(const void *a, const void *b)
{
	return *(int *)b - *(int *)a;
}

int main()
{
	int i, j, N, M, a, L;

	scanf("%d%d", &N, &M);
	for (i = 0; i < M; i++) {
		scanf("%d%d", &a, &L);
		for (j = 0; j < L; j++) wall[(a + j) % N] = 1;
	}
	for (j = 0; j < N; j++) if (wall[j] == 0) break;
	if (j == N) printf("%d 1\n", N);
	else {
		for (i = 0; i < N; i++) {
			if (wall[(j + i) % N] && wall[(j + i + 1) % N]) {
				wall[(j + i + 1) % N] += wall[(j + i) % N];
				wall[(j + i) % N] = 0;
			}
		}
		qsort(wall, N, sizeof(int), cmp);
		a = 1;
		for (i = 1; i < N; i++) {
			if (wall[i] == wall[i - 1]) a++;
			else {
				printf("%d %d\n", wall[i - 1], a);
				if (wall[i] == 0) break;
				a = 1;
			}
		}
	}
	return 0;
}


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

#define f(a, b) for(auto i = a;i < b;i++)
typedef long long int ll;

void solve()
{
	return ;
}
double maxvolume(double  s) 
{  
    double l= s / 3.0; 
    s -= l; 
    double b = s / 2.0; 
    double h = s - b; 
  	
    return l * b * h; 
}

int main()
{
	double n;
	cin >> n;
	cout << setprecision(16) <<maxvolume(n) << "\n";
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a>c)
	{
		cout<<((c+24)*60+d-a*60-b-e);
	}
	else
	cout<<(c*60+d-b-a*60-e);
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[100100];
int main()
{
    cin>>n>>k;
    for (int i = 1; i <= n; i++) cin>>a[i];
    sort(a + 1, a + 1 + n);
    int minn = 1e9;
    for (int i = 1; i <= n-k+1; i++)
    {
        if(a[k + i - 1] - a[i] < minn) minn = a[k + i - 1] - a[i];
    }
    printf("%d", minn);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define float       double
#define	endl		'\n'
#define maxpq       priority_queue<ll>
#define minpq       priority_queue<ll, vector<ll>, greater<ll> >
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define EPS         1e-9
#define INF         1e18
#define PI          3.14159265358979323846
#define MAXI        1000000
#define what_is(x)  cerr << #x << " is " << x << endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define N 100005
int modexp(int x,int n,int mod){
	x%=mod;
	int res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n/=2;
	}
	return res;
}
int modInverse(int n, int p)
{ 
    return modexp(n, p - 2, p); 
} 
int nCr(int n,int r, int p) 
{ 
    if (r == 0) 
        return 1; 
    int fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
// writing good dfs function
//void dfs(int start,int parent)
//{
//	sz[start]=1;
//	df[start]=df[parent]+1;
//	for(auto x:v[start])
//	{
//		if(x==parent) continue;
//		dfs(x,start);
//		sz[start]+=sz[x];
//	}
//}
signed main()
{
	fast;
	int t=1;
//	cin>>t;
	while(t--)
	{
		int x;
		cin>>x;
		if(x==0)
		{
			cout<<1<<endl;
		}
		else
		{
			cout<<0<<endl;
		}
	}
   return 0;
}

Measured memory_bytes: 3632
def pointUpdate(BIT,index,val):
    mod = 998244353
    while index < len(BIT):
        BIT[index] += val
        BIT[index] %= mod
        index += index&-index

def pointQuery(BIT,index):
    mod = 998244353
    total = 0
    while index > 0:
        total += BIT[index]
        index -= index&-index
        total %= mod

    return total

def rangeUpdate(BIT,l,r,val):
    pointUpdate(BIT,l,val)
    pointUpdate(BIT,r+1,-val)

def main():
    n,k = map(int,input().split())
    segs = []
    for i in range(k):
        l,r = map(int,input().split())
        segs.append((l,r))

    segs.sort()

    mod = 998244353
    BIT = [0]*(n+1)
    BIT[1] = 1
    for cell in range(1,n+1):
        curr = pointQuery(BIT,cell)
        if cell == n:
            print(curr)
        for l,r in segs:
            left = min(cell+l,n+1)
            right = min(cell+r,n+1)
            rangeUpdate(BIT,left,right,curr)

main()


Measured memory_bytes: 70724
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//233
	int n,m;
	cin>>n>>m;
	vector<vector<bool>> arr(m, vector<bool>(n, false));
	REP(i,0,m-1) {
		int k;
		cin>>k;
		while(k--) {
			int val;
			cin>>val;
			arr[i][val-1]=1;
		}
	}
	vi pa(m);int cnt = 0;
	REP(i,0,m-1)cin>>pa[i],pa[i]%=2;
	for(int i=0;i<1<<n;i++) {
		vector<bool> bulbs(n,false);
		for(int j=0;j<n;j++) {
			if((i>>j)&1)bulbs[j]=1;
		}
		int bs = 0;
		REP(j,0,m-1) {
			int tc = 0;
			REP(k,0,n-1){
				if(bulbs[k]&&arr[j][k])tc++;
			}
			if(tc%2==pa[j])bs++;
			else break;
		}
		if(bs==m)cnt++;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int last[26];
int c[26];
int s[365][26];
int a[365];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int d; cin >> d;
    for(int i=0;i<26;i++){
    	cin >> c[i];
    }
    for(int i=0;i<d;i++){
    	for(int j=0;j<26;j++){
    		cin >> s[i][j];
    	}
    }
    for(int i=0;i<d;i++){
    	a[i]=myRand(26)+1;
    }
    int res=0;
    for(int i=0;i<d;i++){
    	res+=s[i][a[i]-1];
    	last[a[i]-1]=i+1;
    	for(int j=0;j<26;j++){
    		res-=c[j]*(i+1-last[j]);
    	}
    }
    for(int i=0;i<1e6;i++){
    	int day,qq;
    	day=myRand(d)+1;
    	qq=myRand(26)+1;
    	int resres=res;
    	int qqq=a[day-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres+=c[qq-1]*(i+1-last[qq-1]);
            resres+=c[qqq-1]*(i+1-last[qqq-1]);
        }
        a[day-1]=qq;
        resres-=s[day-1][qqq-1];
        resres+=s[day-1][qq-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres-=c[qq-1]*(i+1-last[qq-1]);
            resres-=c[qqq-1]*(i+1-last[qqq-1]);
        }
        if(resres>=res){

        }
        else{
        	if(i<=1e5&&resres<res+15){

        	}
        	else{
        		a[day-1]=qqq;
        	}
        }
    }
    for(int i=0;i<d;i++){
    	printf("%d\n",a[i]);
    }
}



Measured memory_bytes: 3812
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){

    int r;
    cin >> r;
    P(r * r);
    return  0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define ll long long

using pi = pair<int, int>;

typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

Order_Set X;

const int mxn = 1e6+100;
const int Mod = 1e9+7;

int arr[mxn], qs[mxn];
int bitOn[55];
map<int,int>Mp, cnt, op;
vector<int>Pi, Ans;
vector<int>G[mxn];
set<int>seet[mxn];

const int N = 25;

int n, m;
char a[N][N];
int vis[N][N], dist[N][N];
int dx[4]={-1, +1, 0, 0};
int dy[4]={0, 0, +1, -1};

int bfs(int x, int y)
{
	memset(vis, 0, sizeof(vis));
	queue<pi>q;
	q.push({x, y});
	vis[x][y]=1;
	dist[x][y]=0;
	int mx = 0;
	while(!q.empty()){
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		for(int dir=0;dir<4;dir++){
			int nx=x+dx[dir];
			int ny=y+dy[dir];
			if(nx<0 || ny<0 || nx>=n || ny>=m || a[nx][ny] == '#')
				continue;
			if(!vis[nx][ny]){
				dist[nx][ny]=dist[x][y]+1;
				mx = max(mx, dist[nx][ny]);
				vis[nx][ny]=1;
				q.push({nx, ny});
			}
		}
	}
	return mx;
}


int main()
{
	ios::sync_with_stdio(false);

	cin >> n >> m;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(a[i][j] == '.'){
				ans = max(ans, bfs(i, j));
			}
		}
    }

	cout << ans <<endl ;

	return 0;
}


Measured memory_bytes: 71936
#include<stdio.h>
#define MAX 2000001

int H;

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
void maxheap(int* ary,int i){
  int l,r,largest,tmp;
  l=left(i);
  r=right(i);
  if(l<=H && ary[l]>ary[i]){largest=l;}
  else{largest=i;}
  if(r<=H && ary[r]>ary[largest]){largest=r;}
  if(largest!=i){
    tmp=ary[i];
    ary[i]=ary[largest];
    ary[largest]=tmp;
    maxheap(ary,largest);
  }
}
void buildmaxheap(int* ary){
  int i;
  for(i=H/2;i>0;i--){
    maxheap(ary,i);
  }
}
int main(){
  int i,n,ary[MAX];
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&ary[i]);
  }
  buildmaxheap(ary);
  for(i=1;i<=H;i++){
    printf(" %d",ary[i]);
  }
  printf("\n");
  return 0;
}



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

int main(){
  int n;
  while(cin >> n, n){
    int k, cnt = 0, t = 0;
    for (int i = 0; i < n; i++) {
      cin >> k;
      if(k > 0)cnt++;
      if(k > 1)t++;
    }
    if(t > 0){
      std::cout << cnt + 1 << std::endl;
    }else{
      std::cout << "NA" << std::endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
int a[10001];

void solve(){
	FOR(x,1,101){
		FOR(y,1,101){
			FOR(z,1,101){
				if(x*x+y*y+z*z+x*y+x*z+y*z <= 10000)++a[x*x+y*y+z*z+x*y+x*z+y*z];
			}
		}
	}
	int n; cin >> n;
	FOR(i,1,n+1) cout << a[i] << '\n';
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


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

int main(){
  int n,k;
  cin >>n >>k;
  if((n+1)/2>=k) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n, i, j, mini, tmp, count = 0;
    cin >> n;
    int a[n];
    for(i = 0; i < n; i++) cin >> a[i];
    for(i = 0; i < n; i++){
        mini = i;
        for(j = i; j < n; j++) if(a[j] < a[mini]) mini = j;
        tmp = a[i];
        a[i] = a[mini];
        a[mini] = tmp;
        if(a[i] != a[mini]) count++;
    }
    for(i = 0; i < n-1; i++) cout << a[i] << " ";
    cout << a[i] << endl << count << endl;
    return 0;
}


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

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if (a==b&&a==c){
		cout << 1 << endl;
	}

	else if((a==b&&b!=c)||(b==c&&c!=a)||(c==a&&a!=b)){
		cout << 2 << endl;
	}

	else {
		cout << 3 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

from collections import defaultdict, deque, Counter
from sys import exit
import math
import copy
from bisect import bisect_right

import sys
sys.setrecursionlimit(1000000)
import heapq
INF = 10**10

def dijkstra(graph, start, n):
    h = []
    heapq.heappush(h, (0, start))
    costs = [INF for _ in range(n)]
    while h:
     cost, cur = heapq.heappop(h)
     if costs[cur] != INF:
         continue
     costs[cur] = cost
     for edge in graph[cur]:
         ecost, tgt = edge
         if costs[tgt] == INF:
             heapq.heappush(h, (cost + ecost, tgt))

    return costs

def main():
    x, n = getList()
    nums = getList()
    ans = -1
    tmp = 100000
    for i in range(-200, 201):
        if i not in nums and abs(i - x) < tmp:
            ans = i
            tmp = abs(i - x)

    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 67956
from functools import reduce
INF = int(1e9+7)


def main():
    N, *An = map(int, open(0).read().split())
    An.sort()
    if N % 2:
        if [0] + [i for i in range(2, N, 2) for j in range(2)] == An:
            print(reduce(lambda x, y: (x << 1) % INF, range(N // 2), 1))
            return
    else:
        if [i for i in range(1, N, 2) for j in range(2)] == An:
            print(reduce(lambda x, y: (x << 1) % INF, range(N // 2), 1))
            return
    print(0)
    return


main()


Measured memory_bytes: 14436
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class CRally {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<int> x(n);
        rep(i,n){
            in >> x[i];
        }
        int ans=10000000;
        for(int i=1;i<=100;i++){
            int t=0;
            rep(j,n){
                t+=pow(i-x[j],2);
            }
            ans = min(ans,t);
        }
        out << ans << endl;
	}
};


int main() {
	CRally solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a[10000],i,s=0,c=0,n;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            c=1;
        }
        else if(a[i]!=a[i-1])
        {
            s=s+c/2;
            c=1;
        }
        else
        {
            c++;
        }
    }
    s=s+c/2;
    cout<<s;

}

Measured memory_bytes: 256
class BIT():

    __slots__ = ["n", "data"]

    def __init__(self, length_or_list):
        if isinstance(length_or_list, int):
            self.n = length_or_list + 1
            self.data = [0] * self.n
        else:
            self.n = len(length_or_list) + 1
            self.data = [0] + length_or_list
            for i in range(1, self.n):
                if i + (i & -i) < self.n:
                    self.data[i + (i & -i)] = self.data[i + (i & -i)] + self.data[i]        

    def point_append(self, index, delta):
        index += 1
        while index < self.n:
            self.data[index] = self.data[index] + delta
            index += index & -index
        
    def prefix_folded(self, end):
        res = 0
        while end > 0:
            res += self.data[end]
            end -= end & -end
        return res

    def folded(self, begin, end):
        ret = 0
        while begin < end:
            ret += self.data[end]
            end -= end & -end
        while end < begin:
            ret -= self.data[begin]
            begin -= begin & -begin
        return ret

def main():
    import sys
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read
    N, Q = map(int, input().split())
    seg = BIT(list(map(int, input().split())))
    for _ in range(Q):
        a, b, c = map(int, input().split())
        if a:
            print(seg.folded(b, c))
        else:
            seg.point_append(b, c)

if __name__ == "__main__":
    main()

Measured memory_bytes: 125476
#include<stdio.h>
int main()
{
    int a,b,c,x;
    scanf("%d\n",&x);
    a=x/3600;
    b=(x%3600)/60;
    c=(x%3600)%60;
    printf("%d:%d:%d\n",a,b,c);
    return 0;
    
    
}


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

int main() {
  int A, B, C;
  int count = 0;
  cin >> A >> B >> C;

  while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
    int newA = B / 2 + C / 2;
    int newB = A / 2 + C / 2;
    int newC = A / 2 + B / 2;
    if (newA == A && newB == B && newC == C) {
      count = -1;
      break;
    }
    A = newA;
    B = newB;
    C = newC;
    count++;
  }

  cout << count << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;
//using ll=long long;

int main(){
  long x;
  cin >> x;

  vector<long> a(100001, 1);
  vector<long> b;
  a.at(0)=0;
  a.at(1)=0;
  a.at(2)=2;

  //10^5までの素数を求める
  for (long i=2; i<=317; i++){
    //if (a.at(i)!=0) a.at(i)=i;
    for (long j=i+1; j<=100000; j++) {
      if (a.at(j)!=0) {
    if (j%i==0) a.at(j)=0;
    else        a.at(j)=j;
      }
    }
  }

  long result;
  bool flag;
  //入力値の二乗まで回す
  for (long i=x; i<=x*x; i++) {
    result=i;
    flag=true;
    //ループ範囲をiの平方根までにする
    long bend=(long)sqrt(i)+1;
    for (long j=0; j<bend; j++) {
      //0は除外
      if (a.at(j)==0) continue;
      //自分が素数だったらそのまま出力
      if (i==a.at(j)) {
        cout << i << endl;
        return 0;
      }
      //超えたら次にいく
      if (i<a.at(j)) break;
      //割り切れたら素数ではないので次にいく
      if (i%a.at(j)==0) {
        flag=false;
        break;
      }
    }
    if (flag==true) break;
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 4120
t = int(input())

def floor_sum(n, m, a, b):
    """
    Σ(i=0 -> N-1) floor((A * i + B) / M)
    """
    result = 0
    if a >= m:
        result += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        result += n * (b // m)
        b %= m

    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return result
    result += (n - (x_max + a - 1) // a) * y_max
    result += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return result

for _ in range(t):
    n,m,a,b = map(int,input().split())
    print(floor_sum(n,m,a,b))


Measured memory_bytes: 75824
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << (b!=1?a-b:0) << endl;
}


Measured memory_bytes: 256
from sys import stdin
from itertools import repeat
def main():
    n, m = map(int, stdin.readline().split())
    a = map(int, stdin.readline().split(), repeat(10, n))
    dat = map(int, stdin.read().split(), repeat(10, 2 * m))
    f = [0] * (n + 1)
    g = [0] * (n + 1)
    for x in a:
        if x - f[x] >= 1:
            g[x-f[x]] += 1
        f[x] += 1
    ans = sum(not x for x in g) - 1
    p = []
    for i in xrange(m):
        x, y = dat[i*2], dat[i*2+1]
        x -= 1
        f[a[x]] -= 1
        if a[x] - f[a[x]] >= 1:
            g[a[x]-f[a[x]]] -= 1
            if not g[a[x]-f[a[x]]]:
                ans += 1
        a[x] = y
        if y - f[y] >= 1:
            if not g[y-f[y]]:
                ans -= 1
            g[y-f[y]] += 1
        f[y] += 1
        p.append(ans)
    print "\n".join("%i" % x for x in p)
main()


Measured memory_bytes: 43824
word = gets.chomp.split("")

list = word.group_by { |x| x}.to_h

result = []
list.each do |key, value|
    if value.length % 2 == 0
        result << "ture"
    else
        result << "false"
    end
end

if result.include?("false")
    puts  "No"
else
    puts " Yes"
end

Measured memory_bytes: 1788