akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long N, A, B;
    cin >> N >> A >> B;

    long long a = 0, b = 0;
    a = N % (A+B);
    b = N / (A+B);

    if (N < A+B && N >= A) cout << A << endl;
    else if (N < A+B) cout << a << endl;
    else if (a > A) cout << b*A+A << endl;
    else cout << b*A+a << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n,m = list(map(int,input().split()))
x = list(map(int,input().split()))
x.sort()
#各座標の、右隣の座標までの距離を求める
right_distance = [j-i for i,j in zip(x,x[1::])]
right_distance.sort()
ret = 0
while n < m:
    ret += right_distance.pop(0)
    m -= 1
print(ret)

Measured memory_bytes: 13308
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


K = int(input())

# 解法1
# 数列 s は、s[1] = 7, s[i+1] = s[i] * 10 + 7 の漸化式で与えられる
# 特性方程式 α = α * 10 + 7 を考えると、α = -7/9 より、
# s[i+1] + 7/9 = 10 * (s[i] + 7/9) となる
# つまり、s[i] + 7/9 = 10^(i-1) * (7 + 7/9)
# <=> s[i] = 10^(i-1) * 70/9 - 7/9
# <=> s[i] = 7/9 * (10^i - 1)
# よって、7/9 * (10^i - 1) % K == 0 となるような最小の正の整数 i を求めれば良いことになる

# 解法2
# s[i] = s[i-1] * 10 + 7 より、s[i] % K = (s[i-1] * 10 + 7) % K
# a[i] = s[i] % K とすると、# a[i] = a[i-1] % K だから、
# a[i] を順番に計算し、a[i] == 0 となる最初の i を出力しても OK

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    i = 1
    a_i = 0
    while True:
        a_i = (a_i * 10 + 7) % K
        if a_i == 0:
            print(i)
            break
        i += 1


Measured memory_bytes: 75012
program sumitrust2019C
	integer(8)::X
	integer(8)::flg=0
	
	read(5,*)X
	
	if(mod(X,100)==0)then
		flg=1
	else if(mod(mod(X,100),5)==0)then
		if(mod(X,100)/5<=X/100)then
			flg=1
		end if
	else if(mod(X,100)/5+1<=X/100)then
		flg=1
	end if
	
	print'(i0)',flg
end program sumitrust2019C


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll M=1e9+7;
const ll mxx=1e5+7;

ll dp[2001];
ll fun(ll tar)
{
	 if(tar==0)return 1;
	 if(tar<3)return 0;
	
	 if(dp[tar]!=-1)return dp[tar];
     ll ans=0;
	 for(int i=3;i<=tar;i++)
	 {
        ans+=fun(tar-i);
        ans%=M;
	 }
	 return dp[tar]=ans;

}

int main()
{

    ll s;
    cin>>s;
    memset(dp,-1,sizeof dp);
    cout<<fun(s);
   
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <functional>

template <typename F>
auto fix(F&& f) {
	return[f = std::forward<F>(f)](auto&& ... args) {
		return f(f, std::forward<decltype(args)>(args)...);
	};
}

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

	std::vector<std::vector<int>> edges(n);
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		std::cin >> a >> b;
		--a, --b;

		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	std::vector<int> ans(n);
	for (int i = 0; i < q; ++i) {
		int p, x;
		std::cin >> p >> x;
		--p;

		ans[p] += x;
	}

	std::vector<bool> visited(n);
	auto dfs = fix([&](auto f, int x, int cost) -> void {
		visited[x] = true;

		ans[x] += cost;
		
		int childrenSum = 0;
		for (auto&& next : edges[x]) {
			if (visited[next])
				continue;

			f(f, next, ans[x]);
		}
	});
	dfs(0, 0);

	for (auto&& e : ans)
		std::cout << e << std::endl;
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
// ミント
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
int main(){
  ll n,m ;cin>>n>>m ;
  if(abs(n-m)>1) cout<<0<<endl ;
  else{
    mint a=1 ;
    rep(i,n){
      a*=i+1 ;
    }
    rep(i,m){
      a*=i+1 ;
    }
  if(n==m) cout<<a*2<<endl ;
  else cout<<a<<endl ;
  }
    return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
#define Graph vector<vector<int>>
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
#define inf 1000000321
#pragma GCC optimize("Ofast")
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S,T;
    cin >> S>>T;
    int N = S.size();
    int M = T.size();
    ll ans = N+M+N+M+2;
    for(int i = 0;i < N-M+1;i++){
        ll pre = 0;
        for(int j = 0;j < M;j++){
            if(S[i+j] != T[j]){
                pre++;
            }
        }
        ans = min(ans,pre);
    }
    if(S == T)ans = 0;
    cout << ans << endl;
}   

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0;i<n;i++)
const long long MOD = 1000000007;
const long long INF = MOD*MOD;
typedef pair<int,int> P;
typedef long long ll;
ll n,m,k;
string s,s1,s2;

