akhauriyash/Code-Regression huggingface dataset:
# abc168_b.py
# https://atcoder.jp/contests/abc168/tasks/abc168_b

# B - ... (Triple Dots) /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 200点

# 問題文
# 英小文字からなる文字列 Sがあります。
# Sの長さが K 以下であれば、Sをそのまま出力してください。
# Sの長さが K を上回っているならば、先頭 K文字だけを切り出し、末尾に ... を付加して出力してください。

# 制約
#     Kは 1 以上 100以下の整数
#     Sは英小文字からなる文字列
#     Sの長さは 1 以上 100以下

# 入力
# 入力は以下の形式で標準入力から与えられる。
# K
# S

# 出力
# 問題文の通りに出力せよ。

# 入力例 1
# 7
# nikoandsolstice

# 出力例 1
# nikoand...

# nikoandsolstice の長さは 15であり、K=7を上回っています。
# この先頭 7文字を切り出して末尾に ... を付加した文字列 nikoand... を出力します。

# 入力例 2
# 40
# ferelibenterhominesidquodvoluntcredunt

# 出力例 2
# ferelibenterhominesidquodvoluntcredunt

# ガイウス・ユリウス・カエサルの名言です。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    K = int(lines[0])
    S = lines[1]
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if len(S) > K:
        result = S[:K] + '...'
    else:
        result = S

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['7', 'nikoandsolstice']
        lines_export = ['nikoand...']
    if pattern == 2:
        lines_input = ['40', 'ferelibenterhominesidquodvoluntcredunt']
        lines_export = ['ferelibenterhominesidquodvoluntcredunt']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9212
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
using System.IO;

namespace ConsoleApp2
{
    class Program {
        static decimal C(int a,int b) {
            decimal res = 1;
            for (int i = 0; i < b; i++) {
                res *= (a - i);
                res /= (i + 1);
            }
            return res;
        }
        static void Main(string[] Args) {
            //Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));

            var l = new List<string>(ReadLine().Split(' ')).Select(int.Parse).ToList();
            int N = l[0];
            int A = l[1];
            int B = l[2];

            var Value = new List<string>(ReadLine().Split(' ')).Select(long.Parse).GroupBy(i => i).OrderBy(x => -x.Key).ToList();

            /*
            foreach (var e in Value) {
                WriteLine(e.Key + ":" + e.Count());
            }
            */            

            decimal res = 0;
            decimal ave = 0; /* 合計の意味もある */

            if (A <= Value[0].Count()) {
                for (int i = A; i <= B; i++) {
                    //WriteLine(String.Format("{0}C{1} = {2}", A, Value[0].Count(), C(Value[0].Count(), i)));
                    res += C(Value[0].Count(), i);
                }
                ave = Value[0].Key;
            } else {
                int i;
                int A_ = A;
                for (i = 0; A >= Value[i].Count(); i++) {
                    A -= Value[i].Count(); /* 選んだ */
                    ave += Value[i].Key * Value[i].Count();
                }
                res = C(Value[i].Count(), A);
                ave += Value[i].Key * A;
                ave /= A_;
            }
            WriteLine(ave);
            WriteLine(res);

            ReadLine();
        }
    }
}


Measured memory_bytes: 13652
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
#include <string.h>
#include<bits/stdc++.h>
#define MOD 1046527
#define MAX 1046527
using namespace std;

bool A[MAX+10]={};
char s[MAX+10][100]={};

unsigned long long int hash2(char str[]){
  int t;
  unsigned long long int a=0,p=1;
  for(int i=0;i<(int)strlen(str);i++){
    if(str[i]=='A')t=1;
    else if(str[i]=='T')t=2;
    else if(str[i]=='C')t=3;
    else if(str[i]=='G')t=4;
    else t=0;
    a+=t*p;
    p*=5;
  }for(int i=0;;i++){
    unsigned long long int c=(a%MOD+i*(1+a%(MOD-1)))%MOD;
    if(!strcmp(s[c],str)||strlen(s[c])==0){
      a=c;
      break;
    }
  }
  //printf("%llu ",a);fflush(stdout);
  return a;
}

