akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>h(n),a(n);
  rep(i,0,n)cin>>h[i];
  rep(i,0,n)cin>>a[i];
  map<ll,ll>mp;
  mp[0]=0;
  rep(i,0,n){
    auto itr=mp.lower_bound(h[i]);
    auto itr2=prev(itr,1);
    mp[h[i]]=a[i]+itr2->se;
    ll x=mp[h[i]];
    for(auto tmp=itr;tmp!=mp.end();){
      if(tmp->se <= x)tmp=mp.erase(tmp);
      else break;
    }
  }
  cout<<(--mp.end())->se<<endl;
  return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int cnt=0;
string s;
void f(int i){
    int first=i/100;
    int second=(i-first*100)/10;
    int third=i%10;
  	int k=0;
  	int c[3]={first,second,third};
    for(int a=0;a<s.size();a++){
      if(s[a]-'0'==c[k]) k++;
      if(k==3) {cnt++;return;}
    }
  	
}
int main(){
  int N;
  cin>>N>>s;
  for(int i=0;i<=999;i++) f(i); 
  cout<<cnt;
}

Measured memory_bytes: 256
n,w = map(int,input().split())
info = [[0,0]]+[list(map(int,input().split())) for i in range(n)]
v = 0
for i in range(n+1):
  v += info[i][1]

## dp[i][j]:i番目までのアイテムを詰めたときに総価値jになるときの最小重さ
dp = [[float("inf")]*(v+1) for i in range(n+1)]

for i in range(n+1):
  dp[i][0] = 0

for i in range(1,n+1):
  for j in range(1,v+1):
    if j-info[i][1]>=0:
      dp[i][j] = min(dp[i-1][j],dp[i-1][j-info[i][1]]+info[i][0])
    else:
      dp[i][j] = dp[i-1][j]

for j in range(v+1):
  if dp[n][j] <= w:
    ans = j
print(ans)

Measured memory_bytes: 380728
# import math
# import statistics
# import itertools
# a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
A,B= map(str,input().split())
# f = list(map(int,input().split()))
# g = [input().split for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen

lis=["A","B", "C", "D", "E", "F"]
if lis.index(A)<lis.index(B):
    print("<")
elif lis.index(A)==lis.index(B):
    print("=")
else:
    print(">")



Measured memory_bytes: 9048
#include<iostream>

using namespace std;

void bubbleSort(int A[100], int n){

    int flag = 1, counter = 0, j;

    while(flag){
        flag--;
        for(j=n-1;j>0;j--){
            if(A[j] < A[j-1]){
                A[j] += A[j-1];
                A[j-1] = A[j] - A[j-1];
                A[j] = A[j] - A[j-1];
                counter++;
                flag++;
            }
        }
    }

    for(j=0;j<n;j++){
        if(j == 0){
            cout << A[j];
        }else{
            cout << " " << A[j];
        }
    }

    cout << endl << counter << endl;

}

int main(){

    int i, n;
    int A[100] = {0};

    cin >> n;

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

    bubbleSort(A, n);

    return 0;
}


Measured memory_bytes: 3076
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct Rope{
	double x;
	double y;
	double l;
};
int n;
Rope r[10];

double balloon_H(double X, double Y){
	double ans = 1e9;
	for (int i = 0; i < n; i++){
		double h = r[i].l*r[i].l - (r[i].x - X)*(r[i].x - X) -(r[i].y - Y)*(r[i].y - Y);
		if (ans>h)ans = h;
	}
	
	return ans;
}
double searchy(double x){
	double min = -100.0;
	double max = 100.0;
	for (int i = 0; i < 200; i++){
		double div1 = (min * 2 + max) / 3;
		double div2 = (min + 2 * max) / 3;
		if (balloon_H(x, div1) < balloon_H(x, div2))
			min = div1;
		else
			max = div2;
	}
	return balloon_H(x,min);
}
int main() {
	while (cin >> n, n){
		for (int i = 0; i < n; i++){
			cin >> r[i].x >> r[i].y >> r[i].l;
		}
		double e = 0.00001f;
		double min = -100.0;
		double max = 100.0;

		for (int i = 0; i < 200;i++){
			double div1 = (min * 2 + max) / 3;
			double div2 = (min + 2 * max) / 3;
			if (searchy(div1) < searchy(div2))
				min = div1;
			else
				max = div2;
		}
		
		printf("%.7f\n", sqrt(searchy(min)));
	}
}

Measured memory_bytes: 1236
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename T>
constexpr T det2(const T &a1, const T &a2, const T &b1, const T &b2) {
  return a1 * b2 - b1 * a2;
}

