akhauriyash/Code-Regression huggingface dataset:
//==========================================================================
//
//                   Bismillahir-Rahmanir-Rahim
//
// ==========================================================================
#include <bits/stdc++.h>
#define        ll                              long long int
#define        f(x,y,z)                        for(int x=y;x<z;x++)
#define        pii                             pair<int,int>
#define        pll                             pair<ll,ll>
#define        CLR(a)                          memset(a,0,sizeof(a))
#define        SET(a)                          memset(a,-1,sizeof(a))
#define        N                               100010
#define        M                               1000000007
#define        pi                              acos(-1.0)
#define        ff                              first
#define        ss                              second
#define        pb                              push_back
#define        inf                             (int)1e9
#define        eps                              1e-9
using namespace std;
int dx[]={0,0,1,-1,-1,-1,1,1};
int dy[]={1,-1,0,0,-1,1,1,-1};
template < class T> inline T biton(T n,T pos){return n |((T)1<<pos);}
template < class T> inline T bitoff(T n,T pos){return n & ~((T)1<<pos);}
template < class T> inline T ison(T n,T pos){return (bool)(n & ((T)1<<pos));}
template < class T> inline T gcd(T a, T b){while(b){a%=b;swap(a,b);}return a;}
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }
inline int nxt(){int aaa;scanf("%d",&aaa);return aaa;}
inline ll lxt(){ll aaa;scanf("%lld",&aaa);return aaa;}
inline double dxt(){double aaa;scanf("%lf",&aaa);return aaa;}
template <class T> inline T bigmod(T p,T e,T m){T ret = 1;
for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % m;p = (p * p) % m;
} return (T)ret;}
#define sayed
#ifdef sayed
     #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif
struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///******************************************START******************************************

 int mat[200][200];
 int in[200][200];
 int edge[104][105];
void  reset(int n){
   f(i,0,n+1) f(j,0,n+1) mat[i][j]=inf;
 }
void warshall(int n){
   f(k,1,n+1) f(i,1,n+1) f(j,1,n+1)
       if(mat[i][k]+mat[k][j]<mat[i][j]) mat[i][j]=mat[i][k]+mat[k][j];
}
int main(){
     //freopen("out.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
   //cin.tie(0);
   reset(105);
   int n=nxt();
   int m=nxt();
   for(int i=0;i<m;i++){
      int a=nxt();
      int b=nxt();
      int c=nxt();
      mat[a][b]=mat[b][a]=c;
      in[a][b]=in[b][a]=c;
      edge[a][b]=1;
   }
  // reset(n);
   warshall(n); int c=0;
  // cout<<mat[1][2]<<endl;
   for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
        if(edge[i][j]&&mat[i][j]<in[i][j]){
            c++;
        }
    }
   }
   cout<<c<<endl;


return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdbool.h>

int main(void){
    int n;

    scanf("%d",&n);
    int a[n];
    bool flag = true;
    for(int i=0;i<n;++i){
        scanf("%d",a+i);
    }
    for(int j=0;j<n;++j){
        if(a[j]%2==0){
            if(a[j]%3!=0&&a[j]%5!=0){
                flag = false;
            }
        }
    }
    if(flag){
        printf("APPROVED");
    }else{
        printf("DENIED");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#include<algorithm>
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int n=abs(a-b);
  int m=abs(a-c);
  if(n>m)cout<<"B"<<endl;
  else cout<<"A"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

int main(void){

  int size,truck,capacity,max=0,sum=0;
  cin>>size>>truck;
  vector<int> weight(size);
  for(int i=0;i<size;i++){
    cin>>weight.at(i);
    if(max<weight.at(i)) max=weight.at(i);
    sum+=weight.at(i);
  }

  capacity=max*truck;
  while(capacity<sum){
    max++;
    capacity=max*truck;
  }
  int tcap,tnum;
  while(true){
    tcap=0;tnum=1;
    for(int i=0;i<size;i++){
      tcap+=weight.at(i);
      if(tcap>max){
        tcap=weight.at(i);
        tnum++;
      }
      if(tnum>truck) break;
    }
    if(tnum<=truck) break;
    max++;
  }
  cout<<max<<endl;
  return 0;

}



Measured memory_bytes: 3136
import copy
import numpy as np
n = int(input())
a = list(map(int, input().split()))
S = sum(abs(np.array([0] + a) - np.array(a+[0])))
a = [0] + a + [0]
for i in range(1, len(a)-1):
    cost = S + abs(a[i-1] - a[i+1]) - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]))
    print(cost)

