akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

////////////////////////////////////////

ll comb(int t){
    return (ll)t*(t-1)/2;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,m;cin>>n>>m;
    int a[n][n];memset(a,0,sizeof(a));
    rep(i,0,m-1){
        int x,y;cin>>x>>y;x--;y--;
        a[x][y]=1;a[y][x]=1;
    }
    vector<i_i>v;
    int pos=0;
    int c[n];rep(i,0,n-1)c[i]=-1;
    while(pos<=n-1){
        i_i z=i_i(0,0);
        queue<int>q;
        q.push(pos);c[pos]=0;z.first++;
        while(q.size()){
            int t=q.front();q.pop();
            rep(i,0,n-1){
                if(i==t)continue;
                if(a[i][t]==0){
                    if(c[i]==c[t]){
                        cout<<-1<<endl;
                        return 0;
                    }
                    if(c[i]==-1){
                        c[i]=1-c[t];
                        if(c[i]==0)z.first++;
                        else z.second++;
                        q.push(i);
                    }
                    
                }
            }
        }
        if(z.second!=0)v.pb(z);
        while(pos<=n-1&&c[pos]!=-1)pos++;
        
    }
    /*for(auto x:v){
        cout<<x.first<<" "<<x.second<<endl;
    }*/
    int res=0;
    for(auto x:v)res+=x.first+x.second;
    res=n-res;
    
    bool dp[v.size()+1][n+1];memset(dp,false,sizeof(dp));
    dp[0][0]=true;
    if(v.size()>=1)rep(i,0,v.size()-1){
        rep(j,0,n){
            if(j-v[i].first>=0)dp[i+1][j]|=dp[i][j-v[i].first];
            if(j-v[i].second>=0)dp[i+1][j]|=dp[i][j-v[i].second];
        }
    }
    vector<int>z;
    rep(j,0,n)if(dp[v.size()][j])z.pb(j);
    int k=lower_bound(z.begin(),z.end(),(n-res)/2)-z.begin();
    if(k==z.size())k--;
    int p=z[k];
    int q=n-p;
    if(q>=n/2){
        q=n/2;
        p=n-q;
    }
    ll ans=comb(p)+comb(q);
   // cout<<ans<<endl;cout<<k<<endl;
   // for(auto x:z)cout<<x<<" ";cout<<endl;
    if(k>0){
        int p=z[k-1]+res;
        int q=n-p;
        if(p>=n/2){
            q=n/2;
            p=n-q;
        }
        ans=min(ans,comb(p)+comb(q));
    }
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 2176
import java.util.Scanner;

class Main{

    static Scanner scan;
    
    public static void main(String[] args) {
	scan = new Scanner(System.in);

	int n;
	for (int i = 1; ; i++) {
	    n = scan.nextInt();
	    if (n == 0) break;
	    System.out.printf("Case %d: %d\n", i, n);
	}
    }
}



Measured memory_bytes: 66412
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			String s = sc.next();
			if(s.compareTo("0")==0) break;
			
			int n = s.length();
			char[] a = s.toCharArray();
			ArrayDeque<char[]> que = new ArrayDeque<char[]>();
			ArrayList<String> list = new ArrayList<String>();
			boolean flag = false;
			boolean check = false;
			String t;
			
			for(int k=1;k<n;k++){
				if(a[k]!=a[0]){
					flag = true;
					break;
				}
			}
			if(flag==false){
				System.out.println(0);
			}else{
				que.offer(a);
				list.add(s);
				for(int z=1;;z++){
					int y = que.size();
					check = false;
					for(int i=0;i<y;i++){
						char[] b = que.peek();
						
						for(int j=0;j<n-1;j++){
							char[] c = b.clone();
							if(b[j]=='r' && b[j+1]=='g'){
								c[j] = 'b';
								c[j+1] = 'b';
							}else if(b[j]=='g' && b[j+1]=='r'){
								c[j] = 'b';
								c[j+1] = 'b';
							}else if(b[j]=='g' && b[j+1]=='b'){
								c[j] = 'r';
								c[j+1] = 'r';
							}else if(b[j]=='b' && b[j+1]=='g'){
								c[j] = 'r';
								c[j+1] = 'r';
							}else if(b[j]=='b' && b[j+1]=='r'){
								c[j] = 'g';
								c[j+1] = 'g';
							}else if(b[j]=='r' && b[j+1]=='b'){
								c[j] = 'g';
								c[j+1] = 'g';
							}
							StringBuffer sb = new StringBuffer();
							for(int k=0;k<n;k++) sb.append(c[k]);
							t = sb.toString();
							
							flag = false;
							
							for(int k=1;k<n;k++){
								if(c[k]!=c[0]){
									flag = true;
									break;
								}
							}
							
							if(flag==false){
								System.out.println(z);
								check = true;
								j = n;
								i = y;
							}else if(list.contains(t)==false){
								check = true;
								list.add(t);
								que.offer(c);
							}
	
						}
						if(check==false){
							System.out.println("NA");
							i = y;
						}
						que.poll();
					}
					if(flag==false || check==false) break;
				}
			}
		}	
	}	
}

