akhauriyash/Code-Regression huggingface dataset:
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

map<ll,ll> mp;

ll mypw(ll x,ll k)
{
  if(k == 0)return 1;
  ll a = mypw(x,k / 2);
  a = a * a % MOD;
  if(k & 1)return a * x %MOD;
  else return a;
}

ll fac[MAXn];

ll c(ll a,ll b)
{
  return fac[a] * mypw(fac[b],MOD-2)%MOD * mypw(fac[a - b],MOD-2)%MOD;
}

int main()
{
    IOS();
    fac[0] = 1;
    REP1(i,MAXn-1)fac[i] = fac[i-1] * i %MOD;
    ll n,m;
    cin>>n>>m;
    for(ll i = 2;i * i <= m;i++)
    {
      while(m % i == 0)
      {
        m /= i;
        mp[i]++;
      }
    }
    if(m != 1)mp[m] ++;
    ll tt = 1;
    debug(mp);
    for(auto tmp:mp)
    {
      debug(tmp.Y,n);
      tt = tt * c(tmp.Y + n - 1,tmp.Y) % MOD;
    }
    cout<<tt<<endl;
}


Measured memory_bytes: 1792
use std::collections::HashSet;

fn main() {
    let n: usize = {
        let mut n = String::new();
        std::io::stdin().read_line(&mut n).ok();
        n.trim().parse().unwrap()
    };

    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    let mut line: HashSet<i32> = line.split_whitespace()
                                   .map(|c|c.parse().unwrap())
                                   .collect();
    println!("{}", if n == line.len() { "YES" } else { "NO" });
}

Measured memory_bytes: 14240
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int INF = 987654321;
const bool TESTCASES = 0;
const bool CODEJAM = 0;

