akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll; 
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = 998244353;
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}
	
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init(888888);
	int ans = 0;
	int n,m; cin>>n>>m;
	for(int i=0;i<=min(n,m);i++)
	{
		int res=mult(choose(n,i),mult(choose(m,i),mult(fact[i],mult(modpow(m+1,n-i),modpow(n+1,m-i)))));
		if(i&1) ans=add(ans,MOD-res);
		else ans=add(ans,res);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 14208
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200005)
n, q = map(int, input().split())

to = [[] for i in range(n+1)]


for i in range(n-1):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

score = [0]*(n+1)
for i in range(q):
    p, x = map(int, input().split())
    score[p] += x


def down_tree(index, parent):
    for i in to[index]:
        if i == parent:
            continue
        score[i] += score[index]
        down_tree(i, index)



down_tree(1, 1)

print(' '.join(map(str, score[1:])))

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<ll> A(N);
  for (ll i = 0 ; i < N; i++) cin >> A.at(i);
  vector<ll> cnt(N+1);
  for (ll i = 0; i < N; i++) {
    cnt.at(A.at(i))++;
  }
  ll sum = 0;
  for (ll i = 1; i <= N; i++) {
    sum += cnt.at(i) * (cnt.at(i) - 1) / 2;
  }
  for (ll i = 0; i < N; i++) {
    ll j = A.at(i);
    ll y = cnt.at(j);
    ll x = sum - y * (y-1) / 2 + (y-1) * (y-2) / 2;
    cout << x << "\n";
  }

  return 0;
}



Measured memory_bytes: 5760
x, y = map(int, input().split())
b3 = 2*x - y
a3 = 2*y - x
if a3 % 3 != 0 or b3 % 3 != 0:
    print(0)
else:
    a = a3 // 3
    b = b3 // 3

    def cmb(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7 #出力の制限
    N = 10**6
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    ans = cmb(a+b , a, mod)
    print(ans)

Measured memory_bytes: 121848
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D, G;
  cin >> D >> G;
  int ps[D + 1];
  int cs[D + 1];
  vector<int> perm_vec;
  for (int i = 1; i <= D; ++i) {
    int pi, ci;
    cin >> pi >> ci;
    ps[i] = pi;
    cs[i] = ci;
    perm_vec.push_back(i);
  }
  int ans = INT_MAX;

  do {
    int G2 = G;
    int cnt = 0;
    for (int k = 0; k < D; ++k) {
      int i = perm_vec[k];
      if (G2 > ps[i] * 100 * i + cs[i]) {
        G2 -= ps[i] * 100 * i + cs[i];
        cnt += ps[i];
        continue;
      }

      for (int j = 0; j < ps[i]; ++j) {
        if (j == ps[i] - 1) {
          G2 -= cs[i];
        }
        G2 -= 100 * i;
        ++cnt;
        if (G2 <= 0) {
          goto BREAK;
        }
      }
    }

  BREAK:
    ans = min(ans, cnt);
  } while (next_permutation(perm_vec.begin(), perm_vec.end()));

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<iostream>
#include<queue>
using namespace std;
map<string,int>f;
map<string,bool>ff;
queue<string>Q;
int main()
{
	string s,t;
	int ans=0;
	int a,b;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) {
		cin>>s;
		f[s]++;
		if(!ff[s]) {
			ff[s]=1;
			Q.push(s);
		}
	}
	scanf("%d",&b);
	for(int i=1;i<=b;i++) {
		cin>>t;
		f[t]--;
		if(!ff[t]) {
			ff[t]=1;
			Q.push(t);
		}
	}
	while(!Q.empty()) {
		string fff=Q.front();
		Q.pop();
		ans=max(ans,f[fff]);
	}
	printf("%d",ans);//
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int h, w, v[5]={0, 1, 0, -1, 0}, wc, bc;
string s[400];
bool y[400][400];
ll ans;
void dfs(int a, int b){
  y[a][b] = true;
  if(s[a][b]=='#'){
    bc++;
  }else{
    wc++;
  }
  FOR(i, 0, 4){
    int aa = a+v[i], bb = b+v[i+1];
    if(0<=aa && aa<h && 0<=bb && bb<w && !y[aa][bb] && s[a][b] != s[aa][bb]){
      if(s[aa][bb]=='#'){
        ans += wc;
      }else{
        ans += bc;
      }
      dfs(aa, bb);
    }
  }
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  FOR(i, 0, h) cin >> s[i];
  FOR(i, 0, h)FOR(j, 0, w) if(!y[i][j]){
    wc=0;
    bc=0;
    dfs(i, j);
  }
  cout << ans << endl;
}

Measured memory_bytes: 18048
N=int(input())
if 1<=N<=9:
  print(N)
elif 10<=N<=99:
  print(9)
elif 100<=N<=999:
  print(9+N-100+1)
elif 1000<=N<=9999:
  print(909)
elif 10000<=N<=99999:
  print(909+N-10000+1)
else:
  print(90909)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			boolean[] student = new boolean[30];
			for(int i =0; i < 28;i++){
				student[scan.nextInt() -1] = true;
			}
			for(int i = 0; i < student.length;i++){
				if(!student[i])
					System.out.println(i + 1);
			}
		}finally{
			if(scan !=null) scan.close();
		}
	}
}

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

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
	//作るときはParentの値を全て-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
	//AとBをくっつける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついているからくっつけない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっつけたい
		//大小が逆だったらひっくり返しちゃう
		if (size(A) < size(B)) swap(A, B);
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
	//AとBが同じグループにいるか
	bool same(int A, int B) { return root(A) == root(B); }
};


