akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> odds(n,0);
    for(int i = 0; i < n; i++){
        if((a[i] - 1) % 2 == 1)
        odds[i]++;
        if(a[i] % 2 == 1)
        odds[i]++;
        if((a[i] + 1) % 2 == 1)
        odds[i]++;
    }
    ll ans = 1;
    for(int i = 0; i < n; i++){
        ans *= 3;
    }
    ll k = 1;
    for(ll i = 0; i < n; i++){
        k *= odds[i];
    }
    cout << ans - k << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

void solve() {
    int s,w;
    cin>>s>>w;
    if(w>=s) cout<<"un";
    cout<<"safe";
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 3620
import sys,queue,math,numpy as np,scipy as sc
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
N,M = LI()
E = [LI() for _ in range(M)]
ans = 0
for i in range(M):
    g = np.array([i for i in range(N+1)])

    def root(x):
        if g[x] != x:
            g[x] = root(g[x])
        return g[x]

    for j in range(M):
        if i != j: g[root(E[j][0])] = root(E[j][1])

    ans += (root(E[i][0]) != root(E[i][1]))

print (ans)

Measured memory_bytes: 19432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

int main(){
    char a,b; cin >> a >> b;
    if(a>b){
        cout << ">" << endl;
    }else if(a==b) {
        cout << "=" << endl;
    }else {
        cout << "<" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	long long max, min, sum, n, a, i;
	cin >> n;
	max = -1000000;
	min = 1000000;
	sum =0;
	for(i = 0; i < n; i++) {
		cin >> a;
		if (a > max) 
			max = a;
		if (a < min) 
			min = a;
		sum = sum + a;
	}		
		cout << min << " " << max << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3104
H, W = map(int, input().split())
#外壁として障害物置く
H += 2
W += 2
P = [[] for _ in range(H*W)]

move = [(0, 1), (1, 0), (-1, 0), (0, -1)]

for y in range(1, H-1):
  for x in range(1, W-1):
    for z in move:
      P[x+W*y].append(x+z[0]+W*(y+z[1]))

for y in range(H-2):
  L = input()
  for x, s in enumerate(L):
    if s == "#":
      P[x+1 + W*(y+1)] = []

def bfs(x, y):
    s = x + W*y
    d = [-1] * (H*W)
    d[s] = 0
    p_old = [s]
    cnt = 1
    m_cnt = 0
    last = 1
    #print(d, p_old)
    while p_old:
      p_new = []
      for i in p_old:
        for j in P[i]:
          if d[j] == -1 and P[j] != []:
            d[j] = cnt
            m_cnt = max(m_cnt, cnt)
            p_new.append(j)
      p_old = p_new
      cnt += 1
      #print(d, p_old)
    return m_cnt

ans = 0

for y in range(1, H-1):
  for x in range(1, W-1):
    ans = max(ans, bfs(x, y))

print(ans)

Measured memory_bytes: 9292
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int ans = 0;
		ans = n % 1000;
		if (ans == 0)
			System.out.println(0);
		else
			System.out.println(1000 - ans);
	}

}


Measured memory_bytes: 35728
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}


int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

//#############################
const int MAXN = 1000005;

int main() {
    ll x;
    cin >> x;
    
    double p = 100;
    double interest = 0.01;
    ll years = 1;
    double compound = (1+interest);
    ll total = 101;
    while(total < x) {
        total += (ll)(total*0.01);
        years++;
    }

    cout << years << endl;

    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
#define INF (ll)1e18
#define s(v) v.size()
#define e(v) v.empty()

using namespace std;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
// bool sortbysec(const pll &a, const pll &b){return (a.second < b.second);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

ll dp[MAX][13];
ll mod[6] = {1, 10, 9, 12, 3, 4};
string str;
ll ans = 0;
// ll n;

ll ctoi(char x){return x-'0';}

ll getAns(ll m, ll k){
    // cout<<m<<" "<<k<<endl;
    // cout<<n<<endl;
    ll n = s(str);
    // cout<<n<<endl;
    if(dp[m][k] != -1)  return dp[m][k];
    dp[m][k] = 0;
    if(m == 0){
        if(str[n-1-m] == '?'){
            if(k < 10){
                dp[m][k] = 1;
                return 1;
            }else{
                dp[m][k] = 0;
                return 0;
            }
        }else{
            if(k == ctoi(str[n-1-m])){
                // cout<<m<<" "<<k<<endl;
                dp[m][k] = 1;
                return 1;
            }else{
                dp[m][k] = 0;
                return 0;
            }
        }
    }
    if(str[n-1-m] == '?'){
        // cout<<m<<" "<<k<<endl;
        rep(j, 10){
            ll tmp = k-j*mod[m%6];
            tmp %= 13; 
            tmp += 13;
            tmp %= 13;
            dp[m][k] += getAns(m-1, tmp);
            dp[m][k] %= MOD;
        }
    }
    else{
        ll tmp = k - ctoi(str[n-1-m])*mod[m%6];
        tmp %= 13;
        tmp += 13;
        tmp %= 13;
        dp[m][k] = getAns(m-1, tmp);
    }
    // cout<<dp[m][k]<<endl;
    return dp[m][k];
}


int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        cin>>str;
        memset(dp, -1, sizeof(dp[0][0])*MAX*13);
        ll n = s(str);
        cout<<getAns(n-1, 5);
    }
}

