akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define endl "\n"
#define ff first
#define ss second
#define inp(a) int a; cin>>a;
#define inpa(a,n) vector<int>a(n+1); FOR(i,1,n) cin>>a[i];
#define PI 3.141592653589793238
#define QUICK ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vec(x) vector<x>
#define pii pair<int,int>
#define mem(a,b) memset(a, b, sizeof a)
#define FOR(i,j,n) for(int i= j; i<=n; i++)
#define srt(a); sort(a.begin(), a.end())
#define CASE int t; cin>>t; while(t--)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed<<setprecision(n)
#define print(x) for(auto c : x) cout << c << " ";
#define dbg(x) cerr << #x << " :: "<< x << endl;
#define dbg2(x,y) cerr << #x << " :: "<<x <<"\t" << #y << " :: "<<y <<endl;
#define upcase(s)  transform(s.begin(), s.end(), s.begin(), ::toupper)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define int ll
const int INF = 1e9 + 7;
const int SIZE = 1e9 + 5;
const int MOD = 1e9 + 7; 
//////////// template ends here //////////////////////////
const int maxn = 1e5 + 2;

vec(int)wt(101, 0), val(101, 0);
vec(vec(int))dp(101, vec(int)(maxn, -1));

int topdown(int n, int value){

	if(n ==0 && value == 0)
		return 0;
	if(n == 0)
		return INF;

	if(dp[n][value] != -1)
		return dp[n][value];
	
	int sub1 = topdown(n-1, value);
	if(value >= val[n])
		sub1 = min(sub1, topdown(n-1, value - val[n]) + wt[n]);

	dp[n][value] = sub1;
	return sub1;
}


void solve(){	

	inp(n); inp(w);
	FOR(i,1,n)
		cin>>wt[i]>>val[i];
	
	for(int i = maxn-1; i>=0; i--){
		if(topdown(n,i) <= w){
			cout << i << endl;
			break;
		}
	}

}



int32_t main(){
	#ifndef ONLINE_JUDGE 
		freopen ("input.txt","r",stdin);
		freopen ("output.txt","w",stdout);
	#endif	
	QUICK;
	//CASE{
		solve();
	//}
	printclock;
}

Measured memory_bytes: 83032
#include "iostream"
#include "stdio.h"
#include "cmath"
using namespace std;

int main(int argc, char const *argv[])
{
	double x1, y1, x2, y2=0;

	cin >> x1 >> y1 >> x2 >> y2;

	printf("%.10f\n", sqrt( pow(x1 - x2, 2) + pow(y1 - y2, 2) ));
	return 0;
}


Measured memory_bytes: 3268
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
	    while(true){
	 	    int a = Integer.parseInt(std.next());
	 	    String op = std.next();
	 	    int b = Integer.parseInt(std.next());

	 	    if(op.equals("+")) System.out.println(a+b);
	    	else if(op.equals("-")) System.out.println(a-b);
	    	else if(op.equals("*")) System.out.println(a*b);
	    	else if(op.equals("/")) System.out.println(a/b);
	    	else break;
	    }
	}
}

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

bool isPrime[100001];
int np[100001];

int main(){
	for(int i=2;i<=100000;i++){
		isPrime[i]=true;
	}
	for(int i=2;i*i<=100000;i++){
		if(isPrime[i]){
			for(int j=i+i;j<100000;j=j+i){
				isPrime[j]=false;
			}
		}
	}
	np[0]=0;
	for(int i=1;i<=100000;i++){
		if(isPrime[i] and isPrime[(i+1)/2]){
			np[i]=np[i-1]+1;
		}else{
			np[i]=np[i-1];
		}
	}
	int q,l,r;
	cin>>q;
	while(q--){
		cin>>l>>r;
		cout<<np[r]-np[l-1]<<endl;
	}
}

Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
  int n;
  int a[100];
  cin >> n;
  for (int i=0;i<n;i++) {
      cin >> a[i];
  }
  for (int i=n-1;0<=i;i--) {
      if (i==0){
        cout << a[i];
      }else{
        cout << a[i] << " ";
      }
  }
  cout << endl;
}


Measured memory_bytes: 3076
#include "stdio.h"

