akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

S  = input()

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != 'R' and S[i] != 'U' and S[i] != 'D':
            print("No")
            sys.exit()
    else:
        if S[i] != 'L' and S[i] != 'U' and S[i] != 'D':
            print("No")
            sys.exit()

print("Yes")



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

using namespace std;

const long long MOD = 1e9+7;

long long memo[2005][2005];

long long ncr(int i, int j){
	if(i < j){
		return 0;
	}else if(j == 0){
		return 1;
	}else if(memo[i][j] != -1){
		return memo[i][j];
	}else{
		return memo[i][j] = (ncr(i-1, j)+ncr(i-1, j-1))%MOD;
	}
}

int main(){
	int N, K;
	scanf("%d%d", &N, &K);
	
	int B = K;
	int R = N-K;
	
	memset(memo, -1, sizeof(memo));
	
	for(int i = 1; i <= K; i ++){
		printf("%lld\n", ncr(R+1, i)*ncr(B-1, i-1)%MOD);
	}
	
	return 0;
}


Measured memory_bytes: 31744
INF = 105 * 10 ** 7
dp = [INF] * 100100

N, K = map(int, input().split())
h = list(map(int, input().split())) + [0] * 100

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])


Measured memory_bytes: 53216
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10;
int n,m,d[N],pre[N];
vector<int> g[N];
inline void add(int a,int b){g[a].push_back(b),g[b].push_back(a);}
void bfs(){
	queue<int> q; memset(d,-1,sizeof d); q.push(1); d[1]=0;
	while(q.size()){
		int u=q.front();	q.pop();
		for(int to:g[u]) if(d[to]==-1) d[to]=d[u]+1,pre[to]=u,q.push(to);
	}
}
signed main(){
	cin>>n>>m;
	for(int i=1,a,b;i<=m;i++)	scanf("%d %d",&a,&b),add(a,b);
	bfs();
	for(int i=1;i<=n;i++)	if(d[i]==-1)	return puts("No"),0;
	puts("Yes");
	for(int i=2;i<=n;i++)	printf("%d\n",pre[i]);
	return 0;
}


Measured memory_bytes: 10992
#include "bits/stdc++.h"
using namespace std;

