akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A,B,C,D,E,F,G,H,L,M,N,P,Q,R,W,X,Y,Z;
string S,T;
vector<ll> V(100007);

int main(){
  cin >> A >> N;
  rep(i,N){
    cin >> B;
    M+=B;
  }
  if(M>=A){
    cYes;
  }
  else{
    cNo;
  }
}

Measured memory_bytes: 1532
#!/usr/bin/env python
# coding: utf-8

INF = 10**9+7
def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    l = input()

    dp = [[0 for _ in range(2)] for _ in range(100001)]
    dp[0][0] = 2
    dp[0][1] = 1

    for i, d in enumerate(l[1:]):
        if d == '1':
            dp[i+1][0] = 2*dp[i][0] % INF
            dp[i+1][1] = dp[i][0] % INF + 3*dp[i][1] % INF
        else:
            dp[i+1][0] = dp[i][0] % INF
            dp[i+1][1] = 3*dp[i][1] % INF
    ans = (dp[len(l)-1][0]+dp[len(l)-1][1]) % INF
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21292
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int i=0; i<n; ++i)

int main() {
  int n;
  std::cin >> n;
  std::string s[110];
  rep(i, n) std::cin >> s[i];

  std::map<std::string, int> march;

  int cnt = 0;

  march["P"] = 0;
  march["W"] = 0;
  march["G"] = 0;
  march["Y"] = 0;

  rep(i, n) {
    march[s[i]] += 1;
  }

  if(march["P"]) cnt += 1;
  if(march["W"]) cnt += 1;
  if(march["G"]) cnt += 1;
  if(march["Y"]) cnt += 1;

  if(cnt == 3) std::cout << "Three" << std::endl;
  else if(cnt == 4) std::cout << "Four" << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String main[]){
        Scanner sc = new Scanner(System.in);
        char[] a = sc.next().toCharArray();
        char[] b = sc.next().toCharArray();
        int tor= 0;
        for(int i = 0;i< a.length ;i++){
           tor += (a[i]==b[i]?1:0);
        }
        System.out.println(tor);
    }
}

Measured memory_bytes: 22740
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "9 45000" => "0 9 0",
    "20 196000" => "-1 -1 -1",
    "1000 1234000" => "2 54 944",
    "2000 20000000" => "2000 0 0"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: i32,
        y: i32
    }

    let mut ans = None;

    'outer: for i in 0..n  + 1{
        for j in 0..n - i + 1 {
            let k = n - i - j;

            if i * 10000 + j * 5000 + k * 1000 == y {
                ans = Some((i, j, k));
                break 'outer;
            }
        }
    }

    let (x, y, z) = ans.unwrap_or((-1, -1, -1));
    format!("{} {} {}", x, y, z)
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = sc.nextDouble();
		double b = sc.nextDouble();
		double c = 0;
		double C = sc.nextDouble() * (Math.PI / 180);
		double S = 0;
		double L = 0;
		double h = 0;
		h = b * Math.sin(C);
		double bcosC = b * Math.cos(C);
		double aminusbcosC = a - bcosC;
		c = Math.sqrt(Math.pow(h, 2) + Math.pow(aminusbcosC, 2));
		S = a * h / 2;
		L = a + b + c;
		System.out.printf("%f%n%f%n%f%n", S, L, h);
		sc.close();
	}
}


Measured memory_bytes: 28124
use std::io::*;

