akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int n, h, w;
    cin >> n >> h >> w;
    cout << ((n - w + 1) * (n - h + 1));
}

Measured memory_bytes: 3664
<?php

    $line = trim(fgets(STDIN));
    
    $linerev = strrev($line);
    
    $num = strlen($line);
    
    $count=0;
    // echo $line;
    // echo "\n";
    // echo $linerev;
    
    for($i=0;$i<$num/2;$i++){
        if($line[$i] != $linerev[$i]){
            $count++;
        }
    }
    echo $count;
?>

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

typedef long long int ll;
typedef pair<ll, int> P;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n, k;
  cin >> n >> k;

  priority_queue<P> p;
  for (int i = 0; i < n; i++) {
    ll t, d;
    cin >> t >> d;
    p.push(make_pair(d, t));
  }

  vector<ll> ma(n + 1);                           // 種類数がiの時のおいしさ最大
  vector<int> neta(n + 1);                        // ネタiをどれだけ選んでいるか
  priority_queue<P, vector<P>, greater<P>> have;  // 手持ちのやつ

  // まず大きい順にK個取り出す
  ll oishi = 0, count = 0;
  for (int i = 0; i < k; i++) {
    auto now = p.top();
    p.pop();
    oishi += now.first;
    if (neta[now.second] == 0) count++;
    neta[now.second]++;
    have.push(now);
  }

  ll ans = oishi + count * count;  // 現時点で最高
  while (!p.empty() && !have.empty()) {
    while (neta[p.top().second] != 0 && !p.empty()) p.pop();          // 初めてのネタが来るまで
    while (neta[have.top().second] < 2 && !have.empty()) have.pop();  // 2つ以上だぶってるネタが来るまで
    if (p.empty() || have.empty()) continue;

    neta[p.top().second]++;
    neta[have.top().second]--;
    oishi = oishi - have.top().first + p.top().first;
    count++;
    p.pop();
    have.pop();

    ans = max(ans, oishi + count * count);
  }

  cout << ans << endl;
}


Measured memory_bytes: 6000
n = int(input())
a = list(map(int, input().split()))
ans = 0
jud = True
while jud:
  for i in range(n):
    if a[i]%2==0:
      a[i]=a[i]//2
    else:
      jud = False
      break
  if jud: ans+=1
  else: break
print(ans)

Measured memory_bytes: 8892
n = int(input())
pyr = []
for i in range(n):
    x, y, h = map(int, input().split())
    if h != 0:
        pyr.append((x, y, h))

if len(pyr) == 1:
    print(*pyr[0])
    exit()

for i in range(101):
    for j in range(101):
        cx, cy = (i, j)
        h_list = []
        for k in range(len(pyr)):
            x, y, h = pyr[k]
            h_list.append(h + abs(x - cx) + abs(y - cy))
        if len(set(h_list)) != 1:
            continue
        else:
            print(cx, cy, h_list[0])
            exit()

Measured memory_bytes: 42220
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

const int MAX_N = (int)2e5 + 5;
int A[MAX_N], ans[MAX_N];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N;
    cin>>N;
    for(int i=1;i<=N;i++) cin>>A[i];
    for(int i=N;0<i;i--){
        int s = 0;
        for(int j=2*i;j<=N;j+=i){
            s ^= ans[j];
        }
        ans[i] = A[i] ^ s;
    }
    vector<int> b;
    for(int i=1;i<=N;i++){
        if(ans[i]) b.push_back(i);
    }
    cout<<b.size()<<endl;
    for(auto u : b) cout<<u<< ' ';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3192
/**
 *   author: Shubham Srivastava
 *   created: 29 January 2019  00:10:39
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    long long n;
    cin>>n;
    long long height[n+1];
    for(int i=1;i<=n;i++)
    	cin>>height[i];
    long long ans[n+1] = {0};
    ans[1] = 0;
    ans[2] = abs(height[2]-height[1]);
    for(int i=3;i<=n;i++)
    {
    	ans[i] = min(ans[i-1] + abs(height[i]-height[i-1]), ans[i-2] + abs(height[i]-height[i-2]));
    }
    cout<<ans[n];
return 0;
}

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


void solve(std::string S){
    if (S.compare("ABC") == 0) {
        printf("ARC\n");
    } else {
        printf("ABC\n");
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

typedef long long ll;

#define PI 3.1415926535897932384626433
#define MOD 1000000007

int main(){
    int p, q, r;
    cin >> p >> q >> r;
    cout << min({p + q, p + r, q + r}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
long long n, c, k, t[100005], ans = 0, flag = 0;
int main()
{
    cin >> n >> c >> k;
    for(int i = 0; i < n; i ++) cin >> t[i];
    sort(t, t + n);
    long long tmp = t[0];
    for(int i = 0; i < n; i ++) {
        if(t[i] - k <= tmp) {
            flag ++;
            if(flag > c) flag = 1, ans ++, tmp = t[i];
        }
        else
            flag = 1, tmp = t[i], ans ++;
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 1024
n=int(input())
s=input()
r=[[0]*(n+1) for _ in range(n+1)]

#print(r)

maxV=0
for i in range(n):
  for j in  range(n):
    ii=n-1-i
    jj=n-1-j
    if s[ii]==s[jj]:
      r[ii][jj]=min(r[ii+1][jj+1]+1,abs(ii-jj))
      maxV=max(maxV,r[ii][jj])

print(maxV)


Measured memory_bytes: 230664
#include<bits/stdc++.h>
using namespace std;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug_x(x) cout<< #x <<"---> : "<<x<<endl;
#define debug_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
//std::mt19937 mrand(random_device{}());
//int rnd(int x) { return mrand() % x ; }
const ll mod=1e7;
ll ksm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

/***********************/

