akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

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

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

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

ll N,P;
void input(){
    fast_io();
    cin >> N >> P;
}

map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


int solve(){
    auto pf = prime_factor(P);
    DBG(P)
    ll ans = 1;
    DBG(pf)
    for(auto p:pf) {
        DBG(p)
        while(p.second>=N) {
            ans *= p.first;
            p.second -= N;
            }
        }
    cout << ans << endl;
    return 0;
}   

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        double p;
        double[] d = new double[n];
        for(int i = 0; i < n; i++){
            p = Double.parseDouble(sc.next());
            d[i] = (p+1)/2;
        }
        
        double a = 0;
        for(int i = 0; i < k; i++){
            a += d[i];
        }
        double max = a;
        for(int i = k; i < n; i++){
            a -= d[i-k];
            a += d[i];
            if(a > max) max = a;
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 61320
#include <iostream>
#include <algorithm> 
#include <vector>
#include <cmath>


using namespace std;

int main () {
    int N, K;
    cin >> N >> K;
    vector <int>h(N);
    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
    }
    
    vector <int>dp(N);
    dp[0] = 0;
    for (int i = 1 ; i < N ; i++)
    {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        for (int j = 2 ; j <= K ; j++) {
            if (i - j < 0) break;
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << dp[N - 1] <<endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9) + 7;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int[] nums = new int[3];
		for (int i = 0; i < 3; i++) {
			nums[i] = sc.nextInt();
		}
		
		Arrays.sort(nums);
		
		int k = sc.nextInt();
		while (k > 0) {
			nums[2] *= 2;
			k--;
		}
		
		System.out.println(nums[0] + nums[1] + nums[2]);
	}

    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 22484
#include<stdio.h>

int main(){
    int N;
    int A[2000];
    int i, j, k ,v;

    scanf("%d", &N);

    for(i=0; i<N; i++){
        if(i>0){
            printf(" ");
        }
        scanf("%d", &A[i]);
        printf("%d", A[i]);
    }
    printf("\n");

    for(i=1; i<N; i++){
        v = A[i];
        j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j = j - 1;
        }
        A[j+1] = v;
        for(k=0; k<N; k++){
            if(k>0){
                printf(" ");
            }
            printf("%d", A[k]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define rep(i,l,r) for (ll i=l;i<=r;i++)
ll N,M,a,b,c,t,ans,q[100007],qw[100007];
int main (){
	scanf("%lld",&N);
	rep(i,1,N) scanf("%lld",&q[i]);
	rep(i,1,N){
		ll p1=1,p2=N,s=0;
		while (p1+i<N){
			p1+=i;if (qw[p1]==i) break;s+=q[p1];qw[p1]=i;
			p2-=i;if (qw[p2]==i) break;s+=q[p2];qw[p2]=i;
			if (p2>i+1) ans=max(ans,s);
		}
	}
	printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n,m,qq;

/* add your algorithm here */

int main() {
  cin >> n >> m >> qq;
  int train[n+1][n+1];

  rep(i,n+1)rep(j,n+1) train[i][j] = 0;

  rep(i,m) {
    int l,r; cin >> l >> r;
    train[l][r]++;
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      train[i][j] += train[i-1][j];
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      train[i][j] += train[i][j-1];
    }
  }

  rep(i,qq) {
    int p,q; cin >> p >> q;
    int cnt = 0;
    cnt = train[q][q] + train[p-1][p-1] - train[p-1][q] - train[q][p-1];
    cout << cnt << endl;
  }
}


Measured memory_bytes: 1920
n=int(input())
l=list(map(int,input().split()))

l.sort()

ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if(l[k]<l[i]+l[j] and l[i]!=l[j] and l[j]!=l[k]):
                ans+=1


print(ans)

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

int main()
{
    int n; cin >> n;
    vector<string> w(n);
    for (int i = 0; i < n; i++) cin >> w[i];

    bool flag = true;
    for (int i = 1; i < n; i++) {
        if (w[i-1].back() != w[i].front()) flag = false;
        for (int j = 0; j < i-1; j++) {
            if (w[j] == w[i]) flag = false;
        }
    }

    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define int long long int
#define modulo 1000000007
using namespace std;
vector<int>adj[1005];
vector<int> ans;
int s=INF;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
    }
    for(int i=1;i<=n;i++){
        vector<int> vis(n+1,false);
        vector<int> tree(n+1);
        vector<int> arr;
        queue<int> bfs;
        bool yes=true;
        bfs.push(i);
        arr.pb(i);
   //     tree[i]=i;
        while(!bfs.empty()&&yes){
            int x=bfs.front();
            bfs.pop();
            vis[x]=true;
            for(int j=0;j<adj[x].size()&&yes;j++){
                int y=adj[x][j];
                if(y==i){
                    yes=false;
                    int curr=x;
                    while(curr!=i){
                        arr.pb(curr);
                        curr=tree[curr];
                    }
                    if(arr.size()<s){
                        ans=arr;
                        s=arr.size();
                    }
                    break;
                }
                if(vis[y])continue;
                tree[y]=x;
                bfs.push(y);
            }
        }
    }
    if(s==INF)cout<<-1;
    else {
        cout<<ans.size()<<"\n";
        for(int i=0;i<ans.size();i++)cout<<ans[i]<<"\n";
    }
}


Measured memory_bytes: 384
H,W = map(int,input().split())
if H != 1 and W != 1:
    if (H*W) % 2 == 0:
        print(int(H*W/2))
    elif (H*W) % 2 == 1:
        print(int((H*W+1)/2))
else:
    print(1)

Measured memory_bytes: 3060
ab = []
for i in range(3):
    ai, bi = map(int, input().split())
    ab.append(ai)
    ab.append(bi)

l = [0] * 4
for x in ab:
    l[x - 1] += 1

if max(l) == 3:
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3060
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static final int MAX_N = 30;
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[][] a = new int[n][MAX_N];
		for(int i=0; i<n; i++){
			int k = Integer.parseInt(sc.next());
            if (k == 0) break;
            for(int j=0; j<k; j++) {
                a[i][j] = sc.nextInt();
            }
		}
    	sc.close();
    	HashSet<Integer> hs = new HashSet<>();
    	for (int i=0; i<a[0].length;i++){
    		hs.add(a[0][i]);
    	}
    	hs.remove(0);
    	for(int i=0; i<n; i++){
    		HashSet<Integer> hso = new HashSet<>();
    		for (int j=0; j<a[i].length;j++){
        		hso.add(a[i][j]);
        	}
    		hs.retainAll(hso);
    	}
    	System.out.println(hs.size());
	}

}


Measured memory_bytes: 22100
#include<stdio.h>

int main(void)
{
  int a,b,c,aa,bb,cc;

  scanf("%d%d%d",&a,&b,&c);

   if(a > b){
    aa = b;
    b = a;
    a = aa;
}

   if(b > c){
    bb = c;
    c = b;
    b = bb;
}

   if(a > b){
    cc = b;
    b = a;
    a = cc;
}

  printf("%d %d %d\n",a,b,c);

  return 0;
}

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

using namespace std;

int main(void)
{
  int h,w; cin>>h>>w;
  vector< vector<char> > c(2*h,vector<char>(w));
  for(int i=0;i<2*h;i+=2){
    for(int j=0;j<w;j++){
      cin>>c[i][j]; c[i+1][j]=c[i][j];
    }
  }
  
  for(int i=0;i<2*h;i++){
    for(int j=0;j<w;j++){
      cout<<c[i][j];
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int temp = sc.nextInt();//気温
      
    	if(temp>=30){
			System.out.println("Yes");
    	}else{
        	System.out.println("No");
        }
    } 
}



Measured memory_bytes: 35676
using System;

namespace ABC060C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] bufs = Console.ReadLine().Split(' ');
            int N = Int32.Parse(bufs[0]);
            int T = Int32.Parse(bufs[1]);

            bufs = Console.ReadLine().Split(' ');

            int res = 0;
            int cut = 0;

            for (int i = 0; i < N; i++)
            {
                int t = Int32.Parse(bufs[i]);
                res = (t > cut) ? res + T : res + T - (cut - t);
                cut = t + T;
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 28512
n,k = map(int,input().split())
h = list(map(int,input().split()))

#降順にソートしたリストを作る
new_h = sorted(h,reverse=True)

#必殺技はカウントしない、攻撃はモンスターの体力を加算
ans = 0
for i in range(n):
    if i <= k-1:
        ans += 0
    else:
        ans += new_h[i]

print(ans)

Measured memory_bytes: 26024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int x,y;
  cin >> x >> y;
  if(x==y) {
    cout << 0 << endl;
    return 0;
  }
  if(abs(x) == abs(y)) {
    cout << 1 << endl;
    return 0;
  }
  if(x < y) {
    if(abs(x) < abs(y)) {
      if(x < 0) {
        cout << y+x+1 << endl;
        return 0;
      } else {
        cout << y-x << endl;
        return 0;
      }
    } else {
      if(y <= 0) {
        cout << -x+y << endl;
        return 0;
      } else {
        cout << -x-y+1 << endl;
        return 0;
      }
    }
  } else {
    if(abs(x) < abs(y)) {
      if(x < 0) {
        cout << -y+x+2 << endl;
        return 0;
      } else {
        cout << -y-x+1 << endl;
        return 0;
      }
    } else {
      if(y <= 0) {
        cout << y+x+1 << endl;
        return 0;
      } else {
        cout << -y+x+2 << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL  INF=1<<31;
const LL MOD=1000000007;



int main(){
     int n;
     cin>>n;
     vector<int> pr(n+1,1);
     for(int i=2;i<=n;++i){
          int x=i;
          for(int j=2;j<=i;++j){
               while(x%j==0){
                    x/=j;
               pr[j]++;
               }
          }
     }
     LL ans=1;
     for(int i=2;i<=n;++i){
          ans=ans%MOD*(pr[i])%MOD;
     }
     cout<<ans<<endl;
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


signed main(){

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

    unordered_map<int,int> m;
    for(int i = 0; i < n; ++i)
        ++m[a[i]];
    vector<int> v;
    for(auto& p : m)
        v.push_back(p.second);
    sort(v.begin(), v.end());
    vector<int> rui(n + 1, 0);
    vector<i64> cnt(n + 1, 0);
    for(int i = 0; i < v.size(); ++i)
        ++rui[v[i]];
    for(int i = n; i > 0; --i){
        cnt[i - 1] = cnt[i] + rui[i];
        rui[i - 1] += rui[i];
    }

    // rui[k]: k以上の物の数

    // k減らすのをc回できるかどうか
    auto f = [&](int k, int c){
        return n - cnt[c] >= 1LL * k * c;
    };

    for(int k = 1; k <= n; ++k){
        int ok = 0;
        while(f(k, ok + 1))
            ++ok;
        printf("%d\n", ok);
    }
}



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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010, INF = 0x3f3f3f3f;

int n, m;
int a[N];
set<int> S;

int main()
{
	scanf("%d%d", &n, &m);
	
	int mina = INF, maxd = -INF;
	for (int i = 0; i < n; i ++ )
	{
		scanf("%d", &a[i]);
		maxd = max(maxd, a[i] - mina);
		mina = min(mina, a[i]);
	}
	
	int res = 0;
	for (int i = 0; i < n; i ++ )
	{
		S.insert(a[i]);
		if (S.count(a[i] - maxd)) res ++ ;
	}
	
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int b,c,d;
	b=a%1000;
	a=a/1000;
	c=b%100;
	b=b/100;
	d=c%10;
	c=c/10;
	vector <int> n;
	n.push_back(a);
	n.push_back(b);
	n.push_back(c);
	n.push_back(d);
	int max=*max_element(n.begin(),n.end());
	if(max==a)
	{
			if(a+b+c+d==7)
		{
			cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a+b+c-d==7)
		{
			cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a+b-c+d==7)
		{
			cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a-b+c+d==7)
		{
			cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a+b-c-d==7)
		{
			cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a-b+c-d==7)
		{
			cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a-b-c+d==7)
		{
			cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a-b-c-d==7)
		{
			cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<"7"<<endl;
			exit(0);
		}
	}
	if(max==b)
	{
			if(a+b+c+d==7)
		{
			cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a+b+c-d==7)
		{
			cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a+b-c+d==7)
		{
			cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a+b-c-d==7)
		{
			cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<"7"<<endl;
			exit(0);
		}
		
	}
	if(max==c)
	{
			if(a+b+c-d==7)
		{
			cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a-b+c+d==7)
		{
			cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a-b+c-d==7)
		{
			cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a+b+c+d==7)
		{
			cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			
	}
	if(max==d)
	{
			if(a+b+c+d==7)
		{
			cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a+b-c+d==7)
		{
			cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a-b+c+d==7)
		{
			cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
			if(a-b-c+d==7)
		{
			cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<"7"<<endl;
			exit(0);
		}
	}
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		
		h = sc.nextInt();
		w = sc.nextInt();
		n = sc.nextInt();
		calc();
		
	}
	int h;
	int w;
	int n;
	public void calc(){
		String[][] map = new String[h][w];
		for(int i = 0; i < h; i++){
			String line = sc.next();
			for(int j = 0; j < w; j++){
				map[i][j] = line.substring(j, j+1);
			}
		}
		
		boolean t = false;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w-1; j++){
				String[][] checkMap = new String[h][w];
				for(int a = 0; a < h; a++){
					for(int b = 0; b < w; b++){
						checkMap[a][b] = map[a][b];
					}
				}
				if(!(checkMap[i][j].equals(".") && checkMap[i][j+1].equals("."))){
					String s = checkMap[i][j];
					checkMap[i][j] = checkMap[i][j+1];
					checkMap[i][j+1] = s;
					fall(checkMap);
					t = check(checkMap);
					if(t) break;
				}
			}
			if(t) break;
		}
		if(t) System.out.println("YES");
		else System.out.println("NO");
	}


	public boolean check(String[][] map){
		boolean t = true;
		while(t){
			t = delete(map);
			fall(map);
			t=t;
		}
		for(int i = 0;i < h; i++){
			for(int j = 0; j < w; j++){
				if(!map[i][j].equals(".")) return false;
			}
		}
		return true;
	}
	
	public boolean delete(String[][] map){
		ArrayList<Integer[]> wlist = new ArrayList<Integer[]>();
		for(int i = 0; i < h; i++){
			String s = map[i][0];
			int yoko = 1;
			int x = i;
			int y = 0;
			for(int j = 1; j < w; j++){
				if(map[i][j].equals(s) && !s.equals(".")){
					yoko++;
				}
				else{
					if(yoko >= n) 
						wlist.add(new Integer[]{x,y,yoko});
					s = map[i][j];
					yoko = 1;
					x = i;
					y = j;
				}
			}
			if(yoko >= n)
				wlist.add(new Integer[]{x,y,yoko});
		}

		ArrayList<Integer[]> hlist = new ArrayList<Integer[]>();
		for(int j = 0; j < w; j++){
			String s = map[0][j];
			int tate = 1;
			int x = 0;
			int y = j;
			for(int i = 1; i < h; i++){
				if(map[i][j].equals(s) && !s.equals(".")){
					tate++;
				}
				else{
					if(tate >= n) hlist.add(new Integer[]{x,y,tate});
					s = map[i][j];
					tate = 1;
					x = i;
					y = j;
				}
			}
			if(tate >= n) hlist.add(new Integer[]{x,y,tate});
		}

		if(wlist.size() == 0 && hlist.size() == 0) return false;
		while(wlist.size() != 0){
			Integer[] item = wlist.get(0);
			wlist.remove(0);
			int x = item[0];
			int y = item[1];
			for(int i = 0; i < item[2]; i++){
				map[x][y] = ".";
				y++;
			}
		}
		while(hlist.size() != 0){
			Integer[] item = hlist.get(0);
			hlist.remove(0);
			int x = item[0];
			int y = item[1];
			for(int i = 0; i < item[2]; i++){
				map[x][y] = ".";
				x++;
			}
		}
		return true;
	}
	public void fall(String[][] map){
		for(int j = 0; j < w; j++){
			int sum = 0;
			for(int i = h-1; i >= 0; i--){
				String s = map[i][j];
				if(s.equals(".")) sum++;
				else if(sum != 0){
					map[i+sum][j] = map[i][j];
					map[i][j] = ".";
					i = i+sum;
					sum = 0;
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 29504
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h)
    {
        cin >> g[i];
    }
    rep(i, h + 2)
    {
        rep(j, w + 2)
        {
            if (j == 0 || j == w + 1 || i == 0 || i == h + 1)
            {
                cout << "#";
            }
            else
            {
                cout << g[i - 1][j - 1];
            }
        }

        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 305;

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	long long sum = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin >> a[i][j];
			b[i][j] = a[i][j];
			if(i<j) sum += a[i][j];
		}
	}

	priority_queue< pair<long long, pair<int,int>> > pq;
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			pq.push(make_pair(a[i][j], make_pair(i, j)));
		}
	}
	while(!pq.empty()) {
		auto now = pq.top();
		pq.pop();
		pair<int,int> pos = now.second;
		long long val = now.first;
		if(a[pos.first][pos.second] != val) continue;
		long long mn = 1e15;
		for(int j = 0; j < n; j++) {
			if(j == pos.first || j == pos.second) continue;
			mn = min(mn, a[pos.first][j] + a[j][pos.second]);
		}
		if(mn == val) {
			sum -= val;
			a[pos.first][pos.second] = 1e15;
			a[pos.second][pos.first] = 1e15;
		}
	}

	for(int k = 0; k < n; k++) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
			}
		}
	}

	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(a[i][j] != b[i][j]) {
				cout << -1;
				exit(0);
			}
		}
	}

	cout << sum;

	return 0;
}