void solve() {
  double x1, y1, x2, y2, x3, y3, xp, yp;
  while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp) {
    double a = det2(xp - x1, yp - y1, x2 - x1, y2 - y1),
           b = det2(xp - x2, yp - y2, x3 - x2, y3 - y2),
           c = det2(xp - x3, yp - y3, x1 - x3, y1 - y3);
    cout << ((a > 0 && b > 0 && c > 0) || (a < 0 && b < 0 && c < 0) ? "YES" : "NO") << endl;
  }
}

Measured memory_bytes: 3052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
void NewYear() {
	int M;
	cin >> M;
	cout << (48 - M) << endl;
}
int main() {
	NewYear();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl

using namespace std;
using i64 = long long;

int main()
{
    int n;
    cin >> n;

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

    sort(l.begin(), l.end());

    int num = 0;

    for (int ic = n - 1; ic >= 2; ic--)
    {
        for (int ib = ic - 1; ib >= 1; ib--)
        {
            int c = l[ic];
            int b = l[ib];
            if (2 * b <= c)
                break;
            int il = -1;
            int ir = ib;
            while (ir - il > 1)
            {
                int imid = (il + ir) / 2;
                int lmid = l[imid];
                if (lmid > c - b)
                {
                    ir = imid;
                }
                else
                {
                    il = imid;
                }
            }
            int ia = ir;
            // debug2(ia, ib, ic);
            // debug(counter);
            num += ib - ia;
        }
    }

    cout << num << endl;

    return 0;
}

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

vector<int> XX( int N ) {
	vector<int >ret;
	for( size_t i = 1; i <= sqrtl( N ); i++ ) {
		if( N%i == 0 ) {
			ret.push_back( i );
			ret.push_back( N / i );
		}
	}
	return ret;
}

int main() {
	int N;
	cin >> N;
	vector<int>data( N );
	auto XXX = XX( N );
	for( size_t i = 0; i < N; i++ ) {
		cin >> data[i];
	}
	long long int ans = 0;
	for( size_t i = 0; i < XXX.size(); i++ ) {
		bool f = 1;
		for( size_t j = 0; j < XXX[i]; j++ ) {
			for( size_t k = 0; k < N / XXX[i]; k++ ) {
				if( data[k] != data[k + j*N / XXX[i]] ) {
					f = 0;
				}
			}
		}
		if( f ) {
			if( ans < XXX[i] ) {
				ans = XXX[i];
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3616
// Why do we fall ? So we can learn to pick ourselves up.
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String ss = sc.next();
        int t = 0;
        for(int i=0; i<n; i++){
            char c = ss.charAt(i);
            i++;
            if(i==n){
                t++;
                break;
            }
            while(ss.charAt(i)==c){
                i++;
                if(i==n){
                    t++;
                    break;
                }
            }
            if(i==n){
                break;
            }
            i--;
            t++;
            }
        System.out.println(t);
        }
    }

Measured memory_bytes: 24236
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write('\n'.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


n,k=mdata()
p=mdata()
c=mdata()
ans=-INF
for i in range(n):
    c1=[]
    a=i
    while True:
        a=p[a]-1
        c1.append(c[a])
        if a==i:
            break
    m1=0
    for j in range(min(k,len(c1))):
        m1+=c1[j]
        ans=max(m1,ans)
    if m1>0:
        t=k//len(c1)
        m1=max(0,m1*(t-1))
        ind=max(0,len(c1)*(t-1))
        ans=max(ans,m1)
        for i in range(ind,k):
            m1+=c1[i%len(c1)]
            ans=max(ans,m1)
out(ans)



Measured memory_bytes: 85836
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999
#define P pair<int,int>
int a[5],maxi,maxv=9,ans=0;
bool check=false;
signed main(){
    rep(i,5){
        cin>>a[i];
        if(a[i]%10<maxv&&a[i]%10!=0){
            maxi=i;
            maxv=a[i]%10;
        }
        if(a[i]%10)check=true;
    }
    if(check==false)maxv=0;
    rep(i,5){
        if(i==maxi||a[i]%10==0)ans+=a[i];
        else ans+=(a[i]-a[i]%10)+10;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

ll n;
vector<ll> h;

void solve() {
    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << endl;
}

int main() {
    cin >> n;
    h.resize(n);
    rep(i, n) cin >> h[i];
    solve();
    return 0;
}

Measured memory_bytes: 1792
S = str.upper(input())

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)


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

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size(); ++i) {
        if (i & 1) {
            // even pos
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
                cout << "No\n";
                return 0;
            }
        } else {
            // odd pos
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}


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

bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
    return (a.second < b.second); 
} 
  
// Function to find maximal disjoint set 
int maxDisjointIntervals(vector<pair<int, int> > list) 
{ 
    int ans = 0;
    // Sort the list of intervals 
    sort(list.begin(), list.end(), sortbysec); 
  
    // First Interval will always be 
    // included in set 
    ans = 1;
  
    // End point of first interval 
    int r1 = list[0].second; 
  
    for (int i = 1; i < list.size(); i++) { 
        int l1 = list[i].first; 
        int r2 = list[i].second; 
  
        // Check if given interval overlap with 
        // previously included interval, if not 
        // then include this interval and update 
        // the end point of last added interval 
        if (l1 >= r1) { 
            ans++;
            r1 = r2; 
        } 
    } 

    return ans;
} 

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        int n;
        cin >> n;
        vector<pair<int,int>> v(n), a(n);
        for(int i=0;i<n;i++)
        {   
            cin >> v[i].first >> v[i].second;
            a[i].first = v[i].first - v[i].second;
            a[i].second  = v[i].first + v[i].second;
        }

        int ans = maxDisjointIntervals(a);
        cout << ans << '\n';

    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 5504
class UnionFind(object):
    def __init__(self, N):
        self.parent = [-1] * N #parent[i] は(i+1)番目の要素が含まれる要素数の(-1)倍
    #要素が負-->その数を親とするグループに属する要素の数×(-1)
    #要素が正-->親のindex

    #Aがどのグループに属しているかを調べる
    def root(self, A):
        if self.parent[A-1] < 0: #負の数-->その数は親
            return A
        self.parent[A-1] = self.root(self.parent[A-1]) #負では無い時、親の場所が入っているから、親が属しているグループを、自分自身に入れる(一度確認したところは直接親を見れるようにする)
        return self.parent[A-1] #親の位置を返す

    #Aが含まれているグループに属している数を返す
    def size(self, A):
        return -1 * self.parent[self.root(A)-1]

    #AとBをくっ付ける
    def connect(self, A, B):
        A = self.root(A) #Aを含むグループの親を返す
        B = self.root(B) #Bを含むグループの親を返す
        if A == B: #親が同じならなにもしない
            return False
        
        #大きい方(A)に小さい方(B)をつなぎたい
        if self.size(A) < self.size(B): #大小関係が逆の時は入れ替える
            A, B = B, A
        
        self.parent[A-1] += self.parent[B-1] #大きい方に小さい方を加える　（負の数＋負の数 = 新しいグループに含まれる数×(-1)）
        self.parent[B-1] = A #加えられた親の値を、加えた先の親の位置に書き変える
        return True
    
    def same(self, A, B):
        if self.root(A) == self.root(B):
            return True
        else:
            return False
            
N, M = map(int, input().split())

p = list(map(int, input().split()))

uni = UnionFind(N)
for _ in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if uni.same(x, y):
        pass
    else:
        uni.connect(x, y)

count = 0
for i in range(N):
    if uni.same(p[i] - 1, i):
        count += 1
print (count)


Measured memory_bytes: 13812
// LCA: Doubling

// ???????????????
#include<iostream>
#include<vector>
#include<algorithm>
// ?????????
class RootedTree {
public:
  RootedTree(int n);
  int size() const;
  int parent(int v, int n = 1) const;
  void join(int u, int v);
  void initialize(int root);
  int lca(int u, int v) const;
private:
  void initialize(int current, int previous, int depth);
  std::vector<std::vector<int>> edge_;
  std::vector<std::vector<int>> parent_;  // parent_[v][i]: ??????v???2^i????????????
  std::vector<int> depth_;
public:   // ???????????°??¨
  void print(int c, int p) {
    std::cout<<c<<":";
    for(auto i: parent_[c])std::cout<<" "<<i;
    std::cout<<std::endl;
    for(auto n: edge_[c])if(n!=p)print(n,c);
  }
};
// ?????????????????????
RootedTree::RootedTree(int n) : edge_(n) {}
// ????????°
int RootedTree::size() const {return edge_.size();}
// ??????v???n????????????
int RootedTree::parent(int v, int n) const {
  if(!n) return v;
  if(__builtin_popcount(n) == 1) return parent_[v][__builtin_ctz(n)];
  for(int i = 31 - __builtin_clz(n); 0 <= i; --i) if((n >> i) & 1) v = parent_[v][i];
  return v;
}
// ????????????
void RootedTree::join(int u, int v) {
  edge_[u].push_back(v);
  edge_[v].push_back(u);
}
// ?????????
void RootedTree::initialize(int root) {
  parent_.assign(size(), std::vector<int>());
  depth_.assign(size(), 0);
  initialize(root, root, 0);
}
void RootedTree::initialize(int current, int previous, int depth) {
  depth_[current] = depth;
  parent_[current].push_back(previous);
  for(int i = 1; (1 << i) <= depth; ++i) parent_[current].push_back(parent_[parent_[current][i - 1]][i - 1]);
  for(const auto& next: edge_[current]) if(next != previous) initialize(next, current, depth + 1);
}
// LCA
int RootedTree::lca(int u, int v) const {
  // u, v???????????±????????????
  if(depth_[u] > depth_[v]) std::swap(u, v);
  v = parent(v, depth_[v] - depth_[u]);
  // LCA????±???????
  if(u == v) return u;
  for(int i = 31 - __builtin_clz(depth_[u]); 0 <= i; --i) {
    if(parent_[u][i] == parent_[v][i]) continue;
    u = parent_[u][i];
    v = parent_[v][i];
    i = std::min(i, 31 - __builtin_clz(depth_[u]) + 1);
  }
  return parent_[u][0];
}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  RootedTree tree(n);
  for(int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    for(int j = 0; j < k; ++j) {
      int c;
      cin >> c;
      tree.join(i, c);
    }
  }
  tree.initialize(0);
  int q;
  cin >> q;
  for(int i = 0; i < q; ++i) {
    int u, v;
    cin >> u >> v;
    cout << tree.lca(u, v) << endl;
  }
}

Measured memory_bytes: 27132
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

m = 10
for i in [a, b, c, d, e]:
    if i%10 != 0 and i%10<m:
        m = i%10


m = 10 - m


total = 0
for i in [a, b, c, d, e]:
    if i % 10 != 0:
        total += (i//10)*10+10
    else:
        total += i
print(total-m)

Measured memory_bytes: 38256
"use strict";

function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function main(input) {
  var _splitNum$filter = splitNum(input).filter(function (x) {
    return x;
  }),
      _splitNum$filter2 = _toArray(_splitNum$filter),
      N = _splitNum$filter2[0],
      ps = _splitNum$filter2.slice(1);

  ps.sort(function (a, b) {
    return b - a;
  });
  ps[0] /= 2;
  var sum = ps.reduce(function (a, b) {
    return a + b;
  }, 0);
  console.log(sum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


Measured memory_bytes: 21064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a < b) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }
    }
}


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

using namespace std;

typedef long long LL;
#define N 120000

LL n,m,v,p,ans,a[N];

bool check(LL x){
	LL t=max(v-(p-1)-(n-x)-1,0LL)*m,tmp=0;
	for (LL i=p;i<x;++i)
		if (a[x]+m<a[i]) return 0;
		else tmp+=a[x]+m-a[i];
	return tmp>=t;
}

int main(){
	scanf("%lld%lld%lld%lld",&n,&m,&v,&p);
	for (LL i=1;i<=n;++i) scanf("%lld",a+i);
	sort(a+1,a+n+1,greater<LL>());
	LL l=p+1,r=n; ans=p;
	while (l<=r){
		LL mid=(l+r)>>1;
		if (check(mid)){ans=mid; l=mid+1;}
		else r=mid-1;
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 1024
while True:
    h,w = map(int, input().split())
    if h==0 and w==0:
        break
    a=1
    while a<=h:
        if a%2:
            b=1
            while b<=w:
            
                if b%2:
                    print('#',end='')
                else:
                    print('.',end='')
                b+=1
        else:
            b=1
            while b<=w:
            
                if b%2:
                    print('.',end='')
                else:
                    print('#',end='')
                b+=1
        print('')
        a+=1
    print('')


Measured memory_bytes: 7008
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  char a , b;
  cin >> a >> b;
  if(a > b)cout << '>' << endl;
  else if(a == b)cout << '=' << endl;
  else cout << '<' << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>pat[3000];
vector<int>ko[3000];
int dat[3000];
bool flag[3000];
void dfs(int node)
{
	flag[node] = true;
	for (int i = 0; i < pat[node].size(); i++)
	{
		if (!flag[pat[node][i]])dfs(pat[node][i]), ko[node].push_back(pat[node][i]);
	}
}
bool calc(int node)
{
	bool r = true;
	for (int i = 0; i < ko[node].size(); i++)
	{
		if (dat[node] > dat[ko[node][i]])r &= calc(ko[node][i]);
	}
	if (r)return false;
	else return true;
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num; i++)scanf("%d", &dat[i]);
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	for (int i = 0; i < num; i++)
	{
		for (int j = 0; j < num; j++)ko[j].clear(), flag[j] = false;
		dfs(i);
		if (calc(i))printf("%d ", i + 1);
	}
	printf("\n");
}

Measured memory_bytes: 768
#include <algorithm>
#include <iostream>
#include <vector>
#define SZ(x) ((int) (x).size())
using namespace std;

const int MOD = (int) 1e9 + 7;

int Pow(int x, int y) {
    int ret = 1;
    for (;y > 0; y /= 2) {
        if (y & 1) {
            ret = ret * (int64_t) x % MOD;
        }
        x = x * (int64_t) x % MOD;
    }
    return ret;
}

int invMod(int x) {
    return Pow(x, MOD - 2);
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    if (n == 2) {
        cout << 1 << '\n';
    } else if (n == 3) {
        cout << 4 << '\n';
    } else {
        vector<int> fact(n + 1, 1);
        for (int i = 1; i <= n; ++i) {
            fact[i] = fact[i - 1] * (int64_t) i % MOD;
        }
        vector<int> inv(n + 1, 0);
        inv[1] = 1;
        for (int i = 2; i <= n; ++i) {
            inv[i] = (MOD - MOD / i) * (int64_t) inv[MOD % i] % MOD;
        }
        vector<int> ifact(n + 1, 1);
        for (int i = 1; i <= n; ++i) {
            ifact[i] = ifact[i - 1] * (int64_t) inv[i] % MOD;
        }
        auto comb = [&](int n, int k) -> int {
            if (n < 0 || k < 0 || k > n) {
                return 0;
            }
            return fact[n] * (int64_t) ifact[n - k]  % MOD * ifact[k] % MOD;
        };
        int ans = fact[n - 1] * (int64_t) n % MOD;
        for (int k = 0; k < n; ++k) {
            int v = comb(n - 1 - k - 1, k);
            v = v * (int64_t) fact[k] % MOD;
            v = v * (int64_t) fact[n - k - 1] % MOD;
            ans = (ans - v + MOD) % MOD;
        }
        cout << ans << '\n';
    }
}


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

int main(){

   char str[10001];

   int joi=0,ioi=0;

   

   while(cin >> str){
  
   joi=0;ioi=0;
 
   for(int i=0;str[i+2] != '\0'; i++){

       if(str[i] == 'I'&&str[i+1] == 'O'&& str[i+2] == 'I') ioi++;

       else if(str[i] == 'J'&&str[i+1] == 'O'&& str[i+2] == 'I') joi++;
   }

  cout << joi <<endl << ioi <<endl;

  }
}

Measured memory_bytes: 1148
n = int(input())
h = [int(i) for i in input().split()]
ans = 0
for i in range(n-1):
    flag = True
    while flag:
        flag = False
        t = n - i
        for j in range(i+1):
            if 0 not in h[j:j+t]:
                for k in range(t):
                    h[j+k] -= 1
                flag = True
                ans += 1
print(ans + sum(h))

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC142A()
{
	int N;
	cin >> N;
	cout << std::fixed << std::setprecision(30) << static_cast<double>((N + 1) / 2) / N << endl;
}

int main()
{
	ABC142A();
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char num[1005];
    int sum=0;
    while(1)
    {
        scanf("%s",num);
        sum=0;
        if (num[0]=='0') break;
        int i, sz=strlen(num);
        for(i=0;i<sz;i++)
 
        {
            sum+=num[i] - '0';
        }
 
    printf("%d\n",sum);
    }
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 1e14
#define N 300001
#define K 33

int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int l,r,d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r;i++)
        if(i % d == 0)
            ans++;
    cout << ans;

    
    return 0;    
} 


Measured memory_bytes: 3636
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int d[] = new int[100000];
		int change = 0;
		String input = sc.next();

		char tmp = input.charAt(0);
		int c = 0;
		for(int i = 1 ; i < n ; i++){
			if(tmp == input.charAt(i)){
				c++;
			}else{
				tmp = input.charAt(i);
				d[change] = c+1;
				c = 0;
				change++;
			}
		}
		d[change] = c+1;
		change++;

		int m = 0;
		int mPos = 0;
		int sum = 0;
		for(int i = 0 ; i < 2*k+1 && i < change ; i++){
			sum += d[i];
		}
		m = sum;
		for(int i = 1 ; i+2*k < change ; i++){
			sum -= d[i-1];
			sum += d[i+2*k];
			if(sum > m){
				m = sum;
				mPos = i;
			}
		}

		int ans = m-1;
		for(int i = 0 ; i < mPos ; i++){
			ans += d[i]-1;
		}
		for(int i = mPos+2*k+1 ; i < change ; i++){
			ans += d[i]-1;
		}

		System.out.println(ans);
	}
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int count = 0;
	if (a > b) {
		count = 0;
	}
	else while (count < c) {
		b -= a;
		count++;
		if (a > b) 
			break;
	}
	cout << count << endl;
	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>;

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    ll c = max((a - 1), 0ll) / x;
    ll d = b / x;
    ll ans = d - c + (a == 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    var N = input[0];
    var len = N.length;
    if(N.length%2==0){
        console.log("No");
    }else{
        if(check(N) && check(N.substring(0, (len-1)/2)) && check(N.substring((len+2)/2, len))){
            console.log("Yes");
        }else{
            console.log("No");
        }
    }
}
function check(st){
    for(var i=0;i<st.length;i++){
        if(st[i] != st[st.length-i-1]){
            return false;
        }
    }
    return true;
}



Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));

