akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(ll n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
     mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
mint dp[200005];
int main(){
    int n;
    cin>>n;
    V<int> a(n+1);
    for(int i=0;i<n;i++)cin>>a[i];
    V<int> bfo(200005,-1);
    dp[0]=1;
    for(int i=0;i<n;i++){
        if(bfo[a[i]]!=-1&&i-bfo[a[i]]>1){
            dp[i]+=dp[bfo[a[i]]];
        }
        dp[i+1]+=dp[i];
        bfo[a[i]]=i;
    }
    cout<<dp[n]<<"\n";
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int n; cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n-1) cin>>c[i];
    int sum=0;
    rep(i,n){
        sum+=b[a[i]-1];
        if(i>0 && a[i]==a[i-1]+1) sum+=c[a[i]-2];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>  
#include<cstdio>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<climits>   
#include<cmath> 
#include<vector>  
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map> 
#define inf 9999999; 
using namespace std;

bool vis[100005];
int sons[100005],father[100005],deep[100005],n;
vector<int> tu[100005];
void dfs(int son,int fa)
{
	int k;
	sons[son]=1;
	deep[son]=deep[fa]+1;
	father[son]=fa;
	for(int i=0;i<tu[son].size();i++)
	{
		k=tu[son][i];
		if(k==fa) continue;
		if(vis[k]==0)
		{
			vis[k]=1;
			dfs(k,son);
			sons[son]+=sons[k];
		}
	}
}

int main()
{
	int i,x,y,tot;
	cin>>n;
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		tu[x].push_back(y);
		tu[y].push_back(x);
	}
	memset(deep,0,sizeof(deep));
	memset(vis,0,sizeof(vis));
	vis[1]=1;
	dfs(1,0);
	tot=deep[n]-deep[1]-1;
	tot/=2;
	x=n;
	while(tot--)
		x=father[x];
	if(sons[x]>=n-sons[x])
	{
		cout<<"Snuke"<<endl;
	}
	else
	{
		cout<<"Fennec"<<endl;
	}
}

Measured memory_bytes: 14848
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
string s;
int n=700;
cin>>s;
for(int i=0;i<=2;i++)
if(s[i]=='o')
n+=100;
cout<<n;
system("pause");
return 0;
}

Measured memory_bytes: 504
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
 
#define MP make_pair
#define PB push_back
#define ST first
#define ND second
 
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>;
 
//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k
 
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;
 
void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
 
string s;
int n;
 
bool isp(string s) {
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != s[(int)s.size()-1-i])
      return false;
  }
  return true;
}
 
int main() {
  init_ios();
  cin >> s;
  n = s.size();
  if (!isp(s)) {
    cout<<"No\n"; 
    return 0;
  }
  s = "!" + s;
  string q = "";
  for (int i = 1; i <= (n-1)/2; ++i)
    q += s[i];
  if (!isp(q)) {
    cout<<"No\n";
    return 0;
  }
  q = "";
  for (int i = (n+3)/2; i <= n; ++i)
    q += s[i];
  if (!isp(q)){
    cout<<"No\n";
    return 0;
  }
  cout<<"Yes\n";
}

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

using namespace std;

int main(void)
{
    int N, M;
    int H[100000];

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

    bool check[100000];
    for(int i = 0; i < N; i++){
        check[i] = true;
    }
    
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        if(H[a-1] <= H[b-1]){
            check[a-1] = false;
        }
        if(H[a-1] >= H[b-1]) {
            check[b-1] = false;
        }
    }

    int count = 0;
    for(int i = 0; i < N; i++){
        if(check[i] == true){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 4116
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int h1 = scan.nextInt();
		int m1 = scan.nextInt();
		int h2 = scan.nextInt();
		int m2 = scan.nextInt();
		int k = scan.nextInt();
		int time = 0;

		if(m1 <= m2) {
			time += (h2 - h1) * 60 + (m2 - m1);
			time -= k;
		}else {
			time += ((h2 - h1) * 60) - (m1 - m2);
			time -= k;
		}

		System.out.println(time);
	}
}


Measured memory_bytes: 35668
#include <cstdio>
#include <cassert>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <sstream>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

int m[1010][1010];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    int i, j;
    for (i=0; i<n; ++i) {
        int x, y, bw = 0;
        char c;
        scanf("%d%d", &x, &y);
        while (!(c = getchar()) || c == ' ' || c == '\n');
        bw = ((c == 'W') ^ (x / k) ^ (y / k)) & 1;
        x %= k; y %= k;
        if (bw) {
            ++m[0][0], --m[x+1][0], --m[0][y+1], m[x+1][y+1] += 2;
        } else {
            ++m[x+1][0], ++m[0][y+1], m[x+1][y+1] -= 2;
        }
    }
    for (i=0; i<k; ++i) {
        int s = 0;
        for (j=0; j<k; ++j) {
            m[i][j] = (s += m[i][j]);
        }
    }
    for (j=0; j<k; ++j) {
        int s = 0;
        for (i=0; i<k; ++i) {
            m[i][j] = (s += m[i][j]);
        }
    }
    int mx = -1;
    for (i=0; i<k; ++i) {
        for (j=0; j<k; ++j) {
            mx = max({mx, m[i][j], n - m[i][j]});
        }
    }
    printf("%d\n", mx);
    return 0;
}