Measured memory_bytes: 60368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;

int main() {
  int h, w;
  cin >> h >> w;
  int count = 0;

  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
      if (s[i][j] == '.') count++;
    }
  }

  vector<vector<int>> dist(h, vector<int>(w, -1));

  queue<pair<int, int>> que;

  vector<pii> record;

  que.push({0, 0});
  dist[0][0] = 0;

  while (!que.empty()) {
    pii temp = que.front();
    que.pop();

    for (int i = 0; i < 4; i++) {
      pii t = {temp.first + dx[i], temp.second + dy[i]};

      if (t.first >= 0 && t.first < h && t.second >= 0 && t.second < w &&
          dist[t.first][t.second] == -1 && s[t.first][t.second] != '#') {
        dist[t.first][t.second] = dist[temp.first][temp.second] + 1;
        que.push(t);
        record.push_back(t);
      }
    }
  }

  int ans = count - dist[h - 1][w - 1] - 1;

  cout << (dist[h - 1][w - 1] == -1 ? -1 : ans) << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 998244353;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;

class Factorial {
    vector<mint> facts, factinv;
public:
    explicit Factorial(int n) : facts(n+1), factinv(n+1) {
        facts[0] = 1;
        for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1] * mint(i);
        factinv[n] = facts[n].inv();
        for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * mint(i+1);
    }
    mint fact(int k) const {
        if(k >= 0) return facts[k]; else return factinv[-k];
    }
    mint operator[](const int &k) const {
        if(k >= 0) return facts[k]; else return factinv[-k];
    }
    mint C(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return facts[p] * factinv[q] * factinv[p-q];
    }
    mint P(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return facts[p] * factinv[p-q];
    }
    mint H(int p, int q) const {
        if(p < 0 || q < 0) return 0;
        return q == 0 ? 1 : C(p+q-1, q);
    }
};
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    Factorial f(n+m);
    mint ans = 0;
    for (int i = n-1-k; i < n; ++i) {
        ans += f.C(n-1, i)*mint(m)*(mint(m-1).pow(i));
    }
    cout << ans.val << "\n";
    return 0;
}

Measured memory_bytes: 6376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N; cin >> N; vector<ll> A(N); for(ll i = 0; i < N; i++){ cin >> A[i]; A[i]--;}
  
  vector<ll> idx(N); for(ll i = 0; i < N; i++){ idx[A[i]] = i;}
  ll ans = 0;
  set<ll> s;
  
  for(ll x = N-1; x >= 0; x--){
    //x (1-indexedでx+1)が、secondになりうるかを調べる
    ll itr = idx[x];
    s.insert(itr);
    
    auto it = s.find(itr);
    vector<ll> l(2,-1); vector<ll> r(2,N);
    
    for(ll j = 0; j < 2; j++){
      if( it == s.begin()){ break;}
      it--;
      l[1-j] = *it;}
    
    auto it2 = s.find(itr);
    
    for(ll j = 0; j < 2; j++){
      it2++;
      if( it2 == s.end()){ break;}
      r[j] = *it2;}
    
    ans += (x+1)*( (itr-l[1])*(r[1]-r[0]) + (r[0]-itr)*(l[1]-l[0]));
    
  }
  
  cout << ans << endl; return 0;}
    
    

Measured memory_bytes: 6528
//ID:computerbox --> Hajiyev Huseyn
#include <bits/stdc++.h>
#define FAST_READ ios_base::sync_with_stdio(0);/*cin.tie(0); cout.tie(0);*/
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 200010

using namespace std;

ll ans[MAXN];
ll c,s,f,n;
int main(){
FAST_READ;
cin>>n;
for(ll i=0;i<n-1;i++)
{
cin>>c>>s>>f;
 for(ll j=0;j<i+1;j++)
 {
   if(ans[j]<s)
   {
    ans[j]=s+c;
   }
   else
   {
    ans[j]+=c+f-(((ans[j]%f)==0)?f:ans[j]%f);
   }
  }
}
for(ll i=0;i<n;i++)
{
  cout<<ans[i]<<endl;
}






return 0;
} 

Measured memory_bytes: 256
from copy import deepcopy

xy = [[0 for i in range(20)] for i in range(20)]
no = deepcopy(xy)

def rec(n, m):
    if no[n][m]:
        return 0
    if n == 0 or m == 0:
        return 0
    if n == 1 and m == 1:
        return 1

    xy[n][m] = rec(n - 1, m) + rec(n, m - 1)
    return xy[n][m]

def main():
    global xy, no
    while True:
        a, b = map(int, input().split())
        if a == b == 0:
            break

        n = int(input())
        for i in range(n):
            x, y = map(int, input().split())
            no[x][y] = 1

        print(rec(a, b))
        
        xy = deepcopy([[0 for i in range(20)] for i in range(20)])
        no = deepcopy(xy)

