akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef unsigned long long ull;

const int MOD =  1000000007; //   1000000009 , 1000000023 ,1000000007 , 998244353
const ll INF = ll(1e18);
const ld PI = 4*atan((ld)1);

using namespace __gnu_pbds;
template<typename T, class cmp = std::less<T>>
using Tree = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

bool isprime(ll n){
  for(ll i=2 ; i*i<=n ; i++){
    if(n%i==0)return false;
  }
  return true;
}

int main() {
  #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(10);

  string s;
  cin >> s;
  ll sum = 0;
  for(auto &x:s){
    sum += (x - '0');
  }
  //cout << sum;
  if(sum%9==0)cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 3756
from collections import deque
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
def BFS(s):
	cnt = [0] * (N+1)
	flg = [-1] * (N+1)
	flg[s] = 0
	q = deque([s])
	while q:
		cp = q.popleft()
		for d in [-1,1]:
			tmp = cp + d
			if (0 <= tmp < N) and (flg[tmp] == -1):
				flg[tmp] = flg[cp] + 1
				ans[flg[tmp]] += 1
				q.append(tmp)
		if cp == X:
			if flg[Y] == -1:
				flg[Y] = flg[cp] + 1
				ans[flg[Y]] += 1
				q.append(Y)
		if cp == Y:
			if flg[X] == -1:
				flg[X] = flg[cp] + 1
				ans[flg[X]] += 1
				q.append(X)
	return cnt

for i in range(N):
	C = BFS(i)

for a in ans[1:]:
	print(a//2)

Measured memory_bytes: 53724
import numpy as np

def spaceinput():
    return list(map(int,input().split(" ")))

N=int(input())
w=spaceinput()

cs=np.cumsum(w)

res=10**9
for i in range(len(cs)-1):
    diff=np.abs((cs[-1]-cs[i])-cs[i])

    if res>diff:
        res=diff

print(res)

Measured memory_bytes: 12428
N,x = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
for i in range(N-1):
    if(a[i] > x):
        cnt += a[i] - x
        a[i] = x
    
    if(a[i] + a[i+1] > x):
        cnt += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
    
print(cnt)

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

dic = {}
for a in A:
    if a in dic: dic[a] += 1
    else: dic[a] = 1

ans = 0
for k in dic:
    x = dic[k]
    ans += x * (x - 1) // 2

for a in A:
    print(ans - dic[a] + 1)

Measured memory_bytes: 86476
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}
 
int main() {
	init();

	int N, L; cin >> N >> L;
	vector<string>s(N);
	rep(i, N)cin >> s[i];
	sort(all(s));
	rep(i, N) {
		cout << s[i];
		if (i == N - 1)cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque

nVertices = int(input())
g = [[] for _ in range(nVertices + 1)]
edges = []
for _ in range(nVertices - 1):
    u, v = map(int, input().split())
    edges.append((u, v))
    g[u].append(v)
    g[v].append(u)

colours = defaultdict(int)
q = deque([(0, 1)])
maxColour = 0
while q:
    par, vertex = q.pop()
    parColor = colours[(par, vertex)]
    colour = 1
    for child in g[vertex]:
        if child != par:
            if colour == parColor:
                colour += 1
            colours[(vertex, child)] = colour
            maxColour = max(maxColour, colour)
            colour += 1
            q.appendleft((vertex, child))

print(maxColour)
for e in edges:
    print(colours[e] or colours[e[::-1]])


Measured memory_bytes: 89120
import sys

input = sys.stdin.readline


def calc_next_hw(H, W, h, w):
    # -->
    if h % 2 == 0:
        if w == W - 1:
            next_h = h + 1
            next_w = W - 1
        else:
            next_h = h
            next_w = w + 1
    # <--
    else:
        if w == 0:
            next_h = h + 1
            next_w = 0
        else:
            next_h = h
            next_w = w - 1
    return next_h, next_w


def main():
    H, W = map(int, input().split())
    a = [None] * H
    for i in range(H):
        a[i] = list(map(int, input().split()))

    ans = []
    h, w, = 0, 0
    next_h, next_w = 0, 0
    for _ in range(H * W - 1):
        next_h, next_w = calc_next_hw(H, W, h, w)
        if a[h][w] % 2 == 1:
            a[h][w] -= 1
            a[next_h][next_w] += 1
            ans.append((h + 1, w + 1, next_h + 1, next_w + 1))
        h, w = next_h, next_w

    print(len(ans))
    for xyxy in ans:
        print(*xyxy)


if __name__ == "__main__":
    main()


Measured memory_bytes: 26684
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	printf("%d\n",a-max((b+d-1)/d,(c+e-1)/e));
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 1; i <= N; i++){
        ans += to_string(i).size() % 2;
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
ll a[maxn],b[maxn],x[maxn],y[maxn],l,r,mid,n;
vector <ll> d;

int main(){
    cin >> n;
    for (int i=1;i<=n;i++) cin >> a[i];
    for (int i=1;i<=n;i++) cin >> b[i];
    int ans=0; long long s=0;
    for (int i=1;i<=n;i++) s+=a[i]-b[i];
    if (s<0) {puts("-1");return 0;} s=0;
    for (int i=1;i<=n;i++){
        if (a[i]<b[i]) s+=b[i]-a[i],ans++;
        else d.push_back(a[i]-b[i]);
    }
    sort(d.begin(),d.end(),greater<int>());
    for (int i=0;i<d.size();i++){
        if (s<=0) break;
        s-=d[i]; ans++;
    }
    cout << ans << endl;
}


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

int max(int x, int y)
{
    if (x>=y) return x;
    else return y;
}

int main()
{
    int a, b, c, k;
    scanf("%d%d%d", &a, &b, &c);
    scanf("%d", &k);
    int maxm = max(a, max(b,c));
    int ans = a + b + c + maxm*pow(2, k) - maxm;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  rep(i,365) cout << (i+1)%26+1 << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD1 1000000007

int main() {
  int val=700;
  string s;
  cin >> s;
  rep(i,3){
    if(s[i] == 'o') val += 100;
  }

  cout << val << endl;

}

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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

vector<long long> arr;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);

    string a;

    cin >> a;

    if(a.size() == 26){
        for(int pos = 25; pos > 0; pos--){
            for(int i = 0; i < 26; ++i){
                if(i <= a[pos - 1] - 97) continue;
                bool found = false;
                for(int j = 0; j < pos; ++j){
                    if(a[j] - 97 == i){
                        found = true;
                        break;
                    }
                }
                if(found == false){
                    cout << a.substr(0, pos - 1) << ((char) (i + 97));
                    return 0;
                }
            }
        }

        cout << -1;

        return 0;
    }

    for(int i = 0; i < 26; ++i){
        bool found = false;
        for(char j : a){
            if(j - 97 == i){
                found = true;
                break;
            }
        }
        if(found == false){
            cout << a << ((char) (i + 97));
            return 0;
        }
    }

    cout << -1;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll k,x;
	cin>>k>>x;
	Yn( 500*k >= x) ;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
#include<tuple>
#include<stack>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

//const ll MOD_CONST = 1000000007;
const ll MOD_CONST = 998244353;


const int INF = 1000000000;
const ll BIG_NUM = 1000000000000000000;



int main() {
	int x;
	cin >> x;
	
	ll ans;
	ans = (x / 500) * 1000;
	x %= 500;
	ans += (x / 5) * 5;
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
long a;
main()
{
	while(cin>>a,a)
	{
		string ans="";
		while(a)
		{
			ans+='0'+(a%-10<0?10+a%-10:a%-10);
			a=a/-10+(a%-10<0?1:0);
		}
		for(int i=ans.size();i--;)cout<<ans[i];
		cout<<endl;
	}
}



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

int main() {
  int n,m;
  cin >>n>>m;
  vector<int>a,b;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    if(x==1&&y!=n){
      a.push_back(y);
    }
    if(x!=1&&y==n){
      b.push_back(x);
    }
  }
  map<int,int>mp;
  for(int x:a){
    if(mp.count(x))mp.at(x)=1;
    else mp[x]=1;
  }
  for(int x:b){
    if(mp.count(x)){
      cout<<"POSSIBLE"<<endl;
      return 0;
    }
  }
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}
      

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1001001001;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int N; cin >> N;
    vector <int> H(N);
    rep(i,N) cin >> H[i];
    
    vector <int> dp(N+1,INF);
    dp[0]=0;
    
    for (int i=1; i<N; i++){
        chmin(dp[i],dp[i-1]+abs(H[i]-H[i-1]));
        if(i>1) chmin(dp[i],dp[i-2]+abs(H[i]-H[i-2]));
    }
    cout << dp[N-1] << endl;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
vector<int> two(int D,int N){//NをDけたの二進数表記
  vector<int> num(D);
  for(int i=0;i<D;i++){
    num.at(D-1-i)=N%2;
    N/=2;
  }
  return num;
}

int main() {
  int D,G;
  cin>>D>>G;
  vector<vector<int>> pc(D,vector<int>(3));
  for(int i=0;i<D;i++){
    cin>>pc.at(i).at(0)>>pc.at(i).at(1);
    pc.at(i).at(2)=100*(i+1)*pc.at(i).at(0)+pc.at(i).at(1);
  }//100(i+1)点問題の数、ボーナス、全問正解時の点数
  
  vector<int> ans(0);
  
  for (int i=0;i<pow(2,D);i++){
    vector<int> select=two(D,i);
    int correct=0,point=0;//今までの正解数、合計点
    for(int k=0;k<D;k++){
      correct+=pc.at(k).at(0)*select.at(k);
      point+=pc.at(k).at(2)*select.at(k);
    }
    if(point>=G){
      ans.push_back(correct);
    }
    else{
      for(int j=0;j<D;j++){
        if (select.at(D-1-j)==0){
          if((G-point-1)/(100*(D-j))+1<pc.at(D-1-j).at(0)){
            ans.push_back((G-point-1)/(100*(D-j))+1+correct);
          }
        }
      }
    }
  }
  
  sort(ans.begin(),ans.end());
  cout<<ans.at(0)<<endl;
  
}

Measured memory_bytes: 512
def gcd(a, b):
    x, y = [a, b] if a > b else [b, a]
    while y:
        x, y = y, x%y
    return x

def lcm(a, b):
    return a*b // gcd(a, b)

n = int(input())
A = [int(x) for x in input().split(' ')]

tmp = A[0]
for i in range(1, n):
    tmp = lcm(tmp, A[i])

print(tmp)


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

using namespace std;
using ll = long long;

int main() {
    int M;
    ll K;
    cin >> M >> K;

    if(M == 1 and K == 1) {
        cout << -1 << endl;
        return 0;
    }

    ll n = 1LL;
    for(int i = 0; i < M; i++) {
        n *= 2;
    }
    if(K >= n) {
        cout << -1 << endl;
        return 0;
    }

    if(K == 0) {
        for(int i = 0; i < n; i++) {
            cout << i << ' ' << i;
            if(i == n-1) {
                cout << endl;
            } else {
                cout << ' ';
            }
        }
    } else {
        cout << K;
        for(int i = 0; i < n; i++) {
            if(i == K) continue;
            cout << ' ' << i;
        }

        cout << ' ' << K;
        for(int i = n-1; i >= 0; i--) {
            if(i == K) continue;
            cout << ' ' << i;
        }

        cout << endl;
    }
}

Measured memory_bytes: 1792
#include <stdio.h>
double zenka(double q)
{
 double x=q/2;
   while(x*x*x-q>=0.00001*q || x*x*x-q<=-0.00001*q)
   {
       x=x-((x*x*x)-q)/(3*x*x);
   }
   return x;
}
int main(void)
{
   int q;

   while(1)
   {
       scanf("%d",&q);
       if(q==-1) break;
       else
       {
           printf("%.7f\n",zenka(q));
       }
   }
   return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <algorithm>
#include <cstdint>

using namespace std;

int main()
{
uint64_t a,b,c;
cin >> a >> b >> c;
if ((a%2)==0 || (b%2)==0 || (c%2)==0) cout << "0\n";
else cout << min(a*b, min(a*c, b*c)) << "\n";
}


Measured memory_bytes: 256
A,B,C = map(int,input().split())

def g(t, x):
  res = 0
  while t > x:
    x += 2
    res += 1
  if t < x:
    res += x - t
  return res
  
def f(t, A, B, C):
  return g(t, A) + g(t, B) + g(t, C)

ans = 99999
for t in range(0, 401):
  ans = min(ans, f(t, A, B, C))
print(ans)


Measured memory_bytes: 3060
M=8**7
m,f,g,i=M*476+1,[j:=1],[k:=1]*M,0
while i<M:i+=1;f+=f[-1]*i%m,
g+=pow(f[-1],m-2,m),
while i:g[i-1]=g[i]*i%m;i-=1
A,B=map(int,input().split())
if A<B:A,B=B,A
while j<=B:i+=k*f[A+B-j]*g[B-j];k=k*2%m;j+=1
print((i*f[B]*g[A+B]+A)%m)

Measured memory_bytes: 174880
N = int(input())
W = input()
dict = {W:1}
p = W
ans = 'Yes'
for n in range(N-1):
  W = input()
  if (p[-1] != W[0]) or (W in dict):
    ans = 'No'
    break
  else:
    dict[W] = 1
    p = W
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> T(n);
  for (int i = 0; i < n; i++) {
    cin >> T.at(i);
  }
  
  int m;
  cin >> m;
  vector<int> P(m);
  vector<int> X(m);
  for (int i = 0; i < m; i++) {
    cin >> P.at(i) >> X.at(i);
  }
  
  for (int i = 0; i < m; i++) {
    vector<int> S(n);
    for (int i = 0; i < n; i++) {
      S.at(i) = T.at(i);
    }
    
    int ans = 0;
    int sr = P.at(i) - 1;
    S.at(sr) = X.at(i);
    ans = accumulate(S.begin(), S.end(), 0);
    
    cout << ans << endl;
  }

}

Measured memory_bytes: 3628
#include<stdio.h>
int R=1,C=1,H[2000010]={0};
int N[2000010]={-1000};
int hyouka(int a,int b){//printf("%d %d\n",a,b);
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;//prih();//printf("%d\n",i);
}
int hout(){
  int rt=H[1],i=0,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[i/2]=k;
  return rt;
}
int main(){
  int a;
  char s[100];
  while(scanf("%s",s),s[2]-'d'){//prih();
    if(s[2]=='s'){
      scanf("%d",&a);
      hin(a);
    }
    else printf("%d\n",N[hout()]);
  }//prih();
  return 0;
}

Measured memory_bytes: 12980
use itertools::Itertools;
use proconio::input;

fn main() {
    input!(p: [(i64, i64)]);

    let smm = p.iter().map(|(x, y)| x + y).minmax().into_option().unwrap();
    let tmm = p.iter().map(|(x, y)| x - y).minmax().into_option().unwrap();
    let ans = std::cmp::max(smm.1 - smm.0, tmm.1 - tmm.0);

    println!("{}", ans);
}


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

using namespace std;

typedef long long ll;
const int N = 50;

ll p3[N];
ll n;
ll solve(int k) {
    ll rem = n - 2 * p3[k] + 2;

    ll ans = 2 * k;
    if (rem < 0) return n;

    ans +=  rem / p3[k];
    rem %= p3[k];
    while (rem) {
        ans += rem % 3;
        rem /= 3;
    }
    return ans;
}
int main() {
    p3[0] = 1;
    for(int i = 1; i < N; i++) p3[i] = p3[i - 1] * 3;
    cin >> n;
    
    ll ans = n;
    for(int i = 1; p3[i] <= n; i++) 
        ans = min(ans, solve(i));
    cout << ans << endl;
}



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

int main() {
  int A, N;
  0 <= A <= 1000;
  1 <= N <= 10000;
  
  cin >> N >> A;

  if ( N % 500 <= A ) {
    cout << "Yes" << endl;
  }
  else { cout << "No" << endl ; 
       }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int n,m;
  cin >> n >> m;
  vb accnt(n,false);
  vi wacnt(n,0);
  rep(i,m) {
    int a;
    cin >> a;
    string str;
    cin >> str;
    if(str=="AC")accnt[a-1] = true;
    if(str=="WA" && !accnt[a-1]) wacnt[a-1] += 1;
  }
  int f = 0;
  int g = 0;
  rep(i,n){
    if(accnt[i]){
      f++;
      g += wacnt[i];
    }
  }
  cout << f << " " << g << endl;
}


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

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

    vector<bool> solved(N + 1, false);
    pair<int, int> ans = make_pair(0, 0);
    vector<int> penalty(N + 1, 0);
    int p;
    string S;
    for (int i = 0; i < M; i++)
    {
        cin >> p >> S;
        if (solved[p])
        {
            continue;
        }
        if (S == "AC")
        {
            ans.first++;
            solved[p] = true;
        }
        if (S == "WA")
        {
            penalty[p]++;
        }
    }

    for (int i = 1; i <= N; i++)
    {
        if (solved[i])
        {
            ans.second += penalty[i];
        }
    }
    cout << ans.first << " " << ans.second << endl;
}


Measured memory_bytes: 640
def dfs(v,n,visited):
    all_visted=1
    for i in range(n):
        if visited[i]==0:
            all_visted=0
    if all_visted==1:
        return 1
    count=0
    for i in range(n):
        if path[v][i]==0 or visited[i]==1:
            continue
        visited[i]=1
        count+=dfs(i,n,visited)
        visited[i]=0
    return count
n,m=map(int,input().split())
path=[[0]*n for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    path[a-1][b-1]=1
    path[b-1][a-1]=1
visited=[0]*n
visited[0]=1#点1は訪問済み
print(dfs(0,n,visited))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
 
const int lim = 1e6 + 5;
const int Inf = 1000000007;
const long long mod = 1000000007;//998244353;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
int p[200005];
int pos[200005];
int dp[200005];

int main()
{
//	Fastio();
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> p[i];
		pos[p[i]] = i;
	}
	dp[n] = 1;
	for(int i = n - 1; i >= 1; i--)
	{
		if(pos[i] < pos[i + 1])
		{
			dp[i] = dp[i + 1] + 1;
		}
		else
		{
			dp[i] = 1;
		}
	}
	int m = 0;
	for(int i = 1; i <= n; i++)
	{
		m = max(m, dp[i]);
	}
	cout << n - m;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,ll>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=205;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,k,Mod,Fac[MAXN],iFac[MAXN];
inline void Add(int&x,int y){x+=y,x>=Mod?x-=Mod:0;}
inline int Fp(int x,int k){int ans=1;for(;k;k>>=1,x=1ll*x*x%Mod)if(k&1)ans=1ll*ans*x%Mod;return ans;}
inline void Init(int n){
	Fac[0]=1;Rep(i,1,n)Fac[i]=1ll*Fac[i-1]*i%Mod;
	iFac[n]=Fp(Fac[n],Mod-2);Red(i,n,1)iFac[i-1]=1ll*iFac[i]*i%Mod;
}
inline int Solve(int n,int k){
	int ans=0;
	Rep(deg,1,min(k,n-2)){
		static int dp[MAXN][MAXN];
		if(n-1-deg>k)continue;
		memset(dp,0,sizeof(dp)),dp[0][deg]=1,dp[0][deg+1]=Mod-1;
		Rep(i,0,deg-1)Rep(j,deg,n-1){
			Add(dp[i][j],dp[i][j-1]);
			int tmp=dp[i][j],l=max(max(j,i+2),n+i-k),r=min(n-1,k+(i+1));
			if(l<=r)Add(dp[i+1][l],tmp),Add(dp[i+1][r+1],Mod-tmp);
		}Rep(i,deg,n-1)Add(dp[deg][i],dp[deg][i-1]),Add(ans,dp[deg][i]);
	}return 1ll*ans*Fac[n-1]%Mod;
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),k=read(),Mod=read(),Init(n);int ans=(k==n-1)?Fac[n]:0;
	Rep(i,3,n)ans=(ans+1ll*Fac[n]*iFac[i]%Mod*Solve(i,k-(n-i)))%Mod;
	cout<<ans<<'\n';
	return 0;
}




Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 200000009
int dep[100005];
int n;
const ll MOD=1e9+7;
vi E[100005];
ll dp[100005][2];// 0:all 1:white
int main(){
	ios::sync_with_stdio(false);
	memset(dep,-1,sizeof(dep));
	cin>>n;
	for (int i=1;i<n;++i){
		int u,v;cin>>u>>v;
		E[u].pb(v);E[v].pb(u);
	}
	dep[1]=0;
	queue<int> Q;priority_queue<pii> q;
	Q.push(1);q.push(mp(0,1));
	while(!Q.empty()){
		int cur=Q.front();Q.pop();
		int sz=E[cur].size();
		for (int i=0;i<sz;++i){
			int to=E[cur][i];
			if (dep[to]!=-1) continue;
			dep[to]=dep[cur]+1;
			Q.push(to);q.push(mp(dep[to],to));
		}
	}
	while(!q.empty()){
		int cur=q.top().S;q.pop();
		int sz=E[cur].size();
		if (sz==1&&cur!=1){
			dp[cur][0]=2,dp[cur][1]=1;continue;
		}
		ll res1=1,res2=1;// 1:white 2:black
		for (int i=0;i<sz;++i){
			int to=E[cur][i];
			if (dep[cur]>dep[to]) continue;
			res1*=dp[to][0];res2*=dp[to][1];
			res1%=MOD;res2%=MOD;
		}
		dp[cur][1]=res1;dp[cur][0]=res1+res2;dp[cur][0]%=MOD;
	}
	cout<<dp[1][0]<<endl;
	return 0;
}

Measured memory_bytes: 9332
#include <bits/stdc++.h>
using namespace std;
main(){
int a,b;
char c;
while(true){
  cin>>a>>c>>b;
  if(c=='?')break;
  if(c=='+')cout<<a+b<<endl;
  else if(c=='-')cout<<a-b<<endl;
  else if(c=='*')cout<<a*b<<endl;
  else if(c=='/')cout<<a/b<<endl;

} 
  return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb(a) push_back(a)
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;



using namespace std;
int n;
int a[20];
int ans;
int redc;

int main(){
  cin >> n;
  REP(i,n){
    int k;
    cin >> k;
    a[k/400]++;
    if(k>=3200) redc++;
  }
  REP(i,8){
    if(a[i]>0) ans ++;
  }
  if(ans>0){
    cout << ans << " " << ans+redc << endl;
  }
  else{
    cout << 1 << " " << ans+redc << endl;
  }
  return 0;
}


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

int main()
{
int AC=0,WA=0,TLE=0,RE=0;
int T;
cin>>T;
for(int i=0;i<T;++i)
{
    string s;
    cin>>s;
 if(s=="AC")
        AC++;
 else if(s=="WA")
    WA++;
 else if(s=="TLE")
    TLE++;
 else if(s=="RE")
    RE++;

}
cout<<"AC x "<<AC<<endl<<"WA x "<<WA<<endl<<"TLE x "<<TLE<<endl<<"RE x "<<RE<<endl;
    return 0;
}


Measured memory_bytes: 3556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int[,] map = new int[n, n];

                int x = n / 2;
                int y = x + 1;
                int len = n * n;

                map[y, x] = 1;

                for (int i = 2; i <= len; i++)
                {
                    x++; y++;

                    if (x == n) x = 0;
                    if (y == n) y = 0;

                    while (map[y, x] != 0)
                    {
                        x--; y++;

                        if (x == -1) x = n - 1;
                        if (y == n) y = 0;
                    }
                    map[y, x] = i;
                }

                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        string temp = string.Format("{0,4}", map[i, j]);
                        sb.Append(temp);
                    }
                    sb.Append("\n");
                }
                Console.Write(sb);
            }
        }
    }
}

