akhauriyash/Code-Regression huggingface dataset:
/**
 * 	author: MahfuzAhmed
 * 	created: 08.08.2019 
**/

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define forn(var,from,to) for(int var=(from);var<(to);var++)
#define forx(var,from,to) for(int var=(from);var<=(to);var++)
#define fory(var,from,to) for(int var=(from);var>=(to);var--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(p) p.begin(),p.end()
typedef long long ll;
//~ const double pi = 2*acos(0.0);
//~ const long long mod = 1e9+7;
//~ const int MAX_N = 1e6+5;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
       
    #ifdef _DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    
    string s; cin >> s;
    
    set<int> n;
    
    for(char a: s){
        n.insert(a);
    }
    
    if(n.size() == 2)
        cout << "Yes\n";
    else
        cout << "No\n";
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int h,w,s,t;
  cin>>h>>w>>s>>t;

  auto YES=[](){cout<<"Yes"<<endl;exit(0);};
  auto NO=[](){cout<<"No"<<endl;exit(0);};
  if(h==1){
    if(s==1||s==w) YES();
    NO();    
  }
  if(w==1){
    if(t==1||t==h) YES();
    NO();
  }
  if(h%2==0||w%2==0) YES();
  if((s+t)%2==0) YES();
  NO();
  return 0;
}



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


#define ll          long long
#define uint        unsigned int 
#define ld          long double
#define SAM         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define mod         1000000007
#define mxn         200005
#define pb          push_back
#define pii         pair<int,int>
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define all(x)      x.begin(),x.end()

using namespace std;



int main()
{
    SAM;
    int n;
    cin>>n;
    if(n%1000==0)
        cout<<"0";
    else
    {
        int k=n%1000;
        cout<<1000-k;
    }
    
    return 0;
}




Measured memory_bytes: 3644
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const int INF = 1e9+1;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}

string S;
ll K;
//文字iはn日後にi^nの大きさになる
ll day = 5000000000000000;