Measured memory_bytes: 22920
from collections import Counter
N = int(input())
s = input()
mx = 0
for i in range(1,N):
    ans1 = dict(Counter(s[:i]))
    ans2 = dict(Counter(s[i:]))
    count = 0
    for j in ans1:
        if j in ans2:
            count += 1
    mx = max(mx,count)
    
print(mx)

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

map<int,map<int,int>> mp;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W,m;
    cin >> H >> W >> m;
    vector<int> h(m),w(m);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        --x;--y;
        h[i]=x; w[i]=y;
        mp[x][y]=1;
    }
    vector<int> yoko(H,0),tate(W,0);
    vector<vector<int>> a(H),b(W);
    rep(i,m){
        ++yoko[h[i]];
        ++tate[w[i]];
        a[h[i]].push_back(w[i]);
        b[w[i]].push_back(h[i]);
    }
    int maxt=0,maxy=0;
    rep(i,H){
        maxy=max(maxy,yoko[i]);
    }
    rep(i,W){
        maxt=max(maxt,tate[i]);
    }
    vector<int> t,y;
    rep(i,H){
        if(yoko[i]==maxy) y.push_back(i);
    }
    rep(i,W){
        if(tate[i]==maxt) t.push_back(i); 
    }
    ll cnt=y.size()*t.size();
    ll mm=m;
    if(cnt>mm){
        cout << maxy+maxt << "\n";
        return 0;
    }
    bool ok=true;
    for(auto u:y){
        for(auto v:t){
            if(mp[u][v]==0){
                cout << maxt+maxy << "\n";
                return 0;
            }
        }
    }
    cout << maxt+maxy-1 << "\n";
    return 0;
}   


Measured memory_bytes: 87096
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	ios_base::sync_with_stdio(0);
  	cin.tie(NULL); 

  	long long a, b;
  	cin >> a >> b;
  	cout << (a*b)/__gcd(a, b) << '\n';

  	return 0;
}

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

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

    rep(i, 1000){
        if(pow(K, i) > N){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int func(char s[10000]){
  int num[4000],ans=0,n,cnt=0,lp[4000],rp[4000],l,r;
  char ss[10000];
  l=r=0;
  n=strlen(s);
  for(int i=1;i<n-1;i++){
    if(s[i]=='['){
      l++;
      if(l-r==1)
        lp[cnt]=i;
    }
    else if(s[i]==']'){
      r++;
      if(l-r==0){
        rp[cnt]=i;
        for(int j=lp[cnt];j<=rp[cnt];j++)
          ss[j-lp[cnt]]=s[j];
        ss[rp[cnt]-lp[cnt]+1]='\0';
        num[cnt]=func(ss);
        cnt++;
      }
    }
  }
  if(cnt>0){
    sort(num,num+cnt);
    for(int i=0;i<=cnt/2;i++)
      ans+=num[i];
  }
  else{
    for(int i=1;i<n-1;i++){
      ans*=10;
      ans+=s[i]-'0';
    }
    ans/=2;
    ans++;
  }
  return ans;
}

int main(){
  int n;
  char s[10010];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s",s);
    printf("%d\n",func(s));
  }
}


Measured memory_bytes: 2780
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }
    int sum = 1;
    for (int i = 1; i < n; i ++){
        if (s[i] != s[i-1]) sum ++;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1144
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}



signed main(){
	
	string s;
	
	cin >> s;
	
	rep(i,1,1+s.size()){
		if((i % 2 && (s[i-1] == 'L')) || (!(i % 2) && (s[i-1] == 'R'))){
			cout << "No" << endl;
			break;
		}
		else if(i == s.size())cout << "Yes" << endl;
		
	}
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
      mint a = pow(t>>1);
      a *= a;
    if (t&1) a *= *this;
      return a;
  }
   mint inv() const { return pow(MOD-2);}
   mint& operator/=(const mint a) { return *this *= a.inv();}
   mint operator/(const mint a) const { return mint(*this) /= a;}
};
typedef vector<mint> vm;
typedef vector<vm> vvm;

