akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
using namespace std;
#define N 505
int vl[N*3],n,ct,d[4][2]={-1,0,1,0,0,1,0,-1};
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long as[N][N],mx;
int main()
{
	for(int i=501;i<=10000;i++)
	{
		int fg=0;
		for(int j=2;j<=100;j++)if(i%j==0)fg=1;
		if(!fg)vl[++ct]=i;
	}
	for(int i=1;i<=500;i++)as[i][i]=vl[1]*i;
	int st=2;
	for(int i=2;i<=500;i+=2){for(int j=1;i+j<=500;j++)as[i+j][j]=vl[st]*(j+i/2),as[j][i+j]=vl[st+1]*(j+i/2);st+=2;}
	for(int i=1;i<=500;i++)
	for(int j=1;j<=500;j++)
	if((i+j)&1)
	{
		long long st=1;
		for(int s=0;s<4;s++)
		{
			int vl=as[i+d[s][0]][j+d[s][1]];
			if(vl)st=st/gcd(st,vl)*vl;
		}
		as[i][j]=st+1;
		if(mx<st)
		mx=st;
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++,printf("\n"))
	for(int j=1;j<=n;j++)
	printf("%lld ",as[i][j]);
}//

Measured memory_bytes: 4480
#include <math.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

using ll = long long;

int A, B, C;

int main() {
    cin >> A >> B >> C;
    
    if (A == B) { cout << C << endl; return 0; }
    if (B == C) { cout << A << endl; return 0; }
    if (A == C) { cout << B << endl; return 0; }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


int ans = LLONG_MIN;
char s[23][23];
int vis[23][23], dist[23][23], ways[23][23], dx[4]={-1, +1, 0, 0}, dy[4]={0, 0, +1, -1};
int bfs(int x, int y, int n, int m){
    memset(vis, 0, sizeof(vis));
    queue<pair<int, int> > q;
    q.push({x, y});
    ways[x][y] = 1;
    vis[x][y] = 1;
    dist[x][y] = 0;
    int mx = 0;
    while(!q.empty()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for(int dir = 0; dir < 4; dir++){
            int nx = x + dx[dir], ny = y + dy[dir];
            if(nx < 1 || ny < 1 || nx > n || ny > m || s[nx][ny] == '#')continue;
            if(!vis[nx][ny]){
                dist[nx][ny] = dist[x][y] + 1;
                mx = max(mx, dist[nx][ny]);
                vis[nx][ny] = 1;
                ways[nx][ny] += ways[x][y];
                q.push({nx, ny});
            }
            else if(dist[x][y] + 1 == dist[nx][ny])ways[nx][ny] += ways[x][y];
        }
    }
    return mx;
}


void solve(){
    int n, m;
    cin>>n>>m;
    f(i,23)f(j,23)s[i][j] = '#';
    for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++)cin>>s[i][j];
    for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++){
        if(s[i][j] == '.')ans = max(ans,bfs(i,j,n,m));
    }
    cout<<ans;
}


int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define max(a,b) (a > b ? a : b)
#define min(a,b) (a < b ? a : b)

int main(void) {
	int a1, a2, a3;
	
	scanf("%d %d %d", &a1, &a2, &a3);
	printf("%d\n", max(a1,max(a2,a3))-min(a1,min(a2,a3)));
	
	return 0;
}

Measured memory_bytes: 128
n = int(input())

a = []
for i in range(n):
    a.append(int(input()))

check = [1]*n
p = 1
ans = 1
total = 0
while check[p-1] == 1:
    total += 1
    check[p-1] = 0
    if a[p-1] == 2:
        ans = 0
        break
    
    p = a[p-1]


if ans == 1:
    total = -1
print(total)