int main(){
  char s; cin >> s;
  int tmp = s - 'a';
  cout << (char)('a'+tmp+1)  << "\n";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d,e,f,g,h,x=0,y=0;
    while(cin >> a >> b >> c >> d >> e >> f >> g >> h){
        x=0;
        y=0;
        if (a==e){x=x+1;} 
        if (b==f){x=x+1;} 
        if (c==g){x=x+1;}
        if (d==h){x=x+1;}
        if (e==b || e==c || e==d){y=y+1;}
        if (f==a || f==c || f==d){y=y+1;}
        if (g==a || g==b || g==d){y=y+1;}
        if (h==a || h==b || h==c){y=y+1;}
        cout << x << " " << y << endl;
    }  
return 0 ;
}



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

int main() {
    char c;
    cin >> c;

    if (c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}


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

using ll = long long;

vector<ll> v;
void dfs(ll x, int d){
  if(d < 0) return;
  v.push_back(x);
  int a = x % 10;
  if(a != 0) dfs(10 * x + a - 1, d - 1);
  if(a != 9) dfs(10 * x + a + 1, d - 1);
  dfs(10 * x + a, d - 1);
}

signed main(){

    int K; cin >> K;
    for(int i = 1; i <= 9; i++) dfs(i, 9);
    sort(v.begin(), v.end());
    cout << v[K - 1] << endl;

    return 0;
}

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

int N;
int main(){
	cin >> N;
	int ans = 1e9;
	for(int i=0;i<=N;i++){
		int c = 0;
		int t = i;
		while(t>0){
			c += t%6;
			t /= 6;
		}
		t = N-i;
		while(t>0){
			c += t%9;
			t /= 9;
		}
		if(ans>c) ans = c;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); //cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

void solve(){
	int n; cin >> n;
	if (n == 25){
		cout << "Christmas";
	}
	if (n == 24){
		cout << "Christmas Eve";
	}
	if (n == 23){
		cout << "Christmas Eve Eve";
	}
	if (n == 22){
		cout << "Christmas Eve Eve Eve";
	}
}	

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

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i64 = input();
    let b: i64 = input();
    let c: i64 = input();
    let d: i64 = input();

    let a = a - 1;
    let na = a - a / c - a / d + a / lcm(c, d);
    let nb = b - b / c - b / d + b / lcm(c, d);
    println!("{}", nb - na);
}

fn lcm(x: i64, y: i64) -> i64 {
    x / gcd(x, y) * y
}

fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[50000],i,j,k,n;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    long long sum=0;
    for(i=0;i<k;i++)
    {
        sum=sum+a[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3556
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n,k,q;
  cin >> n >> k >> q;

  vector<int> a(q);
  REP(i,q) cin >> a[i];
  
  vec cnt(n,0);
  REP(i,q) cnt[a[i]-1]++;

  REP(i,n){
    if(k-q+cnt[i]>0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) 1e9
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	int n;
	cin>>n;
	int v[n][3];
	for(int i=0; i<=n; i++){
		cin>>v[i][0]>>v[i][1]>>v[i][2];
	}
	//int dp[n+1][3];
	vector <vector <int>> dp(n+1, vector <int>(3, 0));
	for(int i=1; i<=n; i++){
		for(int j=0; j<3 ;j++){
			dp[i][j] = max(dp[i][j], dp[i-1][(j+1)%3] + v[i-1][j]);
			dp[i][j] = max(dp[i][j], dp[i-1][(j+2)%3] + v[i-1][j]);
		}
	}
	cout<<*max_element(dp[n].begin(), dp[n].end());
}

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

int main(){
  int N; cin >>N;
  vector<tuple<string,int,int>> R(N);
  repeat(i,N){
    string S;
    int P;
    cin >>S>>P;
    R.at(i) = make_tuple(S,-1*P,i+1);
  }
  sort(R.begin(),R.end());
  
  repeat(i,N){
    int ans;
    ans = get<2>(R.at(i));
    cout << ans << endl;
  }
}

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

using namespace std;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    cout << (i==3 ? '8' : s[i]);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  string s;

  cin>>s;

  ll fi = (s[0]-'0')*10 + s[1]-'0';
  ll se = (s[2]-'0')*10 + s[3]-'0';

  if( (fi == 0 && se > 12) || (se == 0 && fi > 12) || (fi > 12 &&  se > 12) || (fi==0 && se==0) ){
    cout << "NA" << endl;
    return 0;
  }
  else if( fi > 12 || fi==0 ){
    cout << "YYMM" << endl;
    return 0;
  }
  else if( se > 12 || se==0 ){
    cout << "MMYY" << endl;
    return 0;
  }
  else{
    cout << "AMBIGUOUS" << endl;
    return 0;
  }

  return 0;

}


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

int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll even =0;
    ll odd =0;
    ll mul =0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if( a[i] %2 ==1 )
            odd++;

        if( a[i] %4 ==0 )
            mul ++;
        if( a[i] %4 != 0 && a[i] %2==0 )
        {
            even++;
        }

    }
    if( odd > mul + 1  )
    {
        cout<<"No";
    }
    else if( odd == (mul +1) && even >0)
    {
        cout<<"No";
    }
    else if( odd <=(mul+1) && even ==0 )
    {
        cout<<"Yes";
    }
    else if( odd == mul)
    {
        cout<<"Yes";
    }
    

}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define vi vector<ll>
#define all(v) v.begin(), v.end()

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n = 0;
	cin >> n;
	ll sol = 0, tmp = 0;
	string s;
	cin >> s;
	rep(i, n)
	{
		if(s[i] == 'I')
			tmp++;
		else if(s[i] == 'D')
			tmp--;
		if(tmp > sol)
			sol = tmp;
	}
	cout << sol << endl;
	
	#ifdef LOCAL_DEFINE
		cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif
	return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