int main(){
  int n;
  char str1[100];
  char str2[100];
  unsigned long long int h=1;
  cin>>n;
  for(int i=0;i<n;i++){
    scanf("%s %s",str1,str2);
    h=hash2(str2);
    if(str1[0]=='i'){
      A[h]=true;
      strcpy(s[h],str2);
    }
    else if(str1[0]=='f'){
      if(A[h]&&!strcmp(s[h],str2))printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}



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

int main() {
    // cout<<fixed<<setprecision(12);
    ll n;
    cin >> n;
    
    vector<ll> vec(n);
    map<ll, ll> mp;
    ll x;
    rep(i, n) {
        cin >> x;
        vec.at(i) = x;
        mp[x]++;
    }
    
    ll comb = 0;
    // for (const auto& [key, value] : mp){
    //     // cout << key << " => " << value << "\n";
    //     comb += (value * (value-1)) / 2;
    // }
    
    
    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        comb += (iter->second * (iter->second-1)) / 2;
    }
    
    
    map<ll, ll> comb_mp;
    // for (const auto& [key, value] : mp){
    //     comb_mp[key] = comb - ((value * (value-1)) / 2) + (((value-1) * (value-2)) / 2);
    // }
    for (auto iter = begin; iter != end; iter++) {
        comb_mp[iter->first] = comb - ((iter->second * (iter->second-1)) / 2) + (((iter->second-1) * (iter->second-2)) / 2);
    }
    
    ll y;
    rep(i, n) {
        y = vec.at(i);
        cout << comb_mp[y] << endl;
    }
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,a[100005],cnt[100005],mx;

int main(){
    ios_base :: sync_with_stdio(0); cin.tie();
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(int i=1;i<=100000;i++){
        mx=max(mx,cnt[i-1]+cnt[i]+cnt[i+1]);
    }
    cout << mx;
}


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

void solve(long long A, long long B)
{
    cout << (A - 1) * (B - 1) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var buf = new string[h];
        var ss = new string('.', w);
        var a = new bool[w];
        var p = 0;
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s != ss) buf[p++] = s;
            for (int j = 0; j < w; j++)
                if (s[j] == '#') a[j] = true;
        }
        for (int i = 0; i < p; i++)
        {
            var ans = "";
            for (int j = 0; j < w; j++)
                if (a[j]) ans += buf[i][j];
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
// ---------- begin chmin, chmax ----------
trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------

use proconio::marker::*;
use proconio::*;
use std::cmp::*;
use std::collections::*;

fn run() {
    input! {
        n: usize,
        p: [(f64, f64, Chars); n],
    }
    let map = vec![('U', 0), ('L', 1), ('D', 2), ('R', 3)]
        .into_iter()
        .collect::<BTreeMap<_, _>>();
    let dir = [(0f64, 1f64), (-1f64, 0f64), (0f64, -1f64), (1f64, 0f64)];
    let mut p = p
        .into_iter()
        .map(|(x, y, s)| (x, y, map.get(&s[0]).cloned().unwrap()))
        .collect::<Vec<_>>();
    let inf = 10f64.powi(9);
    let mut time = vec![0f64];
    for _ in 0..4 {
        let mut down = -inf;
        let mut up = -inf;
        let mut fix = -inf;
        for &(_, y, d) in p.iter() {
            if d == 0 {
                up.chmax(y);
            } else if d == 2 {
                down.chmax(y);
            } else {
                fix.chmax(y);
            }
        }
        time.push(down - fix);
        time.push((down - up) * 0.5);
        time.push(fix - up);
        for p in p.iter_mut() {
            *p = (-p.1, p.0, (p.2 + 1) & 3);
        }
    }
    let mut ans = inf * inf;
    for t in time {
        if t < 0f64 {
            continue;
        }
        let mut range = (inf, -inf, inf, -inf);
        for &(x, y, d) in p.iter() {
            let x = x + dir[d].0 * t;
            let y = y + dir[d].1 * t;
            range.0.chmin(x);
            range.1.chmax(x);
            range.2.chmin(y);
            range.3.chmax(y);
        }
        ans.chmin((range.1 - range.0) * (range.3 - range.2));
    }
    println!("{:.2}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 13660
#include<iostream>

using namespace std;
int main()

{

string s1,s2,s3;

cin>>s1>>s2>>s3;

if(s1[0]>='a'&&s1[0]<='z'){
    s1[0]-=32;
}
if(s2[0]>='a'&&s2[0]<='z'){
    s2[0]-=32;
}
if(s3[0]>='a'&&s3[0]<='z'){
    s3[0]-=32;
}
cout<<s1[0]<<s2[0]<<s3[0]<<endl;




return 0;

}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
#include <numeric>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <cassert>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>

int main() {
	long long int a, b, c, d; std::cin >> a >> b >> c >> d;
	std::cout << std::max({ a * c, a * d, b * c, b * d }) << std::endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <utility>
#include <vector>
#include <algorithm>
 
using namespace std;
 
typedef pair<int, int> pii;
 
signed main(){
  int p, q;
  int k;
  cin >> p >> q;
  k = __gcd(p, q);
  p /= k;
  q /= k;
   
  int q_ = q;
  vector<pii> ans;
  for(int i = 2 ; i <= sqrt(q) ; i++){
    if(q_%i == 0){
      pii p = make_pair(i, 1);
      q_ /= i;
      while(q_%i == 0){
        p.second++;
        q_ /= i;
      }
      ans.push_back(p);
    }
  }
 
  if(q_ > 1) ans.push_back(pii(q_, 1));
   
  int a = 1;
  for(int i = 0 ; i <(int) ans.size() ; i++){
    a *= ans[i].first;
  }
 
  cout << a << endl;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
using lint=long long;
 
int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);
 
	lint x=0;
	for(int i=2;i<n;i++) x^=a[i];
 
	if(a[0]+a[1]<x || (a[0]+a[1]-x)%2!=0) return puts("-1"),0;
 
	lint y=(a[0]+a[1]-x)/2;
	if((~x&y)!=y || a[0]<y) return puts("-1"),0;
 
	// maximize r s.t. r & ~x = y, r <= a[0]
	lint res=y;
	for(int i=60;i>=0;i--) if((x>>i&1)==1) {
		if((res|(1LL<<i))<=a[0]) res|=1LL<<i;
	}
	printf("%lld\n",res==0?-1:a[0]-res);
 
	return 0;
}

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

int n;
int a[100000];

ll solve(ll t){
  ll res = 0, sum = 0;
  for (ll i = 0; i < n; i++, t = -t){
    sum += a[i];
    if (sum * t > 0) continue;
    res += abs(sum - t);
    sum += t * abs(sum - t);
  }
  return res;
}

int main(){
  cin >> n;
  REP(i,n) cin >> a[i];
  ll res = solve(1);
  res = min(res, solve(-1));
  cout << res << endl;
  return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n,k;
  cin >> n >> k;
  ll ans = 0;
  int b;
  for(b=k+1;b<=n;b++)
  {
    int full = n/b;
    int marg = n%b;
    ans += full*(b-k);
    ans += max(marg-k+1,0);
    if(k == 0)ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = gets.to_i
h = gets.chomp.split.map(&:to_i)
count = 0
max = 0
1.upto(n-1) do |i|
  if h[i] <= h[i-1] then
    count += 1
  else
    max = count if max < count
    count = 0 if count != 0
  end
end
max = count if max < count
puts max

Measured memory_bytes: 9604
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
  for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair


const int mod = 1e9+7;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod; return a;} 
inline int sub(int a,int b){a-=b;if(a<0) a += mod; return a;}
inline int mul(int a, int b){ return a*1ll*b%mod;}
inline int power(int x, ll y){
  int res = 1;
  while(y){
    if(y&1) res = mul(res , x);
    x = mul(x,x);
    y >>= 1;
  }
  return res;
}
int r, c,k;
const int N = 3e3 + 100;
ll val[N][N];
ll dp[4][N][N];

int main(){
  fio; cout<<fixed<<setprecision(25);	
  cin >> r >> c >>k;
  int r1, c1, v1;
  for(int i =1 ;i <= k ; ++i){
    cin >> r1 >> c1 >> v1;
    val[r1][c1] = v1;
  }
  for(int i = 1;i <= r; ++i){
    for(int j =1 ;j <= c; ++j){
      for(int k = 0;k < 4; ++k){
        dp[0][i][j] = max(dp[0][i][j] , dp[k][i-1][j]);
        dp[1][i][j] = max(dp[1][i][j] , val[i][j] + dp[k][i-1][j]);
        if(k){
          dp[k][i][j] = max(dp[k][i][j] , val[i][j] + dp[k-1][i][j-1]);
          dp[k][i][j] = max(dp[k][i][j] , dp[k][i][j-1]);
        }
      }
    }
  }
  ll mx = 0;
  for(int i = 0;i < 4 ; ++i)
    mx = max(mx , dp[i][r][c]);
  cout << mx << endl;
  return 0;
}



Measured memory_bytes: 366764
def main():
    s = input()
    if s[0] == s[-1]:
        if len(s) % 2 == 0:
            print("First")
        else:
            print("Second")
    else:
        if len(s) % 2 == 0:
            print("Second")
        else:
            print("First")


if __name__ == "__main__":
    main()


Measured memory_bytes: 39152
n = int(input())
a = list(map(int, input().split()))

def insertionSort(a, n):
    for i in range(1, n):
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print(' '.join(map(str, a)))

print(' '.join(map(str, a)))
insertionSort(a, n)


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

#define ll long long
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)

int main(void)
{

  int a,b,h;
  cin >> a >>b >>h;

  cout << (a+b)*h/2 <<endl;

 
 return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
typedef long long ll;

using namespace std;

int main(){
	int N, K;
  	cin >> N >> K;
  	string S;
  	cin >> S;
  	int p = 0;
  	for(int i = 0; i < S.size()-1; i++){
   		if(S[i] == S[i+1]) p++;
    }
  	int ans = min(p+2*K, N-1);
  	cout << ans << endl;
}

Measured memory_bytes: 512
x=[]
while True:
    a,op,b = map(str,input().split())
    a,b = int(a),int(b)
    if op == '?':
        break
    elif op=='+':
        x1 = a+b
    elif op=='-':
        x1 = a-b
    elif op=='*':
        x1 = a*b
    elif op=='/':
        if a%b != 0:
            x1 = int(a//b)
        else:
            x1=int(a/b)
    x.append(x1)
for i in range(len(x)):
    print(x[i])


Measured memory_bytes: 5600
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int64_t A[100001];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		in >> A[i];
	}

	int64_t count = 0;
	//+-+-
	int64_t sum = 0;
	for (size_t i = 0; i < N; i++)
	{
		sum += A[i];
		if (i & 1) {
			if (sum >= 0) {
				count += sum + 1;
				sum = -1;
			}
		}
		else {
			if (sum <= 0) {
				count += -sum + 1;
				sum = 1;
			}
		}
	}
	int64_t min = count;
	
	count = 0;
	//-+-+
	sum = 0;
	for (size_t i = 0; i < N; i++)
	{
		sum += A[i];
		if (i & 1) {
			if (sum <= 0) {
				count += -sum + 1;
				sum = 1;
			}
		}
		else {
			if (sum >= 0) {
				count += sum + 1;
				sum = -1;
			}
		}
	}

	min = std::min(min, count);

	out << min << endl;

	return 0;
}
#endif


Measured memory_bytes: 1024
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if(a+b==c||a+c==b||b+c==a)out.println("Yes");
        else out.println("No");
    }
}

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

using namespace std;

const int MOD = 1e9 + 7;
int n, m, nrc;
int dp[3003], fact[200002], inv[200002];

struct Ciuperci {
  int x, y;
}v[3003];

bool cmp (Ciuperci x, Ciuperci y) {
  if (x.x == y.x)
    return x.y < y.y;
  else
    return x.x < y.x;
}

int lol(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1LL * ans * a % MOD;
     a = 1LL * a * a % MOD;
     b >>= 1;
  }
  return ans;
}

void precalculare() {
  fact[0] = fact[1] = 1;
  for(int i = 2; i <= 200000; ++i)
    fact[i] = (1LL * fact[i - 1] * i) % MOD;
  inv[200000] = lol(fact[200000], MOD - 2);
  for(int i = 200000 - 1; i >= 0; --i)
    inv[i] = (1LL * inv[i + 1] * (i + 1)) % MOD;
}

int comb(int n, int k) {
  return (1LL * fact[n] * inv[k] % MOD * inv[n - k]) % MOD;
}

int main() {
  precalculare();
  cin >> n >> m >> nrc;
  for (int i = 1; i <= nrc; ++i) {
    cin >> v[i].x >> v[i].y;
  }
  sort(v + 1, v + 1 + nrc, cmp);
  v[++nrc].x = n;
  v[nrc].y = m;
  for (int i = 1; i <= nrc; ++i) {
    dp[i] = comb(v[i].x + v[i].y - 2, v[i].x -1);
    for (int j = 1; j < i; ++j)
      if(v[j].y <= v[i].y)
        dp[i] = (dp[i] - 1LL * dp[j] * comb(v[i].x - v[j].x + v[i].y - v[j].y, v[i].x - v[j].x) % MOD + MOD) % MOD;
  }
  cout << dp[nrc];
  return 0;
}


Measured memory_bytes: 2304
N = int(input())
a = list(map(int, input().split()))

i = 0
j = 1
cnt = 0
while i < N:
    if a[i] == j:
        i += 1
        j += 1
    else:
        i += 1
        cnt += 1

if cnt == N:
    print(-1)
else:
    print(cnt)

Measured memory_bytes: 24744
use std::io;
use std::f64;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn isPrime(x: u64) -> bool {
    let mut ret = true;
    let limit = f64::sqrt(x as f64) as u64 + 1;
    for i in 2..limit {
        if x % i == 0 {
            ret = false;
            break;
        }
    }
    ret
}

fn main() {

    let mut count = 0;
    from_line!(n: u64);
    for _ in 0..n {
        from_line!(num: u64);

        if isPrime(num) {
            count += 1;
        }
    }
    println!("{}", count);

}



Measured memory_bytes: 5048
/* ITP1_7_B */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();
      String str = "";

      while((str = br.readLine()).equals("0 0") == false){
        // input
        String[] input = str.split(" ");
        int n = Integer.parseInt(input[0]);
        int x = Integer.parseInt(input[1]);
        if(n < 3 || n > 100) return;

        int count = 0;
        // finish
        if(n == 0 && x == 0) break;
        // check
        for(int i = 1; i <= n; i++){
          for(int j = (i + 1); (i + j) < x; j++){
            int k = x - i - j;
            if(k > j && k <= n) count++;
          }
        }
        sb.append(count + "\n");
      }
      // output
      System.out.print(sb);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 24532
import java.util.*;
import java.io.*;

/*
   AtCoder contest code
   coder : yoichidon
 */

public class Main {
    public static String longer(String x, String y){
        if(x.length() > y.length()) return x;
        else return y;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] a = new long[N];
        for(int n=0; n<N; n++) a[n]=sc.nextLong();

        long[][] dp = new long[N+1][N+1];
        //dp[i][j] : taro's point with deque which starts with a_i and have j elms
        //a[i], a[i+1], ... +a[i+j-1]
        for(int i=0; i<=N; i++) dp[i][0]=0;
        for(int j=1;j<=N; j++) for(int i=0; i<N; i++) if(i+j<=N){
            dp[i][j] = Math.max(a[i+j-1] - dp[i][j-1],   a[i] - dp[i+1][j-1]);
        }

        System.out.println(dp[0][N]);

    }
}


