akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

const int mod = 1000000007;
struct ModInt {
    lint x;
    ModInt (lint a) : x((a % mod + mod) % mod) {}
    ModInt operator - () const {
        return ModInt(-x);
    }
    ModInt &operator += (const ModInt &a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator -= (const ModInt &a) {
        if ((x -= a.x) < 0) x += mod;
        return *this;
    }
    ModInt &operator *= (const ModInt &a) {
        (x *= a.x) %= mod;
        return *this;
    }
    ModInt operator + (const ModInt &a) const {
        ModInt res(*this);
        return res += a;
    }
    ModInt operator - (const ModInt &a) const {
        ModInt res(*this);
        return res -= a;
    }
    ModInt operator * (const ModInt &a) const {
        ModInt res(*this);
        return res *= a;
    }
    ModInt pow(lint t) const {
        if (!t) return 1;
        ModInt a = pow(t / 2);
        a *= a;
        if (t % 2) a *= *this;
        return a;
    }
    ModInt inv() const {
        return pow(mod - 2);
    }
    ModInt &operator /= (const ModInt &a) {
        return (*this) *= a.inv();
    }
    ModInt operator / (const ModInt &a) const {
        ModInt res(*this);
        return res /= a;
    }
    friend ostream &operator << (ostream &os, const ModInt &a){
        os << a.x;
        return os;
    }
};

int main() {
    int N;
    cin >> N;
    vector<lint> C(N);
    rep(i, N) cin >> C[i];
    if (N == 1) {
        cout << C[0] * 2 % 1000000007 << "\n";
        return 0;
    }
    sort(C.rbegin(), C.rend());
    ModInt ans(0);
    rep(i, N) {
        ModInt M(C[i] * (i + 2));
        ans += M;
    }
    ModInt M(2);
    rep(i, 2 * N - 2) ans *= M;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1792
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    N = I()
    ans = 0

    while True:
        if N >= 1000:
            N -= 1000
            if N ==0:
              break
        else:
            ans = 1000-N
            break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10016
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {
    int n, m; cin>>n>>m;
    set<pair<int, int> > s;
    for(int i=0;i<m;i++) {
        int a, b; cin>>a>>b;
        s.insert({a,b});
    }
    for(int i=0;i<n;i++) {
        if(s.count({1,i}) && s.count({i,n})) {
            cout<<"POSSIBLE\n";
            return;
        }
    }
    cout<<"IMPOSSIBLE\n";
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define mod  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

#define MAX_N 2000005
#define MOD 1000000007

ll inv[MAX_N],fac[MAX_N],finv[MAX_N];

void make()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2;i<MAX_N;i++){
		inv[i] = MOD - (long long)inv[MOD%i] * (MOD/i) % MOD;
		fac[i] = (long long)fac[i-1] * i % MOD;
		finv[i] = (long long)finv[i-1] * inv[i] % MOD;
	}
}

ll com(int a,int b)
{
    //cerr << a << " " << b << endl;
	if(a < b){
		return 0;
	}
	return fac[a] * (finv[a-b] % MOD) % MOD;
}

int main(){
    int n,m;
    make();
    cin >> n>> m;
    vector<int> a(n),b(m);
    rep(i,n)cin >> a[i];
    rep(i,m)cin >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int x = 0;
    int y = 0;
    int c = 0;
    ll ans = 1;
    if(a[n-1]!=b[m-1]){
        cout << 0 << endl;
        return 0;
    }
    rep(i,n-1){
        if(a[i]==a[i+1]){
                    cout << 0 << endl;
        return 0;
        }
    }
    rep(i,m-1){
        if(b[i]==b[i+1]){
                    cout << 0 << endl;
        return 0;
        }
    }
    while(1){
        //cerr << x << " " << y << " " << ans << endl;
        if(x==n&&y==m)break;
        if(x==n){
            int p = b[y];
            ll tmp = com(p-c-1,n-x-1)*(ll)(n-x)%mod;
            ans *= tmp;
            ans %= mod;

            c += n-x;
            y++;
        }else if(y==m){
            int p = a[x];
                ll tmp = com(p-c-1,m-y-1)*(ll)(m-y)%mod;
                ans *= tmp;
                ans %= mod;
                x++;
                c += m-y;
        }else{
            if(a[x]==b[y]){
                int p = a[x];
                ll tmp = com(p-c-1,m-1-y+n-1-x);
                ans *= tmp;
                ans %= mod;
                c += m-1-y+n-1-x +1;
                x++;
                y++;
            }else if(a[x]>b[y]){
                int p = b[y];
                ll tmp = com(p-c-1,n-x-1)*(ll)(n-x)%mod;
                ans *= tmp;
                ans %= mod;

                c += n-x;
                y++;
            }else{  
                int p = a[x];
                ll tmp = com(p-c-1,m-y-1)*(ll)(m-y)%mod;
                ans *= tmp;
                ans %= mod;
                x++;
                c += m-y;
            }
        }
        if(ans==0)break;
    }
    cout << ans << endl;
    return 0;
}

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

namespace D
{
    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 nk = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var pn = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var max = 0.0;

