akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define L long long
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,m,x[310][310],a[310],w[310],p;
bool t[310];
inline int orz()
{
	int i,j=0;
	for(i=1;i<=m;i++)
	  if(w[i]>w[j])
	    j=i;
	p=min(p,w[j]);
	return j;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	  for(j=1;j<=m;j++)
	    scanf("%d",&x[i][j]);
	for(i=1;i<=n;i++)
	  {
	   a[i]=1;
	   w[x[i][1]]++;
	  }
	p=1e9;
	k=orz();
	for(i=1;i<m;i++)
	  {
	   t[k]=1;
	   w[k]=0;
	   for(j=1;j<=n;j++)
	     if(x[j][a[j]]==k)
	       {
		    while(t[x[j][a[j]]])
		      a[j]++;
		    w[x[j][a[j]]]++;
		   }
	   k=orz();
	  }
	printf("%d\n",p);
	return 0;
}


Measured memory_bytes: 640
def main():
    from collections import deque
    S = deque(input())
    Q = int(input())

    q_list = [input().split() for _ in range(Q)]

    flag = False
    for q in q_list:
        if len(q) == 1:
            t = q[0]
        else:
            t, f, c = q

        if t == '1':
            flag = not flag
        else:
            if (f == '1') ^ flag:
                S.appendleft(c)
            else:
                S.append(c)
    if flag:
        S.reverse()
    print("".join(S))


if __name__ == '__main__':
    main()


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

typedef pair<int, int> Pii;
typedef pair<Pii, string> Pis;

struct Edge {
  int to, cost;  
};

int N, M, K, P;
vector<int> s, t;
vector<int> ss[1000];
vector<int> tt[1000];
vector<Edge> G[1000];

int dij() {
  priority_queue<Pis, vector<Pis>, greater<Pis> > Q;
  map<string, bool> used[N];
  string ini = "";
  string ends = "";
  for ( int i = 0; i < K; i++ ) {
    ini += "0";
    ends += "2";
  }

  for ( int j = 0; j < (int)ss[P].size(); j++ ) {
    if ( ini[ss[P][j]] == '0' ) ini[ss[P][j]] = '1';    
  }
  for ( int j = 0; j < (int)tt[P].size(); j++ ) {
    if ( ini[tt[P][j]] == '1' ) ini[tt[P][j]] = '2';	
  }
  
  Q.push(Pis(Pii(0, P), ini));
  
  while ( !Q.empty() ) {    
    Pis p = Q.top(); Q.pop();    
    int c = p.first.first;
    int n = p.first.second;
    string sta = p.second;
    //cout << n << " " << c << " "  << sta << endl;
    //cout << n << endl;
    if ( sta == ends ) return c;

    if ( used[n][sta] ) continue;
    used[n][sta] = true;

    for ( int i = 0; i < (int)G[n].size(); i++ ) {
      Edge e = G[n][i];
      int to = e.to, cost = e.cost;
      string nxt = sta;      
      for ( int j = 0; j < (int)ss[to].size(); j++ ) {
	if ( nxt[ss[to][j]] == '0' ) nxt[ss[to][j]] = '1';	
      }
      for ( int j = 0; j < (int)tt[to].size(); j++ ) {
	if ( nxt[tt[to][j]] == '1' ) nxt[tt[to][j]] = '2';	
      }
      Q.push(Pis(Pii(c+cost, to), nxt));      
    }
    //cout << n << endl;
  }

  return -1;
}

int main() {
  cin >> N >> M >> K >> P;
  P--;
  
  for ( int i = 0; i < M; i++ ) {
    int x, y, w;
    cin >> x >> y >> w;
    x--; y--;
    G[x].push_back(Edge{y, w});
    G[y].push_back(Edge{x, w}); 
  }
 
  s = vector<int>(K);
  t = vector<int>(K);
  for ( int i = 0; i < K; i++ ) {
    cin >> s[i] >> t[i];
    s[i]--; t[i]--;
    ss[s[i]].push_back(i);
    tt[t[i]].push_back(i);    
  } 
  
  int ans = dij();
  if ( ans == -1 ) cout << "Cannot deliver" << endl;
  else cout << ans << endl;
  
  return 0;
}



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


int main(){
        long double a,b,n;
        cin >> a >> b >> n;
        //long double max = -1;
        long double x = 0;
        // while(x <= n) {
        //
        //         if(value > max) {
        //                 max = value;
        //         }
        //         x++;
        // }
        if(b-1 <= n) n = b-1;
        long double value = floor(a*n/b) - (a * floor(n/b));
        cout << value << "\n";

}


Measured memory_bytes: 3268
#include <algorithm>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define INF 0x3f3f3f3f
#define MOD 1000000007

using namespace std;
typedef long long ll;

mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

template <typename T> void read(T &x) {
  x = 0;
  char c = getchar();
  T sig = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      sig = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 3) + (x << 1) + c - '0';
  x *= sig;
}