void solve() {
	int n;
	cin >> n;
	vector<int> A, B, C;
	A = B = C = vector<int>(n);
	REP(n) cin >> A[i] >> B[i] >> C[i];
	vector<vector<int>> dp(n + 1, vi(3));
	for(int i = 1; i <= n; i++) {
		dp[i][0] = A[i - 1] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = B[i - 1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = C[i - 1] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout << *max_element(all(dp[n])) << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 9776
#include <bits/stdc++.h>
using namespace std;
struct segtree{
	vector<int> data;
	int n;
	int init(int N){
		n=1;
		while(n<N)	n*=2;
		data.assign(2*n-1,INT_MAX);
		return n;
	}
	void update(int i,int x){
		i+=n-1;
		data[i]=x;
		while(i>0){
			i=(i-1)/2;
			data[i]=min(data[2*i+1],data[2*i+2]);
		}
	}
	int find(int l,int r,int a,int b,int k){
		if(b<=l or r<=a)	return INT_MAX;
		if(a<=l and r<=b)	return data[k];
		int vl=find(l,(l+r)/2,a,b,2*k+1);
		int vr=find((l+r)/2,r,a,b,2*k+2);
		return min(vl,vr);
	}
};
int main(){
	int n,q;	cin>>n>>q;
	segtree seg;	n=seg.init(n);
	for(int i=0;i<q;i++){
		int com,x,y;	cin>>com>>x>>y;
		if(com==0){
			seg.update(x,y);
		}
		else{
			cout<<seg.find(0,n,x,y+1,0)<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2060
#include <iostream>
typedef long long int ll;


using namespace std;

ll MOD = 1000000000LL + 7LL;


ll pow_mod(ll a, ll n) {
    if (n == 0LL) {
        return 1LL;
    }
    ll p = pow_mod(a, n / 2);
    ll temp = (p * p) % MOD;
    if (n % 2 == 0LL) {
        return temp;
    } else {
        return (a * temp) % MOD;
    }
}

int main(int argc, char const *argv[]) {
    ll x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll n = (x + y) / 3;
    x -= n;
    y -= n;

    if (x < 0LL or y < 0LL) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1LL;
    for (ll i = x + 1; i < x + y + 1; i++) {
        ans = (ans * i) % MOD;
    }
    for (ll i = 1LL; i < y + 1; i++) {
        ans = (ans * pow_mod(i, MOD - 2)) % MOD;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  multiset<int> st;
  REP(i, 1 << n) {
    int s;
    cin >> s;
    st.insert(-s);
  }
  vector<int> cur, nxt;
  cur.push_back(*st.begin());
  st.erase(*st.begin());
  REP(i, n) {
    nxt = cur;
    REP(j, cur.size()) {
      auto it = st.upper_bound(cur[j]);
      if (it == st.end()) {
        puts("No");
        return 0;
      }
      nxt.push_back(*it);
      st.erase(st.find(*it));
    }
    cur = nxt;
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 14324
#include<bits/stdc++.h>
const long long mod = 1000000007;

int main()
{
    int n;
    std::cin>>n;
    std::vector<int> v(n);
    std::deque<int> dq;
    for(int i=0;i<n;i++)std::cin>>v[i];
    for(int i=0;i<n;i++){
        if(i%2==0)dq.push_back(v[i]);
        else dq.push_front(v[i]);
    }
    if(n&1){
        for(int i=0;i<n;i++)std::cout<<*(dq.end()-1-i)<<" ";
    }else{
        for(int i=0;i<n;i++)std::cout<<*(dq.begin()+i)<<" ";
    }
    return 0;
        
}

Measured memory_bytes: 3840
# seishin.py
N = int(input())
MOD = 10**9 + 7

fact = [1]*(N+1)
rfact = [1]*(N+1)

for i in range(1, N+1):
    fact[i] = r = i*fact[i-1] % MOD
    rfact[i] = pow(r, MOD-2, MOD)

ans = cnt = 0
for K in range((N+1)//2, N):
    res = fact[K]*fact[K-1]*rfact[2*K-N] % MOD
    ans += (res - cnt) * K % MOD
    cnt = res
    ans %= MOD
print(ans)


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

const int MAXN = 100005;

int N, K, Q, ai, A[MAXN];
int main(){
	scanf("%d %d %d", &N, &K, &Q);
	for(int i = 0; i < Q; i++){
		scanf("%d", &ai);
		A[ai - 1]++;
	}
	for(int i = 0; i < N; i++){
		if(K - Q + A[i] > 0)printf("Yes\n");
		else printf("No\n");
	}
	
	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        int n = in.intNext();
        int m = in.intNext();

        ArrayList<Integer>[] adjacency = new ArrayList[n+1];
        for (int i = 1; i <= n; i++) adjacency[i] = new ArrayList<>();
        Integer[] parents = new Integer[n+1];
        Arrays.fill(parents, null);
        parents[1] = 0;

        for (int i = 0; i < m; i++) {
            int a = in.intNext(), b = in.intNext();

            adjacency[a].add(b);
            adjacency[b].add(a);
        }

        Deque<Integer> deque = new LinkedList<>();
        deque.add(1);
        while (deque.size() > 0) {
            int node = deque.pollFirst();
            for (int child: adjacency[node]) {
                if (parents[child] == null) {
                    parents[child] = node;
                    deque.add(child);
                }
            }
        }
        out.println(getResult(n, parents));

        out.close();
    }

    static StringBuilder getResult(int n, Integer[] parents) {
        StringBuilder res = new StringBuilder("Yes\n");
        for (int i = 2; i <= n; i++) {
            if (parents[i] == null) return new StringBuilder("No\n");
            res.append(parents[i]).append("\n");
        }
        return res;
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}




Measured memory_bytes: 76872
while n = gets do
  n = n.to_i
  sum = 0
 
  (0..9).each do |a|
    (0..9).each do |b|
      (0..9).each do |c|
        (0..9).each do |d|
          if  a + b + c + d == n
            sum +=1
          end
        end
      end
    end
  end
  puts sum
end


Measured memory_bytes: 6852
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int m,n;
    while(cin>>m>>n,n||m){
        vector<bool> f(7368792,false);
        for(int i=m;;i++){
            if(f[i]==false){
                n--;
                if(n==-1){
                    cout<<i<<endl;
                    break;
                }
                for(int j=i;j<7368792;j+=i){
                    f[j]=true;
                }
            }
        }
        
    }
}



Measured memory_bytes: 3912
#include <stdio.h>
int main(){
	long long int N;
	char S;
	scanf("%lld",&N);
	char dummy;
	scanf("%c",&dummy);
	long long int i;
	long long int c[26];
	for(i=0;i<26;i++){
		c[i]=0;
	}
	int j;
	for(i=0;i<N;i++){
		scanf("%c",&S);
		j=(int)S-(int)'a';
		c[j]=c[j]+1;
	}
	long long int ans;
	ans=1;
	for(i=0;i<26;i++){
		ans=ans*(c[i]+1)%1000000007;
	}
	ans=ans-1;
	printf("%lld",ans);
}

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

int main(){
  int x, y;
  cin >> x >> y;
  if(x % y == 0 || y % x == 0) {
    cout << (x + y) / 2 << endl;
  } else {
    cout << (x + y) / 2 + 1<< endl;
  }
}



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

int main() {
    int n;
    cin >> n;
    long long t, a;
    long long pt, pa;
    cin >> pt >> pa;
    for (int i = 1; i < n; i++) {
        cin >> t >> a;
        if (pt <= t && pa <= a) {
            pt = t;
            pa = a;
        } else {
            long long x = max((pt + t - 1) / t, (pa + a - 1) / a);
            pt = t * x;
            pa = a * x;
        }
    }

    cout << pt + pa << endl;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
  ios_base::sync_with_stdio (false);
  cin.tie(NULL);

  ll N, W;

  cin >> N >> W;

  vl w(N, 0);
  vl v(N, 0);

  FOR(i, 0, N){
    cin >> w[i] >> v[i];
  }

  vl dp(W+1, 0);


  FOR(i, 0, N){
    vl newDp(W+1, 0);
    FOR(j, 0, W+1){
      if((j > 0 && dp[j] == 0) || j+w[i] > W) continue;
      newDp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
    }

    FOR(j, 0, W+1){
      dp[j] = max(dp[j], newDp[j]);
      newDp[j] = 0;
    }
  }

  ll maximum = 0;
  FOR(j, 0, W+1){
    maximum = max(dp[j], maximum);
  }

  cout << maximum << endl;

}


Measured memory_bytes: 1804
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#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 FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

string s;

void init() {

}

void input() {

}

void solve() {
  cin >> s;
  reverse(ALL(s));

  LL sum = 1;
  LL last1result = 1;
  REP(i, SZ(s)) {
    if (s[i] == '1') {
      last1result = (last1result * 2 + sum) % 1000000007;
    }
    sum = (sum*3) % 1000000007;
  }
  cout << last1result << endl;
}

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


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


int main() {
  int a;cin>>a;
  if(a==1) cout << 0 << endl;
  else cout << 1 << endl;
}
 

Measured memory_bytes: 3616
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int a[N];
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n, s = 0;	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];		
		s += a[i]*pow(-1, i+1);
	}
	cout << s << " ";
	for(int i = 2; i <= n; i++){
		cout << 2*(a[i-1] - s/2) << " ";
		s = 2*(a[i-1] - s/2);
	}
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> a(N + 2);
	for (int i = 1; i <= N; ++i) { cin >> a[i]; }

	for (int k = 0; k < K; ++k) {
		vector<int> b(N + 2, 0);
		for (int i = 1; i <= N; ++i) {
			int l = max(1, i - a[i]);
			int r = min(N, i + a[i]) + 1;
			b[l] += 1;
			b[r] -= 1;
		}
		int min_a = 1e8;
		for (int i = 1; i <= N + 1; ++i) {
			b[i] += b[i - 1];
			if (i <= N) { min_a = min(min_a, b[i]); }
		}
		a = b;
		if (min_a >= N) { break; }
	}
	for (int i = 1; i <= N; ++i) {
		cout << a[i] << (i < N ? " " : "\n");
	}

	return 0;
}


Measured memory_bytes: 4840
import sys
from collections import deque
input = sys.stdin.readline

class Node:
    def __init__(self, id):
        self.id = id
        self.link = []
        self.cost = []
        self.check = False

def main():
    N = int(input())
    
    nodes = [Node(i) for i in range(N+1)]

    for i in range(N-1):
        a, b, c = map(int, input().split())
        nodes[a].link.append(nodes[b])
        nodes[b].link.append(nodes[a])
        nodes[a].cost.append(c)
        nodes[b].cost.append(c)
    
    Q, K = map(int, input().split())

    q = deque()
    q.append((nodes[K], 0))
    nodes[K].check = True
    costs = [0] * (N+1)
    while len(q) > 0:
        node, cost = q.popleft()
        costs[node.id] = cost
        for i in range(len(node.link)):
            next_node = node.link[i]
            if not next_node.check:
                q.append((next_node, cost + node.cost[i]))
                next_node.check = True
    
    for i in range(Q):
        x, y = map(int, input().split())
        print(costs[x] + costs[y])
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 72224
class atcoder:
    N=int(input())
    A=[]
    A=list(map(int,input().split()))
    ans=0
    n=0
    for i in range(len(A)):
        if A[i]%2==0:
            n+=1
            if A[i]%3==0 or A[i]%5==0:
                ans+=1
            else:
                pass
        else:
            pass
    if n==ans:
        print('APPROVED')
    else:
        print('DENIED')

Measured memory_bytes: 3064
import fractions

n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))

if n == 1:
    print("POSSIBLE" if arr[0] == k else "IMPOSSIBLE")
else:
    # 最大公約数
    gcd = arr[0]
    for num in arr[1:]:
        gcd = fractions.gcd(gcd, num)

    print("POSSIBLE" if (k % gcd == 0 and k <= max(arr)) else "IMPOSSIBLE")


Measured memory_bytes: 16240
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

const double PI=3.14159265358979;

int main(int argc, char* argv[])
{
    while(1) {
        int n;
        scanf("%d", &n);
        if(n==0) break;
        vector<int> s(n);
        double av=0.0;
        int i;
        for(i=0; i<n; i++) {
            scanf("%d", &s[i]);
            av += s[i];
        }
        av /= n;
        double sum=0;
        for(i=0; i<n; i++) {
            sum +=(s[i]-av)*(s[i]-av);
        }
        sum /= n;
        printf("%.10lf\n", sqrt(sum));
    }

    return 0;
}



Measured memory_bytes: 2756
abc=[]
answer=0
for i in range(5):
    d=int(input())
    if d%10==0:
        answer+=d
    else:
        answer+=(int(d/10+1))*10
        abc.append(d%10)
if len(abc)>0:
    answer-=10-min(abc)
print(answer)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000010;
const int oo = 1e9;

int h , w, d;
char color[4] = {'R', 'G', 'Y', 'B'};
char ans[510][510];
int OFFSET = 1100;

int main() {
	//freopen("input.txt", "r", stdin);
	cin >> h >> w >> d;
	int offset = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0 ; j < w ; ++j) {
			int newI = i-j+OFFSET;
			int newJ = i+j+OFFSET;
			int c = (newI/d)%2 + 2*((newJ/d)%2);
			ans[i][j] = color[c];
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0 ; j < w ; ++j) {
			printf("%c", ans[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 768
using System.Linq;
using System;
class Program
{
    static void Main(string[] args)
    {
        var input = System.Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(input[0]);
        var k = long.Parse(input[1]);
        long result = -1 ;
        var abList = new int[n].Select(w => System.Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray()).OrderBy(w=> w[0]).ToList();
        for(var i = 0; i < n; i++)
        {
            k -= abList[i][1];
            if (k <= 0)
            {
                result = abList[i][0];
                break;
            }   
        }
        System.Console.WriteLine(result);
        //System.Console.Read();
    }
}

Measured memory_bytes: 27444
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import numpy as np

def scores(c, s, t):
    last = [0] * 26
    V = []
    lastv = 0
    for d, i in enumerate(t):
        last[i] = d+1
        v = s[d*26+i]
        sub = sum([c[j]*(d+1-last[j]) for j in range(26)])
        # print(v, sub)
        lastv += v-sub
        V.append(lastv)
    return V


def main():
    D, *cs = map(int, read().split())
    c = cs[:26]
    s = cs[26:]

    b = 0
    ans = []
    for d in range(D):
        maxi = 0
        for i in range(26):
            if s[b+i] > s[b+maxi]:
                maxi = i
        ans.append(maxi + 1)
        b += 26

    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 27620
#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>;

vector<int> v[200000];
ll c[200000] = {};
void dfs(int i, ll cv = 0, int parent=-1) {
	cv += c[i];
	c[i] = cv;
	for(int j: v[i]) {
		if (j == parent) continue;
		dfs(j, cv, i);
	}
}


int main() {
	int n, q;
	cin >> n >> q;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		c[p - 1] += x;
	}
	dfs(0);
	rep(i, n) {
		cout << c[i] << ' ';
	}
	cout << endl;
}



Measured memory_bytes: 24320
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>


#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> v(n + 1);

    ll ans = 0;
    for (unsigned int i = 1; i <= n; i++) {
        for (unsigned int j = i; j <= n; j += i) {
            v[j]++;
        }
    }

    for (unsigned int i = 1; i <= n; i++) {
        ans += i * v[i];
    }
    cout << ans << endl;
}


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

int main()
{
    int a,b,c;
    cin>>c>>a>>b;
    int n=min(a,b);
    n+=c;
    int m=max(a,b);
    if(n<m){
        cout<<m-n<<endl;
    }
    else{
        cout<<0<<endl;
    }
}

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

  int main(){
   int n,m;
      cin>>n>>m;
      vector<vector<int>> a(n,vector<int>(m,0));
      vector<string> v(n);
      for(int i=0;i<n;i++)cin>>v[i];
      a[n-1][m-1]=1;
      for(int i=n-2;i>=0;i--){
          if(v[i][m-1]=='#'){
              a[i][m-1]=0;
          }else{
              a[i][m-1]=a[i+1][m-1];
          }
      }
       for(int i=m-2;i>=0;i--){
          if(v[n-1][i]=='#'){
              a[n-1][i]=0;
          }else{
              a[n-1][i]=a[n-1][i+1];
          }
      }
      for(int i=n-2;i>=0;i--){
          for(int j=m-2;j>=0;j--){
              if(v[i][j]=='#'){
                  a[i][j]=0;
              }else{
                  a[i][j]=((lli)a[i+1][j]+(lli)a[i][j+1])%dl;
              }
          }
      }
      cout<<a[0][0]<<endl;
  }

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n;
    cin >> n;
    vector<int> d1(n),d2(n);
    rep(i,n){
        cin >> d1[i];
        cin >> d2[i];
    }
    int z=0;
    bool ans=false;
    rep(i,n){
        if(d1[i]==d2[i]) z++;
        else z=0;
        if(z==3) ans=true;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

main(){
	bool b;
	string s;
	b = true;
	cin>>s;
	
	for(int i=0;i<s.size();i++){
		if(i%2 == 0){
			if(s[i] == 'L'){
				b = false;
				break;
			}
		}	
		else if(s[i] == 'R'){
			b = false;
			break;
		}
	}
	if(b == true)	cout<<"Yes";
	else			cout<<"No";
}

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

using namespace std;

void solve()
{
	string str;
	cin >> str;
	int size = str.size() - 1;
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 0; i < n; ++i)
	{
		string ring;
		cin >> ring;
		for(int j = 0; j < size; ++j)
		{
			ring += ring[j];
		}
		if(ring.find(str) != string::npos)
		{
			++ans;
		}
	}
	cout << ans << endl;
}

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

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n, x;
    cin >> n >> x;

    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    sort(all(a));
    int ans = 0, sum = 0;
    rep(i, n){
        sum += a[i];
        if(sum > x) break;
        ans++;
        if(sum == x) break;
    }

    if(sum < x) ans--;
    cout << ans << endl;

    return 0;
}

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

#define ll long long
#define ull unsigned long long

const int N = 6e4 +5;
ll ar[N];

void Mo35(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

void countVal(ll n){

    for(ll x=1; x<=n; ++x)
        for(ll y=1; y<=n; ++y)
            for(ll z=1; z<=n; ++z)
                ar[(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x)]++;

}

int main(){
Mo35();

    ll n; cin>> n; countVal(sqrt(n));
    for(ll i=1; i<=n;) cout<< ar[i++]<< "\n";

return 0;
}

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

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

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

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v)                               \
  cerr << #v << ": ";                              \
  REP(__i, (v).size()) cerr << ((v)[__i]) << ", "; \
  cerr << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()

int main() {
  int N, M;
  cin >> N >> M;
  REP(i, M) {
    int tmp;
    cin >> tmp;
    N -= tmp;
  }

  if (N < 0)
    cout << -1 << endl;
  else
    cout << N << endl;
}


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

struct Problem {

    UL SX[1401][1401] = {};

    void Solve() {
        UL H, W; scanf("%d%d", &H, &W);
        rep(y, H) rep(x, W) {
            UL c; scanf("%d", &c);
            if (c == 1) continue;
            SX[x + 1][y] = SX[x][y] + 1;
        }
        UL ans = 0;
        deque<pair<UL, UL>> Q;
        for (UL x = 1; x <= W; x++) {
            Q.push_back({ 0,0 });
            for (UL y = 0; y <= H; y++) {
                UL p = y;
                while (Q.back().first > SX[x][y]) {
                    ans = max(ans, Q.back().first * (y - Q.back().second));
                    p = Q.back().second;
                    Q.pop_back();
                }
                Q.push_back({ SX[x][y], p });
            }
        }
        printf("%d\n", ans);
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



Measured memory_bytes: 26492
import sys
sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
D = [int(input()) for i in range(N)]
C = [int(input()) for i in range(M)]
memo = {}
def dfs(i, j):
    if i == N:
        return 0
    if j == M:
        return 10**9
    if (i, j) in memo:
        return memo[i, j]
    memo[i, j] = res = min(dfs(i+1, j+1) + D[i]*C[j], dfs(i, j+1))
    return res
print(dfs(0, 0))

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

#define N 100000
int a[N];
int fsum[N];
int bsum[N];

int main(void){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", a+i);
    }
    fsum[0] = abs(a[0]-0);
    for(int i=1; i<n; i++){
        fsum[i]=fsum[i-1]+abs(a[i]-a[i-1]);
    }
    bsum[n-1] = abs(a[n-1]-0);
    for(int i=n-2; i>=0; i--){
        bsum[i]=bsum[i+1]+abs(a[i]-a[i+1]);
    }
    printf("%d\n", abs(a[1]-0) + bsum[1]);
    for(int i=1; i<n-1; i++){
        printf("%d\n", fsum[i-1]+abs(a[i+1]-a[i-1])+bsum[i+1]);
    }
    printf("%d\n", fsum[n-2]+abs(a[n-2]-0));
    return 0;
}


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

class Solver {
  public:
    bool solve() {
        ll x; cin >> x;
        ll ans = x / 11 * 2;
        x %= 11;
        if(x > 0) ans += (x > 6 ? 2 : 1);
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

namespace AcCepted
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            bool result = false;

            if (s.StartsWith("A"))
            {
                string tmpS = s.Remove(0, 2);
                tmpS = tmpS.Remove(tmpS.Length - 1, 1);
                int cPos = s.IndexOf('C');

                if (tmpS.Count(a => a == 'C') == 1)
                {
                    string upper = s.Remove(cPos, 1);
                    upper = upper.Remove(0, 1);
                    
                    if (IsUpper(upper))
                    {
                        result = true;
                    }
                }
            }

            Console.WriteLine(result ? "AC" : "WA");
        }

        private static bool IsUpper(string str)
        {
            bool result = true;

            foreach (char c in str)
            {
                if (char.IsUpper(c))
                {
                    result = false;
                }
            }

            return result;
        }
    }
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int A, P;
    cin >> A >> P;
    P += A * 3;
    cout << P / 2 << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

const double INF = 1e17;

double d[1003];
bool used[1003];

int n;
double x[1003], y[1003], r[1003];

void dijkstra(){
    fill(d, d + n + 2, INF);
    fill(used, used + n + 2, false);
    d[0] = 0.0;
    while(true){
        int now = -1;
        for(int i = 0; i <= n + 1; i++){
            if(!used[i] && (now == -1 || d[i] < d[now])){
                now = i;
            }
        }
        used[now] = true;
        if(now == -1) break;
        for(int i = 0; i <= n + 1; i++){
            d[i] = min(d[i], d[now] + max(0.0, sqrt((x[i] - x[now]) * (x[i] - x[now]) + (y[i] - y[now]) * (y[i] - y[now])) - (r[i] + r[now])));
        }
    }
}

int main(){
    double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    cin >> n;
    x[0] = xs, y[0] = ys, x[n + 1] = xt, y[n + 1] = yt, r[0] = r[n + 1] = 0;
    for(int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> r[i];
    dijkstra();
    cout << fixed << setprecision(15) << d[n + 1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
class cube {
public:
	string color;
	void input() {
		string str;
		color = "";
		for (int i = 0; i < 6; ++i) {
			cin >> str;
			color += str[0];
		}
	}
};
int turn[3][4]{ {1,2,4,3},{0,1,5,4},{0,2,5,3} };
void turncube(cube&, int);
bool check(cube, cube);
int main() {
	int num;
	while (cin >> num&&num != 0) {
		vector<cube> line(num);
		for (int i = 0; i < num; ++i) {
			line[i].input();
		}
		int ans = 0;
		for (int i = 0; i < line.size() - 1; ++i) {
			for (int j = i+1; j < line.size(); ++j) {
				if (check(line[i], line[j])) {
					swap(line[j], line.back());
					line.pop_back();
					++ans;
					--j;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

void turncube(cube &a, int num) {
	for (int i = 0; i < 3; ++i) {
		swap(a.color[turn[num][i]], a.color[turn[num][i + 1]]);
	}
}

bool check(cube a, cube b) {
	int num[] = { 1,1,1,1,2,1,1,1,1 };
	int i = 0;
	while (a.color[0] != b.color[0]) {
		turncube(a, num[i++]);
	}
	for (int i = 0; i < 4; ++i) {
		bool flag = true;
		turncube(a, 0);
		for (int j = 0; j < 6; ++j) {
			if (a.color[j] != b.color[j]) {
				flag = false;
			}
		}
		if (flag)return true;
	}
	return false;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define lb lower_bound
#define f(i,p,n) for(ll i=p;i<n;i++)
#define debug(x) cout<<"["<<#x<<": "<<x<<"]"<<endl
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

ll exp(ll a,ll b,ll m);

int main()
{
 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*
 	#ifndef ONLINE_JUDGE
        freopen("/home/savish/Desktop/2019/io/input.txt", "r", stdin);
        freopen("/home/savish/Desktop/2019/io/output.txt", "w", stdout);
    #endif
*/
    ll n,m;
    cin>>n>>m;
    string s[n];
    f(i,0,n) cin>>s[i];

    ll dp[n][m];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    f(i,0,n)
    {
    	f(j,0,m)
    	{
    		if(s[i][j]=='#') dp[i][j] = 0;
    		else 
    			{
    				if(i-1>=0 && s[i-1][j]=='.') dp[i][j] += dp[i-1][j];
    				if(j-1>=0 && s[i][j-1]=='.') dp[i][j] += dp[i][j-1];
    			}

    		dp[i][j] = dp[i][j]%mod;  
    	//	cout<<dp[i][j]<<" ";
    	}
    	//cout<<endl;
    }//
    cout<<dp[n-1][m-1]<<endl;
    
    
return 0;
}

ll exp(ll a,ll b,ll m)
{
	if(b==0)
	{
		return 1;
	}
	ll temp =exp(a,b/2,m);
	temp=(temp*temp)%m;
	if(b&1)
	{
		return (temp*(a%m))%m;
	}
	return temp;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >>c;
    if(b%c==0)
    {
        cout << 1+(b-a)/c <<"\n";
    }
    else
        cout << (b-a)/c << "\n";
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) < TMPend; (i)++)
#define RFOR(i, f, n) for(int (i) = (f), TMPend = (n); (i) >= TMPend; (i)--)
#define REP(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0, TMPend = (n); (i) < TMPend; (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int bitcount(int v, int n) {
  int cnt = 0;
  rep(i, n) {
    cnt += bool(v & (1 << i));
  }
  return cnt;
}

long long mod(long long v, long long M) {
  if (v >= M) {
    return v % M;
  }
  return v;
}

int main(){
  int input(n);
  vector<vector<int>> a(n);
  rep(i, n) {
    int list_input(ai, n);
    vector<int> tmp(ai, ai + n);
    a[i] = tmp;
  }

  long long ok = (1 << n) - 1;
  long long dp[1 << n];
  long long M = 1'000'000'000 + 7;

  rrep(state, (1 << n) - 1) {
    if (state == ok) {
      dp[state] = 1;
      continue;
    }

    long long cnt = 0;
    int i = bitcount(state, n);
    rep(index, n) {
      int p = 1 << index;
      if (a[i][index] && !(state & p)) {
        cnt = mod(cnt + dp[state + p], M);
      }
    }
    dp[state] = mod(cnt, M);
  }

  out(dp[0]);
}


Measured memory_bytes: 16640
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 03/12/2017 12:28:12
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define POB pop_back
#define dist(a, b) sqrt(a*a + b*b)
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vipi;
bool compare(pi p1, pi p2){
	 if(1) return true;
	 return false;
}

int main(){
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie();
	//char c = '1';
	//cout<<int(c) - 48<<endl;
	string nbr;
	cin>>nbr;
	int sum = 0;
	for(int i = 0; i < nbr.size(); i++) {
		sum += int(nbr[i]) - 48;
	}
	int n = stoi(nbr);
	if(n % sum == 0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define endl "\n"
#define MOD 1000000007

vector<vector<ll>> matmul(const vector<vector<ll>>& a, const vector<vector<ll>>& b) {
    ll p = a.size();
    ll q = a[0].size();
    
    ll r = b[0].size();
    // assume valid
    vector<vector<ll>> c (p, vector<ll> (r));
    
    for (ll i = 0; i < p; i++) {
    
        for (ll j = 0; j < r; j++) {
            c[i][j] = 0;
            for (ll k = 0; k < q; k++) {
                c[i][j] = (c[i][j] + (a[i][k]*b[k][j])%MOD)%MOD;
            }
        }
    }
    return c;
} 

vector<vector<ll>> exp(vector<vector<ll>>& a, ll b) {
    ll n = a.size();
    
    vector<vector<ll>> res (n, vector<ll> (n, 0)); // assume square
    for (ll i = 0; i < n; i++) {
        res[i][i] = 1;
    }

    while (b > 0) {
        if (b&1) {
            res = matmul(res, a);
        }
        a = matmul(a, a);
        b = b >> 1;
    }
    return res;
}


int main(void) {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    ll n, k;
    cin >> n >> k;
    vector<vector<ll>> G (n, vector<ll> (n));

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < n; j++) {
            cin >> G[i][j];
        }
    }
    auto ans = exp(G, k);
    ll count = 0;
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < n; j++) {
            count= (count + ans[i][j])%MOD;
        }
    }
    cout << count << endl;


    
    return 0;
}

Measured memory_bytes: 3692
#!/usr/bin/env python3
import sys


def solve(S: int, W: int):
    if S > W:
        print("safe")
    else:
        print("unsafe")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(S, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include<bits/stdc++.h>
#define pb push_back
#define fori(j,n) for(int i=j ; i<n ; i++)
#define forj(i,n) for(int j=i ; j<n ; j++)
#define fork(i,n) for(int k=i ; k<n ; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int

using namespace std;

void solve()
{
	lli n,d;
	cin>>n>>d;
	lli cnt=0;
	for(int i=0 ; i<n ; i++)
	{
		lli x,y;
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=d) cnt++;
	}
	cout<<cnt;
	
}

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

	// int t;cin>>t;
	// while(t--)
	// {
		solve();
		// cout<<endl;
	// }


	return 0;

}

Measured memory_bytes: 3668
#include <iostream>
using namespace std;
 
int main(){
  int a,b,k;
  double x,y;
 
  cin >> a >> b;
  x = a * 2.0;
  y = b;
  k = a+b;
  for(int i=1;i<a;i++){
    for(double j=1.0;j<y;j++){
      if(i*2*(y/x) == j){
        k--;
        break;
      }
    }
  }
  cout << k << endl;
}


Measured memory_bytes: 3092
n,y = map(int,input().split())
ans = 0
c = 1
for i in range(y // 10000 + 1,-1,-1):
    for j in range(y // 5000 + 1,-1,-1):
        if n - i - j >= 0 and y - 10000 * i - 5000 * j == 1000 * (n-i-j):            
            if c != 0:
                print(i, j, (y-10000*i-5000*j)//1000)
                c = 0
if c == 1:
    print('-1 -1 -1')

Measured memory_bytes: 3064
import math
mod=10**9+7

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def comb(n, r, mod = 10**9 + 7):
    return ( framod(n,mod) * pow(framod(n-r,mod),mod-2,mod ) * pow(framod(r,mod),mod-2,mod))
X,Y=map(int,input().split())
if (X + Y) % 3 ==0:
  s,t= ( 2*X - Y ) // 3 , (2*Y - X) // 3
  if s*t<0:
    print(0)
  else:
    print(comb(s+t,s) % mod)
else:
  print(0)



Measured memory_bytes: 38512
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin >> a >> b;
    sort(a.begin(),a.end());
    sort(b.rbegin(),b.rend());
    if(a < b)
    cout << "Yes" << endl;
    else 
    cout << "No" << endl;
}


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

int u[50], a[50], cnt, ans, lim;
string s;
int dfs(string&s, int&i) {
	if (s[i] == '(') {
		int b = cnt++;
		i++; int l = dfs(s, i); i++;
		int r = dfs(s, i); i++;
		if (a[b] == 0)return l&r;
		else if (a[b] == 1)return l | r;
		else return l^r;
	}
	else {
		int a = u[s[i] - '1']; i++;
		return a;
	}
}
void calc(int p) {
	if (p == lim) {
		int i = 0; cnt = 0; if (dfs(s, i) == (1 << 4) - 1)ans++;
		return;
	}
	rep(i, 3)a[p] = i, calc(p + 1);
}
int main() {
	while (getline(cin, s), s != "END") {
		int n; scanf("%d", &n);
		memset(u, 0, sizeof(u));
		rep(i, n)rep(j, 4) {
			int a; scanf("%d", &a);
			u[i] |= a << j;
		}
		cnt = 0; int i = 0; dfs(s, i);
		lim = cnt;
		ans = 0; calc(0);
		printf("%d\n", ans);
		scanf("\n");
	}
}

Measured memory_bytes: 3176
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

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

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

int main() {
    int n = 0;
    cin >> n;
    int cnt_74 = 0, cnt_24 = 0, cnt_14 = 0, cnt_4 = 0, cnt_2 = 0;
    for (int i=1; i<=n; i++) {
        if (is_prime(i)) {
            int tmp = 0;
            int cur = i;
            while (cur <= n) {
                tmp += n / cur;
                cur *= i;
            }
            if (tmp >= 74) {
                cnt_74++;
            }
            if (tmp >= 24) {
                cnt_24++;
            }
            if (tmp >= 14) {
                cnt_14++;
            }
            if (tmp >= 4) {
                cnt_4++;
            }
            if (tmp >= 2) {
                cnt_2++;
            }
        }
    }
    cout << cnt_74 + cnt_24*(cnt_2-1) + cnt_14*(cnt_4-1) + cnt_4*(cnt_4-1)*(cnt_2-2)/2 << endl;
    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[30][51000];

int main(){
    ll n,w;
    cin >> n >> w;
    ll val[n],wei[n];
    for (ll i=0;i<n;i++)cin >> val[i] >> wei[i];
    ll dp[n+1][w+1100],ans=0;
    for (ll i=0;i<=n;i++){
        fill(dp[i],dp[i]+w+1,0);
    }
    for (ll i=0;i<n;i++){
        for (ll j=0;j<=w;j++){
            if (j<wei[i]){
                dp[i+1][j]=dp[i][j];
            }else{
                dp[i+1][j]=max(dp[i][j],dp[i+1][j-wei[i]]+val[i]);
            }
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 11404