akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		long p=0;
		for(int i = 1;;i++) {
			p+=s[1];
			if(p>=s[0]){
				Console.WriteLine(i*s[2]);
				return;
			}
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> x(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    int ans = 0;
    for (int i = 0; i < 2 * n; i += 2) {
        ans += x[i];
    }

    cout << ans << endl;

}

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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> snk(n);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            a--;
            snk[a]++;
        }
    }
    int ans = 0;
    rep(i, n) {
        if (snk[i]==0)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
N = gets.to_i
as = gets.split.map(&:to_i)
sums = Array.new(N)
sum_table = {}
sum = 0
as.each.with_index do |a, i|
  sum += a
  sums[i] = sum
  sum_table[sum] ||= []
  sum_table[sum].push(i)
end

ans = 0
prev_sum = 0
sums.each.with_index do |sum, i|
  indexes = sum_table[prev_sum]
  prev_sum = sum
  next unless indexes
  j = indexes.bsearch_index do |j|
    i <= j
  end
  next unless j
  ans += indexes.size - j
end
puts ans


Measured memory_bytes: 38660
ans = []

while True:
  cin = raw_input().split()
  a = int(cin[0])
  b = int(cin[2])
  if cin[1] == "+":
    ans.append(a + b)
  elif cin[1] == "-":
    ans.append(a - b)
  elif cin[1] == "*":
    ans.append(a * b)
  elif cin[1] == "/":
    ans.append(a // b)
  elif cin[1] == "?":
    break

for i in range(len(ans)):
  print(ans[i])

Measured memory_bytes: 6444
#include <iostream>
#include <vector>
#include <algorithm>
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;

typedef long long ll;

struct Q{
    Q(int p, int q): p(p), q(q){}

    int p, q;
};

Q sub(Q x, Q y){
    int a = x.p * y.q - y.p * x.q;
    int b = x.q * y.q;
    return Q(a, b);
}

int p, q, a, n;
int ans;

void dfs(Q x, int t, int b, int m){
    if(x.p == 0){
        ++ans;
        return;
    }
    if(m == n){
        return;
    }
    int k = max((x.q + x.p - 1) / x.p, t);
    while(ll(k) * b <= a){
        dfs(sub(x, Q(1, k)), k, k * b, m + 1);
        ++k;
    }
}

int main(){
    while(1){
        cin >> p >> q >> a >> n;
        
        if(!p){
            break;
        }

        ans = 0;
        dfs(Q(p, q), 1, 1, 0);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

struct UnionFind {
	vector<int> par, rank;
	vector<int> cnt;
	
	UnionFind(int n) {
		par.resize(n);
		rank.resize(n);
		cnt.resize(n);
		REP(i, n) {
		 par[i] = i;
		 rank[i] = 0;
		 cnt[i] = 1;
		}
	}
	
	int operator[] (int x) {
		return find(x);
	}
	
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		
		if (rank[x] < rank[y]) swap(x, y);
		
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	
	int size(int x) {
		return cnt[find(x)];
	}
	
};

int N, M;
int A[112345], B[112345];
ll ans[112345];

int main() {
	cin >> N >> M;
	REP(i, M) scanf("%d %d", A + i, B + i), A[i]--, B[i]--;
	
	UnionFind uf(N);
	
	ll cur = (ll)N * (N - 1) / 2;
	
	for (int i = M - 1; i >= 0; i--) {
		ans[i] = cur;
		if (uf[A[i]] != uf[B[i]]) {
			cur -= uf.size(A[i]) * uf.size(B[i]);
			uf.unite(A[i], B[i]);
		}
	}
	
	REP(i, M) printf("%lld\n", ans[i]);
	
	
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <cmath>

int main() {
    int N, A, B;
    std::cin >> N >> A >> B;

    auto result = 0;

    for (int i = 1; i <= N; ++i) {
        auto value = i;
        auto sum = 0;

        for (int j = 5; j >= 0; --j) {
            auto base = static_cast<int>(std::pow(10, j));

            if (value >= base) {
                auto digit = value / base;
                sum += digit;
                value -= digit * base;
            }

            if (sum > B) {
                goto EXIT_SUM;
            }
        }

        if (sum >= A) {
            result += i;
        }

        EXIT_SUM:
        continue;
    }

    std::cout << result << std::endl;

    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
long long  INF=1'0000'0000'0000'0000'00;
long long  mod=10'0000'0007;
using namespace std;


long long stairs(int n){
long long i=1;
while(n>0){
i=i*n;
if(i>mod){
    i%=mod;
}
n-=1;
}
return i;
}
int main(){

int N,M;
cin >> N>>M;
long long ans=0;
if(abs(N-M)>=2){
    cout<<ans<<endl;
    return 0;
}
else if(abs(M-N)==1){
    if(M<N){
    ans=N*stairs(N-1);
    if(ans>=mod){
        ans%=mod;
    }
    ans*=stairs(N-1);
    if(ans>=mod){
        ans%=mod;
    }
    cout<<ans<<endl;
    }

    else{
        ans=M*stairs(M-1);
    if(ans>=mod){
        ans%=mod;
    }
    ans*=stairs(M-1);
    if(ans>=mod){
        ans%=mod;
    }
    cout<<ans<<endl;
    }
}

else if(M==N){
    ans=2*stairs(N);
    if(ans>=mod){
        ans%=mod;
    }
    ans*=stairs(N);
    if(ans>=mod){
        ans%=mod;
    }
    cout<<ans<<endl;
}
   

 return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    char a, b;
    cin >> a >> b;
    if(a == 'H'){
        if(b == 'H') cout << 'H' << endl;
        else cout << 'D' << endl;
    }
    else{
        if(b == 'H') cout << 'D' << endl;
        else cout << 'H' << endl;        
    }

    return 0;
}

Measured memory_bytes: 3624
from functools import reduce
def comb(n, max_k, mod):
    """
    (n,k) := n個からk個選ぶ組み合わせ
    k = 0~max_Kまでを計算して返す
    """
    res = [1]*(max_k+1)
    t = 1
    for i in range(max_k+1):
        res[i] *= t
        t *= n-i
        t %= mod

    n = reduce(lambda x,y: (x*y)%mod, range(1,max_k+1), 1)
    n = pow(n,-1, mod)

    for i in reversed(range(max_k+1)):
        res[i] *= n
        res[i] %= mod
        n *= i
        n %= mod
    return res

MOD = 10**9+7

def resolve():
    K = int(input())
    N = len(input())
    res = 0
    x = 1
    com = comb(N+K, K , MOD)

    for c in com:
        res += x*c
        res %= MOD
        x *= 25
        x %= MOD
    print(res)
resolve()

Measured memory_bytes: 48920
def main():
    A, B, C, D = [int(i) for i in input().split()]

    max_start = max(A, C)
    min_finish = min(B, D)
    t_sub = min_finish - max_start
    
    if(t_sub < 0):
        print(0)
    else:
        print(t_sub)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int maxn=50;
const long long maxl=1000000000;
long long sx=maxl+1,bx=-maxl-1,sy=maxl+1,by=-maxl-1;
long long x[maxn+1],y[maxn+1];
int n,k;
long long ans=(maxl*2+1)*(maxl*2+1);
void dfs(int p,int c){
	if(c+n-(p-1)<k)return;
	long long ar=(bx-sx)*(by-sy);
	if(c>0&&ar>=ans)return;
	if(p==n+1){
		ans=min(ans,ar);
		return;
	}
	//point p not chosen
	dfs(p+1,c);
	
	//point p chosen
	long long _sx=sx,_bx=bx,_sy=sy,_by=by;
	sx=min(sx,x[p]);bx=max(bx,x[p]);
	sy=min(sy,y[p]);by=max(by,y[p]);
	dfs(p+1,c+1);
	sx=_sx;bx=_bx;sy=_sy;by=_by;
}
	
int main(int argc,char *argv[]){
	if(argc>=2){freopen(argv[1],"r",stdin);}
	if(argc>=3){freopen(argv[2],"w",stdout);}
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)scanf("%lld%lld",&x[i],&y[i]);
	dfs(1,0);
	printf("%lld",ans);
	fclose(stdin);fclose(stdout);
	return 0;
}

Measured memory_bytes: 256
words = input().split()
word2count={}
maxlength = 0
maxlengthword=None
for word in words:
    word2count[word] = word2count.get(word, 0) + 1
    if maxlength < len(word):
        maxlength = len(word)
        maxlengthword = word

print(sorted(word2count.items(), key=lambda x: -1*x[1])[0][0],maxlengthword)

Measured memory_bytes: 7428
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        int n, k;
        BufferedReader br =
                new BufferedReader (new InputStreamReader (System.in));
        String[] line1 = br.readLine().split(" ");
        n = Integer.parseInt(line1[0]);
        k = Integer.parseInt(line1[1]);
        int[] h = new int[n];
        String[] line2 = br.readLine().split(" ");
        for(int i = 0; i < line2.length; i++){
            h[i] = Integer.parseInt(line2[i]);
        }
        int[] result = new int[n];
        result[0] = 0;
        for(int i = 1; i < n; i++){
            int min = result[i - 1] + Math.abs(h[i] - h[i - 1]);
            if(i >= 2){
                for(int j = Math.max(0, i - k); j < i; j++) {
                    int temp = result[j] + Math.abs(h[i] - h[j]);
                    if(min > temp){
                        min = temp;
                    }
                }
            }
            result[i] = min;
        }
        System.out.println(result[n - 1]);
    }


}


Measured memory_bytes: 35812
#include <bits/stdc++.h>
using namespace std;
int depth, width, height;
double a, b;

bool judge(int rad) {
    return(rad > sqrt(a+b));
}

int main(void) {
    while(cin >> depth >> width >> height, depth|(width|height)) {
        a = (width*width / 4.0);
        b = (height*height / 4.0);
        int num; cin >> num;
        for(int r = 0; r < num; r++) {
            int input; cin >> input;
            puts((judge(input)) ? "OK":"NA");
        }
    }
    return(0);
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define DIM (long long)3007
#define INF (long long)100000007

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pairll;

ll n,m,i,j,k,sum,f1,f2,v1,v2;
ld a[DIM];
ld dp[DIM][DIM],res;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    for(i=1; i<=n; i++){
        cin >> a[i];
    }
    dp[1][1]=a[1];
    dp[1][0]=1-a[1];

    for(i=2; i<=n; i++){
        for(j=0; j<=n; j++){
            if(j) dp[i][j]=dp[i-1][j-1]*a[i];
            if(i>j) dp[i][j]+=dp[i-1][j]*(1-a[i]);
        }
        cout << endl;
    }
    for(i=n/2+(n%2); i<=n; i++) res+=dp[n][i];
    cout << fixed << setprecision(10) << res << endl;








    return 0;
}


Measured memory_bytes: 141568
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  ll x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

const long double PI=3.14159265359;
 
 
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll a,b,x;
  std::cin>>a>>b>>x;

  ll max=a*a*b;

  long double as=a,bs=b,xs=x;

  long double xl;
  long double yl;

  if(2*x<=max){
    xl=((2*xs)/as)/bs;
    yl=b;
  }else{
    yl=(2*(max-xs)/(as*as));
    xl=a;
  }

  long double arc=atan2l(yl,xl);

  std::cout<<std::setprecision(10)<<std::fixed<<(arc/PI)*180;
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

int main(){
	int i,j,k,l,a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
    // a = health, b = strength
    i = (a-1)/d;
    a -= d*i;
    c -= b*i;
    if(c <= b) printf("Yes");
    else printf("No");
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 3724
main = do
    str <- getLine
    let y = read ( take 4 str ) :: Int
    let m = read ( take 2 ( drop 5 str ) ) :: Int
    let d = read ( take 2 ( drop 8 str ) ) :: Int
    let f = (y<=2019)&&(m<=4)&&(d<=30)
    putStr (if f then "Heisei" else "TBD")

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

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Array.Sort(a);
        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            ans += a[3 * n - 2 * (n - i)];
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 40396
class Card {
  constructor(mark, value) {
    this.mark = String(mark);
    this.value = Number(value);
  }

  equals(other) { return this.value === other.value && this.mark === other.mark; }

  compareTo(other) {
    if (this.value === other.value) return 0;
    else if (this.value < other.value) return -1;
    else return 1;
  }

  toString() { return `${this.mark} ${this.value}` }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  let arr = lines.map(r => r.split(' ')).map(c => new Card(c[0], c[1]));
  const quick_arr = Array.from(arr);

  quickSort(quick_arr, 0, n - 1);
  arr = arr.map((e, idx) => ({val: e, idx: idx}))
      .sort((a, b) => a.val.compareTo(b.val) || a.idx - b.idx)
      .map(e => e.val);

  console.log(arr.every((card, i) => card.equals(quick_arr[i]))
      ? 'Stable' : 'Not stable');
  console.log(quick_arr.join('\n'));
})();

function quickSort(arr, p, r) {
  const partition = function(arr, p, r) {
     let x  = arr[r];
     let i = p - 1;
     for (let j = p; j < r; j++) {
       if (arr[j].compareTo(x) <= 0) {
         i++;
         [arr[i], arr[j]] = [arr[j], arr[i]];
       }
     }
     [arr[i + 1], arr[r]] = [arr[r], arr[i + 1]];
     return i + 1;
  }

  quickSort = function(arr, p, r) {
    if (p < r) {
      let q = partition(arr, p, r);
      quickSort(arr, p, q - 1);
      quickSort(arr, q + 1, r);
    }
  }
  quickSort(arr, p, r);
}



Measured memory_bytes: 75596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-9;
const int inf=2e9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
ll dp[4010][4010],MOD=1000000007;
// a^b mod MOD
ll powmod(ll a,ll b){
	ll out=1;
	ll p=a%MOD;
	while(b){
		if(b&1)out=out*p%MOD;
		p=p*p%MOD;
		b>>=1;
	}
	return out;
}
#define M 10000
vector<ll> fact;
void init(){
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// nCr
ll nCr(ll n,ll r){
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%MOD,MOD-2)%MOD;
	return out;
}	
int main(){
	init();
	int n;
	cin>>n;
	vp in(n);
	rep(i,n)cin>>in[i].first>>in[i].second;
	rep(i,n)dp[-in[i].first+2005][-in[i].second+2005]++;
	rep(i,4009)rep(j,4009)(dp[i+1][j+1]+=dp[i+1][j]+dp[i][j+1])%=MOD;
	ll out=0;
	rep(i,n)(out+=dp[in[i].first+2005][in[i].second+2005])%=MOD;
	rep(i,n)(out+=MOD-nCr(2*(in[i].first+in[i].second),2*in[i].first))%=MOD;
	cout<<out*powmod(2,MOD-2)%MOD<<endl;
}












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

using namespace std;

using ll = long long;

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

    string t;
    cin >> t;

    ll sum = 0;
    for (int i = 0; i < n; i++) {
        if (i - k >= 0 && t[i - k] != 'x' && t[i - k] == t[i]) {
            t[i] = 'x';
            continue;
        }
        switch(t[i]) {
            case 'r' : sum += p; break;
            case 's' : sum += r; break;
            case 'p' : sum += s; break;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);
		int n = r.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = r.nextInt();
		}
		int res = Integer.MAX_VALUE;
		for (int x = -100; x <= 100; x++) {
			int cost = 0;
			for (int i = 0; i < arr.length; i++) {
				cost += (arr[i] - x) * (arr[i] - x);
			}
			res = Math.min(res, cost);
		}
		System.out.println(res);
	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public InputReader(FileReader stream) {
			reader = new BufferedReader(stream);
			tokenizer = null;
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

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

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

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 7764
def f(k):
    if k == 1:
        return [[0],[1]]
    else:
        h = f(k-1)
        h_plus = [hi + [0] for hi in h]
        h_minus = [hi + [1]for hi in h]
        return h_plus + h_minus

def count(select_h,select_w,hw):
    chw = hw.copy()
    count = 0
    for i,si in enumerate(select_h):
        for j,sj in enumerate(select_w):
            if not(si or sj):
                count += chw[i][j]
    return count

H,W,K = map(int,input().split( ))
hw = [list(str(input())) for _ in range(H)]
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
             hw[h][w] = 1
        else:
            hw[h][w] = 0

select_hs = f(H)
select_ws = f(W)
ans = 0
for select_h in select_hs:
    for select_w in select_ws:
        if count(select_h,select_w,hw) == K:
            ans += 1
print(ans)

Measured memory_bytes: 9256
from sys import stdin, setrecursionlimit
from collections import deque

setrecursionlimit(10 ** 9)


def input():
    return stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    s = [input() for _ in range(H)]

    gx, gy = H - 1, W - 1
    q = deque([(0, 0)])
    dist = [[-1] * W for _ in range(H)]
    dist[0][0] = 1

    while q:
        x, y = q.popleft()
        if x == gx and y == gy:
            break

        for dx, dy in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            nx, ny = x + dx, y + dy
            if 0 <= nx < H and 0 <= ny < W and dist[nx][ny] == -1 and s[nx][ny] == '.':
                q.append((nx, ny))
                dist[nx][ny] = dist[x][y] + 1

    if dist[gx][gy] == -1:
        print(-1)
    else:
        ans = sum(row.count('.') for row in s) - dist[gx][gy]
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int x,y,n,q,t;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t>>x>>y;
		if((t<x+y)||((x+y)%2!=t%2)){
			cout<<"No"<<endl;
			return 0;
		}
	}
    cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;



int main() {
	string t = "ACGT";
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		for (int j = i; j < s.size(); j++) {
			bool f = false;
			for (int p = 0; p < 4; p++) {
				if (s[j] == t[p])f = true;
			}
			if (f)ans = max(ans, j - i + 1);
			else break;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,q = map(int,input().split())
s = list(input())
check = [0]*n
const = 0
for i in range(n-1):
    check[i] = const
    if s[i] == 'A' and s[i+1] == 'C':
        check[i+1] = const + 1
        const += 1
        i += 1
check[-1] = const
for i in range(q):
    l,r = map(int,input().split())
    print(check[r-1]-check[l-1])


Measured memory_bytes: 56440
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define foreach(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define all(c) begin(c),end(c)
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

string tostr(int x)
{
	ostringstream oss; oss<<x;
	return oss.str();
}

bool isbrace(char c)
{
	return c=='[' || c==']';
}

void solve()
{
	string s; cin>>s;
	for(int j=s.find("]]");j!=-1;j=s.find("]]",j+1)){
		int i=s.rfind("[[",j)+1;
		replace_if(begin(s)+i,begin(s)+j+1,isbrace,' ');
		
		vi a;
		istringstream iss(s.substr(i,j+1-i));
		for(int k;iss>>k;) a.push_back(k);
		sort(all(a));
		
		fill(begin(s)+i,begin(s)+j+1,' ');
		
		int x=0;
		rep(k,(a.size()+1)/2) x+=(a[k]+1)/2;
		string t=tostr(x*2-1);
		copy(all(t),begin(s)+i);
	}
	
	replace_if(all(s),isbrace,' ');
	int res=(atoi(s.c_str())+1)/2;
	cout<<res<<endl;
}

int main()
{
	int tc; cin>>tc;
	rep(_,tc) solve();
}

Measured memory_bytes: 1332
n,m,l = map(int,input().split())

a=[]
for i in range(n):
    array_a=list(map(int,input().split()))
    a.append(array_a)

b=[]
for j in range(m):
    array_b=list(map(int,input().split()))
    b.append(array_b) 

C=[]
for k in range(n):
    line=[]
    for s in range(l):
        c=0
        for t in range(m):
            c+=a[k][t]*b[t][s]
        line.append(c)
    C.append(line)

for line in C:
    print(*line)


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

int N,W,H;

int main(){
    cin >> N >> W >> H;
    vector<int> X(H+2,0),Y(W+2,0);
    int x,y,w;
    for(int i=1;i<=N;i++){
        cin >> x >> y >> w;
        X[max(y-w,0)]++; X[min(y+w,H+1)]--;
        Y[max(x-w,0)]++; Y[min(x+w,W+1)]--;
    }
    bool ok1 = true;
    for(int i=0;i<=H-1;i++){
        if(X[i]==0) ok1 = false;
        X[i+1] += X[i];
    }
    bool ok2 = true;
    for(int i=0;i<=W-1;i++){
        if(Y[i]==0) ok2 = false;
        Y[i+1] += Y[i];
    }
    cout << ((ok1 || ok2)? "Yes":"No") << endl;
}


Measured memory_bytes: 3632
import math
 
N = int(input())
mod = 10**9+7
 
def get_primes(n):
    ps = [0, 0] + [i for i in range(2, n+1)]
    for i in range(2, n+1):
        if ps[i] == 0:
            continue
        for j in range(i * i, n+1, i):
            ps[j] = 0
    return [p for p in ps if p]
 
 
prime = get_primes(N)
 
ans = 1
for p in prime:
    tmp = 0
    for i in range(1, int(math.log(N, p))+1):
        tmp += N // (p**i)
 
    ans = (ans * (tmp + 1)) % mod
 
print(ans)

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	std::string s;
	std::cin >> s;
	int n = s.size();
	bool res = true;
	for (int i = 0; i < n; i++) {
		if (i & 1 && s[i] != 'L' && s[i] != 'U' && s[i] != 'D') res = false;
		if (!(i & 1) && s[i] != 'R' && s[i] != 'U' && s[i] != 'D') res = false;
	}
	std::cout << (res ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;cin >> s;
  vector<string> sa(16);
  for (int i=0;i<16;i++) {
    string x="";
	if (i & 8) x+='A';
	x+="KIH";
	if (i & 4) x+='A';
	x+='B';
	if (i & 2) x+='A';
	x+='R';
	if (i & 1) x+='A';
	sa[i]=x;
  }
  long long r=0;
  for (int i=0;i<16;i++) if (s==sa[i]) r=1;
  if (r) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
  
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] s = str.split(" ");

		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		int c = Integer.parseInt(s[2]);
		if((a <= 10000) && (a >= 1) && (b <= 10000) && (b >= 1) && (c <= 10000) && (c >= 1)){

			if((b < c) && (a < c)){
				if(a > b){
					System.out.println(b +" "+ a +" "+ c);
				}else{
					System.out.println(a +" "+ b +" "+ c);
				}
			}else if((a < b)&&(c < b)){
				if(a > c){
					System.out.println(c +" "+ a +" "+ b);
				}else{
					System.out.println(a +" "+ c +" "+ b);
				}
			}else{
				if(b > c){
					System.out.println(c +" "+ b +" "+ a);
				}else{
					System.out.println(b +" "+ c +" "+ a);
				}
			}
		}
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int X, Y, Z; cin >>X>>Y>>Z;
    
    int ans = (X - Z) / (Y + Z);

    cout << ans << endl;
}


Measured memory_bytes: 256
typedef long long ll;

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

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int a = getInt();
  const int b = getInt();
  const int c = getInt();
  const int x = getInt();
  const int y = getInt();

  const int n = 2 * max(x, y);

  ll ans = 1ll << 60;
  REP(i,n+1){
    const int t = i / 2;
    const int xx = max(0, x - t);
    const int yy = max(0, y - t);

    ans = min<ll>(ans, xx * a + yy * b + i * c);
  }

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

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  #define int long
  int N,M;cin>>N>>M;
  priority_queue<int> A;
  for(int i=0;i<N;i++){
    int tmp;cin>>tmp;A.push(tmp);
  }
  for(int i=0;i<M;i++){
    int f=A.top();A.pop();
    A.push(f/2);
  }int ans=0;
  while(!A.empty()){
    ans+=A.top();A.pop();
  }
  cout<<ans;
  
}



Measured memory_bytes: 1400
#include<stdio.h> 
int main(){
  int i=0,j=0;
  char a[1200];
  
  while(1){
    scanf("%c",&a[j]);
      if(a[j]=='\n') break;
      j++;
    }
    for(i=0;i<j;i++){

      if(a[i]>=65 && a[i]<=90){
	a[i]+=32;
      }
      else if(a[i]>=97 && a[i]<=122) {
	a[i]-=32;
      }
    }
  
  
    for(i=0;i<j;i++){
      printf("%c",a[i]);
    }

    printf("\n");


    return 0;
    }


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

const int mod = 1000000007;
//const int mod = 998244353;
const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dj[] = {0, -1, 0, 1, -1, 1, -1, 1};

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    if(x > 0 && (double)x/d - k > 0){
        cout << x - k*d << endl;
        return 0;
    }
    else if(x < 0 && (double)x/d + k < 0){
        cout << abs(x + k*d) << endl;
        return 0;
    }
    if(x < 0) x = (-1)*x;
    ll dir = x%d;
    ll dir_cnt = x/d;
    ll dist = abs(dir - d);
    if(dir_cnt%2 == 0){
        if(k%2 == 0) cout << dir << endl;
        else cout << dist << endl;
    }
    else{
        if(k%2 == 0) cout << dist << endl;
        else cout << dir << endl;
    }
    return 0;
}


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

namespace AtCoder
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var x = Console.ReadLine ().Split (' ').Select(int.Parse).ToArray ();
			var A = new SortedSet<int>{4,6,9,11};
			var C = new SortedSet<int>{1,3,5,7,8,10,12 };
			if((A.Contains(x[0])&&A.Contains(x[1]))||(C.Contains(x[0])&&C.Contains(x[1])))
				Console.WriteLine ("Yes");
			else
				Console.WriteLine ("No");
		}
	}
}


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

