akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

const int INF = 1e9;
const int MAX_N = 2000;

struct edge { int to, cost; };

int n;
vector<edge> g[MAX_N];
int d[MAX_N][MAX_N];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d[s], d[s] + n, INF);
    d[s][s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[s][v] < p.first) continue;
        for (int i = 0; i < g[v].size(); i++) {
            edge e = g[v][i];
            if (d[s][e.to] > d[s][v] + e.cost) {
                d[s][e.to] = d[s][v] + e.cost;
                que.push(P(d[s][e.to], e.to));
            }
        }
    }
}

int main() {
    int x, y;
    cin >> n >> x >> y;
    x--; y--;
    edge e;
    e.to = y, e.cost = 1;
    g[x].push_back(e);
    e.to = x;
    g[y].push_back(e);
    for (int i = 0; i < n - 1; i++) {
        e.to = i + 1;
        g[i].push_back(e);
        e.to = i;
        g[i + 1].push_back(e);
    }
    for (int i = 0; i < n; i++) dijkstra(i);
    int t[n][n];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) t[i][j] = d[i][j];
        sort(t[i], t[i]+n);
    }
    for (int i = 1; i <= n - 1; i++) {
        ll ans = 0;
        for (int j = 0; j < n; j++) {
            ans += upper_bound(t[j], t[j]+n, i) - lower_bound(t[j], t[j]+n, i);
        }
        ans /= 2;
        cout << ans << endl;
    }
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  if (n == k) {
    ans = 0;
  } else if (n < k) {
    ll num = abs(n-k);
    ans = min(n, num);
  } else {
    ll num = n%k;
    if (num == 0) {
      ans = 0;
    } else {
    ll num2 = k%num;
    ans = min(num, num2);
    }
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc105/tasks/abc105_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int n, k, r;

  cin >> n >> k;

  r = n % k == 0 ? 0 : 1;

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

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

	for (char i = 'a'; i <= 'z'; i++) {
		if (s.find(i) == -1) {
			//もし見つからなかったら
			printf("%c",i);
			return 0;
		}
	}

	printf("None");
	return 0;
}

Measured memory_bytes: 512
if __name__ == '__main__':
    n = input()
    n_keta = len(n)
    dp = [0 for _ in range(n_keta)]
    for i in range(n_keta):
        i_result = 10 ** (i + 1) - 1
        for j in range(i):
            i_result -= dp[j]
        dp[i] = i_result

    result = 0
    for i in range(0, n_keta, 2):
        result += dp[i]

    if n_keta % 2 != 0:
        result -= 10 ** n_keta - 1 - int(n)

    print(result)

Measured memory_bytes: 38492
#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main(void) {
    io;
    string s; cin >> s;
    int count[26] = {0};
    for (int i = 0; i < (int)s.size(); i++) {
        count[s[i]-'a']++;
    }
    for (int i = 0; i < (int)s.size(); i++) {
        int x = count[s[i]-'a'];
        if (x & 1) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}



