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

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

  if (N[0]==N[1]&&N[1]==N[2]||N[1]==N[2]&&N[2]==N[3]){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

}



Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		if (A+B<C+D) {
			System.out.println("Right");
		} else if (A+B==C+D) {
			System.out.println("Balanced");
		} else {
			System.out.println("Left");
		}
	}
}

Measured memory_bytes: 22612
//#include <bits\stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define ll long long
#define y1 bad_fdsaf
#ifdef Stetsyk
#define files freopen("input.txt", "r", stdin);
#else
#define files
#endif
const int mod = 1e9 + 7;
const int N = 1e2 + 5;
int h, w;
int a[26];
string s;
int main(){
    files;
    cin >> h >> w;
    for(int i = 0; i < h; ++i){
        cin >> s;
        for(int j = 0; j < w; ++j){
            a[s[j] - 'a']++;
        }
    }
    for(int i = 0; i < 26; ++i){
        a[i] %= 4;
    }
    int pos1 = 0;
    int pos2 = 0;
    if(h % 2 == 1 && w % 2 == 1){
        pos1 = h + w - 2;
        pos2 = 1;
    }
    else if(h % 2 == 1){
        pos1 += w;
    }
    else if(w % 2 == 1){
        pos1 += h;
    }
    for(int i = 0; i < 26; ++i){
        if(a[i] % 2 && pos2){
            a[i] --;
            pos2 = 0;
        }
        if(a[i] && a[i] % 2 == 0 && pos1){
            pos1 -= 2;
            a[i] = 0;
        }
    }
    int flag = 0;
    for(int i = 0; i< 26; ++i){
        flag |= a[i];
    }
    if(flag){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}


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

const int nmax=8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]){ // vは現在の頂点
 bool all_visited=true;
 for(int i=0; i<N; i++){
  if(visited[i]==false){ // 全ての頂点を通過した場合はvisited[i]=trueになるため、
    all_visited=false;}
 }

 if(all_visited){return 1;} // aii_visited=trueで1通りのルートがresに追加される

 int ret=0; // 繋がっていないならres=0がresに追加される
 for(int i=0; i<N; i++){
  if(graph[v][i]==false){continue;} // graph[v][i]がどこかに繋がっているなら以下の処理実行
  if(visited[i]){continue;} // i(Bの値)がまだ未到達(false)の場合は以下の処理実行
  visited[i]=true; // i(Bの値)がまだ未到達の場合は到達したことにしてtrueにする
  ret+=dfs(i, N, visited);  // i(Bの値)の処理を再帰dfsで行う
  visited[i]=false; // 一度そのルートで通った辺はfalseにしてリセットする
 }

 return ret; // この数値が返される
}

int main(){
int N, M;
 cin>>N>>M;
 for(int i=0; i<M; i++){
  int A, B;
  cin>>A>>B;
  graph[A-1][B-1]=graph[B-1][A-1]=true; // 頂点A, Bは互いに繋がっていることを表す
 }

 bool visited[nmax];
 for(int i=0; i<N; i++){
  visited[i]=false; // 処理前なのでまだ全ての辺は未通過(false)にする
 }

 visited[0]=true; // Bの初期値を通過済み(true)にする
 cout<<dfs(0, N, visited);
 return 0;
}

Measured memory_bytes: 256
program prob2
    implicit none
    integer(8) :: n
    integer(8), allocatable :: a(:)
    integer(8) :: i, ans
    
    read(*,*) n
    allocate(a(n))
    read(*,*) a

    ans = gcd(a(1), a(2))
    do i = 3, n
        ans = gcd(ans, a(i))
    end do

    write(*,*) ans

    deallocate(a)

    stop
contains


integer(8) function gcd(a, b)
    implicit none
    integer(8) :: a, b
    integer(8) :: l, m, n

    m = a
    n = b

    do
    l = mod(m, n)
    if (l == 0) exit
    m = n
    n = l
    end do

    gcd = n

    return
end function gcd

end program prob2

Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, l, a[100005];

int main()
{
    scanf("%lld%lld",&n,&l);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    ll mx = 0, idx;
    for(int i=1;i<n;i++) {
        if(mx < a[i] + a[i+1]) {
            mx = a[i] + a[i+1];
            idx = i;
        }
    }
    if(mx<l) {puts("Impossible"); return 0;}
    puts("Possible");
    for(int i=1;i<idx;i++) printf("%d\n",i);
    for(int i=n-1;i>=idx;i--) printf("%d\n",i);
}


