akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    bool P = false;
    bool W = false;
    bool G = false;
    bool Y = false;

    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        if (s == "P")
        {
            P = true;
        }
        else if (s == "W")
        {
            W = true;
        }
        else if (s == "G")
        {
            G = true;
        }
        else if (s == "Y")
        {
            Y = true;
        }
    }

    if (P && W && G)
    {

        if (Y)
        {
            cout << "Four" << endl;
        }
        else
        {
            cout << "Three" << endl;
        }
    }
}

Measured memory_bytes: 256
n,k = map(int, input().split(' '))
result = 0

for i in range(k, n+2):
  min = ((i-1)*i)/2
  max = (n*(n+1))/2-((n-i)*(n-i+1))/2
  result = (result + max-min+1)%(10**9+7)

print(int(result))

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

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

    if(a == 0) cout << b/x + 1 << endl;
    else cout << b/x - (a - 1)/x  << endl;

    return 0;
}

Measured memory_bytes: 3584
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	var i int
	if sc.Scan() {
		if num, err := strconv.Atoi(sc.Text()); err == nil {
			i = num
		}
	}
	return i
}

func floorFunction(a int, b int, x int) int {
	floorA := (a * x) / b
	floorB := (x / b) * x
	return floorA - floorB
}

func main() {
	sc.Split(bufio.ScanWords)
	var max int
	a, b, n := nextInt(), nextInt(), nextInt()

	if n < b {
		// A*floor(x/B) < 1
		max = floorFunction(a, b, n)
	} else if b <= n {
		// 1 <= A*floor(x/B)
		// (+ or 0) - (+ or 0)
		max = floorFunction(a, b, b-1)
	}
	fmt.Println(max)
}


Measured memory_bytes: 1760
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    vector<vector<ll>> grid(3, vector<ll>(3,0));

    rep(j,0,3)
        rep(i,0,3)
            cin >> grid[j][i];

    ll n;
    cin >> n;
    vector<ll> b(n);
    rep(i,0,n) cin >> b[i];
  
    rep(k,0,n) 
        rep(j,0,3)
            rep(i,0,3)
                if (grid[j][i]==b[k]) grid[j][i] = 0;

    //for (auto l : grid)
    //{
    //    for (auto k: l)
    //        cout << ' ' << k;
    //    cout << endl;
    //}

    rep(i,0,3)
    {
        if ((grid[0][i] + grid[1][i] + grid[2][i]) == 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    } 

    rep(i,0,3)
        if ((grid[i][0] + grid[i][1] + grid[i][2]) == 0)
        {
            cout << "Yes" << endl;
            return 0;
        }

    if (0 == (grid[0][0] + grid[1][1] + grid[2][2]))
    {
        cout << "Yes" << endl;
        return 0;
    }
    else if (0 == (grid[0][2] +grid[1][1] + grid[2][0]))
    {
        cout << "Yes" << endl;
        return 0;
    }
    else 
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);getchar();
    int i;
    char a[51];
    for(i=0;i<n;i++)
    {scanf("%c",&a[i]);
    if(i+1==k) a[i]=a[i]+32;}a[i]=0;
    puts(a);
    return 0;
}


Measured memory_bytes: 128
n, d = gets.split.map(&:to_i)

point = []
n.times do
  point << gets.split.map(&:to_i)
end

ans = 0
(0..(n-1)).to_a.combination(2).each do |i, j|
  y = point[i]
  z = point[j]
  
  sum = 0
  d.times do |k|
    sum += ((y[k] - z[k]) ** 2)
  end
  
  num = Math.sqrt(sum)
  if num.to_s =~ /^[0-9]+\.0$/
    ans += 1
  end
end

puts ans

Measured memory_bytes: 1788
import math
N=int(input())
q=int(math.sqrt(N*2))
if N*2!=q*q+q:print("No");exit()
S=[list(range(1,q+1))]
S+=[[j]for j in S[0]]
last=q
for i in range(1,q):
	r=list(range(last+1,last+1+q-i))
	S[i]+=r
	for j in range(q-i):S[i+j+1]+=[r[j]]
	last=r[-1]
print("Yes")
print(len(S))
for s in S:print(len(s)," ".join(map(str,s)))

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ld long double
 
using namespace std;
 
 
const int N = 2e5 + 123;
const int MAXN = 1e5 + 12;
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;
 

ll n, m, d[N];
bool vis[N], is[N];
vector <pll> g[N];
 
 
void djk() {
    priority_queue <pair<ll, ll> > q;
    q.push({0, 1});
    pair<ll, ll> tmp;
    ll u, w;
    while (!q.empty()) {
        tmp = q.top();
        q.pop();
        u = tmp.se;
        w = -tmp.f;
        if (vis[u])
            continue;
        vis[u] = 1;
        d[u] = w;
        if (u != 1 && !vis[u - 1])
            q.push({-w, u - 1});
        for (int i = 0; i < g[u].size(); i++)
            if (!vis[g[u][i].f])
                q.push({-w - g[u][i].se, g[u][i].f});
    }
} 
 
 
int main() {
    cin >> n >> m;
    ll x, y, z;
    for (int i = 1; i <= m; i++) {
        cin >> x >> y >> z;
        g[x].pb({y, z});
    }
    memset(d, -1, sizeof(d));
    djk();
    cout << d[n];
    return 0;
}

