akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(void){

  int d,n,t,a,b,c,dp[202][202];
  vector<int>T,A,B,C;

  cin >> d >> n;
    T.clear();
    A.clear();
    B.clear();
    C.clear();

    for(int i=0;i<d;i++){
      cin >> t;
      T.push_back(t);
    }

    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      A.push_back(a);
      B.push_back(b);
      C.push_back(c);
    }

    for(int i=0;i<202;i++)
      for(int j=0;j<202;j++)
	dp[i][j]=-1;

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
       
	  if(A[i]<=T[0] && T[0]<=B[i] && A[j]<=T[1] && T[1]<=B[j])
	    dp[0][j]=max(dp[0][j],abs(C[i]-C[j]));
	}
    }

    for(int i=1;i<=d;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	    if(A[k]<=T[i+1] && T[i+1]<=B[k] && dp[i-1][j]>=0)
	      dp[i][k]=max(dp[i][k],dp[i-1][j]+abs(C[j]-C[k]));
	}
      }
    }

    int ans=0;
    for(int i=0;i<n;i++){
      ans=max(ans,dp[d-2][i]);
    }
    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1380
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n);
	rep(i, 0, n) cin >> a[i];
	sort(all(a));
	map<int, int> ex;
	rep(i,0,n) ++ex[a[i]];
	if (ex[1] > 0) {
		if (ex[1] == 1) {
			cout << 1 << endl;
		} else {
			cout << 0 << endl;
		}
		return 0;
	}
	int cnt = 0;
	rep(i,0,n) {
		if (ex[a[i]] > 1) {
			continue;
		}
		bool ok = true;
		for(int d = 2; d * d <= a[i]; ++d) {
			if (a[i] %d == 0) {
				if (ex.count(d) > 0 || ex.count(a[i] / d) > 0) {
					ok = false;
					break;
				}
			}
		}
		if (ok) {
			++cnt;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 13500
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		int a[] = new int[N];
		for(int i = 0 ; i < N ; i++) {
			a[i] = sc.nextInt();
		}
		int[][] s = new int[H][W];
		int h = 0, w = 0;
		for(int i = 0 ; i < N ; i++) {
			for(;a[i]-- > 0;) {
				s[h][w] = i + 1;
				if(h % 2 == 0) {
					if(w == W - 1) {
						h++;
					} else {
						w++;
					}
				} else {
					if(w == 0) {
						h++;
					} else {
						w--;
					}
				}
			}
		}
		for(int i = 0 ; i < H ; i++) {
			for(int j = 0 ; j < W ; j++) {
				System.out.print(s[i][j] + " ");
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 33772
n=int(input())
M=list(map(int,input().split()))
M.sort()
dic={}
dic[M[0]]=1
for i in range(1,n):
	if(M[i]!=M[i-1]):
		dic[M[i]]=1
	else:
		dic[M[i-1]]+=1

L=list(dic.keys())
l=len(L)
L.sort()
count=0
for i in range(0,l):
	for j in range(0,i):
		for k in range(0,j):
			if(L[i]<L[j]+L[k]):
				count+=dic[L[i]]*dic[L[j]]*dic[L[k]]
print(count)

Measured memory_bytes: 67240
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int N;
  while(cin>>N && N){
    vector<int> l(N);
    REP(i, N) cin>>l[i];
    int M = 256;
    int as, aa, ac;
    double ent = 1e32;
    REP(S, 16)REP(A, 16)REP(C, 16){
      vector<int> R(N + 1);
      R[0] = S;
      REP(i, N){
        R[i + 1] = (A * R[i] + C) % M;
        while(R[i + 1] >= M) R[i + 1] -= M;
      }
      REP(i, N){
        R[i + 1] += l[i];
        while(R[i + 1] >= M) R[i + 1] -= M;
      }
      double cnt[256] = {};
      REP(i, N) cnt[R[i + 1]] += 1.0;
      double e = 0;
      REP(i, 256)if(cnt[i] != 0){
        double c = cnt[i];
        e += -c/N * log(c/N);
        if(!(e + EPS < ent)) goto END;
      }
      ent = e;
      as = S, aa = A, ac = C;
END:;
    }
    printf("%d %d %d\n", as, aa, ac);
  }
  return 0;
}

Measured memory_bytes: 1216
n, m = map(int, raw_input().strip().split())
ar = [0]*n
for _ in range(m):
	for v in map(int, raw_input().strip().split()):
		ar[v-1]+=1
answ = "YES"
for x in ar:
	if x % 2 != 0:
		answ = "NO"
		break
print answ

Measured memory_bytes: 6532
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <algorithm>
#include <limits.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#define ll long long
#define MSET(x) memset((x), 0, sizeof((x)))
#define MMSET(x) memset((x), -1, sizeof((x)))
#define rep(i, a, b) for ( int (i) = a; (i) < (b) ; ++ (i) )
#define repA(i, a, b) for ( int (i) = a ;  (i) <= (b) ; ++ (i) )
#define repD(i, a, b) for ( int (i) = a; (i) >= (b) ; -- (i) )
#define fi first
#define se second
#define pb push_back
#define mfind(m, item) ((m).find((item)) != (m).end())
#define mp(a,b) make_pair((a),(b))
#define mt(a,b,c) make_pair(make_pair((a),(b)), (c))
#define tfi first.first
#define tse first.second
#define tth second
#define print cout << endl
#define tri pair<pair<int, int>, int>
using namespace std;

int a,b,c,x;

int main(){
    while ( cin >> a >> b >> c >> x ) {
        int cnt = 0;
        for ( int i = 0 ; i <= a ; ++ i ) {
            for ( int j = 0 ; j <= b ; ++ j ){
                for ( int k = 0 ; k <= c;  ++ k ) {
                    if ( i * 500 +  j * 100 + 50 * k == x ) ++ cnt;
                }
            }
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

int main() {
  int n, x;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> x;
    if(x % 2) {
      std::cout << "first\n";
      return 0;
    }
  }
  
  std::cout << "second\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
  if (A + B < C * 2) {
    cout << A * X + B * Y << endl;
    return 0;
  }
  else {
    int ans = 0;
    ans += C * 2 * min(X, Y);
    if (X >= Y) {
      if (A < C * 2) {
        ans += A * (X - Y);
      }
      else {
        ans += C * 2 * (X - Y);
      }
    }
    else {
      if (B < C * 2) {
        ans += B * (Y - X);
      }
      else {
        ans += C * 2 * (Y - X);
      }
    }
    cout << ans << endl;
    return 0;
  }
}

Measured memory_bytes: 256
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NMX = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NMX[0]; var M = NMX[1]; var X = NMX[2];
            var Ci = new int[N];
            var Aij = new int[N, M];
            for (int i = 0; i < N; i++)
            {
                var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                Ci[i] = read[0];
                for (int j = 1; j < M + 1; j++) Aij[i, j - 1] = read[j];
            }

            var result = int.MaxValue;
            for (int i = 0; i < (1 << N); i++)
            {
                var study = new int[M];
                var amount = 0;
                for (int j = 0; j < N; j++)
                {
                    if ((i & (1 << j)) > 0)
                    {
                        amount += Ci[j];
                        for (int k = 0; k < M; k++)
                        {
                            study[k] += Aij[j, k];
                        }
                    }
                }
                var isSuccess = true;
                for (int l = 0; l < M; l++)
                {
                    if (study[l] < X)
                    {
                        isSuccess = false;
                        break;
                    }
                }
                if (isSuccess)
                {
                    result = Math.Min(result, amount);
                }
            }

            Console.WriteLine(result != int.MaxValue ? result : -1);
        }
    }
}


Measured memory_bytes: 27856
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 2e5+10;
const int M = 1e6+10;
/*=================================================================================*/

ll sum;
int gcd(int a,int b){
	return b ? gcd(b, a%b) : a;
}
int main() {
	int n,a,b,c,d;
	scanf("%d",&n);
	for(a=1;a<=n;a++)
		for(b=1;b<=n;b++)
			for(c=1;c<=n;c++)
				d=gcd(a,b),d=gcd(c,d),sum+=d;
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 3788
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

// Scanner 2
var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	d := nextInt()

	var ret int
	for i := 0; i < n; i++ {
		p := nextInt()
		q := nextInt()

		if sqrt(pow(p, 2)+pow(q, 2)) <= float64(d) {
			ret++
		}
	}

	fmt.Println(ret)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func sqrt(p int) float64 {
	return math.Sqrt(float64(p))
}
func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}


Measured memory_bytes: 4916
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
int ar[100005];

pi hei[100005];
lint res[100005];
int main(){
  cin>>n;
  REP(i,n){
    cin>>ar[i];
    hei[i]={ar[i],i};
  }
  sort(hei,hei+n,greater<pi>());

  int pos=n,h=-1;
  int cnt=0;
  REP(i,n){
    int j=i;
    while(hei[j].fr==hei[i].fr) ++j;
    if(h==-1){
      h=hei[i].fr;
      pos=hei[j-1].sc;
    }else{
      res[pos]+=(h-hei[i].fr)*(lint)cnt;
      chmin(pos,hei[j-1].sc);
      h=hei[i].fr;
    }
    cnt+=j-i;
    i=j-1;
  }
  res[0]+=h*(lint)n;
  REP(i,n) printf("%lld\n",res[i]);
  return 0;
}





Measured memory_bytes: 3072
#!/home/matsumotokazuho/.pyenv/shims/pypy
# import math
# from copy import deepcopy
# from operator import itemgetter
# from collections import defaultdict
# from collections import Counter
# from collections import deque
# import pprint
# import itertools
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

H, W = map(int, input().split())
Board = [list(input().rstrip()) for _ in range(H)]

# q = deque()
q = []
# for i, j in itertools.product(range(H), range(W)):
for i in range(H):
    for j in range(W):
        if Board[i][j] == '#':
            # Board[i][j] = 0
            q.append((i, j))

ans = 0
while q:
    qq = []
    ans += 1
    for yx in q:
        for d in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            y = yx[0] + d[0]
            x = yx[1] + d[1]
            # y, x = [i+j for i, j in zip(yx, d)]
            if y < 0 or H - 1 < y or x < 0 or W - 1 < x:
                pass
            elif Board[y][x] == '.':
                # Board[y][x] = Board[q[0][0]][q[0][1]] + 1
                Board[y][x] = '#'
                qq.append((y, x))
    q = qq

# ans = max(list(itertools.chain.from_iterable(Board)))
# ans = max(itertools.chain.from_iterable(Board))
# pprint.pprint(Board)
print(ans-1)


Measured memory_bytes: 194556
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, d = nm()
    ans = 0
    for _ in range(n):
        x, y = nm()
        ans += x ** 2 + y ** 2 <= d ** 2
    print(ans)
    return

solve()


Measured memory_bytes: 9212
import numpy as np
n,k=map(int,input().split())
m=np.zeros((3*k,3*k),dtype=int)
l=2*k
o=0
for _ in range(n):
  x,y,c=input().split()
  x,y=int(x)%l,int(y)%l
  t=c=='W'
  m[x,y]+=1-2*t
  o+=t
for _ in range(2):
  m[l:]=m[:k]
  m=np.cumsum(m,axis=0)
  m[:l]=m[k:]-m[:l]
  m=m.T
m=m[:l,:l]
print(o+(m+np.roll(np.roll(m,k,axis=0),k,axis=1)).max())

Measured memory_bytes: 153084
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn main(){
    let mut n = read_as_vec::<u32>()[0];
    let mut ans = 0;

    let mut base = 1;
    for i in 0..3{
        let tmp = n%10;
        if tmp == 1 || tmp == 9{
            ans += (10-tmp)*base;
        }else{
            ans += tmp*base;
        }
        base *= 10;
        n /= 10;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main{

     static long getHash(int y,int m,int o){
	return (long)(y*10000+m*100+o);
    }


    public static void main(String[] args){
	int Y,M,O;
	Scanner in = new Scanner(System.in);
	long premeiji = getHash(1868,9,7);
	long meiji_u = getHash(1868,9,8),meiji_b = getHash(1912,7,29);
	long taisho_u = getHash(1912,7,30),taisho_b = getHash(1926,12,24);
	long showa_u = getHash(1926,12,25),showa_b = getHash(1989,1,7);
	long heisei = getHash(1989,1,8);


	while(in.hasNext()){
	    Y = in.nextInt();
	    M = in.nextInt();
	    O = in.nextInt();
	    long input = getHash(Y,M,O);
	    if(input <= premeiji)System.out.println("pre-meiji");
	    else if(meiji_u <= input && input <= meiji_b)System.out.println("meiji " + (Y-1867) + " " + M + " " + O);
	    else if(taisho_u <= input && input <= taisho_b)System.out.println("taisho " + (Y-1911) + " " + M + " " + O);
	    else if(showa_u <= input && input <= showa_b)System.out.println("showa " + (Y-1925) + " " + M + " " + O);
	    else if(heisei <= input)System.out.println("heisei " + (Y-1988) + " " + M + " " + O);
	}

    }

}

Measured memory_bytes: 12000
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict
import bisect
from fractions import Fraction
 
H = int(input())
A = math.log(H, 2)

ans = 0
for i in range(0,int(A)+1):
    ans += 2**i

print(ans)

Measured memory_bytes: 13664
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,ans;
  cin>>n;
  vector<int> v1(100001),v2(100001);
  for(int i=0;i<n;i++){
    int v;
    cin>>v;
    if(i%2==0){
      v1[v]++;
    }else{
      v2[v]++;
    }
  }
  int v1max1=0,v1max2=0,v2max1=0,v2max2=0;
  int v1max1id,v1max2id,v2max1id,v2max2id;
  for(int i=1;i<100001;i++){
    if(v1[i]>v1max1){
      v1max2=v1max1;
      v1max2id=v1max1id;
      v1max1=v1[i];
      v1max1id=i;
    }else if(v1[i]>v1max2){
      v1max2=v1[i];
      v1max2id=i;
    }

    if(v2[i]>v2max1){
      v2max2=v2max1;
      v2max2id=v2max1id;
      v2max1=v2[i];
      v2max1id=i;
    }else if(v2[i]>v2max2){
      v2max2=v2[i];
      v2max2id=i;
    }
  }
  if(v1max1id!=v2max1id){
    ans=n-v1max1-v2max1;
  }else{
    ans=min(n-v1max1-v2max2,n-v1max2-v2max1);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

int main() {
    int A,B,C,D;

    cin >> A >> B >> C >> D;

    while(1){
        C -= B;
        if(C <= 0){
            cout << "Yes" << endl;
            break;
        }

        A -= D;
        if(A <= 0){
            cout << "No" << endl;
            break;
        }

    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    int count = 3;
    cin >> a >> b >> c;
    if (a == b) count--;
    if (b == c) count--;
    if (c == a) count--;
    if (a == b && b == c && c == a) count=1;
    cout << count << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int e,b;
  cin >> e >> b;
  int a[b+1]={0};
  for(int i=0;i<b;i++){
    cin >> a[i];
  }
  int sum=(e-a[b-1])+a[0];
  int m;
  
  for(int i=0;i<b;i++)sum=max(sum,a[i+1]-a[i]);
  cout << e-sum << endl;
}
  


Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define int long long
using pii = pair<int, int>;
int dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};
char s[405][405];

pii dfs(int x, int y) {
    pii ret = {0, 0};
    char t = s[x][y];
    if (t == '#') {
        ret.first++;
    } else {
        ret.second++;
    }
    // 同じマスを重複してカウントしないようにする
    s[x][y] = 0;
    for (int i = 0; i < 4; i++) {
        char u = s[x + dx[i]][y + dy[i]];
        // まだ通っていないマス＆次マスの色が異なる
        if (u > 0 && t != u) {
            auto t = dfs(x + dx[i], y + dy[i]);
            ret.first += t.first;
            ret.second += t.second;
        }
    }
    return ret;
}

signed main() {
    int h, w;
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        cin >> s[i] + 1;
        s[i][w + 1] = 0;
    }
    int ans = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (s[i][j]) {
                pii ret = dfs(i, j);
                ans += ret.first * ret.second;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define vi vector <ll>
#define hell 1000000007
#define pii pair <ll,ll>
#define inf (ll)(1e16)
#define pb push_back

using namespace std;

vi adj[1001];
vi par(1001,-1);
ll st;

ll bfs(ll s)
{
    queue <ll> q;
    q.push(s);
    vi dist(1001,-1);
    par.assign(1001,-1);
    par[s]=-1;
    dist[s]=0;
    while(!q.empty())
    {
        ll x=q.front();
        q.pop();
        for(auto ch:adj[x])
        {
            if(dist[ch]==-1)
            {
                par[ch]=x;
                q.push(ch);
                dist[ch]=1+dist[x];
            }
            else if(ch==s)
            {
                par[s]=-1;
                st=x;
                return dist[x]+1;
            }
        }
    }
    return inf;
}

void solve()
{
    ll n,m,ans;
    cin>>n>>m;
    rep(i,0,m)
    {
        ll u,v;
        cin>>u>>v;
        adj[u].pb(v);
    }
    ans=inf;
    vi res;
    rep(i,1,n+1)
    {
        ll x=bfs(i);
        if(x<ans)
        {
            ans=x;
            res.clear();
            while(st!=-1)
            {
                res.pb(st);
                st=par[st];
            }
        }
    }
    if(ans==inf)
    {
        cout<<-1;
        return;
    }
    cout<<ans<<"\n";
    for(ll x:res)
        cout<<x<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 384
<?php

fscanf(STDIN, '%d', $N);
$list = [];
for ($i = 1; $i <= $N; ++$i) {
    $list[] = array_map('intVal', explode(' ', trim(fgets(STDIN))));
}

$dp = [];
$dp[0][0] = 0;
$dp[0][1] = 0;
$dp[0][2] = 0;

for ($j = 1; $j <= $N; ++$j) {
    for ($k = 0; $k <= 2; ++$k) {
        $remain = [0, 1, 2];
        unset($remain[$k]);
        $remain = array_values($remain);
        $dp[$j][$k] = max($dp[$j-1][$remain[0]] + $list[$j-1][$k], $dp[$j-1][$remain[1]] + $list[$j-1][$k]);
    }
}

echo max($dp[$N][0], $dp[$N][1], $dp[$N][2]);


Measured memory_bytes: 86512
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
	ll X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	vector<ll> A(X), B(Y), C(Z);
	rep(i, X) cin >> A[i];
	rep(i, Y) cin >> B[i];
	rep(i, Z) cin >> C[i];

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	// bool unUsed[X][Y][Z];// X, Y, Z が大きいとエラーになる．
	//rep(i, X) rep(j, Y) rep(k, Z) unUsed[i][j][k] = true;

	// vectorで確保する
	vector<vector<vector<bool>>> unUsed(X, vector<vector<bool>>(Y, vector<bool>(Z, true)));

	priority_queue<vector<ll>> cand;
	//vector<ll> tmp = {(A[X-1]+B[Y-1]+C[Z-1]), X-1, Y-1, Z-1};
	cand.push({(A[X-1]+B[Y-1]+C[Z-1]), X-1, Y-1, Z-1});
	unUsed[X-1][Y-1][Z-1] = false;

	while(K>0) {
		cout << cand.top()[0] << endl;
		// add cand
		ll x, y, z;
		x = cand.top()[1];
		y = cand.top()[2];
		z = cand.top()[3]; 
		cand.pop();

		if(x>0) {
			if(unUsed[x-1][y][z]) {
				cand.push({A[x-1]+B[y]+C[z], x-1, y, z});
				unUsed[x-1][y][z] = false;
			}
		}
		if(y>0) {
			if(unUsed[x][y-1][z]) {
				cand.push({(ll)(A[x]+B[y-1]+C[z]), x, y-1, z});
				unUsed[x][y-1][z] = false;
			}
		}
		if(z>0) {
			if(unUsed[x][y][z-1]) {
				cand.push({A[x]+B[y]+C[z-1], x, y, z-1});
				unUsed[x][y][z-1] = false;	
			}
		}

		K--;
	}

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<int> p(n);
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		p[i] = (x == i + 1);
	}
	int ans = 0;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(p[i]){
			cnt++;
		}else{
			ans += (cnt + 1)/2;
			cnt = 0;
		}
	}
	ans += (cnt + 1)/2;
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int degree=0,count=0;
    for (int i=0;i<s.size();i++) {
        if (s[i]=='R') {
            degree+=90;
        } else {
            degree-=90;
        }
        if (degree==360) {
            count++;
            degree=0;
        } else if (degree==-360) {
            degree=0;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n;
    cin>>n;
    cout<<n*n<<NL;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long HMY(long min,long max,long a){     //HowManyYakusuu
    return (long)(max/a) - (long)((min-1)/a);
}
long SKS(long a,long b){       //SaishouKoubaiSuu
    long x=a*b; 
    long c;
    if(a<b){
        c=a;
        a=b;
        b=c;
    }
    c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return x/b;
}
int main(){
    // Your code here!
    long A;
    long B;
    long C;
    long D;
    scanf("%ld %ld %ld %ld",&A,&B,&C,&D);
    printf("%ld",1+B-A-(HMY(A,B,C)+HMY(A,B,D)-HMY(A,B,SKS(C,D))));
  	return 0;
}

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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

ll M = 1e7 + 7;

ll binpow(ll a, long long b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}



void solve() {

	string s , t;
	cin >> s >> t;

	int n = s.size() , m = t.size();

	int ans = t.size();

	for (int i = 0 ; i <= n - m ; i++) {
		int cnt = 0;
		for (int j = 0 ; j < m ; j++) {

			if (s[i + j] != t[j])
				cnt++;

		}

		ans = min(ans , cnt);
	}

	cout << ans << "\n";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin >> t;

	while (t--)
		solve();
	return 0;
}





Measured memory_bytes: 3640
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <set>
#include <cmath>
#include <algorithm>
#include <locale>

//pair sort firstに揃う

#define int long long
#define pb(n) push_back(n)
#define For(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define F first
#define S second
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define ELM 100001 //問題によっては1000000001に変更

//限定
using namespace std;

signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int A=ctoi(s[0]),B=ctoi(s[1]),C=ctoi(s[2]),D=ctoi(s[3]);
    if (A+B+C+D==7) {
        cout<<A<<'+'<<B<<'+'<<C<<'+'<<D<<"=7"<<endl;
    }else if(A+B+C-D==7){
        cout<<A<<'+'<<B<<'+'<<C<<'-'<<D<<"=7"<<endl;
    }else if(A+B-C+D==7){
        cout<<A<<'+'<<B<<'-'<<C<<'+'<<D<<"=7"<<endl;
    }else if(A+B-C-D==7){
        cout<<A<<'+'<<B<<'-'<<C<<'-'<<D<<"=7"<<endl;
    }else if(A-B+C+D==7){
        cout<<A<<'-'<<B<<'+'<<C<<'+'<<D<<"=7"<<endl;
    }else if(A-B+C-D==7){
        cout<<A<<'-'<<B<<'+'<<C<<'-'<<D<<"=7"<<endl;
    }else if(A-B-C+D==7){
        cout<<A<<'-'<<B<<'-'<<C<<'+'<<D<<"=7"<<endl;
    }else if(A-B-C-D==7){
        cout<<A<<'-'<<B<<'-'<<C<<'-'<<D<<"=7"<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,K,Q,T;
  int A[100002]={};
  scanf("%d %d %d",&N,&K,&Q);
  for(int i=1;i<=N;i++)
    A[i]=0;
  for(int i=1;i<=Q;i++){
    scanf("%d",&T);
    A[T]++;
  }
  for(int i=1;i<=N;i++){
    if(Q-A[i]<K) printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2012
#include<cstdio>
#include<cstring>

using namespace std;

const long long mod = 998244353;

long long dp[4040][4040];

int N;
char ch[2020];

void input(){
	scanf("%s", ch);
	N = strlen(ch);
}

long long solve(){
	int rall = 0, ball = 0;
	dp[0][0] = 1;
	for(int i = 0; i < N * 2; ++i){
		if(i < N){
			if(ch[i] == '0') rall += 2;
			else if(ch[i] == '1'){
				rall++;
				ball++;
			}else{
				ball += 2;
			}
		}
		for(int j = 0; j <= i; ++j){
			int r = j, b = i - j;
			if(r + 1 <= rall){
				dp[r + 1][b] = (dp[r + 1][b] + dp[r][b]) % mod;
			}
			if(b + 1 <= ball){
				dp[r][b + 1] = (dp[r][b + 1] + dp[r][b]) % mod;
			}
		}
	}
	return dp[rall][ball];
}

int main(){
	input();
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 127104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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 (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int dp[100005];
vvi graph;

int dfs(int v) {
    if (dp[v] != -1) return dp[v];
    int res = 0;
    for (auto nv : graph[v]) {
        chmax(res, dfs(nv) + 1);
    }
    return dp[v] = res;
}

void solve(int N, int M, std::vector<int> x, std::vector<int> y){
    graph.resize(N);
    rep(i, M) {
        x[i]--; y[i]--;
        graph[x[i]].push_back(y[i]);
    }
    memset(dp, -1, sizeof(dp));
    int ans = 0;
    rep(i, N) chmax(ans, dfs(i));
    cout << ans << endl;
}

int main(){
    int N, M;
    cin >> N >> M;
    vi x(M), y(M);
    for(int i = 0 ; i < M ; i++){
        cin >> x[i] >> y[i];
    }
    solve(N, M, x, y);
    return 0;
}

Measured memory_bytes: 9728
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m,x[110],y[110];
bool e[110][110],vis[110];
int cp[110];
bool dfs(int x)
{
	for (int i=1;i<=n;i++)
		if (e[x][i]&&!vis[i])
		{
			vis[i]=1;
			if (cp[i]==0||dfs(cp[i]))
				{cp[i]=x;return 1;}
		}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
	for (int xx,yy,i=1;i<=n;i++)
	{
		scanf("%d%d",&xx,&yy);
		for (int j=1;j<=n;j++)
			if (x[j]<=xx&&y[j]<=yy) e[j][i]=1;
	}
	int ans=0;
	for (int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		if (dfs(i)) ans++;
	}
	printf("%d",ans);
} 

Measured memory_bytes: 256
import sys
from itertools import combinations, permutations

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]

    mod = 1000000007
    rgb = [0, 0, 0]
    count = 1
    for i in range(N):
        a = A[i]
        if rgb[0] == a:
            if rgb[1] == a:
                if rgb[2] == a:
                    count *= 3
                    count %= mod
                else:
                    count *= 2
                    count %= mod
            rgb[0] += 1
        else:
            if rgb[1] == a:
                if rgb[2] == a:
                    count *= 2
                    count %= mod
                rgb[1] += 1
            else:
                if rgb[2] == a:
                    rgb[2] += 1
                else:
                    count = 0
                    break
    
    print(count)
                    
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14228
S=input();T=input()
dps=[0]*len(S)
for i in range(len(S)):
    if S[i]=="A":
        dps[i]+=1
    if i!=0:
        dps[i]+=dps[i-1]

dpt=[0]*len(T)
for i in range(len(T)):
    if T[i]=="A":
        dpt[i]+=1
    if i!=0:
        dpt[i]+=dpt[i-1]
dps=[0]+dps
dpt=[0]+dpt

q=int(input())
for i in range(q):
    a,b,c,d=map(int,input().split())
    sc=dps[b]-dps[a-1]
    sa=sc-(b-a+1-sc)
    tc=dpt[d]-dpt[c-1]
    ta=tc-(d-c+1-tc)
    if sa%3==ta%3:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 13396
#include<stdio.h>
int main(){
  long long int n,x,a1,a2,res=0;
  scanf("%lld%lld",&n,&x);
  scanf("%lld",&a1);
  if(a1>x){
    res=a1-x;
    a1=x;
  }
  while(--n){
    scanf("%lld",&a2);
    if(a1+a2>x){
      res+=a1+a2-x;
      a2=x-a1;
    }
    a1=a2;
  }
  printf("%lld\n",res);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main(){
    int x;
    cin >> x;
    vector<bool> expo(x + 1);
    expo[1] = 1;
    //2 <= b <= x, 2^2 <= v <= x;
    for(int b = 2; b <= x; b++){
        int v = b * b;
        while(v <= x){
            expo[v] = 1;
            v *= b;
        }
    }
    for(int i = x; i >= 1; i--){
        //Big - small
        if(expo[i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  cin>>N;
  
 // int sw;
  int sw1;
  char s;
  string S;
  
  while(N!=0){
    
    sw1=N%26;
    
    N=N/26;
    
    if(sw1==0){
      sw1=26;
      N=N-1;
    }
    
    s='a'+sw1-1;
    
    S=S+s;
    
    
  }
  
  reverse(S.begin(), S.end());
  cout<<S<<endl;
    
}




Measured memory_bytes: 3632
N, Q = map(int, input().split())
E = [[] for i in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  E[a-1].append(b-1)
#print(E)
xs = [0]*N
for i in range(Q):
  p, x = map(int, input().split())
  xs[p-1] += x
#print(xs)
rs = [0]*N
q = [0]
while q:
  p = q.pop()
  rs[p] += xs[p]
  for c in E[p]:
    rs[c] += rs[p]
    q.append(c)
print(" ".join(map(str, rs)))


Measured memory_bytes: 64932
#include <stdio.h>

int main(void) {
    char S[3];
    scanf("%s", S);
    int count=0;
    for(int i=0; i<3; i++) {
        if(S[i]=='o') count +=1;
    }
    
    printf("%d", 700+count*100);
    return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

vector<int> G[100010];
bool vis[100010];

void dfs(int pos)
{
    vis[pos] = true;
    rep(i, G[pos].size()) if (!vis[G[pos][i]]) dfs(G[pos][i]);
    return;
}

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

    int n, m;
    cin >> n >> m;
    vector<int> x(m), y(m), z(m);
    rep(i, m) cin >> x[i] >> y[i] >> z[i];
    rep(i, m)
    {
        x[i]--;
        y[i]--;
        G[x[i]].push_back(y[i]);
        G[y[i]].push_back(x[i]);
    }
    int ans = 0;
    rep(i, n)
    {
        if (!vis[i])
        {
            ans++;
            dfs(i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
const long long mod=1000000007;
int n,k;
long long fac[5000003],inv[5000003],ifac[5000003],d[2003][2003];
inline long long C(long long n,long long m){
	if(n<m){
		return 0;
	}
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
	cin>>n>>k;
	if(k==1){
		cout<<1<<endl;
		return 0;
	}
	fac[0]=inv[0]=ifac[0]=fac[1]=inv[1]=ifac[1]=1;
	for(int i=2;i<=5000000;i++){
		fac[i]=(fac[i-1]*i)%mod;
		inv[i]=inv[mod%i]*(mod-mod/i)%mod;
		ifac[i]=(ifac[i-1]*inv[i])%mod;
	}
	d[0][1]=1;
	for(int i=2;i<=n;i++){
		d[0][i]=d[0][i-1]*C(i*(k-1)-1,k-2)%mod;
	}
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			d[i][j]=(d[i-1][j]+d[i][j-1]*C(i+j*(k-1)-1,k-2)%mod)%mod;
		}
	}
	cout<<(d[n][n]*fac[n])%mod<<endl;
	return 0;
}

Measured memory_bytes: 148736
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N, M, P;
  while(cin >> N >> M >> P, N || M || M) {
    i64 sum = 0;
    i64 m = 0;
    rep(i,1,N + 1) {
      i64 a;
      cin >> a;
      sum += a;
      if(i == M) m = a;
    }
    if(m == 0) cout << 0 << endl;
    else cout << sum * 100 * (100 - P) / (m * 100) << endl;
  }
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }


int main() {
    init();

    int n, p; cin >> n >> p;
    ll a[2] = {};
    FOR(i, 0, n) {
        int in; cin >> in;
        ++a[in % 2];
    }

    ll ans = (1LL << n);
    if (a[1])ans >>= 1;
    else if (p)ans = 0;
    cout << ans << "\n";
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll A, B;
ll Q;
int main() {
    //cout.precision(10);
    cin >> A >> B >> Q;
    vector<ll> s(A + 2);
    vector<ll> t(B + 2);
    for(int i = 1; i <= A; i++) {
        cin >> s[i];
    }
    for(int i = 1; i <= B; i++) {
        cin >> t[i];
    }
    s[0] = -1e13;
    t[0] = -1e13;
    s[A + 1] = 1e13;
    t[B + 1] = 1e13;
    while(Q--) {
        ll x;
        cin >> x;
        auto safteritr = lower_bound(s.begin(), s.end(), x);
        auto tafteritr = lower_bound(t.begin(), t.end(), x);
        ll ans = 1e15;
        ans = min(ans, max(*safteritr, *tafteritr) - x);
        ans = min(ans, x - min(*(safteritr - 1), *(tafteritr - 1)));
        ans = min(ans, *tafteritr - x + *tafteritr - *(safteritr - 1));
        ans = min(ans, *safteritr - x + *safteritr - *(tafteritr - 1));
        ans = min(ans, x - *(tafteritr -1)+ *safteritr - *(tafteritr-1));
        ans = min(ans, x - *(safteritr-1) + *tafteritr - *(safteritr-1));
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        String ans = "No";
        for(int i = 1; i <= 9; i++){
            if((n%i == 0) && (1 <= n/i) && (n/i <= 9)){
                ans = "Yes";
            }
        }
        
        System.out.println(ans);
    }
}

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

int main()
{

   int a,b,c,d;
   cin>>a>>b>>c>>d;
   while(1)
   {
       if(c-b <=0){
        cout<<"Yes"<<endl;
        return 0;
       }
       c=c-b;
       if(a-d<=0)
       {
           cout<<"No"<<endl;
           return 0;
       }
       a=a-d;


   }
   return 0;

}


Measured memory_bytes: 3620
#include <stdio.h>
#define SIZE 25

int solve(int,int);
int A[SIZE],a;
int main()
{
  int i,B[205],b,heaven;
  scanf("%d",&a);
  for(i=0;i<a;i++)
    {
      scanf("%d",&A[i]);
    }
   scanf("%d",&b);
  for(i=0;i<b;i++)
    {
      scanf("%d",&B[i]);
    }
  for(i=0;i<b;i++)
    {
      heaven=solve(0,B[i]);
      if(heaven==0)
	printf("no\n");
      else
	printf("yes\n");
    }
  return 0;
}

int solve(int count,int tar)
{
  int result;  
  if(tar==0)
    return 1;
  if(count > a)
    return 0;
  result=solve(count+1,tar)+solve(count+1,tar-A[count]);
  return result;
}



Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    const int ss = (int)s.size(), ts = (int)t.size();
    int dp[ss + 1][ts + 1]; rep(i, ss + 1) rep(j, ts + 1) dp[i][j] = 0;
    /*
    cout << "  "; rep(j, ts) cout << t[j] << " ";
    cout << endl;
     */
    rep(i, ss) {
        //cout << s[i] << " ";
        rep(j, ts) {
            
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
            //cout << dp[i + 1][j + 1] << " ";
        }
        //cout << endl;
    }
    //cout << dp[ss][ts] << endl;
    string u;
    int i = ss, j = ts;
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i - 1][j]) {
            --i;
        } else if (dp[i][j] == dp[i][j - 1]) {
            --j;
        } else {
            u = s[i - 1] + u;
            --i; --j;
        }
    }
    
    cout << u << endl;
}


Measured memory_bytes: 35456
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        mut a: i32,
        b: i32,
        mut c: i32,
        d: i32,
    }

    loop {
        c -= b;
        if c <= 0 {
            println!("Yes");
            return;
        }

        a -= d;
        if a <= 0 {
            println!("No");
            return;
        }
    }
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
using gragh = vector<vector<int>>;

void search(int row,int col,vector<vector<string>> &grid,int k,int W) {
    grid[row][col] = to_string(k);
    for (int move:{1, -1}) {
        if (0 <= col + move && col + move<W){
                    if (grid[row][col+move] == "."){

                        search(row, col + move, grid, k, W);
                    }
            }
    }
}

string search_2(int row,int col,vector<vector<string>> &grid,int H,int move) {
        if (0 <= row + move && row + move < H) {
            if (grid[row + move][col] ==  ".") {
                grid[row + move][col] = search_2(row + move, col, grid,H,move);
            }
            return grid[row + move][col];
        }
    }

int main() {
    int H,W,K;
    cin>>H>>W>>K;
    vector<vector <string> > grid (H,vector<string>(W));
//    vector<vector<string>grid(H,vector<string>(W));
    string S;
    for (int i = 0; i < H; ++i) {
        cin>>S;
        for (int j = 0; j < W; ++j) {
            grid[i][j] = S[j];
        }
    }
    int k = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (grid[i][j] == "#"){
                search(i,j,grid,k,W);
                k++;
            }
        }
    }
    for (int i =0;i<H;i++) {
        if (grid[i][0] == "."){
            for (int j = 0; j < W; ++j) {
                if(i!=0) {

                    grid[i][j] = search_2(i, j, grid, H, -1);
                }else{
                    grid[i][j] = search_2(i, j, grid, H, 1);
                }
            }
        }
    }
    for (int l = 0; l < H; ++l) {
        for (int i = 0; i < W; ++i) {
            cout<<grid[l][i]+" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 5760
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    vector<int> a(n), b(m);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    for(int i=0; i<m; ++i)
        cin >> b[i];

    int ret = 0;
    for(int i=0; i<m; ++i){
        int k = i;
        for(int j=0; j<n; ++j){
            if(k < m && a[j] == b[k])
                ++ k;
        }
        ret = max(ret, k-i);
    }

    cout << ret << endl;
    return 0;
}

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

using namespace std;

constexpr int N = 100000;
constexpr int M = 100000;
constexpr int MAX = 10;

int p[M + 1];
string s[M + 1];
bool solved[N + 1];
char aux[MAX + 2];
int penalty[N + 1];

int main() {
	int ans, pen, n, m, i;

	scanf("%d%d", &n, &m);
	ans = pen = 0;

	for (i = 1; i <= m; i++) {
		scanf("%d %s", p + i, aux);
		s[i] = string(aux);

		if (!solved[p[i]]) {
			if (s[i] == "AC") {
				solved[p[i]] = true;
				pen += penalty[p[i]];
				ans++;
			}
			else {
				penalty[p[i]]++;
			}
		}
	}

	printf("%d %d\n", ans, pen);

	return 0;
}

Measured memory_bytes: 6528