Measured memory_bytes: 7372
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int X;
    cin >> X;
    int ok = 0;

    REP(i, A + 1)
    REP(j, B + 1)
    REP(k, C + 1)
    if (i * 500 + j * 100 + k * 50 == X) ok++;

    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);

    ll a, b, c;
    cin >> a >> b >> c;

    ll x = c - a - b;

    cout << (x > 0 && 4 * a * b < x * x ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int a,sum=0;
int main()
{
	cin>>s;
	if(s[0]=='A')
	{
		for(a=2;a<=s.size()-2;a++)
		{
			if(s[a]=='C')
			sum=sum+1;
		}
		if(sum==1)
		{
			sum=0;
			for(a=1;a<s.size();a++)
			{
				if(s[a]!='C')
				if(s[a]<'a'||s[a]>'z')
				sum=sum+1;
			}
			if(sum==0)
			{
				cout<<"AC";
				return 0;
			}
		}
	}
	cout<<"WA";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mo=1e9+7,maxn=1e5+5;
int n,m,b[maxn];
struct vect
{
	int v[3];
	vect(){memset(v,0,sizeof(v));}
}ans;
struct mat
{
	int a[3][3];
	mat(){memset(a,0,sizeof(a));}
}pw[32],G;
mat operator*(const mat &A,const mat &B)
{
	mat C;
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)C.a[i][j]=0;
	for(int k=0;k<3;k++)
	for(int i=0;i<3;i++)
	for(int j=0;j<3;j++)
		C.a[i][j]=(C.a[i][j]+A.a[i][k]*B.a[k][j]%mo)%mo;
	return C;
}
inline vect operator * (const vect &A,const mat &B)
{
	vect D;
	for(int i=0;i<3;i++)D.v[i]=0;
	for(int i=0;i<3;i++) 
		for(int j=0;j<3;j++)D.v[i]=(D.v[i]+A.v[j]*B.a[i][j]%mo)%mo;
	return D;
}
inline void mul(int x)
{
	for(int i=0;(1<<i)<=x;i++) 
		if(x>>i&1)ans=ans*pw[i];
}
void prep()
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)pw[0].a[i][j]=1;
	pw[0].a[0][0]=pw[0].a[1][0]=2;
	pw[0].a[1][2]=0;
	G.a[1][0]=2;
	G.a[0][0]=G.a[1][1]=G.a[2][2]=G.a[2][0]=G.a[2][1]=1;
}
signed main()
{
	cin>>n>>m;
	ans.v[0]=1;
	for(int i=1;i<=m;i++)cin>>b[i];
	sort(b+1,b+m+1);
	prep();
	for(int i=1;(1<<i)<=n;++i)pw[i]=pw[i-1]*pw[i-1];
	for(int i=1;i<=m;i++)mul(b[i]-b[i-1]-1),ans=ans*G;
	mul(n-b[m]);
	cout<<ans.v[2]%mo; 
	return 0;
}
/*
写完转移方程就开始折腾，发现直接写成矩阵形式就好了。
然后把不关键的合在一起转移，事情就结束了。
*/

