akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;
ll L;
ll A[200000],a[200000],b[200000],c[200000],d[200000],x[200000],y[2000000],z[2000000],w[2000000],tmp[200000];
ll q(ll i){
  if(A[i]==0) return 2;
  return (A[i]%2LL);
}

void solve(){
  a[0] = q(0);
  b[0] = 0xffffffffffff;
  c[0] = (A[0]+1)%2;
  d[0] = A[0];
  rep1(i,L-1){
    a[i] = min(a[i-1], d[i-1]) + q(i);
    b[i] = min(b[i-1], a[i-1]) + (A[i]+1LL)%2LL;
    c[i] = min(c[i-1], d[i-1]) + (A[i]+1LL)%2LL;
    d[i] = d[i-1] + A[i];
  }
}
ll ans;
int main()
{
  cin>>L;
  if(L==1){
    puts("0");
    return 0;
  }
  rep(i,L){
    cin>>A[i];
  }
  solve();
  rep(i,L){
    tmp[i]=A[L-1-i];
    x[i]=a[i];
    y[i]=b[i];
    z[i]=c[i];
    w[i]=d[i];
  }
  rep(i,L) A[i]=tmp[i];
  solve();
  // rep(i, L ) cout<<a[i]<<endl;
  // puts("as");
  // cout<<a[L-1]<<endl<<b[L-1]<<endl?<<c[L-1]<<endl<<d[L-1]<<endl;
  ans = min(a[L-1], min(b[L-1] , min(c[L-1] , min(d[L-1], min( x[L-1], min(y[L-1], min(z[L-1], w[L-1])))))));
  rep(i,L-1){
    ans = min(ans, a[i]+w[L-2-i]);
    ans = min(ans, c[i]+w[L-2-i]);
    ans = min(ans, d[i]+w[L-2-i]);
    ans = min(ans, b[i]+w[L-2-i]);
    ans = min(ans, a[i]+z[L-2-i]);
    ans = min(ans, c[i]+x[L-2-i]);
    ans = min(ans, a[i]+y[L-2-i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 21248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h, w;
 
  // 変数aで入力を受け取る
  cin >> h >> w;
 
  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;
  
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    cout << "#";
    cout << s;
    cout << "#" << endl;
  }
  
  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
moji = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
memo = {}
for i in range(len(moji)):
    memo.setdefault(moji[i],i)
#print(memo)
n = int(input())
s = str(input())
ans = ''
for i in range(len(s)):
    ans += moji[(memo[s[i]]+n)%26]
print(ans)

Measured memory_bytes: 9204
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    n: i64,
    x: i64,
    t: i64,
    }


    let mut cnt = 0;
    let mut max =0;
    for i in 0..2000 {
      cnt += x;
      max += t;
      if cnt >=n {
        break;
      }
    }

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


Measured memory_bytes: 2132
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int nx[4] = {1,0,-1,0};
int ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int c = 0;
    rep(i,n){
        if (s[i] == 'E') c++;
    }
    int ans = c;
    rep(i,n){
        if (s[i] == 'E') c--;
        chmin(ans,c);
        if (s[i] == 'W') c++;
    }
    PRINT(ans);
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int main()
{
    int n,k;
    long long ans=99999999999999;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    for(int i=0;i<=(n-k);i++)
    {
        long long s=((long long)a[i+k-1]-a[i]+(long long)abs(0-a[i]));
        ans=min(ans,s);
        s=((long long)a[i+k-1]-a[i]+(long long)abs(0-a[i+k-1]));
        ans=min(ans,s);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 640
a = input()
b = 0
if a == "SAT":
    b = 1
if a == "SUN":
    b = 7
if a == "MON":
    b = 6
if a == "TUE":
    b = 5
if a == "WED":
    b = 4
if a == "THU":
    b = 3
if a == "FRI":
    b = 2
print(b)

Measured memory_bytes: 2940
#include<iostream>
#include<array>
#include<vector>
#include<string>
#define f(i,a,b) for(i=a;i<b;i++)
using namespace std;
int main()
{
	int i;
	string a, b;
	cin >> a >> b;
	string p;
		string q;
	f(i, 0, stoi(a))
	{
		q += b;
	}
	f(i, 0, stoi(b))
	{
		p += a;
	}
//	cout << p << q << endl;
	int x = p.compare(q);
	if (x == 0)
		cout << p;
	else if (x > 0)
		cout << q;
	else
		cout << p;
/*	if (strcmp(p,q)==0)
		cout << p;
	else if (strcmp(p,q)<0)
		cout << p;
	else
		cout << q;*/
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 200005, M = N << 2, G = 5, mo = 924844033 ; 
using namespace std ;

int n, e, ter[N << 1], nxt[N << 1], lnk[N], sz[N], inv[N], fac[N], A[N] ;
int f[N], a[2][M], rev[M] ;

void add(int x, int y) {
	ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e ;
}

void dfs(int p, int las) {
	sz[p] = 1 ;
	for (int i = lnk[p]; i; i = nxt[i]) if (ter[i] != las) {
		dfs(ter[i], p) ;
		sz[p] += sz[ter[i]] ;
	}
}

inline int mul(int a, int b) {
	int ans = 1, w = a % mo ;
	for ( ; b; b /= 2) {
		if (b & 1) ans = (ll) ans * w % mo ;
		w = (ll) w * w % mo ;
	}
	return ans ;
}

void dft(int x, int fl) {
	int u, v, w, wn, invG = mul(G, mo - 2) ;
	rep(i, 0, n - 1) if (i < rev[i]) swap(a[x][i], a[x][rev[i]]) ;
	for (int i = 2; i <= n ; i <<= 1) {
		if (fl) wn = mul(invG, (mo - 1) / i) ; else wn = mul(G, (mo - 1) / i) ;
		for (int j = 0; j < n; j += i) 
		  for (int w = 1, q = j; q < j + i / 2; q ++, w = (ll) w * wn % mo) {
			  u = a[x][q], v = (ll) a[x][q + i / 2] * w % mo ;
			  a[x][q] = (u + v) % mo, a[x][q + i / 2] = (u - v) % mo ;
		  }
	}
}

void ntt(int size_k) {
	int na, nb ;
	na = nb = ++ size_k ;
	rep(i, 0, n - 1) rep(j, 0, 1) a[j][i] = 0 ;
	rep(i, 1, na - 1) a[0][A[i]] = (a[0][A[i]] + fac[A[i]]) % mo ;
	rep(i, 0, na - 1) a[1][i] = inv[na - 1 - i] ;
	for (n = 1; n <= na + nb; )  n <<= 1 ;
	rep(i, 0, n - 1) {
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) ? (n >> 1) : 0) ;
	}
	dft(0, 0), dft(1, 0) ;
	rep(i, 0, n - 1) a[0][i] = (ll) a[0][i] * a[1][i] % mo ;
	dft(0, 1) ;
	int INV = mul(n, mo - 2) ;
	rep(i, 1, size_k) {
		int j = na - 1 + i ;
		int res = (ll) a[0][j] * INV % mo ;
		f[i] = (f[i] + res) % mo ;
	}
}

int main() {
	int n ; 
	scanf("%d", &n) ;
	int x, y ;
	rep(i, 1, n - 1) {
		scanf("%d%d", &x, &y) ;
		add(x, y), add(y, x) ;
	}
	fac[0] = 1 ;
	rep(i, 1, n) fac[i] = (ll) fac[i - 1] * i % mo ;
	inv[n] = mul(fac[n], mo - 2) ;
	for (int i = n - 1; i >= 0; -- i) inv[i] = (ll) inv[i + 1] * (i + 1) % mo ;
	dfs(1, 0) ;
	rep(i, 1, n) f[i] = 0 ;
	rep(i, 1, n) A[i] = i > 1 ? sz[i] : 0 ;
	ntt(n) ;
	rep(i, 1, n) A[i] = n - sz[i] ;
	ntt(n) ;
	rep(i, 1, n) f[i] = (ll) f[i] * inv[i] % mo ;
	rep(i, 1, n) {
		int ret = (ll) n * fac[n] % mo * inv[i] % mo * inv[n - i] % mo - f[i] ;
		ret = (ret % mo + mo) % mo ;
		printf("%d\n", ret) ;
	}
	return 0 ; 
}

Measured memory_bytes: 27392
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	String s = sc.nextLine();
    	
    	for(int i=0; i<19; i++){
    		if(i == 5 || i == 13)
    			System.out.print(" ");
    		else
    			System.out.print(s.substring(i, i+1));
    	}
    

    }
}


Measured memory_bytes: 10068
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int n;
int a[505][505];
vector <int> vec[50];

void solve(int l,int r,int depth)
{
	if(l+1==r || l==r) return;
	int mid=l+r>>1;
	for(int i=l;i<mid;i++)
	{
		for(int j=mid;j<r;j++)
		{
			a[i][j]=a[j][i]=depth;
		}
	}
	solve(l,mid,depth+1);
	solve(mid,r,depth+1);
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n;
	solve(0,n,1);
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			cout<<a[i][j]<<' ';
		}
		cout<<endl;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1536
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]