class UnionFind {
  int n;
  vector<int> parent, size;

public:
  UnionFind(int n) {
    this->n = n;
    parent = vector<int>(n);
    size = vector<int>(n, 1);
    for (int i = 0; i < n; ++i)
      parent[i] = i;
  }

  int find(int idx) {
    if (parent[idx] == idx)
      return idx;
    return parent[idx] = find(parent[idx]);
  }

  void connect(int a, int b) {
    int fa = find(a), fb = find(b);
    if (fa != fb) {
      if (size[fa] > size[fb]) {
        parent[fb] = fa;
        size[fa] += size[fb];
      } else {
        parent[fa] = fb;
        size[fb] += size[fa];
      }
    }
  }

  int solve() { return *max_element(size.begin(), size.end()); }
};

class Solution {
public:
  void solve() {
    int n, m;
    read(n), read(m);
    UnionFind uf(n);
    for (int i = 0; i < m; ++i) {
      int u, v;
      read(u), read(v);
      u--, v--;
      uf.connect(u, v);
    }
    printf("%d", uf.solve());
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution solution = Solution();
  solution.solve();
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> p;

	cin >> N;
	p.resize(N);
	llong cnt = 0;
	for (int i = 0; i < N; ++i) {
		cin >> p[i];
		cnt += p[i] != i+1;
	}

	if (cnt == 2 || cnt == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

map<int, int> kv;
vector<int> cnt[100005];
int n, m;

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        kv[x]++;
    }
    for (auto t : kv) if (t.se % 2 == 1)
    {
        cnt[t.fi % m].pb(t.fi);
    }
    for (auto t : kv)
    {
        for (int i = 0; i < t.se - t.se % 2; i++) cnt[t.fi % m].pb(t.fi);
    }
    int answer = 0;
    for (int i = 0; i * 2 <= m; i++)
    {
        if (i + i == m || i == 0)
        {
            int k = cnt[i].size() / 2;
            for (auto t = 0; t < 2 * k; t++) kv[cnt[i][t]]--;
            answer += k;
        }
        else
        {
            int k = min(cnt[i].size(), cnt[m - i].size());
            for (auto t = 0; t < k; t++) kv[cnt[i][t]]--;
            for (auto t = 0; t < k; t++) kv[cnt[m - i][t]]--;
            answer += k;
        }
    }
    for (auto t : kv)
    {
        answer += t.se / 2;
    }
    printf("%d\n", answer);
    return 0;
}

Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))


Int dp[1 << 21];
Int cnt[1 << 21];
Int a[22][22];
int main(){
  int n;
  cin >> n;
  for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++)
      cin >> a[i][j];
  
  for(int i = 0;i < (1<<n);i++){
    if(i == 0){dp[i] = 1;continue;}
    cnt[i] = cnt[i - (i&-i)] + 1;
    for(int j = 0;j < n;j++){
      if((i >> j) % 2 == 0)continue;
      if(a[j][cnt[i]-1] == 0)continue;
      dp[i] = (dp[i]+ dp[i - (1<<j)]) % MOD; 
    }
  }
  cout << dp[(1<<n) - 1] << endl;
  return 0;
}

Measured memory_bytes: 33024
#include <cstdio>
#include <cctype>
#include <utility>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int m = in(); m; m--) {
		int f = in(), y = in(), n = in(), g = 0;
		while (n--) {
			double r;
			int o, d, t = f;
			scanf("%d %lf %d", &o, &r, &d);
			if (o)
				for (int i = 0; i < y; i++)
					t = t + t * r - d;
			else {
				int u = 0;
				for (int i = 0; i < y; i++) {
					u += t * r;
					t -= d;
				}
				t += u;
			}
			g = max(g, t);
		}
		outl(g);
	}
}


Measured memory_bytes: 2672
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
print("Yes" if len(set(S))==3 else "No") 

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

using namespace std;