Measured memory_bytes: 4376
def main():
    h,w,a,b=map(int,input().split())
    Ans=[[0]*w for _ in range(h)]
    for x in range(h):
        for y in range(w):
            Ans[x][y]=int((x<b)^(y<a))
    for ans in Ans:
        print(*ans,sep='')
    return
    
if __name__=='__main__':
    main()

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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n; cin >> n;
  vector<int> A(n + 1);
  long long ans = 0;
  for (int i = 0; i < n + 1; ++i) cin >> A[i];
  for (int i = 1; i < n + 1; ++i) {
    int b; cin >> b;
    int m = min(A[i - 1], b); b -= m, A[i - 1] -= m;
    ans += m;
    m = min(A[i], b); b -= m, A[i] -= m;
    ans += m;
  }
  cout << ans << '\n';

}


Measured memory_bytes: 640
n, m, x, y = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
X.sort()
Y.sort()
res = False
for z in range(x+1, y+1):
    if X[-1] < z <= Y[0]:
        res = True
if(res):
    print('No War')
else:
    print('War')



Measured memory_bytes: 3060
#include <iostream>
#include <string>

int main()
{
    int a, b;

    std::cin >> a >> b;
    if( ((a % 2)==1) && ((b % 2) == 1)){
        std::cout << "Odd" << std::endl;
    } else {
        std::cout << "Even" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
# ABC107C - Candles (ARC101C)
def main():
    _, k = map(int, input().split())
    x = tuple(map(int, input().split()))
    print(min(r - l + min(abs(l), abs(r)) for l, r in zip(x, x[k - 1 :])))


if __name__ == "__main__":
    main()

Measured memory_bytes: 14352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(var,start,stop,step) for(long long var=start;var<stop;var+=step)
#define vi vector<int>
#define fio  cin.tie(nullptr); ios::sync_with_stdio(false); cout.tie(nullptr);
 

int main()
{
     fio;
     string s;
     cin>>s;
     if(s[1]=='B')
          cout<<"ARC"<<endl;
     else
          cout<<"ABC"<<endl;
               return 0;
}



Measured memory_bytes: 3556
#include <iostream>
using namespace std;
int main(void){
    int a,b,x;
    char op;
    while(true){
        cin >>a>>op>>b;
        if(op=='?')break;
        if(op=='+'){
            x=a+b;
        }
        else if(op=='-'){
            x=a-b;
        }
        else if(op=='*'){
            x=a*b;
        }
        else if(op=='/'){
            x=a/b;
        }
        cout <<x<<endl;
    }
}


Measured memory_bytes: 3092
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    int n;
    char s[11];
    long long int ans = 0;
    int a = 0, b = 0, ab = 0;
    int len;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", s);
        len = strlen(s);
        if (s[len - 1] == 'A' && s[0] == 'B')
        {
            ab++;
        }
        else if (s[0] == 'B')
        {
            b++;
        }
        else if (s[len - 1] == 'A')
        {
            a++;
        }
        for (int i = 0; i < len - 1; i++)
        {
            if (s[i] == 'A' && s[i + 1] == 'B')
            {
                ans++;
            }
        }
    }
    if (a == 0 && b == 0)
    {
        ans += fmaxl(fminl(ab - 1, n - 1), 0);
    }
    else
    {
        ans += fmaxl(fminl(fminl(a + ab, b + ab), n - 1), 0);
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{
ll n,ans=0;
cin>>n;
vector<ll> a(n+1);
a.at(0)=0;
for (int i = 1; i <= n; i++)
{
    cin>>a.at(i);
    if (a.at(i)<a.at(i-1))
    {
        ans=ans+a.at(i-1)-a.at(i);
        a.at(i)=a.at(i-1);
    }
    
}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4844
using System;

public class A13{
  static int N = 8;
  static int NOFREE = -1;
  static int FREE = 0;
  static int[] row = new int[N];
  static int[] col = new int[N];
  static int[] rsla = new int[2 * N - 1];
  static int[] lsla = new int[2 * N - 1];
  static bool[,] board = new bool[N,N];

  public static void Main(){
    int input1 = int.Parse(Console.ReadLine());
    for(int i = 0;i < input1;i++){
      int[] input2 = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      board[input2[0],input2[1]] = true;
    }
    Calc(0);
  }

  static void Calc(int i){
    if(i == N){
      Print();
      return;
    }
    for(int j = 0;j < N;j++){
      if(NOFREE == col[j] ||
      NOFREE == rsla[i + j] ||
      NOFREE == lsla[i - j + N - 1]) continue;

      row[i] = j;
      col[j] = rsla[i + j] = lsla[i - j + N -1] = NOFREE;
      Calc(i + 1);
      row[i] = col[j] = rsla[i + j] = lsla[i - j + N - 1] = FREE;
    }
  }

  static void Print(){
    for(int i = 0;i < N;i++){
      for(int j = 0;j < N;j++){
      if(board[i,j] && row[i] != j) return;
      }
    }
  for(int i = 0;i < N;i++){
    for(int j = 0;j < N;j++){
      Console.Write((row[i] == j) ? "Q" : ".");
    }
    Console.WriteLine();
  }
}
}



Measured memory_bytes: 18016
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    vector<int>a(n);
    vector<int>x(m),y(m);
    vector<int>c(n+1,0);
    rep(i,n){
        scanf("%d",&a[i]);
        c[a[i]]++;
    }
    int ans = 0;
    vector<int>k(n*2,0);
    for(int i = 1; i <= n; i++){
        for(int j = i-1+n; j >= i-c[i]+n ; j--){
            k[j]++;
        }
    }
    for(int i = n; i < n*2; i++){
        if(k[i] == 0){
            ans++;
        }
    }
    rep(i,m){
        scanf("%d %d", &x[i], &y[i]);
        x[i]--;
        int old = a[x[i]];
        int now = y[i];
        if(old == now){
            printf("%d\n", ans);
            continue;
        }
        k[n+now-c[now]-1]++;
        if(k[n+now-c[now]-1]==1 && now-c[now]-1>=0)ans--;
        k[n+old-c[old]]--;
        if(k[n+old-c[old]]==0 && old-c[old] >= 0)ans++;
        printf("%d\n", ans);
        c[a[x[i]]]--;
        c[y[i]]++;
        a[x[i]] = y[i];
    }
    return 0;
}

Measured memory_bytes: 6144
#include <iostream>
using namespace std;
int a[100];
int n;
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i < n - 1; ++i) {
        if (a[i] < a[i + 1] && a[i - 1] < a[i]) {
            ++ans;
        }
        else if (a[i] > a[i + 1] && a[i - 1] > a[i]) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[][] a = new char[n][n];
		for (int i = 0; i < n; i++) {
			a[i] = br.readLine().toCharArray();
		}
		br.close();

		int col = 0;
		for (int j = 0; j < n; j++) {
			for (int i = 0; i < n; i++) {
				if (a[i][j] == '.') {
					col++;
					break;
				}
			}
		}

		int min = n + 1;
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			for (int j = 0; j < n; j++) {
				if (a[i][j] == '.') {
					cnt++;
				}
			}

			boolean flg = false;
			for (int i2 = 0; i2 < n; i2++) {
				if (a[i2][i] == '#') {
					flg = true;
					break;
				}
			}
			if (!flg) {
				cnt++;
			}
			min = Math.min(min, cnt);
		}
		if (min == n + 1) {
			System.out.println(-1);
		} else {
			System.out.println(min + col);
		}
	}
}


