akhauriyash/Code-Regression huggingface dataset:
// Gracias, Rodolfo
// Gracias, MarcosK
// Gracias, Graphter
// Obrigado, Dilson
//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for (Long i = a; i < b; i++)
#define roF(i,a,b) for (Long i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) (v).begin(),(v).end()

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long Long;
typedef long double Double;
typedef unsigned long long ULong;
typedef pair<Long, Long> Pair;
typedef vector<Long> Vector;
typedef vector<Pair> PairVector;

const int N = 1e6;
const Long INF = 1e18;
const Double EPS = 10e-9;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
Long random(Long a, Long b) { return uniform_int_distribution<Long> (a, b) (rng); }

void solve() {
	Long n, k;
	cin >> n >> k;
	Long x[n];
	For(i, 0 ,n) cin >> x[i];
	Long ans = INF;
	For(i, 0, n - k + 1) {
		Long l = x[i];
		Long r = x[i + k - 1];
		Long temp;
		if ((l > 0 and r > 0) or (l < 0 and r < 0)) {
			temp = max(abs(l), abs(r));
		} else {
			temp = min(2 * abs(l) + abs(r), abs(l) + 2 * abs(r));
		}
		ans = min(ans, temp);
	}
	cout << ans << endl;
}

int main() {
	fastio;
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 4396
from math import sqrt
N, D = map(int, input().split())
X = []
ans = 0
for _ in range(N):
    x = [int(s) for s in input().split()]
    X.append(x)
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        sqdist = round(sqrt(dist))
        if sqdist ** 2 == dist:
            ans += 1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<numeric>
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
const int maxn=1000000;
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);
void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
const int nn=1e5+5;
int result[100005];
void solve() {
   int n,k;
   cin>>n>>k;
   int arr[n];
   int cnt=0;
   for(int i=0;i<n;++i){
       cin>>arr[i];
       if(arr[i]>=k) cnt++;
   }
   cout<<cnt<<"\n";
   
    
}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //fillprime();
    //int t;cin>>t;while(t--)
    solve();
}