int main() {
    cin >> S;
    cin >> K;
    int i = 0;
    if (K <= 100) {
        bool flag = true;
        for (int i = 0; i < K; i++) {
            if (S[i] != '1') flag = false;
        }
        if (flag) {
            cout << "1\n";
            return 0;
        }
    }
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#n=int(input())
n,k=map(int,input().split())
A = list(map(lambda x:int(x)-1,input().split()))
v = [-1 for _ in range(n)]
v[0] = 0
x = 0
i = 0
flag = False
while True:
    i+=1
    y = A[x]
    k-=1
    if k==0:
        break
    if not flag and v[y]>=0:
        flag = True
        t = i-v[y]
        k%=t
        x=y
        if k==0:
            print(y+1)
            exit(0)
    else:
        v[y]=i
        x=y
print(y+1)


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

int main(){
  string s;
  cin >> s;
  int ans = 100000;
  int num = atoi(s.c_str());
  for(int i=0;i<s.size()-2;i++){
    string str = s.substr(i,3);
    int x = atoi(str.c_str());
    if(abs(753-x)<ans){
      ans = abs(753-x);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
'''
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']

for i in range(len(s)):
    if (i+1) % 2 == 1:
        if s[i] not in odd:
            print('No')
            exit(0)
    else:
        if s[i] not in even:
            print('No')
            exit(0)

print('Yes')

'''

odd = s[::2]
even = s[1::2]

if 'L' in odd or 'R' in even:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 38384
N, M = map(int,input().split())
Hn = list(map(int,input().split()))
res = [True]*N
for m in range(M):
  A, B = map(int,input().split())
  A = A - 1
  B = B - 1
  if Hn[A] > Hn[B]:
    res[B] = False
  elif Hn[A] < Hn[B]:
    res[A] = False
  else:
    res[A] = False
    res[B] = False

ans = 0
for r in res:
  if r is True:
    ans += 1
print(ans)


Measured memory_bytes: 20132
m[]={2189,89,1232,866,1796,2603},a,b,c,r;main(d){char s[9];for(;~scanf("%s",s);r+=a%3?b%3?(b+6-a)%6<3?2:5:3+!b:a?6:1)*s<65?printf(r?"%d\n":0,r),a=c=r=0,b=1:*s%6-4?d=(*s-78?*s%5-1:0)+c&3,a=m[a]>>3*d&7,b=m[b]>>3*d&7:(c+=*s+3);}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, XYH):
    XYH.sort(key=lambda x: x[2], reverse=True)
    MM = 101
    M = [[1] * MM for _ in range(MM)]
    for r, (x, y, h) in enumerate(XYH):
        if h == 0:
            M[x][y] = 0
            continue
        for i in range(MM):
            for j in range(MM):
                t = abs(i-x) + abs(j - y) + h
                if r == 0:
                    M[i][j] = t
                else:
                    if M[i][j] != t:
                        M[i][j] = 0

    

    for i in range(MM):
        for j in range(MM):
            if M[i][j] != 0:
                if i > 0 and M[i-1][j] != 0:
                    continue
                if i < MM -1 and M[i+1][j] != 0:
                    continue
                if j > 0 and M[i][j-1] != 0:
                    continue
                if j < MM -1 and M[i][j+1] != 0:
                    continue
                return '%d %d %d' % (i, j, M[i][j])

    assert False


def main():
    N = read_int()
    XYH = [read_int_n() for _ in range(N)]
    print(slv(N, XYH))


if __name__ == '__main__':
    main()


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

int main() {
  int x;cin>>x;
  while(1){
    bool ans=true;
    for(int i=2;i<x;i++){
      if(x%i==0)ans=false;
    }
    if(ans)break;
    x++;
  }
  cout<<x<<endl;
}

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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n;

	s = "No";
	rep(i, n){
		rep(j, n){
			if(4*i+7*j == n) s = "Yes";
		}
	}
	cout << s << endl;
}	

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N, D;
  IN(N,D);
  vvll X(N, vll(D));
  REP(i,N){
    REP(j,D) IN(X[i][j]);
  }

  ll ans = 0;
  REP(i,N){
    FOR(j,i+1,N){
      ll tmp = 0;
      REP(k,D) tmp += (X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      ll tmp_sqrt = (ll)sqrt(tmp);
      if(tmp_sqrt*tmp_sqrt==tmp) ans++;
    }
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] x = new int[n];
		for(int i = 0; i < n; i++){
			x[i] = sc.nextInt();
		}
		int ans = 1000000000;
		for(int i = 0; i+k-1 < n; i++){
			int work;
			if(x[i] < 0 && x[i+k-1] > 0){
				work = Math.min(Math.abs(x[i]),Math.abs(x[i+k-1]))*2+Math.max(Math.abs(x[i]),Math.abs(x[i+k-1]));
			}else{
				work = Math.max(Math.abs(x[i]),Math.abs(x[i+k-1]));
			}
			ans = Math.min(ans,work);
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 50560
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    long long n,q;
    cin>>n>>q;
    vector < vector<int> > a(n);
    while(q--)
    {
        int b;
        cin>>b;
        if(b==0)
        {
           long long t,x;
           cin>>t>>x;
           a[t].push_back(x);
        }
        else if(b==1)
        {
            long long t;
            cin>>t;
            if(!a[t].empty())
            {
                long long i=a[t].size()-1;
                cout<<a[t][i]<<endl;
            }
        }
        else
        {
            long long t;
            cin>>t;
            if(!a[t].empty())
            {
                a[t].pop_back();
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3824
#include <stdio.h>

int f[50];

int dp(int n)
{
  if (n == 0 || n == 1)
    return f[n] = 1;
  if (f[n])
    return f[n];
  else
    return f[n] = dp(n-1) + dp(n-2);
}

int main(void)
{
  int n;
  scanf("%d", &n);
  printf("%d\n", dp(n));
}



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

struct Benri {
    Benri() {
        std::cin.tie(0); ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
    }
} benri;
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; }

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
#define MOD2 998244353




int main() {
    int N,M; cin >> N >>M;
    vi d(M,0);
    rep(i,N){
        int K; cin >> K;
        rep(j,K){
            int a; cin >> a; a--;
            d[a]++;
        }
    }
    int ans = 0;
    rep(i,M) if(d[i]== N) ans ++;
    cout << ans << endl;

}




Measured memory_bytes: 256
import numpy as np
H, W = map(int, input().split())
mp = np.array([list(input()) for _ in range(H)], dtype=str)

import queue
q = queue.Queue()
visit = (mp == "#")

def can_visit(x, y):
    """訪問可能ならTrue。壁、既訪問、世界外ならFalse"""
    if x < 0 or y < 0 or x >= W or y >= H:
        return False
    return not visit[y, x]

def push_neighbor(x, y, d):
    """隣接マスをキューにpush"""
    lis = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
    for nx, ny in lis:
        if can_visit(nx, ny):
            q.put((nx, ny, d+1))
            visit[ny, nx] = True

def furthest(sx, sy):
    """位置(sx, sy)から見て一番遠い場所までの距離"""
    # 初期化
    global visit
    visit = (mp == "#")
    if visit[sy, sx]:# 例外処理(スタート地点が壁の中)
        return 0
    visit[sy, sx] = True# 初期位置は訪問済み
    # 計算
    q.put((sx, sy, 0))
    while not q.empty():
        x, y, d = q.get()
        push_neighbor(x, y, d)
    return d

dist = max([furthest(sx, sy) for sx in range(W) for sy in range(H)])
print(dist)

Measured memory_bytes: 14192
/**
 * @Author:      H S-J
 * @DateTime:    2018-01-07 20:01:27
 * @Description: 
 */
#include <bits/stdc++.h>
using namespace std;
#define MST(a, b) memset(a, b, sizeof(a));
#define CLR(a) MST(a, 0);
#define DBG(x) cout << '#' << " = " << (x) << endl;
#define ALL(x) x.begin(), x.end()
#define INS(x) inserter(x, x.begin())
#define lson(x) (x) << 1
#define rson(x) (x) << 1|1
#define pb push_back
#define rep(x, y, z) for (int x = y; x < z; ++x)
#define ech(x, y, z) for (auto x = z.begin(), y = z.end(); x != y; ++x)
#define lowbit(x) (x & (-x))
#define opr operator
#define _st first
#define _nd second
#define prior_q1(x) priority_queue<x>
#define prior_q2(x) priority_queue<x, vector<x>, greater<x> >
typedef long long LL;
typedef stringstream strstm;
struct FastIO {
    static const int S = 1310720;
    int wpos;
    char wbuf[S];
    FastIO() : wpos(0) {}
    inline int xchar() {
        static char buf[S];
        static int len = 0, pos = 0;
        if (pos == len)
            pos = 0, len = fread(buf, 1, S, stdin);
        if (pos == len) return -1;
        return buf[pos ++];
    }
    inline int xuint() {
        int c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x;
    }
    inline int xint() {
        int s = 1, c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        if (c == '-') s = -1, c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x * s;
    }
    inline LL xlongint() {
        LL s = 1, c = xchar(), x = 0;
        while (c <= 32) c = xchar();
        if (c == '-') s = -1, c = xchar();
        for (; '0' <= c && c <= '9'; c = xchar()) x = x * 10 + c - '0';
        return x * s;
    }
    inline void xstring(char *s) {
        int c = xchar();
        while (c <= 32) c = xchar();
        for (; c> 32; c = xchar()) * s++ = c;
        *s = 0;
    }
    inline void wchar(int x) {
        if (wpos == S) fwrite(wbuf, 1, S, stdout), wpos = 0;
        wbuf[wpos ++] = x;
    }
    inline void wint(LL x) {
        if (x < 0) wchar('-'), x = -x;
        char s[24];
        int n = 0;
        while (x || !n) s[n ++] = '0' + x % 10, x /= 10;
        while (n--) wchar(s[n]);
    }
    inline void wstring(const char *s) {
        while (*s) wchar(*s++);
    }
    ~FastIO() {
        if (wpos) fwrite(wbuf, 1, wpos, stdout), wpos = 0;
    }
} io;
const LL maxn = 1e6 + 111;
LL a[maxn], b[maxn];
int main(int argc, char const *argv[]) {
    ios::sync_with_stdio(0);cin.tie(0);
    int n, h; cin >> n >> h;
    rep(i, 0, n) cin >> a[i] >> b[i];
    LL max_a = *max_element(a, a + n);
    sort(b, b + n, [](LL vala, LL valb) {
        return vala > valb;
    });
    LL ans = 0;
    rep(i, 0, n) {
        if(max(a[i], b[i]) >= max_a) {
            h -= max(a[i], b[i]);
            ++ans;
        }
        if(h <= 0) {
            goto nest;
        }
    }
    if(h < max_a) ++ans;
    else {
        if(h%max_a == 0)
            ans += h/max_a;
        else {
            ans += h/max_a;
            ++ans;
        }
    }
    nest:
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7168
n, k = map(int,input().split())
d = list(map(str,input().split()))

ans = n
f = 0
while True:
    ansstr = list(str(ans))
    l = len(ansstr)
    cnt = 0
    for i in range(l):
        if ansstr[i] in d:
            break
        else:
            cnt += 1
            if cnt == l:
                f = 1
                break

    if f:
        break

    ans += 1

print(ans)


Measured memory_bytes: 46172
#include<stdio.h>
int main(){
  int s[100][5],i,j,n,max,min,sum;
  while(1){
    max=0;
    min=500;
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      sum=0;
      for(j=0;j<5;j++){
	scanf("%d",&s[i][j]);
	sum+=s[i][j];
      }
      if(max<sum)max=sum;
      if(min>sum)min=sum;
    }
    printf("%d %d\n",max,min);
  }
  return 0;
}

Measured memory_bytes: 1028
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        int b = sc.nextInt();
        String c[] = new String[a];
        String cc[][] = new String[a][b];
        int tate[] = new int[a];
        int yoko[] = new int[b];
        Arrays.fill(tate,0);
        Arrays.fill(yoko,0);
        int i,j;
      	for(i = 0;i < a;i++){
          c[i] = sc.next();
          cc[i] = c[i].split("");
        }
        for(i = 0;i < a;i++){
          for(j = 0;j < b;j++){
            if(cc[i][j].equals("#")){
            tate[i] = 1;
            yoko[j] = 1;
            }
          }
        }
      	for(i = 0;i < a;i++){
          if(tate[i] == 1){
          	for(j = 0;j < b;j++){
            	if(yoko[j] == 1){
             		 System.out.print(cc[i][j]);
           		}
          	}
          System.out.println("");            
          }
        }
    }
}

Measured memory_bytes: 40004
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define ll long long

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


//naosu
long int gcd(long int a,long int b){
  long int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

int upll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;
}

int downll(const void*a, const void*b){
  return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;
}

void sortup(ll*a,int n){
  qsort(a,n,sizeof(ll),upll);
}

void sortdown(ll*a,int n){
  qsort(a,n,sizeof(ll),downll);
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}


long int lcm(long int a,long int b){
  return a/gcd(a,b)*b;
}


long int f(long int n,long int c,long int d){
  long int cnt=n/c+n/d-n/lcm(c,d);
  return n-cnt;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  char s[100];
  scanf("%s",s); 
  
  if(s[2]==s[3] && s[4]==s[5]){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 1640
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

bool dp[81][81][26000];
int A[81][81], B[81][81];
bool used[81][81];

int H, W;

void bfs() {
    queue<pair<int, int>> q;
    q.emplace(0, 0);
    dp[0][0][80] = true;

    while(!q.empty()) {
        auto p = q.front(); q.pop();
        int x = p.fi, y = p.se;
        if (x >= W || y >= H || used[y][x]) continue;
        used[y][x] = true;

        int c1 = A[y][x] - B[y][x], c2 = -c1;
        c1 += 80; c2 += 80;

        REP(i, 26000) {
            if (!dp[y][x][i]) continue;

            dp[y + 1][x][i + c1] = true;
            dp[y + 1][x][i + c2] = true;
            dp[y][x + 1][i + c1] = true;
            dp[y][x + 1][i + c2] = true;
        }

        q.emplace(x, y+1);
        q.emplace(x+1, y);
    }
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    cin >> H >> W;

    REP(h, H) REP(w, W) cin >> A[h][w];
    REP(h, H) REP(w, W) cin >> B[h][w];

    bfs();

    int ans = inf;
    REP(i, 26000) {
        if (dp[H][W-1][i]) {
            ans = min(ans, abs(i - 80 * (H + W)));
        }
    }

    print(ans);
}


Measured memory_bytes: 111592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
	cin >> N;
	bool flag;
	flag = false;
	
	for(int i=0;i<3;i++){
		int cf;
		cf = N%10;
		if(cf == 7){
			flag = true;
			break;
			}
		else{
			N = N/10;
			}
	}
	
	if(flag == true){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}


}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(n) for(int i=0;i<n;i++)

double abs(double x){
	if(x>0) return x;
	else return -x;
}

int main(void){
	int q; cin >> q;
	rep(q){
		double xp0, yp0, xp1, yp1; cin>>xp0>>yp0>>xp1>>yp1;
		double xp2, yp2, xp3, yp3; cin>>xp2>>yp2>>xp3>>yp3;
		double t0 = (xp2-xp3)*(yp0-yp2) - (yp2-yp3)*(xp0-xp2);
		double t1 = (xp2-xp3)*(yp1-yp2) - (yp2-yp3)*(xp1-xp2);
		double t2 = (xp0-xp1)*(yp2-yp0) - (yp0-yp1)*(xp2-xp0);
		double t3 = (xp0-xp1)*(yp3-yp0) - (yp0-yp1)*(xp3-xp0);
		double o1 = (xp0+xp1)/2; double o2 = (xp2+xp3)/2; double o3 = (yp0+yp1)/2; double o4 = (yp2+yp3)/2;
		double r1 = abs(xp0-xp1)/2; double r2 = abs(xp2-xp3)/2; double r3 = abs(yp0-yp1)/2; double r4 = abs(yp2-yp3)/2;
		int ret = 0;
		// parallel
		if((t0==0 && t1==0) || (t2==0 && t3==0)){
			if(abs(o1-o2) <= (r1+r2) && abs(o3-o4) <= (r3+r4)) ret = 1;
		}else{
			if(t0*t1 <= 0 && t2*t3 <= 0) ret = 1;
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    hash<string> hs;

    set<int> ss;
    for (int i = 0; i < n; i++) {
        if (as[i] == 0) {
            ss.insert(hs("0"));
            continue;
        }
        string t = "";
        for (int j = i; j < n; j++) {
            t += as[j] + '0';
            ss.insert(hs(t));
        }
    }

    for (int i = 0;; i++) {
        if (!ss.count(hs(to_string(i)))) {
            cout << i << endl;
            return 0;
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++) cin >> h[i];
  int res = 0;
  while (true) {
    if (*max_element(h.begin(), h.end()) == 0) break;
    int i = 0;
    for (;i < N;) {
      if (h[i] == 0) i++;
      else {
        while (h[i] > 0 && i < N) {
          h[i]--;
          i++;
        }
        res++;
      }
    }
  }
  cout << res <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<int> A;
	vector<int> B;
	int INF = (int)1 << 50;

	A.push_back(-INF);
	B.push_back(-INF);
	
	int a;
	for (int i = 0; i < N; i++) {
		cin >> a; A.push_back(a);
	}
	for (int i = 0; i < M; i++) {
		cin >> a; B.push_back(a);
	}

	A.push_back(INF);
	B.push_back(INF);
	vector<int> res(Q);
	for (int i = 0; i < Q; i++) {
		cin >> a;
		res[i] = INF;

		{
			int ans = 0;
			int t1 = *(--lower_bound(A.begin(), A.end(), a));
			ans += abs(a - t1);
			int t2 = *(--lower_bound(B.begin(), B.end(), t1));
			ans += abs(t1 - t2);
			res[i] = min(res[i], ans);
		}
		{
			int ans = 0;
			int t1 = *(--lower_bound(A.begin(), A.end(), a));
			ans += abs(a - t1);
			int t2 = *lower_bound(B.begin(), B.end(), t1);
			ans += abs(t1 - t2);
			res[i] = min(res[i], ans);
		}
		{
			int ans = 0;
			int t1 = *lower_bound(A.begin(), A.end(), a);
			ans += abs(a - t1);
			int t2 = *(--lower_bound(B.begin(), B.end(), t1));
			ans += abs(t1 - t2);
			res[i] = min(res[i], ans);
		}
		{
			int ans = 0;
			int t1 = *lower_bound(A.begin(), A.end(), a);
			ans += abs(a - t1);
			int t2 = *lower_bound(B.begin(), B.end(), t1);
			ans += abs(t1 - t2);
			res[i] = min(res[i], ans);
		}


		{
			int ans = 0;
			int t1 = *(--lower_bound(B.begin(), B.end(), a));
			ans += abs(a - t1);
			int t2 = *(--lower_bound(A.begin(), A.end(), t1));
			ans += abs(t1 - t2);
			res[i] = min(res[i], ans);
		}
		{
			int ans = 0;
			int t1 = *(--lower_bound(B.begin(), B.end(), a));
			ans += abs(a - t1);
			int t2 = *lower_bound(A.begin(), A.end(), t1);
			ans += abs(t1 - t2);
			res[i] = min(res[i], ans);
		}
		{
			int ans = 0;
			int t1 = *lower_bound(B.begin(), B.end(), a);
			ans += abs(a - t1);
			int t2 = *(--lower_bound(A.begin(), A.end(), t1));
			ans += abs(t1 - t2);
			res[i] = min(res[i], ans);
		}
		{
			int ans = 0;
			int t1 = *lower_bound(B.begin(), B.end(), a);
			ans += abs(a - t1);
			int t2 = *lower_bound(A.begin(), A.end(), t1);
			ans += abs(t1 - t2);
			res[i] = min(res[i], ans);
		}




	}
	
	for (int i = 0; i < Q; i++) {
		cout << res[i] << endl;
	}
}

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

int main() {
	constexpr int INF = 1<<20;
	constexpr int dx[4] = {1, 0, -1, 0};
	constexpr int dy[4] = {0, 1, 0, -1};

	int H, W;
	cin >> H >> W;
	vector<string> S(H, "");
	for(int i=0; i<H; i++) cin >> S[i];
	
	vector<vector<int>> d(H*W, vector<int>(H*W, INF));
	for(int i=0; i<H*W; i++) d[i][i] = 0;

	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(S[i][j] == '#') continue;
			for(int k=0; k<4; k++){
				int nx = dx[k] + i;
				int ny = dy[k] + j;
				if(nx <= -1 || ny <= -1 || nx >= H || ny >= W || S[nx][ny] == '#') continue;
				d[i*W+j][nx*W+ny] = 1;
				d[nx*W+ny][i*W+j] = 1;
			}
		}
	}

	auto warshall_floyd = [](vector<vector<int>> &d){
		for(int k=0; k<d.size(); k++){
			for(int i=0; i<d.size(); i++){
				for(int j=0; j<d.size(); j++){
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
	};

	warshall_floyd(d);

	int ans = 0;
	for(int i=0; i<H*W; i++){
		for(int j=0; j<H*W; j++){
			if(d[i][j] == INF || i == j) continue;
			ans = max(ans, d[i][j]);
		}
	}	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> ls(N);
    for (int i = 0; i < N; ++i) {
        cin >> ls[i];
    }
    sort(ls.begin(), ls.end());
    size_t count = 0;
    for (auto ia = ls.begin(); ia != ls.end(); ++ia) {
        for (auto ib = ia+1; ib != ls.end(); ++ib) {
            const int lb = *ib-*ia+1;
            const int ub = *ia+*ib-1;
            count += upper_bound(ib+1, ls.end(), ub) - lower_bound(ib+1, ls.end(), lb);
        }
    }
    
    cout << count << '\n';
}



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

int main() {
  int N; cin >> N;
  
  int answer = 0;
  
  for (int i = 1; i <= N; i += 2) {
    int divisor = 0;
    for (int j = 1; j <= N; j++) if (i % j == 0) divisor++;
    if (divisor == 8) answer++;
  }
  
  cout << answer << endl;
}

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

using namespace std;
const int maxn = 1<<19;
int W,H,N;
int ans = 0;
struct node{
	int x,y;
}pt[maxn];
bool cmp(node aa,node bb) {
	return aa.x < bb.x;
}
struct seg {
	seg *ls,*rs;
	int mx,laz;
}z[maxn<<1],*tl,*rt;
int sgtot;

int sl[maxn],sr[maxn],XX[maxn],tot;
int TL,TR,stl[maxn],str[maxn];

void ptd(seg *&p) {
	if(!p->laz) return;
	p->ls->laz += p->laz;
	p->rs->laz += p->laz;
	p->ls->mx += p->laz;
	p->rs->mx += p->laz;
	p->laz = 0;
	return;
}

void maketree(seg *&p,int l,int r) {
	p = &z[++sgtot];
	p->laz = 0;
	if(l==r) {
		p->mx = -XX[l];
		return;
	}
	int mid = (l+r)>>1;
	maketree(p->ls,l,mid);
	maketree(p->rs,mid+1,r);
	p->mx = max(p->ls->mx,p->rs->mx);
}

void change(seg *&p,int l,int r,int x,int y,int d) {
	if(x<=l&&r<=y) {
		p->mx += d; p->laz += d;
		return;
	}
	int mid = (l+r)>>1;
	ptd(p);
	if(y<=mid) change(p->ls,l,mid,x,y,d);
	else if(x>mid) change(p->rs,mid+1,r,x,y,d);
	else change(p->ls,l,mid,x,y,d),change(p->rs,mid+1,r,x,y,d);
	p->mx = max(p->ls->mx,p->rs->mx);
}

int query(seg *&p,int l,int r,int x,int y) {
	if(x<=l&&r<=y) return p->mx;
	int mid = (l+r)>>1;
	ptd(p);
	if(y<=mid) return query(p->ls,l,mid,x,y);
	else if(x>mid) return query(p->rs,mid+1,r,x,y);
	else return max(query(p->ls,l,mid,x,y),query(p->rs,mid+1,r,x,y));
}

void solve() {
	tl = z; tot = 0;
	TL = TR = 0;
	int ZJ = (H/2);
	sort(pt+1,pt+1+N,cmp);
	
	for(int i=1,j=1;i<=N;i=j) {
		++tot; XX[tot] = pt[i].x;
		sl[tot] = ZJ; sr[tot] = H-ZJ;
		while(j<=N&&pt[i].x==pt[j].x) {
			if(pt[j].y<=ZJ) {
				sl[tot] = min(sl[tot],ZJ-pt[j].y);
			}
			if(pt[j].y>=ZJ) {
				sr[tot] = min(sr[tot],pt[j].y-ZJ);
			}
			j++;
		}
	}
	maketree(rt,1,tot);
	for(int i=1;i<=tot;i++) {
		if(i!=1) {
			ans = max(ans,rt->mx+XX[i]);
			ans = max(ans,H+XX[i]-XX[i-1]);
		}
		while(TL>1&& sl[ stl[TL] ] > sl[i] ) {
			change(rt,1,tot,stl[TL-1],stl[TL]-1,-sl[stl[TL]]);
			TL--;
		}
		while(TR>1&& sr[ str[TR] ] > sr[i] ) {
			change(rt,1,tot,str[TR-1],str[TR]-1,-sr[str[TR]]);
			TR--;
		}
		if(TL>0) change(rt,1,tot,stl[TL],i-1,sl[i]);
		if(TR>0) change(rt,1,tot,str[TR],i-1,sr[i]);
		stl[++TL] = i; str[++TR] = i;
	}
}

int main() {
	scanf("%d%d%d",&W,&H,&N);
	for(int i=1;i<=N;i++) {
		scanf("%d%d",&pt[i].x,&pt[i].y);
	}
	
	pt[++N] = (node) {0,0};
	
	pt[++N] = (node) {0,H};
	pt[++N] = (node) {W,0};
	
	pt[++N] = (node) {W,H};
	
	solve();
	for(int i=1;i<=N;i++) swap(pt[i].x,pt[i].y);
	swap(H,W);
	solve();
	printf("%d",ans*2);
}

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

signed main(){
    int n;
    cin>>n;
    vector<int> L(n);
    int su = 0;
    for(int i=0;i<n;i++){
        cin>>L[i];
        su += L[i];
    }
    sort(L.begin(),L.end());
    if(2*L[n-1] < su ){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
  int N;
  cin>>N;
  int ans=0;
  
  for(int i=1;;i++){
    if(i*i>N){
      ans=(i-1)*(i-1);
      break;
    }
  }
      cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int bubbleSort(int A[],int N) {
	int sw = 0;
	bool flag = 1;
	for(int i=0; flag; i++) {
		flag = 0;
		for(int j=N-1; j>=i+1; j--) {
			if(A[j] < A[j-1]) {
				swap(A[j], A[j-1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void) {
	int A[100], N, sw;
	cin >> N;
	for(int i=0;i<N; i++) cin >> A[i];

	sw = bubbleSort(A,N);

	for(int i = 0; i < N; i++) {
		if(i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a,ll b);

int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll g=c/gcd(c,d)*d;
  ll x=b/c-(a-1)/c;
  ll y=b/d-(a-1)/d;
  ll z=b/g-(a-1)/g;
  cout<<(b-a+1)-x-y+z<<endl;
  return(0);
}

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


Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]
flag = True
used = []
used.append(w[0])
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        flag = False
    elif w[i][-1] == w[i+1][0]:
        if w[i+1] not in used:
            used.append(w[i+1])
        else:
            flag = False
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
function main(input) {
  var N = input[0].split(" ")[0]-0;
  var K = input[0].split(" ")[1]-0;
  var ans = input[1].split(" ").map(v=>v-0).sort((a,b)=>b-a).filter((v,i)=>i<K).reduce((a,b)=>a+b);
  
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include <bits/stdc++.h>
    using namespace std;
     
	int price,hour,kotei;


    int main() {
      cin >> price >> hour >> kotei;
      
      if(price * hour <= kotei) {
        cout << price * hour << endl;
      }
      else if (price * hour == kotei) {
        cout << kotei << endl;
      }
      else {
        cout << kotei << endl;
      }  
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
//#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
const lli INF = 1e18L+5;
/*
lli power(lli x,lli y)
{
    lli res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}
*/
int main()
{
//cout.precision(10);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   //freopen("input1.txt","r",stdin);
   //freopen("outputmid1.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
		string s;
		cin>>s;
		int flag=0;
		for(lli i=1;i<=s.size();i++)
		{
			if((s[i-1]=='R'&&i%2==0)||(s[i-1]=='L'&&i%2==1))
			{
				cout<<"No"<<endl;
				flag=1;
				break;
			}
		}
		if(flag==0)
		cout<<"Yes"<<endl;
	}
}
/*
6
0 8 13 14 17 19
*/


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <assert.h>
#include <numeric>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)(1e5+5)
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){fast;
	int i,n,k,s=0;cin>>n>>k;vi v(n);
	for(i=0;i<n;i++) cin>>v[i];
	sort(all(v));
	for(i=0;i<k;i++) s+=v[i];cout<<s<<endl; 
}


Measured memory_bytes: 3608
def rate(m, f, r)
  return 'F' if m == -1 || f == -1
  a = m + f
  return 'A' if 80 <= a
  return 'B' if (65...80).include?(a)
  return 'C' if (50...65).include?(a) || r >= 50
  return 'D' if (30...50).include?(a)
  return 'F'
end
readlines.each do |line|
  m, f, r = line.split.map(&:to_i)
  break if [m, f, r].all? {|i| i == -1 }
  puts rate(m, f, r)
end

Measured memory_bytes: 6104
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
int n,m;
struct Union_Find
{
	vec fa;
	Union_Find()
	{
		fa.resize(n);
		rep(i,0,n)fa[i]=i;
	}
	int find(int x)
	{
		return x==fa[x]?x:fa[x]=find(fa[x]);
	}
	void unite(int a,int b)
	{
		fa[find(a)]=find(b);
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
};
int main()
{
	cin>>n>>m;
	Union_Find query;
	vec p(n);
	rep(i,0,n)p[i]=read()-1;
	rep(i,0,m)
	{
		int x=read(),y=read();
		query.unite(x-1,y-1);
	}
	int ans=0;
	rep(i,0,n)if(query.same(p[i],i))ans++;
	cout<<ans<<endl;/**/
	return 0;
}



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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> x(N);
    vector<ll> y(N);
    rep(i, N) {
        cin >> x[i] >> y[i];
    }
    vector<ll> indices(N);
    iota(indices.begin(), indices.end(), 0);
    double ans = 0.;
    ll cnt = 0;
    do {
        cnt ++;
        double sum = 0.;
        rep(i, N-1) {
            ll tmp = (x[indices[i]] - x[indices[i+1]]) * (x[indices[i]] - x[indices[i+1]]);
            tmp += (y[indices[i]] - y[indices[i+1]]) * (y[indices[i]] - y[indices[i+1]]);
            sum += sqrt(tmp);
        }
        ans += sum;
    } while (std::next_permutation(indices.begin(), indices.end()));
    print(setprecision(20) << ans/cnt);
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cout << H << " ";
	debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// コンパイル時、コマンド「debug」を使用 --> マクロが使えるように

void solve(){
	// ここに処理を記述
	// コンパイル時はコマンド「gpp」--> c++17でコンパイル
	int H, N;
	cin >> H >> N;

	debug(H,N);
	debug(gcd(H,N));

	vector<int> A;
	int temp = 0;
	for(int i=0; i<N; i++){
			cin >> temp;
			A.emplace_back(temp);
	}

	int damage = 0;
	rep(i,A.size()){
		damage += A[i];
		if(damage >= H){
			cout << "Yes" << endl;
			break;
		}
	}

	if(damage < H){
		cout << "No" << "\n";
	}
}

int main(){
	#define int ll
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
    if(b>a)
        swap(a,b);
    if(a%b==0)
        return b;
    //cout<<"1"<<endl;
    gcd(b,a%b);
}
int main()
{
    long long int a,b,c,d,n,t,r,i,j,k,x,y,m,p,s,mx,mn;
    cin>>t;
    int ar[t];
    for(i=0; i<t; i++)
    {
        cin>>ar[i];
    }
    b=ar[0];
    for(i=1; i<t; i++)
    {
        b=gcd(b,ar[i]);
        if(b==1)
            break;
    }
    cout<<b<<endl;
}



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

int main(){
    int N;
    cin >> N;
    int64_t ans = 0;
    for (int i = 1; i <= N; i++){
        if (i % 3 == 0 || i % 5 == 0){
            continue;
        }
        else{
            ans += i;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    int alice = 0;
    int bob = 0;
    for(int i=0;i<n;i++){
        if(i%2==0)alice+=a[i];
        else bob+=a[i];
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
tmp = list(map(int,input().split()))
tenbo = [[tmp[i],[i],0] for i in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    tenbo[a-1][1].append(b-1)
    tenbo[b-1][1].append(a-1)

cnt = 0
for i in range(n):
    if tenbo[i][2] == 0:
        for j in tenbo[i][1]:
            if j != i and tenbo[j][0] >= tenbo[i][0]:
                tenbo[i][2] = -1
                break
        if tenbo[i][2] == 0:
            tenbo[i][2] = 1
            cnt += 1
            for j in tenbo[i][1]:
                if tenbo[j][2] == 0:
                    tenbo[j][2] = -1

print(cnt)

Measured memory_bytes: 45000
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s = "";
  cin >> s;
  int n = (int)s.size();
  
  // check XX
  for (int i=0; i<n-1; i++) {
    if (s.at(i) == s.at(i+1)) {
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }
  
  // check XYX
  for (int i=0; i<n-2; i++) {
    if (s.at(i) == s.at(i+2)) {
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }
  
  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
a,v = map(int, input().split())
b,w = map(int, input().split())
t = int(input())
if a<b:
    new_a = a + v*t
    new_b = b + w*t
    if new_a >= new_b:
        print("YES")
    elif new_a < new_b:
        print("NO")
elif a>b:
    new_a = a - v*t
    new_b = b - w*t
    if new_a <= new_b:
        print("YES")
    elif new_a > new_b: 
        print("NO")


Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define int long long
const int inf = 1e18;
using namespace std;

template<typename tp> inline void read(tp &x) {
	x=0;char c=getchar();
	for(;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0',c=getchar());
}
const int N = 2e5 + 10 ; 
int x,y,z,n;
struct P {
	int a,b,c;
}p[N];
inline bool cmp(P a, P b) {
	return a.a-a.b<b.a-b.b;
}
int suma,sumb,sum,t1[N],t2[N],ans=0;
priority_queue<int,vector<int> , greater<int> > q;

main() {
	memset(t1,168,sizeof(t1));
	memset(t2,168,sizeof(t2));
	cin>>x>>y>>z;
	n=x+y+z;
	for(int i=1;i<=n;i++) {
		read(p[i].a);read(p[i].b);read(p[i].c);
		p[i].a-=p[i].c;
		p[i].b-=p[i].c;
		sum+=p[i].c;
	}
	sort(p+1,p+n+1,cmp);
	int ans=-inf;
	for(int k=1;k<=y;k++) q.push(p[k].b),sumb+=p[k].b,t1[k]=max(t1[k],sumb);
	for(int k=y+1;k<=n;k++) {
		int u=q.top();q.pop();
		sumb-=u;
		sumb+=max(u,p[k].b);
		t1[k]=max(t1[k],sumb);
		q.push(max(u,p[k].b));
	}
	while(!q.empty()) q.pop();
	for(int k=n;k>=n-x+1;k--) 
		q.push(p[k].a),suma+=p[k].a,t2[k]=max(t2[k],suma);
	for(int k=n-x;k>=1;k--) {
		int u=q.top();q.pop();
		suma-=u;
		suma+=max(u,p[k].a);
		t2[k]=max(t2[k],suma);
		q.push(max(u,p[k].a));
	}
//	for(int i=1;i<=n;i++) {
//		printf("%d %d %d\n",p[i].a,p[i].b,p[i].c);
//	}
//	puts("____________");
//	for(int i=1;i<=n;i++) {
//		printf("%d ",t1[i]);
//	}puts("____________");
//	for(int i=1;i<=n;i++) {
//		printf("%d ",t2[i]);
//	}puts("____________");
	for(int k=y;k<=n-x;k++)
		ans=max(ans,t1[k]+t2[k+1]);
	cout<<ans+sum<<"\n";
}

Measured memory_bytes: 7544
#include <iostream>
#include <stdio.h>
#include<algorithm>
#include <math.h>
#include <string.h>
#define eps 1e-9
typedef long long int ll;
using namespace std;
int a[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int i=0;i<n-1;i++)
    {
        if(a[i]==a[i+1])
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = [[int(i) for i in input().split()] for i in range(2)]
ans = []
sm = 0 

for i in range(n):
    sm += a[0][i] 
    tmp = sm
    for j in range(i, n):
        tmp += a[1][j]
    ans.append(tmp)
print(max(ans))


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

int main()
{
    string s;
    bool flag = true;
    cin >> s;
    for (int i = 0; i < s.length(); i++)
    {
        if (i&1)
        {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D')
            {
                flag = false;
                break;
            }
        }
        else
        {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D')
            {
                flag = false;
                break;
            }
        }
    }
    if (flag) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3624
#include<iostream>

int main(){
    int a, b, c;
    std::cin >> a >> b >> c;
    if(a == b + c || b == a + c || c == a + b){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import numpy as np


n = int(raw_input())

A_list = map(int,raw_input().split())

minus_sum = sum(x<0 for x in A_list)

arr_A = np.array(A_list)
abs_arr = np.abs(arr_A)
ABS_list = abs_arr.tolist()
#print ('ABS_list',ABS_list)

_min = min(ABS_list)
min_id = [i for i, x in enumerate(ABS_list) if x == _min]

if(minus_sum%2 == 0):
	print sum(ABS_list)
else:
	print sum(ABS_list)-ABS_list[min_id[0]]-ABS_list[min_id[0]]


Measured memory_bytes: 21544