            var cumSum = pn.CumulativeSum();

            for (var i = 0; i <= nk[0] - nk[1]; i++)
            {
                var sum = cumSum.ElementAt(i + nk[1]) - cumSum.ElementAt(i);
                if (max < sum) max = sum;
            }
            Console.WriteLine((max + nk[1]) / 2.0);
        }
    }

    public static class LinqExtensions
    {
        public static IEnumerable<int> CumulativeSum(this IEnumerable<int> items)
        {
            if (items == null) throw new ArgumentNullException();
            var count = items.Count();
            if (count < 1) throw new ArgumentException();
            var array = new int[count + 1];
            array[0] = 0;
            for (var i = 1; i < array.Length; i++)
            {
                var index = i - 1;
                array[i] = items.ElementAt(index) + array[index];
            }
            return array;
        }
    }
}


Measured memory_bytes: 32220
P = [1 for i in range(250000)]
# 素数リスト(0 ~)

P[0] = 0
P[1] = 0

for i in range(2, 250000) :
    for j in range(2, 250000 // i) :
        P[i * j] = 0
        # 倍数はフラグを0に
        
while True :
    n = int(input())
    
    if n == 0 :
        break
    
    else :
        print(P[n + 1 : 2 * n + 1].count(1))


Measured memory_bytes: 8936
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
using namespace std;
// clang-format on

main {
  int a, b;
  cin >> a >> b;
  cout << prec(23) << a / b << ' ' << a % b << ' ' << 1.0 * a / b << endl;
}

Measured memory_bytes: 3280
### subroutines

def bsearch(ranges, tm)
  i = 0
  j = ranges.length - 1

  while i <= j
    k = (i + j) / 2
    r0, r1 = ranges[k]
    if tm + 30 > r0 && tm < r1
      return k
    end

    if tm >= r1
      i = k + 1
    else
      j = k - 1
    end
  end

  nil
end

### main

loop do
  n = gets.to_i
  break if n == 0

  prgs = 7.times.map{[]}
  prghash = {}

  n.times do
    name, wd, st = gets.strip.split
    wdi = wd.to_i
    sti = st.to_i
    tm = (sti / 100 - 6) * 60 + (sti % 100)

    prghash[name] = [wdi, tm]
    prgs[wdi] << tm
  end
  #p prgs
  #p prghash

  for prg in prgs
    prg.sort!.uniq!
  end
  #p prgs

  pn = gets.to_i
  anchors = 7.times.map{[]}

  pn.times do
    wdi, sti = prghash[gets.strip]
    anchors[wdi] << sti
  end
  #p anchors

  count = 0

  for anc in anchors
    anc.sort!

    for i in (0...(anc.length - 1))
      if anc[i + 1] - anc[i] < 30
        count = -1
        break
      end
    end
    break if count == -1
  end

  if count == -1
    puts -1
    next
  end

  for i in (0..6)
    prg = prgs[i]
    anc = anchors[i]
    #p [prg, anc]

    ranges = [[0, 24 * 60]]
    for an in anc
      k = bsearch(ranges, an)
      if ! k.nil?
        r0, r1 = ranges[k]
        rs = []
        if r0 < an && an - r0 >= 30
          rs << [r0, an]
        end
        if an + 30 < r1 && r1 - an >= 60
          rs << [an + 30, r1]
        end
        ranges[k, 1] = rs
      end
    end
    count += anc.length

    for range in ranges
      r0, r1 = range

      for tm in prg
        break if tm + 30 > r1
        if tm >= r0
          #p [r0, r1, tm]
          count += 1
          r0 = tm + 30
        end
      end
    end
    #p ranges
  end

  puts count
end

Measured memory_bytes: 6272
#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 };
ll dp[110000];

int main(){cout<<fixed<<setprecision(10);
		   int n,k;
           cin>>n>>k;
           vin h(n);
           rep(i,0,n)cin>>h[i];
           dp[0]=0;
           rep(i,1,n){
             dp[i]=INF;
             rep(j,1,k+1){
              if(i-j>=0)chmin(dp[i],dp[i-j]+abs(h[i]-h[i-j])); 
             }
           }
           cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4584
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
long long cmpfunc (const void * a, const void * b) {
   return ( *(long long*)a - *(long long*)b );
}



int main(void){
   
long long int test,i,j,n,count,flag=0,o1=0,o2=0,b1,x,m,l,max,sum2,min,f,c,r,o,sum1,sum=0,y,a[1000000],b[1000000],count1=0,a2,b2;

scanf("%lld",&n);
for(i=0;i<n+1;i++){
    scanf("%lld",&a[i]);
    
}


for(i=0;i<n;i++){
    scanf("%lld",&b[i]);
  
}
j=count=0;
for(i=0;i<n;i++){
  if(a[i]>=b[i]){
      count+=b[i];
      a[i]-=b[i];
      b[i]=0;
      
  }else{
      if(b[i]>=a[i]){
          count+=a[i];
          b[i]-=a[i];
          a[i]=0;
          if(b[i]>=a[i+1]){
              count+=a[i+1];
              b[i]-=a[i+1];
              a[i+1]=0;
            
          }else{
              count+=b[i];
              a[i+1]-=b[i];
              b[i]=0;
          }
          
      }
  }
  
}
printf("%lld",count);
return 0;
}


Measured memory_bytes: 6656
class Vector
  attr_accessor :x, :y

  def initialize(x, y)
    @x, @y = x, y
  end

  def self.sub(a, b)
    x = a.x - b.x
    y = a.y - b.y

    new(x, y)
  end
end

while line = gets
  x1, y1, x2, y2, x3, y3, xp, yp = line.chomp.split.map(&:to_f)

  a = Vector.new(x1, y1)
  b = Vector.new(x2, y2)
  c = Vector.new(x3, y3)
  p = Vector.new(xp, yp)

  ab = Vector.sub(b, a)
  bp = Vector.sub(p, b)
  bc = Vector.sub(c, b)
  cp = Vector.sub(p, c)
  ca = Vector.sub(a, c)
  ap = Vector.sub(p, a)

  cross_product1 = ab.x * bp.y - ab.y * bp.x
  cross_product2 = bc.x * cp.y - bc.y * cp.x
  cross_product3 = ca.x * ap.y - ca.y * ap.x

  if (cross_product1 > 0 && cross_product2 > 0 && cross_product3 > 0) ||
      (cross_product1 < 0 && cross_product2 < 0 && cross_product3 < 0)
    puts 'YES'
  else
    puts 'NO'
  end
end

Measured memory_bytes: 8776
#include<bits/stdc++.h>
#define slowanddetermined ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

const long long mod=1e9+7;
long long inverseMod(long long x,long long mod);
long long nCr(long long n,long long r,long long mod){
    //when r is lesser and is greater
    long long res=1;
    if(r>n-r)r=n-r;
    long long div=1;
    for(long long  i=0;i<r;i++){
        res=(res*(n-i))%mod;
    }

    for(long long i=1;i<=r;i++){
        div=(div*i)%mod;
    }
    return (res*inverseMod(div,mod))%mod;
}


long long power(long long x,long long n,long long mod){
//(x^n)%mod
long long result=1;

    while(n){
        if(n%2)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n/=2;
    }
    return result;
}

long long inverseMod(long long x,long long mod){

return power(x,mod-2,mod);
}


int main()
{
    slowanddetermined

    int n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    long long ans=0;
    if(p==2){
        for(int i=0;i<n;i++){
            if((s[i]-'0')%2==0)ans+=i+1;
        }
    }
    else if(p==5){
        for(int i=0;i<n;i++){
            if(((s[i]-'0')%5)==0)ans+=i+1;
        }
    }
    else{

        map<long long ,long long >mp;
        mp[0]=1;
        long long a;
        long long last=0;
        long long pow=1;
        long long value=0;
        for(int i=n-1;i>=0;i--){
            value=(value+pow*(s[i]-'0'))%p;
            mp[value]++;
            pow=(pow*10)%p;
        }
        for(auto i:mp){
            ans+=(i.second*(i.second-1))/2;
        }
        //ans+=mp[0];



    }
    cout<<ans;





    return 0;

}


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

int a[100000];

int main() {
	// your code goes here
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;++i) scanf("%d",&a[i]);
	
	int even = 0;
	int even_even = 0;
	int odd = 0;
	
	for(int i=0;i<N;++i){
		int temp = a[i];
		if(temp%2 == 0){
			if(temp%4 == 0) even_even++;
			else even++;
		}
		else odd++;
	}
	
	if(even_even>=odd || (even_even+odd==N && odd-even_even==1)) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

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

int a[5001];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	while(cin >> n && n != 0){
		a[0] = 0;
		for(int i = 1; i <= n; ++i){
			cin >> a[i];
			a[i] += a[i - 1];
		}

		int m = -100000;
		for(int i = 1; i <= n; ++i){
			for(int j = 0; j < i; ++j){
				m = max(m, a[i] - a[j]);
			}
		}

		std::cout << m << std::endl;
	}

	return 0;
}

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

const int Nmax = 50;
const int Amax = 50;
const int Xmax = 50;

long dp[Nmax+1][Nmax+1][Nmax*Xmax+1] = {};
long xarr[Xmax+1];
long N,A;
long M;

int arr_max()
{
  int m = 0;
  for (int i = 0; i < N; i++) m = max(m,(int)(xarr[i]));
  return m;
}

int main()
{
  cin >> N >> A;
  for (int i = 1; i <= N; i++) cin >> xarr[i];
  // finish inputting

  long M = max(arr_max(),(int)A);
  //  cout << M << endl;
  for (int j = 0; j <= N; j++) {
    for (int k = 0; k <= j; k++) {
      for (int s = 0; s <= M*N; s++) {
	//	if (j >= 1 && k >= 1 && s < xarr[j])
	//	if (j == 33 && k == 4 && s == 12) cout << "b" << endl;
	if (j >= 1 && s < xarr[j]) {
	  //	  if (j == 33 && k == 4 && s == 12) cout << "a" << endl;
	  dp[j][k][s] = dp[j-1][k][s];
	}
	else if (j >= 1 && k >= 1 && s >= xarr[j]) {
	  dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-xarr[j]];
	  //	  if (j == 33 && k == 4 && s == 12) cout << "a" << endl;
	}
	else if (j == 0 && k == 0 && s == 0)
	  dp[j][k][s] = 1;
	else {
	  //	  if (j == 33 && k == 4 && s == 12) cout << "a" << endl;
	  dp[j][k][s] = 0;
	}
      }
    }
  }
  //  cout << dp[N-1][3][9]  << endl;
  // cout << dp[2][1][1] << ":"<< dp[2][1][4]<< ":" << dp[1][1][1] << ":" << dp[2][2][6] << endl;
  long cnt = 0;
  for (int i = 1; i <= N; i++) {
    cnt += dp[N][i][i*A];
    //    if (cnt > 6017) cout << ":::" << endl;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 49152
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int K;
  cin >> K;
  rep(i, K) {
    if (B <= A) B *= 2;
    else C *= 2;
  }
  bool bl = (A < B && B < C);
  puts(bl ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 3620
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 文字列の入力
    s <- getLine
    let h = head $ elemIndices 'A' s
        t = last $ elemIndices 'Z' s
    -- 出力
    putStrLn . show $ t - h + 1


Measured memory_bytes: 13820
#include<stdio.h>

int main(void){
    int h,w,i,j;
    i = 0;
    j = 0;
    while(1){
    scanf("%d %d",&h,&w);
        if(h == 0 && w == 0){
            break;
        }
        while(i < h){
            if(i % 2){
                while(j < w){
                        if(j % 2){
                            printf("#");
                        }else{
                            printf(".");
                        }
                        j++;
                }
            }else{
                while(j < w){
                        if(j % 2){
                            printf(".");
                        }else{
                            printf("#");
                        }
                        j++;
                }
            }
            j = 0;
            printf("\n");
            i++;
        }
        i = 0;
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 572
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left, bisect_right
N,K,C=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()

#左から
L=[]
over=-1
L_cnt=0
for i,x in enumerate(S):
    if x=="o" and over<i:
        L.append(i)
        L_cnt+=1
        if L_cnt==K: break
        over=i+C

#右から
R=[]
over=-1
R_cnt=0
for i,x in enumerate(S[::-1]):
    if x=="o" and over<i:
        R.append(N-1-i)
        R_cnt+=1
        if R_cnt==K: break
        over=i+C

L.sort()
R.sort()

for x,y in zip(L,R):
    if x==y:
        print x+1

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

typedef long long ll;

int n;
ll res;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    --n;
    res = 1LL * (1 + n) * n / 2;
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 3652
# A以上B以下の整数の個数から、Cの倍数の個数とDの倍数の個数を引いて最後にCとDの公倍数の個数を加える。
a, b, c, d = gets.split.map(&:to_i)

# A以上B以下の個数 all
all = b - a + 1

# B以下のCの倍数の個数
c_multiple_b_ika = b / c
# A未満のCの倍数の個数
c_multiple_a_miman = (a - 1) / c

# B以下のDの倍数の個数
d_multiple_b_ika = b / d
# A未満のDの倍数の個数
d_multiple_a_miman = (a - 1) / d

# CとDの最小公倍数
def gcd_of_two(a, b)
  small, large = [a, b].sort
  if small == 0
    return large
  else
    gcd_of_two(small, large % small)
  end
end

def lcm_of_two(a, b)
  gcd = gcd_of_two(a, b)
  return a * b / gcd
end

lcm = lcm_of_two(c, d)

# B以下の公倍数の個数
lcm_multiple_b_ika = b / lcm
# A未満の公倍数の個数
lcm_multiple_a_miman = (a - 1) / lcm

# 個数計算
puts all - (c_multiple_b_ika - c_multiple_a_miman) - (d_multiple_b_ika - d_multiple_a_miman) + (lcm_multiple_b_ika - lcm_multiple_a_miman)


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll s(ll x){
	if(x%10!=0) return (x/10+1)*10;
	else return x;
}
//a,b x
int main(){
	ll A,B,C,D,E; cin>>A>>B>>C>>D>>E;
  	cout<<s(A)+s(B)+s(C)+s(D)+s(E)-max(s(A)-A,max(s(B)-B,max(s(C)-C,max(s(D)-D,s(E)-E))));
}

Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    s = int(input())
    S.append(s)
sumS = sum(S)
if sumS % 10 != 0:
    print(sumS)
else:
    S = sorted(S)
    flag = 0
    for j in range(N):
        if S[j] % 10 != 0:
            print(sumS - S[j])
            flag = 1
            break
    if flag == 0:
        print(0)


Measured memory_bytes: 3060
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
const int inf = 0x3f3f3f3f;

int n, m, len;
char s[maxn], t[maxn];
int sd[5][maxn], td[5][maxn];
map<int, char> mp;

int main() {
   // freopen("in.txt", "r", stdin);
    mp[1] = 'L';
    mp[2] = 'R';
    mp[3] = 'U';
    mp[4] = 'D';
    cin >> n >> m >> len;
    int sx, sy;
    cin >> sx >> sy;
    cin >> (s + 1);
    cin >> (t + 1);
    for (int i = 1; i <= len; i++) {
        for (int j = 1; j <= 4; j++) {
            sd[j][i] = sd[j][i - 1] + (s[i] == mp[j] ? 1 : 0);
            td[j][i] = td[j][i - 1] + (t[i] == mp[j] ? 1 : 0);
        }

        while (td[2][i] - sd[1][i] >= m - sy + 1) {
            td[2][i]--;
        }
        while (td[1][i] - sd[2][i] >= sy) {
            td[1][i]--;
        }
        while (td[3][i] - sd[4][i] >= sx) {
            td[3][i]--;
        }
        while (td[4][i] - sd[3][i] >= n - sx + 1) {
            td[4][i]--;
        }
        if (sd[1][i] - td[2][i - 1] >= sy) {
            printf("NO\n");
            return 0;
        }
        if (sd[2][i] - td[1][i - 1] >= m - sy + 1) {
            printf("NO\n");
            return 0;
        }

        if (sd[3][i] - td[4][i - 1] >= sx) {
            printf("NO\n");
            return 0;
        }
        if (sd[4][i] - td[3][i - 1]>= n - sx + 1) {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

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

typedef long long ll;

const int N = 5001;
int n, k;
int a[N];
bool dp[N];

bool check(int x) {
    if (a[x] >= k) return true;
    memset(dp, 0, sizeof dp);
    dp[0] = true;
    for (int i = 0; i < n; ++i) {
        if (i == x) continue;
        for (int j = k - 1; j > 0; --j) {
            if (j >= a[i] && dp[j - a[i]]) {
                dp[j] = true;
            }
        }
    }
    for (int i = k - a[x]; i < k; ++i) {
        if (dp[i]) {
            return true;
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum < k) {
        cout << n << endl;
        exit(0);
    }
    sort(a, a + n);
    int l = 0, r = n - 1;
    while (l < r) {
        int m = (r - l) / 2 + l;
        if (check(m))
            r = m;
        else
            l = m + 1;
    }
    cout << l << endl;

    return 0;
}



Measured memory_bytes: 3604
import java.util.*;
import java.io.*;
@SuppressWarnings("unchecked")
class Main {
	static LinkedList<Integer>[] graph;

	public static void solve(int n){
		int[] distance = new int[n];
		int[] marks = new int[n];
		Queue<Integer> q = new LinkedList<>();
		q.add(1);
		while(!q.isEmpty()){
			int poll = q.poll();
			for(int child : graph[poll]){
				if(distance[child] == 0){
					distance[child] = distance[poll]+1;
					marks[child] = poll;
					q.add(child);
				}
			}
		}		

		//System.out.print(Arrays.toString(distance));
	 System.out.println("Yes");
    for(int i = 2; i < marks.length; i++){
      System.out.println(marks[i]);
    }

	}


	public static void main(String[] args) throws Exception {
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     	 String[] in = br.readLine().trim().split(" ");
		int n = Integer.parseInt(in[0]);
		n = n+1;
		int e = Integer.parseInt(in[1]);
		graph = new LinkedList[n];
		for(int i = 0; i < n; i++)
			graph[i] = new LinkedList<Integer>();



		for(int i = 0;i<e;i++){
			in = br.readLine().trim().split(" ");
			int a = Integer.parseInt(in[0]);
			int b = Integer.parseInt(in[1]);
			graph[a].add(b);
			graph[b].add(a);


}
	
          solve(n);


   

	}
}

Measured memory_bytes: 77092
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] hw = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long w = (long)Math.Ceiling((double)hw[1] / 2);
            long h = hw[0];
            long res;
            if (hw[0] == 1 || hw[1] == 1)
            {
                res = 1;
            }
            else if (h % 2 == 0)
            {
                res = hw[1] * (h / 2);
            }
            else
            {
                res = hw[1] * (h / 2) + w;
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int N;
int A[20], B[20], C[20];
int ans = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)		cin >> A[i];
	for (int i = 0; i < N; i++)		cin >> B[i];
	for (int i = 0; i < N-1; i++)		cin >> C[i];
	
	int temp = 22;
	for (int i = 0; i < N; i++)
	{
		if (A[i] == temp+2) ans += C[temp];
		ans += B[A[i] - 1];
		temp = A[i] - 1;
	}

	cout << ans;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<vector<pair<int, int> > > vii;
//vector<pii> vii;
vector<pll> vll;
//vii.clear();
//vii.resize(n + 1);


int arr[maxii];
int arr2[maxii];
bool check[maxii];
bool check2[1000][1000];
int n,m;
int x[]={1,-1,0,0};
int y[]={0,0,-1,1};
int x2[]={1,-1,0,0,1,-1,1,-1};
int y2[]={0,0,-1,1,1,-1,-1,1};
int bx[]={0,0,1,-1,-1,1,1,-1};
int by[]={1,-1,0,0,-1,-1,1,1};
int kx[] = {1,1,2,2,-1,-1,-2,-2};
int ky[] = {2,-2,1,-1,2,-2,1,-1};

bool isvisited(int xx,int yy)
{
    if(xx<1 || yy<1 || xx>n ||yy>m)
    {
        return false;
    }
    else if(check2[xx][yy]==true)
    {
        return false;
    }
    else return true;
}
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
   sc(n)
   for(int i=1;i<=n;i++)
   {
       sc(arr[i])
       sc(arr2[i])
   }
   int c=0;
   for(int i=1;i<=n-2;i++)
   {
       if(arr[i]==arr2[i] && arr[i+1]==arr2[i+1] && arr[i+2]==arr2[i+2])
       {
           c=1;
           break;
       }
   }
   if(c==1)
   {
       printf("Yes");
   }
   else cout<<"No";
}






Measured memory_bytes: 3840
#include <iostream>
using namespace std;
int main(){
  long N, sum=0, a, NN, b, waru=10;
  cin>>N;
  NN=N;
  while(N!=0){
    a=N%waru;
    N-=a;
    b=a*10/waru;
    sum+=b;
    waru*=10;
  }
  if(NN%sum==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
c=0
n=int(input())
l=list(map(int, input().split()))
for i in range(n-1):
    m=i
    for j in range(i,n):
        if l[j] < l[m]:
            m=j
    if i != m:
        t=l[i]
        l[i]=l[m]
        l[m]=t
        c+=1
print(*l)
print(c)

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
 
  if ((x/10)%111 == 0) {
    cout << "Yes" << endl;
  }
  
  else if ((x-(x/1000)*1000)%111 == 0){
    cout << "Yes" << endl;
  }
  
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int N;
	cin>>N;
	int M;
	cin>>M;
	
	vector<vector<pair<int,int>>> E(N,vector<pair<int,int>>());
	vector<int> jisuu(N,0);
	for(int i=0;i<M;i++){
		int l,r,d;
		cin>>l>>r>>d;
		l--;r--;
		E[l].emplace_back(r,d);
		jisuu[r]++;
	}
	
	vector<int> V;
	
	queue<int> Q;
	for(int i=0;i<N;i++){
		if(jisuu[i]==0){
			Q.push(i);
		}
	}
	
	while(Q.size()!=0){
		int from = Q.front();
		V.push_back(from);
		Q.pop();
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i].first;
			jisuu[to]--;
			if(jisuu[to]==0){
				Q.push(to);
			}
		}
	}
	
	if(V.size()!=N){
		cout<<"No"<<endl;
		return 0;
	}
	
	vector<int> x(N,-1);
	
	for(int i=0;i<N;i++){
		int now = V[i];
		if(x[now]==-1)x[now]=0;
		for(int j=0;j<E[now].size();j++){
			int to = E[now][j].first;
			int d = E[now][j].second;
			if(x[to]==-1){
				x[to] = x[now] + d;
			}
			else{
				if(x[to]!=x[now]+d){
					cout<<"No"<<endl;
					return 0;
				}
			}
		}
	}
	
	cout<<"Yes"<<endl;
	
		
    return 0;
}


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

using namespace std;

#define int long long

void solve() {
    string s;
    cin >> s;
    if (s.size() % 2) {
        cout << "No";
        return;
    }
    for (int i = 0; i < s.size(); i += 2) {
        if (s[i] != 'h' || s[i + 1] != 'i') {
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int P[10010];

int root(int a){
    if (P[a] == a) return a;
    return (P[a] = root(P[a]));
}

bool is_same_set(int a, int b){
    return root(a) == root(b);
}

void unite(int a, int b){
    P[root(a)] = root(b);
}

int main(){
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N; i++){
        P[i] = i;
    }
    for(int k = 0; k < Q; k++){
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0){
            unite(x, y);
        }else if(com == 1){
            if(is_same_set(x, y)) cout << "1" << endl;
            else cout << "0" << endl;
        }
    }
}

Measured memory_bytes: 3208
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
import sys
import itertools


def solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    ans = 0
    for A in itertools.combinations_with_replacement(range(1, M+1), N):
        ans = max(sum([d[i]
                       for i in range(Q) if A[b[i]]-A[a[i]] == c[i]]), ans)
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (Q)  # type: "List[int]"
    b = [int()] * (Q)  # type: "List[int]"
    c = [int()] * (Q)  # type: "List[int]"
    d = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        a[i] = int(next(tokens)) - 1
        b[i] = int(next(tokens)) - 1
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68592
import sys
input = sys.stdin.readline
from collections import Counter

N=int(input())
A=Counter(list(map(int,input().split())))
x=[0,0]
for a in A:
    if A[a]>1:x.append(a)
    if A[a]>3:x.append(a)
x.sort()
print(x[-1]*x[-2])

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    set<int> se;
    for (int i = 0; i < N; i++) {
        cin >> d[i];
        se.insert(d[i]);
    }
    cout << se.size() << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<deque>
 
using namespace std;
typedef long long ll;

bool isOK(vector<ll> __p)
{
    if(__p[0] == __p[1])
    {
        if (__p[1] > __p[2])
        {
            return true;
        }
    }
    else if(__p[0] < __p[1])
    {
        if(__p[1] <= __p[2])
        {
            return true;
        }
    }
    else
    {
        if(__p[1] > __p[2])
        {
            return true;
        }
    }
    
    return false;
}
 
int main(void)
{
    int n;
    cin >> n;

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

        if(i >= 2)
        {
            vector<ll> __p(3);
            __p[0] = p[i - 2];
            __p[1] = p[i - 1];
            __p[2] = p[i];
            _p.push_back(__p);
        }
    }

    int ans = 0;

    for(vector<ll> __p : _p)
    {
        if(isOK(__p))
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String n = scan.next();
		int ans = 0;
		for(int i = 0;i < n.length(); ++i){
			int x = n.charAt(i)-'0';
			ans += x;
			ans %= 9;
		}
		System.out.print(ans==0?"Yes":"No");

	}
}


Measured memory_bytes: 40324
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

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

  vector<int64_t> P(N);
  for (int64_t n = 0; n < N; ++n) {
    cin >> P[n];
    --P[n];
  }
  vector<int64_t> C(N);
  for (int64_t n = 0; n < N; ++n) {
    cin >> C[n];
  }
  int64_t res = -1000000001;
  for (int64_t n = 0; n < N; ++n) {
    int64_t i = n;
    int64_t sum = 0;
    vector<int64_t> sums;
    while (true) {
      i = P[i];
      sum += C[i];
      sums.push_back(sum);
      if (i == n) break;
    }
    for (size_t j = 0; j < sums.size(); ++j) {
      if (K < j + 1) break;
      int64_t loop = (K - j - 1) / sums.size();
      if (sum < 0) {
        res = max(res, sums[j]);
      } else {
        res = max(res, loop * sum + sums[j]);
      }
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3812
import java.util.Scanner;

//public class atcoder0221_A{
public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int result = 0;
		//
		result = N/2;
		if(N%2==1)result++;
		System.out.println(result);
	}
}

Measured memory_bytes: 23764
#include<stdio.h>

int main(){
	int a,b,n_1,sum,ans;
	scanf("%d %d",&a,&b);
	n_1 = (b-a);
	sum = (n_1-1)*(n_1)/2;
	ans = sum - a;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
def main():
    N = int(input())
    txy = [[0,0,0]] + [[int(i) for i in input().split()] for j in range(N)]
    for i in range(1,N+1):
        cur_distance = abs(txy[i][1] - txy[i-1][1]) + abs(txy[i][2] - txy[i-1][2])
        t_diff = txy[i][0] - txy[i-1][0]
        if t_diff < cur_distance or t_diff%2 != cur_distance%2:
            print("No")
            break
    else:
        print("Yes")
if __name__ == '__main__':
    main()

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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int i=1;
    while(true){
        if(a<=0){
            puts("No");
            break;
        }else if(c<=0){
            puts("Yes");
            break;
        }
        if(i%2==0){
            a-=d;
        }else{
            c-=b;
        }
        i++;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 998244353
#define bit(x) (1 << x)
#define par pair<int,int>
#define maxn 4005

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

ll a,Dp[maxn],sol,N,S;

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> S;

    for(int i=1;i<=N;i++){
        cin >> a;
        for(int j=S;j>=a;j--)
            Dp[j]=(Dp[j] + Dp[j-a])%mod;
        Dp[a]=(Dp[a]+i)%mod;
        sol=(sol+Dp[S])%mod;
    }

    cout << sol;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<string,ll> pll;
typedef pair<pll,pll> ppll;
typedef vector <pll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

int main(){
	FAST;
    ll n, k, m, z = 0, x, y, ans = 0, j, t = 0, c = 0, i;
    cin >> n ;
    string s;
    vi v;
    for ( i = 0 ; i < n ; i ++ ){
    	cin >> s >> x;
    	v.pb({s , x});
    }
    cin >> s;
    for ( i = n - 1 ; i >= 0 ; i -- ){
    	if ( v[i].ff == s ) break;
    	ans += v[i].ss;
    }
    cout << ans;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int[][] b = new int[3][3];
        String ans="No";
        
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                b[i][j] = sc.nextInt();
            }
        }
        
        int n = sc.nextInt();
        int[] a = new int[n];
        
        for(int k=0; k<n; k++){
            a[k] = sc.nextInt();
            for(int i=0; i<3; i++){
                for(int j=0; j<3; j++){
                    if(b[i][j]==a[k]){
                        b[i][j]=0;
                    }
                }
            }
        }
        
        if(b[0][0]==0 && b[0][1]==0 && b[0][2]==0){
            ans="Yes";
        }
        if(b[1][0]==0 && b[1][1]==0 && b[1][2]==0){
            ans="Yes";
        }
        if(b[2][0]==0 && b[2][1]==0 && b[2][2]==0){
            ans="Yes";
        }
        if(b[0][0]==0 && b[1][0]==0 && b[2][0]==0){
            ans="Yes";
        }
        if(b[0][1]==0 && b[1][1]==0 && b[2][1]==0){
            ans="Yes";
        }
        if(b[0][2]==0 && b[1][2]==0 && b[2][2]==0){
            ans="Yes";
        }
        if(b[0][0]==0 && b[1][1]==0 && b[2][2]==0){
            ans="Yes";
        }
        if(b[0][2]==0 && b[1][1]==0 && b[2][0]==0){
            ans="Yes";
        }
        
        System.out.println(ans);
        
	}
}


Measured memory_bytes: 35696
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  ll ans=0,mx=a[0];
  for(int i=1;i<n;i++)
  {
    if(a[i]>mx)
      mx=a[i];
    else
      	ans+=(mx-a[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5156
n = int(input())
a = list(map(int, input().split()))

cnt = [0] * ((10 ** 6) + 1)

for elem in a:
    cnt[elem] += 1

unique = []

for i in range((10 ** 6) + 1):
    if cnt[i] == 1:
        unique.append(i)

cnt = [0] * ((10 ** 6) + 1)

a = list(set(a))

for elem in a:
    for m in range(elem * 2, (10 ** 6) + 1, elem):
        cnt[m] = 1

ans = 0
        
for elem in unique:
    if cnt[elem] == 0:
        ans += 1

print(ans)

Measured memory_bytes: 48028
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	map<int, int> mp;
	int N, tmp;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		mp[tmp]++;
	}

	int ans = 0;
	for (const auto &e : mp) {
		if (e.first > e.second) ans += e.second;
		else ans += e.second - e.first;
	}

	cout << ans << "\n";
	return 0;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9


int main(){
  ll H;
  cin >> H;
  int bit = 0;
  REP(i, 63){
    if(H >> i & 1){
      bit = i;
    }
  }
  ll ans = 1;
  REP(i, bit+1){
    ans *= 2;
  }
  cout << ans - 1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
int A[MAXN];
int F[MAXN];
int G[MAXN];
int K, N;

int fpm(int b, int e) {
  int p = 1;
  while (e) {
    if (e & 1) {
      p = 1LL * p * b % MOD;
    }
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return p;
}

int inv(int x) { return fpm(x, MOD-2); }

void init() {
  F[0] = 1;
  G[0] = 1;
  for (int i = 1; i <= N; ++i) {
    F[i] = 1LL * F[i-1] * i % MOD;
    G[i] = inv(F[i]);
  }
}

int ncr(int n, int r) {
  if (r > n) return 0;
  if (r == 0) return 1;
  return 1LL * F[n] * G[r] % MOD * G[n-r] % MOD;
}

int pick(int i, int cur, int cnt) {
  int end = std::min(cur, K);
  int sum = 0;
  for (int k = 1; k <= end; ++k) {
    int mul = 1LL * ncr(cur, k) * ncr(cnt, K - k) % MOD; 
    int val = 1LL * A[i] * mul % MOD;
    if (val < 0) val += MOD;
    sum = (1LL * sum + val) % MOD;
  }
  return sum;
}

int main() {
  scanf(" %d%d", &N, &K);
  init();
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  std::sort(A, A+N);
  // Maximum
  int cnt = 0;
  int ret = 0;
  for (int i = 0; i < N; ) {
    int j = i;
    while ((j < N) && (A[j] == A[i])) ++j;
    int cur = j - i;
    ret = (1LL * ret + pick(i, cur, cnt)) % MOD;
    cnt += cur;
    i = j;
  }
  // Minimum
  cnt = 0;
  for (int i = N-1; i >= 0; ) {
    int j = i;
    while ((j >= 0) && (A[j] == A[i])) --j;
    int cur = i - j;
    ret = (1LL * ret - pick(i, cur, cnt) + MOD) % MOD;
    cnt += cur;
    i = j;
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 1536
def count_div(n):
    c = 0
    while n % 2 == 0 and n > 1:
        c += 1
        n = n / 2
    return c


if __name__ == '__main__':
    maximum = (0, 0)
    for i in range(int(input()), 0, -1):
        current = count_div(i)
        if current >= maximum[0]:
            maximum = (current, i)
    print(maximum[1])

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a+b+c-max({a,b,c})<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
const int N=105;
int even[N],odd[N],n,m,ev,od,ans;
int main()
{
	cin>>n>>m;
	ans+=max(0,n*(n-1)/2)+max(0,m*(m-1)/2);
	cout<<ans;
    return 0;
}


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

int main() {
  int k, s;
  cin >> k >> s;
  
  int count = 0;
  for (int i=0; i<=k; i++) {
    for (int j=0; j<=k; j++) {
      int l = s - (i + j);
      if (0 <= l && l <= k) count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 3604