for i in range(N):
    a,b = map(int,input().split())
    A[i] = a
    B[i] = b

A_sort = sorted(A)
B_sort = sorted(B)

if N % 2 == 1:
    print(B_sort[N//2] - A_sort[N//2] + 1)
else:
    med_A = (A_sort[N//2] + A_sort[N//2 - 1])
    med_B = (B_sort[N//2] + B_sort[N//2 - 1])
    print(med_B - med_A + 1)

Measured memory_bytes: 28592
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class AtCoderr
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (i * j == n)
                    {
                        WriteLine("Yes");
                        return;
                    }

                }
            }
            WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
import java.util.*;

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

            Map<Integer,Integer> map = new TreeMap<Integer, Integer>();
            for(int i = 0; i < N; i++){
                int X = sc.nextInt();
                int L = sc.nextInt();
                map.put(X,L);
            }

            int leftArm = -1000000001;
            int rightArm = 0;
            int removeNum = 0; 
      
            for (Integer key : map.keySet()){

                if(leftArm + rightArm > key - map.get(key)){
                    removeNum++;

                    if(leftArm + rightArm > key + map.get(key)){
                        leftArm = key;
                        rightArm = map.get(key);
                    }
                
                }else{
                    leftArm = key;
                    rightArm = map.get(key);                   
                }
            }   
            int ans = N - removeNum;
            System.out.println(ans);
   
        sc.close();

        }catch(NoSuchElementException e){
			System.out.println("無効な値です");
		}
    }
}

Measured memory_bytes: 98544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

ll mpow(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) {
      res=res*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  ll sum=0;
  for(ll i=0;i<n;i++) (sum+=a[i])%=mod;
  (sum*=sum)%=mod;
  for(ll i=0;i<n;i++) {
    sum=(sum-a[i]*a[i]%mod+mod)%mod;
  }
  sum=sum*mpow(2,mod-2)%mod;
  cout << sum << endl;
}

Measured memory_bytes: 4800
import sys
from collections import deque
from decimal import Decimal
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    a,b,x = IL()
    v = a*a*b
    if v/2<=x:
        ang = math.atan((v-x)*2/a**3)
    else:
        ang = math.atan(a*b*b/2/x)
    print(math.degrees(ang))
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 27212
N = int(input())
A = list(map(int, input().split()))

A.sort()
A = A[::-1]

ans = A[0]
if N%2 ==0:
    for i in range((N-2)//2):
        for j in range(2):
            ans += A[i+1]
else:
    for i in range((N-3)//2):
        for j in range(2):
            ans += A[i+1]
    ans += A[(N-3)//2+1]
print(ans)

Measured memory_bytes: 94084
using System;
using System.Linq;

internal class Program
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToList();
                        if (input[0] >= input[1] / 500.0)
                        {
                            Console.WriteLine("Yes");
                            return;
                        }
                        Console.WriteLine("No");
        }
    }

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

typedef long long ll;

int main(){
    int n, k; cin >> n >> k;
    ll ans = k;
    for(int i = 1; i < n; i++)
    {
        ans *= k-1;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
from collections import deque

def bfs(string):
    can = ["dream", "dreamer", "erase", "eraser"]
    queue = deque([])
    queue.append("dream")
    queue.append("dreamer")
    queue.append("erase")
    queue.append("eraser")
    while queue:
        judge = queue.popleft()
        if judge == string:break
        for temp in can:
            ans = judge + temp
            if ans == string[:len(ans)]:
                queue.append(ans)
    return "YES" if judge == string else "NO"

if __name__ == '__main__':
    s = input()
    print(bfs(s))

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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.first << ", " << p.second << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    // MAX = 3^n
    // TODO read someo f editorial
    int n;
    cin >> n;
    int temp;
    int bad = 1;
    for (int i = 0; i < n; i++) {
        cin >> temp;
        if (temp % 2 == 0) {
            bad *= 2;
        }
    }
    cout << pow(3, n) - bad;
}


Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,nn,dig,num;
  cin>>n;
  num=0;
  nn=n;
  while(nn){
      dig=nn%10;
      num+=dig;
      nn=nn/10;
  }
  if(n%num==0)
  cout<<"Yes";
  else
  cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>

using namespace std;

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

    int s = 0;
    for (int i = 0; i < n; i++) {
        s += l + i;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int cur = 0;
        for (int j = 0; j < n; j++) {
            if (j != i) {
                cur += l + j;
            }
        }

        if (abs(cur - s) < abs(ans - s)) {
            ans = cur;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;

int main (){
    int a,b,c,d;
    bool ans;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(abs(a-c) <= d)
      ans = true;
    else if(abs(a-b) <= d && abs(b-c) < d)
      ans = true;
    else ans = false;

    if(ans) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        
        int N = scanner.nextInt();
        
        int C_0 = 0;
        int C_1 = 0;
        int C_2 = 0;
        int C_3 = 0;
        String s[] = new String[N]; 
        
        for(int i=0; i<N; i++){
            
            s[i] = scanner.next();
            
            if(s[i].equals("AC")){
                C_0 += 1;
            }else if(s[i].equals("WA")){
                C_1 += 1;
            }else if(s[i].equals("TLE")){
                C_2 += 1;
            }else{
                C_3 += 1;
            }
        }
        
        System.out.print("AC x ");
        System.out.println(C_0);
        
        System.out.print("WA x ");
        System.out.println(C_1);
        
        System.out.print("TLE x ");
        System.out.println(C_2);
        
        System.out.print("RE x ");
        System.out.println(C_3);

    }
}


Measured memory_bytes: 63976
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 10000000007;

#define rep(i,n) for (int i=0; i < int(n); i++)

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


Measured memory_bytes: 256
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,0,n)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n,m;
ll k;
string s;

int ans = 0;

bool solve(){

	cin >> s;
	int c[]={0,0,0};
	REP(i, s.size()) c[s[i]%3]++;
	int m = min(c[0], min(c[1], c[2]));
	REP(i,3) c[i] -= m;
	REP(i,3) dump(c[i]);
	REP(i, 3) if(c[i]>1) return 0;
	REP(i, 3) if(c[i]==0) return 1;
	return 0;
}

int main() {
	cout << (solve() ? "YES" : "NO") << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 5e3 + 5;
const int INF  = 1e9;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n;
vector <int> a, b;
char s[MAXN], t[MAXN];
bool fail(vector <int> &a, int cnt, int &ans) {
	vector <int> tmp = a;
	if (cnt == 0) return false;
	if (cnt >= 0) {
		int now = 0;
		while (cnt > 0) {
			if (a.empty()) return true;
			if (a.back() == 1) now++;
			else {
				cnt--;
				ans += now + 1;
				now += 2;
			}
			a.pop_back();
		}
		while (now--) a.push_back(1);
	} else {
		cnt = -cnt;
		int now = 0, state = 0;
		while (cnt > 0) {
			if (a.empty()) return true;
			if (a.back() == 2) now++;
			else if (state == 0) state = 1, ans += now;
			else {
				ans += now + 1;
				cnt--, now++;
				state = 0;
			}
			a.pop_back();
		}
		while (now--) a.push_back(2);
	}
	return false;
}
void debug(vector <int> &a) {
	for (auto x : a)
		cerr << x << ' ';
	cerr << endl;
}
int func(int x) {
	int y = b.size() - x - a.size();
	vector <int> c = a; int ans = 0;
	reverse(c.begin(), c.end());
	if (fail(c, x, ans)) return INF;
	reverse(c.begin(), c.end());
	if (fail(c, y, ans)) return INF;
	vector <int> e, d;
	for (unsigned i = 0; i < b.size(); i++) {
		if (b[i] == 2) d.push_back(i);
		if (c[i] == 2) e.push_back(i);
	}
	assert(d.size() == e.size());
	for (unsigned i = 0; i < d.size(); i++)
		ans += abs(d[i] - e[i]);
	return ans;
}
int main() {
	read(n);
	scanf("\n%s", s + 1);
	scanf("\n%s", t + 1);
	if (n == 1) {
		if (s[1] != t[1]) cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		if (s[i] == s[i - 1]) {
			a.pop_back();
			a.push_back(2);
		} else a.push_back(1);
		if (t[i] == t[i - 1]) {
			b.pop_back();
			b.push_back(2);
		} else b.push_back(1);
	}
	int ans = INF;
	for (int i = -n; i <= n; i++)
		if ((s[1] == t[1]) ^ (i % 2 != 0)) chkmin(ans, func(i));
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	for (int i = -n; i <= n; i++)
		if ((s[n] == t[n]) ^ (i % 2 != 0)) chkmin(ans, func(i));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
N, L = map(int, input().split())

a = []
min_v = float('inf')
min_i = 0
for i in range(N):
    value = L + i
    if abs(value) < min_v:
        min_v = abs(value)
        min_i = i
    a.append(value)

newa = a[:min_i] + a[min_i+1:]

print(sum(newa))


Measured memory_bytes: 3060
N, M = map(int, input().split())
cleared = [False] * N
penalties = [0] * N
n_ac, penalty = 0, 0
for i in range(M):
    p, s = input().split()
    p = int(p)
    if not cleared[p - 1]:
        if s == "AC":
            cleared[p - 1] = True
            n_ac += 1
        else:
            penalties[p - 1] += 1

for i in range(N):
    if not cleared[i]:
        penalties[i] = 0

print(n_ac, sum(penalties))

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

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

void deb(deque<int> da){
    int x=da.size();
    rip(i,x,0){
        if(i==x-1){
            printf("%d\n",da.front());
        }else{
            printf("%d ",da.front());
            da.pop_front();
        }
    }
}

int main(){
    int n;
    deque<int> q;
    cin >> n;
    string s;
    int d;
    rip(i,n,0){
        cin >> s;
        if(s=="insert"){
            cin >> d;
            q.push_front(d);
        }else if (s=="deleteFirst"){
            q.pop_front();
        }else if (s=="deleteLast"){
            q.pop_back();
        }else{
            cin >> d;
            int x=q.size();
            bool ju=true;
            rip(i,x,0){
                if(q.front()==d && ju){
                    ju=false;
                }else{
                    q.push_back(q.front());
                }
                q.pop_front();
            }
        }
        //deb(q);
    }
    int x=q.size();
    rip(i,x,0){
        if(i==x-1){
            printf("%d\n",q.front());
        }else{
            printf("%d ",q.front());
            q.pop_front();
        }
    }
}


Measured memory_bytes: 7196
// AOJ 2440 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2440)
#include<iostream>
#include<set>
#include<string>
#define rep(i,a) for(int i=0;i<(a);++i)

int N, M;
std::set<std::string> s;
bool key = true;

int main()
{
	std::cin >> N;
	rep( i, N )
	{
		std::string U;
		std::cin >> U;

		s.insert(U);
	}

	std::cin >> M;
	rep( i, M )
	{
		std::string T;
		std::cin >> T;
			
		if( s.count(T) )
		{
			key ^= true;
			std::cout << (key?"Closed by ":"Opened by ");
		}
		else
			std::cout << "Unknown ";

		std::cout << T << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1232
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int n;
	cin >> n;
	vector<bool> vi(n);
	int w = 1, x = 7 % n;
	while(x && !vi[x]) {
		w++;
		vi[x] = 1;
		x = (x * 10 + 7) % n;
	}
	cout << (x? -1: w) << '\n';
}



Measured memory_bytes: 3740
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int n, m;
int u[200000];

vector<int> v[200000];

int find(int x)
{
	return u[x]==x?x:u[x]=find(u[x]);
}

int main()
{
	int i, j, k, l;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		int x;
		scanf("%d", &x);
		for(j=0;j<x;j++)
		{
			int y;
			scanf("%d", &y), y--;
			v[y].push_back(i);
		}
	}
	for(i=0;i<n;i++) u[i]=i;
	for(i=0;i<m;i++)
	{
		for(j=0;j+1<v[i].size();j++)
		{
			int x=v[i][j], y=v[i][j+1];
			u[find(x)]=find(y);
		}
	}
	for(i=0;i<n;i++) if(find(i) != find(0)) return !printf("NO\n");
	printf("YES\n");
	return 0;
}
//*/

Measured memory_bytes: 7676
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int fun(int x)
{
	int sum=0;
	int p=1;
	while(sum <=x)
	{
		sum+=p;
		p++;
	}
	return p-2;
}
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;cin>>n;
    v vec;
    for(int i=2;i*i<=n;i++)
    {
    	if(n%i==0)
    	{
    		int cnt=0;
    		while(n%i==0)
    		{
    			cnt++;
    			n/=i;
    		}
    		vec.pb(cnt);
    	}
    }	
    if(n>1)
    	vec.pb(1);
    int ans=0;
    for(auto it:vec)
    {
    	ans+=fun(it);
    }
    cout<<ans<<endl;
    // int n;cin>>n;
    // cout<<fun(n);
    return 0;
}

Measured memory_bytes: 3652
a = int(input())
b = int(input())
c = int(input())
X = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            sum = 500*i + 100*j + 50*k
            if sum == X:
                count += 1
print(count)

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

const int MAXN = 200010;
int A[MAXN], n, at[MAXN];
struct st {
	int f[20][MAXN];
	void build(int n) {
		for (int i = 1; i != 20; ++i)
			for (int j = 1; j + (1 << i) - 1 <= n; ++j)
				f[i][j] = std::min(f[i - 1][j], f[i - 1][j + (1 << i - 1)]);
	}
	int qry(int l, int r) {
		int L = std::__lg(r - l + 1);
		return std::min(f[L][l], f[L][r - (1 << L) + 1]);
	}
} t[2];
struct item {
	int v, l, r;
	bool operator < (item b) const { return v > b.v; }
};
std::priority_queue<item> q;
void push(int l, int r) {
	if (l <= r) q.push((item) {t[l & 1].qry(l + 1 >> 1, r >> 1), l, r});
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i)
		std::cin >> A[i], at[A[i]] = i, t[i & 1].f[0][i + 1 >> 1] = A[i];
	t[0].build(n >> 1), t[1].build(n >> 1);
	push(1, n);
	while (!q.empty()) {
		item t = q.top(); q.pop();
		int a = ::t[t.l & 1 ^ 1].qry(at[t.v] + 2 >> 1, t.r + 1 >> 1);
		std::cout << t.v << ' ' << a << ' ';
		push(t.l, at[t.v] - 1), push(at[t.v] + 1, at[a] - 1), push(at[a] + 1, t.r);
	}
	return 0;
}


Measured memory_bytes: 31996
#include <cstdint>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

void wf(int n,vector<vector<int>> &dist) {
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (dist[i][k] + dist[k][j] < dist[i][j]) {
					dist[i][j] = dist[i][k] + dist[k][j];
					dist[j][i] = dist[i][k] + dist[k][j];
				}
			}
		}
	}
}

