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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, m;
  vector<vector<int>> g;
  vector<vector<double>> dp, prob;
  Solver2(LL n, LL m) : n(n), m(m), g(n), dp(n, vector<double>(n)), prob(n, vector<double>(n)){};

  void solve() {
    for (int i = 0; i < m; ++i) {
      int s, t;
      cin >> s >> t;
      g[--s].push_back(--t);
    }

    for (int s = 0; s < n; ++s) {
      prob[s][s] = 1.0;
      for (int i = 0; i < n; ++i) {
        int sz = g[i].size();
        for (int j = 0; j < sz; ++j) {
          prob[s][g[i][j]] += (prob[s][i]) / sz;
        }
      }
      for (int i = 0; i < n; ++i) {
        int sz = g[i].size();
        for (int j = 0; j < sz; ++j) {
          dp[s][g[i][j]] += (dp[s][i] + prob[s][i]) / sz;
        }
      }
    }

    double ans = dp[0][n - 1];
    for (int i = 0; i < n; ++i) {
      int s = g[i].size();
      if (s == 1) continue;
      for (int j = 0; j < s; ++j) {
        double tmp = dp[0][n - 1];
        for (int k = 0; k < s; ++k) {
          tmp -= (dp[0][i] / prob[0][i] + 1.0 + dp[g[i][k]][n - 1]) * (prob[0][i] / s);
          if (k != j) {
            tmp += (dp[0][i] / prob[0][i] + 1.0 + dp[g[i][k]][n - 1]) * (prob[0][i] / (s - 1));
          }
        }
        ans = min(ans, tmp);
      }
    }
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 9088
#include <cstdio>
#include <algorithm>
#include <stack>
#include <cmath>
using namespace std;

#define REP(i, n) for(int i = 0;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 llong long long

int main() {
  int d;
  while(scanf("%d", &d) != EOF) {
    int s = 0;
    FOR(i,1,600/d) {
      s += d*(int)pow(i*d,2);
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int main() {



	int i,bb,cc, n,maxc,maxb,max2b,max2c ,a[100000], b[100000] = { 0 }, c[100000] = {0};
	scanf("%d", &n);
	for (i = 0; i < n; i++)scanf("%d", &a[i]);
	for (i = 0; i < n; i++) {
		if (i % 2 == 0) {
			b[a[i]]++;
		
		}
		else c[a[i]]++;
	}
	maxc = b[0];
	maxb = c[0];
	max2b = maxb;
	max2c = maxc;
	for (i = 1; i < 100000; i++) {
		if (maxb < b[i]) {
			max2b = maxb;
			maxb = b[i];
			
			 bb = i;
		}
		else if (max2b < b[i])max2b = b[i];
		if (maxc < c[i]) {
			max2c = maxc;
			maxc = c[i];
			
			 cc = i;
		}
		else if (max2c < c[i])
			max2c = c[i];
	}
	
	
	if (bb != cc)printf("%d", n - maxc - maxb);
	else if (max2b > max2c)printf("%d", n - maxc - max2b);
	else printf("%d", n - maxb - max2c);

	
	

	return 0;

}

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

typedef long long ll;
ll K, N;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin >> N >> K;
    vector<ll> h(N);
    for(ll i=0; i<N; i++){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    ll minh=1e9;
    for(ll i=0; i<N-K+1; i++){
        if(h[i+K-1]-h[i]<minh) minh = h[i+K-1] -h[i];
    }
    cout << minh << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define F first
#define S second
#define mod 1000000007

signed main()
{
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif
	/************************************/
	
	int n, a;
	cin>>n>>a;
	if(2*a <n) cout<<n - 2*a;
	else cout<<"0";
	
	
	
}

Measured memory_bytes: 256
import math
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

def quickSort(arr):
  if len(set(arr)) == 1:
    return arr
  res = []
  pivot = arr[math.floor(len(arr)/2)]
  left = []
  right = []
  center = []
  for i in arr:
    if i < pivot:
      left.append(i)
    elif i > pivot:
      right.append(i)
    else:
      center.append(i)
  if len(left) != 0:
    res = quickSort(left)
  res.extend(center)
  if len(right) != 0:
    res.extend(quickSort(right))
  return res

p = quickSort(p)
print(sum(p[:K]))

Measured memory_bytes: 9220
N = int(input())
A = [int(i) for i in input().split()]
MOD = 10 ** 9 + 7

sum_mod = 0
for v in A:
    sum_mod += v
    sum_mod %= MOD

ans = 0
for v in A:
    sum_mod -= v
    if sum_mod < 0:
        sum_mod = MOD + sum_mod
    ans += ((v * sum_mod) % MOD)
    ans %= MOD

print(ans)

Measured memory_bytes: 94248
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  string S;
  cin>>S;
  int X=0;
  rep(i,4){
    if(S[i]=='+') X++;
    else X--;
  }
  cout<<X<<endl;
}

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

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

    int n;
    cin>>n;
    int mn = 1e9, ans = 0;
    for (int i=1; i<=n; i++) {
        int x;
        cin>>x;
        mn = min(mn, x);
        if (x == mn)    ans++;
    }
    cout<<ans<<endl;
}

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

     int arr[n];
     for(int i=0;i<n;i++)
       cin>>arr[i];



       int value1,value2;

        for(int i=0;i<n;i++)
        {
           if(i==0)
           {
             value1=arr[i];
             value2=arr[i];
           }
           else
           {
              if(value1 > arr[i])
              value1=arr[i];

              if(value2 < arr[i])
              value2=arr[i];
           }
        }
        long long int sum=0;
        for(int i=value1;i<=value2;i++)
        {
           long long int final=0;
           for(int j=0;j<n;j++)
           final+=(arr[j]-i)*(arr[j]-i);

             if(i==value1)
             sum = final;

             else{
               if(final < sum)
                sum = final;
             }
        }
        cout<<sum;
}


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

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define vi vector<int>
#define vvi vector<vi>

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;






int main(){

        int n;
        cin >> n;
        vi a(n), b(n), c(n);

        for(int i = 0; i < n; i++){
                cin >> a[i];
        }
        for(int i = 0; i < n; i++){
                cin >> b[i];
        }
        for(int i = 0; i < n; i++){
                cin >> c[i];
        }

        sort(all(a));
        sort(all(b));
        sort(all(c));

        ll ans = 0;

        for(ll i = 0; i < n; i++){
                ll x = (lower_bound(all(a), b[i]) - a.begin());
                ll y = (n - (upper_bound(all(c), b[i]) - c.begin()));

                ans += x * y;
        }

        cout << ans << endl;

        return 0;


}












Measured memory_bytes: 1536
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	Scanner scan=new Scanner(System.in);
	while(true)
	    {
		int h,w;
		h=scan.nextInt();
		w=scan.nextInt();
		if(h==0 && w==0)break;
		char t[][]=new char[h][w];
		int count[][]=new int[h][w];
		for(int i=0;i<h;i++)
		    {
			String str=scan.next();
			for(int j=0;j<w;j++)
			    {
				t[i][j]=str.charAt(j);
			    }
		    }
		int i=0,j=0;
		while(true)
		    {
		    if(t[i][j]=='>')
			{
			    count[i][j]++;
			    j++;
			}
		    else if(t[i][j]=='<')
			{
			    count[i][j]++;
			    j--;
			}
		    else if(t[i][j]=='^')
			{
			    count[i][j]++;
			    i--;
			}
		    else if(t[i][j]=='v')
			{
			    count[i][j]++;
			    i++;
			}
		    else if(t[i][j]=='.')
			{
			    System.out.println(j+" "+i);
			    break;
			}
		    if(count[i][j]==1)
			{
			    System.out.println("LOOP");
			    break;
			}
		    }
		
	    }
    }
}

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

