akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#include <cstring>
#include <iterator>
#include <list>
#include <set>
#include <map>
#include <bitset>
using namespace std;

char s[200020];
int main()
{
  scanf("%s", s);

  int firsta = 200000000;
  int lastz = 0;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == 'A')
      firsta = min(firsta, i);
    else if (s[i] == 'Z')
      lastz = max(lastz, i);
  }

  printf("%d\n", lastz-firsta+1);
}

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

using namespace std;

#define endl '\n'

typedef long long ll;

const int maxn = 1e4 + 10;
const int maxd = 1e2 + 10;
const ll mod = 1e9 + 7;

ll dp[maxn][maxd];
int d;
string s;

ll solve(int n, int rem){
	if(n == 0)
		return (rem ? 0 : 1);
	if(dp[n][rem] != -1)
		return dp[n][rem];
	ll ans = 0;
	for(int i = 0; i < 10; i++)
		ans += solve(n - 1, (rem + i) % d), ans %= mod;
	return dp[n][rem] = ans;	
}

ll calc(){
	int sum = 0, n = (int)s.size();
	
	ll ans = 0;
	
	for(int i = 0; i < n; i++){
		int top = s[i] - '0';
		for(int j = 0; j < top; j++){
			int rem = (sum + j) % d;
			ans += solve(n - i - 1, rem), ans %= mod;
		}
		sum += top;
		sum %= d;
	}
	
	ans--;
	ans += mod;
	ans %= mod;
	
	if(sum == 0)
		ans++, ans %= mod;
	
	return ans;
}

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

	cin >> s >> d;
	memset(dp, -1, sizeof(dp));
	
	cout << calc() << endl;
	
	return 0;
}

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

using namespace std;
#ifdef ONLINE_JUDGE
#define cerr if(false)cerr
#endif
#define int long long
#define ld1 long double
#define watch(x) cerr << (#x) << " is " << (x) << endl
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout<<setprecision(14);
#define cint int t;cin>>t;while(t--)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
#define MAXN (int)1e6 + 11
#define INF (int)1e9
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define endl '\n'
#define vcc vector<char>
#define rep(i,a,b) for(int i=a;i<b;i++)
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
    for(int i=0;i<v.size();i++) {
        if(i) out << " ";
        out << v[i];
    }
    return out << endl;
}

const int mod=998244353;
//const int hell=mod;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int powmod(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return powmod(a,mod-2);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

string t;
int n;

void solve(){
    cin>>t;
    n=t.length();

    for(int i=0;i<n;i++){
        if(t[i]=='?') t[i]='D';
    }
    cout<<t<<endl;
}


int32_t main() {
    faster;

#ifndef ONLINE_JUDGE
    READ("input.txt");
    WRITE("output.txt");
    double beg=clock();
#endif

    int t=1;
//    cin>>t;

    while(t--){
        solve();
    }

#ifndef ONLINE_JUDGE
    double end=clock();
    cout<<endl;
    cerr<<"*** Total time = "<<(end-beg)/CLOCKS_PER_SEC;
#endif
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=n;++i)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if (c>=a && c<=b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  string s;
  cin >> N >> s;

  int l = 0, r = 0, p = 0, ans = 0;
  while (ans < N / 2 + 1 && r < N) {
    p = r + 1;
    bool flag = false;
    int ll = l, rr = r;
    while (p + rr - ll < N) {
      if (s.substr(p, r - l + 1) == s.substr(l, r - l + 1)) {
        flag = true;
        break;
      }
      p++;
    }
    if (!flag) {
      if (l + 1 < r)
        l++;
      else
        r++;
    } else {
      if (r - l + 1 < N / 2 + 1)
        r++;
      else
        l++;
    }
    if (flag) ans = max(ans, r - l);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        k: usize,
        s: String,
    }

    if s.len() <= k {
        println!("{}", s);
    } else {
        println!("{}{}", &s[..k], "...")
    }
}


Measured memory_bytes: 2160
#include <iostream>
#include <vector>
#include <climits>
#include <cstdio>

using namespace std;

int main()
{
  	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int n;
 	cin >> n;
  	vector<int> arr(n);
  	int maxval1 = INT_MIN, maxval2 = INT_MIN, id1, id2;
  	for (int i = 0; i < n; ++i) {
     	cin >> arr[i];
      	if (arr[i] > maxval1) maxval1 = arr[i], id1 = i;
    }
  	for (int i = 0; i < n; ++i)
      	if (arr[i] > maxval2 && i != id1) maxval2 = arr[i], id2 = i;
  	for (int i = 0; i < n; ++i) {
      	if (i != id1) cout << maxval1 << endl;
      	else cout << maxval2 << endl;
    }
 	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve(ll N, vl A);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll N;
    cin >> N;
    vl A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    solve(N, move(A));
}