int main() {
	int n, m, k; cin >> n >> m >> k;
	vector<int> res(n);
	vector<vector<int>> blo(n);
	UnionFind Uni(n);
	rep(i, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		Uni.connect(a, b);
		res[a]++; res[b]++;
	}
	rep(i, k) {
		int c, d; cin >> c >> d;
		c--; d--;
		blo[c].emplace_back(d);
		blo[d].emplace_back(c);
	}
	rep(i, n) {
		int ans = Uni.size(i) - res[i] - 1;
		for (auto& c : blo[i]) if (Uni.same(c, i))ans--;
		cout << ans << (i == n - 1 ? "\n" : " ");
	}
	return 0;
}


Measured memory_bytes: 6784
fun main(args: Array<String>) {
    val num = readLine()!!.toInt()
    val string = readLine()!!

    if (num % 2 == 1) {
        println("No")
        return
    }

    val halfLen = num / 2
    for (i in 0..halfLen-1) {
        if (string[i] != string[halfLen + i]) {
            println("No")
            return
        }
    }

    println("Yes")
}

Measured memory_bytes: 33704
from itertools import permutations

n = int(input())
x, y = [0]*n, [0]*n
for i in range(n):
  x[i], y[i] = map(int, input().split())

def dist(a, b):
  dx = x[a] - x[b]
  dy = y[a] - y[b]
  return (dx**2 + dy**2)**0.5

ans = 0
np = [x for x in range(n)]
p = list(permutations(np))
for a in p:
  memo = 0
  for i in range(n-1):
    memo += dist(a[i],a[i+1])
  ans += memo
print(ans / len(p))