Measured memory_bytes: 36460
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    string S;
    cin >> S;
    vector<int> cnts(26, 0);
    for (const char c : S)
    {
        ++cnts[c - 'a'];
    }

    if (S == "zyxwvutsrqponmlkjihgfedcba")
    {
        cout << -1 << endl;
    }
    else if (S.length() < 26)
    {
        char c;
        for (int i = 0; i < 26; ++i)
        {
            if (cnts[i] == 0)
            {
                c = 'a' + i;
                break;
            }
        }
        cout << S << c << endl;
    }
    else
    {
        set<char> s;
        for (int i = 25; i >= 1; --i)
        {
            s.insert(S[i]);
            if (S[i] > S[i - 1])
            {
                char C;
                for (const char c : s)
                {
                    if (c > S[i - 1])
                    {
                        C = c;
                        break;
                    }
                }
                S[i - 1] = C;
                S = S.substr(0, i);
                break;
            }
        }
        cout << S << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
struct team{
  int n;
  int ti;
};

bool ascending_time_team(const team& _t1,const team& _t2){
  return _t1.ti<_t2.ti;
}
int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    std::vector<team> v;
    for(int i=0;i<n;i++){
    int c1,m[4],s[4];
    std::cin>>c1>>m[0]>>s[0]>>m[1]>>s[1]>>m[2]>>s[2]>>m[3]>>s[3];
    int tsec=0;
    for(int i=0;i<4;i++)
      tsec+=m[i]*60+s[i];
    team t;
    t.n=c1;
    t.ti=tsec;
    v.push_back(t);
    }
    std::sort(v.begin(),v.end(),ascending_time_team);
    std::cout<<v[0].n<<"\n"<<v[1].n<<"\n"<<v[v.size()-2].n<<"\n";
  }
}