int main()
{

int n;
cin>>n;

int arr[n];
loop(i,n) cin>>arr[i];

int mini;
int ans=INT_MAX;

for(int i=-100;i<=100;i++){
        mini=0;

    for(int j=0;j<n;j++){

      mini=mini+((arr[j]-i)*(arr[j]-i));

    }

    ans=min(ans,mini);

}

cout<<ans;
}




Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h> 
using namespace std;
typedef long long int lli;
const int MaxN=20;
#define fst first
#define snd second
#define mp make_pair
	lli mcd(lli a,lli b){	
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli N,M,X,res=1e9;
	lli nivel[MaxN];
	lli costo[MaxN];
	vector <lli> sube[MaxN];
	void bruta(lli ind,lli llevo){
		//cout<<ind<<" "<<llevo<<"\n";
		if(ind==N+1){
			int i,si=1;
			for(i=0;i<M;i++){
				if(nivel[i]<X)si=0;
			}
			if(si)res=min(res,llevo);
			return;
		}
		int i;
		bruta(ind+1,llevo);
		for(i=0;i<M;i++){
			nivel[i]+=sube[ind][i];
		}
		bruta(ind+1,llevo+costo[ind]);
		for(i=0;i<M;i++){
			nivel[i]-=sube[ind][i];
		}
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,j,p;
	cin>>N>>M>>X;
	for(i=1;i<=N;i++){
		cin>>costo[i];
		for(j=0;j<M;j++){
			cin>>p;
			sube[i].push_back(p);
		}
	}
	bruta(1,0);
	if(res==1e9)cout<<"-1";
	else cout<<res;
}	
		

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<vector<ll>> connect(N);
  for (ll i = 0; i < N; ++i) {
    ll u, k;
    cin >> u >> k;
    for (ll j = 0; j < k; ++j) {
      ll v;
      cin >> v;
      connect.at(u - 1).push_back(v - 1);
    }
  }
  // for (ll i = 0; i < N; ++i) {
  //   sort(connect.at(i).begin(), connect.at(i).end());
  //   reverse(connect.at(i).begin(), connect.at(i).end());
  // }
  stack<ll> s;
  s.push(0);
  vector<bool> already(N, false);
  vector<pll> ans(N);
  already.at(0) = true;
  ans.at(0).first = 1;
  ll cnt = 2;
  while (!s.empty()) {
    ll check = s.top();
    bool tip = true;
    for (ll i = 0; i < connect.at(check).size(); ++i) {
      if (already.at(connect.at(check).at(i))) {
        continue;
      }
      already.at(connect.at(check).at(i)) = true;
      tip = false;
      s.push(connect.at(check).at(i));
      ans.at(connect.at(check).at(i)).first = cnt;
      cnt += 1;
      break;
    }
    if (tip) {
      ans.at(check).second = cnt;
      s.pop();
      cnt += 1;
    }
    if (s.empty()) {
      for (ll i = 0; i < N; ++i) {
        if (!already.at(i)) {
          already.at(i) = true;
          s.push(i);
          ans.at(i).first = cnt;
          cnt += 1;
          break;
        }
      }
    }
  }
  for (ll i = 0; i < N; ++i) {
    cout << i + 1 << ' ' << ans.at(i).first << ' ' << ans.at(i).second << endl;
  }
}



Measured memory_bytes: 3120
import sys
from bisect import bisect_left

input = sys.stdin.readline


def main():
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())

    colors = []
    for a in A:
        idx = bisect_left(colors, a)
        if idx == 0:
            colors.insert(0, a)
        else:
            colors[idx - 1] = a

    ans = len(colors)
    print(ans)


if __name__ == "__main__":
    main()


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


int main(){
	int n ; cin>>n;
	vector<vector<int> >claims(n,vector<int>(n,2));

	for(int i = 0 ; i < n ; i ++){
		int q; cin>>q;
		for(int j = 0 ; j< q ; j++){
			int a,b; cin>>a>>b;
			claims[i][a-1]=b;
		}
	}

	for(int i = 0 ; i < n ; i++){
		claims[i][i]=1;
	}

	for(int i=0 ; i<n ; i++){
		for(int j = 0 ; j < n ; j++){
			if(claims[i][j]==1){
				for(int k = 0 ;  k < n  ; k++){
					if(claims[i][k]+claims[j][k]==1){
						claims[i][i]=0;
					}
				}
			}
		}
	}

	

	int max = 0;
	for(int i=0 ; i <(1<<n) ; i++ ){
		vector<int>honest;
		for(int j = 0 ; j < n ; j++){
			if(i&(1<<j)){
				honest.push_back(j);
			}
		}
		bool check=true;
		for(int j= 0 ; j < honest.size() ; j++){
			for(int k = 0 ; k < honest.size() ; k ++){
				for(int z = 0 ; z< n ; z++){
					if(claims[honest[j]][z]+claims[honest[k]][z]==1){
						check=false;
					}
				}
			}
		}

		for(int j=0 ; j < honest.size() ; j++){
			for(int k = 0 ; k < honest.size() ; k++){
				if(claims[honest[j]][honest[k]]==0){
					check=false;
				}
			}
		}

		for(int j = 0 ; j < honest.size() ; j ++){
			for(int k = 0 ; k < n ; k++){
				if(claims[honest[j]][k]==1){
					if(find(honest.begin(),honest.end(),k)==honest.end()){
						check=false;
					}
				}
			}
		}

		if(check){
			if(honest.size()>max){
				max=honest.size();
			}
		}
	}

	cout<<max;


	int l ; cin>>l;
	
}

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

"""
参考：https://www.hamayanhamayan.com/entry/2018/01/28/231916
・幅優先
・辺の情報の持たせ方を工夫して、辺のループを余計に回さないようにする。
"""

from collections import deque

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

