akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <utility>
#include <cmath>
using namespace std;

typedef pair<int,int> pii;
const int N = 100006;

pii p[N];

int dis(pii a,pii b)
{
    return abs(a.first - b.first) + abs(a.second - b.second);
}

int pre[N];

int main ()
{
    int n,m,d;
    scanf("%d %d %d",&n,&m,&d);
    for (int i=1;n>=i;i++)
    {
        for (int j=1;m>=j;j++)
        {
            int x;
            scanf("%d",&x);
            p[x] = make_pair(i,j);
        }
    }
    for (int i=d+1;n*m>=i;i++)
    {
        pre[i] = pre[i-d] + dis(p[i],p[i-d]);
    }
    int q;
    scanf("%d",&q);
    while (q--)
    {
        int l,r;
        scanf("%d %d",&l,&r);
        printf("%d\n",pre[r]-pre[l]);
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD =1000000007;//1e9 + 7;

int main(){
    bool so[101010]={};
    for(int i=4;i<100100;i+=2){
        so[i]=1;
    }
    for(int i=3;i<=100100;i+=2){
        if(so[i])continue;
        int c=i*2;
        while(c+i<=100100){
            so[i+c]=1;
            c+=i*2;
        }
    }
    ll x;
    cin>>x;
    REP(i,x,102001){
        if(!so[i]){
            cout<<i<<endl;
            break;
        }
    }
}

Measured memory_bytes: 384
A,B,C,D=map(int,input().strip().split())

if A%C==0:
    c=B//C-A//C+1
else:
    c=B//C-A//C

if A%D==0:
    d=B//D-A//D+1
else:
    d=B//D-A//D

def gcd(C,D):
    a=min([C,D])
    b=max([C,D])
    tmp=a
    a=b%a
    b=tmp
    if a==0:
        return tmp
    else:
        return gcd(a,b)

CD=C*D//gcd(C,D)
if A%CD==0:
    cd=B//CD-A//CD+1
else:
    cd=B//CD-A//CD

print((B-A+1-c-d+cd))

Measured memory_bytes: 9156
import sys
#input = sys.stdin.buffer.readline

def main():
    N = input()
    K = int(input())
    
    dp = [[0]*4 for _ in range(2)]
    dp[1][0] = 1
    
    for st in N:
        num = int(st)
        use = [[0]*4 for _ in range(2)]
        if num == 0:
            for i in range(4):
                use[0][i] += dp[0][i]
                use[1][i] += dp[1][i]
                if i != 3:
                    use[0][i+1] += dp[0][i]*9
        else:
            for i in range(4):
                use[0][i] += dp[0][i]+dp[1][i]
                if i != 3:
                    use[1][i+1] += dp[1][i]
                    use[0][i+1] += dp[0][i]*9
                    use[0][i+1] += dp[1][i]*(num-1)
        dp = use
    
    print(dp[0][K]+dp[1][K])

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n;
	cin >> n;
	vi a(n);
	Foz(i, n) cin >> a[i];
	int ans = 1, mn = a[0];
	For(i, 1, n) {
		ans += (a[i] < mn);
		ckmin(mn, a[i]);
	}
	cout << ans << '\n';
}



Measured memory_bytes: 1024
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int maxi = n;
    int mini = 1;
    rep(i, n - 1) if(a[i] >= a[i + 1]) mini++;
    cout << mini << '\n' << maxi << '\n';

}



Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define INF 1000000