mp = float('inf')
def f(i, anum, alen, bnum, blen, cnum, clen):
    global mp
    if i == n:
        if alen * blen * clen == 0:
            return
        mp = min(mp, abs(anum-a)+10*(alen-1) + abs(bnum-b)+10*(blen-1) + abs(cnum-c)+10*(clen-1))
    else:
        f(i+1, anum+l[i], alen+1, bnum, blen, cnum, clen)
        f(i+1, anum, alen, bnum+l[i], blen+1, cnum, clen)
        f(i+1, anum, alen, bnum, blen, cnum+l[i], clen+1)
        f(i+1, anum, alen, bnum, blen, cnum, clen)

f(0, 0, 0, 0, 0, 0, 0)


print(mp)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)
	s, x0, y0 := nextStr(), nextInt(), nextInt()
	rs := []rune(s)
	n := len(rs)
	idx := 0
	for idx < n {
		if rs[idx] == 'T' {
			break
		}
		x0--
		idx++
	}

	xArray, yArray := make([]int, 0), make([]int, 0)
	mode := 'x'
	count := 0
	for idx <= n {
		switch {
		case idx == n:
			switch {
			case mode == 'x':
				if count > 0 {
					xArray = append(xArray, count)
					count = 0
				}
				mode = 'y'
			case mode == 'y':
				if count > 0 {
					yArray = append(yArray, count)
					count = 0
				}
				mode = 'x'
			}
			break
		case rs[idx] == 'F':
			count++
		case rs[idx] == 'T':
			switch {
			case mode == 'x':
				if count > 0 {
					xArray = append(xArray, count)
					count = 0
				}
				mode = 'y'
			case mode == 'y':
				if count > 0 {
					yArray = append(yArray, count)
					count = 0
				}
				mode = 'x'
			}
		}
		idx++
	}

	xSum, ySum := 0, 0
	for _, x := range xArray {
		xSum += x
	}
	for _, y := range yArray {
		ySum += y
	}
	if x0 > xSum || x0 < -xSum || y0 > ySum || y0 < -ySum || (xSum-x0)%2 != 0 || (ySum-y0)%2 != 0 {
		fmt.Print("No")
		return
	}

	var xGoal, yGoal int
	switch {
	case x0 > 0:
		xGoal = (xSum - x0) / 2
	default:
		xGoal = (xSum + x0) / 2
	}
	switch {
	case y0 > 0:
		yGoal = (ySum - y0) / 2
	default:
		yGoal = (ySum + y0) / 2
	}
	xDp, yDp := make([]bool, xGoal+1), make([]bool, yGoal+1)
	xDp[0], yDp[0] = true, true
	for _, x := range xArray {
		for xi := xGoal; xi >= x; xi-- {
			if xDp[xi-x] {
				xDp[xi] = true
			}
		}
	}
	for _, y := range yArray {
		for yi := yGoal; yi >= y; yi-- {
			if yDp[yi-y] {
				yDp[yi] = true
			}
		}
	}

	if xDp[xGoal] && yDp[yGoal] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 768