Measured memory_bytes: 3612
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	const int M = 1000000007;
	int R, C;
	scanf("%d%d", &R, &C);
	char str[1002];
	int dp[2][1002] = {};
	for (int i = 1; i <= R; ++i) {
		scanf("%s", str + 1);
		for (int j = 1; j <= C; ++j)
			if (i == 1 && j == 1)
				dp[1 & i][j] = 1;
			else if (str[j] == '#')
				dp[1 & i][j] = 0;
			else {
				dp[1 & i][j] = dp[1 & ~i][j] + dp[1 & i][j - 1];
				if (dp[1 & i][j] >= M)
					dp[1 & i][j] -= M;
			}
	}
	printf("%d\n", dp[R & 1][C]);
	return 0;
}

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 money[] = new double[N];
		String unit[] = new String[N];
		double otosidama[] = new double[N];
		double sum = 0;
		for (int i = 0; i < money.length; i++){
			money[i] = sc.nextDouble();
			unit[i] = sc.next();
			
		}

		for (int j = 0; j < money.length; j++){
			if(unit[j].equals("BTC")){
				otosidama[j] = money[j] * 380000.0;
			}
			else if(unit[j].equals("JPY")){
				otosidama[j] = money[j];
			}else{
System.out.println("DEBUG");
}
		}
		for (int k = 0; k < otosidama.length; k++){
			sum += otosidama[k];

		}
		System.out.println(sum);
	}
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> s[M];
    for (int i = 0; i < M; i++) {
        int k; cin >> k;
        s[i].resize(k);
        for (int j = 0; j < k; j++) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }
    vector<int> p(M);
    for (int i = 0; i < M; i++) cin >> p[i];

    int ans = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        int sum = 0;
        for (int i = 0; i < M; i++) {
            int cnt = 0;
            for (int j = 0; j < s[i].size(); j++) {
                if ((bit >> s[i][j]) & 1) cnt++;
            }
            if (cnt % 2 == p[i]) sum++;
        }
        if (sum == M) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int a, b, c, x;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    int ans = 0;
    rep(i, a + 1) {
        rep(j, b + 1) {
            rep(k, c + 1) {
                if(x == 500 * i + 100 * j + 50 * k) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,m,dp[1010][1010];
string s[1010];

int main()
{
	cin>>n>>m;
	rep(i,n) cin>>s[i];
	dp[0][0]=1;
	bool ok=true;
	for(int i=1;i<m;i++)
	{
		if(s[0][i]=='#') ok=false;
		dp[0][i]=(ok ? 1:0);
	}
	ok=true;
	for(int i=1;i<n;i++)
	{
		if(s[i][0]=='#') ok=false;
		dp[i][0]=(ok ? 1:0);
	}
	for(int i=1;i<n;i++)
	{
		for(int j=1;j<m;j++)
		{
			if(s[i][j]=='#') continue;
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
		}
	}
	cout<<dp[n-1][m-1]<<endl;
	rt0;
}

Measured memory_bytes: 9216
from itertools import accumulate


def binary(N, T):  # 二分探索 # N:探索要素数
    l, r = -1, N + 1
    while r - l > 1:
        if T < b[(l + r) // 2]:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r - 1


n, m, k = map(int, input().split())
a = [0] + list(accumulate(map(int, input().split())))
b = [0] + list(accumulate(map(int, input().split())))

ans = 0
for i, ai in enumerate(a):
    t = k - ai
    if t >= 0:
        j = binary(m, t)
        ans = max(ans, i + j)
print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> n(4);
  for (int i = 3; i >= 0; i--) {
    n.at(i) = N % 10;
    N /= 10;
  }
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<3> s(tmp);
    int t = n.at(0);
    for (int i = 0; i < 3; i++) {
      if (s.test(i)) {
        t += n.at(i + 1);
      }
      else {
        t -= n.at(i + 1);
      }
    }
    if (t == 7) {
	  cout << n.at(0);
      for (int i = 0; i < 3; i++) {
        if (s.test(i))
          cout << "+";
        else
          cout << "-";
        cout << n.at(i + 1);
      }
      cout << "=7" << endl;
      break;
    }
  }
}

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

int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	
	int ans=0;
	for(int i=1;i<=n;i++){
		int v=i%10+i%100/10+i%1000/100+i/1000%10+i/10000;
		if(a<=v&&v<=b) ans+=i;
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func swap(a *int, b *int) {
	tmp := *a
	*a = *b
	*b = tmp
}

func main() {
	var a int
	var b int
	var c int
	fmt.Scanf("%d%d%d", &a, &b, &c)
	if a > b {
		swap(&a, &b)
	}
	if b > c {
		swap(&b, &c)
	}
	if a > b {
		swap(&a, &b)
	}
	fmt.Printf("%d %d %d\n", a, b, c)
}



Measured memory_bytes: 1132
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int BUF = 200005;


int nNode, nEdge;
int edge[BUF][2];

void read() {
    cin >> nNode;
    nEdge = nNode - 1;
    for (int i = 0; i < nEdge; ++i) {
        cin >> edge[i][0] >> edge[i][1];
        --edge[i][0];
        --edge[i][1];
    }
}


void work() {
    long long ans = 0;
    for (int i = 0; i < nNode; ++i) {
        ans += 1LL * (i + 1) * (nNode - i);
    }

    for (int i = 0; i < nEdge; ++i) {
        if (edge[i][0] > edge[i][1]) {
            swap(edge[i][0], edge[i][1]);
        }
        ans -= 1LL * (edge[i][0] + 1) * (nNode - edge[i][1]);
    }
    
    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 5200
//{{{By oToToT
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <random>
#include <utility>
#include <stack>
#include <sstream>
#include <functional>
#include <deque>
#include <cassert>
using namespace std;
/* include everything for Kotori~ <3 */

using lld = int64_t;
using llu = uint64_t;
using llf = long double;
using PII = pair<int,int>;
using PIL = pair<int,lld>;
using PLI = pair<lld,int>;
using PLL = pair<lld,lld>;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
/* define some types for Ruby! */

#define FF first
#define SS second
#define SZ(x) (int)((x).size())
#define ALL(x) begin(x), end(x)
#define PB push_back
#define WC(x) while(x--)
/* make code shorter for Di~a~ */

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.FF<<","<<p.SS<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
/* make output easier for Ainyan~n~ */

bool debug = 0;
#define DUMP(x) if(debug) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<'\n'
template<typename T>
void DEBUG(const T& x){if(debug) cerr<<x;}
template<typename T, typename... Args>
void DEBUG(const T& head,const Args& ...tail){
	if(debug){cerr<<head; DEBUG(tail...);}
}
/* Let's debug with Nico~Nico~Ni */
//}}}

int main(int argc, char* argv[]){
	if(argc>1 and string(argv[1])=="-D") debug=1;
	if(!debug){ios_base::sync_with_stdio(0);cin.tie(0);}
	string ss; cin >> ss;
	int cnt=0;
	int64_t ans = 0;
	for(int i=SZ(ss)-1;i>=0;i--){
		if(ss[i]=='W') {
			cnt++;
		}else if(ss[i]=='B'){
			ans+=cnt;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
int n,k,s;
int main()
{
	scanf("%d%d%d",&n,&k,&s);
	for(int i=1;i<=k;i++) printf("%d ",s);
	for(int i=k+1;i<=n;i++) printf("%d ",s==inf?s-1:s+1);
	printf("\n");
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define MAX 30
#define INF 10000000.0
struct S{
	int e,s,b;
};

struct S2{
	int d,c,to;
};

int main(){

	int n,m;
	int s,g;
	int x,y,d,c;
	int min;
	float cost[MAX+1][MAX+1][MAX+1];
	S point,tmp;
	S2 nod;
	vector<S2> ed[MAX+1];
	queue<S> no;

	while(1){

		cin>>n>>m;
		if(n==0&&m==0) break;

		for(int i=1;i<=n;i++){
			if(!ed[i].empty()) ed[i].clear();
		}

		for(int i=0;i<=30;i++){
			for(int j=0;j<=30;j++){
				for(int k=0;k<=30;k++){
					cost[i][j][k]=INF;
				}
			}
		}

		cin>>s>>g;
		point.e=s,point.s=0,point.b=0;
		cost[0][s][0]=0;

		for(int i=0;i<m;i++){
			cin>>x>>y>>d>>c;
			nod.c=c,nod.d=d,nod.to=y;;
			ed[x].push_back(nod);
			nod.to=x;
			ed[y].push_back(nod);
		}

		no.push(point);
		while(!no.empty()){
			point=no.front();
			no.pop();
			for(int i=0;i<ed[point.e].size();i++){
				if(point.b!=ed[point.e][i].to){
					for(int j=-1;j<=1;j++){
						if(point.s+j>0&&point.s+j<=30){
							//if(point.s+j==1&&ed[point.e][i].to==g) cout<<cost[point.s][point.e]+((double)ed[point.e][i].d/(point.s+j))<<endl;
							if(ed[point.e][i].c>=point.s+j){
								//cout<<point.e<<","<<point.b<<","<<point.s<<","<<ed[point.e][i].to<<","<<cost[point.s][point.e]<<"^^"<<cost[point.s][point.e]+(double)ed[point.e][i].d/(point.s+j)<<endl;
								if(cost[point.s+j][ed[point.e][i].to][point.e]>cost[point.s][point.e][point.b]+((float)ed[point.e][i].d/(point.s+j))){
									cost[point.s+j][ed[point.e][i].to][point.e]=cost[point.s][point.e][point.b]+((float)ed[point.e][i].d/(point.s+j));
									tmp.e=ed[point.e][i].to;
									tmp.s=point.s+j;
									tmp.b=point.e;
									no.push(tmp);
								}
							}
						}
					}
				}
			}
		}
		min=0;
		for(int i=1;i<=30;i++){
			if(cost[1][g][i]<cost[1][g][min]) min=i;
		}
		if(min==0) printf("unreachable\n");
		else printf("%.5f\n",cost[1][g][min]);
	}

}

Measured memory_bytes: 1608
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    vector<int> P(N); repp(i,0,N) cin >> P[i];
    vector<int> Q(N); repp(i,0,N) cin >> Q[i];
    vector<int> s(N); repp(i,1,N+1) s[i-1] = i;
    sort(s.begin(), s.end());
    vector<vector<int>> v;
    while(next_permutation(s.begin(), s.end())) {
        v.push_back(s);
    };
    cout << abs(upper_bound(v.begin(), v.end(), P) - upper_bound(v.begin(), v.end(), Q)) << endl;

}



Measured memory_bytes: 3256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int inputCount = int.Parse(Reader.ReadLine());
        this.Items = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();

        long minItem = Items.Min();
        long maxItem = Items.Max();

        long minB = 1000000000 * -2;
        long maxB = 1000000000 * 2;

        long b = GetAns(minB, maxB);
        long ans = GetCalc(b);
        Console.WriteLine(ans);

    }

    private long GetAns(long min, long max) {
        if(max-min <= 2) {
            long tmp1 = GetCalc(min);
            long tmp2 = GetCalc((max + min) / 2);
            long tmp3 = GetCalc(max);

            long tmp4 = new long[] { tmp1, tmp2, tmp3 }.Min();
            if(tmp1 == tmp4) {
                return min;
            } else if(tmp2 == tmp4) {
                return (max + min) / 2;
            } else {
                return max;
            }
        }

        long mid1 = min + ((max - min) / 3);
        long mid2 = max - ((max - min) / 3);

        long valMin = GetCalc(min);
        long valMid1 = GetCalc(mid1);
        long valMid2 = GetCalc(mid2);
        long valMax = GetCalc(max);

        long minVal = new long[] { valMin, valMid1, valMid2, valMax }.Min();

        if(valMin == minVal) {
            return GetAns(min, mid1);
        } else if(valMid1 == minVal) {
            return GetAns(min, mid2);
        } else if(valMid2 == minVal) {
            return GetAns(mid1, max);
        } else {
            return GetAns(mid2, max);
        }
    }

    private long GetCalc(long target) {
        if(dic.ContainsKey(target)) {
            return dic[target];
        }

        long num = 0;
        for (int i = 1; i <= Items.Length; i++) {
            num += Math.Abs(Items[i - 1] - (i + target));
        }
        dic[target] = num;
        return num;
    }

    private Dictionary<long, long> dic = new Dictionary<long, long>();
    private long[] Items;





    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



1
10




";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 32516
n = int(input())


#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

ans = 1

for _ in range(n):
    ans = lcm(ans, int(input()))

print(ans)

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

class Program {
  static void Main() {
    var e = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
    for (int i = 0; i <= 8; i += 4) {
      if (!(e[i] == e[i + 1] && e[i + 1] == e[i + 2] && e[i + 2] == e[i + 3])) {
        Console.WriteLine("no");
        return;
      }
    }
    Console.WriteLine("yes");
  }
}


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

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    char c = s.at(k-1);
    if (c == 'A') {
        s.at(k-1) = 'a';
    }
    else if (c == 'B') {
        s.at(k-1) = 'b';
    }
    else if (c == 'C') {
        s.at(k-1) = 'c';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

satis = 0

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

next = -1

for i in range(N):
	satis += B[A[i]-1]
	if next == A[i]-1:
		satis += C[next-1]
	next = A[i]

print(satis)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    long long A,B,C;
    
    cin >> A >> B >> C;
    
    if ( A%2 == 0 || B%2 == 0 || C%2 == 0 ) {
        cout << 0 << endl;
        return 0;
    }
    
    long long a, b, c;
    
    a = (( A/2 + 1 ) * B * C ) - ( (A/2) * B * C) ;
    b = ( A *( B/2 + 1) * C ) - (A * (B/2) * C) ;
    c = (( C/2 + 1 ) * B * A ) - ( A * B * (C/2) );
    
    cout << min( c, min(  a , b ) ) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 500

int H, W;
string s[MAX];
int dxy[] = {1,-1,0,0};
int BB, WW;

int fuga(int d,int y, int x, int used[MAX][MAX]){//cout<<y<<" "<<x<<endl;
	if(used[y][x]) return 0;
	used[y][x] = true;
	
	if(s[y][x] == '#') BB++;
	else WW++;
	
	int ans = 0;
	
	for(int i = 0; i < 4; i++){
		int nx = x + dxy[i], ny = y + dxy[3-i];
		if(nx >= W || nx < 0 || ny >= H || ny < 0) continue;
		if(s[ny][nx] == s[y][x]) continue;
		// ans += fuga(d+1,ny,nx,used);
		// if(s[ny][nx] == '#') BB++;
		// else WW++;
		ans += fuga(d+1,ny,nx,used);
	}
	// return ans+d;
	return 0;
}

int hoge(){
	int ans = 0;
	int used[MAX][MAX] = {};
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){//cout<<i<<" "<<j<<" ++++ "<<endl;
			BB = 0, WW = 0;
			// ans += fuga(0,i,j, used);
			fuga(0,i,j, used);
			ans += BB*WW;
			// cout<<i<<" "<<j<<" ++++ "<<BB<<" "<<WW<<endl;
		}
	}
	
	return ans;
}

signed main(){
	cout<<fixed<<setprecision(7);
	
	cin>>H>>W;
	
	rep(i,H){
		cin>>s[i];
	}
	
	cout<<hoge()<<endl;
	
	return 0;
}

Measured memory_bytes: 19968
#include <cstdio>
#include <string.h>

using namespace std;

int N, K, D[20];

bool check(int n) {
    char num[10];
    sprintf(num, "%d", n);
    int len = strlen(num);
    for (int i = 0; i < strlen(num); i++) {
        for (int j = 0; j < K; j++) if (num[i] == D[j]+'0') return false;
    }
    return true;
}

int solve() {
    for (int n = N; n <= 10*N; n++) {
        if (check(n)) return n;
    }
}

int main() {
    scanf("%d%d", &N, &K);
    for (int i = 0; i < K; i++) scanf("%d", D+i);
    int ans = solve();
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
void swap(int *a,int *b)
{
     int tmp;
     tmp=*a;
     *a=*b;
     *b=tmp;
}



int main (void)
{
     int a,b,c;
     
     scanf("%d",&a);
     scanf("%d",&b);
     scanf("%d",&c);
     
     swap(&a,&b);
     swap(&a,&c);
     
     printf("%d %d %d",a,b,c);
     return 0;
     }
    
     

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

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

    static int S[500001], Z[500001];
    for(int i=1; i<=N; i++){
        S[i] = S[i-1] ^ A[i-1];
        Z[i] = Z[i-1] + (S[i] == 0);
    }

    const int M = 1<<20;
    static int64_t dp[M][2];
    for(int i=0; i<M; i++) dp[i][0] = 1;
    static int last[M];

    for(int i=1; i<=N; i++){
        if(S[i] == 0) continue;
        int s = S[i];
        int z = Z[i] - Z[last[s]];
        add(dp[s][0], dp[s][1] * z);
        add(dp[s][1], dp[s][0]);
        last[s] = i;
    }

    int64_t ans = 0;
    if(S[N] == 0){
        ans = power_mod(2, Z[N-1]);
        for(int i=1; i<M; i++) add(ans, dp[i][1]);
    }else{
        ans = dp[S[N]][0];
    }
    cout << ans << endl;
    return 0;
}


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

ll INF = 1LL << 60;

int 
main() {

  int N; cin >> N;
  vector<ll> arr(N);
  rep(i, 0, N) cin >> arr[i];
  vector<ll> acum(N + 1, 0);
  rep(i, 0, N) acum[i + 1] = acum[i] + arr[i];

  map<ll, ll> ans;
  rep(i, 0, N + 1){
    ans[acum[i]]++;
  }

  ll sum = 0;
  for(auto x: ans){
    ll num = x.second;
    sum += num * (num - 1) / 2;
  }
 
  cout << sum << endl;

}


Measured memory_bytes: 18824
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
bool f[100001];
int c[100002]={0};


int main() {
  int Q; cin >> Q;
  vector<int> L(Q), R(Q);
  for(int i = 2; i <= 100000; ++i) {
    if(!f[i]) {
      for(int j = i+i; j <= 100000; j+=i) {
        f[j] = true;
      }
    }
  }
  for(int i = 3; i <= 100000; i+=2) {
    if(!f[i] && !f[(i+1)/2]) c[i]++;
  }
  for(int i = 3; i<= 100000; ++i) c[i] += c[i-1];
  for(int i = 0; i < Q; ++i) {
    cin >> L[i] >> R[i];
    cout << c[R[i]] - c[L[i]-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    cout<<(n+1)*n/2;
}



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

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

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

  vector<int> a(4);
  rep(i, a.size()) cin >> a[i];
  sort(a.begin(), a.end());
  bool flag = false;
  if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) flag = true;

  cout << (flag ? "YES" : "NO") << '\n';
  return 0;
}


Measured memory_bytes: 256
main = 
    interact (calc . words)


calc :: [String] -> String
calc (a:op:b:xs)
    | op == "+" = (show $ round (x + y)) ++ "\n" ++ calc xs
    | op == "-" = (show $ round (x - y)) ++ "\n" ++ calc xs
    | op == "*" = (show $ round (x * y)) ++ "\n" ++ calc xs
    | op == "/" = (show $ floor (x / y)) ++ "\n" ++ calc xs
    | otherwise = ""
    where
        x = read a
        y = read b


Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,k;
ll a[200001];
bool check(ll x){
    ll mov=0;
    for(ll i=0;i<n;i++){
        mov+=(a[i]-1)/x;
    }
    if(mov<=k){
        return true;
    }
    return false;
}
int main()
{
    cin>>n>>k;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    ll lp=1;
    ll rp=1000000000;
    ll mid;
    bool flag1=true,flag2=true;
    while(lp<rp){
        flag1=true,flag2=true;
        mid=(lp+rp)/2;
        if(check(mid)){
            rp=mid;
        }else{
            lp=mid+1;
        }

    }
    cout<<lp<<endl;
}

Measured memory_bytes: 5156
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from collections import defaultdict, Counter


def solve():
    n = int(input())
    v = [int(i) for i in input().split()]
    d1 = Counter(v[::2])
    d2 = Counter(v[1::2])
    rd1 = defaultdict(list)
    rd2 = defaultdict(list)
    for k, v in d1.items():
        rd1[v].append(k)
    for k, v in d2.items():
        rd2[v].append(k)
    a1 = [i for i in sorted(rd1.keys(), reverse=True)]
    a2 = [i for i in sorted(rd2.keys(), reverse=True)]
    ans = n
    la1 = len(a1) - 1
    la2 = len(a2) - 1
    for h in range(3):
        for i in range(3):
            aa1 = rd1[a1[min(h, la1)]]
            aa2 = rd2[a2[min(i, la2)]]
            s1 = set(aa1)
            s2 = set(aa2)
            if len(s1) > 1 or len(s2) > 1 or (s1 - s2):
                ans = min(
                    ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)])
            else:
                ans = min(ans, (n // 2) - a1[min(h, la1)] + (n // 2) - a2[min(i, la2)]
                          + min(a1[min(h, la1)], a2[min(i, la2)]))
    print(ans)


if __name__ == "__main__":
    solve()


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

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";

vector<int> A2(50, 2);
vector<int> B2(50, 2);
vector<int> XOR_AB(50, 0);
int digitA, digitB;

int get2(ll x, bool isA) {
    ll temp = x;
    for (int i = 0; i < 50; i++) {
        if ( isA ) {
            A2[i] = temp % 2;
            digitA = i;
        } else {
            B2[i] = temp % 2;
            digitB = i;
        }
        temp /= 2;
        if (temp==0) break;
    }
    return 0;
}

int getXOR() {

    int tempA = 0, tempB = 0;
    if ((A2[1] + A2[0]) % 2 == 1) {
        tempA = 1;
    }
    if ((B2[1] + B2[0]) % 2 == 1) {
        tempB = 1;
    }
    XOR_AB[0] = (tempA + tempB) % 2;

    for (int i = 1; i < 50; i++) {
        tempA = 0, tempB = 0;
        if (A2[0] == 0 && A2[i] == 1 && i <= digitA) {
            tempA = 1;
        }
        if (B2[0] == 0 && B2[i] == 1 && i <= digitB) {
            tempB = 1;
        }
        XOR_AB[i] = (tempA + tempB) % 2;
    }
    return 0;
}

int main() {

    CIN(ll, A);
    CIN(ll, B);

    get2(max(A - 1, 0LL), true);
    get2(B, false);

    getXOR();

    // SHOW(XOR_AB);

    ll ans = 0;
    for (int i = 49; i >=0; i--) {
        ans = ans * 2 + XOR_AB[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

#define MOD(x) (x % 2019)

typedef long long ll;
using namespace std;

int main() {
	ll l, r;

	scanf("%lld %lld", &l, &r);

	r = min(l + 2020, r);

	int result = 2019;
	for(ll i = l; i < r; i++) {
		for(ll j = i + 1; j <= r; j++) {
			result = min(MOD(MOD(i) * MOD(j)), (ll)result);
		}
	}

	printf("%d\n", result);

	return 0;
}

Measured memory_bytes: 128
import math
x = []
for i in range(5):
    x.append(int(input()))

bk = [x[i]%10 for i in range(5)]
new_bk = [(e if e !=0 else 9) for e in bk]
bmin = min(new_bk)
last_index=new_bk.index(bmin)
last = x.pop(last_index)
intbk=[math.ceil(e/10)*10 for e in x]
print(sum(intbk)+last)



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int64_t x;
    cin>>x;
    int64_t a=x/500*1000;
    int64_t b=(x%500)/5*5;
    cout<<a+b<<endl;
}


Measured memory_bytes: 256
using System;

class Program
{
  public static void Main(string[] args)
  {
    string[] read = Console.ReadLine().Split(' ');
    int a = int.Parse(read[0]);
    int b = int.Parse(read[1]);
    int c = int.Parse(read[2]);
    int count = 0;
    for(int i = a;i <= b;i++)
    {
      if(c%i == 0) count++;
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;

bool solve(vector <int> a) {
	ll tmp = 0,tmp1 = 0;
	for (int u : a){
		if (u % 2)
			tmp1++;
		else
			tmp++;
	}
	if (tmp % 2)
		return 1;
	if (tmp1 != 1)
		return 0;
	for (int i = 0; i < n;i++){
		if (a[i] % 2)
			a[i]--;
		if (a[i] == 0)
			return 0;
	}
	ll w = 0;
	for (int u : a)
		w = gcd(w,u);
	for (int i = 0; i < n; i++)
		a[i] /= w;
	return 1 - solve(a);
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cin >> n;
	vector <int> a;
	for (ll i = 0, x; i < n; i++){
		cin >> x;
		a.push_back(x);
	}
	bool ans = solve(a);
	if (ans)
		cout << "First" << endl;
	else
		cout << "Second" << endl;
}

Measured memory_bytes: 13084
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using E = tuple<int,int,ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

int n;
vector<vector<E>> tree;

int depth[100010];
int par[100010][20];

void init_par_depth(int node,int d, int p){
  depth[node] = d;
  par[node][0] = p;
  for(E edge : tree[node]){
    int next,c;
    ll w;
    tie(next,c,w) = edge;
    if(next != p){
      init_par_depth(next,d+1,node);
    }
  }
}

void fill_par(int root){
  init_par_depth(root,0,-1);
  for(int i = 1;i < 20;++i){
    for(int node = 0;node < n;++node){
      if(par[node][i-1] == -1){
        par[node][i] = -1;
      } else {
        par[node][i] = par[par[node][i-1]][i-1];
      }
    }
  }
}

int lca(int a,int b){
  if(depth[b] > depth[a]){
    swap(a,b);
  }
  for(int i = 0;i < 20;++i){
    if((depth[a] - depth[b]) & (1 << i)){
      a = par[a][i];
    }
  }
  assert(depth[a] == depth[b]);
  if(a == b){
    return a;
  }
  for(int i = 19;i >= 0;--i){
    if(par[a][i] != par[b][i]){
      a = par[a][i];
      b = par[b][i];
    }
  }
  return par[a][0];
}

ll ans[100010];
ll cnt[100010];
ll sum[100010];
using Q = tuple<int,ll,int,ll>;
vector<vector<Q>> query;

void calc(int node,int p,ll dist){
  for(Q q : query[node]){
    int id,x;
    ll mult,y;
    tie(id,mult,x,y) = q;
    ans[id] += mult * (dist - sum[x] + cnt[x] * y);
  }

  for(E edge : tree[node]){
    int next,c,w;
    tie(next,c,w) = edge;
    if(next != p){
      cnt[c]++;
      sum[c] += w;
      calc(next,node,dist+w);
      cnt[c]--;
      sum[c] -= w;
    }
  }
}


int main(void){
  int q;
  cin >> n >> q;
  tree = vector<vector<E>>(n);
  for(int i = 0;i < n-1;++i){
    int a,b,c;
    ll w;
    scanf("%d %d %d %lld", &a, &b, &c, &w);
    --a;--b;
    tree[a].push_back(make_tuple(b,c,w));
    tree[b].push_back(make_tuple(a,c,w));
  }
  fill_par(0);

  query = vector<vector<Q>>(n);
  for(int i = 0;i < q;++i){
    int x,u,v;
    ll y;
    scanf("%d %lld %d %d", &x, &y, &u, &v);
    --u;--v;
    int a = lca(u,v);
    query[a].push_back(make_tuple(i,-2LL,x,y));
    query[u].push_back(make_tuple(i,1LL,x,y));
    query[v].push_back(make_tuple(i,1LL,x,y));
  }

  fill(ans,ans+100010,0LL);
  fill(cnt,cnt+100010,0LL);
  fill(sum,sum+100010,0LL);
  calc(0,-1,0);

  for(int i = 0;i < q;++i){
    printf("%lld\n", ans[i]);
  }
  return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

constexpr ll INF = 1e15;

constexpr ll mod = 1e9 + 7;

template<typename T>
void cmpmax(T& reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void cmpmin(T& reference, T value) {
	reference = min(reference, value);
}

int main() {
	ll a;
	cin >> a;
	a %= 10;
	if (a == 3) {
		cout << "bon" << endl;
		return 0;
	}
	if (a == 0 || a == 1 || a == 6 || a == 8) {
		cout << "pon" << endl;
		return 0;
	}
	cout << "hon" << endl;
	return 0;
}



Measured memory_bytes: 3636
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vii adj(N);
int a[N];

void  solve(){

}
int32_t main()
{
    FIO
    string s,t; cin>>s>>t;
    int p=0;
    fi(i,s.length()) if(s[i]!=t[i]) p++;
    cout<<p<<"\n";
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

Measured memory_bytes: 15528
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int area = a * b;
        int length = (2 * a) + (2 * b);
        
        System.out.println(area + " " + length);
    }
}


Measured memory_bytes: 26084
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n;
	while(cin>>n){
		if (n == 0)break;
		vector<string> v;
		string s; int out=0;
		for (int i = 0; i < n; i++) {
			cin >> s;
			v.push_back(s);
		}
		while (true) {
			int x = out;
			bool f = true;
			int cnt = 0;
			while (x<n&&cnt+(int)v[x].size() <= 5) {
				cnt+=v[x].size();
				x++;
			}
			if (cnt != 5) {
				f = false;
			}
			cnt = 0;
			while (x<n&&cnt + (int)v[x].size() <= 7) {
				cnt += v[x].size();
				x++;
			}
			if (cnt != 7) {
				f = false;
			}
			cnt = 0;
			while (x<n&&cnt + (int)v[x].size() <= 5) {
				cnt += v[x].size();
				x++;
			}
			if (cnt != 5) {
				f = false;
			}
			cnt = 0;
			while (x<n&&cnt + (int)v[x].size()<=7){
				cnt += v[x].size();
				x++;
			}
			if (cnt != 7) {
				f = false;
			}
			cnt = 0;
			while (x<n&&cnt + (int)v[x].size() <= 7) {
				cnt += v[x].size();
				x++;
			}
			if (cnt != 7) {
				f = false;
			}
			if (f)break;
			out++;
		}
		cout << out+1 << endl;
	}
	return 0;
}



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

const int INF = 1000000000;

int main() {
	int h, n; cin >> h >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i) >> b.at(i);
	}
	vector<vector<int>> dp(n + 1, vector<int>(h + 1));
	dp[0][0] = 0;
	for (int j = 1; j <= h; j++) {
		dp[0][j] = INF;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= h; j++) {
			dp.at(i).at(j) = min( dp.at(i - 1).at(j), dp.at(i).at( max(j - a.at(i - 1), 0 ) )+ b.at(i - 1) );
            dp[i][j] = min( dp[i - 1][j], dp[i][max(j - a[i - 1],0)]+ b[i - 1] );
		}
	}
	cout << dp.at(n).at(h) << endl;
}


Measured memory_bytes: 39424
n = int(input())
h = list(map(int, input().split()))
h = h[::-1]

if n == 1:
  print('Yes')

for i in range(n-1):
  if h[i+1] - h[i] > 1:
    print('No')
    break
  elif h[i+1] - h[i] == 1:
    h[i+1] -= 1
    
  if (i == n-2) and (h[n-2] >= h[n-1]):
    print('Yes')

Measured memory_bytes: 63984
#include <iostream>
using namespace std;
int main(){
    int x;
    int y;
    int t;
    while(1){
        cin >> x >> y;
         if ( x == 0 && y == 0 ) {
          break;  
         }
         
         if(x>y){
              t=x;
              x=y;
              y=t;
         }
         
         cout<<x<<" "<<y<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3088
N, M = map(int, input().split())
city = [[] for _ in range(N + 1)]
for i in range(M):
    p, y = map(int, input().split())
    city[p].append([y, i + 1])
ans = [-1 for _ in range(M + 1)]
for k in range(1, N + 1):
    tmp = city[k]
    if len(tmp) > 0:
        for j, t in enumerate(sorted(tmp)):
            name = str(k).zfill(6) + str(j + 1).zfill(6)
            ans[t[1]] = name
print("\n".join(ans[1:]))

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

map<ll, ll> primefact(ll n) {
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

ll N;
VL a;

int main() {
    cin >> N;
    a.resize(3 * N);
    VECCIN(a);
    sort(All(a), greater<ll>());
    ll sum = 0;
    REP(i, N) { sum += a[2 * i + 1]; }
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 2560
//const int N=1e5;
#define INF 1e9
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
int n; string s;
void sol() {
	cin >> n; cin >> s;
	int red = 0, w = 0, swp = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'W')
			++w;
		else
			++red;
	}
	int cnt = min(red, w);
	for (int i = 0; i < red; ++i) {
		if (s[i] == 'W')
			++swp;
	}
	cnt = min(cnt, swp);
	cout << cnt << "\n";
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	while (t--) {
		sol();
	}

	return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod = 1000000007;
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */


// GCDを求めます
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}

// 最小公倍数を求める
ll lcm(ll a, ll b){
    if(a<=b) return a/gcd(a,b)*b;
    else return a/gcd(b,a) * b;
}


int main(void){
    int n;
    cin >> n;
    vector<ll> t;
    for(int i=0; i<n; i++){
        ll x;
        cin >> x;
        t.push_back(x);
    }


    ll LCM = t[0];

    for(int i=1; i<n; i++){
        if(t[i]<=LCM){
            LCM = lcm(t[i], LCM);
        }
        else{
            LCM = lcm(LCM, t[i]);
        }
    }

    cout << setprecision(20) << LCM;

    return 0;
}

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

#define N 212345
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define all(cont) cont.begin(), cont.end()
#define sortcmp(n, cmpfunc) sort(all(n), cmpfunc)
#define fastio ios::sync_with_stdio(false); cin.tie(0)

ll powm(ll a, ll b);
ll divm(ll a, ll b);
ll multm(ll a, ll b);
ll subm(ll a, ll b);
ll addm(ll a, ll b);

int main(){
	int n;
	int preb[N], sufw[N], ans;
	string s;
	fastio;
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.in", "r", stdin);
 //    	freopen("output.out", "w", stdout);
	// #endif	

    cin >> n >> s;
    if(n == 1) cout << '0' << endl;
    else {
	    preb[0] = 0;
	    for(int i = 1 ; i < n ; i++){
			preb[i] = preb[i-1];
			if(s[i-1] == '#') preb[i]++;
		}
		
		sufw[n] = 0;
		for(int i = n-1 ; i >= 1 ; i--){
			sufw[i] = sufw[i+1];
			if(s[i] == '.') sufw[i]++;
		}

		ans = preb[0] + sufw[1];
		for(int i = 1 ; i < n ; i++)
			ans = min(ans, preb[i]+sufw[i+1]);
		
		
		cout << ans << endl;
	}


	return 0;
}

// template function
ll gcd(int a, int b) { 
	if (b == 0) return a; 
	return gcd(b, a % b);  
} 

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

ll powm(ll a, ll b){
	ll x=1, y=a; 
    while (b > 0) {
        if (b%2) x = (x*y) % mod;
        y = (y*y) % mod;
        b /= 2;
    }
    return x % mod;
}

ll multm(ll a, ll b){
	return ((a%mod) * (b%mod)) % mod;
}

ll divm(ll a, ll b){
	return (a * powm(b, mod - 2)); 
}

ll subm(ll a, ll b){
	a -= b;
  	if (a < 0) a += mod;
	return a;
}

ll addm(ll a, ll b){
	a += b;
  	if (a >= mod) a -= mod;
  	return a;
}

Measured memory_bytes: 2196
#!/usr/bin/env python3
import itertools
def index(p):
    for i, q in enumerate(itertools.permutations(range(1, len(p) + 1))):
        if p == q:
            return i
    assert False
def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))
    print(abs(index(p) - index(q)))
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060