Measured memory_bytes: 2808
import java.io.*;
public class Main {

	public static void main(String[] args) throws IOException{
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		
		while(true){
		String str = br.readLine();
		if(str == null)
			break;
		int count = 0;
		int index = -1;
		while(true){
			index = str.indexOf(" ", index+1);
			count++;
			if(index == -1)break;
		}

		int n = count;
		int zure = -1;
		boolean f = true;
		String c = str.toString();
		String[] star  = new String[n];
		char[] ch  = new char[n];
		for(int i = 0; i < n; i++){
			if(c.indexOf(" ") !=  -1){
				String prestr = c.substring(0, c.indexOf(" "));
				star[i] = prestr.toString();
				c = c.substring(c.indexOf(" ") + 1);
			}
			else{
				star[i] = c.toString();
			}
			//System.out.println(star[i]);
			ch = star[i].toCharArray();
			
			if((seisa(ch, star[i].length())) != -1){
				if(zure == -1){
					zure = seisa(ch, star[i].length());
				}
			}
		}
		for(int i = 0; i < n;i++){
			ch = star[i].toCharArray();
			for(int j = 0; j < star[i].length(); j++){
				if(ch[j] != '.'){
					ch[j] += zure;
					if(ch[j] > 122)
						ch[j] -= 26;
				}
				System.out.print(ch[j]);
			}
			if(i != n-1)
			System.out.print(" ");
		}
		System.out.println();
	}
	}
	
	
	