H, W = [int(x) for x in input().split()]
A_s = [input() for _ in range(H)]

pos = [0, 0]
num = 1
while True:
    if pos == [H - 1, W - 1]:
        total = sum(map(lambda A: A.count("#"), A_s))
        ans = total == num
        break
    h, w = pos
    if h != H - 1 and A_s[h + 1][w] == "#":
        pos = [h + 1, w]
        num += 1
        continue
    if w != W - 1 and A_s[h][w + 1] == "#":
        pos = [h, w + 1]
        num += 1
        continue
    ans = False
    break

print("Possible" if ans else "Impossible")


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <string>
#include <sstream>
#include <cstring>
#include <cmath>

using namespace std;

#ifdef DEBUG
#define LOG(args) cout << args << "\n"
#define debug(x) x
#else
#define LOG(args)
#define debug(x)
#endif

#define vi vector<int>
#define ii pair<int, int>
#define vii vector< ii >
#define vvi vector< vi >
#define mp make_pair
#define pb push_back
#define ms(x, v) memset(x, v, sizeof(x))
#define all(x) x.begin(), x.end()
#define REP(x, n) for(int x = 0; x < n; x++)
#define REPV(x, v, n) for(int x = v; x < n; x++)
#define REVE(x, n) for(int x = n; x >= 0; x--)

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, curr = 1000;
	cin >> N;
	while(curr < N)
		curr += 1000;
	cout << curr - N << "\n";
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

int mod_pow(int n, int p, int MOD){
  int r = 1;
  for(; p > 0; p >>= 1){
    if(p & 1LL) r = (r * n) % MOD;
    n = (n * n) % MOD;
  }
  return r; // r = n^p % MOD
}

int f(int x, int b){
  if(x == 0) return 0LL;
  int cnt = 0;
  int base = 1;
  while(x != 0){
    if(x % (base * b) == 0){

    }else{
      x -= base;
      cnt++;
    }
    base *= b;
  }
  return cnt;
}

signed main(){

  int n; cin >> n;
  string s; cin >> s;

  reverse(s.begin(), s.end());
  int bit = 0;
  for(int i = 0; i < n; i++){
    bit += s[i] == '1';
  }

  int r1 = 0, r2 = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == '1') r1 = (r1 + mod_pow(2, i, (bit+1))) % (bit+1); 
    if(s[i] == '1'){
      if(bit-1 == 0) r2 = 0;
      else r2 = (r2 + mod_pow(2, i, (bit-1))) % (bit-1); 
    }
  }

  auto rec = [&](auto&& rec, int res)->int{
    int b = f(res, 2);
    if(b == 0) return 1LL;
    return rec(rec, res % b) + 1;
  };

  vector<int> start(n), ans(n);
  for(int i = 0; i < n; i++){
    if(s[i] == '0'){
      start[i] = (r1 + mod_pow(2, i, (bit+1)) % (bit+1)) % (bit+1); 
      ans[i] = rec(rec, start[i]);
    }else{
      if(bit-1 == 0){
        ans[i] = 0;
      }else{
        start[i] = (r2 - mod_pow(2, i, (bit-1)) + bit-1) % (bit-1); 
        ans[i] = rec(rec, start[i]);
      }
    }
    //ans[i] = rec(rec, start[i]);
  }
  reverse(ans.begin(), ans.end());
  for(int p : ans){
    cout << p << endl;
  }

  return 0;
}