bool check_joint(int n, int inf, vector<vector<int>> dist) {
	wf(n,dist);
	bool ok = true;
	for (int i = 0; i < n; ++i) {
		if (dist[0][i] >= inf) {
			ok = false;
		}
	}
	return ok;
}

int main(){
	int n;
	int m;
	cin >> n >> m;
	int inf = n * n + 1;
	vector<vector<int>> dist = vector<vector<int>>(n, vector<int>(n,inf));
	vector<pair<int, int>> edge;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edge.push_back(make_pair(a, b));
		dist[a][b] = 1;
		dist[b][a] = 1;
	}
	int sum = 0;
	for (int i = 0; i < edge.size(); ++i) {
		auto p = edge[i];
		dist[p.first][p.second] = inf;
		dist[p.second][p.first] = inf;
		if (!check_joint(n,inf,dist)) {
			sum++;
		}
		dist[p.first][p.second] = 1;
		dist[p.second][p.first] = 1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string str, com, str2, p;
    int q, a, b;
    cin >> str >> q;
    for (int i=0; i<q; i++){
        cin >> com >> a >> b;
        str2.clear();
        str2 = str.substr(a, b-a+1);
        if (com == "print"){
            cout << str2 << endl;
        } else if (com == "reverse"){
            for (int j=0; j<b-a+1; j++){
                str[a+j] = str2[b-a-j];
            }
        } else if (com == "replace"){
            cin >> p;
            //str.erase(a, b-a+1);
            //str.insert(a,p);
            str.replace(a, b-a+1, p);
        }
    }
    return 0;
}