int main(){

  int T_alice,T_bob,R_alice,R_bob;

  scanf("%d%d%d%d",&T_alice,&T_bob,&R_alice,&R_bob);

  if (R_alice==-1||R_bob==-1)
    if (T_alice>T_bob)
      printf("Bob\n");
    else if (T_alice<T_bob)
      printf("Alice\n");
    else
      printf("Draw\n");
  else if (R_alice > R_bob)
    printf("Alice\n");
  else if (R_alice <R_bob)
    printf("Bob\n");
  else
    printf("Draw\n");

  return 0;
}



Measured memory_bytes: 2092
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	if(a+b==c||a+c==b||a==b+c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 384
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let _N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let M = buf_it.next().unwrap().parse::<usize>().unwrap();

    let mut cnt = HashMap::new();
    for _ in 0..M{
        let a = buf_it.next().unwrap().parse::<usize>().unwrap();
        let b = buf_it.next().unwrap().parse::<usize>().unwrap();
        let t = *(cnt.get(&a).unwrap_or(&0));
        cnt.insert(a, 1-t);
        let t = *(cnt.get(&b).unwrap_or(&0));
        cnt.insert(b, 1-t);
    }
    println!("{}",if cnt.values().sum::<i32>()==0{"YES"} else {"NO"});

}


Measured memory_bytes: 14240
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<long long> x(n);
    vector<long long> y(m);
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < m; i++) cin >> y[i];
    x.insert(x.begin(), -1e18);
    y.insert(y.begin(), -1e18);
    x.push_back(1e18);
    y.push_back(1e18);
    while (q--) {
        long long u;
        cin >> u;
        long long s[2];
        long long t[2];
        s[0] = *lower_bound(x.begin(), x.end(), u);
        s[1] = *prev(upper_bound(x.begin(), x.end(), u));
        t[0] = *lower_bound(y.begin(), y.end(), u);
        t[1] = *prev(upper_bound(y.begin(), y.end(), u));
        long long ans = 8e18;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                ans = min(ans, abs(u - s[i]) + abs(s[i] - t[j]));
                ans = min(ans, abs(u - t[j]) + abs(s[i] - t[j]));
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

    vector<int> c;
    for (int i=0; i<999; ++i) {
        c.push_back((i+1) * (i+2) / 2);
    }

    int diff = b - a;
    cout << c[diff-1] - b << endl;;
}




Measured memory_bytes: 256
# input
W, H, N = gets.chomp.split.map(&:to_i)
field = Array.new(H+1).map{Array.new(W+1, 1)};
query = []
N.times do
  query.push(gets.chomp.split.map(&:to_i))
end

# main 
query.each do |q|
  od = q[2]
  xfr = 0; xto = W+1; yfr = 0; yto = H+1
  case od
    when 1 then
      xto = q[0]
    when 2 then
      xfr = q[0]
    when 3 then
      yto = q[1]
    when 4 then
      yfr = q[1]
  end
      
  (yfr...yto).each do |i|
    (xfr...xto).each do |j|
      field[i][j] = 0
    end
  end
end

ans = 0
(0...H).each do |i|
  (0...W).each do |j|
    if field[i][j] == 1 then ans += 1 end
  end
end

# output
puts ans


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){
    
    ll n;
    scanf("%lld", &n);

    rep(i, 3500){
        rep(j, 3500){
            ll I = i+1, J = j+1;
            double W = (double)n*I*J/(4.0*I*J-n*I-n*J);
            if(W > 0 and W == (int)W){
                cout << (int)W << sp << I << sp << J << endl;
                return 0;
            }
        }
    }
   
}


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

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

inline int read() {
  int s = 0, base = 1;
  char c;
  while (!isdigit(c=getchar())) if (c == '-') base = -base;
  while (isdigit(c)) {
    s = s * 10 + (c^48);
    c = getchar();
  }
  return base * s;
}

template<class T>
inline void print(T x) {
  if(x/10 != 0) {
    print(x/10);
    putchar(x%10+'0');
  }
}

template<class T>
inline void write(T x) { 
  if (x) putchar('-');
  x=abs(x);
  print(x);
}

template<class T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}

int N;
int A[100002];
// B[i]: A[i]とA[i-1]の距離
int B[100002];
// C[i]: A[i]を消すことでどれだけ距離が減るか
int C[100002] = {0};

