akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};


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

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

    vector<mint> q(s + 1, 0);
    mint ans = 0;
    rep(i, n) {
        q[0] += 1;
        {
            vector<mint> q2(s + 1, 0);
            rep(j, s + 1) {
                q2[j] += q[j];
                if (j + a[i] <= s) q2[j + a[i]] += q[j];
            }
            q = q2;
        }
        ans += q[s];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int amount = s.nextInt();
        int rem = amount % 1000;
        if(rem == 0) {
            System.out.println(rem);
        } else {
            System.out.println(1000-rem);
        }
   }
}

Measured memory_bytes: 35780
import sys
input = sys.stdin.readline
S = list(input())
S.remove("\n")
S = list(map(int, S))
min = 653
for i in range(len(S)-2):
    a = S[i]*100+S[i+1]*10+S[i+2]
    if abs(a-753) < min:
        min = abs(a-753)
print(min)

Measured memory_bytes: 38256
#include <bits/stdc++.h> 
using namespace std; 
#define int long long
int n,rec[1000050],ans=0;

signed main(){
	cin>>n;
	for(int i=1;i<n;i++){
		int val=(n-1)/i;
		ans+=val;
	}
	cout<<ans<<endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

void solve(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }

    a = cumsum(a);
    // sort(all(a));
    // printvector(a);
    map<ll,ll> mp;
    for (ll i = 0; i < n; i++) {
        mp[a[i]]++;
    }
    mp[0]++;

    ll ans=0;
    for (map<ll,ll>::iterator itr = mp.begin(); itr != mp.end(); itr++){
        ll m = itr->second;
        ans += (m * (m-1)) / 2;
    }

    cout << ans << endl;
    // for (map<ll,ll>::iterator itr=mp.begin(); itr!=mp.end(); itr++){
    //     cout << itr->first << " " << itr->second << endl;
    // }
}

void solve2(){
   	int n;
	scanf("%d",&n);
	ll ret=0,sum=0;
    map <ll,int> mp;
	mp[0]++;
	for(int i=0;i<n;i++)
	{
		ll a;
		scanf("%lld",&a);
		sum+=a;
		ret+=mp[sum];
		mp[sum]++;
	}
	printf("%lld\n",ret);

    // for (map<ll,int>::iterator itr=mp.begin(); itr!=mp.end(); itr++){
    //     cout << itr->first << " " << itr->second << endl;
    // }

    return;
}

