akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main(){

    input!{
        n: usize,
        m: usize,
        a: [usize;n],
    }

    let mut sum: usize = 0;
    for &i in &a{
        sum += i;
    }

    let mut border = sum / (4*m);
    let r = sum % (4*m);
    if r!=0 {
        border += 1;
    } 
    let mut cnt = 0;
    for &i in &a{
        if i >= border {
            cnt += 1;
        } 
    }
    if cnt >= m {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))

times = 0
flag = 1
while flag:
    flag = 0
    for j in range(n-1,0,-1):
        if A[j] < A[j-1]:
            A[j-1], A[j] = A[j], A[j-1]
            times += 1
            flag = 1

B = " ".join([str(num) for num in A])
print(B)
print(times)




Measured memory_bytes: 5608
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
ll cnt[100001];
int main() {
	int N;
	ll K;
	cin >> N >> K;
	for (int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		cnt[a] += b;
	}
	for (int ans = 1; ans <= 100000; ++ans) {
		if (K <= cnt[ans]) {
			cout << ans << endl;
			break;
		}
		K -= cnt[ans];
	}
	return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

const lint M = 1000000000000000000;

int main(){
    lint n;
    cin >> n;
    vector< vector< pair<lint, lint> > > tree(n);
    for(lint i = 0 ; i < n - 1 ; i++){
        lint a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        tree[a].push_back(make_pair(b, c));
        tree[b].push_back(make_pair(a, c));
    }
    lint q, k;
    cin >> q >> k;
    k--;
    queue<lint> bfs;
    bfs.push(k);
    vector<lint> dis(n, M);
    dis[k] = 0;
    while(!bfs.empty()){
        lint tmp = bfs.front();
        bfs.pop();
        for(lint i = 0 ; i < tree[tmp].size() ; i++){
            if(dis[tree[tmp][i].first] == M){
                bfs.push(tree[tmp][i].first);
                dis[tree[tmp][i].first] = dis[tmp] + tree[tmp][i].second;
            }
        }
    }
    for(lint i = 0 ; i < q ; i++){
        lint x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << dis[x] + dis[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 9984
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
//const double EPS = 1e(-12);
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

int arr[100010];

map<int, int> mp;

ll powmod(ll x, ll n)
{
    ll res = 1;
    while (n)
    {
        if ((n & 1) == 1)
        {
            res *= x;
            res %= MOD;
        }
        x = x * x;
        x %= MOD;
        n >>= 1;
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    int N;
    cin >> N;

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

    int odd = 0, even = 0;

    for (auto e : mp)
    {
        if (e.second == 2)
            even++;
        else
            odd++;
    }

    if (N % 2 == 0)
    {
        if (N / 2 != even)
        {
            cout << 0 << endl;
            return 0;
        }
        else
        {
            cout << powmod(2, even) << endl;
        }
    }
    else
    {
        if (!(mp[0] == 1 && N / 2 == even))
        {
            cout << 0 << endl;
            return 0;
        }
        else
        {
            cout << powmod(2, even) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3200
import std.stdio;
import std.conv;
import std.math;

void main() {
	double n;
	scanf("%lf", &n);
	auto y = n / 1.08;
	auto n2 = n.to!int;
	auto y2 = y.ceil.to!int;

	if (floor(y2 * 1.08).to!int == n2 || floor((y2+1) * 1.08).to!int == n2) {
		y2.write;
	}
	else {
		":(".write;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
ii trans[10] = {{1, 0}, {1, 2}, {1, 4}, {1, 6}, {1, 8}, {2, 1}, {2, 3}, {2, 5}, {2, 7}, {2, 9}};

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  ll res = 0;
  vi ost;
  for(int i = 0; i < n; i++){
    int d;
    ll c;
    cin >> d >> c;
    if(c % 2 == 1){
      ost.push_back(d);
      c--;
    }
    int num = d;
    while(c > 0){
      int tonum = trans[num].second;
      res += (c / 2) * trans[num].first;
      num = tonum;
      c /= 2;
      if(c % 2 == 1){
        ost.push_back(num);
        c--;
      }
    }
  }
  for(int i = 0; i < int(ost.size()) - 1; i++){
    int x = ost[i] + ost[i + 1];
    res++;
    while(x >= 10){
      int nn = x;
      int a1 = nn % 10;
      nn /= 10;
      int a2 = nn % 10;
      x = a1 + a2;
      res++;
    }
    ost[i + 1] = x;
  }
  cout << res;
}

Measured memory_bytes: 18664
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll k; cin >> k;

    if(k % 2 == 0){
        cout << -1 << endl;
        return 0;
    }

    ll tmp = 7;
    ll cnt = 0;
    map<ll, ll> mp;
    while(true){
        tmp = tmp % k;
        cnt++;
        if(tmp % k == 0){
            break;
        }else{
            if(mp[tmp] == 0){
                mp[tmp]++;
            }else{
                cout << -1 << endl;
                return 0;
            }
            tmp = tmp*10 + 7;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 66092
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, M = sc.nextInt()
    val X = Array.fill(M)(sc.nextInt()).sorted

    if (N >= M)
      println(0)
    else
      println(X(M-1) - X(0) - X.sliding(2).map(_.reduce((a, b) => b - a)).toSeq.sorted(Ordering.Int.reverse).take(N - 1).sum)
  }

}


Measured memory_bytes: 79984
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long sum = 0;

        for (int a = 1; a <= N; a++) {
            if (!(a % 3 == 0 || a % 5 == 0)) {
                sum += a;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 27224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }






int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    
    int n;
    while (cin >> n && n) {
        string s[n];
        rep(i, n) cin >> s[i];
        vector<string> head(n);
        vector<vector<string> > contents(n);
        rep(i, n) { // make head's
            string c;
            rep(j, sz(s[i])) {
                if (s[i][j] == ':') {
                    head[i] = c;
                    break;
                }
                c += s[i][j];
            }
        }
        // rep(i, n) cout << head[i] << " "; cout << endl;
        rep(i, n) {
            int flg = 0; // :?
            string c;
            rep(j, sz(s[i])) {
                if (s[i][j] == ':') { flg = 1; continue; }
                if (flg == 0) continue;
                if (s[i][j] == ',' || s[i][j] == '.') {
                    contents[i].eb(c);
                    c = "";
                    continue;
                }
                c += s[i][j];
            }
        }
        // rep(i, n) { rep(j, sz(contents[i])) cout << contents[i][j] << " "; cout << endl; }
        
        queue<int> q;
        set<int> can;
        can.insert(0);
        int used[104] = {0};
        q.push(0);
        used[0] = 1;
        while (!q.empty()) {
            int now = q.front();
            q.pop();
            rep(i, sz(contents[now])) {
                rep(j, n) {
                    if (head[j] == contents[now][i] && used[j] == 0) {
                        used[j] = 1;
                        can.insert(j);
                        q.push(j);
                        break;
                    }
                }
            }
        }
        
        set<string> S;
        for (auto i : can) rep(j, sz(contents[i])) {
            rep(k, sz(head)) {
                if (contents[i][j] == head[k]) break;
                if (k == sz(head) - 1) {
                    S.insert(contents[i][j]);
                }
            }
        }
        cout << sz(S) << endl;
    }
}





Measured memory_bytes: 3380
n=int(input())
A=list(map(int,input().split()))

s=0
cap=[]
flag=False
ans=2**(n+1)-1
for i,a in enumerate(A):
    s*=2
    s+=a
    cap.append(2**i-s)
    #if i!=n:
    #    ans-=a*(2**(n+1-i)-2)
    if s>2**i:
        flag=True
        break

if flag:
    print(-1)
else:
    remain=2**n-s
    ans=0
    node=0
    for i in range(n,-1,-1):
        a=A[i]
        c=cap[i]
        node=min(c,node)+a
        ans+=node
    print(ans)

Measured memory_bytes: 702168
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
score=0
te=[]
for a in range(n):
  if a-k>=0and te[0].count('prs'['rsp'.index(t[a])])==2:
    te+=[[t[a],'spr'['rsp'.index(t[a])]]]#;print(t[a],'あいこ')
  else:
    score+=[p,r,s]['rsp'.index(t[a])]#;print('prs'['rsp'.index(t[a])],'勝ち')
    te+=[['prs'['rsp'.index(t[a])]]*2]
  if a-k>=0:
    del te[0]
print(score)
#prrsp

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>>S(H, vector<char>(W));
    vector<vector<int>> num(H+2, vector<int>(W+2));
    rep(i,H) {
        rep(j,W) {
            cin >> S[i][j];
        }
    }


    rep(i,H) {
        rep(j,W) {
            if (S[i][j] == '#') {
                for (int k = i; k <= i + 2; k++) {
                    for (int l = j; l <= j + 2; l++) {
                        num[k][l]++;
                    }
                }
            } 
        }
    }





    rep(i, H) {
        rep(j, W) {
            if (S[i][j] == '.') {
                cout << num[i+1][j+1];
            }
            if (S[i][j] == '#') {
                cout << '#';
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define INF (1<<28)

int ans = 0;
int cur = 0;
int mp[22][22];

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

int dfs(int x,int y,int lim){
	if( cur >= ans )return 0;
	
	if( lim <= 0 ) return 0;
	
	for(int i = 0 ; i < 4 ; i++){
		int X = x+dx[i] , Y = y+dy[i];
		if( mp[Y][X] == 1 ) continue;
		int f = 1;
		while(1){
			if(mp[Y][X] == -1){ f=false;break; }
			else if(mp[Y][X] == 2 || mp[Y][X] == 0){ X+=dx[i],Y+=dy[i]; }
			else if(mp[Y][X] == 1){ X-=dx[i],Y-=dy[i];break;  }
			else if(mp[Y][X] == 3){
				if( ans > cur+1 ){
					ans = cur+1;
				}
				return 0;
			}
		}
		if( f ){
			cur++;
			mp[Y+dy[i]][X+dx[i]] = 0;
			dfs(X,Y,lim-1);
			cur--;
			mp[Y+dy[i]][X+dx[i]] = 1;
		}
	}
	return 0;
}

int main(){
	int w,h;
	while(cin >> w >> h && w){
		for(int i = 0 ; i < 22 ; i++)
			for(int j = 0 ; j < 22 ; j++)
				mp[i][j] = -1;
		int sx , sy;
		for(int i = 0 ; i < h ; i++){
			for(int j = 0 ; j < w ; j++){
				cin >> mp[i+1][j+1];
				if( mp[i+1][j+1] == 2 ){
					sx = j+1;
					sy = i+1;
				}
			}
		}
		
		ans = INF;
		dfs(sx,sy,10);
		
		cout << (ans==INF?-1:ans) << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000
#define gc getchar_unlocked
#define pc putchar_unlocked
#define pb(a) push_back((a))


int main(){
    lo t,n;
    cin>>t;


        lo ans=(t-2)*180;
        cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
n, a = [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]
max_num = max(num_list)
field = [ [ 0 for i in range(5000) ] for i in range(n+1) ]
field[0][0] = 1

b = num_list[0]
for i in num_list:
    for j in range(n,0,-1):
        for k in range(5000):
            if k >= i:
                field[j][k] += field[j-1][k-i]



ans = 0
for i in range(1,n+1):
    ans += field[i][a*i]
print(ans)

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

int main()
{
	
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b && a!=c) || (a==c && a!=b )|| (b==c && a!=b))
	{
		cout<<"Yes"<<endl;
	}
	else
		cout<<"No"<<endl;
	return 0;
	
}


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

int main(){
  int n;
  cin >> n;
  int d1 = n % 10;
  int d2 = n / 10 % 10;
  int d3 = n / 100;
  if(d1==7 || d2==7 || d3==7){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>

#define maxn 110
int a[maxn];
int main()
{
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);
	std::sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i)
	{
		if (m < a[i]) {printf("%d\n", i - 1); return 0;}
		m -= a[i];
	}
	printf("%d\n", !m ? n : n - 1);
	return 0;
}

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

int main() {
  int N, x;
  cin >> N >> x;
  int a[N];
  ll ans = 0;
  for (int i=0; i<N; i++)
    cin >> a[i];
  if (a[0] > x) {
    ans += a[0]-x;
    a[0] = x;
  }
  for (int i=1; i<N; i++) {
    if (a[i-1]+a[i] > x) {
      ans += a[i-1]+a[i]-x;
      a[i] -= a[i-1]+a[i]-x;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{

  int N,A[100][2];
  cin>> N;
  for(int i=0;i<N;i++)cin>> A[i][0];
  for(int i=0;i<N;i++)cin>> A[i][1];

  int ret=0;
  int sum[100][2];
  sum[0][0]=A[0][0];
  sum[N-1][1]=A[N-1][1];
  for(int i=1;i<N;i++)
  {
    sum[i][0]=sum[i-1][0]+A[i][0];
    cerr<< sum[i][0]<< " "<< endl;
  }
  cerr<< endl;
  for(int i=N-2;i>-1;i--)
  {
    sum[i][1]=sum[i+1][1]+A[i][1];
    cerr<< sum[i][1]<< " "<< endl;
  }
  cerr<< endl;
  for(int i=0;i<N;i++)
  {
    ret=max(ret,sum[i][0]+sum[i][1]);
    cerr<< sum[i][0]+sum[i][1]<< endl;
  }
  cout<< ret<< endl;

  return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


# sys.setrecursionlimit(10**5)


def main():
    h, n = geta(int)

    if h <= sum(list(geta(int))):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 52464
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>  // assert(x>=10), 部分点問題
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <set>

#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
#define SORT(v,n) sort(v,v+n)
#define VSORT(v) sort(all(x))
#define FILL(v, value) (v+(sizeof(v) / sizeof *(v)), value);
#define inf 999999999
#define dbg(x) cout<<#x<<":"<<x<<endl;
#define pb(a) push_back((a))
#define mp(a) make_pair((a))
#define pi 2*acos(0.0)
#define in scanf
#define out printf
#define fi first
#define se second

// --
#define bit(n) (1LL<<(n)) // 左bitシフト
// --

using namespace std;

typedef long long llong;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<llong, pll> plp;

const int MOD=1000000007;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};  // 右下左上


int main(int argc, char**argv){
    int n, m;
    int t[100+2];
    int p[100+2];
    int x[100+2];

    cin >> n;
    rep(i, n) in("%d", &t[i]);
    int sum = 0;
    rep(i, n) sum += t[i];

    cin >> m;
    rep(i, m){
        in("%d%d", &p[i], &x[i]);
        p[i]--;
    }

    rep(i, m){
        out("%d\n", sum - (t[p[i]] - x[i]));
    }
    return 0;
}




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

int main() {
  int N;
  cin >> N;
  
  vector<int> Vi,Ci; 
  rep(i,N){
    int tmpVi;
    cin >> tmpVi;
    Vi.push_back(tmpVi); 
  }
  
  rep(i,N){
    int tmpCi;
    cin >> tmpCi;
    Ci.push_back(tmpCi); 
  }
  
  int ans = 0;
  rep(i,N){
    int earn = Vi.at(i) - Ci.at(i);
    if(earn > 0) ans += earn;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INT(a) scanf("%d",&a)
#define STR(a) scanf("%s",a)
#define DBL(a) scanf("%lf",&a)
#define LNG(a) scanf("%lld",&a)
#define PI acos(-1)

int sum[100005];
int main(){
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int mx=0, psum=1, ptr=0;
	vector< int > vc;
	if(s[0]=='0') vc.push_back(0);
	for(int i=1;i<n;i++){
		if(s[i]!=s[i-1]){
			vc.push_back(psum);
			psum=1;
		} else psum++;
	}
	vc.push_back(psum);
	if(s[n-1]=='0') vc.push_back(0);
	int len = vc.size();

	//for(int i=0;i<len;i++) cout<<vc[i]<<endl;
		
	
	int sz = k*2+1;
	//if(s[0]=='0') sum[0]+=vc[0], ptr=1;
	for(int i=0;i<len;i++){
		sum[i]=sum[i-1]+vc[i];
		if(i+1<=sz) mx=max(mx, sum[i]);
		else{
			if(i%2==0) mx = max(mx, sum[i]-sum[i-sz]);
			else continue;
			//cout<<i<<" "<<mx<<" "<<sum[i]<<" "<<sum[i-sz]<<endl;
		}
	}

	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <numeric>

inline int gcd(int a, int b){
  if(b<a) std::swap(a, b);
  int r = a % b;
  if(r==0) return b;
  while(r!=0) r = a % b, a = b, b = r;
  return a;
}

inline int read(){
	int x=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=x*10+c-'0';c=getchar();}
	return x*f;
}

int cnt[1000001];
int main(){
  int n = read();
  int num = read();
  int o = 0, g = num;
  if(num==1) o=1;
  int ex = (n-1)/4;
  cnt[num] = 1;

  for(int i=0;i<ex;i++){
    int num = read();
    if(num==1) o++;
    g = std::gcd(g, num);
    cnt[num]++;

    num = read();
    if(num==1) o++;
    g = std::gcd(g, num);
    cnt[num]++;

    num = read();
    if(num==1) o++;
    g = std::gcd(g, num);
    cnt[num]++;

    num = read();
    if(num==1) o++;
    g = std::gcd(g, num);
    cnt[num]++;
  }

  for(int i=0;i<(n-1)%4;i++){
    int num = read();
    if(num==1) o++;
    g = std::gcd(g, num);
    cnt[num]++;
  }

  if(n - o > 80000){
    if(g==1) printf("setwise coprime\n");
    else printf("not coprime\n");
    return 0;
  }

  int max_S = 0;
  for(int i=2;i<=1000000;i++){
    int S = 0;
    for(int j=i;j<=1000000;j+=i) S += cnt[j];
    if(max_S<S) max_S = S;
  }
  if(max_S<2) printf("pairwise coprime\n");
  else if(max_S != n) printf("setwise coprime\n");
  else printf("not coprime\n");
}


Measured memory_bytes: 7536
#include<stdio.h>

int main(void)
{
	int a, b, c, d;

	scanf("%d%d%d%d", &a, &b, &c, &d);

	if (a*b >= c*d)
		printf("%d\n", a*b);
	else
		printf("%d\n", c*d);

	return 0;
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var card = new int[3][];
        for (int i = 0; i < card.Length; ++i)
        {
            card[i] = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        }
        var n = int.Parse(Console.ReadLine());
        var seqB = Console.In.ReadToEnd().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();

        var indices = new Dictionary<int, int>();
        for (int i = 0; i < card.Length; ++i)
        {
            for (int j = 0; j < card[i].Length; ++j)
            {
                indices[card[i][j]] = i << 3 | 1 << j;
            }
        }

        var hit = new int[3];
        for (int i = 0; i < seqB.Length; ++i)
        {
            int index;
            if (indices.TryGetValue(seqB[i], out index))
            {
                hit[index >> 3] |= index & 7;
            }
        }
        
        var bingo = hit.Any(x => x == 7);
        bingo = bingo || hit.Aggregate(7, (x, y) => x & y) > 0;
        bingo = bingo || (hit[0] & 4 | hit[1] & 2 | hit[2] & 1) == 7 || (hit[0] & 1 | hit[1] & 2 | hit[2] & 4) == 7;
        Console.WriteLine(bingo ? "Yes" : "No");
    }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    rep(i, 0, 4) {
        cout << s[i];
    }
    cout << ' ';
    rep(i, 4, s.size()) {
        cout << s[i];
    }
    cout << endl;
}

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

public class Main {

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = "";
		ArrayList<Integer> lines = new ArrayList<Integer>();

		try {
			while (null != (s = br.readLine())) {
				lines.add(Integer.valueOf(s));
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		for (Integer n : lines) {

			if (n < 0) {
				return;
			} else if (n > 36) {
				System.out.println(0);
			} else {
				try {
					int count = 0;

					for (int a = 0; a <= 9; a++) {
						for (int b = 0; b <= (n - a) && b <= 9; b++) {
							for (int c = 0; c <= (n - a - b) && c <= 9; c++) {
								int d = n - a - b - c;
								if (d <= 9)
									count++;
							}
						}
					}
					System.out.println(count);
				} catch (NumberFormatException e) {
					e.printStackTrace();
				}
			}

		}
	}
}

Measured memory_bytes: 17796
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct shop {
    string name;
    int point, id;
};

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

    int N;
    cin >> N;
    vector<shop> sp(N);
    REP(i, N) {
        string s;
        int a;
        cin >> s >> a;
        sp[i].name  = s;
        sp[i].id    = i + 1;
        sp[i].point = a;
    }
    sort(ALL(sp), [&](const shop x, const shop y) {
        if (x.name == y.name)
            return x.point > y.point;
        return x.name < y.name;
    });

    REP(i, N) { std::cout << sp[i].id << '\n'; }

    return 0;
}

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

int main() {
	int N; cin>>N;
	vector<int> H(N);
	for (int i=0; i<N; i++)
		cin>>H[i];
	int ans=0;
	for (int i=0; i<N; i++) {
		bool is_candidate=true;
		for (int j=0; j<i; j++) {
			if (H[j]>H[i]) {
				is_candidate=false;
				break;
			}
		}
		if (is_candidate)
			ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  int A,B; cin>>A>>B;

  int  ans = -1;
  FOR(p, 1, 10004) {
    if (((int)(p * 0.08) == A) && ((int)(p * 0.1) == B)) {
      ans = p;
      break;
    }
  }

  cout << ans << endl;


  return 0;
}


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

int main(void)
{
    int N;
    int a[200];

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

    int Alce = 0;
    int Bob = 0;

    sort(a, a + N, greater<int>());

    for (int j=0; j < N; j++){

        if(j % 2 == 0) Alce += a[j];
        else Bob += a[j];
    }
    cout << Alce - Bob << endl;

}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    char s[100005];
    ll n;
    scanf("%s",s);
    n= strlen(s);
    ll p[n],ls[n],lma=0;
    rep(i,0,n) p[i]=0;
    rep(i,1,n){
        if(s[i]=='L'){
            if(s[i-1]=='R'){
                ls[lma]=i;
                lma++;
            }
        }
    }
    ll j=0;
    // rep(i,0,lma){
    //     printf("%lld\n",ls[i]);
    // }
    rep(i,0,n){
        if(i>ls[j] && s[i]=='R'){
            j++;
        }
        if(  ABS( ls[j]-i )%2 ){
            p[ls[j]-1]++;
        }else{
            p[ls[j]]++;
        }
    }
    rep(i,0,n){
        printf("%lld ",p[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
	int N;
	string S, T;
	cin >> N >> S >> T;
	string u;
	for (int i = 0; i < N; i++) {
		u += S[i];
		u += T[i];
	}

	cout << u << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = []
b = []
for i in range(m):
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)

ans = [0 for i in range(n)]

for i in range(m):
    ans[a[i]-1] += 1
    ans[b[i]-1] += 1

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

Measured memory_bytes: 3064
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (x, a, b) = (v[0], v[1], v[2]);
    if b <= a {
        println!("delicious");
    } else {
        let b = b - a;
        if b <= x {
            println!("safe");
        } else {
            println!("dangerous");
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int cnt = 0;
  while(a >= b){
    b *= 2;
    ++cnt;
  }
  while(b >= c){
    c *= 2;
    ++cnt;
  }
  cout << (cnt <= k ? "Yes":"No") << endl;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  string s;
  while (cin >> s) {
    lli sum = 0;
    for (int bit = 0; bit < (1 << (s.size() - 1)); ++bit) {
      vector<string> v;
      string t;
      for (int i = 0; i < s.size(); ++i) {
        t += s[i];
        if (bit & (1 << i)) {
          v.push_back(t);
          t = "";
        }
      }
      v.push_back(t);
      // each (s, v) cout << s << ","; cout << endl;
      each (s, v) sum += atol(s.c_str());
    }
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 764
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

int main() {
  int n; cin >> n;
  vector<ll> A(n);
  loop(i,0,n) cin >> A[i];
  sort(A.begin(), A.end());
  ll max_ = A[n-1];
  n--;
  A.pop_back();
  ll min_ = 100000000000000;
  ll ans = -1;
  for (auto &&a: A) {
    if (abs(a*2 - max_) < min_) {
      min_ = abs(a*2 - max_);
      ans = a;
    }
  }
  
  cout << max_ << " " << ans << endl;
  return 0;
}


Measured memory_bytes: 4004
#include<bits/stdc++.h>
using namespace std;
int main()
{
double A,m,x,v;
    int N;
    cin>>N;
    for( int i=1;i<=N;i++)
    {
        cin>>A;
        x+=(1/A);
    }
    v=1/x;
    printf("%lf",v);
    return 0;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
tmp = 0
p.sort(reverse=True)
p.append(0)
q.sort(reverse=True)
q.append(0)
r.sort(reverse=True)
r.append(0)
z = X+Y
e, f, g = 0, 0, 0
for i in range(z):
    if X>0 and ((p[e]>=q[f] and p[e]>=r[g]) or (Y==0 and p[e]>=r[g])):
        tmp = tmp+p[e]
        e += 1
        X -= 1
    elif Y>0 and ((q[f]>=p[e] and q[f]>=r[g]) or (X==0 and q[f]>=r[g])):
        tmp = tmp+q[f]
        f += 1
        Y -= 1
    elif r[g]>p[e] or r[g]>q[f]:
        tmp = tmp+r[g]
        g += 1
        
print(tmp)

Measured memory_bytes: 23216
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <chrono>
#include <numeric>
#include <list>

using namespace std;


list<int> edges[51];
bool flg[51];


bool dfs(list<int> a, int e){
  while (!a.empty()) {
    int q = a.front();
    a.pop_front();
    if (flg[q])
      continue;
    flg[q] = true;
    if (q==e) {
      return true;
    } else {
      a.insert(a.end(), edges[q].begin(), edges[q].end());
    }
  }
  return(false);
}


int main(){
  int n, m;
  int count=0;
  cin >> n >> m;
  for (int i=0;i<m;i++) {
    int a, b;
    cin >> a >> b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for (int i=0;i<=n;i++) {
    list<int> es = edges[i];
    if (es.empty()) {
      continue;
    }
    int es_array[51];
    int k=0;
    for (int e:es) {
      es_array[k] = e;
      k++;
    }
    //    cout << "i:" << i << endl;
    for (int j=0;j<k;j++) {
      es.remove(es_array[j]);
      for (int i=0;i<=n;i++) {
	flg[i] = false;
      }
      flg[i] = true;
      //      cout << "e:" << es_array[j] << endl;
      /*      for (int tmp:es) {
	cout << tmp << " ";
	}*/
      //      cout << endl;
      if (!dfs(es, es_array[j])) {
	count++;
	//	cout << "bridge:" << count << " "<< i << " to " << es_array[j] << endl;
      }
      es.push_back(es_array[j]);
    }
  }
  cout << count/2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#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;
//const long long MOD = 998244353;
using namespace std;

vector<vector<int> > g;
vector<int> d;
vector<int> maxd;
vector<int> up;

int dfs(int par, int curr, int depth_curr)
{
    d[curr]=depth_curr;
    up[curr]=par;
    int siz=(int)g[curr].size();
    int max=depth_curr;
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(next==par) continue;

        int ret=dfs(curr, next, depth_curr+1);
        max=MAX(ret,max);
    }
    return maxd[curr]=max;
}

int main(int argc, char* argv[])
{
    int n,u,v;
    scanf("%d%d%d", &n, &u, &v); u--; v--;

    g.resize(n);
    d.resize(n);
    maxd.resize(n);
    up.resize(n);
    int i;
    for(i=0; i<n-1; i++) {
        int a,b;
        scanf("%d%d", &a, &b); a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    if(u==v) {
        printf("0\n"); return 0;
    }
    dfs(-1,v,0);

    int curr=u;
    int tmp=(d[u]-1)/2;
    for(i=0; i<tmp; i++) {
        u=up[u];
    }

    printf("%d\n", maxd[u]-1);

    return 0;
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	int n;
	cin>>n;
	vector<ll>v(n);
	multiset<ll> s;
	for(int i=0;i<n;i++){
		scanf("%lld", &v[i]);
	}
	s.insert(v[0]);
	for(int i=1; i<n;i++){
		auto it = s.lower_bound(v[i]);
		if(!(it==s.begin())){
			it--;
			s.erase(it);
		}
		s.insert(v[i]);
	}
	cout<<s.size()<<endl;
}

Measured memory_bytes: 5760
#%%
n = int(input())
s = list(input())
for i in range(n):
	s[i] = int(s[i])
#print(s)

l = [0] * 10
r = [0] * 10
for i in range(n):
	r[s[i]] += 1

ans = [0] * 1002

for i in range(n):
	if i == 0:
		l[s[i]] += 1
		r[s[i]] -= 1
		r[s[i+1]] -= 1
	elif i == n-1:
		pass
	else:
		for j in range(10):
			for k in range(10):
				if l[j] != 0 and r[k] != 0:
					a = j
					b = s[i]
					c = k
					tmp = a * 100 + b * 10 + c
					if ans[tmp] == 0:
						ans[tmp] = 1

		l[s[i]] += 1
		r[s[i+1]] -= 1
	#print('l', l)
	#print('r', r)


q = ans.count(1)
"""
for i in range(len(ans)):
	if ans[i] != 0:
		print(i)
"""
print(q)

Measured memory_bytes: 3444
# 解説放送

def main():
    N, K = map(int, input().split())
    *P, = (int(x) - 1 for x in input().split())
    *C, = map(int, input().split())

    ans = -10**9 - 1

    for si in range(N):
        g = []
        tot = 0
        cur = si
        while True:
            cur = P[cur]
            g.append(C[cur])
            tot += C[cur]
            if cur == si or len(g) == K:
                break

        L = len(g)
        t = 0
        for i, x in enumerate(g, start=1):
            t += x
            now = t
            if tot > 0:
                rep = (K - i) // L
                now += tot * rep

            ans = max(ans, now)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84080
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int x[100], y[100];
int mini[100], rr[100];
int main()
{
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size() + t.size(); i++)
	{
		if (i % 2 == 0)printf("%c", s[i / 2]);
		else printf("%c", t[i / 2]);
	}
	printf("\n");
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<int, int> > x;
    vector<pair<int, int> > y;
    int a, b;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        x.push_back(make_pair(b, a));
    }
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        y.push_back(make_pair(a, b));
    }
    sort(x.begin(), x.end(), greater<pair<int, int> >());
    sort(y.begin(), y.end());
    int cnt = 0;
    
    vector<pair<int, int> >::iterator itx;
    vector<pair<int, int> >::iterator ity;
    for (ity = y.begin() ; ity != y.end() && !x.empty(); ity++) {
        pair<int, int> tempy = *ity;
        for (itx = x.begin() ; itx != x.end() ; itx++) {
            pair<int, int> tempx = *itx;
            if (tempx.second < tempy.first && tempx.first < tempy.second) {
                cnt++;
                x.erase(itx);
                break;
            }
            
        }
    }
    cout << cnt << '\n';
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, P := ReadInt(), ReadInt()
	factors := Factorization(P)
	ans := 1
	for i := 0; i < len(factors); i++ {
		factor, cnt := factors[i][0], factors[i][1]
		ans *= Pow(factor, cnt/N)
	}
	fmt.Println(ans)
}

func Pow(a, b int) int {
	x := 1
	for b > 0 {
		if b&1 == 1 {
			x *= a
		}
		a *= a
		b >>= 1
	}
	return x
}

func Factorization(n int) [][]int {
	res := [][]int{}
	for i := 2; i*i <= n; i++ {
		if n%i != 0 {
			continue
		}
		cnt := 0
		for n%i == 0 {
			n /= i
			cnt++
		}
		res = append(res, []int{i, cnt})
	}
	if n != 1 {
		res = append(res, []int{n, 1})
	}
	return res
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

#define db(x) cerr << #x ": " << (x) << '\n';

#define int long long

using namespace std;

typedef long long ll;

typedef long double ld;

const int oo = 1e18;

int K, N;

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

    cin >> K >> N;

    vector<int> vect;

    for(int i = 0 ; i < N ; i++)
    {
        int n;
        cin >> n;
        vect.push_back(n);
    }

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

    int may = -1;

    for(int i = 1 ; i < vect.size() ; i++)
    {
        may = max(may,vect[i]-vect[i-1]);
    }
    may = max(may,K-vect.back()+vect[0]);

    cout << K-may << '\n';

    return 0;
}


Measured memory_bytes: 2420
from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse import csr_matrix


H, W = map(int, input().split())

maze = [list(input()) for _ in range(H)]

# build graph
cnt = 0
node_num_dic = {}
for r in range(H):
    for c in range(W):
        if maze[r][c] == '.':
            node_num_dic[(r, c)] = cnt
            cnt += 1

act = [[-1, 0], [0, -1], [1, 0], [0, 1]]
nei_graph = [[0] * (cnt) for _ in range(cnt)]

for r in range(H):
    for c in range(W):
        if maze[r][c] == '.':

            for r_x, c_x in act:
                new_r = r + r_x
                new_c = c + c_x
                if (0 <= new_r <= H - 1) and (0 <= new_c <= W - 1):
                    if maze[new_r][new_c] == '#':
                        continue

                    from_num = node_num_dic[(r, c)]
                    to_num = node_num_dic[(new_r, new_c)]

                    nei_graph[from_num][to_num] = 1


nei_graph = floyd_warshall(nei_graph, directed=False)

ret = 0
for r in range(cnt):
    for c in range(cnt):
        if nei_graph[r][c] != float('inf'):
            ret = max(ret, nei_graph[r][c])

print(int(ret))


Measured memory_bytes: 17952
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
const int mod=1e9+7;
const int N=1e5+10;
vector<int> g[N];
struct node{
    int u,v;
};
int vis[N],clor[N],n,u,v,mx,s;
vector<node>edge;
map<pair<int,int>,int>m;
void bfs(int s)
{
    queue<int >q;
    q.push(s);
    vis[s]=1;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        int c=1;
        for(auto v:g[u])
        {
            if(!vis[v])
            {
                q.push(v);
                if(c==clor[u])
                    (c==mx-1)?c=mx:(c=(c+1)%mx);
                clor[v]=c;
               m[{min(u,v),max(u,v)}]=c;
                (c==mx-1)?c=mx:(c=(c+1)%mx);
                vis[v]=1;
            }
        }
    }
}
int main()
{
    cin>>n;
    for(int i=0; i<n-1; i++)
    {
        int a,b;
        cin>>a>>b;
        edge.push_back({a,b});
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i=1; i<=n; i++)
    {
        if(g[i].size()>mx)
        {
            mx=g[i].size();
            s=i;
        }
    }
    bfs(s);
    clor[s]=0;
     cout<<mx<<endl;
    for(auto i:edge) cout<<m[{min(i.u,i.v),max(i.u,i.v)}]<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 998244353;

ll modpow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int cnt = 0;
			for (int k = j + 1; k < n; k++) {
				if (x[i] == x[j]) {
					if (x[k] == x[i]) {
						cnt++;
					}
				} else if ((x[i] - x[j]) * (y[k] - y[i]) == (y[i] - y[j]) * (x[k] - x[i])) {
					cnt++;
				}
			}
			(ans += modpow(2, cnt)) %= MOD;
		}
	}
	(ans += n + 1) % MOD;
	ans = (modpow(2, n) - ans + MOD) % MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> arrN;
vector<int> arrW;
vector<vector<long long>> dp;
long long knapSackAt(int n,int w){
    if(dp[n][w]!=-1){
        return dp[n][w];
    }
    if(n==0){
        if(arrN[0]<=w){
            dp[n][w] = arrW[0];
            return dp[n][w];
        }else {
            dp[n][w] = 0;
            return dp[n][w];
        }

    }if(arrN[n]<=w){
        dp[n][w] = max(knapSackAt(n-1,w),(arrW[n]+knapSackAt(n-1,w-arrN[n])));
        return dp[n][w];
    }else{
        dp[n][w] = knapSackAt(n-1,w);
        return dp[n][w];
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,w;
    cin >> n >> w;
    arrN = vector<int>(n);
    arrW = vector<int>(n);
    for(int i =0;i<n;i++){
        cin >> arrN[i] >> arrW[i];
    }   
    dp = vector<vector<long long>>(n,vector<long long>(w+1,-1));

    cout << knapSackAt(n-1,w) << "\n";
    return 0;
}

Measured memory_bytes: 82320