Measured memory_bytes: 9340
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int N = 100;
const int INF = 1<<21;
int n, M[N][N];
int d[N];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  rep(i, n) d[i] = INF;
  d[s] = 0;
  int u;
  while(!q.empty()) {
    u = q.front();
    q.pop();
    rep(v, n) {
      if (!M[u][v]) continue;
      if (d[v] != INF) continue;
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  rep(i, n) {
    cout << i+1 << " " << ((d[i] == INF) ? (-1) : d[i]) << endl;
  }
}

int main() {
  int u, k, v;
  cin >> n;
  rep(i, n) {
    rep(j, n) {
      M[i][j] = 0;
    }
  }
  rep(i, n) {
    cin >> u >> k;
    u--;
    rep(j, k) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  bfs(0);
  
  return 0;
}


Measured memory_bytes: 3164
N,A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for _ in range(2501)] for _ in range(N+1)] for _ in range(N+1)]
for i in range(N+1):
    dp[i][0][0] = 1
for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,2501):
            dp[i][j][k] = dp[i-1][j][k]
            if k>=X[i-1]:
                dp[i][j][k] += dp[i-1][j-1][k-X[i-1]]
cnt = 0
for j in range(1,N+1):
    cnt += dp[N][j][j*A]
print(cnt)

Measured memory_bytes: 95196
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll a[200100];
ll b[200100];
ll c[200100];
ll ans=INFl;
ll sum=0;
int main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	REP(i,n){
		if(i!=0){
			b[i]=b[i-1]+a[i];
		}else{
			b[i]=a[i];
		}
		c[i]=sum-b[i];
		ans=min(ans,abs(b[i]-c[i]));
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
        int n,m,total=0;
        cin>>n;
        int t[n];
        for(int i=0;i<n;i++){
                cin>>t[i];
                total+=t[i];
        }
        cin>>m;
        int p[m],x[m];
        for(int i=0;i<m;i++){
                cin>>p[i]>>x[i];
                cout<<total-t[p[i]-1]+x[i]<<endl;
        }

}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    int m, k;
    cin >> m >> k;
    
    if (m == 1) {
        if (k == 0) {
            cout << "0 0 1 1" << endl;
            return 0;
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    
    int n = (1 << m);
    if (k < 0 or n <= k) {
        cout << -1 << endl;
        return 0;
    }
    
    vector<int> v;
    repeat (i, n) {
        if (i == k) continue;
        v.push_back(i);
    }
    
    cout << k << " ";
    for (auto e: v) cout << e << " ";
    cout << k << " ";
    reverse(v.begin(), v.end());
    for (auto e: v) cout << e << " ";
}

Measured memory_bytes: 2424
var lines=[];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', function (line) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines);
});