Measured memory_bytes: 1536
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N, K;
	cin >> N >> K;
	if (N == 1 || K == 1) {
		cout << 1;
		return 0;
	}
	cout << DIVCEIL(N, 2) * DIVCEIL(K, 2) + (N / 2) * (K / 2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

const LL MAXN = 1e5+10;
vector<PLL> edges[MAXN];
LL colour[MAXN];

void dfs(LL src, LL par, LL clr) {
	colour[src] = clr;
	rep(it, edges[src].begin(), edges[src].end()) {
		if(it->first != par)	dfs(it->first, src, clr^(it->second%2));
	}
}

int main() {
	sll(n);
	rep(i, 0, n-1) {
		sll(u); sll(v); sll(w);
		edges[u].push_back(MP(v, w));
		edges[v].push_back(MP(u, w));
	}
	dfs(1, 0, 0);
	rep(i, 1, n+1)	pll(colour[i]), nl;
}


Measured memory_bytes: 11008
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200010

vector<int>b[8];
vector<int>ax;
vector<int>ay;


int main() {
	char a[N];
	f(i, N)a[i] = 0;
	int c[10];
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	b[0].push_back(1);
	f(i, 7) {
		f(j, b[i].size()) {
			b[i + 1].push_back(b[i][j]);
		}
		b[i + 1].push_back(i + 2);
		for(int j=b[i].size()-1;j>=0;j--){
			b[i + 1].push_back(-b[i][j]);
		}
		b[i + 1].push_back(-(i + 2));
	}
	scanf("%d", &n);
	scanf("%s", a);
	k = strlen(a);
	if (a[0] == '0') {
		printf("Impossible\n");
		return 0;
	}
	x = 1;
	ax.push_back(0);
	ay.push_back(0);
	f(i, k) {
		f(j, i) {
			if ((i&j) == j) {
				if ((a[i] == '1') && (a[j] == '0')) {
					printf("Impossible\n");
					return 0;
				}
			}
		}
	}
	f(i, n) {
		f(j, x) {
			if (a[j] == '1') {
				if (a[x + j] == '0') {
					y = 1;
					z = x + j;
					f(ii, n) {
						if (z % 2 == 1) {
							c[y] = ii + 1;
							y++;
						}
						z /= 2;
					}
					y -= 2;
					f(ii, b[y].size()) {
						if (b[y][ii] > 0) {
							for (int j = 1; j <= c[b[y][ii]] - 1; j++) {
								ax.push_back(j);
								ay.push_back(0);
							}
							ax.push_back(c[b[y][ii]]);
							ay.push_back(0);
							ax.push_back(c[b[y][ii]]);
							ay.push_back(1);
							ax.push_back(c[b[y][ii]]-1);
							ay.push_back(1);
							for (int j = c[b[y][ii]] - 1; j >= 0; j--) {
								ax.push_back(j);
								ay.push_back(0);
							}
						}
						else {
							for (int j = 1; j <= c[-b[y][ii]] - 1; j++) {
								ax.push_back(j);
								ay.push_back(0);
							}
							ax.push_back(c[-b[y][ii]] - 1);
							ay.push_back(1);
							ax.push_back(c[-b[y][ii]]);
							ay.push_back(1);
							ax.push_back(c[-b[y][ii]]);
							ay.push_back(0);
							for (int j = c[-b[y][ii]] - 1; j >= 0; j--) {
								ax.push_back(j);
								ay.push_back(0);
							}
						}
					}
				}
			}
			else {
				if (a[x + j] == '1') {
					printf("Impossible\n");
					return 0;
				}
			}
		}

		x *= 2;
	}
	printf("Possible\n");
	printf("%d\n", ax.size() - 1);
	f(i, ax.size()) {
		printf("%d %d\n", ax[i], ay[i]);
	}


	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> C(N), S(N), F(N);
  for(int i=0; i<N; i++){
    cin >> C.at(i) >> S.at(i) >> F.at(i);
  }
  for(int i=0; i<N-1; i++){
    int Ans=0;
    for(int j=i; j<N-1; j++){
      int mod=Ans%F.at(j);
      if(mod==0){
        mod=F.at(j);
      }
      Ans=max(S.at(j), Ans+F.at(j)-mod);
      Ans+=C.at(j);
    }
    cout << Ans << endl;
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    string S;
    cin >> S;
    for(int i = 0;i < S.size();i++) {
        cout << 'x';
    }
    cout << endl;
}

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

int main(){
    int64_t X,ans = 0,count = 100;
    cin >> X;
    while (count < X){
        ans++;
        count *= 1.01;
    }
    cout << ans << endl;
}


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

int main() {
    long long x;
    cin >> x;
    long long n = 100;
    long long count = 0;
    while (n < x) {
        n *= 1.01;
        count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3

def main():
    N,K = map(int, input().split())
    hights = [int(s) for s in input().split()]
    
    count = 0
    for hight in hights:
        if hight >= K:
            count+= 1
    
    print(count)

if __name__ == "__main__":
    main()


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

int m, n;

int rec(vector<int> rest, map<vector<int>, int>& memo) {
    if(memo.count(rest) == 1) {
        return memo[rest];
    }
    int& res = memo[rest];
    if(rest.size() <= 1) {
        return res = 0;
    }
    res = m;
    for(int i=0; i<m; ++i) {
        vector<int> rest1, rest2;
        for(auto val : rest) {
            if((val >> i) & 1) {
                rest1.push_back(val);
            } else {
                rest2.push_back(val);
            }
        }
        res = min(res, max(rec(rest1, memo), rec(rest2, memo)) + 1);
    }
    return res;
}

int main() {
    while(cin >> m >> n, m) {
        vector<int> v(n);
        for(int i=0; i<n; ++i) {
            string s;
            cin >> s;
            int t = 0;
            for(int i=0; i<m; ++i) {
                t <<= 1;
                t |= s[i] == '1';
            }
            v[i] = t;
        }
        map<vector<int>, int> memo;
        cout << rec(v, memo) << endl;
    }
}


Measured memory_bytes: 5308
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=1e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=1e9;
const double ep=1e-7;
using namespace std;
ll n,k;
ll ai[maxn],bi[maxn];
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0){ x=1, y=0; return a;}
    ll gcd=exgcd(b,a%b,x,y);
    ll tp=x;
    x=y, y=tp-a/b*y;
    return gcd;
}
ll mult(ll a,ll b,ll mod){
    ll res=0;
    while(b>0){
        if(b&1) res=(res+a)%mod;
        a=(a+a)%mod;
        b>>=1;
    }
    return res;
}
ll excrt(){
    ll x,y;
    ll ans=bi[1],M=ai[1];
    for(ll i=2;i<=n;++i){
        ll a=M,b=ai[i],c=(bi[i]-ans%ai[i]+ai[i])%ai[i];
        ll gcd=exgcd(a,b,x,y);
        x=mult(x,c/gcd,b/gcd);
        ans+=x*M;
        M*=b/gcd;
        ans=(ans%M+M)%M;
    }
    return (ans%M+M)%M;
}
int main(){
    cin>>n>>k;
    ll LCA=1;
    for(ll i=1;i<=n;++i)
    {
    	cin>>ai[i];
    	bi[i]=ai[i]/2;
    	LCA=LCA/__gcd(LCA,ai[i])*ai[i];
	}
	ll x=excrt(),ju=0;
	if(x<0||x>k)
	{
		puts("0");return 0;
	}
	for(ll i=1;i<=n&&!ju;i++)
	{
		if((x-bi[i])%ai[i])ju=1;
	}
	if(ju)
	{
		puts("0");return 0;
	}
	ll ans=(k-x)/LCA+1;
	printf("%lld\n",ans);
}


Measured memory_bytes: 1792
#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;

ll n;
ll l[201];
int main() {
    cin>>n;
    REP(i, 0, 2*n) cin>>l[i];

    sort(l, l+2*n);

    ll ans=0;
    REP(i, 0, n){
        ans+=l[2*i];
    }
    cout<<ans<<endl;
    return 0;
}

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

const int mod = 1e9 + 7;

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

void sub_self (int & a, int b) {
    a -= b;
    if (a < 0) a += mod;
}

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

int power (int a, int k) {
	int ans = 1;
	while (k >= 1) {
		if (k & 1) ans = mul (ans, a);
		a = mul (a, a);
		k >>= 1;
	}
	return ans;
}

int inverse (int a) {
	return power (a, mod - 2);
}

int main() {
	ios::sync_with_stdio (false);
	int n, k;
	cin >> n >> k;
	vector < int > a (n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort (a.begin(), a.end());
    vector < int > fact (n + 1), invfact (n + 1);
    fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = mul (fact[i - 1], i);
    }
    for (int i = 0; i <= n; i++) {
        invfact[i] = inverse (fact[i]);
    }
    auto choose = [&] (int N, int K) {
        if (N < K) return 0;
        return mul (fact[N], mul (invfact[K], invfact[N - K]));
    };
    int answer = 0;
    int nck = choose (n, k);
    for (int i = 0; i + 1 < n; i++) {
        int diff = (a[i + 1] - a[i]) % mod;
        // diff * (nck - ((i + 1)ck + (n - 1 - i)ck)) 
        int res = nck;
        sub_self (res, choose (i + 1, k));
        sub_self (res, choose (n - 1 - i, k));
        add_self (answer, mul (res, diff));
    }
    printf ("%d\n", answer);
	return 0;
}



Measured memory_bytes: 1408
def main():

    N, M = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))

    mod = pow(10, 9) + 7
    dp = [[0 for _ in range(M+1)] for _ in range(N+1)]
    dp[0][0] = 0
    # for i in range(N): dp[i][0] = 0
    # for j in range(M): dp[0][j] = 0

    for i in range(N):
        for j in range(M):
            dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j] - dp[i][j]
            if S[i] == T[j]:
                dp[i+1][j+1] += dp[i][j] + 1
            dp[i+1][j+1] %= mod
    # print(dp)
    return dp[N][M] + 1