int main(int argc, char const* argv[])
{
    // solve();
    solve2();
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
ll f(ll a){
	if(a==0) return 2;
	if(a%2==0){
		ll t=f(a/2);
		return t*t;
	}
	return a*f(a-1);
}


signed main(){
	ll h; cin>>h;
	ll k=h;
	ll ans=0,cnt=1;
	while(1<=k){
		ans+=cnt;
		cnt*=2;
		k/=2;
	}
	//ans+=f(cnt);
	cout<<ans;
	
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

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

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	for (int i = 0; i < n + m - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;

		g[a].emplace_back(b);
	}

	vector<int> inDegree(n);

	for (int i = 0; i < n; i++) {
		for (int v : g[i]) {
			inDegree[v]++;
		}
	}

	int r = -1;
	for (int i = 0; i < n; i++) {
		if (inDegree[i]==0) {
			r = i;
		}
	}

	vector<int> p(n);
	p[r] = -1;
	queue<int> q;
	

	q.push(r);
	while (!q.empty()) {
		int v = q.front();
		//cout << v << endl;
		q.pop();
		
		

		for (int u : g[v]) {
			
			inDegree[u]--;
			if (inDegree[u] != 0) {
				continue;
			}
			p[u] = v;
			
			q.push(u);
		}
		
	}

	for (int pi: p) {
		cout << pi + 1 << endl;
	}
	
}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

ll pre[3][30];

int main() {
    int n,C;
    cin>>n>>C;
    int d[33][33],c[510][510];
    rep(i,C){
        rep(j,C){
            cin>>d[i][j];
        }
    }
    rep(i,n){
        rep(j,n){
            cin>>c[i][j];
            c[i][j]--;
        }
    }

    rep(col,C){
        rep(i,n){
            rep(j,n){
                pre[(i+j)%3][col]+=d[c[i][j]][col];
            }
        }
    }

    ll ans=INF;
    for(int r0=0;r0<C;r0++){
        for(int r1=0;r1<C;r1++){
            for(int r2=0;r2<C;r2++){
                if(r0==r1 || r0==r2 || r1==r2) continue;
                ans=min(ans,pre[0][r0]+pre[1][r1]+pre[2][r2]);
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int D; cin >> D;
    vector<int> c(27);
    for (int i = 1; i < 27; i++) {
        cin >> c[i];
    }

    vector<vector<int>> s(D+1, vector<int> (27));
    for (int i = 1; i < D+1; i++) {
        for (int j = 1; j < 27; j++) {
            cin >> s[i][j];
        }
    }

    vector<int> t(D+1);
    for (int i = 1; i < D+1; i++) {
        cin >> t[i];
    }

    ll score = 0;
    vector<int> last(27, 0);
    for (int i = 1; i < D+1; i++) {
        score += s[i][t[i]];
        last[t[i]] = i;
        for (int j = 1; j < 27; j++) {
            score -= c[j] * (i - last[j]);
        }
        printf("%lld\n", score);
    }


}

Measured memory_bytes: 3688
from sys import exit

S = input()
if S[0] != 'A' or S[1].isupper() or S[-1].isupper():
    print('WA')
    exit()
c = 0
for s in S[2:-1]:
    if s == 'C':
        c += 1
    elif s.isupper():
        print('WA')
        exit()

if c == 1:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N, M;
vi G[100010];
int d[100010];
int from[100010];

signed main()
{
	cin >> N >> M;

	rep(i, M) {
		int a, b; cin >> a >> b;
		--a, --b;

		G[a].PB(b);
		G[b].PB(a);
	}

	queue<int> q;
	q.push(0);
	memset(d, -1, sizeof d);
	d[0] = 0;

	while (q.size()) {
		int a = q.front();
		q.pop();

		for (int nxt : G[a]) {
			if (d[nxt] != -1) continue;

			d[nxt] = d[a] + 1;
			from[nxt] = a;
			q.push(nxt);
		}
	}

	puts("Yes");

	range(i, 1, N) {
		printf("%lld\n", from[i] + 1);
	}
}




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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }


const ll MAX = 110000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

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

  ll N, K;
  cin >> N >> K;

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

  COMinit();

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

  ll ans_max = 0;
  for(int i = N; i >= K; i--){
    ll tmp = 0;
    tmp = COM(i-1, K-1);
    ans_max = (ans_max + ((A[i-1] + MOD) * tmp) % MOD) % MOD;
  }

  sort(A.rbegin(), A.rend());

  ll ans_min = 0;
  for(int i = N; i >= K; i--){
    ll tmp = 0;
    tmp = COM(i-1, K-1);

    ans_min = (ans_min + ((A[i-1] + MOD) * tmp) % MOD) % MOD;
  }
  
  cout << (ans_max  + MOD - ans_min) % MOD << endl;



  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    string S;
    cin >> S;

    int ans[S.size()] = {};
    int count_R = 0, count_L = 0, id;
    REP (i, S.size()) {
        if (S.at(i) == 'R') {
            if (count_L == 0) {
                count_R++;
            } else {
                int tmp = count_R + count_L;
                ans[id] = ans[id+1] = tmp/2;
                if (tmp % 2 != 0) {
                    if (count_R % 2 != 0) {
                        ans[id]++;
                    } else {
                        ans[id+1]++;
                    }
                }
                count_R = count_L = 0;
                count_R++;
            }
        }
        if (S.at(i) == 'L') {
            if (count_L == 0) {
                id = i-1;
                count_L++;
            } else {
                count_L++;
            }
            if (i == S.size()-1) {
                int tmp = count_R + count_L;
                ans[id] = ans[id+1] = tmp/2;
                if (tmp % 2 != 0) {
                    if (count_R % 2 != 0) {
                        ans[id]++;
                    } else {
                        ans[id+1]++;
                    }
                }
            }
        }
    }

    REP (i, S.size()) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<int> p(n);
  for (auto &x: p) cin >> x;

  int minimum = p[0];
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (minimum >= p[i]) {
      ans++;
      minimum = p[i];
    }
  }

  cout << ans << endl;

  return 0;
}


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

vector<int>to[200005];//辺を入力するための配列を準備
vector<int>ans;//答の配列を準備
void dfs(int v,int p=-1){
  //注目しているのはv、親は第二引数なし、デフォルト引数
  for(int u:to[v]){//辺に沿ってvに入るuを一つ一つチェック
    if (u==p)continue;//逆走させない枝刈り
    ans[u]+=ans[v];//累積和、今がv、次がu
    dfs(u,v);//再帰、uが始点、vが終点?
  }
}
int main(){
  int n,q;
  cin>>n>>q;  
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    --a;--b;//ノード番号は1始まりなので0始まりに修正
    to[a].push_back(b);//aに入る辺はbから
    to[b].push_back(a);
  }
  ans.resize(n);//resizeしないとエラー、ノード数の配列が必要
  rep(i,q){
    int p,x;
    cin>>p>>x;
    --p;//ノード番号は1始まりなので0始まりに修正
    ans[p]+=x;//ノードpに対して大きさxを加える
    //こっちは累積和ではなく、ノードに来た時の加点を入力している
  }
  dfs(0);//ゼロから深さ優先探索を開始、親はp=-1（デフォルト引数）
  rep(i,n){//ノード0からの大きさを出力
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 23552
a=[list(map(int,input().split())) for i in range(3)]
for i in range(2):
    for j in range(2):
        if a[i][j]-a[i][j+1]==a[i+1][j]-a[i+1][j+1]:
            continue
        else:print("No");exit()
print("Yes")  

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){
  
  int n,k;
  cin >> n >> k;
  vector<int> v(n,0);
  rep(i,k){
    int d;cin >> d;
    rep(j,d){
      int x;cin >> x;
      x--;
      v[x]++;
    }
}
ll res = 0;
  rep(i,n)if(v[i] == 0)res++;
  cout << res << endl;
  
  


  

  return 0;
}

Measured memory_bytes: 3600
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    int n;
    scan(n);

    auto adj = new int[][](n, 0);
    foreach (i ; 0 .. n-1) {
        int ai,bi;
        scan(ai,bi);
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    int dfs(int v, int p) {
        if (adj[v].length == 1) {
            return 0;
        }

        int res, dmax;
        bool zero;

        foreach (u ; adj[v]) {
            if (u == p) continue;
            int d = dfs(u, v);
            if (!d) {
                zero = 1;
                d++;
            }
            res += d;
        }

        if (zero) res--;
        return res;
    }

    int ans = 1;

    foreach (i ; 0 .. n) {
        if (adj[i].length > 2) {
            ans = dfs(i, -1);
            break;
        }
    }

    writeln(ans);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 13180
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    if N % 2 == 0:
        print(N, N, N // 2)
    else:
        ans = (0, 0, 0)
        for h in range(1, 3501):
            for n in range(h, 3501):
                # 式をwについて解いた
                num = N * n * h
                denom = 4 * h * n - N * (h + n)
                if denom > 0 and num % denom == 0:
                    w = num // denom
                    ans = (h, n, w)
                    break

        print(*ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9924
while true do
  begin
    *length_arr, speed1, speed2 = gets.chomp.split(',').map{|x| x.to_i}
  rescue
    break
  end
  length = length_arr.inject{|sum,n| sum+n}
  l = speed1 * length / ( speed1 + speed2 ).to_f
  le = 0
  length_arr.each_with_index do |len, i|
    le += len
    if le >= l then
      puts i+1
      break
    end
  end
end

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

int main()
{
    int n, d;
	cin >> n >> d;
	int x[n][d];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=d;j++)
		{
			cin >> x[i][j];
		}
	}
	int ans = 0;
	int dst = 0;
	//cout << x[1][1] << endl;
	
	for(int i=1;i<=n-1;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			for(int k = 1;k<=d;k++)
			{
				int t = x[j][k]-x[i][k];
				//cout << x[1][1];
				dst += t*t;
				
			}
			int t = sqrt(dst); 
    		if(t * t == dst)
				ans++;
    
			dst = 0;
		}
	}
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int n, k;
	cin >> n >> k;
	int s = 0, x;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		s += 2*min(x, abs(k-x));
	}
	cout << s << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ll long long
#define vi vector <int>
#define vvi vector <vector<int> >
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>=b;i--)
#define init(i,k) memset(i,k,sizeof i)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
inline ll add(ll a, ll b){ return ((a%MOD)+(b%MOD))%MOD;}
inline ll mul(ll a, ll b){ return ((a%MOD)*(b%MOD))%MOD;}
inline ll sub(ll a, ll b){ return ((a%MOD)-(b%MOD)+MOD)%MOD;}
// const int N = 1e5+7;
 