Measured memory_bytes: 47344
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdint>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    string s1,s2;
    cin >> s1;
    cin >> s2;
    if(s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let x = read_as_vec::<u64>()[0];

    let mut ans = 0;
    for b in 1..40{
        for p in 2..12{
            let tmp = u64::pow(b, p);
            if tmp > x{
                break;
            }
            ans = cmp::max(ans, tmp);
        }
    }

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        cnt = 0;
        ll i = 0;
        while(cnt < n){
            i++, cnt += i;
        }
        print(i);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int a,b;
    cin >> a >> b;
    if(a + b == 15) cout << '+' << endl;
    else if(a * b == 15) cout << '*' << endl;
    else cout<< 'x' << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main() {
	int n, r, d, w, h, x;
	while (1) {
		cin >> d >> w >> h;
		if (d + w + h == 0)
			return 0;
		if (d <= h && w <= h)
			x = d * d + w * w;
		else if (d <= w && h <= w)
			x = d * d + h * h;
		else if (w <= d && h <= d)
			x = w * w + h * h;
		cin >> n;
		for (int lop = 0; lop < n; lop++) {
			cin >> r;
			if (4*r*r > x)
				cout << "OK\n";
			else
				cout << "NA\n";
		}
	}
	return 0;
}


Measured memory_bytes: 2972
#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>;
vector<int> s;
vector<int> c;
int n, m;
bool ok(string str) {
    if (str.size() != n) return false;
    for (int i = 0; i < m; ++i) if (str[s[i]] != (char)(c[i] + '0')) return false;
    return true;
}

string solve() {
    for (int i = 0; i <= 999; ++i) {
        string str = to_string(i);
        if (ok(str)) return str;
    }
    return "-1";
}
int main(){
    cin >> n >> m;
    s.resize(m); c.resize(m);
    rep(i,m){
        cin >> s[i] >> c[i];
        s[i]--;
    }
    string ans = solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

#ifndef INTERACTIVE
[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}
#endif // INTERACTIVE

int main() {
    int n; cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    a.push_back(-1488);
    n += 1;

    int ans = 0;
    int curl = 1;
    for (int i = 1; i < n; ++i) {
        if (a[i] != a[i - 1]) {
            ans += curl / 2;
            curl = 1;
        } else {
            curl += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
/*
AizuOnline A1103
Board Arrangements for Concentration Games
*/
#include <stdio.h>

char  tehai[45];
int haiti[]={1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34};

int rel_pos[]={10,21,22,33};
int cnt;
char dummy;

void showhand(char mark)
{
  /*
  int i,j,k;

  printf("%c",mark);
  for(i=0;i<4;i++)
    {
      for(j=0;j<=4;j++)
        if(tehai[k=i*10+j])
          printf("%d",k);
      printf("/");
    }
  printf("\n");
  */
  /*
    scanf("%c",&dummy);
  */
}

void isagari()
{ int i,j;

  showhand('B');

  for(i=0;i<45;i++)
    if(tehai[i])
      goto NEXT;
  cnt++;
  return;

 NEXT:
  for(i=0;i<45;i++)
    {  
      if(tehai[i]==0)
	continue;
      for(j=0;j<4;j++)
	{
	  if( tehai[i+rel_pos[j]])
	    {  tehai[i]--;
	      tehai[i+rel_pos[j]]--;
	      isagari();
	      tehai[i]++;
	      tehai[i+rel_pos[j]]++;
	    }
	}
      break;
    }
    return;
}

int main()
{
  
  int  i;
  int ret;
  int c;
  int a1,a2,a3,a4,a5,a6,a7,a8;
  char buf[256];

  while(NULL != fgets(buf,200,stdin))
    {
      sscanf(buf,"%d %d %d %d %d %d %d %d",&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8);
    
      if(a1 > 4)break;

      rel_pos[0]=a1+a2*10;
      rel_pos[1]=a3+a4*10;
      rel_pos[2]=a5+a6*10;
      rel_pos[3]=a7+a8*10;
      /*      printf("%d\n",rel_pos[0]); */
      for(i=0;i<45;i++)
	tehai[i]=0;
 
      for(i=0;i<16;i++)
	tehai[haiti[i]]=1;

      cnt = 0;
  /*  showhand('A'); */ 
      
      isagari();  
      printf("%d\n",cnt);
    }
  return(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	ll a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;
}

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

using namespace std;

const int N = 2e5 + 100;
int n, a[N];
int mx1[N], mx2[N];

int main()
{
    cin >> n;
    for( int i = 1;  i<= n; i ++ ){
        cin >> a[i];
        mx1[i] = max( mx1[i - 1], a[i] );
    }
    for( int i = n; i >= 1; i -- ){
        mx2[i] = max( mx2[i + 1], a[i] );
    }

    for( int i = 1; i <= n; i ++ ){
        cout << max( mx1[i-1], mx2[i + 1 ]) << endl;
    }

}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

ll mod = 1e9+7;
const int N = 5e5+5;

//fact:階乗,
//finv:階乗の逆元
//inv:逆元
ll fact[N], finv[N], inv[N];

//テーブルを作る前処理
void init(){
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < N; i++){
    //階乗
    fact[i] = fact[i-1] * i % mod;
    //逆元
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    //階乗の逆元
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

//二項係数計算(mod入る)
ll COM(int n, int k){
  if(n<k) return 0;
  return ( fact[n] * (finv[k] * finv[n-k] % mod) % mod ) % mod;
}

//有理数計算
ll frac(ll y, ll x){
  return (mod + y*x%mod) %mod;
}

int main(void){
  init();
  int i,B,W;
  ll x=inv[2],y=1;
  cin >> B >> W;
  ll p = 0, q = 0;

  REP(i,B+W){
    //cout << p << " " << q << " " << frac(y-p+q,x) << endl;
    cout << frac(y-p+q,x) << endl;
    p = p*2 + COM(i,B-1);
    p %= mod;
    q = q*2 + COM(i,W-1);
    q %= mod;
    x *= inv[2];
    x %= mod;
    y *= 2;
    y %= mod;
  }
  return 0;
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

int main() {
    vi a(4, -1);
    cin >> a[0];
    ll ans = 1;
    while (a[0] != a[3]) {
        ans++;
        for (int i = 2; i >= 0; i--) {
            a[i + 1] = a[i];
        }
        if (a[1] % 2 == 0)
            a[0] = a[1] / 2;
        else
            a[0] = a[1] * 3 + 1;
    }
    cout << ans << endl;
}


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

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

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

    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a % 2 == 0 && a % 3 !=0 && a % 5 != 0) {
            cout << "DENIED\n";
            return 0;
        }
    }

    cout << "APPROVED\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2010;
int n;
bitset<N>a[N],b[N],L[N],R[N];
char s[N];

int main(){
	n=read();
	For(i,2,n){
		scanf("%s",s+1);
		FOR(j,1,i){
			if (s[j]=='0') a[j][i]=1,b[i][j]=1;
				else b[j][i]=1,a[i][j]=1;
		}
	}
	For(i,1,n) L[i][i]=R[i][i]=1;
	For(len,2,n){
		For(l,1,n-len+1){
			int r=l+len-1;
			if (R[l+1][r]&&a[l][r]) L[r][l]=1;
			if ((R[l+1]&L[r]&a[l]).any()) L[r][l]=1;
			if (L[r-1][l]&&a[r][l]) R[l][r]=1;
			if ((R[l]&L[r-1]&a[r]).any()) R[l][r]=1;
		}
	}
	printf("%d\n",(R[1]&L[n]).count());
}

Measured memory_bytes: 5764
#include <bits/stdc++.h>
#define MAX 300010
using namespace std;

int cnt[MAX];
int ans[MAX];
int lastPos[MAX];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int t;
		cin >> t;
		cnt[t - 1]++;
	}
	sort(cnt, cnt + N);
	for (int i = 0; i < N - 1; i++)
	{
		for (int j = cnt[i]; j < cnt[i + 1]; j++) lastPos[j] = i;
	}
	for (int i = cnt[N - 1]; i < N; i++) lastPos[i] = N - 1;
	for (int i = 0; i < N - 1; i++)
	{
		ans[N - 1 - i] = cnt[i];
		for (int j = 0; j < cnt[i]; j++)
		{
			int p = lastPos[cnt[i + 1]];
			lastPos[cnt[p]]--;
			cnt[p]++;
			if (cnt[lastPos[cnt[p]]] != cnt[p]) lastPos[cnt[p]] = p;
		}
	}
	ans[0] = N;
	for (int i = 0; i < N; i++) cout << ans[i] << "\n";
	return 0;
}


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

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            String S = reader.readLine();
            int N = S.length();

            int[] C = new int[N];
            for (int i = 0; i < N; i++) {
                C[i] = 1;
            }

            for (int i = 0; i < N; i++) {
                if (S.charAt(i) == 'R') {
                    if (S.charAt(i + 1) == 'R') {
                        C[i + 2] += C[i];
                        C[i] = 0;
                    }
                }
            }

            for (int i = N - 1; i >= 0; i--) {
                if (S.charAt(i) == 'L') {
                    if (S.charAt(i - 1) == 'L') {
                        C[i - 2] += C[i];
                        C[i] = 0;
                    }
                }
            }

            StringBuilder ans = new StringBuilder();
            ans.append(C[0]);
            for (int i = 1; i < N; i++) {
                ans.append(" ").append(C[i]);
            }

            System.out.println(ans.toString());
        }
    }

}


Measured memory_bytes: 26940
(N, T) = map(int, input().split())
c = []
for i in range(N):
    (tmpc, tmpt) = map(int, input().split())
    if tmpt <= T:
        c.append(tmpc)

if len(c) == 0:
    ans = 'TLE'
else:
    ans = min(c)

print(ans)




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

using namespace std;

signed main()
{
    vector<int> count(3,1);
    count.at(0)=0;
        string s;
        cin >>s;
        if(s.at(0)=='R')count.at(0)=1;
    for(int i=1;i<3;i++)
    {
        if(s.at(i)==s.at(i-1)&&s.at(i)=='R'&&s.at(i-1)=='R')
        {
            count.at(i)+=count.at(i-1);
        }
        else if(s.at(i)=='R')
        {
            continue;
        }
        else
        {
            count.at(i)=0;
        }
    }
    cout << max(count.at(0),max(count.at(1),count.at(2))) << endl;
    return(0);
}

Measured memory_bytes: 3624
//============================================================================
// Name        : abc141_c.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : https://atcoder.jp/contests/abc141/tasks/abc141_c
//============================================================================

// わずかに早くなるかも
#pragma GCC optimize ("Ofast")
// 浮動小数点数の計算がボトルネックとなるときは 100ms くらい改善するかも？
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

// C++の標準ライブラリを一行で一括でインクルードする
#include <bits/stdc++.h>
// #include <iostream>
using namespace std;

// 数値の読み取り, 低速な cin の使用を回避する
inline int read() {
	int f = 1, x = 0; // 負数フラグ、絶対値
	char ch = getchar();
	while (ch < '0' || ch > '9') { // 数値以外を飛ばす
		if (ch == '-') { // ただし '-' のとき負数フラグを立てる
			f = -1;
		}
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') { // 数値の読み取り
		x = x * 10 + (ch - '0');
		ch = getchar();
	}
	return x * f;
}

// K から自分以外が正解した回数を引いて 0 以下なら No
// <=> K - (解答できなかった回数) <= 0 なら No
// <=> K - (Q - 解答できた回数) <= 0 なら No
// <=> K - Q + (解答できた回数) <= 0 なら No
const int MAXN=100001;
int N, K, Q, c[MAXN]; // 関数外の場合は 0 で初期化される
int main() {

	N=read();K=read();Q=read();
	// 解答者の入力 -> 解答者ごとの解答数の集計
	for (int i = 1; i <= Q; ++i) { // i 番目に正解したのは参加者 read()
		++(c[read()]);
	}
	// 出力
	for (int j = 1; j <= N; ++j) {
		puts((K - Q + c[j] <= 0) ? "No" : "Yes"); // cout よりも puts
	}
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	ll a, b; cin >> a >> b;

	int flg = 0;
	if (abs(a - b) >= 2) {
		flg = 1;
	}
	else if(a - b == 0){
		flg = 2;
	}
	else {
		flg = 3;
	}
	
	//階乗をもとめる
	ll nn = 1;
	for (int i = 1; i <= a; i++) {
		nn = nn * i % 1000000007;
	}
	ll mn = 1;
	for (int i = 1; i <= b; i++) {
		mn = mn * i % 1000000007;
	}

	
	if (flg == 1) {
		cout << 0 << endl;
	}
	else if (flg == 2) {
		cout << nn * mn * 2 % 1000000007 << endl;
	}
	else {
		cout << nn * mn % 1000000007 << endl;
	}
}

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

int main() {
	int k; cin >> k;
	long count = 0;
	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			for (int c = 1; c <= k; c++) {
				count += gcd(a, gcd(b, c));
			}
		}
	}
	cout << count << endl;
	return 0;
}


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