if __name__ == '__main__':
    print(main())


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

int n, ind[N], ld[N], cnt, num[N];
vector<int> G[N];

void dfs(int u, int p, int now, int &dep, int &pnt) {
    if (now > dep) dep = now, pnt = u;
    for (int v : G[u])
        if (v != p) dfs(v, u, now + 1, dep, pnt);
}

inline void getans(int *p) {
    int now = 1;
    for (int i = 1; i <= cnt; ++i, ++now) {
        int nxt = now + num[i];
        p[nxt] = now;
        for (int j = now; j < nxt; ++j)
            p[j] = ++now;
    }
}

int stk[N], top;

void dfs2(int u, int p, int d) {
    stk[++top] = u;
    if (u == d) {
        for (int i = top; i; --i)
            ind[stk[i]] = 1;
        memcpy(ld, stk, sizeof(stk));
        cnt = top;
    }
    for (int v : G[u])
        if (v != p) dfs2(v, u, d);
    stk[top--] = 0;
}

inline bool small(int *pa, int *pb) {
    for (int i = 1; i <= n; ++i)
        if (pa[i] != pb[i]) return pa[i] < pb[i];
    return false;
}

inline void write(int *p) {
    for (int i = 1; i <= n; ++i)
        printf("%d%c", p[i], " \n"[i == n]);
}

