akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int N, A;
	cin >> N >> A;

	cout << N * N - A << endl;
	return 0;
}

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

class Dise {
public:
	Dise();
	short num[6];
	//目の値を入力
	void InputNumber();
	//一番上合わせ回転
	void RotateTop(short);
	//前面合わせ
	void RotateFront(short);
};

Dise::Dise()
{
	for (int i = 0; i < 6; i++) {
		num[i] = 0;
	}
}

void Dise::InputNumber() 
{
	//計6マス入力
	for (short i = 0; i < 6; i++) {
		cin >> num[i];
	}
}

void Dise::RotateTop(const short pos)
{
	//すでに上面
	if (pos == 0) {
		return;
	}

	if (pos == 5) {
		swap(num[0], num[5]);
		swap(num[1], num[4]);
		return;
	}

	//反対側以外
	swap(num[pos], num[0]);
	swap(num[pos], num[5 - pos]);
	swap(num[pos], num[5]);
}

void Dise::RotateFront(const short pos)
{
	//すでに前
	if (pos == 1) {
		return;
	}

	//後ろ面
	if (pos == 4) {
		swap(num[1], num[4]);
		swap(num[2], num[3]);
		return;
	}

	swap(num[pos], num[1]);
	swap(num[pos], num[5 - pos]);
	swap(num[pos], num[4]);	
}

//異なるサイコロか判別
bool IsDistance(short, Dise*);


int main()
{
	//サイコロ数
	short n;
	//サイコロ

	string result = "Yes";
	Dise dise[100];
	//サイコロ数
	cin >> n;

	//指定サイコロ数入力
	for (short i = 0; i < n; i++) {
		//目を入力
		dise[i].InputNumber();
		//同じサイコロが存在するか
		if (result=="Yes" && IsDistance(i, &dise[0])) {
			result = "No";
			break;
		}	
	}
	
	cout << result << endl;

	return 0;
}

//iは入力した配列 Dise*は先頭
bool IsDistance(const short i,Dise *dise)
{
	Dise copy = dise[i];
	short k, l, m;

	for (short j = 0; j < i; j++) {

		for (k = 0; k < 6; k++) {
			//てっぺんと同じ数字
			if (copy.num[k] == dise[j].num[0]) {
				break;
			}
		}
		//同じ数字がない
		if (k < 6) {
			//てっぺん合わせ
			copy.RotateTop(k);
			for (l = 0; l < 6; l++) {
				//前面と同じ値
				if (copy.num[l] == dise[j].num[1]) {
					break;
				}
			}
			//下面 同じ数字なし
			if (l < 5 ) {
				//前面合わせ
				copy.RotateFront(l);
			}

			//面調べる
			for (m = 0; m < 6; m++) {
				//異なる
				if (dise[j].num[m] != copy.num[m]) {
					break;
				}
			}
			//全て同じなら
			if (m == 6) {
				return true;
			}
		}
	}
	//全て異なる
	return false;
}



Measured memory_bytes: 3156
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		Map<String, String> hinaMap = new HashMap<>();

		for(int i = 0; i < N; i++) {
			String s = sc.next();
			hinaMap.put(s, s);
		}

		sc.close();

		String answer = "";

		if(hinaMap.size() == 3) {
			answer = "Three";
		}else if(hinaMap.size() == 4) {
			answer = "Four";
		}

		System.out.println(answer);
	}

}


Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main(){
  char B,OUT;
  cin >> B;
  if(B == 'A')OUT = 'T';
  else if(B =='T')OUT = 'A';
  else if(B =='C')OUT = 'G';
  else OUT = 'C';
  cout << OUT << endl;
}

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

int main()
{
    int l,a,b,c,d;
    cin>> l>>a>>b>>c>>d;

    int kl=(a%c==0?a/c:a/c+1);
    int sl=(b%d==0?b/d:b/d+1);
    cout << l-max(kl,sl)<< endl;
    return 0;
}



Measured memory_bytes: 3096
check = 7
l = list(input())
n = len(l)-1

for i in range(2**n):
    v = ['+']*n
    for j in range(n):
        if (i >> j) & 1 == 1:
            v[j] = '-'
    
    working = l[0]
    for k in range(n):
        if v[k] == '+':
            working += ('+'+str(l[k+1]))
        else:
            working += ('-'+str(l[k+1]))
    ans = eval(working)
    if ans == check:
        print(working+'=7')
        exit()

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
int a,b,c,d,e,f;
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
if(a*1+b*5+c*10+d*50+e*100+f*500>=1000){
printf("1\n");
}
else{
printf("0\n");
}
return 0;
}


Measured memory_bytes: 1992
n,m=map(int,input().split())
h=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(m):
    tmp=[int(i) for i in input().split()]
    a.append(tmp[0]-1)
    b.append(tmp[1]-1)