if __name__ == '__main__':
    main()

Measured memory_bytes: 8104
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int
int main(){
  char a[5];
  cin >> a;
  if(a[0]==a[2])cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
 int n,a[3][3],b[10];
 bool appear[3][3];
 rep(i,3){
   rep(j,3){
     cin >> a[i][j];
   }
 }
 cin >> n;
 rep(i,n){
   cin >> b[i];
 }
 rep(i,n){
   rep(j,n){
     appear[i][j]=false;
     rep(k,n){
       if(a[i][j]==b[k]) appear[i][j]=true;
     }
   }
 }
 string ans = "No";
 rep(i,3){
   if(appear[i][0] and appear[i][1] and appear[i][2]) ans = "Yes";
 }
 rep(i,3){
   if(appear[0][i] and appear[1][i] and appear[2][i]) ans = "Yes";
 }
 if(appear[0][0]and appear[1][1] and appear[2][2]) ans = "Yes";
 if(appear[0][2]and appear[1][1] and appear[2][0]) ans = "Yes";
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int x=0,x_max=0;
  for(int i=0;i<N;i++){
      if(S[i]=='I')
          x+=1;
      else
          x-=1;
      if(x>x_max)
          x_max=x;
  }
  cout<<x_max<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

vector<int> common_divisor(int A, int B){
	vector<int> res; res.clear();
	int x = min(A, B);
	for (int i = x; i >= 1; --i){
		if (A % i == 0 && B % i == 0){
			res.push_back(i);
		} // end if
	} // end for

	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int A, B, K; cin >> A >> B >> K;
	--K;

	vector<int> ans = common_divisor(A,B);
	cout << ans[K] << endl;
	
	return 0;
}

Measured memory_bytes: 256
x=int(input())

era=[1]*(10**6+1)
era[0]=0
era[1]=0
k=2
while k<10**6+1:
  if era[k]==1:
    for i in range(2*k,10**6+1,k):
      era[i]=0
  if k==2:
    k+=1
  else:
    k+=2
for i in range(x,10**6+1):
  if era[i]==1:
    print(i)
    break

Measured memory_bytes: 16796
n = gets.to_i
a = readlines.map{|e| e.split.map &:to_f}
count = 0.0
sum = 0
[*0..n-1].permutation.each{ |e|
    e.each_cons(2) { |i, j|
        x = a[i][0] - a[j][0]
        y = a[i][1] - a[j][1]
        sum += Math.sqrt(x ** 2 + y ** 2)
    }
    count += 1
}
puts sum / count

Measured memory_bytes: 1916
#include<iostream>
#include<string>
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)

using namespace std;

string S;
int pos;

bool dream();
bool erase();

bool dream () {
  if (pos >= (int)S.size()) return true;
  if (S.substr(pos, 5) != "dream") return false;
  pos += 5;
  if (pos >= (int)S.size()) return true;
  if (S.substr(pos, 3) == "era") {
    return erase();
  }
  else if(S.substr(pos, 2) == "er") {
    pos += 2;
    if (pos >= (int)S.size()) return true;
    if (S[pos] == 'd') {
      return dream();
    } else if (S[pos] == 'e') {
      return erase();
    } else return false;
  }  
  else if(S[pos] == 'd') {
    return dream();
  }  
  else return false;
}

bool erase() {
  if (pos >= (int)S.size()) return true;
  if (S.substr(pos, 5) != "erase") return false;
  pos += 5;
  if (pos >= (int)S.size()) return true;
  if (S[pos] == 'r') {
    pos += 1;
    if (pos >= (int)S.size()) return true;
  }
  if (S[pos] == 'd') {
    return dream();
  } else if (S[pos] == 'e') {
    return erase();
  } else return false;
}