Measured memory_bytes: 11512
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

class Program {
    static void Main(string[] args) {
        var a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        Array.Sort(a);
        Console.WriteLine(a[0] % 2 != 0 && a[1] % 2 != 0 && a[2] % 2 != 0 ? a[0] * a[1] : 0);
    }
}

Measured memory_bytes: 13524
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman001 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define inFile(t) freopen((t),"r",stdin)
#define outFile(t) freopen((t),"w",stdout)
#define pb push_back
#define pf push_front
#define Pb pop_back
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define Pf pop_front
#define sz size
#define MP make_pair
#define Pc __builtin_popcount
#define pi 2*acos(0)
#define BiEdge(v,a,b) (v)[(a)].pb(b),(v)[(b)].pb(a)
#define mod 998244353
#define point complex<ld>
#define X real()
#define Y imag()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define cross(a,b)(conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define rectangle pair<coordinate,coordinate>
#define line tuple<ll,ll,ll>
#define EPS 1e-7
#define polygon vector<point>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
int const N = 1e5+5,M = 305;
using namespace std;
int n,arr[4];
ld memo[M][M][M];
ld solve(int f,int s,int t)
{
    if(!f && !s && !t)
        return 0;
    ld &ans = memo[f][s][t];
    if(ans != -1)
        return ans;
    ans = 0;
    if(f)
        ans+=(f*1.0/n*1.0)*(solve(f-1,s,t)+1);
    if(s)
        ans+=(s*1.0/n*1.0)*(solve(f+1,s-1,t)+1);
    if(t)
        ans+=(t*1.0/n*1.0)*(solve(f,s+1,t-1)+1);
    ld prob = ((n-(f+s+t))*1.0/n*1.0);
    ans = ((ans + prob)/(1-prob));
    return ans;
}
int main()
{
    abdelrahman001
    for(int i = 0;i<M;i++)
        for(int j = 0;j<M;j++)
            for(int k = 0;k<M;k++)
                memo[i][j][k] = -1;
    cin >> n;
    for(int i = 0,x;i<n;i++)
        cin >> x,arr[x]++;
    cout << fixed << setprecision(9) << solve(arr[1],arr[2],arr[3]);
    return 0;
}


Measured memory_bytes: 443648
A,B=map(int,input().split())
B+=1
Abit=[0]*41
for j in range(41):
    bitp=A//(2*(2**j))
    bitm=A%(2*(2**j))
    Abit[j]+=bitp*(2**j)
    Abit[j]+=max(0,bitm-2**j)
Bbit=[0]*41
for j in range(41):
    bitp=B//(2*(2**j))
    bitm=B%(2*(2**j))
    Bbit[j]+=bitp*(2**j)
    Bbit[j]+=max(0,bitm-2**j)
res=0
for j in range(41):
    Bbit[j]-=Abit[j]
    res+=(Bbit[j]%2)*(2**j)
print(res)

Measured memory_bytes: 3064
/* dijkstra.cpp
    ダイクストラ法で、ある頂点から各頂点への最短距離を求めるアルゴリズム
    負の辺が含まれる場合はうまく計算出来ないので、ベルマンフォード法を用いる

    verified: AOJ GRL_1_A
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
*/

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

template <typename T>
struct Edge {
    int to;
    T cost;
};
using Graph = vector<vector<Edge<long long>>>;  // 距離/コストの型 T を指定する
const long long INF = (1LL << 60);              // 型 T のINF (完全な最大値は取らないように)