void solve(ll N, vl A){
    ll can=1+N%2;

    vvl dp(can+1,vl(N+10,-LINF));
    repe(i,can){
        repe(j,i){
            dp[i][j]=0;
        }
    }
    rep(i,N){
        repe(j,can){
            dp[j][i]+=A[i];
            repe(k,can){
                if(j+k>can)continue;
                chmax(dp[j+k][i+k+2],dp[j][i]);
            }
        }
    }
    ll ans=-LINF;
    repe(i,can)repe(j,can)chmax(ans,dp[i][N+j]);
    cout<<ans<<endl;
}



Measured memory_bytes: 11120
#include <iostream>
#include <stdio.h>
#include <cstring>

using namespace std;

int main()
{
	long long a = 0, b = 0, compare = 100000000000000000;
	long long num1 = 0, num2 = 0, num3 = 0;
	cin >> a >> b;
	
	if(a%3 == 0 or b%3 == 0){
		
		cout << 0;
	}
	
	else{
		
		for(int i = 1; i < b; i++){
			
			num1 = a/2*i;
			num2 = (a-a/2)*i;
			num3 = a*(b-i);
			
			if(num1 <= num2 and num2 <= num3 and num3 - num1 < compare){
				
				compare = num3 - num1;
			}
			
			else if(num1 <= num3 and num3 <= num2 and num2 - num1 < compare){
				
				compare = num2 - num1;
			}
			
			else if(num3 <= num1 and num2 - num3 < compare){
				
				compare = num2 - num3;
			}
		}
		
		for(int i = 1; i < a; i++){
			
			num1 = b/2*i;
			num2 = (b-b/2)*i;
			num3 = b*(a-i);
			
			if(num1 <= num2 and num2 <= num3 and num3 - num1 < compare){
				
				compare = num3 - num1;
			}
			
			else if(num1 <= num3 and num3 <= num2 and num2 - num1 < compare){
				
				compare = num2 - num1;
			}
			
			else if(num3 <= num1 and num2 - num3 < compare){
				
				compare = num2 - num3;
			}
		}
		
		if(compare > a)
			compare = a;
		
		else if(compare > b)
			compare = b;
			
		cout << compare;
	}
}


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 pii = pair<int,int>;
using pil = pair<pii,int>;