function main(lines) {
  const [n, m, x, y, xs, ys] = parseLines(lines);
  console.log(formula(x, y, xs, ys));
}

function formula(x, y, xs, ys) {
  const xMax = Math.max(...xs, x);
  const yMin = Math.min(...ys, y);
  return xMax < yMin ? 'No War' : 'War';
}

function parseLines(lines) {
  const [n, m, x, y] = lines[0].trim().split(' ').map(s => parseInt(s));
  const xs = lines[1].trim().split(' ').map(s => parseInt(s));
  const ys = lines[2].trim().split(' ').map(s => parseInt(s));
  return [n, m, x, y, xs, ys];
}


Measured memory_bytes: 7500
// 解答不能.
// jeremy624氏.
// https://atcoder.jp/contests/abc152/submissions/9636799
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define a first
#define b second
const int MAX = 1000005;
const int MOD = 1e9 + 7;

int a[MAX], b[MAX];

LL mPow(LL a, LL lv){
    if(lv == 0) return 1LL;
    LL t = mPow(a, lv / 2);
    t = (t * t) % MOD;
    if(lv & 1) t = (t * a) % MOD;
    return t;
}

int main() {
    int n;
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]);
    repx(i, 2, MAX - 4){
        if(b[i] != 0) continue;
        b[i] = i;
        repx(j, i, (MAX - 4) / i + 1) if(b[j * i] == 0) b[j * i] = i;
    }
    
    map<int, int> m;
    rep(i, n){
        int t = a[i];
        map<int, int> now;
        while(t > 1){
            int n = b[t];
            t /= n;
            now[n]++;
        }
        if(i) for(auto v : now) m[v.a] += v.b - min(v.b, m[v.a]);
        else  m = now;
    }
    
    LL res = 0, val = 1;
    for(auto &v : m) val = (val * mPow(v.a, v.b)) % MOD;
    rep(i, n) res = (res + val * mPow(a[i], MOD - 2)) % MOD;
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 4736
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)  # 大きい順にソート
amax = A[0]
half = N // 2
ans = sum(A[:half]) * 2 - amax
if N%2 == 1:
    ans += A[half]