int pa[N], pb[N];

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;

    for (int i = 1, u, v; i < n; ++i)
        scanf("%d%d", &u, &v),
        G[u].push_back(v),
        G[v].push_back(u);

    int p1, p2, d;
    d = 0, dfs(1, 0, 0, d, p1);
    d = 0, dfs(p1, 0, 0, d, p2);

    dfs2(p1, 0, p2);

    for (int i = 1, u; i <= cnt; ++i) {
        u = ld[i];
        for (int v : G[u])
            if (!ind[v]) ++num[i], ind[v] = -1;
    }

    for (int i = 1; i <= n; ++i)
        if (!ind[i]) puts("-1"), exit(0);

    getans(pa);
    reverse(num + 1, num + cnt + 1);
    getans(pb);

    write(small(pa, pb) ? pa : pb);

    return 0;
}


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n, d, x, j;
  cin >> n >> d >> x;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    j = 0;
    while (j * a[i] + 1 <= d) {
      ans++;
      j++;
    }
  }
  cout << ans + x << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));

for($j=0; $j<strlen($s); $j++) {
    $ss = [];
    for ($i = 0; $i < strlen($s); $i++) {
        $ss[] = $s[$i];
    }
    $ss[-1] = array_pop($ss);
    ksort($ss);
    $ss = array_values($ss);

    $s = '';
    for ($i = 0; $i < count($ss); $i++) {
        $s .= $ss[$i];
    }

    if ($s == $t) {
        echo 'Yes';
        exit;
    }
}

echo 'No';


Measured memory_bytes: 4604
N, M, X = map(int, input().split())
cost = []
A = []
for _ in range(N):
    ca = list(map(int, input().split()))
    cost.append(ca[0])
    A.append(ca[1:])

ans = 10**9
for bit in range(2**N):
    alg = [0]*M
    c = 0
    for i in range(N):
        if bit >> i & 1 == 1:
            for j in range(M):
                alg[j] += A[i][j]
            c += cost[i]
    if min(alg) >= X:
        ans = min(ans, c)

if ans == 10**9:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9160
#include <stdio.h>

int main(){
  int N,C;
  scanf("%d%d",&N,&C);
  int i,j,k,t,s;
  int D[C+1][C+1];
  int c[N+1][N+1];
  for(i=1;i<C+1;i++){
    for(j=1;j<C+1;j++){
      scanf("%d",&D[i][j]);
    }
  }
  for(i=1;i<N+1;i++){
    for(j=1;j<N+1;j++){
      scanf("%d",&c[i][j]);
    }
  }

  int an[3]={0,0,0};
  int amari[N*N][3];

  for(i=1;i<N+1;i++){
    for(j=1;j<N+1;j++){
      t=(i+j)%3;
      s=an[t];
      amari[s][t]=c[i][j];
      an[t]=an[t]+1;
    }
  }
  
  int amcost[C+1][3];
  for(i=0;i<3;i++){
    for(j=0;j<C+1;j++){
      amcost[j][i]=0;
    }
  }
  
  for(i=0;i<3;i++){
    for(j=1;j<=C;j++){
      for(k=0;k<an[i];k++){
	amcost[j][i]=amcost[j][i]+D[amari[k][i]][j];
      }
    }
  }
  
  long int cost=amcost[1][0]+amcost[2][1]+amcost[3][2];
  for(i=1;i<=C;i++){
    for(j=1;j<=C;j++){
      for(k=1;k<=C;k++){
	if(i!=j&&j!=k&&k!=i){
	  if(cost>amcost[i][0]+amcost[j][1]+amcost[k][2]){
	    cost=amcost[i][0]+amcost[j][1]+amcost[k][2];
	  }
	}
      }
    }
  }
  //printf("%d %d\n",amari[0][0],amari[1][0]);
  printf("%ld",cost);
  return 0;
}


Measured memory_bytes: 3968
n = gets.to_i

def SQRT(n)
    s=1; 
    while (s*s>n||n>=(s+1)*(s+1)) do 
        s=(n/s+s)/2
    end 
    return s
end
ans = 11
for a in 1..SQRT(n) do
    if n%a==0 then
        b = n/a
        len = b.to_s.length
        ans = len
    end
end
puts ans

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

int main(){
    int n;
    cin >> n;
    int t,a,h;
    cin >> t >> a;
    double mini = 10000;
    int ans;
    int i;
    for (i = 1;i <= n;i++){
        cin >> h;
        double T = t - h*0.006;
        if (mini > abs(a-T)){
            ans = i;
            mini = abs(a-T);
        }
    }

    cout << ans << endl;
}

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