class Combi {
public:
  v(ll) fac, inv, finv;
  void init(int N) {
    fac[0] = fac[1] = 1; inv[1] = 1; finv[0] = finv[1] = 1;
    for (int i = 2; i < N; i++) {
      fac[i] = fac[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
      finv[i] = finv[i - 1] * inv[i] % MOD;
    }
  }
  Combi(int N) : fac(N + 1), inv(N + 1), finv(N + 1) { init(N + 1); }
  ll Cmod(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
  }
  ll Pmod(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
  }
};
  
int main() {
  int N;
  int a,b,c,d;
  cin >> N;
  cin >> a >> b >> c >> d;
  Combi comb(N*2);
  vv(ll) memo(N+1,vl(N+1,-INF));
  auto dfs = [&](auto self,int x,int y) -> mint {
    
    if(y==0) return mint(1);
    if(x>b) return mint(0);
    if(x>y) return mint(0);
    if(memo[x][y]>=0) {
      return mint(memo[x][y]);
    }
    mint res = self(self,x+1,y);
    mint tmp = 1;
    for(int k=1,ny=y;k<=d&&x<=ny;k++) {
      tmp *= comb.inv[k]*comb.Cmod(ny,x);
      ny -= x;
      if(c<=k) {
        res += tmp * self(self,x+1,ny);
      }
    }
    memo[x][y]=res.x;
    return res;
  };
  mint ans = dfs(dfs,a,N);
  cout << ans.x << endl;
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  cout << (b-a)*(b-a+1)/2 - b << endl;

}



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

using namespace std;
int main(){
long long n=0,d=0,ans=0,x=0,y=0;
cin>>n>>d;
d=d*d;
while(n--){
cin>>x>>y;
x=x*x,y=y*y;
if(x+y<=d)ans++;
}
cout<<ans;



    return 0;
}


Measured memory_bytes: 3620
s=gets.chomp
t=[""]
(s.length).times do |i|
  t.length.times do |j|
    t[j]+=s[i]
    if t[j]=="dream"
      t<< ""
    elsif t[j]=="erase"
      t<< ""
    elsif t[j]=="dreamer"
      t[j]=""
    elsif t[j]=="eraser"
      t[j]=""
    elsif t[j][0]!=?d&&t[j][0]!=?e
      t[j]=nil
    elsif t[j].length==8
      t[j]=nil
    end
  end
  t.compact!
end
puts t.include?("")? :YES : :NO

Measured memory_bytes: 2044
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long

using namespace std;

int n;

int main(){
  cin >> n;
  string s[n];
  vector<char> c;
  vector<ll int> v;
  char march[5] = {'M', 'A', 'R', 'C', 'H'};
  
  REP(i, n) cin >> s[i];
  REP(i, n) c.push_back(s[i][0]);
  
  REP(i, 5){
    int num;
    num = count(c.begin(), c.end(), march[i]);
    if(num != 0){
      v.push_back(num);
    }
  }

  int l = v.size();
  if(l <= 2){
    cout << 0 << endl;
  }else if(l == 3){
    printf("%lld\n", v[0] * v[1] * v[2]);
  }else if(l == 4){
    printf("%lld\n", v[0] * v[1] * v[2] + v[0] * v[1] * v[3] + v[0] * v[2] * v[3] + v[1] * v[2] * v[3]);
  }else{
    printf("%lld\n", v[0] * v[1] * v[2] + v[0] * v[1] * v[3] + v[0] * v[1] * v[4] + v[0] * v[2] * v[3] + v[0] * v[2] * v[4] +  v[0] * v[3] * v[4] + v[1] * v[2] * v[3] + v[1] * v[2] * v[4] + v[1] * v[3] * v[4] + v[2] * v[3] * v[4]);
  }

  return 0;
}

Measured memory_bytes: 6400
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    int price = 700;
    
    String first = s.substring(0, 1);
    String second = s.substring(1, 2);
    String third = s.substring(2, 3);
    
    if (first.equals("o")) {
      price += 100;
    }
    if (second.equals("o")) {
      price += 100;
    }
    if (third.equals("o")) {
      price += 100;
    }
    