int main(){
while(1){
	int n,x;
	cin>>n>>x;
	if(n==0 && x==0) break;
	int ans=0;
	for(int a=1;a<=n;a++){
	for(int b=a+1;b<=n;b++){
	for(int c=b+1;c<=n;c++){
	if(a+b+c !=x) continue;
	ans++;
	}}}
	cout<<ans<<endl;
	}
  return 0;
}


Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
ll A[200000];
ll B[200000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
	bool same = 1;
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] != B[i]) same = 0;
		sum += A[i];
	}
	if (same) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] > B[i]) {
			ans = max(ans, sum - A[i] + (A[i] - B[i]));
		}
	}
	cout << ans << endl;
}

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

vector<int> operator * (const vector<int> &a, const vector<int> &b){
	vector<int> c(a.size());
	for(int i = 0; i < a.size(); i++) c[i] = b[a[i]];
	return c;
}
vector<int> inv(const vector<int> &a){
	vector<int> b(a.size());
	for(int i = 0; i < a.size(); i++) b[a[i]] = i;
	return b;
}

char neg(char x){
	if(x == 'A') x = 'a';
	else if(x == 'a') x = 'A';
	else if(x == 'B') x = 'b';
	else if(x == 'b') x = 'B';
	else assert(false);
	return x;	
}

string inverse(string s){
	reverse(s.begin(), s.end());
	for (char& x : s){
		x = neg(x);
	}
	return s;
}

string process(string s){
	string z;
	for(char x : s){
		if(!z.empty() && z.back() == neg(x)){
			z.pop_back();
		} else {
			z += x;
		}
	}
	return z;
}

void test(){
	string x = "A";
	string y = "B";
	for(int j = 3; j < 100; j++){
		string z = process(inverse(x) + y);
		cout << j << " " << z << endl;
		x = y; y = z;
	}
	exit(0);
}

