akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

using namespace std;

LL const mod = 924844033, MAXN = 1e4 + 5;
int vis[MAXN], len[MAXN], tot;
LL dp[2][MAXN][2], g[2][MAXN], frac[MAXN];
vector <LL> f[MAXN];

int main() {
 // freopen("count.in", "r", stdin);
 // freopen("count.out", "w", stdout);
  int n, k; scanf("%d %d", &n, &k);
  frac[0] = 1;
  for (RI i = 1; i <= n; ++i) frac[i] = frac[i - 1] * 1ll * i % mod;
  if (!k) return printf("%lld\n", frac[n]), 0;
  for (RI i = 1; i <= n; ++i)
    if (!vis[i]) {
      len[++tot] = 0;
      for (RI j = i; j <= n; j += k)
        vis[j] = 1, ++len[tot];
      memset(dp, 0, sizeof(dp));
      dp[1][0][0] = 1;
      for (RI j = 2; j <= len[tot]; ++j) {
        for (RI l = 0; l <= j >> 1; ++l) {
          dp[j & 1][l][0] = (dp[(j + 1) & 1][l][0] + dp[(j + 1) & 1][l][1]) % mod;
          if (l > 0) dp[j & 1][l][1] = dp[(j + 1) & 1][l - 1][0];
        }
      }
      for (RI j = 0; j <= len[tot] >> 1; ++j)
        f[tot].push_back(dp[len[tot] & 1][j][0] + dp[len[tot] & 1][j][1]);
    }
  g[1][0] = 1;
  for (RI i = 2; i <= (tot << 1) + 1; ++i) {
    memset(g[i & 1], 0, sizeof(g[i & 1]));
    for (RI j = 0; j <= len[i >> 1] >> 1; ++j)
      for (RI k = j; k <= n; ++k)
        g[i & 1][k] = (g[i & 1][k] + g[(i + 1) & 1][k - j] * f[i >> 1][j] % mod) % mod;
  }
  LL ans = 0;
  for (RI i = 0; i <= n; ++i)
    ans = (ans + (i & 1 ? -1ll : 1ll) * g[1][i] * frac[n - i] % mod) % mod;
  printf("%lld\n", (ans % mod + mod) % mod);
  return 0;
}

Measured memory_bytes: 1024
a = int(input())
if 400 <= a <= 599:
  b = 8
elif 600 <= a <= 799:
  b = 7
elif 800 <= a <= 999:
  b = 6
elif 1000 <= a <= 1199:
  b = 5
elif 1200 <= a <= 1399:
  b = 4
elif 1400 <= a <= 1599:
  b = 3
elif 1600 <= a <= 1799:
  b = 2
elif 1800 <= a <= 1999:
  b = 1
print(b)

Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

int main()
{
    int a,b;
    cin >> a >> b;

    string res;

    if(a > b)
    {
        res = "a > b";
    }
    else if(a < b)
    {
        res = "a < b";
    }
    else
    {
        res = "a == b";
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3160
n=int(input())
a=[int(i) for i in input().split()]
b=sum(a)//2
c=[0]*n
c[-1]=b-sum(a[:-1:2])
for i in range(n-1,0,-1):
  c[i-1]=a[i-1]-c[i]
print(" ".join([str(i*2) for i in c]))

Measured memory_bytes: 19104
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static List<List<Integer>> o = new ArrayList<List<Integer>>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        al(N, new ArrayList<Integer>());

        double sum = 0.0;
        for (List<Integer> order : o) {
            for (int oi = 0; oi < order.size() - 1; oi++) {
                int i = order.get(oi);
                int j = order.get(oi+1);
                sum += Math.sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
            }
//            for (Integer i : order) {
//                System.out.print(i);
//            }
//            System.out.println();
        }
        System.out.println(sum / o.size());
    }

    public static void al(int N, ArrayList<Integer> order) {
        if (order.size() == N) {
            o.add(order);
        } else {
            for (int i = 0; i < N; i++) {
                if (!order.contains(Integer.valueOf(i))) {
                    ArrayList<Integer> copy = (ArrayList<Integer>) order.clone();
                    copy.add(i);
                    al(N, copy);
                }
            }
        }
    }
}


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



int main(){
	int N,i,R,B;
  	cin>>N;
  	char s[N]={};
  	R = 0;
  	B = 0;
  	for(i=0;i<N;i++){
  		cin>>s[i];
      	if(s[i]=='R'){
        	R++;
        }else if(s[i]=='B'){
        	B++;
        }
    }
  	if(R>B){
    	printf("Yes");
    }else{
    	printf("No");
    }
  	
  
    
    
  	return 0;
}



