akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define fors(i,a,b) for(int i=(a);i<=(b);++i)
#define ford(i,a,b) for(int i=(a);i>=(b);--i)
#define min(x,y) ((x) < (y) ? (x) : (y))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define swap(x,y) ((x)^=(y),(y)^=(x),(x)^=(y))
const int maxn=1e6+7;
typedef long long ll;
const int inf=1<<25;

inline char getch(){
    static char buf[inf],*p1=buf,*p2=buf;
    return p1==p2 && (p2=(p1=buf)+fread(buf,1,inf,stdin),p1==p2) ? EOF : *p1++;
}
int read(){
    int s=0,f=1;
    char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1; c=getchar();}
    while(c>='0' && c<='9') {s=s*10+c-48;c=getchar();}
    return s*f;
}
void write(int x){
    if(x<0) {putchar('-');x=-x;}
    if(x>9) write(x/10);
    putchar(x%10+48);
}

int a[maxn];
int n;
struct node
{
    int id,w;
}cnt[maxn+7],cnt2[maxn+7];
int cmp(node a,node b){
    return a.w>b.w;
}
int ans,tot,tot2;
int main(int argc, char const *argv[])
{
//    freopen("sss.in","r",stdin);
    n=read();
    fors(i,1,n) a[i]=read();
    for(int i=1;i<=n;i+=2)
        cnt[a[i]].w+=1,cnt[a[i]].id=a[i],tot+=1;

    for(int i=2;i<=n;i+=2)
        cnt2[a[i]].w+=1,cnt2[a[i]].id=a[i],tot2+=1;

    sort(cnt2+1,cnt2+maxn,cmp);
    sort(cnt+1,cnt+maxn,cmp);

    int ans=0;
    if(cnt[1].id == cnt2[1].id){
        ans+=((tot-cnt[2].w) < (tot2-cnt2[2].w) ? (tot-cnt[2].w+tot2-cnt2[1].w) : (tot2-cnt2[2].w+tot-cnt[1].w));
    }
    else ans+=n-cnt[1].w-cnt2[1].w;
    write(ans),putchar(10);
    
    return 0;
}


Measured memory_bytes: 16640
import java.util.Scanner;
public class Main {

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

		boolean f=false;
		for(int i=1;i<10;i++) {
			for(int j=1;j<10;j++) {
				if(i*j==a) {
					f=true;
					break;
				}
			}
		}
		if(f)
			System.out.println("Yes");
		else
			System.out.println("No");



	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,n);
  int l[1123]={};
  int r[1123]={};
  int i;
  int sum=0;
  rep(i,n)
    {
      cin>>l[i]>>r[i];
      sum+=r[i]-l[i]+1;
    }
  putv(sum);
  
  return 0;
}


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

#define int long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 2002;


void solve() {
    int a , b , c , d;
    cin >> a >> b >> c >> d;
    int flag = 1;
    while(a > 0 and c > 0) {
        if(flag) c -= b;
        else a -= d;
        flag ^= 1;
    }
    if(a <= 0) cout << "No";
    else cout << "Yes";
}