Measured memory_bytes: 7852
#include <iostream>
int main()
{
	int h1,h2,m1,m2,s1,s2;
	while(std::cin>>h1>>m1>>s1>>h2>>m2>>s2){
		int sum = (h2*3600+m2*60+s2)-(h1*3600+m1*60+s1);
		printf("%d %d %d\n",sum/3600,(sum%3600)/60,sum%60);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
char str[200005];
int dp[200005];
int Next[200005][30];
int main()
{
	while(scanf("%s",str)!=EOF)
	{
	
	int len=strlen(str);
	for(int i=0;i<26;i++)//以Len结尾的i出现的位置 
		Next[len][i]=len;
	for(int i=len-1;i>=0;i--)
	{
		for(int j=0;j<26;j++)
			Next[i][j]=((str[i]==(j+'a'))?i:Next[i+1][j]);
	}
	dp[len]=1;
	for(int i=len-1;i>=0;i--)
	{
		dp[i] = dp[Next[i][0]+1]+1;
		for(int j=1;j<26;j++)
			dp[i] = min (dp[i], dp[Next[i][j]+1]+1);
	}
	int flag=0;
	while(dp[flag])
	{
		for(int i=0;i<26;i++)
		{
			if(dp[flag]==dp[Next[flag][i]+1]+1)
			{
				printf("%c",'a'+i);
				flag=Next[flag][i]+1;
				break;
			}
		}
	}
	printf("\n");
}
	return 0;

}

Measured memory_bytes: 24704
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iostream>

using namespace std;

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

	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << N - K << endl;
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define hoise cerr<<"hoise - "<<__LINE__<<"\n";
#define tham getchar();
#define FASTIO ios::sync_with_stdio(false);cin.tie(nullptr);

using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
using vl = vector <ll>;

const int MXN = (int)2e5+6;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }


template <typename T> using orderedSet = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using orderedSet1 = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*--------------------------------------------------------------------------------------------------------------------------*/




int main(){
	FASTIO
	double r;
	cin >> r;
	cout << fixed << setprecision(12) << 2.0 * PI * r << endl;
	
    return 0;
}

/*

*/


Measured memory_bytes: 3804
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_B

??°?????????

?????????????????°???????????????????¨??????????????????°?????????????????????????????????
"""

if __name__ == '__main__':
    while True:
        # ??°?????????????????\???(??????????????????)
        raw_input = input()

        if raw_input == '0':
            break

        # ???????????°??????????¨??????????????????????
        total = sum(map(int, raw_input))
        print(total)

Measured memory_bytes: 7632
#include <stdio.h>
 
int main (){
  int x;
  int y;
  while(1){
  scanf("%d %d", &x,&y);
  if(x < y){
    printf("%d %d\n",x , y);
  }else{
    if(x == 0&& y ==0)break;
    printf("%d %d\n", y,x);
   }
  }
  return 0;
     
}

Measured memory_bytes: 596
#include <stdio.h>

double sqrt(double b) {
    //f(x)=x^2-b
    //f'(x)=2x
    //tangent line: y-f(a)=f'(a)(x-a)
    //zero of tangent line: x=a-f(a)/f'(a)
    double x = 1, xnext;
    while(1) {
        xnext = x-(x*x-b)/(2*x);
        if(x-xnext <= 0.000001 && x-xnext >= -0.000001) {
            break;
        }
        x = xnext;
    }
    return x;
}

bool prime(int x) {
    if (x==2) {
        return true;
    }
    if (x%2==0 ) {
        return false;
    }
    for (int i=2;i<=sqrt(x);i++) {
        if (x%i==0){
            return false;
        }
    }
    return true;
}


int main() {
    int n, x, cnt=0;
    scanf("%d", &n);
    for (int i=0;i<n;i++){
        scanf("%d", &x);
        if (prime(x)) {
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}



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

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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; }

ll h1,m1,h2,m2,k,s,e;
int main() {
    INIT();

    cin >> h1>>m1>>h2>>m2>>k;

    if(h1 < h2 || (h1 == h2 && m1 < m2)) {
        s = h1 * 60 + m1;
        e = h2 * 60 + m2;
    } else {
        s = h1 * 60 + m1;
        e = (h2 + 24) * 60 + m2;
    }

    cout << fixed << e - s - k;
}

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

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;
    int ans = 2 * n;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == b[i] && b[i] == c[i]) ans -= 2;
        else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) ans--;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll n;
ll sum[500];
ll dp[500][500];
vl a;
int main(){
    cin>>n;
    a.assign(n,0);
    memset(sum,0,sizeof(sum));
    rep(i,500){
        rep(j,500){
            dp[i][j]=LINF;
        }
    }
    rep(i,n)cin>>a[i];
    rep(i,500)dp[i][i]=0;
    rep(i,n){
        sum[i+1]=sum[i]+a[i];
    }
    for(int len=1;len<=n-1;len++){
        rep(i,n){
            if(i+len>=n)continue;
            int j=i+len;
            for(int l=i;l<j;l++){
                chmin(dp[i][j],dp[i][l]+sum[l+1]-sum[i]+dp[l+1][j]+sum[j+1]-sum[l+1]);    
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 5560
from collections import Counter
def CaC(S,cp):
    s1 = S[:cp]
    s2 = S[cp:]
    
    c1 = Counter(s1)
    c2 = Counter(s2)
    
    count = 0
    if len(c1)<len(c2):
        for key in c1:
            if key in c2:
                count+=1
    else:
        for key in c2:
            if key in c1:
                count+=1
    return count
    
N = int(input())
S = input()

Max = 0
for i in range(1,N):
    m = CaC(S,i)
    if m>Max:
        Max=m
print(Max)

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

int main() {
  int K,S,count;
  cin >> K >> S;
  count = 0;

  for(int X = 0; X <= K; X++){
    for(int Y = 0; Y <= K; Y++){
      if (0 <= S-X-Y && S-X-Y <= K){
        count++;
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut, SubAssign, Range};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet, HashMap};
use std::fmt::{Display, Formatter, Error};

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}

macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn main() {
    let_all!(n: usize);
    let mut count = vec![0; 200100];
    for _ in 0..n {
        let_all!(a: usize, b: usize);
        count[a + b] += 1;
    }
    for i in 0 .. count.len() {
        if count[i] >= 2 {
            count[i + 1] += count[i] / 2;
            count[i] %= 2;
        }
        if count[i] > 0 {
            println!("{} 0", i);
        }
    }
}



Measured memory_bytes: 5056
n=int(input())
k=[[0,0] for i in range(n)]
for i in range(n):
    a,l=map(int,input().split())
    left=a-l
    right=a+l
    k[i][0]=left
    k[i][1]=right
k.sort(key=lambda x:x[1])
tmp=k[0][1]
ans=1
for i in range(n):
    if k[i][0]>=tmp:
        tmp=k[i][1]
        ans+=1
print(ans)

Measured memory_bytes: 58272
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll q,a,b,cnt,p,l;
int main()
{
	cin>>q;
	while(q--){
		cin>>a>>b;
		p=a*b;
		l=sqrt(p);
		if(l*(l+1)<p) cnt=2*(l-1)+1;
		else cnt=2*(l-1);
		if(l*l==p&&a!=b) cnt--;
		if(a*b==4) cnt=1;
		cout<<cnt<<endl;
	}
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import math
import itertools

# 入力
#N = int(input())
#S = str(input())
M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())

if M1+1 == M2 :
  print (1)
else :
  print (0)


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll a,b;
  cin >> a >> b;
  ll ans = a+b;
  CHMAX(ans,a-b);
  CHMAX(ans,a*b);
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,k;
  cin >> n >> k;
  int ans = 0;
  rep(i,n){
    int x;
    cin >> x;
    ans += min(2*abs(x),2*abs(x-k));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
float PHI = 1.6180339;
//const float  PI_F=3.14159265358979f;
#define MAX 100000 
#define endl "\n"    
//typedef long long float;
#define int long long
//#define float unsigned long long

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    int cnt=1;
    char prev=s[0];
    for(int i=1;i<n;i++)
    {
        if(s[i]!=prev)
        ++cnt;
        prev=s[i];
    }
    cout<<cnt<<endl;

}

Measured memory_bytes: 512
while True:
    
    a,op,b = input().split()
    a = int(a)
    b  = int(b)
    
    if op == "0":
        exit(0)
    elif op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)
    else:
        break
    


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll a,v,b,w,t; cin >> a >> v >> b >> w >> t;
  ll dis_ab = abs(a - b);
  if(v <= w) {
    cout << "NO" << endl;
    return 0;
  }
  
  ll ver = abs(v - w);
  ll ver_t = ver * t;

  if(dis_ab <= ver_t){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  
}



Measured memory_bytes: 3596
import Control.Monad
import Data.List

main = do
    [n, x] <- map read <$> words <$> getLine
    xs     <- map read <$> words <$> getLine
    putStrLn $ show $ solve x xs

solve :: Int -> [Int] -> Int
solve x xs = foldl1 gcd $ map (abs . (-) x) xs

Measured memory_bytes: 36220
#include <cstdio>
int main(){
	long long int t1, t2, a1, a2, b1, b2;
	scanf("%lld %lld %lld %lld %lld %lld", &t1, &t2, &a1, &a2, &b1, &b2);
	if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2){
		printf("infinity\n");
		return 0;
	}else if (a1 > b1 && a2 > b2){
		printf("0\n");
		return 0;
	}else if (a1 < b1 && a2 < b2){
		printf("0\n");
		return 0;
	}
	long long int l = 0, r = 1000000000000000;
	while (l < r){
		long long int m = l + (r - l) / 2;
		long long int as = m * (t1 * a1 + t2 * a2);
		long long int bs = m * (t1 * b1 + t2 * b2);
		long long int am = as + t1 * a1, bm = bs + t1 * b1;
		long long int ae = am + t2 * a2, be = bm + t2 * b2;
		int ip = 0;
		if ((as < bs && am > bm) || (as > bs && am < bm)){
			ip++;
		}
		if ((am < bm && ae > be) || (am > bm && ae < be)){
			ip++;
		}
		if (as == bs){
			ip++;
		}
		if (am == bm){
			ip++;
		}
		if (ae == be){
			ip++;
		}
		if (ip == 2){
			l = m + 1;
		}else{
			r = m;
		}
	}
	long long int w1 = l;
	l = 0, r = 1000000000000000;
	while (l < r){
		long long int m = l + (r - l) / 2;
		long long int as = m * (t1 * a1 + t2 * a2);
		long long int bs = m * (t1 * b1 + t2 * b2);
		long long int am = as + t1 * a1, bm = bs + t1 * b1;
		long long int ae = am + t2 * a2, be = bm + t2 * b2;
		int ip = 0;
		if ((as < bs && am > bm) || (as > bs && am < bm)){
			ip++;
		}
		if ((am < bm && ae > be) || (am > bm && ae < be)){
			ip++;
		}
		if (as == bs){
			ip++;
		}
		if (am == bm){
			ip++;
		}
		if (ae == be){
			ip++;
		}
		if (ip != 0){
			l = m + 1;
		}else{
			r = m;
		}
	}
	long long int w2 = l;
	printf("%lld\n", w1 * 2 + w2 - w1 - 1);
}

Measured memory_bytes: 128
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)

int main() {
    int n;
    cin >> n;
    vector<int> a(n - 1);
    rep(i, n - 1) {
        cin >> a.at(i);
        a.at(i)--; // 0-index
    }
    vector<int> s(n, 0);
    rep(i, n - 1) {
        s.at(a.at(i))++;
    }
    rep(i, n) {
        cout << s.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 4820
sx, sy, tx, ty = map(int, input().split())

ans = ''

dx = tx - sx
dy = ty - sy

ans += 'R' * dx + 'U' * dy + 'L' * dx + 'D' * dy
ans += 'D' + 'R' * (dx + 1) + 'U' * (dy + 1) + 'L'
ans += 'U' + 'L' * (dx + 1) + 'D' * (dy + 1) + 'R'

print(ans)


Measured memory_bytes: 3060
N = int(input())
D = list(map(int, input().split()))
map_D = dict()
map_D[0] = 1
for d in D:
    if d in map_D:
        map_D[d] += 1
    else:
        map_D[d] = 1

new_D = []
is_zero = False
for (k, v) in map_D.items():
    
    if ((k == 0 or k == 12) and v >= 2) and v >= 3:
        is_zero = True
        break
    else:
        for i in range(v):
            new_D.append(k)

new_D.sort()
final_D = []
for i in range(len(new_D)):
    if i % 2 == 0:
        final_D.append(new_D[i])
    else:
        final_D.append(24 - new_D[i])

ans = 100
for i in range(len(final_D) - 1):
    for j in range(i + 1, len(final_D)):
        ans = min(ans, min(24 - abs(final_D[i] - final_D[j]), abs(final_D[i] - final_D[j])))

if is_zero:
    print(0)
else:
    print(ans)

Measured memory_bytes: 9256
#include <stdio.h>
#define POINT 41

int P[POINT], I[POINT], Po[POINT];
int n, now = 0, s = 0;

void Rec(int, int);

void Rec(int l, int r) {
    int c,m;
    
    if(l >= r) {
        return;
    }
    c = P[now++];
    m = Find(c);
    Rec(l, m);
    Rec(m + 1, r);
    Po[s++] = c;
}

int Find(int c) {
    int i;
    
    //接点番号が一致したIndexを返す
    for(i = 0 ; i < n ; i++) {
        if(c == I[i]) {
            return i;
        }
    }
    return 0;
}

int main(void){
    int i;
    
    scanf("%d",&n);
    
    //preoder include
    for(i = 0 ; i < n ; i++) {
        scanf("%d",&P[i]);
    }
    
    //inoder include
    for(i = 0 ; i < n ; i++) {
        scanf("%d",&I[i]);
    }
    
    Rec(0,n);
    
    for(i = 0 ; i < n-1 ; i++) {
        printf("%d ",Po[i]);
    }
    printf("%d\n", Po[n-1]);
    return 0;
}



Measured memory_bytes: 2100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;

const int MaxN = 50;
int n;
LL a[MaxN + 5];
LL b[MaxN + 5];
LL pred[MaxN + 5];
LL succ[MaxN + 5];

int main()
{
	while (~scanf("%d", &n)) {
		for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
		LL cnt = 0;
		while (true) {
			sort(a + 1, a + n + 1);
			if (a[n] < n) break;
			for (int i = 1; i <= n; i++) b[i] = a[i] / n;
			pred[0] = succ[n + 1] = 0;
			for (int i = 1; i <= n; i++) pred[i] = pred[i - 1] + b[i];
			for (int i = n; i >= 1; i--) succ[i] = succ[i + 1] + b[i];
			for (int i = 1; i <= n; i++) a[i] = a[i] % n + pred[i - 1] + succ[i + 1];
			cnt += pred[n];
		}
		printf("%lld\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A_list = list(map(int, input().split()))
M = max(A_list)+1
cnt = [0 for _ in range(M)]

for i in A_list:
    if cnt[i] != 0:
        cnt[i] = 2
        continue
    for j in range(i, M, i): cnt[j] += 1

ans = 0
for k in A_list:
    if cnt[k] == 1: ans += 1
print(ans)


Measured memory_bytes: 32376
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();
		int Y = scan.nextInt();
		int tmp = -1;
		String result="No";
		scan.close();

		for(int i = 0;i<=X;i++) {
			tmp = 2*i + 4*(X-i);
			if(Y==tmp) {
				result = "Yes";
			}
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 35816
#A, B, C からなる長さ N の文字列 S と、1 以上 N 以下の整数 K が与えられます。 
#文字列 S の K 文字目を小文字に書き換え、新しくできた S を出力してください。
n, k = map(int, input().split())
s = input()
print(s[:k - 1] + s[k - 1].lower() + s[k:])#スライス　a[始まりの位置: 終わりの位置: スライスの増分]
#k-1番目までをprint, k-1番目を小文字に変換，　k番目から最後まで出力

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

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

  int x=-1,y=-1,z=-1;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(10000*i+5000*j+1000*(n-i-j)==Y&&n-i-j>=0){
        x=i;y=j;z=n-i-j;
      }
    }
  }
  cout << x <<" "<< y << " "<< z <<endl;
  return 0;
}

Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//assert(q==w) если q!=w --> runtime error
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int> > matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1,x;i<=n;i++){
        cin>>x;
        if(x%2==0 && (x%3!=0 && x%5!=0)){
            cout<<"DENIED";
            return 0;
        }
    }
    cout<<"APPROVED";
	exit(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

ll ex_euclid(ll a, ll b, ll &x, ll &y){
  if (b == 0){
    x = 1;
    y = 0;
    return a;
  }
  ll d = ex_euclid(b, a%b, y, x);
  y -= a/b * x;
  return d;
}

ll modinv(ll a, ll p){
  ll x, y, d;
  d = ex_euclid(a, p, x, y);
  assert(d == 1);
  return ((x % MOD) + MOD) % MOD;
}

const int maxN = 500001;
ll fac[maxN], inv[maxN], finv[maxN];

// O(N) precomputation
void modnCk_init(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i=2; i<maxN; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = modinv(i, MOD); // O(logN)
//    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD; // O(1)
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

// O(K)
ll modnCk_bigN(int N, int K){
  if (N < K) return 0;
  if (K == 0) return 1;
  ll ret = N;
  inv[1] = 1;
  for (int k=2; k<=K; k++){
    inv[k] = MOD - inv[MOD%k] * (MOD/k) % MOD;
    ret = ret * ((N-k+1) * inv[k] % MOD) % MOD;
  }
  return ret;
}

// O(1) with O(N) precomputation
ll modnCk(int n, int k){
  if (n < k) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(int argc, const char * argv[]) {
  int N, M, K;
  cin >> N >> M >> K;
  
  modnCk_init();
  ll c = modnCk(N*M-2, K-2);
  ll ans = 0;
  for (int d=1; d<N; d++)
    ans = (ans + ((c * d % MOD) * (M * M % MOD) % MOD) * (N-d) % MOD) % MOD;
  
  for (int d=1; d<M; d++)
    ans = (ans + ((c * d % MOD) * (N * N % MOD) % MOD) * (M-d) % MOD) % MOD;
  
  cout << ans << endl;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin >> a[i];
  long long sumodd = 0;
  long long sumeven = 0;
  long long anseven = 0;
  long long ansodd = 0;
  for (int i=0; i<n; i++){
    sumodd += a[i];
    sumeven += a[i];
    if (i%2 == 0){
      if (sumodd <= 0){
        ansodd -= sumodd - 1;
        sumodd = 1;
      }
      if (sumeven >= 0){
        anseven += sumeven + 1;
        sumeven = -1;
      }
    }else{
      if (sumeven <= 0){
        anseven -= sumeven - 1;
        sumeven = 1;
      }
      if (sumodd >= 0){
        ansodd += sumodd + 1;
        sumodd = -1;
      }
    }
  }
  cout << min(ansodd,anseven) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <array>

int main() {
  std::array<int, 9> g;
  for(auto &gi: g)
    std::cin >> gi;
  int d121 = g[0] - g[3];
  int d122 = g[1] - g[4];
  int d123 = g[2] - g[5];
  int d131 = g[0] - g[6];
  int d132 = g[1] - g[7];
  int d133 = g[2] - g[8];
  if (d121 == d122 && d121 == d123 &&
      d131 == d132 && d131 == d133)
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No"  << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int a[200000];
int s[20];

bool ok(int x)
{
    for (int i = 0; i < 20; ++i)
        if ((a[x] & (1 << i)) && s[i])
            return false;
    return true;
}

void add(int x)
{
    for (int i = 0; i < 20; ++i)
        if (a[x] & (1 << i))
            s[i]++;
}

void rem(int x)
{
    for (int i = 0; i < 20; ++i)
        if (a[x] & (1 << i))
            s[i]--;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int p = 0, q = 0;
    ll sol = 0;
    add(p);
    while (q < n)
    {
        while (q + 1 < n && ok(q + 1))
            add(q + 1), q++;
        //cout << p _ q << endl;
        sol += q - p + 1;
        rem(p); p++;
        if (q < p)
        {
            add(p);
            q++;
        }
    }
    cout << sol;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

class RangeArray {
public:
	map<ll,ll> V;
	void clear(){ V.clear();V[-1]=V[(1<<30)+1]=-1; }
	RangeArray() { clear(); }

	ll operator[](ll v) { return (--V.lower_bound(v+1))->second; }
	
	void set_range(ll L,ll R,ll v) { // A[L..(R-1)]=v
		if(L>=R) return;
		auto it=V.lower_bound(R+1);
		ll t=(--it)->second; V[R]=t;
		it=V.lower_bound(R); it--;
		while(it->first>=L) it=V.erase(it), it--;
		V[L]=v;
	}
};

int N;
ll K;
ll A[101010],B[101010];
ll X[101010][2];
ll S[101010];

RangeArray ra;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	K*=2;
	FOR(i,N) {
		cin>>A[i]>>B[i];
		A[i]*=2;
		if(B[i]==1 && A[i]>K/2) return _P("-1\n");
		S[i+1]=S[i]+A[i];
	}
	
	FOR(i,2) {
		ra.clear();
		for(x=1;x<=N;x++) {
			int v=ra[S[x]%(K/2)];
			if(v==-1) {
				X[x][i]=2*S[x];
			}
			else {
				ll d=S[x]-S[v];
				X[x][i]=X[v][i]+(d+K/2-1)/(K/2)*(K/2)*2;
			}
			if(B[x-1]==1) {
				ll L=S[x-1]+1,R=S[x]+1;
				if(L+(K/2)<=R) ra.set_range(0,(K/2),x);
				else {
					L%=K/2;
					R%=K/2;
					if(L<R) {
						ra.set_range(L,R,x);
					}
					else {
						ra.set_range(L,K/2,x);
						ra.set_range(0,R,x);
					}
				}
			}
		}
		FOR(x,N+1) S[x]=S[N]-S[x];
		reverse(B,B+N);
		reverse(S,S+N+1);
	}
	
	ll ret=1LL<<60;
	FOR(i,N+1) ret=min(ret,X[i][0]+X[N-i][1]);
	cout<<ret/2<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 10368
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int x = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == 'I')
                x++;
            else
                x--;
            if (max < x)
                max = x;
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc077/tasks/abc077_b

int main() {

    int N; cin >> N;
    ll prev = 1;
    REP(i, 100005) {
        if (i*i > N) {
            cout << prev << "\n";
            return 0;
        }
        prev = i*i;
    }

    return 0;
}


Measured memory_bytes: 256
w, h, n = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
xy = []
a = []
for i in range(n):
    xy.append([li[i][0], li[i][1]])
    a.append(li[i][2])

left, right = [0, 0], [w, h]

for i in range(n):
    if a[i] == 1:
        if left[0] < xy[i][0]:
            left[0] = xy[i][0]
    elif a[i] == 2:
        if right[0] > xy[i][0]:
            right[0] = xy[i][0]
    elif a[i] == 3:
        if left[1] < xy[i][1]:
            left[1] = xy[i][1]
    else:
        if right[1] > xy[i][1]:
            right[1] = xy[i][1]

if left[0] >= right[0] or left[1] >= right[1]:
    ans = 0
else:
    ans = (right[0]-left[0]) * (right[1]-left[1])
print(str(ans))


Measured memory_bytes: 38256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int a0, L;
	while(cin >> a0 >> L, a0|L) {
		string a = toStr(a0);
		FOR(i, a.size(), L-1) {
			a.push_back('0');
		}

		int step = 1;
		vi num;
		num.push_back(a0);

		while(true) {
			sort(RALL(a));
			string smax = a;
			sort(ALL(a));
			string smin = a;
			int tmp = toInt(smax)-toInt(smin);

			REP(i, step) {
				if(num[i] == tmp) {
					cout << i << " " << num[i] << " " << step-i << endl;
					goto next;
				}
			}

			num.push_back(tmp);

			a = toStr(tmp);
			FOR(i, a.size(), L-1) {
				a.push_back('0');
			}
			step++;
		}

		next:;
	}

	return 0;
}

Measured memory_bytes: 1252
str = input()
for _ in range(int(input())):
  odr = input().split()
  a = int(odr[1])
  b = int(odr[2]) + 1
  if odr[0] == 'replace':
    str = str[:a] + odr[3] + str[b:]
  elif odr[0] == 'reverse':
    str = str[:a] + str[a:b][::-1] + str[b:]
  else:
    print(str[a:b])



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;

	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	if(a>b) swap(a,b);

	cout<< a <<" "<< b <<" "<< c << endl;
	return 0;
}


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

int main(){
  
  string s; //, ans;
  cin >> s;
  int gnum = 0, pnum = 0, cnt = 0;
  
  for (int i = 0; i < s.length(); i++) {
    if (s.at(i) == 'g') {
      if (pnum == gnum) {
        //ans.insert(i,'g');
        gnum++;
      } else {
        //ans.insert(i,'p');
        pnum++;
        cnt++;
      }
    } else {
      if (pnum == gnum) {
        //ans.insert(i,'g');
        gnum++;
        cnt--;
      } else {
        //ans.insert(i,'p');
        pnum++;
      }
    }
    
    /*if (pnum == gnum) ans.insert(i, 'g');
    else {
      if (s.at(i) == 'g') ans.insert('p');
      else
    }*/
  }
  
  cout << cnt;
  
  return 0;
}

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

int main(int argc, const char * argv[]) {
    int a = 0;
    cin >> a;
    
    if (a == 1) {
        printf("Hello World");
    } else {
        int b = 0;
        int c = 0;
        cin >> b >> c;
        cout << b + c;
    }
    
    return 0;
}


Measured memory_bytes: 256
ran = int(input())
list_a = [int(a) for a in input().split()]
list_a.reverse()
for i in range(int(ran)):
    if not i == ran-1:
        print('{} '.format(list_a[int(i)]), end = '')
    else:
        print('{}'.format(list_a[int(i)]))


Measured memory_bytes: 5612
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#pragma gcc target ("avx2")
#pragma gcc optimization ("Ofast")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int d;
	scanf("%d", &d);
	vector<ll> c(26);
	rep(i, 26)scanf("%lld", &c[i]);
	vector<vector<ll>> s(d, vector<ll>(26));
	rep(i, d)rep(j, 26)scanf("%lld", &s[i][j]);
	vector<ll> last(26);
	ll ans = 0, tmp;
	int idx = 1;

	rep(i, d) {
		rep(k, 26) {
			int t = k + 1;
			tmp = 0;
			tmp += s[i][t - 1];
			rep(j, 26) if(j != k) ans -= (c[j] * (i + 1 - last[j]));
			if (ans < tmp) idx = k + 1, ans = tmp;
		}
		last[idx - 1] = i + 1;
		printf("%d\n", idx);
	}

	Please AC;
}

Measured memory_bytes: 3904
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

def bfs(A):
    d = [[0,1],[0,-1],[1,0],[-1,0]]
    used = [[False]*W for _ in range(H)]
    q = []
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                used[i][j] = True
                q.append([i,j])
    c = 0
    while q:
        q1 = []
        count_flag = False
        for place in q:
            for move in d:
                new_x, new_y = place[0]+move[0], place[1]+move[1]
                if 0<=new_x<H and 0<=new_y<W:
                    if used[new_x][new_y]==False:
                        used[new_x][new_y] = True
                        q1.append([new_x,new_y])
                        count_flag = True
        q = q1
        if count_flag:
            c += 1
    return c

H,W = II()
A = [list(map(str, input())) for _ in range(H)]
print(bfs(A))

Measured memory_bytes: 179492
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int main() {
	string S;
	cin >> S;
	cout << S.front() << S.size() - 2 << S.back() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int n;ll s,S;
const int MAX_N=100050;

vll bita(MAX_N),bitb(MAX_N);
vll a(MAX_N);

void add(vll& b,int i,ll x){
    while(i<=n){
        b[i]+=x;
        i+=i&(-i);
    }
}

void init(){
    rep(i,n)add(bita,i+1,a[i]);
}

ll sum(vll& b,int i){
    s=(ll)0;
    while(i>0){
        s+=b[i];
        i-=i&(-i);
    }
    return s;
}

//[l,r)にxを加算
//関数の呼び出しは時間がかかるので遅かったら配列を渡すとかの工夫が必要
void addquery(int l,int r,ll x){
    add(bita,l,-x*(ll)(l-1));
    add(bitb,l,x);
    add(bita,r+1,x*(ll)r);
    add(bitb,r+1,-x);
}

//[l,r)の和
//関数の呼び出しは時間がかかるので遅かったら配列を渡すとかの工夫が必要
ll sumquery(int l,int r){
    S=(ll)0;
    S+=sum(bita,r)+sum(bitb,r)*(ll)r;
    S-=sum(bita,l-1)+sum(bitb,l-1)*(ll)(l-1);
    return S;
}

int main(){
    int q;cin>>n>>q;
    init();
    vll ans;
    int c,s,t;ll x;
    rep(i,q){
        cin>>c>>s>>t;
        if(c==0){
            cin>>x;
            addquery(s,t,x);
        }
        else ans.push_back(sumquery(s,t));
    }
    rep(i,ans.size())cout<<ans[i]<<endl;
}


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

int main() {
  string s;
  cin >> s;
  if ((s.at(0) =='7') || (s.at(1) == '7') || (s.at(2) == '7'))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

void dfs(int here, vector<vector<int>> &edges, vector<int> &seen, int ignore)
{
    seen[here] = 1;

    for (int i = 0; i < edges.size(); i++)
    {
        if (i == ignore)
            continue;
        int next = -1;
        if (edges[i][0] == here)
            next = edges[i][1];
        if (edges[i][1] == here)
            next = edges[i][0];
        if (next >= 0 && seen[next] == 0)
        {
            dfs(next, edges, seen, ignore);
        }
    }
}

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

    int bridges = 0;

    int n, m;
    cin >> n >> m;
    vector<vector<int>> edges(m, vector<int>(2));
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        edges[i] = {a - 1, b - 1};
    }

    for (int i = 0; i < m; i++)
    {
        vector<int> seen(n, 0);
        dfs(0, edges, seen, i);
        bool seen_entire = true;
        for (int i = 0; i < n; i++)
        {
            if (seen[i] <= 0)
            {
                seen_entire = false;
                break;
            }
        }
        if (!seen_entire)
            bridges++;
    }

    cout << bridges << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
 
int main(){
    int n;
    long long X=0,x=0,ans=1000000000000000000LL;
    cin >> n;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        X += a[i];
    }
    for(int i=0;i<n;i++){
        x+=a[i];
        if(i+1<n) ans = min(ans,abs(X-2*x));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792