akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

const int MEM = 2010;
ll dp[MEM][MEM]={};
ll mx[MEM]={};
ll mxa;

vector<pair<pair<ll,ll>,ll>> change;

void chmax(pair<ll,ll> X,ll Y){
    change.push_back({X,Y});
}

//in-placeの更新遅延
void reflect(void){
    REP(i,change.size()){
        pair<ll,ll> X=change[i].first;
        ll Y=change[i].second;
        
        if(dp[X.first][X.second]<Y){
            
            dp[X.first][X.second]=Y;
            dp[X.second][X.first]=Y;
            mx[X.first]=max(mx[X.first],dp[X.first][X.second]);
            mx[X.second]=max(mx[X.second],dp[X.second][X.first]);
            mxa=max(mxa,mx[X.first]);
            mxa=max(mxa,mx[X.second]);
        }
    }
    change.clear();
}
    
int main(void){
    ll N,p,q,r;
    ll Ans=0;
    vector<array<ll,3>> A;
    
    cin >> N;
    cin >> p >> q;
    p--;q--;
    REP(i,N-1){
        array<ll,3> a;
        cin >> a[0] >> a[1] >> a[2];
        REP(j,3){a[j]--;}
        sort(a.begin(),a.end());
        A.push_back(a);
    }
    cin >> r;r--;
    
    
    REP(i,MEM){REP(j,MEM){dp[i][j]=-INF;}}
    REP(i,MEM){mx[i]=-INF;}
    
    dp[p][q]=0;dp[q][p]=0;
    mx[p]=0;mx[q]=0;
    mxa=0;
    
    
    REP(i,A.size()){
        array<ll,3> D = A[i];
        
        //パターン1 (来たやつ全部いっしょ)
        if(D[0]==D[2]){
            Ans++;
            continue;
        }
        //パターン2 (来たやつ2ついっしょ)
        if(D[0]==D[1]){
            REP(j,N){
                chmax({j,D[2]},dp[j][D[0]]+1);
            }
        }
        if(D[1]==D[2]){
            REP(j,N){
                chmax({j,D[0]},dp[j][D[2]]+1);
            }
        }
        //パターン3 (来たやつ全部違う)
        chmax({D[1],D[2]},dp[D[0]][D[0]]+1);
        chmax({D[0],D[2]},dp[D[1]][D[1]]+1);
        chmax({D[0],D[1]},dp[D[2]][D[2]]+1);
        
        
        //ここからは得にならない遷移
        //パターン4 (来たやつそのまま受け流す(ナベアツ))
        //in-placeにつきコード不要
        
        //パターン5 (来たやつ1つ受け取る)
        REP(j,N){
            REP(k,3){
                chmax({j,D[k]},mx[j]);
            }
        }
        //パターン6 (来たやつ2つ受け取る)
        chmax({D[0],D[1]},mxa);
        chmax({D[0],D[2]},mxa);
        chmax({D[1],D[2]},mxa);
        
        reflect();
        
    }
    //最後の1回
    chmax({r,r},dp[r][r]+1);
    reflect();
    
    Ans+=mxa;
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 35336
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    for (int i = 1; i <= n; i++) {
      if (i + i * 8 / 100 == n) {
        System.out.println(i);
        return;
      }
    }
    System.out.println(":(");
  }
}

Measured memory_bytes: 32656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL<<60;