print(ans)

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

int main()
{
	int n;
	cin >> n;
	vector<int> lv(n);
	for (auto& l : lv) {
		cin >> l;
	}

	sort(lv.begin(), lv.end(), std::greater<int>());

	int ret = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			int diff = lv[i] - lv[j];
			for (int k = j+1; k < n; ++k) {
				if (diff < lv[k]) {
					++ret;
				}
			}
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder text = new StringBuilder();
		while (true) {
			int H = scan.nextInt();
			int W = scan.nextInt();
			if (H == 0 && W == 0) {
				scan.close();
				text.deleteCharAt(text.lastIndexOf("\n"));
				System.out.println(text.toString());
				break;
			} else {
				for(int i = 0;i < H;i++){
					for(int t = 0;t < W ;t++){
						if(i == 0 || i == H - 1 || t == 0 || t == W - 1)
							text.append("#");
						else
							text.append(".");
					}
					text.append("\n");
				}
				text.append("\n");
			}
		}
	}
}

Measured memory_bytes: 20856
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;;
using vvi=vector<vi>;
using vb=vector<bool>;
using pii=pair<int,int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vector<vb> matr(n,vb(n,false));
    rep(i,0,n){
        int index;
        cin>>index;
        index--;
        int num,in;
        cin>>num;
        rep(c,0,num){
            cin>>in;
            in--;
            matr[index][in]=true;
        }
    }
    rep(i,0,n){
        int cnt=0;
        rep(j,0,n){
            if(cnt++)cout<<" ";
            cout<<matr[i][j];
        }
        cout<<endl;
    }
    return 0;
}





Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

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

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