int main(){
  cin >> S;
  if (dream()) cout << "YES" << endl;
  else if (!(pos = 0) && erase()) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    while(getline(cin,str))
    {
        for(int i=0;i<str.length();++i){
            if(str[i]>='a'&&str[i]<='z')str[i]+=('A'-'a');
        }
            cout<<str<<endl;
    }
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
void solve()
{
	ll int n;
	cin>>n;
	string s;
	while(n>0){
		int d=n%26;
		if(d==0){
			s+="z";
			n/=26;
			n-=1;
		}
		else{
		s+=(char(96+d));
		n/=26;}
	}
	reverse(s.begin(),s.end());
	cout<<s;
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


Measured memory_bytes: 3660
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s.back() != 's') cout << s + 's' << endl;
    else cout << s + "es" << endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

vector<bool> visited;
void dfs(vector<vector<bool>> G, int v){
    visited[v] = true;
    rep(v2, visited.size()){
        if(G[v][v2] == false) continue;
        if(visited[v2] == true) continue;
        dfs(G, v2);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    visited.resize(n);
    vector<vector<bool>> G(n, vector<bool>(n));
    vector<pair<int, int>> p(m);
    
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        p[i] = make_pair(a, b);
        G[a][b] = true;
        G[b][a] = true;
    }
    int ans = 0;
    rep(i, m){
        int a = p[i].first; int b = p[i].second;
        G[a][b] = false; G[b][a] = false;
        rep(j, n) visited[j] = false;
        
        dfs(G, 0);
        
        bool f = false;
        rep(j, n) if(visited[j] == false) f = true;
        if(f) ans++;
        G[a][b] = true; G[b][a] = true;
    }
    
    cout << ans << endl;
    return 0;
}




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


int h, w;
char s[100][100];

int visited[100][100];
int res[100][100];

void white_explore(int r, int c, int rv, set<pair<int,int>> &q) {
	if (visited[r][c]) return;
	visited[r][c] = 1;
	res[r][c] = rv;
	if (r < h - 1) {
		if (s[r+1][c] == '.')
			white_explore(r+1, c, rv, q);
		else {
			q.insert(pair<int,int>(r+1,c));
		}
	}
	if (c < w -1){
		if(s[r][c+1]=='.')
			white_explore(r,c+1,rv,q);
		else {
			q.insert(pair<int,int>(r,c+1));
		}
	}
}

void black_explore(int r, int c, int rv, set<pair<int,int>> &q){
	if (visited[r][c]) return;
	visited[r][c] = 1;
	res[r][c] = rv;
	if (r < h-1){
		if (s[r+1][c]=='.') {
			q.insert(pair<int,int>(r+1,c));
		} else {
			black_explore(r+1,c,rv,q);
		}
	}
	if (c < w-1){
		if (s[r][c+1]=='.'){
			q.insert(pair<int,int>(r,c+1));
		}else{
			black_explore(r,c+1,rv,q);
		}
	}
}


int main() {
	cin >> h >> w;
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			cin >> s[i][j];
	set<pair<int,int>> q;
	int rv = 0;
	if (s[0][0] == '.') {
		white_explore(0, 0, rv, q);
		rv = 1;
	} else {
		q.insert(make_pair<int,int>(0,0));
		rv  = 1;
	}
	set<pair<int,int>> q2;
	while(!q.empty()) {
		set<pair<int,int>> next_q;
		for(auto p: q) {
			black_explore(p.first, p.second, rv, next_q);
		}
		if (next_q.empty()) break;
		q2.clear();
		for(auto p: next_q) {
			white_explore(p.first, p.second, rv, q2);
		}
		rv += 1;
		swap(q, q2);
	}
	cout << res[h-1][w-1] << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MAX 1000000000
using namespace std;

int main(){
  int n; cin >> n;
  vector<bool> cnt(MAX, false);
  for(int i=0; i<n; ++i){
    int x; cin >> x;
    if(cnt[x-1] == true){
      cout << "NO" << endl;
      return 0;
    }
    cnt[x-1] = true;
  }
  cout << "YES" << endl;
  return 0;
}


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

int main() {
  int64_t A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int64_t ans = 100000000000;
  for (int64_t i = 0; i <= max(X, Y); i++) {
    int64_t a, b, ab, zero;
    zero = 0;
    a = max(X-i, zero);
    b = max(Y-i, zero);
    ab = 2*i;
    ans = min(ans, A*a + B*b + C*ab);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
a=list(map(int,input().split()))
a.sort(reverse=True)
cnt=0
if (a[0]-a[1])%2==0:
    cnt+=(a[0]-a[1])//2
    if (a[0]-a[2])%2==0:
        cnt+=(a[0]-a[2])//2
    else:
        cnt+=(a[0]-a[2])//2+2
else:
    cnt+=(a[0]-a[1])//2+1
    a[2]+=1
    if (a[0]-a[2])%2==0:
        cnt+=(a[0]-a[2])//2
    else:
        cnt+=(a[0]-a[2])//2+2
print(cnt)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>

using namespace std;
#define NUM 753

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {

	char in[256];
	int min = 999999;
	int num;
	
	scanf("%s", &in);
	string s(in);
	
	for(int i=0; i<s.size()-2; i++){
		num = ctoi(s[i]) *100 + ctoi(s[i+1]) * 10 + ctoi(s[i+2]);
		if(abs(NUM - num) < min) min = abs(NUM - num);
	}
	
	printf("%d\n", min);
	
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll x;
    cin>>x;
    if (x==0)
    {
        cout<<"1\n";
        return 0;
    }
    cout<<"0\n";
}


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

nums = [0]
for a in A:
    nums.append(nums[-1]+a)

sumA = nums[-1]
ans = 10**20
for a in nums[1:-1]:
    p = abs(2*a-sumA)
    ans = min(ans, p)
print(ans)

Measured memory_bytes: 24812
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main()
{
	vector<int> v(3);
	for (int i = 0; i < 3; i++) {
		cin >> v[i];
	}

	sort(v.begin(), v.end());
	cout << v[1] + v[0] << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Here your code !
A = int(input())
N = tuple(input().split())
bs=[]
ss=[]
def isStable(a,b):
    leng = int(len(a))
    for i in range(leng):
        for j in range(i+1,leng):
            for x in range(leng):
                for y in range(x+1,leng):
                    if a[i][1]==a[j][1] and a[i]==b[y] and a[j]==b[x]:
                        return "Not stable"
    return "Stable"
    
def bSort(n,a):
    n = list(n)
    for i in range(a):
        for j in range(a-1,i,-1):
            if int(n[j][1]) < int(n[j-1][1]):
                n[j],n[j-1]=n[j-1],n[j]
    return n
    #print(" ".join(n))

    
def seleSort(n,a):
    n = list(n)
    for i in range(a):
        minj = i
        for j in range(i+1,a):
            if n[j][1]<n[minj][1]:
                minj = j
                
        n[i],n[minj]=n[minj],n[i]
    return n
    #print(" ".join(n))

bs = bSort(N,A)
ss = seleSort(N,A)
print(" ".join(bs))
print(isStable(bs,bs))
print(" ".join(ss))
print(isStable(bs,ss))

Measured memory_bytes: 7824
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)

int main() {
	int n, q, l, r, ac[100001] = { 0 };
	char s[100001];
	scanf("%d %d %s\n",&n,&q,s);
	rep(i, n - 1) {
		if (s[i] == 'A' && s[i + 1] == 'C')ac[i + 1] = ac[i] + 1;
		else ac[i + 1] = ac[i];
	}
	rep(i, q) {
		scanf("%d %d", &l, &r);
		printf("%d\n", ac[r - 1] - ac[l - 1]);
	}
}

Measured memory_bytes: 1280
#include <iostream>
constexpr int n_max = 50'000;  //'

int main(void) {
    int n;
    std::cin >> n;

    for (int x = 1; x < n_max; ++x) {
        int t = x * 1.0800;
        if (t == n) {
            std::cout << x << std::endl;
            return 0;
        }
        if (t > n) break;
    }

    std::cout << ":(\n";
    return 0;
}


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



int main() {
  int N, L;
  cin >> N >> L;
  vector<int> taste(N);
  for (int i = 0; i < N; i++) taste[i] = L + i;

  int A = L + N - 1;
  int eat;
  int ans = 0;

  if (L >= 0) eat = L;
  else if (A <= 0) eat = A;
  else eat = 0;

  for (int i = 0; i < N; i++) {
    if (taste[i] != eat) ans += taste[i];
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   int a,b,c,t=0;
   scanf("%d%d%d",&a,&b,&c);
   for(int i=b;i<=c;i++)
   {
	   if(i%a==0)
	   {
		   t=1;
		   i=c+20;
	   }
   }
   if(t==1)printf("OK");
   else if(t==0)printf("NG");
   return 0;
}

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

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

    if (s == "SUN")
    {
        cout << 7 << endl;
    }
    else if (s == "MON")
    {
        cout << 6 << endl;
    }
    else if (s == "TUE")
    {
        cout << 5 << endl;
    }
    else if (s == "WED")
    {
        cout << 4 << endl;
    }
    else if (s == "THU")
    {
        cout << 3 << endl;
    }
    else if (s == "FRI")
    {
        cout << 2 << endl;
    }
    else if (s == "SAT")
    {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int stones[] = new int[n+1];
        int dp[] = new int[n+1];
        for(int i = 1 ; i <= n ; i++ ){
            stones[i] = scanner.nextInt();
        }
        System.out.println(solve(stones,dp,n,k));

    }
    public static int solve(int[] stones , int[] dp , int n , int k ){
        if(n <=1){
            return 0;
        }
        for(int i = 2 ; i<= n ; i++) {
            dp[i] = Integer.MAX_VALUE;
            for(int j = i-1 ;j >= 1 && (i-j) <= k ; j--){
                    dp[i] = Math.min(dp[i] , Math.abs(stones[i] - stones[j]) + dp[j]);
            }
        }
        return dp[n];
    }

}



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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

using Graph = vector<vector<int>>;

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    template<typename First,typename Second> void inputTwoVec(vector<First> &first,vector<Second>& second){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i] >> second[i];
        }
    }

    void inputGraph(Graph &g,int path_num,bool isdirected){
        for(int i = 0;i < path_num;i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            if(isdirected){
                g[a].push_back(b);
            }
            else{
                g[a].push_back(b);
                g[b].push_back(a);
            }
        }
    }
}

void calculate(){
    int N,K;
    Input::input(N,K);
    for(long long mili = 0; mili <= N;mili++){
        for(long long fi = 0;fi + mili <= N;fi++){
            long long tho = N - mili - fi;
            long long sum = 10'000 * mili + 5'000 * fi + 1'000 * tho;
            if(sum == K){
                cout << mili << " " << fi << " " << tho << '\n';
                return;
            }
        }
    }
    cout << "-1 -1 -1\n";
}

int main(int,char**){
    calculate();    
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク

    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n,k;
  cin >> n >> k;
  ll ans=k;
  rep(i,n-1) ans*=(k-1);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int a, b;

int main(){
	cin >> a >> b;
	int c;
	if(b == 100){
		c = a * 1000 + b;
	}
	else if(b > 9){
		c = a * 100 + b;
	}
	else{
		c = a * 10 + b;
	}
	
	int i;
	for(i = 1; i * i < c; i++){}
	if(i * i == c){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	
	return 0;
}

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

class Hand
{
  public:
    Hand(vector<int> cards);

  public:
    string what_hand();

  private:
    bool is_one_pair();
    bool is_two_pair();
    bool is_three_card();
    bool is_straight();
    bool is_full_house();
    bool is_four_card();

  private:
    vector<int> m_hand;
};

Hand::Hand(vector<int> cards) :
  m_hand(5)
{
  for (int i = 0; i < 5; ++i)
  {
    m_hand[i] = cards[i];
  }
  sort(m_hand.begin(), m_hand.end());
}

string Hand::what_hand()
{
  if (is_four_card())
  {
    return "four card";
  }
  else if (is_full_house())
  {
    return "full house";
  }
  else if (is_straight())
  {
    return "straight";
  }
  else if (is_three_card())
  {
    return "three card";
  }
  else if (is_two_pair())
  {
    return "two pair";
  }
  else if (is_one_pair())
  {
    return "one pair";
  }
  else
  {
    return "null";
  }
}

bool Hand::is_one_pair()
{
  int prev = -1;
  for (int card : m_hand)
  {
    if (prev == -1)
    {
      prev = card;
      continue;
    }
    if (prev == card) return true;
    prev = card;
  }
  return false;
}

bool Hand::is_two_pair()
{
  if ((m_hand[0] == m_hand[1] and m_hand[2] == m_hand[3]) or
      (m_hand[0] == m_hand[1] and m_hand[3] == m_hand[4]) or
      (m_hand[1] == m_hand[2] and m_hand[3] == m_hand[4]) )
  {
    return true;
  }
  else
  {
  return false;
  }
}

bool Hand::is_three_card()
{
  for (int i = 0; i < 3; ++i)
  {
    if (m_hand[i] == m_hand[i+1] and m_hand[i] == m_hand[i+2])
    {
      return true;
    }
  }
  return false;
}

bool Hand::is_straight()
{
  if (m_hand[0] == 1 and m_hand[1] == 10 and m_hand[2] == 11 and 
      m_hand[3] == 12 and m_hand[4] == 13)
  {
    return true;
  }

  int prev = -1;
  for (int card : m_hand)
  {
    if (prev == -1)
    {
      prev = card;
      continue;
    }
    if (prev + 1 != card)
    {
      return false;
    }
    prev = card;
  }
  return true;
}

bool Hand::is_full_house()
{
  if ((m_hand[0] == m_hand[1] and m_hand[0] == m_hand[2] and
       m_hand[3] == m_hand[4]) or
      (m_hand[2] == m_hand[3] and m_hand[2] == m_hand[4] and
       m_hand[0] == m_hand[1]) )
  {
    return true;
  }
  else
  {
    return false;
  }
}

bool Hand::is_four_card()
{
  if ((m_hand[0] == m_hand[1] and m_hand[0] == m_hand[2] and m_hand[0] == m_hand[3]) or
      (m_hand[1] == m_hand[2] and m_hand[1] == m_hand[3] and m_hand[1] == m_hand[4]) )
  {
    return true;
  }
  else
  {
    return false;
  }
}

int main(void)
{
  cin >> noskipws;
  while (true)
  {
    vector<int> cards(5);
    char buf_ch;
    for (int& card : cards)
    {
      cin >> card;
      cin >> buf_ch;
    }
    if (cin.eof() ) break;

    Hand hand(cards);
    cout << hand.what_hand() << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll solve(ll i,ll j,vector < vector < ll > > &a,vector < vector < ll > > &dp,ll c,ll n)
{
	if(j==n-1)
	{
		return a[j][i];
	}
	if(dp[i][j]!=-1)
	{
		return dp[i][j];
	}
	if(i==0)
	{
		c=a[j][i]+max(solve(1,j+1,a,dp,c,n),solve(2,j+1,a,dp,c,n));
	}
	if(i==1)
	{
		c=a[j][i]+max(solve(0,j+1,a,dp,c,n),solve(2,j+1,a,dp,c,n));
	}
	if(i==2)
	{
		c=a[j][i]+max(solve(1,j+1,a,dp,c,n),solve(0,j+1,a,dp,c,n));
	}
	dp[i][j]=c;
	return dp[i][j];
}
int main()
{
	ll n;
	cin>>n;
	vector < vector <ll> > a(n,vector <ll > (3)); 
	for (ll i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	vector<vector<ll> > dp(3,vector<ll>(n,-1));
	ll x=0,maxs=0;
	for (ll i=0;i<3;i++)
	{
		x=solve(i,0,a,dp,0,n);
		maxs=maxs>x?maxs:x;
	}
	cout<<maxs;
}

Measured memory_bytes: 17392
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n;
    cin>>n;
    map<string,int> ht;
    ht.insert({"AC",0});
    ht.insert({"WA",0});
    ht.insert({"TLE",0});
    ht.insert({"RE",0});
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        ht[s]++;
    }
    cout<<"AC x "<<ht["AC"]<<"\n";
    cout<<"WA x "<<ht["WA"]<<"\n";
    cout<<"TLE x "<<ht["TLE"]<<"\n";
    cout<<"RE x "<<ht["RE"]<<"\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1e5;
const int INF = 1e9;



int main() {
    char c;
    cin >> c;
    char arr[] = {'a', 'e', 'i', 'o', 'u'};
    for (char z : arr)
        if (c == z)
            cout << "vowel", exit(0);
    cout << "consonant";
}



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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    vector<int> W(N);
    rep(i, N) cin >> W.at(i);

    int min = INF_32;
    rep(i, N - 1)
    {
        int s1 = accumulate(W.begin(), W.begin() + i + 1, 0);
        int s2 = accumulate(W.begin() + i + 1, W.end(), 0);
        int diff = abs(s1 - s2);
        if (diff < min)
            min = diff;
    }

    cout << min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(Int i=0;i<h;i++) cin>>s[i];

  {
    vector<string> t;
    for(Int i=0;i<h;i++)
      if(s[i]!=string(w,'.')) t.emplace_back(s[i]);
    s=t;
    h=s.size();
  }
  
  {
    vector<string> t(h);
    for(Int j=0;j<w;j++){
      Int flg=0;
      for(Int i=0;i<h;i++) flg|=s[i][j]=='#';
      if(!flg) continue;
      for(Int i=0;i<h;i++)
	t[i].push_back(s[i][j]);
    }
    s=t;
    w=s[0].size();
  }
  

  for(string x:s) cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, A[20], B[20], C[20]; cin >> N;
  REP(i, N){
    cin >> A[i]; A[i]--;
  }
  REP(i, N) cin >> B[i];
  REP(i, N-1) cin >> C[i];
  int ans = 0;
  REP(i, N){
    ans += B[A[i]];
    if(i > 0){
      if(A[i] == A[i-1]+1) ans += C[A[i-1]];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<functional>
#include<algorithm>
#include<map>
using namespace std;
map<long long, long long>H;
vector<pair<long long, long long>>x[300000]; long long dist[300000];
long long n, m, a[300000], b[300000], c[300000], D;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>Q;
void dijkstra() {
	for (long long i = 0; i < 300000; i++)dist[i] = 999999999999999999LL;
	dist[1] = 0; Q.push(make_pair(0, 1));
	while (!Q.empty()) {
		long long a1 = Q.top().first, a2 = Q.top().second; Q.pop();
		for (long long i = 0; i < x[a2].size(); i++) {
			if (dist[x[a2][i].first] > dist[a2] + x[a2][i].second) {
				dist[x[a2][i].first] = dist[a2] + x[a2][i].second;
				Q.push(make_pair(dist[x[a2][i].first], x[a2][i].first));
			}
		}
	}
}
int main() {
	cin >> n >> m >> D; for (long long i = 0; i < m; i++) { cin >> a[i] >> b[i] >> c[i]; x[a[i]].push_back(make_pair(b[i], c[i])); x[b[i]].push_back(make_pair(a[i], c[i])); }
	dijkstra();
	long long minx = 99999999999999999LL, sum2 = 0;
	for (long long i = 0; i < m; i++)H[max(dist[a[i]], dist[b[i]])] += c[i];
	sort(dist + 1, dist + n + 1); long long maxn = dist[n];
	for (long long i = 0; i < m; i++)sum2 += c[i];

	for (long long j = 1; j <= n; j++) {
		if (dist[j - 1] == dist[j])continue;
		long long i = dist[j];
		sum2 -= H[i];
		minx = min(minx, i*D + sum2);
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 32444
#include <iostream>
#include <queue>

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

const int INF = 1 << 21;

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

  int a[n][n];

  rep(i, n) rep(j, n) a[i][j] = 0;

  rep(i, n) {
    int u, k;
    std::cin >> u >> k;
    rep(j, k) {
      int v;
      std::cin >> v;
      a[u - 1][v - 1] = 1;
    }
  }

  int d[n];
  rep(i, n) d[i] = INF;
  d[0] = 0;

  std::queue<int> q;
  q.push(0);

  while (!q.empty()) {
    int u = q.front();
    q.pop();
    rep(j, n) {
      if (a[u][j] && d[j] == INF) {
        d[j] = d[u] + 1;
        q.push(j);
      }
    }
  }

  rep(i, n) std::cout << i + 1 << ' ' << (d[i] == INF ? -1 : d[i]) << '\n';

  return 0;
}



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

int main()
{
	int ar[3];
	cin>>ar[0]>>ar[1]>>ar[2];
	sort(ar,ar+3);
	int ans=abs(ar[0]-ar[1])+abs(ar[2]-ar[1]);
	cout<<ans<<"\n";
return 0;
}


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

using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	if((a>=1&& a<=9)&&(b>=1&& b<=9))
	{
		cout<<a*b;
	}else{
		cout<<"-1";
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main() {
	int q; cin >> q;
	priority_queue<int> f;
	priority_queue<int, vector<int>, greater<int>> g;
	ll x=0, add = 0;
	rep(i, 0, q) {
		int t; cin >> t;
		if (t == 1) {
			int a, b; cin >> a >> b;
			add += b;
			if (f.size() <= g.size()) {
				f.push(a);
				x++; add -= a;
			}
			else {
				g.push(a);
				x--; add += a;
			}
			while (!f.empty() && !g.empty() && f.top() > g.top()) {
				add += f.top()*2; add -= g.top()*2;
				int p = f.top();
				f.pop(); f.push(g.top());
				g.pop(); g.push(p);
			}
		}
		else {
			printf("%d %lld\n", f.top(), 1LL*x * f.top() + add);
		}
	}
	return 0;
}


Measured memory_bytes: 3452
#include <iostream>
using namespace std;
int main() {
    int n, X; cin >> n >> X;
    int x[n]; for (int i = 0; i < n; i++) cin >> x[i];
    unsigned long long s[n+1];
    s[0] = 0; for (int i = 0; i < n; i++) s[i+1] = s[i] + x[i];
    unsigned long long ans;
    for (int m = 1; m <= n; m++) {
        unsigned long long sum = (unsigned long long)(m + n) * X;
        sum += 5 * (s[n] - s[max(0, n-2*m)]);
        for (int c = 7, i = n-2*m; i > 0; c += 2, i -= m) {
            sum += c * (s[i] - s[max(0, i-m)]);
        }
        if (m == 1 || sum < ans) ans = sum;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,n,i,j,k,x,sum1= 0,sum2=0,c1=0,c2=0;
    cin>>n ;
    for(i = 0 ;i<n ;i++)
    {
        cin>>x;
        if(i %2 == 0)
        {
            sum1+=x;
            sum2+=x;
            if(sum1>=0){
                c1+= sum1- (-1);
                sum1=-1;
            }
            if(sum2<=0)
            {
                c2+= (-1)*sum2 + 1;
                sum2=1;
            }
        }
        else
        {
            sum1+=x;
            sum2+=x;
              if(sum2>=0){
                c2+= sum2- (-1);
                sum2=-1;
            }
            if(sum1<=0)
            {
                c1+= (-1)*sum1 + 1;
                sum1=1;
            }
        }
       // cout<<c1<<endl;
    }
   // cout<<c1<<c2<<endl;
    cout<<min(c1,c2)<<endl;
    return 0 ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    int k, a, b;
    scanf("%d%d%d", &k, &a, &b);
    bool flag = false;
    for(int i = a; i <= b; i++) {
        if(i % k == 0) flag = true;
    }
    printf("%s\n", flag ? "OK" : "NG");
    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
	int N, M; cin >> N >> M; 
	int L = INT_MIN; int R = INT_MAX;  
	for(int i = 0; i < M; i++){
		int l, r; cin >> l >> r; 
		L = max(L, l); R = min(R, r); 
	}
	if(L <= R) cout << (R - L) + 1 << endl; 
	else cout << 0 << endl; 
}


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

int main(){
   int n,k,maxa;
   cin >> n >> k;
   vector<int> a(n);
   maxa = 0;
   rep(i,n) {
      cin >> a[i];
      maxa = max(a[i],maxa);
   }
   int l=0,r=maxa;
   while(r-l>1){
      int x=(r+l)/2;
      auto f = [&](int x){
         ll now = 0;
         rep(i,n) now += (a[i]-1)/x;
         return now<=k;
      };
      if(f(x)) r=x; else l=x;
   }
   cout << r << endl;
   return 0;  
}

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

int main(){
    int a,b,c,d;    cin>>a>>b>>c>>d;
    if(a+b>c+d)cout<<"Left"<<endl;
    else if(a+b==c+d)cout<<"Balanced"<<endl;
    else cout<<"Right"<<endl;

    return 0;
}


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

int main()
{
  int N, Y;
  cin >> N >> Y;

  int x, y, z;
  x = y = z = -1;
  bool found = false;
  for (int i = 0; i <= N; ++i)
  {
    for (int j = 0; j <= N; ++j)
    {
      if (i + j > N) break;
      int k = N - (i + j);
      if (i * 10000 + j * 5000 + k * 1000 == Y)
      {
        x = i;
        y = j;
        z = k;
        found = true;
      }
    }
    if (found) break;
  }

  cout << x << " " << y << " " << z << endl;

  return 0;
}


Measured memory_bytes: 256