akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1000000000;

int main(){
    int N;cin>>N;
    vector<int> odd,even;
    rep(i,N){
        int S;cin>>S;
        if(i%2)odd.push_back(S);
        else even.push_back(S);
    }
    sort(odd.begin(),odd.end());sort(even.begin(),even.end());
    pair<int,int> odd1=make_pair(0,0),odd2=make_pair(0,0),even1=make_pair(0,0),even2=make_pair(0,0);
    int count=0,p=even.at(0);
    rep(i,even.size()){
        if(even.at(i)==p){
            count++;
            if(i==even.size()-1){
                if(count>even1.second){
                    even2=even1;
                    even1.first=p;even1.second=count;
                }
                else if(count>even2.second){
                    even2.first=p;
                    even2.second=count;
                }
                break;
            }
        }
        else{
            if(count>even1.second){
                even2=even1;
                even1.first=p;even1.second=count;
            }
            else if(count>even2.second){
                even2.first=p;
                even2.second=count;
            }
            count=0;p=even.at(i);i--;
        }
    }
    count=0;p=odd.at(0);
    rep(i,odd.size()){
        if(odd.at(i)==p){
            count++;
            if(i==odd.size()-1){
                if(count>odd1.second){
                    odd2=odd1;
                    odd1.first=p;odd1.second=count;
                }
                else if(count>odd2.second){
                    odd2.first=p;
                    odd2.second=count;
                }
                break;
            }
        }
        else{
            if(count>odd1.second){
                odd2=odd1;
                odd1.first=p;odd1.second=count;
            }
            else if(count>odd2.second){
                odd2.first=p;
                odd2.second=count;
            }
            count=0;p=odd.at(i);i--;
        }
    }
    if(odd1.first!=even1.first)cout<<N/2+N%2-even1.second+N/2-odd1.second<<endl;
    else cout<<min(N/2+N%2-even1.second+N/2-odd2.second,N/2+N%2-even2.second+N/2-odd1.second)<<endl;
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int main(){
  int N, K; cin >> N >> K;

  int ans = 0;

  while(N){
    N /= K;
    ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
// const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

const int MAX=1000;
long long COM[MAX][MAX];
// テーブル作成
void COMinit(){
    memset(COM,0,sizeof(COM));
    COM[0][0]=1;
    for(int i=1;i<MAX;i++){
        COM[i][0]=1;
        for(int j=1;j<MAX;j++){
            COM[i][j]=COM[i-1][j-1]+COM[i-1][j];
        }
    }
}
int main(){
    COMinit();
    long long n,a,b; cin>>n>>a>>b;
    long long v[n]; rep(i,n) cin>>v[i];
    sort(v,v+n); reverse(v,v+n);
    long long sum=0,cnt=0,cntin=0;
    rep(i,n){
        if(i<a) sum+=v[i];
        if(v[i]==v[a-1]){
            cnt++;
            if(i<a) cntin++;
        }
    }
    long long ans=0;
    if(v[0]==v[a-1]){
        for(int i=a;i<=b;i++){
            ans+=COM[cnt][i];
        }
    }else{
        ans+=COM[cnt][cntin];
    }
    printf("%.10f\n",1.0*sum/a);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8064
#Coding:Utf-8

N, M, C= map(int, input().split())
B=list(map(int, input().split()))
count=0
for i in range(N):
    A=[]
    total=0
    A=list(map(int, input().split()))
    for j in range(M):
        total=total+(A[j]*B[j])
    else:
        if total+C>0:
            count+=1

print(count)


Measured memory_bytes: 3060
N = int(input())
hs = list(map(int, input().split()))
cs = [0, abs(hs[1]-hs[0])]
for i in range(2, N):
  c = min(cs[i-1]+abs(hs[i]-hs[i-1]), cs[i-2]+abs(hs[i]-hs[i-2]))
  cs.append(c)
r = cs[-1]
print(r)


Measured memory_bytes: 13980
N = int(input())
word = list(input())
X1 = ['A','B','C','D','E','F','G','H','I','J','K','L','M']
X2 = ['N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
Y1 = ['a','b','c','d','e','f','g','h','i','j','k','l','m']
Y2 = ['n','o','p','q','r','s','t','u','v','w','x','y','z']
x = 0
y = 0
answer = ""
for i in word:
  if i in X1:
    x += 1
  elif i in X2:
    x -= 1
  elif i in Y1:
    y += 1
  elif i in Y2:
    y -= 1
print(abs(x)+abs(y))
if abs(x)+abs(y) > 0:
  if x > 0:
    answer += "A" * x
  elif x < 0:
    answer += "N" * abs(x)
  if y > 0:
    answer += "a" * y
  elif y < 0:
    answer += "n" * abs(y)
  print(answer)


Measured memory_bytes: 6520
def solve(h, n, A, B):
    dp = [float("inf")] * h + [0]
    for i in range(h, -1, -1):
        if dp[i] == float("inf"):
            continue
        for j in range(n):
            if 0 <= i - A[j]:
                dp[i - A[j]] = min(dp[i - A[j]], dp[i] + B[j])
            else:
                dp[0] = min(dp[0], dp[i] + B[j])
    return dp[0]

if __name__ == '__main__':
    h, n = map(int, input().split())
    a = [0] * n
    b = [0] * n

    for i in range(n):
        a[i], b[i] = map(int, input().split())

    print(solve(h, n, a, b))

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

int main(){
  double a, b, c, d, e, f;
  while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f)!=EOF){
    double x=(c*e-b*f)/(a*e-b*d), y=(c*d-a*f)/(b*d-a*e);
    if(x==0)x=0.0;
    if(y==0)y=0.0;
    printf("%.3f %.3f\n", x, y);
  }
  return 0;
}

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

int main(){

int m,f,r;

while(1){
cin>>m>>f>>r;
    
    if(m==-1 && f==-1 && r==-1){
        break;
    }else if(m==-1 || f==-1){
        cout<<"F"<<endl;  
    }else if(m+f>=80){
        cout<<"A"<<endl;
    }else if(m+f>=65){
        cout<<"B"<<endl;
    }else if(m+f>=50){
        cout<<"C"<<endl;
    }else if(m+f>=30){
        if(r>=50){
            cout<<"C"<<endl;
        }else{
            cout<<"D"<<endl;
        }    
        
    }else if(f>=0){
        cout<<"F"<<endl;
    }

}

    return 0;
}


Measured memory_bytes: 3092
use std::io::stdin;
use std::str::FromStr;
#[allow(dead_code, unused_mut)]
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().expect("1")
}
#[allow(dead_code, unused_mut)]
fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().expect("2"))
        .collect()
}
#[allow(dead_code, unused_mut)]
fn read_two<T: FromStr>() -> (T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap())
}
#[allow(dead_code, unused_mut)]
fn read_three<T: FromStr>() -> (T, T, T) {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut x = s.split_whitespace().map(|x| x.parse().ok().unwrap());
    (x.next().unwrap(), x.next().unwrap(), x.next().unwrap())
}
fn main() {
    let (sh, wo) = read_two::<i32>();
    if sh <= wo {
        println!("unsafe");
    } else if sh > wo {
        println!("safe");
    }
}

