akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
//ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

ll dp[2][310][310];
const ll mod = 1e9+7;

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

	dp[1][1][0] = 1;
	rep(i,M) {
		rep(j,N+1) {
			rep(k,N+1) {
				if(k)
					dp[i&1][j][k] = dp[i+1&1][j][k] * k % mod;
				else
					dp[i&1][j][k] = dp[i+1&1][j][k] * j % mod;
				if(k == 0) {
					for(ll l = 1; l < j; l++) {
						dp[i&1][j][k] += dp[i+1&1][l][j-l] * l % mod;
						dp[i&1][j][k] %= mod;
					}
				}
				else {
					dp[i&1][j][k] += dp[i+1&1][j][k-1] * (N-(j+k-1)) % mod;
				}
				dp[i&1][j][k] %= mod;
			}
		}
	}
	cout << dp[M-1&1][N][0] << endl;
	return 0;
}


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

using namespace std;

int main()
{
	int a, b, c;
	cin>>a>>b>>c;
	if(a==5 && b==5 && c==7)
		cout<<"YES";
	else if(a==5 && b==7 && c==5)
		cout<<"YES";
	else if(a==7 && b==5 && c==5)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}
	


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	while(true){
		cin>>n;
		if(n==0)
			break;
		int minprime=n;
		while(true){
			bool t=true;
			for(int i=2;i*i<=minprime;i++){
				if(minprime%i==0)
					t=false;
			}
			if(t==true)
				break;
			minprime--;
		}
		int maxprime=n;
		while(true){
			bool t=true;
			for(int i=2;i*i<=maxprime;i++){
				if(maxprime%i==0)
					t=false;
			}
			if(t==true)
				break;
			maxprime++;
		}
		cout<<maxprime-minprime<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
def main():
    N = int(input())
    S = input()
    if N == 1:
        print("No")
        exit(0)
    elif N % 2 != 0:
        print("No")
        exit(0)

    half = int(N / 2)
    for i in range(half):
        if S[i] != S[half + i]:
            print("No")
            exit(0)

    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define rep(i,b) for(ll i=0;i<b;i++)
#define all(v) (v).begin(),(v).end()

ll dist[25][105][105], cost[105][105];
ll INF=100000000;
int main()
{
    for(;;) {
        int n, m, com, s, g;
        cin >> n >> m >> com >> s >> g;

        if(!n) break;
        rep(i, 25) rep(j, 105) rep(k, 105) dist[i][j][k] = j==k?0:INF;
        vl x(m), y(m), d(m), c(m);
        rep(i, m) {
            cin >> x[i] >> y[i] >> d[i] >> c[i];
            x[i]--, y[i]--, c[i]--;
            dist[c[i]][x[i]][y[i]]=min(dist[c[i]][x[i]][y[i]], d[i]);
            dist[c[i]][y[i]][x[i]]=min(dist[c[i]][y[i]][x[i]], d[i]);
        }
        vl p(com);
        rep(i, com) cin >> p[i];
        vector<vl> q(com), r(com);
        rep(i, com) {
            q[i] = vl(p[i]-1), r[i] = vl(p[i]);
            rep(j, p[i]-1) cin >> q[i][j];
            rep(j, p[i]) cin >> r[i][j];
        }

        rep(l, com) rep(k, n) rep(i, n) rep(j, n) {
            dist[l][i][j]=min(dist[l][i][j], dist[l][i][k] + dist[l][k][j]);
        }

        rep(i, 105) rep(j, 105) cost[i][j] = i==j?0:INF;
        rep(l, com) {
            rep(i, n) rep(j, n) {
                ll tmp = 0;
                rep(k, p[l]-1) {
                    if(dist[l][i][j] < q[l][k]) {
                        tmp += (dist[l][i][j] - (k==0?0:q[l][k-1])) * r[l][k];
                        break;
                    } else {
                        tmp += (q[l][k] - (k==0?0:q[l][k-1])) * r[l][k];
                    }
                }
                if(p[l] == 1) {
                    tmp = dist[l][i][j] * r[l][0];
                } else if(dist[l][i][j] > q[l].back()) {
                    tmp += (dist[l][i][j] - q[l].back()) * r[l].back();
                }
                cost[i][j]=min(cost[i][j], tmp);
            }
        }

        rep(k, n) rep(i, n) rep(j, n) cost[i][j]=min(cost[i][j], cost[i][k] + cost[k][j]);

        if(cost[s-1][g-1] >= INF) cout << -1 << endl;
        else cout << cost[s-1][g-1] << endl;
    }
}


Measured memory_bytes: 5516
#include <bits/stdc++.h>
#define ll long long int 
using namespace std ;

int naive (string s )
{
    int count = 0 ; 
    string t  = "ABC" ; 
    for ( int i = 0 ; i<=s.size () - t.size () ; i++ ) 
    {
        int j ; 
        for ( j = 0 ; j <t.size () ; j++ ) 
        {
            if (s[i+j] != t[j] ) 
                break ;
        }
        if ( j == t.size () ) 
            count ++ ;  
    }
    return count ; 
}


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

    cout << naive ( s ) << endl ; 
    
    return 0 ; 
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#include <boost/range/algorithm.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.length();
  int count = 1;
  ll ans = 0;
  rep(i, n - 1) {
    if (s[i] == s[i + 1]) count++;
    if ((s[i] != s[i + 1]) || (i == n - 2)) {
      ans += count / 2;
      count = 1;
    }
  }
  ans *= k;
  int f = 0;
  int b = 0;
  char fc = s[0];
  char bc = s[n - 1];
  while (fc == s[0]) {
    f++;
    fc = s[f];
  }
  while (bc == s[n - 1]) {
    b++;
    bc = s[n - 1 - b];
  }
  if ((f % 2 == 1) && (b % 2 == 1) && (fc == bc)) ans += k - 1;

  if (f == n) {
    ans = (ll)n * k / 2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int K,A,B;
  
  scanf("%d", &K);
  scanf("%d", &A);
  scanf("%d", &B);
  
  int i,j;
  
  if(K>=1 && K<=1000 && A>=1 && A<=1000 && B>=1 && B<=1000 && A<=B && K<=B){
    for(i=1; i*K<=B; i++){
      if(A<=i*K && i*K<=B){
        puts("OK");
      if(A<=(i+1)*K && (i+1)*K<=B)
        break;
      }
    }
    
    for(j=1; j*K<=B; j++){
      if(B<(j+1)*K){
        if(A<=j*K && j*K<=B)
          break;
        else
          puts("NG");
      }
    }
    
  }
  else{
    puts("NG");
  }
  
  return 0;
}

Measured memory_bytes: 1656
#include"iostream"
using namespace std;
int main()
{
	long a,b;
	while(cin>>a>>b)
	{
		a=a+b;
		int i=0;
		while(a)
		{
			a=a/10;
			i+=1;
		}
		cout<<i<<endl;
	}
	return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n,m;cin >> n >> m;
    vector<int> toshi(n,0);
    rep(i,m)
    {
        int a,b;cin >> a>> b;
        a--;b--;
        toshi[a]++;
        toshi[b]++;
    }
    for (auto &&i : toshi)
    {
        cout << i << endl;
    }
    
}

Measured memory_bytes: 3572
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (0 until n).map { sc.next().toInt() }
    println(problem2020d(n, a))
}