void printRect(int w, int h)
{
    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            if (((x+y) % 2) == 0)
                cout << '#';
            else
                cout << '.';
        }
        cout << endl;
    }
}

int main(void)
{
    while (1)
    {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0)
            break;
        printRect(w, h);
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3068
#include <stdio.h>
int main()
{
int N,M,a,b,c;
scanf("%d", &N);

if(100<N || N<999)
{
    a=N%10;
    M=N/10;
    b=M%10;
    c=M/10;
    if(a==7 || b==7 || c==7)
    {
        printf("Yes");
    }
    else{
        printf("No");
    }
}
else{
    printf("input is not right");
}
}


Measured memory_bytes: 2152
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		Arrays.sort(s);
		Arrays.sort(t);
		String s_asc = String.valueOf(s);
		String t_desc = new StringBuilder(String.valueOf(t)).reverse().toString();
		if(s_asc.compareTo(t_desc) < 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21844
# ABC120D

import sys
input=sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.p=[-1]*n
        self.size=[1]*n
        
    def root(self, x):
        st=set()
        while self.p[x]>=0:
            st.add(x)
            x=self.p[x]
        for y in st:
            self.p[y]=x
        return x
    def find(self, x, y):
        return self.root(x)==self.root(y)
    def union(self, x, y):
        r1=self.root(x)
        r2=self.root(y)
        if r1==r2:
            return
        p1=self.p[r1]
        p2=self.p[r2]
        if p1<=p2:
            self.p[r2]=r1
            self.size[r1]+=self.size[r2]
            if p1==p2:
                self.p[r1]-=1
        else:
            self.p[r1]=r2
            self.size[r2]+=self.size[r1]

    
def main():
    N,M=map(int,input().split())
    AB=[tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
    
    uft=UnionFind(N)
    ansl=[int(N*(N-1)//2)]
    for i in range(M-1,0,-1):
        a=AB[i][0]
        b=AB[i][1]
        if not uft.find(a,b):
            ansl.append(ansl[-1]-( uft.size[uft.root(a)]*uft.size[uft.root(b)] ))
        else:
            ansl.append(ansl[-1])
        uft.union(a,b)
        
    for i in range(M-1,-1,-1):
        print(ansl[i])
    
    
    
    
if __name__=="__main__":
    main()


Measured memory_bytes: 94500
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, M, a[50], b[50], c[50], d[50];
    cin >> N >> M;
    REP(i, N) {
        cin >> a[i] >> b[i];
    }
    REP(i, M) {
        cin >> c[i] >> d[i];
    }
    REP(i, N) {
        int md = 100000000 * 4, res;
        REP(j, M) {
            if (amin(md, abs(a[i] - c[j]) + abs(b[i] - d[j]))) {
                res = j;
            }
        }
        cout << res + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    vector<vector<ll>> bingo;
    REP(i, 3){
        vector <ll> line;
        REP(j, 3){
            ll a; cin >> a;
            line.push_back(a);
        }
        bingo.push_back(line);
    }
    vector<vector<bool>> atari(3, vector<bool>(3, false));
    ll n; cin >> n;
    REP(i, n){
        ll b; cin >> b;
        REP(j, 3){
            REP(k, 3){
                if (bingo[j][k] == b){
                    atari[j][k] = true;
                }
            }
        }
    }
    if (
            (atari[0][0] && atari[0][1] && atari[0][2]) or
            (atari[1][0] && atari[1][1] && atari[1][2]) or
            (atari[2][0] && atari[2][1] && atari[2][2]) or
                    (atari[0][0] && atari[1][0] && atari[2][0]) or
                    (atari[0][1] && atari[1][1] && atari[2][1]) or
                    (atari[0][2] && atari[1][2] && atari[2][2]) or
                    (atari[0][0] && atari[1][1] && atari[2][2]) or
                    (atari[2][0] && atari[1][1] && atari[0][2])){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];

    int ans=0;
    for(int i=0;i<n;i++){
        int ai=0;
        while(a[i]%2==0){
            ai++;
            a[i] /= 2;
        }
        ans += ai;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		boolean[] pmap = new boolean[10001];
		pmap[1]=true;
		for(int i=2;i<10000;i++)
			if(!pmap[i])
				for(int j=2;i*j<=10000;j++)
					pmap[i*j]=true; //素数でない


		Scanner scan = new Scanner(System.in);

		while(scan.hasNext()){
			int n = scan.nextInt();

			int c=0;
			for(int i=1;i<=n;i++){
				int j=n+1-i;
				if(!pmap[i] && !pmap[j])
					c++;
			}
			System.out.println(c);
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

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

typedef struct edge_ {
    int to;
    ll cost;
} edge;

vector<vector<edge> > G;
vector<ll> dist, par;
ll INF = 9999999999999;

void dijkstra(int n, int s) {
    dist.resize(n);
    par.resize(n);
    for (int i = 0; i < n; i++)
        dist[i] = INF;
    dist[s] = 0;

    priority_queue<P, vector<P>, greater<P> > pque;
    
    pque.push(P((ll)0, s));

    while (!pque.empty()) {
        P p = pque.top();
        pque.pop();
        int u = p.second;
        ll d = p.first;
        if (d > dist[u])
            continue;
        
        for (int i = 0; i < G[u].size(); i++) {
            edge e = G[u][i];
            int v = e.to;
            ll c = e.cost;
            if (dist[v] <= dist[u] + c)
                continue;
            
            dist[v] = dist[u] + c;
            pque.push(P(dist[v], v));
            par[v] = u;
        }
    }
}

//nは頂点数、mは辺数
//受け取る頂点番号を−１していることに注意
void build_graph(int n, ll m) {
    G.resize(n);
    for (int i = 0; i < m; i++) {
        int a, b;   cin >> a >> b;
        a--, b--;
        edge e1 = {b, 1}, e2 = {a, 1};
        G[a].push_back(e1);
        G[b].push_back(e2);
    }
}

int main() {
    int n, m;   cin >> n >> m;
    build_graph(n, m);
    dijkstra(n, 0);

    cout << "Yes" << endl;
    for (int i = 1; i < n; i++)
        cout << par[i]+1 << endl;

        return 0;
}

Measured memory_bytes: 19372
import itertools
import sys
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
x = [i+1 for i in range(n)]
ans = 0
c = 1

if p == q:
  print(0)
  sys.exit()
for j in itertools.permutations(x,n):
    y = list(j)
    if p == y:
       ans += c
    elif q == y:
        ans -= c
    
    c += 1

print(abs(ans))

Measured memory_bytes: 3064
while True:
    m,f,r=map(int,input().split())
    if m == -1 and f== -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print("F")
    elif m+f >= 80:
        print("A")
    elif m+f >= 65:
        print("B")
    elif m+f >= 50:
        print("C")
    elif m+f >=30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")
        


Measured memory_bytes: 5592
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int m,n;
	if (c%b==0) m=c/b;else m=c/b+1;
	if (a%d==0) n=a/d;else n=a/d+1;
	if (m<=n) cout<<"Yes";else cout<<"No";
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int main()
{
  double a;
  cin >> a;
  int tmp = a / 1.08;
  if((int)tmp*1.08==a){
    cout << tmp << endl;
  }
  else if ((int)((tmp+1) * 1.08) == a)
  {
    cout << tmp+1 << endl;
  }else{
    cout << ":(" << endl;
  }
}


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


def main():
    from itertools import permutations

    n, m = map(int, input().split())
    graph = [[0 for __ in range(n)] for _ in range(n)]
    ans = 0

    for i in range(m):
        ai, bi = map(lambda x: int(x) - 1, input().split())
        graph[ai][bi] = 1
        graph[bi][ai] = 1

    for j in list(permutations(range(n))):
        count = 0

        if j[0] == 0:
            for k in range(n - 1):
                _from = j[k]
                _to = j[k + 1]

                if graph[_from][_to] == 1:
                    count += 1

            if count == n - 1:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int a,b;
  string s;
  cin >> a >> b >> s;
  bool flag=true;
  r(i,a+b+1){
    if(i!=a){
    if(!(s.at(i)-'0'>=0&&s.at(i)-'0'<=9))flag=false;
    }
    else if(s.at(i)!='-')flag=false;
  }
  if(flag)cout << "Yes" <<endl;
  else cout << "No"<<endl;
  
}

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

typedef long long int LLI;
typedef priority_queue<LLI, vector<LLI>, greater<LLI>> Q;

int N;
int M;
LLI ans;
LLI as[114514];
bool used[114514];
Q que;
Q qs[114514];
vector<int> es[114514];

void dfs(int v, Q &q) {
  used[v] = true;
  q.push(as[v]);
  for (int u : es[v]) {
    if (used[u]) continue;
    dfs(u, q);
  }
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i=0; i<N; i++) scanf("%lld", &as[i]);
  for (int i=0; i<M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    es[a].emplace_back(b);
    es[b].emplace_back(a);
  }

  int num = 0;
  for (int i=0; i<N; i++) {
    if (!used[i]) {
      dfs(i, qs[i]);
      ans += qs[i].top(); qs[i].pop();
      if (qs[i].size() > que.size()) swap(qs[i], que);
      while (!qs[i].empty()) {
        LLI v = qs[i].top(); qs[i].pop();
        que.push(v);
      }
      num++;
    }
  }

  if (que.size()+2 < num) {
    puts("Impossible");
    return 0;
  }

  for (int i=0; i<num-2; i++) {
    LLI v = que.top(); que.pop();
    ans += v;
  }

  if (num == 1) puts("0");
  else printf("%lld\n", ans);  
}


Measured memory_bytes: 11772
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int t[101];
  int sm = 0;
  int m, p, x;
  cin >> n;
  for(int i=1;i<=n;i++){
    cin >> t[i];
    sm += t[i];
  }
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> p >> x;
    cout << sm+(x-t[p]) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  cout << a[0] + a[1] + a[2] * 10 << endl;
}


Measured memory_bytes: 256