Measured memory_bytes: 130052
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    int p = Integer.parseInt(sc.next());
    
    int ans = (a*3 + p) / 2;
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
from math import sqrt
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append( list( map(int, input().split()) ) )

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k]-X[j][k])**2
        dist = sqrt(dist)
        if dist % 1 == 0:
            cnt += 1
print(cnt)

Measured memory_bytes: 38384
#include<cstdio>
int main(void){int n,m,a[100],b,p[100]={0},i,j;scanf("%d%d",&n,&m);for(i=0;i<m;++i){scanf("%d",a+i);--a[i];}for(i=0;i<m;++i){for(j=0;j<n;++j){scanf("%d", &b);--b;if(b==a[i]){b=j;goto pp;}else{b=a[i];pp:++p[b];}}}for(i=0;i<n;++i){printf("%d\n",p[i]);}return(0);}


Measured memory_bytes: 2728
#include<bits/stdc++.h>
#define upd(a,b) a=add(a,b)
#define rdc(a,b) a=sub(a,b)
#define inv(x) power(x,Mod-2)
using namespace std;
typedef long long ll;
const int Mod=1e9+7;
int add(int a,const int b){a+=b;if(a>=Mod)a-=Mod;return a;}
int sub(int a,const int b){a-=b;if(a<0)a+=Mod;return a;}
int mul(const int a,const int b){return (ll)a*b%Mod;}
int power(int x,int cs)
{
	int ras=1;
	while(cs)
	{
		if(cs&1) ras=mul(ras,x);
		x=mul(x,x);cs>>=1;
	}
	return ras;
}
const int N=60;
int n,ans=0;
int dp[N][N],C[N][N];
int main()
{
	int i,j,x,y;
	scanf("%d",&n);
	for(i=0;i<=n;i++)
	{
		C[i][0]=1;
		for(j=1;j<=i;j++) C[i][j]=add(C[i-1][j-1],C[i-1][j]);
	}
	dp[1][0]=dp[1][1]=1;
	for(i=1;i<n;i++)
	{
		for(j=0;j<=i;j++)
		{
			for(x=j;i+x<=n;x+=2)
			{
				if(x==0) continue;
				for(y=0;y<=x;y++)
				{
					upd(dp[i+x][abs(y-((x+j)>>1))],mul(mul(C[i+x][x],C[x][y]),dp[i][j]));
				}
			}
		}
	}
	ans=dp[n][0];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define OUT(x) cout << x << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int n;
  cin >> n;
  bool add=false;//奇数が含まれるかどうか
  REP(i,n){
    int a;cin>>a;
    if(a%2==1) add=true;
  }
  if(add) cout << "first" << endl;
  else cout << "second" << endl;
}


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


