akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)

 
int main(){
    int H,W,D;
    cin >> H >> W >> D;
    int A[H][W];
    int X[H * W],Y[H * W];

    rep(i,H){
        rep(j,W){
            cin >> A[i][j];
            Y[A[i][j] - 1] = i;
            X[A[i][j] - 1] = j;
        }
    }

    int Z[H * W];
    for(int i=0;i<D;i++){
        Z[i] = 0;
        for(int j=i+D;j<W*H;j+=D){
            Z[j] = Z[j-D] + abs(X[j] - X[j-D]) + abs(Y[j] - Y[j-D]);
        }
    }
    int Q;
    cin >> Q;
    rep(i,Q){
        int L,R;
        cin >> L >> R;
        cout << Z[R-1] - Z[L-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
int main( ){
  int x,y,i;
  for(i=1;i>0;i++)
    {
      scanf("%d%d",&x,&y);
      if(x>y){
	printf("%d %d\n",y,x);
      }
      if(x<y){
	printf("%d %d\n",x,y);
      }
      if(x==y){
	if(x!=0){
	  printf("%d %d\n",x,y);
	}
	if(x==0){
	  break;
	}
      }
    }
  return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashSet;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N=sc.nextInt();
   int D1[]=new int[N];
   int D2[]=new int[N];
   int count=0;
  for (int k=0;k<N ;k++ ) {
    D1[k]=sc.nextInt();
    D2[k]=sc.nextInt();
  }
for (int n=0;n<N ;n++ ) {
  if (count==3) {
    break;
  }
  if (D1[n]==D2[n]) {
    count++;
  }else{
    count=0;
  }
}
if(count==3){
  System.out.println("Yes");

}else{
  System.out.println("No");
}

}
}


Measured memory_bytes: 35932
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var A  = parseInt(input[0], 10);
    var op = input[1];
    var B  = parseInt(input[2], 10);
	//出力
    if (op == '+') {
      console.log(A+B);
    } else if (op == '-') {
      console.log(A-B);
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29600
#include <stdio.h>

int a[1000000];

int main() {

    int k, n;
    int i;
    int max;
    int temp;
    int ans;

    scanf("%d %d", &k, &n);
    for(i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    max = k - a[n-1] + a[0];
    for(i = 0; i < n-1; i++) {
        temp = a[i+1] - a[i];
        if(max < temp) {
            max = temp;
        }
    }

    ans = k - max;
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define pb              push_back
//#define mp              make_pair
#define pii             pair<int,int>
//#define vec             vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define no_of_test(x)   int x; cin>>x; while(x--)

const int mod = 1e9 + 7;
void very_fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}
int32_t main()
{
	very_fast();
	//no_of_test(x)
	{
		string s;
		cin >> s;
		if (s[0] == 'R')
		{
			if (s[1] == 'R' && s[2] == 'R')
			{
				cout << 3 << endl;

			}
			else if (s[1] == 'R' && s[2] != 'R')
			{
				cout << 2 << endl;

			}
			else if (s[2] == 'R' && s[1] != 'R')
				cout << 1 << endl;
			else
				cout << 1 << endl;
		}

		else if (s[1] == 'R')
		{
			if ( s[2] == 'R')
			{
				cout << 2 << endl;

			}
			else
				cout << 1 << endl;
		}
		else if (s[2] == 'R')
			cout << 1 << endl;
		else
			cout << 0 << endl;

	}
	return 0;
}



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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}

typedef pair<int,int> P;

const int H=50,W=50;
int h,w,mem[H][W],dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
char s[H][W];

int bfs(){
    queue<P> que;
    P sp=P(0,0),ep=P(h-1,w-1);
    que.push(sp);
    mem[0][0]=0;
    while(que.size()){
        P a=que.front();que.pop();
        if(a.first==ep.first&&a.second==ep.second)break;
        rep(k,4){
            int ny=a.first+dy[k],nx=a.second+dx[k];
            if(0<=ny&&ny<h&&0<=nx&&nx<w&&s[ny][nx]!='#'&&mem[ny][nx]==INF){
                que.push(P(ny,nx));
                mem[ny][nx]=mem[a.first][a.second]+1;
            }
        }
    }
    return mem[ep.first][ep.second];
}

int main(){
    int i,j,count=0;
    //入力
    cin>>h>>w;
    rep(i,h){
        rep(j,w){
            cin>>s[i][j];
            if(s[i][j]=='.')count+=1;
            mem[i][j]=INF;
        }
    }
    //処理
    int rm=bfs();
    //出力
    if(rm>=INF){
        cout<<-1<<endl;
    }else{
        cout<<count-1-rm<<endl;
    }
}

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

int main() {
	int i, a, b, c;
	while (~scanf("%d%d%d", &a, &b, &c)) {
		int ans = 0;
		for (i = a; i <= b; i++) {
			if (c % i == 0) ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main(){
    int num;
    int ans=0;
    std::vector<int> a,conf;
    std::vector<int> b;

    // 入力
    for(int i=0; i<3; i++){
        int temp1, temp2, temp3;
        std::cin >> temp1 >> temp2 >> temp3;
        b.push_back(temp1);
        b.push_back(temp2);
        b.push_back(temp3);
    }

    std::cin >> num;

    for(int i=0; i<num; i++){
        int temp;
        std::cin >> temp;
        a.push_back(temp);
    }    

    // 横
    ans = 0;
    for(int i=0; i<3; i++){
        for(int k=0; k<a.size();k++){
            if(b.at(i) == a.at(k)) ans++;
        }
    }
    if(ans == 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    ans = 0;
    for(int i=3; i<6; i++){
        for(int k=0; k<a.size();k++){
            if(b.at(i) == a.at(k)) ans++;
        }
    }
    if(ans == 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    ans = 0;
    for(int i=6; i<9; i++){
        for(int k=0; k<a.size();k++){
            if(b.at(i) == a.at(k)) ans++;
        }
    }
    if(ans == 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    }


    // 縦
    ans = 0;
    for(int i=0; i<b.size(); i+=3){
        for(int k=0; k<a.size();k++){
            if(b.at(i) == a.at(k)) ans++;
        }
    }
    if(ans == 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    ans = 0;
    for(int i=1; i<b.size(); i+=3){
        for(int k=0; k<a.size();k++){
            if(b.at(i) == a.at(k)) ans++;
        }
    }
    if(ans == 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    ans = 0;
    for(int i=2; i<b.size(); i+=3){
        for(int k=0; k<a.size();k++){
            if(b.at(i) == a.at(k)) ans++;
        }
    }
    if(ans == 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    // 斜め
    ans = 0;
    for(int i=0; i<b.size(); i+=4){
        for(int k=0; k<a.size();k++){
            if(b.at(i) == a.at(k)) ans++;
        }
    }
    if(ans == 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    }

    ans = 0;
    for(int i=2; i<b.size(); i+=2){
        if(i == 8) break;
        for(int k=0; k<a.size();k++){
            if(b.at(i) == a.at(k)) ans++;
        }
    }
    if(ans == 3) {
        std::cout << "Yes" << std::endl;
        return 0;
    }


    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
*a, = map(int, input().split())

mar = k - 1  # max replacible count

ret = 1 + (n - k + mar - 1) // mar
print(ret)

# 左端から長さKの区間をのりしろ1で貼り続ける
# 最小値1を含む要素に重なる区間から順に操作を始めれば可能
# i = a.index(1)
# mar = k - 1  # max replacible count
#
# le = (i + mar - 1) // mar  # [0,i)
# ri = (n - i - 1 + mar - 1) // mar  # [i+1,n)
#
# print(le + ri)


Measured memory_bytes: 13812
#include "bits/stdc++.h"
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
using namespace std;

#define ll long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()



// substr(start, len)

int main(){

  ll A, B, M, min = 0;
  cin >> A >> B >> M;

  vector<ll> a(A, 0), b(B, 0);
  rep(i, 0, A){
    cin >> a[i];
  } 
  rep(i, 0, B){
    cin >> b[i];
  }

  min = *min_element(all(a)) + *min_element(all(b));

  vector<ll> x(M, 0), y(M, 0), c(M, 0);
  ll sum = 0;

  rep(i, 0, M){
    cin >> x[i] >> y[i] >> c[i];
    sum = a[x[i]-1] + b[y[i]-1] - c[i];
    if(sum < min) min = sum;
  }

  cout << min << endl;



  

// CHECK if it's possible to overflow!!
}

Measured memory_bytes: 4224
n=int(input());l=[list(map(int,input().split()))for i in[0]*n];a=[0]*n;d=1;k=n*(n-1)
while sum(a)<k and 0<d<9999:
 L=[0]*n;y=0;d+=1
 for i in range(n):
  if a[i]<n-1:
   x=l[i][a[i]]-1
   if l[x][a[x]]-1==i and L[x]+L[i]<1:
    a[i]+=1;a[x]+=1;L[i]=L[x]=y=1
 d*=y
print([k//2,d-1][d<9999])

Measured memory_bytes: 53980
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>//小数点以下表示
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main(){
    vector<int> a(3);
    rep(i,3){
        cin>>a.at(i);
    }
    if(a.at(0)==a.at(1)&&a.at(0)!=a.at(2)){
        cout<<"Yes"<<endl;
    }
    else if(a.at(0)==a.at(2)&&a.at(0)!=a.at(1)){
        cout<<"Yes"<<endl;
    }
    else if(a.at(1)==a.at(2)&&a.at(0)!=a.at(1)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();

            int[] A = new int[N];
            int[][] X = new int[N][N];
            int[][] Y = new int[N][N];

            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
                for (int j = 0; j < A[i]; j++) {
                    X[i][j] = sc.nextInt() - 1;
                    Y[i][j] = sc.nextInt();
                }
            }

            int ans = 0;

            for (int i = 1; i < (1 << N); i++) {
                UnionFindTree tree = new UnionFindTree(N);

                for (int j = 0; j < N; j++) {
                    if (((i >> j) & 1) == 1) {
                        tree.unite(N, j);
                    }
                }

                int ans2 = 0;
                for (int j = 0; j < N; j++) {
                    if (tree.same(N, j)) {
                        for (int k = 0; k < A[j]; k++) {
                            int x = X[j][k];
                            int y = Y[j][k];

                            boolean same = tree.same(N, x);

                            if ((same && y == 0) || (!same && y == 1)) {
                                ans2 = -10;
                                j = N;
                                break;
                            }
                        }

                        ans2++;
                    }
                }

                ans = Math.max(ans, ans2);
            }

            System.out.println(ans);
        }
    }

    public static class UnionFindTree {

        private int[] parent;

        private int[] rank;

        public UnionFindTree(int N) {
            parent = new int[N + 1];
            rank = new int[N + 1];
            for (int i = 0; i <= N; i++) {
                parent[i] = i;
                rank[i] = 0;
            }
        }

        public int find(int x) {
            if (parent[x] == x) {
                return x;
            } else {
                int p = find(parent[x]);
                parent[x] = p;
                return p;
            }
        }

        public void unite(int x, int y) {
            x = find(x);
            y = find(y);

            if (x == y) {
                return;
            }

            if (rank[x] < rank[y]) {
                parent[x] = y;
            } else {
                parent[y] = x;
                if (rank[x] == rank[y]) {
                    rank[x]++;
                }
            }
        }

        public boolean same(int x, int y) {
            return find(x) == find(y);
        }

    }

}


Measured memory_bytes: 29268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = ReadLine().Split().Select(ushort.Parse).ToArray();
		if(n[0] % 3 == 0 || n[1] % 3 == 0 || (n[0] + n[1]) % 3 == 0)
			WriteLine("Possible");
		else
			WriteLine("Impossible");
	}
}


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

int main(){
      char a[4];
      int c=0;
      for(int i=0;i<4;i++){
            cin>>a[i];
            if(a[i]==a[i-1]||a[i]==a[i-2]||a[i]==a[i-3]){
                  c=c+1;
            }
      }
      if(c==2)
      {     cout<<"Yes"<<endl;
      }
      else{cout<<"No"<<endl;}

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll ans = 0;
	ll N;
	cin >> N;
	ll anstmp = 1;
	rep(i, N) {
		anstmp *= 10;
		anstmp %= mod;
	}
	ans += anstmp;
	ans %= mod;
	anstmp = 1;
	rep(i, N) {
		anstmp *= 9;
		anstmp %= mod;
	}
	ans -= anstmp;
	ans += mod;
	ans %= mod;
	anstmp = 1;
	rep(i, N) {
		anstmp *= 9;
		anstmp %= mod;
	}
	ans -= anstmp;
	ans += mod;
	ans %= mod;
	anstmp = 1;
	rep(i, N) {
		anstmp *= 8;
		anstmp %= mod;
	}
	ans += anstmp;
	ans %= mod;


	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <vector>
#include <queue>
#include <iostream>
#include <stdio.h>

using namespace std;

#define NODE_NUM 10000
#define INF 100000

typedef struct Node {
    //????????????????????????????????????
    int idx;
    
    // ????????????????????????????????¨??????????????±
    vector<int> edges_to;    // ?????¨???????????\?¶??????????????????????
    vector<int> edges_cost;  // ?????¨??????????????????
    
    // ??????????????????????????????????????????
    bool done;  // ?¢??????????????????????
    int cost;   // ????????????????????????????????§??????????????????????°??????????
}Node;

Node nodes[NODE_NUM];


struct NodeCompare
{
    bool operator()(const Node &t1, const Node &t2) const
    {
        //?????????????????????????????????????????????????????????????????????????????´?????????????????????????????????
        return t1.cost > t2.cost;
    }
};

void Dijkstra(int node_num, int start_node){
    
    // ?????????
    for (int i =0 ; i < node_num; i++) {
        nodes[i].done = false;
        nodes[i].cost = INF;
        nodes[i].idx = i;
    }

    //????????????????????\???????°?????????????????????????
    priority_queue<Node, vector<Node>, NodeCompare> q;
    
    // ????????????????????????????????????0
    nodes[start_node].cost = 0;
    q.push(nodes[start_node]);
    
    // ??¢?????´???????????????
    while(!q.empty()){
        
        // ?¢????????????????????????????
        Node doneNode = q.top();
        q.pop();
        
        //???????¢?????????????????????????????????????????????¨??±?????????
        if (doneNode.done) continue;
        
        // ?¢????????????°????????????
        nodes[doneNode.idx].done = true;
        
        // ??\?¶?????????????????????±?????´??°??????
        for(int i = 0; i < doneNode.edges_to.size(); i++){
            
            int to = doneNode.edges_to[i];
            int cost = doneNode.cost + doneNode.edges_cost[i];
            if( nodes[to].cost == INF || cost < nodes[to].cost){
                nodes[to].cost = cost;
                if(!nodes[to].done){
                    q.push(nodes[to]);
                }
            }
        }
    }
}

int main( ){
    
    int i, j, n, k, v, c, u;
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d %d",&u,  &k);
        
        for (j =0 ; j < k; j++) {
            scanf("%d %d", &v, &c);
            nodes[u].edges_cost.push_back(c);
            nodes[u].edges_to.push_back(v);
        }
    }
    
    Dijkstra(n, 0);
    
    for (i=0; i<n; i++) {
        printf("%d %d\n", i, nodes[i].cost);
    }
    
    return 0;
}

Measured memory_bytes: 40116
n,a = map(int,input().split())
x = list(map(int,input().split()))
t = [[[0] * (50*(j+1)+1) for j in range(i+2)] for i in range(n+1)]
ans = 0
t[0][0][0] = 1

for i in range(1, n+1):
    for j in range(i+1):
        for k in range(50*j + 1):
            if j >= 1 and k >= x[i-1]:
                t[i][j][k] = t[i - 1][j - 1][k - x[i-1]] + t[i - 1][j][k]
            else:
                t[i][j][k] = t[i - 1][j][k]
for i in range(1,n+1):
    ans += t[n][i][i*a]
print(ans)

Measured memory_bytes: 21748
n=int(input())
s=str(input())
if n%2==0:
    x=s[0:int(n/2)]
    y=s[int(n/2):n]
    if x==y:
        print("Yes")
    else:
        print("No")
else:
    print("No")        
                    


    
                       
    



Measured memory_bytes: 2940
N = int(input())
weigh = []
weigh = list(map(int,input().split(' ')))
min_y = 100*100
for i in range(N):
  weigh_1 = weigh[0:i]
  weigh_2 = weigh[i:]
  s1 = sum(weigh_1)
  s2 = sum(weigh_2)
  t = abs(s1-s2)
  if t<min_y:
    min_y = t
  if min_y == 0:
    break

print(min_y)

Measured memory_bytes: 3064
wdays = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday)
mdays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
base = 3

while (line = gets)
  m, d = line.chop.split(" ").map{|s| s.to_i}

  if m == 0 || d == 0
    break
  end

  days = base + d
  (0...(m - 1)).each{|k| days += mdays[k]}

  puts wdays[days % 7]
end

Measured memory_bytes: 6096
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

for i in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

def dfs(v, parent):
    for i in graph[v]:
        if i==parent:
            continue
        counter[i] += counter[v]
        dfs(i, v)
        
dfs(0, -1)
print(*counter)      

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N, K;
int x[110000];
signed main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++)cin >> x[i];

    int ans = LLONG_MAX;
    for (int i = 0; i + K - 1 < N; i++) {
        if (x[i] < 0 && x[i + K - 1] < 0) {
            ans = min(ans, -x[i]);
        } else if (x[i] > 0 && x[i + K - 1] > 0) {
            ans = min(ans, x[i + K - 1]);
        } else {
            ans = min(ans, -x[i] + 2 * x[i + K - 1]);
            ans = min(ans, -2 * x[i] + x[i + K - 1]);
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 1024
import bisect
N=int(input())

alist=[]
for i in range(N):
  alist.append(int(input()))
#print(alist)

color_list=[alist.pop()]
for i in reversed(range(N-1)):
  a=alist[i]
  if a>=color_list[-1]:
    #insert to tail
    color_list.append(a)
  else:
    #replace
    pos=bisect.bisect(color_list,a)
    color_list[pos]=a
  #print(color_list)
  
print(len(color_list))

Measured memory_bytes: 7832
n,m=map(int,input().split())
xs=[tuple(map(int,input().split())) for _ in range(m)]
c=0
def root(n):
  if union[n]==n:
    return n
  union[n]=root(union[n])
  return union[n]
for i in range(m):
  union={x:x for x in range(1,n+1)}
  t=0
  for j in range(i):
    x,y=xs[j]
    union[root(x)]=root(y) 
  for j in range(i+1,m):
    x,y=xs[j]
    union[root(x)]=root(y) 
  for k in range(1,n+1):
    if union.get(k)==k:
      t+=1
  if t!=1:
    c+=1
print(c)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
int main(){
	int n; std::cin >> n;
	std::vector<long long int> numbers(n); for (auto& a : numbers) std::cin >> a;
	for (auto i = 0; i < n; ++i) {
		numbers[i] -= i + 1;
	}
	std::sort(numbers.begin(), numbers.end());
	auto lower = numbers[(n - 1) / 2];
	auto upper = numbers[n / 2];
	long long int lower_sum{ 0LL }, upper_sum{ 0LL };
	for (const auto a : numbers) {
		lower_sum += std::abs(a - lower);
		upper_sum += std::abs(a - upper);
	}
	std::cout << std::min(lower_sum, upper_sum) << std::endl;
}



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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(void){


    int n;
    cin >> n;

    if(n % 1000 == 0){
        cout << 0 << "\n";
    }else{
        cout << 1000 - n%1000 << "\n";
    }

    return 0;
}

Measured memory_bytes: 3560
package main

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

func main() {
	N := nextInt()
	t := make([]int, N)
	for i := 0; i < N-1; i++ {
		v := nextInt()
		t[v-1] += 1
	}
	for i := 0; i < N; i++ {
		fmt.Println(t[i])
	}
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

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

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

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 6196
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var [t,tt,r,rr]=input.trim().split(" ").map(Number);
if(r==-1 || rr==-1){
  if(t>tt)console.log("Bob");
  else if(t<tt)console.log("Alice");
  else if(t==tt)console.log("Draw");
}
else if(r>rr)console.log("Alice");
else if(r<rr)console.log("Bob");
else if(r==rr)console.log("Draw");


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

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int sum = 0;
			for(int i=0;i<n;i++){
				int s = sc.nextInt() + sc.nextInt() + sc.nextInt();
				int w = sc.nextInt();
				
				if(160<s || 25<w);
				else if((140<s && s<=160) || (20<w && w<=25)) sum+=1600;
				else if((120<s && s<=140) || (15<w && w<=20)) sum+=1400;
				else if((100<s && s<=120) || (10<w && w<=15)) sum+=1200;
				else if((80<s && s<=100) || (5<w && w<=10)) sum+=1000;
				else if((60<s && s<=80) || (2<w && w<=5)) sum+=800;
				else sum+=600;
			}
			System.out.println(sum);
		}	
	}	
}

Measured memory_bytes: 56400
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n;

int main(){
	cin>>n;
	ll m=INF;
	for(int i=0;i<5;i++){
		ll x;
		cin>>x;
		m=min(m,x);
	}
	cout<<4+(n+m-1)/m<<endl;
}

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

S=input()

for i in range(0,len(S),1):
  if S[i]=='A':
    aind=i
    break
for i in range(len(S)-1,0,-1):
  if S[i]=='Z':
    zind=i
    break
print(zind-aind+1)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
int ans=1000000000;
int main(){
   string s;
   string t;
   cin>>s;
   for(int i=0;i<8;i++){
       t="";
       for(int j=i;j<i+3;j++){
           t+=s[j];
       }
       int p=toInt(t);
       ans=min(ans,abs(p-753));
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]

x = A[:]
x.sort()
Amax = x[N-1]
Amax2 = x[N-2]
print("")
for a in A:
    if a < Amax:
        print(Amax)
    elif a == Amax:
        print(Amax2)

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

int main(){
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  
  if(b>=c && d>=b){
    if(a<=c){
      cout << b-c <<endl;
    }
    else{
      cout << b-a <<endl;
    }
  }
  else if(a<=d && d<=b){
    if(a>=c){
      cout << d-a <<endl;
    }
    else{
      cout << d-c <<endl;
    }
  }
  else{
    cout << 0 <<endl;
  }
}



Measured memory_bytes: 3632
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>	
#include <utility>
#include <cinttypes>
#include <string>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <deque>
using namespace std;

int main(){
    cout<<std::fixed<<setprecision(10);
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n,m;
    long long sum = 0ll;
    std::deque<int> a;
    vector<pair<int,int>> bc;
    cin>>n;
    cin>>m;
    bc.reserve(m);
    for (int i=0;i<n;i++){
        int ai;
        cin>>ai;
        a.push_back(ai);
    }
    for (int i=0;i<m;i++){
        int bi,ci;
        cin>>bi;
        cin>>ci;
        bc.push_back(pair<int,int>(bi,ci));
    }
    sort(a.begin(),a.end());
    sort(bc.begin(),bc.end(),[](pair<int,int>p1, pair<int,int>p2) -> int { return ( p1.second > p2.second ); } );
    for (int i=0;i<m;i++){
        for (int j=0;j<bc[i].first;j++){
            if (a.size()==0){
                break;
            }
            if (a[0]<bc[i].second){
                sum += bc[i].second;
                a.pop_front();
            } else {
				break;
            }
        }
        if (a.size()==0){
            break;
        }
    }
    cout<<accumulate(a.begin(),a.end(),sum)<<"\n";
}

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t = "keyence";
    cin >> s;
    int n = t.size();
    if (s.size() < n) {
        cout << "NO\n";
        return 0;
    }
    vector<bool> l(n + 1), r(n + 1);
    rep (i, n + 1) {
        if (t.substr(0, i) == s.substr(0, i)) l[i] = true;
        if (t.substr(n - i) == s.substr(s.size() - i)) r[i] = true;
    }
    rep (i, n + 1) eprintf("%d", l[i] * 1); eprintf("\n");
    rep (i, n + 1) eprintf("%d", r[i] * 1); eprintf("\n");
    rep (i, n + 1) {
        if (l[i] && r[n - i]) {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int ma = max(max(A,B),C);
    cout << pow(2,K)*ma+A+B+C-ma << endl;
}


Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  ll N,K;
  cin >> N >> K;
  vector<ll> H(N);
  for(int i = 0; i < N; i++){
    cin >> H[i];
  }

  sort(H.begin(), H.end());
  
  ll ans = 0;
  if(N <= K){
    ans = 0;
  }
  else{
    for(int i = 0; i < N-K; i++){
      ans += H[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
bool prime(int x) {
    
    bool b = true;
    if(x == 2) {
        b = true;
    }
    else if(x % 2 == 0) {
        b = false;
    }
    else {
        double root = sqrt(x);
        for(int i = 3; i <= root; i += 2) {
            if(x%i == 0) {
                b = false;
                break;
            }
        }
    }
    return b;
}
int main() {
    int n,a;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        cin >> a;
        if(prime(a)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3088
from collections import deque

def dfs(G, visited, s, n, ans):
  # すべての頂点を訪れた場合の処理
  if all(visited) :
    ans += 1
    return ans
  #　次の頂点の探索
  for i in G[s] :
    if visited[i] == False :
      visited[i] = True
      ans = dfs(G, visited, i, n, ans)
      visited[i] = False
  return ans

#　グラフGの入力
n,m = map(int,input().split())
G = [[] for j in range(n)]
for i in range(m) :
  a,b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)
  

visited = [False for i in range(n)]
visited[0] = True
ans = 0
print(dfs(G, visited, 0, n, ans))

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N,X; cin >> N >> X;
    vector<int> a(N);
    for(int &i : a) cin >> i;
    for(int i = 1; i < a.size(); i++) a[i] += a[i - 1];
    int cont = 0;
    for(int i : a) cont += (i <= X);
    cout << cont + 1 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll x,n;
    cin>>x>>n;
    vi p(n);
    rep(i,0,n)cin>>p[i];
    sort(p.begin(),p.end());
    rep(i,0,110){
        auto n=lower_bound(p.begin(),p.end(),x-i);
        if(n==p.end()||*n!=x-i){
            cout<<x-i<<endl;
            return 0;
        }
        auto pos=lower_bound(p.begin(),p.end(),x+i);
        if(pos==p.end()||*pos!=x+i){
            cout<<x+i<<endl;
            return 0;
        }
    }
    return 0;
}




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

using ll=long long;

vector<ll> generate(int n,ll s,ll w){
    vector<ll> a(n);
    ll g=s;
    for(int i=0;i<n;i++){
        a[i]=(g/7)%10;
        if(g%2==0) g=g/2;
        else g=(g/2)^w;
    }
    return a;
}
ll solve(int n,vector<ll> a,ll q){
    if(q==2 || q==5){
        set<int> valid;
        for(int i=0;i<10;i++)if(i%q==0) valid.insert(i);
        ll res=0;
        ll sum=0;
        for(int i=0;i<n;i++){
            if(a[i]!=0){
                sum++;
            }
            if(valid.count(a[i])){
                res+=sum;
            }
        }
        return res;
    }
    vector<ll> sum(n+1);
    sum[n]=0;
    ll tenp=1;
    for(int i=n-1;i>=0;i--){
        sum[i]=(sum[i+1]+a[i]*tenp)%q;
        tenp=(tenp*10)%q;
    }
    ll res=0;
    map<ll,ll> mp;
    for(int i=0;i<n;i++){
        if(a[i]!=0) mp[sum[i]]++;
        ll x=sum[i+1];
        res+=mp[x];
    }
    return res;
}
int main(){
    int n;
    ll s,w,q;
    while(cin>>n>>s>>w>>q,n){
        vector<ll> a=generate(n,s,w);
        cout<<solve(n,a,q)<<endl;
    }
    return 0;
}


Measured memory_bytes: 10700
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	ll X;
	cin >> X;
	int i = 1;
	ll sum = 0;
	while (true)
	{
		sum += i;
		if (sum - X <= i && sum - X >= 0)break;
		i++;
	}
	cout << i << endl;
	return 0;
}

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int a, b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin>>N;
    vector<ll> A;
    rep(i,0,N){
        ll a;
        cin>>a;
        A.pb(a);
    }
    sor(A);
    ll res1=0,res2=0;
    if(N%2){
        rep(i,N/2+1,N){
            res1+=2*A[i];
        }
        rep(i,0,N/2-1){
            res1-=2*A[i];
        }
        res1-=A[N/2-1]+A[N/2];
        rep(i,0,N/2){
            res2-=2*A[i];
        }
        rep(i,N/2,N){
            res2+=2*A[i];
        }
        res2-=A[N/2]+A[N/2+1];
    }
    else{
        rep(i,N/2,N){
            res1+=2*A[i];
        }
        rep(i,0,N/2){
            res1-=2*A[i];
        }
        res1+=-A[N/2]+A[N/2-1];
    }
    cout <<max(res1,res2)<<"\n";
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef double ld;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=500005,M=2000005,inf=1e9;
namespace G{
	struct edge{int v,f,c,p;};
	vector<edge> e[N];
	int d[N],r[N],in[N],n,m,s,t;
	void init(int _n,int _s,int _t){
		n=_n,s=_s,t=_t,m=0;
	}
	void add(int a,int b,int c){
		e[a].pb((edge){b,0,c,e[b].size()});
		e[b].pb((edge){a,0,0,e[a].size()-1});
	}
	int bfs(){
		static int q[N]; int l=0,r=0;
		fill(d+1,d+n+1,0),d[s]=1;
		for(l=r=0,q[r++]=s;l<r;){
			int u=q[l++];
			REP(i,e[u].size()){
				edge &v=e[u][i];
				if(!d[v.v]&&v.f<v.c){
					d[q[r++]=v.v]=d[u]+1;
					if(v.v==t)return 1;
				}
			}
		}
		return 0;
	}
	int dfs(int u,int a){
		if(u==t)return a;
		int res=0; in[u]=1;
		for(int &k=r[u];k<e[u].size();k++){
			edge &v=e[u][k];
			if(v.f<v.c&&d[v.v]==d[u]+1&&!in[v.v]){
				int now=dfs(v.v,min(a,v.c-v.f));
				v.f+=now,e[v.v][v.p].f-=now,res+=now;
				if(!(a-=now))break;
			}
		}
		return in[u]=0,res;
	}
	int flow(){
		int res=0;
		while(bfs()){
			fill(r+1,r+n+1,0);
			res+=dfs(s,inf);
		}
		return res;
	}
}
int A[N],B[N],x[N],y[N];
int n,cnt,a,b,s,t,ans;
map<int,int> E[N];

int main(){
	read(n);
	rep(i,1,n)read(x[i]),++x[i];
	rep(i,1,n)read(y[i]),++y[i];
	rep(i,1,n)if(!A[i]){
		++cnt;
		for(int p=i;!A[p];p=x[p])
			A[p]=cnt;
	}
	rep(i,1,n)if(!B[i]){
		++cnt;
		for(int p=i;!B[p];p=y[p])
			B[p]=cnt;
	}
	s=++cnt,t=++cnt;
	G::init(t,s,t);
	rep(i,1,n){
		a=x[i],b=y[i];
		if(a==i&&b==i)	continue;
		ans++;
		if(a==i)		E[s][B[i]]++;
		else if(b==i)	E[A[i]][t]++;
		else if(a==b)	E[A[i]][B[i]]++,E[B[i]][A[i]]++;
		else			E[A[i]][B[i]]++;
	}
	rep(u,1,cnt)for(auto v:E[u])
		G::add(u,v.fi,v.se);
	printf("%d\n",ans-G::flow());
	return 0;
}

Measured memory_bytes: 64000
import itertools
n = int(input())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))
c = []
for i in range(1,n+1):
	c.append(i)

p_list = list(itertools.permutations(c))
ans = abs(p_list.index(a) - p_list.index(b))
print(ans)


Measured memory_bytes: 10100
N,A,B = map(int,input().split())


sum = 0
for i in range(1,N+1):
    isum = 0
    m = i
    while m != 0:
        isum += m%10
        m = m // 10
    if isum >= A and isum <=B:
        sum += i
print(sum)



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

#define rep(i, a, b) for(lli i  = (lli)(a); i < (lli)(b);i++)
#define REP(i,n) for(lli(i)=0;(i)<(lli)(n);(i)++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(v) (v).size()
#define all(v) (v).begin(), (v).end()
#define trace(x) cerr << #x << ": " << x << endl;

typedef long long int lli;
typedef pair<lli, lli> ii;
typedef pair<ii, lli> iii;
typedef vector<lli> vi;
typedef vector<ii> vii;
typedef double C;

int main(){
	fastio;
	char op;
	lli a,b; cin>>a>>op>>b;
	//char op; cin>>op;
	if(op=='+') cout<<a+b;
	else cout<<a-b;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<string> v;
int a[10];
int main()
{
    int n;
    cin >> n;
    int m ;
    cin >> m;
    for(int i = 0;i < m;i++)
    {
        cin >> a[i];
    }
    int flag = 0;
    for(int i = n; ;i++)
    {
        int j = i;
        while(j)
        {

            flag = 0;
            int x = j % 10;
            for(int q = 0;q < m;q++)
            {
                if(x == a[q])
                {
                    flag = 1;
                    break;
                }
            }
            if(flag)
            {
                break;
            }
            j /= 10;
        }
        if(!flag)
        {
            cout << i << endl;
            return 0;
        }
    }


}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	double x;
	double y;
} POINT;

int intersect(double min, double max, double p){
	if (min <= p && p <= max){
		return (1);
	}
	return (0);
}

int main(void)
{
	POINT a1, a2, b1, b2;
	
	while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &a1.x, &a1.y, &a2.x, &a2.y, &b1.x, &b1.y, &b2.x, &b2.y) != EOF){
		if ((intersect(a1.x, a2.x, b1.x) || intersect(a1.x, a2.x, b2.x) || intersect(b1.x, b2.x, a1.x) || intersect(b1.x, b2.x, a2.x))&&
			(intersect(a1.y, a2.y, b1.y) || intersect(a1.y, a2.y, b2.y) || intersect(b1.y, b2.y, a1.y) || intersect(b1.y, b2.y, a2.y))){
				printf("YES\n");
			}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=INF,cnt,sum; cin>>n;
    vector<ll> a(n,0);
    rep(i,n) cin>>a[i];
    sum=0; cnt=0;
    rep(i,n){
        sum+=a[i];
        if(i%2){
            if(sum>=0){
                cnt+=sum+1;
                sum=-1;
            }
        }
        else{
            if(sum<=0){
                cnt+=1-sum;
                sum=1;
            }
        }
    }
    ans=min(ans,cnt);
    sum=0; cnt=0;
    rep(i,n){
        sum+=a[i];
        if(i%2==0){
            if(sum>=0){
                cnt+=sum+1;
                sum=-1;
            }
        }
        else{
            if(sum<=0){
                cnt+=1-sum;
                sum=1;
            }
        }
    }
    ans=min(ans,cnt);
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int a[100];
int main()
{
	int i,j,k,n,m=1;
	ll x,y;
	scanf("%d%lld",&n,&x);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&y);
		j=0;
		while(y>0)
		{
			a[j]+=y&1;
			y=y>>1;
			j++;
		}
		m=max(m,j);
	}
	j=0;
	ll x1=x;
	while(x>0)
	{
		x=x>>1;
		j++;
	}
	m=max(m,j);
	x=x1;
	bool bo=0;
	for(i=m-1;i>=0;i--)
	{
		if(bo)
		{
			if(a[i]<n-a[i])
			{
				a[i]=n-a[i];
			}
		}
		else
		{
			if(a[i]<n-a[i])
			{
				if((x>>i)&1)
				{
					a[i]=n-a[i];
				}
			}
			else
			{
				if((x>>i)&1)
				{
					bo=1;
				}
			}
		}
	}
	ll ans=0;
	for(i=m-1;i>=0;i--)
	{
		ans+=1ll*a[i]*(1ll<<i);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  ll start, end;

  rep(i, ll(s.size())) {
    if (s[i] == 'A') {
      start = i;
      break;
    }
  }
  rep(i, ll(s.size())) {
    if (s[s.size()-1-i] == 'Z') {
      end = s.size()-i;
      break;
    }
  }

  cout << end - start << endl;

  return 0;
}


Measured memory_bytes: 3716
#include <iostream>
using namespace std;
int main()
{
    int R;
    cin>>R;
    if (R<1200)
    {
        cout<<"ABC";
    }
    else if (1200<=R&&R<2800)
    {
        cout<<"ARC";
    }
    else if (2800<=R&&R<=4208)
    {
        cout<<"AGC";
    }
    return 0;

}


Measured memory_bytes: 256
import java.io.*;

public class Main{
	public static void main(String[] arsg) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		for(int i = 1;i<=count;i++){
			if(i%3==0 || String.valueOf(i).contains("3")){System.out.print(" "+i);}
		}
		System.out.println();
	}
}

Measured memory_bytes: 27628
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<ll> a(n), sum(n);
	rep(i, 0, n - 1)cin >> a[i];
	sum[0] = a[0];
	rep(i, 1, n - 1)sum[i] = sum[i - 1] + a[i];
	map<ll, ll> mp;
	rep(i, 0, n - 1)++mp[sum[i]];
	ll ans = 0;
	for (pair<ll, ll> x : mp)
	{
		ll num = x.second;
		if (x.first == 0)ans += num * (num + 1) / 2;
		else if (num != 1)ans += (num - 1)*num / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 15872
function Main(input) {
    var input = input.split('\n');
    var n = parseInt(input[0], 10);
    var sum = 0;
    for(i = 1; i <= n; i++) {
      var a = input[i].split(' ').map(n => parseInt(n, 10));
      sum += a[1] - a[0] + 1;
    }
    console.log(sum);
 }
  Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7740
#include <stdio.h>
#include <math.h>

int main()
{
    int n;
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if((int)log10(i)%2==0)
        {
            ans++;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128