int main(){
    ssd;
    int n,k;cin>>n>>k;
    string d,a;
    for(int i=0;i<k;i++){
        cin>>d;
        a+=d;
    }
    while(string::npos != to_string(n).find_first_of(a)) 
    {
        ++n;
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    N = II()
    S = [input() for i in range(N)]
    Sn = set(S)

    print(len(Sn))


if __name__ == "__main__":
	main()

Measured memory_bytes: 95556
#include <cstdio>
char str[100005];
int put(int a, int b){
	printf("%d %d\n", a, b);
	return 0;
}
int solve(){
	for(int i = 0; str[i]; i ++){
		if(str[i+1] && str[i] == str[i+1]) return put(i+1, i+2);
		if(str[i+2] && str[i] == str[i+2]) return put(i+1, i+3);	
	}
	return put(-1, -1);
}
int main(){
	scanf("%s", str);
	solve();
}

Measured memory_bytes: 256
from sys import stdin
N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
v1 = 0
v2 = 0
v4 = 0
for i in a:
    if i % 4 == 0:
        v4 += 1
    elif i % 2 == 0:
        v2 += 1
    else:
        v1 += 1
#print(v4,v2,v1)
if v4 >= (v1 + v2 - 1):
    print("Yes")
else:
    if (v4 >= v1) and (v2 >= 2):
      print("Yes")
    else:
      print("No")

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

int main() {
    int N, Q; cin >> N >> Q;
    string str; cin >> str;

    // 累積和
    vector<int> s(N+1, 0);
    for (int i = 0; i < N; ++i) {
        if (i+1 < N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }

    // クエリ
    for (int q = 0; q < Q; ++q) {
        int l, r; cin >> l >> r;
        --l, --r; // 0-indexed にする
        cout << s[r] - s[l] << endl;
    }
}   

Measured memory_bytes: 1408
import sys
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

MOD = 10**9 + 7
def main():
	n, k = read()
	par = defaultdict(int)
	for i in range(1, n+1):par[i] = i
	def find(x):
		while par[x] != x:
			par[x] = par[par[x]]
			x = par[x]
		return(x)
	for q in range(k):
		x, y = read()
		par[find(x)] = find(y)
	size = defaultdict(int)
	for i in range(1, n+1):
		size[find(i)] += 1
	print(max(size.values()))




if __name__ == "__main__":
	main()


Measured memory_bytes: 130936
from collections import defaultdict

N,M = map(int,input().split(" "))
G = defaultdict(lambda:[])
D = defaultdict(lambda:-1)
E = defaultdict(lambda:0)
for i in range(M):
    l,r,d = map(int,input().split(" "))
    l -= 1
    r -= 1
    G[l].append((r,d))
    E[r] = 1
for i in range(N):
    if E[i]:
        continue
        #   深さ優先探索で探索される予定のやつをはじく
    s = [i]
    #   深さ優先探索
    while len(s):
        l = s.pop()
        for r,d in G[l]:
            if D[r] != -1:
                continue
                #   ここで弾くと計算量が減る？わからん
            D[r] = D[l] + d
            s.append(r)
for l in range(N):
    for r,d in G[l]:
        if D[l] + d == D[r]:
            continue
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 65708
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int k;
  string s;
  cin>>k;
  cin>>s;
  
  if((int)s.size()>k)
  {
     cout<<s.substr(0,k)<<"...\n";
  }
  
  else
    cout<<s<<endl;
    
   return 0;
}


Measured memory_bytes: 3584
using System;

namespace AtCoderTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int b = int.Parse(input[0]);
            int c = int.Parse(input[1]);
            //出力
            Console.WriteLine(b*c);
        }
/*
 static void _Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            int a = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int b = int.Parse(input[0]);
            int c = int.Parse(input[1]);
            // 文字列の入力
            string s = Console.ReadLine();
            //出力
            Console.WriteLine((a + b + c) + " " + s);
        }
*/
    }
}


Measured memory_bytes: 27532
s :: [Int] -> [Int]
s x = (x !! 4) : (x !! 0) : (x !! 2) : (x !! 3) : (x !! 5) : (x !! 1) : []