fun problem2020d(n: Int, a: List<Int>): Long {
    var genkin = 1000L
    var kabu = 0L
    for (i in 0 until n - 1) {
//        debugLog(genkin, kabu)
        if (a[i] < a[i + 1]) {
            kabu += genkin / a[i]
            genkin %= a[i]
//            debugLog("i:$i buy")
            continue
        }
        if (a[i] > a[i + 1]) {
            genkin += kabu * a[i]
            kabu = 0
//            debugLog("i:$i sell")
            continue
        }
    }
//    debugLog(genkin, kabu)
    genkin +=  kabu * a.last()
    return genkin
}

Measured memory_bytes: 37880
# https://atcoder.jp/contests/abc150/tasks/abc150_d



N, M = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

require 'prime'
index_of_2 = Prime.prime_division(as.first).first[1]

lcm = as.inject(1) do |result, ai|
  if (ai / (2 ** index_of_2)).even?
    puts 0
    exit
  end
  result.lcm(ai/2)
end

lcm_x_count = M / lcm

puts lcm_x_count / 2 + lcm_x_count % 2


Measured memory_bytes: 12804
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        s: chars,
    }
    println!("{}", if s[2] == s[3] && s[4] == s[5] { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int b = 0, r = 0;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == '0')b++;
    else r++;
  }
  cout << min(r, b) * 2 << endl;
  return 0;
}

Measured memory_bytes: 512
import math
a, b, h, m = map(int, input().split())

hour_rad = ((2 * math.pi) / 720) * ((60 * h) + m)
min_rad =  ((2 * math.pi) / 60) * m
rad_ = abs(hour_rad - min_rad)
hour_cos = b * math.cos(rad_)
hour_sin = b * math.sin(rad_)

length_1 = a - hour_cos
length_2 = hour_sin

if rad_ == math.pi:
    ans = abs(length_1) + abs(length_2)
else:
    ans = math.sqrt((length_1 ** 2) + (length_2 ** 2))
print(ans)

Measured memory_bytes: 9464
// Author : Mohamed Sameh
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
typedef long long ll ;
using namespace std ;
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n ,m ;
    cin >> n >> m;
    vector<int> v (n);
    int sum =0;
    for (int i =0 ; i < n ;i++)
    {
        cin >> v[i];
        sum += v[i];
    }
    sort(all(v)); 
    int b = (sum+4*m-1) / (4 * m ); 
    for (int i = n-1 ; i >=0 && m ; i--)
    {
        if (v[i] >= b )
        {
            m--;
        }else 
        break;
    }
    if (m == 0 )
    {
        cout <<"Yes\n"; 
    }else 
    cout <<"No\n"; 

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int A, P;
	cin >> A >> P;
	int n = 3*A + P;

	cout << n / 2 << '\n';

	return 0;
}

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