	static int seisa(char[] prech, int len){
		char[] ch = prech.clone();
		
		if(!(len == 3 || len == 4))return -1;
		
		if(len == 3){
			for(int i = 0; i < 26;i++){
				if(ch[0] == 't' && ch[1] == 'h' && ch[2] == 'e')
					return i;
				for(int j = 0; j < len;j++){
					if(++ch[j] > 122)
						ch[j] -= 26;
				}
			}
		}
		if(len == 4){
			for(int i = 0; i < 26;i++){
				if(ch[0] == 't' && ch[1] == 'h'
					&& ch[2] == 'i' && ch[3] == 's')
					return i;
				for(int j = 0; j < len;j++){
					if(++ch[j] > 122)
						ch[j] -= 26;
				}
			}
		}
		if(len == 4){
			for(int i = 0; i < 26;i++){
				if(ch[0] == 't' && ch[1] == 'h' 
					&& ch[2] == 'a' && ch[3] == 't')
					return i;
				for(int j = 0; j < len;j++){
					if(++ch[j] > 122)
						ch[j] -= 26;
				}
			}
		}

		return -1;
	}
}

Measured memory_bytes: 9348
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int A, B;
    cin >> A >> B;

    bool f = true;
    REP(x, 2000) {
        if (int(x * 0.08) == A && int(x * 0.1) == B) {
            cout << x << endl;
            f = false;
            break;
        }
    }

    if (f) cout << -1 << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    char s[4];

    int count = 0;
    for (int i = 0; i < 4; i++)
    {
        cin >> s[i];
        if (s[i] == '+')
        {
            count += 1;
        }
        else
        {
            count -= 1;
        }
    }

    cout << count << endl;
    return 0;
}

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


