akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		Map<String, Integer> hms = new HashMap<>();
		for (int i = 0; i < n; i++) {
			String s = sc.next();

			if (hms.containsKey(s)) {
				hms.put(s, hms.get(s) + 1);
			} else {
				hms.put(s, 1);
			}
		}

		int m = sc.nextInt();
		Map<String, Integer> hmt = new HashMap<>();
		for (int i = 0; i < m; i++) {
			String t = sc.next();

			if (hmt.containsKey(t)) {
				hmt.put(t, hmt.get(t) + 1);
			} else {
				hmt.put(t, 1);
			}
		}

		List<String> list = new ArrayList<>();
		list.addAll(hms.keySet());
		list.addAll(hmt.keySet());

		int ans = 0;
		for (String e : list) {
			int tmp = 0;
			if (hms.containsKey(e)) {
				tmp += hms.get(e);
			}
			if (hmt.containsKey(e)) {
				tmp -= hmt.get(e);
			}

			ans = Math.max(ans, tmp);
		}

		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    ll n;
    cin >> n;
    map<ll,ll> m;
    for(ll i=2;i<=sqrt(n);i++)
    {
        while(n%i==0)
        {
            ll p=i;
            if(m.find(i)==m.end())
            m[i]=1;
            else
            m[i]++;
            n/=i;
        }
    }
    if(n!=1)
    {
        if(m.find(n)==m.end())
        m[n]=1;
        else
        m[n]++;
    }
    ll ans=0;
    for(auto itr=m.begin();itr!=m.end();itr++)
    {
        ll i=1;
        ll val=(*itr).second;
        while(1)
        {
            ll sum=i*(i+1)/2;
            if(sum>val)
            break;
            i++;
        }
        ans+=i-1;
    }
    cout << ans << endl;
}


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

	return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int n, k;
    string s;
    cin>>n>>k>>s;

    int a1 = 0, a2 = 0;
    REP(i,n-1) {
        if (s[i] == 'L' && s[i+1] == 'R')
            a1++;
        if (s[i] == 'R' && s[i+1] == 'L')
            a2++;
    }

    int ans;
    ans = min(n - 1, n - 1 - a1 - a2 + k * 2);
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef set<int>        si;

template<typename T> T sgn (T x)      {return x<0? -1:x!=0; }
template<typename T> T gcd (T a, T b) {return a ? gcd (b % a, a) : b; }
//pi=acos(-1)
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define popcount __builtin_popcount
#define eb emplace_back
#define emp emplace
#define ss second
#define ff first
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

int ans, m, n;
int a[N], b[N];

void solve(){
    scanf("%d", &n);
    forn(i,0,n){
        scanf("%d %d", a+i, b+i);
    }
    sort(a,a+n);
    sort(b,b+n);
    m = n/2;
    //printf("%d\n", m);
    if(n&1){
        ans = b[m]-a[m]+1;
    }
    else{
        ans = b[m]+b[m-1] - (a[m]+a[m-1]) + 1;
    }
    printf("%d\n",ans);
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;//scanf("%d",&t);
    while(t--)solve();
}

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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> ans(n+1,0);
    for (int i = 1; i <= 100; i++) {
        for (int j = 1; j <= 100; j++) {
            for (int k = 1; k <= 100; k++) {
                auto num = i*i+j*j+k*k+i*j+j*k+k*i;
                if(num>n)continue;
                ans[num]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        std::cout << ans[i] << std::endl;
    }
}

Measured memory_bytes: 3552
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}

LL K;
int main()
{
    //std::ios::sync_with_stdio(false);
    while(~scanf("%lld",&K))
    {
        if(K==0)
        {
            puts("4");
            printf("3 3 3 3\n");
        }
        else if(K==1)
        {
            puts("3");
            printf("1 0 3\n");
        }
        else if( K <= 50)
        {
            printf("%lld\n", K);
            for(int i=1;i<=K;i++)
            {
                printf("%lld%c", i, i==K?'\n':' ');
            }
        }
        else
        {   
            LL base = K/50;
            LL res = K%50;
            puts("50");
            for(int i=1;i<=50;i++)
            {
                printf("%lld%c", base+(i-1)+((50-i)<res?1:0), i==50?'\n':' ');
            }
        }
        
    }
    //printf("%lld\n", ((x)%mod+mod)%mod );
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
}


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

