akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    string s, t;
    cin >> s >> t;
    set<int> index[26];
    rep(i, (int)s.size()) {
        index[s[i] - 'a'].emplace(i);
    }
    rep(i, (int)t.size()) {
        if (index[t[i] - 'a'].empty()) {
            cout << -1 << endl;
            return;
        }
    }
    ll ans = 0;
    int cur = 0;
    rep(i, (int)t.size()) {
        int j = t[i] - 'a';
        set<int>::iterator itr = index[j].lower_bound(cur);
        if (itr == index[j].end()) {
            itr = index[j].begin();
            ans += s.size();
        }
        cur = *itr + 1;
    }
    ans += cur;
    cout << ans << endl;
}

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


Measured memory_bytes: 8536
/*            AUTHOR - SHIVAM GUPTA
                       Jalpaiguri Govt. Engg College             */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<ll> ve[100005];
ll vis[100005],z;
ll a[100005],dp[100005],n,k;

ll f(ll x)
{
    if(dp[x]!=-1){
        return dp[x];
    }
    ll z=1e9;
    if(x>=n-1)
    return 0;
    for(ll i=1;i<=k and i+x<n;i++)
    z=min(z,abs(a[x]-a[x+i])+f(x+i));
    // cout<<x<<" "<<z<<"\n";
    return dp[x]=z;
}

void solve()
{
    vector<ll> v;        vector<pair <ll,ll>> vp;
    map<ll,ll> mp;       set<ll> st;        multiset<ll> mst;
    ll m=0,i=0,j=0,c=0,l=0,r=0,p=0,q=0,x=0,y=0,z=0,flag=0,sum=0;
    // ll a[300005]={0},b[300005]={0},ans[300005];
    string s,t;
    cin>>n>>k;
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<=n;i++)dp[i]=-1;
    
    cout<<f(0)<<endl;
    
}
bool imp=false;int main()
{
    fio;
    int t=1;
    if(imp)
	cin>>t;
	ll j=t;
    while(t--){
    // cout<<"Case #"<<j-t<<": ";
    solve();}
    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 10010;
int n, w[N], v[M], W;
int dp[N][M];//从第i个物品到最后一个（n-1）物品，总重量不超过j的最大价值
int main(){
    scanf("%d %d", &n, &W);
    for(int i = 0; i < n; i++) scanf("%d %d", &v[i], &w[i]);

    for(int j = 0; j <= W; j++) dp[n][j] = 0;
    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j <= W; j++){
            if(w[i] > j){
                dp[i][j] = dp[i+1][j];
            }
            else{
                dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
            }
        }
    }
    printf("%d\n", dp[0][W]);
    return 0;
}


Measured memory_bytes: 7192
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int n, en, len;
vector<int> gr[200005];

void f(int u, int pr, int dt) {
	if(dt > len) len = dt, en = u;
	for(auto v:gr[u]) if(v!=pr) f(v, u, dt+1);
}

int main() {
	int i, t1, t2;
	cin >> n;
	while(--n) {
		scanf("%d%d", &t1, &t2);
		gr[t1].push_back(t2);
		gr[t2].push_back(t1);
	}
	f(1, 0, 0);
	f(en, 0, 0);
	puts(len%3==1 ? "Second" : "First");
	return 0;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e18 + 7;

ll f(ll b, ll n){
    if (b == 1) return -1;
    if (n < b) return n;
    return f(b, n/b) + n%b;
}


int main (){
    ll n, s, d;

    cin >> n >> s;

    d = n - s;

    if (d < 0){
        cout << "-1" << endl;
    }
    else if (d == 0){
        cout << n+1  << endl;
    }
    else {
        ll ans = mod;

        for (int i=1; i<=sqrt(d); i++){
            if (d%i != 0) continue;

            ll b = i+1;

            if (f(b, n) == s) ans = min(ans, b);

            b = d/i+1;

            if (f(b, n) == s) ans = min(ans, b);
        }

        if (ans != mod) cout << ans << endl;
        else cout << "-1" << 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 = sc.nextInt();
        
        int[] array = new int[n];
 
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }

        int ans = 0;
        int num = 1;

        for (int i = 0; i < n; i++) {
            if (array[i] == num) {
                num++;
            } else {
                ans++;
            }
        }

        if (num == 1) {
            ans = -1;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 77168
#include<iostream>
#define REP(i,s,n) for(int i=s ; i < n ; i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int main(){

  int n,m;
  int card1[100],card2[100];
  int sum1,sum2;
  bool flag;
  
  while(1){
    
    cin >>n>>m;
    if(n == 0 && m == 0)break;
    
    sum1=0,sum2=0;
    flag=false;
    
    rep(i,n){
      cin >>card1[i];
      sum1+=card1[i];
    }
    rep(i,m){
      cin >>card2[i];
      sum2+=card2[i];
    }
    
    rep(i,n){
      rep(j,m){
	if(sum1-card1[i]+card2[j] == sum2-card2[j]+card1[i]){
	  cout <<card1[i]<<" "<<card2[j]<<endl;
	  flag=true;
	  break;
	}
      }
      if(flag)break;
    }
  
    if(!flag)cout <<"-1"<<endl;

  }
  
  return 0;  
}

Measured memory_bytes: 1160
import java.util.Scanner;

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

        int a = n / 100;
        int b = (n % 100) / 10;
        int c = n % 10;

        if (a < b || a < c) {
            System.out.println((a + 1) * 100 + (a + 1) * 10 + (a + 1));
        } else {
            System.out.println(a * 100 + a * 10 + a);
        }
    }
}








Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e16;
typedef long long ll;

