akhauriyash/Code-Regression huggingface dataset:
"""
隣接リストで与えられる有向グラフを，隣接行列で構成しなおす
"""
n = int(input())

for i in range(n):
    mat = [0 for _ in range(n)]
    l = list(map(int, input().split()))
    deg = l[1]
    for r in range(deg):
        index = l[r+2]-1
        mat[index] = 1
    print(' '.join(map(str, mat)))



Measured memory_bytes: 5616
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 8000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int from,to,cost;};
int pow2(int n,int i){if(i==1)return n;return n*pow(n,i-1);};

typedef long long ll;

using namespace std;


//�ő����
ll gcd(ll a,ll b){
    
    if(a==0 || b==0)return 0;
    if(a<b){
        ll sw;
        sw=a;
        a=b;
        b=sw;
    }
    
    ll r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
//�ŏ����{��
ll lcm(ll a,ll b){


    if(a==0 || b==0)return 0;

    return a/gcd(a,b)*b;

}

int ans,ans2;
int n,m;
vector<int> factor;



signed main(){  
    
    cin>>n>>m;
    int num=gcd(n,m);
    for(int i=1;i*i<=num;i++){
        if(num%i==0){
            factor.push_back(i);
            if(i!=num/i)factor.push_back(num/i);
        }
        //cout<<num<<endl;
    }
    //factor.push_back(num);

    sort(factor.begin(),factor.end());
    int G=factor[0];
    for(auto x:factor){
        int G2=lcm(x,G);
        if(G2==x*G){
            ans++;
            G=G2;
            
        }//cout<<x<<endl;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
/*input
2000 20 100
*/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long 
#define vl vector<ll> 
#define pl pair<ll,ll> 
#define vpl vector<pl> 
#define vvl vector<vl> 
using namespace std;
int main() {
ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

  		ll d,t,s;
  		cin>>d>>t>>s;
  		if(s*t >= d)cout<<"Yes";
  		else cout<<"No";
return 0;
}


Measured memory_bytes: 3596
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    a, b, c = map(int, input().split())
    k = int(input())
    x = 0
    y = 0
    z = 0
    for x in range(0, k+1):
        for y in range(0, k-x+1):
            for z in range(0, k-(x+y)+1):
                a1 = a * (2 ** x)
                b1 = b * (2 ** y)
                c1 = c * (2 ** z)
                a2 = a * (2 ** x)
                b2 = b * (2 ** z)
                c2 = c * (2 ** y)
                a3 = a * (2 ** y)
                b3 = b * (2 ** x)
                c3 = c * (2 ** z)
                a4 = a * (2 ** y)
                b4 = b * (2 ** z)
                c4 = c * (2 ** x)
                a5 = a * (2 ** z)
                b5 = b * (2 ** x)
                c5 = c * (2 ** y)
                a6 = a * (2 ** z)
                b6 = b * (2 ** y)
                c6 = c * (2 ** x)
                if (a1 < b1 and b1 < c1) or (a2 < b2 and b2 < c2) or(a3 < b3 and b3 < c3) or (a4 < b4 and b4 < c4) or (a5 < b5 and b5 < c5) or (a6 < b6 and b6 < c6):
                    print("Yes")
                    exit()
    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 72644
/*2019/08/25 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/

int main(){
    ll n,k;
    static ll a[200000],b[200000];
    static ll num[200000]={};

    scanf("%lld %lld",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%lld %lld",&a[i],&b[i]);
        num[a[i]-1]+=b[i];
    }

    ll cnt=0;
    for(int i=0;i<100000;i++){
        cnt+=num[i];
        if(cnt>=k){
            printf("%d\n",i+1);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3456
// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sorva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll mod=1e9+7;
ll const maxn=1e6+6;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {     
    bool prim[n+1]; 
    memset(prim, true, sizeof(prim)); 
  
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) { 
            for (int i=p*p; i<=n; i += p) 
                prim[i] = false; 
        } 
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v; 
}
ld dis(ll x1,ll y1,ll x2,ll y2){
    ld ans=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    return ans;
}
ll fact(ll n){
    ll ans=1;
    fr(i,1,n)ans*=i;
    return ans;
}
int main(){

    fio;
    ll n;
    cin>>n;
    vpii a(n);
    fr1(i,n)cin>>a[i].fi>>a[i].se;
    vld v;
    fr1(i,n){
        fr(j,i+1,n-1){
            ld x=dis(a[i].fi,a[i].se,a[j].fi,a[j].se);
            v.pb(x);
        }
    }
    ll cnt=2;
    cnt*=(fact(n-1));
    ld ans=0;
    fr1(i,sz(v)){
        //cout<<v[i]<<" ";
        ans+=cnt*v[i];
    }
    ll r=fact(n);
    ld res=ans/r;
    cout<<fixed<<setprecision(10)<<res;
   return 0;
}

Measured memory_bytes: 256
import math
N = 10**5
Q = int(input())

primes = set()
visited = set()
for i in range(2,N+1):
  if i in visited: continue
  primes.add(i)
  j = i
  while j <= N:
    visited.add(j)
    j += i

C = [0 for _ in range(N+1)]
ct = 0
for x in range(3,N+1,2):
  if x in primes and (x+1)//2 in primes:
    ct += 1
  C[x] = ct
  
#print(primes)
#print(C)

for _ in range(Q):
  l, r = map(int, input().split())
  print(C[r] - C[l-2])
  

Measured memory_bytes: 94096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int K = in.nextInt();
		int R = in.nextInt();
		int S = in.nextInt();
		int P = in.nextInt();
		char[] c = in.next().toCharArray();
		long ans = 0;
		for (int i = 0; i < N; i++) {
			if (c[i] == 'r') {
				if ((i - K) >= 0 && c[i] == c[i - K]) {
					c[i] = '0';
				} else {
					ans += P;
				}
			} else if (c[i] == 's') {
				if ((i - K) >= 0 && c[i] == c[i - K]) {
					c[i] = '0';
				} else {
					ans += R;
				}
			} else if (c[i] == 'p') {
				if ((i - K) >= 0 && c[i] == c[i - K]) {
					c[i] = '0';
				} else {
					ans += S;
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 28276
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


N, Q = map(int, input().split())
G = [[] for _ in [0]*N]
for _ in [0]*(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

cnt = [0]*N
for _ in [0]*Q:
    p, x = map(int, input().split())
    cnt[p-1] += x

def dfs(v=0, pre=-1, x=0):
    cnt[v] += x
    for u in G[v]:
        if u == pre:
            continue
        dfs(u, v, cnt[v])
    return


dfs()
print(*cnt)


Measured memory_bytes: 268436
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    string S;
    cin >> S;
    int cnt = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'p') {
            cnt++;
        }
    }
    cout << S.size()/2-cnt << endl;
}


Measured memory_bytes: 3668
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m, b[33], a[33], c, cnt;

int main(){
    cin >> n >> m >> c;
    REP(i, m)cin >> b[i];
    REP(i, n){
        REP(j, m)cin >> a[j];
        int num = c;
        REP(j, m)num += a[j]*b[j];
        if(num > 0)cnt++;
    }
    cout << cnt << endl;
}

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

int min(int a, int b){
    return (a<b)?a:b;
}

int main(){
    int n;
    cin >> n;
    int h[n];
    int cost[n];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    cost[0] = 0;
    cost[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
    }
    cout << cost[n-1];
}


Measured memory_bytes: 4364
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 102;
const int CKiek = 10;

int n, F[CMax][CKiek], P[CMax][CKiek+1], S[CMax], ats = -1000000007;

void go(int zingsnis, int sum[], int paimta) {
    int sum1 = 0, sum2 = 0, kiek1 = 0, kiek2 = 0;
    if (zingsnis == CKiek) return;

    go(zingsnis+1, sum, paimta);

    for (int i = 0; i < n; i++) {
        sum1 += P[i][sum[i]];
        if (F[i][zingsnis] > 0) {
            sum[i]++;
        }
        sum2 += P[i][sum[i]];
    }

    go(zingsnis+1, sum, paimta + 1);

    for (int i = 0; i < n; i++) {
        if (F[i][zingsnis] > 0) {
            sum[i]--;
        }
    }

    if (paimta > 0) ats = max(ats, sum1);
    ats = max(ats, sum2);
}

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < CKiek; j++) {
            scanf("%d", &F[i][j]);
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < CKiek+1; j++) {
            scanf("%d", &P[i][j]);
        }
    }

    go(0, S, 0);

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


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	static int s[];
	
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		
		int n, q, com, x, y;
		
		n = scan.nextInt();
		q = scan.nextInt();
		
		s = new int[n];
		
		for(int i = 0; i < n; i++) {
			s[i] = -1;
		}
		
		for(int i = 0; i < q; i++) {
			com = scan.nextInt();
			x = scan.nextInt();
			y = scan.nextInt();

			x = Search(x);
			y = Search(y);
			
			if(com == 0 && x != y) { //unite x??¨y?????\?????????????????????????????????????????¨?????????
				if(y < x) {
					int tmp = x;
					x = y;
					y = tmp;
				}
				
				s[x] += s[y];
				s[y] = x;
				
			} else if(com == 1) {//same
				if(x == y) {
					System.out.println(1);
				} else {
					System.out.println(0);
				}
			}
		}
		
		scan.close();
	}
	
	public static int Search(int x){ 
		//???????????????????????°???????´??????????????????°????????¨???????????\?????????????????????????±???????
		if(s[x] < 0) {
			return x;
		} else {
			return s[x] = Search(s[x]);
		}
	}
}

Measured memory_bytes: 101180
#include<bits/stdc++.h>
using namespace std;
string a,yl="AKIHABARA";
int now,k;
int main(){
    cin>>a;
    for(int s=0;s<a.size();s++){
        if(a[s]==yl[now]){now++;}//匹配成功
        else{//匹配不成功
            if(s>0)
            if(a[s]==a[s-1]){//连续两个一样
                cout<<"NO"<<endl;
                exit(0);} 
            if(yl[now]=='A')now++,s--;//是A，pass
            else{//不是A，输出NO
                cout<<"NO"<<endl;
                exit(0);}}}
    k=a.size();//最后，查错
    for(int s=0;s<a.size();s++){
        if(a[s]=='A')k--;}
    if(k==5)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
}

Measured memory_bytes: 384
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    s = s.replace("hi","");
    if(s.length() == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

int main(){
    
    long long N, M;
    cin >> N >> M;
    
    if(N==1 && M==1)    cout << 1 << endl;
    else if(N==1 && M!=1)   cout << M-2 << endl;
    else if(N!=1 && M==1)   cout << N-2 << endl;
    else if(N!=1 && M!=1)   cout << (N-2)*(M-2) << endl;

}


Measured memory_bytes: 256
A,B,C = open(0).read().split()
P = "a"

for x in range(len(A)+len(B)+len(C)):
  if P=="a":
    if A=="":
      print("A")
      exit()
    else:
      P = A[0]
      A = A[1:]
      
  elif P=="b":
    if B=="":
      print("B")
      exit()
    else:
      P = B[0]
      B = B[1:]
      
  else:
    if C=="":
      print("C")
      exit()
    else:
      P = C[0]
      C = C[1:]

Measured memory_bytes: 8960
class Dice:
    top = 0
    def __init__(self,one,two,three,four,five,six):
        self.one = one
        self.two = two
        self.three = three
        self.four = four
        self.five = five
        self.six = six

    def role(self,direction):
        global top
        if(direction == 'S'):
                t1 = self.one
                self.one = self.five
                t2 = self.two
                self.two = t1
                t3 = self.six
                self.six = t2
                t4 = self.five
                self.five = t3
                top = self.one
       
        if(direction == 'E'):
            t1 = self.one
            self.one = self.four
            t2 = self.three
            self.three = t1
            t3 = self.six
            self.six = t2
            self.four = t3
            top = self.one
        if(direction == 'N'):
            t1 = self.one
            t2 = self.two
            t5 = self.five
            t6 = self.six
            self.one = t2
            self.two = t6
            self.six = t5
            self.five = t1
            top = self.one
        if(direction == 'W'):
            t1 = self.one
            t3 = self.three
            t4 = self.four
            t6 = self.six
            self.one = t3
            self.four = t1
            self.six = t4
            self.three = t6
            top = self.one
            
        return(top)
arr = [int(i) for i in input().split()]
op = str(input())
final = 0
a = Dice(arr[0],arr[1],arr[2],arr[3],arr[4],arr[5])
for i in range(len(op)):
     final = a.role(op[i])
print(final)



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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long H, long long W, std::vector<std::string> A){
  queue<vector<ll>> q;
  for(ll i=0; i<H; i++) {
    for(ll j=0; j<W; j++) {
      if(A[i][j]=='#') {
	vector<ll> v = {0, i, j};
	q.push(v);
      }
    }
  }
  ll d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
  ll ans = 0;
  while(!q.empty()) {
    auto v = q.front();
    q.pop();
    for(ll i=0; i<4; i++) {
      ll nx = v[2] + d[i][0];
      ll ny = v[1] + d[i][1];
      if(0<=nx and nx<W and 0<=ny and ny<H and A[ny][nx]=='.') {
	A[ny][nx] = '#';
	vector<ll> nv = {v[0]+1, ny, nx};
	ans = max(ans, nv[0]);
	q.push(nv);
      }
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long H;
  scanf("%lld",&H);
  long long W;
  scanf("%lld",&W);
  std::vector<std::string> A(H);
  for(int i = 0 ; i < H ; i++){
    std::cin >> A[i];
  }
  solve(H, W, std::move(A));
  return 0;
}


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

#define ll long long
const int N = 1e3 + 5;
const ll mod = 1e9 + 7;

ll mul(ll a, ll b){
	return (a * b) % mod;
}
ll power(ll x, ll y){
	if(y == 1){
		return x;
	} else {
		ll tmp = power(x, y/2);
		if(y & 1){
			return mul(mul(tmp, tmp), x);
		} else {
			return mul(tmp, tmp);
		}
	}
}

ll n, a, b, c, d, dp[N][N];
ll fac[N], rev[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> a >> b >> c >> d;
	fac[0] = 1;
	rev[0] = power(fac[0], mod - 2);
	for(int i = 1; i <= n; i++){
		fac[i] = (fac[i - 1] * i) % mod;
		rev[i] = power(fac[i], mod - 2);
	}
	for(int i = a - 1; i <= b; i++){
		dp[0][i] = 1;
	}
	for(int i = 1; i <= n; i++){
		for(int j = a; j <= b; j++){
			dp[i][j] = dp[i][j - 1];
			for(int k = c; k <= d && k * j <= i; k++){
				ll tmp = mul(mul(mul(fac[n - i + j * k], rev[n - i]), power(rev[j], k)), rev[k]);
				dp[i][j] = (dp[i][j] + mul(dp[i - j * k][j - 1], tmp)) % mod;
			}
		}
	}
	cout << dp[n][b];
}

Measured memory_bytes: 8192
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int l,r;
    cin >> l >> r;
    ll ans = 2019;
    r = min(r,l+2019);
    for(int i=l;i<r;i++){
        for(int j=i+1;j<=r;j++){
            ans = min(ans,(ll)((ll)i*j)%2019LL);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize)(list:[i64]));
    list.into_iter().map(|x| x - 1).sum::<i64>().to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "3\n3 4 6" => "10",
    test2: "5\n7 46 11 20 11" => "90",
    test3: "7\n994 518 941 851 647 2 581" => "4527",
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def powmod(a, n, m):
    L = [1 for _ in range(n+1)]
    for i in range(n):
        L[i+1] = L[i] * a % m
    return L

def solve(L: str):
    p = len(L)
    pm = powmod(3, p, MOD)
    
    s = ''
    for i, c in enumerate(L[::-1]):
        if i == 0:
            if c == '1':
                res = 3
            else:
                res = 1
            continue
        
        if c == '0':
            res = res
        else:
            res = (pm[i] + res * 2) % MOD
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = next(tokens)  # type: int
    solve(L)

if __name__ == '__main__':
    main()


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<bool> flg(n,false);
    REP(i,n){
        cin>>a[i];
        a[i]--;
    }
    int loc=0,cou=0;
    while(loc!=1){
        cou++;
        if(flg[loc]){
            cout << -1 << endl;
            return 0;
        }
        flg[loc]=1;
        loc=a[loc];
    }
    cout << cou << endl;
}


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{

  public static void main(String[] args){

    BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
    String str="";
    StringTokenizer stk;
    int hirosi_i,hirosi_y;
    int kenjir_i,kenjir_y;
    int iwana_P,yamame_P,iwana10_B,yamame20_B;
    int sc_h,sc_k;

    try{
      str=bfr.readLine();
      if(str=="") {
        System.exit(0);
      }
      stk=new StringTokenizer(str," ");
      hirosi_i=Integer.parseInt(stk.nextToken());
      hirosi_y=Integer.parseInt(stk.nextToken());

      str=bfr.readLine();
      if(str=="") {
        System.exit(0);
      }
      stk=new StringTokenizer(str," ");
      kenjir_i=Integer.parseInt(stk.nextToken());
      kenjir_y=Integer.parseInt(stk.nextToken());

      str=bfr.readLine();
      if(str=="") {
        System.exit(0);
      }
      stk=new StringTokenizer(str," ");
      iwana_P=Integer.parseInt(stk.nextToken());
      yamame_P=Integer.parseInt(stk.nextToken());
      iwana10_B=Integer.parseInt(stk.nextToken());
      yamame20_B=Integer.parseInt(stk.nextToken());

      sc_h=iwana_P*hirosi_i+(hirosi_i/10)*iwana10_B+yamame_P*hirosi_y+(hirosi_y/20)*yamame20_B;
      sc_k=iwana_P*kenjir_i+(kenjir_i/10)*iwana10_B+yamame_P*kenjir_y+(kenjir_y/20)*yamame20_B;

      if(sc_k>sc_h) {
    	  System.out.println("kenjiro");
      }

      else if(sc_k<sc_h) {
    	  System.out.println("hiroshi");
      }

      else if(sc_k==sc_h) {
    	  System.out.println("even");
      }

    } catch (IOException e) {
      System.exit(0);
    }
    catch(NumberFormatException e) {
      System.exit(0);
    }

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


Measured memory_bytes: 24128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(a=="SUN")
        cout<<7;
    else if(a=="MON")
        cout<<6;
    else if(a=="TUE")
        cout<<5;
    else if(a=="WED")
        cout<<4;
    else if(a=="THU")
        cout<<3;
    else if(a=="FRI")
        cout<<2;
    else
        cout<<1;





return 0;
}



Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    ll n,m;
    cin>>n>>m;
    vector<vector<ll>> ab(n,vector<ll>(2));
    for(ll i=0;i<n;i++){
        cin>>ab[i][0]>>ab[i][1];
    }
    sort(ab.begin(),ab.end());
    ll ans=0;
    for(ll i=0;i<n;i++){
        ans+=ab[i][0]*min(ab[i][1],m);
        m-=ab[i][1];
        if(m<=0) break;
    }
    cout<<ans<<endl;
    return 0;
}

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

/*                        [Template]                        */
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) x.find( y ) != x.end()
#define _matrix(T) vector<vector<T>>
template<class T>
auto matrix( int r, int c, T v ){
	return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
int mod = (int)1e9 + 7 ;

/************************************************************/

signed main(){
	float D, T, S ;
	cin >> D >> T >> S ;
	if( D / S <= T ) cout << "Yes\n" ;
	else cout << "No\n" ;
	return 0 ;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N;
std::set<int> set;
int main() {
    std::cin >> N;
    REP(i, N) {
        int A;
        std::cin >> A;
        auto it = set.find(A);
        if( it != set.end() ) {
            set.erase(it);
        } else {
            set.insert(A);
        }
    }
    std::cout << set.size() << std::endl;
}

Measured memory_bytes: 4864
n = int(input())
d,x = map(int, input().split())
a = [int(input()) for i in range(n)]

key = 0
ans = 0
for i in range(n):
    if d % a[i] == 0:
        key = d // a[i]
    else:
        key = (d//a[i])+1
    ans += key
    key = 0
print(ans+x)


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

public class Main {

	public static void main(String[] args) throws Exception{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] s = br.readLine().split("\\s+");
		int m = Integer.parseInt(s[0]);
		int n = Integer.parseInt(s[1]);
		long res = n;
		for(int i=1;i<m;i++)
		{
			res *= n-1;
			if(res > Math.pow(2, 31)-1)
			{
				System.out.println((long)Math.pow(2, 31)-1);
				return;
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 33832
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

bool vis[M+4];
int cnt[M+4];
vector<int>ses;
int n;
int b[M+4];
bool chk(int x)
{
    int pos=0;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            pos++;
            if(pos==x)
            {
                if(b[i]==x)
                {
                    vis[i]=1;
                    ses.pb(x);
                    cnt[x]--;
                    return true;
                }
            }
        }
    }
    return false;
}
 main()

{
    fast
    cin>>n;
    f(i,1,n)
    {
        cin>>b[i];
        cnt[b[i]]++;
    }
    rf(i,n,1)
    {
        int flag=0;
        rf(j,i,1)
        {
            if(cnt[j]>=1){

            if(chk(j))
            {
                flag=1;
                break;
            }

            }
        }
        if(flag==0)
        {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    reverse(ses.begin(),ses.end());
    f(i,1,n)
    {
        if(vis[i]==0)
        {
            cout<<"-1"<<endl;
            //done("hey")
            return 0;
        }
    }
    for(auto x:ses)
    {
        cout<<x<<" ";
    }
    cout<<endl;
    return 0;

}





































Measured memory_bytes: 3656
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int X, A;
    cin >> X >> A;
    if (X < A) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt[105];
int main() {
	int a,b,c,ans=0;
	cin>>a>>b>>c;
	cnt[a]++;
	ans=1;
	cnt[b]++;
	if(cnt[b]==1)ans++;
	cnt[c]++;
	if(cnt[c]==1)ans++;
	cout<<ans;
	return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	vector< tuple<string, int, int> > t(n);
	for(int i=0; i < n; i++) {
		cin >> get<0>(t.at(i)) >> get<1>(t.at(i));
		get<1>(t.at(i)) *= -1;;
		get<2>(t.at(i)) = i+1;
	}
	sort(t.begin(), t.end());
	for(auto &tx : t) {
		printf("%d\n", get<2>(tx));
	}
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;  cin >> a >> b;
    if (a + b < 10) {
      cout << a + b << '\n';
    } else {
      cout << "error" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
const main = (input: string) => {
  const [A, B] = input.trim().split(" ").map(str => parseInt(str))
  const getGcd = (a: number, b: number): number => {
    if(b === 0) {
      return a
    }
    return getGcd(b, a % b)
  }

  const answer = A * B / getGcd(A, B)

  console.log(answer)
}

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


Measured memory_bytes: 7372
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 11 20:44:38 2020

@author: adarsh
"""


s=input()
t=input()
n=len(s)
m=len(t)
dp = [[0 for i in range(m+1)] for j in range(n+1)]

for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=dp[i-1][j-1]+1 
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])
ans="" 
i=n
j=m
while (i>0 and j>0):
    if dp[i][j]==dp[i][j-1]:
        j=j-1
    elif dp[i][j] ==dp[i-1][j]:
        i=i-1 
    else:
        ans=s[i-1]+ans 
        i-=1
        j-=1
print(ans)
            

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

int main(){
  int n;
  cin >> n;
  int a;
  for(int i=0; i<n; i++){
    cin >> a;
    if(a%2==1)continue;
    if(a%3!=0 && a%5!=0){
      cout << "DENIED" << endl;
      return 0;
    } 
  }
  cout << "APPROVED" << endl;
  return 0;
}

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

using namespace std;

int q[200001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int num;
    cin >> num;
    q[num] = i;
  }

  int maxcnt = 1;
  int cnt = 1;
  for (int i = 2; i <= n; i++) {
    if (q[i] > q[i - 1]) {
      cnt++;
    } else {
      if (cnt > maxcnt) {
        maxcnt = cnt;
      }
      cnt = 1;
    }
  }
  if (cnt > maxcnt) {
    maxcnt = cnt;
  }

  cout << n - maxcnt << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        for(int i = 0; i <= 10000; i++){
            int x = scan.nextInt();
            int y = scan.nextInt();
            if(x == 0 && y == 0){
                break;
            }
            if(x > y){
                int temp;
                temp = x;
                x = y;
                y = temp;
            }
            System.out.println(x + " " + y);
        }
    }
}

Measured memory_bytes: 34924
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n;

int main()
{
  scanf("%d",&n);
  int m = n;
  int sum = 0;
  while (m > 0)
  {
    sum += m % 10;
    m /= 10;
  }
  puts(n % sum == 0 ? "Yes" : "No");
  return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
typedef pair<pl, int> pli;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

bool dead[300];
int n, s, t;
pli dist[300];
ll all;

ll ask (int a, int b) {
    a++; b++;
    if (a == b) return 0;
    cout << "? " << a << " " << b << endl;
    cout.flush();
    ll d; cin >> d;
    return d;
}

int main() {
    cin >> n >> s >> t;
    s--; t--;
    all = ask(s, t);
    dist[s] = pli(pl(0, all), s);
    dist[t] = pli(pl(all, 0), t);
    rep(i,n) {
        if (i == s || i == t) continue;
        dist[i] = pli(pl(ask(s,i), ask(i,t)), i);
    }
    sort(dist, dist+n);
    vector<int> ans;
    int pos = 0;
    rep(i,n) {
        if (dist[i].first.first + dist[i].first.second != all) continue;
        ll mid = ask(dist[pos].second, dist[i].second);
        if (dist[pos].first.first + mid + dist[i].first.second == all) {
            pos = i;
            ans.push_back(dist[i].second);
        }
    }
    cout << "!";
    rep(i,ans.size()) cout << " " << ans[i]+1;
    cout << endl;
}



Measured memory_bytes: 4668
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <bitset>
#include<list>
#include <iomanip>
using namespace std;
#define Clear(a) memset(a,-1,sizeof(a))
#define FILL(a) fill(a,a+1000000,true);
#define fastIO ios::sync_with_stdio(false)
#define mp make_pair
#define All(a) a.begin(),a.end()
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
#define PI 3.1415926535897932385
#define INF 1000000000
#define eps 1e-7
#define MOD 100000000
#define maxN 500010
const int OO = (int)1e6;
using namespace std;
int n, m;
vi v;
int dp[100009];
int solve(int idx) {
	if (idx == n-1)return 0;
	if (dp[idx] != -1)return dp[idx];
	int ans1 = OO;
	if (idx + 1 < n)
		ans1 = abs(v[idx] - v[idx + 1])+solve(idx+1);
	int ans2 = OO;
	if (idx + 2 < n)
		ans2 = abs(v[idx] - v[idx + 2])+solve(idx+2);
	return dp[idx] = min(ans1, ans2);
}

int main()
{

	fastIO;
	cin >> n;
	Clear(dp);
	for (int c = 0; c < n; c++) {
		int x;
		cin >> x;
		v.push_back(x);
	}
	cout << solve(0) << endl;
	return 0;
}

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

int main() {
    int n,k;
    cin >> n >> k;
    char s[n];
    char t[0];
    cin >> s;
    t[0] = tolower(s[k-1]);
    s[k-1] = t[0];
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,long long> pi;
long long dist[100005];
vector<pi>tree[100005];
bool visited[100005];
void dfs(int curr,long long d){
	dist[curr] = d;
	visited[curr] = true;
	for(int i=0; i<tree[curr].size(); i++){
		int child = tree[curr][i].first;
		long long len = tree[curr][i].second;
		if(!visited[child]) dfs(child,d+len);
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	for(int i=1; i<n; i++){
		int a,b;
		long long d;
		cin>>a>>b>>d;
		tree[a].push_back(pi(b,d));
		tree[b].push_back(pi(a,d));
	}
	int q,k;
	cin>>q>>k;
	dfs(k,0);
	while(q--){
		int a,b;
		cin>>a>>b;
		cout<<dist[a]+dist[b]<<'\n';
	}
}

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

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

    int n;
    cin >> n;

    int edges[3];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) cin >> edges[j];
        sort(edges, edges + 3);
        cout << (edges[0] * edges[0] + edges[1] * edges[1] ==
                         edges[2] * edges[2]
                     ? "YES"
                     : "NO")
             << endl;
    }

    return EXIT_SUCCESS;
}

Measured memory_bytes: 3092
n, m = gets.chomp.split(' ').map(&:to_i)
@tree = Array.new(n)
n.times { |i| @tree[i] = [] }
m.times do
  a, b = gets.chomp.split(' ').map { |i| i.to_i - 1 }
  @tree[a] << b
  @tree[b] << a
end
def rec(current, visited)
  return 1 if visited.length == @tree.length
  total = 0
  @tree[current].each do |i|
    next if visited.include?(i)
    cloned = visited.dup
    cloned << i
    total += rec(i, cloned)
  end
  total
end
puts rec(0, [0])

Measured memory_bytes: 2300
def main():
    N = int(input())
    A = list(map(int, input().split()))
    approve = True
    for a in A:
        if a % 2 == 0:
            if a % 3 == 0 or a % 5 == 0:
                pass # ok
            else:
                approve = False
                break
    if approve:
        print('APPROVED')
    else:
        print('DENIED')

    

main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef array<ll,2> pll;
const ll NMAX=3005,MOD=1e9+7;
ld dp[NMAX][NMAX];

int main()
{
    ll n;
    ld p,ans=0;
    cin>>n;
    dp[0][0]=1;
    for(ll i=1;i<=n;i++){
        cin>>p;
        for(ll cnt=0;cnt<=i;cnt++){
            dp[i][cnt]=dp[i-1][cnt-1]*p+dp[i-1][cnt]*(1-p);
        }
    }
    for(ll i=n/2+1;i<=n;i++)
        ans+=dp[n][i];
    cout<<fixed<<setprecision(9)<<ans;
    return 0;
}


Measured memory_bytes: 85524
#include <iostream>
#include <algorithm>
//#include <string>
//#include <map>
//
//#include <string.h>

using namespace std;

//typedef long long llong;


int main() {
    unsigned int N, A, B;
    cin >> N;
    cin >> A;
    cin >> B;
    string str;
    cin >> str;
    unsigned int numOfPassed = 0,rankOfOverseas = 1;
    for(int i = 0; i < str.length(); i++) {
        if(str[i] == 'a') { //japanese
            if(numOfPassed < A+B) {
                numOfPassed++;
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else if(str[i] == 'b') { //overseas
            if((numOfPassed < (A+B)) && (rankOfOverseas <= B)) {
                numOfPassed++;
                rankOfOverseas++;
                cout << "Yes" << endl;
            } else {
                cout <<"No" << endl;
            }
        } else { //otherwise
            cout <<"No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
map<string ,int> memo;
int main()
{
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];

		int min1=1e9;
		for(int i=1;i<=100;i++)//coordinate
	{
		int sum=0;
		for(int j=0;j<n;j++)
		{
		     sum+=(a[j]-i)*(a[j]-i);
		}
		min1=min(min1,sum);
	}
	cout<<min1;
    return 0;
}


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

#define MOD_BY UINT32_C(1000000007)

uint32_t add(uint32_t a, uint32_t b) {
	return a + b - MOD_BY * (a + b >= MOD_BY);
}

uint32_t sub(uint32_t a, uint32_t b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

uint32_t mul(uint32_t a, uint32_t b) {
	return (uint32_t)(((uint64_t)a * b) % MOD_BY);
}

uint32_t pou(uint32_t a, uint32_t b) {
	uint32_t r = 1;
	while (b > 0) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

uint32_t inv(uint32_t a) {
	return pou(a, MOD_BY - 2);
}

uint32_t dexibu(uint32_t a, uint32_t b) {
	return mul(a, inv(b));
}

uint32_t nCr(uint32_t n, uint32_t r) {
	uint32_t ret = 1;
	uint32_t i;
	if (r > n) return 0;
	if (n - r < r) r = n - r;
	for (i = 0; i < r; i++) ret = mul(ret, n - i);
	for (i = 1; i <= r; i++) ret = dexibu(ret, i);
	return ret;
}

int main(void) {
	uint32_t n, a, b;
	if (scanf("%" SCNu32 "%" SCNu32 "%" SCNu32, &n, &a, &b) != 3) return 1;
	printf("%" PRIu32 "\n", sub(sub(sub(pou(2, n), nCr(n, a)), nCr(n, b)), 1));
	return 0;
}


Measured memory_bytes: 128