Measured memory_bytes: 256
/*
 *        ~Botay~
 *    code by kazalika
 */

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ldb;
typedef double db;
typedef vector<int> vint;
typedef vector<ll> vll;
#define forn(a, i, n) for (int i = (a); i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) int(x.size())
const int N = 3e6 + 6;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(20);

  ll n;
  cin >> n;
  ll ans = 0;
  vector<pll> div;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i) continue;
    ll cn = 0;
    while (n % i == 0) {
      n /= i;
      cn++;
    }
    div.emplace_back(i, cn);
  }
  if (n > 1) div.emplace_back(n, 1);
  forn(0, i, sz(div)) {
    forn(1, j, 70) {
      if (div[i].second < j) break;
      ans++;
      div[i].second -= j;
    }
  }
  cout << ans;

}

Measured memory_bytes: 3656
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,A = ilint()
ans = A[0]
for a in A[1:]:
    ans = gcd(ans,a)
print(ans)

Measured memory_bytes: 88492
#include <iostream>
using namespace std;
using ll = long long;

ll N, M;
int main(){
    cin >> N >> M;
    if(N < M) swap(N, M);
    if(M == 1){
        if(N == 1) cout << 1 << endl;
        else if(N == 2) cout << 0 << endl;
        else cout << N-2 << endl;
    }else if(M == 2){
        cout << 0 << endl;
    }else{
        cout << (N-2)*(M-2) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

constexpr int len = 1 << 18;
int mx = 0, my = 0;

int dist(const std::pair<int, int> &p) {
    if (p.second == 0) return p.first;
    if (p.first == mx) return mx + p.second;
    if (p.second == my) return 2 * mx + my - p.first;
    return 2 * mx + 2 * my - p.second;
}

int main() {
    int r, c, n;
    std::cin >> r >> c >> n;
    std::vector<std::pair<std::pair<int, int>, std::pair<int, int>>> v;

    {
    std::vector<int> xs { 0, r }, ys { 0, c };
    for (int i = 0; i < n; i++) {
        int x, y, z, w;
        std::cin >> x >> y >> z >> w;
        if ((x == 0 || x == r || y == 0 || y == c) && (z == 0 || z == r || w == 0 || w == c)) {
            v.push_back({ { x, y }, { z, w } });
            xs.push_back(x); xs.push_back(z);
            ys.push_back(y); ys.push_back(w);
        }
    }
    std::sort(xs.begin(), xs.end());
    std::sort(ys.begin(), ys.end());
    xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
    ys.erase(std::unique(ys.begin(), ys.end()), ys.end());
    mx = std::lower_bound(xs.begin(), xs.end(), r) - xs.begin();
    my = std::lower_bound(ys.begin(), ys.end(), c) - ys.begin();
    auto compress = [&](auto &p) {
        p.first = std::lower_bound(xs.begin(), xs.end(), p.first) - xs.begin();
        p.second = std::lower_bound(ys.begin(), ys.end(), p.second) - ys.begin();
    };
    for (auto &el : v) {
        compress(el.first);
        compress(el.second);
    }
    }

    std::vector<int> b(2 * mx + 2 * my + 1);
    for (const auto &el : v) {
        auto p = dist(el.first), q = dist(el.second);
        if (p > q) std::swap(p, q);
        b[p]++; b[q + 1]--;
    }
    for (int i = 1; i <= 2 * mx + 2 * my; i++) b[i] += b[i - 1];
    for (const auto &el : v) {
        auto p = dist(el.first), q = dist(el.second);
        if (b[p] != b[q]) {
            std::cout << "NO" << std::endl;
            return 0;
        }
    }
    std::cout << "YES" << std::endl;

    return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  cout << min({abs(A - B) + abs(B - C), abs(A - C) + abs(C - B),
              abs(B - A) + abs(A - C), abs(B - C) + abs(C - A),
              abs(C - A) + abs(A - B), abs(C - B) + abs(B - A)}) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef unsigned long long int ull;
using namespace std;
int main()
{
    long long int a,b,c;
    long long int d;
    cin>>a>>b>>c;
    d=c-a-b;
    if(d<0)
    {
        cout<<"No"<<endl;
    }
    else if((4*a*b)<(d*d))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n,used[51][51],day[51][32];

int solve(){
  vector <int> l;
  for(int i=1;i<=30;i++){
    l.clear();
    for(int j=0;j<n;j++)if(day[j][i]==1)l.push_back(j);
    int a[51] = {};
    for(int j=0;j<l.size();j++)
      for(int k=0;k<n;k++) a[k] = (a[k] | used[l[j]][k]);
    
    for(int j=0;j<l.size();j++){
      for(int k=0;k<n;k++) used[l[j]][k] = a[k];
      for(int k=j+1;k<l.size();k++) used[l[j]][l[k]]=used[l[k]][l[j]]=1;
    }

    for(int j=0;j<l.size();j++){
      int cnt=0;
      while(cnt<n && used[l[j]][cnt]==1)cnt++;
      if(cnt==n)return i;
    }
    
  }
  return -1;
}

int main(){

  while(1){
    cin >> n;
    if(n==0)break;
    memset(used,0,sizeof(used));
    memset(day,0,sizeof(day));
    for(int i=0;i<n;i++){
      used[i][i]=1;
      int a,b;
      cin>>a;
      while(a--)cin>>b,day[i][b]=1;
    }
    cout << solve()<<endl;
  }

  return 0;
}

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

using namespace std;

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

int func(int x, int y, vector<vector<int>> &map){

    if(map[y][x] == -1)
        return 0;

    if(map[y][x] == 1)
        return 0;

    map[y][x] = 1;

    int ret = 0;

    for(int i = 0; i < 4; i++){
        ret += func(x + dx[i], y + dy[i], map);
    }

    return ret + 1;

}

int main(){

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

    while( true ){

        int w, h;
        cin >> w >> h;
        
        if(w == 0 && h == 0)
            break;

        int x,y;
        vector<vector<int>> map(h + 2, vector<int>(w + 2, -1));
        for(int i = 0; i < h; i++){
            string s;
            cin >> s;
            for(int j = 0; j < w ; j++){
                if(s[j] == '.')
                    map[i + 1][j + 1] = 0;
                else if(s[j] == '#')
                    map[i + 1][j + 1] = -1;
                else {
                    map[i + 1][j + 1] = 0;
                    x = j + 1;
                    y = i + 1;
                }
            }
        }

        cout << func(x, y, map) << endl;
        /*
        for(auto &x:map){
            for(auto &y: x)
                cout << y << ' ';
            cout << endl;
        }
        */

    }

    return 0;

}


Measured memory_bytes: 3040
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	string s;
	switch (n % 10) {
		case 3: s = "bon"; break;
		case 0: case 1: case 6: case 8: s = "pon"; break;
		default: s = "hon"; break;
	}

	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3108
n = int(input())
C = []
S = []
F = []

for i in range(n-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(n-1):
    time = S[i]
    time += C[i]
    for j in range(i+1, n-1):
        if time < S[j]:
            time = S[j]
        if time%F[j] != 0:
            time = F[j] * (time//F[j] + 1)
        time += C[j]
    print(time)
print(0)

Measured memory_bytes: 3064
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    for _ in 0..N {
        let entry = map.entry(read()).or_insert(0);
        *entry += 1;
    }
    let mut ans = map.len();
    let mut parity = 0;
    for v in map.values() {
        let v = if v % 2 == 0 { 2 } else { 1 };
        if v == 2 {
            if parity != 0 {
                parity = 0;
            } else {
                parity += 1
            }
        }
    }
    ans -= parity;
    println!("{}", ans);
}


Measured memory_bytes: 5276
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
	ll n;
	cin>>n;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	sort(all(v));
	ll ans = 0;
	rep(i,0,v.sz-1){
		ans+= v[i];
	}
	cout << ans + v[v.sz-1]/2 << endl;
	return 0;
}

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

int main()
{
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int diff = (H2*60+M2)-(H1*60+M1);
    cout << diff - K << endl; 
}

Measured memory_bytes: 3640
n = int(input())
h = [int(i) for i in input().split()]
h[0] -= 1
for i in range(1, n):
    if h[i] < h[i-1]:
        print("No")
        break
    if h[i] > h[i-1]:
        h[i] -= 1
else:
    print('Yes')

Measured memory_bytes: 14396
import java.util.*;

class Main {
  static final int INF = 2000000000;
  static class Vertex implements Comparable<Vertex> {
    List<Route> routes = new ArrayList<Route>();
    int cost = INF;

    public void addRoute(Vertex to, int dist) {
      routes.add(new Route(this, to, dist));
    }

    public int compareTo(Vertex o) {
      return cost - o.cost;
    }
  }

  static class Route {
    Vertex from;
    Vertex to;
    int weight;

    public Route(Vertex from, Vertex to, int weight) {
      this.from = from;
      this.to = to;
      this.weight = weight;
    }
  }

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int v = scan.nextInt();
    int e = scan.nextInt();
    int sP = scan.nextInt();

    Vertex[] vertexArr = new Vertex[v];

    for(int i = 0 ; i < v ; i++) {
      vertexArr[i] = new Vertex();
    }

    int start;
    int end;
    int weight;
    for(int i = 0 ; i < e ; i++) {
      start = scan.nextInt();
      end = scan.nextInt();
      weight = scan.nextInt();
      vertexArr[start].addRoute(vertexArr[end], weight);
    }

    vertexArr[sP].cost = 0;

    PriorityQueue<Vertex> pq = new PriorityQueue<Vertex>(Arrays.asList(vertexArr));
    while (!pq.isEmpty()) {
      Vertex s = pq.poll();
      for (Route route : s.routes) {
        Vertex to = route.to;
        int cost = s.cost + route.weight;
        if (cost < to.cost) {
          pq.remove(to);
          to.cost = cost;
          pq.add(to);
        }
      }
    }

    for (Vertex s : vertexArr) {
      if(s.cost == INF) {
        System.out.println("INF");
      } else System.out.println(s.cost);
    }
  }
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x >= y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x <= y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int a, b;
  cin >> a >> b;
  if (a + b == 15) cout << '+' << '\n';
  else if (a * b == 15) cout << '*' << '\n';
  else cout << 'x' << '\n';
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	cin>>n;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		if(a%b==0){
			cout<<b<<endl;
		}
		else{
			cout<<a%b<<endl;
		}
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 3192
s = input()
k = int(input())

same = 1
for i in range(1, len(s)):
    if s[i-1] == s[i]:
        same += 1
    else:
        break

if same == len(s):
    print((len(s) * k )// 2)
    exit()

re_same = 1
for i in range(len(s)-2, -1, -1):
    if s[i+1] == s[i]:
        re_same += 1
    else:
        break


f = 0
count = 0
for i in range(1, len(s)):
    if f == 1:
        f = 0
        continue

    if s[i-1] == s[i]:
        f = 1
        count += 1


if (re_same + same) % 2 == 0 and s[0] == s[len(s)-1]:
    print(count*k + k - 1)
else:
    print(count*k)





Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[1000010], n;
ll mem[1000010][2];
ll dp(int x, int nm){
	if(x==n){
		if(nm==0)
			return 0;
		return 1e9;
	}
	if(mem[x][nm]!=-1){
		return mem[x][nm];
	}
	ll res=1e9;
	if(nm){
		res=min(res, 10-a[x]+dp(x+1, 0));
		res=min(res, 10-a[x]-1+dp(x+1, 1));
	}
	else{
		res=min(res, a[x]+dp(x+1, 0));
		res=min(res, a[x]+1+dp(x+1, 1));
	}
	mem[x][nm]=res;
	return res;
}
char s[1000010];
int main(){
    // while(cin>>n){
        ll ans=0;
        scanf("%s",s);
        n=strlen(s);
        for(int i=0; i<n; ++i){
        	a[i]=s[i]-'0';
        }
        memset(mem, -1, sizeof mem);
        ans=min(1+dp(0, 1), dp(0, 0));
        cout<<ans<<endl;

    // }
  return 0;
}




Measured memory_bytes: 67584
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/

//sometimes it's the people who no one imagines anything of 
//who do the things that no one can imagine.

//code author: iamxlr8

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main() 
{
    off;
    ll N,W;
    cin>>N>>W;
    ll w[N+1],v[N+1];
    for(ll i=1;i<=N;i++)
        cin>>w[i]>>v[i];
    ll dp[N+1][W+1];
    memset(dp,-1,sizeof(dp));
    for(ll i=0;i<=N;i++)
    {
        for(ll k=0;k<=W;k++)
        {
            if(i==0||k==0)
                dp[i][k]=0;
            else
            {
                ll x=INT_MIN;
                x=max(x,dp[i-1][k]);
                if(k-w[i]>=0)
                    x=max(x,dp[i-1][k-w[i]]+v[i]);
                dp[i][k]=x;
            }
        }
    }
    cout<<dp[N][W];
    return 0;
}

Measured memory_bytes: 79232
var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
})

rl.on('line', function (x) {
    lines.push(x);
});

rl.on("close", function () {
    var S = lines[0].split("");
    if (S[0] !== "A") { console.log("WA"); return (0); }
    if (S[1] !== S[1].toLowerCase()) { console.log("WA"); return (0) }

    var counter = 0;
    for (var i = 2; i < S.length - 1; i++) {

        if (S[i] === "C") { counter++; S[i] = "c"; }
        if (1 < counter) { console.log("WA"); return (0); }
        if (S[i] !== S[i].toLowerCase()) { console.log("WA"); return (0); }

    }
    if (counter === 0) {console.log("WA"); return (0) }
    if (S[S.length - 1] !== S[S.length - 1].toLowerCase()) { console.log("WA"); return (0) }

    console.log("AC");
});

Measured memory_bytes: 21320
import sys

n = int(input())
t, a = map(int, input().split())
h_list = list(map(int, input().split()))
h_temp = [abs((t - h * 0.006) - a) for h in h_list]

min_h = min(h_temp)

for i in range(n):
    if h_temp[i] == min_h:
        print(i + 1)
        sys.exit()

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < t; i++) {
			String[] sa = br.readLine().split(" ");
			int n = Integer.parseInt(sa[0]);
			int m = Integer.parseInt(sa[1]);
			int a = Integer.parseInt(sa[2]);
			int b = Integer.parseInt(sa[3]);
			pw.println(floorSum(n, m, a, b));
		}
		br.close();
		pw.flush();
	}

	/**
	 * floor((a * i + b) / m) の i＝0～n-1 の総和<br>
	 * y = (a/m)x + b/m、x軸、y軸、x = nで囲まれた領域の格子点の数（x軸上とx = n上は含まない）<br>
	 * 制約：0≦n≦10^9, 1≦m≦10^9, 0≦a,b＜m<br>
	 * O(log(n + m + a + b))
	 */
	static long floorSum(long n, long m, long a, long b) {
		long ans = 0;
		if (a >= m) {
			ans += (n - 1) * n * (a / m) / 2;
			a %= m;
		}
		if (b >= m) {
			ans += n * (n / m);
			b %= m;
		}

		long ymax = (a * n + b) / m;
		long xmax = (ymax * m - b);
		if (ymax == 0) {
			return ans;
		}
		ans += (n - (xmax + a - 1) / a) * ymax;
		ans += floorSum(ymax, a, m, (a - xmax % a) % a);
		return ans;
	}
}