l_edges = [[] for i in range(N)]
r_edges = [[] for i in range(N)]
for i in range(M):
    l, r, d = map(int, input().split())
    l_edges[l-1].append((r-1, d))
    r_edges[r-1].append((l-1, d))

# 訪問済メモ
visited = [0] * N

def bfs(start):
    # この開始位置を基準とした相対位置を記録する
    pos = {start: 0}
    que = deque()
    que.append(start)
    visited[start] = 1
    while len(que) != 0:
        cur = que.popleft()
        # 左から見た右側を確認
        for r, d in l_edges[cur]:
            # 訪問済なら矛盾がないか検証する
            if visited[r]:
                if pos[r] - pos[cur] != d:
                    print('No')
                    exit()
            # 未訪問なら今回の情報を記録する
            else:
                visited[r] = 1
                pos[r] = pos[cur] + d
                # 次回以降、開始位置として使うのでキューに詰める
                que.append(r)
        # 右から見た左側を確認
        for l, d in r_edges[cur]:
            if visited[l]:
                if pos[cur] - pos[l] != d:
                    print('No')
                    exit()
            else:
                visited[l] = 1
                pos[l] = pos[cur] - d
                que.append(l)

for i in range(N):
    # 訪問済(確認済)でなければ走破しに行く
    if not visited[i]:
        bfs(i)
# 最後まで矛盾がなければOK
print('Yes')