int main() {
  ll sum = 0;

  N = read();
  A[0] = 0;
  FOR(i,1,N+1) {
    A[i] = read();
    B[i] = abs(A[i] - A[i-1]);
    sum += B[i];
  }
  A[N+1] = 0;
  B[N+1] = abs(A[N+1] - A[N]);
  sum += B[N+1];

  FOR(i,1,N+1) {
    printf("%d\n", sum - (B[i] + B[i+1]) + abs(A[i+1] - A[i-1]));
  }

  return 0;
}

Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int k, x;
	cin >> k >> x;

	int ans_min = max(x - k + 1, -1000000);
	int ans_max = min(x + k - 1, 1000000);
	int ans = ans_min;
	while (ans <= ans_max) {
		cout << ans << " ";
		ans++;
	}
	cout << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int[] B = new int[N];
            int[] C = new int[N - 1];
            String SA = Console.ReadLine();
            String[] LA = SA.Split(' ');
            String SB = Console.ReadLine();
            String[] LB = SB.Split(' ');
            String SC = Console.ReadLine();
            String[] LC = SC.Split(' ');

            for (int i=0; i<N; i++)
            {
                A[i] = int.Parse(LA[i]);
                B[i] = int.Parse(LB[i]);
                if(i != N - 1)
                {
                    C[i] = int.Parse(LC[i]);
                }
            }

            int res = 0;

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

            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking 
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1<<29)
using namespace std;
int n,m,ans;
char s[100005],t[100005];
void check(int x){
	for (int i=1,j=1;i<=n;i+=n/x,j+=m/x)
		if (s[i]!=t[j]) return;
	ans=x;
}
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
int main(){
	scanf("%d%d%s%s",&n,&m,s+1,t+1);
	int G=gcd(n,m);
	for (int i=1,j=1;i<=n;i+=n/G,j+=m/G)
		if (s[i]!=t[j]) return puts("-1"),0;
	for (int i=1;i<=n;i++) if (n%i==0&&m%i==0) check(i);
	if (ans==0) puts("-1");
	else printf("%lld\n",1ll*n*m/ans);
} 

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
const int INF=1e9;
int n,m,P;
vector<pii> R[2505],G[2505];
bool vis[2505];
inline void dfs(int u){
	vis[u]=1;
	for (int i=0;i<R[u].size();++i) if (!vis[R[u][i].F]) dfs(R[u][i].F);
}
int cnt[2505];
int dis[2505];
int que[2505],h,t;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m>>P;
	for (int i=1;i<=m;++i){
		int x,y,c;cin>>x>>y>>c;
		R[y].pb(mp(x,c));
	}
	memset(vis,0,sizeof(vis));
	dfs(n);
	for (int i=1;i<=n;++i) if (vis[i]){
		for (int j=0;j<R[i].size();++j){
			if (vis[R[i][j].F])G[R[i][j].F].pb(mp(i,P-R[i][j].S));
		}
	}
	memset(vis,0,sizeof(vis));
	fill(dis,dis+2505,INF);
	dis[1]=0;
	h=t=0;
	que[t++]=1;vis[1]=1;cnt[1]=1;
	while(h!=t){
		int u=que[h++],d=dis[u];vis[u]=0;
		if (h>=2505) h=0;
		for (int i=0;i<G[u].size();++i){
			int v=G[u][i].F,cost=G[u][i].S;
			if (dis[v]>dis[u]+cost){
				dis[v]=dis[u]+cost;
				if (!vis[v]) que[t++]=v,++cnt[v],vis[v]=1;
				if (t>=2505) t=0;
				if (cnt[v]>=n){
					cout<<-1<<endl;return 0;
				}
			}
		}
	}
	cout<<max(0,-dis[n])<<endl;
	return 0; 
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

// えびちゃんの make_vector (ここから)
template <typename Tp, size_t N>
std::vector<Tp> make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N == 1), const Tp&>::type x) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N > 1), const Tp&>::type x) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector_detail<Tp, N-1>(sizes, x))>(size, make_vector_detail<Tp, N-1>(sizes, x));
}

template <typename Tp, size_t N>
auto make_vector(const size_t(&sizes)[N], const Tp& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return make_vector_detail<Tp, N>(s, x);
}
// えびちゃんの make_vector (ここまで)

