akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll K;
    cin >> K;
    ll exp = 0;
    ll ans = 0;
    ll cnt = 0;
    while (exp <= pow(10, 6) + 10) {
        ans += 7 * modpow(10, exp, K);
        ans %= K;
        cnt++;
        exp++;
        if (ans == 0) {
            cout << cnt << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,t,ans=1001;
    cin>>n>>t;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(t>=b)ans=min(ans,a);
    }
    if(ans==1001)cout<<"TLE"<<endl;
    else cout<<ans<<endl;
}


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


int main(){
  string s;
  cin >> s;
  int k,i,j;
  i=0;
  k=0;
  j=0;
  while(i<s.size()){
    if(s[i]==s[i+1] && j==0){
      i+=2;
      k++;
      j=1;
    }else if(s[i]==s[i+1] && j==1){
      i++;
      k++;
      j=0;
    }else if(s[i]!=s[i+1]){
      i++;
      k++;
      j=0;
    }

  }
  cout << k << endl;
  return 0;
}


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

using namespace std;

int x, n;
bool vis[105];

int main()
{
    
    cin >> x >> n;
    for (int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        vis[a] = 1;
    }
    for (int d = 0; d <= 100; d++)
    {
        if (!vis[x - d])
        {
            cout << x - d << endl;
            return 0;
        }
        if (!vis[x + d])
        {
            cout << x + d << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	char C;
	cin >> C;
	C += 1;
	cout << C << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(void){
    int a,b;cin >> a >> b;
    string s; cin >> s;

    bool isnew = false;
    int preCount = 0;
    int fuCount = 0;

    for (int i=0;i<s.size();i++){
        if (s[i]!='-'){
            if (!isnew) {
                preCount++;
            } else {
                fuCount++;
            }
        } else {
            isnew = true;
        }
    }

    if (preCount == a && fuCount == b) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

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

int mod(int a, int K)
{
	return a % K;
}

int main()
{
	int K;

	scanf("%d", &K);
	int num = 7;
	int ans = 1;
	int *check = calloc(K, sizeof(int));
	if (K % 2 == 0)
	{
		printf("-1\n");
		return (0);
	}
	int m;
	do {
		m = mod(num, K);
		if (m == 0)
			break;
		if (check[m] == 1)
		{
			ans = -1;
			break;
		}
		check[m] = 1; // mではわりきれなかった。
		ans++;
		num = m * 10 + mod(7, K);
	} while(1);
	printf("%d\n", ans);
	return (0);
}


Measured memory_bytes: 5640
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n1 = sc.nextInt();
		int n2 = sc.nextInt();
		int n3 = sc.nextInt();
		int n4 = sc.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		list.add(n1);
		list.add(n2);
		list.add(n3);
		list.add(n4);
		
		if(list.contains(1) && list.contains(9) && list.contains(7) && list.contains(4)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 21332
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


def inv(a, mod):
    return pow(a, mod - 2, mod)


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


def main():
    N = int(input().strip())
    C = [10 ** 5] * 26
    for _ in range(N):
        tmp = [0] * 26
        S = input().strip()
        for s in S:
            tmp[ord(s) - ord("a")] += 1

        for i in range(26):
            C[i] = min(C[i], tmp[i])

    res = ""
    for i, c in enumerate(C):
        if c == 0:
            continue
        res += chr(i + ord("a")) * c
    print(res)


if __name__ == "__main__":
    main()



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

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

    int b[m];
    rep(i,m) cin >> b[i];
    
    int ans = 0;
    rep(i,n) {
        int res = 0;
        rep(j,m) {
            int a;
            cin >> a;
            res += a*b[j];
        }
        if (res > -c) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  ll n;
  cin>>n;
  if(n&1){
    cout<<0<<'\n';
    return 0;
  }
  ll two=0, five=0;
  ll cur=2;
  while(cur<=n){
    two+=n/cur;
    cur*=2;
  }
  cur=5;
  while(cur<=n){
    five+=n/cur/2;
    cur*=5;
  }
  cout<<min(two, five)<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
const int maxn=2e5+10;
ll a[maxn],sum[maxn];
ll aabs(ll a,ll b)
{
    return a>b?(a-b):(b-a);
}
int main()
{
    ll n;
    cin>>n;
    ll i,j,ans=0;
    for(i=1; i<=n; i++)
        cin>>a[i],ans+=a[i],sum[i]=a[i]+sum[i-1];
    ll minn=1ll<<62;
    for(i=1; i<n; i++)
        minn=min(aabs(ans-sum[i],sum[i]),minn);
    cout<<minn<<endl;
    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main()
{
	int n;
	int AC = 0, WA = 0, TLE = 0, RE = 0;
	char s[100000][3];
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%s", s[i]);
		if(s[i][0] == 'A'){
			AC++;
		}else if(s[i][0] == 'W'){
			WA++;
		}else if(s[i][0] == 'T'){
			TLE++;
		}else{
			RE++;
		}
	}

	printf("AC x %d\n", AC);
	printf("WA x %d\n", WA);
	printf("TLE x %d\n", TLE);
	printf("RE x %d\n", RE);
}


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

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

  vector<int> a(n);
  rep (i, n) cin >> a[i];

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

  int alice = 0, bob = 0; //得点
  rep (i, n) {
    if (i % 2 == 0) alice += a[i];
    else bob += a[i];
  }

  cout << alice - bob << endl;

  return 0;
}


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

using namespace std;

#define int64 long long 
#define fi first
#define se second
const int mod = (int) 1e9 + 7;

const int nax = 2e5 + 5;

void add_self(int &a, int b){
	a = a + b;
	if(a >= mod)a -= mod;	
}


void test_case(){
	int n;
	cin >> n;
	vector<int64> a, b, c, d;
	for(int i=0; i<n; i++){
		int x, y;
		cin >> x >> y;
		a.push_back(x + y);
		b.push_back(x - y);
		c.push_back(-x + y);
		d.push_back(-x - y);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	sort(d.begin(), d.end());
	int64 ans = a[n-1] - a[0];
	ans = max(ans, b[n-1] - b[0]);
	ans = max(ans, c[n-1] - c[0]);
	ans = max(ans, d[n-1] - d[0]);
	cout<<ans<<"\n";
}

int main(){
	int t=1;
	//cin>>t;
	while(t--){
		test_case();
	}
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  string s,t;
  cin >>s >> t;
  ll ans = 0;
  REP(i,3){
    if(s[i]==t[i]) ans++;
  }
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int n;

void dfs(string s, char c) {
	if (s.size() == n) {
		cout << s << endl;
	}
	else {
		for (char i = 'a'; i <= c; ++i) {
			if (i == c) dfs(s + i, c + 1);
			else dfs(s + i, c);
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	dfs("", 'a');
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;

public class Main {
  public static void main(String[]$) {
    Scanner s=new Scanner(System.in);
    long a=s.nextInt(),b=s.nextInt(),c=s.nextInt();
    System.out.println(a%2+b%2+c%2==3?Math.min(Math.min(a*b,b*c),c*a):0);
  }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 200011
ll s[27];
int main(){
   ll n,i,x,y,k,ans=0;
   string a;
   cin>>a;
   for(i=0;i<a.size();i++){
      s[a[i]-'a']+=1;
   }
   for(i=0;i<27;i++){
      if(s[i]%2!=0){
        cout<<"No"<<endl;
        ans=1;
        break;
      }

   }
   if(ans==0) cout<<"Yes"<<endl;

}





Measured memory_bytes: 3612
def count_unit(ss,pp):
    count = 0
    for i in lst:
        if ss == i.lower():
            count = count + 1
    return count

s = str(input())
sum = 0
while True:
    lst = list(map(str, input().split()))
    if lst[0] == "END_OF_TEXT":
        print(sum)
        break
    else:
        sum += count_unit(s,lst)



Measured memory_bytes: 5560
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Queue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;



public class Main{
	
	static int posx;
	static int posy;
	static int type;
	static int diff;
	static int INF = Integer.MAX_VALUE;
	static int[][] d;
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 
	 int N=sc.nextInt();
	 
	 int[] p=new int[N];
	 
	 for(int i=0;i<N;i++) {
		 p[i]=sc.nextInt();
	 }
	
	 int count = 0;
	 
	 for(int i=0;i<N-1;i++) {
		 if(p[i]==i+1&&p[i+1]==i+2) {
			 int temp=p[i+1];
			 p[i+1] = p[i];
			 p[i] = temp;
			 count++;
		 }
	 }
	 
	 for(int i=0;i<N;i++) {
		 if(p[i]==i+1) {
			 
			 count++;
		 }
	 }
	 
	 System.out.println(count);
	
	
	
	 
	 
	 
	
	 
	 
	 
 }
	


}


Measured memory_bytes: 48828
// 去吧！皮卡丘! 把AC带回来！
//			へ　　　　　／|
// 　　/＼7　　　 ∠＿/
// 　 /　│　　 ／　／								AC		AC		AC		AC
//		│　Z ＿,＜　／　　 /`ヽ						AC		AC		AC		AC
//		│　　　　　ヽ　　 /　　〉					AC		AC		AC		AC
// 　Y　　　　　`　 /　　/	/						AC		AC		AC		AC
// 　亻●　.　●　　〈　/　/						AC		AC		AC		AC
// 　()　 へ　　　　|　＼〈							AC		AC		AC		AC
// 　　>- ._　 ィ　 │ ／／							AC		AC		AC		AC
// 　 / へ　　 /　/＜| ＼＼							AC		AC		AC		AC
// 　 ヽ_/　　(_／　 │／／							AC		AC		AC		AC
// 　　 7　　　　　　　|／							AC		AC		AC		AC
// 　　 ＞―r￣￣`-―＿/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

using namespace std;

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int n,k,c;
char s[200010];
int lwork[200010],rwork[200010];

int main(int argc,char const *argv[])
{
	ios::sync_with_stdio(false);
	
	scanf("%d%d%d",&n,&k,&c);
	scanf("%s",s);
	
	for(int i=0;i<n;i++)
	{
		int add=(s[i]=='o');
		
		if(i==0)lwork[i]=add;
		else if(i<c+1)lwork[i]=max(lwork[i-1],add);
		else lwork[i]=max(lwork[i-1],lwork[i-c-1]+add);
	}
	for(int _i=0;_i<n;_i++)
	{
		int i=n-1-_i;
		int add=(s[i]=='o');
		
		if(_i==0)rwork[i]=add;
		else if(_i<c+1)rwork[i]=max(rwork[i+1],add);
		else rwork[i]=max(rwork[i+1],rwork[i+c+1]+add);
	}
	for(int i=0;i<n;i++)
	{
		int works=0;
		
		if(i>0)works+=lwork[i-1];
		if(i<n-1)works+=rwork[i+1];
		if(works<k)printf("%d\n",i+1);
	}
	
	//printf("Time used=%.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*	GOD BLESS	*/


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n,p,m;
char s[10];
while(cin>>n>>p){
int x[n],y[n]; m=10000000;
for(i=0;i<n;i++){
    cin>>x[i]>>y[i];
    if(x[i]<m&&y[i]<=p)m=x[i];
} if(m==10000000)cout<<"TLE"<<endl;
else cout<<m<<endl;
}
return 0;
}


Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main(){
ll Q,H,S,D,N;
cin>>Q>>H>>S>>D>>N;
N*=4;
ll ans=0;
if((D<=S*2)&&(D<=H*4)&&(D<=Q*8)){
    ans+=(N/8)*D;
    N=N%8;
    if((S<=H*2)&&(S<=Q*4)){
        ans+=S*(N/4);
    }
    else if(H*2<=Q*4){
        ans+=H*(N/2);
    }
    else{
        ans+=Q*N;
    }


}
else if((S*2<=H*4)&&(S*2<=Q*8)){
    ans+=(N/4)*S;
}
else if(H*4<=Q*8){
    ans+=(N/2)*H;

}
else{
    ans+=N*Q;
}
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 3652
const main = (input) => {
  const [nStr, s] = input.split('\n')
  const n = Number(nStr)
  let result = 1
  for (let i = 1; i < n; i++) {
    const pre = s[i-1]
    const char = s[i]
    if (pre !== char) result++
  }
  console.log(result)
  
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
typedef double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265

int arr[100000];
int st[100001];


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n , m;
    cin >> n >> m;
    int a , b;
    vector<PII> vec;
    set<int> aa;
    memset(st , 1000001 , sizeof(st));
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        a--;
        b--;
        st[a] = min(st[a] , b);
        aa.insert(a);
    }
    for (auto it : aa) {
        vec.pb({it , st[it]});
    }
    sort(all(vec));

    set<PII> vans;
    int l = -1;
    int r = 1000001;
    bool f = false;
    for (int i = 0; i < (int)vec.size(); i++) {
        if (vec[i].first > l && vec[i].first < r) {
            l = vec[i].first;
            r = min(r , vec[i].second);
            f = true;
            if (i + 1 == (int)vec.size()) {
                vans.insert({l , r});
            }
        }
        else {
            if (f) vans.insert({l , r}) , f = false , l = vec[i].first , r = vec[i].second;
            else vans.insert({l , r}) , l = vec[i].first , r = vec[i].second;
        }
    }
    vans.insert({l , r});

    cout << (int)vans.size() << endl;

    return 0;
}


Measured memory_bytes: 6524
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;
const int N = 550;
const int M = 1000010;

int f[N][N];
int n,m;
int ans;

struct data{
	int i,j;
	int x,y;
}e[M];

void init() {
	scanf("%d%d",&n,&m);
	for(int i = 1 ; i <= n ; i++)
	  	for(int j = 1 ; j <= m ; j++)
	    	scanf("%d",&f[i][j]);
}
void work() {
	for(int i = 1 ; i < n ; i++)
	  	for(int j = 1 ; j <= m ; j++)
			if(f[i][j] & 1) {
				f[i+1][j]++;
				e[++ans].i = i;
				e[ans].j = j;
				e[ans].x = i + 1;
				e[ans].y = j;
			}
	for(int i = 1 ; i < m ; i++) 
		if(f[n][i] & 1) {
			f[n][i + 1]++;
			e[++ans].i = n;
			e[ans].j = i;
			e[ans].x = n ;
			e[ans].y = i + 1;
		}
}
void print() {
	printf("%d\n",ans);
	for(int i = 1 ; i <= ans ; i++) 
		printf("%d %d %d %d\n",e[i].i,e[i].j,e[i].x,e[i].y); 	
}

int main() {
	init();
	work();
	print();
	return 0;
}

Measured memory_bytes: 6400
n,m = map(int, input().split())
a = []
b = []
c = []
for i in range(m):
  a.append(list(map(int, input().split())))
for i in range(m):
  b.append(a[i][0])
  c.append(a[i][1])
  
b_max = max(b)
c_min = min(c)

ans = max(0, min(c) - max(b) + 1)

print(ans)



Measured memory_bytes: 29076
mod=998244353
N,M,K=map(int,input().split())
MAX_N=N+1
Fact=[0 for i in range(MAX_N+1)]
Finv=[0 for i in range(MAX_N+1)]
Fact[0]=1
for i in range(MAX_N):
    Fact[i+1]=(i+1)*Fact[i]
    Fact[i+1]%=mod
Finv[-1]=pow(Fact[-1],mod-2,mod)
for i in range(MAX_N-1,-1,-1):
    Finv[i]=(i+1)*Finv[i+1]
    Finv[i]%=mod
def C(n,k):
    return (Fact[n]*Finv[k]*Finv[n-k])%mod
'''
i in range(K+1)で総和を取る
隣り合うブロックの色が同じ色なのはi通り
隣り合うブロックの色が異なるのはN-1-i通り
｜の選び方はN-1Ci
同じものをつなげてN-i個のブロックと見なせる
これに対してM*((M-1)のN-1-i)乗だけある
0<=i<=K
よりN-1-i>=N-1-K>=0
問題なし
'''
ans=0
for i in range(K+1):
    ans+=(C(N-1,i)*M*pow(M-1,N-1-i,mod))%mod
    ans%=mod
print(ans)

Measured memory_bytes: 103132
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(30);
    int n,i,a,s=0,m;
    vector<int> h;
    vector<int> tab;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        h.push_back(a);
    }
    for(i=0;i<n-1;i++){
        if(h[i+1]<=h[i]){
            s=s+1;
        }
        else if (h[i+1]>h[i]){
            tab.push_back(s);
            s=0;
        }
        if (i==n-2)
            tab.push_back(s);
    }
    m=0;
    for(i=0;i<tab.size();i++){
        if(tab[i]>m){
            m=tab[i];
        }
    }
    cout<<m;
    return 0;
}


Measured memory_bytes: 1400
public class Main {


  private static void solve() {
    int n = ni() - 1;
    long a = nl();
    long b = nl();
    long c = nl();
    long d = nl();


    for (long k = 0; k <= n; k++) {
      long min = a + k * c - (n - k) * d;
      long max = a + k * d - (n - k) * c;
      if (min <= b && b <= max) {
        System.out.println("YES");
        return;
      }
    }
    System.out.println("NO");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23124
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    vector<int> c;
    int x = 1;
    while(x <= n){
        c.push_back(x);
        x *= 6;
    }
    x = 9;
    while(x <= n){
        c.push_back(x);
        x *= 9;
    }
    int dp[15][100010];
    rep(i, c.size()+1){
        rep(j, n+1){
            if(j == 0){
                dp[i][j] = 0;
            }else{
                dp[i][j] = INF;
            }
        }
    }
    REP(i, 1, c.size() + 1){
        REP(j, 1, n+1){
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            if(j >= c[i-1]){
                dp[i][j] = min(dp[i][j], dp[i][j-c[i-1]] + 1);
            }
        }
    }
    cout << dp[c.size()][n] << endl;
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<long long> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	if (n & 1) {
		long long low = a[n / 2], high = b[n / 2];
		cout << high - low + 1 << '\n';
	} else {
		int l = n / 2 - 1, r = n / 2;
		long long ans = (b[l] + b[r]) - (a[l] + a[r]);
		cout << ans + 1 << '\n';
	}

	return 0;
}

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

int main() {
  int N, p=0, w=0, g=0, y=0;
  string S;
  cin >> N;
  
  for (int i=1; i<=N; i++){
    cin >> S;
    
    if (S=="P")
      p++;
    if (S=="W")
      w++;
    if (S=="G")
      g++;
    if (S=="Y")
      y++;
  }
  if (p*w*g*y==0)
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b,c,k,count=0;
    cin>>a>>b>>c;
    cin>>k;
    while(b<=a)
    {
        b=b*2;
        count++;
    }
    while(c<=b)
    {
        c=c*2;
        count++;
    }
    if(count<=k)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>


using namespace std;

int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
	{
		cout << 0;
	}
	else
	{
		long long t1, t2;
		if (a > b) {
			if (b >= c) {
				t1 = c;
				t2 = b;
			}
			else if (b < c) {
				t1 = b;
				if (c >= a)
				{
					t2 = a;
				}
				else if (c < a)
				{
					t2 = c;
				}
			}
		}
		else
		{
			if (b < c) {
				t1 = a;
				t2 = b;
			}
			else
			{
				t1 = a;
				t2=c;
			}
		}
		cout << t1*t2;
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

ll N;
ll cnt[100];

int main() {
  cin >> N;
  rep(i, 0, N) {
    ll a;
    cin >> a;
    rep(i, 0, 60) {
      if (a & (1LL << ll(i))) ++cnt[i];
    }
  }

  ll ans = 0;
  ll base = 1;
  rep(i, 0, 60) {
    ll ccnt = cnt[i] * (N - cnt[i]) % MOD;
    ans += base * ccnt % MOD;
    ans %= MOD;

    base *= 2;
    base %= MOD;
  }

  cout << ans;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, d;
    cin >> n >> d;
    ll x[100][100] = {0};
    rep(i, 0, n) rep(j, 0, d) cin >> x[i][j];

    ll ans = 0;
    rep(i, 0, n) rep(j, 0, n) {
        if(i >= j) continue;
        double l = 0;
        rep(k, 0, d) l += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        double sl = sqrt(l);
        if (abs(sl - (ll)sl) < 1e-12) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
  int num,count;
  vector<int> v(4,0) ;
  while(cin >> num){
    count = 0;
    for(int i = 0; i < 10; ++i){
      for(int j = 0; j < 10; ++j){
        for(int k = 0; k < 10; ++k){
          for(int l = 0; l < 10; ++l){
            if(i + j + k + l == num){
              ++count ;
            }
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

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

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

  int n;
  vector<int> val(3);
  cin >> n >> val[0] >> val[1] >> val[2];
  
  vector<pair<int, int>> p(n+1);
  for (int i = 0; i < n; ++i) {
    string t;
    cin >> t;
    p[i].first = t[0] - 'A';
    p[i].second = t[1] - 'A';
  }
   
  string ans;
  auto add = [&](int l, int r) {
    val[l]++;
    val[r]--;
    ans += 'A'+l;
  };

  for (int i = 0; i < n; ++i) {
    int a = p[i].first, b = p[i].second;
    if (!val[a] && !val[b]) {
      cout << "No" << '\n';
      return 0;
    }
  
    if (!val[a]) add(a, b);
    else if (!val[b]) add(b, a);
    else {
      if (a == p[i+1].first || a == p[i+1].second) add(a, b);
      else add(b, a);
    }
  }
  
  cout << "Yes\n";
  for (auto i : ans) cout << i << '\n';
}


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

using ll =  long long;
using pint =  pair<int,int>;

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
//#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  set<int> s;
  rep(i,3){
    int t;cin>>t;s.insert(t);
  }
  if(s.size()==2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main() {
    int N, K;
    cin >> N >> K;
    long int length[N + 1];
    length[0] = 0;
    for (int i = 1; i <= N; ++i) {
        cin >> length[i];
        length[i] += length[i - 1];
    }
    vector<long long int> sum;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            sum.push_back(length[j] - length[i]);
        }
    }
    long long int answer = 0;
    for (int i = 41; i >= 0; --i) {
        int checkOverK = 0;
        answer += (long long int)pow(2, i);
        for (int j = 0; j < sum.size(); ++j) {
            if ((sum[j]&answer) == answer) ++checkOverK;
        }
        if (checkOverK < K) answer -= (long long int)pow(2, i);
    }
    cout << answer << endl;
}

Measured memory_bytes: 6384
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		long a = parseLong(sc.next());
		char[] bs= sc.next().toCharArray();
		long b = 100*(bs[0]-'0')+10*(bs[2]-'0')+(bs[3]-'0');
//		double b = Double.parseDouble(sc.next());
		sc.close();
//		long ans=(long)((double)a*b);
		long ans=(a*b)/100;
		out.println(ans);
	}
}


Measured memory_bytes: 26996
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int x,y,z;
    cin >> x >> y >> z;

    x = x - z;

    cout << x / (y + z) << endl;
    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    rep(i, b) {
        rep(j, a) { cout << "0"; }
        rep(j, w - a) { cout << "1"; }
        cout << "\n";
    }
    rep(i, h - b) {
        rep(j, a) { cout << "1"; }
        rep(j, w - a) { cout << "0"; }
        cout << "\n";
    }
    return 0;
}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
        int N; cin>>N;
        vint T(N);
        int sumT=0;
        REP(i,N){
                cin>>T[i];
                sumT+=T[i];
        }
        int M; cin>>M;
        REP(i,M){
                int P,X; cin>>P>>X;
                cout<<sumT-T[P-1]+X<<endl;
        }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<int>B(N);
  for(int i=0;i<N;i++){
  if(i<=(N-1)/2){
  B.at(i)=A.at(N-1-2*i);
  }else{
  B.at(i)=A.at((N%2)+2*(i-(N+1)/2));
  }
  }for(int i=0;i<N-1;i++)
    cout<<B.at(i)<<" ";
  cout<<B.at(N-1)<<endl;
  return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c,d,e; cin>>a>>b>>c>>d>>e;
	cout<<(15-a-b-c-d-e)<<endl;
	return 0;
}


Measured memory_bytes: 3620
#from collections import deque
#from math import gcd
MOD = 10**9 + 7
N = int(input())
#N, K = map(int, input().split())
#A = list(map(int, input().split()))
ans = 0
#print(ans)
if N == 1:
  print(0)
  exit()
eight = [1]
two = [1]
for k in range(N):
  eight.append(eight[-1]*8%MOD)
  two.append(two[-1]*2%MOD)



fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
  fact.append((fact[-1] * i) % MOD)
  inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
  factinv.append((factinv[-1] * inv[-1]) % MOD)

for k in range(2, N+1):
  ans += eight[N-k]*(two[k]-2)%MOD*fact[N]%MOD*factinv[N-k]%MOD*factinv[k]%MOD
  ans %= MOD

print(ans)

Measured memory_bytes: 218128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[25],b[25],c[25];
int main(){
    int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
        sum+=b[i];
    }
    for(int i=1;i<n;i++){
        cin>>c[i];
    }
    for(int i=1;i<n;i++){
        if(a[i]==a[i+1]-1){
            sum+=c[a[i]];
        }
    }
    cout<<sum<<endl;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	array<int, 3> a;
	cin >> a[0] >> a[1] >> a[2];
	cout << a[0] * a[1] / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[] array = new int[n + 1];

			for(int i = 0; i <= n; i++){ 
				array[i] = sc.nextInt();
			}
			
			LOOP:
			for(int i = 0; i <= n; i++){
				int prev = Integer.MIN_VALUE;
				int diff = Integer.MIN_VALUE;
				
				for(int j = 0; j <= n; j++){
					if(i == j){
						continue;
					}else if(prev == Integer.MIN_VALUE){
						prev = array[j];
						continue;
					}else if(diff == Integer.MIN_VALUE){
						diff = array[j] - prev;
					}else{
						if(diff != array[j] - prev){
							continue LOOP;
						}
					}
					
					prev = array[j];
				}
				
				System.out.println(array[i]);
				break;
			}
		}
		
		sc.close();
	}
}

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

int H, W;
vector<vector<int>> field;

void dfs(int h, int w) {
  field[h][w] = 0;

  for (int dh = -1; dh <= 1; dh++) {
    for (int dw = -1; dw <= 1; dw++) {
      int nh = h + dh, nw = w + dw;

      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (field[nh][nw] == 0) continue;

      dfs(nh, nw);
    }
  }
}

int main() {
  while (cin >> W >> H) {
    if (H == 0 || W == 0) break;
    field.assign(H, vector<int>(W, 0));
    for (int h = 0; h < H; h++) {
      for (int w = 0; w < W; w++) {
        cin >> field[h][w];
      }
    }
    int count = 0;
    for (int h = 0; h < H; h++) {
      for (int w = 0; w < W; w++) {
        if (field[h][w] == 0) continue;
        dfs(h, w);
        count++;
      }
    }

    cout << count << endl;
  }
}


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

using namespace std;
int a[1111];
int main(){
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n;i++){
  cin>>a[i];
  }
  sort(a,a+n);
  int tot = 0;
  for(int i=0;i<k;i++)
    tot += a[i];
  cout<<tot<<endl;
  }

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int i=0,c=0,d=0;
  while(s[i]!='\0'){
    if(s[i]=='A')
      c++;
    else
      d++;
    i++;
  }
  if(c!=0 && d!=0)
    cout<<"Yes";
  else
    cout<<"No";
}


Measured memory_bytes: 3564
#include<stdio.h>
#define max 100005
#define nil -1

struct Node{
  int p,l,r;
};

struct Node T[max];
int n,D[max];

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);
  if(T[u].p==nil){
    printf("root, ");
  }
  else if(T[u].l == nil){
    printf("leaf, ");
  }
  else {
    printf("internal node, ");
  }
  printf("[");

for(i=0,c=T[u].l;c!=nil;i++,c=T[c].r){
  if(i){
    printf(", ");
  }
  printf("%d",c);
}
printf("]\n");
}

int rec(int u,int p){
  D[u] = p;
  if(T[u].r != nil){
    rec(T[u].r,p);
  }
  if(T[u].l != nil){
    rec(T[u].l,p+1);
  }
  return 0;
}


int main(){
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p = T[i].l = T[i].r = nil;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0){
        T[v].l = c;
      }
      else {
        T[l].r =c;
      }
      l=c;
      T[c].p =v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==nil){
      r=i;
    }
  }
  rec(r,0);
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}



Measured memory_bytes: 6380
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Text;

namespace Fish.aizu
{
	public static class AizuOnlineJudge
	{
		public static int[] SplitToInts(string line)
		{
			return line.Split(' ').Select(x => int.Parse(x)).ToArray();
		}
		public static double[] SplitToDoubles(string line)
		{
			return line.Split(' ').Select(x => double.Parse(x)).ToArray();
		}
		public static long[] SplitToLongs(string line)
		{
			return line.Split(' ').Select(x => long.Parse(x)).ToArray();
		}
		public static int Main()
		{
			Compute(Console.In, Console.Out);
			return 0;
		}
		
		public static void Compute(TextReader reader, TextWriter writer)
		{
			var n = int.Parse(reader.ReadLine());
			var taro = 0;
			var hanako = 0;
			
			for (int i = 0; i < n; i++)
			{
				var line = reader.ReadLine();
				var ary = line.Split(' ');
				
				var result = ary[0].CompareTo(ary[1]);
				if (0 == result)
				{
					taro += 1;
					hanako += 1;
				}
				else if (0 < result)
				{
					taro += 3;
				}
				else
				{
					hanako += 3;
				}
			}
			writer.WriteLine(taro + " " + hanako);
		}
	}
}

Measured memory_bytes: 6412
#include<stdio.h>
int main()
{
	int w,a,b;
	scanf("%d %d %d",&w,&a,&b);
	int x;
	if(a>b)
	{
		x=a;
		a=b;
		b=x;
	}
	a+=w;
	if(a>b)
	  printf("0\n");
	else
	  printf("%d\n",b-a);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  const double pi=2*acos(-1.0);
  cout<<setprecision(10)<<
    sqrt(a*a+b*b-2*a*b*cos((m*pi/60)-((60*h+m)*pi/720)));
}


Measured memory_bytes: 4172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
#define fir first
#define sec second
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define rrp(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define gc() getchar()
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc() ; !isdigit(tmp) ; tmp = gc())
    key = (tmp == '-');
  for ( ; isdigit(tmp) ; tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int MOD = (int)(1e9 + 7);
int power(int a,int b) {
  int ret = 1;
  while (b) {
    if (b&1) ret = 1ll * ret * a % MOD;
    a = 1ll * a * a % MOD;
    b >>= 1;
  }
  return ret;
}
inline void Add(int& x,int y) {
  x = x + y >= MOD ? x + y - MOD : x + y;
}
inline void Sub(int& x,int y) {
  x = x - y < 0 ? x - y + MOD : x - y;
}

const int N = 3010;
int dp[N][N], val[N], n, q, inv2, tag, ans;
int main() {
  int x,y;
  read(n), read(q);
  rep (i, 1, n) read(val[i]);
  rep (i, 1, n) rep (j, 1, n) if (val[i] > val[j])
    dp[i][j] = 1;
  inv2 = (MOD + 1) / 2;
  tag = 1;
  while (q --) {
    read(x), read(y);
    rep (i, 1, n) if (i != x && i != y) {
      dp[x][i] = dp[y][i] = 1ll * (dp[x][i] + dp[y][i]) * inv2 % MOD;
      dp[i][x] = dp[i][y] = 1ll * (dp[i][x] + dp[i][y]) * inv2 % MOD;
    }
    dp[x][y] = dp[y][x] = 1ll * (dp[x][y] + dp[y][x]) * inv2 % MOD;
    tag = tag * 2 % MOD;
  }
  rep (i, 1, n) rep (j, 1, n) dp[i][j] = 1ll * dp[i][j] * tag % MOD;
  rep (i, 1, n) rep (j, i+1, n) Add(ans, dp[i][j]);
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, P; cin >> N >> P;
  string S; cin >> S;
  ll result = 0;
  if (P==2||P==5) {  
    rep(i,N) {
      int now = S[i] - '0';
      if (now%P==0) result += i+1;
    }
  }
  else {
    int num[N];
    rep(i,N) {
      int now = S[i] - '0';
      num[i] = i==0 ? now%P : (num[i-1]*10+now)%P;
    }
    int tmp = 1;
    per(i,N) {
      num[i] = (num[i]*tmp)%P;
      tmp = (tmp*10)%P;
    }
    // debug(num,num+N);

    map<ll, ll> count;
    rep(i,N) count[num[i]]++;
    // for (auto x: count) cout << x.first << "->" << x.second << endl;

    for (auto x: count) {
      if (x.first==0) result += x.second*(x.second+1)/2;
      else result += x.second*(x.second-1)/2;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1796
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};


int main() {

    string S,T;

    cin >> S >> T;

    bool f = true;

    REP(i,S.size()){
        if(S[i]!=T[i])f = false;
    }

    cout << ((f)?"Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        //入力
        int N = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        int[] V = new int[N];
        int[] C = new int[N];

        //変数の割り当て
        for (int i = 0; i < N; i++) {
            V[i] = int.Parse(s.Split(' ')[i]);
            C[i] = int.Parse(t.Split(' ')[i]);
        }

        //計算
        //各VとCの差を取った値をDと置く
        int[] D = new int[N];

        //Dの計算
        for (int i = 0; i < N; i++) {
            D[i] = V[i] - C[i];
        }

        //回答となる数値
        int ans = 0;

        //計算
        for (int i = 0; i < N; i++) {
            if (D[i] > 0) {
                ans += D[i];
            }
        }

        //出力
        Console.WriteLine(ans);



    }
}

Measured memory_bytes: 11092