size_t cur=0;
int mul[3][3]={{0,0,0},{0,1,1},{0,1,2}};
int add[3][3]={{0,1,2},{1,1,2},{2,2,2}};


int term(string S);
int expression(string S);

int logic(string S){
	int n = S[cur] - '0'; 
	cur++; 
	return n;
}


int factor(string S) {
	if (S[cur] == '('){
		cur++;
		int n = expression(S);
		assert(S[cur] == ')');
		cur++;
		return n;
	}else if(S[cur] == '-'){
		cur++;
		int n;
		/*if( S[cur] == '0' ||S[cur] == '1' ||S[cur] == '2')
			 n = logic(S);
		else */
			 n = factor(S);
		if(n==1)
			return n;
		else
			return abs(n-2);
	}else
		return logic(S);
}

int expression(string S){
	int sum = factor(S);
	while(S[cur] == '*' || S[cur] == '+'){
		char op = S[cur];
		cur += 1;
		int b = factor(S);
		if( op == '*')
			sum=mul[sum][b];
		else 
			sum=add[sum][b];
	}
	return sum;
}

void ReplaceStr(string& str, const string& from, const string& to)
{
  string::size_type pos = 0;

  while(pos = str.find(from, pos), pos != string::npos) {
    str.replace(pos, from.length( ), to);
    pos += to.length();
  }
}