const int mod=1e9+7;

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

long long dp[401][401];

int main()
{
int n;
cin>>n;
vector<int>a(n);
for(auto &x:a)cin>>x;
auto sum=[&](int L,int R){long long s=0;
for(int i=L;i<=R;i++){s+=a[i];}return s;};
for(int L=n-1;L>=0;L--)
{
for(int R=L;R<n;R++)
{
if(L==R)dp[L][R]=0;
else 
{long long z=sum(L,R);
dp[L][R]=1e18;
for(int k=L;k<R;k++){
dp[L][R]=min(dp[L][k]+dp[k+1][R]+z,dp[L][R]);}

}
}
}
cout<<dp[0][n-1];
}

Measured memory_bytes: 1536
iN ,iX  = [int(x) for x in input().split()]
aX = [int(x) for x in input().split()]

aCum = [0]*iN
aCum[0] = aX[0]
for i in range(1,iN):
    aCum[i]=aCum[i-1]+aX[i]

def fCeil(iT,iR):
    return -1 * iT // iR * -1
#マネして記法を圧縮してみたがどうだろう
def fCalcCost(iN,iX,aCum,iK):
    return (iN + iK ) * iX + 5 * aCum[-1] +sum(2*aCum[-i*iK -1] for i in range(2,fCeil(iN,iK)))

iTotalCost = fCalcCost(iN,iX,aCum,1)
iULim = fCeil(iN,2) + 1
for iK in range(2,fCeil(iN,2)+1):
    iThisCost = fCalcCost(iN,iX,aCum,iK)
    if iThisCost > iTotalCost:
        break
    else:
        iTotalCost = iThisCost
print(iTotalCost)


Measured memory_bytes: 25840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        br.close();
        int n = Integer.parseInt(st.nextToken());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        System.out.println(Math.min(n*a, b));
        System.out.println("\n");
    }
}


Measured memory_bytes: 21332
def qpow(b,t,m):
  f=format(t,'b')[::-1]
  arr=[b]
  tmp=b
  for i in range(1,len(f)):
    tmp=(tmp**2)%m
    arr.append(tmp)
  ans=1
  for i in range(len(f)):
    if f[i]=='1':
      ans=(ans*arr[i])%m
  return ans    

l=input()
dp=[[0,0] for _ in range(len(l))]
if l[-1]=='1':
  dp[-1][0]=1
  dp[-1][1]=2
else:
  dp[-1][0]=1
  dp[-1][1]=0
for i in range(len(l)-2,-1,-1):
  if l[i]=='0':
    dp[i][0]=dp[i+1][0]+dp[i+1][1]
    dp[i][1]=0
  else:
    dp[i][0]=qpow(3,len(l)-i-1,10**9+7)
    dp[i][1]=(2*(dp[i+1][0]+dp[i+1][1]))%(10**9+7)
print((dp[0][0]+dp[0][1])%(10**9+7))

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

int main(void) {
  vector<int> as(9);
  int n;
  for (int &a : as) {
    std::cin >> a;
  }
  std::cin >> n;

  vector<int> bs(n);
  for (int &b : bs) std::cin >> b;

  for (const int &b : bs) {
    for (int &a : as) {
      if (a == b) {
        a = 0;
        break;
      }
    }
  }

  string result = "No";
  if (as[0] == as[1] && as[0] == as[2]) result = "Yes";
  if (as[3] == as[4] && as[3] == as[5]) result = "Yes";
  if (as[6] == as[7] && as[6] == as[8]) result = "Yes";
  if (as[0] == as[3] && as[0] == as[6]) result = "Yes";
  if (as[1] == as[4] && as[1] == as[7]) result = "Yes";
  if (as[2] == as[5] && as[2] == as[8]) result = "Yes";
  if (as[0] == as[4] && as[0] == as[8]) result = "Yes";
  if (as[2] == as[4] && as[2] == as[6]) result = "Yes";

  cout << result << endl;
  return 0;
}

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

using namespace std;

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