Measured memory_bytes: 6760
#include<stdio.h>
#include<stdlib.h>
int main() {
	int m, n1, n2, n3;
	scanf("%d%d%d", &n1, &n2, &n3);
	if (abs( n1) < abs(n2)) {
		m = n1;
		n1 = n2;
		n2 = m;
	}
	if (abs(n1) <abs( n3)) {
		m = n3;
		n3 = n1;
		n1 = m;
	}
	if (abs(n2) < abs(n3)) {
		m = n2;
		n2 = n3;
		n3 = m;
	}
	printf("%d ", abs(n1 - n2) + abs(n2 - n3));
	return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const ll inf = (ll)1e9 + 7;
int main()
{
    ll i, j, k, n;
    cin >> n;
    cout << (n + 1) / 2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,T;
  cin >> N >> T;
  vector<long long> t(N);
  for(long long i = 0;i<N;i++){
    cin >> t[i];
  }
  long long X = 0;
   for(long long i = 0;i<N-1;i++){
     if(t[i+1]-t[i] <= T){
       X += t[i+1]-t[i];
     }
     else if(t[i+1]-t[i] > T){
       X += T;
     }
    }
     cout << X + T << endl;
     
}

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

using namespace std;

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

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

	string S; cin >> S;

	int n = (int)S.length();
	int res = INF;

	rep (i, n - 3 + 1){
		vector<int> cand; cand.clear();
		for (int j = i; j < i + 3; ++j){
			cand.push_back((int)(S[j] - '0'));
		} // end if

		int curr = 0;
		rep (j, 3){
			curr *= 10;
			curr += cand[j];
		} // end rep
//		cerr << "curr: " << curr << endl;
		int diff = abs(753 - curr);
		res = min(res, diff);
	} // end rep
	
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
/* Manish Pant - insider_pants, hello_my_friend */
    
#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;

#define F first
#define S second
#define endl "\n"
#define pb push_back

typedef long long ll;
typedef long double ldob;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T> ostream& operator << (ostream &os, const multiset<T> &v) { for (T i : v) os << i << " "; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.F << ' ' << v.S; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.F << " => " << i.S << ')' << ' '; return os; } 

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
ll n, k;
vector<ll> ans(N);

ll power(ll x, ll y)
{
    if(x == 0) return 0;
    ll ans = 1;
    while(y > 0)
    {
        if(y & 1) ans = (ans * x) % MOD;

        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans % MOD;
}

void solve()
{
    ll res = 0;
    ll cnt = 0;
    for(ll i = k; i >= 1; i--)
    {
        ll multiple = k / i;
        ll total = power(multiple, n);
        for(ll j = i + i; j <= k; j += i) total = (total - ans[j] + MOD) % MOD;

        ans[i] = total;
        res = (res + (total * i) % MOD) % MOD;
    }
    cout << res << endl;
}

int main()
{
    fast();
    cin >> n >> k;
    solve();
}

Measured memory_bytes: 3888
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
const ll MAX = 1e9;
 
int main() {
    ll n;
    cin >> n;

    vl a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    ll m = n*(n+1)/2;
    if(sum%m != 0) {
        out("NO");
        re0;
    }

    ll t = sum/m;  // 操作回数

    vl b(n);
    rep(i, n-1) {
        b[i] = a[i+1] - a[i] - t;
    }
    b[n-1] = a[0] - a[n-1] - t;

    rep(i, n) {
        if(b[i] > 0) {
            out("NO");
            re0;
        }
        if(abs(b[i])%n != 0) {
            out("NO");
            re0;
        }
    }
    
    out("YES");
    re0;
}

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

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

    // SUN,MON,TUE,WED,THU,FRI,SAT

    if(s == "SUN"){
        std::cout << 7 << std::endl;
    }else if(s == "MON"){
        std::cout << 6 << std::endl;
    }else if(s == "TUE"){
        std::cout << 5 << std::endl;
    }else if(s == "WED"){
        std::cout << 4 << std::endl;
    }else if(s == "THU"){
        std::cout << 3 << std::endl;
    }else if(s == "FRI"){
        std::cout << 2 << std::endl;
    }else{
        std::cout << 1 << std::endl;
    }
    
    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 pair<int,int>P;

int n;
int x[20000],y[20000];
P p[40000];
vector<int>id[20000];

vector<int>E[80000],G[80000];
int N;

void init(int n){
	N=1;while(N<n)N<<=1;
	rep(i,2*N-1){
		E[i].clear();
		G[i].clear();
	}
}
void add_edge(int a,int b,int x,int k=0,int l=0,int r=N){
	if(b<=l||r<=a)return;
	if(a<=l&&r<=b){
		E[x+N-1].push_back(k);
		G[k].push_back(x+N-1);
		return;
	}
	add_edge(a,b,x,k*2+1,l,(l+r)/2);
	add_edge(a,b,x,k*2+2,(l+r)/2,r);
}

bool used[80000];
vector<int>vs;
int cmp[80000];

void dfs(int v){
	used[v]=true;
	for(int u:E[v]){
		if(!used[u])dfs(u);
	}
	if(v<N-1&&!used[v*2+1])dfs(v*2+1);
	if(v<N-1&&!used[v*2+2])dfs(v*2+2);
	vs.push_back(v);
}
void rdfs(int v,int k){
	cmp[v]=k;
	for(int u:G[v]){
		if(cmp[u]==-1)rdfs(u,k);
	}
	if(v&&cmp[(v-1)/2]==-1)rdfs((v-1)/2,k);
}
void scc(){
	memset(used,0,sizeof(used));
	memset(cmp,-1,sizeof(cmp));
	vs.clear();
	rep(i,2*N-1){
		if(!used[i])dfs(i);
	}
	int cnt=0;
	for(int i=vs.size()-1;i>=0;i--){
		if(cmp[vs[i]]==-1){
			rdfs(vs[i],cnt++);
		}
	}
}
bool C(int d){//全てd以上にできるか?
	init(2*n);
	rep(i,2*n){
		int s=lower_bound(p,p+i,P(p[i].first-d+1,-1))-p;
		int t=lower_bound(p+i,p+2*n,P(p[i].first+d,-1))-p;
		add_edge(s,i,id[p[i].second][id[p[i].second][0]==i]);
		add_edge(i+1,t,id[p[i].second][id[p[i].second][0]==i]);
	}
	scc();
	rep(i,n){
		if(cmp[id[i][0]+N-1]==cmp[id[i][1]+N-1])return false;
	}
	return true;
}
int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%d%d",&x[i],&y[i]);
		if(x[i]>y[i])swap(x[i],y[i]);
		p[i*2]=P(x[i],i);
		p[i*2+1]=P(y[i],i);
	}
	sort(p,p+2*n);
	rep(i,2*n){
		id[p[i].second].push_back(i);
	}
	int l=0,r=INT_MAX/2;
	while(r-l>1){
		int t=(l+r)/2;
		if(C(t))l=t;
		else r=t;
	}
	cout<<l<<endl;
}

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