int main(void){
	string S;
	while(cin >> S, S !="."){
	int num=0;
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<3;k++){
					cur=0;
					string I,J,K,T;
					I=i+'0';
					J=j+'0';
					K=k+'0';
					T=S;
					ReplaceStr( T,"P", I );
					ReplaceStr( T,"Q", J );
					ReplaceStr( T,"R", K );
					int r;
					r=expression(T);
					if(r==2)
						num++;
				}
			}
		}
	cout << num << endl;
	}
return 0;
}

Measured memory_bytes: 1200
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int X = 753;
    int sub = Integer.MAX_VALUE;
    for (int i = 0; i < S.length() - 2; i++) {
      int tmp = Integer.parseInt(S.substring(i, 3 + i));
      int tmpsub = Math.abs(X - tmp);
      if (sub > tmpsub) {
        sub = tmpsub;
      }
    }
    System.out.println(sub);
  }
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323
#define M           998244353


void solve()
{
      ll n, m;
      ll l=1,r=n;
      cin>>n>>m;
      rep(i,0,m)
      {
             ll a,b;
             cin>>a>>b;
             l=max(l,a);
             r=min(r,b);
      }
      ll ans = r-l+1;
      cout<<max(0LL,ans);
}


int main()
{
       speed_up;
       //pre();
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 256
a, b = map(int, input().split())
g = [['.']*100 for _ in range(100)]
for j in range(100):
    for i in range(50,100):
        g[i][j] = '#'
#print_dp(g)

b_cnt = 1
i = 0
j = 0
while b_cnt < b:
    g[i][j] = '#'
    j += 2
    if j >= 100:
        i += 2
        j = 0
    b_cnt += 1
a_cnt = 1
i = 99
j = 0
while a_cnt < a:
    g[i][j] = '.'
    j += 2
    if j >= 100:
        i -= 2
        j = 0
    a_cnt += 1
print("100 100")
for i in range(100):
    print("".join(g[i]))

Measured memory_bytes: 64080
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法
#define JUUHATI 1000000000000000000 
#define JUUHATIPLUS 1000000000000000001 

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int A,B,pla,minus,addd;
    cin >> A >> B;

    pla = A + B;
    minus = A - B;
    addd = A * B;

    if(pla >= minus and pla >= addd)
        cout << pla << endl;
    else if(minus >= pla and minus >= addd)
        cout << minus << endl;
    else if(addd >= pla and addd >= minus)
        cout << addd << endl;
    
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
char a[8][8],b[8][8];
long long n;
long long sum;
long long num;
int main(){
	cin>>n;
	rep(i,n){
		cin>>num;
		sum+=num;
	}
	cout<<sum/n<<endl;

}

Measured memory_bytes: 3088
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

H = int(input())
"""
100
50 50
25 25 25 25
12 * 8
6 * 16
3 * 32
1 * 64
ans = 1 + 2 + 4 + 8 + 16 + 32 + 64
"""
x = 1
for i in range(41):
    x *= 2
    if H < x:
        k = i
        break

anss = [1]
for i in range(41):
    anss.append(anss[-1] * 2 + 1)
print(anss[k])


Measured memory_bytes: 66924
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;

vector<long long int> inverse;
vector<long long int> f, f_inverse;

void factorial_Initialize(int max){
    vector<long long int> a(max+1,1);
    inverse = a;
    f = a;
    f_inverse = a;

    for (int i=2; i<=max; i++){
        inverse[i]   = MOD - inverse[MOD % i] * (MOD / i) % MOD;
        f[i]         = f[i-1]         * i          % MOD;
        f_inverse[i] = f_inverse[i-1] * inverse[i] % MOD;
    }
}

long long int nCr(int n, int r){
    if(n < r || r < 0) return 0;
    if (n >= f.size()){
        factorial_Initialize(n);
    }
    return f[n] * f_inverse[r] % MOD * f_inverse[n-r] % MOD;
}

long long int modpow(int b, int p){
    long long int num = 1, power = b;
    for(int i=0; i<=30; i++){
        if((p>>i) & 1) num *= power;

        num %= MOD;
        power *= power;
        power %= MOD;
    }
    return num;
}

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

    long long int ans = 0;
    for(int i=n-k; i<=n; i++){
        long long int add = (m * modpow(m-1, i-1) % MOD) * nCr(n-1, i-1) % MOD;

        ans += add;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9492
#include<stdio.h>

int main(){
	long long N,S=0,n;
	scanf("%lld",&N);
	n=N;
	while(n>0){
		S+=n%10;
		n/=10;
	}
	
	if(N%S==0)printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 128
x,k,d = map(int, input().split())

if abs(x) - k*d >= 0:
    print(abs(abs(x)-k*d))

else:
    y = abs(x)//d 
    if (k - y) % 2 ==0:
        print(abs(x)% d)
    else:
        print((y+1)*d-abs(x))	

Measured memory_bytes: 9204
n=int(input())
s=raw_input()

def solve(s,n):
    if "W" not in s or "R" not in s or s.find("WR")==-1:
        return 0

    else:
        arr=list(s)
        i=0
        j=n-1
        count=0

        while i<j:
            if arr[i]=="W" and arr[j]=="R":
                count += 1
                i+=1
                j-=1

            elif arr[i]=="W" and arr[j]=="W":
                j-=1
            elif arr[i]=="R" and arr[j]=="R":

                i+=1
            else:
                i+=1
                j-=1
        return count
print(solve(s,n))





Measured memory_bytes: 80728
#include<iostream>
#include<math.h>

using namespace std;

const long MIN = -1234567890;

long gcd(long n, long m) {
    if (n < m)swap(n, m);
    if (n == m || m == 0)return n;
    return gcd(m, n % m);
}

long pri(){
    long ans = 0;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int m;
        bool flag = false;
        cin >> m;
        for(int j = 2; j <= sqrt(m); j++){
            if(m % j == 0) {
                flag = true;
                break;
            }
        }
        if(!flag) ans++;
    }
    return ans;
}

long max_gap(){
    long n,m, ans = MIN, min;
    cin >> n;
    cin >> m;
    min = m;
    for(int i = 1; i < n; i++){
        cin >> m;
        if(ans < (m - min)) ans = (m - min);
        if(min > m)min = m;
    }
    return ans;
}

int main() {
    cout << max_gap() << endl;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MOD 1000000007

ll n,x;

ll b[55],p[55];

ll dfs(ll i,ll j){
  if(i == 0){
    if(j < 1) return 0;
    else return 1;
  }
  else if(j<=1) return 0;
  else if(1 < j && j <= 1 + b[i-1] + p[i-1]) return dfs(i-1,j-1);
  else if(j == b[i-1] + p[i-1] + 2) return p[i-1]+1;
  else if(b[i-1] + p[i-1] + 2< j && j <= b[i] + p[i] - 1) return dfs(i-1,j - (2 + b[i-1] + p[i-1])) + p[i-1] + 1;
  else if(b[i] + p[i] <= j) return p[i];

}

int main(){
  cin >> n >> x;
  b[0] = 0;
  p[0] = 1;
  for(int i = 1; i < 55; i++){
    b[i] = 2*b[i-1] + 2;
    p[i] = 2*p[i-1] + 1;
  }
  cout << dfs(n,x) <<endl;
  return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int c[3][3];
int a[3], b[3];
bool ok(int a) {
    return (0 <= a and a <= 100);
}

int main() {
    rep(i, 3) rep(j, 3) cin >> c[i][j];

    for (a[0]=0; a[0]<=c[0][0]; ++a[0]) {
        for (a[1]=0; a[1]<=c[1][1]; ++a[1]) {
            for (a[2]=0; a[2]<=c[2][2]; ++a[2]) {
                b[0] = c[0][0]-a[0];
                b[1] = c[1][1]-a[1];
                b[2] = c[2][2]-a[2];

                bool ok=true;
                rep(i, 3) rep(j, 3) {
                    if (a[i]+b[j] != c[i][j]) {
                        ok = false;
                        i=100; j=100;
                        break;
                    }
                }
                if (ok) {
                    cout << "Yes" << endl;
                    return 0;
                }

            }
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
cnt = 0

# 約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

for i in range(1, N+1, 2):
    if len(make_divisors(i)) == 8:
        cnt += 1

print(cnt)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}

int main(){
    ll x; scanf("%lld",&x);
    
    map<ll,ll> ck;
    for(ll i=-1000;i<=1000;i++) ck.insert({i*i*i*i*i,i});
    for(ll i=0;i<=1000;i++){
        auto p=ck.find(i*i*i*i*i-x);
        if(p!=ck.end()){
            printf("%lld %lld\n",i,p->second);
            break;
        }
    }
}

Measured memory_bytes: 3924
//We are still young.
// B.cpp
// Created on 2019-02-16 19:54
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;

#define MAXN 100100
#define MAXE 400400

typedef pair<int, int> pii;
#define X first
#define Y second
const int INF = 0x7FFFFFFF;
#define Debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> inline void read(T &x) {
    int ch = getchar();
    bool fg = false;
    for (x = 0; !isdigit(ch); ch = getchar()) {
        if (ch == '-') {
            fg = true;
        }
    }
    for (; isdigit(ch); ch = getchar()) {
        x = x * 10 + ch - '0';
    }
    if (fg) {
        x = -x;
    }
}

int n, m, a[MAXN];

int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
#endif
	read(n), read(m);
	for(int i = 1; i <= n; i++) {
		int x; read(x);
		for(int j = 1; j <= x; j++) {
			int y; read(y);
			a[y]++;
		}
	}
	int ans = 0;
	for(int i = 1; i <= m; i++) {
		if(a[i] == n) ans++;
	}
	cout << ans ;
#ifdef LOCAL
	Debug("My Time: %.3lfms", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int a = sc.nextInt();
      int b = sc.nextInt();
      long sum  = 0;

      for(int i = 1; i <= n; i++) {
        if(digitSum(i, a, b))
          sum += i;
      }
      System.out.println(sum);
  }

  private static boolean digitSum(int n, int a, int b) {
    int sum = 0;
    while(n > 0) {
      sum += n % 10;
      n /= 10;
      if(sum > b) return false;
    }

    return sum >= a;
  }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long D = long.Parse(str[1]);
		long ans = 0;
		long[,]A = new long[N,D];
		for(var i=0;i<N;i++){
			string[] str2 = Console.ReadLine().Split();
			for(var j=0;j<D;j++){
				A[i,j] = long.Parse(str2[j]);
			}
		}
		for(var i=0;i<N;i++){
			for(var j=i+1;j<N;j++){
				long a = 0;
				for(var k=0;k<D;k++){
					a += (A[i,k]-A[j,k])*(A[i,k]-A[j,k]);
				}
				long b = (long)Math.Pow(a,0.5);
				if(b*b==a){
					ans++;
				}
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()



int main(){
  ll N,K;
  cin >> N >> K;
  vec A(1e5,0);
  rep(i,N){
    ll a,b;
    cin >> a >> b;
    A.at(a-1)+=b;
  }
  ll k=0;
  rep(i,1e5){
    k+=A.at(i);
    if(k>=K){
      cout << i+1 << endl;
      return 0;
    }
  }
}
      

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

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(3e6))
UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
        # undirected graph
        init_adj_table[v_to].append(v_from)
    return init_adj_table


def graph_dfs(current, prev):
    global timer
    pre_v[current] = lowest_v[current] = timer
    timer += 1

    color[current] = VISITED_IN_STACK
    for adj in adj_table[current]:
        if color[adj] is UNVISITED:
            parent_v[adj] = current
            # recursive dfs
            graph_dfs(adj, current)
            lowest_v[current] = min(lowest_v[current], lowest_v[adj])
        elif adj is not prev:
            lowest_v[current] = min(lowest_v[current], pre_v[adj])

    return None


def art_points():
    graph_dfs(dfs_root, -1)

    np = 0
    for v in range(1, vertices):
        parent = parent_v[v]
        if parent is dfs_root:
            np += 1
        elif pre_v[parent] <= lowest_v[v]:
            art_set.add(parent)

    if np > 1:
        art_set.add(dfs_root)

    return art_set


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])
    pre_v, parent_v, lowest_v = ([float('inf')] * vertices for _ in range(3))
    init_adj_table = tuple([] for _ in range(vertices))

    timer = 0
    # root
    dfs_root = 0

    art_set = set()
    color = [UNVISITED] * vertices

    adj_table = generate_adj_table(v_info)

    res = art_points()
    # print('parent', parent_v, 'preorder', pre_v, 'postorder', lowest_v)
    if res:
        print(*sorted(res), sep='\n')

Measured memory_bytes: 23608
N=int(input())
Stot=0.5*N*(N+1)

S3=0.5*(N//3)*(3+3*(N//3))
S5=0.5*(N//5)*(5+5*(N//5))
S15=0.5*(N//15)*(15+15*(N//15))
print(int(Stot-S3-S5+S15))

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

vec<vll> dp;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(30);

    int n,weight; cin >> n >> weight;
    vi w(n), v(n); rep(i,n) cin >> w[i] >> v[i];
    dp.resize(n+1, vll(100001, infll));
    dp[0][0] = 0;  // 初期化の後は初期条件の決定

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= 100000; ++j) {
            if(j-v[i] >= 0) chmin(dp[i+1][j], dp[i][j-v[i]] + w[i]);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    int ans;
    for(int j = 100000; j >= 0; --j) {
        if(dp[n][j] <= weight) {
            ans = j;
            break;
        }
    }
    cout << ans << '\n';

    // 復元
    // int i = n-1;
    // int j = ans;
    // while(i>=0&&j>=0) {
    //     if(j-v[i] >= 0 && dp[i+1][j] == dp[i][j-v[i]]+w[i]) {
    //         cout << i+1 << '\n';
    //         j = j-v[i];  // ここ先に--iやってミスったので注意
    //         --i;
    //     }
    //     else --i;
    // }
}

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

int main(){
  int l,n;
  cin >> n >> l;
  vector<string> s(n);
  for(int i = 0; i < n; i++){
    cin >> s[i];
  }
  sort(s.begin(),s.end());
  for(int i = 0; i < n; i++){
    cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <sstream>
#include <set>
#include <algorithm>

using namespace std;

set<string> st;

string getStr(int n)
{
  ostringstream ss;
  ss << n;
  return ss.str();
}

void func(int a[11], int n, string str, int k, bool b[11], int p)
{
  if(k == p){
    st.insert(str);
    return ;
  }

  for(int i = 0; i < n; i++){
    if(b[i]){
      b[i] = false;
      func(a, n, str+getStr(a[i]), k, b, p+1);
      b[i] = true;
    }
  }

  return ;
}

int main()
{
  int n, m, a[11];
  bool b[11];

  while(cin>>n && n){
    cin >> m;

    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    fill(b, b+11, true);
    func(a, n, "", m, b, 0);

    cout << st.size() << endl;
    st.clear();
  }

  return 0;
}

Measured memory_bytes: 1048
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  a, b, c = map(int, readline().split())
  print(a*b//2)
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5372