akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int ret=0;
	for(int i=a;i<=b;i++){
		int x=i;
		int d[5];
		for(int j=0;j<5;j++){
			d[j]=x%10;
			x/=10;
			
		}
		if(d[0]==d[4] && d[1]==d[3])ret++;
	}
	
	cout<<ret<<endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define itn int
using namespace std;
const int N=1e6;
const long long mod=1e9+7;
const long long mod2=998244353;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
ll mul(ll a,ll b,ll c){ll ans=0;for(;b;b>>=1,a=(a+a)%c)if(b&1)ans=(ans+a)%c;return ans;}
ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=mul(a,a,c))if(b&1)ans=mul(ans,a,c);return ans;}

int main(){
	//freopen("in.txt","r",stdin);
	int a,b;
	cin>>a>>b;
	if(a>b)swap(a,b);
	if((a+b)&1)o("IMPOSSIBLE");
	else o(a+b>>1);
}


Measured memory_bytes: 256
"use strict"

function Main(input) {
  let lines = input.split('\n');
  const [a, b, c, d] = lines[0].split(' ').map(BigInt);

  let product_matrix = [];
  product_matrix.push(a * c);
  product_matrix.push(a * d);
  product_matrix.push(b * c);
  product_matrix.push(b * d);
  const max = product_matrix.reduce((a,b)=>a>b?a:b)

  console.log(max.toString());
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29624
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
string n, m;

int main(){
	cin >> n >> m;
	string ans = "YES";
	for(ll i = 0; i < n.size(); i++){
		if(n[i] != m[m.size()-1-i]){
			ans = "NO";
			break;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main(){
	int w, h;
	cin >> w >> h;
	vector<ll> p(w), q(h);
	for(int i = 0; i < w; i++) cin >> p[i];
	for(int i = 0; i < h; i++) cin >> q[i];
	vector<P> va;
	for(int i = 0; i < w; i++) va.push_back(P(p[i], 0));
	for(int i = 0; i < h; i++) va.push_back(P(q[i], 1));
	sort(va.begin(), va.end());
	ll res = 0;
	ll num = w + 1, num2 = h + 1;
	for(int i = 0; i < va.size(); i++){
		if(va[i].second == 0){
			res += num2 * va[i].first;
			num--;
		}else if(va[i].second == 1){
			res += num * va[i].first;
			num2--;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3956
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
ll solve(ll a[],ll dp[],ll n)
{
	if(n<=0)
		return 0;
	if(dp[n]!=inf)
		return dp[n];
	dp[n]=min(n-1<0 ?inf :solve(a,dp,n-1)+abs(a[n]-a[n-1]),n-2<0 ?inf :solve(a,dp,n-2)+abs(a[n]-a[n-2]));
	return dp[n];
}
int main()
{
	checkpoint1();
	ll n;
	cin>>n;
	ll a[n],dp[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
		dp[i]=inf;
	}
	dp[0]=0;
	cout<<solve(a,dp,n-1);
	return 0;
}

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

int main() {
  int N, K, R, S, P, ans = 0;
  string T;
  cin >> N >> K >> R >> S >> P >> T;
  for(int i=0;i<N;i++){
    if(i < K){
      if(T[i] == 'r') ans += P;
      else if(T[i] == 's') ans += R;
      else if(T[i] == 'p') ans += S;
    }  
    else if(i >= K){
      if(T[i] == T[i-K]){
        T[i] = 'o';
      }
      if(T[i] == 'r') ans += P;
      else if(T[i] == 's') ans += R;
      else if(T[i] == 'p') ans += S;
    }  
  }  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    
    string a[10];
    cin>>a[0]>>a[1]>>a[2];
    ll now=0;
    while(a[now].size()>0){
        ll Now=now;
        Now=a[now][0]-'a';
        a[now]=a[now].substr(1);
        now=Now;
    }
    cout<<(char)(now+'A')<<endl;
    return 0;
}

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

int main() {
    int n, x;
    while (true) {
        cin >>n >>x;
        if ((n==0)&&(x==0))
            break;
        int S=0;
        for (int i=1; i<=n; i++)
            for (int j=i+1; j<=n; j++) {
                int k=x-i-j;
                if ((k<=j)||(k>n))
                    continue;
                if ((i==j)||(j==k)||(i==k))
                    continue;
                S++;
            }
        cout <<S <<endl;
    }
    return 0;
}


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

using namespace std;

vector <int> V[101010], G[101010], T[101010];
int K[101010], D[101010], F[101010];
char str[101010];
bool chk[101010];
int n, m, cnt;

void die() { printf("NO\n"); exit(0); }

void dfs(int p)
{
	chk[p] = 1;
	K[cnt] = (K[cnt] + D[p]) % 26;
	T[cnt].push_back(p);
	
	for(int &t: V[p]){
		if(!chk[t]) dfs(t);
	}
}

int check(int p)
{
	int ret = K[p];
	chk[p] = 1;
	
	for(int &t: G[p]){
		if(!chk[t]) ret = (ret + check(t)) % 26;
	}
	
	return ret;
}

int main()
{
	int i, a, b, p, k;
	
	scanf("%s", str);
	
	n = strlen(str);
	
	D[0] = str[0] - 'a';
	D[n] = (26 + 'a' - str[n-1]) % 26;
	
	for(i=1; i<n; i++){
		D[i] = (26 + str[i] - str[i-1]) % 26;
	}
	
	scanf("%d", &m);
	
	for(i=1; i<=m; i++){
		scanf("%d%d", &a, &b); a --;
		V[a].push_back(b);
		V[b].push_back(a);
	}
	
	for(i=0; i<=n; i++){
		if(!chk[i]){
			cnt ++;
			dfs(i);
		}
	}
	
	for(i=1; i<=cnt; i++){
		chk[i] = 0;
		
		sort(T[i].begin(), T[i].end());
		
		for(int &t: T[i]){
			if((~n & 1) && t == (n >> 1)) continue;
			else if(*lower_bound(T[i].begin(), T[i].end(), n - t) == n - t) continue;
			if(F[n - t]){
				G[i].push_back(F[n - t]);
				G[F[n - t]].push_back(i);
			}
			else F[t] = i;
		}
	}
	
	for(i=1; i<=cnt; i++){
		if(!chk[i] && check(i)) die();
	}
	
	printf("YES\n");
	
	return 0;
}

Measured memory_bytes: 14848
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();
        int x = c - a, y = d - b;
        System.out.println((c-y)+" "+(d+x)+" "+(a-y)+" "+(b+x));
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;

const int max_n = 1e5+5;
const int mod = 1e9 + 7;

int fac[max_n];

int powmod(int a, int m) {
	if (m == 0) return 1;
	if (a == 0) return 0;
	int sq = powmod(a, m/2);
	sq = (sq * 1LL * sq) % mod;
	if (m%2 == 0) return sq;
	return (sq * 1LL * a) % mod;
}

int pref[max_n];
int sum(int a, int b) {
	return a == 0 ? pref[b] : (pref[b] - pref[a-1] + mod) % mod;
}

int main() {
	make(n);
	makev(v, n);
	pref[0] = v[0];
	FOR(i,1,n) pref[i] = (pref[i-1] + v[i])%mod;
	fac[0] = 1;
	FOR(i,1,n+1) fac[i] = (i * 1LL * fac[i-1]) % mod;
	int ans = (fac[n] * 1LL * sum(0,n-1)) % mod;
	int suma = sum(0,n-1);
	FOR(k,1,n) {
		int brzegowe = (sum(0,k-1) + sum(n-k,n-1))%mod;
		int loc = (fac[n] * 1LL * powmod(k+1, mod-2))%mod;
		loc = (loc * 1LL * brzegowe) % mod;
		ans = (ans + loc) % mod;

		loc = (fac[n] * 2LL * powmod(k+1, mod-2))%mod;
		loc = (loc * 1LL * powmod(k+2, mod - 2)) % mod;
		loc = (loc * 1LL * (suma - brzegowe + mod)) % mod;
		ans = (ans + loc) % mod;

		int lewo = k;
		int prawo = n-1-k;
		if (lewo <= prawo ) {
			suma = (suma + sum(lewo,prawo)) % mod;
		} else {
			suma = (suma - sum(prawo+1,lewo-1) + mod) % mod;
		}
	}
	printf("%d\n", ans);
}



Measured memory_bytes: 1528
#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
#define all(a) a.begin(), a.end() 
using namespace std;

int main() {
  int x;
  cin >> x;
  int ans = 10-(x/200);
  cout << ans << endl;
  
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    int t_before = 0;
    int x_before = 0;
    int y_before = 0;
    REP(i,N){
        int t,x,y; cin >> t >> x >> y;
        if((t-t_before)%2 == (100000+x+y-x_before-y_before)%2 && abs(x-x_before)+abs(y-y_before) <= t-t_before){

            t_before = t;
            x_before = x;
            y_before = y;
        }else{
            cout << "No" << endl;
            return 0;
        }

    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		int n1 = Integer.parseInt(str);
		for (int i = 1; i <10; i++) {
			if (n1 % i == 0 & n1 / i < 10) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");

	}

}


Measured memory_bytes: 23892
import math


def main():
    items = []

    for i in range(5):
        items.append(int(input()))

    maxi = 0
    for i in range(5):
        if items[i] % 10 < items[maxi] % 10 and items[i] % 10 != 0:
            maxi = i

    ret = 0
    for i in range(5):
        if i != maxi:
            if items[i] % 10 != 0:
                ret += int(math.floor(items[i] / 10) + 1) * 10
            else:
                ret += int(math.floor(items[i] / 10)) * 10
            continue
        ret += items[i]

    print(ret)


main()


Measured memory_bytes: 3064
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as B

query :: [(Int,Int,Int)] -> [(Int,Int,Int)]
query cs =
  foldl' (flip $ \(x,y,h) ->
             filter $ if h > 0
                      then (\(cx,cy,ch) -> ch == h + abs (x-cx) + abs (y-cy))
                      else (\(cx,cy,ch) -> ch <= abs (x-cx) + abs (y-cy)))
  [(cx,cy,h0 + abs (x0-cx) + abs (y0-cy)) | cx <- [0..100], cy <- [0..100]]
  cs'
  where
    (cs0,(x0,y0,h0):cs1) = span (\(_,_,h) -> h <= 0) cs
    cs' = cs0 ++ cs1

main :: IO ()
main = do
  n <- getLine
  cs <- map ((\(a:b:c:_)->(a,b,c))
              . unfoldr (B.readInt . B.dropWhile (== ' '))) 
         . B.lines <$> B.getContents
  let (cx,cy,ch):_ = query cs
  putStrLn $ show cx ++ ' ' : show cy ++ ' ' : show ch

Measured memory_bytes: 892
#n = gets.chomp.to_i
a,b,c,d = gets.chomp.split(" ").map(&:to_i);
class Array
  def lcm
    self.inject{|a,b| a.lcm(b)}
  end
end

a -= 1
c_d = [c,d].lcm
under_a = a - (a/c) - (a/d) + (a/c_d) 
under_b = b - (b/c) - (b/d) + (b/c_d)

puts under_b - under_a

Measured memory_bytes: 1788
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	int n, m;
	cin >> n >> m;
	cout << max(0, n - 2 * m) << endl;
}
int main() {
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int sx,sy,tx,ty;
  int i,tmp;
  
  scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
  
  //s-->t
  tmp=tx-sx;
  for(i=0;i<tmp;i++){
    printf("R");
  }
  tmp=ty-sy;
  for(i=0;i<tmp;i++){
    printf("U");
  }
  
  //t-->s
  tmp=tx-sx;
  for(i=0;i<tmp;i++){
    printf("L");
  }
  tmp=ty-sy;
  for(i=0;i<tmp;i++){
    printf("D");
  }
  
  //s-->t
  tmp=tx-sx+1;
  printf("D");
  for(i=0;i<tmp;i++){
    printf("R");
  }
  tmp=ty-sy+1;
  for(i=0;i<tmp;i++){
    printf("U");
  }
  printf("L");
  
  //t-->s
  tmp=tx-sx+1;
  printf("U");
  for(i=0;i<tmp;i++){
    printf("L");
  }
  tmp=ty-sy+1;
  for(i=0;i<tmp;i++){
    printf("D");
  }
  printf("R");
 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define int long long

signed main() {
    string s;
    cin >> s;

    if(s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
// ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//


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


struct Node
{
	bool path[8];
};
Node nodes[8];
int N, M, sum = 0;


void next(vector<bool> checked, int now)
{
	checked[now] = true;

	bool flag = true;
	for (size_t i = 0; i < N; i++)
	{
		if (!checked[i])
		{
			flag = false;
			break;
		}
	}
	if (flag)
	{
		sum++;
		return;
	}

	for (int i = 0; i < N; i++)
	{
		if (nodes[now].path[i] && !checked.at(i))
		{
			next(checked, i);
		}
	}
}


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

	vector<bool> checked(N);

	for (size_t i = 0; i < M; i++)
	{
		int a, b;
		cin >> a;
		cin >> b;
		a--; b--;
		nodes[a].path[b] = true;
		nodes[b].path[a] = true;
	}

	next(checked, 0);
	cout << sum;

}



/*
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	unsigned long long N;
	string s, n;

	cin >> N;
	cin >> s;
	cin >> n;

	unsigned cur = 0;
	for( unsigned i = 0 ; i < s.length() ; i++)
	{
		if (s[i] == n[cur])
			cur++;
		else
		{
			i -= cur;

			cur = 0;
		}
		
	}


	cout << max((unsigned long long)(s.length() + n.length() - cur), N);


}
*/



/*
#include <iostream>
#include <memory>

using namespace std;
int main()
{
	long long x, y, z;
	cin >> x;
	cin >> y;
	cin >> z;

	if(x >= y && x >= z)
	{
		if (x % 2 == 0)
		{
			cout << 0;
			return 0;
		}
		cout << y * z;
	}else if( y >= x && y >= z)
	{
		if (y % 2 == 0)
		{
			cout << 0;
			return 0;
		}
		cout << x * z;
	}else
	{
		if (z % 2 == 0)
		{
			cout << 0;
			return 0;
		}
		cout << x * y;
	}
}*/
/*
int main()
{
	bool n = false, s = false, w = false, e = false;
	while(int c = std::cin.get())
	{
		if (c == EOF)break;
		switch (c)
		{
		case 'N':
			n = true;
			break;
		case 'S':
			s = true;
			break;
		case 'W':
			w = true;
			break;
		case 'E':
			e = true;
			break;
		}
	}

	if (n && s && !e && !w || n && s && e && w || !n && !s && e & w || !n && !s && !w && !e)
	{
		std::cout << "Yes";
	}
	else
	{
		std::cout << "No";
	}

    return 0;
}
*/


Measured memory_bytes: 256
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
 
distance1=[-1 for i in range(n)]
distance1[0]=0
next=connection[0]
next2=[]
check=[-1 for i in range(n)]
check[0]=1
checkct=1
ct=0
while len(next)!=0 and checkct!=n:
  ct+=1
  for i in range(len(next)):
    distance1[next[i]]=ct
    check[next[i]]=1
    checkct+=1
    for j in range(len(connection[next[i]])):
      if check[connection[next[i]][j]]==-1:
        next2.append(connection[next[i]][j])
  next=next2
  next2=[]

x=max(distance1)
x=distance1.index(x)

distance2=[-1 for i in range(n)]
distance2[x]=0
next=connection[x]
next2=[]
check=[-1 for i in range(n)]
check[x]=1
checkct=1
ct=0
while len(next)!=0 and checkct!=n:
  ct+=1
  for i in range(len(next)):
    distance2[next[i]]=ct
    check[next[i]]=1
    checkct+=1
    for j in range(len(connection[next[i]])):
      if check[connection[next[i]][j]]==-1:
        next2.append(connection[next[i]][j])
  next=next2
  next2=[]

if max(distance2)%3==1:
  print('Second')
else:
  print('First')

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

int main() {

    int A; // 500
    int B; // 100
    int C; // 50
    int X;

    int a500 = 500;
    int b100 = 100;
    int c50 = 50;

    int p = 0;
    
    cin >> A >> B >> C >> X;

    for (int i = 0; i <= A; i++) {
        int a_tmp = a500 * i;

        if (a_tmp == X){
            //cout <<  a_tmp << endl;
            p = p + 1; 
            continue;
        }

        for (int j = 0; j <= B; j++) {
            int b_tmp = b100 * j;

            if (a_tmp + b_tmp == X){
                //cout <<  a_tmp << " " << b_tmp << endl;
                p = p + 1; 
                continue;
            }

            for (int k = 0; k <= C; k++) {
                int c_tmp = c50 * k;

                if (a_tmp + b_tmp + c_tmp == X){
                    //cout <<  a_tmp << " " << b_tmp << " " << c_tmp << endl;
                    p = p + 1; 
                    continue;
                }
            }
        }
    }

    cout <<  p << endl;

    return 0;

}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL << 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = INF;
    if ((B - A - 1) % 2) {
        ans = (B - A) / 2;
    }
    ans = min(ans, A - 1 + (B - A - 1) / 2 + 1);
    ans = min(ans, N - B + (B - A - 1) / 2 + 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
int main(){
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>
#include <deque>
using namespace std;
typedef pair<int,int> P;

int n,m;
deque<P> d;

int main()
{
    while(scanf("%d%d",&n,&m),n||m){
        d.clear();
        for(int i=0;i<m;i++)d.push_back(P(0,i+1));
        while(n--){
            for(int i=0;i<m;i++){
                int t;
                scanf("%d",&t);                                                                                                                                                                           
                d[i].first-=t;                                                                                                                                                                            
            }                                                                                                                                                                                             
        }                                                                                                                                                                                                 
        sort(d.begin(),d.end());                                                                                                                                                                          
        for(int i=0;i<m;i++){                                                                                                                                                                             
            printf("%d",d[i].second);                                                                                                                                                                     
            printf(i!=m-1?" ":"\n");                                                                                                                                                                      
        }                                                                                                                                                                                                 
    }                                                                                                                                                                                                     
}                                                                                                                                                                                                         
       

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

#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9;
const int MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 1e5 + 5;

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n, k; cin >> n >> k;
	string s; cin >> s;
	vector<pii> v;
	v.push_back(make_pair(0, -1)); 
	for (int i = 0; i < n; i++) {
		if (s[i] == '0') continue;
		int j = i + 1;
		while (j < n && s[i] == s[j]) j++;
		j--;
		v.push_back(make_pair(i, j));
		i = j;
	}
	v.push_back(make_pair(n, n - 1));
	int ans = k;
	for (int i = 0; i < sz(v); i++) ans = max(ans, v[min(i + k, sz(v) - 1)].second - v[i].first + 1);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1020
def main():
    from collections import defaultdict
    from collections import Counter
    import sys

    n = int(input())
    a = list(map(int, sys.stdin.readline().split()))

    d = Counter(a)
    e = defaultdict(int)

    base = sum(v * (v - 1) // 2 for v in d.values())
    e = {k: base - (v >= 2) * (v - 1) for k, v in d.items()}

    p = [str(e[x]) + '\n' for x in a]
    q = ''.join(p)
    print(q)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44276
N=int(input())
W=[input() for i in range(N)]
result='Yes'
for i in range(N-1):
    if W[i][-1] != W[i+1][0]:
        result='No'
        break
W_unique=list(set(W))
if len(W) != len(W_unique):
    result='No'
print(result)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long x[n];
  long y[n];
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
  }

  map<pair<long,long>,int>m;
  set<pair<long,long> >s;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i != j){
       long p = x[i]-x[j];
       long q = y[i]-y[j];
       m[make_pair(p,q)]++;
       s.insert(make_pair(p,q));
      }
      
    }
  }
  int maxx = 0;
  for(auto p: s){
    maxx = max(maxx,m[p]);
  }

cout << n-maxx << endl;
  



}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    string S;
    cin >> N >> S;

    vector<int> r(N);
    vector<int> g(N);
    vector<int> b(N);

    if(S[0] == 'R') {
        r[0] = 1;
    } else if(S[0] == 'G') {
        g[0] = 1;
    } else {
        b[0] = 1;
    }

    for(int i = 1; i < N; i++) {
        if(S[i] == 'R') {
            r[i] = 1;
        } else if(S[i] == 'G') {
            g[i] = 1;
        } else {
            b[i] = 1;
        }

        r[i] += r[i - 1];
        g[i] += g[i - 1];
        b[i] += b[i - 1];
    }

    ll count = 0;

    for(int i = 0; i < N - 2; i++) {
        for(int j = i + 1; j < N - 1; j++) {
            if(S[i] != S[j]) {
                ll c;
                if(S[i] == 'R') {
                    if(S[j] == 'G') {
                        c = b[N - 1] - b[j];
                    } else {
                        c = g[N - 1] - g[j];
                    }
                } else if(S[i] == 'G') {
                    if(S[j] == 'B') {
                        c = r[N - 1] - r[j];
                    } else {
                        c = b[N - 1] - b[j];
                    }
                } else {
                    if(S[j] == 'R') {
                        c = g[N - 1] - g[j];
                    } else {
                        c = r[N - 1] - r[j];
                    }
                }
                if(j + j - i < N) {
                    if(S[j + j - i] != S[i] && S[j + j - i] != S[j]) {
                        c--;
                    }
                }
                count += c;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,ans=0;string A,B,C;char a,b,c;cin>>N>>A>>B>>C;
  for(int i=0;i<N;i++){
    a=A.at(i);b=B.at(i);c=C.at(i);
    if(a==b && b==c)continue;
    else if(a==b or b==c or c==a)ans++;
    else ans+=2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NUM 100


int main(){
  int i,n,count,flag,hoji;
  int a[NUM];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  flag=1;
  while(flag>0){
    flag=0;
    for(i=n-1;i>=1;i--){
      if(a[i]<a[i-1]){
	hoji=a[i];
	a[i]=a[i-1];
	a[i-1]=hoji;
	count++;
	flag=1;
      }
    }
  }


  for(i=0;i<n;i++){
    if(i!=n && i!=0){
      printf(" ");
    }
    printf("%d",a[i]);
  }

  printf("\n");
  printf("%d\n",count);

  return 0;
}




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

int main()
{
	int n;
	cin >> n;
	map<string, vector<int>> m;
	m["S"].resize(14);
	m["H"].resize(14);
	m["C"].resize(14);
	m["D"].resize(14);
	for (int i = 0; i < n; i++)
	{
		string s;
		int k;
		cin >> s >> k;
		m[s][k] = 1;
	}

	vector<string> c = { "S","H","C","D" };
	for (int i = 0; i < 4; i++)
	{
		for (int j = 1; j < 14; j++)
		{
			if (m[c[i]][j] == 0)
			{
				cout << c[i] << " " << j << endl;
			}
		}
	}


	return 0;
}

Measured memory_bytes: 3128
s = input()
Acnt = 0 
cnt = 0
BC = False
for i in range(len(s)-1):
    if BC :
        BC = False
        continue
    if s[i] == 'A':
        Acnt += 1
        BC = False
    elif s[i:i+2] == 'BC':
        cnt += Acnt
        BC= True
    else:
        Acnt = 0
        BC = False
#    print(i,Acnt)
print(cnt)

Measured memory_bytes: 3500
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<tuple>
#include<cmath>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

struct vec {
  int64_t x, y;
  vec(): x(0), y(0) {}
  vec(int64_t x, int64_t y) : x(x), y(y) {}
  vec operator+=(vec const& v) { x += v.x; y += v.y; return *this; }
  vec operator-=(vec const& v) { x -= v.x; y -= v.y; return *this; }
  vec operator+(vec const& v) const { return vec(x + v.x, y + v.y); }
  vec operator-(vec const& v) const { return vec(x - v.x, y - v.y); }

  int64_t dot(vec const& v) const { return x*v.x + y*v.y; }

  bool operator==(vec const& v) const { return x*v.y == y*v.x && dot(v) >= 0; }
  bool operator<(vec const&v) const {
    if(*this == v) return false;
    if(y > 0 && v.y > 0) {
      if((x > 0 && v.x > 0) || (x < 0 && v.x < 0)) return y * v.x < x * v.y;
      if(x <= 0 && v.x >= 0) return false;
      return true;
    } else if (y < 0 && v.y < 0) {
      if((x < 0 && v.x < 0) || (x > 0 && v.x > 0)) return y * v.x < x * v.y;
      if(x >= 0 && v.x <= 0) return false;
      return true;
    } else if (y > 0 && v.y < 0) return true;
    if (y < 0 && v.y > 0) return false;
    if (y == 0 && x > 0 && (v.y != 0 || (v.y == 0 && v.x < 0))) return true;
    if (y == 0 && x < 0 && v.y < 0) return true;
    if (v.y == 0 && v.x < 0 && y > 0) return true;
    return false;
  }
  friend std::ostream& operator<<(std::ostream &os, vec const& v) {
    return os << "(" << v.x << "," << v.y << ")";
  }
};

int const MAXN = 100;
vec p[MAXN*2];
int N;

int main() {
  std::cout << std::setprecision(15) << std::fixed;
  std::cin >> N;
  int j = 0;
  for(int i = 0; i < N; ++i) {
    int x, y; std::cin >> x >> y;
    if(x == 0 && y == 0) continue;
    p[j++] = vec(x, y);
  }
  N = j;
  if(N < 1) fin(0.0);
  std::sort(p, p+N);
  for(int i = 0; i < N; ++i) p[i+N] = p[i];
  int64_t sum2 = 0, ans2 = 0;
  vec sum;
  j = 0;
  for(int i = 0; i < N; ++i) {
    while(j < i+N) { 
      vec nv = sum + p[j];
      int64_t n2 = nv.dot(nv);
      if(n2 <= sum2) break;
      sum = nv; sum2 = n2;
      ans2 = std::max(ans2, sum2);
      ++j;
    }
    sum -= p[i];
    sum2 = sum.dot(sum);
    ans2 = std::max(ans2, sum2);
  }
  fin(std::sqrt((double)ans2));
  return 0;
}


Measured memory_bytes: 256
import sys
from math import floor
input = sys.stdin.readline

def main():
    a,b=map(int,input().split())
    u=max(floor((a+1)/0.08)+1,floor((b+1)/0.1)+1)
    f=min(floor(a/0.08),floor(b/0.1))
    x=-1
    for i in range(f,u+1):
        if floor(i*0.08)==a and floor(i*0.1)==b:
            x=i
            break
    print(x)

if __name__ == '__main__':
    main()

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

const int mod = 1000000007;


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

    vector<ll> numbers(n);
    rep(i, n) cin >> numbers[i];

    vector<ll> zero_counts(64), one_counts(64);
    for (ll l : numbers) {
        rep(i, 64) {
            bool b = (l >> i) & 1;
            if (b) one_counts[i]++;
            else zero_counts[i]++;
        }
    }

    vector<ll> contribution(64, 0);
    rep(i, 64) {
        ll rate = 1ll << i;
        ll c = zero_counts[i] * rate - one_counts[i] * rate;
        contribution[i] = c;
    }

    vector<bool> k_bits(64);

    rep(i, 64) {
        bool b = (k >> i) & 1;
        k_bits[i] = b;
    }

    vector<ll> candidate;

    auto check = [&](vector<bool> &k_bits) {
        ll x = 0;
        rep(i, 64) {
            if (!k_bits[i]) continue;
            if (contribution[i] <= 0) continue;
            ll j = (1ll << i);
            x += j;
        }

        ll ans = 0;
        for (ll l : numbers) ans += (l ^ x);

        candidate.push_back(ans);
    };


    check(k_bits);

    rep(i, 64) {
        if (!k_bits[i]) continue;
        vector<bool> k_bits2 = k_bits;
        k_bits2[i] = false;
        rep(j, i) k_bits2[j] = true;
        check(k_bits2);
    }

    cout << *max_element(candidate.begin(), candidate.end()) << endl;

}


Measured memory_bytes: 1024
//       THIS IS MY NINJA WAY
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ctime>
#include<vector>
#include<algorithm>

#define str string
#define dbl double
#define ll long long int
#define ull unsigned long long int
#define vl vector<ll> 
#define vs vector<str>
#define pll pair<ll,ll> 
#define vll vector<pll>
#define sl set<ll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define BS binary_search
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define fr(i,a,b) for(long long i=a; i<b; i++)
#define nfr(i,a,b) for(long long i=a; i<=b; i++)
#define psl pair<str,ll>
#define pls pair<ll,str>
#define pss pair<str,str>
#define lcm(a,b) (a*b)/__gcd(a,b)
#define ALL(a) a.begin(),a.end()
#define stl stack<ll>
#define coml complex<ll>
#define INF 0x3f3f3f3f3f3f3f3f
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define read(v,n) fr(i,0,n)cin>>v[i];
#define print(x) fr(i,0,x.size())cout<<x[i]<<" ";cout<<"\n";
const ll MOD = 1e9+7;
const ll N = 2e5 + 5;
using namespace std;
using namespace __gnu_pbds;
void solve(){
	ll n;
	cin>>n;
	vector<vl> v(n,vl(3));
	fr(i,0,n){
		fr(j,0,3)cin>>v[i][j];
	}
	vector<vl> dp(n,vl(3,0));
	dp[0]=v[0];
	fr(i,1,n){
		fr(j,0,3){
			fr(k,0,3){
				if(j!=k)dp[i][k]=max(dp[i][k],dp[i-1][j]+v[i][k]);
			}
		}
	}
	cout<<*max_element(ALL(dp[n-1]));
}
int main()
{
	fast
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r" , stdin);
		freopen("output.txt", "w" , stdout);
	#endif

	ll t;
	t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

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

using namespace std;

const int INF = 0x0fffffff;

string S;

void slove() {
}

int main(int argc, char* argv[]) {
    //// for cin
    //ios::sync_with_stdio(false);
    //cin.tie(0);

    cin >> S;

    int rv = 0;

    for (size_t i = 0; i < S.size() - 1; ++i) {
        if (S[i] != S[i+1]) {
            rv++;
        }
    }

    cout << rv << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int searchd(vector<int> v, int x, int y) {
  rep(i,v.size()) {
    int x_c = count(v.begin(), v.end(), x);
    int y_c = count(v.begin(), v.end(), y);
    if (x_c == y_c && x_c == 1) {
      return 1;
    }
  }
};

int main() {
  int x,y;
  cin >> x >> y;
  vector<int> v1 = {1,3,5,7,8,10,12};
  vector<int> v2 = {4,6,9,11};
  vector<int> v3 = {2};
  if (searchd(v1, x,y) == 1 || searchd(v2, x,y) == 1 || searchd(v3, x,y) == 1) {
    cout << "Yes" << "\n";
  } else {
    cout << "No" << "\n";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, x) for (ll i = 0; i < (x); i++)

using namespace std;
typedef long long int ll;
// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M>
class modint {
 public:
  int64_t a;

  explicit constexpr modint(const int64_t x = 0) noexcept :
    a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  constexpr modint pow(ll t) const {
    if (!t) return modint(1);
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};
// }}}

using mint = modint<1000000007>;
mint fact[1000000];
mint inv_fact[1000000];

mint p(ll n, ll k) {
  return fact[n] * inv_fact[n - k];
}

mint c(ll n, ll k) {
  return p(n, k) * inv_fact[k];
}

int main(void) {
  fact[0] = fact[1] = mint(1);
  inv_fact[0] = inv_fact[1] = mint(1);

  for (ll i = 2; i < 1000000; i++) fact[i] = fact[i-1] * mint(i);
  for (ll i = 2; i < 1000000; i++) inv_fact[i] = inv_fact[i-1] / mint(i);

  ll N, M;
  cin >> N >> M;
  auto C = p(M, N);
  auto E = mint(0);
  for (ll i = 1; i <= N; i++) {
    E += mint(-1).pow(i+1) * c(N,i) * p(M-i,N-i);
  }
  auto D = p(M, N) - E;
  cout << (C * D).value() << endl;
  return 0;
}


Measured memory_bytes: 19248
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}



int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll r = n / (a + b);
	ll amari = n - (a + b) * r;
	if (amari < a) {
		cout << r * a + amari;
	}
	else {
		cout << (r + 1) * a;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=220000;
int n,x,a[N];
int main(){
	scanf("%d",&n); 
	
	memset(a,0,sizeof a);
	for(int i=2;i<=n;++i){
		scanf("%d",&x);
		++a[x];
	}
	
	for(int i=1;i<=n;++i)printf("%d\n",a[i]);
	
	return 0;
} 

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

int main() {
    int n, k; cin >> n >> k;
    int p[n]; for (int i = 0; i < n; i++) cin >> p[i];
    deque<pair<int, int> > deq_max, deq_min;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        if (i >= k) {
            if (deq_max.front().second == i-k) deq_max.pop_front();
            if (deq_min.front().second == i-k) deq_min.pop_front();
            if (p[i-k] > deq_min.front().first || p[i] < deq_max.front().first) ans++;
        }
        while (!deq_max.empty() && deq_max.back().first < p[i]) deq_max.pop_back();
        deq_max.push_back({p[i], i});
        while (!deq_min.empty() && deq_min.back().first > p[i]) deq_min.pop_back();
        deq_min.push_back({p[i], i});
    }
    int cnt = 0, c = 0;
    for (int i = 1; i < n; i++) {
        if (p[i-1] < p[i]) c++; else c = 0;
        if (c == k-1) cnt++;
        // cerr << i << ' ' << c << ' ' << cnt << endl;
    }
    cout << (cnt ? ans - cnt + 1 : ans) << endl;
}


Measured memory_bytes: 2688
L, R = map(int, input().split())
lr = R-L
if lr >= 2019:
    print(0)
else:
    ans = 2018
    for i in range(L, R+1):
        for j in range(i+1, R+1):
            t = i*j % 2019
            if t < ans:
                ans = t
    print(ans)


Measured memory_bytes: 40940
h, w = gets.chomp.split.map(&:to_i)
if h == 1 || w == 1
  p 1
  exit
end
if h.even?
  p (h * w) / 2
else
  if w.even?
    p (h * w) / 2
  else
    p ((h * w) / 2.0).ceil
  end
end


Measured memory_bytes: 1788
import java.util.*;

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
        char[] ch = sc.next().toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < ch.length; i++) {
            if (ch[i] == '9') {
                sb.append('1');
            } else if (ch[i] == '1') {
                sb.append('9');
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s, t;
    while (1)
    {
        cin >> s;
        if (s == ".")
            break;
        cin >> t;
        vector<string> vs, vt;
        string tmp = "";
        rep(i, s.size())
        {
            tmp += s[i];
            if (tmp.size() > 1 && tmp[0] == '"' && tmp[tmp.size() - 1] == '"')
            {
                vs.push_back(tmp);
                tmp = "";
            }
            if (tmp[0] != '"' && s[i + 1] == '"')
            {
                vs.push_back(tmp);
                tmp = "";
            }
        }
        if (tmp != "")
            vs.push_back(tmp);
        tmp = "";
        rep(i, t.size())
        {
            tmp += t[i];
            if (tmp.size() > 1 && tmp[0] == '"' && tmp[tmp.size() - 1] == '"')
            {
                vt.push_back(tmp);
                tmp = "";
            }
            if (tmp[0] != '"' && t[i + 1] == '"')
            {
                vt.push_back(tmp);
                tmp = "";
            }
        }
        if (tmp != "")
            vt.push_back(tmp);
        // rep(i, vs.size()) cout << vs[i] << " ";
        // cout << endl;
        // rep(i, vt.size()) cout << vt[i] << " ";
        // cout << endl;
        if (vs.size() != vt.size())
        {
            cout << "DIFFERENT" << endl;
            continue;
        }
        int cnt = 0;
        rep(i, vs.size())
        {
            if (vs[i] == vt[i])
                continue;
            if (vs[i][0] == '"' && vt[i][0] == '"')
                cnt++;
            else
                cnt = 2;
        }
        if (cnt == 0)
            cout << "IDENTICAL" << endl;
        else if (cnt == 1)
            cout << "CLOSE" << endl;
        else
            cout << "DIFFERENT" << endl;
    }
}


Measured memory_bytes: 3048