int main(){

  double a, b, x; cin >> a >> b >> x;

  double S = x / a;

  if (S > (a * b) / 2){
    double tan = -1 / a * (2 * S / a - 2 * b);
    double ans = 90 * atan(tan) / asin(1);
    cout << setprecision(16) << ans << endl;
  }else{
    double tan = 2 * S /(b * b);
    double ans = 90 * atan(tan) / asin(1);
    cout << setprecision(16) << 90 - ans << endl;
  }
  
    
  return 0;
}


Measured memory_bytes: 256
N, K = map(int,input().split())
P = list(map(int,input().split()))
LIST = [0]
for i in range(N):
    LIST.append(LIST[i]+P[i])
MAX = 0
for i in range(N-K+1):
    tmp = LIST[i+K]-LIST[i]
    if MAX < tmp:
        MAX = tmp
print((MAX+K)/2)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }return 0; }
#define all(a)  (a).begin(),(a).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define vll vector<ll>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
const int INF = 1<<29; 
int N, A, B, C;
vector<int> L;

int rec(int i, int a, int b, int c) {
    if (i == N) {
        if (!a || !b || !c) return INF; 
        return abs(a - A) + abs(b - B) + abs(c - C); 
    }

    int res = rec(i+1, a, b, c);
    
    chmin(res, rec(i+1, a + L[i], b, c) + (a ? 10 : 0));
    chmin(res, rec(i+1, a, b + L[i], c) + (b ? 10 : 0));
    chmin(res, rec(i+1, a, b, c + L[i]) + (c ? 10 : 0));
    
    return res;
}