int main() {
  int64_t N,K,ans=-1*INF; cin>>N>>K;
  vector<int64_t> P(N);
  rep(i,N){
    cin>>P.at(i);
    P.at(i)--;
  }
  vector<int64_t> C(N);
  rep(i,N) cin>>C.at(i);
  
  rep(i,N){
    vector<bool> seen(N,true);
    vector<int64_t> T;
    int64_t k=i,c=0,sum=0,MAX=-1*INF,NMAX=0,MAX2=-1*INF;
    
    while(seen.at(k)){
      seen.at(k)=false;
      T.push_back(C.at(k));
      if(c>0) T.at(c)+=T.at(c-1);
      if(T.at(c)>MAX){
        MAX=T.at(c);
        NMAX=c+1;
      }
      sum+=C.at(k);
      k=P.at(k);
      c++; 
    }
    
    int64_t t=T.size(),r=K/t,q=K%t;
    if(q<NMAX){
      rep(i,q) MAX2=max(MAX2,T.at(i));
      auto temp=max(MAX,max(MAX+sum*(r-1),MAX2+sum*r));
      if(K>=NMAX)ans=max(ans,temp);
      else ans=max(ans,MAX2);
    }
    else ans=max(ans,max(MAX,MAX+sum*r));
  }
  cout<<ans;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(a) a.begin(), a.end()

vector <int> a, sum;



signed main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int n;
	cin >> n;

	a.resize(n);sum.resize(n);

	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(i == 0) sum[i] = a[i];
		else sum[i] = sum[i - 1] + a[i];
	}



	int m = INT_MAX;
	for(int i = 0; i < n; i++) {
		m = min(m, abs(sum[i] - (sum[n - 1] - sum[i])));
	}

	cout << m << endl;
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    cin.tie(NULL);
    ios::sync_with_stdio(false);   
    ll s;cin>>s;
    vector<int> ax(s);
    for (int i = 0; i < s; ++i)
        cin>>ax[i];
    sort(ax.begin(),ax.end());
    for (int i = 0; i < s; ++i)
    {
        if(ax[i]==ax[i+1]){
            cout<<"NO"<<endl;
            return 0;
         }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  n = n%10;
  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
  {
    cout << "hon" << endl;
  }else if (n == 0 || n == 1 || n == 6 || n == 8)
  {
    cout << "pon" << endl;
  }else
  {
    cout << "bon" << endl;
  }
  
  
  
  return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<bitset>
using namespace std;
const int N=1010,M=5050;
int i,j,k,n,m,En,ch;
int h[N],fa[N],f[N],X[N];
bitset<M> g;
struct edge { int s,n;} E[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
}
bool dfs(int x) {
	for (int k=h[x];k;k=E[k].n) if (!dfs(E[k].s)) return 0;
	g.reset();
	g[0]=1;
	int sum=0;
	for (int k=h[x];k;k=E[k].n) {
		g=g<<X[E[k].s]|g<<f[E[k].s];
		sum+=X[E[k].s]+f[E[k].s];
	}
	for (int i=X[x];i>=0;i--) if (g[i]) {
		f[x]=sum-i;
		return 1;
	}
	return 0;
}
int main() {
	R(n);
	for (i=2;i<=n;i++) R(fa[i]),E_add(fa[i],i);
	for (i=1;i<=n;i++) R(X[i]);
	if (dfs(1)) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

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

int min(int a, int b) {
    if (a <= b) return a;
    else return b;
}

int main()
{
    int n ,k, x[100];
    scanf("%d%d", &n, &k);
    int i;
    int sum = 0;
    for (i=0; i<n; i++)
    {
        scanf("%d", &x[i]);
        sum += min(x[i], abs(x[i] - k));
    }
    printf("%d\n", sum*2);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
vector <long long> p;
vector <long long> val;
long long W; 
long long n;
long long knapSack(){ 
    long long DP[n + 1][W + 1]; 
    for (int i = 0; i <= n; i++){ 
        for (int i1 = 0; i1 <= W; i1++){ 
            if (i == 0 || i1 == 0) {
                DP[i][i1] = 0; 
            }else{
                 if (p[i - 1] <= i1){ 
                    DP[i][i1] = max(val[i - 1] + DP[i - 1][i1 - p[i - 1]], DP[i - 1][i1]); 
                }else{
                    DP[i][i1] = DP[i - 1][i1];
                }
            } 
        } 

    } 
  
    return DP[n][W]; 
} 
  
int main() 
{ 
    cin>>n>>W;
    val.resize(n);
    p.resize(n);
    for (int i = 0; i<n; i++){
        cin>>p[i]>>val[i];
    }
    cout<<knapSack()<<endl; 
    return 0; 
} 

Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second
int main()
{
    ll k,n;cin >> n >> k;
    ll arr[n];
    ll sum=0;
    
    for(ll i=0;i<n;i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);
    for(ll i=0;i<k;i++)
    {
        sum = sum + arr[i];
    }
    cout << sum << endl;
}
    

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define V vector
#define VI vector<int>
#define VL vector<ll>
#define VP vector<pair<int,int> >
#define VPL vector<pair<ll,ll> >
#define F first
#define S second
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

int main()
{
    sts(s);
    int n=s.size();
    VI wcnt(n);wcnt.at(n-1)=0;
    ll sum=0;
    repr(i,n){
        if(i!=n-1)wcnt.at(i)=wcnt.at(i+1);
        if(s.at(i)=='W')wcnt.at(i)+=1;
    }
    rep(i,n)if(s.at(i)=='B')sum+=wcnt.at(i);
    print(sum);
    return 0;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	int alphabetCountMin[26];
	FOR(i,0,26)alphabetCountMin[i] = INF;
	FOR(i,0,n){
		string s;
		cin >> s;
		int alphabetCount[26];
		FOR(j,0,26)alphabetCount[j] = 0;
		FOR(j,0,(int)s.size()){
			alphabetCount[s[j] - 'a']++;
		}
		FOR(j,0,26)alphabetCountMin[j] = min(alphabetCountMin[j], alphabetCount[j]);
	}
	FOR(i,0,26){
		FOR(j,0,alphabetCountMin[i])
			printf("%c", 'a'+i);
	}
	printf("\n");
	return 0;
}


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

using namespace std;

#define DEBUG(...) fprintf(stderr,__VA_ARGS__)

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

// using LL = long long;
// using uLL = unsigned long long;
typedef long long LL;
typedef unsigned long long uLL;

const int Mod = 998244353;
const LL INF = 1e18;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}
// template<typename T , typename ... Args>inline void read(T &x , Args&& ... y) { read(x) , read(y...); }

vector<LL> Ans; vector<double> val;
int k , len ; LL res;

int sum(LL x)
{
    int res = 0;
    while(x)
    {
        res += x % 10;
        x /= 10;
    }
    return res;
}

int main()
{
    read(k);
    for(len = 1 , res = 1 ; len <= 14 ; len++ , res *= 10)
    {
        rep(j , 1 , 9999)
        {
            Ans.push_back((j + 1) * res - 1) , val.push_back(0);
        }
    }
    sort(Ans.begin() , Ans.end()) , unique(Ans.begin() , Ans.end());
    val[Ans.size()] = INF * 1.0;
    per(i , Ans.size() - 1 , 0)
    {
        val[i] = 1.0 * Ans[i] / sum(Ans[i]);
        if(val[i] > val[i + 1]) Ans[i] = 0;
        chkmin(val[i] , val[i + 1]);
    }
    for(int i = 0 ; k ; i++)
    if(Ans[i]) printf("%lld\n" , Ans[i]) , k--;
    return 0;
}



Measured memory_bytes: 3564
import java.util.Scanner  ;
public class Main{
public static void main(String[]args){

Scanner sc = new Scanner(System.in);

while(true){
    int H = sc.nextInt();
    int W = sc.nextInt();
    if(H == 0 && W == 0){
        break;
    }
    for(int i= 0;i<H;i++){
        for(int j= 0;j<W;j++){
            System.out.printf("#");
        }
        System.out.printf("\n");
    }
    System.out.printf("\n");
}
}
}


Measured memory_bytes: 64068
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;

    if(n == m) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int dp[120][10001] = { 0 }, w[1000] = { 0 }, k[1000] = { 0 }, N, M, i, j;
	cin >> N >> M;
	for (i = 1; i <= N; i++){
		cin >> k[i] >> w[i];
	}
	for (i = 1; i <= N; i++){
		for (j = 1; j <= M; j++){
			if (i == 1){
				if (j >= w[i]){
					dp[i][j] = k[i];
					if (dp[i][j] <= dp[i - 1][j]){
						dp[i][j] = dp[i - 1][j];
					}
				}

			}
			else{
				if (dp[i][j] <= dp[i - 1][j]){
					dp[i][j] = dp[i - 1][j];
				}
				if (j >= w[i]){
					if (k[i] + dp[i - 1][j - w[i]] > dp[i][j]){
						dp[i][j] = k[i] + dp[i - 1][j - w[i]];
					}

				}
			}
		}
	}
	cout << dp[N][M] << endl;
	return 0;
}

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    string s;
    cin >> s;
    REP(i,s.size()){
        if(s[i] == '?'){
            int cnt = 1;
            int index = i + 1;
            while(index != s.size() - 1 ){
                if(s[index] == '?'){
                    cnt++;
                    index++;
                }else break;
            }
            REP(j,cnt)s[i + j] = 'D';
            i = i + cnt - 1;
        }

    }
    println(s);
    return 0;
}

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