typedef unsigned long long ull;

struct Edge{
    int to, cost;
};

int C, N, M, S, D;
int cost[110][110];
int d[110][20], used[110][20];

void dijkstra(){
    REP(i, 110){
        REP(j, 20){
            d[i][j] = INF;
            used[i][j] = 0;
        }
    }

    d[S][0] = 0;

    while(1){
        int u = -1, v = -1;
        REP(i, N){
            REP(j, C+1){
                if(!used[i][j] && (u == -1 || d[u][v] > d[i][j])){u = i; v = j;}
            }
        }

        if(u == -1){break;}
        used[u][v] = 1;

        REP(i, N){
            if(v+1 <= C){
                d[i][v+1] = std::min(d[i][v+1], d[u][v] + cost[u][i] / 2);
            }
            d[i][v] = std::min(d[i][v], d[u][v] + cost[u][i]);
        }
    }
}

int main(){
    while(std::cin >> C >> N >> M >> S >> D, C){
        S--; D--;

        REP(i, 110){
            REP(j, 110){
                cost[i][j] = INF;
            }
        }

        REP(i, M){
            int from, to, co;
            std::cin >> from >> to >> co;
            from--; to--;
        
            cost[from][to] = co;
            cost[to][from] = co;
        }

        dijkstra();

        int res = INF;
        REP(i, C+1){
            res = std::min(res, d[D][i]);
        }

        std::cout << res << std::endl;
    }
}

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

