akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 200 + 10;
const int maxm = 100000 + 10;
const ll MOD = 1e9 + 7;

ll N, X;

vector<vector<ll>> dp(maxn, vector<ll>(maxm, -1));
vector<ll> nums(maxn);

ll f(ll i, ll x) {
    if (i == N) {
        return x;
    }
    if (dp[i][x] != -1) {
        return dp[i][x];
    }
    ll ans = 0;
    ans += f(i + 1, x % nums[i]);
    ans += f(i + 1, x) * (N - i - 1);
    return dp[i][x] = ans % MOD;
}

int main() {
    cin >> N >> X;
    for (int i = 0; i < N; ++i) {
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end(), greater<ll>());
    cout << f(0, X) << endl;
    return 0;
}

Measured memory_bytes: 165632
#include <algorithm> 
#include <iostream> 
using namespace std; 
int main(){
int a,b,c;
int d=1;
cin>>a>>b>>c;
if(a!=b&&a!=c&&b!=c){
cout<<3<<endl;
return 0;
}
if((a==b&&a!=c)||(b==c&&b!=a)||(c==a&&c!=b)){
cout<<2<<endl;
return 0;
}
cout<<1<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define M 16777216 // 4^12
#define L 14

int H[M][L] = { 0 };

int getChar(char ch) {
    if (ch == 'A') return 0;
    else if (ch == 'C') return 1;
    else if (ch == 'G') return 2;
    else if (ch == 'T') return 3;
}

/* convert a string into an integer value */
long long getKey(string str) {
    long long sum = 0, p = 1, i;
    for (i = 0; i < str.size(); i++) {
        sum += p * (getChar(str[i]));
        p *= 4;
    }
    return sum;
}

int find(string str)
{
    return H[getKey(str)][str.size()];
}

int insert(string str)
{
    return ++H[getKey(str)][str.size()];
}

int main() {
    int i, n;
    string str, cmd;
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> cmd >> str;
        if (cmd == "insert") {
            insert(str);
        }
        else if (cmd == "find")
        {
            if (find(str)) {
                cout << "yes" << endl;
            }
            else {
                cout << "no" << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 60484
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

x,y,z = 0,0,0
for _ in range(int(input())):
    a,b,c = ilele()
    d = a + max(y,z)
    e = b + max(x,z)
    f = c + max(x,y)
    x,y,z = d,e,f
print(max(x,y,z))
    

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

class trie
{
	private:
		trie* ch[26];
		int cnt;
		vector<int> count_ch;
		
	public:
	
		trie()
		{
			cnt=0;
			count_ch=vector<int>(26,0);
			for(int i=0;i<26;i++)
			{
				ch[i]=NULL;
			}
		}
		
		int insert(string s)
		{
			trie* node= this;
			
			int ans=0;
			
			vector<int> count(27,0);
			
			for(int i=0;i<s.length();i++)
			{
				count[s[i]-'a']++;
			}
			
			for(int i=0;i<s.length();i++)
			{
				if(i+1==s.length())
				{
					ans+=node->count_ch[s[i]-'a'];
				}
				for(int j=0;j<26;j++)
				{
					if(count[j])
						node->count_ch[j]++;
				}
				if(node->ch[s[i]-'a']==NULL)
					node->ch[s[i]-'a']=new trie();
				node=node->ch[s[i]-'a'];
				count[s[i]-'a']--;
			}
			return ans;
			
		}
		
		

};



int main()
{
    int n;
    cin>>n;
    
    ll ans=0;
    
    trie* head=new trie();
    
    vector<string> v1;
    
    for(int i=0;i<n;i++)
    {
		string s;
		cin>>s;
		reverse(s.begin(),s.end());
		
		v1.push_back(s);
		ans+=head->insert(s);
	}
	reverse(v1.begin(),v1.end());
	head=new trie;
	for(int i=0;i<n;i++)
	{
		ans+=head->insert(v1[i]);
	}
	cout<<ans;
}


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

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<int> snuke(N, 0);
    for (int i = 0; i < K; i++)
    {
        int di; cin >> di;
        for (int j = 0; j < di; j++)
        {
            int Aij; cin >> Aij;
            snuke[Aij-1]++;
        }
        
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
        if (snuke[i] == 0)
            ans++;
    cout << ans << endl;
}

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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

ostream& operator<<(ostream &out, const pii &a) { return out << '(' << a.x << ", " << a.y << ')'; }
istream& operator>>(istream &in, pii &a) { return in >> a.x >> a.y; }

const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

const int maxV = 1e5;

// lambda-expression: [] (args) -> retType { body }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// cerr << boolalpha;
	(cout << fixed).precision(10);
	
	int N;
	cin >> N;
	vi p(N, 0);
	for (int i = 0; i < N; i++) cin >> p[i];
	int ans = 0;
	bool lastF = false;
	for (int i = 0; i < N; i++) {
		if (p[i] - 1 == i) {
			if (lastF) {
				lastF = false;
			} else {
				lastF = true;
				ans++;
			}
		} else lastF = false;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s;
  int n;
  double kane, res = 0;
  cin >> n;
  rep(i, n) {
    cin >> kane >> s;
    if (s == "JPY") {
      res += kane;
    }else {
      res += kane * 380000;
    }
  }
  cout << res << endl;
}


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

list_size = 10000010

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)


def conv(n,r):
    if r == 0:
        return 1
    return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

ans = 0
for i in range((N//2)):
    ans += conv(N,i) * pow(2,i,MOD)
    ans %= MOD

print((pow(3,N,MOD)-ans*2)%MOD)

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

int main()
{
    int x[4], y[4];
    cin >> x[0] >> y[0] >> x[1] >> y[1];
    int ux, uy;
    ux = x[1] - x[0];
    uy = y[1] - y[0];
    for (int i = 2; i <= 3; i++) {
        int vx = -uy;
        int vy = ux;
        x[i] = x[i - 1] + vx;
        y[i] = y[i - 1] + vy;
        ux = vx;
        uy = vy;
    }
    cout << x[2] << " " << y[2] << " " << x[3] << " " << y[3] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll i, j, k, l, m=0, p=0, h, f=0, ff=0;
    string a, b;
    vector<ll>v[26];
    cin>>a;
    cin>>b;
    for(i=0; i<a.size(); i++){
        j=(int)(a[i])-97;
        v[j].push_back(i+1);
    }

    for(i=0; i<b.size(); i++){
        f=0;
        j=(int)(b[i])-97;
        if(v[j].size()==0){
            cout<<"-1"<<endl;
            ff=1;
            break;
        }
        k=lower_bound(v[j].begin(), v[j].end(), m)-v[j].begin();
        for(h=k; h<v[j].size(); h++){
            if(v[j][h]!=m){
                p=p+(v[j][h]-m);
                m=v[j][h];
                f=1;
                //cout<<m<<" "<<p<<endl;
                break;
            }
        }
        if(f==0){
            p=p+(a.size()-m)+ v[j][0];
            m=v[j][0];
            //cout<<m<<" "<<p<<endl;
        }
    }
    if(ff==0) cout<<p<<endl;
    return 0;
}


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

int main()
{
    int k; cin>>k;
    vector<int> a(k);
    for(auto& e: a) cin>>e;

    long L=2, R=2;
    for(int e: a={rbegin(a), rend(a)}) {
        L=(L+e-1)/e*e;
        R=R/e*e+e-1;
    }
    if (L>R)
        cout<<"-1\n";
    else
        cout<<L<<' '<<R<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int k,now,mp[N];
int main()
{
	cin>>k;
	for(int i=1;;i++)
	{
		now=(now*10+7)%k;
		if(!now){printf("%d",i);return 0;}
		if(mp[now]){puts("-1");return 0;}
		mp[now]=1;
	}
}


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

int main(){
  int n, flag = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    char s;
    cin >> s;
    if(s == 'Y') flag = 1;
  }
  if(flag) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL calc(LL k,LL n)
{
	if(n<k) return n;
	else if(n%k==0) return calc(k,n/k);
	else return n%k;
}
int main(void)
{
	LL n; scanf("%lld",&n);
	LL x;
	x=n-1;
	LL res=0; 
	for(LL i=1;i*i<=x;i++)
	{
		if(x%i) continue;
		if(i>1) res++;
		if(i*i!=x) res++;
	}
	
	x=n;
	for(LL i=1;i*i<=x;i++)
	{
		if(x%i) continue;
		if(i>1)
		{
			if(calc(i,n)==1) res++;
		}
	}
	res++; 
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ull fun(ull n) {
	if (n < 2) {
		return 1;
	} else {
		return n * fun(n - 2);
	}
}

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

	if(n % 2 == 1) {
		cout << 0 << endl;
	} else {
		long long ans = 0LL;
		for(int i = 1; i < 26; ++i){
			ans += n / ((long long)pow(5, i)*2);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 640
//【AtCoder 2069】Snuke's Subway Trip（图重构）
#include <queue>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define x first
#define y second
#define pb push_back
typedef pair<int, int> pii;
const int maxn = 1000005;
vector<pii> ver, line[maxn];
vector<int> g[maxn];
int n, m, fa[maxn], cur, was[maxn], newn, dis[maxn];
int getfa(int u) {
	return fa[u] == u ? u : fa[u] = getfa(fa[u]);
}
void merge(int u, int v) {
	if (was[u] != cur) {
		was[u] = cur;
		ver.pb(pii(0, u));
		fa[u] = u;
	}
	if (was[v] != cur) {
		was[v] = cur;
		ver.pb(pii(0, v));
		fa[v] = v;
	}
	fa[getfa(u)] = getfa(v);
}
int main() {
	scanf("%d %d", &n, &m), newn = n;
	for (int u, v, w, i = 1; i <= m; i++) {
		scanf("%d %d %d", &u, &v, &w);
		line[w].pb(pii(u, v));
	}
	for (int i = 1; i <= 1000000; i++) {
		ver.clear(), ++cur;
		for (int j = 0; j < line[i].size(); j++) {
			merge(line[i][j].x, line[i][j].y);
		}
		for (int j = 0; j < ver.size(); j++) {
			ver[j].x = getfa(ver[j].y);
		}
		sort(ver.begin(), ver.end());
		for (int j = 0, k = 0; j < ver.size(); j = k) {
			++newn;
			while (k < ver.size() && ver[j].x == ver[k].x) {
				g[newn].pb(ver[k].y);
				g[ver[k++].y].pb(newn);
			}
		}
	}
	queue<int> que;
	que.push(1);
	for (int i = 2; i <= newn; i++) {
		dis[i] = -2;
	}
	dis[1] = 0;
	while (!que.empty()) {
		int u = que.front();
		que.pop();
		for (int i = 0; i < g[u].size(); i++) {
			int v = g[u][i];
			if (dis[v] == -2) {
				dis[v] = dis[u] + 1;
				que.push(v);
			}
		}
	}
	printf("%d\n", dis[n] >> 1);
	return 0;
}

Measured memory_bytes: 73984
from collections import defaultdict


def main():
    w = input()
    dic = defaultdict(int)
    for c in w:
        dic[c] += 1
    for d in dic:
        if dic[d] % 2 == 1:
            print('No')
            exit()
    print('Yes')


if __name__ == "__main__":
    main()


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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r) {
	if(l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m+1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());
	for(int i = 0; i < n; i++) {
		if(i) cout << " ";
		cout << post[i]; 
	}
	cout << endl;
}

int main() {
	int k;
	cin >> n;
	
	for(int i = 0; i < n; i++) {
		cin >> k;
		pre.push_back(k);
	}
	
	for(int i = 0; i < n; i++) {
		cin >> k;
		in.push_back(k);
	}
	
	solve();
    
	return 0;	
}

Measured memory_bytes: 3136
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

char a[101];
char b[101];
int main()
{
	scanf(" %s",a);
	scanf(" %s",b);
	int lena = strlen(a);
	int lenb = strlen(b);
	if(lena < lenb){
		printf("LESS\n");
	}
	else if(lena > lenb) {
		printf("GREATER\n");
	}
	else {
		if (strcmp(a,b) < 0) printf("LESS\n");
		else if(strcmp(a,b) > 0) printf("GREATER\n");
		else printf("EQUAL\n");
	}
}

Measured memory_bytes: 128
#include<cstdio>
using namespace std;
const int maxm=4005;
const int maxv=maxm/2;
const int maxn=200005;
const int mod=1000000007;
int n,ans;
int a[maxn],b[maxn];
int f[maxm][maxm],C[maxm][maxm];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for (int i=1;i<=n;i++) f[maxv-a[i]][maxv-b[i]]++;
	for (int i=1;i<maxm;i++) C[i][0]=C[0][i]=1;
	for (int i=1;i<maxm;i++)
		for (int j=1;j<maxm;j++){
			f[i][j]=(f[i][j]+f[i-1][j]+f[i][j-1])%mod;
			C[i][j]=(C[i-1][j]+C[i][j-1])%mod;
		}
	for (int i=1;i<=n;i++){
		ans=(ans+f[maxv+a[i]][maxv+b[i]])%mod;
		ans=(ans-C[a[i]*2][b[i]*2]+mod)%mod;
	}
	ans=1LL*ans*(mod+1)/2%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 126976
#include <stdio.h>
int main(){
	int a,b;
	char op;
while(1){
	scanf("%d %c %d",&a,&op,&b);
	if(op=='?'){break;}
	else if(op=='+'){
		printf("%d\n",a+b);
	}
	else if(op=='-'){
		printf("%d\n",a-b);
	}
	else if(op=='*'){
		printf("%d\n",a*b);
	}
	else if(op=='/'){
		printf("%d\n",a/b);
	}
}
return 0;
}

Measured memory_bytes: 600
// at_abc139c.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int MOD = 1e9 + 7;
int main()
{
    int num;cin >> num;
    vector<int>v(num, 0);
    int best, cur, curnum;
    best = cur = 0;
    for (int i = 0;i < num;i++) {
        cin >> v[i];
    }
    curnum = MOD;
    for (int i = 0;i < num;i++) {
        if (curnum >= v[i]) {
            cur++;
            curnum = v[i];
        }
        else {
            cur = 1;
            curnum = v[i];
        }
        best = max(best, cur);
    }
    cout << best-1 << "\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 640
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print(int((b-a)//2))
else:
    if a-1<n-b:
        #if a+int((b-a-1)/2)<b-1:        
        print(a+int((b-a-1)//2))
        #else:
         #   print(b-1)
    else:
       # if n-b+1+int((n-(a+n-b+1))/2)<n-a:
        print(n-b+1+int((n-(a+n-b+1))//2))
        #else:
         #   print(n-a)

Measured memory_bytes: 3060
#include <stdio.h>

void getgcd(int,int);

int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  getgcd(a,b);
  
  return 0;
}

void getgcd(int a,int b){
  int m,n,k;
  if(a>=b){
    m=a;
    n=b;
  }
  else {
    m=b;
    n=a;
  }
  while(n!=0){
    k=m%n;
    m=n;
    n=k;
  }
  printf("%d\n",m);
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll T1, T2, A1, A2, B1, B2;
  cin >> T1 >> T2;
  cin >> A1 >> A2;
  cin >> B1 >> B2;

  ll V1 = A1 - B1;
  ll V2 = A2 - B2;

  if((V1>0 && V2>0) || (V1<0 && V2<0)){
    cout << 0 << endl;
  }
  else if(V1*T1 + V2*T2 == 0){
    cout << "infinity" << endl;
  }
  else {
    if(V1<0 && V2>0){
      V1 *= -1;
      V2 *= -1;
    }
    ll W1 = V1 * T1;
    ll W2 = V1 * T1 + V2 * T2;

    if(W2 > 0){
      cout << 0 << endl;
    }
    else if(W2 + W1 < 0){
      cout << 1 << endl;
    }else{
      ll cnt = W1/abs(W2);
      cnt *= 2;
      if(W1%W2==0) cnt--;
      cnt += 1;
      cout << cnt << endl;
    }
  }
  
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll nn,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

struct Graph{
    struct edge{
        int to;
        ll cap;
        ll rev;
    };

    int n;
    vector<vector<edge>> edges;

    Graph(int N){
        n = N;
        edges.resize(n, vector<edge>());
    }

    int size() const{return n;}

    vector<edge> &operator[](int v){return edges[v];}
};

struct Dinic{
    int N;
    vector<int> level;
    vector<int> itr;
    Graph G;

    Dinic(int n) : G(n){N = n;}

    void add_edge(int from, int to, ll cap, ll rev_cap){
        G[from].push_back({to, cap, (int)G[to].size()});
        G[to].push_back({from, rev_cap, (int)G[from].size() - 1});
    }

    bool g_level(int s, int t){
        level.assign(N, -1);
        queue<int> que;
        que.push(s);
        level[s] = 0;
        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(auto &e : G[v]){
                if(e.cap > 0 && level[e.to] == -1){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
        return level[t] >= 0;
    }

    ll dfs(int v, int t, ll f){
        if(v == t)return f;

        for(int &i = itr[v]; i < G[v].size(); i++){
            auto &e = G[v][i];
            if(e.cap > 0 && level[e.to] > level[v]){
                ll mi_f = dfs(e.to, t, min(f, e.cap));
                if (mi_f > 0) {
                    e.cap -= mi_f;
                    G[e.to][e.rev].cap += mi_f;
                    return mi_f;
                }
            }
        }
        return 0;
    }

    ll max_flow(int s, int t) {
    ll result = 0;
    ll flow;
    while (g_level(s, t)) {
      itr.assign(N, 0);
      while ((flow = dfs(s, t, 1e9)) > 0)
        result += flow;
    }
    return result;
  }
};

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

    cin>>nn;
    int s=0,t=nn+1;
    rep(i,nn)cin>>a[i];
    Dinic dinic(nn + 2);
    rep(i,nn){
        if(a[i]>=0){
            dinic.add_edge(i+1,t,a[i],0);
            ans+=a[i];
        }
        else{
            dinic.add_edge(s,i+1,-a[i],0);
        }
    }
    rrep(i,1,nn+1){
        for(ll j=2;i*j<=nn;j++){
            dinic.add_edge(i,i*j,INF,0);
        }
    }
    Cout(ans-dinic.max_flow(s,t));
    return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b;cin>>a>>b;

  cout<<max(a+b,max(a-b,a*b))<<endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

// A - Frog 1
// https://atcoder.jp/contests/dp/tasks/dp_a

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &h[i])
	}
	var dp = make([]int, n)
	dp[0] = 0
	dp[1] = Abs(h[1] - h[0])
	var tmp1 int
	var tmp2 int
	for i := 2; i < n; i++ {
		tmp1 = dp[i-2] + Abs(h[i]-h[i-2])
		tmp2 = dp[i-1] + Abs(h[i]-h[i-1])
		if tmp1 < tmp2 {
			dp[i] = tmp1
		} else {
			dp[i] = tmp2
		}
	}
	fmt.Printf("%d\n", dp[n-1])
}


Measured memory_bytes: 6324
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[] dx = {1,0,-1,0};
		int[] dy = {0,1,0,-1};
		int max = 0;
		String[][] maze = new String[h][w];
		for(int i = 0; i < h; i++) maze[i] = sc.next().split("");
		for (int sx = 0; sx < h; sx++) {
			for (int sy = 0; sy < w; sy++) {
				if(maze[sx][sy].equals("#")) continue;
				int[][] d = new int[h][w];
				for (int i = 0; i < h*w; i++) d[i%h][i/h] = 1000;
				d[sx][sy] = 0;
				point point = new point(sx, sy);
				Queue<point> que = new ArrayDeque<point>();
				que.add(point);
				while(0 != que.size()) {
					point p = que.poll();
					for(int i = 0; i < 4; i++) {
						int cx = p.x + dx[i];
						int cy = p.y + dy[i];
						if(cx >= 0 && cx <= h-1 && cy >= 0 && cy <= w-1 && !maze[cx][cy].equals("#")  && d[cx][cy] == 1000) {
							d[cx][cy] = d[p.x][p.y] + 1;
							que.add(new point(cx, cy));
						}
					}
				}
				for (int i = 0; i < h*w; i++) {
					if(d[i%h][i/h] < 1000) max = Math.max(max,d[i%h][i/h]);
				}
			}
		}
		System.out.println(max);
		sc.close();
	}
	public static class point{
		int x; int y;
		point(int x,int y){
			this.x = x; this.y =y;
		}
	}
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }	//最大公約数(Greatest Common Divisor)
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }			//最小公倍数(Least Common Multiple)

long long comb(long long m) {
	return (m * (m - 1)) / 2;
}


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

	ll ans = 0;

	rep(i, s.size()) {
		if (s[i] != t[i])
			ans++;
	}

	cout << ans << endl;
	


}

Measured memory_bytes: 3916
l=list(map(int, input().split(' ')))
a=l[0]
v=l[1]
l=list(map(int, input().split(' ')))
b=l[0]
w=l[1]
s=int(input())
ans=True
if a>b:
    ans=a-v*s<=b-w*s
else:
    ans=a+v*s>=b+w*s
if ans:
    print("YES")
else:
    print("NO")
    



Measured memory_bytes: 61692
# coding:utf-8
while 1:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for j in range(w):
            if i==0 or i==h-1 or j==0 or j==w-1:
                if j==w-1:
                    print("#")
                else :
                    print("#",end='')
            else :
                print(".",end='')
    print()


Measured memory_bytes: 7000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;


int main() {
  ll n;
  cin >> n;
  vec a(n);
  ll s=0;
  for(ll i=0;i<n;i++) {
    cin >> a[i];
    s+=a[i];
  }
  ll cnt=0;
  ll d=n*(n+1)/2;
  if(s%d) {
    cout << "NO" << endl;
    return 0;
  }
  else {
    cnt=s/d;
  }
  vec b(n);
  for(ll i=0;i<n;i++) {
    b[(i+1)%n]=a[(i+1)%n]-a[i];
  }
  for(ll i=0;i<n;i++) {
    b[i]-=cnt;
  }
  ll f=0;
  for(ll i=0;i<n;i++) {
    if(b[i]%n) {
      cout << "NO" << endl;
      return 0;
    }
    f+=abs(b[i])/n;
  }
  if(f==cnt) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 4832
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        a: [u64; n + 1],
        b: [u64; n],
    }
    let mut a = a.clone();
    let mut b = b.clone();
    let min = std::cmp::min;
    let mut ans = 0;
    for i in 0..n {
        let v = min (a[i], b[i]);
        ans += v;
        a[i] -= v;
        b[i] -= v;
        let v = min (a[i + 1], b[i]);
        ans += v;
        a[i + 1] -= v;
        b[i] -= v;
    }
    println! ("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 12280
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	long long a[100];
	scanf("%d",&n);
	a[0] = 2;
	a[1] = 1;
	for(int i=2 ; i<=n ; i++){
		a[i] = a[i-2] + a[i-1];
	}
	printf("%lld\n",a[n]);
}	


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

int main() {
  int n;cin>>n;
  string s;cin>>s;
  
  vector<int> sw(n);
  vector<int> se(n);
  for (int i=0;i<n;i++) {
    if(i==0) {
      sw.at(i)=0;
      se.at(n-1-i)=0;
    }
    else {
      s.at(i-1)=='W'?sw.at(i) = sw.at(i-1)+1:sw.at(i) = sw.at(i-1);
      s.at(n-i)=='E'?se.at(n-1-i) = se.at(n-i)+1:se.at(n-1-i) = se.at(n-i);
    }
    //cout << sw.at(i) << " " << se.at(n-i-1) << endl;
  }
  int ans=sw.at(0)+se.at(0);
  for(int i=0;i<n;i++) {
    ans=min(ans,sw.at(i)+se.at(i));
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <string>

int main() {
    int result = 0;
    std::string s;
    std::string w;
    std::transform(w.begin(), w.end(), w.begin(), tolower);
    std::cin >> w;
    std::cin.ignore();
    while (true) {
        std::cin >> s;
        if (s == "END_OF_TEXT") break;
        std::transform(s.begin(), s.end(), s.begin(), tolower);
        if (s == w) result += 1;
    }
    std::cout << result << std::endl;
}


Measured memory_bytes: 3164
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	int a,b,x;
	cin >> a >> b >> x;
	if(a<=x && x<=a+b)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxStore = 2e5 + 5;
int nbStore, sj, totNeg, totZer;
ll sum[maxStore];
struct STORE {
	ll slope, add;
	STORE operator = (const STORE &d) {
		slope = d.slope;
		add = d.add;
		return (*this);
	}
} store[maxStore], zero[maxStore];
ll dp[maxStore][35];
bool cmp1(STORE fir, STORE sec) {
	return (1ll * sec.slope * (fir.add + 1) < 1ll * fir.slope * (sec.add + 1));
}
bool cmp2(STORE fir, STORE sec) {
	return fir.add < sec.add;
}
int main() {
	scanf("%d%d", &nbStore, &sj);
	for (int i = 1; i <= nbStore; ++i) {
		STORE tmp;
		scanf("%lld%lld", &tmp.slope, &tmp.add);
		if (tmp.slope != 0)
			store[++totNeg] = tmp;
		else zero[++totZer] = tmp;
	}
	sort(store + 1, store + totNeg + 1, cmp1);
	sort(zero + 1, zero + totZer + 1, cmp2);
	for (int i = 1; i <= totZer; ++i)
		sum[i] = sum[i - 1] + zero[i].add + 1;
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	for (int pre = 1; pre <= totNeg; ++pre) {
		dp[pre][0] = 0;
		//前几个取0个应该都是0 
		for (int chos = 1; chos <= 30; ++chos) {
			dp[pre][chos] = dp[pre - 1][chos];
			if (dp[pre - 1][chos - 1] > 1e9)
				continue ;
			ll tmp = (dp[pre - 1][chos - 1] + 1) * (store[pre].slope + 1) + store[pre].add;
			if (tmp > 1e9) continue ;
			else dp[pre][chos] = min(dp[pre][chos], tmp);
		}
	}
	int ans = 0;
	for (int chos = 0; chos <= 30; ++chos) {
		ll spare = sj - dp[totNeg][chos];
		if (spare < 0) break ;
		int pos = upper_bound(sum + 1, sum + totZer + 1, spare) - sum;
		ans = max(chos + pos - 1, ans);
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a>0) cout << "Positive" << endl;
  else if(b<0 and (b-a)%2==0) cout << "Negative" << endl;
  else if(b<0 and (b-a)%2==1) cout << "Positive" << endl;
  else cout << "Zero" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if((a+b)%3==0||a%3==0||b%3==0){
		cout<<"Possible"<<endl;
	}
	else{
		cout<<"Impossible"<<endl;
	}
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[False]*(k+1) #0:i個だったら必ず負ける，正:勝つ
    for i in range(min(A),k+1):
        for a in A:
            if i-a>=0 and not dp[i-a]:
                dp[i]=True
                break
        else:
            dp[i]=False
    if dp[k]:
        print("First")
    else:
        print("Second")

if __name__=='__main__':
    main()

Measured memory_bytes: 40560
N = int(input())
box = list(map(int, input().split()))
mcnt = float('inf')
for b in box:
    cnt = 0
    while b % 2 == 0:
        b = b // 2
        cnt += 1
        if cnt > mcnt:
            break
    if cnt < mcnt:
        mcnt = cnt
print(mcnt)

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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define MAX 99999999

int main(){
    string s;
    cin >> s;
    int count = MAX;
    for(int i = 0;i < s.size();i++){
        int a = 0;
        int b = 0;
        for(int j = 0;j < s.size();j++){
            if(s.at(j) == s.at(i)){
                b = max(a,b);
                a = 0;
            }
            else{
                a++;
            }
        }
        b = max(a,b);
        count = min(count,b);
    }
    cout << count << endl;
}


Measured memory_bytes: 256
# ABC115 C - Christmas Eve
# 案1. nCk通りについてhmax - hminを網羅的に計算する(TLE)
# 案2. ソートして、1〜Kまで、2〜K+1まで、N-K+1〜Nを調べる

N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]

h = sorted(h)
ans = 9999999999
for i in range(N-K+1):
    ans = min(ans, h[i+K-1] - h[i])
print(ans)

Measured memory_bytes: 8280
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String N = in.next();
		int n = Integer.parseInt(N);
		int temp = 0;
		for(int i = 0; i < N.length(); i++){
			temp += Integer.parseInt(String.valueOf(N.charAt(i)));
		}
		if(n % temp == 0)System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 22612
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

const int INF = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i, n, x[N], y[N];

void solve()
{
    cin >> n;
    int mnd = INF, mns = INF, mxd = -INF, mxs = -INF;
    for (i = 1; i <= n; i++)
    {
        cin >> x[i] >> y[i];
        mnd = min(mnd, x[i] - y[i]);
        mns = min(mns, x[i] + y[i]);
        mxd = max(mxd, x[i] - y[i]);
        mxs = max(mxs, x[i] + y[i]);
    }
    int ans = max(mxs - mns, mxd - mnd);
    cout << ans;
}

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

Measured memory_bytes: 6764
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
int inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
vector <pair<string, int>> music;
int n;
string x;
int xx=0;

//inputします
void input() {
    cin >> n;
    music.resize(n);
    ff(i, 0, n) {
        cin >> music[i].first >> music[i].second;
    }
    cin >> x;
}

//ライブラリ置き場

//main
int main() {
    input();
    i64 ans = 0;
    ff(i, 0, n) {
        if (xx)ans += music[i].second;
        if (x == music[i].first) {
            xx = 1;
        }
    }
    cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], lst[N], mark[N], ans;
vector<int> v[3], gr[N];
void dfs(int x) {
	v[0].push_back(x);
	v[1].push_back(a[x]);
	mark[x] = 1;
	for (auto u : gr[x]) {
		if (!mark[u]) 
			dfs(u);
	}
	return;
}
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	for (int i = 0; i < n; i++) {
		if (!mark[i]) {
			dfs(i);
			for (int j = 0; j < v[0].size(); j++) 
				lst[v[0][j]] = i + 1;
			for (int j = 0; j < v[1].size(); j++) 
				if (lst[v[1][j]] == i + 1) {
					ans++;
				}
			v[0].clear();
			v[1].clear();
		}	
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 10788
def input_from_console():
    d, t, s = map(int, input().split())
    return d, t, s


def solve(d, t, s):
    result = "No"
    if d <= t * s:
        result = "Yes"
    return result


def main():
    d, t, s = input_from_console()
    print(solve(d, t, s))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Measured memory_bytes: 9204
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int l, r, d;

int main()
{
    scanf("%d%d%d", &l, &r, &d);
    int cnt = 0;
    for(int i=l; i<=r; i++){
        if(i%d == 0)
            cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 1732
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int A[] = new int[N];
        for (int i=0; i<N; i++)
            A[i] = Integer.parseInt(sc.next());
        int B[] = new int[N];
        for (int i=0; i<N; i++)
            B[i] = Integer.parseInt(sc.next());
        int C[] = new int[N-1];
        for (int i=0; i<N-1; i++)
            C[i] = Integer.parseInt(sc.next());
        sc.close();

        int sum = Arrays.stream(B).sum();

        for (int i=0; i<N-1; i++) {
            if (A[i]+1==A[i+1])
                sum += C[A[i]-1];
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(sum);
        out.flush();
    }
}

Measured memory_bytes: 26196
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
vector<string>g;
vector<vector<bool>>used;
vector<vector<int>>memo;
int cnt = 0;
int dfs(int y,int x){
    
    used[y][x] = true;
    char c = g[y][x];
    if(c == '#')cnt++;
    int cal = (c == '.');
    rep(k,4){
        int ny = y + dy[k];
        int nx = x + dx[k];
        if(valid(nx, ny) and c != g[ny][nx] and !used[ny][nx]){
            cal += dfs(ny,nx);
        }
    }
    return cal;
}
signed main(){
    cin >> H >> W;
    g = vector<string>(H);
    used = vector<vector<bool>>(H,vector<bool>(W,false));
    for(auto & s :g) cin >> s;
    int ans = 0;
    rep(i,H)rep(j,W)if(g[i][j] == '#' and !used[i][j]){
        ans += dfs(i,j) * cnt;
        cnt = 0;
    }
    cout << ans << endl;
}




Measured memory_bytes: 13056
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long q = sc.nextLong();
		long h = sc.nextLong();
		long s = sc.nextLong();
		long d = sc.nextLong();
		long n = sc.nextLong();
		long[] minValue = new long[4];
		minValue[0] = q;
		minValue[1] = Math.min(2 * minValue[0], h);
		minValue[2] = Math.min(2 * minValue[1], s);
		minValue[3] = Math.min(2 * minValue[2], d);
		long ans = n / 2 * minValue[3] + n % 2 * minValue[2];
		System.out.println(ans);
	}
}

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

int main() {
  int N, F = 0;
  cin >> N;

  for (int i =0; i < N; i++) {
    string color;
    cin >> color;
    if (color == "Y") {
      F = 1;
    }
  }
  if (F)
    cout << "Four" << endl;
  else 
    cout << "Three" << endl;
}


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

int main()
{
    int n;
    int n100, n10, n1;

    cin >> n;

    n100 = (n - (n % 100)) / 100;
    n10  = (n % 100 - n % 10) / 10;
    n1 = n % 10;

    if(n100 == 1){
        n100 = 9;
    }
    else if( n100 == 9){
        n100 = 1;
    }

    if(n10 == 1){
        n10 = 9;
    }
    else if( n10 == 9){
        n10 = 1;
    }

    if(n1 == 1){
        n1 = 9;
    }
    else if( n1 == 9){
        n1 = 1;
    }

    cout << n100 * 100 + n10 * 10 + n1 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

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

    int cnt=0;
    REP(i, 0, 3){
        if(s[i]==t[i]) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	ll n,a;
	ll x=1e5+5;
	cin >> n;
	ll eaten=0;
	ll c[x];
	FOR(i,x) c[i]=0;
	FOR(i,n){
		cin >> a;
		c[a+1]++;
	}
	FOR(i,x){
		eaten+=max(c[i]-1,0LL);
	}
	if(eaten%2)eaten++;
	cout <<n-eaten; 
	

	return 0;
}

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

int main() {
	int N;
	long M;
	cin >> N >> M;
	vector<pair<long, long>> AB(N);
	for (pair<long, long>& i : AB) cin >> i.first >> i.second;
	sort(AB.begin(), AB.end());
	long sum = 0, ans = 0;
	for (int i = 0; sum < M; ++i) {
		if (M - sum < AB[i].second) {
			ans += (M - sum) * AB[i].first;
			sum = M;
		}
		else {
			sum += AB[i].second;
			ans += AB[i].first * AB[i].second;
		}
	}
	cout << ans;
}

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

int main() {
	int N;
	cin >> N;
	int sn = 0;
	int n = N;
	for(int i = 0;N > 0;i++){
		sn += N % 10;
		N /= 10;
	}
	if(n % sn == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int main(){
  int a[3];
  rep(i,3) cin>>a[i];
  sort(a,a+3);
  prin(a[0]+a[1]);
  

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){

	    int n = sc.nextInt();

	    int count = 0;
	    int sum = 0;
	    for(int i=0; i<=9; i++){
		for(int j=0; j<=9; j++){
		    for(int k=0; k<=9; k++){
			for(int l=0; l<=9; l++){
			    sum = i+j+k+l;
			    if(sum==n){count++; l = 9;}
			}
		    }
		}
	    }

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

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include <unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 100000+10

ll N,H;
ll A[VMAX],B[VMAX];
ll ans;


int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N>>H;
    REP(i,N){
        cin>>A[i]>>B[i];
    }
    std::sort(A,A+N);std::sort(B,B+N);
    REP(i,N){
        if(A[N-1]<B[N-1-i])H-=B[N-1-i];
        else break;
        ans++;
        if(H<=0){
            cout<<ans<<endl;
            return 0;
        }
    }
    DEB(ans)
    ans+=(H%A[N-1]==0?H/A[N-1]:H/A[N-1]+1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
program main
  implicit none
  
  integer :: a,b,i,j,p,q
  
  read(*,*)a,b
  if (b < 10) then
    p = 10*a+b
  else if (b < 100) then
    p = 100*a+b
  else
    p = 1000*a+b
  end if
  
  q = int(sqrt(real(p)))
  if (q*q == p) then
    write(*,*)'Yes'
  else
    write(*,*)'No'
  end if
end program main

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: return true;
    }

    // n > 2 が保証された

    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }

    return true;
}

int main()
{
	int x;

	cin>>x;
	int ss = x + 10000;
	for (size_t i = x; i < ss; i++) {
		if (is_prime(i)) {
			cout << i;
			return 0;
		}
	}
	return 0;
}


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


int main(){
    int N , A , B; cin >> N >> A >> B;

    if((A - B -1) % 2 == 0) cout << "Borys" << endl;
    else cout << "Alice" << endl;
    return 0;
}


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

map<long long,long long>m;
long long a[1000010];
long long n,k;

int main()
{
	cin>>n>>k;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(int i=1; i<=n; i++)
		a[i]=(a[i-1]+a[i]-1)%k;
	long long ans=0;
	m[0]++;
	for(int l=0,r=1; r<=n; r++)
	{
		if(r-l==k)
			m[a[l++]]--;
		ans+=m[a[r]];
		m[a[r]]++;
	}
	cout<<ans<<endl;
}


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

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

const int maxn = 1e5 + 5;
vector<int> G[maxn * 2];

class CManagement {
 public:
  void solve(std::istream &in, std::ostream &out) {
      int n, x;
      in >> n;

      for (int i = 0; i < n; ++i)
          G[i].clear();

      forn(i, n - 1) {
          in >> x;
          G[x - 1].push_back(i + 1);
      }
      //dfs(0);
      for (int i = 0; i < n; ++i) {
          out << G[i].size() << '\n';
      }
  }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    CManagement solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 14560
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	int[] h = ReadIntArray();
	int ans = 0;
	int m = 0;
	for (int i = 1; i < n; i++)
	{
	    if (h[i] <= h[i-1]){ m++; }
	    else
	    {
		ans = Math.Max(ans, m);
		m = 0;
	    }
	}
	ans = Math.Max(ans, m);
	WriteLine(ans);
    }
}


Measured memory_bytes: 28252