Measured memory_bytes: 108240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n;
ll a[200005];
ll s;
ll ans;
int main(void){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	ll m=s%2;
	s=s/2;
	//cout<<s<<" "<<m<<endl;
	for(int i=0;i<n;i++){
		if(s-a[i]>0){
			s-=a[i];
		}else{
			if(s*2+m>(a[i]-s)*2-m){
				ans=(a[i]-s)*2-m;
				//cout<<(s-a[i])*(-2)+m<<endl;
			}else{
				ans=s*2+m;
				//cout<<1<<endl;
			}
			cout<<ans<<endl;
			return 0;
		}
	}
	
	
}


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

int main(void) {
	multiset<int> S;
	int q, com, x, y;
	cin >> q;
	while (q--) {
		cin >> com;
		switch (com) {
			case 0:
				cin >> x;
				S.insert(x);
				cout << S.size() << endl;
				break;
			case 1:
				cin >> x;
				cout << S.count(x) << endl;
				break;
			case 2:
				cin >> x;
				S.erase(x);
				break;
			case 3:
				cin >> x >> y;
				set<int>::iterator it = S.lower_bound(x);
				set<int>::iterator end = S.upper_bound(y);
				while (it != end) {
					cout << *it << endl;
					it++;
				}
				break;
		}
	}
}


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

vector<vector<ll>> lis;
vector<ll> dset;
ll d=0;

void find(ll p) {
    if(dset[p] == -1 || dset[p] > d) {
        dset[p] = d;
        d++;
        for(ll i:lis[p]) {
            find(i);
        }
        d--;
    }
}

int main() {
    ll n;
    cin >> n;
    for(ll i=0;i<n;i++) {
        ll u,k;
        cin>>u>>k;
        vector<ll> aaa;
        for(ll j=0;j<k;j++) {
            ll tmp;
            cin>>tmp;
            aaa.push_back(tmp-1);
        }
        lis.push_back(aaa);
        dset.push_back(-1);
    }
    find(0);
    for(ll i=0;i<n;i++) {
        cout << i+1<<" "<<dset[i]<<endl;
    }
}



Measured memory_bytes: 3168
#include<stdio.h>

int main()
{
  char S[100],T[100];
  int N;
  int j = 0;
  int ai = 0,bi = 0;

  scanf("%d",&N);
  scanf("%s",S);
  scanf("%s",T);

  for(int i = 0;i < N*2;i++){
    if(i%2 == 0){
      printf("%c",S[ai]);
      ai++;
    }
    else if(i%2 == 1){
      printf("%c",T[bi]);
      bi++;
    }
  }

  return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

template<class T>
inline bool chmax(T &a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
};

template<class T>
inline bool chmin(T &a, T b) {
  if(a > b) {
    a = b;
    return true;
  }
  return false;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi p(n);
  vi q(n);
  vi A(n);
  rep(i, 0, n) {
    A[i] = i+1;
  }
  rep(i, 0, n) {
    cin >> p[i];
  }
  rep(i, 0, n) {
    cin >> q[i];
  }

  int cnt = 0;
  int p_, q_;

  do {
    cnt++;
    bool p_flag = true, q_flag = true;
    rep(i, 0, n) {
      if (A[i] != p[i]) {
        p_flag = false;
      }
      if (A[i] != q[i]) {
        q_flag = false;
      }
    }

    if (p_flag) {
      p_ = cnt;
    }
    if (q_flag) {
      q_ = cnt;
    }
  } while (next_permutation(All(A)));

  cout << abs(p_ - q_) << endl;

  return 0;
};


Measured memory_bytes: 256
package main

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

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - ID
	var N, M int
	fmt.Scan(&N, &M)

	var P, Y int
	input := make(map[int]int, M)
	yearSort := make([]int, M)
	year := make([]int, M)
	city := make([]int, M)

	sc.Split(bufio.ScanWords)
	for i := 0; i < M; i++ {
		P = nextInt()
		Y = nextInt()
		input[Y] = P
		yearSort[i] = Y

		year[i] = Y
		city[i] = P
	}

	ans := make(map[int]int, M)
	count := make(map[int]int, M)

	sort.Sort(sort.IntSlice(yearSort))
	for i := 0; i < M; i++ {
		count[input[yearSort[i]]]++
		ans[yearSort[i]] = count[input[yearSort[i]]]
	}

	for i := 0; i < M; i++ {
		fmt.Printf("%06d%06d\n", city[i], ans[year[i]])
	}
}