fn check(x: i64, mut n: i64) -> bool {
    while n % x == 0 {
        n /= x
    }
    n % x == 1
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let n: i64 = itr.next().unwrap().parse().unwrap();
    let m = n - 1;

    let mut ans = 1; // n
    if m > 1 {
        ans += 1;
    }
    let mut i = 2;
    while i * i <= m {
        if m % i == 0 {
            ans += 1;
            if m / i != i {
                ans += 1;
            }
        }
        i += 1;
    }

    i = 2;
    while i * i <= n {
        if n % i == 0 {
            if check(i, n) {
                ans += 1;
            }
            if n / i != i && check(n / i, n) {
                ans += 1;
            }
        }
        i += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-

###
# main
if(__name__ == '__main__'):
    # input
    k = int(input())
    s = input()

    postfix = ""
    if k < len(s):
        postfix = "..."
    elif len(s) < k:
        k = len(s)

    ans = s[0:k] + postfix

    print(ans)

# else:
    # do nothing

Measured memory_bytes: 9176
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    private int N;
    private List<E>[] Edges;
    private long[] Dist;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        Edges = new List<E>[N];
        for (int i = 0; i < N; i++)
        {
            Edges[i] = new List<E>();
        }

        for (int i = 0; i < N - 1; i++)
        {
            int u = sc.NextInt() - 1;
            int v = sc.NextInt() - 1;
            long w = sc.NextInt();

            Edges[u].Add(new E(v, w));
            Edges[v].Add(new E(u, w));
        }

        Dist = new long[N];
        Search(0, -1, 0);

        Console.WriteLine(string.Join("\n", Dist.Select(l => l % 2 == 0 ? 1 : 0)));
    }

    private void Search(int i, int parent, long dist)
    {
        Dist[i] = dist;
        foreach (E e in Edges[i])
        {
            if (e.V == parent) continue;
            Search(e.V, i, dist + e.W);
        }
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

struct E
{
    public int V;
    public long W;

    public E(int v, long w)
    {
        V = v;
        W = w;
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

using namespace std;

const int MOD = 1e9 + 7;
void add(int &a, int b)
{
	a += b;
	if (a >= MOD)
		a -= MOD;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	string s;
	cin >> s;

	vector<int> dp(2);
	dp[1] = 1;
	for (int len = 2; len <= n; len++)
	{
		vector<int> new_dp(dp.size() + 1);
		vector<int> pref;
		pref.push_back(dp.front());
		for (int i = 1; i < dp.size(); i++)
			pref.push_back((pref.back() + dp[i]) % MOD);

		char cmp = s[len - 2];
		for (int new_val = 1; new_val <= len; new_val++)
		{
			if (cmp == '<')
				new_dp[new_val] = pref[new_val - 1];
			else
				new_dp[new_val] = (pref.back() - pref[new_val-1] + MOD) % MOD;
		}
		dp = new_dp;
	}

	int ans = 0;
	for (auto i : dp)
		add(ans, i);
	cout << ans << "\n";
}



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

int main()
{
    int n;
    cin >> n;
    int p[23];
    for(int i = 0; i < n; i++) cin >> p[i];
    int ans = 0;
    for(int i = 1; i < n - 1; i++){
        if((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1])) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;cin>>n;
  int ans=0;
  rep(i,n){
    int x;cin>>x;
    while(x%2==0){
      x/=2;
      ans++;
      }
    }
  cout<<ans<<endl;
  return 0;
}


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

bool equalV(vector<int> &v,vector<int> &vv){
	for(int i=0;i<v.size();++i){
		if(v[i] != vv[i]) return false;
	}
	return true;
}

int main(){
	int n;
	cin >> n ;
	vector<int> v(n),vv(n);
	for(int i=0;i<n;++i){
		cin >> v[i];
	}
	
	vector<int> data(n);
	for(int i=0;i<n;++i){
		data[i] = i+1;
		cin >> vv[i];
	}
	
	int cnt = 1;
	int a;
	int b;
	
	
	
	do{
		if(equalV(v,data)){
			a = cnt;
		}
		if(equalV(vv,data)){
			b = cnt;
		}
		cnt++;
	}while(next_permutation(data.begin(),data.end()));
	
	
	cout << abs(a-b) <<endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)


// from: https://atcoder.jp/contests/abc137/submissions/6831647
template<typename T>
struct BellmanFord{
	struct edge{
		int u,v;
		T w;
		edge(){}
		edge(int u,int v,T w):u(u),v(v),w(w){}
	};

	int n;
	vector< vector<int> > G,Ginv;
	vector<int> reach;
	BellmanFord(int n):n(n),G(n),Ginv(n),reach(n,0){}

	vector<edge> es;
	void add_edge(int u,int v,T c){
		es.emplace_back(u,v,c);
		G[u].emplace_back(v);
		Ginv[v].emplace_back(u);
	}

	void dfs(int v){
		if(reach[v]) return;
		reach[v]=1;
		for(int u:Ginv[v]) dfs(u);
	}

	T build(int from,int to,int &neg_loop){
		dfs(n-1);
		const T INF = numeric_limits<T>::max();
		vector<T> ds(n,INF);
		ds[from]=0;
		for(int j=0;j<n;j++){
			bool update=0;
			for(auto e:es){
				if(!reach[e.u]||!reach[e.v]||ds[e.u]==INF) continue;
				if(ds[e.v]>ds[e.u]+e.w){
					ds[e.v]=ds[e.u]+e.w;
					update=1;
				}
			}
			if(!update) break;
			if(j==n-1){
				neg_loop=1;
				return INF;
			}
		}
		neg_loop=0;
		return ds[to];
	}
};

ll n,m,p,ans;

int main(){
	cin>>n>>m>>p;
	BellmanFord<ll> f(n);
	rep(i,m){
		ll a,b,x;
		cin>>a>>b>>x;
		f.add_edge(a-1,b-1,p-x);
	}
	int neg_loop;
	ans = f.build(0,n-1,neg_loop);
	cout<<(neg_loop?-1:max(-ans,0LL))<<endl;
	return 0;
}

Measured memory_bytes: 640
S=raw_input()
l=len(S)

if S[0]!="A":
	print "WA"
	quit()

s=2
e=l-2
cnt=0
for i in range(s,e+1):
	if S[i]=="C": cnt+=1

if cnt!=1:
	print "WA"
	quit()

komoji=list("abcdefghijklmnopqrstuvwxyz")

for i in range(1,l):
	if S[i]=="C": continue
	if S[i] not in komoji:
		print "WA"
		quit()


print "AC"

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

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

    int N;
    cin>>N;

    int A[N+2]={0};
    int B[N+2];
    int C[N+1];

    int cnt=0;

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

    for(int i=1;i<=N;i++){
        cin>>B[i];
    }

    for(int i=1;i<=N;i++){
        cin>>C[i];
    }


    for(int i=1;i<=N;i++){
        cnt=cnt+B[A[i]];

        if(A[i]+1==A[i+1]){
            cnt=cnt+C[A[i]];
        }


    }

    cout<<cnt<<"\n";

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
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; }

ll a, b;

template<typename T>
T gcd(T x, T y) {
    if (y==0) return x;
    return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y) {
    T g = gcd(x, y);
    return x / g * y;
}

int main() {
    cin >> a >> b;
    cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    int N;
    cin>>N;
    vector<float> v(N);
    rep(i,N)cin>>v[i];
    sort(all(v));
    float ans = v[0];
    rep1(i,N){
        ans = (ans + v[i])/2;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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(b<a){ a=b; return 1; } return 0; }
using namespace std;

void GreaterString(string &s, string t){
    if(s == "-") s = t;
    else if(s.size() < t.size()) s = t; 
    else if(s.size() == t.size()){
        if(s < t) s = t;
    }
}

int main(){
    Init();
    ll n, m;
    cin >> n >> m;
    vi a(m);
    rep(i, m) cin >> a[i];

    // 使う本数(match[0]はダミー)
    ll match[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    // dp[i]; マッチ棒をi本使って作れる最大値
    vector<string> dp(n+10, "-"); dp[0] = "";

    for(ll i=0; i<=n; i++){
        if(dp[i] == "-") continue;
        for(auto num: a){
            GreaterString(dp[i+match[num]], dp[i]+(char)(num+'0'));
        }
    }
    cout << dp[n] << endl;
}

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

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

	if(a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])
		cout << "YES" <<endl;
	else
		cout << "NO" <<endl;
}

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

struct Circle {
    int x, y, r, c, id;
};
bool overlap[24][24];
char mem[1 << 24];

inline int sq(int x) {
    return x * x;
}

void calc_overlap(vector<Circle> &cir) {
    int n = cir.size();
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            overlap[cir[i].id][cir[j].id] = sq(cir[i].x - cir[j].x) + sq(cir[i].y - cir[j].y) < sq(cir[i].r + cir[j].r);
            overlap[cir[j].id][cir[i].id] = overlap[cir[i].id][cir[j].id];
        }
    }
}

int dfs(vector<Circle> &cir, int key) {
    if (mem[key] != -1) return mem[key];

    int n = cir.size();
    bool ok[24] = {}; // ok[i] := cir[i]の上に何も重なってなければtrue

    for (Circle &c: cir) {
        ok[c.id] = true;
    }
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            if ( ! overlap[cir[i].id][cir[j].id]) continue;
            if (cir[i].id < cir[j].id) {
                ok[cir[j].id] = false;
            } else {
                ok[cir[i].id] = false;
            }
        }
    }

    int ret = 0;
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            Circle a = cir[i];
            Circle b = cir[j];
            if ( ! ok[a.id] || ! ok[b.id] || a.c != b.c) continue;

            swap(cir[j], cir.back()); cir.pop_back();
            swap(cir[i], cir.back()); cir.pop_back();
            key = key - (1 << a.id) - (1 << b.id);

            ret = max(ret, 2 + dfs(cir, key));

            cir.push_back(a); swap(cir[i], cir.back());
            cir.push_back(b); swap(cir[j], cir.back());
            key = key + (1 << a.id) + (1 << b.id);
        }
    }
    return mem[key] = ret;
}