signed main(){
    
    int n; cin >> n;
    vector<pair<pair<string, int>, int> > v(n);
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        int val; cin >> val;
        v[i].first.first = s;
        v[i].first.second = -val;
        v[i].second = i + 1;
    }

    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++) cout << v[i].second << endl;

    return 0;
}


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

 
int main()
{   
    long long N, K;
    cin >> N >> K;
    
    bool have[N];
    for(int i=0; i<N; i++){
        have[i] = false;
    }
    long long d, A;
    
    for(int i=0; i<K; i++){
        cin >> d;
        for(int j=0; j<d; j++){
            cin >> A;
            have[A-1] = true;
        }
    }
    
    long long sum = 0;
    for(int i=0; i<N; i++){
        sum += !have[i];
    }
    cout << sum << endl;
  
}


Measured memory_bytes: 3632
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;
import std.bigint;
import std.numeric;


void main()
{
  int n, k;
  readf("%d %d\n", &n, &k);
  
  auto result = 0.0;
  foreach (i; 1..n+1) {
    auto div = 1;
    while (k > div * i) {
      div *= 2;
    }
    result += 1 / div.to!double;
  }
  writefln("%.18f", result / n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

  int l, r;
  int total = 0;

  for (int i=0; i<N; i++) {
    cin >> l >> r;
    total += r - l + 1;
  }

  cout << total << endl;
}


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

const ll MOD = 1000000007;
const ll MAX = 100100;
const double PI = 3.1415926;

#define vll vector<ll>
#define max_heap priority_queue<int>
#define min_heap priority_queue<int , vector<int>, greater<int> >
#define pb push_back
#define all(container) container.begin(), container.end()
#define pll pair<ll,ll>
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";
// #define traverse( container, it) for( typeof(container.begin()) it = container.begin(); it!=container.end(); it++)
string k;
int d,n;
ll dp[110][10100][2];

int get(int i)
{
	return (((int)k[i]) - 48);
}
ll f(ll sum, ll index, bool eq)
{
	if (index == n)
	{
		if (sum % d == 0)
			return 1;
		else
			return 0;
	}
	if (dp[sum][index][eq] != -1)
		return dp[sum][index][eq];

	ll ans = 0;
	if (eq)
	{
		int digit = get(index);
		for(int i = 0; i < digit; ++i)
		{
			ans += (f((sum + i)%d, index + 1, !eq)%MOD);
			ans %= MOD;
		}
		ans += (f((sum + digit)%d, index + 1, eq)%MOD);
		ans %= MOD;
	}
	else
	{
		for(int i = 0 ; i <= 9; ++i)
		{
			ans += (f((sum + i)%d, index + 1, eq)%MOD);
			ans %= MOD;
		}
	}
	return (dp[sum][index][eq] = ans);
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(dp,-1,sizeof(dp));
	cin >> k;
	cin >> d;
	n = k.length();
	ll answer = f(0,0,1);
	answer--;
	if (answer == -1)
		answer = MOD - 1;

	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 18560
/*
 
dunjen_master
 
*/
 

 
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=998244353;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 

inline ll mul(ll a,ll b){

    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}

  

 
#define all(x) (x).begin(),(x).end()

/* ordered_set A;
   A.insert(x);
   A.erase(x);
   A.order_of_key(x) // no of elements less than (<) x
   *A.find_by_order(k-1) // kth smallest element
*/
// int n;
// ll dp[200005][205];
// ll ans=0;
// int a[200005];
// int req;
// ll neg=-1e15;


// ll fun(int indx,int last){
//    // cout<<indx<<" "<<last<<" "<<req<<endl;
//     if(indx==n){
//         if(last==req){
//             return 0;
//         }else{
//             return neg;
//         }
//     }

//     if(dp[indx][last]!=-1){
//         return dp[indx][last];
//     }
    
//     ll ans=neg;

//     ans=max(ans,fun(indx+1,last));

//     if(last==0)ans=max(ans,1+fun(indx+1,a[indx]));
//     if(last==a[indx])ans=max(ans,1+fun(indx+1,a[indx]));
//     if(a[indx]==req)ans=max(ans,1+fun(indx+1,a[indx]));

//     return dp[indx][last]=ans;


// }









int main(){


    int n;
    cin>>n;
    set<string>s;
    while(n--){
        string str;
        cin>>str;
        s.insert(str);
    }

    cout<<s.size()<<endl;
    
 
    
}

    

    
 
    



Measured memory_bytes: 19220
a = [int(x) for x in input().split()]
min_val = float("inf")
for i in range(len(a)):
    val = 0
    b = a[0:i] + a[i+1:len(a)]
    if abs(a[i]-b[0]) < abs(a[i]-b[1]):
        val += abs(a[i] - b[0])
        val += abs(b[0] - b[1])
    else:
        val += abs(a[i] - b[1])
        val += abs(b[1] - b[0])
    min_val = min(min_val,val)
print(min_val)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int a, b, c, x, y; cin >> a >> b >> c >> x >> y;
	long long int ans = LLONG_MAX;
	long long int n = max(x, y)*2;
	long long int z = 0;
	for(long long int i=0;i<=n;i+=2){
		long long int s = max(z, x-i/2);
		long long int t = max(z, y-i/2);
		long long int total = c*i+a*s+b*t;
		ans = min(ans, total);
		//cout << total << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k%2==0){
        cout << a-b << endl;
    }
    else cout << b-a << endl;
}


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

int main() {
    int n;
    cin>>n;
    int d=0;
    int t=n;
    while (t) {
        d+=t%10;
        t/=10;
    }
    if (n%d==0)
        puts("Yes");
    else
        puts("No");
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  string S;
  cin >> S;

  bool f = true;
  rep(i, 1, 4) {
    if (S[i] == S[i-1]) f = false;
  }

  if (f) puts("Good");
  else puts("Bad");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	final static double[] LV500 = { 35.5, 37.5, 40, 43, 50, 55, 70 };
	final static double[] LV1000 = { 71, 77, 83, 89, 105, 116, 148 };
	final static String[] lv = { "AAA", "AA", "A", "B", "C", "D", "E" };

	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		a: while (in.hasNext()) {
			double _500 = in.nextDouble();
			double _1000 = in.nextDouble();
			String s = "NA";
			for (int i = 0; i < 7; i++) {
				if (LV500[i] > _500) {
					for (int j = i; j < 7; j++) {
						if (LV1000[j] > _1000) {
							System.out.println(lv[j]);
							continue a;
						}
					}
					break;
				}
			}
			System.out.println("NA");
		}
	}
}

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