int main() {
  int a,b,c,d; cin >> a >> b >> c;
  if((b*10+c)%4 == 0)
  cout << "YES" << endl;
  else
  {
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}

ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
//////////////////////////////////////
int dp[15][9][2];
int main(){
    int n;
    cin>>n;
    vi num;
    while(n>0){
        num.push_back(n%10);
        n/=10;
    }
    reverse(all(num));
    //for(int x:num)cout<<x<<endl;
    n=num.size();
    
    rep(i,n){
        dp[i][0][1]=1;
    }
    dp[0][0][0]=1;
    dp[0][0][1]=0;
    rep(i,n){
        rep(j,8){
            if(num[i]==3){
                dp[i+1][j|0b001][0]+=dp[i][j][0];
            }
            else if(num[i]==5){
                dp[i+1][j|0b010][0]+=dp[i][j][0];
            }
            else if(num[i]==7){
                dp[i+1][j|0b100][0]+=dp[i][j][0];
            }
            
            if(num[i]>3){
                dp[i+1][j|0b001][1]+=dp[i][j][0];
            }
            if(num[i]>5){
                dp[i+1][j|0b010][1]+=dp[i][j][0];
            }
            if(num[i]>7){
                dp[i+1][j|0b100][1]+=dp[i][j][0];
            }
            
            dp[i+1][j|0b001][1]+=dp[i][j][1];
            dp[i+1][j|0b010][1]+=dp[i][j][1];
            dp[i+1][j|0b100][1]+=dp[i][j][1];

            //printf("%d:%d:0=%d\n",i+1,j,dp[i+1][j][0]);
            //printf("%d:%d:1=%d\n",i+1,j,dp[i+1][j][1]);
        }
        
    }
    int ans=dp[n][7][0]+dp[n][7][1];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n, q;
  scanf ("%" SCNi32 "%" SCNi32, &n, &q);
  char *s = (char *) calloc (n + 1, sizeof (char));
  scanf ("%s", s);
  i32 *sum = (i32 *) calloc (n + 1, sizeof (i32));
  for (i32 i = 0; i < n - 1; ++i) {
    sum[i + 2] += sum[i + 1] + (s[i] == 'A' && s[i + 1] =='C' ? 1 : 0);
  }
  while (q--) {
    i32 l, r;
    scanf ("%" SCNi32 "%" SCNi32, &l, &r);
    printf ("%" PRIi32 "\n", sum[r] - sum[l]);
  }
}

int main (void) {
  run ();
  return 0;
}

Measured memory_bytes: 1280
#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;

#define lp(i,n) for(int i = 0; i <n;i++)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define sz(v) ((int)((v).size()))
typedef long long ll;
typedef unsigned long long ull;
template<class T> using ordered_set=tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)4e4+5;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
// int n,m,k;
// int col[N],row[N];
//  vector<int>a(n),b(m);
// void get_row(){
//       int start = 0,end=0;
//     while(idx<n){