#define deb(x) {x}
#ifndef local
    #define deb(x) ;
#endif
///---------------------------------------------------------------

int power(int x, unsigned int y, int p=MOD)  
{  
    int res = 1;
    x = x % p;
    while (y > 0)  
    {  
        if (y & 1)res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res%p;  
}

void solve()
{
    int n,k;cin>>n>>k;
    int ans=0;
    vi v((int)1e5+10,0);
    repD(i,k,1){
        int temp=0;
        int t = floor(k/i);
        temp = power(t,n);
        int c=2;
        while(i*c <= k){
            temp =sub(temp,v[i*c]);
            c++;
        }
        v[i]=temp;
        ans=add(ans,mul(temp,i));
    }
    cout<<ans<<endl; 
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    #ifdef local
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    clock_t qwertyuiop = clock();
    #endif
 
    int t=1;
    // cin>>t;
    // rep(i,2,(int)1e5+3)fac[i]=mul(fac[i-1],i);
    // sieve((int)1e5+3);
    // rep(i,1,(int)1e5+2)if(!is_composite[i])p[i]++;
    // rep(i,1,(int)1e5+2)p[i]+=p[i-1];
    // rep(i,1,(int)1e5+2)cout<<p[i]<<" ";cout<<endl;
    rep(a,0,t)
    {
        // cout<<"Case #"<<a+1<<": ";
        solve();
    }

    // solve();
    
    #ifdef local
    {qwertyuiop = clock() - qwertyuiop;
    double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;
    cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "
    <<time_taken<<" seconds\n";}
    #endif
}

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

int main(){
    string S;
    cin >> S;

    bool IncludeSeven = false;
    for(int i=0;i<3;i++){
        if(S[i] == '7'){
            IncludeSeven = true;
        }
    }
    if(IncludeSeven == true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};


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

    int n;
    cin >> n;
    vector<ll> a(n);
    int zero = 0;
    rep(i,n){
        cin >> a[i];
        if(a[i] == 0) zero = 1;
    }
    if(zero) {
        cout << 0 << endl;
        return 0;
    }
    ll sum = 1;
    int flag = 0;
    rep(i,n){
        if(sum < LONG_LONG_MAX/a[i]) {
            sum *= a[i];
            if(sum >= 1000000000000000001){
                cout << -1 << endl;
                return 0;
            }
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }


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


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

#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define pb push_back

using ll = long long;
using pii = pair<int, int>;

template<typename T> using V = vector<T>;

// dist(a, b) = D(a) + D(b) - 2 * D(L)
// Traverse the tree using a DFS. For current node store the following values:
// freq_till[i] - denotes the frequency of color i from root till current node
// sum_till[i] - denotes the sum of weights of color i from root till current node

const int MAXN = 1e5 + 10, LOG = log2(MAXN) + 2;

typedef struct {
	int x, y, u, v;
} Query;

vector< pair<int, pii> > adj[MAXN];
vector<int> qry_idx[MAXN];
Query qrs[MAXN];
int sum_till[MAXN], freq_till[MAXN], ans[MAXN];
int dep[MAXN], up[LOG][MAXN];
int N, Q;

void dfslca(int cur, int par) {
    up[0][cur] = par;
    for (int i = 1; i < LOG; ++i)
        up[i][cur] = up[i - 1][up[i - 1][cur]];

    for (auto nxt : adj[cur]) if (nxt.ff != par) {
        dep[nxt.ff] = dep[cur] + 1;
        dfslca(nxt.ff, cur);
    }
}

int getlca(int u, int v) {
    if (dep[u] > dep[v]) swap(u, v);
    for (int i = LOG - 1; i >= 0; --i)
        if (dep[v] - (1 << i) >= dep[u])
            v = up[i][v];
    if (u == v) return u;
    for (int i = LOG - 1; i >= 0; --i)
        if (up[i][u] != up[i][v])
            u = up[i][u], v = up[i][v];
    return up[0][u];
}


void dfs(int cur, int par, ll tsum) {
	for(int i : qry_idx[cur]) {
		ll add = 1;
		if(i < 0)
			add = -2; 
		i = abs(i);
		ll sum = tsum - sum_till[qrs[i].x] + (freq_till[qrs[i].x] * qrs[i].y);
		ans[i] += add * sum;
	}
	for(auto nxt : adj[cur]) {
		if(nxt.ff == par)
			continue;
		++freq_till[nxt.ss.ff];
		sum_till[nxt.ss.ff] += nxt.ss.ss;
		dfs(nxt.ff, cur, tsum + nxt.ss.ss);
		sum_till[nxt.ss.ff] -= nxt.ss.ss;
		--freq_till[nxt.ss.ff];
	}
}

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	cin >> N >> Q;
	for(int i = 1; i < N; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		adj[a].pb({b, {c, d}});
		adj[b].pb({a, {c, d}});
	}
	dfslca(1, 0);
	for(int i = 1; i <= Q; ++i) {
		cin >> qrs[i].x >> qrs[i].y >> qrs[i].u >> qrs[i].v;
		int L = getlca(qrs[i].u, qrs[i].v);
		//cerr << L << '\n';
		qry_idx[qrs[i].u].pb(i);
		qry_idx[qrs[i].v].pb(i);
		qry_idx[L].pb(-i);
	}
	dfs(1, 0, 0LL);
	for(int i = 1; i <= Q; ++i) {
		cout << ans[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 27772
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <fstream>
using namespace std;

#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 REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;
#define MOD 1000000007

int main() {
    
    ll N; cin >> N;
    vector<ll> a(N),b(N);
    REP(i,N) cin >> a[i];
    REP(i,N) cin >> b[i];
    
    vector< pair<ll,ll> > p(N*2);
    REP(i,N) p[i] = make_pair(a[i],0);
    REP(i,N) p[i+N] = make_pair(b[i],1);
    
    sort(p.begin(),p.end());
    
    ll cntF = 0;
    ll cntB = 0;
    ll ans = 1;
    REP(i,N*2) {
        ll f = p[i].second;
        if(f==1) {
            if(cntF > 0) {
                ans *= cntF;
                cntF--;
            } else {
                cntB++;
            }
        } else {
            if(cntB > 0) {
                ans *= cntB;
                cntB--;
            } else {
                cntF++;
            }
        }
        ans %= MOD;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int main(){
	int N,M,K;
	cin>>N>>M>>K;
	set<int> S;
	FOR(i,0,N+1){
		FOR(j,0,M+1){
			S.insert(M*i+N*j-i*j*2);
		}
	}
	if(S.find(K)!=S.end()){
		Yes(1);
	}else{
		Yes(0);
	}
	return 0;
}


Measured memory_bytes: 13056
using System;

public class Hello
{
    public const int MOD = 1000000007;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var map = new bool[h, w];
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                if (s[j] == '.') map[i, j] = true;
        }
        var dp = new int[h, w];
        setDP(map, dp, h, w);
        var ans = goDP(map, dp, h, w);
        Console.WriteLine(ans);
    }
    static long goDP(bool[,] map, int[,] dp, int h, int w)
    {
        for (int i = 1; i < h; i++)
            for (int j = 1; j < w; j++)
            {
                if (map[i, j]) dp[i, j] = dp[i - 1, j] + dp[i, j - 1];
                dp[i, j] %= MOD;
            }
        return dp[h - 1, w - 1];
    }
    static void setDP(bool[,] map, int[,] dp, int h, int w)
    {
        for (int i = 1; i < w; i++)
        {
            if (map[0, i]) dp[0, i] = 1;
            else break;
        }
        for (int i = 1; i < h; i++)
        {
            if (map[i, 0]) dp[i, 0] = 1;
            else break;
        }
    }
}

Measured memory_bytes: 19932
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

int main()
{
    string s,t;
    ll k=0;
    cin>>s>>t;
    rep(i,0,2)
    {
        k+=(s[i]==t[i]);
    }cout<<k;
    return 0;
}


Measured memory_bytes: 256
/*
Author: Babin Dutta
*/
 
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
 
ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
	ll n, sum = 0; cin>>n;
	ll a[n];
	map<ll,ll> mp;
	f(i,n){
		cin>>a[i];
		sum += a[i];
		mp[a[i]]++; 
	}
	ll q,u,v; cin>>q;
	while(q--){
		cin>>u>>v;
		ll x = 0;
		if(mp.count(u)) x = mp[u];
		sum += (v-u)*x;
		mp.erase(u);
		mp[v] += x;
		cout<<sum<<endl;
	}
}
 
int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}

Measured memory_bytes: 8388
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [1, 1, 1, 0, 0, -1, -1, -1]

for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            count = 0
            for k in range(8):
                x = i + dx[k]
                y = j + dy[k]

                if (0 <= x <= H - 1) and (0 <= y <= W -1):
                    if S[x][y] == "#":
                        count += 1
            S[i][j] = str(count)

for i in range(H):
    print(''.join(S[i]))


Measured memory_bytes: 3188
import math
N, K = map(int, input().split())
As = list(map(int, input().split()))


def cut_num(a, cut_length):
    return math.ceil(a/cut_length) - 1


"""cut length N binary search
if cut num > K, search more longer cut length,
"""
l = 1
r = max(As)

while r > l + 1:
    m = (l+r)//2
    current_cut_num = sum([cut_num(a, m) for a in As])
    if current_cut_num <= K:
        r = m
    else:
        l = m
    

if sum([cut_num(a, l) for a in As]) <= K:
    print(l)
else:
    print(r)

Measured memory_bytes: 31144
def C_MaximalValue():
    N = int(input())
    B = list(map(int, input().split()))
    ans = B[0] + B[N-2]
    for i in range(N -2):
        ans += min(B[i], B[i+1])
    print(ans)

if __name__ == "__main__":
    C_MaximalValue()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int K;
int ret = 0;

int dfs(vector<vector<int>> &G, int cur = 0, int par = -1){
    int depth = 0;

    for(int v: G[cur]){
        depth = max(depth, dfs(G, v, cur) + 1);
    }
    
    if(par != 0 && depth == K - 1 && cur != 0){
        ret++;
        return -1;
    }
//    cout << cur << ": " << depth << endl;
    return depth;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N >> K;
    vector<vector<int>> G(N);
    rep(i, N){
        int a;
        cin >> a, a--;
        if(i == 0){
            if(a != 0) ret++;
        }
        else{
            G[a].pb(i);
        }
    }
    
    dfs(G);
    
    output(ret, 0);
    
    return 0;
}

Measured memory_bytes: 12032
N = int(input())
n = N
result = 0
for i in range(1,len(str(N))+1):
    result = result + n //(10**(len(str(N))-i))
    n = n % (10**(len(str(N))-i))
if N % result == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//今はわからなくともいつかは

bool vi[201];
int to[20002], we[20002], ne[20002];
int he[201];
int s = 110;
int g = 120;
int sagasu(int A, int F) {
	if (vi[A] == 0) {
		vi[A] = 1;
		for (int i = he[A]; i; i = ne[i]) {
			if (we[i]) {
				int j = to[i];
				int f = min(F, we[i]);

				if (j == g) {
					we[i] -= f;
					return f;
				}
				else {
					int tmp = sagasu(j, f);
					if (tmp) {
						we[i] -= tmp;
						we[i ^ 1] += tmp;
						return tmp;
					}
				}
			}
		}
	}
	return 0;
}

int num = 2;
inline void add(int A, int B, int F) {
	to[num] = B;
	we[num] = F;
	ne[num] = he[A];
	he[A] = num++;
	to[num] = A;
	we[num] = 0;
	ne[num] = he[B];
	he[B] = num++;
}

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


	int N;
	cin >> N;

	ll goukei = 0;
	rep1(i, N) {
		int a;
		cin >> a;
		if (a >= 0) {
			goukei += a;
			add(i, g, a);
		}
		else {
			add(s, i, -a);
		}
	}
	rep1(i, N) {
		for (int j = i + i; j <= N; j += i) {
			add(i, j, 1e9);
		}
	}

	int tmp = 0;
	while (tmp = sagasu(s, 1e9)) {
		goukei -= tmp;
		memset(vi, 0, sizeof(vi));
	}
	co(goukei);

	Would you please return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left,bisect_right
n=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))

ans=0
for i in B:
    ans +=bisect_left(A,i)*(n-bisect_right(C,i))
print(ans)

Measured memory_bytes: 107108
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
typedef long long lli;
const int INF = 1e9 + 19;
const int maxn = 12;
const int maxm = 1005;
int n, m;
int c[maxm], x[maxm];

int dp[(1 << maxn) + 5];

void ReadInput()
{
    cin >> n >> m;
    for(int i = 0; i < m; ++i)
    {
        int k;
        cin >> c[i] >> k;
        x[i] = 0;
        for(; k > 0; --k)
        {
            int a;
            cin >> a;
            --a;
            x[i] |= (1 << a);
        }
    }
}

void Solve()
{
    fill(begin(dp), end(dp), INF);
    dp[0] = 0;
    for(int mask = 0; mask < (1 << n); ++mask)
    {
        if(dp[mask] == INF) continue;

        for(int i = 0; i < m; ++i)
        {
            int nmask = mask | x[i];
            dp[nmask] = min(dp[nmask], dp[mask] + c[i]);
        }
    }

    if(dp[(1 << n) - 1] == INF) cout << "-1\n";
    else cout << dp[(1 << n) - 1] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


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

int main(){
    using namespace std;
    unsigned long N, P, Q;
    cin >> N >> P >> Q;
    vector<long> C(N);
    for(auto& i : C)cin >> i;
    
    vector<long> D(N);
    for(size_t i = 0; i < N; ++i)D[i] = (Q - i) * P - C[i];
    sort(D.begin(), D.end(), greater<>());
    
    long ans{accumulate(C.begin(), C.end(), 0L)}, ad{ans};
    for(unsigned long k = 0; k < N; ++k)ans = max(ad += 2 * k * P + D[k], ans);
    
    cout << ans << endl;
}


Measured memory_bytes: 10760
#include <bits/stdc++.h>
using namespace std;
 
void solve(std::string S){
    bool s1 = S[0] == 'R';
    bool s2 = S[1] == 'R';
    bool s3 = S[2] == 'R';
    if( s1 && s2 && s3){
      cout << 3 << endl;
    } else if(!( s1 || s2 || s3)){
      cout << 0 << endl;
    } else if(s2 && (s1 || s3)){
      cout << 2 << endl;
    } else {
      cout << 1 << endl;
    }
}
 
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main(){
	int n;	cin >> n;
	int w[n+1],sum[n+1];
	for(int i=1;i<=n; i++){
		cin >> w[i];
	}
	sum[1]=w[1];
	for(int i=2;i<=n;i++)	sum[i]=sum[i-1]+w[i];
	
	int mindiff=INT_MAX,	diff;
	for(int t=2; t<=n; t++){
		diff=abs(2*sum[t-1] - sum[n]);	
		mindiff=min(diff,mindiff);
	}
	cout << mindiff <<endl;
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main()
{
	int k,a,b;
	bool f = true;
	cin >> k >> a >> b;
	for (int i = a;i <= b;i++)
	{
		if (i % k == 0)
		{
			cout << "OK\n";
			f = false;
			break;
		}
	}
	if (f) cout << "NG\n";

}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int a,b,n;
    cin >> a >> b >> n;
    
   int res = 0;
    
   int upper =  min(n,b-1);
    
    res = (a*upper)/b;
    
   cout <<res;
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3644
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

int main() {
	ll N;
	cin >> N;
	string s = toStr(N);
	int l = s.size(), ans = 0;
	REP(i, l) {
		ans += (s[i] - '0');
	}
	
	ans = max(ans, (s[0]-'0'-1) + (l-1)*9);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc163/tasks/abc163_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)
const int MOD = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    int sum = 0;
    FOR(i, K, N + 2) {
        int tmin = i * (i - 1) / 2;
        int tmax = i * (N + N - i + 1) / 2;
        sum = (sum + (tmax - tmin + 1)) % MOD;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3636
n,k = map(int, input().split())

ans = [0]*n
for ki in range(k):
  d = int(input())
  al = map(int, input().split())
  for a in al:
    ans[a - 1] = ans[a - 1] + 1

cnt=0
for i in ans:
  if i == 0: cnt+= 1

print(cnt)

Measured memory_bytes: 9188
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(c, it) for (iter(c) it = (c).begin(); it != (c).end(); it++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;

int main() {
  int n,m;
  cin >> n >> m;
  int d=n,a;
  rep(i,m) {
    cin >> a;
    d=__gcd(d,a);
  }
  if(d==1) pr("Yes");
  else pr("No");
  return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N; cin >> N;
	using P = pair<ll,ll>;
	V<P> ps;
	rep(i,N){
		int x,y; cin >> x >> y;
		if(x==0 && y==0) continue;
		ps.emplace_back(x,y);
	}
	sort(all(ps),[&](P l,P r){
		return atan2(l.fs,l.sc) < atan2(r.fs,r.sc);
	});
	ll mx = 0;
	N = ps.size();
	rep(l,N){
		ll X=0,Y=0;
		rep(i,N){
			int j = (l+i)%N;
			X += ps[j].fs, Y += ps[j].sc;
			chmax(mx,X*X+Y*Y);
		}
	}
	cout << sqrt(mx) << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
    int i,n;
    int x[100];
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &x[i]);
    }
    
    for (i = n-1; i >= 0; i--) {
    printf("%d", x[i]); 
    if(i!=0) printf(" ");
    else printf("\n");
    }
    return 0;
}



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

#include <math.h>
#include <stdlib.h>


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

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    const set<int> a{1,3,5,7,8,10,12};
    const set<int> b{4,6,9,11};

    int x, y; cin >> x >> y;
    bool ans = false;
    if(x == y) ans = true;
    if(a.count(x) == 1 && a.count(y) == 1) ans = true;
    if(b.count(x) == 1 && b.count(y) == 1) ans = true;

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

    return 0;
}


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

int main() {
string S,T;
  cin>>S>>T;
  int c=0;
  for(int i=0;i<3;i++){
    if(S.at(i)==T.at(i)){
      c++;
    }
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int three(int n);

int main(void){
	int n, i;

	scanf("%d", &n);
	for(i = 3; i <= n; i++)
		if(three(i))
			printf(" %d", i);
	printf("\n");
}

int three(int n){
	if(!(n%3))
		return 1;
	do{
		if(n%10 == 3)
			return 1;
	}while(n /= 10);

	return 0;
}



Measured memory_bytes: 2044
#include<stdio.h>
int main()
{
    int a,b,sub,mul,add;
    scanf("%d %d",&a,&b);
    add=a+b;mul=a*b;sub=a-b;
    if(add>mul&&add>sub)
    {
        printf("%d",add);
    }
    else if(mul>add&&mul>sub)
    {
        printf("%d",mul);
    }
    else
        printf("%d",sub);
}


Measured memory_bytes: 128
h,w,a,b=map(int,input().split())
mod=10**9+7
N=10**6
ans=0
def comb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(1,h-a+1):
  ans=(ans+comb(b+i-2,i-1,mod)*comb(h+w-b-i-1,w-b-1,mod))%mod
print(ans)

Measured memory_bytes: 127700