int main() {
    int n;
    cin >> n;
    int x[n];
    for (auto &xi:x) cin >> xi;
    int ans = INF;
    for (int p = 1; p <= 100; p++) {
        int sum = 0;
        for (auto &xi:x) sum += (xi - p) * (xi - p);
        ans = min(ans, sum);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long


int a, b, ans;
int cnt[5];


int main(){

	cin >> a >> b;

	for (int i = a; i <= b; i++){
		int c = i;
		int x = 0;
		while (x < 5){
			cnt[x] = c % 10;
			c /= 10;
			x++;
		}
		if (cnt[0] == cnt[4] && cnt[1] == cnt[3])ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class345
    {
        static void Main()
        {
            var K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            if (S.Length <= K)
            {
                Console.WriteLine(S);return;
            }
            else
            {
                string ans = S.Substring(0,K);
                ans += "...";
                Console.WriteLine(ans);
            }
        }
    }
}


Measured memory_bytes: 27480
#include<cstdio>
#include<cmath>
using namespace std;
int ans,now,a[5];
int main()
{
	for (int i=1; i<=3; i++)
		scanf("%d",&a[i]);
	ans=10000;
	for (int i=1; i<=3; i++)
		for (int j=1; j<=3; j++)
			for (int k=1; k<=3; k++)
				if (i!=j && j!=k && k!=i)
				{
					now=abs(a[i]-a[j])+abs(a[j]-a[k]);
					if (now<ans) ans=now;
				}
	printf("%d",ans);
}

Measured memory_bytes: 128
def d():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    # print('A = {}'.format(A))
    warps = [1]
    w = {}

    for i in range(K):
        city = A[warps[-1] - 1]
        # print('city, warps = {}, {}'.format(city, warps))
        if city in w:
            lsi = warps.index(city)
            Kn = (K - lsi) % (len(warps) - lsi)
            print(warps[lsi + Kn])
            return
        else:
            warps.append(city)
            w[city] = city
    print(warps[-1])


def dd():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    v = []
    w = {}
    now = 0
    for i in range(K):
        print('i, v, w, now = {}, {}, {}, {}'.format(i, v, w, now))
        p = A[now]
        now = p-1
        if p in w:
            j = v.index(p)
            df = i-j
            Kn = (K-i-1) % df
            p = v[j+Kn]
            break
        else:
            v.append(p)
            w[p] = p
    print(p)


##########
if __name__ == "__main__":
    d()


Measured memory_bytes: 32256
n = gets.to_i
queue = Queue.new
queue << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9

for i in 1..n do
  x = queue.pop
  if x % 10 != 0
    queue << 10 * x + x % 10 - 1
  end
  queue << 10 * x + x % 10
  if x % 10 != 9
    queue << 10 * x + x % 10 + 1
  end
end

puts x


Measured memory_bytes: 3784
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int n1,t;
int main()
{
	string c;
	int len,f=1;
	cin>>c;
 	len=c.length();
 	for(int i=0;i<len;i++)
  	{
  		if(c[i]!='A' && c[i]!='C')
			if(isupper(c[i]))
				f=0;
	}
	int count=0;
	for(int i=2;i<len-1;i++)
   		if(c[i]=='C')  
		   	count++;
	if(count!=1)
		f=0;
	if(c[0]!='A')
		f=0;
	if(f==1)
		cout<<"AC"<<endl;
	else
		cout<<"WA"<<endl;
  	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int n;
	int i,m,e,j;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%d%d%d",&m,&e,&j);
			if(m==100||e==100||j==100){
				printf("A\n");
			}else if(m+e>=180){
				printf("A\n");
			}else if(m+e+j>=240){
				printf("A\n");
			}else if(m+e+j>=210){
				printf("B\n");
			}else if(m+e+j>=150&&(m>=80||e>=80)){
				printf("B\n");
			}else{
				printf("C\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2512
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;

const LL INF=1<<30;
const LL MOD=1000000007;




int main(){
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    cout<<h*w-a*w-b*h+a*b<<endl;
}



Measured memory_bytes: 256
N=gets.to_i
h=gets.chomp.split.map(&:to_i)
ans = 0
flag = false
100.times do 
  0.upto(N-1) do |i|
    if h[i] > 0
      h[i] -= 1
      if flag == false
        flag = true
        ans += 1
      end
    else
      flag = false
    end
  end
  flag = false
end
puts ans

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

#define MAX 25
#define NIL -1

struct node{
  int parent, left, right;
};

node T[MAX];
int  n, D[MAX], H[MAX];

void insert(){
  int i;
  
  for(i=0; i<n; i++) T[i].parent=T[i].left=T[i].right=NIL;

  for(i=0; i<n; i++){
    int id;
    scanf("%d", &id);
    scanf("%d %d", &T[id].left, &T[id].right);

    T[T[id].right].parent=T[T[id].left].parent=id;
  }
}

void print(int i){
  int sibling;
  
  printf("node %d: parent = %d, ", i, T[i].parent);

  if(T[i].parent == NIL) printf("sibling = %d, ", NIL);
  else{
    if(T[T[i].parent].left != i) printf("sibling = %d, ", T[T[i].parent].left);
    else printf("sibling = %d, ", T[T[i].parent].right);
  }

  if(T[i].left != NIL && T[i].right != NIL) printf("degree = 2, depth = %d, height = %d, ", D[i], H[i]);
  else if(T[i].left == NIL && T[i].right == NIL) printf("degree = 0, depth = %d, height = %d, ", D[i], H[i]);
  else printf("degree = 1, depth = %d, height = %d, ", D[i], H[i]);

  if(T[i].parent == NIL) printf("root\n");
  else if(T[i].left == NIL && T[i].right == NIL) printf("leaf\n");
  else printf("internal node\n");
}

void setD(int i, int d){
  D[i]=d;
  if(T[i].left != NIL) setD(T[i].left, d+1);
  if(T[i].right != NIL) setD(T[i].right, d+1);
}

int setH(int i){
  int h1=0, h2=0;

  if(T[i].left != NIL) h1=setH(T[i].left)+1;
  if(T[i].right != NIL) h2=setH(T[i].right)+1;
  
  return H[i]=max(h1, h2);
}

int main(void){
  int i, root;
  
  scanf("%d", &n);
  insert();
  for(i=0; i<n; i++){
    if(T[i].parent == NIL){
      root=i;
      break;
    }
  }
  
  setD(root, 0);
  setH(root);
  
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 3212
#include<stdio.h>
int n,i,p,c,ans=0;
int a[100000];
int x[100000];
int y[100000];

int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    x[i]=-1;
    y[i]=-1;
  }
  for(i=0;i<n;i++){
    p=i;
    c=0;
    while(x[p]==-1){
      x[p]=c++;
      y[p]=i;
      p=(p+a[p])%n;
    }
    if(y[p]==i)ans+=(c-x[p]);
  }
  printf("%d\n",ans);
  return 0;
}

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

int main(void){
int N,cnt = 0;
std::cin >> N;
std::vector<int> v(N),c(N);

for(int i=0;i<N;i++) 
std::cin >> v[i];

for(int i=0;i<N;i++) 
std::cin >> c[i];

//入力終わり

for(int i=0;i<N;i++) {
if(v[i]-c[i] > 0)
cnt+=v[i]-c[i];
}

cout << cnt;
return 0;
}

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

int main (){
    string S;
  cin>>S;
    for(int i=0;i<5;i++){
        cout<<S.at(i);
    }
    cout<<" ";
    for(int i=0;i<7;i++){
        cout<<S.at(6+i);
    }
    cout<<" ";
    for(int i=0;i<5;i++){
        cout<<S.at(14+i);
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int ans = 700;
  for(int i =0 ;i < 3;i++){
    if(s.at(i) == 'o') ans += 100;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 30;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int x, a, b;

int main()
{
	cin >> x >> a >> b;

	if (abs(x - a) < abs(x - b)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}

	return 0;
}


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

struct state {
  int node;
  int ticket;
  int cost;
  state(int n, int t, int c) : node(n), ticket(t), cost(c) {}
  bool operator<(const state& s) const
  {
    return cost > s.cost;
  }
};

int main()
{
  int c, n, m, s, d;
  while (cin >> c >> n >> m >> s >> d && c != 0) {
    --s;  --d;
    vector<vector<pair<int,int> > > g(n);
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      --a;  --b;
      g[a].push_back(make_pair(b, f));
      g[b].push_back(make_pair(a, f));
    }

    priority_queue<state> q;
    q.push(state(s, c, 0));
    vector<vector<int> > city(n, vector<int>(c+1, 1000000));
    city[s][c] = 0;
    while (!q.empty()) {
      const state s = q.top();
      q.pop();
      if (s.node == d) {
        cout << s.cost << endl;
        break;
      }

      city[s.node][s.ticket] = s.cost;
      for (vector<pair<int,int> >::const_iterator it(g[s.node].begin()); it != g[s.node].end(); ++it) {
        const int next = it->first;
        const int cost = s.cost + it->second;
        if (cost < city[next][s.ticket]) {
          city[next][s.ticket] = cost;
          q.push(state(next, s.ticket, cost));
        }
        if (s.ticket > 0) {
          const int cost2 = s.cost + it->second/2;
          if (cost2 < city[next][s.ticket-1]) {
            city[next][s.ticket-1] = cost2;
            q.push(state(next, s.ticket-1, cost2));
          }
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if(s==u) a--;
    else b--;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
/*
	Author: Ritik Patel
*/
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
// #define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
// #pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#include <bits/stdc++.h>
using namespace std;
 
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
//find_by_order()->returns an iterator to the k-th largest element(0-based indexing)
//order_of_key()->Number of items that are strictly smaller than our item
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define int long long int
// #define ll long long int
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
// #define ld long double
// const ld PI  = 3.141592;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&


void solve(){
    int N; cin >> N;
    vector<int> A(N + 1);
    int cnt = 0;
    for(int i = 1; i <= N; ++i){
        cin >> A[i];
        if((i&1) and (A[i]&1)){
            ++cnt;
        }
    }
    cout << cnt << '\n';
}
 
 
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    // cin >> T;
    for(int i = 1; i <= T; ++i){
        // brute();
        solve();
    }
    return 0;
}
 
/*
Sample inp
*/

Measured memory_bytes: 3648
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 入力

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();

		// 判定
		int sum = 0;
		for(int i = 0; i < k; i++){
			if(a > 0){
				sum +=1;
				a -= 1;
			}else if(b > 0) {
				b -= 1;
			}else if(c > 0) {
				sum -=1;
				c -= 1;
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 35924
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/18  Problem: ABC 079 D / Link: http://abc079.contest.atcoder.jp/tasks/abc079_d  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL H,W;

LL ans = 0LL;





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

	cin >> H>>W;
	VVI d(10, VI(10, 0));
	FOR(i, 0, 10) {
		FOR(j, 0, 10) {
			cin >> d[i][j];
		}
	}int V = 10;
	FOR(k, 0, V) {
		FOR(i, 0, V) {
			if (d[i][k] == LINF)continue;
			FOR(j, 0, V) {
				if (d[k][j] == LINF)continue;
				if (d[i][j] > d[i][k] + d[k][j]) {
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}



	VVI a(H, VI(W, 0));
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			cin >> a[i][j];
			if (a[i][j] != -1) {
				ans += d[a[i][j]][1];
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.nextLine();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        //long start = System.nanoTime();
        System.out.println(solve(n, k, h));
        //long end = System.nanoTime();
        //System.err.println("execution time: " + ((end-start)/1_000_000) + "ms");
    }
    private static int solve(int n, int k, int[] h) {
        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(h[1]-h[0]);
        for (int i = 2; i < n; i++) {
            dp[i] = Integer.MAX_VALUE;
            for (int j = 1; j <= Math.min(i, k); j++) {
                dp[i] = Math.min(dp[i], dp[i-j]+Math.abs(h[i]-h[i-j]));
            }
        }
        return dp[n-1];
    }
}


Measured memory_bytes: 50656
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  int n, m;
  cin >> n >> m;
  map<int,int> d;
  forn(i,m){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    d[a]++;
    d[b]++;
  }
  forn(i,n){
    cout <<d[i] << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 


*/

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=100005;
typedef pair<int,int> P;
struct Node{
    int x,y,id;
    bool operator < (Node p){
        return P(x,y)<P(p.x,p.y);
    }
};
int R,C;
int n;
vector<Node> v[2];
int get(int x,int y){
    if(x==0||y==C)return 0;
    if(y==0||x==R)return 1;
    return -1;
}
int main(){
    scanf("%d%d%d",&R,&C,&n);
    for(int i=1;i<=n;i++){
        int x1,y1,x2,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        if(get(x1,y1)!=-1&&get(x2,y2)!=-1){
            v[get(x1,y1)].push_back({x1,y1,i});
            v[get(x2,y2)].push_back({x2,y2,i});
        }
    }
    for(int i=0;i<2;i++)sort(v[i].begin(),v[i].end());
    reverse(v[1].begin(),v[1].end());
    stack<int> s;
    for(int i=0;i<2;i++){
        for(auto p:v[i]){
            int x=p.id;
            if(!s.empty()&&s.top()==x)s.pop();
            else s.push(x);
        }
    }
    if(!s.empty())printf("NO\n");
    else printf("YES\n");
    return 0;
}

Measured memory_bytes: 3048
let k_n = stdin.ReadLine().Split(' ') |> Array.map int
let mutable a = stdin.ReadLine().Split(' ') |> Array.map int
a <- Array.sort(a)
a <- Array.rev(a)
let mutable ans = 0
for i in [0..k_n.[1]-1]do
ans<-ans+a.[i]
done;;
printfn "%d" ans


Measured memory_bytes: 21736
#include "bits/stdc++.h"

using namespace std;

bool possible(long long longestLog, const vector<long long>& A, long long K) {
    long long N = A.size();
    long long numOfLongestLogs = 0;
    for (long long i = 0; i < N; ++i) {
        numOfLongestLogs += A[i] / longestLog;
        if (A[i] % longestLog == 0) {
            --numOfLongestLogs;
        }
    }
    return (numOfLongestLogs <= K);
}

void Main() {
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N, 0LL);
    for (long long i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<long long>());

    long long ub = A.front();
    long long lb = 0LL;
    while (ub - lb > 1LL) {
        long long mid = (ub + lb) / 2LL;
        if (possible(mid, A, K)) {
            ub = mid;
        }
        else {
            lb = mid;
        }
    }
    bool test = possible(lb, A, K);
    if (test) {
        test != test;
    }
    cout << ub << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4764
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[][] c = new int[3][3];
            for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) c[i][j] = in.nextInt();
            int[] a = new int[3];
            int[] b = new int[3];
            a[0] = 0;
            b[0] = c[0][0] - a[0];
            b[1] = c[0][1] - a[0];
            b[2] = c[0][2] - a[0];
            a[1] = c[1][0] - b[0];
            a[2] = c[2][0] - b[0];

            String ans = "Yes";
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    if (c[i][j] != a[i] + b[j]) {
                        ans = "No";
                        break;
                    }
                }
            }

            out.println(ans);
        }

    }
}



Measured memory_bytes: 23764
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0; // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int N;
  int A[100010];
  cin >> N;
  for (auto i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int ans = 0;
  for (auto i = 0; i < N; ++i) {
    if (A[i]%2 == 1) ans++;
  }
  cout << ((ans%2 == 0) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int n, m;
int e[100010];
bool used[200010];

signed main() {
    memset(used, false, sizeof(used));
    int n, m; cin >> n >> m;
    rep(i,0,m) cin >> e[i];
    set<int> s;
    repr(i,m-1,0) {
        if(used[ e[i] ]) continue;
        cout << e[i] << endl;
        used[ e[i] ] = true;
    }
    repq(i,1,n) {
        if(!used[i]) cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 4080
#include"bits/stdc++.h"

using namespace std;

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

	if (S == "a" || S == "i" || S == "u" || S == "e" || S == "o") {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys

def sa(Type= int):
  return [Type(x) for x in input().split()]

def solve():
  r, c = sa()

  mat = []

  for _ in range(r):
    arr = sa()
    arr.append(sum(arr))

    mat.append(arr)

  arr = []
  for i in range(c+1):
    arr.append(sum([mat[x][i] for x in range(r)]))

  mat.append(arr)

  print('\n'.join([' '.join([str(s) for s in x]) for x in mat]))

if __name__ == '__main__':
  # sys.stdin = open('input.txt', 'r')
  solve()


Measured memory_bytes: 5792
from collections import deque

x = input()
n = len(x)

deq = deque()

for i in range(n):
    if x[i] == 'S':
        deq.appendleft(x[i])
    elif x[i] == 'T' and  deq and deq[0] == 'S':
        deq.popleft()
    else:
        deq.appendleft('T')

print(len(deq))

Measured memory_bytes: 44512
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 101010
void build(){

}
int n , c , k , t[ N ];
void init(){
  scanf( "%d%d%d" , &n , &c , &k );
  for( int i = 1 ; i <= n ; i ++ )
    t[ i ] = getint();
  sort( t + 1 , t + n + 1 );
}
int dp[ N ];
void solve(){
  for( int i = 1 , j = 1 ; i <= n ; i ++ ){
    while( i - j + 1 > c or 
           t[ j ] < t[ i ] - k ) j ++;
    dp[ i ] = dp[ j - 1 ] + 1;
  }
  printf( "%d\n" , dp[ n ] );
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 1024
package main

import "fmt"

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	ans := 300
	// 愚直に全列挙
	arr := [][]int{{a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b}, {c, b, a}}
	for _, v := range arr {
		ans = min(ans, abs(v[0]-v[1])+abs(v[1]-v[2]))
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
from itertools import permutations

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

i = 0

for x in permutations(range(1, n + 1)):
    i += 1
    if list(x) == p:
        a = i
    if list(x) == q:
        b = i

print(abs(a - b))

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int h = in.nextInt();
        int n = in.nextInt();
        int sum=0;
        for(int i=0;i<n;i++){
            sum+=in.nextInt();
        }
        out.println((sum>=h)?"Yes":"No");
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 34504
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

ll A,B;

bool IsPrime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> A >> B;
    vector<ll> V,W,X;
    V = divisor(A);W = divisor(B);
    REP(i,V.size()){
        REP(j,W.size()){
            if(V[i] == W[j]) X.pb(W[j]);
        }
    }
    ll cnt = 0;
    REP(i,X.size()){
        if(IsPrime(X[i])){
            ++cnt;
        }
    }
    cout << cnt+1 << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define pin pair<int,int>
pin solve(V<pin>& ab, int ex) {
	if (!ex) { return mkp(1, 0); }
	V<V<pin>> qab(2);
	for (pin x : ab) {
		qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
		if (x.first & 1) { qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2)); }
	}
	V<vel> c(2, vel(2));
	rep(i, 2) {
		for (pin x : qab[i]) {
			int qc = (2 * x.first + x.second) % 3;
			if ((qc + 1) % 2) { c[i][0] ^= 1; }
			if (qc) { c[i][1] ^= 1; }
		}
	}
	rep(i, 2) {
		if (!c[1 - i][0] && !c[1 - i][1]) {
			pin ans = solve(qab[i], ex - 1);
			ans.first *= 2; ans.second *= 2; ans.second += i;
			return ans;
		}
	}
	for (pin& v : ab) { v.first++; }
	pin ans = solve(ab, ex); ans.first--;
	return ans;
}
signed main() {
	long long inf = 2e17;
	int n; scanf("%lld", &n);
	V<pin> ab(n);
	rep(i, n) {
		long long a, b; scanf("%lld", &a); scanf("%lld", &b);
		ab[i] = { a + inf,b + inf };
	}
	pin ret = solve(ab, 70);
	cout << ret.first - inf << " " << ret.second - inf;
}


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

  const int MOD = 1000000007;
  const int INF = 1e9;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
  #define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
  #define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

  //最大公約数 
  ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b,a%b);
  }

  //最小公倍数
  ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
    unsigned r;
    while ((r=a%b)) {
      a = b;
      b = r;
    }
    return b;
  } 


  //  int X[8]={-1, 0, 1, -1, 1, -1, 0, 1};
  //  int Y[8]={1, 1, 1, 0, 0, -1, -1, -1};




int main() {
int N;
cin >> N;
vector<int> A(N);
REP(i, N) cin >> A[i];

int cnt = 1;
REP(i, N)
if(A.at(i) % 2 == 0)cnt *=2;

int ans = pow(3, N) - cnt;
print(ans);

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            int a = in.nextInt();
            int b = in.nextInt();
            if (a == 0 && b == 0) {
                break;
            } else if (a <= b) {
                System.out.println(a + " " + b);
            } else if (b <= a){
                System.out.println(b + " " + a);
            }
            
        }
    }
}

Measured memory_bytes: 35684
#include <cstdio>
#include <cstring>

char tree1[500000],tree2[500000];
char c1[500000],c2[500000];
int i,m,n1,n2,l1,l2,r1,r2;

inline char merge(char x,char y)
{
	if ((x=='A') && (y=='A')) return 'B';
	if ((x=='A') && (y=='B')) return 'C';
	if ((x=='A') && (y=='C')) return 'A';
	if ((x=='B') && (y=='A')) return 'C';
	if ((x=='B') && (y=='B')) return 'A';
	if ((x=='B') && (y=='C')) return 'B';
	if ((x=='C') && (y=='A')) return 'A';
	if ((x=='C') && (y=='B')) return 'B';
	if ((x=='C') && (y=='C')) return 'C';
}

inline void buildtree1(int l,int r,int node)
{
	if (l==r)
		tree1[node]=c1[l];
	else
	{
		int mid=(l+r)>>1;
		buildtree1(l,mid,node<<1);
		buildtree1(mid+1,r,node<<1|1);
		tree1[node]=merge(tree1[node<<1],tree1[node<<1|1]);
	}
	return;
}

inline void buildtree2(int l,int r,int node)
{
	if (l==r)
		tree2[node]=c2[l];
	else
	{
		int mid=(l+r)>>1;
		buildtree2(l,mid,node<<1);
		buildtree2(mid+1,r,node<<1|1);
		tree2[node]=merge(tree2[node<<1],tree2[node<<1|1]);
	}
	return;
}

inline int asktree1(int l,int r,int x,int y,int node)
{
	if ((l==x) && (r==y))
		return tree1[node];
	int mid=(l+r)>>1;
	if (y<=mid)
		return asktree1(l,mid,x,y,node<<1);
	if (x>mid)
		return asktree1(mid+1,r,x,y,node<<1|1);
	return merge(asktree1(l,mid,x,mid,node<<1),asktree1(mid+1,r,mid+1,y,node<<1|1));
}

inline int asktree2(int l,int r,int x,int y,int node)
{
	if ((l==x) && (r==y))
		return tree2[node];
	int mid=(l+r)>>1;
	if (y<=mid)
		return asktree2(l,mid,x,y,node<<1);
	if (x>mid)
		return asktree2(mid+1,r,x,y,node<<1|1);
	return merge(asktree2(l,mid,x,mid,node<<1),asktree2(mid+1,r,mid+1,y,node<<1|1));
}

int main()
{
	scanf("%s",c1+1);
	n1=strlen(c1+1);
	buildtree1(1,n1,1);
	scanf("%s",c2+1);
	n2=strlen(c2+1);
	buildtree2(1,n2,1);
	scanf("%d",&m);
	for (i=1;i<=m;i++)
	{
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		if (asktree1(1,n1,l1,r1,1)==asktree2(1,n2,l2,r2,1))
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

    /*
    ||||||||||||||||||||||||||||||||||||||||||||||||
       |      |||         |      ||||    ||||  |   |
      | |     |   |      | |     |   |  |      |   |
     |   |    |    |    |   |    |   |  |      |   |
    |||||||   |    |   |||||||   |||     |||   |||||
    |     |   |   |    |     |   | |        |  |   |
    |     |   |||      |     |   |  ||  ||||   |   |
    ||||||||||||||||||||||||||||||||||||||||||||||||

    */
    using namespace std;
    //#include "testlib.h"
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define int long long
    #define ll long long
    #define M 1000000007

    #define mii  map<ll ,ll >
    #define msi  map<string,ll >
    #define mis  map<ll int, string>
    #define rep(a,b)    for(ll i=a;i<b;i++)
    #define rep0(n)    for(ll i=0;i<n;i++)
    #define repi(i,a,b) for(ll i=a;i<b;i++)
    #define pb push_back
    #define vi vector<ll>
    #define mp make_pair
    #define vs vector<string>
    #define ppb pop_back
    #define endl '\n'
    #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define r0 return 0;
    #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
    #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
    #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #define input freopen("input.txt", "r", stdin);
    #define Set(a, s) 4(a, s, sizeof (a))
    #define FOR repi
    #define pii pair<int,int>
    //#define float long double
    ll max(ll a, ll b) { return (a > b)? a : b;}
    int min(int a, int b) { return (a < b)? a : b;}

    int find(int l,int r,int n){
        int f=(l-1)/n;
        int ans=r/n;
        return ans-f;
    }
     int solve()
     {
        int l,r,a,b;
        cin>>l>>r>>a>>b;
        int n=r-l+1;
        int f1=find(l,r,a);
        int f2=find(l,r,b);
        int f3=find(l,r,(a*b)/__gcd(a,b));
        n-=(f1+f2-f3);
        //cout<<f1<<" "<<f2<<" "<<f3<<" "<<n;
        cout<<n;
         
     }
    signed main()
    {   
        asdf
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}

Measured memory_bytes: 256
#include<stdio.h>

int aa(int n) {
	int ans = 0;
	while(n) {
		ans += n%10;
		n /= 10;
	}
	return ans;
}

int main() {
	int m, n, a, b, ans, N;
	while(scanf("%d",&N)!=EOF) {
		scanf("%d%d",&a,&b);
		ans = 0;
		for(int i=1;i<=N;i++) {
			n = aa(i);
			if(n>=a&&n<=b) {
				ans+=i;
//				printf("%d.",n);
			}
		}
		printf("%d\n",ans);
	}
}

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

int main()
{
        ll h, k;
        cin>>h>>k;

        if (k > h) {
                cout<<0<<endl;
                return 0;
        }
        vector < int > health;
        ll data;
        for (ll i = 0; i < h; i++) {
                cin>>data;
                health.push_back(data);
        }

        sort(health.begin(), health.end(), greater < ll >());

        for (int i = 0; i < k; i++) {
                health[i] = 0;
        }

        ll sum = 0;
        for (int i = 0; i < health.size(); i++) {
                sum+= health[i];
        }

        cout<<sum<<endl;
        return 0;
}


Measured memory_bytes: 1528
import sys
from collections import defaultdict as dd
from collections import deque
from functools import *
from fractions import Fraction as f
from copy import *
from bisect import *	
from heapq import *
from math import *
from itertools import permutations ,product
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
def inc(d,c):
	d[c]=d[c]+1 if c in d else 1
def bo(i):
	return ord(i)-ord('A')	
def li():
	return [int(xx) for xx in input().split()]
def fli():
	return [float(x) for x in input().split()]	
def comp(a,b):
	if(a>b):
		return 2
	return 2 if a==b else 0		
def gi():	
	return [xx for xx in input().split()]
def fi():
	return int(input())
def pro(a): 
	return reduce(lambda a,b:a*b,a)		
def swap(a,i,j): 
	a[i],a[j]=a[j],a[i]	
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())			
def gh():
	sys.stdout.flush()
def isvalid(i,j):
	return 0<=i<n and 0<=j<n	
def bo(i):
	return ord(i)-ord('a')	
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)


t=1
N=10**6+5
spf=[i for i in range(N+1)]
for i in range(2,int(ceil(sqrt(N)))+2):
	if spf[i]==i:
		for j in range(i*i,N,i):
			if spf[j]==j:
				spf[j]=i
			
def fact(i):
	s=set()
	while i!=1:
		s.add(spf[i])	
		i//=spf[i]
	return s	

while t>0:
	t-=1
	n=fi()
	a=li()
	s=set()
	g=a[0]
	flag=0
	for i in range(n):
		g=gcd(g,a[i])
		k=fact(a[i])
		if len(s&k)!=0:
			flag|=1
		s|=k
	if flag==0:
		print("pairwise coprime")
	elif g==1:
		print("setwise coprime")	
	else:
		print("not coprime")			


Measured memory_bytes: 196176