using namespace std;

#define FOR(i,a,b) for (int i =(a); i <(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second

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

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

const bool debug = 0;

int n;
string s;

int cnt[10], ba;

int main() {
	while (cin >> n, n) {
		cin >> s;
		
		memset(cnt, 0, sizeof(cnt));
		ba = 0;
		
		int turn = 0;
		REP(i, s.size()) {
			cnt[turn]++;
			
			switch (s[i]) {
				case 'M': // ???
					break;
				case 'S': // ??????
					ba += cnt[turn];
					cnt[turn] = 0;
					break;
				case 'L': // ?§?
					cnt[turn] += ba;
					ba = 0;
					break;
			}
			
			turn = (turn + 1) % n;
		}
		
		sort(cnt, cnt + n);
		REP(i, n) printf("%d ", cnt[i]);
		printf("%d\n", ba);
		
	}
	return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll dp[300000],rdp[300000];
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  string s;cin>>s;
  for(int i=0;i<n-1;i++){
    if(s[i]=='W'){
      dp[i+1]+=dp[i]+1;
    }else{
      dp[i+1]+=dp[i];
    }
  }
  for(int i=n-2;i>=0;i--){
    if(s[i+1]=='E'){
      rdp[i]+=rdp[i+1]+1;
    }else{
      rdp[i]+=rdp[i+1];
    }
  }
  for(int i=0;i<n-1;i++){
    // P(i);
    // P(dp[i]);
    // P(rdp[i]);
    // P("-----");
    dp[i]+=rdp[i];
  }
  ll minn=INF;
  for(int i=0;i<n;i++){
    minn=min(minn, dp[i]);
  }
  // P("-----");
  P(minn);

  return 0;
}


Measured memory_bytes: 5396
n = int(input())
a = []

for i in range(n):
    x,y = input().split()
    z = int(y)
    if x == "S":
        a.append(z + 0)
    elif x == "H":
        a.append(z + 13)
    elif x == "C":
        a.append(z + 26)
    elif x == "D":
        a.append(z + 39)

for i in range(1,53):
    if not i in a:
        if i <= 13:
            print("S {}".format(i))
        elif i <= 26:
            print("H {}".format(i - 13))
        elif i <= 39:
            print("C {}".format(i - 26))
        elif i <= 52:
            print("D {}".format(i - 39))



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

