akhauriyash/Code-Regression huggingface dataset:
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

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

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let n: usize;
    input!(n);
    let s = input_line_str().to_charvec();
    let mut buf = 0_isize;
    let mut ans = 0;
    for c in s {
        if c == 'I' {
            buf += 1;
        } else {
            buf -= 1;
        }
        ans = std::cmp::max(ans, buf);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d,s=0,A[210],k=1e9,a=0,t;
	cin >> n >> d;
	d -=1;
	for (int i = 1; i <= n; ++i)
	{
		A[i]=d+i;
		s += A[i];
	}

	for (int i = 1; i <= n; ++i)
	{
		t = s-A[i];
		if(k>abs(s-t))
		{
			k=abs(s-t);
			a=t;
		}
	}
	cout << a << "\n";
	return 0;
}

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

typedef long long ll;

// http://www.usaco.org/index.php?page=viewproblem2&cpid=495
// https://cses.fi/problemset/task/1740

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s; cin >> s;
    int cur = 0, res = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'R')
            cur++;
        else
            cur = 0;
        res = max(cur, res);
    }
    res = max(cur, res);
    cout << res;
}
/*

















*/


Measured memory_bytes: 3588
#include <stdio.h>
         
        int main(void){
        	int N;
          	scanf("%d",&N);
          	if(N==1||N==2||N==3||N==5||N==6||N==9||N==10||N==13||N==17){
            	printf("No\n");
            } else {
           		printf("Yes\n");
            }
        }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    string s;
    cin >> s;
    vector<int> alp(26);
    REP(i, s.size()) { alp[s[i] - 'A']++; }
    REP(i, alp.size()) {
        if (alp[i] == 2 || alp[i] == 0) {

        } else {
            std::cout << "No" << '\n';
            return 0;
        }
    }
    std::cout << "Yes" << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<set>
#include<queue>
#include<algorithm>

using namespace std;

long long p[100100],l[100100];
long long a[100100],b[100100];
int N;

struct BIT{
	int N;
	int dat[100100];
	void init(int N_){
		N=N_;
		for(int i=1;i<=N;i++) dat[i]=0;
	}
	void add(int i,int x=1){
		while(i<=N){
			dat[i]+=x;
			i+=(i&(-i));
		}
	}
	int sum(int i){
		int res=0;
		while(i>0){
			res+=dat[i];
			i-=(i&(-i));
		}
		return res;
	}
};

BIT bit;

typedef pair<long long,int> P;

P ps[100100];
priority_queue<int> que;

int perm[100100];

int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%lld",p+i);
	}
	for(int i=1;i<=N;i++) scanf("%lld",l+i);
	a[0]=0,b[0]=0;
	for(int i=1;i<=N;i++){
		a[i]=a[i-1]+p[i];
		b[i]=b[i-1]+l[i];
	}
	for(int i=1;i<=N;i++) ps[i]=P(a[i],i);
	sort(ps+1,ps+N+1);
	for(int i=1;i<=N;i++){
		long long val=ps[i].first-ps[i-1].first;
		if(val<l[i]){
			printf("-1\n");
			return 0;
		}
	}
	for(int i=1;i<=N;i++) perm[i]=ps[i].second;