int main() {
  int N, K, totalDis;
  cin >> N >> K;

  for (int i = 0; i < N; i++) {
	int x;
    cin >> x;
    
    if (x <= K / 2) {
      totalDis += x * 2;
    } else {
      totalDis += (K - x) * 2;
    }
  }
  
  cout << totalDis << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int x,a,b;
    cin >> x>>a>>b;
    
    cout << (x-a)%b<< endl; 

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#define MAX 3001
using namespace std;
int n;
vector<int>ABC(3);

int calc(vector<int> vec,vector<int>take)
{
  vector< vector<int>>abc(4);
  for(int i=0;i<n;i++)
  {
    abc[vec[i]].push_back(take[i]);
  }
  if(abc[0].size()==0 or abc[1].size()==0  or abc[2].size()==0)return MAX;
  int res=0;
  for(int i=0;i<3;i++)
  {
    res+=(abc[i].size()-1)*10;
    res+=abs(ABC[i]-accumulate(abc[i].begin(), abc[i].end(),0));
  }
  //cout<<res;
  return res;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n>>ABC[0]>>ABC[1]>>ABC[2];
  vector<int>l(n);
  int resu=MAX;
  for(int i=0;i<n;i++)
  {
    cin>>l[i];
  }
  vector<int>use(n);
  for(int i=0;i<(1<<(2*n));i++)
  {
    //初期化
    for(int j=0;j<n;j++)
    {
      use[j]=(i>>(2*j))%4;
    }
    resu=min(resu,calc(use,l));

  }
  cout<<resu<<endl;
  return 0;

}


Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)


def search(idx, S):
    if S == (1 << N) - 1:
        return 1

    cnt = 0
    for n in G[idx]:
        if ((S >> n) & 1) == 1:
            continue

        cnt += search(n, S | (1 << n))

    return cnt

print(search(0, 1))

Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iomanip>

using namespace std;

typedef long long LL;

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

const int N = 20 + 2;
const int INF = 1000000;

int n, m;
int ret;
int color[N][N];

int ok(int x, int y)
{
	static int c[4];
	c[0] = color[x][y];
	c[1] = color[x + 1][y];
	c[2] = color[x][y + 1];
	c[3] = color[x + 1][y + 1];
	for(int i = 0; i < 4; ++ i)
		for(int j = i + 1; j < 4; ++ j)
			if (c[i] == c[j])
				return true;
	return false;
}

int ok(int xa, int ya, int xb, int yb)
{
	if (color[xb][yb] >= 0) return false;
	if (color[xa][ya] >= 0) return false;
	color[xa][ya] = color[xb][yb] = INF;
	for(int cx = xa - 1; cx <= xb; ++ cx) {
		for(int cy = ya - 1; cy <= yb; ++ cy) {
			if (! ok(cx, cy)) {
				color[xa][ya] = color[xb][yb] = -1;
				return false;
			}
		}
	}
	color[xa][ya] = color[xb][yb] = -1;
	return true;
}

set<vector<vector<int> > > ss;

void dfs(int cur)
{
	if (cur * 2 == n * m) {
		++ ret;
		return;
	}
	int ways = 5, rx, ry;
	for(int i = 1; i <= n; ++ i) {
		for(int j = 1; j <= m; ++ j) {
			if (color[i][j] >= 0) continue;
			int curWays = 0;
			if (i + 1 <= n && ok(i, j, i + 1, j)) {
				++ curWays;
			}
			if (j + 1 <= m && ok(i, j, i, j + 1)) {
				++ curWays;
			}
			if (i - 1 >= 1 && ok(i - 1, j, i, j)) {
				++ curWays;
			}
			if (j - 1 >= 1 && ok(i, j - 1, i, j)) {
				++ curWays;
			}
			if (curWays < ways) {
				ways = curWays;
				rx = i;
				ry = j;
			}
		}
	}
	if (ways == 0 || ways == 5) {
		return;
	}
	int i = rx, j = ry;
	if (i + 1 <= n && ok(i, j, i + 1, j)) {
		color[i][j] = color[i + 1][j] = cur;
		dfs(cur + 1);
		color[i][j] = color[i + 1][j] = -1;
	}
	if (i - 1 >= 1 && ok(i - 1, j, i, j)) {
		color[i - 1][j] = color[i][j] = cur;
		dfs(cur + 1);
		color[i - 1][j] = color[i][j] = -1;
	}
	if (j + 1 <= m && ok(i, j, i, j + 1)) {
		color[i][j] = color[i][j + 1] = cur;
		dfs(cur + 1);
		color[i][j] = color[i][j + 1] = -1;
	}
	if (j - 1 >= 1 && ok(i, j - 1, i, j)) {
		color[i][j - 1] = color[i][j] = cur;
		dfs(cur + 1);
		color[i][j - 1] = color[i][j] = -1;
	}
}

