akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Pg
{
    static void Main()
    {
        Prime p = new Prime();
        List<bool> Pmlst = p.GetPrimeNums().ToList();
        int n;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            int count = 0;
            for (int i = 2; i <= n / 2; ++i)
            {
                if (Pmlst[i] && Pmlst[n - i])
                {
                    ++count;
                }
            }
            Console.WriteLine(count);
        }
    }
}
class Prime
{
    const int MAX = 50000;
    internal IEnumerable<bool> GetPrimeNums()
    {
        for (int i = 0; i <= MAX; ++i)
        {
            if (IsPrime(i))
                yield return true;
            else
                yield return false;
        }
    }
    private bool IsPrime(int num)
    {
        if (num < 2)
            return false;
        else if (num == 2)
            return true;
        else if (num % 2 == 0)
            return false;

        for (int i = 3; i <= Math.Sqrt(num); i += 2)
        {
            if (num % i == 0)
                return false;
        }
        return true;
    }
}


Measured memory_bytes: 16184
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int main(void){
	while(1){
		int n, m; cin >> n >> m;
		if(n == 0 && m == 0) return 0;
		vector<int> p(n);
		rep(i, n) cin >> p[i];
		p.push_back(0);//??¢????????????????????\??????
		vector<int> pp((n + 1) * (n + 1));
		int cnt = 0;
		rep(i, n + 1)rep(j, n + 1){
			pp[cnt] = p[i] + p[j];
			cnt++;
		}
	
		sort(pp.begin(), pp.end());
		int ans = 0;
		//?¨???????(n^2*log(n*n))
		rep(i, (n + 1) * (n + 1)){
			int tmp = pp[i];
			int aim = m - tmp;
			if(aim < 0) continue;
			tmp += *(upper_bound(pp.begin(), pp.end(), aim) - 1);
			if(tmp <= m) ans = max(ans, tmp);
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 5380
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int cnt500 = int.Parse(Console.ReadLine());
        int cnt100 = int.Parse(Console.ReadLine());
        int cnt50 = int.Parse(Console.ReadLine());
        int sum = int.Parse(Console.ReadLine());
        
        var sums = Enumerable.Range(0, cnt500 + 1).SelectMany(a =>
            Enumerable.Range(0, cnt100 + 1).SelectMany(b =>
                Enumerable.Range(0, cnt50 + 1).Select(c =>
                    a * 500 + b * 100 + c * 50
                )
            )
        );

        int output = sums.Count(x => x == sum);
        Console.WriteLine(output);
    }
}

Measured memory_bytes: 11348
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const int MAX = 1000000;
const int MOD = 1000000007;

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

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

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


int main(){
  int N; cin >> N; int tmp; vector<int> cnt[N];
  rep(i, N+1){
    int a; cin >> a; a--; cnt[a].push_back(i+1);
    if(cnt[a].size()==2){tmp=a; break;}
  }
  tmp = N - abs(cnt[tmp][0] - cnt[tmp][1]);
  COMinit();
  rep(i, N+1){
    int ans;
    if(i==0) ans = N;
    else ans = (COM(N+1, i+1) - COM(tmp, i));
    if(ans<0) ans+=mod;
    cout << ans << endl;
  }
}

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

using namespace std;


int main() {
    int n , s ; cin  >> n >> s;
    int ans = 0;
    for(int i = 0; i <=n; ++i){
        for(int j = 0; j  <= n; ++j){
            if(s - (i + j) >= 0 && s - (i + j) <= n)ans++;
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3560
while gets
  str, arr = $_.chomp, [*"a".."z"]
  
  until /the|this|that/ =~ str
    i = 0
    
    str.each_char do |c|
      str[i] = arr[(arr.index(c) + 1) % 26] if /\w/ =~ c
      i += 1
    end
  end
  
  puts str
end

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

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



Measured memory_bytes: 3124
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.trim().split(/ |\n/), cid = 0;

function main() {
    let N = +cin.shift().slice(-1);
    switch (N) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            console.log("hon");
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            console.log("pon");
            break;
        default:
            console.log("bon");
    }
}
main();

Measured memory_bytes: 29656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n,X;cin>>n>>X;
    vin x(n);
    rep(i,n)cin>>x[i];
    rep(i,n)x[i]=abs(x[i]-X);
    rep(i,n-1)x[i+1]=__gcd(x[i],x[i+1]);
    cout<<x[n-1]<<endl;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++){
        cin >> s[i];
    }
    for (int i = 0; i < h; i++){
        cout << s[i] << endl;
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
   int n, i, j;
   int a[100001] = {};
   int mon, m1, m2, m3;
   mon = 0;
   a[0] = 0;

   scanf("%d",&n);

   a[n+1] = 0;

   for(i=1;i<=n;i++){
      scanf("%d",&a[i]);
   }

   for(i=0;i<=n;i++){                                                
      mon += abs(a[i+1]-a[i]);
   }

   for(i=0;i<n;i++){
      m1 = abs(a[i+1]-a[i]);
      m2 = abs(a[i+2]-a[i+1]);
      m3 = abs(a[i+2]-a[i]);

      printf("%d\n",mon-m1-m2+m3);
   }

   return 0;
}


Measured memory_bytes: 1536
#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()
{
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    vector<pair<char, ll>> h ={ { 'M', 0 }, { 'A', 0 }, { 'R', 0 }, { 'C', 0 }, { 'H', 0 } };
    set<string> ss;
    rep(i, n) {
        rep(j, h.size()) {
            if (s[i][0] == h[j].first && !ss.count(s[i])) {
                h[j].second++;
                ss.insert(s[i]);
            }
        }
    }
    ll ans = 0;
    for (ll i = 0; i <= 4; i++) {
        for (ll j = i+1; j <= 4; j++) {
            for (ll k = j+1; k <= 4; k++) {
                ans += h[i].second * h[j].second * h[k].second;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13876
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> digits(n);
	for (int i = 0; i < n; i++) cin >> digits[i];

	int cnt = 0;
	bool has_even = false;
	while (true) {
		for (int i = 0; i < n; i++) {
			if (digits[i] % 2 == 0) {
				digits[i] = digits[i] / 2;
			} else {
				has_even = true;
				break;
			}
		}

		if (has_even) break;
		cnt++;
	}

	cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef  unsigned long long ULL;
typedef  double db;
typedef  long double ld;
#pragma comment(linker, "/STACK:102400000,102400000")
#define fuck(x) cout<<x<<endl
#define fuck1(x,y) cout<<x<<" "<<y<<endl
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define MP(a,b) make_pair(a,b)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
const int INF = 0x3f3f3f3f3f,mod = 1e9+7;
const double eps  =1e-6,PI = acos(-1);
template<typename T> inline void read(T &x){
    x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
const int maxn =1e5+100;
int N,ax[maxn];
priority_queue<double,vector<double>,greater<double> > ac;
int main(){
    read(N);
    double ans = 0;
    for(int i = 1;i<=N;i++){
        read(ax[i]);
        ans+=1.0/ax[i];
    }
    ans = 1.0/ans;
    cout<<setprecision(10)<<fixed<<ans<<endl;

    return 0;
}
/*
abc
abc
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////



int main(){fastio
    
    ll a,b,k;cin>>a>>b>>k;
    ll c=min(a,k);
    a-=c;
    k-=c;
    c=min(b,k);
    b-=c;
    k-=c;
    cout<<a<<" "<<b<<endl;
    
    
    return 0;
}


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

int main(){
	/*input*/
	int n, l;	cin >> n >> l;
	/*calculation*/
	int aji = 0;
	for(int i = 1; i <= n; i++){
		if(l > 0){
			if(i == 1) continue;
			aji += l + i - 1;
		}else if(l + n - 1 < 0){
			if(i == n) continue;
			aji += l + i - 1;
		}else{ 
			aji += l + i - 1;
		}
	}
	/*output*/
	cout << aji << endl;
}


Measured memory_bytes: 256
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_6_A&lang=jp
#  Binary Search : python3
#  2018.11.26 yonezawa

import sys
input = sys.stdin.readline

def main():
    n = int(input())
    l = list(map(int,input().split()))

    for i in range(int(input())):
        max = n -1
        min = 0
        mid = max // 2
        d = int(input())
        while True:
            if (l[mid] > d ):
                max = mid
            elif (l[mid] == d ):
                print ("1")
                break
            else:
                min = mid
            mid =  (max + min ) // 2 
            if ( mid == max or mid == min ):
                if ( l[mid] == d or l[max] == d):
                    print ("1")
                    break
                #print ("debug:",min,mid,max,l[mid])
                print ("0")
                break

if __name__ == '__main__':
    main()


Measured memory_bytes: 16852
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> h(n);
    for(int i = 0; i < n; i++){
        std::cin >> h[i];
    }
    int maxh = h[0];
    int cnt = 1;
    for(int i = 1; i < n; i++){
        if(maxh <= h[i]){
            cnt++;
            maxh = h[i];
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 256
/******************************************
* AUTHOR : GEEOTHERMAL/CODEFORCES
  USED BY : Shivam Jalotra
  COLLEGE : Nit Kurukshetra
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	// Create a mutimap that stores the dish-number and then B(i) and C(i) respectively 
	// Then go through that map and if key+1 just comes after key 
	// Add the value of ci to the sum 
	//Else  just add the value of Bi to the map 

	// But since I don't know maps right now
	// Lets do it with vector

	// Take in inputs
	int N;
    cin >> N;
	vector<int>A(N);vector<int> B(N); vector<int>C(N-1); 
	
	
	int number;
	for(int i=0 ; i < N; i++){
		cin >> number;
		A[i] = number;
	}
	for(int i=0 ; i < N; i++){
		cin >>number;
		B[i] = number;
	}
	for(int i=0 ; i < N-1; i++){
		cin >> number;
		C[i] = number;
	}


	// Main Algorithm starts
	int sum = 0;
	for(int i = 0; i < N ; i++){
		sum += B[A[i]-1];
		if(A[i] == A[i-1] + 1){
			sum += C[A[i-1]-1];
		
			// cout << sum << endl;
		}
		

	}

	cout << sum; 

	return 0;
}

Measured memory_bytes: 256
program tautonym_puzzle
  implicit none
  integer(8) :: n
  integer :: k = 0, l = 1, i
  integer, allocatable :: p(:)
  read(*,*) n
  n = n+1_8
  do while (rshift(n,k) > 0_8)
    k = k+1
  end do
  k = k-2
  p = [integer::]
  do i = k, 0, -1
    p = [p,l]
    l = l+1
    if (btest(n,i)) then
      p = [l,p]
      l = l+1
    end if
  end do
  write(*,'(i0)') 2*(l-1)
  write(*,'(i0)',advance='no') 1
  do i = 2, l-1
    write(*,'(x,i0)',advance='no') i
  end do
  do i = 1, l-1
    write(*,'(x,i0)',advance='no') p(i)
  end do
  write(*,*)
end program tautonym_puzzle

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,T;
  double A;
  cin >> N;
  cin >> T >> A;
  
  double df = 100000 * 0.006;
  int ans;
  for(int i=0; i<N; i++) {
    int h;
    cin >> h;
    double c = T - h * 0.006;
    c = max( A, c ) - min( A, c);
    if(df > c ) {
      df = c;
      ans = i + 1;
    }
  }

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

Measured memory_bytes: 256
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;



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

	char a = s[k - 1];

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != a) {
			s[i] = '*';
		}

	}
	
	cout << s << endl;
	return 0;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, S: "List[str]"):
    ret = 1
    status = 0
    i = 0
    while i < N:
        #print(i, status, ret)
        if status == 1:
            ret *= 2
        if S[0][i] == S[1][i]:
            if status == 0:
                ret *= 3
            status = 1
        else:
            if status == 0:
                ret *= 3 * 2
            elif status == 2:
                ret *= 3
            status = 2
            i += 1
        i += 1
        ret %= MOD
    ret %= MOD
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(2) ]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;
const int MAX = 2000005;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

long long inverse[MAX+1];
long long factorial[MAX+1];
long long factorial_inverse[MAX+1];

void calc(int n) {
	inverse[1] = 1;
	factorial[0] = factorial[1] = 1;
	factorial_inverse[0] = factorial_inverse[1] = 1;
	for (int i = 2; i <= n; i++) {
		inverse[i] = MOD - inverse[MOD%i] * (MOD/i) % MOD;
		factorial[i] = i * factorial[i-1] % MOD;
		factorial_inverse[i] = inverse[i] * factorial_inverse[i-1] % MOD;
	}
}

long long comb(long long n, long long k) {
	return factorial[n] * (factorial_inverse[k] * factorial_inverse[n-k] % MOD) % MOD;
}

long long f(long long r, long long c) {
	return mod(comb(r+c+2, r+1) - 1);
}

int main() {
	calc(MAX);
	long long r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	long long ans = mod(f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 50068
#include <stdio.h>

int main(void)
{
	int n;
	scanf("%d",&n);
	if(n<=111)printf("111\n");
	else if(n<=222)printf("222\n");
	else if(n<=333)printf("333\n");
	else if(n<=444)printf("444\n");
	else if(n<=555)printf("555\n");
	else if(n<=666)printf("666\n");
	else if(n<=777)printf("777\n");
	else if(n<=888)printf("888\n");
	else if(n<=999)printf("999\n");
	return 0;
}



Measured memory_bytes: 128
/**
 *    @author: yuhongtao
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<sstream>
using namespace std;
#define pi acos(-1.0) 
#define ms(x,n) memset(x,n,sizeof(x));
#define pb push_back
#define fi first
#define se second
const int mod=1e9+7;
typedef long long ll;//string::npos
typedef long long iint;
long long gcd(ll a,ll b){ return a%b==0?b:gcd(b,a%b);}
long long quick_pow(ll x,ll r){
    long long ans=1;
    while(r){
        if(r&1) ans=ans*x;//%mod
        x=x*x; r>>=1;
    }
    return ans;
}
inline long long read(){
	long long s=0,w=1;
	char ch=getchar();
	while(ch<48||ch>57){
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(ch>=48&&ch<=57){
		s=(s<<1)+(s<<3)+(ch^48);
		ch=getchar();
	}
	return s*w;
}
const int inf=2147483647;
const int maxn=1e6+5;//greater<ll>
//priority_queue<ll,vector<ll>,less<ll> > q;
//vector<string> vt;
//pair<int,int> p;
//set<int> s;
//map<char,int> m;
int main(){
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	cout<<a*b<<endl;





	getchar();
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using pii = pair<int,int>;
#define ALL(x) (x).begin(),(x).end()

int main(){
	string N;
	cin >> N;
	bool flag = false;
	for(int i=0;i<N.size();i++)
		if(N[i] == '7')
			flag = true;
	cout << (flag ? "Yes" : "No") << endl;
}

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

const int mxn = 100005;
int n, a[mxn][4];
int ff[mxn][4];

int dfs( int r, int c ) 
{
  if( r == 0 ) return 0;
  int& ret = ff[r][c];
  if( ~ret ) return ret;

  ret = 0;
  for(int i = 1; i <= 3; i++) 
  {
    if( i == c ) continue;
    ret = max(ret, a[r][c] + dfs( r - 1, i ));
  } 
  return ret;
}

int main() 
{
  scanf("%d", &n);
  for(int i = 1; i <= n; i++) 
  {
    scanf("%d %d %d", &a[i][1], &a[i][2], &a[i][3]);
  }
  memset(ff, -1, sizeof ff);
  printf("%d\n", max(dfs( n, 3 ), max(dfs( n, 2 ), dfs( n, 1 ))));
  return 0;
}

Measured memory_bytes: 11136
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data',function(chunk){

var inputs = chunk.toString().trim();
    var data = inputs.split(' ').map(Number);
    var a = data[0];
    var b = data[1];
    var c = data[2];
    var count = 0;
    for (var i = a; i < b + 1; i++){
        if (c % i === 0){
            count ++;
        }
}
    console.log(count);
});

Measured memory_bytes: 15592
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double h,w;
	cin>>h>>w;
	if(h==1 || w==1){
		cout<<1<<endl;
	}else{
		cout<<fixed<<setprecision(0)<<ceil((h*w)/2)<<endl;
	}
	return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

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

const ll maxf = 10000000;
ll fact[maxf+5];
ll ifact[maxf+5];

void fact_init(){
  fact[0] = 1;
  for(ll i=1; i<=maxf; i++) fact[i] = (fact[i-1] * i) % MOD;
  ifact[maxf]=modpow(fact[maxf],MOD-2);
  for(ll i=maxf; i>=1; i--) ifact[i-1] = (ifact[i] * i) % MOD;
}

ll comb(ll n, ll r){
  if(n<r || n<0 || r<0) return 0;
  if(fact[0] == 0) fact_init();
  return ((fact[n] * ifact[n-r]) % MOD * ifact[r]) % MOD;
}

ll naive_comb(ll n, ll r){
  ll res = 1;
  for (ll i = n; i > n - r; i--) res = res * i % MOD;
  for (ll i = 1; i <= r; i++) res = (res * modpow(i, MOD-2)) % MOD;
  return res;
}


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll k; string s; cin>>k>>s;
  ll n=s.size();
  
  ll a=1;
  ll b=modpow(26,k);
  
  ll mo=modpow(26,MOD-2);
  
  ll ans=0;
  // i: n+kの中において、s[n-1]を置く位置
  irep(i,n-1,n+k){
    ans+=a*b%MOD*comb(i,n-1)%MOD;
    ans%=MOD;
    (a*=25)%=MOD;
    (b*=mo)%=MOD;
  }
  cout<<ans<<endl;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5 + 9, M = 1e6 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


#define neig(a, u, e, v) for(int v, e = (a).head[u] ; ~e and (v = (a).to[e], 1) ; e = (a).nxt[e])

struct Adj {
	int head[N], nxt[M], to[M], ne, n;
	void init(int n) {
		memset(head, -1, n * sizeof(head[0]));
		ne = 0;
		this->n = n;
	}
	void addEdge(int f, int t) {
		nxt[ne] = head[f];
		to[ne] = t;
		head[f] = ne++;
	}
	void addBiEdge(int f, int t) {
		addEdge(f, t);
		addEdge(t, f);
	}
	int addNode() {
		head[++n] = 0;
		return n;
	}
} adj;



int dp[N];

int dfs(int u){
    int &ret = dp[u];
    if(~ret)    return dp[u];

    ret = 0;
    neig(adj, u, e, v)
        ret = max(ret, dfs(v));

    ret++;

    return ret;
}


int n, m, u, v;

void go(int tc){
    cin >> n >> m;
    adj.init(n);
    for(int i = 0;i < m;i++){
        cin >> u >> v;  u--, v--;
        adj.addEdge(u, v);
    }

    memset(dp, -1, sizeof dp);

    int ans = 0;
    for(int i = 0;i < n;i++)
        ans = max(ans, dfs(i));

    cout << ans - 1;
}

int main(){
    init();

    int t, tc = 1;  t = 1;//cin >> t;
    while(t--)  go(tc++);

}


Measured memory_bytes: 4864
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	ans := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		for a%2 == 0 && a > 1 {
			ans++
			a /= 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;

int main() 
{
  int a[5], k, count = 0;
  for (int i = 0; i < 5; i++)
  cin >> a[i];
  cin >> k;
  for (int i = 0; i < 5; i++)
  {
    for (int j = i + 1; j < 5; j++)
    {
    if (abs(a[j] - a[i]) > k)
      count++;
    }
  }
  if (count == 0)
    cout << "Yay!" << endl;
  else 
    cout << ":(" << endl;
  return 0;
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 300111;
int fact[N], ofact[N];

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


int main() {
    ios::sync_with_stdio(false);

    int n;
    ll a, b;
    ll k;
    cin >> n >> a >> b >> k;

    fact[0] = 1;
    for (int i = 1; i < N; ++i)
        fact[i] = (1LL*i*fact[i-1]) % MOD;
    ofact[N-1] = pw(fact[N-1], MOD-2);
    for (int i = N-2; i >= 0; --i)
        ofact[i] = (1LL*ofact[i+1]*(i+1)) % MOD;

    int ans = 0;
    for (int x = 0; x <= n; ++x) {
        ll k1 = k - x*a;
        if (k1 % b == 0) {
            ll y = k1 / b;
            if (y > n || y < 0)
                continue;
            ll w = 1;
            (w *= fact[n]) %= MOD;
            (w *= ofact[x]) %= MOD;
            (w *= ofact[n-x]) %= MOD;
            (w *= fact[n]) %= MOD;
            (w *= ofact[y]) %= MOD;
            (w *= ofact[n-y]) %= MOD;
            ans = (ans + w) % MOD;
        }
    }
    cout << ans << "\n";

    return 0;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

const int MAX = 510000;
const int MOD = 1000000007;

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

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

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

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit();
    int H, W, A, B; cin >> H >> W >> A >> B;
    ll ans = 0;
    //(1,1)から(H,W)
    //(H+1-A,1),(H+1-A, B),(H, B),(H, 1)の四角には行けない
    //(H-A, B+1)から下に行く + (H-A, B+2)から下に行く + ... + (H-A, W)から下に行くの和が答え
    //COM(H-A-1 + B+k, B+k)*COM(A-1 + ((W-1)-(B+k)),A-1)
    for(int k = 0; B+k < W; k++){
        //B+k回右に行く
        ll acc = 1;
        acc = acc * COM(H-A-1 + B+k, B+k) % MOD;
        acc = acc * COM(A-1 + W-1 - (B+k), A-1) % MOD;
        ans = (ans + acc) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12160
#include<stdio.h>

using namespace std;

int main(){
  int A, B, C, X;
  scanf("%d\n%d\n%d\n%d", &A, &B, &C, &X);
  int cnt = 0;
  for(int i = 0; i <= A; i++){
    int value = 500*i;
    if(value > X){
      value = 0;
      continue;
    }
    for(int j = 0; j <= B; j++){
      value = 500*i + 100*j;
      if(value > X){
        value = 0;
        continue;
      }
      for(int k = 0; k <= C; k++){
        value = 500*i + 100*j + 50*k;
        if(value == X){
          value = 0;
          cnt++;
          continue;
        }
      }
    }
  }
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;

int main()
{
    unordered_map<string, int> um;
    int N;
    cin >> N;
    vs S(N);
    string tmp;
    rep(i, 0, N) {
        cin >> tmp;
        if (um.find(tmp) != um.end()) {
            um[tmp] += 1;
        } else {
            um[tmp] = 0;
        }
    }
    cout << um.size() << endl;
}

Measured memory_bytes: 24044
//
// Created by 李青坪 on 2018/12/13.
//

#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#define MAXN 50000
#define MAXM 20
#define NIL -1
#define INFINITY 1<<30
using namespace std;

int n, m;
int coin[MAXM+1];
int cnt[MAXM+1][MAXN+1];

int leastCoinDP(){
    for (int i = 0; i <= m; ++i) {
        fill(cnt[i], cnt[i]+n+1, INFINITY);
    }
    cnt[0][0] = 0;
    for (int i = 1; i <= m; ++i) {
        cnt[i][0] = 0;
        for (int j = coin[i]; j <= n; ++j) {
            if (coin[i] == n) {
                return 1;
            }
            cnt[i][j] = min(cnt[i-1][j], cnt[i][j-coin[i]]+1);
        }
        //所有小于coin[i+1]面值的j都用不上coin[i+1]，故这些j的值都等于使用coin[i]计算的最小硬币枚数
        for (int j = 1; j < coin[i+1]; ++j) {
            cnt[i+1][j] = cnt[i][j];
        }
    }
    int minC = INFINITY;
    for (int i = 1; i <= m; ++i) {
        minC = min(minC, cnt[i][n]);
    }
    return minC;
//    return cnt[m][n];
}

int main(){
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; ++i) {
        scanf("%d", &coin[i]);
    }
    printf("%d\n", leastCoinDP());
}


Measured memory_bytes: 6860
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
#define MAXN 300100
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
int32_t main(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(n*a,b)<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                        
#define pb push_back                            
#define mp make_pair                            
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)((x).size())
#define jonathan ios_base::sync_with_stdio(0)
#define livingston cin.tie(0)
using namespace std;                            
                                                
void yes() {cout << "Yes" << endl;}                                               
void no() {cout << "No" << endl;}                                                        
                                                
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};         
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; 

const int INF = 1e9 + 9;
const long long LINF = 1e18 + 8;
const double EPS = 1e-9;
const long long MOD = 1e9 + 7; //998244353
const double PI = acos(-1);

void solve() {
    int n, m; cin >> n >> m;
    char c[n + 1][m + 1];
    for (int i = n; i >= 1; i--) {
        for (int j = 1; j <= m; j++) {
            cin >> c[i][j];
        }
    }
    long long res = 0;
    for (int column = 1; column < m; column++) {
        vector<vector<int> > precalc(n + 2, vector<int>(n + 2));
        vector<vector<int> > dp(n + 2, vector<int>(n + 2));
        for (int f = n; f > 0; f--) {
            for (int s = n; s > 0; s--) {
                if (c[f][column] == c[s][column + 1]) {
                    precalc[n - f + 1][n - s + 1]++;
                    int mn = min(f, s);
                    precalc[n - (f - mn) + 1][n - (s - mn) + 1]--; 
                }
            }
        }
        for (int f = 1; f <= n; f++) {
            for (int s = 1; s <= n; s++) {
                precalc[f][s] += precalc[f - 1][s - 1];
            }
        }
        for (int a = n; a >= 0; a--) {
            for (int b = n; b >= 0; b--) {
                if (a == n and b == n) continue;
                if (a == n) {
                    dp[a][b] = dp[a][b + 1] + precalc[a][b + 1];
                } else if (b == n) {
                    dp[a][b] = dp[a + 1][b] + precalc[a + 1][b];
                } else {
                    dp[a][b] = min(dp[a + 1][b] + precalc[a + 1][b], dp[a][b + 1] + precalc[a][b + 1]);
                }
            }
        }
        res += dp[0][0];
    }
    cout << res << endl;
}

int main() {
    jonathan; 
    livingston;
    solve();
    return 0;
}

Measured memory_bytes: 4092
import java.util.*;

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

        int N = sc.nextInt();
        int[] A = new int[N - 1];
        int[] B = new int[N];



        for(int i=0; i<N-1; i++){
            A[i] = sc.nextInt();
            B[i] = 0;
        }
        B[N - 1] = 0;

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

        for(int i=0; i<N; i++){
            System.out.println(B[i]);
        }
    }
}

Measured memory_bytes: 63084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
 
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    n--;
    ll ans = (n*(n+1))/2;
    cout << ans << endl;


 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll s;
    cin >> s;
    vector<ll>ans(2010,0);
    ans[3]=ans[4]=ans[5]=1;
    for(ll i=6;i<2010;i++){
        ans[i]=ans[i-1]+ans[i-3];
        ans[i]%=MOD;
    }
    cout << ans[s] << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> data(N);
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  vector<bool> keep(data.at(N - 1), false);
  int ans = 0;
  set<int> multi;
  for(int i = 0; i < N; i++) {
    if(multi.count(data.at(i))) {
      ans--;
      multi.erase(data.at(i));
    }
    else if(!keep.at(data.at(i) - 1)) {
      ans++;
      multi.insert(data.at(i));
      for(int j = 1; j * data.at(i) <= data.at(N - 1); j++) {
        keep.at(j * data.at(i) - 1) = true;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
	int n;cin>>n;
	int x[n];
	vector<int> x2(n);
	for(int i=0;i<n;i++){
		cin>>x[i];
		x2[i]=x[i];
	}
	sort(x2.begin(),x2.end());
	int middle1=x2[n/2-1];
	int middle2=x2[n/2];
	for(int i=0;i<n;i++){
		if(x[i]<=middle1){
			cout<<middle2<<endl;
		}else{
			cout<<middle1<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n;
signed main() {
	cin >> n;
	map<string, int>mp;
	rep(i, n) {
		string s; cin >> s;
		sort(all(s));
		mp[s]++;
	}
	int ans = 0;
	for (auto i : mp) {
		ans += i.second * (i.second - 1) / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int k, a, b;
	cin >> k >> a >> b;

	if (a >= b) {
		cout << k + 1 << "\n";
	} else {
		long long max_biscuits = 1;
		int ops = min(k, a - 1);
		max_biscuits += ops;
		k -= ops;
		if (b - a == 1) {
			max_biscuits += k;
		} else {
			max_biscuits += (long long) (k / 2) * (b - a);
			if (k & 1) {
				++max_biscuits;
			}
		}

		cout << max_biscuits << "\n";
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int H, W; cin >> H >> W;
    rep (i, 0, H) {
        string in; cin >> in;
        rep (j, 0, 2) {
            cout << in << endl;
        }
    }
}

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

using namespace std;

const int N = 18;
const long long inf = 2e18;

map<pair<int, int>, long long> dp[N][N];
int a[N];

long long rec(int l, int r, pair<int, int> c) {
  if (l+1 == r)
    return 0;
  auto it = dp[l][r].find(c);
  if (it != dp[l][r].end())
    return it->second;
  int cl = c.first, cr = c.second, sum = cl + cr;
  long long ret = inf;
  for (int i = l+1; i < r; ++i) {
    ret = min(ret, rec(l, i, make_pair(cl, sum)) + rec(i, r, make_pair(sum, cr)) + 1LL * a[i] * sum);
  }
  return dp[l][r][c] = ret;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d", a+i);
  printf("%lld\n", rec(0, n-1, make_pair(1, 1)) + a[0] + a[n-1]);
  return 0;
}


Measured memory_bytes: 16640
package main

import (
  "fmt"
)

func main() {
  var N, W int
  fmt.Scanf("%d %d\n", &N, &W)
  w, v := make([]int, N), make([]int, N)
  for i:=0;i<N;i++ {
    fmt.Scanf("%d %d\n", &w[i], &v[i])
  }
  fmt.Println(solve(N, W, w, v))
}

// dp[i][c] = max(dp[i-1][c], dp[i-1][c-w[i]]+v[i])
// 特别注意容易不足的情况的处理
func solve(n, C int, w, v []int) int {
  dp := make([][]int, n+1)
  for i:=range dp {
    dp[i] = make([]int, C+1)
  }
  for i:=1;i<=n;i++ {
    for c:=0;c<=C;c++ {
      if c-w[i-1]>=0 {
        dp[i][c] = max(dp[i-1][c], dp[i-1][c-w[i-1]]+v[i-1])
      } else {
        dp[i][c] = dp[i-1][c]
      }
    }
  }
  return dp[n][C]
}

func max(a, b int) int {
  if a > b {
    return a
  }
  return b
}

Measured memory_bytes: 81792
from itertools import accumulate
from collections import deque
from collections import defaultdict

def func(x):
    return x - 1

def main():
    N, K = map(int, input().split())
    A = list(map(func, map(int, input().split())))
    B = [0] + list(accumulate(A))
    for i in range(N+1):
        B[i] %= K

    Q = deque()
    d = defaultdict(int)
    ans = 0
    for i in range(N+1):
        ans += d[B[i]]
        d[B[i]] += 1
        Q.append(B[i])
        if len(Q) == K:
            a = Q.popleft()
            d[a] -= 1

    print(ans)


    


if __name__ == "__main__":
    main()

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll n,m;
int main()
{
    ll x;
    sfl(x);
    for(ll i=-1000;i<=1000;i++)
    {
        n = i*i*i*i*i;
        for(ll j=-1000;j<=1000;j++)
        {
            if(n - (j*j*j*j*j) ==  x)
            {
                pf("%lld %lld\n",i,j);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3756
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

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

	vector<int> dp(N);
	lint ans = 0;
	for (int i = 0; i < N; i++) {
		if (i - A[i] >= 0) ans += dp[i - A[i]];
		DMP(i, dp);
		if(i + A[i] < N) dp[A[i] + i]++;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4780
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>

using namespace std;

typedef struct {
	int start;
	int end;
} Confrict;

// 構造体vectorのソート方法を指定する関数
bool cmp_end(const Confrict& left, const Confrict& right) {
	return left.end < right.end;
}

int main() {

	int N, M;
	cin >> N >> M;
	vector<Confrict> array;
	vector<bool> solved;

	for (int i = 0; i < M; i++) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		Confrict tmp;
		tmp.start = tmp1 - 1;
		tmp.end = tmp2 - 1;
		array.push_back(tmp);
		solved.push_back(false);
	}

	sort(array.begin(), array.end(), cmp_end);

	int count = 0;
	while (array.size()!=0) {
		count++;
		int cutpoint = array[0].end - 1;
		int last_id = array.size();
		for (int i = 0; i < array.size(); i++) {
			if (cutpoint < array[i].start) {
				//この紛争の直前までは解決済み
				last_id = i;
				break;
			}
		}
		array.erase(array.begin(), array.begin() + last_id);
	}

	cout << count << endl;

	return 0;

}


Measured memory_bytes: 1528