vector<int> bf(vector<int> p, vector<int> q, int k){
	if(k == 1) return p;
	for(int b = 2; b < k; b++){
		p = inv(p) * q;
		swap(p, q);
	}
	return q;
}

vector<int> expo(vector<int> p, int n){
	if(n == 0) return p * inv(p);
	if(n & 1) return p * expo(p, n-1);
	return expo(p*p, n/2);
}

vector<int> solve(vector<int> p, vector<int> q, int k){
	if(k <= 10) return bf(p, q, k);
	int c = (k - 4) / 6;
	vector<int> lhs = inv(q) * p * q * inv(p);
	vector<int> rhs = inv(lhs);
	return expo(lhs, c) * solve(p, q, k - c * 6) * expo(rhs, c);
}


int main(){
	cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> p(n), q(n);
	for(int i = 0; i < n; i++) cin >> p[i];
	for(int i = 0; i < n; i++) cin >> q[i];
	for(int i = 0; i < n; i++) p[i]--, q[i]--;
	vector<int> ans;
	ans = solve(p, q, k);
	//assert(ans == bf(p, q, k));
	for(int r = 0; r < n; r++){
		cout << ans[r] + 1 << ' ';
	}
	cout << '\n';
}

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

int a,b,c,d,e,k;
cin>>a>>b>>c>>d>>e>>k;
cout<<(e-a <= k ?"Yay!" : ":(" );
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	int x = 0;char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	return x;
}
inline void write(int x){
	if (!x){
       ptc('0');
       return;
	}
	int dg[20] , len = 0;
	while (x) dg[len++] = x % 10 , x /= 10;
	while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	write(x);
	ptc('\n');
}
inline int add(int x,int y){
	x += y;if (x >= mod) x -= mod;
	return x;
}
inline int sub(int x,int y){
	x -= y;if (x < 0) x += mod;
	return x;
}
inline int qpow(int x,int y){
	int res = 1;
	while (y){
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;y >>= 1;
	}
	return res;
}

const int N = 610;
int link[N] , dp[N][N] , g[N];
int n , k , ans;

int in(int l,int r,int pos){
	return pos <= r && l <= pos;
}

int main(){
	scanf("%d%d",&n,&k);
	n <<= 1;
	k <<= 1;
	memset(link , -1 , sizeof link);
	for (int i = 1;i <= k >> 1;i++){
		int u , v;scanf("%d%d",&u,&v);
		u--;v--;
		link[u] = v;
		link[v] = u;
	}
	
	g[0] = 1;for (int i = 2;i <= n;i += 2) g[i] = 1ll * (i - 1) * g[i - 2] % mod;
	
	for (int len = 1;len <= n;len++){
		for (int i = 0;i < n - len + 1;i++){
			int j = (i + len - 1) % n;
			assert(j >= i);
			int free = 0;
			for (int k = i;k <= j;k++){
				if (link[k] != -1 && !in(i , j , link[k])) {
					free = 1;
					break;
				}
				free += link[k] == -1;					
				if (k == j) break;
			}
			if (free & 1) continue;
			dp[i][j] = g[free];
			for (int k = i , cnt = link[i] == -1;k < j;k++ , cnt += link[k] == -1){
				dp[i][j] = sub(dp[i][j] , 1ll * dp[i][k] * g[free - cnt] % mod);
			}
			
//			printf("%d %d %d %d\n",i,j,dp[i][j],free);
		}
	}
	
	for (int i = 0;i < n;i++){
		for (int j = i;j < n;j++)if (dp[i][j]){
			
			int free = 0;
			for (int k = i;k <= j;k++){
				free += link[k] == -1;					
			}
			free = n - k - free;
			ans = add(ans , 1ll * dp[i][j] * g[free] % mod);
		}
	}
	cout<<ans;
	return 0;
}
 


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int c = values[a];
			values[a] = values[b];
			values[b] = c;
		}
		for (int i = 0; i < values.length; i++) {
			System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 26128
import java.util.*


fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    var N: Long
    N = sc.nextLong()
    var K: Long
    K = sc.nextLong()
    var S: String
    S = sc.next()
    solve(N, K, S)
}

fun solve(N: Long, K: Long, S: String) {
    val cs = S.toCharArray()
    cs[(K - 1).toInt()] = cs[(K - 1).toInt()].toLowerCase()
    println(cs)
}



Measured memory_bytes: 31256
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int number;
	int katiten;
	int zyuni;
} team_t;

int comp(const void* x,const void* y) {
	team_t* a=(team_t*)x;
	team_t* b=(team_t*)y;
	if(a->katiten<b->katiten)return 1;
	if(a->katiten>b->katiten)return -1;
	return 0;
}