//	for(int i=1;i<=N;i++) printf("%d ",perm[i]);
//	printf("\n");
	bit.init(N);
	long long ans=0;
	for(int i=1;i<=N;i++){
		ans+=(i-1-bit.sum(perm[i]));
		bit.add(perm[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int N;
int day1[1111],day2[1111];
string name[1111],sup[1111];
const int INF = 1000000007;
vector<int> G[1111];
vector<int> rG[1111];

bool used[1111];
vector<int> V[1111];
vector<int> vs;
void init(){
  for(int i=0;i<N;i++) G[i].clear();
  for(int i=0;i<N;i++) rG[i].clear();
  for(int i=0;i<N;i++) V[i].clear();  
}
int dfs(int v){
  if( used[v] ) return 0;
  int res = 0;
  used[v] = true;
  for( int to : G[v] ){
    res += dfs( to );
  }
  vs.push_back( v );
  return res + day2[v];
}
void rdfs(int v,int cnt){
  if( used[v] ) return;
  used[v] = true;
  for( int to : rG[v] ) {
    rdfs( to, cnt );
  }
  V[cnt].push_back(v);
}
int scc(){
  memset( used, 0, sizeof( used ) );
  vs.clear();
  for(int i=0;i<N;i++){
    dfs( i );
  }
  memset( used, 0, sizeof( used ) );
  reverse( vs.begin(), vs.end() );
  int cnt = 0;
  for(int v : vs ){
    if( used[v] ) continue;    
    rdfs( v, cnt++ );
  }
  return cnt;
}
void add_edge(int from,int to){
  G[from].push_back( to );
  rG[to].push_back( from );
}

int main(){
  while( cin >> N && N ){
    init();
    map<string,int> H;
    for(int i=0;i<N;i++){
      cin >> name[i] >> day1[i] >> sup[i] >> day2[i];
      H[name[i]] = i;
    }
    for(int i=0;i<N;i++)
      add_edge( H[sup[i]], H[name[i]] );

    int n = scc();
    int res = 0;
    memset( used, 0, sizeof( used ) );
    for(int i=0;i<n;i++){
      int sum = 0;
      int min_pc = INF;
      int nv = V[i].back();
      if( used[nv] ) continue;
      for( int v : V[i] ){
        sum += day2[v];
        min_pc = min( min_pc, day1[v] - day2[v] );
      }
      res += dfs(nv) + min_pc;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 3584
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int LEN = 1e5 + 5;
const int oo = 1e9;
int head[LEN];
struct edge {
    int vet, next;
} E[LEN * 2];
int i, j, k, n, m, s, t, tot;
bool checkodd, checkval;
int L[LEN], R[LEN], isodd[LEN], ans[LEN];
void add(int u, int v) {
    E[++tot] = (edge){v, head[u]};
    head[u] = tot;
}
void dfs(int u, int pre) {
    for (int e = head[u]; e != -1; e = E[e].next) {
        int v = E[e].vet;
        if (v != pre) {
            if (isodd[v] != -1 && isodd[v] != (isodd[u] ^ 1)) {
                checkodd = false;
            }
            isodd[v] = isodd[u] ^ 1;
            dfs(v, u);
            L[u] = max(L[u], L[v] - 1);
            R[u] = min(R[u], R[v] + 1);
        }
    }
    if (L[u] > R[u]) {
        checkval = false;
    }
}
void dfs2(int u, int pre) {
    for (int e = head[u]; e != -1; e = E[e].next) {
        int v = E[e].vet;
        if (v != pre) {
            L[v] = max(L[v], L[u] - 1);
            R[v] = min(R[v], R[u] + 1);
            dfs2(v, u);
        }
    }
}
void dfsans(int u, int pre) {
    for (int e = head[u]; e != -1; e = E[e].next) {
        int v = E[e].vet;
        if (v != pre) {
            if (L[v] <= ans[u] + 1 && ans[u] + 1 <= R[v]) {
                ans[v] = ans[u] + 1;
            } else {
                ans[v] = ans[u] - 1;
            }
            dfsans(v, u);
        }
    }
}
int main() {
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        head[i] = -1;
        L[i] = -oo;
        R[i] = oo;
        isodd[i] = -1;
    }
    for (int i = 1; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        add(x, y);
        add(y, x);
    }
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) {
        int x, c;
        scanf("%d %d", &x, &c);
        L[x] = R[x] = c;
        isodd[x] = c % 2;
        s = x;
    }
    checkodd = checkval = true;
    dfs(s, -1);
    if (checkodd == false || checkval == false) {
        puts("No");
        return 0;
    }
    ans[s] = L[s];
    dfsans(s, -1);
    puts("Yes");
    for (int i = 1; i <= n; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 9088
N, M = map(int, input().split())

L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

l_max = max(L)
r_min = min(R)

if l_max <= r_min:
    print(r_min - l_max + 1)
else:
    print(0)


Measured memory_bytes: 10996
r1 = r2 = 0
try:
    while 1:
        a, b, c = map(int, input().split(','))
        if a ** 2 + b ** 2 == c ** 2:
            r1 += 1
        elif a == b:
            r2 += 1
except:
    pass

print(r1)
print(r2)

Measured memory_bytes: 7508
def main():
    n, m = map(int, input().split())
    p, y = [0 for i in range(m)], [0 for i in range(m)]
    for i in range(m):
        p[i], y[i] = map(int, input().split())
    ans = solve(n, m, p, y)


def solve(n, m, p, y):
    kens = [[] for i in range(n + 1)]
    for i in range(m):
        kens[p[i]].append(y[i])
    for ken in kens:
        ken.sort()
    
    #id 生成
    ids = [{} for i in range(n + 1)]
    for indken, ken in enumerate(kens):
        for indsi, yi in enumerate(ken, 1):
            ids[indken][yi] = str(indken).zfill(6) + str(indsi).zfill(6)
    
    #出力
    for i in range(m):
        print(ids[p[i]][y[i]])

    return

if __name__ == '__main__':
    main()

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

typedef long long ll;

ll N;

int main() {
    cin >> N;

    ll ans = (N - 1) * N / 2;
    cout << ans << endl;
}

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

int gcd(int a, int b){ //a,bの最大公約数
    if(a%b==0){
        return (b);
    }
    return (gcd(b, a%b));
}

int main(){
    int k;
    cin >> k;
    long int cnt=0;

    for(int a=1; a<=k; a++){
        for(int b=1; b<=k; b++){
            for(int c=1; c<=k; c++){
                cnt += gcd(gcd(a,b),c);
            }
        }
    }

    cout << cnt << endl;
}

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

int top, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop() {
  top--;
  return S[top+1];
}

int main() {
  string in;

  int a, b;
  top = 0;

  while (cin >> in) {
    if (in[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (in[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (in[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(in.c_str()));
    }
  }

  cout << pop() << endl;

  return 0;
}


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

int n,k;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    if(k==1)cout<<0<<endl;
    else cout<<n-k<<endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static void p(String s) {System.out.println(s);}
	static Scanner sc = new Scanner(System.in);
	static int a,b,c,n,m;
	//<--main------------------------------------------------>
	public static void main(String[] args) {
		a=sc.nextInt();
		b=sc.nextInt();
		int max=Math.max(a, b);
		int min=Math.min(a,b);
		int ans=max+Math.max(max-1, min);
		p(""+ans);

	}

}


Measured memory_bytes: 21844
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>

using namespace std;

const int MAX_N = 40;
const int MAX_A = 10;
const int INF = 1000;

int N, MA, MB;
int A[MAX_N], B[MAX_N], C[MAX_N];
int dp[MAX_N + 1][MAX_N * MAX_A + 1][MAX_N * MAX_A + 1];

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

    cin >> N >> MA >> MB;

    int asum = 0;
    int bsum = 0;

    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i] >> C[i];
        asum += A[i];
        bsum += B[i];
    }

    fill(dp[0][0], dp[N][0], INF);

    dp[0][A[0]][B[0]] = C[0];
    dp[0][0][0] = 0;

    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j <= asum; j++) {
            for (int k = 0; k <= bsum; k++) {
                if (j >= A[i + 1] && k >= B[i + 1]) {
                    dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - A[i + 1]][k - B[i + 1]] + C[i + 1]);
                } else {
                    dp[i + 1][j][k] = dp[i][j][k];
                }
            }
        }
    }

    int ans = INF;

    for (int j = 1; j <= asum; j++) {
        for (int k = 1; k <= bsum; k++) {
            int cost = dp[N - 1][j][k];
            if (cost != INF && MB * j == MA * k) {
                ans = min(cost, ans);
            }
        }
    }

    if (ans == INF) {
        ans = -1;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 28736
#include <stdio.h>
#include <stdlib.h> 
#include <string.h>
 
typedef struct node {
  int key;
  struct node *next, *prev;
} Node;
 
Node *nil;
 
void make_node(void);
void insert(int);
void deleteFirst(void);
void deleteLast(void);
Node * Search(int);
void deleteNode(Node *);
void deleteKey(int);
void Print(void);
 
int main()
{
  int i, n, key;
  char command[15];
   
  scanf("%d", &n);
 
  make_node();
 
  for( i = 0 ; i < n ; i++ ){
    scanf("%s", command);
    if( command[0] == 'i' ){
      scanf("%d", &key);
      insert(key);    
    } 
    else if( command[0] == 'd' ){
      if( strlen(command) > 6 ){
    if( command[6] == 'F' ) deleteFirst();
    else if( command[6] == 'L' ) deleteLast();
      }
      else {
    scanf("%d", &key);
    deleteKey(key);
      }
    }
  }
 
  Print();            
 
  return 0;
}
 
void make_node()
{
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}
   
void insert(int key)
{
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}
 
void deleteFirst()
{
  deleteNode(nil->next);
}
 
void deleteLast()
{
  deleteNode(nil->prev);
}
 
void deleteKey(int key)
{
  deleteNode(Search(key));
}
 
void deleteNode(Node *z)
{
  if( z == nil ) return;
  z->prev->next = z->next;
  z->next->prev = z->prev;
  free(z);
}
 
Node *Search(int key)
{
  Node *v = nil->next;
  while( v != nil && v->key != key ) v = v->next;
  return v;
}
 
void Print(){
  Node *v = nil->next;
  int count=0;
   
  while(1){
    if( v == nil ) break;
    if( count++ >= 1 ) printf(" ");
    printf("%d", v->key);
    v = v->next;
  }
  printf("\n");
}

Measured memory_bytes: 31788
#include<bits/stdc++.h>
using namespace std;
#define N 200005
int a[N],b[N],tmp[N<<1];
int cnt[N<<1];
int n,m,tot;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",&a[i]),tmp[++tot]=a[i];
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	  scanf("%d",&b[i]),tmp[++tot]=b[i];
	sort(tmp+1,tmp+tot+1);
	tot=unique(tmp+1,tmp+tot+1)-tmp-1;
	for(int i=1;i<=n;i++)
	  a[i]=lower_bound(tmp+1,tmp+tot+1,a[i])-tmp;
	for(int i=1;i<=m;i++)
	  b[i]=lower_bound(tmp+1,tmp+tot+1,b[i])-tmp;
	for(int i=1;i<=n;i++)
	  cnt[a[i]]--;
	for(int i=1;i<=m;i++)
	  cnt[b[i]]++;
	for(int i=1;i<=400000;i++)
	  if(cnt[i]>0)
	  {
	  	puts("NO");
	  	return 0;
	  }
	puts("YES");
	return 0;
}

Measured memory_bytes: 4096
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
pii point[3010];
bool ex[5010][5010];
int main(){
	int n;
	while(cin>>n,n){
		if(n==0)break;
		rep(i,5010){
			rep(j,5010){
				ex[i][j]=false;

			}
		}
		memset(point, 0, sizeof(point));
		for(int i=0;i < n;i++){
			cin>>point[i].first>>point[i].second;
			ex[point[i].second][point[i].first]=true;
		}
		/*rep(i,n){
			printf("(x,y) =(%d,%d)\n",point[i].first,point[i].second);
		}*/
			int ans =0;
			for(int i=0;i < n;i++){
				for(int j=0;j < n;j++){
					if(i==j)continue;
					int dx =abs(point[j].first-point[i].first);
					int dy =abs(point[j].second-point[i].second);
					int tmp =dx*dx+dy*dy;
					if(tmp<=ans)continue;
				/*printf("(x1,y1) =(%d,%d)\n",point[i].first,point[i].second);
				printf("(x2,y2) =(%d,%d)\n",point[j].first,point[j].second);
				printf("(dx,dy) = (%d,%d)\n",dx,dy);*/
				int nx1 =point[j].first+dy;
				int ny1 =point[j].second+dx;

				int nx2 =point[i].first+dy;
				int ny2 =point[i].second+dx;
				//
				int mnx1 =(point[j].first-dy);
				int mny1 =(point[j].second-dx);

				int mnx2 =(point[i].first-dy);
				int mny2 =(point[i].second-dx);
				/*printf("(nx1,ny1) =(%d,%d)\n",nx1,ny1);
				printf("(nx2,ny2) =(%d,%d)\n",nx2,ny2);
				printf("(mnx1,mny2) =(%d,%d)\n",mnx1,mny1);
				printf("(mnx1,mny2) =(%d,%d)\n",mnx2,mny2);
				cout <<endl;*/
				if(nx1<=5000&&ny1<=5000&&nx2<=5000&&ny2<=5000&&
				   ex[ny1][nx1]&&ex[ny2][nx2]){
					ans=max(ans,tmp);
				//cout <<ans<<endl;
				continue;
			}
			if(mnx1>=0&&mny1>=0&&mnx2>=0&&mny2>=0&&
			   ex[mny1][mnx1]&&ex[mny2][mnx2]){
				ans=max(ans,tmp);
		}
	}
}
cout <<ans<<endl;
}
return 0;
}

Measured memory_bytes: 25704
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
int main(int argc,char** argv){
  int N,K;
  cin>>N>>K;
  vector<int> h(N);
  for(int i=0;i<N;i++){
    cin>>h[i];
  }
  sort(h.begin(),h.end());
  int diff=INT_MAX;
  for(int i=K-1;i<N;i++){
    diff=min(diff,h[i]-h[i-K+1]);
  }
  cout<<diff<<endl;
  return 0;
}


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

ans = float('inf')
for i in range(N - K + 1):
    ans = min(ans, A[i + K - 1] - A[i] + min(abs(A[i + K - 1]), abs(A[i])))
print(ans)


Measured memory_bytes: 14224
n=int(input())
S=[]
for i in range(n) :
    s=list(map(int,input().split()))
    S.append(s)

count=0
for i in range(n) :
    if S[i][0]==S[i][1] :
        count+=1
    if count==3 :
        print("Yes")
        exit()
    if S[i][0]!=S[i][1] :
        count=0

print("No")

Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		ans += 2 * min(x, k - x);
	}
	cout << ans << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void) {

	int i, j, n=0, l;
	char s[27];

	scanf("%s", &s);
	l = strlen(s);
	for (i = 0; i < l; i++) {
		for (j = i+1; j < l; j++) {
			if (s[i] == s[j])
				n = 1;
		}
	}

	if (n == 1) {
		printf("no\n");
	}

	else if( n==0 ){
		printf("yes\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
#define miz(x,y) x=min(x,y)
typedef long long ll;
ll inf=1e16;
ll dp[20001][256];
int main(){
	while(true){
		int N,M,c[16],x[20000];
		cin>>N>>M;
		if(N==0) break;
		rep(i,M) cin>>c[i];
		rep(i,N) cin>>x[i];
		rep(i,N+1) rep(j,256) dp[i][j]=inf;
		dp[0][128]=0;
		rep(i,N){
			rep(j,256) if(dp[i][j]!=inf){
				rep(k,M){
					int s=min(255,max(0,j+c[k]));
					miz(dp[i+1][s],dp[i][j]+(s-x[i])*(s-x[i]));
				}
			}
		}
		ll ans=inf;
		rep(j,256) miz(ans,dp[N][j]);
		cout<<ans<<endl;
	}
}

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

ll A, B, K;

int main()
{
	cin >> A >> B >> K;
	for (ll i = 0; i < K; ++i) {
		auto& a = (i & 1) ? B : A;
		auto& b = (i & 1) ? A : B;
		if ((a & 1) == 1) {
			--a;
		}
		a >>= 1;
		b += a;
	}
	cout << A << " " << B;
	return 0;
}

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

int main(){
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans = (h2-h1)*60+(m2-m1);
    ans -= k;
    cout << ans << endl;
    return 0;
}

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

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

    int card[4][13];
     for (int i=0; i<4; i++)
     {
         for(int j=0; j<13; j++)
         {
             card[i][j] = 0;
         }
     }

    char suit;
    int a;
    int num;

    char* S,H,C,D;

    for(int i; i<n; i++)
    {
        cin >> suit >> num;

       if(suit == 'S')     a = 0;
       else if(suit == 'H') a = 1;
       else if(suit == 'C') a = 2;
       else if(suit == 'D') a = 3;

       card[a][num-1] = 1;
    }

         for(int i=0; i<13; i++)
         {
             if (card[0][i] == 0) cout << "S " << i+1 << endl;
         }
           for(int i=0; i<13; i++)
         {
             if (card[1][i] == 0) cout << "H " << i+1 << endl;
         }
           for(int i=0; i<13; i++)
         {
             if (card[2][i] == 0) cout << "C " << i+1 << endl;
         }
           for(int i=0; i<13; i++)
         {
             if (card[3][i] == 0) cout << "D " << i+1 << endl;
         }

    return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;
 
int n;
const int dx[5] = {-1, 0, 0, 0, 1};
const int dy[5] = {0, -1, 0, 1, 0};
int tile[10][10];
int flip[10][10];

int get(int x, int y)
{
	int c = tile[y][x];
	rep(d, 5)
	{
		int x2 = x + dx[d];
		int y2 = y + dy[d];
		if (0 <= x2 && x2 < 10 && 0 <= y2 && y2 < 10)
		{
			c += flip[y2][x2];
		}
	}
	return c % 2;
}

void print()
{
	rep(i, 10)
	{
		rep(j, 10)
		{
			if (j == 9)
			{
				printf("%d\n", flip[i][j]);
			} else {
				printf("%d ", flip[i][j]);
			}
		}
	}
}

bool calc()
{
	for (int i=1; i<10; i++)
	{
		for (int j=0; j<10; j++)
		{
			if (get(j, i-1) != 0)
			{
				flip[i][j] = 1;
			}
		}
	}

	for (int j=0; j<10; j++)
	{
		if (get(j, 9) != 0)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	cin >> n;

	REP(n)
	{
		rep(j, 10)
		{
			rep(k, 10)
			{
				cin >> tile[j][k];
			}
		}

		for (int j=0; j<(1<<10); j++)
		{
			memset(flip, 0, sizeof(flip));
			for (int k=0; k<10; k++)
			{
				flip[0][10-k-1] = j >> k & 1;
			}
			
			if (calc())
			{
				print();
				break;
			}
		}

		/*
		//デバッグ
		rep(j, 10)
		{
			rep(k, 10)
			{
				printf("%d ", tile[j][k]);	
			}
			printf("\n");
		}
		*/
	}

    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#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")
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; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

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 ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n,m;
    cin >> n >> m;
    vector<pair<ll, ll>> c(n);
    rep0(i, n)cin >> c[i].first >> c[i].second;
    sort(all(c));
    ll cnt = 0,ans = 0;
    rep0(i, n){
        if(c[i].second + cnt >= m){
            ans += c[i].first * (m - cnt);
            break;
        }else{
            ans += c[i].first * c[i].second;
            cnt += c[i].second;
        }
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=5000+5;
int f[N],c[N];
signed main(){
	int n,mod;
	cin>>n>>mod;
	f[0]=1;
	int k=(n/2);
	for(int i=1;i<=k+1;++i)
		c[i]=i-2;
	for(int i=k+2;i<=n;++i)
		c[i]=n-i+1;
	for(int i=2;i<=n;++i)
		for(int j=c[i]+1;j<n;++j)
			f[j]+=f[j-(c[i]+1)],f[j]%=mod;
	int ans=0;
	for(int i=0;i<n;++i)
		ans=ans+1ll*f[i]*(n-i)%mod,ans%=mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#define ll long long 
#define dd double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b;
  cin>>a>>b;
  if(a>=13){
  	cout<<b<<endl;
  }
  else if(a>=6&&a<=12){
  	cout<<b/2<<endl;
  }
  else if(a<=5){
  	cout<<"0"<<endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 3656
import java.io.*;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a=scan.nextInt();
        int b=scan.nextInt();
        if(a==b)System.out.println("a == b");
        else if(a<b)System.out.println("a < b");
        else System.out.println("a > b");
    }

}


Measured memory_bytes: 26256
#include <bits/stdc++.h>
using namespace std;
// Macros for easier access
#define ll long long
#define endl '\n'
#define F first
#define S second
#define umap unordered_map
#define uset unordered_set
#define test ll cases; cin>>cases; for(ll testCase = 1; testCase <= cases; testCase++)
#define fill(name, val) memset(name, val, sizeof(name));
#define mop(a, op, b)    (a%mod op b%mod)%mod
#define precise fixed<<setprecision(50)
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define get(a, n)    for(ll it = 0; it < n; it++)    cin>>a[it];
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug(x) cerr << #x << " : " << (x) << endl
// Constants
#define MX 100001
#define mod 1000000007LL
#define inf 1000000000000000000LL
void init(){
	boost;
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

/*	Author: 🆉🅴🅽🅾🅻🆄🆂	*/

template <typename T> class SegTree{
	public:
	ll n;
	T *tree;
	T queryBase;
	T segOp(const T &left, const T &right);
	SegTree(ll len, T *arr, T qb){
		tie(n, queryBase) = tie(len, qb);
		tree = new T[4*n];
		for(ll i = 0; i < 4*n; i++)	tree[i] = queryBase;
		build(1, 0, n-1, arr);
	}
	T build(ll i, ll l, ll r, T *arr){
		if(l == r)	return tree[i] = arr[l];
		return tree[i] = segOp(build(i<<1, l, (l+r)>>1, arr), build(i<<1|1, ((l+r)>>1)+1, r, arr));
	}
	T update(ll i, const T &value, ll p = 1, ll l = 0, ll r = -1){
		if(r == -1)	r = n-1;
		if(l == r)	return tree[p] = value;
		ll m = (l+r)>>1;
		if(i <= m)	update(i, value, p<<1, l, m);	else update(i, value, p<<1|1, m+1, r);
		return tree[p] = segOp(tree[p<<1], tree[p<<1|1]);
	}
	T query(ll l, ll r, ll p = 1, ll tl = 0, ll tr = -1){
		if(tr == -1)	tr = n-1;
		if(l > r)	return queryBase;	// Overflow
		if(l == tl && r == tr)	return tree[p];	// Complete overlap
		ll m = (tl+tr)>>1;
		return segOp(query(l, min(m, r), p<<1, tl, m), query(max(l, m+1), r, p<<1|1, m+1, tr));
	}
};
template <typename T> T SegTree<T>::segOp(const T &left, const T &right){
	return max(left, right);
}

int main(){
	init();
	ll n;	cin>>n;
	ll a[n], h[n];	get(h, n);	get(a, n);
	pll b[n];	for(ll i = 0; i < n; i++)	b[i] = {h[i], i};
	sort(b, b+n);
	ll lis[n] = {0};
	SegTree<ll> s(n, lis, 0);
	for(auto x : b){
		lis[x.S] = s.query(0, x.S-1) + a[x.S];
		s.update(x.S, lis[x.S]);
	}
	cout<<*max_element(lis, lis+n);
}

Measured memory_bytes: 17720
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main()
{
	string str;
	int ans = 0;

	while (getline(cin, str))
	{
		int j = 0;
		for (int i = str.size() - 1; i >= 0; i--)
		{
			if ('0' <= str[i] && str[i] <= '9')
			{
				ans += pow(10, j) * (str[i] - '0');
				j++;
			}
			else
			{
				j = 0;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1216
function main(input) {
  input=input.trim();
  const n = parseInt(input.split(" ")[0], 10);
  const x = parseInt(input.split(" ")[1], 10);
  var arrM=[]
  for(var i=0; i<n; i++){
    var temp=parseInt(input.split("\n")[1+i], 10);
    arrM.push(temp)
  }

  var sum=0;
  for(var i=0; i<n; i++){
    sum+=arrM[i]
  }
  var ans= n+Math.floor((x-sum)/Math.min.apply(null, arrM));
  console.log(ans);
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 23092
import sys
n,u,v=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

x=bfs(u-1)
y=bfs(v-1)
ans=[]
e=[]
ct0=0
for i in range(n):
  if x[i]<y[i] and x[i]!=0:
    ct0+=1
if ct0==0:
  if x[v-1]==1:
    print(0)
  else:
    print(1)
  sys.exit()
for i in range(n):
  if x[i]<y[i]:
    if abs(x[i]-y[i])%2==0:
      if x[i]%2==1:
        ans.append(y[i]-1)
      else:
        ans.append(y[i]-1)
    else:
      ans.append(y[i]-1)
print(max(ans))

Measured memory_bytes: 87256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<int> a(9);
    rep(i,n) {
        int in;
        cin >> in;
        if (in<3200) ++a[in/400];
        else ++a[8];
    }
    int ans=0;
    rep(i,8) {
        if (a[i]>0) ++ans;
    }
    cout << max(1,ans) << ' ' << ans+a[8] << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector < pair < int, int >>A(N);

	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A[i] = make_pair(a, i + 1);
	}

	sort(A.begin(), A.end());

	for (int i = 0; i < N; i++) {
		cout << A[i].second << " ";
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)
#define MAX ((ull)(1e9)+1)

int main(){
	int n, m;
	cin >> n >> m;
	int c[m+1];
	for(int i=0; i<m+1; i++) c[i]=0;

	for(int i=0; i<n; i++){
		int k;
		cin >> k;
		for(int j=0; j<k; j++){
			int a;
			cin >> a;
			c[a]++;
		}
	}
	int cnt=0;
	for(int i=1; i<=m; i++){
		if(c[i]==n) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	static int[] parent, prenum, lowest;
	static int timer=0;
	static boolean[] visited;
	static int V;
	static boolean[][] G;
	
	static void dfs(int current, int prev) {
		prenum[current]=lowest[current]=timer;
		timer++;
		visited[current]=true;
		int next=0;
		for(int i=0; i<V; i++) {
			if(G[current][i]) {
				next=i;
				if(!visited[next]) {
					parent[next]=current;
					dfs(next, current);
					lowest[current]=Math.min(lowest[current], lowest[next]);
				}
				else if(next != prev) {
					lowest[current]=Math.min(lowest[current], prenum[next]);
				}
			}
		}

	}

	static void art_point() {
		for(int i=0; i<V; i++) {
			visited[i]=false;
		}
		timer=1;
		dfs(0, -1);
//		for(int i=0; i<V; i++) {
//			System.out.println("prenum["+i+"]="+prenum[i]+" lowest["+i+"]="+lowest[i]);
//		}
		
		Set<Integer> set=new HashSet<>();
		int np=0;
		for(int i=1; i<V; i++) {
			int p=parent[i];
			if(p==0) {
				np++;
			}
			else if(prenum[p]<=lowest[i]) {
				set.add(p);
			}
		}
		if(np>1) {
			set.add(0);
		}
		Integer[] ans=set.toArray(new Integer[0]);
		Arrays.sort(ans);
		
		for(int i=0; i<set.size(); i++) {
			System.out.println(ans[i]);
		}
		
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			V=sc.nextInt();
			int E=sc.nextInt();
			parent=new int[V];
			prenum=new int[V];
			lowest=new int[V];
			visited=new boolean[V];
			G=new boolean[V][V];
			for(int i=0; i<E; i++) {
				int s=sc.nextInt();
				int t=sc.nextInt();
				G[s][t]=G[t][s]=true;
			}
			art_point();
			
		}
	}
}


Measured memory_bytes: 200864
#include <bits/stdc++.h>
#define endl '\n'
#define _ ios::sync_with_stdio(false);cin.tie(0);

using namespace std;

int main() { _ 
    int x, y;
    cin >> x >> y;
    if(y % 2 == 1){ 
        cout << "No" << endl;
        return 0;
    }   

    if(y > 4*x or y < 2*x){
        cout << "No" << endl;
        return 0;
    }   


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

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,mx=LONG_LONG_MIN,mn=LONG_LONG_MAX;
  cin>>n;
  vector<ll>a(n);
  for(ll i=0;i<n;i++)
    cin>>a[i];
  for(ll i=0;i<n;i++)
  {
    mx=max(mx,a[i]);
  	mn=min(mn,a[i]);
  }
  ll res=LONG_LONG_MAX,index;
  for(ll i=mn;i<mx+1;i++)
  {
    ll s=0;
    for(ll j=0;j<n;j++)
    {
      s+=((a[j]-i)*(a[j]-i));
    }
    if(s<res)
    {
      res=s;
      index=i;
    }
  }
  cout<<res;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 3592
//確かめ 勉強


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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si, sj;
  cin >> si >> sj;
  int ti, tj;
  cin >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  const int INF = 1e9;
  vector<vector<int>> dist(h,vector<int>(w,INF));
  deque<P> q;
  dist[si][sj] = 0;
  q.emplace_back(si,sj);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    int d = dist[i][j];
    q.pop_front();
    //if (dist[i][j] != d) continue;ここなに
    rep(v,4) {
      int ni = i+di[v], nj = j+dj[v];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
      if (s[ni][nj] == '#') continue;
      if (dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    for (int ei = -2; ei <= 2; ++ei) {
      for (int ej = -2; ej <= 2; ++ej) {
        int ni = i+ei, nj = j+ej;
        if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
        if (s[ni][nj] == '#') continue;
        if (dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  int ans = dist[ti][tj];
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9508
#include<bits/stdc++.h>
using namespace std;
#define int long long int
// #include"../Template.cpp"

string s;
int n;

vector<int> solve(int i) {
    if(i == (n-1)) {
        vector<int> vec = {s[i]-'0'};
        return vec;
    }
    vector<int> vec;
    int no = s[i] - '0';
    for(int curr = i+1; curr < n; curr ++) {
        
        vector<int> res = solve(curr);
        for(auto j : res) {
            vec.push_back({j + no});
        }
        no = (no * 10) + (s[curr]-'0');
    }
    vec.push_back(no);
    return vec;
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    n = s.size();
    vector<int> sum = solve(0);
    int ans = accumulate(sum.begin(), sum.end(), 0LL);
    cout << ans << endl;
    return 0;
}

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

int func(long long N)
{
    int ans = 1;

    for(long long i = 2; i * i <= N; i++)
    {
        int flag = 0;

        while(N % i == 0)
            N /= i, flag = 1;
        
        if(flag)
            ans++;
    }

    if(N > 1)
        ans++;

    return ans;
}

int main() {

    long long a, b;
    cin >> a >> b;

    cout << func(__gcd(a, b)) << "\n";
    return 0;
}


Measured memory_bytes: 256
import itertools

N,M,X = map(int, input().split())

C = []
for c in range(N):
    C.append(list(map(int, input().split())))

ans = float('inf')
L = list(range(N))
for i in range(1, N+1):
    for comb in itertools.combinations(L, i):
        kingaku = 0
        TM = [0]*M
        for c in comb:
            kingaku += C[c][0]
            for i in range(1,M+1):
                TM[i-1] += C[c][i]
        isOk = True
        for m in TM:
            if m < X:
                isOk = False
                break

        if isOk:
            ans = min(ans, kingaku)

if ans == float('inf'):
    print("-1")
else:
    print(ans)

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	vector<int> vec;
	for(int i = 0; i < n; i++){
		char c;
		cin >> c;
		if(c == 'R'){
			vec.push_back(0);
		} else {
			vec.push_back(1);
		}
	}
	int start = 0;
	int end = n-1;
	int count = 0;
	while(start < end){
		if(vec[start] == 1 && vec[end] == 0){
			swap(vec[start], vec[end]);
			count++;
			start++;
			end--;
		} else if (vec[start] == 0 && vec[end] == 1){
			start++;
			end--;
		} else if (vec[start] == 0 && vec[end] == 0){
			 start++;
		} else {
			end--;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 4324
#include <stdio.h>

int board[8][8] = {{}};
int row[8] = {};
int left[15] = {};
int right[15] = {};
int down[8] ={};
 
void print(){
 
  for(int i = 0;i < 8;i++){
    for(int j = 0;j < 8;j++){
      if(board[i][j] == 1){
        if(row[i] != j) {
          return;
        }
      }
    }
  }
  for(int i = 0;i < 8;i++){
    for(int j = 0;j < 8;j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    puts("");
  }
 
}
 
void backtrack(int i){
 
  if(i == 8){
    print();
    return;
  }
 
  for(int j = 0;j < 8;j++){
    if(down[j] == 1 || left[i + j] == 1 || right[i - j + 7] == 1) continue;
 
    row[i] = j;
    left[i + j] = right[i - j + 7] = down[j] = 1;
 
    backtrack(i + 1);
 
    row[i] = down[j] = left[i + j] = right[i - j + 7] = 0;
 
  }
 
}
 
 
int main(){
 
  int r,c,k;
 
  scanf("%d",&k);
 
  for(int i = 0;i < k;i++){
    scanf("%d%d",&r,&c);
    board[r][c] = 1;
  }
  backtrack(0);
  return 0;
}

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

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    a = (a + 11) % 13;
    b = (b + 11) % 13;
    
    if (a < b) printf("Bob\n");
    else if (a > b) printf("Alice\n");
    else printf("Draw\n");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    string s;cin>>s;
    map<int,int> mp;
    rep(i,s.size()){
        mp[s[i]-'0']++;
    }
    int res=abs(mp[0]-mp[1]);
    cout<<s.size()-res<<endl;
}


Measured memory_bytes: 3764
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  int n; scanf("%d",&n);
  while(n --> 0){
    P c1, c2; double r1, r2;
    scanf("%lf%lf%lf%lf%lf%lf",&c1.real(),&c1.imag(),&r1,&c2.real(),&c2.imag(),&r2);
    double dist = abs(c1 - c2);
    if(r1 > dist + r2) puts("2");
    else if(r2 > dist + r1) puts("-2");
    else if(r1 + r2 + EPS >= dist) puts("1");
    else puts("0");
  }
  return 0;
}

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

using namespace std;

const int64_t INF = INT64_C(1) << 60;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, P;
  cin >> N >> M >> P;
  vector<vector<pair<int, int>>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--, c -= P;
    G[a].emplace_back(make_pair(b, c));
  }
  vector<int64_t> T(N, -INF);
  T[0] = 0;
  for (int k = 0; k < N; k++) {
    for (int u = 0; u < N; u++) {
      for (auto g : G[u]) {
        int v = g.first, d = g.second;
        if (T[u] != -INF) chmax(T[v], T[u] + d);
      }
    }
  }
  vector<int64_t> used(N, false);
  for (int k = 0; k < N; k++) {
    for (int u = 0; u < N; u++) {
      for (auto g : G[u]) {
        int v = g.first, d = g.second;
        if (T[u] != -INF && (used[u] || chmax(T[v], T[u] + d))) {
          used[v] = true;
        }
      }
    }
  }
  cout << (used[N - 1] ? -1 : max(INT64_C(0), T[N - 1])) << '\n';
  return 0;
}


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

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define MAX 100005
#define INF 1001001001

int n;
vector<int> par, ranks, weight;

void init(int n) {
  ranks.assign(n,0);
  weight.assign(n,0);
  par.resize(n);
  iota(par.begin(), par.end(), 0);
}

int root(int x) {
  if (par[x] == x) return x;
  int rx = root(par[x]);
  weight[x] += weight[par[x]];
  return par[x] = rx;
}

bool isSame(int x, int y) {
  return root(x) == root(y);
}

int getWeight(int x) {
  root(x); // 経路圧縮
  return weight[x];
}

int getDiff(int x, int y) {
  return getWeight(y) - getWeight(x);
}

bool merge(int x, int y, int w) {
  int rx = root(x);
  int ry = root(y);
  if (rx == ry) return false;

  int rw = w;
  rw += getWeight(x);
  rw -= getWeight(y);

  if (ranks[rx] < ranks[ry]) swap(rx,ry), rw = -rw;
  par[ry] = rx;
  weight[ry] = rw;
  if (ranks[rx] == ranks[ry]) ranks[rx]++;

  return true;
}

int main(int, char**)
{
  cin >> n;
  init(n);

  int q; cin >> q;
  vector<int> ans;
  rep(i,q) {
    int command;
    cin >> command;
    if (command == 0) {
      int x, y, z;
      cin >> x >> y >> z;
      merge(x,y,z);
    } else {
      int x, y;
      cin >> x >> y;
      if (isSame(x,y)) ans.push_back(getDiff(x,y));
      else ans.push_back(INF);
    }
  }
  for (auto a : ans) 
    if (a!=INF) cout << a << endl;
    else cout << "?" << endl;

  return 0;
}



Measured memory_bytes: 4640