Measured memory_bytes: 78948
#include <stdio.h>
#include <string.h>
int main(void)
{
	int i;
	char s[6];
	scanf("%s",s);
	for(i=0; i<strlen(s)-1; i++){
		if(s[i]=='A' && s[i+1]=='C'){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

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

const int MOD = (int)1e9+7;

int main(){
  vector<long long> abc(3);
  for(int i=0;i<3;i++)  cin >> abc.at(i);

  sort(abc.begin(),abc.end());
  if(abc.at(0)%2==0 || abc.at(1)%2==0 || abc.at(2)%2==0)  cout << 0 << endl;
  else  cout << abc.at(0)*abc.at(1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PII, PII> PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
typedef vector <int> vi;
const int mod = 1e9+7;
const int inf = 1e9+10;
const ll MOD = 1e9+696969;
const ll INF = 1e18;
const int W = 1e9;
#define maxn 1001009
int n, m, k, a, b, c;
int tab[maxn];

int main()
{
	ll N, M;
	cin >> M >> N;
	ll res = 0;
	ll ile = min(N / 2, M);
	N -= ile * 2; M -= ile;
	res = ile;
	if (M == 0) res += (N / 4);
	cout << res;
}


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

#include<bits/stdc++.h>
using namespace std;
using ll=long long; 
using Weight=ll;
struct Edge {
    int src,dest; Weight weight;
    bool operator<(const Edge &rhs)const{
        return weight<rhs.weight;
    }
};
using Edges=vector<Edge>;
using Graph=vector<Edges>;
 
const Weight INF=1e12;
 
void dijkstra(const Graph &g,int s,vector<Weight> &d){
    assert(0<=s && s<g.size());
    d.assign(g.size(),INF); d[s]=0;
    vector<int> used(g.size(),0);
    using P=pair<Weight,int>;
    priority_queue<P,vector<P>,greater<P>> que;
    que.push({0,s});
    while(!que.empty()){  
        auto val=que.top(); que.pop();
        Weight dist=val.first;
        int v=val.second;
        if(used[v]) continue;
        used[v]=true;
        for(auto e:g[v]){
            int to=e.dest;
            Weight w=e.weight;
            if(dist+w<d[to]){
                d[to]=dist+w;
                que.push({d[to],to});
            }
        }
    }
}




int main(){
    int n;
    cin>>n;
    vector<vector<ll>> edge(n,vector<ll>(n,0));
    for(int i=0;i<n;i++)for(int j=0;j<n;j++) cin>>edge[i][j];
    
    const ll INF=1e15;
    vector<vector<ll>> d(n,vector<ll>(n,INF));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=edge[i][j];
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    if(d!=edge){
        cout<<-1<<endl;
        return 0;
    }

    using pp=pair<ll,pair<int,int>>;
    priority_queue<pp,vector<pp>,greater<>> que;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            que.push({edge[i][j],{i,j}});
        }
    }
 
    ll res=0;
    Graph g(n);
    while(!que.empty()){
        auto val=que.top();
        que.pop();
        long long int cost=val.first;
        int a=val.second.first;
        int b=val.second.second;
        vector<ll> d(n,INF);
        dijkstra(g,a,d);
        if(d[b]!=cost){
            res+=cost;
            Edge e;
            e.src=a;
            e.dest=b;
            e.weight=cost;
            g[a].push_back(e);
            e.src=b;
            e.dest=a;
            g[b].push_back(e);
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2808
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}
ll lcm(ll a, ll b){
	if(a==0 || b==0) return 0;
	return (a*b)/(gcd(a,b));
}
ll multiple_lcm(vector<ll> a){
	ll r=a[0],g;
	bool ok=true;
	for(ll i=1;i<a.size();i++){
		r=lcm(r,a[i]);
	}
	return r;
}
int main() {
	ll n,m,val,l,ans;
	cin>>n>>m;
	vector<ll> a;
	for(ll i=0;i<n;i++){
		cin>>val;
		a.pb(val/2);
	}
	l=multiple_lcm(a);
	bool ok=true;
	for(ll i=0;i<n;i++){
		if((l/a[i])%2==0){
			ans=0;
			ok=false;
			break;
		}
	}
	if(ok){
		ans=m/l;
		ans=(ans+1)/2;
	}
	cout<<ans<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1908
#include <iostream>
#include <list>
using namespace std;
int main(){
        list <long long int> ls;
        int N;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                int x;
                cin >> x;
                if((i+N)%2)
                        ls.push_front(x);
                else
                        ls.push_back(x);
        }
        list<long long int>::iterator itr;
        for( itr=ls.begin() ; itr!=ls.end() ; ++itr ){
                cout<<*itr<<" ";
        }
        cout<<endl;
}

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

const int maxn = 105;
char g[maxn][maxn];
char h[maxn], w[maxn];

int main()
{
	memset(g, 0, sizeof(g));
	memset(h, 0, sizeof(h));
	memset(w, 0, sizeof(w));
	
	int H, W;	cin >> H >> W;
	for(int i = 0; i < H; i ++)
	{
		cin >> g[i];
		for(int j = 0; j < W; j ++)
			if(g[i][j] == '#')	h[i] = w[j] = 1;
	}
	
	for(int i = 0; i < H; i ++)
	{
		if(h[i] == 0)	continue;
		for(int j = 0; j < W; j ++)
		{
			if(w[j] == 0)	continue;
			cout << g[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
int main()
{
    fastio;
    int n,i;
    cin>>n;
    string str,a;
    string c= "...";
    cin>>str;
    if (str.length()<=n)
        cout<<str<<endl;
    else
    {
        for (i=0;i<n;i++)
            a.push_back(str[i]);
        for (i=0;i<3;i++)
            a.push_back(c[i]);
        cout<<a<<endl;
    }
}

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

int main(){
    int n;
    std::cin >> n;
    
    std::vector<bool> s(13, true);
    std::vector<bool> h(13, true);
    std::vector<bool> c(13, true);
    std::vector<bool> d(13, true);
    
    for(int i = 0; i < n; i++){
        char cha;
        int a;
        std::cin >> cha >> a;
        if(cha == 'S') s[a-1] = false;
        else if (cha == 'H') h[a-1] = false;
        else if (cha == 'C') c[a-1] = false;
        else if (cha == 'D') d[a-1] = false;
    }
    
    for(int i = 0; i < 13; i++){
        if(s[i]){
            std::cout << 'S' << " " << i+1 << std::endl;
        }
    }
    for(int i = 0; i < 13; i++){
        if(h[i]){
            std::cout << 'H' << " " << i+1 << std::endl;
        }
    }
    for(int i = 0; i < 13; i++){
        if(c[i]){
            std::cout << 'C' << " " << i+1 << std::endl;
        }
    }
    for(int i = 0; i < 13; i++){
        if(d[i]){
            std::cout << 'D' << " " << i+1 << std::endl;
        }
    }
    
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

long long get(long long K,vector<long long> &A,vector<long long> &B){
	long long ret = 0;
	for(int i=0;i<A.size();i++){
		if((A[i]|K)==K){
			ret += B[i];
		}
	}
	return ret;
}

int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<long long> A(N),B(N);
	for(int i=0;i<N;i++)cin>>A[i]>>B[i];
	
	long long ans = get(K,A,B);
	
	for(int i=0;i<30;i++){
		if((1<<i)&K){
			long long t = K|((1<<i)-1);
			t ^= (1<<i);
			ans = max(ans,get(t,A,B));
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1920
n,m=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
now=[]
bc=[]
for i in range(m):
  BC=[int(x) for x in input().rstrip().split()]
  bc.append(BC)
bc=sorted(bc,key=lambda x:x[1],reverse=True)
A.sort(reverse=True)
d=[]
for b,c in bc:
    d.extend([c]*b)
    if n<=len(d):
      break
A+=d
A.sort(reverse=True)
print(sum(A[:n]))


Measured memory_bytes: 29632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N, M; cin >> N >> M;
    vector<int> v(M, 0);
    for (int i = 0; i < N; ++i) {
        ll K; cin >> K;
        for (int j = 0; j < K; ++j) {
            ll A; cin >> A;
            v[A-1]++;
        }
    }
    int count = 0;
    for (int i = 0; i < M; ++i) {
        if (v[i] == N) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <tuple>
#include <utility>
#include <stdlib.h>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb push_back
#define mp make_pair

int main() {
	int n;
	cin >> n;
	LL ans = 0, num1 = 2, num2 = 1;
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	rep(i, 0, n-1) {
		ans = num2 + num1;
		num1 = num2;
		num2 = ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    /* x: current position
     * k: moving times
     * d: distance when moving once
     */
    long long x, k, d;
    long long times, ans;
    cin >> x >> k >> d;
    times = abs(x)/d;
    if(times >= k){
        ans = abs(x) - k*d;
        cout << ans << endl;
    }else {
        long long now = abs(x) - d*times;
        if((k-times)%2 == 0){
            ans = now;
        }
        else{
            ans = abs(now-d);
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		sc.close();
		StringBuilder sb = new StringBuilder();
		sb.append("2018");
		sb.append(S.substring(4));
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 25812
<?php
$n=trim(fgets(STDIN));
$a=explode(" ",trim(fgets(STDIN)));
$c=array_sum($a)/$n;
$q=10000;
$i=0;
while($i<$n){
  $d=abs($a[$i]-$c);
  if($d<$q){
    $q=$d;
    $ans=$i;
  }
  ++$i;
}
echo $ans;

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

int main(){
    int n;
    cin >> n;
    string s[n];
    int t[n];
    for(int i=0;i<n;i++){
        cin >> s[i];
        cin >> t[i];
    }
    string x;
    cin >> x;
    int ans=0;
    for(int i=0;i<n;i++){
        ans+=t[i];
    }
    for(int i=0;i<n;i++){
        ans-=t[i];
        if(x==s[i]){
            break;
        }
    }
    cout << ans << endl;
}

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

const int maxn = 100010;
int n, ans, suf[maxn];
pair<int, int> p[maxn], q[maxn];

int main() {
    scanf("%d", &n);
    int a = 0, b = suf[n + 1] = INT_MAX;
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &p[i].first, &p[i].second);
        a = max(a, p[i].first), b = min(b, p[i].second);
    }
    sort(p + 1, p + n + 1);
    for (int i = 1; i <= n; i++) {
        ans = max(ans, max(0, b - a + 1) + p[i].second - p[i].first + 1);
        q[i] = {max(0, b - p[i].first + 1), max(0, p[i].second - a + 1)};
    }
    sort(q + 1, q + n + 1), reverse(q + 1, q + n + 1);
    for (int i = n; i; i--) {
        suf[i] = min(suf[i + 1], q[i].second);
    }
    for (int i = 1; i < n; i++) {
        ans = max(ans, q[i].first + suf[i + 1]);
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

int main(void) {
  int n, dp[31];

  dp[0] = dp[1] = 1;
  dp[2] = 2;
  for (int i = 3; i <= 30; i++) {
    dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1];
  }

  while (cin >> n, n) {
    cout << dp[n] / 3650 + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005;

int main()
{
    string s;
    string ss[105];
    int n, l;
    cin >> n >> l;
    for(int i = 0; i < n; ++i)
        cin >> ss[i];
    sort(ss, ss+n);
    for(int i = 0; i < n; ++i)
        s += ss[i];
    cout << s << endl;
    return 0;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int s,w;cin>>s>>w;
  if(s<=w)cout<<"unsafe"<<endl;
  else cout<<"safe"<<endl;
}



Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    private static final int MAX = 44;
    public static void main(String args[]) {
	int[] fib = new int[MAX + 1];
	    fib[0] = 1;
	    fib[1] = 1;

	    for(int i = 2; i <= MAX; i++){
		fib[i] = fib[i-1] + fib[i-2];
            }
   

	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    
	    try {
		while(true){
		    int num = Integer.parseInt(br.readLine());
		    if (num <= 0) {
			break;
		    }
		    System.out.println(fib[num]);
		}
	    }

	    catch(Exception e){
		System.exit(0);
	    }
    }
}		    



Measured memory_bytes: 24256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << # x << "; "<< x << endl


int main() {
	int N, K, l;
	cin >> N >> K;
	vector<int> vec;
	int total = 0;
	for (int i = 0; i < N; i++) {
		cin >> l;
		vec.push_back(l);
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	for (int j = 0; j < K; j++) {
		total += vec.at(j);
	}
	cout << total << endl;
}

Measured memory_bytes: 3608
def check(S, T):
    ans="~"
    for i in range(len(S)-len(T)+1):
        found=True
        for j in range(len(T)):
            if S[i+j] != "?" and T[j] != S[i+j]:
                found=False
                break
        if found: 
            ans=min(ans, S[:i].replace("?", "a")+T+S[i+len(T):].replace("?","a"))

    return ans


S=input()
T=input()

ans=check(S, T)
if ans == "~":
    print("UNRESTORABLE")
else:
    print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max();

// RMQ
template<class T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree(int n_ = 0) : n(n_){
        n = 1;
        while(n < n_) n <<= 1;
        dat.resize(n*2, inf);
    }
    T query(int v, int w, int l, int r){
        if(r <= l || w == 0) return inf;
        if(r - l == w) return dat[v];
        return min(query(v*2, w/2, l, min(r, w/2)),
                   query(v*2+1, w/2, max(0, l-w/2), r-w/2));
    }
    void update(int i, T x){
        i += n;
        dat[i] = x;
        for(; i!=1; i/=2) dat[i>>1] = min(dat[i], dat[i^1]);
    }
    T query(int l, int r){
        return query(1,n,l,r);
    }
    size_t size() const {
        return n;
    }
};

int main(){
    fastios();
    int n, q;
    while(cin >> n >> q){
        SegmentTree<int> st(n);
        rep(i,q){
            char c;
            int x, y;
            cin >> c >> x >> y;
            if(c == '0'){
                st.update(x,y);
            } else {
                cout << st.query(x,y+1) << endl;
            }
        }
    }
}

Measured memory_bytes: 2052
n = int(input())
arr = []
for i in range(n):
  x,y,h = map(int,input().split())
  if h >= 1:
    X,Y,H = x,y,h
  arr.append([x,y,h])

def d(a,b,c,d):
  return abs(c-a)+abs(d-b)


for i in range(101):
  for j in range(101):
    H0 = d(i,j,X,Y)+H
    flag = 1
    for l in arr:
      if l[2] != max(0,H0-d(i,j,l[0],l[1])):
        flag = 0
        break
    if flag == 1:
      print(i,j,H0)
      quit()

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

int main(){
  int n;
  cin >> n;
  string str="";
  for(int i=0; i<3; i++){
    str.insert(str.begin(), n%10+'0');
    n/=10;
  }
  cout << "ABC" << str;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	string s, t;
	cin >> s;
	t = s;
	reverse(ALL(t));
	int ans = 0;
	inc(i, SI(s) / 2) { if(s[i] != t[i]) { ans++; } }
	
	cout << ans << endl;
	
	return 0;
}


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


public class Main {

    static void solve() {
        Scanner scan = new Scanner(System.in);
//        int t = scan.nextInt();
        int n = scan.nextInt();
        Set<String>set = new HashSet<>();
        for(int i=0;i<n;i++) {
            String s = scan.next();
            set.add(s);
        }

        System.out.println(set.size());

//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//            int res = scase(n);
//            System.out.println(res);
//            solveCase(i, n, strs);
//        }
    }

    static void solveCase(int t, int n, String[] strs) {
//
//        System.out.println("Case #" + (t+1) + ": " + res);
    }


//    static int scase(int n) {
//
//    }


    public static void main(String[] args) {

//
        solve();

        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class Node {
//        int val;
//        Node next;
//        Node random;
//
//        public Node(int val) {
//            this.val = val;
//            this.next = null;
//            this.random = null;
//        }
//    }

//    static class Node {
//        int key;
//        int data;
//        Node next;
//        Node prev;
//
//        Node(int key, int data) {
//            this.key = key;
//            this.data = data;
//        }
//    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
}


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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;
int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   int N, M; cin >> N >> M;
   int a[N], b[N], c[M], d[M];
   for(int i = 0; i < N; i++)
      cin >> a[i] >> b[i];
   for(int j = 0; j < M; j++)
      cin >> c[j] >> d[j];
   for(int i = 0; i < N; i++)
   {
      int ans, mindis = 1e9;
      for(int j = 0; j < M; j++)
      {
         int dis = abs(a[i] - c[j]) + abs(b[i] - d[j]);
         if(mindis > dis)
         {
            mindis = dis;
            ans = j;
         }
      }
      cout << ans+1 << nl;
   }


}


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

int main()
{
    int N;
    cin >> N;
    int s = 0;
    int nn = N;
    while (nn > 0) {
        s += nn % 10;
        nn /= 10;
    }
    if (N % s == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main()
{
    string S;
    cin >> S;
    bool ans = true;
    for (int i = 0; i < S.size(); i += 2)
    {
        if (S[i] == 'L')
        {
            ans = false;
        }
    }
    for (int i = 1; i < S.size(); i += 2)
    {
        if (S[i] == 'R')
        {
            ans = false;
        }
    }
    if( ans ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int,input().split()))

ans = 100000000000
#最初と最後だけ調べればOK
for i in range(N - K + 1):
    tmp_min = x[i]
    tmp_max = x[i + K - 1]
    tmp = abs(tmp_min) + abs(tmp_min - tmp_max)
    tmp2 = abs(tmp_max) + abs(tmp_min - tmp_max)
    ans = min(ans, min(tmp, tmp2))
print(ans)





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

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

//for dfs, I prepare container(tree) at global
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1){
	for(int u: to[v]){
		if(u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}
 
//#define int int64_t
signed main()
{
	int n, q; cin >> n >> q;
	for(int i = 0, i_len = (int)n-1; i < i_len; ++i){
		int a, b;
		cin >> a >> b;
		--a;--b;
		to[a].emplace_back(b);
		to[b].emplace_back(a);		
	}
	ans.resize(n);
	for(int i = 0, i_len = (int)q; i < i_len; ++i){
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);
 
	for(int i = 0, i_len = (int)n; i < i_len; ++i){
		cout << ans[i] << "\n";
	}
 
}

Measured memory_bytes: 23424
k,n = map(int,input().split())
a = list(map(int,input().split()))
max_len = k - a[n-1] + a[0]
for i in range(2, n):
    if a[i]-a[i-1] > max_len:
        max_len = a[i]-a[i-1]

print(k - max_len)

Measured memory_bytes: 32252
n,m=map(int,input().split())
lists=list(map(int,input().split()))
sub=list(map(int,input().split()))
mod=10**9+7
tate=0
yoko=0
for i in range(n):
    tate+=lists[i]*(2*(i+1)-1-n)
for j in range(m):
    yoko+=sub[j]*(2*(j+1)-1-m)
print(((tate%mod)*(yoko%mod))%mod)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1e5+10;

int n;
vector<int> adj[N];
int dp[N][2];
int deg[N];
bool vis[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  if (n == 1) {
    puts("2");
    return 0;
  }
  for (int i = 0; i < n-1; i++) {
    int u, v; cin >> u >> v; u--; v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  queue<int> q;
  for (int i = 0; i < n; i++) {
    if (deg[i] == 1) {
      q.push(i);
    }
  }
  int u = -1;
  while (!q.empty()) {
    u = q.front(); q.pop();
    vis[u] = 1;
    dp[u][0] = dp[u][1] = 1;
    for (int v : adj[u]) {
      if (vis[v]) {
        dp[u][0] = ((ll) dp[u][0]) * (dp[v][0] + dp[v][1]) % MOD;
        dp[u][1] = ((ll) dp[u][1]) * dp[v][0] % MOD;
      } else if (--deg[v] == 1) {
        q.push(v);
      }
    }
    //cerr << u << " -> " << dp[u][0] << " " << dp[u][1] << nl;
  }
  cout << (dp[u][0] + dp[u][1]) % MOD << nl;
  return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n;
  cin >> n;
  double sum = 0;
  rep(i,n) {
    int a;
    cin >> a;
    sum += 1.0 / a;
  }
  double ans = 1 / sum;
  printf("%.10f\n", ans);
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int x[5]; rep(i,5) cin >> x[i];
	rep(i,5) {
		if(x[i] == 0) {
			cout << i + 1 << '\n';
			return 0;
		}
	}
	return 0;
}


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

int main(){
    int w,h,n;
    cin >> w >> h >> n;
    vector<vector<int>> b(h, vector<int>(w,0));
    int x,y,a, ans=0;
    for(int k=0;k<n;k++){
        cin >> x >> y >> a;
        if(a == 1){
            for(int i=0;i<h;i++) for(int j=0;j<x;j++) b[i][j] = 1;
        }else if(a == 2){
            for(int i=0;i<h;i++) for(int j=x;j<w;j++) b[i][j] = 1;
        }else if(a == 3){
            for(int i=0;i<y;i++) for(int j=0;j<w;j++) b[i][j] = 1;
        }else{
            for(int i=y;i<h;i++) for(int j=0;j<w;j++) b[i][j] = 1;
        }
    }
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(b[i][j] == 0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * File              : B.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 28.03.2020
 * Last Modified Date: 28.03.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */

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


ll solve(ll x) {
    ll res = 0;
    res += (x / 500L) * 1000L;
    x %= 500;
    res += 5 * (x / 5);
    return res;
}

int main() {
    ll x;
    cin >> x;
    cout << solve(x);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int a = A + B,
            b = A - B,
            c = A * B;

        if (a < b) {
            if (b < c) {
                System.out.println(c);
            } else {
                System.out.println(b);
            }
        } else {
            if (a < c) {
                System.out.println(c);
            } else {
                System.out.println(a);
            }
        }
    }
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int x;
	cin >> x;

	int ans = 0;
	for(int i=1; i<=x; i++){
		ans += i;
		if(ans >= x){
			cout << i << endl;
			break;
		}
	}
	
	return 0;
}


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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

int gcd(int a, int b) {
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

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

signed main(void) {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	a--;
	b--;
	c--;
	d--;
	string ans = "Yes";
	for (int i = a; i < max(c,d); i++) {
		if (s[i] == '#' && s[i + 1] == '#') ans = "No";
	}
	if (d < c) {
		int ok = 0;
		for (int i = b; i <= d; i++) {
			if (s[i-1] == '.' && s[i] == '.' &&  s[i + 1] == '.')ok=1;
		}
		if (ok==0)ans = "No";
	}
	print(ans);
}

Measured memory_bytes: 3708