int main(int argc,char* argv[]) {
	int score[100][100];
	team_t team[100];
	int zyuni[100];
	int i,j;
	int N;
	int gamemax;
	int teamA,teamB,scoreA,scoreB;
	for(i=0;i<100;i++) {
		for(j=0;j<100;j++) {
			if(i==j)score[i][j]=0; else score[i][j]=1;
		}
	}
	scanf("%d",&N);
	gamemax=N*(N-1)/2;
	for(i=0;i<gamemax;i++) {
		scanf("%d %d %d %d",&teamA,&teamB,&scoreA,&scoreB);
		teamA--;
		teamB--;
		if(scoreA>scoreB) {
			/*teamA won teamB*/
			score[teamA][teamB]=3;
			score[teamB][teamA]=0;
		} else if(scoreA<scoreB) {
			/*teamB won teamA*/
			score[teamA][teamB]=0;
			score[teamB][teamA]=3;
		}
	}
	for(i=0;i<N;i++) {
		team[i].number=i;
		team[i].katiten=0;
		for(j=0;j<N;j++) {
			team[i].katiten+=score[i][j];
		}
	}
	qsort(team,N,sizeof(team_t),comp);
	team[0].zyuni=1;
	for(i=1;i<N;i++) {
		if(team[i].katiten<team[i-1].katiten) {
			team[i].zyuni=i+1;
		} else {
			team[i].zyuni=team[i-1].zyuni;
		}
	}
	for(i=0;i<N;i++) {
		zyuni[team[i].number]=team[i].zyuni;
	}
	for(i=0;i<N;i++) {
		printf("%d\n",zyuni[i]);
	}
	return 0;
}

Measured memory_bytes: 0
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>

using namespace std;
 
typedef long long i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	i64 from, to, cost;
	edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
	edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

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

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

#pragma endregion

int t[3] = {3, 5, 7};
string n;

int rec(int k, bool flag, vector<bool> flags){
	if(k == n.length()){
		int cnt = 0;
		for(int i = 0; i < 3; ++i) if(flags[i]) cnt++;
		if(cnt == 3) return 1;
		else return 0;
	}
	int sum = 0;
	if(flag){
		for(int i = 0; i < 3; ++i){
			vector<bool> tmp = flags;
			tmp[i] = true;
			sum += rec(k + 1, true, tmp);
		}
	}else{
		for(int i = 0; i < 3; ++i){
			vector<bool> tmp = flags;
			tmp[i] = true;
			if((n[k] - '0') > t[i]){
				sum += rec(k + 1, true, tmp); 
			}else if((n[k] - '0') == t[i]){
				sum += rec(k + 1, false, tmp);
				break;
			}
		}
	}
	return sum;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	vector<bool> flag(3, false);
	int ans = 0;
	for(int i = 0; i < n.length() - 1; ++i){
		if(i == 0) ans += rec(i, false, flag);
		else ans += rec(i, true, flag);
	}
	cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int w, h;
vector<vector<bool>> mp;


vector<pair<int,int>> dir{{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}};

void dfs(int y, int x)
{
    for(auto i : dir){
        if(mp[y + i.first][x + i.second]){
            mp[y + i.first][x + i.second] = false;
            dfs(y + i.first, x + i.second);
        }
    }
}


int main()
{
    vector<int> AS;
    while(1){
        cin >> w >> h;
        if(!w && !h)break;
        mp.resize(h + 2,vector<bool>(w + 2));
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                int t; cin >> t;
                mp[i][j] = t;
            }
        }

        int ans = 0;
        for(int i = 1; i <= h; i++){
            for(int j = 1; j <= w; j++){
                if(mp[i][j]){
                    mp[i][j] = false;
                    dfs(i, j);
                    ans++;
                }
            }
        }
        AS.push_back(ans);
    }
    for(auto i : AS)cout << i << endl;
}


Measured memory_bytes: 3180
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 各日に対して、関数：残量 -> 最適な熱量 を持つことを考える
# これは折れ線。傾きが増加する部分 → マージしてまとめる
# 常に、傾きの減少列の形で持つことになる

from collections import deque

N,L = map(int,readline().split())
m = map(int,read().split())
TV = zip(m,m)

answer = []
INF = 10 ** 18

# 1日目
t,v = next(TV)
print(t)
qT = deque([t])
qV = deque([v])
sum_q = t * v # 今持っている総熱量

for t,v in TV:
    qT.appendleft(t); qV.appendleft(v)
    sum_q += t * v
    # 右側からvだけ捨てる
    rest = v
    while qV[-1] <= rest:
        x = qV.pop()
        rest -= x
        sum_q -= x * qT.pop()
    qV[-1] -= rest
    sum_q -= rest * qT[-1]
    # 左側から傾きの増大部分をマージ
    while len(qT) >= 2:
        t0 = qT[0]; t1 = qT[1]
        if t0 > t1:
            break
        qT.popleft()
        v0 = qV.popleft(); v1 = qV[0]
        t2 = (t0 * v0 + t1 * v1) / (v0 + v1)
        qT[0] = t2; qV[0] += v0
    print(sum_q/L)

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