ab.sort()

cost = 0
bought = 0
for a, b in ab:
  buy = min(b, m - bought)
  cost += a * buy
  bought += buy
  if bought >= m:
    break

print(cost)


Measured memory_bytes: 27880
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int A,B,X;
	cin>>A>>B>>X;
	puts((A<=X && X<=A+B)?"YES":"NO");
	return 0;
}



Measured memory_bytes: 256
/******************
*  Writer: Oh no  *
******************/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;

int a,b;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>a>>b;
	if((a*b)&1){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	
	return 0;
}


Measured memory_bytes: 256
N,Sa,Sb,Ga,Gb = map(int, input().split())
S = input()

Sa-=1
Sb-=1
Ga-=1
Gb-=1

for i in range(Sa,Ga):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()
for i in range(Sb,Gb):
    if S[i] == "#" and S[i+1] == "#":
        print("No")
        exit()

if Gb < Ga: #Need to swap

    for i in range(Sb-1,Gb):
        if S[i] == "." and S[i+1] == "." and S[i+2] == "." :
            print("Yes")
            exit()

    print("No")

else: # No need to swap
    print("Yes")

Measured memory_bytes: 3572
h,w = map(int, input().split())
cells = [[c%2==1 for c in map(int, input().split())] for i in range(h)]