constexpr long M = 2*1000+1;
int b[2000][1000];
int s[2001][1001];

inline long calc(long x, long y, long w, long h){
    return s[x+w][y+h] - s[x+w][y] - s[x][y+h] + s[x][y];
}

int main(void){
    long n, k;
    cin >> n >> k;
    for(long i=0; i<n; i++){
        long x, y;
        char c;
        cin >> x >> y >> c;
        y %= 2*k;
        if(c=='W'){
            x += k;
        }
        if(y>=k){
            y-=k;
            x+=k;
        }
        x %= 2*k;
        b[x][y]++;
    }
    /*
       for(long y=0; y<2*k; y++){
       for(long x=0; x<2*k; x++){
       cout << b[x+y*2*k] << " ";
       }
       cout << endl;
       }
       cout << endl;
       */
    s[1][1] = b[0][0];
    for(long i=1; i<2*k; i++){
        s[i+1][1] = s[i][1] + b[i][0];
    }
    for(long i=1; i<k; i++){
        s[1][i+1] = s[1][i] + b[0][i];
    }
    for(long x=1; x<2*k; x++){
        for(long y=1; y<k; y++){
            s[x+1][y+1] = b[x][y] + s[x][y+1] + s[x+1][y] - s[x][y];
        }
    }
    /*
       for(long y=1; y<M; y++){
       for(long x=1; x<M; x++){
       cout << s[x+y*M] << " ";
       }
       cout << endl;
       }
       cout << endl;
       */
    long max = 0;
    for(long x=0; x<k; x++){
        for(long y=0; y<k; y++){
            long t = calc(x, y, k, k-y);
            t += calc(0, 0, x, y);
            t += calc(x+k, 0, k-x, y);
            t = t<n/2 ? n-t : t;
            //printf("%ld %ld %ld\n", x, y, t);
            max = t>max ? t : max;
        }
    }
    cout << max;
    return 0;
}


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

typedef long long ll;

const ll M = 1000000000+7;

int main() {
    ll n, k;
    ll ans = 0;
    cin >> n >> k;

    for (ll i = k, x, y; i<=n+1; i++) {
        x = ((i-1)*i>>1);
        y = ((n*2-i+1)*i>>1);
        ans += (y-x)+1;
        ans %=M;
    }

    printf("%lld\n", ans);
}


Measured memory_bytes: 3772
import java.util.Scanner;

public class Main {

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

		for(int i = 0; i < h.length; i++) {
			h[i] = sc.nextInt();
		}
		
		int view = 0;
		for(int i = 0; i < h.length; i++) {
			int max = h[i];			
			for(int j = i; j >= 0; j--) {
				if(h[j] > h[i])	max = h[j]; 
			}
			if(max == h[i]) view++;
		}
		System.out.println(view);
		
	}

}


Measured memory_bytes: 21712
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  string s;
  cin >> s;
  ll len = s.size();

  bool flag = false;
  ll start, end;
  for (int i = 0; i < len-1; ++i) {
    if (s[i] == s[i+1]) {
      flag = true;
      start = i + 1, end = i + 2;
      break;
    }
  }

  for (int i = 0; i < len - 2; ++i) {
    if (s[i] == s[i+2]) {
      flag = true;
      start = i + 1; end = i + 3;
      break;
    }
  }

  if (flag) {
    cout << start << " " << end << endl;
  } else {
    printf("-1 -1\n");
  }
}


Measured memory_bytes: 512
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, p;