int main(){
    int T[101][101], r, c;
    
    cin >> r >> c;
    for ( int i = 0; i < r ; i++)
        for (int j = 0; j < c; j++) cin >> T[i][j];
    
    for ( int i = 0; i <= r; i++ ) T[i][c] = 0;
    for ( int j = 0; j <= c; j++ ) T[r][j] = 0;
    
    for( int i = 0; i < r; i++){
        for( int j = 0; j < c; j++){
            T[i][c] += T[i][j];
            T[r][j] += T[i][j];
            T[r][c] += T[i][j];
        }
            
    }

    for ( int i = 0; i <= r ; i++){
        for ( int j = 0; j <= c; j++){
            if ( j ) cout << " ";
            cout << T[i][j];
        }
        cout << endl;
    }

    return 0;
}

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

int main()
{
    long long int n;
    unsigned long long int ans = 0;
    cin >> n;
    ans = (n * n + n) / 2;
    ans = ans - 3 * (((n / 3) * ((n / 3) + 1)) / 2);
    ans = ans - 5 * (((n / 5) * ((n / 5) + 1)) / 2);
    ans = ans + 15 * (((n / 15) * (n / 15 + 1)) / 2);
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict
import itertools


def resolve():
    n = int(input())
    d = defaultdict(int)
    for _ in range(n):
        d[input()[0]] += 1
    print(sum([d[c1] * d[c2] * d[c3] for c1, c2, c3 in itertools.combinations(["M", "A", "R", "C", "H"], 3)]))


if __name__ == "__main__":
    resolve()


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

long long len,cur,hasil;
string s;

int main(){
	cin >> s;
	len = s.length();
	for(int i=0; i<len; i++){
		cur = int(s[i])-48;
		hasil = (hasil+cur)%9;
	}
	if(hasil==0){
		cout << "Yes" << endl;
	}else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3720
#include<stdio.h>
  
int main(void){
  
int a,b,c,x;
x = 0;
scanf("%d %d %d",&a,&b,&c);
  
if(a == b){

if(c%a == 0 ){
x++;
printf("%d\n",x);
}else{
printf("%d\n",x);
}
 
}else{
 
while(a <= b){
  
if(c%a == 0){
x++;
}
  
a++;
}
printf("%d\n",x);
 
} 
  
return 0;
  
}

Measured memory_bytes: 596
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
ll dp[10001][100][2]={};//dp[i][j][k]:i桁目まで読んだ、j:modD k:K以下である可能性がある
int main(){
	ll MOD=1e+9+7;
	string K;
	scan(K);
	reverse(K.begin(),K.end()); //後ろの桁から見ていく
	int D;
	scan(D);
	int N=K.size();
	dp[0][0][1]=1;
	rep(i,N){
		rep(j,D){
			rep(k,2){
				rep(d,10){
					bool leq=d<(K[i]-'0')||(k==1&&d==(K[i]-'0'));
					dp[i+1][(j+d)%D][leq]+=dp[i][j][k];
					dp[i+1][(j+d)%D][leq]%=MOD;
				}
			}
		}
	}
	prin((dp[N][0][1]-1+MOD)%MOD);//0を除く
	return 0;
}


Measured memory_bytes: 16000
n, k = [ int( val ) for val in raw_input( ).split( " " ) ]
w = []
maxW = sumW = 0
for i in range( n ):
	num = int( raw_input( ) )
	sumW += num
	w.append( num )
	if maxW < num:
		maxW = num

minP = 0
if 1 == k:
	minP = sumW
elif n == k:
	minP = maxW
else:
	left = maxW
	right = 100000*10000
	while left <= right:
		middle = ( left+right )//2
		truckCnt = i = loadings = 0
		while i < n:
			loadings += w[i]
			if middle < loadings:
				truckCnt += 1
				if k < truckCnt+1:
					break
				loadings = w[i]
			i += 1

		if truckCnt+1 <= k:
			minP = middle
		
		if k < truckCnt+1:
			left = middle + 1
		else:
			right = middle - 1

print( minP )

Measured memory_bytes: 10480
n,k = map(int,input().split())

if n > k :
    dp  = [0]*k
    prob_1 = 1/n 
    prob_2 = (n-k+1)/n
    if k % 2 == 0 :
        for i in range(k-1,0,-1) :
            if k // 2 <= i <= k-1 :
                dp[i] = 1/2 * prob_1
            else : dp[i] = dp[i*2] * 1/2
    else :
        for i in range(k-1,0,-1) :
            if k // 2 + 1/2 <= i <= k-1 :
                dp[i] = 1/2 * prob_1
            else : dp[i] = dp[i*2] * 1/2
    print("{}".format(sum(dp)+prob_2))
elif n == k : print("1")

elif  n < k :
    prob_1 = 1/n 
    prob_2 = 1 
    dp = [0]*(k)


    if k % 2 == 0 :
        for i in range(k-1,0,-1) :
            if k // 2 <= i <= k-1 :
                dp[i] = 1/2 
            else : dp[i] = dp[i*2] * 1/2
    else :
        for i in range(k-1,0,-1) :
            if k // 2 + 1/2 <= i <= k-1 :
                dp[i] = 1/2 
            else : dp[i] = dp[i*2] * 1/2
    print("{}".format(sum(dp[0:n+1])*1/n))

Measured memory_bytes: 4980
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(ll i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
class UnionFind {
public:
    vector<ll> par;
    void init(ll n) {
        rep(i, 0, n) {
            //par[i] == iのとき、iの親はiとなるから初期化では全て根であるとする。
            par.push_back(i);
        }
    }

    ll root(ll x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    // これは併合するために使う
    bool unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        // 併合済ならばfalse
        if (x == y) return false;

        par[y] = x;
        return true;
    }

    bool isSame(ll x, ll y) {
        return root(x) == root(y);
    }
};
int main() {
    ll n, m;;
    cin >> n >> m;
    UnionFind T;
    T.init(n);
    rep(i, 0, m) {
        ll b, c;
        cin >> b >> c;
        T.unite(b, c);
    }
    int q;
    cin >> q;
    rep(i, 0, q) {
        ll b, c;
        cin >> b >> c;
        if (T.isSame(b, c)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }

    }
    return 0;
}


Measured memory_bytes: 3940
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    cin>>s;
    int ans = 400000;
    int now = 0;
    for(char c:s) if(c=='E') now++;
    for(char c:s){
        if(c=='E') now--;
        if(now < ans) ans = now;
        if(c=='W') now++;
    }cout<<ans<<endl;
  return 0;
}


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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;

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

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

const long double PI = acos(-1);

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    long double A, B, H, M; cin >> A >> B >> H >> M;
    long double theta;
    long double t = H+M/60;
    long double a = t/12 * 2*PI, b = t*2*PI;
    while(a >= 2*PI) a -= 2*PI;
    while(b >= 2*PI) b -= 2*PI;
    theta = abs(a-b);
    chmin(theta, 2*PI-theta);
    cout << sqrt(A*A+B*B-2*A*B*cos(theta)) << endl;
}

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

using namespace std;

using int64 = long long;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

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

  vector<vector<int64>> dp1 = Make2DVector(n + 1, n + 1, -1LL);
  vector<vector<int64>> dp2 = Make2DVector(n + 1, n + 1, -1LL);
  function<void(int , int)> solve = [&](int l, int r) {
    if (dp1[l][r] >= 0) return;

    if (r - l == 1) {
      dp1[l][r] = 0;
      dp2[l][r] = xs[l];
      return;
    }
    for (int m = l + 1; m <= r - 1; m++) {
      solve(l, m);
      solve(m, r);
      if (dp2[l][r] < 0) {
        dp2[l][r] = dp2[l][m] + dp2[m][r];
      }
      if (dp1[l][r] < 0) {
        dp1[l][r] = dp1[l][m] + dp1[m][r] + dp2[l][r];
      } else {
        dp1[l][r] = min(dp1[l][r], dp1[l][m] + dp1[m][r] + dp2[l][r]);
      }
    }
  };
  solve(0, n);
  cout << dp1[0][n] << endl;
}