using ll=long long;
using int64=int64_t;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    ll s;
    cin >> s;
    string s2=to_string(s);
    int length=s2.size()-1;
    ll ans=0,a,l;
    for (int i=0;i<(1 << length);i++){
        a=s;
        bitset<9> pm(i);
        l=1;
        for(int i2=0;i2<length;i2++){
            if (pm[i2]==1) {
                ll x10=pow(10,l);
                ans+=a%x10;
                a/=x10;
                l=0;
            } 
            l++;
        }
        ans+=a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
while True:
    inp = input().split()
    x, y = (int(inp[0]), int(inp[2]))
    op = inp[1]
    if op == '?':
        break
    else:
        if op == '+':
            print(x + y)
        elif op == '-':
            print(x - y)
        elif op == '*':
            print(x * y)
        elif op == '/':
            print(x // y)



Measured memory_bytes: 5596
import java.util.Scanner;

class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int tosi[] = new int[n];
        int M[] = new int[n];
        int D[] = new int[n];
        int i;

        int k;
        int c = 0;

        for (k = 0; k < n; k++) {
            int total = 0;
            int day = 0;
            tosi[k] = sc.nextInt();
            M[k] = sc.nextInt();
            D[k] = sc.nextInt();

            for (i = tosi[k] + 1; i <= 1000; i++) {
                if (i % 3 == 0) {
                    total += 200;
                } else {
                    total += 195;
                }
            }
            if (tosi[k] % 3 == 0) {
                int tuki = (M[k] - 1) * 20;
                day = tuki + D[k] - 6;

            } else {
                if ((M[k] - 1) % 2 == 0) {
                    day = ((M[k] - 1) / 2) * 20 + ((M[k] - 1) / 2) * 19 + D[k] - 1;

                } else {
                    day = ((M[k]) / 2) * 20 + ((M[k] - 1) / 2) * 19 + D[k] - 1;

                }

            }

            total = total - day;
            System.out.println(total);
        }

    }

}



Measured memory_bytes: 26568
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (int argc, char const *argv[])
{
    char S[(int)1e5 + 1];
    uint64_t N;
    int64_t num0 = 0, num1 = 0, ans = 0;
    char *p;

    gets(S);
    N = strlen(S);
    p = S;

    while (*p) {
        if (*p == '0') {
            num0++;
        } else {
            num1++;
        }
        p++;
    }

    ans = num0 < num1 ? num0 : num1;
    ans *= 2;

    printf("%"PRId64"\n", ans);
}


Measured memory_bytes: 256
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

def isOK(x1,x2):
    sq = 0 
    for i in range(D):
        sq = sq + (x1[i]-x2[i])**2
    sq2 = int(math.sqrt(sq)+0.5)
    if sq == sq2 ** 2:
        return True
    else:
        return False

N,D= nm()

X = [] 
for i in range(N):
    x  = nl()
    X. append(x)
ans =0
for i in range(N-1):
    for j in range(i+1,N):
        if isOK(X[i],X[j]):
            ans = ans + 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
	long long int n, m;
	long long int res = 0;

	cin >> n >> m;

	if (m > 2 * n)
	{
		res += n;
		m -= (n * 2);
		res += (m / 4);
	}
	else
	{
		res += (m / 2);
	}
	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define INT_MAX 0x7FFFFFFF
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(a) ((a)<0?(-(a)):(a))
using namespace std;
typedef long long int LL;

int main(){
  int N, Ha = 0, Hb = 0, Hc = 0;
  cin >> N;
  REP(i, N) {
    int a, b, c;
    cin >> a >> b >> c;
    int tHa = a + MAX(Hb, Hc);
    int tHb = b + MAX(Ha, Hc);
    int tHc = c + MAX(Ha, Hb);
    Ha = tHa; Hb = tHb; Hc = tHc;
  }
  int ret = MAX(Ha, MAX(Hb, Hc));
  cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}


void Main()
{
	ll n,m,l; ll res=0;
	ll k;
	cin>>n>>k;
	VI h(n),b(n);
	rep(i, n) cin >> h[i];
	
	//VVI dp(n*2,VI(INF,0));
	VI dp(1000010,INF);
	//rep(i,n) dp[i]=0;
	dp[0]=0;
	rep(i,n){
		rep(w,k+1){
			ll cost=abs(h[i+w]-h[i]);
			dp[i+w]=min(dp[i+w],dp[i]+cost);
		}
	}
	res=dp[n-1];
	cout << res << "\n";
	return;
}

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