int main() {
    cin >> N >> A >> B >> C;
    L.resize(N);
    for (int i = 0; i< N; ++i) cin >> L[i];
    cout << rec(0,0,0,0) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define long long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar
using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
const int N= 1e5+10;
int n,k;
long p[N], a[N],s[N];
void input()
{
    cin>>n>>k;
    up(i,1,n) cin>>a[i], a[i]+= a[i-1];
}
void solve()
{

    up(i,1,n)
     if (a[i]- a[i-1]>0) p[i]+= a[i]- a[i-1];
    up(i,1,n) p[i]+= p[i-1];
    down(i,n,1)
     if (a[i]- a[i-1]>0) s[i]+= a[i]- a[i-1];
    down(i,n,1) s[i]+= s[i+1];

    long res= -1e15;
    up(i,1,n-k+1) res= max(res, p[i-1]+ s[i+k]+ max(0LL, a[i+k-1]- a[i-1]) );
    cout<<res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive

    #ifdef I_Love_Pork
    #define TASK "tmp"
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
	  #endif

    input();
    solve();

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<lint, int>;
const int MAXN = 200005;

string s;
int a, b, c, d;

bool ok(int l, int r){
	for(int i=l+1; i<r; i++){
		if(s[i-1] == '#' && s[i] == '#') return 0;
	}
	return 1;
}

int main(){
	int n;
	cin >> n >> a >> b >> c >> d;
	cin >> s;
	a--, b--, c--, d--;
	bool ans = ok(a, c) && ok(b, d);
	if(c > d){
		bool bad = 1;
		for(int i=b; i<=d; i++){
			if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.'){
				bad = 0;
			}
		}
		if(bad) ans = 0;
	}
	puts(ans ? "Yes" : "No");
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 char s[n+10];
 sc(s);
 ll w=0,e=0;
 rep(i,0,n){
  if(s[i]=='W')w++;
  else e++;
 }
 llpvec pair(n);
 //pair[i].first->自分より左で東を向いてる人
 //pair[i].second->自分より右で西を向いてる人
 pair[0].first=0;pair[0].second=w;
 ans=0;
 rep(i,0,n){
  if(i!=0)pair[i]={pair[i-1].first,pair[i-1].second};
  if(s[i]=='W')pair[i].second--;
  if(s[i-1]=='E'&&i!=0)pair[i].first++;
  if(pair[i].first+pair[i].second>ans)ans=pair[i].first+pair[i].second;
  //cout<<i<<" "<<pair[i].first<<" "<<pair[i].second<<" "<<ans<<endl;
 }
 ans=n-ans-1;
 pr(ans);
 return 0;}



Measured memory_bytes: 8284
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    from itertools import combinations
    n,m = map(int, input().split())
    print(n*(n-1)//2+m*(m-1)//2)

if __name__ == '__main__':
    main()



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

const int N = 300005;

long long  a[N], b[N], c[N];



int main() {

	long long n, minval = 9999999999999;

	cin >> n;

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

	for (int i = 1; i <= n; ++i) b[i] = b[i - 1] + a[i - 1];

	for (int i = n; i >= 0; --i) c[i] = c[i + 1] + a[i];

	for (int i = 1; i < n; ++i) {

		//cout<<c[i]<<" "<<b[i]<<"\n";

		minval = min(minval, abs(c[i] - b[i]));


	}

	cout << minval << '\n';






}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N,Ans=0;
    int A[114514]={};
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    int f=0;
    REP(i,N){
        if(A[i]!=0){
            f+=A[i];
        }else{
            Ans+=f/2;
            f=0;
        }
    }
    Ans+=f/2;
    cout << Ans << endl;
    return 0;
}   


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main(void){
  int A, B;
  char op;
  cin >> A >> op >> B;

  //演算が＋なら
  if(op == '+')
    cout << A+B << endl;
  //演算がーなら
  else if(op == '-')
    cout << A-B << endl;
  //例外処理
  else
    cout << "error" << endl;

  return 0;
}


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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if ( B - A == 0)
    cout << C << endl;
    if ( C - A == 0)
    cout << B << endl;
    if ( B - C == 0)
    cout << A << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL n, a[212345];
std::deque<LL>ans;

int main()
{
	in >> n;
	rep(i, n) { in >> a[i]; }

	rep(i, n)
	{
		if (i % 2 == 0) { ans.push_back(a[i]); }
		else { ans.push_front(a[i]); }
	}

	if (n % 2 == 1) { std::reverse(ans.begin(), ans.end()); }
	rep(i, n - 1) { out << ans[i] << " "; }
	out << ans[n - 1] << std::endl;
	return 0;
}

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

int main() {
  string S;
  char a, b, c, d;
  cin >> S;
  a = S.at(0);
  b = S.at(1);
  c = S.at(2);
  d = S.at(3);
  if ((a==b) || (b==c) || (c==d)) cout << "Bad" << endl;
  else cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000003
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n;
vector<vector<int>> g;
vector<int> c;

int ans,cnt;
vector<int> ansvec;
void dfs(int v){
    if(ansvec[v])return;
    ansvec[v]=c[cnt++];
    ans+=ansvec[v];
    for(int i:g[v]){
        dfs(i);
    }
}

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    g.resize(n); c.resize(n); ansvec.resize(n);
    rep(i,n-1){
        int a,b; cin>>a>>b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,n)cin>>c[i];
    sort(all(c),greater<int>());

    dfs(0);
    cout<<ans-c[0]<<endl;
    rep(i,n-1)cout<<ansvec[i]<<' ';
    cout<<ansvec[n-1]<<endl;

}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout<<a[j]<<" "
#define wh(t) ll t; cin>>t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define arr(a,n) ll a[n]; fab(i,0,n) cin>>a[i]
#define showdp(d,n,m) fab(i,0,n){ fab(j,0,m) if(d[i][j]==-1 || d[i][j]>9) cout<<d[i][j]<<" "; else cout<<" "<<d[i][j]<<" "; cout<<endl; }
#define prs(u) cout<<u<<" "
#define fab(i,a,b) for(ll i=a;i<b;i++)
#define fba(i,b,a) for(ll i=b;i>=a;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 1000000007
#define MAX 10000007
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define vvl vector<vl>
#define mxe(x,n) *max_element(x,x+n)
#define mne(x,n) *min_element(x,x+n)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
const ll N =(ll)3e5;
const ll inf =(ll)1e18+7;
const ll mod =(ll)1e9+7;
 
bool rsort1(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll,ll> &a,const pair<ll,ll> &b) { return (a.second>b.second);}
bool sort2(const pair<ll,ll> &a,const pair<ll,ll> &b){ return (a.second < b.second);}
 
bool isPrime(ll p)
{
    for(ll i=2;i*i<=p;i++)
        if(p%i==0)
            rr false;
    rr true;
}
 
void sieve(ll n,vl &v)
{
    v.pb(2);
    bool prime[n+1];
    memset(prime,true,sizeof(prime));
    for(ll i=3;i*i<=n;i+=2)
        if(prime[i])
            for(ll j=i;j*i<=n;j+=2)
                prime[j*i]=false;
        
    for(ll i=3;i<=n;i+=2)
        if(prime[i])
            v.pb(i);
}

ll phi(ll n)
{
    ll result=n;
    for(ll p=2;p*p<=n;p++)
    {
        if(n%p==0)
        {
            while(n%p==0)
                n/=p;
            result-=result/p;
        }
    }

    if(n>1)
        result-=result/n;
    return result;
}

ll nCr(ll n, ll k) 
{ 
    ll C[n + 1][k + 1]; 
    ll i, j;  
    for (i = 0; i <= n; i++) 
    { 
        for (j = 0; j <= min(i, k); j++) 
        { 
            if (j == 0 || j == i) 
                C[i][j] = 1;  
            else
                C[i][j] = C[i - 1][j - 1] + 
                          C[i - 1][j]; 
        } 
    }
    return C[n][k]; 
} 


int main()
{
	sup;
    
    ll h,a;
    cin>>h>>a;
    cout<<(h/a)+(h%a>0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
void solve(){
	int n;
	cin>>n;
	int m = n, s = 0;
	while(n){
		s+=n%10;
		n/=10;
	}
	if(m%s) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define rrep(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define chmax(a,b) (a) = max((a),(b))
#define pb push_back
#define sz size()
using namespace std;
typedef vector<int> vi;

struct SCC{
  int V;
  vector<vi> G,rG;
  vi order;

  int sccV;
  vector<vi> sccG, group;
  vi sccID;

  SCC(const vector<vi> &graph):G(graph){
    V = G.sz; rG.resize(V,vi());
    rep(i,V)for(int to : G[i]) rG[to].pb(i);

    vi use(V,0);
    order.clear();
    rep(i,V) if(!use[i]) fdfs(i,use);
    
    use = vi(V,0); sccID.resize(V);
    sccV = 0;
    rrep(i,order.sz) if(!use[order[i]]) rdfs(order[i], sccV++, use);

    group.resize(sccV,vi());
    rep(i,V) group[sccID[i]].pb(i);

    sccG.resize(sccV,vi());
    rep(i,V) for(int to : G[i]){
      if(sccID[i] != sccID[to]) sccG[sccID[i]].pb(sccID[to]);
    }
    rep(i,sccV){
      sort(all(sccG[i]));
      sccG[i].erase(unique(all(sccG[i])), sccG[i].end());
    }
  }

  void fdfs(int v, vi &use){
    use[v] = 1;
    for(int to : G[v]) if(!use[to]) fdfs(to,use);
    order.pb(v);
  }

  void rdfs(int v, int k, vi &use){
    use[v] = 1; sccID[v] = k;
    for(int to : rG[v]) if(!use[to]) rdfs(to, k, use);
  }
};

int main(){
  int n;
  while(cin >> n){
    if(n==0)break;

    vector<vi> g(n);
    vector<double> p(n);
    rep(i,n){
      int m, a;
      cin >> p[i] >> m;
      rep(j,m){
	cin >> a; a--;
	g[i].pb(a);
      }    
    }
    
    SCC scc(g);
    int nn = scc.sccV;
    vi deg(nn,0);
    rep(i,nn){
      for(int to : scc.sccG[i]){
	deg[to]++;
      }
    }

    double ans = 1;
    rep(i,nn){
      if(deg[i] == 0){
	double x = 1;
	for(int v : scc.group[i]){
	  x *= p[v];
	}
	ans *= 1-x;
      }
    }
    
    cout << fixed << setprecision(9) << ans << endl;
  }
}

Measured memory_bytes: 3316
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    a=[]
    for i in range(n):
        a.append(int(input()))
    s=sum(a[0:k])
    max=s
    for i in range(k,n):
        s=int(s+a[i]-a[i-k])
        if max<s:
            max=s
    print(max)


Measured memory_bytes: 9868
Lis=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
N=input()
for i in range(26):
  if N == Lis[i]:
    print(Lis[i+1])

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,r[3],l[3];
	while(true){
	cin>>n;
	if(n==0)
		break;
	string f;
	for(int i=0;i<3;i++)
		r[i]=0,l[i]=0;
	int count=0;
	for(int i=0;i<n;i++){
		cin>>f;
		if(f=="ru")
			r[0]=min(1,r[0]+1);
		if(f=="rd")
			r[0]=max(0,r[0]-1);
		if(f=="lu")
			l[0]=min(1,l[0]+1);
		if(f=="ld")
			l[0]=max(0,l[0]-1);
		if(r[0]==l[0]&&r[2]==l[2]&&r[0]!=r[2])
			count++;
		r[2]=r[1],r[1]=r[0];
		l[2]=l[1],l[1]=l[0];
	}
	cout<<count<<endl;
	}
	return 0;
}

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

int m[101][101];
int visit[101];
int d[101];
int f[101];
int n, t;

void dfs(int u){
  visit[u] = 1;
  d[u] = t;
  t++;
  
  for(int i = 0; i < n; ++i){
    if(m[u][i] == 1 && visit[i] == 0){
      dfs(i);
    }
  }

  f[u] = t;
  t++;
}

main()
{
  int u, k, v;
  t = 1;

  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> u >> k;
    --u;
    for(int j = 0; j < k; ++j){
      cin >> v;
      v--;
      m[u][v] = 1;
    }
  }

  for(int i = 0; i < n; ++i){
    if(visit[i]==0){
      dfs(i);
    }
  }

  for(int i=0; i < n; ++i){
    cout << i+1 << " " << d[i] << " " << f[i] << endl;
  }

  return (0);
}



Measured memory_bytes: 3112
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

int qpow(int b, int e) {
    if(e == 0) return 1;
    if(!(e&1)) return qpow(1ll*b*b%MOD, e>>1);
    return 1ll*qpow(b,e-1)*b%MOD;
}

int fact[400005];

int choo(int n, int k) {
    return 1ll * fact[n] * qpow(fact[k], MOD-2) % MOD * qpow(fact[n-k], MOD-2) % MOD;
}

int N;

inline int f(int k) {
    return choo(2*N-k-1, N-k-1);
}

inline int e(int k) {
    return 1ll * choo(N-1, k) * choo(N, k) % MOD;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    N = n;
    fact[0] = 1;
    rep1(i, 2*n) fact[i] = 1ll * fact[i-1] * i % MOD;
    if(k+1 >= n) {
        cout << f(0) << endl;
        return 0;
    }
    int ans = 0;
    rep(i, k+1) ans = (ans + e(i)) % MOD;
    cout << ans << endl;
}



Measured memory_bytes: 1792
n = int(input())
s = input()
l_1 = []

cnt = 0
for i in s[::-1]:
    if i =='R':
        cnt += 1
    else:
        l_1.append(cnt)

l_1.reverse()

def get_res(l_1):
    for i,j in enumerate(l_1):
        if i+1 == j:
            return j
        elif i+1 > j:
            return i
    return len(l_1)

print(get_res(l_1))

Measured memory_bytes: 11952
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>
#include<regex>
#include<math.h>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}


int main() {
	string s, t;
	cin >> s >> t;

	lli cnt = 0;
	rep0(i, 3)if (s[i] == t[i])cnt++;
	cout << cnt;
}


Measured memory_bytes: 256
### constant

N = 1001

### subroutines

def make_fibo(v)
  f0 = f1 = 1
  fibos = []
  v.times do
    f = (f0 + f1) % N
    fibos << f
    f0, f1 = f1, f
  end
  fibos
end

### main

while line = gets
  v, d = line.split.map(&:to_i)

  fibos = make_fibo(v)

  $nbrs = v.times.map{[]}

  for i in (0...(v - 1))
    for j in ((i + 1)...v)
      if (fibos[i] - fibos[j]).abs < d
        $nbrs[i] << j
        $nbrs[j] << i
      end
    end
  end
  #p $nbrs

  count = 0
  used = v.times.map{false}

  for i in (0...v)
    if ! used[i]
      count += 1
      used[i] = true
      q = [i]

      while ! q.empty?
        u = q.shift
        for v in $nbrs[u]
          if ! used[v]
            used[v] = true
            q << v
          end
        end
      end
    end
  end

  puts count
end

Measured memory_bytes: 10256
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

vector<ll> d, p;

ll solve(ll n, ll x) {
    if (n == 0) return 1;
    if (x == 1) return 0;
    if (x <= d.at(n - 1) + 1) return solve(n - 1, x - 1);
    if (x == d.at(n - 1) + 2) return p.at(n - 1) + 1;
    if (x <= d.at(n - 1) * 2 + 2) return solve(n - 1, x - d.at(n - 1) - 2) + p.at(n - 1) + 1;
    return p.at(n - 1) * 2 + 1;
}

int main() {
    ll n, x;
    scanf("%lld%lld", &n, &x);
    d.resize(n + 1), p.resize(n + 1);
    d.at(0) = 1, p.at(0) = 1;
    for (ll i = 0; i < n; ++i) d.at(i + 1) = 2 * d.at(i) + 3, p.at(i + 1) = 2 * p.at(i) + 1;
    printf("%lld\n", solve(n, x));
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<int> s(N, 0);
  rep(i, K) {
    int d;
    cin >> d;
    rep(i, d) {
      int a;
      cin >> a;
      a--;
      s[a]++;
    }
  }
  int result = 0;
  rep(i, N) {
    if (s[i] == 0) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3624
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

n = load()
if '7' in str(n):
    print('Yes')
else:
    print('No')



Measured memory_bytes: 9516
s=input()
if s[0]=='A':
  s=s.lstrip('A')
else:
  print('WA')
  exit()

if s[1:-1].count('C')==1:
  s=s.replace('C','')
else:
  print('WA')
  exit()
  
if s.islower():
    print('AC')
else:
  print('WA')


Measured memory_bytes: 2940
///cREATED bY BERNARB.01
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef priority_queue<int,vector<int>,greater<int>> pqil;
typedef priority_queue<int> pqig;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef priority_queue<pii> pqiig;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<int, int> mii;
#define mid ((l+r)/2)
#define PB push_back
#define PP pop_back
#define PF push_front
#define DF pop_front
#define F first
#define S second
#define MP make_pair
#define C continue
#define B break
#define R return
#define sz(v) (int)(v).size()
#define len(s) (int)(s).length()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define clr(arr, x) memset((arr), (x), sizeof (arr))
#define loop(n) for(int i=0; i<(n); i++)
#define lop(a, n) for(int i=(a); i<(n); i++)
#define jloop(n) for(ll j=0; j<(n); j++)
#define kloop(n) for(ll k=0; k<(n); k++)
#define rloop(n) for(ll i=(n)-1; i>=0; i--)
#define sgm(y) (((y)*((y)+1))/2)
const ll INF = 2e17+423;
const ll mod = 1e9+7; //998244353;
const ld pi = acos(-1.0);
const ld cmpf = 1e-9;
//__int128_t
//      -ASCII-
//a -> z | A -> Z | 0 -> 9
//97 122 | 65  90 | 48  57
#define endl '\n'
ll po(ll,ll);















int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll a, b, k;
  cin >> a >> b >> k;
  if(k > a) k-=a, a = 0;
  else a-=k, k = 0;
  if(k > 0){
    if(b > k) b-=k, k=0;
    else k-=b, b = 0;
  }
  cout << a << " " << b;
  R 0;
}
/*

*/




























































ll po(ll x, ll n){
  if(n==0) R 1;
  ll y = po(x, n/2);
  y = ((y)*(y));
  if(n%2) y = (y*(x));
  R y;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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; }

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

	lint n, m;
	cin >> n >> m;
	co(abs((n - 2)*(m - 2)));
	gc();
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<cmath>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>



using namespace std;

string s;

int main() {
	cin>>s;
	if(s[0]=='7'||s[1]=='7'||s[2]=='7')cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, q, a[N], lp[N], ans[N], seg[4 * N];
pair<int, int> nxt[N];
struct A
{
	int l, r, idx;
}quer[N];
bool cmp(A lhs, A rhs)
{
	if (lhs.r != rhs.r)
		return lhs.r < rhs.r;
	else
		return lhs.idx < rhs.idx;
}
void upd(int idx, int start, int end, int id)
{
	if (start > end || start > id || end < id)
		return;
	else if (start == end)
		seg[idx] ++;
	else
	{
		int mid = (start + end) / 2;
		upd(2 * idx + 1, start, mid, id);
		upd(2 * idx + 2, mid + 1, end, id);
		seg[idx] = seg[2 * idx + 1] + seg[2 * idx + 2];
	}
}
int query(int idx, int start, int end, int l, int r)
{
	if (start > end || start > r || end < l)
		return 0;
	else if (start >= l && end <= r)
		return seg[idx];
	else
	{
		int mid = (start + end) / 2;
		int ls = query(2 * idx + 1, start, mid, l, r);
		int rs = query(2 * idx + 2, mid + 1, end, l, r);
		return (ls + rs);
	}
}
int main(int argc, char const *argv[])
{
	cin >> n >> q;
	for (int i = 0; i < n; ++i)
	{
		lp[i] = -1;
		cin >> a[i];
		a[i] --;
	}
	for (int i = n - 1; i >= 0; --i)
	{
		nxt[i].second = i;
		if (lp[a[i]] == -1)
			nxt[i].first = n;
		else
			nxt[i].first = lp[a[i]];
		lp[a[i]] = i;
	}
	
	for (int i = 0; i < q; ++i)
	{
		cin >> quer[i].l >> quer[i].r;
		quer[i].l --;
		quer[i].r --;
		quer[i].idx = i;
	}
	
	sort(nxt, nxt + n);
	sort(quer, quer + q, cmp);
	int j = n - 1;
	for (int i = q - 1; i >= 0; --i)
	{
		while (j >= 0 && nxt[j].first > quer[i].r)
		{
			upd(0, 0, n - 1, nxt[j].second);
			
			j --;
		}
		ans[quer[i].idx] = query(0, 0, n - 1, quer[i].l, quer[i].r);
	}
	for (int i = 0; i < q; ++i)
	{
		cout << ans[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 23408
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s,t;
  int n,m;
  cin >>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());
  n = s.size();
  m = t.size();
  if(n<m){
    if(s<=t.substr(0,n))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }else{
    if(s<t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int N,M,S;
const int MOD =100000;
ll dp[3010][51];
int main(){
	while(cin>>N>>M>>S,N||M||S){
		memset(dp,0,sizeof(dp));
		dp[0][0] = 1;
		for(int i =1;i <=M;i++){
			for(int j =N*N;j >=1;j--){
				for(int k = i;k <=S;k++){
					if(k-i>=0){
						dp[k][j]=(dp[k][j]+dp[k-i][j-1])%MOD;
					}
				}
			}
		}
		cout <<dp[S][N*N]<<endl;
	}
	return 0;
}

Measured memory_bytes: 2364
import java.util.Scanner;
import java.util.Arrays;

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

	int N = scan.nextInt();
	int L = scan.nextInt();

	String[] s_ = new String[N];
	for(int i = 0; i < N; i++){
	    s_[i] = scan.next();
	}

	Arrays.sort(s_);

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


Measured memory_bytes: 22100
N,M=gets.split.map &:to_i;r=N;A=$<.map{|e|h={};e.split.each{|f|h[f.to_i]=1};h};(M-1).times{h=Hash.new 0;A.map{|e|h[e.first[0]]+=1};k,v=h.max_by &:last;r=[r,v].min;A.map{|e|e.delete k}};p r

Measured memory_bytes: 10108
=begin
1, 入力された値を出力し、その合計を最後に出力する
1.1 入力された値を last(配列) に追加する
2, last を列ごとに足した数値を ans(配列)に追加する
3, ans の各数値とその合計を出力する
=end

r, c = gets.split.map(&:to_i)

A = Array.new(r){
  arr = gets.split.map(&:to_i)
  arr << arr.sum
}

last = []
(c+1).times do |i|
  last << A.inject(0){|sum, v|
    sum + v[i]
  }
end

A.each{|v|
  puts v.join(' ')
}
puts last.join(' ')


Measured memory_bytes: 7056
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main () {
    int n, k, l; cin >> n >> k >> l;
    UnionFind uf(n);
    rep(i, k) {
        int p, q; cin >> p >> q;
        p--; q--;
        uf.unite(p, q);
    }
    UnionFind uf2(n);
    rep(i, l) {
        int r, s; cin >> r >> s;
        r--; s--;
        uf2.unite(r, s);
    }
    //rep(i, n) uf.find(i), uf2.find(i);
    map<P, int> mp;
    rep(i, n) mp[{uf.find(i), uf2.find(i)}]++;
    rep(i, n) cout << mp[{uf.find(i), uf2.find(i)}] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 16036
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b))cout<<"A"<<endl;
  else cout<<"B"<<endl;

}

Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

const long long MOD = 998244353;
// const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n;
  std::cin>>n;

  ll ans=MOD;

  std::vector<ll> w(n);
  rep(i,0,n)std::cin>>w[i];

  rep(i,0,n+1){
    ll sum1=0,sum2=0;
    rep(j,0,i)sum1+=w[j];
    rep(j,i,n)sum2+=w[j];
    chmin(ans,std::abs(sum1-sum2));
  }  

  std::cout<<ans<<"\n";

  return 0;
}


Measured memory_bytes: 256
// Problem : E - Coprime
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000000

//Solution

int spf[N+5];
int n,a[N];

void sieve(){
    for(int i=2;i<=N;i++) spf[i] = i;
    for(int i=4;i<=N;i+=2) spf[i] = 2;
    for(int i=3;i*i<=N;i+=2){
        if(spf[i] == i){
            for(int j=i*i;j<=N;j+=i){
                if(spf[j] == j) spf[j] = i;
            }
        }
    }
}

void solve(){
    sieve();
    cin>>n;
    int g = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        g = __gcd(g,a[i]);
    }
    if(g > 1){
        cout<<"not coprime\n";
        return;
    }
    set<int> primes;
    for(int i=0;i<n;i++){
        int x = a[i];
        while(x != 1){
            int cur = spf[x];
            if(primes.count(cur)){
                cout<<"setwise coprime\n";
                return;
            }
            primes.insert(cur);
            while(x % cur == 0){
                x /= cur;
            }
        }
    }
    cout<<"pairwise coprime\n";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    for(int test=1;test<=tests;test++){
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 19132
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
map<string,P> range;
stack<set<int> > num;

int getNum(string s){
  int res=0;
  for(int i=0;i<s.size();i++)
    res=res*10+s[i]-'0';
  return res;
}

int main(){
  int n,m,a,b;
  string s;
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>s>>a>>b;
    range[s]=P(a,b);
  }
  bool ans=false;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    set<int> x;
    if('0'<=s[0]&&s[0]<='9'){
      x.insert(getNum(s));
      num.push(x);
    }
    else if('a'<=s[0]&&s[0]<='z'){
      P r=range[s];
      for(int j=r.first;j<=r.second;j++)
	x.insert(j);
      num.push(x);
    }else{
      set<int> B=num.top(); num.pop();
      set<int> A=num.top(); num.pop();
      set<int> C;
      set<int>::iterator i1=A.begin();
      while(i1!=A.end()){
	set<int>::iterator i2=B.begin();
	while(i2!=B.end()){
	  int n1=(*i1),n2=(*i2);
	  if(s=="+")C.insert((n1+n2)%256);
	  if(s=="-")C.insert((n1-n2+256)%256);
	  if(s=="*")C.insert((n1*n2)%256);
	  if(s=="/"){
	    if(!n2){
	      ans=true;
	      break;
	    }
	    C.insert((n1/n2)%256);
	  }
	  i2++;
	}
	if(ans)break;
	i1++;
      }
      if(ans)break;
      num.push(C);
    }
  }
  if(ans)cout<<"error"<<endl;
  else cout<<"correct"<<endl;
  return 0;
}

Measured memory_bytes: 3240
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define SIZE 100010

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

Measured memory_bytes: 1920