int main(){
    string s;
    cin >> s;
    int t = s.size();
    rep(i,t){
        if(i%2 == 0)cout << s[i];
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
	int P[4] = { 6000, 4000, 3000, 2000 };

	int t[4], n[4];

	for (int i = 0; i < 4; i++)
	{
		cin >> t[i] >> n[i];
	}

	for (int i = 0; i < 4; i++)
	{
		cout << P[t[i] - 1] * n[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
#include <stdlib.h>

void Constraints(int W,int H,int x,int y,int r) //制約関数の宣言
{
  if(-100<=x&&x<=100&&-100<=y&&y<=100&&0<W&&W<=100&&0<H&&H<=100&&0<r&&r<=100){}
  else
  {
    printf("条件を満たす入力をしてください。\n");
    exit(0); //条件を満たさない場合プログラム終了
  }
}

void Check(int W,int H,int x,int y,int r,char **a)  //Sort関数の宣言
{
  if(x+r>W)
  {
    *a="No";
  }
  else if(y+r>H)
  {
    *a="No";
  }
  else if(r>x)
  {
    *a="No";
  }
  else if(r>y)
  {
    *a="No";
  }
  else
  {
    *a="Yes";
  }
}

int main(void)
{
  int W,H,x,y,r;
  char *answer="Hellow World";
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  Check(W,H,x,y,r,&answer);
  printf("%s\n",answer);
	return 0;
}



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

int main() {
    int N; cin >> N;
    string s; cin >> s;
    int cnt = 0;
    int l = 0, r = N - 1;
    while (l < r) {
        if (s[l] == 'R') {
            ++l; continue;
        }
        if (s[r] == 'W') {
            --r; continue;
        }
        swap(s[l], s[r]) ;
        ++cnt;
        ++l; --r;
    }
    cout << cnt << endl;
    return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
int n;
cin>>n;
int a[n];
rep(i,n){
    cin>>a[i];
} 
int now=0,count=0;;
rep(i,n){
    if(a[i]==now+1){
        now++;
count++;
    }
}
if(count==0){
    cout<<-1<<endl;
}else
{
    cout<<n-count<<endl;
}


    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	int n;
	cin>>n;
	int m=n%10;
	if(m==2 || m==4 || m==5 || m==7 || m==9) cout<<"hon\n";
	else if(m==0 || m==1 || m==6 || m==8) cout<<"pon\n";
	else cout<<"bon\n";
	return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
 using namespace std;
 
 // #define  int           long long
 #define pb                push_back
 #define ppb               pop_back
 #define pf                push_front
 #define ppf               pop_front
 #define all(x)            (x).begin(),(x).end()
 #define uniq(v)           (v).erase(unique(all(v)),(v).end())
 #define sz(x)             (int)((x).size())
 #define fr                first
 #define sc                second
 #define pint              pair<int,int>
 #define rep(i,a,b)        for(int i=a;i<b;i++)
 #define mem1(a)           memset(a,-1,sizeof(a))
 #define mem0(a)           memset(a,0,sizeof(a))
 #define ppc               __builtin_popcount
 #define ppcll             __builtin_popcountll
 #define vint			   vector<int>
 #define vpint			   vector<pair<int,int>>
 #define mp                make_pair


 void reader() 
 { 
 #ifndef ONLINE_JUDGE 
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout); 
 #endif
 }
 
 void fastIO() {ios_base::sync_with_stdio(false); cin.tie(NULL);}
 
 
 
 void solve()
 {
 
 int x;
 cin>>x;
 if(x==1)
 	cout<<0;
 else
 	cout<<1;
cout<<"\n";
 }
 
 
 
 signed main()
 {
 	reader(); fastIO();
 	long long t=1;
 	//cin>>t;
 	while(t--) solve();
 	return 0;
 }

Measured memory_bytes: 3604
n = int(raw_input())
a = []
for i in range(n):
    a.append(int(raw_input()))

max = a[1] - a[0]
min_num = a[0]
for i in a[1:]:
    if i - min_num > max:
        max = i - min_num
    if min_num > i:
        min_num = i
print max

Measured memory_bytes: 18864
import Numeric

showF :: RealFloat a => a -> String
showF = flip (showFFloat Nothing) ""

readNums :: (Read a, Num a) => IO [a]
readNums = fmap (map read . words) getLine

toRadian d = d / 180 * pi
area a b radC = 1/2 * a * (height a b radC)
cosl a b radC = sqrt $ a^2 + b^2 - 2 * a * b * cos(radC)
height a b radC = b * sin(radC)

main = do
  [a, b, c] <- readNums
  let radc = toRadian c
  let s = area a b radc
  let l = a + b + (cosl a b radc)
  let h = height a b radc
  mapM_ (putStrLn . showF) [s, l, h]

Measured memory_bytes: 4004
import sys
a = [list(map(int,input().split())) for _ in range(3)]
check = [[0]*3 for _ in range(3)]
n = int(input())
for i in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                check[i][j] = 1
#たて
for j in range(3):
    ch = 0
    for i in range(3):
        if check[i][j] == 1:
            ch += 1
    else:
        if ch == 3:
            print('Yes')
            sys.exit()
#よこ
for i in range(3):
    ch = 0
    for j in range(3):
        if check[i][j] == 1:
            ch += 1
    else:
        if ch == 3:
            print('Yes')
            sys.exit()
#斜め
if check[0][0] + check[1][1] + check[2][2] == 3:
    print('Yes')
    sys.exit()
if check[0][2] + check[1][1] + check[2][0] == 3:
    print('Yes')
    sys.exit()

print('No')

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**8)

N = int(input())
edge = [[] for _ in range(N)]

for _ in range(N-1):
  u,v,w = map(int, input().split())
  w %= 2
  v -= 1
  u -= 1
  edge[u].append((w,v))
  edge[v].append((w,u))

color = [-1]*N
#print(edge)
def dfs(s,col):
  #print(s,col)
  for w,v in edge[s]:
    if color[v]==-1:
      color[v] = col^w
      dfs(v,color[v])
  return

color[0] = 0
dfs(0,0)
ans = color

#print(ans)
print(*ans,sep='\n')

Measured memory_bytes: 76488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
signed main() {
	int n;
	cin >> n;
	bitset<32>bit(n);
	cout << bit << endl;
	cout << ~bit << endl;
	cout << (bit<<1) << endl;
	cout << (bit>>1) << endl;
	return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
int n;
char s[100005];
int X,Y;

void solve(){
  X=Y=-1;
  if(n==1)return;
  for(int i=0;i<n;i++){
    if(i+1<n&&s[i]==s[i+1]){
      X=i+1;
      Y=X+1;
      return;
    }
    if(i+2<n&&s[i]==s[i+2]){
      X=i+1;
      Y=X+2;
      return;
    }
  }
}

int main(){
  scanf("%s",s);
  n=strlen(s);
  solve();
  printf("%d %d\n",X,Y);
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int x, y;
  cin >> x >> y;
  rep(a, 101) {
    rep(b, 101) {
      if(a+b == x && 2*a+4*b == y) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
 */
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.Graphics.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int t=0,h=0;
        for (int i = 0; i < n; i++) {
            String s1=sc.next(),s2=sc.next();
            int d=s1.compareTo(s2);
            if(d>0)t+=3;
            else if(d<0)h+=3;
            else {
                t++;
                h++;
            }
        }
        out.println(t+" "+h);
    }
}


Measured memory_bytes: 30424
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
using namespace std;
int n,k,h[100000],ans;
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>h[i];
		if(h[i]>=k)
		 ans++;
	}
	cout<<ans;
	
	re 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
int h,w,n,sr,sc;
string s,t;
int l,r,u,d;
void moveT(char buf){
  if(buf=='L')++l;
  if(buf=='R')--r;
  if(buf=='U')++u;
  if(buf=='D')--d;
}
void moveA(char buf){
  if(buf=='L'&&r<w+1)++r;
  if(buf=='R'&&l>0)--l;
  if(buf=='U'&&d<h+1)++d;
  if(buf=='D'&&u>0)--u;
}
bool check(){
  bool res=false;
  if(l>=w||r<=1)res=true;
  if(u>=h||d<=1)res=true;
  return res;
}
signed main(){
  cin>>h>>w>>n;
  cin>>sr>>sc;
  cin>>s;
  cin>>t;
  l=0;r=w+1;u=0;d=h+1;
  bool flag=false;
  moveT(s[n-1]);
  flag=check();
  for(int i=n-2;i>=0;--i){
    moveA(t[i]);
    moveT(s[i]);
    flag=check();
    if(flag)break;
  }
  if(sr<=u||sr>=d)flag=true;
  if(sc<=l||sc>=r)flag=true;
	if(!flag){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
#define mkp(a, b) make_pair(a, b) 
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

ll modpow(ll a, ll n){
  ll ans = 1;
  while(n > 0){
    if(n & 1) ans = ans * a;
    n >>= 1;
    a = a * a;
  }
  return ans;
}

int main(){
  ll n;
  cin >> n;
  ll stage = 1;
  while(n - modpow(26, stage) > 0){
    n -= modpow(26, stage);
    stage++;
  }
  st ans = "";

  n--;
  rep(i, 0, stage) ans += 'a';
  ll now = stage - 1;
  while(now >= 0){
    ans.at(now) = (char)(ans.at(now) + n % 26);
    n /= 26;
    now --;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n,a[60],maxi=0,at=0;
  cin>>n;
  cout<<n*2-2<<endl;
  lol(i,n){
    cin>>a[i];
    if(abs(maxi)<=abs(a[i])){
      maxi=a[i];
      at=i;
    }
  }
  lol(i,n){
    if(i==at)continue;
    a[i]+=maxi;
    cout<<at+1<<" "<<i+1<<endl;
  }
  if(a[0]>0){
    for(int i=1;i<n;i++){
      cout<<i<<" "<<i+1<<endl;
    }
  }
  else{
    for(int i=n-1;i>0;i--){
      cout<<i+1<<" "<<i<<endl;
    }
  }
  return 0;
}


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

#define ll long long
#define pb push_back

int ans[2003][2003];
deque < int > v;
int sti1, sti2, fii1, fii2;

main() {
    int n = 41 * 42 + 1;
//    freopen("inp.in", "w", stdout);
    int k = 42;
    printf ("%d %d\n", n, k);
    int cnt = 2;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            if (j == 1) {
                ans[i][j] = 1;
            } else {
                ans[i][j] = cnt++;
            }
        }
    }
    int add = k - 1;
    sti1 = 2, fii1 = k;
    for (int i = 2; i <= k; i++) {
        for (int j = 2; j <= k; j++) {
            v.pb(ans[j][i]);
        }
    }
    for (int i = k + 1; i <= k + add; i++) {
        ans[i][1] = 2;
        for (int j = 2; j <= k; j++) {
            ans[i][j] = v.front();
            v.pop_front();
        }
    }
    sti1 = k + 1, fii1 = sti1 + add - 1;
    sti2 = sti1 + add, fii2 = sti2 + add - 1;
    cnt = 3;
    int xi = sti1;
    int res = 0;
    int cn = 0;
//    cout << sti1 << ' ' << fii1 << endl;
//    cout << sti2 << ' ' << fii2 << endl;
    for (int i = sti2; i <= n; i++) {
        ans[i][1] = cnt;
        res++;
        v.clear();
        int ri = sti1 + cn;
        int rj = 2;
        for (int j = 2; j <= k; j++) {
            v.pb(ans[ri][j]);
            ri++;
            if (ri > fii1) {
                ri = sti1;
            }
        }
        for (int j = 2; j <= k; j++) {
            ans[i][j] = v[j - 2];
        }
        cn++;
        if (res >= add) {
            sti1 = sti2;
            fii1 = fii2;
            sti2 = fii1 + 1;
            fii2 = sti2 + add - 1;
            res = 0;
            cnt++;
            cn = 0;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= k; j++) {
            printf ("%d ", ans[i][j]);
        }
        puts("");
    }
}


Measured memory_bytes: 13952
import java.util.Scanner;

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

		for(int i=0; i<days; i++) {
			int furo=sc.nextInt();
			int pool=sc.nextInt();
			int f_mai=sc.nextInt();
			int p_mai=sc.nextInt();

			int matome0=furo*f_mai+pool*p_mai;
			int matome1=4*(furo*5+pool*2+Math.max(f_mai-5, 0)*furo+Math.max(p_mai-2, 0)*pool)/5;
			int matome2=4*(furo*10+pool*4+Math.max(f_mai-10, 0)*furo+Math.max(p_mai-4, 0)*pool)/5;
			int matome3=4*(furo*15+pool*6+Math.max(f_mai-15, 0)*furo+Math.max(p_mai-6, 0)*pool)/5;
			System.out.println(Math.min(Math.min(matome0, matome1), Math.min(matome2, matome3)));
		}
	}
}


Measured memory_bytes: 32124
N,W=map(int,input().split())
w1,v=map(int,input().split())
if w1>W:
    print(0)
    exit()
lst=[[-1]*(3*N-2) for _ in range(N)]
lst[0][0]=v
for i in range(N-1):
    w,v=map(int,input().split())
    for j in range(N-1,-1,-1):
        for k in range(3*N-2):
            if lst[j][k]!=-1:
                if (j+1)*w1+k+w<=W:
                    lst[j+1][k+w-w1]=max(lst[j][k]+v,lst[j+1][k+w-w1])
    lst[0][w-w1]=max(v,lst[0][w-w1])

lst=[i for j in lst for i in j]
print(max(lst))

Measured memory_bytes: 75296
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	ll x, y;
	cin >> x >> y;
	int ans = 0;
	while (x <= y){
		x *= 2;
		ans++;
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  int k; cin >> k;
  vector<int> a(n); cin >> a;
  if(k > 1000){
    for(int i = 0; i < n; ++i){
      if(i)cout << ' ';
      cout << n;
    }
    cout << endl;
    return 0;
  }
  for(int i = 0; i < k; ++i){
    vector<int> v(n);
    for(int j = 0; j < n; ++j){
      int idx = max(0,j-a[j]);
      v[idx]++;
      if(n-1<j+a[j]+1)continue;
      idx = j+a[j]+1;
      v[idx]--;
    }
    vector<int> b(n);
    for(int j = 0; j < n; ++j){
      b[j] += v[j];
      if(j+1<n)b[j+1] = b[j];
    }
    a = move(b);
  }
  for(int i = 0; i < n; ++i){
    if(i)cout << ' ';
    cout << a[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 5640
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int H, W; 
  cin >> H >> W;

  vector<string> s(H);
  REP(i, H) cin >> s[i];

  vector<vector<int>> A(H, vector<int>(W, 0));
  vector<vector<int>> B(H, vector<int>(W, 0));

  REP(i, H) REP(j, W){
    if(s[i][j] == '#') continue;
    A[i][j]++;
    if(i != 0) A[i][j] += A[i-1][j];

    B[i][j]++;
    if(j != 0) B[i][j] += B[i][j-1];
  }

  RREP(i, H-1) REP(j, W){
    if(s[i][j] == '#') continue;
    chmax(A[i][j], A[i+1][j]);
  }

  REP(i, H) RREP(j, W-1){
    if(s[i][j] == '#') continue;
    chmax(B[i][j], B[i][j+1]);
  }


  int ans = 0;
  REP(i, H) REP(j, W){
    chmax(ans, A[i][j]+B[i][j]-1);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 67200
#include <iostream>
#include <algorithm>

using namespace std;

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

    long x = (long)a * b;

    if (a < b) swap(a, b);

    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    cout << x / b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int no, i=0, num, j;
  char Fu[] = {'S', 'H', 'C', 'D'};
  int card[4][13] = {0};
  char mj;

  scanf("%d", &no);

  while(i<no){
    scanf("%s %d", &mj, &num);
    Fu[0] = 'S';

    if(mj == Fu[0])
      card[0][num-1] = num;
    if(mj == Fu[1])
      card[1][num-1] = num;
    if(mj == Fu[2])
      card[2][num-1] = num;
    if(mj == Fu[3])
      card[3][num-1] = num;

    i++;
  }

  for(i=0; i<4; i++){
    for(j=0; j<13; j++){
      if(card[i][j] == 0){
        printf("%c %d\n",Fu[i], j+1);
      }
    }
  }

  return 0;
}



Measured memory_bytes: 1992
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...)
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)

#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 2000010

template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}

//FILE* outFile;

inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int main(){
    int j,k,i,T,ca=0,n,K=0,m;
    scanf("%d", &n);
    int ans = 0, a = 0, b = 0, c = 0;
    char s[12];
    rep(i, 0, n){
        scanf("%s", s);
        m = strlen(s);
        rep(j, 0, m-1){
            if(s[j] == 'A' && s[j+1] == 'B')ans++;
        }
        if(s[0] == 'B' && s[m-1] == 'A')c++;
        else if(s[0] == 'B')b++;
        else if(s[m-1] == 'A')a++;
    }
    //cerr << a  << " " << b << " " << c <<"\n";
    if(a || b)ans += c + min(a, b);
    else if(c){
        ans += c-1;
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

int A[25][25], B[25];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int A, B, C;
	cin >> A >> B >> C;
	cout << min(B/A,C) << '\n';
	cout << flush;
	//for (int i = 0; i < 1e9; ++i){for (int j = 0; j < 1e9; ++j){}}
	
}

Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 1e5 + 20;
int n;
vector <int> g[N], h[N];
set <pii> st1, st2;

int par[N];
vector <int> vec[N];

int cnt;
set <pii> que;

inline void add1 (int u, int v)
{
	if (u > v) swap(u, v);
	st1.insert({u, v});

	if (st2.count({u, v})) que.insert({u, v});
}

inline void rmv1 (int u, int v)
{
	if (u > v) swap(u, v);
	st1.erase({u, v});
	
	if (st2.count({u, v})) que.erase({u, v});
}

inline void add2 (int u, int v)
{
	if (u > v) swap(u, v);
	st2.insert({u, v});

	if (st1.count({u, v})) que.insert({u, v});
}

inline void rmv2 (int u, int v)
{
	if (u > v) swap(u, v);
	st2.erase({u, v});
	
	if (st1.count({u, v})) que.erase({u, v});
}

inline int root (int v) { return par[v]; }

inline void merge (int u, int v)
{
	if ((u = root(u)) == (v = root(v))) return;

	if (_sz(vec[u]) < _sz(vec[v])) swap(u, v);

	for (int x : vec[v])
	{
		for (int y : g[x])
		{
			int z = root(y);
			
			if (z != v) rmv1(v, z);
			if (z != v && z != u) add1(u, z);
		}
		
		for (int y : h[x])
		{
			int z = root(y);
		
			if (z != v) rmv2(v, z);
			if (z != v && z != u) add2(u, z);
		}

		par[x] = u;
		vec[u].pb(x);
	}

	vec[v].clear();
}

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

	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		par[i] = i;
		vec[i].pb(i);
	}

	for (int i = 0, u, v; i < n - 1; i++)
	{
		cin >> u >> v;
		u--, v--;
		g[u].pb(v);
		g[v].pb(u);

		add1(u, v);
	}

	for (int i = 0, u, v; i < n - 1; i++)
	{
		cin >> u >> v;
		u--, v--;
		h[u].pb(v);
		h[v].pb(u);

		add2(u, v);
	}

	while (_sz(que))
	{
		int u = que.begin() -> F, v = que.begin() -> S;
		que.erase(que.begin());

		merge(u, v);

		cnt++;
	}

	assert(cnt <= n - 1);

	cout << (cnt == n - 1 ? "YES" : "NO") << '\n';
}


Measured memory_bytes: 29568
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main() {
    #ifndef ONLINE_JUDGE
	// freopen("test.in", "r", stdin);
    #endif
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll k, n; cin >> k >> n;
    vector<ll> nums(n);
    for_(i, 0, n) cin >> nums[i];
    sort(nums.begin(), nums.end());
    ll g = 0;
    for_(i, 0, n-1) {
        g = max(g, nums[i+1] - nums[i]);
    }
    if (n > 1) g = max(g, k + nums[0] - nums.back());
    cout << k-g << endl;

    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
using namespace std;
const int maxn = 105;
int p, a[maxn][maxn], c[maxn * maxn], n, m, cl;

void naive(int i, int j){
	a[i][j] = p;
	c[p]--;
	if (c[p] == 0) p++;
	return;
}

int main(){
	cin >> n >> m >> cl;
	for (int i = 1; i <= cl; i++) cin >> c[i];
	p = 1;
	for (int i = 1; i <= n; i++){
		if (i % 2) for(int j = 1; j <= m; j++) naive(i, j);
		else for(int j = m; j > 0; j--) naive(i, j);
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++) cout << a[i][j] << " ";
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;long long K=0;
  vector<vector<int>> V(10,vector<int>(10));
  for(int X=1;X<=N;X++){
    string S=to_string(X);
    V[((int)S[0])-48][((int)S[S.size()-1])-48]++;
  }
  for(int X=1;X<10;X++){
    for(int Y=1;Y<10;Y++){
      K+=V[X][Y]*V[Y][X];
    }
  }
  cout<<K<<endl;
}

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

int p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y;

int choice();
int main(){
  int q; cin >> q;

  for(int i=0; i<q; i++){
    cin >> p0x >> p0y >> p1x >> p1y >> p2x >> p2y >> p3x >> p3y;
    cout << choice() << endl;
  }

  return 0;
}

int choice(){
  int res;
  int s1dx, s1dy, s2dx, s2dy;
  s1dx = p1x-p0x; s1dy = p1y-p0y;
  s2dx = p3x-p2x; s2dy = p3y-p2y;
  
  if(s1dx*s2dy-s2dx*s1dy==0) res=2;
  else if(s1dx*s2dx+s1dy*s2dy==0) res=1;
  else res=0;
  return res;
}



Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

const int MOD = 998244353;
const int inv2 = (MOD - MOD/2) % MOD;

int main(){
    int N; cin >> N;
    vector<long long> cnt(1000001, 0);
    for(int i=0;i<N;i++){
        int a; cin >> a;
        cnt[a]++;
    }
    vector<long long> res(1000001, 0);
    for(int b=1000000;b>=1;b--){
        long long sum = 0;
        long long sumSq = 0;
        for(int t=1;t*b<=1000000;t++){
            long long d = t/b;
            sum = (sum + cnt[t*b] * t) % MOD;
            sumSq = (sumSq + cnt[t*b] * t % MOD * t) % MOD;
        }
        res[b] = (sum * sum % MOD + MOD - sumSq) % MOD * inv2 % MOD * b % MOD;
        for(int t=2;t*b<=1000000;t++){
            res[b] = (res[b] + MOD - t * res[t*b] % MOD) % MOD;
        }
    }
    cout << accumulate(res.begin(), res.end(), 0LL) % MOD << endl;
}

Measured memory_bytes: 15872
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

vector<ll> a;
vector<vector<ll>> adj;
ll dfs(ll pos, ll par) {
	if((ll)adj[pos].size()==1) return a[pos];
	ll sum=0;
	ll maxi=0;
	REP(i,(ll)adj[pos].size()) {
		if(adj[pos][i]==par) continue;
		ll buf=dfs(adj[pos][i],pos);
		if(buf==-1) return -1;
		sum+=buf;
		maxi=max(maxi,buf);
	}
	ll buf=0;
	if(maxi<=sum/2) {
		buf=sum/2;
	} else {
		buf=(sum-maxi);
	}
	if(sum<a[pos]) return -1;
	if(sum-a[pos]<=buf) {
		return sum-(sum-a[pos])*2;
	} else {
		return -1;
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	a.resize(n);
	adj.resize(n);
	REP(i,n) cin>>a[i];
	REP(i,n-1) {
		ll q,v;
		cin>>q>>v;
		q--;
		v--;
		adj[q].pb(v);
		adj[v].pb(q);
	}
	if(n==2) {
		if(a[0]==a[1]) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		return 0;
	}
	ll ans=0;
	REP(i,n) {
		if((ll)adj[i].size()>1) {
			ans=dfs(i,-1);
			break;
		}
	}
	if(ans==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 11904
#include<cstdio>
#define ll long long
using namespace std;
ll n;
int main()
{
	ll sum = 0;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++)
	{
		ll q;
		scanf("%lld", &q);
		sum += q;
	}
	sum -= n;
	printf("%lld", sum);
}

Measured memory_bytes: 128
from itertools import product
t=[]
ans=0
n,m=map(int,input().split())
s=list(product([1,-1],repeat=3))
for i in range(n):
    li=[]
    p,q,r=map(int,input().split())
    for a,b,c in s:
        li.append(a*p+b*q+c*r)
    t+=[li]
for j in list(zip(*t)):
    p=sum(sorted(j)[n-m:])
    ans=max(ans,p)
print(ans)


Measured memory_bytes: 3572
#include <stdio.h>
#include <iostream>
#define ll long long
using namespace std;
ll lin() {ll x;scanf("%lld",&x);return x;}
ll f(ll x){
    ll a=x/11*2;
    x-=x/11*11;
    if(x>0)a++;
    if(x>6)a++;
    return a;
}
int main(){cout<<f((lin()))<<endl;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < s.length(); i++) {
		ans += (s[i] != t[i]);
	}
	
	std::cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    cin >> n;
    unordered_map<int, int> um;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        ++um[a];
    }
    pair<int, int> begin = *um.begin();
    if (--begin.second == 0) um.erase(begin.first);
    for (pair<int, int> p : um) {
        int i1 = begin.first;
        int i2 = p.first;
        unordered_map<int, int> umm;
        ++umm[p.first];

        bool ok = true;
        for (int j = 0; j < n - 1; ++j) {
            int i = i1 ^ i2;
            i1 = i2;
            i2 = i;
            if (um.find(i) != um.end()) {
                if (++umm[i] > um[i]) {
                    ok = false;
                    break;
                };
            } else {
                if (j == n - 2 && i == begin.first) {
                } else {
                    ok = false;
                }
                break;
            }
        }
        if (ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3620
/**
 * C - Skill Up
 * https://atcoder.jp/contests/abc167/tasks/abc167_c
 */
#include <bits/stdc++.h>
using namespace std;

int N, M, X;

vector<int>CP(14);
vector<vector<int>> CA(14, vector<int>(14));
vector<bool>KAU_KAWANAI(14, false);

int calcPrice() {
    int price = 0;
    for (int i = 0; i < N; i++) {
        if (KAU_KAWANAI.at(i)) {
            price += CP.at(i);
        }
    }

// int k = 0;
    for (int i = 0; i < M; i++) {
        int syujyukudo = 0;
        for (int j = 0; j < N; j++) {
            if (KAU_KAWANAI.at(j)) {
                syujyukudo += CA.at(j).at(i);
            }
        }
//        k++;

        if (syujyukudo < X) {
            return INT_MAX;
        }
// cout << i << " " <<  syujyukudo << endl;
    }

// cout << M << " " <<  k << " " <<  price << endl;
    return price;
}

int saiki(int i) {
    int minPrice = calcPrice();
    if (i < N) {
        KAU_KAWANAI.at(i) = true;
        minPrice = min(minPrice, saiki(i+1));

        KAU_KAWANAI.at(i) = false;
        minPrice = min(minPrice, saiki(i+1));
    }

    return minPrice;
}
 
int main() {
    // 高橋くんが書店に行くと、N 冊の参考書が売っていました。i 番目の参考書 (1≤i≤N) は Ci 円で売られていて、購入して読むことで、各 j (1≤j≤M) について j 番目のアルゴリズムの理解度が Ai,j 上がります。
    // また、それ以外の方法で理解度を上げることはできません。
    cin >> N >> M >> X;

    // vector<int>CP(N);
    // vector<vector<int>> CA(N, vector<int>(M));
    // vector<vector<int>(M)>CA(N);
    for (int i = 0; i < N; i++) {
        // 値段
        cin >> CP.at(i);
        for (int j = 0; j < M; j++) {
            // アルゴリズムの理解度
            cin >> CA.at(i).at(j);
        }
    }

    int minPrice = saiki(0);
    cout << (minPrice == INT_MAX ? -1 : minPrice) << endl;
}
 

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

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

  if (a + b == c)
  {
    cout << "Yes" << endl;
  }
  else if (a + c == b)
  {
    cout << "Yes" << endl;
  }
  else if (b + c == a)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int h = sc.nextInt();
		int w = sc.nextInt();

		String[] s = new String[h];
		for (int i = 0; i < s.length; i++) {
			s[i] = sc.next();
		}

		char[][] ans = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (s[i].charAt(j) == '#') {
					ans[i][j] = '#';
					continue;
				}
				int count = 0;
				for (int k = i - 1; k <= i + 1; k++) {
					if (k < 0 || h <= k) {
						continue;
					}
					for (int l = j - 1; l <= j + 1; l++) {
						if (l < 0 || w <= l) {
							continue;
						}
						if (s[k].charAt(l) == '#') {
							count++;
						}
					}
				}
				ans[i][j] = (char)('0' + count);
			}
		}

		for (char[] arr : ans) {
			for (char c : arr) {
				System.out.print(c);
			}
			System.out.println();
		}

		sc.close();
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <array>
#include <cmath>

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp; 
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

int main() {
    ll r, D, x;

    cin >> r >> D >> x;

    for (int i = 0; i < 10; ++i) {
        x = x*r - D;
        cout << x << "\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char in[10][10];
int cnt[20];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)if(in[i][j]=='#')cnt[i+j]++;
	for(int i=0;i<a+b-1;i++)if(cnt[i]!=1){printf("Impossible\n");return 0;}
	printf("Possible\n");
}

Measured memory_bytes: 128