Measured memory_bytes: 4512
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int a,b,k;
	cin>>a>>b>>k;

	int c=0;
	int m=min(a,b);
	for(int i=m;i>0;--i){
		if(a%i==0&&b%i==0){
			++c;
			if(k==c){
				cout<<i;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main  implements Runnable { //Runnableを実装する

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行

    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
/*		FastScanner sc = new FastScanner("6 6 \r\n" +
				"..#..#\r\n" +
				"......\r\n" +
				"#..#..\r\n" +
				"......\r\n" +
				".#....\r\n" +
				"....#.");*/
    	//FastScanner sc = new FastScanner("13 1 4 3000");
		int r = Integer.parseInt(sc.next());
		int g = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
		//int b = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[h][w];
		//int atmp[] = new int[h];
		//int max= 0;
		//int blackar[][] = new int[h*w][2];
		//int p=0;
		int ans = 0;
		for(int i =0; i<=n; i++)
		{
			for(int j =0; j<=n; j++)
			{
				int tmp = i*r+j*g;
				tmp = n-tmp;
				if(tmp%b==0 && tmp >= 0)
				{
					ans++;
				}
			}
		}



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

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long nextInt() {
            return Integer.parseInt(next());
        }

    }

}

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

bool prime(int a){
	if(a==1)return false;
	for(long long i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}

int main(){
	int a,d,n;
	while(cin>>a>>d>>n && a+d+n!=0){
		int count=0;
		while(count<n){
			if(prime(a))count++;
			a+=d;
		}
		cout<<a-d<<endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
#define endl "\n"
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define pii pair<int,int> 
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

long long M  = 1e9+7;
 
signed main(){
    fast;
    int h1,a1,h2,a2; cin >> h1 >> a1 >> h2 >> a2;
    int curr = 0;
    while(h1 && h2){
    	if(curr%2 == 0)
    		h2 = max(0ll,h2-a1);
    	else
    		h1 = max(0ll,h1-a2);
    	curr++;
    }
  
    if(curr%2 == 1){
    	cout << "Yes" << endl;
    }
    else
    	cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  VV<> a; assign(a, h, w);
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> a[i][j];
  VV<> res;
  for (int i = 0; i < h; i++) for (int j = 0; j < w - 1; j++) {
    if (a[i][j] & 1) {
      res.push_back(V<>{i, j, i, j + 1});
      a[i][j]--;
      a[i][j + 1]++;
    }
  }
  for (int i = 0; i < h - 1; i++) {
    if (a[i][w - 1] & 1) {
      res.push_back(V<>{i, w - 1, i + 1, w - 1});
      a[i][w - 1]--;
      a[i + 1][w - 1]++;
    }
  }
  cout << res.size() << '\n';
  for (auto&& v : res) cout << v[0] + 1 << ' ' << v[1] + 1 << ' ' << v[2] + 1 << ' ' << v[3] + 1 << '\n';
}

Measured memory_bytes: 10032
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        String a = br.readLine();
        String b = br.readLine();
        String s = "";
        if (a.length() < b.length()) {
            s = "LESS";
        } else if (a.length() > b.length()) {
            s = "GREATER";
        } else {
            for (int i = 0; i < a.length(); i++) {
                if (a.charAt(i) < b.charAt(i)) {
                    s = "LESS";
                    break;
                } else if (a.charAt(i) > b.charAt(i)) {
                    s = "GREATER";
                    break;
                } else if (a.charAt(i) == b.charAt(i) && i == a.length() - 1) {
                    s = "EQUAL";
                }
            }
        }
        System.out.println(s);
        bw.flush();
    }
}


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

using namespace std;

int main(void){
 int n,k;
 cin >> n >> k;
 vector<int> v;
 for(int i = 0; i < n; i++){
  int tmp;
  cin >> tmp;
  v.push_back(tmp);
 }
  
 sort(v.begin(),v.end());
 int sum = 0;
 for(int i = 0; i < k; i++){
  sum += v[i];
 }
  
  cout << sum;

}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<ctype.h>

typedef long long ll;

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll max(ll a, ll b) { return (a > b) ? a : b; }

ll min(ll a, ll b) { return (a < b) ? a : b; }

ll asc(const void* a, const void* b) { return *(ll*)a - *(ll*)b; }

ll dsc(const void* a, const void* b) { return *(ll*)b - *(ll*)a; }

bool flag;

int main() {
	ll a,b,c;
	scanf("%lld%lld%lld", &a,&b,&c);
	for (int i = 1; i <= b/gcd(a, b); i++) {
		if (i*a % b == c) {flag = true;break;}
	}
	if (flag)printf("YES");
	else printf("NO");

	return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    ll x, t;
    cin >> x >> t;
    cout << MAX(x - t, 0) << endl;
    return 0;
}

Measured memory_bytes: 3504
N, A = map(int, input().split())
X = list(map(int, input().split()))

dp = [[[0 for _ in range(3000)] for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1

for i in range(N):
    for j in range(N):
        for t in range(2501):
            dp[i + 1][j][t] += dp[i][j][t]
            dp[i + 1][j + 1][t + X[i]] += dp[i][j][t]

ans = 0

for i in range(1, N + 1):
    ans += dp[N][i][i * A]

print(ans)


Measured memory_bytes: 111196
#include<bits/stdc++.h>
using namespace std;
int dp[4005][4005];
int n,A,B,a[50],b[50],c[50],ans=1e9;
int main()
{
	for(int i=0;i<4005;i++)for(int j=0;j<4005;j++)dp[i][j]=1e9;
	cin>>n>>A>>B;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	dp[0][0]=0;
	for(int i=0;i<n;i++)
		for(int x=4000;x>=a[i];x--)
			for(int y=4000;y>=b[i];y--)
				dp[x][y]=min(dp[x][y],dp[x-a[i]][y-b[i]]+c[i]);
	int x=A,y=B;
	while(x<=4000&&y<=4000)
	{
		ans=min(ans,dp[x][y]);
		x+=A;
		y+=B;
	}
	if(ans==1e9)cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 63484
#include<bits/stdc++.h>
using namespace  std ;
typedef long long  ll;
typedef pair<ll, ll> Pll;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define rad(X) cout << (X) << endl
#define ASH(X) cout << (X) << " "
#define debug(x) cout << #x << " " << x << endl;
#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)
#define cir(I,B,A) for(ll I = (A); I >=(B); I--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define SORT(c) (sort(c.begin(),c.end()))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};
vector<ll>a,b,c;
map<ll,ll>m1,m2,m3;

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

void Execute()
{
      string s;
      cin >> s;

      s=="ABC"?rad("ARC"):rad("ABC");

}

int32_t main()
{
    //freopen("atomm.txt", "r", stdin);
    FAST();
    //CASES

        Execute();

}


Measured memory_bytes: 3616
n,k = map(int,input().split())
i = 0
while(i==0):
  #print(n,k)
  if n>k:
    a = n%k
    if a<n:
      n = a
  else:
    a = abs(k-n)
    if a<n:
      n = a
    else:
      print(n)
      exit()

Measured memory_bytes: 3060
#include<iostream>    
#include<cstdio>  
#include<stdio.h>  
#include<cstring>    
#include<cstdio>    
#include<climits>    
#include<cmath>   
#include<vector>  
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map>  
using namespace std;

string str, str1;
int main()
{
	int n, m, tot, i, tot1;
	cin >> str;
	cin >> str1;
	n = str.length();
	m = str1.length();
	tot = 0;
	tot1 = 0;
	for (i = 0; i <m + n; i++)
	{
		if (i % 2 == 0)
		{
			cout << str[tot];
			tot++;
		}
		else
		{
			cout << str1[tot1];
			tot1++;
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int MAXN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    int arr[n + 1];
    for(int i = 1; i <= n; ++i){
        cin >> arr[i];
    }
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        if(arr[arr[i]] == i){
            ans++;
            arr[arr[i]] = 0;
        }
    }
    cout << ans ;
}

Measured memory_bytes: 4364
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll dist[210][210];

int main() {
  ll N,M,R; cin >> N >> M >> R;
  ll r[R];
  FOR(i,0,R-1) cin >> r[i], --r[i];
  ll A[M],B[M],C[M];

  
  FOR(i,0,209){
    FOR(j,0,209){
      if(i!=j) dist[i][j] = 1e9;
    }
  }
  FOR(i,0,M-1) {
    cin >> A[i], cin >> B[i], cin >> C[i];
    --A[i], --B[i];
    dist[A[i]][B[i]] = C[i];
    dist[B[i]][A[i]] = C[i];
  }

  FOR(k,0,N-1){
    FOR(i,0,N-1){
      FOR(j,0,N-1){
        chmin(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }

  ll ans = 1e9;
  sort(r,r+R);
  do{
    ll disttry = 0;
    // FOR(i,0,R-1) cout << r[i];
    // cout << endl;
    FOR(i,0,R-2){
      disttry += dist[r[i]][r[i+1]];
    }
    chmin(ans,disttry);
  } while (next_permutation(r,r+R));

  cout << ans << endl;

}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a+b==c||a+c==b||c+b==a){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    rep(i,n) cin >> a[i];
    double sum = 0;
    rep(i,n){
        sum += 1/a[i];
    }
    double ans = 1/sum;
    cout << fixed  << setprecision(5) << ans << endl;
}

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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int N;
	cin >> N;
	bool arr[N] = {false};
	arr[0] = true;
	int max_n = sqrt(N);
	int ans = 1;
	REP(i, 2, max_n+1){
		int tmp = i;
		while(tmp <= N){
			arr[tmp-1] = true;
			tmp *= i;
		}
	}
	REP(i, 0, N) if(arr[i] == true) ans= i+1;
	cout << ans;
		

}


Measured memory_bytes: 256
def minimumPress(x, y):
    foo = 0
    if abs(x) < abs(y):
        if x < 0:
            foo += 1
        foo += abs(y) - abs(x)
        x = abs(y)
    elif abs(x) > abs(y):
        if x > 0:
            foo += 1
        foo += abs(x) - abs(y)
        x = -abs(y)
    if x!=y:
        foo += 1
    return foo

def main():
    x, y = [int(i) for i in raw_input().strip().split()]
    print minimumPress(x, y)

if __name__ == '__main__':
    main()

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

using namespace std;

struct Union_find{
	vector<int> par;
	vector<int> rank;
	vector<int> diff_weight;
	Union_find(int p){
		par = vector<int>(p + 1);
		rank = vector<int>(p + 1);
		diff_weight = vector<int>(p + 1);
		for(int i = 1; i <= p; i++){
			par[i] = i;
		}
	}
	int find(int x){
		if(par[x] == x)
			return x;
		else{
			int pa = find(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = pa;
		}
	}
	bool unite(int x, int y, int w){
		w = w + weight(x) - weight(y);
		x = find(x);
		y = find(y);
		if(x == y) return false;
		if(rank[x] < rank[y]){
			par[x] = y;
			diff_weight[x] = - 1 * w;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
			diff_weight[y] = w;
		}
		return true;
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
	int weight(int x){
		find(x);
		return diff_weight[x];
	}
	int diff(int x, int y){
		return weight(y) - weight(x);
	}
};

int main(){
	int n, m, ans = 0;
	cin >> n >> m;
	if(m == 0){
		cout << "Yes" << endl;
		return 0;
	}
	Union_find uf(n);
	for(int i = 0; i < m; i++){
		int x, y, c;
		cin >> x >> y >> c;
		if(uf.unite(x, y, c)){
			continue;
		}else{
			if(uf.diff(x, y) != c){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

class union_find {
private:
	vector<int> uf;

public:
	union_find(int n = 0):uf(n, -1) {}

	int find(int x) {
		return uf[x] < 0 ? x : uf[x] = find(uf[x]);
	}

	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y)
			return false;

		if(uf[x] > uf[y])
			swap(x, y);

		else if(uf[x] == uf[y])
			--uf[x];

		uf[y] = x;
		return true;
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

struct edge {
	int u, v, cost;
	edge(int u, int v, int c):u(u), v(v), cost(c){}
	bool operator<(const edge& e) const {
		return cost < e.cost;
	}
};

int n, m;
vector<pair<int, int> > hidx;
vector<edge> es;
bool alive[200];
union_find uf;

bool check() {
	union_find uf2(n);
	for(int i = 0; i < m; ++i)
		if(alive[es[i].u] && alive[es[i].v])
			uf2.unite(es[i].u, es[i].v);

	for(int i = 0; i < n; ++i)
		for(int j = i + 1; j < n; ++j)
			if(alive[i] && alive[j] && !uf2.same(i, j))
				return false;

	return true;
}

long long kruskal() {
	long long  res = 0;

	for(int i = 0; i < m; ++i) {
		const int u = es[i].u, v = es[i].v;
		if(alive[u] && alive[v] && uf.unite(u, v))
			res += es[i].cost;
	}

	return res;
}

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

	while(cin >> n >> m, n) {
		hidx.clear();
		hidx.reserve(n);
		for(int i = 0; i < n; ++i) {
			int h;
			cin >> h;
			hidx.push_back(make_pair(h, i));
		}

		es.clear();
		es.reserve(m);
		for(int i = 0; i < m; ++i) {
			int a, b, c;
			cin >> a >> b >> c;
			es.push_back(edge(a - 1, b - 1, c));
		}

		sort(hidx.rbegin(), hidx.rend());
		fill(alive, alive + 200, true);
		if(!check()) {
			cout << "0" << endl;
			continue;
		}

		int end = 0;
		for(int i = n - 1; i >= 0; --i) {
			alive[hidx[i].second] = false;
			while(i > 0 && hidx[i].first == hidx[i - 1].first) {
				alive[hidx[--i].second] = false;
			}

			if(!check()) {
				end = i;
				break;
			}
		}

		sort(es.begin(), es.end());
		uf = union_find(n);
		memset(alive, false, sizeof(alive));
		long long ans = 0;
		for(int i = 0; i < n; ++i) {
			alive[hidx[i].second] = true;
			while(i < n - 1 && hidx[i].first == hidx[i + 1].first) {
				alive[hidx[++i].second] = true;
			}

			if(i >= end) {
				ans += kruskal();
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1272
import functools
import operator
n = int(input())
import math
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n /= m
        return c, n
    #
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff
  
a = factorization(n)
b = []
for i,j in a:
  b.append(i)
import itertools
ans = n
for i in range(1,len(b)+1):
  c = list(itertools.combinations(b,i))
  for j in c:
    kake = functools.reduce(operator.mul, j)
    if i %2 == 1:
      ans -= n//kake
    else:
      ans += n//kake
print(int(ans))


Measured memory_bytes: 6348
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <climits>
#include <bitset>

using namespace std;
using ll = long long int;
const ll MOD = 1e9 + 5;

ll mod_pow(ll k, ll p)
{
    if (k == 0)
    {
        return 1 % p;
    }
    if (k == 1)
    {
        return 2 % p;
    }

    if (k % 2 == 0)
    {
        ll tmp = mod_pow(k / 2, p);
        return tmp * tmp % p;
    }
    else
    {
        ll tmp = mod_pow((k - 1) / 2, p);
        tmp *= tmp;
        tmp %= p;
        tmp *= 2;
        tmp %= p;
        return tmp;
    }
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2) % MOD;
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, (k - 1) / 2);
        return tmp * tmp * 2;
    }
}

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

    ll ans = 0;
    for (ll  i = 1; i <= N; i++)
    {
        ll ni;
        cin >> ni;
        if (i % 2 == 1 && ni % 2 == 1) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...







int Main(){


int n =3;
ll arr[n];
for(int i=0 ; i  <n;i++)
cin>>arr[i];

sort(arr,arr+n);

int cnt  =0 ;
for(int i=0;i<=1;i++)
{
	
	if(arr[i]==arr[i+1])
	cnt++;
	
	
}

if(cnt==1)
cout<<"Yes\n";
else
cout<<"No\n";


return 0;

}






int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;


}


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

Measured memory_bytes: 1008
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

//HEADER FILES AND NAMESPACES
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp>   
using namespace std;
using namespace __gnu_pbds;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);  

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r+", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w+", stdout);
// #endif  
	
    int x;
    cin >> x;
    cout << (x^1) << '\n';
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    string S; cin >> S;
    int cnt[4] = {};
    for(char c : S){
        if(c == 'N') cnt[0]++;
        else if(c == 'S') cnt[1]++;
        else if(c == 'W') cnt[2]++;
        else if(c == 'E') cnt[3]++;
    }
    bool ok = true;
    if((cnt[0] == 0 and cnt[1] != 0) or(cnt[0] != 0 and cnt[1] == 0)) ok = false;
    if((cnt[2] == 0 and cnt[3] != 0) or(cnt[2] != 0 and cnt[3] == 0)) ok = false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;


}

Measured memory_bytes: 256
#abc159 b
s=input()
def kaibun(string):
    kj=True
    mid=len(string)//2
    for i in range(mid):
        if string[i]!=string[len(string)-1-i]:
            kj=False
            break
    return kj
x=(len(s)-1)//2
y=(len(s)+3)//2
if kaibun(s)==kaibun(s[:x])==kaibun(s[y-1:])==True:
     print("Yes")
else:
     print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> ans;
    int v = n - n % 2;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (i >= j || j == v)
            {
                continue;
            }
            ans.push_back(P(i, j));
        }
        v--;
    }
    cout << ans.size() << endl;
    for (auto a : ans)
    {
        cout << a.first << ' ' << a.second << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    int N, M ;
    cin >> N >> M;
    vector<vector<int>> jobs(M);
    for(int i = 0; i < N; ++i)
    {
        int A, B;
        cin >> A >> B;
        if(A > M)
        {
            continue;
        }
        jobs[A - 1].push_back(B);
    }

    unsigned long long result = 0;
    priority_queue<int> queue;    
    for(int i = 0; i < M; ++i)
    {
        const auto& jobsForDay = jobs[i];
        for(const auto rev : jobsForDay)
        {
            queue.push(rev);
        }
        if(!queue.empty())
        {
            auto maxRev = queue.top();
            result += maxRev;
            queue.pop();
        }
    }

    cout << result;
}


Measured memory_bytes: 5632
data class ModInt(private var v: Long) {
    companion object {
        private const val MOD = 1000000007L
    }
    init {
        if (v >= MOD) v %= MOD
    }
    operator fun plus(other: ModInt): ModInt {
        val x = v + other.v
        if (x >= MOD) {
            return ModInt(x - MOD)
        }
        return ModInt(x)
    }
    operator fun minus(other: ModInt): ModInt {
        val x = v + MOD - other.v
        if (x >= MOD) {
            return ModInt(x - MOD)
        }
        return ModInt(x)
    }
    operator fun times(other: ModInt): ModInt {
        return ModInt(v * other.v % MOD)
    }
    operator fun div(other: ModInt): ModInt {
        return ModInt(v * calc(other.v, MOD - 2) % MOD)
    }
    private fun calc(a: Long, b: Long): Long {
        if (b == 0L) return 1L
        if (b % 2L == 0L) {
            val d = calc(a, b / 2)
            return d * d % MOD
        }
        return a * calc(a, b - 1) % MOD
    }
    override fun toString(): String {
        return v.toString()
    }
}

const val MOD = 1000000007L

fun main(args: Array<String>) {
    val (X, Y) = listOfInt()
    var s = X + Y
    if (s % 3 != 0) {
        println(0)
        return;
    }
    s /= 3
    val x = X - s
    val y = Y - s
    if (x < 0 || y < 0) {
        println(0)
        return;
    }
    val ans = FermatCombination(x + y).combine(x + y, x).toString()
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)

class FermatCombination(size: Int) {
    var factrial = LongArray(size + 1)
    var inverse = LongArray(size + 1)
    init {
        factrial[0] = 1
        inverse[0] = 1
        for (i in 1 .. size) {
            factrial[i] = factrial[i - 1] * i % MOD
            inverse[i] = pow(factrial[i], MOD.toInt() - 2) % MOD
        }
    }
    fun combine(n: Int, k: Int): Long {
        if (n < k || n < 0 || k < 0) return 0
        return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD
    }
    fun pow(x: Long, n: Int): Long {
        var x = x
        var n = n
        var ans: Long = 1
        while (n > 0) {
            if (n and 1 == 1) {
                ans = ans * x % MOD
            }
            x = x * x % MOD
            n = n shr 1
        }
        return ans
    }
}


Measured memory_bytes: 50108
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
 
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define T int t = 0; cin >> t; while(t--)
#define pr(a) for(int i = 0; i < (int)a.size(); ++i)cout << a[i] << " ";cout << endl;
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e15;
const ll mx = 2e6;
const ll inf = 1e9;
const int sz = 26;
typedef long long ll;

void input(){
    IOS;
    ll n, k;
    cin >> n >> k;
    vector<ll>a(n);
    f(i, n)cin >> a[i];
    ll low = 0, high = 1e9;
    ll ans = 0;
    auto possible = [&](ll x){
        if(x == 0)return false;
        ll cnt = 0;
        f(i, n){
            cnt += (a[i] - 1) / x;
        }
        return cnt <= k;
    };
    while(low <= high){
        
        ll mid = (low + high) / 2LL ;
        //cout << high << " "<< low << endl;
        if(possible(mid)){
            ans = mid;
            high = mid - 1;
        }else low = mid + 1;
    }
    cout << ans << endl;
}

int main(){
    input();
    return 0;
} 
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/

Measured memory_bytes: 4776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    long long n,m;
    long long ans;
    cin >> n >> m;
    if((n!=2) && (m!=2)){
        m=m-2;
        n=n-2;
        if(m<=0){
            m=1;
        }
        if(n<=0){
            n=1;
        }
        ans = m*n;
    }else{
        ans = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long n, b, c = 0, d = 0, e = 110;
	cin >> n;
	for (int h = 1; h <= n; h++) {
		cin >> b;
		if(b % 2 == 1){
			c++;
			e = min(e, b);
		}
		d += b;
	}
	if (c % 2 == 1) {
		cout << d << endl;
	}
	else if (c == 0) {
		cout << '0' << endl;
	}
	else {
		cout << d - e << endl;
	}
	cin >> e;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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; }

ll MOD = 998244353;
vector<ll> fact,fact_inv,inv;
ll nCk(ll n, ll k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

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

    int n,m,k;
    cin >> n >> m >> k;
    fact.resize(n,1);
    fact_inv.resize(n,1);
    inv.resize(n,1);
    for(ll i = 2; i < n; i++) {
        fact[i] = fact[i-1] * i %MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
    vector<ll> m_exp(n);
    m_exp[0] = 1;
    for(int i = 1;i < n; i++) {
        m_exp[i] = (m_exp[i-1] * (m-1))%MOD;
    }
    
    ll ans = 0;
    for(ll i = 0; i <= k; i++) {
        ll anstmp = nCk(n-1, i);
        anstmp *= m;
        anstmp%=MOD;
        anstmp*=m_exp[n-i-1];
        anstmp%=MOD;
        ans+=anstmp;
        ans%=MOD;
    }
    cout << ans << endl;

}

Measured memory_bytes: 9424
v = input().split(" ")

a = int(v[0])
b = int(v[1])
c = int(v[2])

amari = []

tmp1 = 0
tmp2 = 0

for i in range(1, b + 1, 1):
    
    tmp1 += a
    
    amari.append(tmp1 % b)

if c in amari:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
N=int(input())
out=[]
if N==0:
    out.append(0)
else:
    while abs(N)>0:

        if N%2==1:
            out.append(-1)
        else:
            out.append(0)
        N=int(N//-2)
for i in range(len(out)-1):
    if out[i]==-1:
        out[i]=1
        out[i+1]+=1

if out[len(out)-1]==-1:
    out[len(out)-1]=1
    out.append(1)
out.reverse()
if len(out) is not 1:
    while out[0]==0:
        del out[0]


print("".join(map(str,out)))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	private void doIt() {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			double v = sc.nextDouble();
			double t = v / 9.8;
			double y = 4.9 * t * t;
			for(int n = 2; ;n++){
				int floor = n * 5 - 5;
				if(y <= floor){
					System.out.println(n);
					break;
				}
			}
		}

	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 12000
#include<stdio.h>
int cnt1, cnt2, cnt4;
int n;
int x;
int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &x);
		if(x % 4 == 0)
			cnt4 ++;
		else if(x % 2 == 0)
			cnt2 ++;
		else 
			cnt1 ++;
	}
	if(cnt4 >= cnt1)
		printf("Yes\n");
	else if(cnt2 == 0 && cnt4 + 1>= cnt1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {
	int n, m, x;
	int a[101];
	int count = 0;

	cin >> n >> m >> x;

	for (int i = 1; i <= m; i++) {
		cin >> a[i];
	}

	for (int i = 1; i <= m; i++) {
		if (a[i] < x) {
			count++;
		}
		else {
			break;
		}
	}

	cout << min(m - count, count) << endl;

	return 0;
}

Measured memory_bytes: 256
package main

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

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	N := readInt64()
	ans := int64(math.MaxInt64)
	for i := int64(1); i*i <= N; i++ {
		if N%i == 0 {
			j := N / i
			v := (j - 1) + (i - 1)
			ans = min64(ans, v)
		}
	}
	println(ans)
}

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


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

int cal(int x, int y, int z) {
  return (x * x + y * y + z * z + x * y + y * z + z * x);
}

int main() {
  int n;
  cin >> n;
  vector<int> ans(n + 1, 0);

  for (int i = 1; i <= n; i++) {
    for (int x = 1; cal(x, x, x) <= n; x++) {
      for (int y = x; cal(x, y, y) <= n; y++) {
        for (int z = y; cal(x, y, z) <= n; z++) {
          if(cal(x, y, z) == i) {
            if (x == y && y == z) ans[i]++;
            else if ((x == y && y != z) || (y == z && x != z) || (x == z && x != y)) ans[i] += 3;
            else ans[i] += 6;
          }
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  
  switch(n%10){
    case 3:
      cout << "bon" << endl;
      break;
      
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
      
    default:
      cout << "hon" << endl;
      break;
  }
}

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

int main()
{
	int H, W;
	cin >> H >> W;
	string a[101];
	for (int i = 1; i <= H; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= H; i++) {
		cout << a[i] << endl;
		cout << a[i] << endl; 
	}
		return 0;
	}

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

int main()
{
    int a, b;
    int taro[100], hanako[100], tsum, hsum;
    while (cin >> a >> b) {
        if (a == 0 && b == 0)break;
        tsum = hsum = 0;
        for (int i = 0; i < a; i++) {
            cin >> taro[i];
            tsum += taro[i];
        }
        for (int i = 0; i < b; i++) {
            cin >> hanako[i];
            hsum += hanako[i];
        }

        int min = 201, x, y;
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                int newt = tsum - taro[i] + hanako[j], newh = hsum - hanako[j] + taro[i];
                if (newt == newh && (taro[i] + hanako[j]) < min) {
                    min = taro[i] + hanako[j];
                    x = taro[i];
                    y = hanako[j];
                }
            }
        }

        if (min == 201)cout << -1 << endl;
        else cout << x << " " << y << endl;
    }
}

Measured memory_bytes: 3004
n=int(input())
p=list(map(int,input().split()))
c=0
def swap(i):
    global c
    t=p[i+1]
    p[i+1]=p[i]
    p[i]=t
    c+=1
for i in range(n-1):
    if p[i]==i+1:swap(i)
print(c+(p[n-1]==n))


Measured memory_bytes: 14008