akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<chrono>
#define ll long long
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, W, X, Y, Z;
ll ans = 0;
int main() {
	cin >> H >> W;
	vector<vector<char>>a(H, vector<char>(W));
	vector<int>h, w;
	for (int i = 0; i < H; i++) {
		bool flag = 0;
		for (int j = 0; j < W; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#') {
				flag = 1;
			}
		}
		if (flag)h.push_back(i);
	}
	for (int j = 0; j < W; j++) {
		bool flag = 0;
		for (int i = 0; i < H; i++) {
			if (a[i][j] == '#') {
				flag = 1; break;
			}
		}
		if (flag)w.push_back(j);
	}
	for (int i : h) {
		for (int j : w) {
			cout << a[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
// Frog - 1

#include <bits/stdc++.h>
using namespace std;

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

Measured memory_bytes: 1792
import Control.Monad (replicateM)

main :: IO ()
main = do
  n <- readLn
  xs <- replicateM n $ getInts
  print $ solve xs

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: [[Int]] -> Int
solve = foldl (\acc [l,r] -> acc + r - l + 1) 0


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


Measured memory_bytes: 9592
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var S = Console.ReadLine();

        var output = 0;
        for (int i = 0; i < N - 2; i++)
        {
            if (S.Substring(i, 3) == "ABC")
                output++;
        }

        Console.WriteLine(output);
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int h, w;
string map[12];
vector<string> ord;
bool used[12];
int cnt;

bool check() {
    // for (int i = 0; i < h; ++i) {
    //     cout << ord[i] << endl;
    // }
    // cout << endl;

    // if (h % 2 != 0) {
    //     for (int i = 0; i < w; ++i) {
    //         if (ord[h / 2][i] != ord[h / 2][w - i - 1]) return false;
    //     }
    // }
    for (int i = 0; i < w; ++i) used[i] = false;

    for (int i = 0; i < w; ++i) {
        if (used[i]) continue;
        for (int j = i + 1; j < w; ++j) {
            if (!used[j]) {
                bool rev = true;
                for (int k = 0; k < h; ++k) {
                    if (ord[k][i] != ord[h - k - 1][j]) {
                        rev = false;
                        break;
                    }
                }
                if (rev) {
                    used[i] = true;
                    used[j] = true;
                    // cout << i <<", " << j << endl;
                    break;
                }
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < w; ++i) if (used[i]) cnt++;
    

    // cout << cnt << endl;
    if (w % 2 != 0) {
        for (int i = 0; i < w; ++i)
            if (!used[i])
                for (int k = 0; k < h; ++k)
                    if (ord[k][i] != ord[h - k - 1][i]) return false;
    }
    if (cnt == w / 2 * 2) return true;
    return false;
}

bool all_pair(int bit, int depth=0) {
    if (depth == h / 2) {
        // if (h % 2 == 1) {
        //     for (int i = 0; i < h; ++i) {
        //         if (!((bit >> i) & 1)) {
        //             ord[h / 2] = map[i];
        //         }
        //     }
        // }
        return check();
    }
    //cout << bit << endl;

    for (int i = 0; i < h; ++i) {
        if ((bit >> i) & 1) {
        continue;
        } else {
            for (int j = i + 1; j < h; ++j) {
                if ((bit >> j) & 1) continue;
                ord[depth] = map[i];
                ord[h - depth - 1] = map[j];
                bool ok = all_pair(bit | (1 << i) | (1 << j), depth+1);
                if (ok) return true;
            }
            break;
        }
    }

    return false;
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        cin >> map[i];
        ord.push_back("");
    }

    bool ans = false;
    if (h % 2 == 0) {
        ans = all_pair(0);
    } else {
        ans = false;
        for (int i = 0; i < h; ++i) {
            ord[h / 2] = map[i];
            ans |= all_pair(1 << i);
        }
    }
    cout << (ans ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
def main():
  N = int(input())
  a = list(map(int, input().split()))

  avg = round(sum(a) / len(a))

  m = 201
  n = 0

  ans = 0

  for value in a:
    diff = value - avg

    if(diff < m):
      m = diff
      n = value - diff

  for value in a:
    ans += (n - value) ** 2

  print(ans)


if __name__ == "__main__":
  main()

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

ll gcd(ll a, ll b){
  if (a%b == 0)return(b);
  else return(gcd(b, a%b));
}

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

int main(){

  ll n,m;cin>>n>>m;
  string s,t;cin>>s>>t;
  ll l=lcm(n,m);

  ll a=l/n,b=l/m;
  for(ll i=0,j=0;i<n&&j<m;){
    if(i*a>j*b)j++;
    else if(i*a==j*b){
      if(s[i]!=t[j]){
        out(-1);
        return 0;
      }
      i++;
      j++;
    }
    else i++;
  }
  out(l);


  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int L[110];
    rep(i, N) cin >> L[i];
    int ans = 0;
    rep(i, N) {
        REP(j, i + 1, N - 1) {
            if(L[i] == L[j]) continue;
            REP(k, j + 1, N - 1) {
                if(L[k] == L[i] || L[k] == L[j]) continue;
                if(L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]) ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
using namespace std;

vector<int>r[100000];
int DFS(int p, int a) {
	int b = 0;
	for (int c : r[a]) {
		if (c != p) {
			b ^= DFS(a, c)+1;
		}
	}
	return b;
}
signed main() {
	int n; cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y; cin >> x >> y;
		x--; y--;
		r[x].push_back(y);
		r[y].push_back(x);
	}
	if (DFS(-1, 0)) {
		puts("Alice");
	}
	else {
		puts("Bob");
	}
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;
int main(){
  int n,m;
  std::cin >> n>>m;
  std::vector<bool> han(n+1,true);
  rep(i,m){
    int dum;
    std::cin >> dum;
    han[dum]=false;
  }
  std::vector<ll> dp(n+1);
  dp[0]=1;
  for (int i = 0; i < n; i++) {
    /* code */
    for (int j = 1+i; j <= min(n,2+i); j++) {
      if(han[j]){
        dp[j]+=dp[i];
        dp[j]%=MOD;
      }/* code */
    }
  }
  std::cout << dp[n] << std::endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		int cnt[] = new int[26];
		Arrays.fill(cnt, 1);
		for(int i = 0; i < N; i++) {
			cnt[S.charAt(i) - 97]++;
		}
		long ans = 1;
		for(int i = 0; i < 26; i++) {
			ans = (ans * cnt[i]) % 1000000007;
		}
		System.out.println(ans - 1);
	}
}


Measured memory_bytes: 24040
#include<iostream>
using namespace std;
int main(){
	int n,x,ans=0;
	for(;;){
		cin>>n>>x;
		if(n==0 && x==0)break;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				for(int k=j+1;k<=n;k++){
					if((i+j+k)==x)ans++;
				}
			}
		}
		cout<<ans<<endl;
		ans=0;
	}
    return 0;
} 


Measured memory_bytes: 3096
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,M,K = mips()
A = [i for i in mips()]
B = [i for i in mips()]
# N,M <= 200000
ans = 0
clock = K
A2 = [0]
B2 = [0]
for i in range(1,N+1):
    ai = A2[i-1] + A[i-1]
    A2.append(ai)
for i in range(1,M+1):
    bi = B2[i-1] + B[i-1]
    B2.append(bi)
j = M
for i in range(N+1):
    if A2[i] > K:
        break
    while (B2[j] + A2[i] > K):
        j -= 1
    ans = max(ans,i+j)
print(ans)

Measured memory_bytes: 47588
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=2010;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int suma[MAX][MAX],sumb[MAX][MAX],sumc[MAX][MAX];
int main(){
	int n,m,q;cin>>n>>m>>q;
	for(int i=0;i<n;i++){
		string s;cin>>s;
		for(int j=0;j<m;j++){
			if(s[j]=='1'){
				suma[i+1][j+1]=1;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(suma[i][j]){
				sumb[i][j]+=suma[i+1][j];
				sumc[i][j]+=suma[i][j+1];
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			suma[i][j]+=suma[i][j-1];
			sumb[i][j]+=sumb[i][j-1];
			sumc[i][j]+=sumc[i][j-1];
		}
	}
	for(int j=1;j<=m;j++){
		for(int i=1;i<=n;i++){
			suma[i][j]+=suma[i-1][j];
			sumb[i][j]+=sumb[i-1][j];
			sumc[i][j]+=sumc[i-1][j];
		}
	}
	while(q--){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		int ans=suma[x2][y2]+suma[x1-1][y1-1]-suma[x1-1][y2]-suma[x2][y1-1];
		ans-=sumb[x2-1][y2]+sumb[x1-1][y1-1]-sumb[x1-1][y2]-sumb[x2-1][y1-1];
		ans-=sumc[x2][y2-1]+sumc[x1-1][y1-1]-sumc[x1-1][y2-1]-sumc[x2][y1-1];
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 49024
def get_color(rating):
    return rating / 400

N = input()
a = map(int, raw_input().split())
colors = [get_color(a[i]) for i in range(N)]

S, cnt = set(), 0
for c in colors:
    if c < 8:
        S.add(c)
    else:
        cnt += 1
print max(len(S), 1), (len(S) + cnt)

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pi 3.14
using namespace std;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<long long,int> pli;
typedef pair<int,long long> pil;
const int INF=1000000007;
const int MOD=1000000007;
const int nmax=401234;

ll h,w,res;

int main()
{
    scanf("%lld%lld",&h,&w);
    if(h==1 || w==1)
        res=1;
    else
    {
        res=w*(h/2);
        if(h%2==1)
            res+=(w+1)/2;
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private void solve(Scanner sc, PrintWriter out) {
        int H = sc.nextInt();
        int W = sc.nextInt();
        sc.nextLine();
        char[][] A = new char[H][W];
        for (int i = 0; i < H; ++i) {
            String s = sc.nextLine();
            for (int j = 0; j < W; ++j) {
                A[i][j] = s.charAt(j);
            }
        }
 
        int cx = 0;
        int cy = 0;
        if (A[cy][cx] != '#') {
            out.println("Impossible");
            return;
        }
        while (cx + 1 < W || cy + 1 < H) {
            if (cy + 1 < H && A[cy + 1][cx] == '#'
            && cx + 1 < W && A[cy][cx + 1] == '#') {
                out.println("Impossible");
                return;
            } else if (cy > 0 && A[cy - 1][cx] == '#'
                || cx > 0 && A[cy][cx - 1] == '#') {
                out.println("Impossible");
                return;
            } else if (cy + 1 < H && A[cy + 1][cx] == '#') {
                A[cy][cx] = '$';
                ++cy;
            } else if (cx + 1 < W && A[cy][cx + 1] == '#') {
                A[cy][cx] = '$';
                ++cx;
            } else {
                out.println("Impossible");
                return;
            }
        }
        A[cy][cx] = '$';
 
        if (debug) {
            for (int i = 0; i < H; ++i) {
                for (int j = 0; j < W; ++j) {
                    System.err.print(A[i][j]);
                }
                System.err.println();
            }
        }
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                if (A[i][j] == '#') {
                    out.println("Impossible");
                    return;
                }
            }
        }
 
        out.println("Possible");
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            System.err.println((G - S) + "ms");
        }
    }
}

Measured memory_bytes: 23764
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);
    static boolean debug = false;

    static int[][] undirectedGraph(int n, int[] v1, int[] v2) {
		int[] cnt = new int[n];
		for (int i : v1) cnt[i]++;
		for (int i : v2) cnt[i]++;

		int[][] g = new int[n][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]];
		for (int i=0; i<v1.length; i++) {
			int s = v1[i];
			int t = v2[i];
			g[s][--cnt[s]] = t;
			g[t][--cnt[t]] = s;
		}

		return g;
	}

    static boolean[] visited;
    static int[][] g;

    static ArrayList<Integer> list = new ArrayList<>();
    static ArrayList<Integer> list2 = new ArrayList<>();

    static void rec(int cur) {
        list.add(cur);
        visited[cur] = true;
        for (int to : g[cur]) {
            if (visited[to]) continue;
            rec(to);
            break;
        }
    }

    static void rec2(int cur) {
        list2.add(cur);
        visited[cur] = true;
        for (int to : g[cur]) {
            if (visited[to]) continue;
            rec2(to);
            break;
        }
    }

    static void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i=0; i<m; i++) {
            a[i] = in.nextInt() - 1;
            b[i] = in.nextInt() - 1;
        }
        g = undirectedGraph(n, a, b);
        visited = new boolean[n];
        rec(0);

        for (int to : g[0]) {
            if (visited[to]) continue;
            rec2(to);
            break;
        }

        ArrayList<Integer> ans = new ArrayList<>();
        for (int i=list2.size()-1; i>=0; i--) {
            ans.add(list2.get(i));
        }
        for (int i=0; i<list.size(); i++) {
            ans.add(list.get(i));
        }

        out.println(ans.size());
        for (int i=0; i<ans.size()-1; i++) {
            out.print((ans.get(i)+1)+" ");
        }
        out.println((ans.get(ans.size()-1)+1));
    }

    public static void main(String[] args) {
        debug = args.length > 0;
        long start = System.nanoTime();

        solve();
        out.flush();

        long end = System.nanoTime();
        in.close();
        out.close();
    }

    static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 85792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _per(i, n) peri(i, 0, n)
#define peri(i, a, n) for (int i = (n) - 1; i >= (a); --i)
#define per(...) _overload3(__VA_ARGS__, peri, _per)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) {is >> p.fi >> p.se; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {os << p.fi << " " << p.se; return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {each(in, v) is >> in; return is;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {rep(i, sz(v)) {os << v[i] << (i + 1 != sz(v) ? " " : "");} return os;}
struct Init {Init() {ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10);}} init;
int main() {
  string S, T;
  cin >> S >> T;
  if (S == T.substr(0, sz(S))) print("Yes");
  else print("No");
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string,int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int nn;
    cin>>nn;
    vector<psi> ls[11];
    ls[0].push_back(make_pair("a",1));
    for (int n = 1; n < nn; n++)
    {
        for (int i = 0; i < ls[n-1].size(); i++)
        {
            auto now = ls[n-1][i];
            for (int j = 0; j < now.second; j++)
            {
                psi next=make_pair(now.first+(char)('a'+j),now.second);
                ls[n].push_back(next);
            }
            psi next=make_pair(now.first+(char)('a'+now.second),now.second+1);
            ls[n].push_back(next);
        }
    }
    
    for (int i = 0; i < ls[nn-1].size(); i++)
    {
        cout<<ls[nn-1][i].first<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 10736
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
#define clr0(n) (memset(n,0,sizeof n))
#define clr1(n) (memset(n,-1,sizeof n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
}
int main()
{
	int n, l;
	cin >> n >> l;
	vector<string>v(n);
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}
	sort(all(v));
	for (int i = 0; i < n; i++)
		cout << v[i];
	cout << endl;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m = inpm()
way = [[] for _ in range(n+1)]
for i in range(m):
    a,b = inpm()
    way[a].append(b)
    way[b].append(a)

ans = [0 for i in range(n+1)]
q = queue.Queue()
q.put((1,0))
while not q.empty():
    room,sign = q.get()
    if ans[room] != 0:
        continue
    ans[room] = sign

    for i in way[room]:
        q.put((i,room))

print('Yes')
for i in range(2,n+1):
    print(ans[i])

Measured memory_bytes: 115864
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);


int main(){
  int N; cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];

  int ans = 0, now = 1;
  for (int i = 0; i < N; i++){
    if (A[i] == now) now++;
    else ans++;
  }
  
  if (ans == N) ans = -1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

//#define ll long long ;
long long int n;
long long int dp[100000][3];
long long int res(long long  int a[],long long int b[],long long int c[], int i,int f)
{
    if(dp[i][f]!=-1)
    {
        return dp[i][f];
    }
    else
    {
        if(f==0)
        {
            return dp[i][f]=max(res(a,b,c,i-1,1)+a[i],res(a,b,c,i-1,2)+a[i]);
        }
        if(f==1)
        {
            return dp[i][f]=max(res(a,b,c,i-1,0)+b[i],res(a,b,c,i-1,2)+b[i]);
        }
        if(f==2)
        {
            return dp[i][f]=max(res(a,b,c,i-1,0)+c[i],res(a,b,c,i-1,1)+c[i]);
        }

    }
}
int main()
{

    cin>>n;
    long long int a[n];
    long long int b[n];
    long long int c[n];

    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        dp[i][0]=-1;
        dp[i][1]=-1;
        dp[i][2]=-1;
    }
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    long long int p=res(a,b,c,n-1,0);
    long long int q=res(a,b,c,n-1,1);
    long long int r=res(a,b,c,n-1,2);
    long long int result=max(p,q);
    result=max(result,r);
    cout<<result<<endl;


}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    string s;cin>>s;
    int cnt=0;
    for(int i=0;i<3;i++){
        if(s[i]=='1')cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3528
#include <iostream>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

int main() {
  short h, w, max = 0;
  char *values;
  queue<tuple<short, short, short>> blacks;

  cin >> h;
  cin >> w;
  values = new char[w * h];
  for (int i = 0; i < h; ++i) {
    string row;
    cin >> row;
    for (int c = 0; c < w; ++c) {
      if (row[c] == '#') {
        values[i * w + c] = 1;
        blacks.emplace(c, i, 0);
      } else {
        values[i * w + c] = 0;
      }
    }
  }

  const auto bounded = [&](short x, short y) {
    return x >= 0 && x < w && y >= 0 && y < h && values[y * w + x] == 0;
  };

  const auto push = [&](short x, short y, short d) {
    blacks.emplace(x, y, d);
    values[y * w + x] = 1;
    max = d;
  };

  while (!blacks.empty()) {
    short x, y, d;
    tie(x, y, d) = blacks.front();
    blacks.pop();

    if (bounded(x - 1, y)) push(x - 1, y, d + 1);
    if (bounded(x + 1, y)) push(x + 1, y, d + 1);
    if (bounded(x, y - 1)) push(x, y - 1, d + 1);
    if (bounded(x, y + 1)) push(x, y + 1, d + 1);
  }

  cout << max << endl;
  return 0;
}


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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF 2000000000
#define int long long
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
int ll[200000],rr[200000];
long long cnt=0;	

int merge(int a[],int l, int m,int r){
  int n1=m-l;
  int n2=r-m;
  lp(i,n1) ll[i]=a[l+i];
  lp(i,n2) rr[i]=a[m+i];
  int i=0,j=0;
  ll[n1]=INF;
  rr[n2]=INF;
  lps(k,l,r){
    if(ll[i]<rr[j]){
      a[k]=ll[i];
      i++;
    }
    else{
      a[k]=rr[j];
      j++;
      cnt+=(long long)n1-(long long)i;
    }
  }
  return cnt;
}

int mergesort(int a[],int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(a,l,m);
    mergesort(a,m,r);
    merge(a,l,m,r);
  }
  else return 0;
}

signed main(){
  int n;
  cin>>n;
  int a[200000];
  lp(i,n){
    cin>>a[i];
  }
  mergesort(a,0,n);
  cout<<cnt<<endl;
  return 0;
}




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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string S; cin >> S;
	if (S[2] == S[3] && S[4] == S[5]) {
		print("Yes");
	} else {
		print("No");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline void fastRead_int(int &x) {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;
    for(; ((c<48 || c>57) && c != '-'); c = getchar_unlocked());
    if(c=='-') {
      neg = 1;
      c = getchar_unlocked();
    }
    for(; c>47 && c<58 ; c = getchar_unlocked())
      x = (x<<1) + (x<<3) + c - 48;
    if(neg)
      x = -x;
}
int main(){
	int n;
	fastRead_int(n);
	int arr[n], cost[n];
	for (int i = 0; i < n; ++i)
		fastRead_int(arr[i]);
	cost[n-1] = 0;
	cost[n-2] = abs(arr[n-2]- arr[n-1]);
	for(int i = n-3; i >= 0; i--)
		cost[i] = min( abs(arr[i]- arr[i+1]) + cost[i+1],abs(arr[i]- arr[i+2]) + cost[i+2]);
	printf("%d\n", cost[0]);	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	char c;
	int s=0;
	while(scanf("%c",&c)!=EOF)
	{
		if(c=='1'||c=='0')
		{
			if(c=='1')s++;
		}
		else break;
	}
	printf("%d\n",s);
	return 0;
}

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

using namespace __gnu_pbds;
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int) (v).size()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define funoredered_map __fast_unordered_map

template<class Key, class Value, class Hash = std::hash<Key>>
using funordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdb = pair< double, double >;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vvi = vector<vi>;

constexpr int inf = 0x3f3f3f3f;
constexpr double eps = 1e-8;
constexpr ll MOD = 1000000007LL;

template <typename T>
using ordered_set = 
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll powmod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// END OF TEMPLATE CODE

int main()
{
    buff(); 
    int h, a;
    cin >> h >> a;
    cout << h / a + !!(h % a) << '\n';
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  int fx = 0;
  int i = 1;
  while(i <= N){
    int ans = 0;
    ans = N / i;
    ans = ans %10;
    i = i * 10;
    fx = fx + ans;
  }
  
  if(N %fx == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
    
}

Measured memory_bytes: 256
n = gets.to_i
otoshidama_ary = []
n.times do
  otoshidama_ary.push(gets.chomp.split(" ").map(&:to_s))
end
sum = 0
otoshidama_ary.each_with_index do |otoshidama, index|
  if otoshidama[1] == "JPY"
    sum += otoshidama[0].to_i
  elsif otoshidama[1] == "BTC"
    sum += otoshidama[0].to_f * 380000.0
  end
end
puts sum

Measured memory_bytes: 1788
import java.util.*;

public class Main {
    static int modP = 1000000007;
    static long inf  = Long.MAX_VALUE;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<Integer, List<E>> map = new HashMap<>();
        for(int i = 0; i < n-1; i++) {
            int a = in.nextInt()-1;
            int b = in.nextInt()-1;
            int c = in.nextInt();

            List<E> leftList = map.containsKey(a) ? map.get(a) : new LinkedList<>();
            E atob = new E(a,b,c);
            leftList.add(atob);
            map.put(a, leftList);
            List<E> rightList = map.containsKey(b) ? map.get(b) : new LinkedList<>();
            E btoa = new E(b,a,c);
            rightList.add(btoa);
            map.put(b, rightList);
        }
        int q = in.nextInt();
        int k = in.nextInt()-1;
        List<Q> queries = new ArrayList<>();
        for(int i = 0; i < q; i++) {
            int x = in.nextInt()-1;
            int y = in.nextInt()-1;
            Q query = new Q(x,y);
            queries.add(query);
        }

        long[] dist = new long[n];
        Arrays.fill(dist, inf);

        dist[k] = 0;
        Stack<Integer> stack = new Stack<>();
        stack.push(k);
        while(!stack.isEmpty()) {
            int currentNode = stack.pop();
            List<E> edges = map.get(currentNode);
            for(E e : edges) {
                if(dist[e.to] != inf) continue;

                stack.push(e.to);
                dist[e.to] = dist[currentNode] + e.w;
            }
        }

        for(int i = 0; i < q; i++) {
            int x = queries.get(i).x;
            int y = queries.get(i).y;
            print(dist[x] + dist[y]);
        }
    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(int i) {
        System.out.println(i);
    }

    static void print(long i) {
        System.out.println(i);
    }
}

class Q {
    int x, y;
    Q(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

class E {
    int from, to;
    long w;
    E(int from, int to, long w) {
        this.from = from;
        this.to = to;
        this.w = w;
    }
}


Measured memory_bytes: 188356
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();        
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        int k = (N-1)*(N-2)/2;
        if(k < K){
            println(-1);
            return;
        } else{
            StringBuilder sb = new StringBuilder();
            int extra = k-K;
            sb.append(N-1+extra);
            sb.append("\n");
            int n = 1;
            final String end = " "+N+"\n";
            for(int i = 1; i < N; i++){
                sb.append(i);
                sb.append(end);
            }
            for(int i = 1; i < N-1 && extra > 0; i++){
                for(int j = i+1; j < N && extra > 0; j++, extra--){
                    sb.append(i);
                    sb.append(" ");
                    sb.append(j);
                    sb.append("\n");
                }
            }
            print(sb);
        }
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21460
#include<iostream>
#include<vector>
#include<cmath>
#include<limits.h>
#include<algorithm>
#include<cstring>
using namespace std;

const long long inf=1e12;

int main()
{
  int n,t;
  cin>>n>>t;
  long long pricesum=0;
  
  vector<int> w(n),p(n);
  for(int i=0;i<n;i++)
  {
    cin>>w[i]>>p[i];
    pricesum+=p[i];
  }
  
  vector<long long> dp(pricesum+1,inf);
  
  dp[0]=0;
  for(int i=1;i<=n;i++)
      {
            for(int j=pricesum;j>=p[i-1];j--)
            {
                dp[j]=min(w[i-1]+dp[j-p[i-1]],dp[j]);      
          	}
      }
      
    long long ans=0;
    for(int j=1;j<=pricesum;j++)
      {
          if(dp[j]<=t)
          {
              ans=j;
          }
      }
    
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

class Main {
	static final long MOD = 1000000007;
	static Node[] node;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		node = new Node[N];
		
		for(int i = 0; i < N; i++) {
			node[i] = new Node();
			char[] in = scan.next().toCharArray();
			if(in[0] == 'E') {
				node[i].isE = true;
			}
			
			if(in[0] == 'A') {
				node[i].isA = true;
			}
			
			if(in[0] == 'R') {
				node[i].isR = true;
			}
			
			if(in.length == 2) {
				node[i].isO = true;
			}
		}
		
		for(int i = 0; i < N-1; i++) {
			int s = scan.nextInt()-1;
			int t = scan.nextInt()-1;
			node[s].child.add(t);
		}
		
		long ans = dfs(0);
		System.out.println(ans);
		
		scan.close();
	}
	
	static long dfs(int id) {
		Node now = node[id];
		long ret = 0;
		if(now.isE) {
			ret = 1;
			for(int i = 0; i < now.child.size(); i++) {
				ret = (dfs(now.child.get(i)) * ret) % MOD;
			}
			
			if(now.isO) ret = (ret + 1) % MOD;
		}
		
		if(now.isA) {
			if(now.isO) {
				ret = 1;
			}
			
			for(int i = 0; i < now.child.size(); i++) {
				ret = (dfs(now.child.get(i)) + ret) % MOD;
			}
		}
		
		if(now.isR) {
			long[] list = new long[now.child.size()];
			
			for(int i = 0; i < now.child.size(); i++) {
				list[i] = dfs(now.child.get(i));
			}
			
			long nn = (list[0]+1);
			
			for(int i = 1; i < list.length; i++) {
				nn = ((list[i]+1) * nn) % MOD;
			}
			
			if(!now.isO) nn--;
			ret = nn;
		}
		
		return ret;
	}
	
	static class Node {
		boolean isE;
		boolean isA;
		boolean isR;
		boolean isO;
		ArrayList<Integer> child = new ArrayList<Integer>();
	}
}

Measured memory_bytes: 34448
#include <bits/stdc++.h>
using namespace std;
int n,t=0,Link[1010],a[1010],f[1010];
bool g[5010];
struct dsa
{
	int v,nex;
}e[1010];
void Insert(int xx,int yy) {e[++t].nex=Link[xx];e[t].v=yy;Link[xx]=t;return;}
bool dfs(int now)
{
	if (!Link[now]) {f[now]=0;return true;}
	int sum=0,s1=0;
	for (int i=Link[now];i;i=e[i].nex) {
		if (!dfs(e[i].v)) return false;
	    sum+=min(f[e[i].v],a[e[i].v]),s1+=f[e[i].v]+a[e[i].v];
	}	
	if (sum>a[now]) return false;
	for (int i=1;i<=a[now];i++) g[i]=false;
	g[0]=true;
	for (int i=Link[now];i;i=e[i].nex) 
	  for (int j=a[now];j>=min(a[e[i].v],f[e[i].v]);j--) {
	      if (j-a[e[i].v]>=0) g[j]|=g[j-a[e[i].v]];
	   	  if (j-f[e[i].v]>=0) g[j]|=g[j-f[e[i].v]];
	  }
	for (int j=a[now];j>=0;j--)
	  if (g[j]) {f[now]=s1-j;break;}
	return true;
} 
int main()
{
	scanf("%d",&n);
	for (int i=2;i<=n;i++) {
		int xx;
		scanf("%d",&xx);
		Insert(xx,i);
	}
	for (int i=1;i<=n;i++) 
	  scanf("%d",&a[i]);
	if (dfs(1)) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

int w, h;
int island[100][100];

void dfs(int x, int y) {
  island[y][x] = 0;

  repi(mat_y, -1, 2) {
    repi(mat_x, -1, 2) {
      if (x + mat_x < 0 || y + mat_y < 0 || x + mat_x >= w || y + mat_y >= h) continue;
      if (island[y + mat_y][x + mat_x]) dfs(x + mat_x, y + mat_y);
    }
  }
}

int main(){
  while (true) {
    cin >> w >> h;
    if (w == 0 && h == 0) break;

    rep(y, h) {
      rep(x, w) {
        cin >> island[y][x];
      }
    }
    int cnt = 0;
    rep(y, h) {
      rep(x, w) {
        if (island[y][x]) {
          ++cnt;
          dfs(x, y);
        }
      }
    }
    cout << cnt << endl;
  }
}


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

int main(){
	
	int n;
	int a,b;
	
	cin >> n ;
	cin >> a >> b ;
	
	int max=b,num=a;
	
	for( int i=1 ; i<n ; i++ ){
		cin >> a >> b ;
		if( max < b ){
			max=b;
			num=a;
		}
		else if( max == b && num > a ) num=a;
	}
	
	cout << num << " " << max << endl ;
	
return 0;
}

Measured memory_bytes: 1164
using System;
namespace ABC085C_Otoshidama
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            string[] inp = Console.ReadLine().Split(' ');
            int n = int.Parse(inp[0]);
            int y = int.Parse(inp[1]);

            bool flag = false;
            for (int i = 0; i <= n; i++)
            {
                for (int j = 0; j <= n-i; j++)
                {
                    for (int k = 0; k <= n-i-j; k++)
                    {
                        //Console.WriteLine($"{i} {j} {k}");
                        if (10000 * i + 5000 * j + 1000 * k == y && i+j+k == n)
                        {

                            flag = true;
                            Console.WriteLine($"{i} {j} {k}");
                            break;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
                if (flag)
                {
                    break;
                }
            }
            if (!flag)
            {
                Console.WriteLine("-1 -1 -1");
            }
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>

int main()
{
	long n, x, temp1, temp2;

	scanf("%ld%ld", &n, &x);

	temp1= n;
	while(x)
	{
		temp2= n;
		n= x;
		x= temp2% x;
	}

	printf("%ld\n", (temp1- n)* 3);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	int e=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]==s[i+1])
		{
			e++;
			break;	
		}
	}
	if(e)
	{
		cout<<"Bad";
	}
	else
	cout<<"Good";
	cout<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double sum =0;
		for (int i=0;i<N;i++) {
			double d= sc.nextDouble();
			String s = sc.next();
			if (s.equals("BTC")) {
				sum +=d*380000.0;
			} else {
				sum +=d;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 37656
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int MOD = 1e9+7;
const int N = 5*1e5;



int main(){
    AC
    int s, w;
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe"<<endl;
    else
        cout<<"safe"<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int n,f[10003],x,y,a[10003];
vector<int>l[10003];
void dfs(int x1,int fa)
{
	f[x1]=0;
	for(int j=0;j<l[x1].size();j++)
		if(l[x1][j]!=fa)
		{
			dfs(l[x1][j],x1);
			if(f[l[x1][j]]==0&&a[x1]>a[l[x1][j]])
				f[x1]=1;
		}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		l[x].push_back(y),l[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
	{
		dfs(i,0);
		if(f[i]==1)
			cout<<i<<" ";
	}
	return 0;
}

Measured memory_bytes: 768
from functools import reduce

n = int(input())

if n == 0:
  print(0)
  exit()

res = []

while True:
  if n == 0:
    break
  if n == 1:
    res.append(1)
    break
  if n%2 == 0:
    res.append(0)
    n //= -2
  else:
    res.append(1)
    n = (n-1)//(-2)


print(reduce(lambda s, x: s + str(x), reversed(res) ,""))


Measured memory_bytes: 3700
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        ll n;cin>>n;
        ll ans=0;
        for(ll i=1;i<=n;i++){
            ans+=(i)*(n-i+1);
        }
        rep(i,n-1){
            ll u,v;cin>>u>>v;
            if(u>v)swap(u,v);
            ans-=((u)*(n-v+1));
        }
        cout<<ans;
    }   
    timecalculater();
    return 0;   
}

Measured memory_bytes: 3672