vector<LL> PrimeFact(LL n) {
	vector<LL> res;
	while (n != 1) {
		if (n == 2 || n == 3) {
			res.emplace_back(n); n /= n;
			continue;
		}
		bool prime_flag = false;
		for (LL i = 2; i*i <= n; i++) {
			if (n%i == 0) {
				res.emplace_back(i); n /= i;
				prime_flag = true;
				break;
			}
		}
		if (!prime_flag) { res.emplace_back(n); n /= n; }
	}
	return res;
}
map<LL, int>cnt;
int main(){
    INIT;
    cin >> n >> p;
    vector<LL> v = PrimeFact(p);
    REP(i, (int)v.size()){
        cnt[v[i]]++;
    }
    LL ans = 1;
    for(auto it = cnt.begin();it!=cnt.end();++it){
        if((it->second) >= n){
            ans *= pow((it->first), ((it->second)/n));
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {

	int n;
	int cnt=0;
	cin >> n;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		int c=0;
		while(a%2==0){
			a/=2;
			c++;
		}
		cnt+=c;
	}
	cout << cnt;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int calc(string a,string b){
	bool p[26],p2[26];
	int s=0;
	memset(p,0,sizeof(p));
	memset(p2,0,sizeof(p2));
	for(int i=0;i<a.size();i++)
		p[a[i]-97]=true;
	for(int i=0;i<b.size();i++)
		p2[b[i]-97]=true;
	for(int i=0;i<26;i++)
		s+=(p[i]&&p2[i]);
	return s;
}
int main(){
	int asihofosd,maxv=0;
	cin>>asihofosd;
	string s;
	cin>>s;
	for(int i=1;i<s.size();i++)
		maxv=max(maxv,calc(s.substr(0,i),s.substr(i)));
	cout<<maxv;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,ans=0;
  cin >> n >> m;
  vector<int> kusa(m+1);
  for(int i=0; i<n; i++){
   int k;
   cin >> k;
   vector<int> a(k);
   for (int j=0; j<k; j++){
     cin >> a.at(j);
     kusa[a[j]]++;
   }
  }
  for (int abc=0; abc<kusa.size(); abc++){
    if(kusa[abc]==n){
      ans++;
    }  
  
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main() {
    char pi[10];
    int cnt = 0;
    int final_cnt = 0;

    cin >> pi;

    for (int i = 0; i < sizeof(pi); i++) {
        if (pi[i] == 'A') {
            cnt++;
        } else if (pi[i] == 'C') {
            cnt++;
        } else if (pi[i] == 'G') {
            cnt++;
        } else if (pi[i] == 'T') {
            cnt++;
        } else {
            cnt = 0;
        }

        if (final_cnt < cnt) {
            final_cnt = cnt;
        } 
    }

    cout << final_cnt << endl;


}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;

const int loop=2*2*2*2*3*3*5*7*11;
int n;
int d[101],t[101],q[101][25];
int all[loop];
int val[25][25];
void solve(){
	memset(all,0,sizeof(all));
	memset(val,0,sizeof(val));
	for(int i=0;i<n;i++){
		if(loop%d[i]==0){
			for(int j=0;j<loop;j++){
				all[j]+=q[i][(j+t[i])%d[i]];
			}
		}else{
			for(int j=0;j<d[i];j++){
				val[d[i]][j]+=q[i][(j+t[i])%d[i]];
			}
		}
	}
	int res=0;
	int maxi=0;
	for(int i=0;i<loop;i++){
		maxi=max(maxi,all[i]);
	}
	res+=maxi;
	for(int i=1;i<=24;i++){
		maxi=0;
		for(int j=0;j<i;j++){
			maxi=max(maxi,val[i][j]);
		}
		res+=maxi;
	}
	printf("%d\n",res);
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d%d",&d[i],&t[i]);
			for(int j=0;j<d[i];j++){
				scanf("%d",&q[i][j]);
			}
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 2804
import sys
sys.setrecursionlimit(1000000)
K = int(input())
all = []
def dfs(number):
    all.append(number)
    if len(str(number)) == 10:
        return
    for i in range(-1, 2):
        n_number = number % 10 + i
        if n_number >= 0 and n_number <= 9:
            dfs(number*10+n_number)

for i in range(1, 10):
    dfs(i)
all.sort()
print(all[K-1])

Measured memory_bytes: 12316
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>

using namespace std;


int main(){
    int H,W;
    char input;
    //入力開始
    while(cin>>H>>W){
        if(H==0&&W==0)break;
        int data[600][600]={0};
        int width[600][600]={0};
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                cin>>input;
                if(input=='.'){
                    data[i+1][j+1]=1;
                }
            }
        }
        //入力終了
        //処理開始
        /*横の長さを計算*/
        for(int i=1; i<=H; i++){
            for(int j=W; j>=1; j--){
                if(data[i][j]==1){
                    width[i][j]=width[i][j+1]+1;
                }
            }
        }
        int answer = 0;
        
        for(int i=1; i<=H; i++){
            for(int j=1; j<=W; j++){
                if(data[i][j]==1){
                    int min_width = width[i][j];
                    int max_rectangular=width[i][j];
                    for(int k=i+1; k<=H; k++){
                        min_width = min(min_width, width[k][j]);
                        //cout<<min_width<<" ";
                        max_rectangular = max(max_rectangular, min_width*(k-i+1));
                        //cout<<max_rectangular<<endl;
                    }
                    answer = max(answer, max_rectangular);
                }
            }
        }
        cout<<answer<<endl;
        
        
        
        
    }
    
    
}

Measured memory_bytes: 3980
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>()>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    string s=stin();
    ll n=s.length();
    vecll a(26);
    rep(i,n)a[s[i]-'a']++;
    ll ans=n*(n-1)/2+1;
    rep(i,26)ans-=a[i]*(a[i]-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=y;i>=x;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
//	ios::sync_with_stdio(false);
//	cin.tie(0);
const int maxx = 1e7+7;
const int maxn = 1e9+7;
typedef long long ll;
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
ll notprime[maxx]={1,1};
ll prime[maxx];
ll cnt[maxx];
ll num,n,ans;
void Pri(ll n){
	for(ll i=2;i<maxx;i++){
		if(!notprime[i])prime[num++]=i;
		for(ll j=0;j<num && i*prime[j]<maxx;j++){
			notprime[i*prime[j]]=1;
			if(!(i%prime[j]))break;
		} 
	}
}
int sushu(ll a){
	if(a==1)return 0;
	else if(a==2||a==3||a==5){
		return 1;
	}else{
		for(int i=2;i<=sqrt(a);i++){
			if(a%i==0){
				return 0;
			}
		}
		return 1;
	}
}
int main(){
		ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	Pri(10000007);
	if(sushu(n)){
		cout<<1<<endl;
	//	cout<<"K"<<endl;
		return 0;
	}
	rep(i,0,num){
		if(n==1)break;
		int op=0;
		while(n%prime[i]==0)op++,n/=prime[i];
		if(op<3&&op>=1)ans+=1;
		else if(op>=3&&op<6)ans+=2;
		else if(op>=6&&op<10)ans+=3;
		else if(op>=10&&op<15)ans+=4;
		else if(op>=15&&op<21)ans+=5;
		else if(op>=21&&op<28)ans+=6;
		else if(op>=28&&op<36)ans+=7;
		else if(op>=36&&op<45)ans+=8;
		else if(op>=45&&op<55)ans+=9;
	}
	cout<<ans + (n!=1) <<endl;
	return 0;
}

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

typedef long long ll;
using namespace std;
int main()
{

  ll a,b;
  cin>>a>>b;
  ll ans=a+b;
  if(ans>=24)ans-=24;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3636
from collections import deque
import numpy as np
n,k =map(int,input().split())
A = [int(x)-1  for x in input().split()]
arrive_time = [0]*n
time = 1
done = [0]*n
done[A[0]] = 1
arrive_time[A[0]] = time
last = 0
next = A[0]
while True:
    v = next
    if done[A[v]] == 0:
        done[A[v]] = 1 
        time += 1
        arrive_time[A[v]] = time
        next = A[v]
    else:
        last = A[v]
        break  

if time >= k:
    for i,a in enumerate(arrive_time):
        if a == k:
            print(i+1)
else:
    roop = time - arrive_time[last] + 1
    nokori = (k-arrive_time[last])%roop
    ans = nokori+arrive_time[last]
    for i,a in enumerate(arrive_time):
        if a == ans:
            print(i+1)


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

using namespace std;
using llint = long long;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

int n, m, ans;
vector<int> x;

int main() {
    // Input
    cin >> n >> m;
    x.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> x.at(i);
    }

    // Solve
    if (m <= n)
    {
        ans = 0;
        cout << ans << endl;
        return 0;
    }

    sort(x.begin(), x.end());

    vector<int> d(m-1);
    for (int i = 0; i < m-1; ++i) {
        d.at(i) = x.at(i+1) - x.at(i);
    }

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

    ans = x.at(m-1) - x.at(0);
    for (int i = 0; i < n-1; ++i) {
        ans -= d.at(i);
    }

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

Measured memory_bytes: 1024
def main():
    a = list(map(int, input().split()))
    a.sort()
    A, B, C = a[0], a[1], a[2]
    ans = 0
    ans += C-B
    A = A + ans
    B = B + ans
    ans += (B-A) // 2
    A += ((B-A) // 2) * 2
    if A != B:
        ans += 2
    print(ans)
main()

Measured memory_bytes: 61944
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    int A, B, C; cin >> A >> B >> C;
    cout << min(C, B / A) << endl;

    return 0;
}


Measured memory_bytes: 256
//33
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  int t;
  cin>>t;
  while(t--){
    int r[9];
    char s[9];
    for(int i=0;i<9;i++){
      cin>>r[i];
    }
    for(int i=0;i<9;i++){
      cin>>s[i];
    }
    bool f=false;
    int c[]={0,0,0,1,1,1,2,2,2};
    do{
      vector<int> p[3];
      for(int i=0;i<9;i++){
	p[c[i]].push_back(i);
      }
      int i;
      for(i=0;i<3;i++){
	if(!s[p[i][0]]==s[p[i][1]]||s[p[i][0]]!=s[p[i][2]])break;
	if(r[p[i][0]]==r[p[i][1]]&&r[p[i][0]]==r[p[i][2]])continue;
	int rs=1<<r[p[i][0]]|1<<r[p[i][1]]|1<<r[p[i][2]];
	int rl=rs&~(rs-1);
	if((rs&rl<<1)&&(rs&rl<<2))continue;
	break;
      }
      f|=!(i<3);
    }while(!f&&next_permutation(c,c+9));
    cout<<f<<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt();
            }
            HashMap<Integer, Integer> numberToCount = new HashMap<>();
            for (int i = 0; i < N; i++) {
                Integer count = numberToCount.get(a[i]);
                numberToCount.put(a[i], 1 + (count == null ? 0 : count.intValue()));
            }
            int count = 0;
            for (Integer n : numberToCount.keySet()) {
                Integer c = numberToCount.get(n);
                if (c.intValue() < n.intValue()) {
                    count += c.intValue();
                    continue;
                }
                if (c.intValue() >= n) {
                    count += c.intValue() - n.intValue();
                }
            }
            System.out.println(count);
        }
    }
}


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

int n,m,q;
vector<int> e[100005];
int v[100005],d[100005],c[100005];
int color[100005],dist[100005];

void dfs(int u,int d,int col)
{
    if(d<=dist[u]) return;
    dist[u]=d;
    if(color[u]==-1) color[u]=col;
    for(int i=0;i<e[u].size();i++)
        dfs(e[u][i],d-1,col);
}

int main()
{

    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>v[i]>>d[i]>>c[i];
        v[i]--;
    }
    fill(dist,dist+100005,-1);
    fill(color,color+100005,-1);
    
    for(int i=q-1;i>=0;i--)
        dfs(v[i],d[i],c[i]);
    for(int i=0;i<n;i++)
        cout<<((color[i]==-1)?0:color[i])<<'\n';

    return 0;
}

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

int main() {
  int s, s1, s2, s3, n = 0;
  cin >> s;
  s3 = s % 10;
  s2 = (s / 10) % 10;
  s1 = (s / 100) % 10;
 
  if(s1 == 1){
    n = n + 1;
  }
  if(s2 == 1){
    n = n + 1;
  }
  if(s3 == 1){
    n = n + 1;
  }
  
  cout << n << endl;
}

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

int main() {
  int N,T;
  cin >> N >> T;
  vector<pair<int,int>> F(N);
  for (int i=0;i<N;i++) {
    cin >> F.at(i).first >> F.at(i).second;
  }
  sort(F.begin(),F.end());
  vector<vector<int>> dp(N,vector<int>(T,-1));
  int ans = -1;
  for (int i=0;i < N-1;i++) {
    for (int j=0;j < T;j++) {
      if (F.at(i).first > j) {
        dp.at(i).at(j) = (i ? dp.at(i-1).at(j) : 0);
      }
      else {
        dp.at(i).at(j) = (i ? max(dp.at(i-1).at(j),dp.at(i-1).at(j-F.at(i).first) + F.at(i).second) : F.at(i).second);
      }
    }
    ans = max(ans,dp.at(i).at(T-1) + F.at(i+1).second);
  }
  cout << ans << endl;
}

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

int main(){
  int A,B,C,D;

  cin >> A >> B >> C >> D;

  if(A+B>C+D){
    cout << "Left" << endl;
  }
  else if(A+B==C+D){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define ld double
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
//#define len length()
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect


void solve() {
    int n, m;
    cin >> n >> m;
    cout << (n == m ? "Yes" : "No");
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

#define LOADVECTOR(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;

int main() {
	ios::sync_with_stdio(false);
	LOAD(i32, A);
	LOAD(i32, B);
	LOAD(i32, K);
	int n = 0;
	for (int i = 100; i >= 1; --i) {
		if ((A%i) == 0 && (B%i) == 0) {
			++n;
			if (K == n) {
				cout << i;
				return 0;
			}
		}
	}
	return 0;
}
#endif


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

int32_t main(){
    int n,m,x;cin>>n>>m>>x;
    vector<vector<int>> v(n,vector<int> (m));
    vector<int> c(n);
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(auto &j : v[i]) cin>>j;
    }

    int mn=LLONG_MAX;
    for(int i=0;i<(1<<n);i++){
        vector<int> curr(m,0);
        int cost=0;
        for(int j=0;j<12;j++){
            if(i&(1<<j)){
                cost+=c[j];
                for(int k=0;k<m;k++) curr[k]+=v[j][k];
            }
        }
        if(*min_element(curr.begin(),curr.end())>=x) mn=min(mn,cost);
    }
    if(mn==LLONG_MAX) cout<<"-1\n";
    else cout<<mn<<"\n";
    return 0;
}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int R;
  int G;
  cin >>R>>G;
  int x=G-R;
  int y=G+x;
  cout << y<< endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
 
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	vector<int>a;
	int k;
	int n;
	int m = -1;
	int x;
	int ans = 0;

	scanf("%d", &n);
	f(i, n){
		scanf("%d", &x);
		a.push_back(x);
		if (x < 0)x = -x;
		if (m < x){
			m = x;
			k = i;
		}
	}
	printf("%d\n", (2 * n) - 1);
	f(i, n)printf("%d %d\n", k + 1, i + 1);
	if (a[k] < 0){
		f(i, n - 1)printf("%d %d\n", n - i, n - i - 1);
	}
	else{
		f(i, n - 1)printf("%d %d\n", i + 1, i + 2);
	}

	return 0;
}

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

using namespace std;

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

#ifdef ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif

#define pb emplace_back
#define lb lower_bound
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

#define ALL(c) (c).begin(),(c).end()

#define DBG0(x)    {if(DEBUG){ cout << #x << ": " << x << "\t"; }}
#define DBG(x)     {if(DEBUG){DBG0(x); cout << endl;}}
#define DBG2(x, y) {if(DEBUG){DBG0(x); DBG(y);}}
#define DBG3(x, y, z) {if(DEBUG){DBG0(x); DBG2(y, z);}}
#define DBG4(w, x, y, z) {if(DEBUG){DBG0(w); DBG3(x, y, z);}}

template <class T>
ostream& operator<<(ostream& os, vector<T> xs){ for(T x: xs) os << x << ' '; return os; }
template <class S, class T>
ostream& operator<<(ostream& os, pair<S,T> st){ os << "(" << st.first << "," << st.second <<")"; return os; }

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

const int PN = 2100000;
vint ps;
vector<bool> eratos;
void init_primes(void){
    eratos = vector<bool>(PN, false);
    ps.clear();
    for(int i = 2; i < PN; ++i){
        if(!eratos[i]){
            ps.pb(i);
            for(int j = i; j < PN; j += i)
                eratos[j] = true;
        }
    }
    return;
}
int main(void){
    init_primes();
    int n;
    while(cin >> n){
        if(n < 2){
            cout << 0 << endl;
            continue;
        }
        int l = 0, r = ps.size() - 1;
        while(r - l > 1){
            int med = (l + r) / 2;
            if(ps[med] <= n) l = med;
            else r = med;
        }
        cout << l + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 2244
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var next = "";
            switch (s)
            {
                case "Sunny": next = "Cloudy"; break;
                case "Cloudy": next = "Rainy"; break;
                case "Rainy": next = "Sunny"; break;
            }
            Console.WriteLine(next);
        }
    }
}


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

int main(){
int n;
  cin >> n;
long long a[n];
  for(int i=0;i<n;i++) cin >> a[i];
int odd=0;
  for(int i=0;i<n;i++){
  if(a[i]%2==1)odd++;
  }
if(odd%2==0)cout << "YES" << endl;
 else cout << "NO" << endl; 
}

Measured memory_bytes: 4376
def compress_array_to_hash(array)
  hash = {}
  array.map { |e|
    if hash[e].nil?
      hash[e] = 1
    else
      hash[e] += 1
    end
  }
  hash
end

n = gets.to_i
as = gets.split.map(&:to_i)
hash = compress_array_to_hash(as)
count = 0
hash.each do |key, value|
  if key > value
    count += value
  elsif key < value
    count += value - key
  end
end
puts count


Measured memory_bytes: 15236
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

typedef long long ll;

using namespace std;

int H, W;
char orchard[128][128];
void destroy_orchard(char f, int x, int y)
{
	if (x < 0 || y < 0 || x >= W || y >= H || orchard[y][x] != f)
		return;

	orchard[y][x] = 'w';
	int dx[] = { 0, 1, 0, -1 };
	int dy[] = { 1, 0, -1, 0 };
	for (int i = 0; i < 4; ++i)
		destroy_orchard(f, x + dx[i], y + dy[i]);
}
int main()
{
	while (true)
	{
		char buf[128];
		cin.getline(buf, sizeof(buf));
		sscanf(buf, "%d %d", &H, &W);
		if (H == 0 && W == 0)
			break;

		for (int i = 0; i < H; ++i)
			cin.getline(orchard[i], sizeof(orchard[i]));

		int ans = 0;
		for (int i = 0; i < H; ++i)
		{
			for (int j = 0; j < W; ++j)
			{
				if (orchard[i][j] != 'w')
				{
					++ans;
					destroy_orchard(orchard[i][j], j, i);
				}
			}
		}
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("unroll-loops")
#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;

typedef  long long int  ll;
typedef long double ld;
ll N;

void solve()
{
    cin>>N;
    if(N%1000==0)
    cout<<"0"<<"\n";
    else
    cout<<1000-(N%1000)<<"\n";
}
signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    solve();
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
using namespace std;
int k,n,a[200007];
int main(){
	scanf("%d%d",&k,&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int ans=k;
	for(int i=0;i<n;i++){
		if(i!=0&&i!=n-1){
			ans=min(ans,k-a[i]+a[i-1]);
			ans=min(ans,a[i]+k-a[i+1]);	
	//		printf("i=%d ans=%d\n",i,ans);
		}
		else {
			ans=min(ans,k-a[1]+a[0]);
			ans=min(ans,k-a[n-1]+a[n-2]);
			ans=min(ans,a[n-1]-a[0]);	
	//		printf("i=%d ans=%d\n",i,ans);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+8+7;
ll n,m,l;
string s,t;
// int d[100],dp[100][100];

ll func(ll n){
  ll m = 0;
  while(n != 0){
    m += n%10;
    n/=10;
  }
  return m;
}
 
int main(){
  cin >> n;
  if(n % func(n) == 0)puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
n = int(input())
suits = ['S', 'H', 'C', 'D']
cards= []
for suit in suits:
    for i in range(1,14):
        cards.append([suit,str(i)])
for i in range(n):
    cards.remove(input().split())
for i in range(52-n):
    print(cards[i][0],cards[i][1])


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 5e3 + 5;

int V[N], U[N], H[N], P[N], S[N], LCA[N][N];
vector<int> G[N];

void DFS(int v, int p = 0) {
	P[v] = p;
	for (int u : G[v]) if (u != p) H[u] = H[v] + 1, DFS(u, v);
}
ll DFSC(int v, int p = 0) {
	ll t = 1;
	for (int u : G[v]) if (u != p) t *= DFSC(u, v), S[v] += S[u];
	if (!S[v] && p) t *= 2;
	return t;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	for (int i = 1; i < n; i++)  {
		int v, u; cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	DFS(1);
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
		int v = i, u = j;
		while (v != u) {
			if (H[v] < H[u]) swap(v, u);
			v = P[v];
		}
		LCA[i][j] = v;
	}
	int m; cin >> m;
	for (int i = 0; i < m; i++) cin >> V[i] >> U[i];
	ll ans = 0;
	for (int mask = 0; mask < (1 << m); mask++) {
		for (int i = 1; i <= n; i++) S[i] = 0;
		for (int i = 0; i < m; i++) if ((mask >> i) & 1) S[V[i]]++, S[U[i]]++, S[LCA[V[i]][U[i]]] -= 2;
		if (__builtin_popcount(mask) & 1) ans -= DFSC(1);
		else ans += DFSC(1);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
// AOJ 0574
#include<cstdio>
#include<vector>
#define rep(i,a) for( int i = 0; i < (a); ++i )
#define repi(i,a,b) for( int i = (a); i < (b); ++i )

int N, M;
std::vector<std::vector<int> > map( 5002 );

int main()
{
	scanf( "%d%d", &N, &M );
	rep( i, N+2 )
		map[i].resize( i+2 );

	rep( i, M )
	{
		int A, B, X;
		scanf( "%d%d%d", &A, &B, &X );
		--A; --B;
		++map[A][B]; --map[A][B+1];
		--map[A+X+1][B]; ++map[A+X+1][B+X+2];
		++map[A+X+2][B+1]; --map[A+X+2][B+X+2];
	}

	rep( i, N+2 )
		repi( j, 1, i+2 )
			map[i][j] += map[i][j-1];

	repi( i, 1, N+2 )
		rep( j, i+1 )
			map[i][j] += map[i-1][j];

	repi( i, 1, N+2 )
		repi( j, 1, i+1 )
			map[i][j] += map[i-1][j-1];

	int ans = 0;
	rep( i, N )
		rep( j, i+1 )
			ans += map[i][j]?1:0;

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

	return 0;
}

Measured memory_bytes: 49848
def gcd(a,b):
    if not b:
        return a
    while a%b:
        a, b = b, a%b
    return b

def lcm(a,b):
    if not a or not b:
        return 0  # ?
    g = gcd(a,b)
    return a*b//g

a, b = [int(s) for s in input().split()]
print(lcm(a,b))

Measured memory_bytes: 3060
from collections import Counter
from math import gcd

class Prime:
    def __init__(self, N):
        smallestPrime = [1] * (N + 1)
        primes = []

        for i in range(2, N + 1):
            if smallestPrime[i] != 1:
                continue
            primes.append(i)
            for p in range(i * 2, N + 1, i):
                if smallestPrime[p] == 1:
                    smallestPrime[p] = i

        self.smallestPrime = smallestPrime
        self.primes = primes

    def isPrime(self, n):
        return n > 1 and self.smallestPrime[n] == 1

    def factorization(self, n):
        ret = Counter()
        while True:
            p = self.smallestPrime[n]
            if p == 1:
                break
            ret[p] += 1
            n //= p
        if n > 1:
            ret[n] += 1
        return ret

N = int(input())
A = list(map(int, input().split()))
prime = Prime(max(A) + 100)

def isSetwise(A):
    ret = A[0]
    for a in A:
        ret = gcd(ret, a)
    return ret == 1

def isPairwise(A):
    cnt = Counter()
    for a in A:
        for p in prime.factorization(a):
            if cnt[p] >= 1:
                return False
            cnt[p] += 1
    return True

if not isSetwise(A):
    print('not coprime')
elif isPairwise(A):
    print('pairwise coprime')
else:
    print('setwise coprime')


Measured memory_bytes: 127568