Measured memory_bytes: 9728
n = int(input())
S = [input() for _ in range(n)]

dict = {}
for s in S:
    dict[s] = dict.get(s, 0)+1
max_val = max(dict.values())
keys_of_max_val = [key for key in dict if dict[key] == max_val]
keys_of_max_val.sort()
for k in keys_of_max_val:
    print(k)

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

#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vec;
typedef vector<pll> vecp;
typedef map<ll, ll> mpll;

const long double PI  = 3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
#define LOCAL 3
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


void solve()
{
	char c;
	cin>>c;
	c++;
	cout<<c<<endl;
}


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

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

#define ll long long
#define ii pair<int, int>
#define debug(x) cerr << #x << " = " << x << endl;

const int MAX = 3e3 + 100;
int dp[MAX][MAX];
pair<int, ii> p[MAX][MAX];
string s, t;

int dp_solve(int idxs, int idxt)
{
	if(idxs < 0 || idxt < 0)
		return 0;

	int &ans = dp[idxs][idxt];
	if(~ans) return ans;
	auto &parent = p[idxs][idxt];

	parent = {-1, {-1, -1}};
	ans = 0;
	int tmp = dp_solve(idxs-1, idxt);
	if(tmp > ans && idxs-1 >= 0)
	{
		ans = tmp;
		parent = {0, {idxs-1, idxt}};
	}

	tmp = dp_solve(idxs, idxt-1);
	if(tmp > ans && idxt-1 >= 0)
	{
		ans = tmp;
		parent = {0, {idxs, idxt-1}};
	}

	tmp = dp_solve(idxs-1, idxt-1) + 1;
	if(s[idxs] == t[idxt] && tmp > ans)
	{
		ans = tmp;
		parent = {1, {idxs-1, idxt-1}};
	}
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);  cout.tie(NULL);
	cin >> s >> t;
	memset(dp, -1, sizeof dp);
	for(int i = 0; i < MAX; i++)
		for(int j = 0; j < MAX; j++)
			p[i][j] = {-1, {0, 0}};
	int ss = (int) s.size() - 1, st = (int) t.size() - 1;
	dp_solve(ss, st);
	auto cur = p[ss][st];
	string ans = "";
	while(cur.first != - 1)
	{
		if(cur.first == 1)
			if(cur.second.first + 1 <= ss)
				ans += s[cur.second.first + 1];
		if(cur.second.first >= 0 && cur.second.second >= 0)
			cur = p[cur.second.first][cur.second.second];
		else
			break;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 150912
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 5000000007000000000
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int n, t, q;
int a[123456], d[123456], h[123456];
signed main() {
	cin >> n >> t >> q;
	for1(i, n) { cin >> a[i] >> d[i]; h[i] = (d[i] == 1 ? mod : -mod); }
	for1(i, n - 1) {
		if (d[i] == 1 && d[i + 1] == 2) {
			h[i] = (a[i] + a[i + 1]) / 2;
			h[i + 1] = h[i];
			int j = i - 1;
			while (j && d[j] == 1) { h[j] = h[i]; j--; }
			while (i + 1 <= n && d[i + 1] == 2) { h[i + 1] = h[i]; i++; }
		}
	}
	for1(i, q) {
		int p; cin >> p;
		if (d[p] == 1) cout << min(h[p], a[p] + t);
		else cout << max(h[p], a[p] - t);
		cout << endl;
	}
}


Measured memory_bytes: 5440
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 3003, M = 998244353;

int dp[N][N], a[N];

signed main()
{
	IO_OP;
	
	int n, s;
	cin >> n >> s;
	for(int i = 1; i <= n; i++) cin >> a[i];
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= s; j++) {
			dp[i][j] = (dp[i][j] + dp[i - 1][j] * 2 % M) % M;
			if(j - a[i] >= 0) {
				dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i]]) % M;
			}
		}
	}
	cout << dp[n][s] << endl;
	
}