//     }
// }
// void get_col(){
//     int start = 0,end=0;
//     while(idx<m){
//         range(i,idx,n-1){
//             if(!a[])idx++;
//         }
//     }
// }
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    
    // scanf("%d %d %d",&n,&m,&k);
    // a=vector<int>(n),b=vector<int>(m);
    // range(i,0,n-1){
    //     scanf("%d",&a[i]);
    // }    
    // range(i,0,m-1){
    //     scanf("%d",&b[i]);
    // }
    // string s;
    // cin>>s;
    // bool ok = 0;
    // lp(i,sz(s)){
    //     if(s[i]-'0'==7)ok=1;
    // }
    // ok?puts("Yes"):puts("No");
    // int n;
    // cin>>n;
    // ll sum = 0;
    // for(int i=1;i<=n;i++){
    //     if(i%3&&i%5)sum+=i;
    // }
    // cout<<sum<<endl;
    int n;
    cin>>n;
    ll sum =0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)//debug
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
  int n,s;
  cin >> n;
  s = n*n*n;
  cout << s << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int a, b;
  cin >> a >> b;
  int def = b - a;
  int sum = 0;
  REP2(i,1,def+1){
    sum += i;
  }
  //cout << sum << endl;
  int ans = sum - b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Map<String,Integer> map = new HashMap<>();
        int max_letters = 0;
        int max = 0;
        while(sc.hasNext()){
            String str = sc.next();
            if(map.containsKey(str)){
                int cnt = map.get(str);
                max = Math.max(max,cnt+1);
                map.remove(str);
                map.put(str,cnt+1);
            }
            else{
                map.put(str,1);
                max_letters = Math.max(max_letters,str.length());
            }
        }
        String a = "";
        String b = "";
        for(String key : map.keySet()){
            if(map.get(key) == max)
                a = key;
            if(key.length() == max_letters)
                b = key;
        }
        System.out.println(a + " " + b);
    }
}


Measured memory_bytes: 26168
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>
#include <unordered_map>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
/*
102
202
1301
*/
int dp[20][(1<<16)+5];
vvint vv;
int n;
int foo(int s,int x){
	if(s==(1<<n)-1) return 0;
	if(dp[x][s]!=-1) return dp[x][s];
	// bitset<20> bi=s;
	// cout<<x<<" "<<bi.to_string()<<endl;
	int ret=vv[x][0];
	rep(i,n+1){
		if(s&(1<<i)) ret=min(ret,vv[x][i+1]);
	}
	int t=INF;
	int s2=s|(1<<x);
	if(s2==(1<<n)-1) return dp[x][s]=ret;
	rep(i,n){
		if(s2&(1<<i)) continue;
		t=min(t,foo(s2,i));
	}
	ret+=t;
	return dp[x][s]=ret;
}
void mainmain(){
	while(cin>>n,n){
		rep(i,20){
			rep(j,(1<<16)+5){
				dp[i][j]=-1;
			}
		}
		initvv(vv,n,n+1);
		rep(i,n){
			rep(j,n+1){
				cin>>vv[i][j];
				// cout<<vv[i][j]<<" ";
			}
			// cout<<endl;
		}
		int ans=INF;
		rep(i,n) ans=min(ans,foo(0,i));
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 6332
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main(){
string str;
  cin >> str;
 
if(str == "FRI"){cout << 2 << endl;}
if(str == "SAT"){cout << 1 << endl;}
  if(str == "SUN"){cout << 7 << endl;}
  if(str == "MON"){cout << 6 << endl;}
  if(str == "TUE"){cout << 5 << endl;}
  if(str == "WED"){cout << 4 << endl;}
  if(str == "THU"){cout << 3 << endl;}
 
return 0;
}

Measured memory_bytes: 256
s = input()
counts = [0]*2019
counts[0] += 1
num = 0
d = 1
for c in reversed(s):
    d %= 2019 
    num += int(c)%2019 * d
    counts[num % 2019] += 1
    d *= 10
ans = 0
for count in counts:
    ans += count*(count -1) // 2
print(ans)

Measured memory_bytes: 9248
def main():
  n = int(input())
  
  if n == 1: return 0
  if n == 2: return 2
  
  mod = 10**9 + 7

  n_10 = pow(10, n, mod)
  n_9 = pow(9, n, mod)
  n_8 = pow(8, n , mod)
  
  ans = (n_10 - 2*n_9 + n_8) % mod
  
  return ans
  
  
ans = main()
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int s;
  cin >> s;
  set<int> st;
  st.insert(s);
  int ans=1;
  while(1){
    if(s%2==0){
      s /= 2;
    } else {
      s = 3*s+1;
    }
    ans++;
    if(st.find(s)!=st.end()){ break; }
    st.insert(s);
  }
  cout << ans << endl; 
  return 0;
}


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

#define pb push_back
#define sz size()

using namespace std;

const int N = 1e6 + 1;
const int inf = 1e9 + 7;

typedef long double ld;

int n, m;

string s[N];

int dp[1010][1010];

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin>> n>> m;
    for(int i = 0; i < n; i++)cin>> s[i];
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(s[i][j] == '#')continue;
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % inf;
            dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % inf;
        }
    }
    cout<< dp[n - 1][m - 1];
}