int main() {
    int A,B,C,X;
    cin >> A >> B >> C >> X;

    int ans = 0;
    rep(i, A+1){
        rep(j, B+1){
            rep(k, C+1){
                if(500*i+100*j+50*k == X){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
N,L = map(int,input().split())
eat = 301
eatNum = 0
for i in range (0,N):
    if abs(i + L) < eat:
        eat = abs(i + L)
        eatNum = i
ans = 0
for i in range(0,N):
    if i != eatNum:
       ans += i + L
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <cmath>    
#include <complex>
using namespace std;

int tmp[101]={0};

int ab(int ans){
	int u=ans,d=ans;
	if(tmp[ans]==0){
		return ans;
	}else{
		while(1){
			if(tmp[u]==0){
				break;
			}
			u++;
		}
		while(1){
			if(tmp[d]==0){
				break;
			}
			d--;
		}
		if(abs(ans-d)<=abs(ans-u)){
			return d;
		}else{
			return u;
		}
	}
}

int main() {
	int x,n;
	cin>>x>>n;
	int a[n],ans=x;
	for(int i=0;i<n;i++){
		cin>>a[i];
		tmp[a[i]]=1;
		
	}
	ans=ab(ans);
	cout<<ans<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
}
return u;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

while(x!=NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
}
z->parent = y;
if(y == NIL) root = z;
else if(z->key < y->key) y->left = z;
else y->right = z;
}

void inorder(Node u){
if(u == NIL) return;
inorder(u->left);
printf(" %d",u->key);
inorder(u->right);
}
void preorder(Node u){
if(u == NIL) return;
printf(" %d",u->key);
preorder(u->left);
preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

int main(){
  string s ; cin >> s;
  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 705;

vector<int> G[MAX_N];
bool ex[MAX_N][MAX_N];
int used[MAX_N];
bool dp1[MAX_N], dp2[MAX_N];

bool dfs(int u, int c, int& a, int& b)
{
    used[u] = c;
    if(c == 1){
        a++;
    }else{
        b++;
    }
    each(v, G[u]){
        if(!used[v]){
            if(!dfs(v, 3-c, a, b)){
                return false;
            }
        }else{
            if(used[v] == c){
                return false;
            }
        }
    }
    return true;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        ex[a-1][b-1] = ex[b-1][a-1] = true;
    }
    rep(i,n){
        srep(j,i+1,n){
            if(!ex[i][j]) G[i].pb(j), G[j].pb(i);
        }
    }
    vp vec;
    rep(i,n){
        if(!used[i]){
            int a = 0, b = 0;
            if(!dfs(i, 1, a, b)){
                cout << "-1\n";
                return 0;
            }else{
                vec.pb(P(a, b));
            }
        }
    }
    dp1[0] = true;
    rep(i,len(vec)){
        rep(j,n+1) dp2[j] = false;
        rep(j,n+1){
            if(dp1[j]) dp2[j+vec[i].fi] = dp2[j+vec[i].se] = true;
        }
        swap(dp1, dp2);
    }
    int mn = INF;
    rep(i,n+1){
        if(dp1[i]){
            cmn(mn, i*(i-1)/2 + (n-i)*(n-i-1)/2);
        }
    }
    cout << mn << "\n";
    return 0;
}

Measured memory_bytes: 3200
import std.stdio, std.string, std.conv, std.algorithm;

void main(string[] args) {
  readln();
  auto a = readln().chomp.split.map!(to!int);
  int[] t;
  void f(int i){if(t.length<=i){t.length=i+1;} t[i]++;}
  foreach(int i; a){
    if(i>0){ f(i-1); }
    f(i);
    f(i+1);
  }
  t.reduce!max.writeln;
}

Measured memory_bytes: 4272
from copy import deepcopy
from copy import copy

class Dice:
    def __init__(self, labels):
        self.surface = {x: labels[x-1] for x in range(1, 6+1)}
    def move_towards(self, direction):
        if direction == 'N':
            self._move(1, 2, 6, 5)
        elif direction == 'S':
            self._move(1, 5, 6, 2)
        elif direction == 'E':
            self._move(1, 4, 6, 3)
        elif direction == 'W':
            self._move(1, 3, 6, 4)
    def get_upper(self):
        return self.surface[1]
    def _move(self, i, j, k, l):
        temp_label = self.surface[i]
        self.surface[i] = self.surface[j]
        self.surface[j] = self.surface[k]
        self.surface[k] = self.surface[l]
        self.surface[l] = temp_label
    
    def find_pattern(self, pattern):
        dice = deepcopy(self)
        if dice.surface[1] == pattern[0] and dice.surface[2] == pattern[1]:
            return dice.surface[3]
        
        pattern_tested = {'original': dice.surface}
        moves = ['N', 'S', 'E', 'W']
        
        def find(dice, moves):
            next_moves = []
            for move in moves:
                if len(move) == 1:
                    start = 'original'
                else:
                    start = move[:-1]
                    
                dice.surface =pattern_tested[start]
                dice.move_towards(move[-1])
                
                if dice.surface[1] == pattern[0] and dice.surface[2] == pattern[1]:
                    right_label = dice.surface[3]
                    return right_label
                else:
                    move_tested = move
                    pattern_tested[move_tested] = copy(dice.surface)
                    next_moves.extend([move+'N', move+'S', move+'E', move+'W'])
            return find(dice, next_moves)
                
        return find(dice, moves)
    
labels = list(map(int, input().split()))
num_questions = int(input())
questions = [list(map(int, input().split())) for _ in range(num_questions)]
dice = Dice(labels)
results = []

for question in questions:
    right_label = dice.find_pattern(question)
    results.append(right_label)

for result in results:
    print(result)


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

int n;
int s[100010];

bool binarySearch(int key){
	int left = 0;
	int right = n;
	while(left < right){
		int mid = (left + right) / 2;
		if(s[mid] == key){
			return true;
		}
		else if(key < s[mid]){
			right = mid;
		}
		else{
			left = mid + 1;
		}
	}
	return false;
}

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

	cin >> n;

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

	int q;
	cin >> q;

	int ans = 0;
	for(int i = 0; i < q; ++i){
		int t;
		cin >> t;
		if(binarySearch(t)){
			++ans;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1580
#include <iostream>
#include <vector>
#include <iostream>
#include <cstdio>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
 
#define ll long long
#define pb push_back
#define vi vector<int>
#define sz(a) (int((a).size()))
#define mp make_pair
#define f first
#define s second
#define pii pair<int, int>
 
using namespace std;
 
const int mod = 998244353;
const int inf = (int)2e9;
const ll INF = (ll)2e18;
const int N = 100100;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	cout << n * (n + 1) / 2;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        long S = sc.nextLong();
                        long[] A = new long[N];
                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextLong();
                        }
                        int i = 0, j = 0, ans = 100000000;
                        long sum = 0;

                        while (i < N) {
                                while (j < N && sum < S) {
                                        sum += A[j];
                                        j++;
                                }
                                if (sum >= S) {
                                        ans = Math.min(j - i, ans);
                                }
                                sum -= A[i];i++;
                        }
                        if (ans == 100000000) {
                                ans = 0;
                        }
                        System.out.println(ans);
                }
        }
}

Measured memory_bytes: 71116
n,y = map(int,input().split())
a,b,c=-1,-1,-1

for i in range(n+1):
  for j in range(n-i+1):
    # print(10000*i+5000*j+1000*(n-i-j))
    if 10000*i+5000*j+1000*(n-i-j) == y:
      a,b,c=i,j,n-i-j
      break
      
print(a,b,c)

Measured memory_bytes: 3060
import java.util.Scanner;
import java.io.*;
public class Main

{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a==1&&b==2||a==2&&b==1)
        System.out.println(3);
        else if(a==2&&b==3||a==3&&b==2)
        System.out.println(1);
        else if(a==1&&b==3||a==3&&b==1)
        System.out.println(2);
    }
}

Measured memory_bytes: 35728
int main(){
  int k,a=0,b[1000]={};
  scanf("%d",&k);
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int l=1;l<=k;l++){
        if(i<j&&i<l){
          for(int c=i;c>0;c--){
            if(i%c==0&&j%c==0&&l%c==0){
              a+=c;
              break;
            }
          }
        }else if(j<i&&j<l){
          for(int c=j;c>0;c--){
            if(i%c==0&&j%c==0&&l%c==0){
              a+=c;
              break;
            }
          }
        }else{
          for(int c=l;c>0;c--){
            if(i%c==0&&j%c==0&&l%c==0){
              a+=c;
              break;
            }
          }
        }
      }
    }
  }
  printf("%d",a);
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }

int main() {
    init();

    int n, m; cin >> n >> m;
    VI x(n); cin >> x;

    int ans = 0;
    map<int, int> a, b, c;
    each(i, x)++a[i];
    each(i, a) {
        ans += i.second / 2;
        b[i.first % m] += i.second / 2;
        c[i.first % m] += i.second % 2;
    }
    each(i, c) {
        if (i.first == 0 || i.first * 2 == m) {
            ans += i.second / 2;
            i.second %= 2;
        }
        else if (i.second <= c[m - i.first]) {
            ans += i.second;
            c[m - i.first] -= i.second;
            i.second = 0;
        }
    }
    each(i, c) {
        if (i.first == 0)continue;
        ans += min(b[m - i.first], i.second / 2);
    }
    print(ans);
}

Measured memory_bytes: 14720
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int> pii32;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 1e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

vector <pii> v1[2];
int par[2][maxn];
int n, m;

int root (int id, int v) {
	return ((par[id][v] < 0) ? v : par[id][v] = root(id, par[id][v]));
}

bool merge (int id, int v, int u) {
	v = root(id, v);
	u = root(id, u);
	if (v == u)
		return 0;
	par[id][v] = u;
	return 1;
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		--x; --y;
		v1[z & 1].PB(MP(x, y));
	}
	memset(par, -1, sizeof par);
	for (auto x : v1[0])
		merge(0, x.F, x.S);
	int cnt = 0;
	for (int i = 0; i < n; i++)
		if (i == root(0, i))
			cnt++;
	for (auto x : v1[1])
		if (merge(1, root(0, x.F), root(0, x.S)))
			cnt--;
	cout << cnt << "\n";
}


Measured memory_bytes: 2248
#include<iostream>
using namespace std ;
#define ll long long int 
ll arr[3001][3001] , visi[3001][3001] , grr[10000] ;


ll find(ll i , ll j , ll val )
{
    if(visi[i][j]==1)
    {
        return  arr[i][j] ;
    }
    
    if( i==j)
    {
        if(val == 0)
        {
            arr[i][j]= grr[i] ;
        }else
        {
            arr[i][j] = -grr[i] ;
        }
        
        visi[i][j] =1 ;
        return  arr[i][j] ;
    }
    
    
    if(val==0 )
    {
        arr[i][j] = max(grr[i] + find(i+1 , j,1) , grr[j] + find(i, j-1 , 1)) ;
    }else
    {
        arr[i][j] = min(find(i,j-1 ,0) - grr[j] , find(i+1 , j , 0) - grr[i]) ;
    }
    
    
    visi[i][j] =1 ;
    return arr[i][j] ;
    
}
 