command = []
for i in range(h):
    for j in range(w):
        if cells[i][j]:
            if j < w-1:
                cells[i][j+1] ^= True
                command.append((i+1, j+1, i+1, j+2))
            elif i < h-1:
                cells[i+1][j] ^= True
                command.append((i+1, j+1, i+2, j+1))
print(len(command))
for c in command:
    print(*c)            




Measured memory_bytes: 26532
# coding: utf-8
N, L = map(int, input().split())
A = list(map(int, input().split()))
flag = True
l = -1
for i in range(N-1):
    if A[i] + A[i+1] >= L:
        l = i+1
if l < 0:
    print("Impossible")
    exit()
knot = list(range(1, N))
print("Possible")
idx = 1
while idx < l:
    print(idx)
    idx += 1
idx = N-1
while idx > l:
    print(idx)
    idx -= 1
print(l)

Measured memory_bytes: 14304
#include <stdio.h>

int main(void){
    char station[3];
    for(int i=0; i<3; i++){
    scanf("%c", &station[i]);
    }
    if(station[0]==station[1] && station[1]==station[2]){
        printf("No");
    }else{
        printf("Yes");
    }
}

Measured memory_bytes: 128
N, K = map(int,input().split())
A = list(map(int,input().split()))

import math
K = min(K, 43)
for k in range(K):
  light = [0] * (N+1)
  for i in range(N):
    start = max(0,i-A[i])
    end = min(N-1, i+A[i])
    light[start] += 1
    light[end+1] -= 1
  for i in range(1,N):
    light[i] += light[i-1]
    
  A = light

light.pop()
print(" ".join(map(str,light)))