Measured memory_bytes: 2100
function Main(input) {
	var A = parseInt(input.split(" ")[0]);
  var B = parseInt(input.split(" ")[1]);
  var C = parseInt(input.split(" ")[2]);
  if(A <= C && B >= C){
     console.log("Yes");
     }else{
     console.log("No");
     }
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
/*AtCoder Beginner Contest 104(๑•﹏•๑｀)*/

int main(){
	int R; SCD(R);
	if (R <= 1199){
		printf("ABC\n");
	}else if (R <= 2799){
		printf("ARC\n");
	}else{
		printf("AGC\n");
	}
}

Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
check=[0]*n
for i in range(k,n):
    if a[i]>a[i-k]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 98456
import math

Q = int(input())

for i in range(Q):
  A, B = map(int, input().split())
  ABsq = math.ceil((A*B)**(1/2))
  if A == B:
    print(2*(A-1))
  else:
    if ABsq*(ABsq-1) >= A*B:
      print(2*(ABsq-1)-2)
    else:
      print(2*(ABsq-1)-1)
      
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

 inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> N;
}

int solve(){
    vector<int> s(32,0);
    DBG(bitset<32>(N))
    if(N==0) {cout << 0 << endl; return 0;}
    // 
    for (int i = 0; i < 32; i++)
    {
        if((N>>i)&1){
            if(i%2==0) s[i]++;
            else{
                s[i]++;
                s[i+1]++;
            }
        }
        while(s[i]>=2){
            s[i]-=2;
            s[i+1]++;
            s[i+2]++;
        }
    }
    string ans;
    for (int i = 0; i < s.size(); i++)
    {
        ans = to_string(s[i]) + ans;
    }
    while(ans[0]=='0') ans = ans.substr(1);
    cout << ans << endl;
    
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 256
package main 
import(
        "fmt"
        "sort"
)

func main () {
        var n , a int 
        s := []int{}
        fmt.Scan(&n)
        for i := 0 ; i < n ; i++ {
                fmt.Scan(&a)
                s = append (s, a)
        }
        sort.Sort(sort.IntSlice(s))
        nn := n -1
        an := s[nn]-s[0]
        fmt.Println(an)
}


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

using namespace std;

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

	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();

	vector<int> foo(n + 1, 0);
	for (int i = 0; i < n; i++) {
		foo[i + 1] = foo[i] + (s[i] == 'A' ? 1 : 2);
	}

	vector<int> bar(n + 1, 0);
	for (int i = 0; i < m; i++) {
		bar[i + 1] = bar[i] + (t[i] == 'A' ? 1 : 2);
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--; c--;

		int x = (foo[b] - foo[a]) % 3;
		int y = (bar[d] - bar[c]) % 3;
		cout << (x == y ? "YES" : "NO") << "\n";
	}
	return 0;
}