isGood=[1]*n
for i in range(m):
    if h[a[i]] >= h[b[i]]:
        isGood[b[i]] = 0
    if h[a[i]] <= h[b[i]]:
        isGood[a[i]] = 0

ans=sum(isGood)
print(ans)

Measured memory_bytes: 22132
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int a[500];
int main(){
      int n,m,i,j,k,sum=0;
      scanf("%d%d",&n,&m);
      for(i=1;i<=n;i++)scanf("%d",&a[i]);
      sort(a+1,a+n+1);
      for(i=1;i<n;i++)
        if(m>=a[i]){
          sum++;
          m-=a[i];
        }else break;
      if(m==a[n])sum++;
      printf("%d\n",sum);
	  return 0;
}

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

bool check(string s, int start, int goal) {
    int stone_continuous_count = 0;
    for (int i = start + 1; i < goal; i++) {
        if (s[i - 1] == '#') {
            stone_continuous_count++;
            if (stone_continuous_count > 1)
                return false;
        } else {
            stone_continuous_count = 0;
        }
    }
    return true;
}

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    bool flag = true;
    if ((a - b) > 0 && (c - d) < 0 || (a - b) < 0 && (c - d) > 0) {
        flag = false;
        int none_continuous_count = 0;
        for (int i = max(a, b) - 1; i <= min(c, d) + 1; i++) {
            if (s[i - 1] == '.') {
                none_continuous_count++;
                if (none_continuous_count >= 3) {
                    flag = true;
                    break;
                }
            } else {
                none_continuous_count = 0;
            }
        }
    }
    if (flag == false) {
        cout << "No" << endl;
        return 0;
    }
    if (check(s, a, c) && check(s, b, d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 900
n, k = map(int, input().split())

a = list(map(int, input().split()))

min_cost = float("inf")
for i in range(2**n):
    if bin(i).count("1") != k or not i & 1:
        continue

    min_h = a[0]
    cost = 0
    for j in range(1, n):
        if i >> j & 1:
            min_h += 1
            cost += max(0, min_h-a[j])

        min_h = max(min_h, a[j])

    min_cost = min(min_cost, cost)

print(min_cost)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
	int len, len2;
	cin >> len;
	int* arr = new int[len + 1];
	for (int i = 0; i < len; i++)
		cin >> arr[i];
	cin >> len2;
	int* arr2 = new int[len2];
	for (int i = 0; i < len2; i++)
		cin >> arr2[i];
	int cnt = 0;
	for (int i = 0; i < len2; i++) {
		arr[len] = arr2[i];//set a mark at the end of the array to reduce times of compare
		int j;
		for (j = 0; arr[j] != arr[len]; j++);
		if (j != len) cnt++;//compare out of for-loop reduce the compare times
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3092
# coding: utf-8
from pdb import set_trace
#from collections import Counter
import itertools

N = int(input())
L = list(map(int, input().split(" ")))
# print(L)

# C = dict(Counter(L))
# L = sorted(list(set(L)), reverse=True)

# if N<3 or len(L)<3:
#     print(0)
#     exit()
# li = []
# for xa, a in enumerate(L[:-2]):
#     for xb, b in enumerate(L[xa+1:-1]):
#         for xc, c in enumerate(L[xa+2:]):
#             if a+b<c:
#                 break
#             if a+b>c and b+c>a and c+a>b and a!=b and b!=c and c!=a:
#                 _li = sorted([xa, xb+xa+1, xc+xa+2])
#                 if _li in li:
#                     continue
#                 li.append(_li)
# cnt = 0
# for l in li:
#     a = C[L[l[0]]]
#     b = C[L[l[1]]]
#     c = C[L[l[2]]]
#     cnt += (a * b * c)
# print(cnt)
cnt = 0
TRI = list(itertools.combinations(L, 3))
for tri in TRI:
    a, b, c = tri
    if a==b or b==c or c==a:
        continue
    elif a+b>c and a+c>b and b+c>a:
        cnt += 1
print(cnt)

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

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

  for(int i=0;i<3;i++){
    if(n[i] =='1'){
      n[i] = '9';
    }else{
      n[i] = '1'; 
    }
  }
  cout << n << endl;
}


Measured memory_bytes: 256
S=input()
S_len=len(S)
ans=True
for i in range(S_len):
  if i%2==0:
    if S[i]!='R' and S[i]!='U' and S[i]!='D':
      ans=False
      break
  else :
    if S[i]!='L' and S[i]!='U' and S[i]!='D':
      ans=False
      break
if ans:
  print('Yes')
else :
  print('No')

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

using namespace std;
using ll = long long;

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

int main() {
  int l, r, d;
  cin >> l >> r >> d;

  auto f = [&](int k) { return k / d; };

  cout << f(r) - f(l - 1) << endl;
  return 0;
}


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

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> p(n);
  for(int i = 0; i < n; i++) cin >> p.at(i);
  
  int k = abs(p.at(0) - x);
  int ans = k;
  for(int i = 1; i < n; i++){
    int un = abs(p.at(i) - x);
    int a = 0;
    for(int j = 1; j * j <= ans; j++){
      if(ans % j) continue;
      int t = ans / j;
      if(un % j == 0) a = max(a, j);
      if(un % t == 0) a = max(a, t);
    }
    ans = min(ans, a);
  }
  
  cout << ans << endl;    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,x,t,ans;
    cin >> n >> x >> t;
    if (n < x){
        ans = t;
    }
    else if (n % x == 0){
        ans = n * t / x;
    }
    else{
        ans = (n/x + 1) * t;
    }
    cout << ans << endl;
}

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

#define INFTY (1 << 30);
typedef long long ll;

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

  int max_C;
  max_C = B / A;

  if (max_C > C) {
    cout << C << endl;
  } else {
    cout << max_C << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
// Problem : A - Sheep and Wolves
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define pb push_back
#define vi vector<int>


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int s,w;
	cin>>s>>w;
	if(s<=w)
		cout<<"unsafe\n";
	else
		cout<<"safe\n";
   	return 0;
}



Measured memory_bytes: 3652
N = int(input())
S = input()

cws = [0] * N
for i in range(1, N):
  if S[i - 1] == 'W':
    cws[i] = 1
  cws[i] += cws[i - 1]

ces = [0] * N
for i in range(N - 2, -1, -1):
  if S[i + 1] == 'E':
    ces[i] = 1
  ces[i] += ces[i + 1]

print(min(cws[i] + ces[i] for i in range(N)))


Measured memory_bytes: 27040
#include<bits/stdc++.h>
using namespace std;
template<class T>void gi(T &x){
	int f;char c;
	for(f=1,c=getchar();c<'0'||c>'9';c=getchar())if(c=='-')f=-1;
	for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);x*=f;
}
typedef long long ll;
int a,b,c;ll k;
int main(){
  cin>>a>>b>>c>>k;
  if(k&1)swap(a,b);
  printf("%d\n",a-b);
  return 0;
}


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