using namespace std;

#define ll long long




void solve() {

	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int cnt = 0;
	for(int i = 1; i < n - 1; i++) {
		int mx = max(arr[i], max(arr[i - 1], arr[i + 1]));
		int mn = min(arr[i], min(arr[i - 1], arr[i + 1]));
		if(arr[i] != mx && arr[i] != mn) {
			cnt++;
		}
	}
	cout << cnt;

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const long long MOD = 1000000007;
const int MAX_N = 100000;
int n,k;
vi g[MAX_N];

long long perm(long long a, long long b) {
  if (a < b) return 0;
  long long num = 1;
  for (int i = 1; i <= b; i++) {
    num = num * (a-i+1) % MOD;
  }
  return num;
}

ll dfs(int u, int p = -1) {
  ll c = k-(p<0?0:1)-1;
  ll t = perm(c,g[u].size()-(p<0?0:1));
  //printf("u=%d p=%d c=%lld t=%lld\n",u,p,c,t);
  for (int v : g[u]) {
    if (p == v) continue;
    t = t * dfs(v,u) % MOD;
  }

  return t;
}


int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n >> k;

  forn(i,n-1) {
    int a,b; cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  cout << k*dfs(0)%MOD << endl;

  return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_set>
using namespace std;
//#define long long ll

int main() {
	int n;
	cin >> n;
	string s1, s2;
	s1 = "";
	s2 = "";
	bool rev = false;
	while (true) {
		string n1, n2;
		bool ok = false;
		for (int i = 0; i < 4; ++i) {
			if (i & 1)
				n1 = (rev ? '#' + s1 : s1 + '#');
			else
				n1 = (rev ? '.' + s1 : s1 + '.');
			if (i & 2)
				n2 = (rev ? '#' + s2 : s2 + '#');
			else
				n2 = (rev ? '.' + s2 : s2 + '.');
			cout << n1 << '\n' << n2 << '\n';
			cout.flush();
			string res;
			cin >> res;
			if (res == "end")
				return 0;
			if (res == "T") {
				ok = true;
				break;
			}
		}
		if (!ok)
			rev = true;
		else {
			s1 = n1;
			s2 = n2;
		}
	}
	return 0;
}

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

int main(){
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  
  vector<long long> A(a);
  vector<long long> B(b);
  vector<long long> C(c);

  for(auto &v: A) cin >> v;
  for(auto &v: B) cin >> v;
  for(auto &v: C) cin >> v;
  
  sort(A.begin(), A.end(), greater<int>());
  sort(B.begin(), B.end(), greater<int>());

  for(int i = 0; i < x; i++)
    C.push_back(A[i]);

  for(int i = 0; i < y; i++)
    C.push_back(B[i]);

  sort(C.begin(), C.end(), greater<int>());

  long long res = 0;
  for(int i = 0; i < (x+y); i++)
    res += C[i];

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 6000
#include <cstdio>

int main(){
    char s[11];
    scanf("%s",s);
    int countls = 0;
    for(int i = 0; i < 11; i++){
        if('A' <= s[i] && s[i] <= 'z'){
            countls++;
        }
    }
    bool checks[countls];
    for(int i = 0; i < countls; i++){
        checks[i] = true;
        if(i == 0){
            checks[i] = false;
        }
    }
    int countC = 0;
    for(int i = 2; i < countls - 1; i++){
        if(s[i] == 'C'){
            countC++;
            checks[i] = false;
        }
    }

    if(s[0] == 'A' && countC == 1){
        for(int i = 1; i < countls; i++){
            if(checks[i]){
                if('a' <= s[i] && s[i] <= 'z'){
                    continue;
                }else{
                    printf("WA\n");
                    
                    return 0;
                }
            }
        }
        printf("AC\n");
    }else{
        printf("WA\n");
    }

    return 0;
}

Measured memory_bytes: 128
S = input()

while len(S) > 0:
  if (len(S) >= 5):
    if (S[-5:] == 'dream' or S[-5:] == 'erase'):
      S = S[:-5]
      continue
  if (len(S) >= 6):
    if (S[-6:] == 'eraser'):
      S = S[:-6]
      continue
  if (len(S) >= 7):
    if (S[-7:] == 'dreamer'):
      S = S[:-7]
      continue
  break
if (len(S) == 0):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 134300
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,e,f,g,h,i,real[1000],update[1000];
    vector<int>v;
    string s,t;
    while(cin>>a)
    {

      for(b=1;b<=a;b++)
      {
          cin>>real[b];
          update[b]=0;
      }
      c=0;
      while(1)
      {
          d=0;
          f=0;

          for(b=1;b<=a;b++)
          {
              if(update[b]<real[b]&&d==0)
              {
                  d=1;
                  e=b;
                  f=1;
                  update[b]++;
              }
              else if(update[b]<real[b]&&d==1)
              {
                  if(b-1==e)
                  {
                      update[b]++;
                      e=b;
                  }
                  else
                  {
                      d=0;
                      break;
                  }
              }

          }
          if(f==0)
          {
              break;
          }
          c++;


      }
      cout<<c<<endl;

    }






    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
l = {int(input()) for _ in range(m)}
if (n == 1):
    print(1)
else:
    p = 10**9+7
    f = [0] * (n + 1)
    f[0], f[1] = 1, 0 if 1 in l else 1
    for i in range(1, n+1):
        if not i in l:
            f[i] = (f[i - 1] + f[i - 2]) % p

    print(f[n])


Measured memory_bytes: 11884
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


x=int(input())
ans=float('inf')

for i in make_divisors(x):
  a,b=i,x//i
  a,b=str(a),str(b)

  ans=min(ans,max(len(a),len(b)))


print(ans)


Measured memory_bytes: 68036
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      w: usize,
      h: usize,
      n: usize,
      xyas: [(usize, usize, usize); n],
    }

    let mut map = vec![vec![0; h]; w];
    for (x, y, a) in xyas {
        if a == 1 {
            for i in 0..x {
                for j in 0..h {
                    map[i][j] = 1;
                }
            }
        } else if a == 2 {
            for i in x..w {
                for j in 0..h {
                    map[i][j] = 1;
                }
            }
        } else if a == 3 {
            for j in 0..y {
                for i in 0..w {
                    map[i][j] = 1;
                }
            }
        } else if a == 4 {
            for j in y..h {
                for i in 0..w {
                    map[i][j] = 1;
                }
            }
        }
    }

    let mut ans = 0;
    for i in 0..w {
        for j in 0..h {
            if map[i][j] == 0 {
                ans += 1;
            }
        }
    }
    puts!("{}\n", ans);
}


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

using ll = long long;

const int MOD = 1000000007;

const int size = 100005;

void Break()
{
#if _MSC_VER
	static int x = 0;
	++x;
	switch (x)
	{
		__debugbreak();
	}
#endif
}

bool dp[size];

int main()
{
#if _MSC_VER
	freopen("input.txt", "r", stdin);
#endif
	int n, k;
	std::cin >> n >> k;
	std::vector<int> v(n);
	for (int& x : v)
	{
		std::cin >> x;
	}
	for (int i = 0; i <= k; ++i)
	{
		for (int x : v)
		{
			if (i >= x && !dp[i - x])
			{
				dp[i] = true;
			}
		}
	}
	if (dp[k])
	{
		std::cout << "First\n";
	}
	else
	{
		std::cout << "Second\n";
	}
	return 0;
}

Measured memory_bytes: 3688
import scala.io.Source

object Main{
  def main(args: Array[String]){
    val line =
      for{
        in <- Source.stdin.getLines.toList
      } yield in.map(_.toLower)

      val atoz = 'a' to 'z'
      val filteredSting = line.mkString.map(_.toLower).filter(atoz.contains(_))
      println((filteredSting + atoz.mkString).groupBy(n => n).toList.sorted.map{
        case (k,v) => s"$k : ${v.length - 1}"
      }.mkString("\n"))
  }
}

Measured memory_bytes: 44964
N = int(input())
N = N % 10
if  N == 2 or N == 4 or N == 5 or N == 7 or N == 9:
    print("hon")
elif N == 0 or N == 1 or N == 6 or N == 8:
    print("pon")
else:
    print("bon")
  

Measured memory_bytes: 9148
function Main(input){ 
  var inputs = input.split(" ");
  var A = parseInt(inputs[0],10);
  var B = parseInt(inputs[1],10);
  if(Number.isInteger(B/A)==true){
    console.log(A+B);
  }else{
    console.log(B-A);
  }

  
}
    Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 21064
#!/usr/bin/env python3
import sys


class UnionFind():
    def __init__(self, n):
        self.parents = list(range(n))

    def find(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.parents[y] = x


def main():
    N, M = map(int, input().split())
    a = [None] * M
    b = [None] * M
    for i in range(M):
        a[i], b[i] = map(int, input().split())

    ans = 0
    for i in range(M):
        # a[i], b[i] 以外を使ってUnionFind木を作り
        # グラフ全体が非連結になるなら橋
        uf = UnionFind(N)
        for j in range(M):
            if i != j:
                uf.union(a[j]-1, b[j]-1)

        p = uf.find(0)
        for k in range(1, N):
            if p != uf.find(k):
                ans += 1
                break
    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
        string s;
        cin >> s;
        int k;
        cin >> k;
        set<char> S;
        for (int i = 0; i < s.size(); ++i)
                S.insert(s[i]);
        if (S.size() == 1)
        {
                cout << 1ll * k * (int)(s.size()) / 2 << endl;
                return 0;
        }
        if (s.size() == 1)
        {
                cout << k / 2 << endl;
                return 0;
        }
        string t = s;
        int ans1 = 0, ans2 = 0;
        for (int i = 0; i < t.size();)
        {
                int cnt = 1;
                while (i + cnt < t.size() and t[i] == t[i + cnt])
                        ++cnt;
                i = i + cnt;
                ans1 += cnt / 2;
        }
        t = s + s;
        for (int i = 0; i < t.size();)
        {
                int cnt = 1;
                while (i + cnt < t.size() and t[i] == t[i + cnt])
                        ++cnt;
                i = i + cnt;
                ans2 += cnt / 2;
        }
        long long ans = 1ll * (k - 1) * (ans2 - ans1) + ans1;
        //cout << ans1 << " " << ans2 << endl;
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
want = [0,0,0]
ans = []
N,want[0],want[1],want[2] = map(int,input().split())
L = []
for _ in range(N):
    L.append(int(input()))

table = [0,1,2,-1]
import itertools as it
c = list(it.product(table, repeat=N))
for x in c:
    A = 0
    B = 0
    C = 0
    cnt = -3
    z = list(zip(x,L))
    for y in z:
        if y[0] == 0:
            A += y[1]
            cnt += 1
        elif y[0] == 1:
            B += y[1]
            cnt += 1
        elif y[0] == 2:
            cnt += 1
            C += y[1]
        else:
            pass
    if A*B*C == 0:
        continue
    ans.append(abs(A-want[0])+abs(B-want[1])+abs(C-want[2])+cnt*10)
print(min(ans))

Measured memory_bytes: 12932
#include<bits/stdc++.h>
/* #define int long long */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;


signed main() {
    int d;
    int n;
    cin >> d >> n;
    int ans;
    if(n == 100) n++;
    if(d == 0) cout << n << endl;
    else if(d == 1) cout << n * 100 << endl;
    else cout << n * 10000 << endl;

    // cout << cnt << endl;
}


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

using ll = long long;

#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 ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  vi vec(4); rep(i, 4) vec[i] = s[i]-'0';
  rep(i, 1 << 3) {
    int result = vec[0];
    rep(j, 3) {
      if ((i >> j) & 1) {
        result -= vec[j+1];
      } else {
        result += vec[j+1];
      }
    }
    if (result == 7) {
      rep(j, 3) {
        std::cout << vec[j] << ((i>>j) & 1 ? '-' : '+');
      }
      std::cout << vec[3] << "=7\n";
      return 0;
    }
  }
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d", $N, $x);
$max = $N*2-1;
$min = 1;
if($x == $max || $x == $min){
    echo "No\n";    
}else{
    echo "Yes\n";
    if($N == 2){
        echo "1\n2\n3\n";exit;
    }
    if($x == $N*2-2){
        $array = [$x-1, $x, $x+1, $x-2];
    }else{
        $array = [$x+1, $x, $x-1, $x+2];
    }
    for($i = 1; $i <= $N * 2 - 1; $i++){
        $map[$i] = true;
    }
    foreach($array as $a){
        unset($map[$a]);
    }
    $map = array_keys($map);
    for($i = 0; $i < $N-2; $i++){
        $result[] = array_pop($map);
    }
    foreach($array as $a){
        $result[] = $a;
    }
    for($i = 0; $i < $N-1; $i++){
        $result[] = array_pop($map);
    }
    echo implode("\n", $result),"\n";
}


Measured memory_bytes: 24176
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L = sc.nextInt();
		String[] S = new String[N];
		for(int i = 0; i < N; i ++){
			S[i] = sc.next();
		}

		Arrays.sort(S);
		for(int i = 0; i < N; i ++){
			System.out.print(S[i]);
		}


	}
}