Measured memory_bytes: 0
from bisect import bisect_right
from bisect import bisect_left

n,k=map(int,input().split())
#n=100000
#k=100000

#n=100000
#k=100000
x=list(map(int,input().split()))

if x[n-1]<0 :
    t=-x[-k]
#    print(1)
    print(t)
elif x[n-1]==0 :
    t=-x[-k+1]
#    print(2)
    print(t)

elif x[0]>0:
    t=x[k-1]
#    print(3)
    print(t)
elif x[0]==0:
    t=x[k-1-1]
#    print(4)
    print(t)

else:
    iz=bisect_left(x,0)
    if x[iz+1]==0:
        k=k-1
        tmin=10**9
#        print((iz-(k-1)+1),iz,n-1-(k-1))
        for i in range(max(0,iz-(k-1)+1),min(iz,n-1-(k-1)+1)):
            kt=i
            t1=-x[kt]+x[kt+(k-1)]*2
            t2=-x[kt]*2+x[kt+(k-1)]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
#            print(tmin,t1,t2)
            if t1<tmin:
                tmin=t1
            if t2<tmin:
                tmin=t2
    else:
        tmin=10**9
#        print((iz-(k-1)+1),iz,n-1-(k-1))
        for i in range(max(0,iz-(k-1)+1),min(iz,n-1-(k-1)+1)):
            kt=i
            t1=-x[kt]+x[kt+(k-1)]*2
            t2=-x[kt]*2+x[kt+(k-1)]
#        print("2",kt,kt+k-1,t,x[kt],x[kt+k-1])
#            print(tmin,t1,t2)
            if t1<tmin:
                tmin=t1
            if t2<tmin:
                tmin=t2
    print(tmin)
    
#  299993628 
# 1000000000        
#   99990701

Measured memory_bytes: 14252
using System;

namespace ITP1_1_C
{
    class Program
    {
        public static void Main()
        {
            string [] str = Console.ReadLine().Split(' ');

            Console.WriteLine($"{int.Parse(str[0]) * int.Parse(str[1])} {2 *(int.Parse(str[0]) + int.Parse(str[1]))}");
        }
    }
}


Measured memory_bytes: 17992