Measured memory_bytes: 74064
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <bits/stdc++.h>
#include <set>
#include <vector>
#include <queue>
#include <bitset>
#define NL << endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define fill(x, y) memset(x, y, sizeof(y))
#define debug(x)                          \
    {                                     \
        cerr << #x << " = " << x << endl; \
    }
#define inarr(arr, n)                            \
    {                                       \
        for(int i =0;i<n;i++){              \
            cin >> arr[i];                  \
        }                                   \
    }
typedef long long ll;
const int MOD = 1e9 + 7;
using namespace std;

void solve()
{
     ll n; cin >> n;
     ll dp[n][3]; 

     ll a, b, c;
     
     for(int i =0;i<n;i++){
         cin >> a >> b >> c;
        if(i==0){
            dp[0][0] = a;
            dp[0][1] = b;
            dp[0][2] = c;
        }
        else{
            dp[i][0] = a + max(dp[i-1][1], dp[i-1][2]);
            dp[i][1] = b + max(dp[i-1][0], dp[i-1][2]);
            dp[i][2] = c + max(dp[i-1][1], dp[i-1][0]);
        }


     }
     cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));

}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; t = 1; 
    // int t; cin >> t;
    while (t--)
        solve();
}


Measured memory_bytes: 5896
import java.io.*
import java.util.*

// N以下で a % b >= Kとなる(a,b)の組
fun solve(N: Int, K: Int) {
    // N = b*p + r
    // p*(b-k) + max(0, r-K)
    if (K == 0){
        println(N.toLong()*N.toLong())
        return
    }
    var ans = 0L
    for (b in K+1..N) {
        // remainder = p*{0,1,2...b-1} + {0,1,2,...r}
        val r = N % b
        val p = (N - r) / b
        ans += p * (b - K) + Math.max(0, r - K + 1)
    }
    println(ans)

    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val K = sc.next().toInt()
    solve(N, K)
}


Measured memory_bytes: 31516
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;

int main() {
  ll N,A,B,ans;
  cin>>N>>A>>B;
  if((B-A)%2==0) cout<<(B-A)/2<<endl;
  else cout<<min(N-B,A-1)+1+(B-A)/2<<endl;
}	


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

// += すれば-vを考える必要がない

int bill[4][3][10] = {};

int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int n;
    cin >> n;
    
    REP(i, n)
    {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        --b;--f;--r;

        bill[b][f][r] += v;
    }

    REP(i,4)
    {
        REP(j,3)
        {
            REP(k,10)
            {
                cout << " " << bill[i][j][k];
            }
            cout << endl;
        }
        if(i != 4 - 1)
        {
            cout << "####################" << endl;
        }
    }
    //cout << endl;

    return 0;    
}




Measured memory_bytes: 3100
def myAnswer(S:str)-> str:
   #len(S)が2の時種類数が１以外ならOK
   dic = {"a":0,"b":0,"c":0}
   for s in S:
      dic[s]+= 1
   # print(dic)
   dic2 = sorted(dic.values(),reverse = True)
   sub = dic2[0] - dic2[1] + dic2[1] - dic2[2]
   # print(dic2)
   if(sub >=2):
      return "NO"
   else:
      return "YES"
def modelAnswer():
   return
def main():
   S = (input())
   print(myAnswer(S))
if __name__ == '__main__':
   main()




Measured memory_bytes: 3188
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B&lang=ja
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (true) {
        int N, X;
        cin >> N >> X;
        if (N == 0 && X == 0) {
            break;
        }
        int cnt = 0;
        FOR(i, 1, N + 1) FOR(j, i + 1, N + 1) FOR(k, j + 1, N + 1) {
            if (i + j + k == X) {
                cnt++;
                break;
            }
        }
        cout << cnt << endl;
    }

    return 0;
}



Measured memory_bytes: 3216
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

x = 1
y = 1
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]

    m = max(-(-x // a), -(-y // b))
    x = m * a
    y = m * b
print(x + y)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string s;
int n;

inline bool check(int x) {
    if ((n - x) & 1) return false;
    int m = (n - x) / 2;
    for (int i = 0; i < m; ++i) {
        if (s[i] != s[m + i]) return false;
    }
    return true;
}

int main() {
    cin >> s;
    n = s.length();
    for (int i = 1; i < n; ++i) {
        if (check(i)) {
            cout << n - i << endl;
            exit(0);
        }
    }
    return 0;
}


Measured memory_bytes: 3648