Measured memory_bytes: 37480
#include<bits/stdc++.h>
using namespace std;
string x="Positive\n",y="Negative\n",z="Zero\n";
inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
int main(){
	int a=read(),b=read();
	if(a<=0&&b>=0)
		cout<<z;
	else if(a>0&&b>0)
		cout<<x;
	else if(a<0&&b<0){
		int s=abs(a-b)+1;
		if(s%2)
		cout<<y;
		else cout<<x;
	}
	return 0;
}

Measured memory_bytes: 256
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  string s;
  cin >> s;
  int a[256] = {};
  each(c, s) {
    a[c]++;
  }

  each(i, a) {
    if (i > 1) {
      print("no");
      return 0;
    }
  }
  print("yes");
}


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

using namespace std;

typedef long long ll;

const int nax = 9;
const int MOD = 1e9+7;

int a,b,c,n;
vector<int> v(nax);

int dfs(int ind, int p, int q, int r){
    if(ind==n){
        if(min({p,q,r})>0){
            return (abs(a-p)+abs(b-q)+abs(c-r) - 30);
        }
        else{
            return MOD;
        }
    }
    int ans1 = dfs(ind+1, p,q,r);
    int ans2 = dfs(ind+1, p+v[ind], q,r)+10;
    int ans3 = dfs(ind+1, p, q+v[ind],r)+10;
    int ans4 = dfs(ind+1, p,q, r+v[ind])+10;
    return min({ans1, ans2, ans3, ans4});
}