struct Point {
  ll x        = 0;
  bool sunuke = true;
};

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--;
  b--;
  c--;
  d--;
  string s;
  cin >> s;

  queue<Point> q;
  q.push({x : b, sunuke : false});

  bool res  = false;
  bool C    = false;
  bool D    = false;
  ll aNow   = a;
  ll bNow   = b;
  bool nowA = false;
  while (!q.empty()) {
    Point p = q.front();
    q.pop();
    if (nowA && !p.sunuke) continue;
    if (!nowA && p.sunuke) continue;
    if (p.x >= n || s[p.x] == '#') continue;
    if (nowA && p.x == bNow) continue;
    if (!nowA && p.x == aNow) continue;
    if (p.sunuke && C) continue;
    if (!p.sunuke && D) continue;
    if (C && D) break;

    if (p.sunuke) {
      aNow = p.x;
      if (p.x == c) {
        C = true;
        q.push({x : bNow + 1, sunuke : false});
        q.push({x : bNow + 2, sunuke : false});
        nowA = !nowA;
        continue;
      }
      if ((p.x <= n - 1 && (s[p.x + 1] == '#' || p.x + 1 == bNow)) &&
          (p.x <= n - 2 && (s[p.x + 2] == '#' || p.x + 2 == bNow))) {
        break;
      }
      if (aNow > bNow && p.x < n - 1 && s[p.x - 1] == '.' &&
          s[p.x + 1] == '.') {
        q.push({x : bNow + 1, sunuke : false});
        q.push({x : bNow + 2, sunuke : false});
        nowA = !nowA;
      } else {
        q.push({x : p.x + 1, sunuke : true});
        q.push({x : p.x + 2, sunuke : true});
      }
    }
    if (!p.sunuke) {
      bNow = p.x;
      if (p.x == d) {
        D = true;
        q.push({x : aNow + 1, sunuke : true});
        q.push({x : aNow + 2, sunuke : true});
        nowA = !nowA;
        continue;
      }
      if ((p.x <= n - 1 && (s[p.x + 1] == '#' || p.x + 1 == aNow)) &&
          (p.x <= n - 2 && (s[p.x + 2] == '#' || p.x + 2 == aNow))) {
        break;
      }
      if (bNow > aNow && p.x < n - 1 && s[p.x - 1] == '.' &&
          s[p.x + 1] == '.') {
        q.push({x : aNow + 1, sunuke : true});
        q.push({x : aNow + 2, sunuke : true});
        nowA = !nowA;

      } else {
        q.push({x : p.x + 1, sunuke : false});
        q.push({x : p.x + 2, sunuke : false});
      }
    }
  }
  cout << (C && D ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
n=int(input())
s=list(input())
num=[0]*26
for i in range(n):
    num[ord(s[i])-97]+=1
ans=1
for i in range(26):
    ans*=num[i]+1
    ans%=10**9+7
ans-=1
ans%=10**9+7
print(ans)


Measured memory_bytes: 9760
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

int main(){
	
	int a[3];
	
	int total[4];
	
	bool checker = true;
	
	for(int i = 0; i < 4; i++){
		total[i] = 0;
	}
	
	while(true){
		cin >> a[0];
		if(cin.eof()){
			break;
		}
		cin >> a[1] >> a[2];
		if(checker){
			sort(a, a + 3);
			if(a[0] + a[1] <= a[2]){
				checker = false;
				continue;
			}
			total[0]++;
			if(a[0] * a[0] + a[1] * a[1] == a[2] * a[2]){
				total[1]++;
			}else if(a[0] * a[0] + a[1] * a[1] > a[2] * a[2]){
				total[2]++;
			}else{
				total[3]++;
			}
		}
	}
	
	printf("%d %d %d %d\n", total[0], total[1], total[2], total[3]);
	
	return 0;
}

Measured memory_bytes: 1160
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    st = set(S)
    ret = [False] * len(st)
    i = 0
    for s in st:
        if S.count(s) % 2 == 0:
            ret[i] = True
        i+=1
    print('Yes' if all(ret) else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3832
a,b=map(int,input().split())
L=list(map(int,input().split()))
s=0
if L[0]>b:
  s+=L[0]-b
  L[0]=b
for i in range(1,a):
  if L[i-1]+L[i]>b:
    s+=L[i]-b+L[i-1]
    L[i]=b-L[i-1]
print(s)

Measured memory_bytes: 85784