Measured memory_bytes: 4096
import collections
s = input()
head = []
tail = []
is_reveresed = False
q = int(input())
for i in range(q):
    query = input()
    if query[0] == '1':
        is_reveresed = not is_reveresed
    else:
        f = query[2]
        c = query[4]
        if is_reveresed:
            if f == '1':
                tail.append(c)
            else:
                head.append(c)
        else:
            if f == '1':
                head.append(c)
            else:
                tail.append(c)
if is_reveresed:
    print('{}{}{}'.format(''.join(tail[::-1]), s[::-1], ''.join(head)))
else:
    print('{}{}{}'.format(''.join(head[::-1]), s, ''.join(tail)))


Measured memory_bytes: 72664
fun main() {
    val N = readLine()!!.toInt()
    val ans = IntArray(N+1)
    for(x in 1L..100L){
        for(y in 1L..100L){
            for(z in 1L..100L){
                val p = x*x + y*y + z*z + x*y + y*z + z*x
                if(p <= N){
                    ans[p.toInt()]++
                }
            }
        }
    }
    ans.slice(1..N).joinToString(separator = "\n").let { println(it) }
}

Measured memory_bytes: 40888
let for_range s e step f =
  let rec loop i =
    if i > e then ()
    else
      begin f i;loop (i + step) end
  in loop s;;

let a =
  let num = 1000000 in
  let p = Array.init (num+1) (fun x -> 1) in
  let rec loop i =
    if i*i < num then
      begin
        for_range (i+i) num i (fun x -> p.(x) <- 0);
        loop (i+2)
      end
  in
  p.(0) <- 0; p.(1)<-(0);
  for_range 4 num 2 (fun x -> p.(x) <- 0);
  loop 3;
  for i = 1 to num-1 do
    p.(i) <- p.(i) + p.(i-1);
  done;
  let rec read () =
    try let n = read_int () in
        Printf.printf "%d\n" p.(n);
        read ()
    with End_of_file -> ()
  in read ();;

Measured memory_bytes: 10236
#include<iostream>
using namespace std;
main(){
  int n,a,c;

  int b[100];
cin >> n;
  
  for(a=0;a<n;a++){
    cin >> b[a];
  } 
  for(c=n-1;c>=0;c--){
    cout<<b[c];
    if(c==0)break;
    else cout <<" ";  
}

  cout<<"\n";
}

Measured memory_bytes: 1164
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <string.h>

using namespace std;

int N;
int t[2000];