/*
 
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    while(testcase --) {
        solve();
        cout << '\n';
    }
    
    return 0;
}
 



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

int main() {
  string S,T;
  cin >> S >> T;
  
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) != T.at(i)) {
      cout << "No" << endl;
      break;
    }
    else if (S.size() -1 == i) {
      cout << "Yes" << endl;
    }
  }
}



Measured memory_bytes: 3592
from subprocess import call
call (('pypy3', '-c', """
from collections import deque

H,W = map(int,input().split())
c =[]
c.append(['×' for _ in range(W+2)])
ans = []
ans.append([0 for _ in range(W+2)])
q = deque()
for i in range(H):
    tmp = list('×'+input()+'×')
    ans_tmp = []
    for j in range(W+2):
        if tmp[j] == '#':
            ans_tmp.append(0)
            q.append([j,i+1])
        elif tmp[j] == '×':
            ans_tmp.append(0)
        else:
            ans_tmp.append(10**4)
    c.append(tmp)
    ans.append(ans_tmp)

c.append(['×' for _ in range(W+2)])
ans.append([0 for _ in range(W+2)])


def bfs(q):
    while q:
        x,y = q.popleft()
        if c[y][x-1] == '.':
            q.append([x-1,y])
            ans[y][x-1] = ans[y][x] + 1
            c[y][x-1] = '#'
        if c[y][x+1] == '.':
            q.append([x+1,y])
            ans[y][x+1] = ans[y][x] + 1
            c[y][x+1] = '#'
        if c[y-1][x] == '.':
            q.append([x,y-1])
            ans[y-1][x] = ans[y][x] + 1
            c[y-1][x] = '#'
        if c[y+1][x] == '.':
            q.append([x,y+1])
            ans[y+1][x] = ans[y][x] + 1
            c[y+1][x] = '#'

bfs(q)
max_ans = 0
for i in range(H+2):
    #print(ans[i])
    max_ans = max(max_ans,max(ans[i]))

print(max_ans)
"""))

Measured memory_bytes: 189256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        k: i64,
        x: i64,
    }
    if 500*k >= x {
        println!("Yes");
    }else{
        println!("No");
    }
}

Measured memory_bytes: 4352
def main():
    n = int(input())
    a = list(map(int,input().split()))
    # jibun igai no xor = ai
    tot = 0
    for i in range(n):
        tot ^= a[i]
    res = [0]*n
    for i in range(n):
        res[i] = tot ^ a[i]
    print(*res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 98652
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

ll f(ll a, ll b) { // a < b
  if (b < a) {
    return f(b, a);
  }

  if (b % a == 0) {
    return b + a * (b / a - 1);
  } else {
    return 2 * a * (b / a) + f(b % a, a);
  }
}

void solve(long long N, long long X) { print(N + f(X, N - X)); }

int main() {
  long long N;
  scanf("%lld", &N);
  long long X;
  scanf("%lld", &X);
  solve(N, X);
  return 0;
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef pair<int ,int > pii;
typedef long long LL;
const long long oo = 1e9 + 7;

int a,b,c;

int main() {
 //   freopen("test.txt","r",stdin);
    cin >> a >> b >> c;
    int sum = 0;
    for (int i =1 ; i<= b ; i++) {
        for (int j = 1 ; j <= b ; j++) {
            if ( i != j ) {
                sum = a* i + a*j;
                if ( (sum - c) % b == 0 ) {
                    cout << "YES";
                    return 0;
                }
            }
        }
    }
    cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int k;
string s;

int main(){
	cin>>k>>s;
	int n=s.size();
	if(k<n){
		s=s.substr(0,k);
		s+="...";
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3624
from itertools import accumulate

import sys
sdin = sys.stdin.readline

n,k = map(int, sdin().split())
x = list(map(int, sdin().split()))
 
# x1を0とする累積和をとる
x_0 = [xi - x[0] for xi in x]
x0_cum = list(accumulate(x_0))

# K個のろうそくを含む
ans = float('inf')
for i in range(n-k+1):
    ans_cand = x[i+k-1] - x[i] + min(abs(x[i]), abs(x[i+k-1]))

    ans = min(ans_cand, ans)
    
    
print(ans)

Measured memory_bytes: 16096
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
  long long N;
  cin>>N;
  if(N%2==1) cout<<0<<endl;
  else{
    N=N/2;
    long long answer=0;
    long long k=5;
    while(k<=N){
      answer+=N/k;
      k=k*5;
    }
    cout<<answer<<endl;
  }
  
return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int dy[2] = {1,0};
int dx[2] = {0,1};
int h,w;
vector<string>s(10);

int main(){
    int n;cin>>n;
    vector<ll>a(n);
    vector<ll>sum(n+1);
    sum[0] = 0;
    rep(i,n){
        cin>>a[i];
        sum[i+1] = a[i]+sum[i];
    }
    map<ll,ll>mp;
    REP(i,0,n){
        mp[sum[i]]++;
    }
    ll res = 0;
    for(auto x : mp){
        res += x.second*(x.second-1)/2;
    }
    cout<<res<<endl;
}



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

using namespace std;

typedef long long ll;
#define int ll


const int N = 2e5 + 5;

int t;
int n;
long long a[N], b[N];
long long powers[N];


const long long mod = 1e9 + 7; 

map < pair < int , int >, long long > cnt;

map < pair < int , int > , bool > ok;


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


void solve() {

	cin >> n;

	powers[0] = 1;
	for(int i = 1 ; i < N ; i++){
		powers[i] = powers[i - 1] * 2;
		powers[i] %= mod;
	}
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
		cin >> b[i];
	}
	int bad= 0;

	for(int i = 0 ; i < n ; i++){
		if(a[i] < 0 and b[i] < 0){
			a[i] = -a[i];
			b[i] = -b[i];
		}
		if (b[i] < 0){
			a[i] = -a[i];
			b[i] = -b[i];
		}
		if(a[i] == 0 and b[i] == 0){ 
				bad++;
				continue;
		}
		if(a[i] == 0) b[i] = 1;
		if(b[i] == 0) a[i] = 1;

		if(a[i] == 0 || b[i] == 0){
			
			if(a[i] == 0){
				cnt[{1 , 0}]++;
			}
			else{
				cnt[{0, 1}]++;
			}
		} else{
			long long g = gcd(abs(a[i]), abs(b[i]));

			// cout << a[i] << " " << b[i] << " shit"  << endl;
			a[i] /= g;
			b[i] /= g;
			
				cnt[{a[i], b[i]}]++;
			
		}

	}
	long long ans = 1;
	for (auto p : cnt){
		// cout << p.first.first << " " << p.first.second << " " << p.second << " " << endl;
		if(ok[p.first]) continue;
		long long mult = (powers[p.second] + powers[cnt[{p.first.second, -p.first.first}]] - 1) % mod;
		ans = ans * (mult);
		ans %= mod;

		ok[p.first] = true;
		ok[{p.first.second, -p.first.first}] = true;


	}
	ans = ans + mod - 1;
	ans %= mod;

	if(bad){
		ans = ans + bad;
		ans %= mod;
	}

	cout << ans << endl;

}

int32_t main(){
	t = 1;

	while(t--){
		solve();
	}
}

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

const int MAX_N = 310, MAX_Q = 1e5+2;
int H, W, D;
int A[MAX_N][MAX_N];
int Q;
int L[MAX_Q], R[MAX_Q];

ll dist[MAX_N*MAX_N];

void solve()
{
	map<int, pair<int,int>> loc;
	for(int i=1;i<=H;++i)for(int j=1;j<=W;++j){
		loc[A[i][j]] = make_pair(i, j);
	}
	const int LAST = H*W;
	for(int i=D;i<=LAST;++i){
		 dist[i] = dist[i-D] + (abs(loc[i].first-loc[i-D].first)+abs(loc[i].second-loc[i-D].second));
	}
	for(int i=0;i<Q;++i){
		cout << dist[R[i]]-dist[L[i]] << '\n';
	}
}

int main()
{
	cin >> H >> W >> D;
	for(int i=1;i<=H;++i)for(int j=1;j<=W;++j){
		cin >> A[i][j];
	}
	cin >> Q;
	for(int i=0;i<Q;++i) cin >> L[i] >> R[i];
	solve();
	return 0;
}

Measured memory_bytes: 11104
import collections
s = list(input())
ans = "Yes"
c = collections.Counter(s)

if c["N"] * c["S"] == 0:
    if c["N"] != c["S"]:
        ans = "No"
if c["W"] * c["E"] == 0:
    if c["W"] != c["E"]:
        ans = "No"

print(ans)

Measured memory_bytes: 9336
program main
  implicit none
  integer(8) :: n, k, i, r, s, p, res
  character(100000) :: t, used
  character(1) :: using
  read (*, *) n, k
  read (*, *) r, s, p
  read (*, *) t
  res = 0
  do i = 1, n
    if (i <= k) then
      using = t(i:i)
    else
      if (t(i:i) == used(i - k:i - k)) then
        using = "*"
      else
        using = t(i:i)
      end if
    end if
    if (using == "r") then
      res = res + p
    else if (using == "p") then
      res = res + s
    else if (using == "s") then
      res = res + r
    end if
    used(i:i) = using
  end do
  write (*, "(i0)") res
end program main


Measured memory_bytes: 700
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
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 nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

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

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

    ll nums[100100] = {0};

    ll ma = 0;

    for(int i = 0; i < n; i++){
        nums[d[i]]++;
        ma = max(ma, d[i]);
    }

    ll ans = 1;

    if(d[0] != 0 || nums[0] != 1){
        cout << 0 << endl;
        return 0;
    }


    for(int i = 0; i < ma; i++){
        // cout << nums[i] << endl;
        
    
        ll tmp = 1;
        for(int j = 0; j < nums[i + 1]; j++){
            tmp *= nums[i];
            tmp %= 998244353;
        }
        
        ans *= tmp;
        ans %= 998244353;
    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  
  string S,T;
  cin >> S >> T;
  
  bool flag = false;
  int i = 0;
  while(i<S.size()){
  S=S.at(S.size()-1) + S;
  S.pop_back();
  if(S==T){
    flag = true;
    break;
  }
    i++; 
  }
  if(flag == true) cout << "Yes" << endl;

  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
#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>
#include<bitset>
#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=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,A[1001];
	scan(N);
	int flag=1;
	rep(i,N){
		scan(A[i]);
		if(A[i]%2==0){
			if(A[i]%3!=0&&A[i]%5!=0){
				flag=0;
			}
		}
	}
	if(flag){
		prin("APPROVED");
	}
	else prin("DENIED");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		// 入力値の取得
		long A = sc.nextLong();
		double B = sc.nextDouble();
		
		if (B == 0) {
			System.out.println(0);
			sc.close();
			return;
		}
		
		long C = Math.round(B * 100);
		long D = A * C;

		// 結果の出力
		System.out.println(Math.floorDiv(D, 100));

		sc.close();
	}
}


Measured memory_bytes: 28932
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,n,k=0,x;
  cin>>n;
  for (i=1;i<=n;i++)
  {
  	cin>>x;
    if (x!=i)
      k++;
  }
  if (k>2)
    cout<<"NO";
  else
    cout<<"YES";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>

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

std::vector<std::vector<int>> A;
std::vector<bool> hasVisited;


int main(void){
    int n, m; scanf("%d%d", &n, &m);
    A.resize(n+m, std::vector<int>(0));
    REP(i, n){
        int k; scanf("%d", &k);
        REP(j, k){
            int l; scanf("%d", &l); l += n - 1;
            A[i].push_back(l);
            A[l].push_back(i);
        }
    }
    hasVisited.resize(n+m, false);
    std::queue<int> Q;
    Q.push(0); hasVisited[0] = true;
    while(not Q.empty()){
        int v = Q.front(); Q.pop();
        for(int nv : A[v]) if(not hasVisited[nv]){
            Q.push(nv); hasVisited[nv] = true;
        }
    }
    bool judge = true;
    REP(i, n) if(not hasVisited[i]){ judge = false; break; }

    puts(judge ? "YES" : "NO");

    return 0;
}

Measured memory_bytes: 8824
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<Pair> A;
  // int64_t xmin = kInf, xmax = -kInf, ymin = kInf, ymax = -kInf;
  vector<int64_t> L(4, -kInf);
  vector<int64_t> temp(4);
  for (int64_t i = 0; i < N; ++i) {
    int64_t x, y;
    cin >> x >> y;
    temp[0] = x + y;
    temp[1] = x - y;
    temp[2] = -x + y;
    temp[3] = -x - y;
    bool match = false;
    for (int64_t i = 0; i < 4; ++i) {
      if (temp[i] > L[i]) {
        L[i] = temp[i];
        match = true;
      }
    }
    if (match) {
      A.emplace_back(x, y);
    }
  }
  int64_t result = 0;
  const int64_t M = static_cast<int64_t>(A.size());
  for (int64_t i = 0; i < M; ++i) {
    for (int64_t j = i + 1; j < M; ++j) {
      // cerr << B[i].first << " " << B[j].first << endl;
      result = max(result, abs(A[i].first - A[j].first) +
                               abs(A[i].second - A[j].second));
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(){
	int w,n,a,b,tmp,i,j;
	scanf("%d", &w);
	int answer[w];
	for(i=0;i<w;++i) answer[i]=i+1;
	scanf("%d", &n);
	for(i=0;i<n;++i){
		scanf("%d,%d",&a,&b);
		tmp=answer[a-1];
		answer[a-1]=answer[b-1];
		answer[b-1]=tmp;
	}
	for(i=0;i<w;++i) printf("%d\n", answer[i]);
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int S = 0;
    int temp = N;
    while (temp > 0) {
        S += temp % 10;
        temp /= 10;
    }
    if (N % S == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main()
{
	int a, b;

	cin >> a >> b;

	int i = 0;

	if (a == 0 || a == 1) {
		if (b >= 2) {
			i = (b * (b - 1))/2;
		}
		else if (b == 1) {
			i = 0;
		}
	}

	else if (b == 0 || b == 1) {
		if (a >= 2) {
			i = (a * (a - 1))/2;
		}
		else if (a == 1) {
			i = 0;
		}
	}

	else {
		i = (a * (a - 1) + b * (b - 1))/2;
	}

	cout << i;
	return 0;
}

Measured memory_bytes: 3156
using System;
using System.Linq;

class Program
{
    static int X = 10;
    static int XN = 1<<X; // = 512
    static int LMAX = 100000;
    static int[,] dp = new int[XN, LMAX+1];
    
    static int[,] VW;

    static int Dfs(int i, int L)
    {
        if(L<0 ) return -100000000;
        if(i<XN) return dp[i,L];

        var par = i/2;
        var v = VW[i,0];
        var w = VW[i,1];
        
        return Math.Max(Dfs(par, L), Dfs(par, L-w) + v);
    }
    
    static void Main()
    {     
        var N = int.Parse(Console.ReadLine());
        VW = new int[N+1,2];
        for(int i=1; i<=N; ++i) {
            var vw = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var v = VW[i,0] = vw[0];
            var w = VW[i,1] = vw[1];

            if(i<XN) {
                for(int wi=0; wi<=LMAX; ++wi) {
                    dp[i,wi] = dp[i/2,wi];
                    if(wi-w>=0) dp[i,wi] = Math.Max(dp[i,wi], dp[i/2, wi-w]+v);
                }
            }
        }

        var Q = int.Parse(Console.ReadLine());
        for(int iq=0; iq<Q; ++iq) {
            var vL = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int v = vL[0], L = vL[1];

            Console.WriteLine(Dfs(v, L));
        }
    }
}

Measured memory_bytes: 444532
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/2/ALDS1_2_D


def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v


def shellSort(A, n):
    global cnt
    cnt = 0
    # sort period
    G = []
    h = 1
    while h <= len(A):
        G.append(h)
        h = h * 3 + 1
    G.reverse()

    m = len(G)
    for i in range(m):
        insertionSort(A, n, G[i])

    # output
    print(m)
    print(*G)
    print(cnt)
    print(*A, sep='\n')


def solve():
    m = int(input())
    A = [int(input()) for _ in range(m)]
    shellSort(A, m)


if __name__ == '__main__':
    solve()



Measured memory_bytes: 53300
#  --*-coding:utf-8-*--

import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

Q = []
x = 0

for a in A:
    idx = bisect.bisect_right(Q, -a)

    if idx >= len(Q):
        x += 1
        Q.append(-a)
    else:
        Q[idx] = -a

print(x)
    
        


Measured memory_bytes: 11032
def pushpush(N: int, A: list)->list:
    b = []
    for i, a in enumerate(reversed(A)):
        if i % 2 == 0:
            b.append(a)
    for i, a in enumerate(A):
        if i % 2 == N % 2:
            b.append(a)
    return b


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = pushpush(N, A)
    print(' '.join(map(str, ans)))


Measured memory_bytes: 29604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int maxN = int(1e2);
ll ans[int(1e7)] ={};

void solve(long long N){
    for(int x=1;x<=maxN;x++)for(int y=1;y<=maxN;y++)for(int z =1;z<=maxN;z++){
        ans[x*x + y*y + z*z + x*y+y*z +z*x]++;
    }
    for(int i=1;i<=N;i++){
        cout << ans[i] << "\n";
    }

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 4092
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>

using namespace std;

int main() {
  string s;
  int count = 0;
	
  cin >> s;

  int i = (int)'a';
  for (int i = (int)'a'; i <= (int)'z'; i++) {
    count = 0;
    for (int j = 0; j < s.size(); j++) {
      if (i == s[j]) {
        break;
      }
      else {
        count++;
      }
    }
    if (count == s.size()) {
      char ans = (char)i;
      cout << ans << endl;
      return 0;
    }
  }
  cout << "None" << endl;
	return 0;
}


Measured memory_bytes: 512
# coding: utf-8


def main():
    h, w = map(int, input().split())
    a = []

    # 「すべて白」以外の行を登録
    for _ in range(h):
        src = str(input())
        if len(src.replace('.', '')) > 0:
            a.append(src)

    # col行目がすべて白でないインデックスを取得
    blackpos = []
    for col in range(w):
        white = 0
        for row in range(len(a)):
            if a[row][col] == '.':
                white += 1
        if white != len(a):
            blackpos.append(col)

    # すべて白でないindexのもののみprint
    for row in range(len(a)):
        for col in blackpos:
            print(a[row][col], end='')
        print()


if __name__ == '__main__':
    main()


Measured memory_bytes: 4468
N, X, Y = map(int, input().split())
d = {k: 0 for k in range(1, N)}
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        m = min(abs(j - i),
                abs(X - i) + 1 + abs(j - Y),
                abs(Y - i) + 1 + abs(j - X),)
        d[m] += 1
for k in range(1, N):
    print(d[k])


Measured memory_bytes: 3572
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int a,p;
    cin>>a>>p;
    cout<<(a*3+p)/2<<endl;
    return 0;
}



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

#define DEBUG

#ifdef DEBUG
#define dump(x) cout << "[*] " #x ": " << x << endl
#define debug(x) x
#else
#define dump(x)
#define debug(x)
#endif

#define int long long
typedef long long ll;
//constexpr int INF = 1e9;
//constexpr int MOD = 1000000007;

decltype(1) main()
{
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    n %= k;
    cout << min(n, k - n) << endl;
    return 0;
}


Measured memory_bytes: 256
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    a, b, c = map(int, input().split())

    print('YES') if b - a == c - b else print('NO')

if __name__ == '__main__':
    main()

Measured memory_bytes: 10408
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;
  const char* s = S.c_str();

  ll longest = 0;
  ll current = 0;
  REP(i, 0, S.size()) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      current++;
    } else {
      if (longest < current) {
        longest = current;
      }
      current = 0;
    }
  }
  if (longest < current) {
    longest = current;
  }
  cout << longest << endl;

  return 0;
}


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

int main(){
  string r,a;
  while(1){
    cin >> r >> a;
    if(r == "0" && a == "0") break;
    int h=0,b=0;
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
	if(r[i] == a[j]){
	  if(i==j) h++;
	  else b++;
	  break;
	}
      }
    }
    cout << h << " " << b << endl;
  }
}

Measured memory_bytes: 1180
#include <stdio.h>
int solve(int,int);

int n,a[2000];

int main()
{
  int q,mi[2000],i,j,m;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&mi[i]);
  }
  
  for(i=0;i<q;i++){
    if(solve(0,mi[i])==1){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  return 0;
}

int solve(int i,int m){
  int x;
  if(m==0)return 1;
  else if(i>=n)return 0;
  x=solve(i+1,m)||solve(i+1,m-a[i]);
  return x;
}



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

int main()
{
    int n = 0;
    int bottom = 0;

    scanf("%d", &n);

    bottom  = n % 10;

    if (bottom == 3)
    {
        printf("bon");
    } else if (((bottom == 0)||(bottom == 1))||((bottom == 6)||(bottom == 8))){
        printf("pon");
    } else {
        printf("hon");
    }  

    return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <cstdlib>
#include <map>
#include <iostream>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

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

const int N = 2e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int BASE = 31337;

string S;
int k, n;

int main(){
	cin >> n >> k >> S;
	for(int i = 0;i < k;i++){
		string U = S;
		reverse(S.begin(), S.end());
		U += S;
		reverse(S.begin(), S.end());
		for(int i = 1;i <= n;i++){
			if(U.substr(i, n) < S)
				S = U.substr(i, n);
		}
		if(i != k - 1)
			reverse(S.begin(), S.end());
		bool gotov = 1;
		for(char c : S)
			gotov &= (c == S[0]);
		if(gotov)
			break;
	}
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, g, b;
    cin >> r >> g >> b;
    int num = 100*r+10*g+b;
    if(num%4==0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   int n;
           cin>>n;
           vin t(n);
           ll sum=0;
           rep(i,0,n){
            cin>>t[i];
             sum+=t[i];
           }
           int m;
           cin>>m;
           rep(i,0,m){
            int p,x;
             cin>>p>>x;
             cout<<sum+x-t[p-1]<<endl;
           }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,max=0,x=0;
	char s;
	cin>>n;
	lp2(i,n){
		cin>>s;
		if(s=='I'){
			x+=1;
			if(max<=x)max=x;
		}
		else {
			x-=1;
			if(max<=x)max=x;
		}
	}
	cout<<max<<endl;
	return 0;
}

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

int main(){
  int N,L;
  int i,j;
  scanf("%d%d",&N,&L);
  char S[N][L+1];
  for(i=0;i<N;i++){
  	scanf("%s",S[i]);
  }
  
  char tmp[L+1];
  
  for(i=0;i<N;i++){
  	for(j=N-1;j>i;j--){
        //strcmpの返り値は正負、０。しかし環境によって値は異なる
    	if(strcmp(S[j-1],S[j])>0){
        	strcpy(tmp,S[j-1]);
          	strcpy(S[j-1],S[j]);
          	strcpy(S[j],tmp);
        }
    }
  }
  for(i=0;i<N;i++){
  	printf("%s",S[i]);
  }

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cstring>

using namespace std;

int main()
{
    int c=0,k=0;
    string s;
    cin>>s;
    int sizer=s.size();
    for(int i=0 ; i<sizer;i++)
    {
         k+=(s[i]>=97);

    }
      for(int i=2 ; i<sizer-1;i++)
    {
         c+=(s[i]=='C');

    }
    if(s[0]=='A'&& c==1&&k==sizer-2){cout<<"AC";}
        else  cout<<"WA";
    return 0;
}

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

using namespace std;
const int MAX_BIT=50;

int main(){
  long long n, k, dp[MAX_BIT+1][2], c[MAX_BIT+1];
  cin >> n >> k;
  memset(c, 0, sizeof(c));
  memset(dp, 0, sizeof(dp));
  for(int i=0;i<n;i++){
    long long a;cin >> a;
    for(int j=0;j<=MAX_BIT;j++){
      if((a>>j)&1)c[j]++;
    }
  }
  dp[0][0]=0;
  dp[0][1]=0;
  for(int i=1;i<=MAX_BIT;i++){
    if(dp[i-1][0]==0){
      if(k>>(MAX_BIT-i)&1){
        dp[i][0]=c[MAX_BIT-i];
        dp[i][1]=(dp[i-1][1]<<1)+n-c[MAX_BIT-i];
      }
      else{
        dp[i][1]=(dp[i-1][1]<<1)+c[MAX_BIT-i];
      }
    }
    else{
      dp[i][0]=max(dp[i][0], (dp[i-1][0]<<1)+c[MAX_BIT-i]);
      dp[i][0]=max(dp[i][0], (dp[i-1][0]<<1)+n-c[MAX_BIT-i]);
      if(k>>(MAX_BIT-i)&1){
        dp[i][0]=max(dp[i][0], (dp[i-1][1]<<1)+c[MAX_BIT-i]);
        dp[i][1]=(dp[i-1][1]<<1)+n-c[MAX_BIT-i];
      }
      else{
        dp[i][1]=(dp[i-1][1]<<1)+(c[MAX_BIT-i]);
      }
    }
  }
  cout << max(dp[MAX_BIT][1], dp[MAX_BIT][0]) << endl;
}



Measured memory_bytes: 3612
#include<iostream>
#include<string>

using namespace std;

int main(void){
    int N,B,T;
    long long A;
    cin>>N;
    T=0;
    for(int j=1;j<N+1;j++){
        cin>>A;
        B=0;
        while(B==0){
            if(A%2==0){
                T=T+1;
                A=A/2;
            }else{
                B=1;
            }
        }
    }
    cout<<T<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const double PI=3.14159265358979323846;

int main(){
  int h,w;
  cin >> h >> w;
  int sheet[101][101] = {{}};
  rep(i,h)rep(j,w) cin >> sheet[i][j];

  rep(i,h){
    int total_w = 0;
    rep(j,w){
      total_w += sheet[i][j];
      sheet[h][j] += sheet[i][j];
    }
    sheet[i][w] = total_w;
  }
  int total = 0;
  rep(i,h) total += sheet[i][w];
  sheet[h][w] = total;

  rep(i,h+1){
    rep(j,w+1){
      if(j == w){
	cout << sheet[i][j];
	break;
      }
      cout << sheet[i][j] << " ";
    }
    cout << endl;
  }
}



Measured memory_bytes: 3116
s = list(input())

for i in range(int(input())):
    order, a, b, *c = input().split()
    a = int(a)
    b = int(b)
    if order == "print":
        print(*s[a:b+1], sep='')
    if order == "reverse":
        s[a:b+1] = reversed(s[a:b+1])
    if order == "replace":
        s[a:b+1] = c[0]



Measured memory_bytes: 5736
# 64 Kruskal


class UnionFind():
    def __init__(self, v):
        self.rank = [1] * v
        self.par = [x for x in range(v)]
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        if self.find(x) == self.find(y):
            return False
        else:
            p_x = self.find(x)
            p_y = self.find(y)
            if self.rank[p_x] >= self.rank[p_y]:
                self.par[p_y] = p_x
                self.rank[p_y] += 1
            else:
                self.par[p_x] = p_y
                self.rank[p_x] += 1
    
    def same(self, x, y):
        p_x = self.find(x)
        p_y = self.find(y)
        return p_x == p_y
    
v, e = map(int, input().split())
e_l = [[int(x) for x in input().split()] for y in range(e)]
e_l.sort(key= lambda x: x[2])

def Kruskal(s):
    ans = 0
    uf = UnionFind(v)

    for _s, _t, _w in e_l:
        if not uf.same(_s, _t):
            uf.unite(_s, _t)
            ans += _w
    return ans
            
print(Kruskal(0))


Measured memory_bytes: 26616
# Author: cr4zjh0bp
# Created: Sun Mar  8 05:03:14 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N, A, B = na()
C = N % (A + B)
if C == N:
    print(min(N, A))
else:
    print((N // (A + B)) * A + min(C, A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll a[N], b[N];
int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    ll A, B, M;
    cin >> A >> B >> M;
    for (int i = 1; i <= A; i++)
    	cin >> a[i];
    for (int i = 1; i <= B; i ++) {
    	cin >> b[i];
	}
	ll ans = 1e16;
	while (M --) {
		ll x, y, c;
		cin >> x >> y >> c;
		ans = min(ans, a[x] + b[y] - c);
	}
	sort(a + 1, a + A + 1);
	sort(b + 1, b + B  + 1);
	ans = min(ans, a[1] + b[1]);
	cout << max(0ll, ans);
    return (0);
}

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

int main(){
  int n,m;
  while(cin>>n>>m&&n|m){
    vector<pair<int, int>> dp; // 期待値,距離
    for(int i=0;i<n;i++){
      int d,p;
      cin>>d>>p;
      dp.push_back(make_pair(p,d));
    }

    sort(dp.begin(), dp.end());
    int ans=0;
    for(int i=n-1;i>=0;i--){
      if(m>0){
        if(dp[i].second<=m){
          m-=dp[i].second;
          dp[i].second=0;
        }else if(dp[i].second>m){
          dp[i].second-=m;
          m=0;
        }
      }
      ans = ans + dp[i].first*dp[i].second;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1328
import java.util.Scanner;

public class Main {

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

	    long N=gi();
	    long no=0;
	    long m=0;
	    long x=(long)Math.floor(Math.sqrt(N*2));
	    while(true) {
	        long y=(x*(x+1))/2;
	        if (y >N) {
	        	break;
	        }
	        x++;
	    }
	    m=((x*(x+1))/2)-N;

	    for (long i=1; i<=x;i++) {
	    	if (i!=m) {
	    	    System.out.println(i);
	    	}
	    }
//	    if (s>x) {
//	    	System.out.println(n-1);
//	    } else {
//	    	Arrays.parallelSort(a);
//
//	    	System.out.println(c);
//	    }
	    //System.out.println(q*4);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main(){
  int n,i,j,minv,maxv,*r;

  scanf("%d",&n);

  r = malloc(sizeof(int)*n);

  for(i = 0;i < n;i++){
    scanf("%d",&r[i]);
  }

  minv = r[0];
  maxv = r[1] - r[0];
  for(j = 1;j < n;j++){
    if(maxv > (r[j] - minv)){
      maxv = maxv;
    }
    else{
      maxv = r[j] - minv;
    }

    if(minv < r[j]){
      minv = minv;
    }
    else{
      minv = r[j];
    }
  }

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

  return 0;
}

Measured memory_bytes: 1380
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
        }
        int sum1 = 0;
        int sum2 = 0;
        for (int i = 0; i < m; i++) {
            if(x > a[i]) sum1++;
            else if(x < a[i]) sum2++;
        }
        System.out.println(Math.min(sum1, sum2));
    }
}

Measured memory_bytes: 35664
INF = 10**9 + 7


def main():
    from heapq import heappop, heappush
    H, W = (int(i) for i in input().split())
    Ch, Cw = (int(i)-1 for i in input().split())
    Dh, Dw = (int(i)-1 for i in input().split())
    A = [input() for i in range(H)]

    dist = [[INF]*W for _ in range(H)]
    dist[Ch][Cw] = 0
    que = [(0, Ch*W + Cw)]
    while que:
        u_dist, u = heappop(que)
        uh, uw = u//W, u % W
        if dist[uh][uw] < u_dist:
            continue
        for dh in range(-2, 3):
            for dw in range(-2, 3):
                nh = uh + dh
                nw = uw + dw
                if nh < 0 or H <= nh or nw < 0 or W <= nw:
                    continue
                if A[nh][nw] == "#":
                    continue
                cost = 0 if abs(dh) + abs(dw) <= 1 else 1
                if dist[nh][nw] > dist[uh][uw] + cost:
                    dist[nh][nw] = dist[uh][uw] + cost
                    heappush(que, (dist[nh][nw], nh*W + nw))

    if dist[Dh][Dw] == INF:
        print(-1)
    else:
        print(dist[Dh][Dw])

    # for h in range(H):
    #     print(dist[h])


if __name__ == '__main__':
    main()


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

int main(int argc, char const *argv[])
{
	int a,b;

	cin >> a;
	cin >> b;
	if (a<b)
	{
	cout << 'a' << " < " << 'b' << endl;
	}else if(a>b){
	cout << 'a' << " > " << 'b' << endl;
	}else{
	cout << 'a' << " == " << 'b' << endl;
	}
	return 0;
}


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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

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

    string s, t;
    cin >> s >> t;

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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3828
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.*;

/**
 * Created by Harry on 5/10/20.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int n = scanner.nextInt();
        long k = scanner.nextLong();
        int[] A = new int[n+1];
        for(int i=1; i<=n; i++){
            A[i] = scanner.nextInt();
        }
        //{pos, pathIndex}
//        HashMap<Integer, Integer> map = new HashMap();
        int[] map = new int[n+1];
        Arrays.fill(map, -1);
        List<Integer> path = new ArrayList<>();
        int pos = 1;
        int cycleStartPos = -1;
        while(map[pos]==-1){
            map[pos] = path.size();
            path.add(pos);
            pos = A[pos];
            cycleStartPos = pos;
        }

//        System.out.println(path);
        if(path.size()>k){
            System.out.println(path.get((int)k));
        }
        else{
            int cycleStartIdx = map[cycleStartPos];
            int cycleLen = path.size()-cycleStartIdx;
            int beforeCycleLen = cycleStartIdx;
//            System.out.println(cycleStartIdx+","+cycleStartPos);
            k-=beforeCycleLen;
            k%=cycleLen;
            int index = beforeCycleLen+(int)k;
            System.out.println(path.get(index));
        }
    }
}


Measured memory_bytes: 61144