Measured memory_bytes: 170992
n,x,y = map(int,input().split())
anslist = [0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ra = j-i
        rb = abs(x-i) + abs(x-j)
        rc = abs(x-i) + abs(y-j) + 1
        rd = abs(y-i) + abs(y-j)
        anslist[min(ra,rb,rc,rd)] += 1

for i in range(1,n):
    print(anslist[i])


Measured memory_bytes: 48860
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7 ;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std::chrono; 

int main()
{
  // input_from_file 
  // ll q;cin>>q;while(q--){
    ll n;cin>>n;
    if(n>=30) {cout<<"Yes";return 0;}
    cout<<"No";
  // }
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

int main(){
    int a,b; cin >> a >> b;
    int max_ab = -1000 * 1000;

    max_ab = max(max_ab,a+b);
    max_ab = max(max_ab,a-b);
    max_ab = max(max_ab,a*b);
    cout << max_ab << endl;
}

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

int main()
{
    int N;

    cin >> N;

    int A;
    cin >> A;
    int current_max = A;
    unsigned long long count = 0;
    for(int i = 1; i < N; i++) {
        cin >> A;
        if(A <= current_max) {
            count += (current_max - A);
        } else {
            current_max = A;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3668
import math
a,b,x = list(map(int,input().split()))
if x<=a*a*b/2:
    c = x/a/b*2
    print(math.degrees(math.atan(b/c)))
else:
    v = a*a*b-x
    c = v/a/a*2
    print(math.degrees(math.atan(c/a)))

Measured memory_bytes: 3060
n,m=map(int,raw_input().split())
a,b=[],[]
for i in range(n):a.append(map(int,raw_input().split()))
for i in range(m):b.append(input())
for i in range(n):
    ans=0
    for j in range(m): ans+=a[i][j]*b[j]
    print ans

Measured memory_bytes: 6568
#include <iostream>
#include <cmath>

int main(int argc, char** argv) {
  unsigned long N;
  std::cin >> N;
  unsigned long x = std::sqrt(N);
  for (;;--x) {
    if (N % x == 0) break;
  }
  std::cout << (N/x + x - 2) << '\n';
}


Measured memory_bytes: 1016
n = int(input())
a = [input() for i in range(n)]
if len(set(a)) != len(a):
  print("No")
  exit()
for i in range(n-1):
  if not a[i].endswith(a[i+1][0]):
    print("No")
    break
else:
  print("Yes")
       

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

struct edge {
  int ix;
  int *v;
};

struct res {
  int d, v;
};

int *va, *vb;
int *cnt;
bool *visited;
struct edge *e;

struct res visit(int vertex)
{
  struct res r, t;

  r.d = 0;
  r.v = vertex;
  visited[vertex] = true;
  for (int i = 0; i < e[vertex].ix; i++) {
    if (!visited[e[vertex].v[i]]) {
      t = visit(e[vertex].v[i]);
      if (r.d <= t.d) {
        r.d = t.d + 1;
        r.v = t.v;
      }
    }
  }
  visited[vertex] = false;

  return r;
}

int main(void)
{
  int n;
  scanf("%d", &n);

  va = malloc(sizeof(int) * (n - 1));
  vb = malloc(sizeof(int) * (n - 1));
  e = malloc(sizeof(struct edge) * (n + 1));
  cnt = calloc(n + 1, sizeof(int));
  visited = calloc(n + 1, sizeof(bool));
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &va[i], &vb[i]);
  }

  for (int i = 0; i < n - 1; i++) {
    cnt[va[i]]++;
    cnt[vb[i]]++;
  }

  for (int i = 1; i <= n; i++) {
    e[i].ix = 0;
    e[i].v = malloc(sizeof(int) * cnt[i]);
  }

  for (int i = 0; i < n - 1; i++) {
    e[va[i]].v[e[va[i]].ix++] = vb[i];
    e[vb[i]].v[e[vb[i]].ix++] = va[i];
  }

  puts(visit(visit(1).v).d % 3 == 1 ? "Second" : "First");

  for (int i = 1; i <= n; i++) {
    free(e[i].v);
  }
  free(e);
  free(va);
  free(vb);
  free(cnt);
  free(visited);
}


Measured memory_bytes: 21504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int n = s.length;
		int c = n / 2;
		int r = n-1, l = 0;
		for(int i=c;i<n;i++) {
			if (s[i] != s[c]) {
				r = i - 1;
				break;
			}
		}
		for(int i=c;i>=0;i--) {
			if (s[i] != s[c]) {
				l = i + 1;
				break;
			}
		}
//		System.out.println(l + " " + r);
		System.out.println(n - Math.max(n-1-r, l));
	}

}


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

const int MAX_N = 100100;
int A[MAX_N];
ll acum[MAX_N];
int N; ll M;

pair<ll,ll> calc(ll P) {
    ll tot = 0, num = 0;
    for(int i = 0; i < N; ++i) {
        int j = lower_bound(A, A + N, P - A[i]) - A;
        num += (ll)N - j;
        tot += (ll)A[i]*(N-j);
        tot += acum[N] - acum[j];
    }
    return make_pair(tot, num);
}

int main()
{
    scanf("%d %lld", &N, &M);
    for(int i = 0; i < N; ++i) scanf("%d", &A[i]);
    sort(A, A + N);
    for(int i = 0; i < N; ++i) acum[i+1] = A[i] + acum[i];

    ll l = 0, r = 200100;
    while(r-l>1) {
        ll c = (r+l)/2;
        auto p = calc(c);
        if(p.second>=M) l = c;
        else r = c;
    }

    auto p = calc(l);
    ll res = p.first;
    // 「Ax+Ay>=Pとなる(x,y)の組み合わせがM個以上となるPの最大値」であり、
    //そのような(x,y)がM個以上ある場合、はみ出た部分の和は全てPなのでそれを引く
    res -= (p.second - M)*l;
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 1536
import heapq

n = int(input())
d = [float("inf") for i in range(n)]
d[0] = 0
g = []
q = []

for i in range(n):
    heapq.heappush(q, (d[i], i))
    inp = list(map(int, input().split()))
    tmp = []
    for j in range(inp[1]):
        tmp.append(inp[2*j+2:2*j+4])
    g.append(tmp)

while q:
    q_pop = heapq.heappop(q)
    i = q_pop[1]
    if q_pop[0] > 100*100000:
        continue
    for node in g[i]:
        d_tmp = d[i] + node[1]
        if d_tmp < d[node[0]]:
            d[node[0]] = d_tmp
            heapq.heappush(q, (d_tmp, node[0]))

for i in range(n):
    print(i, d[i])

Measured memory_bytes: 8284
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector<int>p(A);
	vector<int>q(B);
	vector<int>r(C);
	for (int i = 0; i < A; i++) cin >> p[i];
	for (int i = 0; i < B; i++) cin >> q[i];
	for (int i = 0; i < C; i++) cin >> r[i];
	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	sort(r.begin(), r.end(), greater<int>());
	vector<int> Red(X + 1);
	vector<int> Green(Y + 1);
	long long sum = 0;
	for (int i = 0; i < X; i++) {
		Red[X - 1 - i] = p[i];
		sum += p[i];
	}
	for (int i = 0; i < Y; i++) {
		Green[Y - 1 - i] = q[i];
		sum += q[i];
	}
	Red[X] = 1000000000;
	Green[Y] = 1000000000;
	int i = 0, j = 0, k = 0;
	while (k < C && (Red[i] < r[k] || Green[j] < r[k])) {
		if (Red[i] < Green[j]) {
			sum += -Red[i] + r[k];
			i++;
			k++;
		}
		else {
			sum += -Green[j] + r[k];
			j++;
			k++;
		}
	}
	cout << sum << endl;
}


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

using ll = long long;
const int mod = 1e9 + 7;

void add_self(ll& a, ll b) {
    a += b;
    if(a > mod) {
        a -= mod;
    }
}

int main()
{
    string K;
    int D;
    cin >> K >> D;

    //dp[i][j] - no.of ways such that sum of digits % D is i.
    // j = 0 - number is not less than K. j = 1 - number is less than K already.
    vector<vector<ll>> dp(D, vector<ll>(2));
    dp[0][0] = 1;

    for(int i = 0; i < (int)K.length(); i++) {
        vector<vector<ll>> new_dp(D, vector<ll>(2));
        for(int d = 0; d < 10; d++) {
            if(d < K[i]-'0') {
                for(int j = 0; j < D; j++) {
                    add_self(new_dp[(j+d)%D][1], dp[j][1]);
                    add_self(new_dp[(j+d)%D][1], dp[j][0]);
                }
            }
            else if(d == K[i]-'0') {
                for(int j = 0; j < D; j++) {
                    add_self(new_dp[(j+d)%D][1], dp[j][1]);
                    add_self(new_dp[(j+d)%D][0], dp[j][0]);
                }
            }
            else {
                for(int j = 0; j < D; j++) {
                    add_self(new_dp[(j+d)%D][1], dp[j][1]);
                }
            }
        }
        dp = new_dp;
    }
    ll ans = dp[0][1] + dp[0][0] - 1;
    if(ans > mod) {
        ans -= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define ff first 
#define ss second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "\n\n" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define testcase(t) int t;cin>>t;while(t--)
#define mp(x,y) make_pair(x,y)
#define in(x) insert(x)
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define PI 3.14159265358979323846
#define SP(x) setprecision(x)
#define reflex ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define M 998244853
#define sz(a) (int)a.size()
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mem(arr,val) memset(arr,val,sizeof(arr)) //For "0" and "-1"                  
#define inp0(a,n) rep(i,0,n-1) cin>>a[i];
#define inp1(a,n) rep(i,1,n) cin>>a[i]; 
#define prll(x) printf("%lld",x)
#define nth_ele(v,n) nth_element(v.begin(), v.begin()+n ,v.end())//O(N)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll gcd(ll n1, ll n2){if(n2!=0) return gcd(n2, n1%n2);else return n1;}
ll powerM(ll a,ll b){if(b==0) return 1;  if(b==1) return a%M; ll x=powerM(a,b/2)%M; if(b&1){return ((((a%M)*(x%M))%M)*(x%M))%M;}return ((x%M)*(x%M))%M;}
ll power(ll a,ll b){if(b==0) return 1;  if(b==1) return a; ll x=power(a,b/2); if(b&1){return ((((a)*(x)))*(x));}return ((x)*(x));}
 

const ll INF=1e18; 
const int SIZE = 100005;
const int SSIZE = 1000005;

int main(){
    ll n;
    cin>>n;
    ll a[n+1],b[n+1],c[n+1];
    inp1(a,n)
    inp1(b,n)
    inp1(c,n-1)
    ll sum=0;
    ll pre=-1;
    rep(i,1,n){
        ll x = a[i];
        sum += b[x];
        if(pre+1 == x) sum += c[pre];
        pre = x;
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 256
a, b, c, d, e, f = [int(i) for i in input().split()]
waterA = [a * 100 * i for i in range(int(f / (100 * a)) + 1)]
waterB = [b * 100 * i for i in range(int(f / (100 * b)) + 1)]
sugarC = [c * i for i in range(int(f / c) + 1)]
sugarD = [d * i for i in range(int(f / d) + 1)]

# まず水が何100gにできるかを算出(<F)
_water = []
for i in range(len(waterA)):
    for j in range(len(waterB)):
        if 100 * a * i + 100 * b * j <= f:
            _water.append(100 * a * i + 100 * b * j)
_water = sorted(_water)[1:]
water = [_water[0]]
for i in range(1, len(_water)):
    if _water[i] != _water[i - 1]:
        water.append(_water[i])
# 砂糖が何gにできるかを算出(<F)
_sugar = []
for i in range(len(sugarC)):
    for j in range(len(sugarD)):
        if c * i + d * j <= f:
            _sugar.append(c * i + d * j)
_sugar = sorted(_sugar)
sugar = [_sugar[0]]
for i in range(1, len(_sugar)):
    if _sugar[i] != _sugar[i - 1]:
        sugar.append(_sugar[i])
# print(water)
# print(sugar)
# 各場合で砂糖の最大量を計算
maxSugar = [-1, -1, -1]  # [dense, sugar, total]
for i in range(len(sugar)):
    for j in range(len(water)):
        if sugar[i] + water[j] > f:
            continue
        elif maxSugar[0] < sugar[i]/(sugar[i]+water[j]) <= e/(100+e):
            maxSugar[0] = sugar[i]/(sugar[i]+water[j])
            maxSugar[1] = sugar[i]
            maxSugar[2] = sugar[i] + water[j]
        # print("s:{} w:{} dense:{}".format(sugar[i], water[j], sugar[i]/(sugar[i]+water[j])))
# print(e/(100+e))
if maxSugar[0] == -1:
    print("1 0")
else:
    print("{} {}".format(maxSugar[2], maxSugar[1]))


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

void main()
{
	while (1) {
		string area[3];
    auto res = "NA";
    bool f;
    foreach (i; 0..3) {
      area[i] = readln.chomp;
      if (area[i] == "0") {
        f = 1;
        break;
      }
      if (area[i].count!(a => a == 'b') == 3) res = "b";
      if (area[i].count!(a => a == 'w') == 3) res = "w";
    }
    if (f) break;
    foreach (i; 0..3) {
      if (area[0][i] == area[1][i] && area[1][i] == area[2][i]) {
        if  (area[0][i] == 'w' || area[0][i] == 'b') {
          res = area[0][i].to!string;
        }
      }
    }
    if (area[0][0] == area[1][1] && area[1][1] == area[2][2] ||
      area[2][0] == area[1][1] && area[1][1] == area[0][2]) {
      if  (area[1][1] == 'w' || area[1][1] == 'b') {
        res = area[1][1].to!string;
      }
    }
    res.writeln;
	}
}

Measured memory_bytes: 1052
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t){e.exports=require("fs")},function(e,t,r){"use strict";r.r(t);var n,o,u=r(0);n=u.readFileSync("/dev/stdin","utf8").trim(),o=n.split(" "),console.log(`${o[1]}${o[0]}`)}]);

Measured memory_bytes: 7372
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 1e6+2;
const ll mod = 1e9+7;



int main(){ 
	speedhack()
	int n; cin >> n;
	vector<ll> v;
	for(int i = 1; i <= n+1; i++){
		ll x; cin >> x;
		v.push_back(x);
	}
	vector<ll> h;
	for(int i = 1; i <= n; i++){
		ll x; cin >> x;
		h.push_back(x);
	}
	ll sum = 0;
	ll curs = 0;
	for(int i = 0; i < h.size(); i++){
		curs = min(v[i],h[i]);
		sum += curs;
		h[i] -= curs;
		curs = min(v[i+1],h[i]);
		sum += curs;
		v[i+1] -= curs;
	}
	cout << sum << endl;

	return 0;
}


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

long long gcd(long long x, long long y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

long long lcm(long long x, long long y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    long N, K;
    cin >> N >> K;
    vector<pair<long, long>> ab(N);
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        ab[i] = pair<long, long>(a, b);
    }
    sort(ab.begin(), ab.end());
    for (int i = 0; i < N; i++)
    {
        K -= ab[i].second;
        if (K <= 0)
        {
            cout << ab[i].first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1792