int main()
{
    ll n ;
    cin >> n ;
    for(ll i= 0 ; i < n ;i++)
    {
        cin >> grr[i] ;
    }
    
    
    cout <<find(0 , n-1 , 0 ) ;
    return 0 ;
    
    
}

Measured memory_bytes: 139904
#include<stdio.h>
int main(){
	int a,b,c,d,e,g=0,h;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a<0){
		g=-1*a*c;
		a=0;
	}
	if(a==0)g=g+d;
	g=g+(b-a)*e;
	printf("%d\n",g);
	return 0;
}


Measured memory_bytes: 2108
#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()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const 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);
	int a, b, c;
	cin>>a>>b>>c;
	int ans=max({a, b, c})-min({a, b, c});
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
V = [0] + list(map(int, input().split())) + [0]

maxv = 0
for l in range(min(K, N) + 1):
    for r in range(min(K, N) - l + 1):
        gets = V[:l + 1] + V[-1 - r:]
        d = K - l - r
        #print("il={},ir={},d={},gets={}".format(il,ir,d,gets))
        for i in range(d):
            if len(gets) <= 0:
                break
            v = min(gets)
            if v >= 0:
                break
            #print("remove={}".format(v))
            gets.remove(v)
        maxv = max(maxv, sum(gets))
        #print("sum(gets)={}".format(sum(gets)))

print(maxv)


Measured memory_bytes: 3064
import sys
k = int(input())
a = ['1','2','3','4','5','6','7','8','9']

while 1:
    x = len(a)
    if k <= x:
        print(a[k-1])
        sys.exit( )
    b=[]
    for z in a:
        if z[-1]!='0':
            b.append(z+str(int(z[-1])-1))
        b.append(z+z[-1])
        if z[-1]!='9':
            b.append(z+str(int(z[-1])+1))
    k-=x
    a=b[:]


Measured memory_bytes: 16936
#include <bits/stdc++.h>
#define NMAX 3004
using namespace std;
int n;
double d[NMAX][NMAX],p[NMAX],sol;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>p[i];
    double prod=1;
    for(int i=0;i<=n;i++)
    {
        d[i][0]=prod;
        prod*=(1-p[i+1]);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            d[i][j]=d[i-1][j]*(1-p[i])+d[i-1][j-1]*p[i];
        }
    }
    for(int j=0;j<=n;j++)
    {
        if(j>n-j)
            sol+=d[n][j];
    }
    cout<<fixed<<setprecision(10)<<sol;
    return 0;
}

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


int main(void){
  const int MOD = (1e9) + 7;

  // ??\??????????????????
  int N, W;
  cin >> N >> W;  
  vector<int> w(N + 1);
  w[0] = 1e9;
  for(int i = 1; i <= N; i++){ cin >> w[i]; }

  // ????????????????????????
  sort(w.begin(), w.end());
  reverse(w.begin(), w.end());


  // dp[i][j]: i???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????°
  vector<vector<long long int> > dp(N + 1, vector<long long int>(W + 2, 0));
  dp[0][0] = 1;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j <= W + 1; j++){
      // dp[i][j]: i???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????°
      // = i-1???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????° * 2
      // + i-1???????????§?????¢?????????????????£?????????[j - w[i], j)???????????????????????????????????°
      // = i-1???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????° * 2
      // + (i-1???????????§?????¢?????????????????£?????????j - w[i]??\??????????????????????????????????????° - j??\??????????????????????????????????????°)
      // = i-1???????????§?????¢?????????????????£?????????j??\??????????????????????????????????????°
      // + (i-1???????????§?????¢?????????????????£?????????j - w[i]??\??????????????????????????????????????°
      int r = max(j - w[i], 0);
      dp[i][j] = (dp[i - 1][j] + dp[i - 1][r]) % MOD;
    }
  }

  // i, j????????´???????????????
  // ??¢?????????j????????????(j, i]?????¶???????????????(i, N]???????????????
  // ??¨????????´???????????????????????°????¨??????????????¨???????
  long long int sum = 0, ans = 0;
  for(int i = N; i >= 0; i--){
    // ???(i, N]???????????????????????¨??????????????????????????§????\???§?????£?????´??????
    // ????????????????????????
    if(sum + w[i] > W){
      ++ans;
      ans %= MOD;
      // ????????\??????????????????????????????????????¨??????????????§????????????????????????
      break;
    }

    // j?????????????????´????????????????????????i?????????????????????????????°????¨????
    long long int total = W - sum;
    for(int j = 1; j < i; j++){
      int low = max(total - w[j] - w[i] + 1, 0LL);
      int up = max(total - w[j] + 1, 0LL);
      ans += dp[j - 1][low] - dp[j - 1][up] + MOD;
      ans %= MOD;
    }

    // ???????????????????????´??°
    sum += w[i];
  }

  // ??????
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 18640
#include <bits/stdc++.h>
using namespace std;
void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
int N, M, x;
int main() {
	scanf("%d%d", &N, &M);
	int ret = N;
	for(int i = 0; i < M; i++) {
		scanf("%d", &x);
		ret = __gcd(ret, __gcd(x, N));
	}
	puts(ret == 1 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3108