    System.out.println(price);
  }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define M 1000000007
#define M 998244353
const int inf=4e18;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	string s;cin>>s;
	if(s[2]==s[3]&&s[4]==s[5])
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

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

int main(){
	int N,K,P,A;
	cin>>N;
	for(int i=0;i<N;i++){
	cin>>K>>P;
	A=K%P;
	 if(K%P==0){
		cout<<P<<endl;
		}else{
		cout<<A<<endl;
	 }
	}
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cmath>
// #include<bits/stdc++.h>

using namespace std;

int main() {
	string S, T;
	cin >> S >> T;

	for (int i = 0; i < S.length(); i++) {
		if (S[i] != T[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

}


Measured memory_bytes: 3060
L, R = (int(_) for _ in input().split())  

result = 2020

if R - L > 2020:
    result = 0
else:
    for i in range(L, R+1):
        for j in range(L, R+1):
            if i < j:
                result = min(result, (j * i) % 2019)

print(result)

Measured memory_bytes: 42220
#include<cstdio>
#include<cstring>
#define fo(i,a,b)for(int i=a;i<=b;i++)
using namespace std;
char c[20],ch;
int n,g,gg;
int main(){
	for(;(ch=getchar())<='Z'&&ch>='A'||ch>='a'&&ch<='z';)c[++n]=ch;
	fo(i,1,n)g+=(c[i]>='A'&&c[i]<='Z'),gg+=(c[i]=='C');
	if(g==2&&c[1]=='A'&&c[2]!='C'&&gg==1&&c[n]!='C')printf("AC");else printf("WA");
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;





signed main() {
    ll n, m, c;
    cin >> n >> m >> c;
    
    ll r = 0;
    
    vll b(m);
    rep(i, m) {
        cin >> b[i];
    }
    
    vll a(m);
    ll tmp = 0;
    rep(i, n) {
        rep(j, m) {
            cin >> a[j];
            tmp += a[j] * b[j];
        }
        tmp += c;
        if (tmp > 0) r ++;
        tmp = 0;
        
    }
    
    mes(r);
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 3516
#! /usr/bin/python3
# A to Z String
""" 文字列から 'A***Z' のような文字列を抜き出す """

s = input()
list_s = list(s)

test = False

def length_AZ(l):
    """ 最初の'A'と最後の'Z'の位置の差を返す関数"""
    len_l = len(l)
    index_A = []
    index_Z = []

    for i in range(len_l):
        if l[i] == 'A':
            index_A.append(i)
        elif l[i] == 'Z':
            index_Z.append(i)

    if test:
        print('index_A =', index_A)
        print('index_Z =', index_Z)

    return max(index_Z) - min(index_A) + 1


def main():
    """ 答えを出力する """
    print(length_AZ(list_s))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12792
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>

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

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		std::vector<int> num;
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (; x; x /= 10) {
			num.push_back(x % 10);
		}
		while (!num.empty()) {
			putchar(num.back() ^ '0');
			num.pop_back();
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 100005;

int n, rt;
std::vector<int> E[N];
int f[N];

void dfs(int u, int fa = -1) {
	bool flag = 0;
	for (int v : E[u]) {
		if (v != fa) {
			dfs(v, u);
			if (!f[v]) {
				flag = 1;
				f[u] += 1;
			} else {
				f[u] += f[v];
			}
		}
	}
	f[u] -= flag;
}

int main() {
	read(n);
	for (int i = 0; i < n - 1; ++i) {
		int u, v;
		read(u), read(v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	rt = -1;
	for (int i = 0; i < n; ++i) {
		if ((int)E[i].size() > 2) {
			rt = i;
			break;
		}
	}
	if (rt == -1) {
		print(1);
		return 0;
	}
	dfs(rt);
	print(f[rt]);
}


Measured memory_bytes: 14140
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t n,x;
  cin >> n >> x;
  vector<int64_t> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int64_t sum = 0;
  int64_t cnt = 0;
  rep(i,n){
    sum += a.at(i);
    if(sum > x){
      break;
    }
    //cout << sum;
    cnt++;
    if(i == n-1 && sum != x){
      cnt--;
    }  
  }
  cout << cnt << endl;
    
  
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int h, w;
  cin >> h >> w;

  vector<string> m(h);
  rep(i, h) {
    cin >> m[i];
  }

  int dx[] = {0, 0, 1, -1};
  int dy[] = {1, -1, 0, 0};
  bool ans = true;
  rep(i, h) {
    rep(j, w) {
      if(m[i][j] == '.') continue;
      bool enable = false;
      rep(k, 4) {
        int y = i + dy[k]; // 縦
        int x = j + dx[k]; // 横
        if(!(0 <= y && y < h && 0 <= x && x < w)) continue;
        if(m[y][x] == '#') {
          enable = true;
        }
      }
      if(!enable) {
        ans = false;
      }
    }
  }

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include <bits/stdc++.h>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(int a,int b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 

 
int main() {
    ll sx,sy,tx,ty;

    cin>>sx>>sy>>tx>>ty;

    int sabunx=tx-sx;
    int sabuny=ty-sy;

    FOR(i,0,sabunx-1){
      cout<<"R";
    }

    FOR(i,0,sabuny-1){
      cout<<"U";
    }
    FOR(i,0,sabunx-1){
      cout<<"L";
    }

    FOR(i,0,sabuny-1){
      cout<<"D";
    }
      cout<<"D";
    FOR(i,0,sabunx){
      cout<<"R";
    }

    FOR(i,0,sabuny){
      cout<<"U";
    }
      cout<<"L";
      cout<<"U";
    FOR(i,0,sabunx){
      cout<<"L";
    }

    FOR(i,0,sabuny){
      cout<<"D";
    }
      cout<<"R";
  return 0;
}





Measured memory_bytes: 256
N = int(input())
X = sorted(list(map(int, input().split())))
p = [[] for _ in range(max(X))]
for i in range(max(X)):
    for j in X:
        p[i].append((j - (i+1)) ** 2)
sums = [sum(pp) for pp in p]
print(min(sums))

Measured memory_bytes: 3316
#include<stdio.h>

int main(void) {
	int a, b, c;

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

	if (a < b){
		if (b < c) {
			printf("Yes\n");
		}
		else if(b >= c) {
			printf("No\n");
		}
	}
	else if(a >= b) {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
n = int(input())
a = list(map(int,input().split()))
hidariwa = sum(a)
migiwa = 0
answer = hidariwa
for i in range(n):
  hidariwa -= a[i]
  migiwa +=a[i]
  answer = min(abs(hidariwa-migiwa),answer)
print(answer)

Measured memory_bytes: 31264
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
lld dp[51][51][2510];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	lld n,a;
	cin >> n >> a;
	lld arr[n];
	for(lld i=0;i<n;i++)
		cin >> arr[i];
	lld m=max(*max_element(arr,arr+n),a);
	dp[0][0][0] = 1;
	for(lld i=0;i<=n;i++)
	{
		for(lld j=0;j<=n;j++)
		{
			for(lld k=0;k<=(m*n);k++)
			{
				if(i==0 && j==0 && k==0)
					dp[i][j][k]=1;
				else if(i>=1 && arr[i-1]>k)
					dp[i][j][k] = dp[i-1][j][k];
				else if(i>=1 && j>=1 && k>=arr[i-1])
					dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-arr[i-1]];
				else
					dp[i][j][k]=0;
			}
		}
	}
	lld ans=0;
	for(lld i=1;i<=n;i++)
	{
		ans+=dp[n][i][i*a];
	}
 	cout << ans;
}

Measured memory_bytes: 51328
#include<iostream> 
#include<cstring> 
#include<limits.h> 
#include<algorithm>
#define inf 1000000007
using namespace std;
 
int dp[200005];
 
int main()
{
    memset(dp, 0, sizeof(dp));
    
    int n,k; cin >> n >> k; int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    
    dp[1] = abs(a[1]-a[0]);
    
    for(int i = 2; i < n; ++i)
    {
        dp[i] = inf;
        
        for(int j = i-1; j >= max(0, i-k); j--) dp[i] = min(dp[i], dp[j] + abs(a[i]-a[j]));
    }
    
    cout << dp[n-1];
}

Measured memory_bytes: 4304
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);
typedef complex<double> P;
typedef complex<double> point;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}

struct L : public vector<P> {
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};

typedef vector<P> G;
typedef vector<P> polygon;

struct C {
	P p; double r;
	C(const P &p, double r) : p(p), r(r) { }
};
//??????????????????
int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;       // counter clockwise
	if (cross(b, c) < 0)   return -1;       // clockwise
	if (dot(b, c) < 0)     return +2;       // c--a--b on line
	if (norm(b) < norm(c)) return -2;       // a--b--c on line
	return 0;
}
bool intersectSP(const L &s, const P &p) {
	return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
P projection(const L &l, const P &p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}
double distanceSP(const L &s, const P &p) {
	if(intersectSP(s, p)) return 0.0;
	const P r = projection(s, p);
	if (intersectSP(s, r)) return abs(r - p);
	return min(abs(s[0] - p), abs(s[1] - p));
}

//?????¢???rate???????????§???????°????
point spinPExtend(const point& p, double theta, double rate = 1.0){
	return p*complex<double>(rate*cos(theta),rate*sin(theta));
}

int main(){
	double r;
	int n;
	while(cin >> r>> n) {
		if((int)r == 0 && n == 0) break;
		C cir({0.0,0.0}, r);
		vector<C> cs;
		vector<double> v;
		vector<int> exist(n, 1);
		rep(i, n) {
			double x, y, _r, _v;
			cin >> x >> y >> _r >> _v;
			cs.pb({{x, y}, _r});
			v.pb(_v);
		}
		int ans = 0;
		while(1){
			int idx = -1;
			double mindist = INF, maxdist = 0.0;
			rep(i, n) if(exist[i] != 0) {
				double dist = abs(cs[i].p);
				if(dist < v[i] + EPS) {
					exist[i] = 0;
					ans++;
					continue;
				}
				cs[i].p *= (dist-v[i])/dist;
				dist = abs(cs[i].p);
				if(dist < r + EPS) {
					exist[i] = 0;
					ans++;
					continue;
				}
				if(dist < mindist - EPS) idx = i, mindist=dist;
				if(dist > maxdist + EPS) maxdist = dist;
			}
			if(idx == -1) break;
			L l(cs[idx].p * (maxdist + 500.0)/abs(cs[idx].p), cs[idx].p*r/abs(cs[idx].p));
			rep(i, n) if(exist[i] != 0) {
				if(distanceSP(l, cs[i].p) < cs[i].r+EPS) exist[i] = 0;
			}
		}
		//rep(i, n) if(exist[i]) ans++;
		rep(i, n) assert(exist[i] == 0);
		cout<<ans<<endl;
	}
}

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

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

    if (S.size() <= K) cout << S << endl;
    else {
        S = S.substr(0, K);
        cout << S << "..." <<endl;
    }
}

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

using namespace std;

typedef long long int ll;

#define FOR(i,l,r) for(i=l;i<r;i++)

#define REP(i,n) FOR(i,0,n)

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

#define P pair<ll,ll>

#define F first

#define S second

signed main(){

  ll N,X,T;cin>>N>>X>>T;

  cout<<((N-1)/X+1)*T<<endl;

  return 0;

}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    int cnt = 0;
    for (int i = sz(s) - 1; i >= 0; --i) {
        if (s[i] == ')') {
            cnt++;
        } else {
            if (cnt) cnt--;
        }
    }
    
    int cnt2 = 0;
    rep(i, sz(s)) {
        if (s[i] == '(') {
            cnt2++;
        } else {
            if (cnt2) cnt2--;
        }
    }
    rep(i, cnt) cout << '(';
    cout << s;
    rep(i, cnt2) cout << ')';
    cout << endl;
}


Measured memory_bytes: 256
//arc058_d.cpp
//Wed Jul  3 21:40:49 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

//nCk を1000000007で割った余りの計算。
const int MAX = 200000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(ll n, ll k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

	COMinit();

	ll ans = 0;
	for (int i=b+1;i<=w;i++){
		ans = (ans + (COM(h-a-1+i-1,max(h-a-1,i-1))*COM(a-1+w-i,max(a-1,w-i)))%MOD)%MOD;
//		cout << i<<endl;
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 4992
import java.io.*;
import java.util.*;

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

    for(int i=0;i<array.length;i++){
      array[i]=Integer.parseInt(scan.next());
    }

    Arrays.sort(array);

    System.out.println(array[0]+" "+array[1]+" "+array[2]);
  }
}


Measured memory_bytes: 26176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
#define f(i,j) f[i+N][j]
#define new_f(i,j) new_f[i+N][j]
const int N=6e3+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,mod,f[N<<1][3],new_f[N<<1][3];

int upd(int a,int b) {
	if(b==0) return a+1;
	if(b==1) return a-1;
	return a;
}

void inc(int &a,int b) {
	a=a+b>=mod?a+b-mod:a+b;
}

int main() {
	cin>>n>>mod;
	f(0,0)=1;
	for(int i=1;i<=3*n;i++) {
		memset(new_f,0,sizeof(new_f));
		for(int j=-3*n;j<=3*n;j++)
			for(int k=0;k<3;k++) {
				if(!f(j,k)) continue;
				inc(new_f(upd(j,k),0),f(j,k));
				if(k+1<3) inc(new_f(j,k+1),1ll*f(j,k)*(i-1)%mod);
			}
		swap(f,new_f);
	}
	int ans=0;
	for(int i=0;i<=3*n;i++)
		for(int j=0;j<3;j++)
			if(upd(i,j)>=0) inc(ans,f(i,j));
	cout<<ans;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define rsort_v(v) std::sort(v.rbegin(), v.rend())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //

int main() {
	int t[3][2];
	loop(i, 3) {
		in(int, a, b);
		t[i][0] = std::min(a, b);
		t[i][1] = std::max(a, b);
	}
	int k[6][3] = {
	{ 0, 1, 2 },
	{ 0, 2, 1 },
	{ 1, 0, 2 },
	{ 1, 2, 0 },
	{ 2, 0, 1 },
	{ 2, 1, 0 }
	};
	loop(tt, 6) {
		int* t1 = t[k[tt][0]];
		int* t2 = t[k[tt][1]];
		int* t3 = t[k[tt][2]];
		loop(t1x, 2)loop(t2x, 2)loop(t3x, 2) {
			if (t1[t1x] == t2[1-t2x] && t2[t2x] == t3[1-t3x] && t3[t3x] != t1[1-t1x]) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
a = list(map(int, input().split()))

band = sum(a[:K])
other = 0
for i in range(K, N):
    other += max(0, a[i])
ans = max(band, 0) + other
for i in range(N - K):
    band -= a[i]
    band += a[K + i]
    other += max(a[i], 0)
    other -= max(a[K + i], 0)
    ans = max(ans, max(band, 0) + other)
print(ans)


Measured memory_bytes: 66080
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
 
const int N = 1e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

inline int mul(int a, int b){
    return ((ll)a * b) % mod;
}

inline int add(int a, int b){
    int ans = a + b;
    if(ans >= mod) ans -= mod;
    return ans; 
}

// credits : codeforces :https://codeforces.com/blog/entry/54396
bool isprime(ll n){
    if(n<2) return false;
    for(ll i=2;i*i*i<=n;++i) if(n%i==0) return false;
    for(int it=0;it<1e2;++it){
        ll i = rand()%(n-1)+1;
        if(__gcd(i,n)!=1) return false;
        // if(mpow(i,n-1,n)!=1) return false;
    }
    return true;
}

vector<ll> in(N), out(N);
vector<int> g[N];

void dfs_in(int src, int par, const int mod){
    ll &cur = in[src];
    cur = 1;
    for(auto i : g[src])
        if(i != par) {
            dfs_in(i, src, mod);
            cur = (cur * (in[i] + 1)) % mod;
        }
}

void dfs_out(int src, int par, const int mod){
    if(par && (int)g[src].size() == 1) return;

    vector<int> child;
    for(auto i : g[src]){
        if(i == par) continue;
        child.pb(i);
    }

    vector<ll> pre((int)child.size() + 2, 1), suf((int)child.size()+2, 1);
    for(int j = 1; j <= (int)child.size(); j++)
        pre[j] = (pre[j-1] * (in[child[j-1]] + 1)) % mod;
    for(int j = (int)child.size(); j > 0; j--)
        suf[j] = (suf[j+1] * (in[child[j-1]] + 1)) % mod;

    for(int j = 1; j <= (int)child.size(); j++){
        int cur = child[j-1];
        ll below = (pre[j-1] * suf[j+1]) % mod;
        out[cur] = (out[src] * below) % mod;
        out[cur] = (out[cur] + 1) % mod;
        dfs_out(cur, src, mod);
    }
}

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    
    int n, mod;
    cin >> n >> mod;
    for(int j = 0; j < n-1; j++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs_in(1, 0, mod);
    out[1] = 1;
    dfs_out(1, 0, mod);
    // for(int j = 1; j <= n; j++) cout << in[j] << " "; cout << endl;
    // for(int j = 1; j <= n; j++) cout << out[j] << " "; cout << endl;

    for(int j = 1; j <= n; j++) cout << (in[j] * out[j]) % mod << "\n";
    return 0;
}


Measured memory_bytes: 24320
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define int long long
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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int N;
vector<ll> A;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N;
  A.resize(N);
  rep(i,N){
    cin >> A[i];
  }
  rep(i,N){
    A[i] = A[i] - (i + 1);
  }
  sort(A.begin(),A.end());
  ll ret = 0;
  ll length = A.size();
  if(length % 2 == 0){
    rep(i,N){
      ret += abs(A[i] - A[length/2]);
    }
  }
  else{
    rep(i,N){
      ret += abs(A[i] - A[(length-1)/2]);
    }
  }

  cout << ret << endl;
  return 0;
}


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

#define int long long
struct Fast {Fast() {cin.tie(0); ios::sync_with_stdio(false);}} fast;

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  // int N;
  // int M;
  array<int, 4> A;
  string S;
  // string T;

  cin >> S;

  for (int i = 0; i < 4; ++i) {
    A[i] = (int)(S[i] - '0');
  }

  for (int i = 0; i < pow(2, 3); ++i) {
    int tmp = A[0];
    bitset<3> bs(i);

    for (int j = 0; j < 3; j++) {
      if (bs.test(j)) tmp += A[j + 1];
      else tmp -= A[j + 1];
    }

    if (tmp == 7) {
      cout << A[0];
      for (int j = 0; j < 3; j++) {
        if (bs.test(j)) cout << "+";
        else cout << "-";
        cout << A[j + 1];
      }
      cout << "=7" << endl;
      return 0;
    }
    
  }
  
  // cout << num << endl;
  // cout << fixed << setprecision(10) << num << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <cmath>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
typedef pair<int, int> PII;

int S;
string N;

int ans=-1;
vector<int> ans_list;
bool ng;

void init()
{
    ans = -1;
    ans_list.resize(0);
    ng = false;
}

void solve(int sum, int k, vector<int> list)
{
    if (sum > S) return;

    if (k == N.size()) { 
        if (sum > ans) {
            ans = sum;
            ans_list = list;
            ng = false;
        } else if (sum == ans) {
            ng = true;
        }
        return;
    }
    
    int n = 0;
    for (int i=0; k+i<N.size(); i++) {
        n *= 10;
        n += N[k+i] - '0';
        
        list.push_back(n);
        solve(sum+n, k+i+1, list);
        list.erase(list.end()-1);
    }
}

int main()
{
    while (cin>>S>>N, S) {
        init();
        
        solve(0, 0, vector<int>());
        
        if (ans == -1) cout << "error" << endl;
        else if (ng) cout << "rejected" << endl;
        else {
            cout << ans << " ";
            for (int i=0; i<ans_list.size(); i++) {
                if (i>0) cout << " ";
                cout << ans_list[i];
            }
            cout << endl;
        }
    }
}

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

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

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

fastio _fast_io;

const int N = 1e5 + 5;
int n;
int a, b, c, d;
bool neg[3];

int main() {
    cin >> n;
    a = n / 1000;
    b = (n % 1000) / 100;
    c = (n % 100) / 10;
    d = n % 10;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
            for (int k = 0; k < 2; ++k) {
                int t = a + b * (i ? 1 : -1) + c * (j ? 1 : -1) + d * (k ? 1 : -1);
                if (t == 7) {
                    char op1 = (i ? '+' : '-');
                    char op2 = (j ? '+' : '-');
                    char op3 = (k ? '+' : '-');
                    cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
                    exit(0);
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3604