e :: [Int] -> [Int]
e x = (x !! 3) : (x !! 1) : (x !! 0) : (x !! 5) : (x !! 4) : (x !! 2) : []

n :: [Int] -> [Int]
n x = (x !! 1) : (x !! 5) : (x !! 2) : (x !! 3) : (x !! 0) : (x !! 4) : []

w :: [Int] -> [Int]
w x = (x !! 2) : (x !! 1) : (x !! 5) : (x !! 0) : (x !! 4) : (x !! 3) : []

turn :: [Int] -> String -> Int
turn list [] = head list
turn list (x : xs)
  | x == 'S' = turn (s list) xs
  | x == 'E' = turn (e list) xs
  | x == 'N' = turn (n list) xs
  | x == 'W' = turn (w list) xs

main = getContents >>= print . (\[a,b] -> turn (map read $ words a) b) . lines

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans1 = a * c, ans2 = a * d, ans3 = b * c, ans4 = b * d;
	cout << max(max(ans1, ans2), max(ans3, ans4)) << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<map>

using namespace std;

string march = "MARCH"; 

int main(){
  int n;
  long long ans=0;
  string s[100009];
  map<char, long long> m;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s[i];
    m[s[i][0]]++;
  }
  for(int i=0;i<3;i++){
    for(int j=i+2;j<5;j++){
      for(int k=i+1;k<j;k++){
        ans += m[march[i]]*m[march[j]]*m[march[k]];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
//#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repm(i, a, n) for (int i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vs vector<string>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define vd vector<double>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define reverse_v(a) reverse(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

template <typename T>
T gcd(T a, T b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

template <typename T>
T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}

bool cmp(const pii &a, const pii &b) //セカンドキー->ファーストキーの順ソート
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

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

int main(void)
{
    int n;
    cin >> n;
    vll a(3 * n);
    rep(i, 0, 3 * n) cin >> a[i];
    sort_v(a);
    reverse_v(a);
    //rep(i, 0, 3 * n) cout << a[i] << endl;
    ll ans = 0;
    rep(i, 0, n)
    {
        ans += a[i * 2 + 1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n){
        printf("3C%02d\n", (n-1)%39+1);
    }
    return 0;
}


Measured memory_bytes: 3116
#include <cstdio>

const int MaxN = 3000 + 5;

int N;
int A[MaxN];
long long Dp[MaxN][MaxN];
bool Vis[MaxN][MaxN];

template <typename Typ>
inline Typ max(Typ x, Typ y) { return x > y ? x : y; }
template <typename Typ>
inline Typ min(Typ x, Typ y) { return x < y ? x : y; }

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &A[i]);
}

long long dfs(int l, int r) {
  if (l > r) return 0LL;
  if (Vis[l][r] == true) return Dp[l][r];
  Vis[l][r] = true;
  int d = l - 1 + N - r;
  if (d & 1) Dp[l][r] = min(dfs(l + 1, r) - A[l], dfs(l, r - 1) - A[r]);
  else Dp[l][r] = max(dfs(l + 1, r) + A[l], dfs(l, r - 1) + A[r]);
  return Dp[l][r];
}

void solve() {
  printf("%lld\n", dfs(1, N));
}

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

Measured memory_bytes: 78464
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
int main(){
    int n,k,s;
    scanf("%d %d %d",&n,&k,&s);
    if(s==1e9){
        for(int i =1;i<=k;i++){
            printf("%d ",s);
        }
        for(int i  = k+1;i<=n;i++){
            printf("1 ");
        }
        printf("\n");
    }
    else{
        for(int i =1;i<=k;i++)
        printf("%d ",s);
        for(int i = k+1;i<=n;i++){
            printf("1000000000 ");
        }
        printf("\n");
    }
}
/*
2 6
5 7
7 5
4 3
6 4
7 3
6 5
5 7
3 6
4 7
*/
//a+a+1=10a+1
//3a+2=10a+2

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

ifstream fin("date.in");
int n, m, k, result = 0;
char input[10][10];

int main() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> input[i][j];

    for (int i = 0; i < (1 << n); i++)
        for (int j = 0; j < (1 << m); j++) {
            int black = 0;

            for (int x = 0; x < n; x++)
                for (int y = 0; y < m; y++)
                    if (!((i >> x) & 1) && !((j >> y) & 1) && input[x][y] == '#')
                        black++;

            if (black == k)
                result++;
        }

        cout << result;

    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
#define P pair<ll,ll>
#define fs first
#define sc second
using namespace std;

int main(){
  string s,t,u;
    ll a,b;
    cin >> s >> t >> a >> b >> u;

    if(s == u) cout << a-1 << " " << b << endl;
    else cout << a << " " << b-1 << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
 b=a[k];b[3],b[4]=b[4],b[3]
t=0
for i in range(n-1):
 d=a[i]
 for j in range(i+1,n):
  e=a[j]
  for p in('012345','152043','215304','302541','410352','514320'):
   f=[d[int(k)]for k in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:t=1
print(('Yes','No')[t])


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

using namespace std;

#define all(x) (x).begin(),(x).end()

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

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


int main(void){

    int k, a[1000005];
    cin >> k;

    a[0] = 7 % k;
    for(int i = 1; i < k; ++i){
        a[i] = (a[i-1] * 10 + 7) % k;
    }

    for(int i = 0; i < k; ++i){
        if(a[i] == 0){
            cout << i+1 << "\n";
            return 0;
        }
    }

    cout << -1 << "\n";

    return 0;
}


Measured memory_bytes: 7504
data = {}

n = int(input())
for i in range(n):
    string = input()
    if string in data.keys():
        data[string] += 1
    else:
        data[string] = 1

m = int(input())
for i in range(m):
    string = input()
    if string in data.keys():
        data[string] -= 1
    else:
        data[string] = -1

print(max(0, max(data.values())))


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <queue>
#include <ctime>
#include <cstring>
#include <cmath>
#include <stack>
#include <set>
#include <unordered_map>
#define INF 0x3f3f3f3f
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define per(i, n) for(int i=n;i>=0;i--)
#define rep2(i, n) for(ll i=1;i<=n;i++)
#define pb(x) push_back(x)
#define clint(x, n) memset(x,n,sizeof(x))
#define mp make_pair
#define fi first
#define se second
#define IO std::ios::sync_with_stdio(false)
#define ull unsigned long long
#define ud long double
#define pii pair<int,int>
using namespace std;
const int maxn = 1e6+5;
const ll inf = 100000000000;
const int mod =998244353;
const int MAX = 123123;
const int N =1005;
inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
ll max(ll a,ll b){
    if(a>b) return a;
    return b;
}
ll min(ll a,ll b){
    if(a<b) return a;
    return b;
}
vector<int> a;
vector<int> b;
vector<int> used;
int ans = 0;
int verp = 1;
int n;

void bfs(int x){
    if(verp==n){
        ans++;
        return;
    }
    for (int i = 0; a.size() > i; i++) {
        if (a[i] == x && used[b[i]] == 0) {
            used[b[i]] = 1;
            verp++;
            bfs(b[i]);
            used[b[i]] = 0;
            verp--;
        } else if (b[i] == x && used[a[i]] == 0) {
            used[a[i]] = 1;
            verp++;
            bfs(a[i]);
            used[a[i]] = 0;
            verp--;
        }
    }
}
int main(){
    int m;
    cin>>n>>m;
    for(int i = 0; i < m;i++){
        int x,y;
        cin>>x>>y;
        a.push_back(--x);
        b.push_back(--y);
        used.push_back(0);
    }
    used[0]=1;
    bfs(0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<math.h>

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

using namespace std;

int main() {
    int n;
    cin >>n;
    vector<pair<int,int> > v(n);
    int x,y;
    for(int i=0;i<n;i++) {
        cin >>x>>y;
        v[i] = make_pair(x,y);
    }

    int cnt = 0;
    int res =0;
    int x_dist;
    int y_dist;

    for(int i=1;i<n;i++) {
        x_dist = v[0].first-v[i].first;
        y_dist = v[0].second-v[i].second;

        for(int j=0;j<n;j++) {
            for(int k=0;k<n;k++) {
                if(x_dist == v[j].first-v[k].first)
                    if(y_dist == v[j].second-v[k].second) cnt++;
            }
        }
        res = max(res, cnt);
        cnt =0;
    }

    cout << n-res << endl;
}

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

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

    vector<string> w(n);
    cin >> w[0];

    for (int i = 1; i < n; i++) {
        string wi;
        cin >> wi;
        if (wi[0] != w[i - 1].back() || find(w.begin(), w.end(), wi) != w.end()) {
            cout << "No" << endl;
            return 0;
        }
        w[i] = wi;
    }
    cout << "Yes" << endl;
}

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

int main()
{
  int h, w;
  std::vector<std::pair<int, int>> list;
  for (;;)
  {
    std::cin >> h >> w;
    if(h == 0 && w == 0) break;
    list.push_back(std::make_pair(h, w));
  }
  for(auto e : list)
  {
    for (int i = 0; i < e.second; i++) std::cout << "#";
    std::cout << "\n";
    for (int i = 1; i < e.first-1; i++)
    {
      std::cout << "#";
      for (int j = 1; j < e.second-1; j++)
      {
        std::cout << ".";
      }
      std::cout << "#" << std::endl;
    }
    for (int i = 0; i < e.second;i++) std::cout << "#";
    std::cout << "\n\n";
  }
  return 0;
}




Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
#define N 3100

ll powe(ll a, ll b){//aのb乗のmod
    ll ret = 1;
    while(0 < b){
        if((b%2) == 0){
            a = (a*a)%MOD;
            b >>= 1;
        }
        else{
            ret = (ret*a)%MOD;
            b--;
        }
    }
    return ret;
}

int main(){
    ll n, s; cin >> n >> s;
    vector<ll> a(n);
    REP(i,n) cin >> a[i];
    vector<vector<ll>> dp(N,vector<ll>(N,0));
    dp[0][a[0]]=powe(2,n-1);
    FOR(i,1,n-1)REP(j,N){
        if (j==a[i]) dp[i][j]+=powe(2,n-1);
        if (j-a[i]>=0){
            //cout << i << " " << j << " " << dp[i-1][j] << " " << dp[i][j] << " " << dp[i-1][j-a[i]] << " " << dp[i-1][j-a[i]]*powe(2,MOD-2) << endl;
            dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i-1][j-a[i]]*powe(2,MOD-2))%MOD;
        }
        else dp[i][j]=(dp[i-1][j]+dp[i][j])%MOD;
    }
    cout << dp[n-1][s] << endl;
}

Measured memory_bytes: 78500
//Link : https://atcoder.jp/contests/abc126/tasks/abc126_f
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define N 100005

int dsu[N];
int f(int x) {
  if(dsu[x]==x) return x;
  return dsu[x] = f(dsu[x]);
}
void merge(int x,int y) {
  x = f(x),y = f(y);
  if(x!=y) {
    dsu[x] = y;
  }
}
void solve() {
  int n,m;
  scanf("%d %d ", &n,&m);
  for(int i=n;i;--i) {
    dsu[i] = i;
  }
  for(int i=0;i<m;++i) {
    int a,b,c;scanf("%d %d %d ", &a,&b,&c);
    merge(a,b);
  }
  int ret = 0;
  for(int i=n;i;--i) {
    if(f(i)==i) {
      ++ret;
    }
  }
  printf("%d\n", ret);
}
int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


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

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef pair<int, TIII> QIIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second
#define MQ(a,b,c,d) MP(a, MT(b,c,d))
#define T1 first
#define T2 second.first
#define T3 second.second
#define Q1 first
#define Q2 second.T1
#define Q3 second.T2
#define Q4 second.T3

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

char board[60][60];
int dist[60][60][2];

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

int main(){
	int w,h;
	char buf[2];
	while(cin>>w>>h,w){
		REP(i,h){
			REP(j,w){
				scanf("%s",buf);
				board[h-1-i][j]=buf[0];
			}
		}
		memset(dist,-1,sizeof(dist));
		priority_queue<QIIII, vector<QIIII>, greater<QIIII> > q;
		REP(i,w)if(board[0][i]=='S')REP(j,2)q.push(MQ(0,0,i,j));
		int ans = -1;
		while(!q.empty()){
			QIIII tmp = q.top();
			q.pop();
			int cd = tmp.Q1;
			int cy = tmp.Q2;
			int cx = tmp.Q3;
			int lr = tmp.Q4;
			if(dist[cy][cx][lr]!=-1)continue;
			dist[cy][cx][lr]=cd;
			if(board[cy][cx]=='T'){
				ans = cd;
				break;
			}
			REP(i,9){
				int nx=cx+(2*lr-1)*dx[i];
				int ny=cy+(2*lr-1)*dy[i];
				if(nx<0||nx>=w||ny<0||ny>=h)continue;
				if(board[ny][nx]=='X'||board[ny][nx]=='S')continue;
				if(board[ny][nx]=='T')q.push(MQ(cd, ny, nx, 1-lr));
				else q.push(MQ(cd+board[ny][nx]-'0', ny, nx, 1-lr));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1376
#include <iostream>
typedef long long llong;
using namespace std;
llong gcd(llong a, llong b)
{
    if (b == 0) return a;
    return gcd(b, a % b);
}
llong lcm(llong a, llong b)
{
    return a * b / gcd(a, b);
}
int main()
{
    llong a1, m1, a2, m2, a3, m3, x1, x2, x3;
    while (true) {
        cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3;
        if (!(a1 | m1 | a2 | m2 | a3 | m3)) break;
        llong r1, r2, r3;
        r1 = r2 = r3 = 0;
        x1 = x2 = x3 = 1;
        do { x1 = x1 * a1 % m1; r1++; } while (x1 != 1);
        do { x2 = x2 * a2 % m2; r2++; } while (x2 != 1);
        do { x3 = x3 * a3 % m3; r3++; } while (x3 != 1);
        cout << lcm(lcm(r1, r2), r3) << endl;
    }
    return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    if (n == 1){
        cout << k << endl;
    }
    else{
        ans *= k;
        for (int i = 0; i < n - 1; i++ ){
            ans *= (k - 1);
        }
        cout << ans << endl;

    }

    
}

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

using ll = long long;

ll dp[51][51];

ll comb(int n, int r) {
       if(n == r) return dp[n][r] = 1;
       if(r == 0) return dp[n][r] = 1;
       if(r == 1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
       return dp[n][r] = comb(n-1,r) + comb(n-1,r-1);
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    map<ll, int> mp;
    for(int i = 0; i < n; i++) cin >> v[i], mp[v[i]]++;
    sort(v.begin(), v.end(), greater<ll>());

    double ans = 0;
    set<ll, greater<ll> > st;
    for(int i = 0; i < a; i++) {
        ans += v[i];
        st.insert(v[i]);
    }
    ans /= a;
    printf("%lf\n", ans);

    if(st.size() == 1) {
        ll sum = 0;
        for(int i = a; i <= min(mp[*st.begin()], b); i++) {
            sum += comb(mp[*st.begin()], i);
        }
        printf("%lld\n", sum);
    } else {
        auto iter = st.begin();
        int num = a;
        for(int i = 0; i < st.size()-1; i++) {
            num -= mp[*iter];
            ++iter;
        }
        printf("%lld\n", comb(mp[*iter], num));
    }
    return 0;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 4e5 + 9, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;



int main(){
    init();

    int n;  cin >> n;
    int fr[N + 10];
    for(int i = 1;i < n;i++){
        int x;  cin >> x;   x--;
        fr[x]++;
    }

    for(int i = 0;i < n;i++)    cout << fr[i] << '\n';

}

Measured memory_bytes: 4392
#include <string>
#include <iostream>
using namespace std;
string s[5][5]; char t[5][5][8]; int tc, n, m1, m2, z, a[27], b[27];
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 5; j++) {
				cin >> s[i][j];
			}
		}
		cin >> m1; fill(a, a + 27, 0); for (int i = 0; i < m1; i++) cin >> z, a[z] = 1;
		cin >> m2; fill(b, b + 27, 0); for (int i = 0; i < m2; i++) cin >> z, b[z] = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 5; j++) {
				for (int k = 0; k < 5; k++) {
					for (int l = 0; l < 5; l++) {
						int cnt = 0;
						for (int v1 = -1; v1 <= 1; v1++) {
							for (int v2 = -1; v2 <= 1; v2++) {
								for (int v3 = -1; v3 <= 1; v3++) {
									int r1 = j + v1, r2 = k + v2, r3 = l + v3;
									if (!v1 && !v2 && !v3) continue;
									if (0 <= r1 && r1 < 5 && 0 <= r2 && r2 < 5 && 0 <= r3 && r3 < 5) {
										if (s[r1][r2][r3] == '1') cnt++;
									}
								}
							}
						}
						if (s[j][k][l] == '0') t[j][k][l] = a[cnt] + 48;
						else t[j][k][l] = b[cnt] + 48;
					}
				}
			}
			for (int j = 0; j < 5; j++) {
				for (int k = 0; k < 5; k++) {
					s[j][k] = t[j][k];
				}
			}
		}
		if (tc++) cout << endl;
		cout << "Case " << tc << ":" << endl;
		for (int i = 0; i < 5; i++) {
			if (i) cout << endl;
			for (int j = 0; j < 5; j++) {
				cout << s[i][j] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int main() {
    int n ;
    std::vector< long long > a ;
    std::cin >> n ;
    
    for( int i = 0 ; i < n ; i++ ) {
        int ii ;
        std::cin >> ii ;
        a.push_back( ii ) ;
    }
    std::cout << *std::min_element( a.begin() , a.end() ) << " " << *std::max_element( a.begin() , a.end() ) << " " << std::accumulate( a.begin() , a.end() , 0LL ) << std::endl ;
}



Measured memory_bytes: 3204
n = int(input())
a = []

maxa = 0
maxa1 = 0
maxcnt = 0
for i in range(n):
    ai = int(input())
    a.append(ai)
    if maxa < ai:
        maxa1 = maxa
        maxa = ai
        maxcnt = 0
    elif maxa == ai:
        maxcnt += 1
    elif maxa1 < ai:
        maxa1 = ai

for i in range(n):
    if a[i] == maxa:
        if maxcnt > 0:
            print(maxa)
        else:
            print(maxa1)
    else:
        print(maxa)


Measured memory_bytes: 12568
class segment_tree_dual:
    def __init__(self, N, compose, funcval, ID_M=None):
        self.compose = compose
        self.ID_M = ID_M
        self.funcval = funcval

        self.height = (N-1).bit_length() #木の段数
        self.N0 = 1<<self.height #木の横幅 >= N
        self.laz = [self.ID_M]*(2*self.N0) #作用素の木
        self.val = None #値の配列

    #初期値の配列を作る
    def build(self,initial):
        self.val = initial[:]

    #laz[k] を子に伝える、k が一番下の場合は laz[k] を val に反映する
    def propagate(self,k):
        if self.laz[k] == self.ID_M: return;
        if self.N0 <= k:
            self.val[k-self.N0] = self.funcval(self.val[k-self.N0], self.laz[k])
            self.laz[k] = self.ID_M
        else:
            self.laz[(k<<1)  ] = self.compose(self.laz[(k<<1)  ],self.laz[k]);
            self.laz[(k<<1)+1] = self.compose(self.laz[(k<<1)+1],self.laz[k]);
            self.laz[k] = self.ID_M;
    
    # 遅延をすべて解消する
    def propagate_all(self):
        upto = self.N0 + len(self.val)
        for i in range(1,upto): self.propagate(i)

    # laz[k]およびその上に位置する作用素をすべて伝播
    def thrust(self,k):
        for i in range(self.height,-1,-1): self.propagate(k>>i)

    # 区間[l,r]に関数 f を作用
    def update(self, L,R,f):
        L += self.N0; R += self.N0+1
        """まず伝播させる（オペレータが可換なら必要ない）"""
        self.thrust(L)
        self.thrust(R-1)
        #登りながら関数 f を合成
        while L < R:
            if R & 1:
                R -= 1
                self.laz[R] = self.compose(self.laz[R],f)
            if L & 1:
                self.laz[L] = self.compose(self.laz[L],f)
                L += 1
            L >>= 1; R >>= 1
    
    # values[k] を取得。
    def point_get(self, k):
        res = self.val[k]
        k += self.N0
        while k:
            if self.laz[k] != self.ID_M:
                res = self.funcval(res, self.laz[k])
            k //= 2
        return res
    
    # values[k] = x 代入する
    def point_set(self, k): 
        self.thrust(k+self.N0)
        self.val[k] = x


# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


n,d,a = [int(i) for i in readline().split()]
xh = [tuple(int(i) for i in readline().split()) for _ in range(n)]
xh.sort()

from operator import add
ID_M = 0


seg = segment_tree_dual(n, add, add, ID_M)
X = [i[0] for i in xh]
H = [i[1] for i in xh]
seg.build(H)


from bisect import bisect_right

d *= 2
ans = 0
for i in range(n):
    h = seg.point_get(i)
    if h < 0: continue
    ans += (h+a-1)//a
    dam = (h+a-1)//a*a 
    
    #print(d,X,X[i]+d)
    idx = bisect_right(X,X[i]+d)-1
    #print(idx)
    seg.update(i,idx,-dam)



print(ans)






Measured memory_bytes: 97320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll zero = 0;
ll INF = 10000000000;

int main(void){
    ll X;
    cin >> X;
    ll Y;
    ll cnt=0;
    for(int i = 0; i <= X/100 ;i++){
        Y = X - i*100;
        if(Y>=0 && Y <= 5*i){
            printf("1");
            cnt = 1;
            break;
        }
    }
    if(cnt == 0) printf("0");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
 int H,W;
 cin>>H>>W;
 char s[55][55];
 for(int i=1;i<=H;i++){
   for(int j=1;j<=W;j++){
     cin>>s[i][j];
   }
 }
 for(int i=1;i<=H;i++){
   for(int j=1;j<=W;j++){
     if(s[i][j]=='#'){
       if(s[i][j-1]!='#'&&s[i][j+1]!='#'&&s[i+1][j]!='#'&&s[i-1][j]!='#'){
         cout<<"No"<<endl;return 0;
       }
     }
   }
 }
 cout<<"Yes"<<endl;
 return 0;
}

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

int N;

int main(void){

    cin >> N;
    int A[N+1];
    for (int i = 0;i <= N;i++) A[i] = 0;
    long long total = 0;
    for (int i = 1;i <= N;i++){
        for (int j = i;j <= N;j++){
            for (int k = j;k <= N;k++){
                total = i * i + j * j + k * k + i * j + j * k + k * i;
                if (total > N) break;
                if (i == j && j == k){
                    A[total] += 1;
                } else if (i == j || j == k || k == i){
                    A[total] += 3;
                } else {
                    A[total] += 6;
                }
//                cout << k << ",";
//               cout << total << ",";
            }
        }
    }

    for (int i = 1;i <= N;i++){
//        cout << i << ",";
        cout << A[i] << endl;
    }

    return 0;
}

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

int main()
{
    ll a,b,c,d;
    ll r1,r2;

    while(cin>>a>>b>>c>>d)
    {
        r1=a*b;
        r2=c*d;

        if(r1>=r2)
            cout<<r1<<endl;
        else
            cout<<r2<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<ll, int> P;

int main() {
	int n; cin >> n;
	vll a(n), b(n);
	Loop(i, n) cin >> a[i] >> b[i];
	ll buf = 0;
	Loopr(i, n) {
		ll x = a[i] + buf, y = b[i];
		ll p = x%y;
		if (p > 0) buf += y - p;
	}
	cout << buf << endl;
	return 0;
}

Measured memory_bytes: 1920
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[][] A = new int[n][m];
		int[] B = new int[m];
		int[] C = new int[n];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j <  m; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < m; i++) {
			B[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				C[i] += A[i][j] * B[j];
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(C[i]);
		}
	}

}



Measured memory_bytes: 40676
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<string,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
bool comp(P a,P b)
{
	if(a.fi.size()!=b.fi.size())return a.fi.size()<b.fi.size();
	else return a.fi<b.fi;
}
int main()
{
	int n;
	map<string,int> m;
	cin >> n;
	string name;
	int order;
	for(int i=0;i<n;i++)
	{
		cin >> name >> order;
		if(m.find(name)==m.end())m[name]=order;
		else m[name]+=order;
	}
	map<string,int>::iterator it;
	vector<P> vec;
	for(it=m.begin();it!=m.end();it++)
	{
		P in;
		in.fi=it->fi;
		in.sec=it->sec;
		vec.pb(in);
	}
	sort(vec.begin(),vec.end(),comp);
	for(int i=0;i<vec.size();i++)
	{
		cout << vec[i].fi << ' ' << vec[i].sec << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <cstdio>
typedef long long ll;
inline ll read(){
  ll ans=0,c=getchar_unlocked();
  while(c<'0'||c>'9'){c=getchar_unlocked();}
  while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar_unlocked();}
  return ans;
}
inline ll gcd(ll a, ll b) {
  return b != 0 ? gcd(b, a % b) : a;
}
int main(){
    int n;
    ll ans=1,x;
    n=read();
    while(n--){
      x=read();
      ans=ans/gcd(ans,x)*x;
    }
    printf("%lld\n",ans);
    return 0;
}

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

int main() {
	int n;
	cin>>n;
	char a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int d=1;
	for(int j=1;j<n;j++)
	{
		if(a[j]!=a[j-1])
		d++;
		
	}
	cout<<d;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(n) for(int i=0;i<n;i++)
#define ll long long
ll mob=1000000007;
using namespace std;
int main()
{ int n;
cin>>n;
vector<int> h;
set<int> y;
FOR(n) {int j;cin>>j;h.push_back(j);y.insert(j);}
if((int)h.size()==(int)y.size())
cout<<"YES";
else
cout<<"NO";
return 0;
}


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

using namespace std;
const int N = 100005;

int n, a[N];

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

Measured memory_bytes: 1536
#include<stdio.h>

int main()
{
  int S, h, m, s;

  scanf("%d",&S);
  h = S / 3600;
  m = (S - h * 3600) / 60;
  s = S - h * 3600 - m * 60;
  printf("%d:%d:%d\n", h, m, s);

  return 0;
}

Measured memory_bytes: 592
// author -> LetsGoAc
#include "bits/stdc++.h"
using    namespace std;
typedef  long double ld;
#define  int long long
typedef  pair<int,int> pii;
#define  RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  rep(i,n) for(i=0; i <n; i++)
#define  repv(i,k,n) for(int i=k; i<=n; i++)
#define  pb push_back
#define  mp make_pair
#define  F  first
#define  S  second
#define  sz(x)  (int)x.size()
#define  all(v) v.begin(),v.end()
#define  endl '\n'
#define  deb(x) c out<<#x<<" = "<<x<<endl
#define  gcd   __gcd
#define  inf   LLONG_MAX
#define  minf  LLONG_MIN 
#define  gi  greater<int> 
#define  gpi greater<pii>  
#define  sp(n) fixed<<setprecision(n)
const int mod = (int)(1e9+7);
int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
int pct(int x)
{   return __builtin_popcountll(x);}
int  lcm(int a,int b){return a*b/gcd(a,b);}
bool is_power_2(int n){ return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
void db()
{   
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
void timeit()
{  
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " <<sp(5)<< 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
int     dx []    =  {-1 , 0 , 1 , 0 ,-1,-1, 1,  1};
int     dy []    =  { 0 , 1 , 0 ,-1 ,-1, 1, 1, -1};
char    dir[]    =  {'U','R','D','L'};
/* ---------------------- ar.cpp --------------------------------- */
const int maxn = 1e6+5;
void solve(int tc)
{
    // cout<<"Case #"<<tc<<": ";
    int n,i,j,k,m,q,l,r;
    string s;
    cin>>n>>s;
    int ans = 0 ;
    int cnt = count(all(s),'W');
    l  = 0 , r=n-1;
    while(l<r)
    {
        if(s[l]=='W' && s[r]=='R')
            ans++ , swap(s[l] , s[r]) , l++ , r--;
        else
            l++;
    }
    r = n-1;
    while(cnt--)
    {
        if(s[r]=='R')
            s[r] = 'W' , ans++;
        r--;
    }
    cout<<ans;
}   
signed main()
{
    // ar.cpp
    RAGE;
  //  db();    
    int t=1;
    //cin>>t;
    for(int i=1; i<=t; i++)
    {
        solve(i);
    }
   // timeit();
    return 0;
}
/*
    1. To find 2's complement , reverse all the bits after 1st set bit. (right - >left.)

*/  

Measured memory_bytes: 3720
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C && C == A)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int a,z;
    a = z = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }
    for(int i = n-1; i > -1; i--){
        if(s[i] == 'Z'){
            z = i;
            break;
        }
    }
    cout << z-a + 1 << endl;

    return 0;
}



Measured memory_bytes: 640