Measured memory_bytes: 54052
import math
n = int(input())

i = 1
ans = 1e16

while i <= math.sqrt(n):
  b = divmod(n,i)
  if b[1] == 0:
    tmp = b[0] + n // b[0] - 2
    if tmp < ans:
      ans = tmp
  i+=1
   
print(ans)

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

int main(){
	string s;
	long long ans = 0;
	long long sumb = 0;
	cin >> s;
	int n = s.size();
	for(auto i : s){
		if(i == 'B') sumb++;
		else ans += sumb;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long n;
long long powmod(long long a,long long b,long long p){
	long long ans=1;
	for(;b;b>>=1){
		if(b&1)ans=(long long)(ans*a)%p;
		a=(long long)(a*a)%p;	
	}
	return ans;
}

int main(){
	scanf("%lld",&n);
	long long t1=powmod(10,n,mod)%mod;
	long long t2=powmod(9,n,mod)%mod;
	long long t3=powmod(8,n,mod)%mod;
	printf("%lld",((t1-t2-t2+t3)%mod+mod)%mod);
	return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;
typedef pair<ll,ll> P;

int main(){
  int N;cin>>N;
  if(N%2==0)print(N/2)
  else print((N/2 +1))
}

Measured memory_bytes: 256
/** @Date    : 2017-07-23 20:59:26
  * @FileName: C.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;

struct yuu
{
	LL a, b, c;
}s[N];

LL sum[N];

int cmp(yuu x, yuu y)
{
	if(x.a - x.b != y.a - y.b)
		return x.a - x.b < y.a - y.b;
	return x.b > y.b;
}

int main()
{
	int x, y, z;
	while(~scanf("%d%d%d", &x, &y, &z))
	{
		int n = x + y + z;
		LL C = 0;
		for(int i = 0; i < n; i++)
		{
			scanf("%lld%lld%lld", &s[i].a, &s[i].b, &s[i].c);
			C += s[i].c;
		}
		sort(s, s + n, cmp);
		priority_queue<LL, vector<LL>, greater<LL> > q;
		LL ma = 0;
		LL ans = 0;
		for(int i = 0; i < y; i++)
		{
			ma += s[i].b - s[i].c;
			q.push(s[i].b - s[i].c);
		}
		for(int i = y; i <= y + z; i++)
		{
			sum[i] = ma;
			ma += s[i].b - s[i].c;
			q.push(s[i].b - s[i].c);
			ma -= q.top();
			q.pop();
		}
		while(!q.empty())
			q.pop();
		ma = 0;
		for(int i = n - 1; i > y + z; i--)
		{
			ma += s[i].a - s[i].c;
			//cout << i << " ~" << ma << endl;
			q.push(s[i].a - s[i].c);
		}

		for(int i = y + z; i >= y; i--)
		{
			ma += s[i].a - s[i].c;
			//cout << i << " ~" << ma << endl;
			q.push(s[i].a - s[i].c);
			ans = max(ans, C + sum[i] + ma);
			ma -= q.top();
			q.pop();
		}
		printf("%lld\n", ans);
	}
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  map<int, int> m;
  rep(i,n){
    int a;
    cin >> a;
    m[a]++;
  }
  int ans = 0;
  for(auto x : m){
    if(x.second % 2) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

import collections

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)

if c.most_common()[0][1] == 1:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 40136
a,b,c,d= gets.chomp.split(" ").map(&:to_i)
e= gets.chomp.split(" ").map(&:to_i)
f= gets.chomp.split(" ").map(&:to_i)

e=e.push(c).sort
f=f.push(d).sort

puts e[-1]<f[0]? "No War":"War"

Measured memory_bytes: 1788
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<math.h>
using namespace std;

int  main()
{
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    for (long long i = k; i < n + 2; i++) {
        long long min = i* (i - 1) / 2;
        long long max = i * n - i * (i - 1) / 2; 
        ans += (max - min+1);
        
    }

    cout << ans%(1000000000+7) << endl;
    return 0;
}

Measured memory_bytes: 3620
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N,M,S = isRaw()
    UVABs = [isRaw() for _ in range(M)]
    Smax = N*51 
    G = [[] for _ in range(N*Smax)]
    
    for uvab in UVABs:
        u,v,a,b = uvab
        for s in range(a*N,Smax*N,N):
            G[s+u-1].append((b,s-(a*N)+v-1))
            G[s+v-1].append((b,s-(a*N)+u-1))
    for n in range(N):
        c,d = isRaw()
        for s in range(N, Smax*N, N):
            G[s+n].append((0,s-N+n))
            if s>=c*N:
                G[s-c*N+n].append((d,s+n))
    cost = dijkstra(G,min(S,Smax-N)*N)
    return "\n".join([str(c) for c in cost[1:N]])


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 130440
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
signed main() {
	int n, m;
	cin >> n >> m;
	cout << n * m << endl;
	ggr
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
    SPEED;
    int h1,m1,h2,m2,k,t=0,mx=0;
    cin>>h1>>m1>>h2>>m2>>k;
    if(h2>=h1)
    {
        t+=(h2-h1)*60;
        t-=m1;
        t+=m2;
        cout<<max(mx,t-k);
    }
    else
    {
        t+=(h2+24-h1)*60;
        t-=m1;
        t+=m2;
        cout<<max(mx,t-k);
    }
}

Measured memory_bytes: 3652
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
    int N, K, Q;
    cin >> N >> K >> Q;

    vector<int> A(Q);
    for (int i = 0; i < Q; i++) {
        cin >> A[i];

        A[i]--;
    }
        

    vector<int> cnt(N, K);
    for (int i = 0; i < Q; i++)
        cnt[A[i]]++;

    for (int i = 0; i < N; i++) {
        cnt[i] -= Q;

        if (cnt[i] > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();



int main(){

  int n,a,b; cin>>n>>a>>b;
  int res = 0;
  int sum = 0;

  REP(i, n)
  {
    sum = 0;
    int num=i+1;
    while(num>0)
    {
      sum+=num%10;
      num /= 10;
    }
    if(a<=sum&&sum<=b)
      res += i + 1;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int N, M;

    scanf("%d %d", &N, &M);

    vector<pair<int, int> > vec;

    for (int i=0; i<M; i++) 
    {
        int x1, x2;
        scanf("%d %d", &x1, &x2);
        vec.push_back({x1, x2});
    }

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

    int cnt = 1;
    int loc = vec[M-1].first;

    for (int i=M-2; i>=0; i--)
    {
        if (vec[i].second <= loc)
        {
            cnt++;
            loc = vec[i].first;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 405
#define lxl long long
#define R register
#define mod 1000000007
using namespace std;

inline lxl read()
{
	lxl x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}

lxl N,C,sum[maxn][maxn],f[maxn][maxn],A[maxn],B[maxn];

int main()
{
	N=read(),C=read();
	for(R int i=1;i<=N;i++) A[i]=read();
	for(R int i=1;i<=N;i++) B[i]=read();
	for(int i=1;i<maxn;i++) sum[i][0]=1;
	for(int i=1;i<maxn;i++)
		for(int k=1;k<maxn;k++)
			sum[i][k]=sum[i][k-1]*i%mod;
	for(int i=1;i<maxn;i++)
		for(int k=0;k<maxn;k++)
			sum[i][k]=(sum[i][k]+sum[i-1][k])%mod;
	f[0][0]=1;
	for(R int i=1;i<=N;i++)
		for(R int j=0;j<=C;j++)
			for(R int k=0;k<=j;k++)
				f[i][j]=(f[i][j]+f[i-1][j-k]*(sum[B[i]][k]-sum[A[i]-1][k]+mod)%mod)%mod;
	printf("%lld\n",f[N][C]);
	return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

signed main()
{   
    gearup;
    ll n; cin >> n;
    cout << n*(n-1)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
    int n, ans;

    while(cin >> n){
        ans = 0;

        if(n <= 36){
            for(int a = 0; a <= 9; a++){
                for(int b = 0; b <= 9; b++){
                    for(int c = 0; c <= 9 ; c++){
                        for(int d = 0 ; d <= 9; d++){
                            if((a + b + c + d ) == n){
                                ans++;
                            }
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2992
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N;
    cin >> N;
    FOR(h, 1, 3500) {
        FOR(n, 1, 3500) {
            int a = N * h * n;
            int b = 4 * n * h - N * h - N * n;
            if (b <= 0) continue;
            if (a % b != 0) continue;
            if (a / b <= 0) continue;
            int w = a / b;
            cout << h << " " << n << " " << w << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import collections
import sys

sys.setrecursionlimit(10 ** 6)

N = int(input())
colors = [int(x) - 1 for x in input().split()]
neighbors = collections.defaultdict(list)
for i in range(N - 1):
    a, b = map(int, input().split())
    neighbors[a - 1].append(b - 1)
    neighbors[b - 1].append(a - 1)

subtree_sizes = [0] * N


def calc_sizes(node, parent):
    sz = 1
    for i in neighbors[node]:
        if i != parent:
            sz += calc_sizes(i, node)
    subtree_sizes[node] = sz
    return sz


calc_sizes(0, -1)
components = {c: {0: N} for c in range(N)}
components[colors[0]] = {}
color_stack = {c: [0] for c in range(N)}
color_stack[colors[0]] = []


def calc_components(node, parent):
    color_stack_pushed = False
    if parent >= 0 and colors[parent] != colors[node]:
        color_parent = color_stack[colors[node]][-1]
        components[colors[node]][color_parent] -= subtree_sizes[node]
        components[colors[parent]][node] = subtree_sizes[node]
        color_stack[colors[parent]].append(node)
        color_stack_pushed = True
    for i in neighbors[node]:
        if i != parent:
            calc_components(i, node)
    if color_stack_pushed:
        color_stack[colors[parent]].pop()


calc_components(0, -1)


def count_paths(n):
    return n * (n + 1) // 2


total_paths = count_paths(subtree_sizes[0])
for c in range(N):
    print(total_paths - sum(count_paths(size) for size in components[c].values()))


Measured memory_bytes: 403732
import numpy as np
import math
A,B,H,M = input().split()
A = int(A)
B = int(B)
H = int(H)
M = int(M)

angle = abs(30* H - 5.5 * M)
if angle > 180:
  angle = 360 - angle

ans = np.sqrt((A**2 + B**2) - (2 * A * B * np.cos(np.radians(angle))))
print(ans)

Measured memory_bytes: 27196
// abc135d: Digits Parade
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

int main(){
  string s;in(s);
  int n = s.size();
  ull dp[2][13];
  rep(i,13) dp[0][i] = 0;
  dp[0][0] = 1;
  rep(i,n){
    int idp = i%2, jdp = (i+1)%2;
    rep(j,13) dp[jdp][j] = 0;
    int digit = s[i]=='?'? -1: s[i]-'0';
    rep(low,10){
      if(digit<0 || low==digit)
        rep(r,13) dp[jdp][(r*10 + low)%13] += dp[idp][r];
    }
    rep(r,13) dp[jdp][r] %= MOD;
  }
  oute(dp[n%2][5]);
}

Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	
	int x = b;
	if (b < 10) x += a * 10;
	else if (b < 100) x += a * 100;
	else x += a * 1000;
	
	int i, flag = 0;
	for (i = 1; i * i <= x; i++) if (i * i == x) flag = 1;
	
	if (flag == 1) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    A_list = [[int(item) for item in input().split()] for _ in range(N)]
    A_list.sort(key=lambda x:x[0])

    # print(A_list)
    T = [[0 for _ in range(7)] for _ in range(N)]

    # bfs
    def bfs(root):
        que = collections.deque([[root, 0, -1]])
        temp_depth = 0
        while que:
            # print(que)
            temp = que.popleft()
            temp_node = temp[0]
            temp_depth = temp[1]
            temp_parent = temp[2]
            T[temp_node][0] = temp_node
            T[temp_node][1] = temp_parent 
            T[temp_node][4] = temp_depth
            children = A_list[temp_node][1:3]
            cnt = 0
            # print(children)
            for child in children:
                if child >= 0:
                    cnt +=1
                    que.append([child, temp_depth+1, temp_node])
                    # print(que)
            T[temp_node][3] = cnt

            siblings = A_list[temp_parent][1:3]
            for sibling in siblings:
                if sibling != temp_node:
                    T[temp_node][2] = sibling


    def height(node):

        max_depth = 0
        height_que = collections.deque([[node, 0]])

        while height_que:
            temp = height_que.popleft()
            temp_node = temp[0]
            temp_depth = temp[1]
            children = A_list[temp_node][1:3]
            # print(children)
            for child in children:
                if child >= 0:
                    height_que.append([child, temp_depth+1])
            max_depth = max(max_depth, temp_depth)
        
        return max_depth 

    def is_root(node):
        root_check_que = collections.deque([node])
        foot_print = [False for _ in range(N)]

        while root_check_que:
            temp_node = root_check_que.popleft()
            foot_print[temp_node] = True
            children = A_list[temp_node][1:3]

            for child in children:
                if child >= 0 and foot_print[child] == False:
                    root_check_que.append(child)

        return all(foot_print)

    
    for i in range(N):
        if is_root(i):
            root = i
            break

    bfs(root)

    for node, left, right in A_list:

        if T[node][1] == -1:
            T[node][6] = 'root' #type
        elif left == -1 and right == -1:
            T[node][6] = 'leaf'
        else:
            T[node][6] = 'internal node'

        T[node][5] = height(node)


    for node, parent, sibling, degree, depth, height, node_type in T:
        print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(node, parent, sibling, degree, depth, height, node_type))
    
if __name__ == "__main__":
    resolve()



Measured memory_bytes: 6028
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#define PB push_back
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define PIE (3.14159265358979323846)
#define MOD 1000000007;
using namespace std;

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

    string s {};
    cin >> s;

    int h {}, i {};
    for (auto const &val: s) {
        if (val == 'h') ++h;
        else if (val == 'i') ++i;
    }

    
    string check {};
    size_t n {(i+h)/2};
    while (n--) {
        check += "hi";
    }

    if (s.empty()) cout<<"No"<<endl;
    else if (check == s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll memo[101][100001];
int n,k,arr[101];
const int mod=1e9+7;
ll solve(int idx=0,int sum=k){
    if(idx<=n && !sum)
        return 1;
    if(idx==n || sum<=0)
        return 0;
    ll &cur=memo[idx][sum];
    if(~cur)
        return cur;
    cur=0;
    cur+=(solve(idx+1,sum)%mod+mod)%mod;
    cur+=(solve(idx,sum-1)%mod+mod)%mod;
    cur-=(solve(idx+1,sum-arr[idx]-1)%mod+mod)%mod;
    return cur%mod;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(memo,-1, sizeof(memo));
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    cout<<solve();
}

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

int main() {
 
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  
  int m = 0;
  
  for (int i = 0; i < N; i++) {
    
    set<int> A;
    set<int> B;
    
    for (int j = 0; j <= i; j++) {
      A.insert(S[j]);
    }
    
    for (int j = i + 1; j < N; j++) {
      B.insert(S[j]);
    }
  
    int ans = 0;
  
    for (char x : A) {
      if (B.count(x)) ans++;
    }
    
    m = max(m, ans);
  }
  
  cout << m << endl;
    
  
}

Measured memory_bytes: 256