void solve() {
	memset(color, -1, sizeof color);
	if (n * m & 1) {
		cout << 0 << endl;
		return;
	}
	ret = 0;
	ss.clear();
	dfs(0);
	cout << ret << endl;
	/*  for(set<vector<vector<int> > >::iterator it = ss.begin(); it != ss.end(); ++ it) {
		for(int i = 0; i < n; ++ i) {
		for(int j = 0; j < m; ++ j) {
		cout << (*it)[i][j] << ' ';
		}
		cout << endl;
		}
		cout << endl << endl;
		}*/
}

int main() {
	for( ; cin >> n >> m && (n || m); ) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1180
#include <algorithm>
#include <iostream>
#include <vector>

using ll = long long int;
using namespace std;

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> pluss;
    vector<ll> minuss;
    vector<ll> zeros;
    for(ll i=0; i<n; ++i){
        ll a; cin >> a;
        if(a < 0){ minuss.push_back(a); }
        else if(a == 0){ zeros.push_back(a); }
        else{ pluss.push_back(a); }
    }
    sort(pluss.begin(), pluss.end());
    sort(minuss.begin(), minuss.end());

    ll p_len = pluss.size();
    ll m_len = minuss.size();
    ll z_len = zeros.size();

    ll minus_num = p_len * m_len;
    ll zeros_num = z_len * (z_len - 1) / 2 + z_len * (m_len + p_len);

    ll l = -1e18 - 10; ll r = 1e18 + 10;
    while(r - l > 1){
        ll mid = (l + r) / 2;
        ll cnt = 0;
        if(mid > 0){
            ll ret = 0;
            for(ll i=0; i<(ll)pluss.size(); ++i){
                ret += upper_bound(pluss.begin(), pluss.end(), mid / pluss[i]) - pluss.begin(); 
                if(pluss[i] * pluss[i] <= mid){ ret -= 1; }
            }
            cnt += ret / 2;
            ret = 0;
            for(ll i=0; i<(ll)minuss.size(); ++i){
                ret += m_len - (ll)(lower_bound(minuss.begin(), minuss.end(), mid / minuss[i]) - minuss.begin()); 
                if(minuss[i] * minuss[i] <= mid){ ret -= 1; }
            }
            cnt += ret / 2;
            cnt += minus_num;
            cnt += zeros_num;
        }
        else if(mid == 0){
            cnt += minus_num;
            cnt += zeros_num;
        }
        else{
            for(ll i=0; i<(ll)pluss.size(); ++i){
                cnt += upper_bound(minuss.begin(), minuss.end(), (mid - pluss[i] + 1) / pluss[i]) - minuss.begin();
            }
        }
        if (cnt >= k){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 2548
#include<stdio.h>

int main()
{
    double a,b,c,d,e,f,g,j;

    while(scanf("%lf",&a) !=EOF){
            scanf("%lf",&b);
            scanf("%lf",&c);
            scanf("%lf",&d);
            scanf("%lf",&e);
            scanf("%lf",&f);
    g=(e*c-b*f)/(a*e-b*d);
    j=(a*f-c*d)/(a*e-b*d);
    g=g+0.00;
    j=j+0.00;
    printf("%.3lf %.3lf\n",g,j);
    }
    return 0;
}


Measured memory_bytes: 1928
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

const int INF = 1e9;

int need[10] = {6,2,5,5,4,5,6,3,7,6};

string maxS(string a, string b){
  if(a.length() > b.length()) return a;
  if(b.length() > a.length()) return b;
  for(int i = 0; i < a.length(); i++){
    if(a[i] == b[i]) continue;
    else if(int(a[i] - b[i]) > 0) return a;
    else return b;
  }
  return a;
}

int main(){
  int N, M;
  cin >> N >> M;

  vector<int> A(M);
  rep(i, M) cin >> A[i];

  // dp[i]はi本使って作れる最大の数
  vector<string> dp(N+10, "");
  //dp[0] = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++){
      if(dp[i] == "" && i != 0) continue;
      char c = '0' + A[j];
      string t = dp[i] + c;
      dp[i + need[A[j]]] = maxS(dp[i + need[A[j]]], t);
    }
  }

  cout << dp[N] << endl;
  return 0;
}



Measured memory_bytes: 38016
#include <iostream>
#include <vector>
using namespace std;
using pll = pair<long long, long long>;
const long long INF = 1LL<<60;

void chmax(pll &a, pll b) {
    long long f, s;
    if (a.first >= b.first) f = a.first, s = max(a.second, b.first);
    else f = b.first, s = max(a.first, b.second);
    a = pll(f, s);
}

int main() {
    int N; cin >> N;
    vector<long long> A(1<<N);
    for (int bit = 0; bit < (1<<N); ++bit) cin >> A[bit];

    vector<pll> dp(1<<N);
    for (int bit = 0; bit < (1<<N); ++bit) dp[bit] = pll(A[bit], -INF);
    for (int i = 0; i < N; ++i) {
        for (int bit = 0; bit < (1<<N); ++bit) {
            if (bit & (1<<i)) {
                chmax(dp[bit], dp[bit ^ (1<<i)]);
            }
        }
    }
    vector<long long> res(1<<N, 0);
    res[0] = 0;
    for (int bit = 1; bit < (1<<N); ++bit) {
        res[bit] = max(res[bit-1], dp[bit].first + dp[bit].second);
        cout << res[bit] << endl;
    }
}
    


Measured memory_bytes: 11264
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main()
{
	int N, K;
	int ans = 0;
	
	std::cin >> N;
	
	std::cin >> K;
	
	ans = K;
	
	for(int i = 0; i < N-1; i++)
	{
		ans *= (K-1);
	}

	std::cout << ans << std::endl;
	return 0;
}


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

int main() {
  int64_t n,k,q;
  cin >> n >> k >> q;
  vector<int64_t> a(n);
  rep(i,q){
    int64_t s;
    cin >> s;
    a[s-1]++;
  }
  
  rep(i,n){
    q-a[i]<k ? cout << "Yes" : cout << "No";
    cout << endl;
  }
}

Measured memory_bytes: 1408
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

int main(){

	int n,a;
	string s;
	cin>>s;

	cout<<s.substr(0,4)<<" "<<s.substr(4)<<endl;

}


Measured memory_bytes: 764
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	scan(N>>K);
	int ans=0;
	rep(i,N){
		int h;
		scan(h);
		if(h>=K) ans++;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    S=ST()
    T=ST()
    lcm = N*M//(gcd(N,M))
    ans = defaultdict(str)
    for i,s in enumerate(S):
        ans[i*lcm//N] = s
    for i,t in enumerate(T):
        if(ans[i*lcm//M] not in (t,"")):
            print(-1)
            return 
    print(lcm)
if __name__ == '__main__':
    main()

Measured memory_bytes: 80488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
const ll MOD = 1000000007;

int main(){
    ll N;cin>>N;
    map<ll,ll> p;
    for(ll i=2;i<=N;i++){
        ll t=i;
        for(ll j=2;j<=i;j++){
            if(t%j!=0)continue;
            else{
                if(p.find(j)==p.end())p[j]=0LL;
                while(t%j==0){
                    p[j]++;
                    t/=j;
                }
            }
        }
    }
    ll res=1;
    for(auto i:p){
        res=(res*(i.second+1))%MOD;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: i32 = n.trim().parse().unwrap();

    let mut m = std::collections::HashMap::<String, bool>::new();
    for _ in 0..n{
        let mut t = String::new();
        std::io::stdin().read_line(&mut t).ok();
        m.insert(t, true);
    }

    println!("{}", m.len());
}

Measured memory_bytes: 18160
#include <bits/stdc++.h>
#define int long long 
#define fu(i, a, b) for (int i = a, I = (b) + 1; i < I; ++i)
#define fd(i, a, b) for (int i = a, I = (b) - 1; i > I; --i)
using namespace std;
const int N = 100005;

template <class T> inline void rd(T &x) {
    x = 0; T f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9') f = ch == '-' ? -1 : 1, ch = getchar();
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    x *= f;
} 

int n, q, top, st[N], f[N], d[N];

inline void solve(int p, int len, int val) {
	int nxtp = lower_bound(st + 1, st + p + 1, len) - st - 1;
	if (!nxtp) d[1] += val, d[len + 1] -= val;
	else f[nxtp] += val * (len / st[nxtp]), solve(nxtp, len % st[nxtp], val); 
}

signed main() {
	rd(n), rd(q);
	st[++top] = n;
	fu(i, 1, q) {
		int x; rd(x);
		while (top && x <= st[top]) --top;
		st[++top] = x;
	}
	f[top] = 1; 
	fd(i, top, 1) solve(i, st[i], f[i]);
	fu(i, 1, n) d[i] += d[i - 1], printf("%lld\n", d[i]);
	return 0;
}

Measured memory_bytes: 4096
import java.util.*;

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 = 0;
		int x, y, z, w;
		for (int i = A; i <= B; i++) {
			x = i / 10000;
			y = i % 10;
			z = i / 1000 - x * 10;
			w = (i % 100 - y) / 10;
			if (x == y && z == w) {
				c++;
			}
		}
		System.out.println(c);
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    map<string, bool> key;
    int n;
    cin >> n;
    rep(i, n)
    {
        string s;
        cin >> s;
        key[s] = true;
    }
    int m;
    cin >> m;
    bool isopen = false;
    rep(i, m)
    {
        string s;
        cin >> s;
        if (key[s])
        {
            if (isopen)
            {
                cout << "Closed by " << s << endl;
            }
            else
            {
                cout << "Opened by " << s << endl;
            }
            isopen ^= true;
        }
        else
        {
            cout << "Unknown " << s << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3244
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


/* define */
#define Yes(X) puts ( (X) ? "Yes" : "No")
#define YES(X) puts ( (X) ? "YES" : "NO")
#define FOR(i, a, b) for ( int i = (a); i < (b) ; i++)
#define REP(i, n) for ( int i = 0; i < (n) ; i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1000000007;

/* alias */
typedef long long ll;
typedef unsigned  u;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0) return Lgcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / Lgcd(a, b) * b;
}

/* main */

int main() {
	int  n, ans = 0;
	cin >> n;
	if (n < 10)ans = n;
	else if (n < 100) ans = 9;
	else if (n < 1000) ans = n - 90;
	else if (n < 10000) ans = 909;
	else if (n < 100000) ans = n - 9090;
	else ans = 90909;
	cout << ans;

}

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

int main(){
    long n;
    cin >> n;
    vector<string> s(n);
    map<string,int> mp;
    rep(i,n){
        cin >> s[i];
        mp[s[i]] += 1;
    }
    int cmax = 0;
    rep(i,n) cmax = max(cmax,mp[s[i]]);
    vector<string> t(0);
    int j = 0;
    for(auto it = mp.begin(); it != mp.end(); it++){
        if(it->second == cmax){
            cout << it->first << endl;
        }
    }
    sort(t.begin(), t.end());
    rep(i,t.size()) cout << t[i] << endl;
    return 0;
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}



void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using namespace std;

class CUnification {
public:
	void solve(std::istream& in, std::ostream& out) {
		string s, aux;
		in >> s;
		int ans = 0;
		REP(i, s.size()){
			if (aux.empty())
				aux.pb(s[i]);
			else{
				if (aux.back() != s[i]){
					aux.pop_back();
					ans += 2;
				} else
					aux.pb(s[i]);
			}
		}
		out << ans;

	}
};

int main() {
	CUnification solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

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

int main() {
    char c; cin >> c;
    string vowel = "aeiou";
    if (find(vowel.begin(), vowel.end(), c) != vowel.end()) {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[2004];
int main(){
    ll n,m;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    ll ans=1e18+5;
    for(int i=1;i<=100;i++){
        ll dns=0;
        for(int j=1;j<=n;j++){
            dns+=(a[j]-i)*(a[j]-i);
        }
        ans=min(ans,dns);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m&&n != 0 && m != 0) {
		bool friends[501];
		bool ffriends[501];
		for (int i = 1; i <= 500; i++) {
			friends[i] = false;
			ffriends[i] = false;
		}
		friends[1] = true;
		ffriends[1] = true;
		vector<int> aa, bb;
		for (int i = 0; i < m; i++) {
			int a, b;
			cin >> a >> b;
			aa.emplace_back(a);
			bb.emplace_back(b);
		}
		for (int i = 0; i < m; i++) {
			if (aa[i] == 1) {
				friends[bb[i]] = true;
				ffriends[bb[i]] = true;
			}
		}
		for (int i = 0; i < m; i++) {
			if (friends[aa[i]] == true) {
				ffriends[bb[i]] = true;
			}
			if (friends[bb[i]] == true) {
				ffriends[aa[i]] = true;
			}
		}
		int ans = 0;
		for (int i = 1; i <= 500; i++) {
			if (ffriends[i]) {
				ans++;
			}
		}
		cout << ans-1 << endl;
	}
}

Measured memory_bytes: 3148
import collections
n = int(input())

s = []
sLen = len(s)
for i in range(n):
    s.append(input())

c = collections.Counter(s)
c_m = c.most_common()
max = c.most_common()[0][1]
print()
ans = []
for i in range(len(c_m)):
    if max != c_m[i][1]:
        break
    ans.append(c_m[i][0])
ans.sort()
for i in ans:
    print(i)


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

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

    int fiveHundredsYenCoinNum = x / 500;
    x -= fiveHundredsYenCoinNum * 500;

    int fiveYenCoinNum = x / 5;

    cout << fiveHundredsYenCoinNum * 1000 + fiveYenCoinNum * 5 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
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; }
using namespace std;


int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  
  if(N%2==1){
    CONo;
    return 0;
  }
  
  else{
    bool CAN=true;
    for(int i=0; i<N/2; ++i){
      if(S.at(i)!=S.at(i+N/2)) CAN=false;
    }
    
    
    if(CAN){
      COYe;
      return 0;
    }
    
    CONo;
    return 0;
  }
  
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
ans=[sum([(p[i]+1)/2 for i in range(k)])]
for i in range(n-k):
    ans.append(ans[-1]-(p[i]+1)/2+(p[k+i]+1)/2)
print(max(ans))

Measured memory_bytes: 24812
#include<stdio.h>

signed main()
{
  int r, g, b;
  scanf("%d %d %d", &r, &g, &b);

  int num = (100 * r) + (10 * g) + b;
  if( num % 4 == 0 ) puts("YES");
  else puts("NO");

  return 0;
}

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

using namespace std;
#define debug(x) { cerr << #x < " = " << x << endl; }
typedef long long ll;

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll n;
	cin >> n;
	
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		if(i%5 != 0 && i%3 != 0){
			sum += i;
		}
	}
	cout << sum << endl; 
	
	return 0;
}


Measured memory_bytes: 3616
import java.util.*;
//累積はプログラミングの世界での呼ばれ方
public class Main {
  public static void main(String[] args) {
    boolean[] isprime = new boolean[100010];
    for(int i = 0; i <= 100000 ; i++){
      isprime[i] = true;
    }

    isprime[0] = isprime[1] = false;

    for(int i = 2 ; i * i <= 100000 ; i++){
      int j = 2;
      while(i * j <= 100000){
        isprime[i*j] = false;
        j++;
      }
    }

    Scanner s = new Scanner(System.in);
    int Q = s.nextInt();
    int[] l1 = new int[Q] , r1 = new int[Q] , SR = new int[100010];
    for(int i = 0; i < Q; i++){
      //System.out.println(N + " " + Q + " " + S);
      l1[i] = s.nextInt();
      r1[i] = s.nextInt();
    }

    SR[0] = 0;
    for(int i = 1; i <= 100000; i++){
      if(isprime[i] && isprime[(i + 1) / 2])
        SR[i] = SR[i - 1] + 1;
      else
      SR[i] = SR[i - 1];
    }
    for(int i = 0; i < Q; i++){
      System.out.println(SR[ r1[i]] - SR[ l1[i] - 1]);
    }
  }
}


Measured memory_bytes: 92400
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

int main(void)
{
    int n, q;

    std::cin >> n;
    std::cin >> q;

    std::vector< std::set<int> > sets;

    for (int i = 0; i < n; i++) {
        std::set<int> set;
        set.insert(i);
        sets.push_back(set);
    }

    for (int i = 0; i < q; i++) {
        int com, x, y;
        std::cin >> com;
        std::cin >> x;
        std::cin >> y;

        int xIndex = -1, yIndex = -1;
        for (int j = 0; j < sets.size(); j++) {
            if (xIndex < 0) {
                std::set<int>::iterator it = sets[j].find(x);
                if (it != sets[j].end()) {
                    xIndex = j;
                }
            }
            if (yIndex < 0) {
                std::set<int>::iterator it = sets[j].find(y);
                if (it != sets[j].end()) {
                    yIndex = j;
                }
            }
            if (xIndex >= 0 && yIndex >= 0) {
                break;
            }
        }

        // unite
        if (com == 0) {
            if (xIndex != yIndex) {
                if (xIndex > yIndex) {
                    std::swap(xIndex, yIndex);
                }
                sets[xIndex].insert(sets[yIndex].begin(), sets[yIndex].end());
                sets.erase(sets.begin() + yIndex);
            }
        }
        // same
        else {
            if (xIndex == yIndex) {
                std::cout << "1" << std::endl;
            } else {
                std::cout << "0" << std::endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4344
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    for i in range(k, n):
        if a[i] > a[i - k]:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 105492
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)

signed main()
{
  int N, K;
  int A[5005];
  
  int it = 0, cnt = 0;
  
  cin >> N >> K;

  Rep(i, N) cin >> A[i];

  sort(A, A + N, greater<int>());

  Rep(i, N) {
    int sum = 0, j;
    for(j = i; j < N; j++) {
      sum += A[j];
      if(sum >= K) {
	it = max(it, j + 1);
	sum -= A[j];
      }
    }
  }

  cout << N - it << endl;

  return 0;
}

  


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll a, b, c;
  cin >> a >> b >> c;
  
  cout << min((a % 2) * (b*c), min((b % 2) * a*c, (c % 2)*a*b)) << endl;

  return 0;
}


Measured memory_bytes: 256
/*
गिरते हैं शहसवार ही मैदान-ए-जंग में ।
वो तिफ़्ल क्या गिरे जो घुटनों के बल चले ।।
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
#define int     long long int
#define ull     unsigned int
#define ld      long double
#define pb      push_back
#define pa      pair<int,int>
#define v1d     vector<int>
#define v2d     vector<vector<int> >
#define vpa     vector<pair<int,int>>
#define M       1000000007
#define MN      LLONG_MIN
#define MX      LLONG_MAX
#define ff      first
#define ss      second
#define endl    "\n"
#define v1s     vector<string>
#define all(v)  v.begin(),v.end()
#define S(v)    sort(v.begin(),v.end())
#define RS(v)   sort(v.rbegin(),v.rend())
#define R(v)    reverse(v.begin(),v.end())
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define T       int tc;cin>>tc;while(tc--)
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)      for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)      for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define sz(v)       (int)(v.size())
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define N 400005


void Weapons19(){
    int n;cin>>n;
    int m;cin>>m;
    int s=0;
    while(m--){
        int x;cin>>x;s+=x;
    }
    if(s>n)cout<<-1;
    else cout<<n-s;









}   

int32_t main(){

    /*
    त्यक्तवाधर्मं च लोभं च
    मोहंचो द्यमास्थिता।
    युद्ध्यध्वमनहंकारा
    यतो धर्मस्ततो जयः।।
    */

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

   

    Weapons19();
    
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double 
#define MOD 1000000007ll 
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
ll power(ll a,ll p,ll m)
{
    ll re=1;
    re%=m;
    for(;p;p>>=1){
        if(p&1) re=re*a%m;
        a=a*a%m;
    }
    return re;
}
int main()
{
    ll x;
    cin>>x;
    x++;
    x %= 2;
    cout<<x<<endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>

using namespace std;

void abc_150a();

void abc_151a();

void abc_152a();

int main()
{
  //abc_150a();
  //abc_151a();
  abc_152a();

}

void abc_150a()
{
  int K, X;
  cin >> K >> X;

  if (500 * K >= X) cout << "Yes\n";
  else cout << "No\n";
}

void abc_151a()
{
  char C;
  cin >> C;

  cout << (char)((int)C + 1) << "\n";
}

void abc_152a()
{
  int N, M;
  cin >> N >> M;
  if (N == M) cout << "Yes\n";
  else cout << "No\n";
}

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<int,ll> pil;

int N,M;
vector<pil> G[100010];
ll X[100010];
bool vis[100010] = {0};
bool flag;

void DFS(int v,ll x)
{
    if(vis[v])
    {
        if(x != X[v])flag = true;
        return;
    }
    vis[v] = true;
    X[v] = x;
    for(int i = 0; i < G[v].size(); i++)DFS(G[v][i].fi,x + G[v][i].se);
    return;
}

int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i < M; i++)
    {
        int a,b;
        ll c;
        scanf("%d%d%lld",&a,&b,&c);
        G[a].push_back(mk(b,c));
        G[b].push_back(mk(a,-c));
    }

    for(int i = 1; i <= N; i++)
    {
        if(!vis[i])
        {
            DFS(i,0);
        }
    }
    if(flag)printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 16512
#include<bits/stdc++.h>
using namespace std;
int n,t[1005];
bool flg[10000];
 
 
int main(){
  for(int i=0;i<10000;i++)flg[i]=false;
 
  cin>>n;
  for(int i=0;i<n;i++)cin>>t[i];
 
  for(int i=0;i<n;i++){
    int num=0;
    for(int j=0;j<4;j++){
      if(i+j>=n)break;
      num=num*10+t[i+j];
      flg[num]=true;
    }
  }
   
  int ans=0;
  while(flg[ans])ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int N;
    cin>>N;
    ll n;
    int i = 0;
    vector<int> ans;
    while (N != 0) {
        n = pow(2, i);
        if (N % (n * 2) != 0) {
            ans.push_back(1);
            if (i % 2 == 0) N -= n;
            else N += n;
        }
        else ans.push_back(0);
        i++;
    }
    reverse(ans.begin(), ans.end());
    if (ans.size() > 0) rep(i, ans.size()) cout<<ans[i];
    else cout<<0;
    cout<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = input().split()
N = list(N[0])
#N=list(map(int,N))
if int(N[0]+N[0]+N[0]) >= int("".join(N)):
    print(int(N[0]+N[0]+N[0]))
else:
    print(int(N[0]+N[0]+N[0])+111)


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}

int divisors(int n){
	int ans = 0; 
	if(n==1){
		return 1;
	}

	else{
		for (int i = 1; i <= sqrt(n); i++){
			if(n%i==0){
				ans++;
				if(i!=sqrt(n)){
					ans++;
				}
			}
		}
	}
	return ans;
}

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

	int sum = 0;


	for (int i = 1; i <= n; i++){
		sum += (i / 2.0) * floor((1.0 * n) / i) * floor(1 + (1.0 * n) / i);
	}
	cout << sum << "\n";

	return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  int cnt = 1;
  rep(i, N) {
    if(!(A[i]%2))
      cnt *= 2;
  }
  int ans = pow(3, N)-cnt;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int N,i,flag=1,temp,num=0;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  /*bubble sort*/
  while(flag){
    flag=0;
    for(i=N-1;i>=1;i--){
      if(A[i]<A[i-1]){
	temp=A[i];
	A[i]=A[i-1];
	A[i-1]=temp;
	flag=1;
	num++;
      }
    }
  }
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i<N-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",num);
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

typedef long long ll;

//printf("%d", n);
//printf("%d", sum);
//scanf("%d", &n);
//scanf("%c", &c);
//scanf("%lf", &d);

#define NUM (10000)

int main(int argc, char** argv){
    int H, A;
    scanf("%d", &H);
    scanf("%d", &A);

    int i = 0;
    while(1){
        H -= A;
        i++;
        if(H <= 0){
            break;
        }
    }

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

    return 0;
}




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

int main() {
  int N,max,mieru;
  vector<int> H(30);
  cin>>N;
  for (int i = 0; i < N; i++) cin>>H[i];
  max = H[0];
  mieru = 1;
  for (int i = 1; i < N; i++) {
    if (H[i] >= max) {
      mieru++;
      max = H[i];
    }
  }
  cout<<mieru<<endl;
  return 0;
}

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

using namespace std;

#define    VI       vector<int>
#define    VS       vector<string>
#define    LL       long long int
#define    ML       map<LL,LL>
#define    VLL      vector<LL>
#define    PB       push_back
#define    MP       make_pair
#define    FT       first
#define    SD       second
#define    PI       2*acos(0.0)
#define    F(i,a,n) for(int i=a;i<=n;i++)
#define    MS(a,v)  memset(a,v,sizeof(a));
#define    DEBUG    cout<<" I AM HERE "<<endl
#define    TC       int T;cin>>T;for(int TC=1;TC<=T;TC++)
#define    SORT(v)  sort(v.begin(),v.end())
#define    RSORT(v) sort(v.begin(),v.end(),greater<int>())
#define    FAST     ios_base::sync_with_stdio(false);cin.tie(NULL);

int main()
{
    FAST
    int n,k,i,nn,x;
    cin>>n>>k;
    int man[n+1];
    int f[150];
    MS(f,0);
    while(k--)
    {
        cin>>nn;
        F(i,0,nn-1)
        {
            cin>>x;
            if(f[x]==0) n--;
            f[x]=1;
        }
    }
    cout<<n<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string s;
int n;

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

  cin >> s;
  n = s.length();

  vector<int> remain;
  remain.push_back(-1);
  int ans = 0;
  int i = 0;  //みるところ
  int j = 1;  //次にみるところ

  while (j < n) {
    // cout << i << ' ' << j << '\n';
    if (s[i] != s[j]) {
      ans += 2;

      if (remain.back() != -1) {
        i = remain.back();
        remain.pop_back();
        j++;
      } else {
        i = j + 1;
        j += 2;
      }
    } else {
      remain.push_back(i);
      i = j;
      j++;
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 972
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
	char A , B;
	cin >> A >> B;

	if(A == 'H' && B == 'H') cout << 'H' << endl;
	else if(A == 'D' && B == 'D') cout << 'H' << endl;
	else cout << 'D' << endl;
}

Measured memory_bytes: 256