Measured memory_bytes: 3184
n=int(input())
t=input()
s=""
for i in range(0,len(t)):
    if(ord(t[i])+n<=90):
        s=s+chr(ord(t[i])+n)
    else:
        d=(ord(t[i])+n)%91+65
        s=s+chr(d)
print(s)

Measured memory_bytes: 40668
#include <algorithm>
#include <array>
#include <atcoder/all>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int N, M;
	cin >> N >> M;
	dsu d(N);

	int a, b;
	rep(i, M) {
		cin >> a >> b;
		a -= 1;
		b -= 1;
		d.merge(a, b);
	}

	set<int> st;
	rep(i, N) {
		st.insert(d.leader(i));
	}
	cout << st.size() - 1 << endl;
	return 0;
}


Measured memory_bytes: 7572
import java.util.*;
import java.io.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		if((n*k) % 2 == 1) {
			System.out.println("Yes");
		}
		else System.out.println("No");
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> h(n);
    rep0(i, n)cin >> h[i];
    vector<vector<ll> > e(n,vector<ll>(0));
    rep0(i, m){
        ll a,b;
        cin >> a >> b;
        --a;
        --b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    ll cnt = 0;
    rep0(i, n){
        bool f = true;
        rep0(j, e[i].size()){
            if(h[e[i][j]] >= h[i]){
                f = false;
                break;
            }
        }
        if(f)++cnt;
    }
    pf(cnt);
    return 0;
}



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