int main(void){
    string s;ll k;
    cin>>s>>k;
    ll n = s.size();
    vi a;
    a.push_back(1);
    
    for(int i=1; i<n; i++){
        if(s[i]==s[i-1])a.back()++;
        else a.push_back(1);
    }
    
    if(a.size()==1){
        cout << n*k/2 << endl;
    }else{
        ll ans = 0;
        if(s[0]!=s[n-1]){
            rep(i,a.size())ans += a[i]/2 * k;
            cout << ans << endl;
        }else{
            ans = a[0]/2 + a.back()/2;
            ans += (a[0]+a.back())/2 * (k-1);
            for(int i=1; i<a.size()-1; i++){
                ans += a[i]/2 * k;
            }
            cout << ans << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3528
#include <stdio.h>
#define N 100000

struct grade{
    int m;
    int f;
    int r;
};

int main(void) {

    int i, j, k;
    int n;
    struct grade stu[N];

    for (i = 0; i < N; i++) {
        stu[i].m = 0;
        stu[i].f = 0;
        stu[i].r = 0;
    }

    i = 0;
    while (1) {
        scanf("%d%d%d", &stu[i].m, &stu[i].f, &stu[i].r);
        if ((stu[i].m == -1) && (stu[i].f == -1) && (stu[i].r == -1)) {
            break;
        } else {
            i++;
        }
    }
    n = i;

    for (i = 0; i < n; i++) {
        if ((stu[i].m == -1) || (stu[i].f == -1)) {
            printf("F\n");
        } else if (stu[i].m + stu[i].f < 30) {
            printf("F\n");
        } else if ((stu[i].m + stu[i].f >= 30) && (stu[i].m + stu[i].f < 50)) {
            if (stu[i].r >= 50) {
                printf("C\n");
            } else {
                printf("D\n");
            }
        } else if ((stu[i].m + stu[i].f >= 50) && (stu[i].m + stu[i].f < 65)) {
            printf("C\n");
        } else if ((stu[i].m + stu[i].f >= 65) && (stu[i].m + stu[i].f < 80)) {
            printf("B\n");
        } else if (stu[i].m + stu[i].f >= 80) {
            printf("A\n");
        }
    }

    return 0;

}

Measured memory_bytes: 1756
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b = 0, n, k;
string s, t;
//cout<<<<endl;


int main()
{
	cin >> s;
	a = 0;
	rep(i, (s.size()+1)/2)
	{
		if (s[i] != s[s.size()-1-i])
			a++;
	}
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MOD = 1e9+7;

int main() {
    int n; cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());

    int ans = 0;
    for (int a = 0; a < n; a++) {
        for (int b = a+1; b < n; b++) {
            int c = lower_bound(l.begin(), l.end(), l[a]+l[b]) - l.begin() - 1;
            ans += c - b;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		int ans=0;
		for(;n>0;n/=10)
		{
			ans+=n%10;
		}
		if(ans==1) ans=10;

		printf("%d\n", ans);
	}

	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    ll A, B, K;
    cin >> A >> B >> K;
    ll temp_calc = 0;

    if (A >= K) {
        A = A - K;
    } else if (A < K) {
        temp_calc = K - A;
        A = 0;
        if (B >= temp_calc) {
            B = B - temp_calc;
        } else {
            B = 0;
        }
    }


    cout << A << endl;
    cout << B << endl;

    return 0;
}

Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 20:40:57
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(auto a : s){
        if(a=='+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
def check(s):
    if len(s)%2 == 1:
        return False
    if s[len(s)//2:] == s[:len(s)//2]:
        return True
    else:
        return False

S = input()

for i in reversed(range(1,len(S))):
    if check(S[:i]):
        print(i)
        break


Measured memory_bytes: 38424
#include <iostream>
#include <iostream>
#include <iterator>
#include <vector>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef long double lld;
typedef pair<int,int> pi;
#define FastIO cin.sync_with_stdio(false),cin.tie(NULL)
#define lli       long long int
#define mod       (ll) 1000000007
#define pb        push_back
#define f(i,s,n)    for (int i=s;i<n;i++)
#define vii       vector<int>
#define seti      set<int>
#define mapi      map<int,int>
#define mapv      map<int,vii>
#define vll       vector<ll>
#define vpp       vector<pp>
#define vss       vector<string>
#define lcm(a,b)    (a*b)/__gcd(a,b)
#define all(a)      a.begin(),a.end()
#define abs(a)      a>0?a:-1*a
#define all(a)      a.begin(),a.end()
#define fo(i,a)       for(auto &i:a)
#define bs(v,x)     binary_search(all(v),x)
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);srand(time(NULL))
#define sortrev(ans) sort(a.begin(), a.end(), greater<int>());
#define vii2d       vector<vector<int>>
#define ms          multiset<int>
#define pairi       pair<int,int>
#define mp          make_pair
#define gcd(a,b)    __gcd(a,b)
vector<vector<int>> ans(200000);
bool visited[200000];
int dfs(int v)
{
  visited[v]=true;
  int c=1;
  for(auto&i:ans[v])
  {
    if (visited[i]==false)
    {
      c+=dfs(i);
    }
  }
  return c;
}
void solve()
{
  int n,k;
  cin>>n>>k;
  map<pairi,int>d;
  f(i,0,n)
  {
    visited[i]=false;
  }
  f(i,0,k)
  {
    int a,b;
    cin>>a>>b;
    a-=1;
    b-=1;
    if ((d[mp(a,b)]==1)||(d[mp(b,a)]==1))
      continue;
    d[mp(a,b)]=1;
    d[mp(b,a)]=1;
    ans[a].pb(b);
    ans[b].pb(a);
  }
  int tot=0;
  f(i,0,n)
  {
    if (visited[i]==false)
    {
      tot=max(tot,dfs(i));
    }
  }
  cout<<tot<<endl;

}
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    int count=1;
    //cout<<t<<endl;
    while(t--)
    {
      solve();
      count+=1;
    }
  return 0;
}


Measured memory_bytes: 48508
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;
typedef pair<int,int> pi;
bool cmp(const pi&a,const pi&b){return a.se<b.se||a.se==b.se&&a.fi<b.fi;}

const int N=300005;

int n,w,h,ans;
pi p[N],b[N];

int u1[N],d1[N],x1[N],m1;
int u2[N],d2[N],x2[N],m2;
int qu[N],va[N],ql,qr;

inline void push(int x,int v){while(va[qr]<=v&&ql<=qr)qr--;qu[++qr]=x,va[qr]=v;}
inline void pop(int x){while(qu[ql]<x&&ql<=qr)ql++;}

void solve(int s,int t,int l,int r){
	if(l>r)return;
	if(s>=t){sort(p+l,p+r+1);return;}
	int H=(s+t+1)>>1,mid=l;
	while(p[mid].se<H&&mid<=r)mid++;
	solve(s,H-1,l,mid-1);solve(H,t,mid,r);
	int i=l,j=mid,k=l;
	while(i<mid||j<=r){
		if(i>=mid)b[k++]=p[j++];
		else if(j>r)b[k++]=p[i++];
		else if(p[i]<p[j])b[k++]=p[i++];
		else b[k++]=p[j++];
	}
	for(i=l;i<k;i++)p[i]=b[i];
	int mi=l;
	while(p[mi].fi<=(w>>1)&&mi<=r)mi++;
	int U,D,L,R;
	m1=m2=0;
	U=t,D=s;
	for(i=mi-1;i>=l;i--){
		++m1,u1[m1]=U,d1[m1]=D,x1[m1]=p[i].fi;
		if(p[i].se>=H)U=min(U,p[i].se);else D=max(D,p[i].se);
	}
	++m1,u1[m1]=U,d1[m1]=D,x1[m1]=0;
	U=t,D=s;
	for(i=mi;i<=r;i++){
		++m2,u2[m2]=U,d2[m2]=D,x2[m2]=p[i].fi;
		if(p[i].se>=H)U=min(U,p[i].se);else D=max(D,p[i].se);
	}
	++m2,u2[m2]=U,d2[m2]=D,x2[m2]=w;
	L=R=1,ql=1,qr=0;
	for(i=1;i<=m1;i++){
		while(u1[i]<=u2[R]&&R<=m2)push(R,x2[R]-d2[R]),R++;
		while(d1[i]>d2[L]&&L<=m2)L++;pop(L);
		if(min(L,R)>1)ans=max(ans,x2[min(L,R)-1]-x1[i]+u1[i]-d1[i]);
		if(ql<=qr)ans=max(ans,va[ql]-x1[i]+u1[i]);
	}
	L=R=1,ql=1,qr=0;
	for(i=1;i<=m2;i++){
		while(u2[i]<=u1[R]&&R<=m1)push(R,-x1[R]-d1[R]),R++;
		while(d2[i]>d1[L]&&L<=m1)L++;pop(L);
		if(min(L,R)>1)ans=max(ans,x2[i]-x1[min(L,R)-1]+u2[i]-d2[i]);
		if(ql<=qr)ans=max(ans,va[ql]+x2[i]+u2[i]);
	}
}

void work(){
	sort(p+1,p+n+1,cmp);
	solve(0,h,1,n);
}

int main(){
	scanf("%d%d%d",&w,&h,&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&p[i].fi,&p[i].se);
	for(int i=1;i<=n;i++)swap(p[i].fi,p[i].se);swap(w,h);
	work();
	for(int i=1;i<=n;i++)swap(p[i].fi,p[i].se);swap(w,h);
	work();
	printf("%d\n",ans*2);
	return 0;
}

Measured memory_bytes: 13440
#include<stdio.h>

int main(){
  int l[30],w,n,i,a,b,s;

  scanf("%d",&w);
  for(i=0;i<w;i++)l[i]=i+1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d,%d",&a,&b);
    s=l[a-1];l[a-1]=l[b-1];l[b-1]=s;
  }
  for(i=0;i<w;i++)printf("%d\n",l[i]);

  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<string.h>
struct Guidebook{
	int i;
	char s[100];
	int r;
};
int main(void) {
	int j, h, n, tmp;
	struct Guidebook book[200];
	scanf("%d", &n);
	for (j = 0; j < n; j++) {
		book[j].i = j + 1;
		scanf("%s %d", &book[j].s, &book[j].r);
	}
	for(h = 0; h < n; h++){
		for (j = 1; j < n; j++) {
			if (strcmp(book[j - 1].s, book[j].s) == 0) {
				if (book[j - 1].r < book[j].r) {
					book[150] = book[j - 1];
					book[j - 1] = book[j];
					book[j] = book[150];
				}
			}
			else if (strcmp(book[j - 1].s, book[j].s) > 0) {
				book[150] = book[j - 1];
				book[j - 1] = book[j];
				book[j] = book[150];
			}
		}
	}
	for (j = 0; j < n; j++) {
		printf("%d\n", book[j].i);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi a(n); rep(i, n) cin >> a[i];

  int ans = 1, sign = 0;
  for (int i = 0; i < n-1; i++) {
    if(a[i+1] == a[i]) continue;
    if(a[i+1] > a[i]){
      if(sign == 0){sign = 1; continue;}
      if(sign == 1) continue;
      if(sign == -1){
        ans++;
        sign = 0;
      }
    }

    if(a[i+1] < a[i]){
      if(sign == 0){sign = -1; continue;}
      if(sign == -1) continue;
      if(sign == 1){
        ans++;
        sign = 0;
      }
    }
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>
using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
const double pi = 3.14159265359;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    int ans=0;
    int i = 0;
    while (i != N-1) {
        int cnt = 0;
        for (int j = i+1; j < N; ++j) {
            if (a[j-1] >= a[j])cnt++;
            else {
                ans = max(ans, cnt);
                i = j;
                break;
            }
            if (j == N - 1) {
                ans = max(ans, cnt);
                i = j;
            }

        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
<?php

$arr = explode(' ', fgets(STDIN));

$n = (int)$arr[0];
$l = (int)$arr[1];
$res = 0;
$min = 100;
for ($i = $l;$i < $l + $n;$i++) {
    $res += $i;
    $min = min($min, abs($i));
}
if ($res < 0) {
    echo $res + $min . PHP_EOL;
} else {
    echo $res - $min . PHP_EOL;
}


Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    string s1;
    cin>>s1;
    int n = s1.size();
    loop(i,0,n)
    {
        if(i%2==0)
       cout<<s1[i];
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 3608
n = int(input())
A = list(map(int,input().split()))
A.sort()
ls = []
pre = A[0]
cnt = 1
for i in range(n):
    if A[i] == pre:
        cnt+=1
    else:
        ls.append((pre,cnt))
        cnt = 1
    pre = A[i]
ls.append((pre,cnt))
ans = 0
pre = 0
for num,cnt in ls:
    if cnt>=2:
        if cnt>=4:
            ans = num**2
        else:
            ans = num*pre
        pre = num
print(ans)


Measured memory_bytes: 14672
#include<stdio.h>

int main(void)
{
   int n, x, a[100001], b, z, i, s, w;

   scanf("%d%d",&n,&x);
   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
      if(x<a[i])
         a[i]=a[i]-x;
      else
         a[i]=x-a[i];
   }
   a[n]=1;
   s=a[0];

   for(i=0;i<n;i++){
      b=a[i+1];
      z=1;
      w=s;
      while(z!=0){
         z=s%b;
         s=b;
         b=z;
      }
   }

   printf("%d\n",w);
   return 0;
}

Measured memory_bytes: 2124
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n, i;


int main(){

	cin >> n >> i;

	cout << n - i + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
s = input()

n = len(s)
d = [0] * n

x = 0
for i in reversed(range(n)):
    if s[i] == 'L':
        x = 0
    else:
        x += 1
        d[i] = x

x = 0
for i in range(n):
    if s[i] == 'R':
        x = 0
    else:
        x += 1
        d[i] = x


counter = [0] * n
for i in range(n):
    if s[i] == 'R':
        if d[i] % 2 == 0:
            counter[i + d[i]] += 1
        else:
            counter[i + d[i] - 1] += 1
    else:
        if d[i] % 2 == 0:
            counter[i - d[i]] += 1
        else:
            counter[i - d[i] + 1] += 1

print(' '.join(map(str, counter)))

Measured memory_bytes: 14452
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i=1;i<10;i++){
     for(int j=1;j<10;j++){
          if(n == i*j){
               cout<<"Yes";
               return 0;
          }
     }
    }
    cout << "No" << endl;
    return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w;
	cin>>h>>w;
	vector<vector<char>> data(h,vector<char>(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>data.at(i).at(j);
		}
	}
	for(int i=0;i<h;i++){
		if(i==0 ){
			for(int k=0;k<w+2;k++){
				cout<<"#";
			}cout<<endl;
		}
		for(int j=0;j<w;j++){
			if(j==0){
				cout<<"#";
			}
			cout<<data.at(i).at(j);
			if(j==w-1){
				cout<<"#";
			}
		}cout<<endl;
		if( i==h-1){
			for(int k=0;k<w+2;k++){
			cout<<"#";
			}cout<<endl;
		}
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		// ビンゴカード
		int bingoCard[][] = new int[3][3];

		// ビンゴ状態管理
		boolean bingo[][] = new boolean[3][3];

		int N;

		int b[] = new int[10];

		// ビンゴカードの値設定
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				bingoCard[i][j] = scan.nextInt();
			}
		}

		//System.out.println(Arrays.deepToString(bingoCard));
		N = scan.nextInt();

		// ビンゴに使う値の設定
		for(int i = 0; i  < N; i++) {
			b[i] = scan.nextInt();
		}

		// ビンゴの当たり管理
		for(int i = 0; i < 3; i++) {
			//System.out.println(i);
			for(int j = 0; j < 3; j++)
			{
				//System.out.println(j);
				bingo[i][j] = false;
				for(int k = 0; k < N; k++) {

					// ビンゴカードの中で数字が一致したらtrue
					if(bingoCard[i][j] == b[k]) {
						bingo[i][j] =  true;
					}
				}
			}
		}

		String ans  = "No";


		for(int i = 0; i < 3; i++) {
			//行がそろった
			if(bingo[i][0] &&  bingo[i][1] && bingo[i][2]) {
				ans = "Yes";
			}
			//列がそろった
			if(bingo[0][i] &&  bingo[1][i] && bingo[2][i]) {
				ans = "Yes";
			}
		}

		// 左上から斜め
		if(bingo[0][0] && bingo[1][1] && bingo[2][2]) {
			ans = "Yes";
		}

		// 右上から斜め
		if(bingo[0][2] && bingo[1][1] && bingo[2][0]) {
			ans = "Yes";
		}


		System.out.println(ans);

	}

}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int i;
  for(i=0;i<str.size();i++){
    if(str[i]>='a'&&str[i]<='z') str[i]+='A'-'a';
    else if(str[i]>='A'&&str[i]<='Z') str[i]+='a'-'A';
  }
    cout << str << endl;
  return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void xin(){
	#ifndef ONLINE_JUDGE 
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}
int main()
{
  	xin();
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    cin>>n;
    if(n%1000 == 0)
    {
    	cout<<0<<endl;
    }
    else
    {
   	cout<<1000 - n%1000<<endl;
   }
}

Measured memory_bytes: 3648
class UF{
  int[] par;
  this(int n){
    par.length=n;
    foreach(i; 0..n) par[i]=i;
  }
  int find(int x){
    if(x==par[x]) return par[x];
    else return par[x]=find(par[x]);
  }
  void unite(int x, int y){
    if((x=find(x))!=(y=find(y))) par[x]=y;
  }
  bool same(int x, int y){
    return find(x)==find(y);
  }
}

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;

  int n, m; rd(n, m);
  alias Edge=Tuple!(int, int);
  auto edge=new Edge[](0);
  foreach(_; 0..m){
    int a, b; rd(a, b);
    edge~=Edge(a-1, b-1);
  }

  int cnt=0;
  foreach(i; 0..m){
    auto uf=new UF(n);
    foreach(j; 0..m){
      if(i==j) continue;
      uf.unite(edge[j][0], edge[j][1]);
    }
    if(!uf.same(edge[i][0], edge[i][1])) cnt++;
  }
  writeln(cnt);
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

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

using namespace std;

struct Edge {
  int to;
  int64_t cost;
};

vector<vector<Edge>> G;
vector<int64_t> distances;

void DFS(int v, int parent, int64_t d) {
  distances[v] = d;
  for (const auto& e : G[v]) {
    if (e.to == parent) continue;
    DFS(e.to, v, d + e.cost);
  }
}

int main() {
  int N;
  cin >> N;
  G.resize(N);
  distances.resize(N);

  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }

  int Q, K;
  cin >> Q >> K;
  K--;
  DFS(K, -1, 0);

  for (int i = 0; i < Q; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    printf("%ld\n", distances[x] + distances[y]);
  }

  return 0;
}


Measured memory_bytes: 14336
#include <iostream>
#include <string>
using namespace std;
int main(){
 int a,b;
 cin>>a>>b;
 if(a==1&&b!=1){cout<<"Alice"<<endl;}
 else if(a>b&&b!=1){cout<<"Alice"<<endl;}
 else if(a==b){cout<<"Draw"<<endl;}
 else{cout<<"Bob"<<endl;}
}



Measured memory_bytes: 256