using namespace std;

string getFixedN(string n) {
    string fixedN = n;
    for (int i = 0; i < n.size(); i++) {
        fixedN[i] = n[i] == '1' ? '9' : '1';
    }
    return fixedN;
}

int main(int argc, char const *argv[]) {
    string n;
    cin >> n;
    cout << getFixedN(n) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int main() {
  int n,m,c,t,cnt=0; cin>>n>>m>>c;
  int b[m];
  rep(i,m) cin>>b[i];
  rep(i,n){
    int s=0;
    rep(j,m) cin>>t,s+=t*b[j];
    if(s+c>0) cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdlib>
#include <stack>
using namespace std;

stack<int> S;
string ch; int ans;

inline void Initial() {
  std::ios::sync_with_stdio(false);
  cout.tie(0); cin.tie(0);
}
inline bool Input() {
  ch=cin.get();
  if (atoi(ch.c_str())==(-1)) {
    return false;
  }
  return true;
}
inline void Stack() {
  while (cin>>ch) {
    if (ch=="+") {
      int a=S.top(); S.pop();
      int b=S.top(); S.pop();
      S.push(a+b);
    }
    else if (ch=="-") {
      int b=S.top(); S.pop();
      int a=S.top(); S.pop();
      S.push(a-b);
    }
    else if (ch=="*") {
      int b=S.top(); S.pop();
      int a=S.top(); S.pop();
      S.push(a*b);
    }
    else {
      S.push(atoi(ch.c_str()));
    }
  }
  ans=S.top();
}
inline void Output() {
  cout<<ans<<endl;
}
int main() {
  Stack(),Output();
  return 0;
}



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

int main()
{
   ll n, a, b;
   cin >> n >> a >> b;
   ll ret =0;
   ll sum = a + b;
   ll cnt = n / sum;
   ll rem = n%sum;
   ret += cnt * a;
   if(rem < a) ret += rem;
   else ret += a;

   cout << ret << endl;
}

Measured memory_bytes: 256
'''
Created on 2020/08/31

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N,M,K=map(int,pin().split())
  A=list(map(int,pin().split()))
  B=list(map(int,pin().split()))
  a=[0]
  b=[0]
  for i in range(N):
    a.append(a[i]+A[i])
  for j in range(M):
    b.append(b[j]+B[j])
  ans=0
  l=M
  for k in range(N+1):
    if a[k]>K:
      break
    while b[l]>K-a[k]:
      l-=1
    ans=max(ans,l+k)
  print(ans)
  return
main()
#解説AC

Measured memory_bytes: 49256
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

vector<int> num;

int main() {
	
	int A[3] = {};
	
	while(cin >> A[0] >> A[1] >> A[2]) {
		num.clear();
		
		for(int i=0;i<3;i++)	
		num.push_back(A[i]);
		
	sort(num.begin(), num.end());
	
		for(int i=0;i<2;i++)
		cout << num[i] << " ";
	
	cout << num[2] << "\n";		
	}
	
	return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int a[3];
      rep(i,3)cin >> a[i];
      sort(a,a+3);
      cout << a[0]+a[1] << endl;
      return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

bool dbgflag = false;

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

  string s;
  cin >> s;

  map<char, int> cnt;
  for (int i = 0; i < s.size(); i++) cnt[(char)s[i]]++;

  if ((((cnt['N'] == 0) && (cnt['S'] != 0)) || ((cnt['N'] != 0) && (cnt['S'] == 0))) || (((cnt['E'] == 0) && (cnt['W'] != 0)) || ((cnt['E'] != 0) && (cnt['W'] == 0)))) cout << "No" << endl;
  else cout << "Yes" << endl;
}


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

using namespace std;

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

typedef long long int lld;
typedef pair<int, int> pii;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(15);
	cout << fixed;

	int n;
	cin >> n;
	cout << 3 * n * n << '\n';



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi S(N);
    rep(i,N) cin>>S[i];
    int counter=0;
    rep(i,N) counter+=S[i];
    bool ok=true;
    rep(i,N) if(S[i]%10!=0) ok=false;
    if(ok) cout<<0<<endl;
    else {
        if(counter%10!=0) cout<<counter<<endl;
        else {
            sort(all(S));
            int diff;
            rep(i,N) {
                if(S[i]%10!=0) {
                    diff=S[i];
                    break;
                }
            }
            cout<<counter-diff<<endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
pair<long long,int> a[2020];
long long dp[2020][2020],res;
void Update(int x,int y,long long val){
	dp[x][y]=max(dp[x][y],val);
}
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].first;
		a[i].second=i;
	} 
	sort(a,a+n);
	reverse(a,a+n);
	for(int x=0;x<n;x++){
		for(int y=0;x+y<n;y++){
			Update(x+1,y,dp[x][y]+a[x+y].first*llabs(a[x+y].second-x));
			Update(x,y+1,dp[x][y]+a[x+y].first*llabs(a[x+y].second-(n-1-y)));
		}
	}
	for(int i=0;i<n;i++)
		res=max(res,dp[i][n-i]);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 26348
const double M_PI=3.14159265358979323846;
#include <stdio.h>

int main()
{
	double r;
	scanf("%lf", &r);

	double a = r * r * M_PI;
	double b = 2 * r * M_PI;

	printf("%lf %lf\n", a, b);
}


Measured memory_bytes: 2756
#include <iostream>
using namespace std;
long long int c(int a, int b){
  long long int ret = 1;
  for(int i = 0; i < b; ++i){
    ret *= (a - i);
  }
  for(int i = 0; i < b; ++i){
    ret /= (b + 1);
  }
  return ret;
}
int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; ++i) cin >> A[i];
  int n = 0;
  for(int i = 0; i < N; ++i){
    if(A[i]%2 == 0) ++n;
  }
  long long int ans = 1;
  for(int i = 0; i < N; ++i){
    ans *= 3;
  }
  long long int t = 1;
  for(int i = 0; i < n; ++i){
    t *= 2;
  }
  cout << ans-t << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
static const int INFTY=(1<<21);
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 10002
int n,M[MAX][MAX],color[MAX],d[MAX];
vector <pair<int,int> > adj[MAX];
void dijkstra(){
    priority_queue <pair<int,int> > PQ;
    d[0]=0;
    color[0]=GRAY;
    PQ.push(make_pair(0,0));
    while(!PQ.empty()){
        pair<int,int> f=PQ.top();
        PQ.pop();
        int u=f.second;
        color[u]=BLACK;
        if(d[u]<f.first*(-1)) continue;

        for(int j=0;j<adj[u].size();j++){
            int v=adj[u][j].first;
            if(color[v]==BLACK) continue;
            if(d[v]>d[u]+adj[u][j].second){
                d[v]=d[u]+adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                color[v]=GRAY;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i<<" "<<(d[i]==INFTY ? -1:d[i])<<endl;
    }
}
int main(){
   int u,k,v,c;
   cin>>n;
   for(int i=0;i<n;i++){
       cin>>u>>k;
       for(int j=0;j<k;j++){
           cin>>v>>c;
           adj[u].push_back(make_pair(v,c));
       }
   }
   for(int i=0;i<n;i++){
       color[i]=WHITE;
       d[i]=INFTY;
   }
   dijkstra();
   return 0;
}


Measured memory_bytes: 8052
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;


/* Iterative Function to calculate (x^y)%p 
  in O(log y) */
int power(int x, int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
}

long modPow(long a, long x, long p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

long modInverse(long a, long p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}

int numerator = -1;
int denominator = -1;

long modBinomial(long n, long k, long p) {
// calculates C(n,k) mod p (assuming p is prime).

  
  if (numerator == -1){
    numerator = 1;
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }
  }
  else
    numerator = numerator * (n - (k - 1)) % p;

  if (denominator == -1){
    denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }
  }else{
    denominator = (denominator * k) % p;
  }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}



signed main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);


  int mod = 998244353;
  int n, m, k;
  cin >> n >> m >> k;

  int ans = 0;
  for (int i = 0 ; i <= k ; i++)
    ans += (((m * modBinomial(n - 1, i, mod)) % mod) * power(m - 1, n - (i + 1), mod) % mod), ans %= mod;

  cout << ans << endl;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan= new Scanner(System.in);
		int h=scan.nextInt();
		int a=scan.nextInt();int c=1;
		while(true)
		{
			
			if(h>a)
			{
				h-=a;
				c++;
			}
			else
			{
				System.out.println(c);
				break;
			}
		}

	}

}


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


long long f(long long A,long long B,long long now = 60){
	if(A==B)return 1;
	if(((A>>now)&1)==((B>>now)&1)){
		if((A>>now)&1){
			A ^= 1LL<<now;
			B ^= 1LL<<now;
		}
		return f(A,B,now-1);
	}
	else{
		long long t = 1LL<<now;
		vector<long long> l,r;
		l.push_back(A);
		for(long long i=0;true;i++){
			if(t+(1LL<<i)>B){
				r.push_back(t+(1LL<<i));
				break;
			}
		}
		
		l.push_back(t+A);
		r.push_back(t*2);
		if(l[1]>=l[0]&&l[1]<r[0]){
			return max(r[0],r[1])-min(l[0],l[1]);
		}
		else{
			return r[0]-l[0]+r[1]-l[1];
		}
	}
}
	

int main(){
	
	long long A,B;
	cin>>A>>B;
	
	cout<<f(A,B)<<endl;
	
	return 0;
}

Measured memory_bytes: 3644
import sys
import math

k = int(input())
a = list(map(int,input().split()))

if a[-1] != 2:
    print(-1)
    sys.exit()
else:
    mi,ma = 2,2
    for i in range(k-1,-1,-1):
        if mi == ma and mi%a[i] != 0 :
            print(-1)
            sys.exit()
        elif mi != ma and math.floor(ma/a[i]) - math.floor((mi-1)/a[i]) == 0:
            print(-1)
            sys.exit()
        else:
            mi = math.ceil(mi / a[i]) * a[i]
            ma = math.floor(ma / a[i]) * a[i] + a[i] - 1
            
    print(mi,ma)

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



using namespace std;

int ans = 0;

main()
{
    int a, b, c;

    cin >> a >> b >> c;

    int mx = a, mn = b, mid = -1, c1 = 0, c2 = 0;

    mx = max(mx, max(b, c));
    mn = min(mn, min(a, c));

    if (a != mx && a != mn)
        mid = a;
    if (b != mx && b != mn)
        mid = b;
    if (c != mx && c != mn)
        mid = c;

    if (a == mx)
        c1++;
    if (b == mx)
        c1++;
    if (c == mx)
        c1++;

    if (mid == -1)
    {
        if(c1 > 1)
            mid = mx;
        else
            mid = mn;
    }

    if ((mid - mn) % 2 != 0)
    {
        ans++;
        mx++;
        mn++;
    }
    ans += (mid - mn) / 2;
    ans += (mx - mid);

    cout << ans;
}




Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N=ii()
    A=lmis()
    A.sort()
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)





main()



Measured memory_bytes: 22928
#include<stdio.h>
#include<math.h>
#define TRUE 1
#define FALSE 2

int isPrime(int);

int main(){
  int i,n,count=0;
  scanf("%d",&n);
  int data[n];
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
    if(isPrime(data[i])==TRUE){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
  }
  

int isPrime(int data){
  int i=3;
  if(data==2)return TRUE;
  if(data<2||data%2==0)return FALSE;
  while(i<=sqrt(data)){
    if(data%i==0){
      return FALSE;
    }
    i=i+2;
  }
  return TRUE;
}



Measured memory_bytes: 2056
def solve():
    N, M = map(int, input().split())
    edges = [[] for _ in range(N*3+1)]
    for i in range(M):
        u, v = map(int, input().split())
        u2, u3 = u+N, u+2*N
        v2, v3 = v+N, v+2*N
        edges[u].append(v2)
        edges[u2].append(v3)
        edges[u3].append(v)
    S, T = map(int, input().split())
    
    dist = [10**15 for _ in range(N*3+1)]
    dist[S] = 0
    que = [S]
    while que:
        que_tmp = []
        for parent in que:
            for child in edges[parent]:
                if dist[child] != 10**15:
                    continue
                que_tmp.append(child)
                dist[child] = dist[parent] + 1
        que = que_tmp
    
    if dist[T] != 10**15:
        print(dist[T]//3)
    else:
        print(-1)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 59888
using System;
using System.Collections.Generic;

namespace ABC144_A
{
    class Program
    {
        static void Main(string[] args) {

            string[] input = Console.ReadLine().Split();
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            if (n <= 9 && k <= 9) {
                Console.WriteLine(n * k);
            } else Console.WriteLine(-1);

            return;

            string strAns = "Yes";
            int intAns = 0;

            var list = new List<int>();
            var arr = new int[n];
            for(int i = 0; i < n; i++) {

            }


            Console.WriteLine(strAns);
            Console.WriteLine(intAns);
        }
    }
}

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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int n;
	cin >> n;
	int count = 0;
	ll sum = 0;
	ll mini = 1000000001;
	ll a;
	for(int i = 0; i < n; i++){
		cin >> a;
		sum += abs(a);
		mini = min(mini,abs(a));
		if(a < 0)count++;
	}
	if(count % 2)cout << sum - 2 * mini << endl;
	else cout << sum << endl;
	return 0; 
}


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

int main(void) {
	string a, b; cin >> a >> b;

	if (a.size() < b.size()) {
		cout << "LESS" << endl;
		return 0;
	}

	if (a > b) {
		cout << "GREATER" << endl;
	}
	else if (a == b) {
		cout << "EQUAL" << endl;
	}
	else { cout << "LESS" << endl; }

	return 0;
}



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

int main(int argc, char const *argv[])
{
    int A,B;
    cin>>A>>B;

    int m=A+B;
    m=max(m,A-B);
    m=max(m,A*B);

    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())
if len(s) < len(t):
    
    k = True
    for i in range(len(s)):
        if s[i] !=t[i]:k = False


s.sort()
t.sort(reverse = True)
ok = "".join(s) < "".join(t)
if len(s) < len(t):ok |=k
if ok:print('Yes')
else:print('No')

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

int main(){
  int n;
  cin >> n;
  vector<string>s(n);
  for(int i=0;i<n;i++) cin >> s[i];
  for(int i=0;i<n;i++) sort(s[i].begin(), s[i].end());
  sort(s.begin(), s.end());

  ll ans = 0;
  int sum = 1;
  for(int i=1;i<n;i++){
    if(s[i] == s[i-1]){
      ans += sum;
      sum++;
    }else{
      sum = 1;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 6432
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            if(abs(v[i] - v[j]) % (n - 1) == 0)
            {
                cout << v[i] << " " << v[j] << endl;
                return 0;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};

int main() {
    int n,m,k=1;
    cin >> n>>m;
    rep(i,m){k*=2;}
    cout << ((n-m)*100+1900*m)*k << endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[310000];
int sum[310000];
vector<pair<int,int> >g[310000];
int dp[310000];
int segtree[524288];
int query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return -1;
	if(c<=a&&b<=d)return segtree[e];
	int L=query(a,(a+b)/2,c,d,e*2);
	int R=query((a+b)/2+1,b,c,d,e*2+1);
	if(L==-1)return R;
	if(R==-1)return L;
	if(dp[L]+(R-L)-(sum[R]-sum[L])<dp[R])return L;
	else return R;
}
void update(int a){
	a+=262144;
	a/=2;
	while(a){
		int L=segtree[a*2];
		int R=segtree[a*2+1];
		if(dp[L]+(R-L)-(sum[R]-sum[L])<dp[R])segtree[a]=L;
		else segtree[a]=R;
		a/=2;
	}
}
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<290000;i++)sum[i+1]=sum[i]+p[i];
	int b;scanf("%d",&b);
	for(int i=0;i<262144;i++)segtree[i+262144]=i;
	for(int i=0;i<=290000;i++)dp[i]=mod;
	dp[0]=0;
	for(int i=0;i<262144;i++)update(i);

	for(int i=0;i<b;i++){
		int l,r;scanf("%d%d",&l,&r);l--;
		g[l].push_back(make_pair(r,(r-l)-(sum[r]-sum[l])));
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<g[i].size();j++){
			int at=query(0,262143,i,g[i][j].first,1);
			dp[g[i][j].first]=dp[at]+(g[i][j].first-at)-(sum[g[i][j].first]-sum[at]);
			update(g[i][j].first);
		}
		dp[i+1]=min(dp[i+1],dp[i]+p[i]);
		update(i+1);
		dp[i]=mod;
		update(i);
	}
	printf("%d\n",dp[a]);
}

Measured memory_bytes: 18816
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;

signed main(void)
{
	while (1) {
		int n, m;
		cin >> n >> m;
		if (n == 0) break;
		int a[100];
		int asum = 0;
		rep(i, n) {
			reader(a[i]);
			asum += a[i];
		}
		set<int> b;
		int bsum = 0;
		rep(i, m) {
			int buf;
			reader(buf);
			bsum += buf;
			b.insert(buf);
		}
		int a1 = 10000;
		int b1 = 10000;
		int target = bsum - asum;
		if (abs(target) % 2 == 0) {
			int d = abs(target) / 2;
			if (target < 0) d *= -1;
			rep(i, n) {
				auto target_b = b.find(d + a[i]);
				if (target_b != b.end()) {
					if (a[i] + *target_b < a1 + b1) {
						a1 = a[i];
						b1 = *target_b;
					}
				}
			}
		}
		if (a1 > 1000) puts("-1");
		else writerLn(a1, b1);
	}
	return 0;
}

Measured memory_bytes: 3104
H, W = map(int, input().split())

if H==1 or W==1:
  Answer =1

elif W%2 ==0:
  Answer = W/2*H
  
else:
  count = (W-1)/2 +1
  if H%2 ==0:
    Answer = count*H - H/2
  else:
    Answer = count*H - (H-1)/2

print(int(Answer))


Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << ((b + c - 1) / b <= (a + d - 1) / d ? "Yes" : "No") << endl;
}

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


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	int ans = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			ans += A.at(i) * A.at(j);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
a,b,q=map(int,input().split())
from bisect import bisect_left
s_list=[]
for i in range(a):
    s_list.append(int(input()))
t_list=[]
for i in range(b):
    t_list.append(int(input()))
for i in range(q):
    x=int(input())
    s_i=bisect_left(s_list,x)
    t_i=bisect_left(t_list,x)
    sL=[]
    if s_i==0:
        sL.append(s_list[0])
    elif s_i==a:
        sL.append(s_list[a-1])
    else:
        sL.append(s_list[s_i-1])
        sL.append(s_list[s_i])
    tL=[]
    if t_i==0:
        tL.append(t_list[0])
    elif t_i==b:
        tL.append(t_list[b-1])
    else:
        tL.append(t_list[t_i-1])
        tL.append(t_list[t_i])
    Min=10**16
    for i in sL:
        for j in tL:
            Min=min(Min,abs(x-i)+abs(j-i))
            Min=min(Min,abs(x-j)+abs(j-i))
    print(Min)
    


Measured memory_bytes: 80728
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <map>
#include <numeric>
#include <queue>

using namespace std;
typedef long long ll;

int main(){
    int n, im, l;
    cin >> n >> im >> l;
    vector<vector<ll>> d(n,vector<ll>(n,10000000000));
    int ai, bi;
    ll ci;
    for(int i=0; i<im; i++){
        cin >> ai >> bi >> ci;
        if(ci<=l){
            d[ai-1][bi-1] = ci;
            d[bi-1][ai-1] = ci;
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            for(int k=0; k<n; k++){
                d[j][k] = min(d[j][i]+d[i][k], d[j][k]);
            }
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(d[i][j]<=l){
                d[i][j] = 1;
            }else{
                d[i][j] = 100000000000;
            }
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            for(int k=0; k<n; k++){
                d[j][k] = min(d[j][i]+d[i][k], d[j][k]);
            }
        }
    }
    int q, si ,ti;
    cin >> q;
    vector<int> ans(q);
    for(int i=0; i<q; i++){
        cin >> si >> ti;
        if(d[si-1][ti-1] < 100000000000){
            ans[i] = d[si-1][ti-1]-1;
        }
        else{
            ans[i] = -1;
        }
    }
    for(int i=0; i<q; i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const ll MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vvll A(2, vll (N, 0) );
    REP(i, 2)
        REP(j, N)
            cin >> A[i][j];
    vvll B1 = A, B2 = A;
    int ans;
    B2[1][0] += B2[0][0];
    REP(i, N-1) {
        B1[0][i+1] += B1[0][i];
        B1[1][i+1] += B1[0][i+1];
        B2[1][i+1] += B2[1][i];
        if (B1[1][i+1] < B2[1][i+1])
            B1[1][i+1] = B2[1][i+1];
        else
            B2[1][i+1] = B1[1][i+1];
    }
    if (B1[0][N-1] < B2[1][N-1])
            cout << B2[1][N-1] << endl;
    else
        cout << B1[1][N-1] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
	if(ch=='A')return 1;
	else if(ch=='C')
		return 2;
	else if(ch=='G')
		return 3;
	else if(ch=='T')
		return 4;
	else 
		return 0;
}

long long getKey(char str[]){
	long long sum=0,p=1,i;
	for(i=0;i<strlen(str);i++){
		sum+=p*(getChar(str[i]));
		p*=5;
	}
	return sum;
}

int h1(int key){
	return key%M;
}

int h2(int key){
	return 1+(key%(M-1));
}

int find(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)
			return 1;
		else if(strlen(H[h])==0)
			return 0;
	}
	return 0;
}

int insert(char str[]){
	long long key,i,h;
	key=getKey(str);
	for(i=0;;i++){
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)
			return 1;
		else if(strlen(H[h])==0){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}


int main(){
	int i,n,h;
	char str[L],com[9];
	for(i=0;i<M;i++)
		H[i][0]='\0';
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",com,str);
		if(com[0]=='i'){
			insert(str);
		}
		else{
			if(find(str)){
				printf("yes\n");
			}
			else{
				printf("no\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 16100
from sys import stdin
import math


N = int(stdin.readline().rstrip())

def sum_of_digit(n):
    total = 0
    s = str(n)
    for i in range(len(s)):
        total = total + int(s[i:i+1])

    return total


def isHarshad(n):
    return n % sum_of_digit(n) == 0

if isHarshad(N):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
vector<int> L;
int DP[2005];
priority_queue<int, vector<int>, greater<int> > que;

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

  cin >> N;
  int a;
  rep(i, N) {
    cin >> a;
    L.push_back(a);
  }
  sort(ALL(L));
  rep(i, N) {
    if (i==0 || i==1) continue;
    rep(j, i-1) {
      que.push(L[j]+L[i-1]);
    }
    int cnt = i-1;
    while(true) {
      if (que.empty()) {
        DP[i] = DP[i-1];
        break;
      }
      int q = que.top();
      if (q<=L[i]) { // qは小さい二つの辺の和
        que.pop();
        cnt--;
      } else {
        DP[i] = DP[i-1] + que.size();
        break;
      }
    }
  }
  cout << DP[N-1] << "\n";
  return 0;
}

Measured memory_bytes: 8812
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for A in combinations_with_replacement(range(1, M+1), N):
    v = 0
    for a, b, c, d in l:
        if A[b-1]-A[a-1]==c:
            v += d
    ans = max(ans, v)
print(ans)


Measured memory_bytes: 9136
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(ReadLine());
            var line = ReadLine()
                .Split(' ')
                .Select(_ => int.Parse(_))
                .ToArray();

            int count = 0;
            for (int i = 0; i < line.Length; i++)
            {
                if (line[i] == i + 1)
                {
                    int j = (i + 1 < line.Length)
                        ? i + 1
                        : i - 1;
                    int buf = line[i];
                    line[i] = line[j];
                    line[j] = buf;
                    count++;
                }
            }

            WriteLine(count);
            ReadLine();
        }
    }
}


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

int main(void){
	int i,j, H,W,length,x,y;
	char buf[102];
	char field[101][101],check[101][101];

	while(scanf("%d %d",&H,&W)!=EOF){
		if(H==0&&W==0) break;
		fgets(buf,sizeof(buf),stdin);
		for(i=0;i<H;i++){
			for(j=0;j<W;j++) check[i][j]=0;
		}

		for(i=0;i<H;i++){
			fgets(buf,sizeof(buf),stdin);
			length=strlen(buf);
			buf[length-1]='\0';
			for(j=0;j<length;j++) field[i][j]=buf[j];
			field[i][j]='\0';
		}
		x=y=0;
		for(;;){
			check[x][y]+=1;
			if(check[x][y]>1){
				printf("LOOP\n");
				break;
			}
			else{
				if(field[x][y]=='>') y++;
				else if(field[x][y]=='<') y--;
				else if(field[x][y]=='^') x--;
				else if(field[x][y]=='v') x++;
				else if(field[x][y]=='.'){
					printf("%d %d\n",y,x);
					break;
				}
			}
		}
	}
	
	return 0;
}

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

int main(){
  int a,b;
  char s[10],t[10],u[10];
  cin>>s>>t>>a>>b;
  cin>>u;
    if(strcmp(s,u)==0){
      a--;
    }else if(strcmp(t,u)==0){
      b--;
    }
  
  cout<<a<<" "<<b<<endl;
  return 0;
}

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

int main() {
    int cnt=0;
    string S;
    cin >> S;

    for (int i=0; i<S.size(); i++) {
        if (S[i] == 'o') cnt++;
    }

    cout << 700 + cnt * 100 << endl;

}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
a = []
b = []
m.times do
  x, y = gets.split.map(&:to_i)
  a << y if x == 1
  b << x if y == n
end
if a & b == []
  puts 'IMPOSSIBLE'
else
  puts 'POSSIBLE'
end

Measured memory_bytes: 9852