int main (){
  int a, b;
  cin >> a >> b;
  int ans = 0;
  
  for ( int i = a; i <=b; i++ ){
    if ( ( i / 1000 ) % 10 == ( i / 10 ) % 10 && i / 10000 == i % 10 )
      ans ++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [0] + [int(i) for i in input().split()]
b = [0] * (n+1)

for i in range(1,n+1)[::-1]:
    mul_sum = sum((b[x] for x in range(i+i,n+1,i)))
    b[i] = (mul_sum%2) ^ a[i]

print(sum(b))
print(" ".join(str(i) for i in range(1,n+1) if b[i]))

Measured memory_bytes: 90844
import sys

sys.setrecursionlimit(10000)


def dfs(x, y):
    global cout
    if 0 <= x < H - 1 and tile[x + 1][y] == ".":
        cout += 1
        tile[x + 1][y] = "#"
        dfs(x + 1, y)
    if 0 < x < H and tile[x - 1][y] == ".":
        cout += 1
        tile[x - 1][y] = "#"
        dfs(x - 1, y)
    if 0 <= y < W - 1 and tile[x][y + 1] == ".":
        cout += 1
        tile[x][y + 1] = "#"
        dfs(x, y + 1)
    if 0 < y < W and tile[x][y - 1] == ".":
        cout += 1
        tile[x][y - 1] = "#"
        dfs(x, y - 1)
    return 0


def search_start():
    for i in range(H):
        for j in range(W):
            if tile[i][j] == "@":
                tile[i][j] = "#"
                return (i, j)


if __name__ == "__main__":
    while True:
        W, H = map(int, input().split())
        if W == 0 and H == 0:
            break
        # print(W, H)
        tile = [list(input()) for _ in range(H)]
        cout = 1
        start = search_start()
        # print(start)
        dfs(start[0], start[1])
        # print(*tile, sep="\n")
        # print("total count : {}".format(cout))
        print(cout)



Measured memory_bytes: 5732
import copy
from collections import deque

H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]


def check(tup):
    global H
    global W
    global S

    tup_x=tup[0]
    tup_y=tup[1]
    if 0<=tup_x<H and 0<=tup_y<W:
        if S[tup_x][tup_y]=='.':
            return True
    else:
        return False

def neighbor(tup):
    x=tup[0]
    y=tup[1]
    cand=[(x-1,y),(x+1,y),(x,y-1),(x,y+1)]
    List=[]
    for c in cand:
        if check(c):
            List.append(c)
    return List

def bfs(start):#startはtuple型
    global H
    global W

    if check(start):
        deq=deque()#as queue
        Dict=[]
        component=[]
        for i in range(W):
            component.append(-1)
        for j in range(H):
            Dict.append(copy.copy(component))

        deq.append(start)
        Dict[start[0]][start[1]]=0
        while deq:
            now=deq.popleft()
            nexts=neighbor(now)
            for next in nexts:
                next_x=next[0]
                next_y=next[1]
                if Dict[next_x][next_y]>=0:
                    continue
                if next in deq:
                    continue
                deq.append(next)
                Dict[next_x][next_y]=Dict[now[0]][now[1]]+1

        M=[]
        for d in Dict:
            M.append(max(d))
        return max(M)
    
    else:
        return 0

Ans=[]
for k in range(H):
    for l in range(W):
        Ans.append(bfs((k,l)))

print(max(Ans))




Measured memory_bytes: 3496
// verified at https://judge.yosupo.jp/submission/3400
#ifndef Union_find_hpp
#define Union_find_hpp

#include <cassert>
#include <cstddef>
#include <vector>

class union_find
{
    std::vector<int> link;

public:
    explicit union_find(const size_t n) : link(n, -1) {}

    size_t find(size_t x)
    {
        assert(x < size());
        // while(link[x] >= 0)
        // {
        //     if(link[link[x]] >= 0) link[x] = link[link[x]];
        //     x = link[x];
        // }
        // return x;
        return link[x] < 0 ? x : (link[x] = find(link[x]));
    }

    size_t size() const { return link.size(); }

    size_t size(const size_t x)
    {
        assert(x < size());
        return -link[find(x)];
    }

    bool same(const size_t x, const size_t y)
    {
        assert(x < size() && y < size());
        return find(x) == find(y);
    }

    size_t unite(size_t x, size_t y)
    {
        assert(x < size() && y < size());
        if((x = find(x)) != (y = find(y)))
        {
            if(link[x] > link[y]) std::swap(x, y);
            link[x] += link[y];
            link[y] = x;
        }
        return x;
    }
}; // class union_find

#endif // Union_find_hpp

#include <iostream>
#include <tuple>

using namespace std;

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

    int n,h,w; cin>>n>>h>>w;
    vector<vector<pair<int,int>>> cards(100000);
    for(int i=n,r,c,a; i--; )
    {
        cin>>r>>c>>a; --r,--c;
        cards[a].emplace_back(r,c+h);
    }
    union_find uf(h+w);
    long long ans{};
    bool ext[2<<17]={};
    for(int i=100000; i; --i)
    {
        for(auto&& e:cards[i])
        {
            int r,c; tie(r,c)=e;
            r=uf.find(r),c=uf.find(c);
            if(r!=c)
            {
                if(ext[r] and ext[c]) continue;
                ext[uf.unite(r,c)]=ext[r]||ext[c];
                ans+=i;
            }
            else if(!ext[r])
            {
                ext[r]=true;
                ans+=i;
            }
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 5760
#include<stdio.h>
#include<math.h>
#define MAX 1000
#define VMAX 10000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int partition(int A[], int p, int r){
  int i, j;
  int x, t;
  x = A[r];
  i = p-1;
  for( j = p ; j < r ; j++ ){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(int A[], int p, int r){
  int q;
  if( p < r ){
    q = partition(A, p, r);
    quickSort(A, p, q-1);
    quickSort(A, q+1, r);
  }
}


int solve(){
  int i, ans = 0;

  int V[MAX];
  for( i = 0 ; i < n ; i++ ){
    B[i] = A[i];
    V[i] = 0;
  }
  quickSort(B, 0, n-1);
  for( i = 0 ; i < n ; i++ ) T[B[i]] = i;
  for( i = 0 ; i < n ; i++ ){
    if( V[i] ) continue;
    int cur = i;
    int S = 0;
    int m = VMAX;
    int an = 0;
    while( 1 ){
      V[cur] = 1;
      an++;
      int v = A[cur];
      m = fmin(m, v);
      S += v;
      cur = T[v];
      if( V[cur] ) break;
    }
    ans += fmin(S+(an-2)*m, m+S+(an+1)*s);
  }

  return ans;
}

int main(){
  int i;
  scanf("%d",&n);
  s = VMAX;
  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &A[i]);
    s = fmin(s, A[i]);
  }
  int ans = solve();
  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	// your code goes here
	ll n,x,t;
	cin>>n>>x>>t;
		ll c=n/x;
		n=n%x;
		if(n%x==0)
		cout<<(c*t)<<"\n";
		else
		cout<<(c+1)*t<<"\n";
	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
using namespace std;
int n, st, ans[5], x, y;
vector<int>h, cnt;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x;
		if (h.size() == 0){
			h.push_back(x);
			cnt.push_back(1);
		}
		else if (h.back() != x){
			h.push_back(x);
			cnt.push_back(1);
		}
		else cnt[cnt.size() - 1]++;
	}
	for (int i = 1; i < h.size() - 1; i++)
	{
		if (h[i - 1]<h[i] && h[i]>h[i + 1])
		{
			if (cnt[i] == 1)
				ans[3]++;
			else ans[0]++;
		}
		if (h[i - 1] > h[i] && h[i] < h[i + 1]){
			if (cnt[i] == 1)
				ans[4]++;
			else ans[1]++;
		}
		if (h[i - 1] < h[i] && h[i] < h[i + 1] && cnt[i]>1)
			ans[2]++;
		if (h[i - 1] > h[i] && h[i] > h[i + 1] && cnt[i] > 1)
			ans[2]++;

	}

	for (int i = 0; i < 5; i++)	{
		cout << ans[i];
		if (i == 4)
			cout << endl;
		else cout << ' ';
	}
	return 0;
}


Measured memory_bytes: 2148
fun power(base: Long, exp: Long, mod: Long): Long {
    return when(exp) {
        0L -> 1
        1L -> base % mod
        else -> power(base * base % mod, exp shr 1, mod) * power(base, exp and 1, mod) % mod
    }
}
fun main() {
    val mod = 1000000007L
    val n = readLine()!!.trim().toInt()
    val num = readLine()!!.trim().split(' ').map(String::toLong).toLongArray()
    val sum = num.sum() % mod
    println(num.map{(it * sum % mod + mod - it * it % mod) % mod}.sum() % mod * power(2, mod - 2, mod) % mod)
}

Measured memory_bytes: 71764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
		String a = S.substring(0, 2);
		String b = S.substring(2, 4);
		
		int A = Integer.parseInt(a);
		int B = Integer.parseInt(b);
		
		if(1 <= B && B <= 12) {
			if(1 <= A && A <= 12) {
				System.out.println("AMBIGUOUS");
			} else {
				System.out.println("YYMM");
			}
		} else if(1 <= A && A <= 12) {
			if(1 <= B && B <= 12) {
				System.out.println("AMBIGUOUS");
			} else {
				System.out.println("MMYY");
			} 
		} else {
			System.out.println("NA");
		}
		
	}
}