int main(){
    cin>>n>>a>>b>>c;

    v.assign(n, 0);

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

    int ans = dfs(0,0,0,0);

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
vector<long long int>cs;
long long int memo[4010][4010][2];
int N;
long long int getans(const int l, const int r,const long long int rest,bool isj) {
	if (l >= N&&r >= N)return getans(l - N, r - N,rest,isj);
	assert(l <= r);
	if (l == r)return 0;
	if (memo[l][r][isj] != -1)return memo[l][r][isj];
	long long nans = 0;
	if (isj||cs[l] >= cs[r - 1]) {
		nans = max(nans, rest - getans(l + 1, r, rest - cs[l], !isj));
	}
	if (isj || cs[l] <= cs[r - 1]) {
		nans = max(nans, rest - getans(l, r - 1, rest - cs[r - 1], !isj));
	}
	return memo[l][r][isj] = nans;
}

int main() {
	for (int i = 0; i < 4010; ++i) {
		for (int j = 0; j < 4010; ++j) {
			for (int k = 0; k < 2; ++k) {
				memo[i][j][k] = -1;
			}
		}
	} cin >> N; cs.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> cs[i];
	}
	cs.insert(cs.end(), cs.begin(), cs.end());
	long long int sum = accumulate(cs.begin(), cs.end(), 0ll)/2;
	long long int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = max(ans ,sum- getans(i+1, i+N,sum-cs[i],false));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 254576
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n = I()
A = LI()


ans = 1
color = [0, 0, 0]
for i in range(n):
    ans = ans * color.count(A[i]) % mod
    for j in range(3):
        if color[j] == A[i]:
            color[j] += 1
            break



print(ans)






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

#define ndot first
#define idx second

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const int MAX_N = 500;
const int INF = 0x3f3f3f3f;

vi rows[MAX_N];
vii r_cnt;
int c_cnt[MAX_N] = {0};
bool c_exist[MAX_N];

int main() {
  int N;
  string s;
  bool isNG = true;
  cin >> N;
  for (int i=0; i<N; i++) {
    c_exist[i] = false;
  }
  for (int i=0; i<N; i++) {
    cin >> s;
    int cnt = 0;
    for (int j=0; j<N; j++) {
      int tmp = (s[j] == '.' ? 0 : 1);
      if (tmp == 1) {
        c_exist[j] = true;
        c_cnt[j]++;
        isNG = false;
      }
      cnt += (1 - tmp);
      rows[i].push_back(tmp);
    }
    r_cnt.push_back(make_pair(cnt, i));
  }
  if (isNG) {
    cout << "-1" << endl;
    return 0;
  }

  int ans = MAX_N * MAX_N;
  // sort(r_cnt.begin(), r_cnt.end());
  for (vii::iterator it=r_cnt.begin(); it!=r_cnt.end(); ++it) {
    int tmp = 0;
    if (!c_exist[it->idx]) tmp = 1;;
    tmp += it->ndot * 2;
    for (int j=0; j<N; j++) {
      if (rows[it->idx][j] == 1 && c_cnt[j] != N) {
        tmp++;
      }
    }
    // cout << it->idx+1 << ", " << it->ndot << " -> " << tmp << endl;
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<iostream>

using namespace std;

int c[100010],p[100010];
bool vis[100010];
int n,d,g,ans=(1<<30),ans1;

void find()
{
	int sum,ans1;
	sum=ans1=0;
	for(int i=1;i<=d;i++){
		if(vis[i]){
			ans1+=c[i];
			sum+=p[i]+c[i]*100*i;
		}
	}
	if(sum>=g){
		ans=min(ans1,ans);
		return ;
	}
	for(int i=d;i;i--){
		if(vis[i])continue;
		int t=c[i];
		while(t>1){
			t--;
			ans1++;
			sum+=100*i;
			if(sum>=g){
				ans=min(ans1,ans);
				return ;
			}
		}
	}
}

void dfs(int x){
	if(x==d+1){
		find();return ;
	}
	vis[x]=1;dfs(x+1);
	vis[x]=0;dfs(x+1);
}

int main()
{
	scanf("%d%d",&d,&g);
	for(int i=1;i<=d;i++){
		scanf("%d%d",&c[i],&p[i]);
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

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

int main()
{
  ll a, b;

  while(cin>>a>>b && a+b){
    cout << gcd(a, b) << endl;
  }

  return 0;
}

Measured memory_bytes: 0