int main(int argc, char** argv) {
    cin >> N;
    int ans = 1e9;

    for (int i = 0; i <= N; i++) {
        // pay i yen using 6
        int count2 = 0;
        int y = i;
        while (y != 0) {
            count2 += y % 6;
            y /= 6;
        }
        y = N - i;
        while (y != 0) {
            count2 += y % 9;
            y /= 9;
        }
        ans = min(ans, count2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
include Math
def koch_Curve(pos)
  list = []
  0.upto(pos.size-2){|i|
    s = [pos[i][0]+(pos[i+1][0] - pos[i][0]) / 3.0, pos[i][1]+(pos[i+1][1] - pos[i][1]) / 3.0]
    t = [pos[i][0]+(pos[i+1][0] - pos[i][0]) / 1.5, pos[i][1]+(pos[i+1][1] - pos[i][1]) / 1.5]
    v = [t[0]-s[0], t[1] - s[1]]
    u = [s[0]+v[0] * $cos - v[1] * $sin, s[1]+v[0] * $sin + v[1] * $cos]
    list += [pos[i], s, u, t]
  }
  list += [pos[pos.size-1]]
  return list
end

$sin = sqrt(3.0)/2.0
$cos = 1.0/2.0

pos = [[0,0],[100,0]]
gets.to_i.times{
  pos = koch_Curve(pos)
}
pos.each{|p|
  printf "%f %f\n", p[0],p[1]
}

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

double N, K;

int main() {
  cin >> N >> K;
  vector<int> A(N), F(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> F[i];
  sort(A.begin(), A.end());
  sort(F.rbegin(), F.rend());
  ll l = -1, r = 1e12;
  while (l + 1 < r) {
    ll c = (l + r) / 2;
    bool ok = [&]{
      ll s = 0;
      rep(i, N) {
        s += max(0ll, A[i] - c / F[i]);
      }
      return s <= K;
    }();
    if (ok) r = c; else l = c;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i, n){
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    int ans = 0;
    rep(i, n){
        if(x == s[i]){
            REP(j, i+1, n) ans += t[j];
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		    Scanner sc = new Scanner(System.in);

		    String s_original = sc.nextLine();
		    String[] s = s_original.split("",0);
		    int n = s.length;
		    int R_i = 0;
		    int L_i = 0;
		    int[] m = new int[n];
		    int flg =0;
		    int num1=0;
		    int num2=0;
		    for(int i=0;i<n;i++) {
		    	m[i]=0;
		    	if(s[i].equals("R")) {
		    		if(flg == 0) {
		    			flg=1;
		    			num1 += 1;
		    		}else if(flg == 1) {
		    			flg=0;
		    			num2+=1;
		    		}else if(flg==2) {
		    			m[R_i]+=num2;
		    			num2=0;
		    			m[L_i]+=num1;
		    			num1=1;
		    			R_i=0;
		    			L_i=0;
		    			flg=1;
		    		}else if(flg==3) {
		    			m[R_i]+=num2;
		    			num2=0;
		    			m[L_i]+=num1;
		    			num1=1;
		    			R_i=0;
		    			L_i=0;
		    			flg=1;
		    		}
		    	}else if(s[i].equals("L")) {
		    		if(flg==2) {
		    			flg=3;
		    			num2+=1;
		    		}else if(flg==3) {
		    			flg=2;
		    			num1+=1;
		    		}else if(flg==0){
		    			R_i = i-1;
		    			L_i = i;
		    			m[R_i]+=num2;
		    			num2=0;
		    			m[L_i]+=num1;
		    			num1=1;
		    			flg=2;
		    		}else if(flg==1) {
		    			R_i = i-1;
		    			L_i = i;
		    			m[R_i]+=num1;
		    			num1=1;
		    			m[L_i]+=num2;
		    			num2=0;
		    			flg=2;
		    		}
		    	}
		    }
		    m[R_i]+=num2;
			m[L_i]+=num1;
		    for(int i=0;i<n;i++) {
		    	System.out.print(m[i]+" ");
		    }

		    sc.close();
	}
}


Measured memory_bytes: 48800
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
#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;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

const int INF=1e9;
const double eps=0.0000000001;

int main(){

    ll x;
    cin >> x;
    ll sum=0;
    for(ll i=1;i<1000000000;i++){
      sum+=i;
      if(sum>=x){
        cout << i << endl;
        return 0;
      }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int r;
    cin>>r;
    if(r<1200) cout<<"ABC"<<endl;
    else if(r<2800) cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
}

Measured memory_bytes: 256
module Main where
 
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

digits :: Integer -> Integer
digits x
  | x > 9 = 1 + (fromIntegral $ digits (x `div` 10))
  | otherwise = 1
dd [a, b] = digits $ a + b
-- dd [a, b] = (digits a, digits b)

main :: IO ()
main = do
    ns <- fmap (fmap (read :: String -> Integer) . words) . lines <$> getContents
    forM_ [0..length ns-1] $ \i -> do
      putStrLn $ show $ dd (ns!!i)

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

#define ll             long long
#define LL             long long
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define TN             typename
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define endl           '\n'

template <TN T> T gcd(T a, T b) {
    return !b ? a : gcd(b, a % b);
}

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

template <TN T> T sqr(T a) {
    return a * a;
}

template <TN T> T cube(T a) {
    return a * a * a;
}

template <TN T> inline void smin(T &a, T b) {
    a = a < b ? a : b;
}

template <TN T> inline void smax(T &a, T b) {
    a = a > b ? a : b;
}

int in() {
    int n;
    scanf("%d", &n);
    return n;
}

ll Lin() {
    ll n;
    scanf("%lld", &n);
    return n;
}

double Din() {
    double n;
    scanf("%lf", &n);
    return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 1e6 + 5;

struct CHT_INC_MAX {
    vl m, b;

    bool bad(int f1, int f2, int f3) {
        return 1.0 * (b[f2] - b[f1]) * (m[f1] - m[f3]) > 1.0 * (b[f3] - b[f1]) * (m[f1] - m[f2]);
    }

    void add(ll M, ll B) {
        m.pb(M), b.pb(B);
        int sz = (int)m.size();
        while(sz >= 3 && bad(sz - 3, sz - 2, sz - 1)) {
            m.erase(m.end() - 2);
            b.erase(b.end() - 2);
            sz--;
        }
    }

    ll f(int idx, ll X) {
        return m[idx] * X + b[idx];
    }

    ll query(ll X) {
        int low = 0, high = (int) m.size() - 1;
        while (high - low >= 5) {
            int mid1 = (low + low + high) / 3;
            int mid2 = (low + high + high) / 3;
            if (f(mid1, X) <= f(mid2, X)) {
                low = mid1 + 1;
            } else {
                high = mid2 - 1;
            }
        }
        ll res = f(low, X);
        for (int i = low + 1; i <= high; i++) {
            res = max(res, f(i, X));
        }
        return res;
    }
};

pair<pll, ll> p[N];

int solve() {
  ll n = Lin();
  cout << n * n * 3 << endl;
    return 0;
}

int main() {
    int test = 1, tc = 0;
    //scanf("%d", &test);
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
int main(){
    int n;
    cin>>n;
    vin a(n-1);
    rep(i,n-1)cin>>a[i];
    sort(all(a));
    vin b(n);
    rep(i,n-1){
        b[a[i]-1]++;
    }
    b[n-1]=0;
    rep(i,n)cout<<b[i]<<endl;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;




int a[200000];
signed main(){
  int n;
  cin >> n;
  rep(i,n)scanf("%lld", &a[i]);
  int sum = 0, k = 0;
  rep(i,n)sum += a[i];
  k = (2*sum)/(n*(n+1));
  if(n*(n+1)*k != 2*sum){
    cout << "NO" << endl;return 0;
  }
  
  int ans = 0, cnt = 0;
  rep(i,n){
    int now = i, prev = (i-1+n)%n;
    int d = (a[prev]+k)-a[now];
    if(a[prev]+k < a[now] or d%n != 0){ans = -1;break;}
    if(d == 0)continue;
    cnt += d/n;
  }
  
  if(ans == -1){cout << "NO" << endl;return 0;}
  cout << (cnt == k ? "YES" : "NO") << endl;
	return 0;
}










Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,a0) memset(a,a0,sizeof(a))
#define vector basic_string
#define fi first
#define se second
#ifndef qwq
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
#endif
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=200010; const double err=1e-11; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;} typedef double lf; typedef long double llf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;} typedef pair<int,int> pii;
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
#define int ll
int n,m;
vector<pii> ans;
signed main(){
	cin>>n>>m;
	if(n%2==1)
	repeat(i,0,m){
		ans.push_back({i+1,n-i-1});
	}
	else{
		repeat(i,0,n/4)
			ans.push_back({i+1,n/4*2-i});
		repeat(i,0,n/2-n/4-1)
			ans.push_back({n/4*2+1+i,n-1-i});
	}
	repeat(i,0,m)cout<<ans[i].fi<<' '<<ans[i].se<<endl;
	return 0;
}

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

using namespace std;

long long gcd (long long a, long long b) {
    if ( a > b )
        swap(a, b);

    long long mod;
    while ( (mod = b % a) != 0 ) {
        b = a;
        a = mod;
    }

    return a;
}

vector<long long> calc_prime_factor (long long val) {
    vector<long long> prime_factor;

    for ( long long i=2; i*i<=val; i++ ) {
        if ( val % i != 0 )
            continue;
        prime_factor.push_back(i);
        while ( val % i == 0 ) {
            val /= i;
        }
    }
    if ( val != 1 )
        prime_factor.push_back(val);

    return prime_factor;
}

int main (void) {
    long long A, B;
    cin >> A >> B;

    long long gcd_val = gcd(A, B);

    vector<long long> prime_factor = calc_prime_factor(gcd_val);

    cout << prime_factor.size() + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("test.txt","r",stdin);
	ll n;
	cin>>n;
	vector<ll> a;
	for(ll i=0;i<=n;i++)
	{
		ll x;
		cin>>x;
		a.push_back(x);
	}	
	vector<ll> b;
	for(ll i=0;i<n;i++)
	{
		ll x;
		cin>>x;
		b.push_back(x);
	}
	ll cnt=0;
	for(ll i=0;i<n;i++)
	{
		if(a[i]<b[i]){
			cnt+=a[i];
			b[i]-=a[i];
		}
		else
		{
			cnt+=b[i];
			b[i]=0;
		}
		if(a[i+1]<b[i])
		{
			cnt+=a[i+1];
			a[i+1]=0;
			b[i]-=a[i+1];
		}
		else{
			cnt+=b[i];
			a[i+1]-=b[i];
		}
	}

	cout<<cnt<<"\n";

}



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

int a[4];
bool buf[4];

bool dfs(int sum, int d) {
  if (d == 4) {
    if (sum == 7) return true;
    return false;
  }
  buf[d] = false;
  if (dfs(sum+a[d], d+1)) return true;
  buf[d] = true;
  if (dfs(sum-a[d], d+1)) return true;
  return false;
}

int main() {
  string s;
  cin >> s;
  rep(i, 4) a[i] = s[i] - '0';
  dfs(0, 0);
  rep(i, 4) {
    if (i) cout << (buf[i] ? '-' : '+') << a[i];
    else {
      if (buf[i]) cout << '-';
      cout << a[i];
    }
  }
  cout << "=7" << endl;
  return 0;
}

Measured memory_bytes: 256
import copy
from itertools import combinations
S = input()

result = 0
for n_plus in range(len(S)):
    for plus_indices in combinations(range(1, len(S)), n_plus):
        S_new = copy.deepcopy(S)
        c = 0
        for i, plus_idx in enumerate(plus_indices):
            S_new = S_new[:plus_idx+i] + '+' + S_new[plus_idx+i:]
        result += eval(S_new)
print(result)

Measured memory_bytes: 3444
A,B,C,D=map(int,input().split())
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
def lcm(a,b):
  return (a*b)//gcd(a,b)
s=(A-1)//C
t=(A-1)//D
u=(A-1)//lcm(C,D)
v=s+t-u
w=A-1-v
S=B//C
T=B//D
U=B//lcm(C,D)
V=S+T-U
W=B-V
print(W-w)


Measured memory_bytes: 3064
A, B, C, D = map(int, input())
if A+B+C+D==7:
    a = "+"
    b = "+"
    c = "+"
elif A+B+C-D==7:
    a = "+"
    b = "+"
    c = "-"
elif A+B-C+D==7:
    a = "+"
    b = "-"
    c = "+"
elif A+B-C-D==7:
    a = "+"
    b = "-"
    c = "-"
elif A-B+C+D==7:
    a = "-"
    b = "+"
    c = "+"
elif A-B+C-D==7:
    a = "-"
    b = "+"
    c = "-"
elif A-B-C+D==7:
    a = "-"
    b = "-"
    c = "+"
elif A-B-C-D==7:
    a = "-"
    b = "-"
    c = "-"

print(str(A)+a+str(B)+b+str(C)+c+str(D)+"=7")

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int n;cin>>n;
   uint64_t ans=0;
   for(int i=1;i<=n;i++){
      if(i%3!=0&&i%5!=0&&i%3!=0&&i%5!=0){
         ans+=i;
      }
   }
   cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

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

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 3564
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N,M; cin >> N >> M;
    int a[N], b[N], c[M], d[M]; REP(i,N) cin >> a[i] >> b[i]; REP(i,M) cin >> c[i] >> d[i];
    vector<priority_queue<pair<int,int>, vector<P>, greater<P>>> dist(N);
    REP(i,N){
        REP(j,M){
            dist[i].push(P(abs(a[i]-c[j])+abs(b[i]-d[j]), j+1));
        }
    }
    REP(i,N) cout << dist[i].top().second << endl;
    return 0;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
total = 0
for i in range(1, n+1):
  total_digit = 0
  j = i
  while j > 0:
    total_digit += j % 10
    j //= 10
    if j == 0:
      if total_digit >= a and total_digit <= b:
        total += i
print(total)

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  string s;
  cin >> s;
  if (s[0] != s[1] || s[1] != s[2]) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	int n;
	double x1,y1,x2,y2,x3,y3,x1_2,x1_3,y1_2,y1_3,z1_2,z1_3,a,b,c,r;
	while(cin >> n){
		for(int i = 0;i < n;++i){
			cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
			z1_2 = (((x1 * x1) + (y1 * y1)) * -1) - (((x2 * x2) + (y2 * y2)) * -1);
			z1_3 = (((x1 * x1) + (y1 * y1)) * -1) - (((x3 * x3) + (y3 * y3)) * -1);
			x1_2 = x1 - x2;
			x1_3 = x1 - x3;
			y1_2 = y1 - y2;
			y1_3 = y1 - y3;
			a = ((y1_2 * z1_3) - (y1_3 * z1_2)) / ((y1_2 * x1_3) - (y1_3 * x1_2));
			b = ((x1_2 * z1_3) - (x1_3 * z1_2)) / ((x1_2 * y1_3) - (x1_3 * y1_2));
			c = ((x1 * x1) + (y1 * y1) + (a * x1) + (b * y1)) * -1;
			r = sqrt((c * -4) + (a * a) + (b * b)) / 2.0;
			printf("%.3f %.3f %.3f\n",a / -2.0,b / -2.0,r);
		}
	}
	return 0;
}

Measured memory_bytes: 0
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object Main extends App {

  var ss = StdIn.readLine().reverse
  val t = StdIn.readLine().reverse
  //val buff = ArrayBuffer.empty[Char]
  val ret = ArrayBuffer.empty[String]

  val len = ss.length
  val lent = t.length
  var i = 0
  var replaced = false
  while (i < len) {
    var j = 0
    var k = i
    var unmatch = false
    //buff.clear()
    while (j < lent && !unmatch && k < len) {
      //if(t(j) == ss(k) || ss(k) == '?'){
      if(t(j) != ss(k) && ss(k) != '?'){
        unmatch = true
      } else {
        //buff.append(t(j))
        j += 1
        k += 1
      }
    }
    if(j == lent && !unmatch){
      ret.append(t)
      ret.append(ss.drop(k))
      replaced = true
      i += len
    } else {
      ret.append(ss(i).toString)
      i += 1
    }
  }

  val result = ret.mkString("")
  println(if(len < lent || !replaced) "UNRESTORABLE" else result.replace("?", "a").reverse)

}


Measured memory_bytes: 25424
#include<iostream>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
struct cmp{
    bool operator() (string s3,string s4){
        int size1=s3.length();
        int size2=s4.length();
        int size3=min(size1,size2);
        for(int i=0;i<size3;i++){
            if(s3.at(i)>s4.at(i))
                return true;
            else if(s4.at(i)>s3.at(i))
                return false;
        }
        if(size1>size2)
            return true;
        else
            return false;
    }
};
string s;
int k;
int Size;
priority_queue<string,vector<string>,cmp> ss;
int aa[5000];
int num;
char cc[26];



int main(){
    cin>>s;
    cin>>k;
    int kk=k;
    Size=s.length();
    for(int i=0;i<26;i++){
        cc[i]='a'+i;
    }
    for(int m=0;m<26;m++){
        num=0;
        for(int i=0;i<Size;i++){
            if(s.at(i)==cc[m]){
                aa[num]=i;
                num++;
            }
        }
        for(int i=0;i<num;i++){
            string sss="";
            int l=aa[i]+k;
            if(l>Size)
                l=Size;
            for(int j=aa[i];j<l;j++){
                sss=sss+s.at(j);
                ss.push(sss);
            }
        }
        string s1="";
        string s2="";
        while(k&&!ss.empty()){
            s2=ss.top();
            ss.pop();
            if(s1!=s2){
                k--;
            }
            s1=s2;
        }
        if(k==0){
            cout<<s2<<endl;
            break;
        }
    }
    if(k!=0){
            k=kk;
        for(int m=0;m<26;m++){
        num=0;
        for(int i=0;i<Size;i++){
            if(s.at(i)==cc[m]){
                aa[num]=i;
                num++;
            }
        }
        for(int i=0;i<num;i++){
            string sss="";
            for(int j=aa[i];j<Size;j++){
                sss=sss+s.at(j);
                ss.push(sss);
            }
        }
        string s1="";
        string s2="";
        while(k&&!ss.empty()){
            s2=ss.top();
            ss.pop();
            if(s1!=s2){
                k--;
            }
            s1=s2;
        }
        if(k==0){
            cout<<s2<<endl;
            break;
        }
    }
    }
    return 0;
}


Measured memory_bytes: 1660
#include <cstdio>
#include <iostream>

static const int MAX_NUM  = 101;
static const int NO_VISIT  = 0;
static const int NOW_VISIT = 1;
static const int END_VISIT = 2;

void MPT(int *pElem, int num)
{
    int i;
    int mincost;
    int target;
    int parent[MAX_NUM];
    int cost[MAX_NUM];
    int state[MAX_NUM] = {0};
    int *tmp;
    int total = 0;

    for (i = 0; i < num; i++) {
        parent[i] = -1;
        cost[i]   = 0x7FFFFFFF;
    }

    cost[0] = 0;

    for (;;) {
        mincost = 0x7FFFFFFF;
        for (i = 0; i < num; i++) {
            if ((state[i] != END_VISIT) && (mincost > cost[i])) {
                target  = i;
                mincost = cost[i];
            }
        }
        if (mincost == 0x7FFFFFFF) {
            break;
        }

        state[target] = END_VISIT;
        total += mincost;

        tmp = pElem + target * MAX_NUM;
        for (i = 0; i < num; i++) {
            if ((state[i] != END_VISIT) && (*(tmp + i) < cost[i])) {
                cost[i]   = *(tmp + i);
                parent[i] = target;
                state[i]  = NOW_VISIT;
            }
        }
    }

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

    return;
}

int main(void)
{
    int i, j;
    int num;
    int tmp;
    int elem[MAX_NUM][MAX_NUM];

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        for (j = 0; j < num; j++) {
            scanf("%d", &tmp);
            elem[i][j] = (tmp != -1) ? tmp : 0x7FFFFFFF;
        }
    }

    MPT(&elem[0][0], num);

    return 0;
}

Measured memory_bytes: 1228
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int sub[200005],n,ans1,ans2,mod=1e9+7,er[200005];
V<int> v[200005];
int ksm(int a,int b){
	int t=mod-2,sum=1;
	while(t){
		if(t&1)sum=sum*a%mod;
		t=t/2;
		a=a*a%mod;
	}
	RE sum*b%mod;
}
void dfs(int p,int fa){
	int re=1;
	for(int i=0;i<v[p].size();i++){
		if(v[p][i]!=fa){
			dfs(v[p][i],p);
			re+=sub[v[p][i]];
			ans2=(ans2-er[sub[v[p][i]]]+1+mod)%mod;
		}
	}
	ans2=(ans2-er[n-re]+1+mod)%mod;
	sub[p]=re;
}
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int x,y;
	cin>>n;
	FOR(i,1,n-1){
		cin>>x>>y;
		v[x].PB(y);v[y].PB(x);
	}
	er[0]=1;
	FOR(i,1,n){
		er[i]=er[i-1]*2%mod;
	}
	ans1=er[n];ans2=er[n-1]*n%mod;
	ans2=(ans2-n+mod)%mod;
	dfs(1,-1);
	cout<<ksm(ans1,ans2);
	RE 0;
}




Measured memory_bytes: 21632
N,K=map(int,input().split())
r,s,p=map(int,input().split())

S=input()
li=[1]*(K)
ans=[0,0,0]

for i in range(N-K):
    if S[i]==S[i+K]:
        li[i%K]+=1
    else:
        if S[i]=="r":
            ans[0]+=(li[i%K]+1)//2
        if S[i]=="s":
            ans[1]+=(li[i%K]+1)//2
        if S[i]=="p":
            ans[2]+=(li[i%K]+1)//2
        li[i%K]=1


for j in range(N-K,N):
    if S[j]=="r":
            ans[0]+=(li[j%K]+1)//2
    if S[j]=="s":
            ans[1]+=(li[j%K]+1)//2
    if S[j]=="p":
            ans[2]+=(li[j%K]+1)//2
    
    
print(p*ans[0]+r*ans[1]+s*ans[2])


Measured memory_bytes: 9772
// 4/30
// 過去問攻略

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <deque>
using namespace std;

int main() {
    long long N, P;
    string S;

    cin >> N >> P;
    cin >> S;
    
    long long ans = 0;

    if (P == 2) {
        for (int i = 0; i < N; i++) {
            int s = S[i] - '0';
            if (s % 2 == 0) {
                // cout << s << endl;
                // ans += ((i + 1) * (i + 2)) / 2;
                ans += i + 1;
            }
        }

        cout << ans << endl;
        return 0;
    }

    if (P == 5) {
        for (int i = 0; i < N; i++) {
            int s = S[i] - '0';
            if (s % 5 == 0) {
                // cout << s << endl;
                ans += i + 1;  // ((i + 1) * (i + 2)) / 2;
            }
        }

        cout << ans << endl;
        return 0;
    }

    else {
        long long dp[P] = {0};
        dp[0] = 1;

        long long val = 0;
        long long moddigit = 1;

        for (int i = 0; i < N; i++) {
            val = (val + (S[N - 1 - i] - '0') * moddigit) % P;
            dp[val]++;
            moddigit = (moddigit * 10) % P;
        }
        
        for (int i = 0; i < P; i++) {
            ans += dp[i] * (dp[i] - 1) / 2;
        }

        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 644
# include <cstdio>
bool f [100001];
int c [100002];
int N ,L , R ;
int main ()
{
for ( int i =2; i <=100000; i ++) if (! f [ i ]) for ( int j = i + i ;j <=100000; j += i )
f[ j ]= true ;
for ( int i =3; i <=100000; i +=2) if (! f [ i ]&&! f [( i +1)/2]) c [ i ]++;
for ( int i =3; i <=100000; i ++) c [ i ]+= c [i -1];
scanf ("%d " ,&N );
while (N--)
{
scanf ("%d %d " ,&L ,& R );
printf ("%d \n " , c [ R ] - c [L -1]);
}
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"

using namespace std;

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

void Main()
{
	int n;
	cin >> n;
	vector<int> ans(n+1, 0);
	//for(int a = 1; a <= n; a++){
		//int ans = 0;
		for(int i = 1; i <= 100; i++){
			for(int j = 1; j <= 100; j++){
				for(int k = 1; k <= 100; k++){
					if(1 <= i*i + j*j + k*k + i*j + j*k + k*i && i*i + j*j + k*k + i*j + j*k + k*i <= n){
						//ans++;
						ans[i*i + j*j + k*k + i*j + j*k + k*i]++;
					}
				}
			}	
		}
		//cout << ans << endl;
	//}
	for(int i = 1; i <= n; i++){
		cout << ans[i] << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  int n;
  cin >> n;
  string s;
  set<string> st[n];
  for(int i=0;i<n;i++){
    cin >> s;
    int len=s.length();
    for(int j=0;j<len-1;j++){
      string s1="",s2="",revs1="",revs2="";
      for(int k=0;k<=j;k++){
        s1 += s[k];
        revs1 += s[j-k];
      }
      for(int k=j+1;k<=len-1;k++){
        s2 += s[k];
        revs2 += s[len+j-k];
      }
      st[i].insert(s1+s2);
      st[i].insert(s1+revs2);
      st[i].insert(s2+s1);
      st[i].insert(s2+revs1);
      st[i].insert(revs1+s2);
      st[i].insert(revs1+revs2);
      st[i].insert(revs2+s1);
      st[i].insert(revs2+revs1);
    }
    cout << st[i].size() << endl;
  }
}

Measured memory_bytes: 8984
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto abk = readints;
    int a = abk[0], b = abk[1], k = abk[2];

    for (int i = a; i <= min(a + k - 1, b); i++)
        writeln(i);

    for (int i = max(a + k, b - k + 1); i <= b; i++)
        writeln(i);
}


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

using namespace std;

int N;
vector<int> A;
struct Value {
    int val;
    int index;
};

int main(void) {
    cin>>N;
    struct Value MIN,MAX;
    
    int temp;
    cin>>temp;
    A.push_back(temp);
    MIN.val = MAX.val = temp;
    MIN.index = MAX.index = 1;

    for(int i = 2;i <= N;i++) {
        int temp;
        cin>>temp;

        A.push_back(temp);
        if(temp > MAX.val) {
            MAX.val = temp;
            MAX.index = i;
        }
        if(temp < MIN.val) {
            MIN.val = temp;
            MIN.index = i;
        }
    }

    
    if(abs(MIN.val) <= abs(MAX.val)) {
        cout<<2*N-2<<endl;
        for(int i = 1;i <= N;i++) {
            if(i != MAX.index)
                cout<<MAX.index<<" "<<i<<endl;
        }
        for(int i = 2;i <= N;i++) {
            cout<<i-1<<" "<<i<<endl;
        }
    } else {
        cout<<2*N-2<<endl;
        for(int i = 1;i <= N;i++) {
            if(i != MIN.index) {
                cout<<MIN.index<<" "<<i<<endl;
            }
        }
        for(int i = N;i >= 2;i--) {
            cout<<i<<" "<<i-1<<endl;
        }
    }

    return 0;
}


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

const int N = 1010;
int p[N];
int n, k;

int main()
{
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%d", &p[i]);
    sort(p + 1, p + 1 + n);

    int res = 0;
    for(int i = 1; i <= k; i++) res += p[i];
    printf("%d\n", res);

    return 0;
}

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

#define endl '\n'

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

    int a,b,c; cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto LS = readln.split.to!(int[]);

    sort!"a > b"(LS);
    auto l = LS[0];
    auto sum_l = reduce!"a + b"(0, LS[1..$]);
    writeln(l < sum_l ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int N;
    cin>>N;
    vector<int>A(N);
    int p=0;
    rep(i,N){
        cin>>A[i];
        if(i==0){
            p+=abs(A[i]);
        }
        else{
            p+=abs(A[i]-A[i-1]);
        }
        if(i==N-1){
            p+=abs(A[i]);
        }
        }
        rep(i,N){
          int ans=p;
            if(i==0){
                ans-=abs(A[0])+ abs(A[0]-A[1]);
                ans+=abs(A[1]);
            }
            else if(i==N-1){
                ans-=abs(A[N-1])+abs(A[N-2]-A[N-1]);
                ans+=abs(A[N-2]);
            }
            else{
                ans-=abs(A[i]-A[i-1])+abs(A[i]-A[i+1]);
                ans+=abs(A[i-1]-A[i+1]);
            }
            cout<<ans<<endl;
        }
    }



Measured memory_bytes: 3748
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
#define MAXN 100000
int x1[MAXN+10],x2[MAXN+10];
bool b[MAXN+10];
void solve(long long N, vector<long long> L, vector<long long> R){
	for(int i=1; i<=N; ++i) {
		x1[i]=i-1;
		x2[i]=i-1;
	}	
	sort(x1+1,x1+1+N,[&](int x,int y){return L[x]>L[y];});
	sort(x2+1,x2+1+N,[&](int x,int y){return R[x]<R[y];});
	int now=0;
	LL sum1=0;
	memset(b,true,sizeof(b));
	int *p1=x1+1,*p2=x2+1;
	for(int i=1; i<=N; ++i) {
		static bool f=true;
		f=!f;
		if (f) {
			while(!b[*p1]) ++p1;
			b[*p1]=false;
			if (L[*p1]<=now && R[*p1]>=now) continue;
			sum1+=abs(now-L[*p1]);
			now=L[*p1];
		} else {
			while(!b[*p2]) ++p2;
			b[*p2]=false;
			if (L[*p2]<=now && R[*p2]>=now) continue;
			sum1+=abs(now-R[*p2]);
			now=R[*p2];
		}
	}
	sum1+=abs(now);
	now=0;
	LL sum2=0;
	memset(b,true,sizeof(b));
	p1=x1+1,p2=x2+1;
	for(int i=1; i<=N; ++i) {
		static bool f=false;
		f=!f;
		if (f) {
			while(!b[*p1]) ++p1;
			b[*p1]=false;
			if (L[*p1]<=now && R[*p1]>=now) continue;
			sum2+=abs(now-L[*p1]);
			now=L[*p1];
		} else {
			while(!b[*p2]) ++p2;
			b[*p2]=false;
			if (L[*p2]<=now && R[*p2]>=now) continue;
			sum2+=abs(now-R[*p2]);
			now=R[*p2];
		}
	}
	sum2+=abs(now);
	//debug(sum1,sum2);
	LL ans=max(sum1,sum2);
	cout<<ans<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long N;
	scanf("%lld",&N);
	vector<long long> L(N-1+1);
	vector<long long> R(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&L[i]);
		scanf("%lld",&R[i]);
	}
	solve(N, L, R);
	return 0;
}



Measured memory_bytes: 4224
#include<stdio.h>
int main(){
  char s[4];
  int d = 0;
  scanf("%s", s);
  switch(s[0]){
    case 'S':
      if(s[1] == 'A') d = 1;
      else d = 7;
      break;
    case 'F':
      d = 2;
      break;
    case 'T':
      if(s[1] == 'H') d = 3;
      else d = 5;
      break;
    case 'W':
      d = 4;
      break;
    case 'M':
      d = 6;
      break;
  }
  printf("%d\n", d);
  return 0;
}

Measured memory_bytes: 128