int main() {
    int n;
    while (cin >> n && n) {
        int x, y, r, c;
        vector<Circle> cir;
        for (int i=0; i<n; ++i) {
            cin >> x >> y >> r >> c;
            cir.push_back((Circle){x, y, r, c, i});
        }

        calc_overlap(cir);
        fill_n(mem, 1 << 24, -1);

        cout << dfs(cir, (1 << n) - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 19540
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		Map<Long, Integer> map = new HashMap<>();
		long count = 0;

		for (int i = 0; i < n; i++) {
			long saveme = sc.nextLong();

			long former = i - saveme;
			long latter = i + saveme;

			count += map.getOrDefault(former, 0);

			map.putIfAbsent(latter, 0);
			map.put(latter, map.get(latter) + 1);
		}

		sc.close();

		System.out.println(count);
	}
}

Measured memory_bytes: 72072
import math


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True


def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)

    return divisors


a, b = map(int, input().split())

a_div = list(make_divisors(a))
a_div_pri = []
for num in a_div:
    if is_prime(num):
        a_div_pri.append(num)

a_div_pri.append(1)
ans = 0
for num in a_div_pri:
    if b % num == 0:
        ans += 1

print(ans)


Measured memory_bytes: 3828
N, Y = map(int, input().split())
A, B, C = 10000, 5000, 1000
yen = mai = 0
for a in range(N+1):
  yen, mai = A * a, a
  for b in range(N+1-mai):
    yen, mai = A * a + B * b, a + b
    for c in range(N-mai, N+1-mai):
      yen, mai = A * a + B * b + C * c, a + b + c
      if mai == N and yen == Y: break
    if mai == N and yen == Y: break
  if mai == N and yen == Y: break