int main() {
	int x, y;
	cin >> x >> y;

	vector<int> group1 = {1, 3, 5, 7, 8, 10, 12};
	vector<int> group2 = {4, 6, 9, 11};

	int type_x=0, type_y=0;

	for(int i=0;i<7;i++) {
		if(group1.at(i) == x) type_x=1;
		if(group1.at(i) == y) type_y=1;
	}

	for(int i=0;i<4;i++) {
		if(group2.at(i) == x) type_x=2;
		if(group2.at(i) == y) type_y=2;
	}

	if(type_x == type_y) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn remove_same_values(vs: &mut Vec<i32>) {
    vs.sort();
    for i in 0..vs.len()-1 {
        if vs[i] == vs[i + 1] {
            vs[i] = 0;
            vs[i + 1] = 0;
        }
    }
}

fn main() {
    let n: usize = read();
    let mut aseq = vec![0; n];
    let mut bseq = vec![0; n];
    for i in 0..n {
        aseq[i] = read();
    }
    aseq.sort();
    for i in 0..n {
        bseq[i] = read();
    }
    remove_same_values(&mut bseq);
    bseq.sort();
    // remove same values
    for i in 0..n-1 {
        if bseq[i] == bseq[i + 1] {
            bseq[i] = 0;
            bseq[i + 1] = 0;
        }
    }
    bseq.sort();
    let mut ans = 0;
    for i in 0..30 {
        let target = 1 << (29 - i);
        for a in aseq.clone() {
            if a < target {
                let minv = target - a; // inclusive
                let maxv = 2 * target - a; // exclusive
                let left = match bseq.binary_search(&minv) {
                    Ok(v) => v,
                    Err(v) => v,
                };
                let right = match bseq.binary_search(&maxv) {
                    Ok(v) => v,
                    Err(v) => v,
                };
                ans ^= target * ((right - left) as i32 % 2);
            } else {
                let minv = 2 * target - a; // exclusive
                let maxv = 3 * target - a; // inclusive
                let left = match bseq.binary_search(&minv) {
                    Ok(v) => v,
                    Err(v) => v,
                };
                ans ^= target * (left as i32 % 2);
                let right = match bseq.binary_search(&maxv) {
                    Ok(v) => v,
                    Err(v) => v,
                };
                ans ^= target * ((n - right) as i32 % 2);
                // println!("{} {} {} {} {} {}", target, a, left, right, minv, maxv);
            }
        }
        for i in 0..n {
            aseq[i] %= target;
            bseq[i] %= target;
        }
        aseq.sort();
        remove_same_values(&mut bseq);
        bseq.sort();
    }
    println!("{}", ans);
}

Measured memory_bytes: 9424
#include <iostream>
#include <vector>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef tuple<int, int, int, int> T;

int h, w;
int a[500][500];
vector<T> ans;

int main() {
	int i, j;
	
	cin >> h >> w;
	rep(i, h) rep(j, w) cin >> a[i][j];
	
	for (i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (j = 0; j + 1 < w; j++) {
				if (a[i][j] % 2) {
					ans.push_back(T(i, j, i, j + 1));
					a[i][j]--;
					a[i][j+1]++;
				}
			}
		}
		else {
			for (j = w - 1; j - 1 >= 0; j--) {
				if (a[i][j] % 2) {
					ans.push_back(T(i, j, i, j - 1));
					a[i][j]--;
					a[i][j-1]++;
				}
			}
		}
		
		if (i + 1 < h && a[i][j] % 2) {
			ans.push_back(T(i, j, i + 1, j));
			a[i][j]--;
			a[i+1][j]++;
		}
	}
	
	cout << ans.size() << endl;
	rep(i, ans.size()) {
		cout << 1 + get<0>(ans[i]) << " " << 1 + get<1>(ans[i]) << " " << 1 + get<2>(ans[i]) << " "  << 1 + get<3>(ans[i]) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5232
#include <stdio.h>
#define MAX 21

int main()
{
  char string[MAX];
  int i, len = 0;

  scanf("%s", string);

  for (i = 0; string[i] != '\0'; i++)
    ;
  
  for (; i-1 >= 0; i--)
    putchar(string[i-1]);
  putchar('\n');

  return 0;
}

Measured memory_bytes: 0
from itertools import combinations as comb

h,w,k = map(int,input().split())
g = [input() for i in range(h)]

row = [i for i in range(h)]
col = [i for i in range(w)]
ANS = 0

for i in range(h+1):
	for cr in comb(row, i):
		for j in range(w+1):
			for cc in comb(col, j):
				gp = [list(s) for s in g]
				for ligne in cr:
					for colonne in range(w):
						gp[ligne][colonne] ="r"
				for colonne in cc:
					for ligne in range(h):
						gp[ligne][colonne] = "r"
				reste = 0
				for ligne in gp:
					reste+=ligne.count("#")
				if reste == k:
					ANS+=1
print(ANS)


Measured memory_bytes: 9220
/* ex2_3
    nnasy   */

#include <stdio.h>

int main(void) {
    int length_N, white;

    //入力の受け取り（N, A）
    scanf("%d%d", &length_N, &white);

    //黒色のマスの個数(N*N-A)の出力
    printf("%d\n", length_N*length_N-white);
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<double, double> pdd;
typedef pair<double, pdd> pddd;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int num[15];
int perf[15];

int main() {
    int n, want;
    scanf("%d%d", &n, &want);
    for(int i = 0; i < n; i++) {
        scanf("%d%d", &num[i], &perf[i]);
    }
    int ret = 1e9;
    for(int mask = 0; mask < (1<<n); mask++) {
        int curr = 0;
        ll amt = 0;
        for(int i = 0; i < n; i++) {
            if((mask&(1<<i))) {
                curr += num[i];
                amt += (i+1)*100LL*num[i] + perf[i];
            }
        }
        for(int i = n-1; i >= 0 && amt < want; i--) {
            if((mask&(1<<i))) continue;
            int a = 0;
            while(amt < want && a < num[i]) {
                a++;
                curr++;
                amt += 100 * (i+1);
            }
            if(a == num[i]) {
                amt += perf[i];
            }
        }
        ret = min(ret, curr);
    }
    printf("%d\n", ret);
}


Measured memory_bytes: 256
def main():
    N = int(input())
    P = [int(x) for x in input().split()]
    ans = 0
    minP = P[0]

    for i in range(N):
        minP = min(minP, P[i])
        if P[i] <= minP:
            ans += 1
    
    print(ans)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 24744
#include <limits.h>
#include <math.h>
#include <stdio.h>

int main(void) {
  char s[5];
  int ans;
  scanf("%s",&s);
  if(s[0]=='S'){
    if(s[1]=='A'){
      ans=1;
    }else if(s[1]=='U'){
      ans=7;
    }
  }
  if(s[0]=='M'){
      ans=6;
  }
  if(s[0]=='T'){
    if(s[1]=='H'){
      ans=3;
    }else if(s[1]=='U'){
      ans=5;
    }
  }
  if(s[0]=='W'){
      ans=4;
  }
  if(s[0]=='F'){
      ans=2;
  }

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

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


bool check_palindrome(string s){
    int n = s.size();
    bool f = true;
    for(int i=0; i<n/2; i++){
        if(s[i] != s[n-1-i]){
            f = false;
            break;
        }
    }

    return f;
}


int main(){
    string S;
    cin >> S;
    int n = S.size();
    string T = S.substr(0, (n-1)/2);
    string U = S.substr((n+3)/2-1, (n-1)/2);
    if(check_palindrome(S) && check_palindrome(T) && check_palindrome(U)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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


int main()
{
    int N, K;
    cin >> N >> K;
    vector<long long> A(N);
    REP(i, N) cin >> A[i];

    FOR(i, K, N){
        if(A[i] > A[i-K]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 4844
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

a.sort()
b.sort()
ans=0

for i in range(29):
    c=[]
    d=[]
    T=2**i
    for u in a:
        c.append(u%(2**(i+1)))
    for u in b:
        d.append(u%(2**(i+1)))
    c.sort(reverse=True)
    d.sort()
    
    left=0
    mid=0
    right=0
    
    count=0
    
    for u in c:
        
        m_left=T-u
        m_mid=2*T-u
        m_right=3*T-u
        
        while left<n:
            if d[left]<m_left:
                left+=1
            else:
                break
        while mid<n:
            if d[mid]<m_mid:
                mid+=1
            else:
                break
        while right<n:
            if d[right]<m_right:
                right+=1
            else:
                break
                
    
        count+=mid-left+n-right

    if count%2==1:
        ans+=2**i
    
print(ans)

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

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

  int result = 0;
  rep(i, N) {
    int x;
    cin >> x;

    int tmp_a = x * 2;
    int tmp_b = (K - x) * 2;
    result += (tmp_a > tmp_b) ? tmp_b : tmp_a;
  }
  cout << result << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
double dp[3005][3005];
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    double a[n];
    for(i=0;i<n;i++)cin>>a[i];
    dp[0][0]=1;
    for(i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1-a[i-1]);
    }
    for(i=1;i<=n;i++)
    {
        for(j=i;j>0;j--)
        {
            dp[i][j]=dp[i-1][j-1]*a[i-1]+dp[i-1][j]*(1-a[i-1]);
        }
    }
    double ans=0;
    for(i=n;i>=0;i--)
    {
        if(i>(n-i))ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(10)<<ans;
}


Measured memory_bytes: 68992
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  int x,y;cin >> x >> y;
  x--;y--;
  vector<int> res(n-1,0);
  rep(i,n) rep(j,n){
    if(i >= j) continue;
    if(i < x){
      if(j <= x) res[j - i - 1]++;
      else if(j < y){
	int in = min(y - j + x - i, j - i - 1);
	res[in]++;
      }
      else {
	res[j - y + x - i]++;
      }
    }
    else if(i < y){
      if(j < y){
	int in = min(y - j + i - x, j - i - 1);
	res[in]++;
      }
      else  {
	int in = min(j - y + i - x, j - i - 1);
	res[in]++;	
      }
    }
    else{
      res[j - i - 1]++;
    }
  }

  rep(i,n-1){
    cout << res[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum;
  while(1){
    sum = 0;
    cin >> n;
    if(n == 0) break;
    for(int i=1; i*i<=n; i++){
	if(n%i == 0 ){
	  int j=n/i;
	  //jは片方の約数
          sum += i;
          if(j != i ) sum += j;
        }
    }
    sum = sum - n;
  if(n==sum) cout << "perfect number" << endl;
  if(n>sum) cout << "deficient number" << endl;
  if(n<sum) cout << "abundant number" << endl;
  }
  return 0;
}


Measured memory_bytes: 2992
#include <stdio.h>

main(){
  int i;
  int data1[200];
  int data2[200];
  int ans;
  int c = 0;
  
  i = 0;
  while(scanf("%d %d", &data1[i], &data2[i]) != EOF){

    ans = data1[i] + data2[i];

    while(ans >= 10){
      ans = ans / 10;
      c++;
    }
    
    printf("%d\n", c+1);
    c = 0;
  }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n,m,k;

int main(){
	cin >> n >> m >> k;
	rep(i,n+1){
		rep(j,m+1){
			if(i*j+(n-i)*(m-j) == k){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

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

class Main{
    static final long MOD=1_000_000_007;
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        long[] a=new long[n];
        for(int i=0;i<n;i++) a[i]=fsc.nextLong();
        fsc.close();
        long ans=0;
        long pow2[]=new long[62];
        for(int i=0;i<=61;i++) pow2[i]=i==0?1:(pow2[i-1]*2)%MOD;
        for(int i=0;i<=61;i++){
            long c0=0, c1=0;
            for(int j=0;j<n;j++){
                if((a[j]&(1l<<i))==0) c0++;
                else c1++;
            }
            ans+=(((c0*c1)%MOD)*pow2[i])%MOD;
            ans%=MOD;
        }
        System.out.println(ans);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

int main() {
    int N;
    cin >> N;
    while (N--) {
        string str;
        cin >> str;
        string ans;
        ans += str[0];
        int corsor = 0;
        for (int i = 1; i * 3 + 1 <= str.size(); i++) {
            auto pre = string(str.begin() + (i-1)*3+1, str.begin() + (i-1)*3+3);
            if (pre == "<-") corsor--;
            else corsor++;

            if (corsor < 0) corsor = 0, ans = str[i*3] + ans;
            if (corsor >= ans.size()) ans += str[i*3];

        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3068
#include<stdio.h>

int main(void)
{
	int i,n,m,x,y,max,min;
	scanf("%d%d%d%d",&n,&m,&max,&min);
	for(i=0;i<n;i++){
		scanf("%d",&x);
		if(x>max)
			max=x;
	}

	for(i=0;i<m;i++){
		scanf("%d",&y);
		if(y<min)
			min=y;
	}
	
	if(max<min)
		printf("No War");
	else
		printf("War");
	return 0;
}
	

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+1;
const int mod=1e9+7;
vector<int>g[N];
#define pb push_back
ll n;
ll dp[N+1][2];

ll add(ll a,ll b)	{return (a + b)%mod; }
ll mul(ll a,ll b) 	{return (1LL*a*b)%mod; }

ll dfs(int u,int par,int color){
	if(dp[u][color]!=-1) return dp[u][color];
	ll mn=1;
	for(auto v:g[u]){
		if(v==par) continue;
		ll temp=dfs(v,u,1);									
		if(color) temp=add(temp,dfs(v,u,0));				
 		mn=mul(mn,temp);
	}
	return dp[u][color]=mn;
}

int main(){
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		u--,v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	cout<<add(dfs(0,-1,1),dfs(0,-1,0))<<endl;
	return 0;
}

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

int main() {
  long long x;
  cin >>x;
  long long t=x/11;
  if(x<=6){
    cout<<1<<endl;
  }else if(x<=11){
    cout<<2<<endl;
  }else if(x%11==0){
    cout<<t*2<<endl;
  }else if(x%11<=6){
    cout<<t*2+1<<endl;
  }else{
    cout<<t*2+2<<endl;
  }
  return 0;
}

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

int main(int argc, char const *argv[])
{
	string n; cin >> n;
	ll cnt = 0;
	for (auto u : n) cnt += u - '0';

	if (stoll(n) % cnt == 0) printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
# from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += gcd(gcd(i, j), k)
print(ans)


exit()
q = [[str(i)] for i in range(1, K+1)]
# print(q)
s = []
ans = 0
while q:
    a = q.pop()
    # print(q)@
    if len(a) == 3:
        # s.append(a)
        ans += int(a[-1])
        # print(a)
    else:
        for i in range(1, K+1):
            b = deepcopy(a)
            if int(b[-1]) <= i:
                b.append(b[-1])
            # b += str(gcd(i, int(b[-1])))
            else:
                b.append(str(i))
            q.append(b)
print(ans)
# print(s)
# print(s)
# ans = 0
# for d in s:
#     print(sorted(list(d))[0])

# print(ans)


Measured memory_bytes: 69028
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;


int main(){
    ll A,B,C,K; cin >> A >> B >> C >> K;

    if (K <= A){
        cout << K << endl;
    }
    else if (K <= (A+B)){
        cout << A << endl;
    }
    else{
        cout << A - (K-(A+B)) << endl;
    }
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String s=gs();
	    //int b=gi();
	    
	    int a=0;
	    for (int i=0; i<4;i++) {
	    	char c=s.charAt(i);
	    	if (c=='+') {
	    		a++;
	    	}else {
	    		a--;
	    	}
	    }

        System.out.println(a);
//        if (a<=8&&b<=8) {
//        	System.out.print("Yay!");
//        }else {
//        	System.out.print(":(");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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


int main() {
  int64_t N, K;
  cin >> N >> K;
  int64_t ans = -(N+1)*(N+2)*(2*N+3)/6 + (K-1)*K*(2*K-1)/6 + (N+1)*(N+K+1)*(N-K+2)/2 + N-K+2;
  ans %=1000000007;
  cout << ans << endl;
}
  

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, ans=0;
  cin >>N;
  if(N%2==1){
    cout << 0 << endl;
    return 0;
  }
  N/=10;
  ans+=N;
  while(N>0){
    N/=5;
    ans+=N;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def mpow(x, n):
    result = 1
    while n != 0:
        if n & 1 == 1:
            result *= x
            result %= 1000000007
        x *= x
        x %= 1000000007
        n >>= 1
    return result


max_A = 1000000

N = int(input())
A = list(map(int, input().split()))

sieve = [0] * (max_A + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, max_A + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, max_A + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

lcm_factors = {}
for i in range(N):
    t = []
    a = A[i]
    while a != 1:
        if len(t) != 0 and t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    for k, v in t:
        if k not in lcm_factors or lcm_factors[k] < v:
            lcm_factors[k] = v

lcm = 1
for k in lcm_factors:
    for i in range(lcm_factors[k]):
        lcm *= k
        lcm %= 1000000007

result = 0
for i in range(N):
    result += lcm * mpow(A[i], 1000000007-2)
    result %= 1000000007
print(result)


Measured memory_bytes: 14532
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 10000000000007;

int main()
{
	ll a,b,q;
	cin >> a >> b >> q;
	vector<ll> s(a),t(b),x(q);
	rep(i,a)
	{
		cin >> s[i];
	}
	rep(i,b)
	{
		cin >> t[i];
	}
	rep(i,q)
	{
		cin >> x[i];
	}
	rep(i,q)
	{
		auto sbin =lower_bound(ALL(s),x[i]);
		auto tbin = lower_bound(ALL(t),x[i]);

		ll fs = abs(x[i]-*sbin);
		ll ft = abs(x[i]-*tbin);
		ll bs = abs(x[i]-max(*s.begin(),*(sbin-1)));
		ll bt = abs(x[i]-max(*t.begin(),*(tbin-1)));
		
		ll A = max(fs,ft);
		ll B = max(bs,bt);
		if(sbin==s.begin())B=INF;
		if(tbin==t.begin())B=INF;
		if(sbin==s.end())A=INF;
		if(tbin==t.end())A=INF;
		ll C = min(fs,bs)+min(ft,bt)+min(min(fs,bs),min(ft,bt));
		
		//cout<<A<<';'<<B<<';'<<C<<endl;
		cout<<min(A,min(B,C))<<endl;
	}

	return 0;
}

Measured memory_bytes: 3712
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]

h.sort()

DEF_MIN = max(h)-min(h)

for i in range(n-k+1):
    tmp = h[i+k-1]-h[i]
    DEF_MIN = min(DEF_MIN, tmp)

print(DEF_MIN)

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    char a[h][w],b[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            a[i][j] = '.';
            b[i][j] = '.';
            if(j==0) a[i][j] = '#';
            if(j==w-1) b[i][j] = '#';
            if(s[i][j]=='#'){
                a[i][j] = '#';
                b[i][j] = '#';
            }
            if(i%2==0 && j!=w-1) a[i][j] = '#';
            if(i%2==1 && j!=0) b[i][j] = '#';
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << a[i][j];
        }
        cout << "\n";
    }
    cout << "\n";
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << b[i][j];
        }
        cout << "\n";
    }
    cout << endl;
}

Measured memory_bytes: 1536
#4
N=int(input())
memo = [{} for i in range(N)]

def check(last3,way,add,num):
    if num == 1:
        memo[num][last3+add] = way
    if num == 2:
        new_last3 = last3[-2:]+add
        if (new_last3!="AGC")&(new_last3!="GAC")&(new_last3!="ACG"):
            if new_last3 in memo[num]:
                memo[num][new_last3]+=way
            else:
                memo[num][new_last3]=way
    if num > 2:
        new_last3 = last3[-2:]+add
        new_last4 = last3[-3:]+add
        if (new_last3!="AGC")&(new_last3!="GAC")&(new_last3!="ACG"):
            if (new_last4!="AGAC")&(new_last4!="AGGC")&(new_last4!="AGTC")&(new_last4!="ATGC"):     
                if new_last3 in memo[num]:
                    memo[num][new_last3]+=way
                else:
                    memo[num][new_last3]=way

for c in "ATGC":
    memo[0][c] = 1

for i in range(1,N):
    for cj in memo[i-1]:
        last3 = cj
        way = memo[i-1][cj]
        for new_c in "ATCG":
            check(last3,way,new_c,i)
su = 0
for i in memo[N-1]:
    su += memo[N-1][i]
print(su%(10**9+7))

Measured memory_bytes: 3868
import math
def judge(Y):
    year = int(Y)
    former = math.floor(year/100)
    latter = year%100
    if(former >= 1 and former <= 12):
        if(latter >= 1 and latter <= 12):
            return("AMBIGUOUS")
        elif(latter == 0 or latter > 12):
            return("MMYY")
    elif(former == 0 or former > 12):
        if(latter >= 1 and latter <= 12):
            return("YYMM")
        elif(latter == 0 or latter > 12):
            return("NA")

S = input()
print(judge(S))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll N,T;
  cin>>N>>T;
  ll ans=100000;
  for(ll i=0;i<N;i++) {
ll c,t;
    cin>>c>>t;
    if(t<=T) {
      ans=min(ans,c);
    }
  }
  
  if(ans==100000) {
cout<<"TLE"<<endl;
    return 0;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include<iostream>

int main()
{
	int r, c;
	int ans[101][101] = { 0 };
	std::cin >> r >> c;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			std::cin >> ans[i][j];
			int point = ans[i][j];
			ans[i][c] += point;
			ans[r][j] += point;
			ans[r][c] += point;
		}
	}


	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			std::cout << ans[i][j];
			if (j != c)
				std::cout << " ";
		}
		std::cout << std::endl;
	}
}

Measured memory_bytes: 3132
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> N, X, Y;
  vector<int> r(N-1, 0);

  REP(i, N)
    for (int j = i + 1; j < N; j++) {
      int mn = min(j - i, 1 + abs(i - (X-1)) + abs(j - (Y-1)));
      r[mn-1]++;
    }

  for (auto& i : r)
    cout << i << endl;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
#define A

struct card
{
	card(const card&a) {
		mark = a.mark;
		num = a.num;
	}
	card(const char* str)
	{
		*this = str;
	}
	card() {}

	char mark;
	int	num;

	void operator = (const char * str) {
		mark = str[0];
		num = str[1] - 0x30;
	}
	bool operator < ( const card & right)const {
		return num < right.num;
	}


};

template<typename T>
int bubbleSort(list<T>&arr, int n) {
	int cunt = 0;
	bool cont = true;
	while (cont)
	{
		typename	list<T>::iterator it1 = arr.begin(), it2 = arr.begin();
		advance(it2, 1);
		cont = false;
		for (int i = 1; i < n; ++i, advance(it1, 1), advance(it2, 1))
		{
			if ( *it2 < *it1 ) {
				swap(*it1, *it2);
				cont = true;
				cunt++;
			}
		}
	}
	return cunt;
}
//template int bubbleSort(list<int>&arr, int n);

template <typename T>
int selectionSort(list<T>& arr, int n) {
	int cunt = 0;
	typename list<T>::iterator it1, it2, min, itend = arr.end();
	for (it1 = arr.begin(); it1 != itend; advance(it1, 1))
	{
		min = it1;
		for (it2 = next(it1); it2 != itend; advance(it2, 1))
		{
			if (*it2 < *min)
				min = it2;
		}
		if (it1 != min) {
			cunt++;
			swap(*it1, *min);
		}
	}
	return cunt;	
}

void listPrint(list<int>& arr) {
	list<int>::iterator it = arr.begin(),itend = arr.end();
	cout << *it;
	advance(it, 1);
	for (; it != itend; advance(it, 1))
		cout << " " << *it;
	cout << endl;
}

#ifdef D
int main(void)
{
	int n;
	cin >> n;
	list<card> arr1, arr2;
	char str[3];
	for (int i = 0 ; i< n; ++i)
	{
		cin >> str;
		card c(str);
		arr1.push_back(c);
		arr2.push_back(c);
	}

	return 0;
}
#endif // D

#ifdef B
int main(void)
{
	int n;
	cin >> n;
	list<int> arr(n);
	for (auto &a : arr)
		cin >> a;
	int cunt = selectionSort(arr,n);
	listPrint(arr);
	cout <<  cunt << endl;
	return 0;
}
#endif // B

#ifdef A
int main(void)
{
	int cunt = 0;
	int n;
	cin >> n;
	list<int> arr(n);
	for (auto& a : arr)
		cin >> a;
	cunt = bubbleSort(arr, n);
	listPrint(arr);
	cout << cunt << endl;
	return 0;
}
#endif // A

Measured memory_bytes: 3088
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

#ifdef LOCAL
#include "../ACL.hpp"
#else
#include <atcoder/all>
#endif

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int k;
    cin >> k;
    REP(i,0,k) cout << "ACL";
    cout << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 3604
def resolve():
    md = 10**9+7
    N = int(input())
    dpt = [[0,0,0,0] for _ in range(N)]
    dpt[0][0]=8
    dpt[0][1]=1    
    dpt[0][2]=1
    dpt[0][3]=0

    for i in range(1,N):
        dpt[i][0] =(dpt[i-1][0]*8)%md 
        dpt[i][1] =(dpt[i-1][1]*9+dpt[i-1][0])%md
        dpt[i][2] =(dpt[i-1][2]*9+dpt[i-1][0])%md
        dpt[i][3] =(dpt[i-1][3]*10+dpt[i-1][1]+dpt[i-1][2])%md
    print(dpt[-1][-1])
resolve()


Measured memory_bytes: 238860
class PriorityQueue
  def initialize(&comp)
    @heap = []
    @node_num = 0
    if !block_given?
      @comp = lambda { |x, y| x <= y }
    else
      @comp = comp
    end
  end

  def push(x)
    i = @node_num # 自分のノード番号
    @node_num += 1
    while i > 0
      par = (i - 1) / 2 # 親のノード番号
      break if @comp.call(@heap[par], x) # 逆転してないなら抜ける
      # 親ノードを下ろして自分を上に
      @heap[i] = @heap[par]
      i = par
    end
    @heap[i] = x
  end

  alias_method(:<<, :push)

  def pop
    # 最(小|大)値
    ret = @heap[0]
    # 根にもってくる値
    @node_num -= 1
    x = @heap[@node_num]
    # 根から下ろしていく
    i = 0
    while i * 2 + 1 < @node_num
      # 子どうしを比較
      a, b = i * 2 + 1, i * 2 + 2
      a = b if b < @node_num && !@comp.call(@heap[a], @heap[b])
      break if @comp.call(x, @heap[a])
      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    return ret
  end

  def get
    @node_num == 0 ? nil : @heap[0]
  end

  def empty?
    return get.nil?
  end
end

q = PriorityQueue.new { |a, b| a[0] > b[0] }
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
a.each do |ai|
  q << [ai, 1]
end
m.times do
  b, c = gets.split.map(&:to_i)
  q << [c, b]
end
ans = 0
cnt = 0
while cnt < n
  x, y = q.pop
  if cnt + y > n
    ans += (n-cnt)*x
    break
  else
    ans += y*x
    cnt += y
  end
end
p ans


Measured memory_bytes: 28180
#include <stdio.h>

int m;
int before[20][20];
int visit_log[20];
char visited_status[20][1<<20];

int search(int pos,int idx,int visited) {
	int i;
	visit_log[idx++]=pos;
	visited|=(1<<pos);
	if(visited_status[pos][visited])return 0;
	visited_status[pos][visited]=1;
	if(visited==(1<<m)-1) {
		printf("%d\n",pos+1);
		return 1;
	}
	for(i=0;i<m;i++) {
		if((visited&(1<<i))==0) {
			int cango=1;
			int j;
			for(j=0;j<idx;j++) {
				if(before[visit_log[j]][i]!=0)cango=0;
			}
			if(cango && search(i,idx,visited)) {
				printf("%d\n",pos+1);
				return 1;
			}
		}
	}
	return 0;
}

int main(void) {
	int n;
	int i,j,k;
	/* input */
	if(scanf("%d",&m)!=1)return 1;
	if(scanf("%d",&n)!=1)return 1;
	for(i=0;i<n;i++) {
		int x,y;
		if(scanf("%d%d",&x,&y)!=2)return 1;
		before[x-1][y-1]=1;
	}
	/* suiiritu */
	for(k=0;k<m;k++) {
		for(i=0;i<m;i++) {
			for(j=0;j<m;j++) {
				if(before[i][k]!=0 && before[k][j]!=0)before[i][j]=1;
			}
		}
	}
	/* search and print */
	search(1,0,0);
	return 0;
}

Measured memory_bytes: 19992
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int N = in.nextInt();
			int M = in.nextInt();
			if(N==0) break;
			int[] h = new int[N+1];
			int[] w = new int[M+1];
			int[] hnum = new int[1500001];
			int[] wnum = new int[1500001];
			
			for(int i=1;i<=N;i++){
				h[i] = in.nextInt()+h[i-1];
			}
			for(int i=1;i<=M;i++){
				w[i] = in.nextInt()+w[i-1];
			}
			
			for(int i=1;i<=N;i++){
				for(int j=i;j<=N;j++){
					hnum[h[j]-h[i-1]] ++;
				}
			}
			for(int i=1;i<=M;i++){
				for(int j=i;j<=M;j++){
					wnum[w[j]-w[i-1]] ++;
				}
			}
			
			long ans = 0;
			for(int i=1;i<=1500000;i++){
				ans += ((long)hnum[i]) * wnum[i];
			}
			
			System.out.println(ans);
			System.gc();
		}
		
	}
}

Measured memory_bytes: 60504
alp = input()

big = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]

if alp in big:
    print("A")
else:
    print("a")

Measured memory_bytes: 9108
from collections import Counter

S = list(input())
T = list(input())

S = Counter(S).most_common()
T = Counter(T).most_common()

for i in range(len(S)):
    if S[i][1] == T[i][1]:
        continue
    else:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 6960
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    map<int, int> M;
    for(int& a:A){
        cin >> a;
        M[a]++;
        M[a+1]++;
        M[a-1]++;
    }

    int ans = 0;
    for(auto i=M.begin(); i!=M.end(); i++){
        ans = max(ans, i->second);
    }

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




Measured memory_bytes: 5120
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#pragma warning(disable : 4996)

int main(void) {
	int n;
	scanf("%d", &n);
	if (n < 2) {
		printf("1\n");
		return 0;
	}
	int f[45];
	f[0] = f[1] = 1;
	for (int i = 2; i <= n; ++i) {
		f[i] = f[i - 2] + f[i - 1];
	}
	printf("%d\n", f[n]);

	return 0;
}



Measured memory_bytes: 2744
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long int;

vector<ll> search_prime_nums(ll N) {
    vector<ll> ans;

    const int max_num = (int)ceil(sqrt(N));
    vector<bool> is_prime(max_num + 1, true);

    for (int i = 2; i <= max_num; i++) {
        if (is_prime[i]) {
            for (int j = 2 * i; j <= max_num; j += i) is_prime[j] = false;
            ans.push_back(i);
        }
    }

    return ans;
}

int main() {
    // Input
    ll N;
    cin >> N;

    // Process
    vector<ll> prime_nums = search_prime_nums(N);

    vector<int> counts;
    ll n = N;
    for (ll p : prime_nums) {
        if (n % p == 0) {
            int cnt = 0;
            while (n % p == 0) {
                n /= p;
                cnt++;
            }
            counts.emplace_back(cnt);
        }
        if (n == 1) break;
    }

    int ans = 0;
    for (int cnt : counts) {
        int tmp = cnt;
        for (int i = 1; i <= tmp; i++) {
            tmp -= i;
            ans++;
        }
    }
    if (n != 1) ans++;

    // Output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4500
N=int(input())
C,S,F=[],[],[]

for i in range(N-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

T=[0]*N
for i in range(N):
    A=0
    for j in range(i,N-1):
        if A>=S[j]:
            A=((A+F[j]-1)//F[j])*F[j]
        else:
            A=S[j]
        A+=C[j]
    T[i]=A

print("\n".join(map(str,T)))

Measured memory_bytes: 67808
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype>  // isupper, islower, isdigit, toupper, tolower
#include <cmath>   // abs, sin, cos, tan
#include <ctime>   // clock

// __builtin_popcountll

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  str s; cin >> s;
  if(s[s.size() - 1] == '?') s[s.size() - 1] = 'D';
  if(s[0] == '?'&&s.size() >= 2&&s[1] == 'D') s[0] = 'P';
  else if(s[0] == '?') s[0] = 'D';
  for(ll i = 1;i < s.size() - 1;i++)
  {
    if(s[i - 1] == 'P'&&s[i] == 'D'&&s[i + 1] == '?')
    {
      if(i != s.size() - 2&&s[i + 2] == 'P') s[i + 1] = s[i + 1] = 'D';
      else s[i + 1] = 'P';
    }
    else if(s[i] == '?') s[i] = 'D';
  }
  fin(s);
  return;
}

//前処理
int main()
{
  int ti = clock();
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  //printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
  return 0;
}

Measured memory_bytes: 4164
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
main(){
    string a,b,c;
    cin >> a >> b >> c;
    a[0] += 'A' - 'a';
    b[0] += 'A' - 'a';
    c[0] += 'A' - 'a';
    cout << a[0] << b[0] << c[0] << endl;
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;

int main()
{
    int k=0,n=0,i,ans=0,b=0;
    int a[1000000];
    scanf("%d",&k);
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    int s=a[1]-a[0];
    for(i=0;i<n-1;i++)
    {
        if(s<a[i+1]-a[i])
        {
        s=a[i+1]-a[i];
        }
    }
    b=a[0]+(k-a[n-1]);
    if(s<b)
    {
        s=b;
    }
    for(i=0;i<n-1;i++)
    {
        ans+=a[i+1]-a[i];
    }
    ans+=b;
    ans-=s;


    

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


Measured memory_bytes: 4532
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int n = 753;
    int min = 10000;

    for (int i = 0; i < s.length()-2; i++) {
      String k = s.substring(i,i+3);
      int d = Integer.parseInt(k);
      int x = Math.abs(d-n);
      min = Math.min(min,x);
    }

    System.out.println(min);

  }

}


Measured memory_bytes: 21972
#include<stdio.h>
#include<string.h>
int main()
{
	char a[500],b[500],c,d[500];
	int l,i,m=0,j;
	gets(a);
	gets(b);
	l=strlen(a);
	for(j=0;j<l;j++)
	{for(i=1;i<l;i++){
		
			
		d[i]=a[i-1];
		if(i==(l-1))
		{
			c=a[i];
			d[i]=a[i-1];
		}
	}
	d[0]=c;
	d[l]='\0';
	
	if(strcmp(d,b) == 0)
		{
			m=1;
			break;
		}
		else
		{
			for(i=0;i<l;i++)
			{
				a[i]=d[i];
			}
		}
	}
	if(m==1)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}
			


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	static boolean check(String s) {
		boolean ret = true;
		for(int i = 0; i < s.length() / 2; i++) {
			ret = ret && (s.charAt(i) == s.charAt(s.length() - 1 - i));
		}
		return ret;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = s.substring(0, (s.length() - 1) / 2);
		String u = s.substring((s.length() + 1) / 2);
		System.out.println(check(s) && check(t) && check(u) ? "Yes" : "No");
	}

}


Measured memory_bytes: 21844