Measured memory_bytes: 1744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String[] strs = str.split(" ");

		int a = Integer.parseInt(strs[0]);
		int b = Integer.parseInt(strs[1]);
		int c = Integer.parseInt(strs[2]);

		int div = 0;

		for (int i = a; i <= b; i++) {
			if (c % i == 0) {
				div++;
			}
		}

		System.out.println(div);
		sc.close();

	}

}



Measured memory_bytes: 26212
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

const ll mod = 1000000007;

int main() {
  ll n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;

  vll ans(n, 0);  // ans[0] no use

  for (ll i = 0; i <= n - 2; i++) {
    for (ll j = i + 1; j <= n - 1; j++) {
      ll canda = abs(i-x) + abs(j-y) + 1;
      ll candb = j - i;
      ll vote = min(canda, candb);
      ans[vote]++;
    }  // j
  } //i

  for (ll i = 1; i <= n - 1; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define endl "\n"
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod=1e7+9;

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

int lcm(int a , int b)
{
	return (a*b)/gcd(a,b);
}

int power(int a , int b , int c)
{
    if(a==0) return 0;
    if(b==0) return 1;

    int res=1;
    a=a%c;
    while(b>0)
    {
        if(b&1)
        {
            res=(res*a)%c;
        }
        a=(a*a)%c;
        b>>=1;
    }
    return res;
}

vector<int> arr;

int32_t main()
{

    fast_in_out;

    int t=1;
    //cin>>t;
    while(t--)
    {
		int n;
		cin>>n;
		int ans=0;
		arr.resize(n+1,0);
		for(int i=1;i<=n;i++)
		{
			for(int j=i;j<=n;j+=i)
			{
				arr[j]++;
			}
		}
		for(int i=1;i<n;i++)
		{
			int x=n-i;
			ans+=arr[x];
		}
		cout<<ans<<endl;
    }

    return 0;
}


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

int main()
{
	int n;cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;++i)cin>>v[i];
	vector<int> evn;
	vector<int> odd;
	for(int i=0;i<n;i+=2)
	{
		evn.push_back(v[i]);
		odd.push_back(v[i+1]);
	}

	sort(evn.begin(),evn.end());
	sort(odd.begin(),odd.end());

	vector<pair<int,int>> evnN;
	vector<pair<int,int>> oddN;

	for(int i=1;i<n/2+1;++i)
	{
		int l=1;
		while(evn[i]==evn[i-1])
		{
			l++;
			i++;
		}
		evnN.push_back(make_pair(l,evn[i-1]));
	}

	for(int i=1;i<n/2+1;++i)
	{
		int l=1;
		while(odd[i]==odd[i-1])
		{
			l++;
			i++;
		}
		oddN.push_back(make_pair(l,odd[i-1]));
	}

sort(oddN.begin(),oddN.end());
sort(evnN.begin(),evnN.end());
reverse(oddN.begin(),oddN.end());
reverse(evnN.begin(),evnN.end());

if(oddN[0].second!=evnN[0].second){
	int ans=0;
	int o = oddN[0].second;
	int e = evnN[0].second;
	for(int i=0;i<n/2;i++)
	{
		if(evn[i]!=e)ans++;
		if(odd[i]!=o)ans++;
	}
	cout<<ans<<endl;
	return 0;
}
if (oddN.size()==1&&evnN.size()==1)
{
	cout<<n/2<<endl;
	return 0;
}

if(oddN.size()==1)
{
	cout<<n/2-(evnN[0].second!=oddN[0].second ? evnN[0].first:evnN[1].first)<<endl;
	return 0;
}
if (evnN.size()==1)
{
	cout<<n/2-(oddN[0].second!=evnN[0].second ? oddN[0].first:oddN[1].first)<<endl;
	return 0;
}

int ans1=n-oddN[0].first-evnN[1].first;
int ans2=n-oddN[1].first-evnN[0].first;

if(ans1>ans2)ans1=ans2;
cout<<ans1<<endl;
	return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#define LL long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    LL int add=0;
    LL int num[100000];
    for (LL int i=0;i<n;i++)
        cin>>num[i];
    for (int i=0;i<n-1;i++)
    {
        if (i+1==num[i])
        {
            add++;
            num[i]=num[i+1];
            num[i+1]=i+1;
        }
    }
    if (num[n-1]==n)
    add++;
    cout<<add<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
char name[100];
int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
Q[tail] = x;
tail = (tail + 1) % LEN;
}

P dequeue(){
P x = Q[head];
head = (head + 1) % LEN;
return x;
}

int min(int a, int b){return a < b ? a : b;}

int main(){
int elaps = 0, c;
int i, q;
P u;
scanf("%d %d", &n, &q);

for(i = 1; i <=n; i++){
scanf("%s", Q[i].name);
scanf("%d", &Q[i].t);
}
head = 1; tail = n + 1;

while(head != tail){
u = dequeue();
c = min(q, u.t);
u.t -= c;
elaps += c;
if(u.t > 0) enqueue(u);
else{
printf("%s %d\n", u.name, elaps);
}
}

return 0;
}


Measured memory_bytes: 12748
N = int(input())
A = input()
B = A.split()
flag = 1
total = 0
while flag :
    flag = 0
    for i in range(N-1, 0, -1) :
        if int(B[i]) < int(B[i-1]) :
            B[i], B[i-1] = B[i-1], B[i]
            flag = 1
            total += 1
print(" ".join(B))
print(total)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define mod (1000*1000*1000+7)
typedef long long ll;
const int N = 100001, D = 101;
ll dp[N][D],d;
int dig[N];
ll sum(int pos, int md) {
    if(pos == 1) {
        int c = 0;
        for(int i = 0; i <= dig[pos]; ++i)
            if((md+i)%d == 0) ++c;
        return c;
    }
    ll ans = 0;
    for(int i = 0; i <= dig[pos]; ++i) {
        if(i == dig[pos])
            ans = (ans + sum(pos-1,(md+i)%d))%mod;
        else {
            ans = (ans + dp[pos-1][(100*d-md-i)%d])%mod;
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string k; cin>>k>>d;
    int n = k.size();
    for(int i = n; i >= 1; --i) dig[i] = k[n-i]-'0'; 
    for(int i = 0; i <= 9; ++i)
        dp[1][i%d]++;
    for(int i = 1; i <= n; ++i)
        for(int j = 0; j < d; ++j)
            for(int l = 0; l <= 9; ++l) 
                dp[i+1][(j+l)%d] = (dp[i+1][(j+l)%d] + dp[i][j])%mod;
    cout<<(sum(n,0)-1+mod)%mod<<"\n";
}

Measured memory_bytes: 11136
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<set>
#include<random>
#include<ctime>
using namespace std;
using ll = long long int;

const int C_NUM = 26;
const int D_MAX = 366;
int D;
int c[C_NUM+5];
int s[D_MAX][C_NUM+5];

int t[D_MAX];
set<int> last[C_NUM+5];


int main(){
    clock_t start = clock();
    cin >> D;
    for(int i = 1; i <= C_NUM; i++)cin >> c[i];
    for(int i = 1; i <= D; i++){
        for(int j = 1; j <= C_NUM; j++){
            cin >> s[i][j];
        }
    }

    for(int j = 1; j <= C_NUM; j++)last[j].insert(0);
    for(int i = 1; i <= D; i++){
        ll merit = 0;
        int choice = 1;
        for(int j = 1; j <= C_NUM; j++){
            ll nowm = s[i][j];
            nowm += c[j] * (i - *last[j].rbegin());
            if (nowm > merit){
                merit = nowm;
                choice = j;
            }
        }
        last[choice].insert(i);
        t[i] = choice;
    }
    clock_t end;
    for(int j = 1; j <= C_NUM; j++)last[j].insert(D+1);
    random_device rnd;
    while((double)(end - start) / CLOCKS_PER_SEC < 1.8){
        int sub;
        int day = (rnd() % D) + 1;
        int o = t[day];
        int nowmax = 0;
        int choice = o;
        for(int n = 1; n <= C_NUM; n++){
            if (n == o)continue;
            sub = s[day][n] - s[day][o];
            int bo = *(--last[o].find(day));
            int ao = *(++last[o].find(day));
            sub -= c[o] * (day - bo) * (ao - day);
            last[o].erase(day);
            last[n].insert(day);
            int bn = *(--last[n].find(day));
            int an = *(++last[n].find(day));
            sub += c[n] * (day - bn) * (an - day);
            if (nowmax < sub){
                nowmax = sub;
                choice = n;
            }
        }
        t[day] = choice;
        end = clock();
    }
    for(int i = 1; i <= D; i++)cout << t[i] << endl;
    return 0;
}

Measured memory_bytes: 4116
#include <stdio.h>
int main(void){
  int i,a[26]={};
  char s[27];
  bool ans=true;
  scanf("%s",s);
  for (i=0;s[i];i++) a[(int)s[i]-97]++;
  for (i=0;i<26;i++){
    if (a[i]>1){
      ans=false;
      break;
    }
  }
  printf("%s\n",(ans)? "yes":"no");
  return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        var n = long.Parse(Console.ReadLine());
        long[] numbers = Console.ReadLine().Split().Select(long.Parse).ToArray();

        bool ok = true;
        for (int i = 0; i < n - 1; i++)
        {            
            if (numbers[i + 1] - numbers[i] > 0)
            {
                numbers[i + 1] -= 1;
            }
            else if (numbers[i + 1] - numbers[i] == 0)
            {
                //何もしない
            }
            else
            {
                ok = false;
            }
        }
        //出力
        if (ok)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

    }
}


Measured memory_bytes: 29404
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
#define MOD 1000000007

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S1, S2;
    cin >> N >> S1 >> S2;
    S1.push_back('0'); S2.push_back('0');
    vector<int> v;
    for(int i=0; i<N; i++)
        if(S1[i] == S2[i]) v.push_back(0);
        else if(S1[i] == S1[i+1]) v.push_back(1);

    long long ans;
    if(v[0]==0) ans = 3;
    else ans = 6;

    for(int i=0; i<v.size()-1; i++){
        if(v[i]==0 && v[i+1]==0) ans *= 2;
        else if(v[i]==0 && v[i+1]==1) ans *= 2;
        else if(v[i]==1 && v[i+1]==0) ans *= 1;
        else if(v[i]==1 && v[i+1]==1) ans *= 3;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    int N;
    string S;
    scanf("%d", &N);
    cin >> S;

    if (N == 1) printf("No\n");
    else {
        string T = S.substr(0, S.length()/2);
        if (T + T == S) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
}
void File()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
	/*freopen("output.txt", "w", stdout);
	freopen("pyramid.in", "r", stdin);*/
#endif
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e5 + 15;
int dx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[8] = { 0, 0, 1, -1, 1, -1, -1, 1 };

vector<ll>arr;

bool valid(ll x)
{
	string s=to_string(x);
	for(int i=0;i<sz(s)-1;i++)
	{
		if(abs(s[i]-s[i+1])>1)
			return 0;
	}
	return x<=3234566667;
}
void BFS()
{
	map<ll,bool> vis;
	queue<ll>qq;	
	for(int i=1;i<10;i++)
	{
		arr.push_back(i);
		qq.push(i);
	}
	while (!qq.empty())
	{
		ll c=qq.front();
		qq.pop();
		int tmp=c%10;
		c*=10;
		c+=(tmp);
		if(valid(c-1)&&vis.find(c-1)==vis.end())
		{
			arr.push_back(c-1);
			qq.push(c-1);
			vis[c-1]=1;
		}
		if(valid(c)&&vis.find(c)==vis.end())
		{
			arr.push_back(c);
			qq.push(c);
			vis[c]=1;
		}
		if(valid(c+1)&&vis.find(c+1)==vis.end())
		{
			arr.push_back(c+1);
			qq.push(c+1);
			vis[c+1]=1;
		}
	}
}

int main()
{
	fast();
	//File();
	BFS();
	sort(all(arr));
	int k;
	cin>>k;
	cout<<arr[k-1];
	return 0;
}

Measured memory_bytes: 7924
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	vector< pii > P(N);
	rep(i, N) {
		cin >> P[i].first;
		P[i].second = i;
	}
	sort(P.rbegin(), P.rend());
	multiset< int > s;
	s.insert(N);
	s.insert(N);
	s.insert(-1);
	s.insert(-1);
	int ans = 0;
	rep(k, N) {
		int i = P[k].second;
		int p = P[k].first;
		auto it = s.lower_bound(i);
		it++;
		int z = *it;
		it--;
		int y = *it;
		it--;
		int x = *it;
		it--;
		int w = *it;
		s.insert(i);
		ans += (i - x) * (z - y) * p;
		ans += (y - i) * (x - w) * p;
		/*cout << p << endl
			 << w << " " << x << " " << i << " " << y << " " << z << endl
			 << ans << endl;
			*/
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
int main(void)
{
  int n,i,j;
  int num[1000000]={0};

  for(i=3;i<1000000;i+=2){
    if(num[i]==1)
      continue;
    for(j=3*i;j<1000000;j+=i*2)
      num[j]=1;
  }

  for(;scanf("%d",&n)!=EOF;){
    int count=1;
    for(i=3;i<=n;i+=2){
      if(num[i]==1)
        continue;
      count+=1;
    }
    if(n<2)
      count=0;
    printf("%d\n",count);
  }

  return 0;
}



Measured memory_bytes: 5612
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 1000005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db double
#define noop
#define flu fflush(stdout)
#define imp {cout<<"impossible\n"; return ;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<endl;}

void sieve_primes(vector<char> &siv) {
    ll n = siv.size();

    siv[0]=0; siv[1]=0;
    for(ll i=2;i<=sqrt(n);i++) {
        if(siv[i]) {
            for(ll j=i*i;j<n;j+=i)
                siv[j]=0;
        }
    }
}

int main() {
    vector<char> siv(Nmax,1);
    sieve_primes(siv);
    get(x);
    rep2(i,x,Nmax) {
        if(siv[i]){
            printf("%lld\n", i);
            break;}
    }
    return 0;  
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(void){
int x,y,z,m,n;
  scanf("%d", &x);
  y=x/500; //500円の枚数
   z = y*1000;
  x=x%500;
  m=x/5;
  n=m*5;
  n=n+z;
  printf("%d\n", n);
  return 0;
}

Measured memory_bytes: 1704
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(double)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define DEBUG
long a[300003];

int main(){
    LL N,A,B;
    cin>>N>>A>>B;
    LL mini=(N-1LL)*A+B;
    LL maxi=(N-1LL)*B+A;
    cout<<max(maxi-mini+1LL,0LL)<<endl;
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  if ( S == "SUN" ){
    cout << 7 << endl;
  }
  else if ( S == "MON" ){
    cout << 6 << endl;
  }
  else if ( S == "TUE" ){
    cout << 5 << endl;
  }
  else if ( S == "WED" ){
    cout << 4 << endl;
  }
  else if ( S == "THU" ){
    cout << 3 << endl;
  }
  else if ( S == "FRI" ){
    cout << 2 << endl;
  }
  else if ( S == "SAT" ){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
import Data.List

main = do
  line <- getLine
  contents <- getContents
  let
    n = read line :: Int
    nums = map sort [ map read $ words l | l <- (take n $ lines contents)]
    result = map (\x -> if is_right_triangle x then "YES" else "NO") nums

  mapM_ putStrLn result

is_right_triangle [a, b, c] = a*a + b*b == c*c

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X,Y;
  cin>>N>>X>>Y;
  vector<int> data(N,0);
    
  for(int i=1;i<N;i++){
    for(int j=i+1;j<=N;j++)
    {
      //cout << "i" << i << "j" << j << endl;
      int tmp;
      tmp = min(j-i, (abs(X-i)+1+abs(j-Y)));
      tmp=min(tmp,abs(Y-i)+1+abs(j-X));
      data.at(tmp - 1)++;
      //cout << data.at(tmp - 1) << endl;
    }
  }
  
  for(int i=0;i<N-1;i++){
    cout << data.at(i) << endl;
  }
}

Measured memory_bytes: 256
n,w = map(int,input().split())

ab = []
for _ in range(n):
    a, b= (int(x) for x in input().split())
    ab.append([a, b])

dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j < ab[i][0]:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max([dp[i][j], dp[i][j-ab[i][0]]+ab[i][1]])
print(dp[n][w])

Measured memory_bytes: 172296
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long A, long long B)
{
    int ans = 0;
    for (int i = 0; i < 2; i++)
    {
        if (A >= B)
        {
            ans += A;
            A--;
        }
        else
        {
            ans += B;
            B--;
        }
    }

    cout << ans << endl;
}

int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	fast_cin();
	int a, b, c, n;
	cin >> a >> b >> c >> n;
	ll ans = 0;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (a * i + b * j > n) {
				break;
			}
			int left = n - a * i - b * j;
			if (left % c == 0) {
				++ans;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
 
def main():
    input = sys.stdin.readline
    H, W, A, B = map(int, input().split())
 
    ans = []
    for h in range(B):
        row = [0]*A + [1]*(W-A)
        ans.append(row)
    
    for h in range(H-B):
        row = [1]*A + [0]*(W-A)
        ans.append(row)
    
    for a in ans:
        print(''.join(map(str, a)))
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 11892
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	auto nte = readln.chomp.split.map!(to!int);
	auto lo = nte[1] - nte[2];
	auto up = nte[1] + nte[2];
	auto san = readln.chomp.split.map!(to!int).array;
	auto res = -1;
	foreach (i, e; san) {
		auto tmp = e;
		while (tmp < lo) tmp += e;
		if (tmp <= up) {
			res = i.to!int + 1;
			break;
		} 
	}
	res.writeln;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;


// Inputs
int D;
vector<int> c;
vector<vector<int>> s;

class Answer {
public:
    // 0~25の構造体
    vector<int> ans;
    explicit Answer() {
        ans.resize(D,0);
    }

    void print_ans() {
        for(const auto &it: ans) cout << it+1 << endl;
    }
};


// スコア計算を行う
ll calc(const Answer& ans) {
    // あるコンテストi-1が開催されていない日数
    vector<int> not_open_term(26,0);
    ll manzoku = 0;
    REP(day,D) {
        manzoku += s[day][ans.ans[day]];
        REP(typ,26) not_open_term[typ]++;
        REP(typ,26) if(typ != ans.ans[day])manzoku -= not_open_term[typ] * c[typ];
        not_open_term[ans.ans[day]] = 0;
        // For B その日終了時に満足度を出力する。
        cout << manzoku << endl;
    }
    return manzoku;
}


void read() {
    cin >> D;
    c.resize(26);
    REP(i,26) cin >> c[i];
    s.resize(D);
    REP(i,D) {
        s[i].resize(26);
        REP(j,26) cin >> s[i][j];
    }
}

// 下がりやすさを無視して一番点が高い物を選ぶ
Answer greedy1() {
    Answer answer = Answer();
    REP(day,D) {
        int mx = 0;
        REP(typ,26) if(chmax(mx,s[day][typ])) answer.ans[day] = typ;
    }
    return answer;
}

// 下がりやすさを考慮して一番高い物を選ぶ
Answer greedy2() {
    Answer answer = Answer();
    // あるコンテストi-1が開催されていない日数
    vector<int> not_open_term(26,0);

    REP(day,D) {
        // 期待値の最大値
        int mx = 0;
        REP(typ,26) {
            // そのコンテストを開催した際の満足度変動値を計算する。
            int manzoku = s[day][typ];
            REP(_typ,26) if(_typ != typ )manzoku-=(not_open_term[_typ] * c[_typ]);
            if(chmax(mx,manzoku)) answer.ans[day] = typ;
        }
        REP(i,26) not_open_term[i]++;
        // 開催するコンテストが決定されたらそれの日数を0にする。
        not_open_term[answer.ans[day]] = 0;
    }
    return answer;

}

void solveB() {
    read();
    Answer answer = Answer();
    REP(i,D) {
        cin >> answer.ans[i];
        answer.ans[i]--;
    }
    cerr << calc(answer) << endl;
}

void solve() {
    read();
    // auto ans = Answer();
    // ans.print_ans();
    auto ans = greedy2();
    ans.print_ans();
}

int main() {
    solveB();
    return 0;
}

Measured memory_bytes: 3588
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

T1, T2 = IL()
a1, a2 = IL()
b1, b2 = IL()
if a1*T1 + a2*T2 > b1*T1 + b2*T2:
  pass
else:
  a1,a2,b1,b2 = b1,b2,a1,a2

if a1*T1 + a2*T2 == b1*T1 + b2*T2:
  print("infinity")
elif a1*T1 >= b1*T1:
  print(0)
else:
  half = b1*T1 - a1*T1
  x = (a1*T1 + a2*T2 - (b1*T1 + b2*T2))
  # half/x >= n
  loop = half//x + 1
  if (loop - 1)*x == half:
    print(loop*2 -2)
  else:
    print(loop*2 -1)

Measured memory_bytes: 39860
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int N=30;
ll dp[(1<<22)];
bool f[N][N];
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>f[i][j];
		}
	}
	dp[0]=1;
	for(int i=0;i<(1<<n);i++)
	{
		int j=0;
		for(int k=0;k<n;k++)
			if((i>>k)&1)
				j++;
		for(int k=0;k<n;k++)
		{
			if(f[j+1][k])
			{
				if(!(i>>k&1))
				{
					dp[i+(1<<k)]+=dp[i];
					dp[i+(1<<k)]%=mod;
				}
			}
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 18688
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = NK[0];
            var K = NK[1];

            
            Console.WriteLine((N*(N-1)+K*(K-1))/2);
        }

        

    }

    class Modular
    {
        private const int M = 1000000007;
        public long value;
        public Modular(long value) { this.value = value; }
        public static implicit operator Modular(long a)
        {
            var m = a % M;
            return new Modular((m < 0) ? m + M : m);
        }
        public static Modular operator +(Modular a, Modular b)
        {
            return (a.value + b.value) % M;
        }
        public static Modular operator -(Modular a, Modular b)
        {
            return a.value - b.value;
        }
        public static Modular operator *(Modular a, Modular b)
        {
            return a.value * b.value;
        }
        public static Modular Pow(Modular a, int n)
        {
            switch (n)
            {
                case 0:
                    return 1;
                case 1:
                    return a;
                default:
                    var p = Pow(a, n / 2);
                    return p * p * Pow(a, n % 2);
            }
        }
        public static Modular operator /(Modular a, Modular b)
        {
            return a * Pow(b, M - 2);
        }
        private static readonly List<int> facs = new List<int> { 1 };
        private static Modular Fac(int n)
        {
            for (int i = facs.Count; i <= n; ++i)
            {
                facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
            }
            return facs[n];
        }
        public static Modular Ncr(int n, int r)
        {
            return (n < r) ? 0
                 : (n == r) ? 1
                            : Fac(n) / (Fac(r) * Fac(n - r));
        }
        public static explicit operator int(Modular a)
        {
            return (int)a.value;
        }

        public static Modular Lcm(Modular a, Modular b)
        {
            var tmp = Gcdl(a.value, b.value);
            return ((a * b) / new Modular(tmp));
        }
        static Modular Gcd(Modular m, Modular n)
        {
            if (n.value > m.value) return Gcd(n, m);
            if (n.value == 0) return m;
            var r = new Modular(m.value % n.value);
            return Gcd(n, r);
        }

        static long Gcdl(long m, long n)
        {
            if (n > m) return Gcdl(n, m);
            if (n == 0) return m;
            return Gcdl(n, m % n);
        }
    }
}


Measured memory_bytes: 11348
import java.util.Scanner;

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

        if (scanner.hasNextLine()) {
            String[] array = scanner.nextLine().split(" ");
            int r = Integer.parseInt(array[0]);
            int D = Integer.parseInt(array[1]);
            long x = Integer.parseInt(array[2]);

            for (int i = 2001; i <= 2010; ++i) {
                x = r * x - D;
                System.out.println(x);
            }
        }
    }
}

Measured memory_bytes: 21716
A, B, C, X = [int(input()) for _ in range(4)]
cnt = 0
for a in range(0, A+1):
    for b in range(0, B+1):
        for c in range(0, C+1):
            if 500*a+100*b+50*c == X:
                cnt += 1
print(cnt)

Measured memory_bytes: 9028
#include <iostream>

using namespace std;

int main() {
  int N, A;
  cin >> N;
  cin >> A;
  
  int remainder = N % 500;
  if (remainder <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  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 = Integer.parseInt(sc.nextLine());
    int[][] point = new int[N][2];
    for(int i = 0; i < N; i++){
      String[] S = sc.nextLine().split(" ");
      point[i][0] = Integer.parseInt(S[0]);
      point[i][1] = Integer.parseInt(S[1]);
    }
    
    double[][] distance = new double[N][N];
    double ans = 0.0;
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        if(i == j){
          continue;
        }
        int x1 = point[i][0];
        int y1 = point[i][1];
        int x2 = point[j][0];
        int y2 = point[j][1];
        
        double dis = Math.sqrt(Math.pow(x1-x2, 2)+Math.pow(y1-y2, 2));
        ans += dis;
      }
    }
    
    int M = 1;
    for(int i = 1; i <= N; i++){
      M *= i;
    }
    ans *= M/N;
    ans /= M;
    System.out.println(ans);
  }
}

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

using namespace std;

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

  long long A = 0;
  long long B = 0;
  for(int i = 0;i < N;++i){
    int temp;
    cin>>temp;
    A += temp;
  }
  for(int i = 0;i < M;++i){
    int temp;
    cin>>temp;
    B += temp;
  }

  long long ans = A * B;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3100
n = gets.to_i
s = gets.chomp.chars

w = Array.new(n, 0)
e = Array.new(n, 0)

0.step(n - 1) do |i|
  if i != 0
    w[i] = w[i - 1]
    w[i] += 1 if s[i - 1] == "W"
    e[n - 1 - i] = e[n - i]
    e[n - 1 - i] += 1 if s[n - i] == "E"
  end
end
puts (0...n).to_a.map {|i| w[i] + e[i] }.min

Measured memory_bytes: 37000
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int n,m,k;
    string ans="No";
    cin >> n >> m >> k;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i*(m-j)+j*(n-i)==k){
                ans = "Yes";
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256