else:
  a = b = c = -1
print('{} {} {}'.format(a, b, c))

Measured memory_bytes: 41068
#include<stdio.h>
int main(){
	int n,a=-1;
	scanf("%d",&n);
	for(int i=1;i<=4;i++){
		if(n%10==a){
			printf("Bad");
			return 0;
		}
		a=n%10;
		n/=10;
	}
	printf("Good");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
}

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

unsigned int MAX=100000+9;
int N, dp[100000][3], ns[100000][3];
int solve(int cur=0, int pre=0){
    if(cur == N) return 0;

    int &ret=dp[cur][pre];
    if(ret!=-1) return ret;

    ret=0;
    for(int i=0;i<3;i++){
        if(i == pre && cur != 0) continue;
        ret=max(ret, solve(cur+1, i)+ns[cur][i]);
    }

    return ret;
}

int main(){
    scanf("%d",&N);
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<N;i++) for(int j=0;j<3;j++) scanf("%d",&ns[i][j]);
    printf("%d", solve());
    return 0;
}


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

//  a^b % m
long long powmod(long long a, long long b, long long m)
{
    long long r = 1;
    for (; b>0; b>>=1, a=a*a%m)
        if (b&1)
            r = r*a%m;
    return r;
}

int main()
{
    long long N, M;
    cin>>N>>M;

    long long MOD = 998244353;
    
    vector<long long> F(M*3/2+N);
    F[0] = 1;
    for (int i=1; i<M*3/2+N; i++)
        F[i] = F[i-1]*i%MOD;

    auto comb = [&](long long a, long long b)
    {
        return F[a]*powmod(F[b], MOD-2, MOD)%MOD*powmod(F[a-b], MOD-2, MOD)%MOD;
    };

    auto f = [&](long long m)
    {
        long long ans = 0;
        for (int o=m%2; o<=min(M, N); o+=2)
            ans += comb(N, o)*comb((m-o)/2+N-1, N-1)%MOD;
        return ans%MOD;
    };

    long long ans = ((f(3*M)-N*f(M-1))%MOD+MOD)%MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 13952
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  if (K == 1) {
    cout << 0 << endl;
  } else {
    cout << N - K << endl;
  }    
  return 0;
}