Measured memory_bytes: 2816
#include <iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int n; int m = 0; int b;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> b;
        int a = floor(sqrt(b));
        if (b == 2 || b == 3 || b == 5) {
            ++m;
            continue;
        }
        for (int j = 2; j <= a; j++) {
            if (b % j == 0) {
                break;
            }
            else if (j == a) {
                ++m;
            }
        }
    }
    cout << m << endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

void solve(){
	long double a, b, h, m;
	cin >> a >> b >> h >> m;
	
	if(h > 12)h-=12;
	if(h == 0)h=12;
	
	long double angle = abs(((m*M_PI)/360 + (h*M_PI)/6)- (m*M_PI)/30);
	long double ans = sqrt(a*a + b*b - 2*a*b*cosl(angle));
	
	printf("%20.20Lf\n",ans);
}

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



Measured memory_bytes: 4180
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define ll long long
#define pb push_back
#define Never
#define To

using namespace std;


ll N;

ll calc(ll pivot, ll X[]){

	ll ok = -1;
	ll ng = N;

	while(abs(ng - ok) > 1){
		ll mid = (ok + ng) / 2;
		if(X[mid] > pivot){
			ok = mid;
		} else {
			ng = mid;
		}
	}

	return ok;
}

ll calc2(ll pivot, ll X[]){

	ll ok = N;
	ll ng = -1;

	while(abs(ng - ok) > 1){
		ll mid = (ok + ng) / 2;
		if(X[mid] < pivot){
			ok = mid;
		} else {
			ng = mid;
		}
	}

	return ok;
}