/* dijkstra(G,s,dis,prev)
    入力：グラフ G, 開始点 s, 距離を格納する dis, 最短経路の前の点を記録するprev
    計算量：O(|E|log|V|)
    副作用：dis, prevが書き換えられる
*/
template <typename T>
void dijkstra(const Graph &G, int s, vector<T> &dis, vector<int> &prev) {
    using P = pair<T, int>;

    int N = G.size();
    dis.resize(N, INF);
    prev.resize(N, -1);
    priority_queue<P, vector<P>, greater<P>> pq;  // the least element is top. first:cost, second: node
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();  // the least element
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {
                dis[e.to] = dis[v] + e.cost;
                prev[e.to] = v;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}

/* get_path(prev, t)
    入力：dijkstra で得た prev, ゴール t
    出力： t への最短路のパス
*/
vector<int> get_path(const vector<int> &prev, int t) {
    vector<int> path;
    for (int cur = t; cur != -1; cur = prev[cur]) {
        path.push_back(cur);
    }
    reverse(path.begin(), path.end());
    return path;
}

int main() {
    int V, E, s, t;
    cin >> V >> E >> s >> t;
    s--, t--;
    Graph G(V);
    Graph G2(V);
    for (int i = 0; i < E; i++) {
        int a, b;
        long long c, d;
        cin >> a >> b >> c >> d;
        a--, b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
        G2[a].push_back({b, d});
        G2[b].push_back({a, d});
    }
    vector<long long> dis1, dis2;
    vector<int> prev;
    dijkstra(G, s, dis1, prev);
    dijkstra(G2, t, dis2, prev);
    long long ans = INF;
    vector<long long> A(V);
    for (int i = V - 1; i >= 0; i--) {
        ans = min(ans, dis1[i] + dis2[i]);
        A[i] = (long long)(1e15) - ans;
    }
    for (auto i : A) {
        cout << i << "\n";
    }

    return 0;
}


Measured memory_bytes: 19396
#include<bits/stdc++.h>
using namespace std ;
int a[100010] ;
int main(){
    int n , sum ;
    cin >> n ; sum = 0 ;
    for( int i = 1 ; i <= n ; i++ ){
        scanf( "%d" , &a[i] ) ;
        sum += abs( a[i] - a[i - 1] ) ;
    }
    sum += abs( a[n] ) ;
    for( int i = 1 ; i <= n ; i++ ){
        int res = sum - abs( a[i] - a[i - 1] ) - abs( a[i] - a[i + 1] ) + abs( a[i - 1] - a[i + 1] ) ;
        printf( "%d\n" , res ) ;
    }
    return 0 ;
}

Measured memory_bytes: 1664
// AGC 020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    int n,a,b; cin >> n >> a >> b;
    int i = 0;
    while(1){
        if(i%2 == 0){
            if(a+1 != b){
                a++;
            }else{
                if(a-1 <= 0) break;
                else a--;
            }
        }else{
            if(b-1 != a){
                b--;
            }else{
                if(b+1 > n) break;
                else b++;
            }
        }
        i++;
    }

    if(i%2 == 0) cout << "Borys" << endl;
    else cout << "Alice" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void count_num(int a,int b){
    string WDay[7] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
    int len[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
    int count = 0;
    for(int i = 0; i< a-1;i++){
        count += len[i];
    }
    count += b;
    cout << WDay[(count+2) % 7] << endl;
}

int main() {
    int a,b;
    while(cin >> a >>  b , a){
        count_num(a,b);
    }
    return 0;
}





Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

ll gcd(ll a, ll b){
  return b ? gcd(b, a%b) : a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    if(n==2){
        cout<<max(a[0], a[1])<<endl;
        return 0;
    }
    vector<int> gcdl(n), gcdr(n);
    gcdl[0]=a[0]; gcdr[n-1]=a[n-1];
    for(int i=1;i<n;i++) {
        gcdl[i] = gcd(gcdl[i-1], a[i]);
    }
    for(int i=n-2;i>=0;i--){
        gcdr[i]=gcd(gcdr[i+1], a[i]);
    }
    // gcdl[0]=0; gcdr[n-1]=0;
    int ans = 0;
    rep(i,n){
        if(i==0){
            ans = max(ans, gcdr[i+1]);
        } else if(i==n-1){
            ans = max(ans, gcdl[i-1]);
        } else if(i==2){
            int t = gcd(a[0], gcdr[i+1]);
            ans = max(ans,t);
        } else if(i==n-2) {
            int t = gcd(gcdl[i-1], a[n-1]);
            ans = max(ans, t);
        } else {
            int t = gcd(gcdl[i-1], gcdr[i+1]);
            ans = max(ans, t);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
function Main(input){
    input= input.split(" ");
    input= input.map(Number);
    children = 2;
    
    var sub = function(arry,num){
        var sum = 0;
        arry.forEach(element => {
            sum += element;
        });
        
        if (arry.indexOf(sum/num) !== -1){
            return true;
        }else{
            return false;
        }
        //return arry.includes(sum/num);
    }
    
    if(sub(input,children)){
        console.log('Yes');
    }else{
        console.log('No');
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 21064
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_100
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            var array = ReadInts();
            long cnt = 0;
            for (int i = 0; i < n; i++)
            {
                while (array[i] % 2 == 0)
                {
                    array[i] /= 2;
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 


int32_t main()
{
	IOS
	string s;cin>>s;
	while((int)s.length() < 15)s+='o';
	int c=count(s.begin(),s.end(),'o');
	if(c>=8)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
}

			


Measured memory_bytes: 256
#!/usr/bin/env python3
#CODEFESTIVAL2016 GrandFinal B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x1,y1 = LI()
x2,y2 = LI()
x3,y3 = LI()
s = abs((x1-x3)*(y2-y3)-(x2-x3)*(y1-y3))
a ,b, c = math.sqrt((x1-x2)**2+(y1-y2)**2),math.sqrt((x2-x3)**2+(y2-y3)**2),math.sqrt((x3-x1)**2+(y3-y1)**2)
r = s/(a+b+c)
ans = max(a,b,c)*r/(2*r+max(a,b,c))
print(ans)


Measured memory_bytes: 38384
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    vector<int> v[200001];

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j;
            cin>>n;
            int ar[n+1],ar2[n+1];
            map<int,int> mp,mp2,mp3;
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
                ++mp[ar[i]];
            }
            for(i=1;i<=n;++i)
            {
                cin>>ar2[i];
                ++mp2[ar2[i]];
                ++mp3[ar2[i]];
            }
            for(auto it:mp)
            {
                if(it.s+mp2[it.f] > n)
                {
                    cout<<"No"<<endl;
                    return 0;
                }
            }
            shuffle(ar2+1,ar2+n+1,rng);
            if(mp.size()<=10)
            {
                sort(ar2+1,ar2+n,greater<int>());
            }
            int ans[n+1];
            
            for(i=1;i<=n;++i)
                ans[i]=ar2[i];
            for(i=1;i<=n;++i)
            {
                if(ans[i]!=ar[i])
                    continue;
                for(j=1;j<=n;++j)
                {
                    if(i==j)
                        continue;
                    if(ar[j]!=ans[i] && ans[j]!=ar[i])
                    {
                        swap(ans[i],ans[j]);
                        break;
                    }
                }
            }
            cout<<"Yes"<<endl;
            for(i=1;i<=n;++i)
                cout<<ans[i]<<" ";
            cout<<endl;
        }
        return 0;
    }


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

int main() {
  int n;
  cin >> n;
  int ans = n * (n + 1) / 2;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> ac(N, 0), pn(N, 0);
    for (int i=0; i<M; ++i) {
        int p;
        string S;
        cin >> p >> S;
        if (S == "AC") ac[p-1]++;
        else if (ac[p-1] == 0) pn[p-1]++;
    }

    int ans1 = 0, ans2 = 0;
    for (int i=0; i<N; i++) {
        if (ac[i] > 0) {
            ans1++;
            ans2 += pn[i];
        }
    }

    cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 1024
sd=[c for c in input()]
t=[c for c in input()]
tl=len(t)
for i in range(len(sd)-tl,-1,-1):
    s=sd.copy()
    m=sd[i:i+tl]
    for j in range(tl):
        if m[j]=='?':
            s[i+j]=t[j]
        elif m[j]==t[j]:
            pass
        else:
            break
    if s[i:i+tl]==t:
        print(''.join(['a' if c=='?' else c for c in s]))
        exit()
print('UNRESTORABLE')


Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int n,d;cin >> n >> d;
    vector<vector<int>> x(n,vector<int> (d,0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }
    map<int,int> ma;
    for (int i = 0; i < 10000; i++) {
        ma[i*i]=1;
    }
    int ans=0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            int sum = 0;
            for (int k = 0; k < d; k++) {
                sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            if(ma[sum]) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
 
using namespace std;
const double EPS = 1e-9;
#define SQR(x) ((x) * (x))
 
int main()
{
  int N, X[10], Y[10], L[10];
  double D[10][10];
 
  while(scanf("%d", &N), N) {
    for(int i = 0; i < N; ++i) {
      scanf("%d %d %d", &X[i], &Y[i], &L[i]);
    }
    for(int i = 0; i < N; i++) {
      for(int j = i + 1; j < N; j++) {
        D[i][j] = sqrt(SQR(X[i] - X[j]) + SQR(Y[i] - Y[j]));
      }
    }
 
    auto check = [&](double val)
    {
      vector< double > R;
      for(int i = 0; i < N; ++i) {
        R.emplace_back(sqrt(SQR(L[i]) - SQR(val)));
      }
      vector< pair< double, double > > P;
      for(int i = 0; i < N; ++i) {
        P.emplace_back(X[i], Y[i]);
        for(int j = i + 1; j < N; ++j) {
          if(abs(R[i] - R[j]) < D[i][j] && D[i][j] < R[i] + R[j]) {
            double a = atan2(Y[j] - Y[i], X[j] - X[i]);
            double theta = acos((SQR(D[i][j]) + SQR(R[i]) - SQR(R[j])) / (2 * D[i][j] * R[i]));
            P.emplace_back(X[i] + R[i] * cos(a + theta), Y[i] + R[i] * sin(a + theta));
            P.emplace_back(X[i] + R[i] * cos(a - theta), Y[i] + R[i] * sin(a - theta));
          }
        }
      }
      for(auto &&e : P) {
        double x, y;
        tie(x, y) = e;
        bool f = true;
        for(int i = 0; i < N; i++) {
          if(sqrt(SQR(X[i] - x) + SQR(Y[i] - y)) > R[i] + EPS) f = false;
        }
        if(f) return (true);
      }
      return (false);
    };
 
    double low = 1.0, high = *min_element(L, L + N);
 
    for(int i = 0; i < 25; ++i) {
      double mid = (low + high) / 2.0;
      if(check(mid)) low = mid;
      else high = mid;
    }
    printf("%.10lf\n", low);
  }
 
}

Measured memory_bytes: 3788
import math
import sys 
input = sys.stdin.readline

N = int(input())
x = list(map(int,input().split()))
mod = 10**9+7

d = [0]*(N-1)

for i in range(N-1):
    d[i] = x[i+1]-x[i]
    d[i] %= mod


kaijou = 1
for i in range(1,N):
    kaijou *= i
    kaijou %= mod


ans=0
x=0

def pow_r(x, n):
    """
    O(log n)
    """
    x %= mod
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)%mod
    else:  # standard case ② n is odd
        return (x * (pow_r(x ** 2, (n - 1) // 2)))%mod

for i in range(N-1):
    #(i+1)%(mod-2)を計算してyへ
    y = pow_r(i+1,mod-2)
    #x+= kaijou//(i+1))%(10**9+7)
    x += kaijou*y
    ans += d[i]*x
    ans %= mod

print(ans)


Measured memory_bytes: 60696
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
int n;
int main()
{
	while(1)
	{
		cin >> n;
		if(n == 0) return 0;
		map<string,int>hoge;
		int dp[105];
		for(int i=0;i<n;i++)
		{
			string s; int v;
			cin >> s >> v;
			hoge[s] = i;
			dp[i] = v;
		}
		int m;
		cin >> m;
		vector<vector<int> >vec[105];
		for(int i=0;i<m;i++)
		{
			string st; cin >> st;
			int n;
			cin >> n;
			int t = hoge[st];
			vector<int>c;
			for(int j=0;j<n;j++)
			{
				string a;
				cin >> a;
				c.pb(hoge[a]);
			}
			vec[t].pb(c);
		}
		
		while(1)
		{
			bool upd = false;
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<vec[i].size();j++)
				{
					int cnt = 0;
					for(int k=0;k<vec[i][j].size();k++) cnt += dp[vec[i][j][k]];
					if(cnt < dp[i])
					{
						dp[i] = cnt;
						upd = true;
					}
				}
			}
			if(!upd) break;
		}
		string t; cin >> t;
		cout << dp[hoge[t]] << endl;
	}
}

Measured memory_bytes: 1244
n = gets.split.map(&:to_i)
card = gets.split.map(&:to_i)
card.sort!
change = Array.new(n[1]).map{Array.new(2,0)}
n[1].times{|i| change[i] = gets.split.map(&:to_i)}
change.sort!{|a,b| b[1] <=> a[1]}
i = 0
j = 0
while  j < n[1] && i < n[0] && change[j][1] > card[i]
  for k in 1..change[j][0]
    if card[i] < change[j][1]
      card[i] = change[j][1]
      i += 1
    else
      break
    end
    if i >= n[0]
      break
    end
  end
  if k == change[j][0]
    j += 1
  end
end
ans = 0
n[0].times{|i| ans += card[i]}
puts ans


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

int main()
{
  fastio;
  for (int i = 1; i <= 5; i++){
    int x; cin >> x;
    if (x == 0) return cout << i, 0;
  }
  return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
using lint = long long;

#pragma GCC optimize ("Ofast", "unroll-loops")
#pragma GCC target ("arch=ivybridge")

const int nmax = 204800, block = 8192, unrl = 16;
int a[nmax], b[nmax];

int main() {

	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < N; i++) scanf("%d", &b[i]);

	int ans = 0;
	for (int i = 0; i + unrl <= N; i += unrl) {
		for (int j = 0; j + block <= N; j += block) {
			for (int k = j; k < block + j; k++) {

				ans ^= (a[i + 0] + b[k]) ^ (a[i + 1] + b[k]);
				ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
				ans ^= (a[i + 4] + b[k]) ^ (a[i + 5] + b[k]);
				ans ^= (a[i + 6] + b[k]) ^ (a[i + 7] + b[k]);
              	ans ^= (a[i + 8] + b[k]) ^ (a[i + 9] + b[k]);
				ans ^= (a[i + 10] + b[k]) ^ (a[i + 11] + b[k]);
				ans ^= (a[i + 12] + b[k]) ^ (a[i + 13] + b[k]);
				ans ^= (a[i + 14] + b[k]) ^ (a[i + 15] + b[k]);

			}
		}
	}

	for (int i = 0; i < N / unrl * unrl; i++) {
		for (int j = N / block * block; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}	
	for (int i = N / unrl * unrl; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 1792
/*
    User ID: qcw
       Time: 2017-10-10 23:05:20
*/
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

ll N,K,A,M,G;
int main(){
    cin.tie(0),ios_base::sync_with_stdio(0);
    cin>>N>>K;
    for(ll i{};i<N;++i){
        cin>>A;
        if(!M)M=G=A;
        else M=max(M,A),G=__gcd(G,A);
    }
    cout<<(K>M||K%G?"IMPOSSIBLE":"POSSIBLE")<<endl;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  string s;
  cin>>s;

  auto is_ok = [](string s){
    int n=s.size();
    rep(i,n/2){
      if(s[i]!=s[n-1-i])return false;
    }
    return true;
  };

  int n = s.size();
  int a = (n-1)/2;
  int b = (n+3)/2-1;
  if(is_ok(s)&&is_ok(s.substr(0,a))&&is_ok(s.substr(b))){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
char S[40];
int F[20][20];
int solve(int k){
	string T;
	string s1, s2;
	for(int i = 0; i < N; i += 1)
		if((k >> i) & 1) s1.push_back(S[i]);
		else  s2.push_back(S[i]);
	for(int i = 2 * N - 1; i >= N; i -= 1)
		T.push_back(S[i]);
	for(int i = 0; i <= N; i += 1) for(int j = 0; j <= s1.size(); j += 1) F[i][j] = 0;
//	cout << T <<endl << s1 << endl << s2 <<endl;
	F[0][0] = 1;
	for(int i = 0; i < N; i += 1) for(int j = 0; j <= s1.size() && j <= i; j += 1){
//		printf("F[%d][%d] = %d\n", i, j, F[i][j]);
		if(i - j < s2.size())
			if(T[i] == s2[i - j]) F[i + 1][j] += F[i][j];
		if(j < s1.size())
			if(T[i] == s1[j]) F[i + 1][j + 1] += F[i][j];
	}
//	printf("F[%d][%d] = %d\n", N, s1.size(), F[N][s1.size()]);
	return F[N][s1.size()];
}
int main(){
	scanf("%d %s", &N, S);
	long long ans = 0;
	for(int i = 0; i <= (1 << N) - 1; i += 1)
		ans += solve(i);
	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
const int MOD = 1e9 + 7;

ll qpow(ll x, ll k) {
    ll r = 1;
    while(k) {
        if(k & 1) r = r * x % MOD;
        k >>= 1;
        x = x * x % MOD;
    }
    return r;
}
ll d[N], a[N];
ll C(int i, int j) {
    return d[i] * qpow(d[i-j], MOD-2) % MOD * qpow(d[j], MOD - 2) % MOD;
}
int main() {
    d[0] = 1;
    for(int i = 1; i < N; i++) {
        d[i] = d[i-1] * i % MOD;
    }
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    ll ans = 0;
    k--;
    for(int i = 0; i < n; i++) {
        int x = n - i - 1;
        if(x >= k) {
            ans -= C(x, k) * a[i] % MOD;
        }
        int y = i;
        if(y >= k) {
            ans += C(y, k) * a[i] % MOD;
        }
        ans = (ans + MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

char s[1000000];

int main()
{
    long long int num = 0;

    scanf("%s",s);

    for(int i = 0;s[i];i++)
        num += s[i] - '0';

    printf("%s\n",num % 9 == 0?"Yes":"No");

    return 0;
}

Measured memory_bytes: 2284
/*
    [Gnana Deepak]
    [August 01, 2020 5:56 PM]
    [C - Vacation]
    [https://atcoder.jp/contests/dp/tasks/dp_c]
    [2000 ms]
    [1024 MB]
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ld = long double;
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define F first
#define S second
#define orderKey order_of_key
#define findOrder find_by_order
#define s(x) set<x>
#define um(x, y) unordered_map<x, y>
#define m(x, y) map<x, y>
#define p(x, y) pair<x, y>
#define v(x) vector<x>
#define min_heap(t) priority_queue<t, vector<t>, greater<t>>
#define max_heap(t) priority_queue<t>
#define ordered_set(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define ss(v) stable_sort(all(v))
#define fori(i, a, b) for (int i = a; i <= b; i++)
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define stprs(x) cout << fixed << setprecision(x);
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define bs binary_search
#define deb(x) cout << #x << "=" << x << '\n';
#define scn(v1)        \
    for (auto &x : v1) \
        cin >> x;
#define R(x) reverse(all(x));
#define lb lower_bound
#define ub upper_bound
const char nl = '\n';
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const ld PI = acos(-1);
const int N = 1e5;
const int imx = LLONG_MAX;
int DP[3][N + 1];
void accio_ac(void)
{
    int n;
    cin >> n;
    DP[2][0] = DP[1][0] = DP[0][0] = 0;
    fori(i, 1, n)
    {
        v(int) v1(3);
        scn(v1);
        fori(j, 0, 2) fori(k, 0, 2)
        {
            if (j != k)
            {
                DP[j][i] = max(DP[j][i], DP[k][i - 1] + v1[j]);
            }
        }
    }
    cout << max({DP[0][n], DP[1][n], DP[2][n]}) << endl;
}
int32_t main(void)
{
    fastio;
    int __ = 1;
    // cin >> __;
    while (__--)
    {
        accio_ac();
    }
    return 0;
}


Measured memory_bytes: 5964
N, K = map(int, input().split())


lst = [False] * N

for i in range(K):
    d = int(input())
    x = list(map(int, input().split()))

    for y in x:
        if lst[y - 1]:
            continue
        else:
            lst[y - 1] = True



cnt = 0
for a in lst:
    if not a:
        cnt += 1

print(cnt)



Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  string t;
  cin>>s>>t;
  int count=0;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      count++;
    }
  }
  cout<<count<<endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  int e[m];
  for (int i = 0; i < m; i++) {
    cin >> e[i];
  }
  bool used[n + 1];
  fill(used, used + n + 1, false);
  for (int i = m - 1; i >= 0; i--) {
    if (used[e[i]]) continue;
    cout << e[i] << endl;
    used[e[i]] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (!used[i]) cout << i << endl;
  }
  return 0;
}



Measured memory_bytes: 3692
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}



Measured memory_bytes: 2148
use proconio::input;
use proconio::marker::Chars;

#[derive(Debug)]
enum State {
    Upright(usize),
    Handstand(usize),
}

fn main() {
    input! {
        _n: usize,
        k: usize,
        s: Chars,
    }

    let mut seq = vec![];

    for c in s {
        match c {
            '0' => {
                if let Some(State::Upright(n)) = seq.last_mut() {
                    *n += 1;
                } else {
                    seq.push(State::Upright(1));
                }
            },
            '1' => {
                if let Some(State::Handstand(n)) = seq.last_mut() {
                    *n += 1;
                } else {
                    seq.push(State::Handstand(1));
                }
            }
            _ => {},
        }
    }

    let mut max_length: usize = 0;
    let mut first_index = None;
    let mut count = 0;
    let mut current_length = 0;
    for i in 0..seq.len() {
        match seq[i] {
            State::Handstand(n) => {
                current_length += n;
            },
            State::Upright(n) => {
                if first_index.is_none() {
                    first_index = Some(i);
                }
                count += 1;
                if count > k {
                    if let Some(index) = first_index.as_mut() {
                        if let State::Upright(num) = seq[*index] {
                            current_length -= num;
                        }
                        if *index > 0 {
                            if let State::Handstand(num) = seq[*index - 1] {
                                current_length -= num;
                            }
                        }
                        *index += 2;
                    }
                }
                current_length += n;
            }
        }
        max_length = std::cmp::max(max_length, current_length);
    }
    println!("{}", max_length);
}


Measured memory_bytes: 4248
N = gets.to_i
dict = {}

N.times do
  si = gets.chomp
  
  if dict.has_key?(si)
    dict[si] += 1
  else
    dict[si] = 0
  end
end

max_count = dict.values.max
puts dict.select { |k, v| v == max_count }.keys.sort

Measured memory_bytes: 48488
#include<bits/stdc++.h>
using namespace std;
const double INF = 1e20;
using pdi = pair<double, int>;

struct graph
{
	int to;
	double cost;
};

double dis(long long s[], long long g[]) {
	double dx = s[0] - g[0], dy = s[1] - g[1];
	return max(0.0, sqrt(dx * dx + dy * dy) - s[2] - g[2]);
}

int main() {
	long long barrier[1010][3];
	for (int i = 0; i < 2; i++)
	{
		cin >> barrier[i][0] >> barrier[i][1];
		barrier[i][2] = 0;
	}
	int N; cin >> N;
	for (int i = 2; i < N+2; i++)
	{
		cin >> barrier[i][0] >> barrier[i][1] >> barrier[i][2];
	}

	vector<graph> g[N+2];
	for (int i = 0; i < N+2; i++)
	{
		for (int j = i+1; j < N+2; j++)
		{
			g[i].push_back(graph{j, dis(barrier[i], barrier[j])});
			g[j].push_back(graph{i, dis(barrier[i], barrier[j])});
		}
	}

	vector<double> dist(N+2, INF);
	dist[0] = 0.0;
	priority_queue<pdi, vector<pdi>, greater<pdi>> que;
	que.emplace(dist[0], 0);
	while (!que.empty())
	{
		double cost;
		int idx;
		tie(cost, idx) = que.top(); que.pop();
		if(dist[idx] < cost) continue;
		for (auto &e : g[idx])
		{
			auto next_cost = cost + e.cost;
			if(dist[e.to] <= next_cost) continue;
			dist[e.to] = next_cost;
			que.emplace(dist[e.to], e.to);
		}
	}
	cout << fixed << setprecision(10) << dist[1] << endl;
	return 0;
}


Measured memory_bytes: 22804
N = int(input())
a_list = list(map(int, input().split()))
r2 = 0
r4 = 0
for i in range(N):
    if a_list[i]%2==0:
        r2 += 1
    if a_list[i]%4==0:
        r4 += 1
r2 -= r4
r0 = N - r2 - r4
if N % 2==0:
    print("Yes") if r4 >= r0 else print("No")
else:
    print("Yes") if r4 >= r0-1 else print("No")


Measured memory_bytes: 14224
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 1e5 + 7;
const int inf = 2e9 + 7;
const ll infl = 1e18 + 7;
const long double eps = 1e-9;
const ll mod = 998244353;

vector<int> ts;
vector<int> g[maxn], rg[maxn];

int dp[maxn], ans = 0;

vector<bool> used;

void top_s(int v) {
	used[v] = true;
	for (int to : g[v]) {
		if (!used[to]) top_s(to);
	}
	ts.push_back(v);
}


int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // _DEBUG

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		rg[b].push_back(a);
	}
	used.assign(n + 1, false);
	for (int i = 1; i <= n; i++) {
		if (!used[i]) top_s(i);
	}
	reverse(ts.begin(), ts.end());
	for (int i = 0; i < ts.size(); i++) {
		for (int to : rg[ts[i]]) {
			dp[ts[i]] = max(dp[ts[i]], dp[to] + 1);
		}
		ans = max(dp[ts[i]], ans);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 14204
// Believe in yourself...
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) (c).size()
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REPD(i,n) for(ll i=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 bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=1e5+10;
const ll mod=1e9+7;

#pragma GCC Optimize("Ofast")

ll N,K;
vector<ll>dv[maxn];
ll sum[maxn];

void add(ll ind,ll x){
	while(ind<maxn){
		sum[ind]+=x;
		ind+= (ind & -ind);
	}
}
ll ask(ll ind){
	ll sm=0;
	while(ind>0){
		sm+=sum[ind];
		ind-= (ind & -ind);
	}
	return sm;
}

int main(){
	for(ll i=1;i<maxn;i++)
		for(ll j=i;j<maxn;j+=i)
			dv[j].PB(i);
	cin>>N>>K;
	ll ans=0;
	FORD(i,N-1,K){
		REP(j,sz(dv[N-i]))
			add(dv[N-i][j],1);
		ans+=N-i+ask(N)-ask(i);
	}
	if(K==0)
		ans-=N;
	cout<<ans;
}

Measured memory_bytes: 16896
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

int d[5];
int v[10];

signed main(){
	for(int i = 0; i < 3; ++i) {
		int a, b;
		cin >> a >> b;
		d[a]++;
		d[b]++;
	}
	for(int i = 1; i <= 4; ++i) {
		v[d[i]]++;
	}
	if(v[1] == 2 && v[2] == 2) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


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

int main() {
int a,b,c,ans;
  ans=0;
  cin>>a>>b>>c;
  cin>>a>>b>>c;
  for(int i=a;i<=b;i++){
  if(i%c==0){ans++;}}
  cout<<ans<<endl;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(n>=1&&m>=1)
	{
		cout<<(n-1)*(m-1)<<endl;
		return 0;
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::cmp::{min, max};
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:String = read();
    let c:Vec<char> = s.chars().collect();
    let mut ans = s.len();
    for i in c.iter() {
        let i = *i;
        let mut tmp = 0;
        for mut j in 0..s.len() {
            let mut k = j;
            while k < s.len() && !((c[k] == i) ^ (c[j] == i)) {
                k += 1;
            }
            if c[j] != i {
                tmp = max(tmp, k - j);
            }
            j = k;
        }
        ans = min(ans, tmp);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2084
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
int p[101];

int main(){
    int n, m, d, v, sum;
    for (; ;) {
        scanf("%d %d", &n, &m);
        if (n == 0 && m == 0) break;
        fill(p, p+m+1, 0);
        sum = 0;
        for (int i = 0; i < n; i++) {
            scanf("%d %d", &d, &v);
            p[d] = max(p[d], v);
        }
        for (int i = 1; i <= m; i++) sum+=p[i];
        printf("%d\n", sum);
    }
    return 0;
}



Measured memory_bytes: 2572
N,M=map(int, input().split())
A,C=[],[]
for i in range(N):
  a,b=map(int, input().split())
  A.append((a,b))
for i in range(M):
  a,b=map(int, input().split())
  C.append((a,b,i+1))

for i in range(N):
  long=10**9
  ans=-1
  for j in range(M):
    d=abs(A[i][0]-C[j][0])+abs(A[i][1]-C[j][1])
    if long>d:
      ans=C[j][2]
      long=d
  print(ans)

Measured memory_bytes: 9228
#include"bits/stdc++.h"
using namespace std;

bool isOK(int x) {
    if (x == 1) {
        return false;
    }

    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) {
            return false;
        }
    }

    int x2 = (x + 1) / 2;
    for (int i = 2; i * i <= x2; i++) {
        if (x2 % i == 0) {
            return false;
        }
    }

    return true;
}

int main() {
    int Q;
    cin >> Q;
    vector<int> l(Q), r(Q);
    for (int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
    }

    vector<int> sum(10e5 + 1, 0);
    for (int i = 1; i <= 10e5; i++) {
        if (i % 2 == 0) {
            sum[i] = sum[i - 1];
            continue;
        }
        if (isOK(i)) {
            sum[i] = sum[i - 1] + 1;
        } else {
            sum[i] = sum[i - 1];
        }
    }

    for (int i = 0; i < Q; i++) {
        cout << sum[r[i]] - sum[l[i] - 1] << endl;
    }
}

Measured memory_bytes: 5376
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int a[110];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,ans=1<<30;
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi();
    for(int t=-100;t<=100;t++) {
	int sum=0;
	for(int i=1;i<=n;i++) sum+=(a[i]-t)*(a[i]-t);
	ans=min(ans,sum);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256