Measured memory_bytes: 764
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int a,b,c;
int main()
{
    scanf("%d/%d/%d",&a,&b,&c);
    if(b<4)
        printf("Heisei\n");
    else if(b==4 && c<=30)
        printf("Heisei\n");
    else
        printf("TBD\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    string s;
    cin >> s;
    ll sum = 0;
    for(auto &&i : s) {
        sum += i - '0';
    }
    cout << max((int)sum, (int)(s.size() - 1) * 9 + s[0] - '0' - 1) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "";
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='0')
                ans+="0";
            if(s.charAt(i)=='1')
                ans+="1";
            if(s.charAt(i)=='B'){
                if(ans.length()>0)
                    ans = ans.substring(0,ans.length()-1);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21204
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=2e9;
const int magic=348;
const LL LINF=2e16;
const double eps=1e-10;

inline int getint()
{
	char ch;
	while ((ch=getchar())<'0' || ch>'9') {}
	int res=ch-'0';
	while ((ch=getchar())>='0' && ch<='9') res=res*10+ch-'0';
	return res;
}

int n;
int a[148];

int main ()
{
	int i;
	n=getint();
	for (i=1;i<=n;++i) scanf("%d",&a[i]);
	int pos_maxn=-INF,neg_minn=INF,pos,neg;
	for (i=1;i<=n;i++)
	{
		if (a[i]>=0 && a[i]>pos_maxn)
		{
			pos_maxn=a[i];
			pos=i;
		}
		if (a[i]<0 && a[i]<neg_minn)
		{
			neg_minn=a[i];
			neg=i;
		}	
	}
	if (pos_maxn==-INF)
	{
		printf("%d\n",n-1);
		for (i=n;i>=2;i--) printf("%d %d\n",i,i-1);
		return 0;
	}
	if (neg_minn==INF)
	{
		printf("%d\n",n-1);
		for (i=1;i<=n-1;i++) printf("%d %d\n",i,i+1);
		return 0;
	}
	printf("%d\n",n*2-2);
	if (pos_maxn>-neg_minn)
	{
		for (i=1;i<=n;i++)
			if (i!=pos) printf("%d %d\n",pos,i);
		for (i=1;i<=n-1;i++) printf("%d %d\n",i,i+1);
	}
	else
	{
		for (i=1;i<=n;i++)
			if (i!=neg) printf("%d %d\n",neg,i);
		for (i=n;i>=2;i--) printf("%d %d\n",i,i-1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e7

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    cin >> n;
    vector<int>l(n),r(n);
    for(int i = 0; i < n; i++) cin >> l[i] >> r[i];
    vector<vector<int>>dp(n,vector<int>(n,INF));
    for(int i = 0; i < n; i++) dp[i][i] = 0;
    for(int p = 2; p <= n; p++)
    {
        for(int i = 0; i+p-1 <= n-1; i++)
        {
            int j = i+p-1;
            int S = INF;
            for(int k = i; k < j; k++) S = min(S,dp[i][k]+dp[k+1][j]+l[i]*r[k]*r[j]);
            dp[i][j] = S;
        }
    }
    cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;

vector<int> edge[101000];
int p[101000];
P hist[101000];
int resV[101000];

P mergeP(P x, P y){
    return P(max(x.fs, y.fs), min(x.sc, y.sc));
}


P dfs(int s, int prev, int index){
    P x;
    if(p[s] != -1){
        if(p[s] % 2 != index){
            return P(10000010, -10100000);
        }
        else {
            x = P(p[s], p[s]);
        }

    }
    else if(index == 0){
        x = P(-2000000, 2000000);
    }
    else{
        x = P(-1999999, 1999999);
    }

    for(auto v: edge[s]){
        if(v == prev){
            continue;
        }
        x = mergeP(x, dfs(v, s, 1-index));
    }
    hist[s] = x;
    return P(x.fs - 1, x.sc + 1);
}


bool dfs2(int s, int prev, int prevValue){
    bool res = true;
    if(prevValue + 1 >= hist[s].fs && prevValue + 1 <= hist[s].sc){
        resV[s] = prevValue + 1;
    }
    else if(prevValue - 1 >= hist[s].fs && prevValue - 1 <= hist[s].sc){
        resV[s] = prevValue - 1;
    }
    else{
        return false;
    }

    for(auto v: edge[s]){
        if(v == prev){
            continue;
        }
        if(!dfs2(v, s, resV[s])){
            res = false;
        }
    }
    return res;
}


int main(){
    ll N, K;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    fill(p, p+N, -1);
    cin >> K;
    int root = -1;
    for(int i = 0; i < K; i++){
        int v, p2;
        cin >> v >> p2;
        v--;
        p[v] = p2;
        if(root == -1){
            root = v;
        }
    }

    dfs(root, root, p[root] % 2);
//    for(int i = 0; i < N; i++){
//        cout << i << " " << hist[i].fs << " " << hist[i].sc << endl;
//    }
    bool res = dfs2(root, root, p[root]+1);
    if(res){
        cout << "Yes" << endl;
        for(int i = 0; i < N; i++){
            cout << resV[i] << endl;
        }
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}




Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    cout<<n*(n-1)/2<<endl;
}

Measured memory_bytes: 256
#                         author:  kagemeka 
#                         created: 2019-11-08 15:54:47(JST)
### modules
## from standard library
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   # if use comb function on AtCoder, 
# import scipy.misc      # select scipy.misc.comb (old version)  

def main():
    *n, = (int(x) for x in sys.stdin.readline().split())
    n.sort()
    print(n[-1] - n[0])


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include <cassert>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
long long power_mod(long long x, long long n, long long m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return power_mod(x * x % m, n / 2, m);
	else
		return x * power_mod(x, n - 1, m) % m;
}
long long power(long long a, long long n) {//aのn乗を計算します。
	long long x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

int dx[4] = { 1,0,-1,0 };//D,R,U,L
int dy[4] = { 0,1,0,-1 };

int N;
int A[505050], B[505050];
int dp[2020202][2];
int cnt[2020202];
signed main() {
	cin >> N;
	REP(i, N)cin >> A[i];
	m0(B);
	REP(i, N) {
		B[i + 1] = A[i] ^ B[i];
	}
	//REP(i, N + 1)pe(B[i]); cout << endl;
	REP(i, 1LL<<20)m0(dp[i]);
	if (B[N] != 0) {
		int x = B[N];
		dp[0][1] = 1;
		REP(i, N) {
			dp[i + 1][0] += dp[i][0];
			dp[i + 1][1] += dp[i][1];
			if (B[i+1] == x) {
				dp[i + 1][0] += dp[i][1];
			}
			else if(B[i+1]==0){
				dp[i + 1][1] += dp[i + 1][0];
			}
			dp[i + 1][0] %= MOD;
			dp[i + 1][1] %= MOD;
		}
		print(dp[N - 1][1]%MOD); return 0;
	}
	else {
		m0(cnt);
		int sum = 0;
		REP(i, 1LL<<20) {
			dp[i][1] = 1;
		}
		REP(i, N) {
			if (B[i] == 0) {
				sum++;
			}
			else {
				dp[B[i]][1] += (dp[B[i]][0] * (sum - cnt[B[i]]))%MOD;
				dp[B[i]][0] += dp[B[i]][1];
				dp[B[i]][0] %= MOD;
				dp[B[i]][1] %= MOD;
				cnt[B[i]] = sum;
			}
			assert(dp[B[i]][0] >= 0);
			assert(dp[B[i]][1] >= 0);
		}
		int ans = 0;
		FOR(i, 1, 1LL<<20) {
			if (dp[i][0] > 0) {
				//pe(i)print(dp[i][0]);
			}
			ans += dp[i][0];
			ans %= MOD;
			assert(ans >= 0);
		}
		ans += power_mod(2, sum - 1, MOD);
		//ans += power(2, sum - 1);
		assert(ans >= 0);
		print(ans% MOD);
	}
}

Measured memory_bytes: 41088
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int D;
vi c(26);
vector<vector<ll>> S(365, vector<ll>(26));
vi ans(365);

ll eval() {
    vi last(26, 0);

    ll score = 0;
    REP(i, D) {
        int t = ans[i];

        score += S[i][t];
        last[t] = i + 1;

        REP(j, 26) {
            score -= c[j] * (i + 1 - last[j]);
        }
    }

    return score;
}

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

    cin >> D;

    REP(i, 26) cin >> c[i];

    vi last(26, 0);
    REP(i, D) {
        vll s(26);
        REP(j, 26) {
            cin >> s[j];
            S[i][j] = s[j];
        }

        vll p(26);
        ll p_all = 0;
        REP(j, 26) {
            p[j] = c[j] * (i + 1 - last[j]);
            p_all += p[j];
        }

        REP(j, 26) {
            s[j] -= p_all - p[j];
        }

        int idx = max_element(ALL(s)) - s.begin();

        last[idx] = i + 1;
        ans[i] = idx;
    }

    ll score = eval();

    std::random_device rd;
    std::mt19937 mt(rd());
    std::uniform_int_distribution<int> d_rng(0, D-1);
    std::uniform_int_distribution<int> t_rng(0, 25);

    REP(i, 3e5) {
        int d = d_rng(mt), t = t_rng(mt);
        if (ans[d] == t) {
            --i;
            continue;
        }

        int old = ans[d];

        ans[d] = t;
        ll new_score = eval();
        if (score < new_score) {
            score = new_score;
        } else {
            ans[d] = old;
        }
    }

    REP(i, D) {
        print(ans[i] + 1);
    }

}


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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

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

  long K, A, B;
  cin >> K >> A >> B;

  if (B - A <= 2) return cout << 1 + K << "\n", 0;

  if (1 + (K - 2) < A) return cout << 1 + K << "\n", 0;

  K -= A + 1;
  long ans = B;

  cout << ans + (B - A) * (K / 2) + K % 2 << "\n";
}

Measured memory_bytes: 3624
n, p = map(int, input().split())
s = input()
r = set()
last = 0
d = {0: 0}
total = 0
rem = 0
if p == 2:
    for i in range(0, len(s)):
        if int(s[i]) % 2 == 0:
            total += i + 1
    print(total)
elif p == 5:
    for i in range(0, len(s)):
        if int(s[i]) % 5 == 0:
            total += i + 1
    print(total)



else:
    power = 1
    for i in range(len(s) - 1, -1, -1):  # handling of 0's as n and rem
        n = int(s[i]) * power + rem
        power *= 10
        power = power % p
        rem = n % p
        if rem in d.keys():
            d[rem] += 1
        else:
            d[rem] = 1
        total += d[rem] - 1
    print(total + d[0])

Measured memory_bytes: 4072
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (int)(n); (i)++)
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; (i)--)
#define For(i, a, b)    for(int i = (a); (i) < (int)(b) ; (i)++)
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n, r; cin >> n >> r;
    int ans = r;

    if(n >= 10) cout << ans << endl;
    else if(n < 10) cout << ans + 100 * (10 - n) << endl;

return 0;
}

Measured memory_bytes: 3560
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    
    N, K = map(int,input().split())
    WD = [tuple(map(int,input().split())) for _ in range(N)]

    def solve(tgt):
        res = 0
        for w,d in WD:
            res += max(0, (tgt-w)//d+1)
        if res >= K:
            return True
        else:
            return False

    ok = 2*(10 ** 18)  # exist
    ng = 0  # not exist
    while abs(ok - ng) > 1:
        cnt = (ok + ng) // 2
        if solve(cnt):
            ok = cnt
        else:
            ng = cnt
    print(ok)
    


Measured memory_bytes: 56704
import bisect

N = int(input())
L =[int(i)for i in input().split()]
L.sort()
ans = 0
for i in range(1,N):
    for j in range(i):
        len = L[i] - L[j] +1
        ind = bisect.bisect_left(L,len) -1
        ans += max(j-ind-1,0)
        #print(L[i],L[j],max(j-ind,0))
print(ans)


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 998244353;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

FiniteField Power(FiniteField x, int p) {
  if (p < 0) return FiniteField(1) / Power(x, -p);
  FiniteField value = 1;
  while (p) {
    if (p % 2) value *= x;
    x *= x;
    p /= 2;
  }
  return value;
}

tuple<vector<FiniteField>, vector<FiniteField>> MakeFactorialTables(int n) {
  vector<FiniteField> factorials(n + 1);
  vector<FiniteField> inverse_factorials(n + 1);
  factorials[0] = 1;
  for (int i = 1; i <= n; i++) {
    factorials[i] = factorials[i - 1] * i;
  }
  inverse_factorials[n] = FiniteField(1) / factorials[n];
  for (int i = n; i >= 1; i--) {
    inverse_factorials[i - 1] = inverse_factorials[i] * i;
  }
  return make_tuple(factorials, inverse_factorials);
}


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

  int n, m, k;
  cin >> n >> m >> k;

  auto[factorials, inverse_factorials] = MakeFactorialTables(n);
  auto c_fn = [&](int n, int k) -> FiniteField {
    if (k < 0 || k > n) return 0;
    return factorials[n] * inverse_factorials[k] * inverse_factorials[n - k];
  };

  FiniteField ans = 0;
  for (int i = 0; i <= k; i++) {
    ans += c_fn(n - 1, n - 1 - i) * FiniteField(m) * Power(FiniteField(m - 1), n - 1 - i);
  }
  cout << ans << endl;
}

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

char judge(int pm, int pe, int pj){
    if ( pm == 100 || pe == 100 || pj == 100 ) return 'A';
    if ( (pm + pe)/2 >= 90 ) return 'A';
    if ( (pm + pe + pj)/3 >= 80 ) return 'A';
    if ( (pm + pe + pj)/3 >= 70 ) return 'B';
    if ( (pm + pe + pj)/3 >= 50 ){
	if ( pm >= 80 || pe >= 80 ) return 'B';
    }
    return 'C';
}

main(){
    int n, pm, pe, pj;
    while(1){
	cin >> n;
	if ( n == 0 ) break;
	assert(1 <= n && n <= 10000);
	for ( int i = 0; i < n; i++ ){
	    cin >> pm >> pe >> pj;
	    assert( 0 <= pm && pm <= 100);
	    assert( 0 <= pe && pe <= 100);
	    assert( 0 <= pj && pj <= 100);
	    cout << judge(pm, pe, pj) << endl;
	}
    }
}

Measured memory_bytes: 0