int main(){

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

	cin >> N;

	ll A[N], B[N], C[N];

	for(ll i = 0; i < N; i++){
		cin >> A[i];
	}
	for(ll i = 0; i < N; i++){
		cin >> B[i];
	}
	for(ll i = 0; i < N; i++){
		cin >> C[i];
	}

	sort(A, A+N, greater<ll>());
	sort(B, B+N, greater<ll>());
	sort(C, C+N, greater<ll>());
	
	ll ans = 0; 

		for(ll b = 0; b < N; b++){
			ans += ( calc(B[b], C) + 1 ) * (N - calc2(B[b], A));
		}

	cout << ans << endl;

	Never To return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6+5 , M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
const double Pii = 3.14159265359;
int n, m, mxk, X1, Y1, X2, Y2;
bool grid[N];
int dis[N];
char ch;
int cr[] = {-1, 1, 0, 0};
int cc[] = {0, 0, -1, 1};

bool valid(int nr, int nc)
{
    return (nr >= 0 && nr < n && nc >= 0 && nc < m);
}

void BFS1(int X1, int Y1)
{
    memset(dis, OO, sizeof dis);
    dis[X1*m+Y1] = 0;
    queue<pair<int, int>> q;
    q.push({X1, Y1});
    while(!q.empty())
    {
        pair<int, int> pu = q.front();
        q.pop();
        for(int k=0; k<4; ++k)
        {
            int kused = 0;
            bool ok = 1;
            int nr = pu.first;
            int nc = pu.second;
            while(kused < mxk && ok)
            {
                nr += cr[k];
                nc += cc[k];
                if(valid(nr, nc) && grid[nr*m+nc] && dis[nr*m+nc] >= dis[pu.first*m+pu.second]+1)
                {
                    if(dis[nr*m+nc] > dis[pu.first*m+pu.second] + 1)
                    {
                        q.push({nr, nc});
                        dis[nr*m+nc] = dis[pu.first*m+pu.second] + 1;
                    }
                    kused++;
                }
                else ok = 0;
            }
        }
    }
}



int main()
{
    FIO
    cin >> n >> m >> mxk >> X1 >> Y1 >> X2 >> Y2;
    X1--; Y1--; X2--; Y2--;
    for(int i=0; i<n; ++i)
    {
        for(int j=0; j<m; ++j)
        {
            cin >> ch;
            if(ch == '.') grid[i*m+j] = 1;
            else grid[i*m+j] = 0;
        }
    }
    BFS1(X1, Y1);
    /*
    for(int i=0; i<n; ++i)
    {
        for(int j=0; j<m; ++j) cout << dis[i*m+j] << " ";
        cout << endl;
    }
    */

    if(dis[X2*m+Y2] == OO) cout << -1 << endl;
    else cout << dis[X2*m+Y2] << endl;
    return 0;
}


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

#define space cout<<" ";
#define line cout<<"\n";

using namespace std;


int main()
{
    long int k,n;
    cin>>k>>n;
    long int a[n];
    for(long int i=0;i<n;i++)
    {
        cin>>a[i];
    }


    long int difference;
    long int maximum = 0;
    long int j;
    for(int i=0;i<n;i++)
    {
        j= (i+1)%n;
        if(j==0)
        {
            if(a[j]==0)
            {
                difference = abs(k-a[i]);
            }
            else{
                difference = abs(k-a[i])+a[j];
            }
        }
        else
        {
        difference = abs(a[j]-a[i]);
        }
        if(difference>maximum)
        maximum = difference;


    }


    cout<<k-maximum;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A, B;
  cin >> A >> B;
  int X = B.size();
  B.at(X - 1) = ' ';
  A = A + ' ';
  if(A == B) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3632
#include<stdio.h>

#define MAX 100010

int main()
{
	int N, M;
	int i;
	int result = 0;
	int height[MAX], isOut[MAX] = {0};
	int a, b;

	scanf("%d %d", &N, &M);
	for (i = 1 ; i < N+1 ; i++)
	{
		scanf("%d", &height[i]);
	}
	
	for (i = 0 ; i < M ; i++)
	{
		scanf("%d %d", &a, &b);

		if (height[a] <= height[b])
		{
			isOut[a] = 1;
		}
		if(height[a] >= height[b])
		{
			isOut[b] = 1;
		}
	}

	for (i = 1 ; i < N+1 ; i++)
	{
		if (!isOut[i])
		{
			result ++;
		}
	}

	printf("%d\n", result);

	return 0;
}

Measured memory_bytes: 2464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A(M);
  for(int i = 0;i<M;i++){
    cin >> A.at(i);
  }
  int sum = 0;
  for(int i = 0;i<M;i++){
    sum += A.at(i);
  }
  cout << max(N-sum,-1) << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);

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

  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;typedef vector<int> vi;typedef vector<ll> vll;
typedef pair<int,int> ii;typedef map<int,int> mii;
inline void rvi(vi &v, int n){int temp; rep(i,n){cin>>temp;v.pb(temp);}}
inline void rvll(vll &v, int n){ll temp;rep(i,n){cin>>temp;v.pb(temp);}}
inline void prvi(vi &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline void prvll(vll &a){rep(i,sz(a)){cout<<a[i]<<" ";}cout<<endl;}
inline vll prefixsum(vi &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vi &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
inline vll prefixsum(vll &a){vll b;b.pb(a[0]);for(int i=1;i<sz(a);i++){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vll &a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];for(int i=sz(a)-2;i>=0;i--){b[i]=a[i]+b[i+1];}return b;}
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
void solve();int main(){ios;solve();return 0;}
//--------SOLVE--------------------------------------------------------------------
void solve()
{
	ll n,m;
	cin>>n>>m;
	vi divisors;
	int i;
	for(i=1;i*i<m;i++)
	{
		if(m%i==0)
		{
			divisors.pb(i);
			divisors.pb(m/i);
		}
	}
	if(i*i==m) divisors.pb(i);
	isort(divisors);
	int ans;
	for(auto x:divisors)
	{
		if(1ll*x*n<=m) ans=x;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include<iostream>
#include <map>
using namespace std;
/*===================Header Template=====================*/
#define N 100010
map<int,int>mp;
long long n,m,a[N],ans=0;
long long c[N];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
		c[i]=c[i-1]+a[i],c[i]%=m,mp[c[i]]++;
	long long ans=mp[0];
	if(mp[0]>1)
		ans+=1ll*mp[0]*(mp[0]-1)/2;
	mp[0]=0;
	for(int i=1;i<=n;i++)
		if(mp[c[i]])
			ans+=1ll*mp[c[i]]*(mp[c[i]]-1)/2,mp[c[i]]=0; 
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;


//vector<string> ans;

int main()
{

	while(1){
		int n, m, c = 0;
		string h, r, a, str;
		vector<string> vec, ch;
		vector<string> ango;

		cin >> n;
		if(n == 0)break;
		for(int i = 0; i < n; i++){
			cin >> h >> r;
			vec.push_back(h);
			ch.push_back(r);
		}
		cin >> m;
		for(int i = 0; i < m; i++){
			cin >> a;
			ango.push_back(a);
		}

		for(int i = 0; i < m; i++){
			for(int j = 0; j < n; j++){
					if(ango[i] == vec[j]){
						ango[i] = ch[j];
						break;
					}
			}
		}
		str = ango[0];

		for(int i = 1; i < m; i++)
			str += ango[i];
		cout << str << endl;
	}

/*	for(int i = 0; i < c; i++)
		cout << ans[i] << endl;*/

	return 0;
}

Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x, y, z;
  cin >> x >> y >> z;
  if(x%(y+z)>=z){
    cout << x/(y+z) << endl;
  }
  else {
    cout << x/(y+z)-1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int x,y;cin>>x>>y;
  if (y%2==1) cout<<"No";
  else {
    if (y>=x*2 && y<=x*4) cout<<"Yes";
    else cout<<"No";
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ


int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    map<char,int> p;
    rep(i,n){
        cin>>s[i];
    }
    rep(i,s[0].length()){
        p[s[0][i]]++;
    }
    for(int i=1;i<n;i++){
        map<char,int> t;
        rep(j,s[i].length()){
            t[s[i][j]]++;
        }
        for(auto c:p){
            char ch = c.first;
            int cnt = c.second;
            p[ch] = min(p[ch],t[ch]) ;
        }
    }
    for(auto c:p){
        char ch = c.first;
        int cnt = c.second; 
        //cout<<ch<<":"<<cnt<<endl; 
        rep(i,cnt){
            cout<<ch;
        }
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

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

	Int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	cout << x2 - (y2 - y1) << " " << y2 - (x1 - x2) << " " << x1 - (y2 - y1) << " " << y1 - (x1 - x2) << "\n";


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<char> a(W);
  for (int i=0; i < W+2; i++){
    cout << '#';
  }
  cout << endl;
  for (int i=0; i < H; i++){
    cout << '#';
    for (int j=0; j < W; j++){
      cin >> a.at(j);
      cout << a.at(j);
    }
    cout << '#';
    cout<< endl;
  }
  for (int i=0; i < W+2; i++){
    cout << '#';
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    
    static int solve(int[] arr, int k, int s, HashMap<Integer, Integer> map) {
        if(s >= arr.length - 1) 
            return 0;
        
        if(map.containsKey(s))
            return map.get(s);
        
        int sum = Integer.MAX_VALUE;
        for(int i = 1; i <= k; i++) {
            if(s + i < arr.length)
                sum = Math.min(sum, solve(arr, k, s + i, map) + Math.abs(arr[s] - arr[s + i]));
        }
        
        map.put(s, sum);
        return sum;
    }
    
    public static void main(String args[]) {
        int n = 0, k = 0;
        int[] arr = null;
        try (Scanner scanner = new Scanner(System.in)) {
            n = scanner.nextInt();
            k = scanner.nextInt();
            
            arr = new int[n];
            for (int i=0; i < n; i++) {
                arr[i] = scanner.nextInt();
            }
        }
        // int[] dp = new int[n];
        // dp[1] = Math.abs(arr[1] - arr[0]);
        // for(int i = 2; i < n; i++) {
        //     dp[i] = Integer.MAX_VALUE;
        //     for(int j = 1; j <= k ; j++) {
        //         if(i - j >= 0)
        //             dp[i] = Math.min(dp[i - j] + Math.abs(arr[i] - arr[i - j]), dp[i]);
        //     }
        // }
        
        System.out.println(solve(arr, k, 0, new HashMap()));
    }
}

Measured memory_bytes: 126196
//Template Jollybee 2017-0720
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;

const int INF=(int)2e9;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
const ll MOD=(ll)1e9+7;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front

int main(){
	string str;
	cin>>str;
	for(int i=0;i<str.length();i++){
		if(i%2==0){
			cout<<str[i];
		}
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 512
from collections import defaultdict
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n=int(input())
    bfr=[[[0]*10 for _ in range(3)]for _ in range(4)]
    for _ in range(n):
        b,f,r,v=map(int,input().split())
        b,f,r=b-1,f-1,r-1
        bfr[b][f][r]+=v
    for i,ff in enumerate(bfr):
        for f in ff:
            print("",*f)
        if i==3:break
        print("####################")

main()



Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int x,y,z,K;
	vector<ll> a(1000),b(1000),c(1000);

	cin >> x>>y>>z>>K;
	rep(i,x) {
		ll n;
		cin >> n;
		a.push_back(n);
	}
	rep(i,y) {
		ll n;
		cin >> n;
		b.push_back(n);
	}
	rep(i,z) {
		ll n;
		cin >> n;
		c.push_back(n);
	}

	sort(a.begin(), a.end(), greater<ll>());
	sort(b.begin(), b.end(), greater<ll>());
	sort(c.begin(), c.end(), greater<ll>());

	priority_queue<ll> Q;

	rep(i,x) {
		rep(j,y) {
			ll pro = (i+1)*(j+1);
			if (pro > K) {
				break;
			}
			rep(k,z) {
				if (pro*(k+1) > K) {
					break;	// 途中までだから、全部10^6の定数倍
				}
				// printf("%lld %lld %lld\n", a[i],b[j],c[k]);
				Q.push(a[i]+b[j]+c[k]);
			}
		}
	}

	rep(i, K) {
		ll q = Q.top(); Q.pop();
		cout << q << endl;
	}
}

















Measured memory_bytes: 1408
#


def main():
    a, b, n = map(int, input().split(" "))
    fac = 0
    start = min(b, n)
    if b <= n:
        fac = start - 1
    else:
        fac = start
    ans = a * fac // b - a * (fac // b)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
// nichijou
#define REP(i,a,b) for (int i(a), _B(b); i < _B; ++i)
#define RP(i,n) REP(i,0,n)
#define PER(i,a,b) for(int i((a)-1), _B(b); i >= _B; --i)
#define PR(i,n) PER(i,n,0)
#define REP1(i,a,b) REP(i,a,(b)+1)
#define RP1(i,n) REP1(i,1,n)
#define PER1(i,a,b) PER(i,(a)+1,b)
#define PR1(i,n) PER1(i,n,1)
#define DO(n) REP(__i,0,n)
template<typename T>
void cmax(T & a, T b) {a = max(a, b);}
template<typename T>
void cmin(T & a, T b) {a = min(a, b);}

// data type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second

// STL container
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define CLR(a) a.clear()
#define BK(a) (a.back())
#define FT(a) (a.front())
#define DB(a) a.pop_back()
#define DF(a) a.pop_front()
#define PB push_back
#define EB emplace_back

/* I gave you my heart and then you turned around. */
void _BG(const char * s) {}
template<typename T, typename ... TT>
void _BG(const char * s,T a, TT...b)
{
	for (int c = 0; *s && (c || *s != ','); ++s) {
		cerr<<*s;
		switch (*s) {
		case '(':
		case '[':
		case '{':
			++c;
			break;
		case ')':
		case ']':
		case '}':
			--c;
			break;
		}
	}
	cerr<<" = "<<a;
	if (*s) {
		cerr<<", ";
		_BG(++s,b...);
	} else
		cerr<<endl;
}
#define BG(...) do { \
	cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
	_BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)

/* Reading input is now 20% cooler! */
bool RD(void) {return true;}
bool RD(char & a) {return scanf(" %c", &a) == 1;}
bool RD(char * a) {return scanf("%s", a) == 1;}
bool RD(double & a) {return scanf("%lf", &a) == 1;}
bool RD(int & a) {return scanf("%d", &a) == 1;}
bool RD(ll & a) {return scanf("%lld", &a) == 1;}

template<typename T, typename ... TT>
bool RD(T & a, TT & ...  b) {return RD(a) && RD(b...);}

/* Do princesses dream of magic sheep? */
#define RI(a) int a; RD(a)
#define RII(a,b) RI(a); RI(b)
#define RIII(a,b,c) RI(a); RII(b,c)
#define RIIII(a,b,c,d) RI(a); RIII(b,c,d)

/* For it's time for you to fulfill your output. */
void PT(const char a) {putchar(a);}
void PT(const char * a) {fputs(a, stdout);}
void PT(char * a) {fputs(a, stdout);}
void PT(const double a) {printf("%.16f", a);}
void PT(const int a) {printf("%d", a);}
void PT(const ll a) {printf("%lld", a);}

/* The line will last forever! */
template<char sep = ' ',char end = '\n'>
void PL(void) {if (end) PT(end);}
template<char sep = ' ',char end = '\n',typename T, typename ... TT>
void PL(const T a, const TT ...  b) {PT(a); if (sizeof...(b) && sep) PT(sep); PL<sep,end>(b...);}

/* Good Luck && Have Fun ! */
set<int> s{4,6,9,11};
int main()
{
	RII(x,y);
	if (x == 2 || y == 2 || s.count(x) != s.count(y))
		PL("No");
	else
		PL("Yes");
}


Measured memory_bytes: 256
from sys import stdin
from collections import defaultdict
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    a=list(map(int,readline().split()))
    q=int(readline())
    b=[0]*q
    c=[0]*q
    for i in range(q):
        b[i],c[i]=map(int,readline().split())

    d=defaultdict(int)
    for i in range(n):
        d[a[i]]+=1

    s=sum(a)

    #クエリ処理
    for i in range(q):
        before=b[i]
        after=c[i]
        s-=before*d[before]
        s+=after*d[before]
        d[after]+=d[before]
        d[before]=0
        print(s)

if __name__=="__main__":
    main()

Measured memory_bytes: 30160
#include<bits/stdc++.h>
using namespace std;
const int N=3005,mod=998244353;
typedef long long ll;
ll dp[N][N][2];
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(c>a) dp[c][d][0]=1;
    if(d>b) dp[c][d][1]=1;
    ll ans=0;
    for(int i=c;i>=a;i--)
        for(int j=d;j>=b;j--)
    {
        if(j-1>=b)
        {
            dp[i][j-1][0]=(dp[i][j-1][0]+dp[i][j][1]*i)%mod;
            dp[i][j-1][1]=(dp[i][j-1][1]+dp[i][j][1]*i)%mod;
        }
        if(i-1>=0)
        {
            dp[i-1][j][0]=(dp[i-1][j][0]+dp[i][j][0]*j)%mod;
            dp[i-1][j][1]=(dp[i-1][j][1]+dp[i][j][0])%mod;
        }
        if(i==a&&j-1==b)
            ans=(ans+dp[i][j][1]*i)%mod;
        if(i-1==a&&j==b)
            ans=(ans+dp[i][j][0]*j)%mod;
    }
    if(a==c&&b==d) ans=1;
    printf("%lld\n",ans);
}


Measured memory_bytes: 144732
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(100100)

n = int(input())
g = [[] for i in range(n)]
c = [-1 for i in range(n)]

for i in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    w = w % 2
    g[u].append([v, w])
    g[v].append([u, w])


def dfs(p, d):
    if c[p] == -1:
        c[p] = d
        for x, w in g[p]:
            dfs(x, d ^ w)


dfs(0, 0)

for i in range(len(c)):
    print(c[i])


Measured memory_bytes: 82256