Measured memory_bytes: 21332
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] Args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int p, q, r;
        p = Integer.parseInt(st.nextToken());
        q = Integer.parseInt(st.nextToken());
        r = Integer.parseInt(st.nextToken());
        if(p + q <= r + q && p + q <= p + r){
            System.out.println(p + q);
        }
        else if(p + r <= p + q && p + r <= r + q){
            System.out.println(p + r);
        }
        else if(r + q <= p + q && r + q <= p + r){
            System.out.println(r + q);
        }

        br.close();
    }
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n, m;
  int x = 0;
  cin >> n;
  m = n;
  while (m != 0) {
    x += m%10;
    m /= 10;
  }
  if (n%x == 0) dump("Yes");
  else dump("No");
  return 0;
}


Measured memory_bytes: 256
// A - Frog 1 / ATCODER
// Time Limit: 2 sec / Memory Limit: 1024 MB
// Score : 
// 100
//points
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for(ll p=1;p<=n;p++)
	{
		cin>>a[p];
	}
	ll dp[100002]={0};
	dp[2]=abs(a[2]-a[1]);
	if(n==2)
	{
		cout<<dp[2]<<endl;
		return 0;
	}
	for(ll ka=3;ka<=n;ka++)
	{
		dp[ka]=1e10;
		for(ll r=1;r<=k&&r<ka;r++)
		{
			dp[ka]=min(dp[ka],(abs(a[ka]-a[ka-r])+dp[ka-r]));	
		}
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792