Measured memory_bytes: 13056
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a,b,c;
	
	cin>>a>>b>>c;
	
	if(a<b&&b<c){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}



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

int main()
{
  int a, b, c, k, i;
  cin >> a >> b >> c >> k;
  int m = max({a, b, c});
  int res = a + b + c - m;
  for (i = 0; i < k; i++)
    m *= 2;
  cout << res + m << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math
n = math.factorial(int(input()))
fac = prime_factorize(n)
ans = 1
mod = 7 + 10 ** 9
from collections import Counter
c = Counter(fac)
for i in c.values():
    ans *= (i + 1)
    ans %= mod
print(ans)

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

#define int long long 
int mod = 1000000007;

int32_t main()
{
    int n,m;
    cin>>n>>m;
    int arr[n];
    for(int i=0; i<n; i++)cin>>arr[i];
    vector<pair<int,int> > v;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back({b,a});
    }
    sort(v.begin(), v.end(), greater<pair<int,int> >());
    sort(arr,arr+n);
    int index=0;
    for(int i=0; i<m; i++)
    {
        int count=0;
        for(int j=index; j<n; j++)
        {
            //index++;
            if(arr[j] < v[i].first)
            {
                arr[j] = v[i].first;
            }
            else
            {
                index = n;
                break;   
            }
            if(j-index+1 == v[i].second)
            {
                index = j+1;
                break;
            }
        }
    }
    int sum=0;
    for(int i=0; i<n; i++)
    {
        //cout<<arr[i]<<" ";
        sum+=arr[i];
    }
    //cout<<endl;
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeSet<Num> front = new TreeSet<>();
        TreeSet<Num> frontStock = new TreeSet<>();
        long frontSum = 0;
        TreeSet<Num> back = new TreeSet<>();
        long backSum = 0;
        Num[] arr = new Num[3 * n];
        for (int i = 0; i < 2 * n; i++) {
            arr[i] = new Num(i, sc.nextInt());
            frontSum += arr[i].value;
            front.add(arr[i]);
        }
        for (int i = 0; i < n; i++) {
            Num tmp = front.pollFirst();
            frontSum -= tmp.value;
            frontStock.add(tmp);
        }
        for (int i = 2 * n; i < 3 * n; i++) {
            arr[i] = new Num(i, sc.nextInt());
            backSum += arr[i].value;
            back.add(arr[i]);
        }
        long max = frontSum - backSum;
        for (int i = n * 2 - 1; i >= n; i--) {
            if (front.contains(arr[i])) {
                front.remove(arr[i]);
                frontSum -= arr[i].value;
                Num tmp = frontStock.pollLast();
                front.add(tmp);
                frontSum += tmp.value;
            } else {
                frontStock.remove(arr[i]);
            }
            back.add(arr[i]);
            backSum += arr[i].value;
            Num tmp = back.pollLast();
            backSum -= tmp.value;
            max = Math.max(max, frontSum - backSum);
        }
        System.out.println(max);
    }
    
    static class Num implements Comparable<Num> {
        int idx;
        int value;
        
        public Num(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int hashCode() {
            return idx;
        }
        
        public boolean equals(Object o) {
            Num n = (Num)o;
            return idx == n.idx;
        }
        
        public int compareTo(Num another) {
            if (value == another.value) {
                return idx - another.idx;
            } else {
                return value - another.value;
            }
        }
        
        public String toString() {
            return idx + ":" + value;
        }
    }
}

Measured memory_bytes: 118152
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    !n <- readLn :: IO Int
    bs <- B.filter (\c -> 'a' <= c && c <= 'z') <$> B.getContents
    print $ solve n bs

solve :: Int -> B.ByteString -> Int
solve n bs = sum [n | a<-[0..n-1], validateA a]
  where
    idx x y = x * n + y
    validateA :: Int -> Bool
    validateA a = and $ do
        i <- [0..n-1]
        j <- [i..n-1]
        return $! B.unsafeIndex bs (idx ((a + i) `rem` n) j) ==
            B.unsafeIndex bs (idx ((a + j) `rem` n) i)


Measured memory_bytes: 1276