Measured memory_bytes: 14712
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;


main()
{
  int H, W;
  int mi = INF;

  cin >> H >> W;

  for(int i=1; i<=H; i++) {
    int a1 = i*W, a2 = (H-i)/2*W, a3 = (H-i-(H-i)/2)*W;
    int dif = max(a1, max(a2, a3)) - min(a1, min(a2, a3));
    
    a2 = W/2*(H-i); a3 = (W-W/2)*(H-i);
    
    dif = min(dif, max(a1, max(a2, a3)) - min(a1, min(a2, a3)));
    mi = min( mi, dif );
  }

  for(int i=1; i<=W; i++) {
    int a1 = i*H, a2 = (W-i)/2*H, a3 = (W-i-(W-i)/2)*H;
    int dif = max( a1, max( a2, a3 ) ) - min( a1, min( a2, a3 ) );
    
    a2 = H/2*(W-i); a3 = (H-H/2)*(W-i);
    
    dif = min(dif, max(a1, max(a2, a3)) - min(a1, min(a2, a3)));
    mi = min( mi, dif );
  }

  cout << mi << endl;
}


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

int main(){
  long int x,y;
  cin >> x >> y;
  if(x*y > 0){
    if((y-x)>=0){
      cout << y-x << endl;
    }else{
      cout << x-y+2 << endl;
    }
  }else if(x*y < 0){
    if((x+y) >= 0){
      cout << y+x+1 << endl;
    }else{
      cout << 1-x-y << endl;
    } 
  }else if(x == 0){
    if(y > 0){
      cout << y << endl;
    }else{
      cout << 1-y << endl;
    }
  }else{
    if(x < 0){
      cout << -x << endl;
    }else{
      cout << x+1 << endl;
    }
  }
    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    s=input()
    s=s+s[0]
    for j in range(4):
        l=[-1]*(N+2)
        for k in range(2):
            l[k]=(j>>k)&1
        for i in range(1,N+1):
            if l[i]==0:
                if s[i-1]=='o':
                    l[i+1]=l[i-1]
                else:
                    l[i+1]=int(not l[i-1])
            else:
                if s[i-1]=='o':
                    l[i+1]=int(not l[i-1])
                else:
                    l[i+1]=l[i-1]
        if l[0]==l[-2] and l[1]==l[-1]:
            for x in l[1:N+1]:
                if x==0:
                    print('S',end='')
                else:
                    print('W',end='')
            print('')
            exit()
    print(-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 56140
// AOJ 2361: Sort
// 2018.4.10 bal4u

#include <stdio.h>
#include <string.h>

#define QSIZE 600000

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

typedef struct { int s, t; } QUE;
QUE que[QSIZE+2]; int qsize;

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define INF 0x30303030
int c[8][8]; int n;
int three[9][8];
char dist[1<<24];

int main()
{
	int i, j, s, ss, ns, t, nt, a, b, bi, bj, ans;

	for (n = 1; n <= 8; n++) for (i = 0; i < n; i++) three[n][i] = 3*(n-i-1);
	n = in();
	for (i = 0; i < n; i++) for (j = 0; j < n; j++) c[i][j] = in();

	s = 0; for (i = 0; i < n; i++) s = (s << 3) | i;
	ans = 0, qsize = 0, enq(s, 0);
	while (qsize) {
		s = que[0].s, t = que[0].t, deq();
		if (dist[s]) continue;
		dist[s] = 1;
		if (t > ans) ans = t;
		for (i = 0; i < n; i++) {
			bi = three[n][i], a = (s >> bi) & 7;
			ss = s ^ (a << bi);
			for (j = i+1; j < n; j++) {
				bj = three[n][j], b = ((s >> bj) & 7);
				ns = (ss ^ (b << bj)) | (b << bi) | (a << bj);
				nt = t + c[i][j];
				if (dist[ns]) continue;
				enq(ns, nt);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}



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

#define int long long
#define double long double

using namespace std;

#define REP(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) REP(i, 0, n)
#define PER(i, a, b) for (int(i) = (a - 1); i >= (b); (i)--)
#define per(i, n) PER(i, n, 0)
#define each(i, n) for (auto &i : n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define dum(val) cerr << #val " = " << val;
#define dump(val) cerr << #val " = " << val << endl;
#define FILL(a, v) fill(a, a + sizeof(a) / sizeof(*a), v)

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const int mod = 1e9 + 7;
const int INF = 1e9;

signed main() {
	int N;
	cin >> N;

	REP(h, 1, 3501)
	REP(n, 1, 3501) {
		// 4 h n w - N n w - N h w - N n h = 0
		// w (4 h n - N n - N h) = N n h
		// w = N n h / (4 h n - N n - N h)
		int l = (N * n * h);
		int r = (4 * h * n - N * n - N * h);

		if (l && r && l % r == 0) {
			int w = l / r;
			if (w <= 0) continue;
			cout << h << " " << n << " " << w << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

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

		Dice d = new Dice(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
		char[] cmd = sc.next().toCharArray();
		
		for (int i = 0; i < cmd.length; i++) {
			if (cmd[i] == 'N') {
				d.N();
			} else if (cmd[i] == 'S') {
				d.S();
			} else if (cmd[i] == 'E') {
				d.E();
			} else if (cmd[i] == 'W') {
				d.W();
			}
		}

		System.out.println(d.now());

		sc.close();
	}
	
	private static class Dice {
		int[] s;
		int up;
		int north;
		int east;

		Dice(int s1, int s2, int s3, int s4, int s5, int s6) {
			s = new int[6];
			s[0] = s1;
			s[1] = s2;
			s[2] = s3;
			s[3] = s4;
			s[4] = s5;
			s[5] = s6;
			up = 1;
			north = 5;
			east = 3;
		}
		
		void N() {
			int temp = 7 - north;
			north = up;
			up = temp;
		}
		
		void S() {
			int temp = 7 - up;
			up = north;
			north = temp;
		}
		
		void E() {
			int temp = 7 - east;
			east = up;
			up = temp;
		}

		void W() {
			int temp = 7 - up;
			up = east;
			east = temp;
		}
		
		int now() {
			return s[up - 1];
		}
	}
}

Measured memory_bytes: 17340
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
ll n,k,a[N],vis[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>k;
    for(ll i=1;i<=n;i++)cin>>a[i];
    ll s=1;
    for(;!vis[s];s=a[s])vis[s]=1;
    for(ll i=1;i<=n;i++)vis[i]=0;
    ll len = 0;
    for(ll cur=s;!vis[cur];cur=a[cur],len++)vis[cur]=1;
    ll init = 0;
    for(ll cur=1;cur!=s;cur=a[cur],init++);
   // cout<<"S: "<<s<<" LEN: "<<len<<" INIT: "<<init<<endl;

    if(k<=init){
        ll cur=1;
        for(;k>0;k--,cur=a[cur]);
        cout<<cur;
        return 0;
    }
    k-=init;

    k%=len;
    for(;k>0;k--,s=a[s]);
    cout<<s;
}


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

#define long long ll
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
typedef pair<int,int>P;


int main(){
	
	string s;
	int K;
	cin>>s;
	cin>>K;
	
	for(int i=0;i<s.size();i++){
		if(i+1==s.size()){
			K%=26;
			for(;K>0;K--){
				if(s[i]=='z')s[i]='a';
				else s[i]++;
			}
		}
		else if(s[i]=='a'){
			
		}
		else if(K>=26-(s[i]-'a')){
			K=K-(26-(s[i]-'a'));
			s[i]='a';
			
			
		}
	}
	
	cout<<s<<endl;
	
	
	
	return 0;
}


Measured memory_bytes: 640
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return true;}return false;}

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(s);
  REP(i,s.size()){
    if(s[i]=='A') {x = i;break;}
  }
  for(int i = s.size()-1; i >= 0; i--){
    if(s[i]=='Z') {y = i;break;}
  }
  OUT(y-x+1);
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> > 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	string s, t;
	cin >> s >> t;
	int x = s[0] - '0';
	int y = t[0] - '0';
	string x1 = "", y1 = "";
	while(y--){
		x1 += s;
	}
	while(x--){
		y1 += t;
	}
	if(x1 < y1)
	cout << x1;
	else
	cout << y1;
}

Measured memory_bytes: 256
import collections

h,w=map(int,input().split())
checked=[[0]*(w+2) for _ in range(h+2)]
board=[['#']*(w+2)]
for _ in range(h):
  board.append(['#']+list(input())+['#'])
board.append(['#']*(w+2))
q=collections.deque()
q.append((1,1,1))
checked[1][1]=1
ans=-1
while 1:
  if len(q)==0:
    break
  x,y,t=q.popleft()
  if x==w and y==h:
    ans=t
    break
  if board[y][x-1]=='.' and checked[y][x-1]==0:
    checked[y][x-1]=1
    q.append((x-1,y,t+1))
  if board[y][x+1]=='.' and checked[y][x+1]==0:
    checked[y][x+1]=1
    q.append((x+1,y,t+1))
  if board[y-1][x]=='.' and checked[y-1][x]==0:
    checked[y-1][x]=1
    q.append((x,y-1,t+1))
  if board[y+1][x]=='.' and checked[y+1][x]==0:
    checked[y+1][x]=1
    q.append((x,y+1,t+1))
if ans==-1:
  print(-1)
else:
  cnt=0
  for i in range(1,h+1):
    cnt+=board[i].count('#')-2
  print(h*w-cnt-ans)

Measured memory_bytes: 3316
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[1000010];
int main()
{
    int i,j,k,n;
    scanf("%s%d",a,&n);
    k=strlen(a);
    for(i=0;i<k;i=i+n)
        printf("%c",a[i]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  private static int x, y;
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    while (true) {
      y = stdIn.nextInt();
      x = stdIn.nextInt();
      if (x == 0 && y == 0) {
        break;
      }
      for (int i = 0;i < y; i++) {
        for (int j =0;j < x; j++) {
          System.out.print("#");
        }
        System.out.println("");
      }
      System.out.println("");
    }
  }
}

Measured memory_bytes: 32600
#include<stdio.h>

int main(){
int n,i,j,d[100];scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&d[i]);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(d[i]<d[j]){
int tmp=d[i];
d[i]=d[j];
d[j]=tmp;
}
}
}
int ans=1;
for(i=1;i<n;i++){
if(d[i]!=d[i-1])ans++;
}
printf("%d\n",ans);
return 0;
}

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

using namespace std;

typedef pair<int,int> PA;
typedef pair<int,PA> P;

int cho,che;
char table[8][8];
vector<P> v;

const int dx[8] = {0,0,1,1,1,-1,-1,-1};
const int dy[8] = {1,-1,0,-1,1,-1,0,1};
const char ch[3] = {'x','o'};

void check(int x,int y,int turn,vector<P> &v){
  char c = ch[turn],d = ch[1-turn];
  int count = 0;

  for(int i = 0 ; i < 8 ; i++){
    int cnt = 0;
    int nx = x + dx[i];
    int ny = y + dy[i];

    while(true){
      if(0 > nx || 0 > ny || nx >= 8 || ny >= 8){
	break;
      }
      if(table[nx][ny] != d){
	if(table[nx][ny] == c){
	  count += cnt;
	}
	break;
      }

      cnt++;
      nx += dx[i];
      ny += dy[i];
    }
  }   

  if(count == 0){
    return;
  }

  if(turn){
    v.push_back(P(-count,PA(x,y)));
  }else{
    v.push_back(P(-count,PA(-x,-y)));
  }
}

void change(P a,int turn){
  char c = ch[turn],d = ch[1-turn];

  a.first = -a.first;

  if(!turn){
    a.second.first = -a.second.first;
    a.second.second = -a.second.second;
  }

  table[a.second.first][a.second.second] = c;

  for(int i = 0 ; i < 8 ; i++){
    int nx = a.second.first + dx[i];
    int ny = a.second.second + dy[i];
    vector<PA> v;

    while(true){
      if(0 > nx || 0 > ny || nx >= 8 || ny >= 8){
	break;
      }
      if(table[nx][ny] != d){
	break;
      }

      v.push_back(PA(nx,ny));
      nx += dx[i];
      ny += dy[i];
    }

    if(!(0 > nx || 0 > ny || nx >= 8 || ny >= 8) && table[nx][ny] == c){
      while(true){     
	if(nx == a.second.first && ny == a.second.second){
	  break;
	}
	table[nx][ny] = c;  
	nx -= dx[i];
	ny -= dy[i];
      }
    }

  } 

  if(turn){
    cho += a.first+1;
    che -= a.first;
  }else{
    cho -= a.first;
    che += a.first+1;
  }
}

int main(){
  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      cin >> table[i][j];

      if(table[i][j] == 'o'){
	cho++;
      }else if(table[i][j] == 'x'){
	che++;
      }
    }
  }

  //true mami ------ false witch
  bool turn = true;
  int pass = 0;

  while(true){
    vector<P> v;
 
    if(pass == 2 || !cho || !che || cho+che == 64){
      break;
    }
 
    for(int i = 0 ; i < 8 ; i++){
      for(int j = 0 ; j < 8 ; j++){
	if(table[i][j] == '.'){
	  int n = turn ? 1 : 0;
	  check(i,j,n,v);
	}
      }
    }  

    int size = (int)v.size();

    if(size == 0){
      pass++;
    }else{
      pass = 0;
      int n = turn ? 1 : 0;
      sort(v.begin(),v.end());
      change(v[0],n);
    }

    turn = !turn;
  }

  for(int i = 0 ; i < 8 ; i++){
    for(int j = 0 ; j < 8 ; j++){
      cout << table[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<cmath>
#include<cstring>

using namespace std;

void swap(int i,int j, int *a){
    int temp = a[i];
    a[i] = a[j];
    a[j] = temp;
}

void quicksort(int *arr, int left, int right){
    int min = (left+right)/2;
    //cout<<"QS:"<<left<<","<<right<<"\n";

    int i = left;
    int j = right;
    int pivot = arr[min];

    while(left<j || i<right)
    {
        while(arr[i]<pivot)
        i++;
        while(arr[j]>pivot)
        j--;

        if(i<=j){
            swap(i,j,arr);
            i++;
            j--;
        }
        else{
            if(left<j)
                quicksort(arr, left, j);
            if(i<right)
                quicksort(arr,i,right);
            return;
        }
    }
}

int main()
{
	int n;
	cin>>n;
	int i;
	int ary[n];
	for(i=0;i<n;i++)
	{
		cin>>ary[i];
	}
	
    quicksort(ary, 0, (sizeof(ary)/sizeof(ary[0]))-1);
    
   
	unsigned long count=1;
	int top=n-1,f=1;
	for(i=n-1;i>0;)
	{
		if(ary[i]==top&&ary[i-1]==top)
		{
			count*=2;
			count=count%1000000007;
			i-=2;
			top-=2;
		}
		else 
		{
			f=0;
			break;
		}
	}
	if(f==0)cout<<"0\n";
	else cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
  long long L[87], N;
  
  scanf("%lld", &N);
  
  L[0] = 2;
  L[1] = 1;
  for (int i = 2; i <= N; i++){
    L[i] = L[i - 1] + L[i - 2];
  }
  
  printf("%lld\n", L[N]);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MD=int(1e9)+7;
int const MAXN=110000;
int N,M;
int a[MAXN];

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	cin>>N>>M;
	rep(i,0,M) {
		int x;
		cin>>x;
		a[x]=-1;
	}

	a[0]=1;
	rep(i,0,N) if (a[i]!=-1) {
		if (a[i+1]!=-1) a[i+1]=(a[i]+a[i+1])%MD;
		if (a[i+2]!=-1) a[i+2]=(a[i]+a[i+2])%MD;
	}
	cout<<a[N]<<"\n";
}


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

int main(){
    int N;  cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++)
        cin >> A[i];

    ll ans = 0;
    ll MOD = 1e9 + 7;
    ll base = 1;
    for(int i=0; i<80; i++){
        ll zero = 0;
        ll one = 0;
        for(int n=0; n<N; n++){
            if(A[n]%2 == 0) zero++;
            if(A[n]%2 == 1) one++;
            A[n]/=2;
        }

        ll add = (base * zero)%MOD;
        add = (add * one)%MOD;
        ans = (ans + add)%MOD;
        base = (base * 2)%MOD;
    }
    cout << ans << endl;
}


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

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize ("-ffloat-store")

#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"

#define sz(a) ( (int) (a).size() )
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for(auto (it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end()) //
#define cpres(c, val) (find(all(c), val) != (c).end()) //

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define forf(i, a, b) for(int i = (a); i < (b); i++)
#define forb(i, a, b) for(int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n-1)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;

const int INF = 0xFFFFFFFFFFFFFFFL;
const int N = 1e9 + 7;

const auto start_time = std::chrono::high_resolution_clock::now();

void zark() {
    #ifdef ZARK
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time - start_time;
    cerr << "Time Taken : " << diff.count() << "s\n";
    #endif
}

#ifdef ZARK
#include "/home/aranjan/Desktop/CP/header.h"
#else
#define dbg(args...)
#endif

void solve() {
    int h, w, k;
    cin >> h >> w >> k;
    int s[11][1001];
    fo(i,h) {
        string S;
        cin >> S;
        fo(j, w) s[i][j] = S[j] - '0';
    }
    int min = INF;
    fo(t, 1<<(h-1)) {
        vi bin;
        for(int num = t; num != 0; num/=2) bin.pb(num%2);
        bin.resize(h-1);
        int ka = __builtin_popcount(t) + 1;
        map<int, pii > lim;
        int a=0;
        lim[0].F = 0;
        fo(i, h) {
            if(i>0 && bin[i-1]) {
                a++;
                lim[a-1].S = i-1;
                lim[a].F = i;
            }
        }
        lim[a].S = h-1;
        vi sum(ka), col(w-1);
        bool f2 = 0;
        fo(j, w) {
            fo(l, ka) {
                forf(i, lim[l].F, lim[l].S + 1) sum[l] += s[i][j];
            }
            bool f = 0;
            fo(l, ka) if(sum[l] > k) {f = 1; break;}
            if(f) {
                fo(l, ka) sum[l] = 0;
                if(j==0) {f2 = 1; break;}
                col[j-1] = 1;
                fo(l, ka) {
                    forf(i, lim[l].F, lim[l].S + 1) sum[l] += s[i][j];
                    if(sum[l] > k) {f2 = 1; break;}
                }
            }
        }
        if(f2) continue;
        int sm = ka-1;
        fo(i,w-1) sm+=col[i]; 
        if(sm < min) min = sm;
    }
    cout << min << endl;
}

int32_t main(int32_t argc, char** argv) {
    fastio;
    #ifdef ZARK
    freopen("input.in", "r", stdin);
    #endif
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
    // cout << fixed << setprecision(35);
    solve();
    zark();
    return 0;
}


Measured memory_bytes: 384
MAX = 2*10**5+1
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

dp = []*(n+1)
l = [-1]*MAX
dp[n] = -1
(n-1).downto(0) do |i|
  v = a[i]
  if l[v] == -1
    dp[i] = i
  else
    dp[i] = dp[l[v]+1]
  end
  l[v] = i
end

s = dp[0]
visited = [false]*MAX
list = []
while s != -1 && !visited[s]
  visited[s] = true
  list << s
  s = dp[l[a[s]]+1]
end
list.unshift(-1) if s == -1
t = list[k % list.length]
ans = []
exit if t == -1
pos = [-1]*MAX
t.upto(n-1) do |i|
  v = a[i]
  if pos[v] != -1
    (ans.length-pos[v]).times do
      pos[ans[-1]] = -1
      ans.pop
    end
  else
    pos[v] = ans.length
    ans << v
  end
end
#p dp
#p l
#p t
puts ans.join(" ")

Measured memory_bytes: 31820
n,t = map(int,input().split())

ans = -1
cst = 10**5
for i in range(n):
    c,tm = map(int,input().split())
    if tm <= t and c <cst:
        cst = c
        ans = c

if ans == -1:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3060
#![allow(unused_imports)]
use num::integer::gcd;
use proconio::*;
use std::cmp::*;
use std::collections::VecDeque;
use std::ops::*;
use std::mem::swap;

fn main() {
   input! {
      s: String,
   }

   let v = s.as_bytes();
   let n = s.len();
   let mut dp = vec![0;2019];
   let mut ans = 0;
   for i in 0..n {
      let mut dp1 = vec![0;2019];
      let a = (v[i] as usize) - 48;
      dp1[a] += 1;
      for j in 0..2019 {
         let x = (j*10 + a) % 2019;
         dp1[x] += dp[j];
      }
      ans += dp1[0];
      swap(&mut dp, &mut dp1);
   }
   println!("{}", ans);
}


Measured memory_bytes: 2448
from collections import deque

N, D, A = map(int, input().split())
XH = [tuple(map(int, input().split())) for _ in range(N)]
XH.sort()

ans = 0
cnt = 0
que = deque()

for x, h in XH:
    while que and que[0][0] <= x:
        cnt -= que.popleft()[1]

    h -= cnt * A

    if h <= 0:
        continue

    ness = -(-h // A)
    cnt += ness
    ans += ness
    que.append((x + 2 * D + 1, ness))

print(ans)


Measured memory_bytes: 44624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"

int mod( int m ,int mod) {
   m %= mod;
   return (m + mod) % mod;
}

int power(int x,int y,int md) {
   int res = 1;
   x = mod(x,md);
   while (y > 0) {
      if (y & 1)
         res =mod(res * x,md);
      y = y / 2;
      x = mod(x * x,md);
   }
   return mod(res,md);
}
	
int curnum(vector<int>&v,int md){
	int ans = 0;
	for(int &i:v)
		ans = mod(ans + power(2,i,md),md);
	return ans;
}

int32_t main() {
	boost;
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;

	/*int tmp = 0;
	for(int i= n- 1;i >= 0; i--) {
		if(s[i] == '1')
			tmp |= (1 << (n - i - 1));
	}*/

	vector<int> v;
	

	for(int i = 0;i<n;i++){
		if(s[i] == '1'){
			cnt++;
			v.push_back(n - i - 1);
		}
	}

	if(cnt == 0) {
		for(int i=1;i<=n;i++){
			cout << 1 << endl;
		}
		return 0;
	}

	int c1 = 0,c2 = 0;
	for(int &i : v){
		c1 = mod(c1 + power(2,i,cnt+1),cnt+1);
		if(cnt > 1)
			c2 = mod(c2 + power(2,i,cnt-1),cnt-1);
	}

	for(int i = 0; i < n; i++) {
		int tt;
		if(s[i] == '1') {
			cnt--;
			if(cnt == 0){
				cnt++;
				cout << 0 << endl;
				continue;
			}
			tt = mod(c2 - power(2,n -i - 1,cnt),cnt);  
			cnt++;
		}
		else{
			cnt++;
			tt = mod(c1 + power(2,n -i - 1,cnt),cnt);
			cnt--;
		}

		int ans = 1;
		while(tt > 0) {
			int tmp = __builtin_popcount(tt);
			tt %= tmp;
			ans++;
		}
		cout << ans << endl;
	}
}



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


def solve(N: int, A: "List[int]"):
    Ap = copy.copy(A)

    A.sort()
    maxA = A[-1]
    A2 = A[-2]

    if maxA == A2:
        for _ in range(N):
            print(maxA)
    else:
        for a in Ap:
            if a == maxA:
                print(A2)
            else:
                print(maxA)
    return


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

if __name__ == '__main__':
    main()

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
#define MAX_N 100000

vll d(MAX_N, LLINF);
struct edge{
  ll cost, to;
  edge(ll t, ll c){
    cost = c;
    to = t;
  }
};


void dijkstra(ll s, vector<vector<edge>> e){
  priority_queue<pll, vector<pll>, greater<pll>> que;
  d[s] = 0;
  que.push(pll(0, s));

  while(!que.empty()){
    pll p = que.top();
    que.pop();
    ll v = p.SE;
    if(d[v] < p.FI)
      continue;
    for(ll i = 0; i < e[v].size(); i++){
      edge g = e[v][i];
      if(d[g.to] > d[v] + g.cost){
        d[g.to] = d[v] + g.cost;
        que.push(pll(d[g.to], g.to));
      }
    }

  }
}

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

  ll n,m;
  cin >> n >> m;
  vector<pair<ll, pll>> clr(m);
  REP(i, m){
    cin >> clr[i].SE.FI >> clr[i].SE.SE >> clr[i].FI;
    clr[i].SE.FI--;
    clr[i].SE.SE--;
  }
  sort(clr.begin(), clr.end());

  //to, cost
  vector<vector<edge>> e(n);
  REP(i, m){
    ll l = clr[i].SE.FI;
    ll r = clr[i].SE.SE;
    ll c = clr[i].FI;

    e[l].push_back(edge(r, c));
  }

  REP1(i, n){
    e[i].push_back(edge(i-1, 0));
  }

  dijkstra(0, e);
  if(d[n-1] == LLINF)
    cout << -1 << endl;
  else
    cout << d[n-1] << endl;

}


Measured memory_bytes: 18300
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int n = s.size() - 2;
	cout << s.at(0) << n << s.at(n + 1) << endl;
}

Measured memory_bytes: 3580
import collections


class UnionFind():
    def __init__(self, N):
        self.rank = [0] * N
        self.par = [i for i in range(N)]

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def same(self, x, y):
        return self.root(x) == self.root(y)


N, K, L = map(int, input().split())
graph_road = UnionFind(N)
graph_train = UnionFind(N)
for k in range(K):
    p, q = map(int, input().split())
    graph_road.unite(p-1, q-1)

for l in range(L):
    r, s = map(int, input().split())
    graph_train.unite(r-1, s-1)

pair = collections.defaultdict(int)
for i in range(N):
    road = graph_road.root(i)
    train = graph_train.root(i)
    pair[(road, train)] += 1

for i in range(N):
    road = graph_road.root(i)
    train = graph_train.root(i)
    print(pair[(road, train)])

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(begin(a), end(a));
    for(int i = 0;i < n;i++){
        cout << a[i].second + 1 << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#define MAX_V 1000
#define MAX_E 2000
#define INF 1e9
using namespace std;
struct edge {
	int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;



bool find_negative_loop(int s)
{
	d[s] = 0;
	int count = 0;
	while (true)
	{
		bool update = false;
		count++;
		for (int i = 0; i < MAX_E; i++)
		{
			
			if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost)
			{
				if (count == V)
				{
					return true;
				}
				d[es[i].to] = d[es[i].from] + es[i].cost;
				update = true;
			}
		}
		if (update == false)
		{
			break;
		}


	}
	return false;
}

int main()
{
	
	int r;
	cin >> V>>E>>r;
	for (int i = 0; i < MAX_V; i++)
	{
		d[i] = INF;
	}
	for (int i = 0; i < E; i++)
	{
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	if (find_negative_loop(r))
	{
		cout << "NEGATIVE CYCLE" << endl;
	}
	else
	{
		for (int i = 0; i < V; i++)
		{
			if (d[i] == INF)
			{
				cout << "INF" << endl;
			}
			else
			{
				cout << d[i] << endl;
			}
		}
	}

	return 0;
}





Measured memory_bytes: 3112