akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

		int n = stdIn.nextInt();
		int k = stdIn.nextInt();
		int[] w = new int[n];
		long max = 0;
		long acc = 0;

		for (int i=0; i<n; i++) {
			w[i] = stdIn.nextInt();
			acc += w[i];
			max = Math.max(max,w[i]);
		}

		long left = max;
		long right = acc;

		while (left < right) {
			long p = (left+right)/2;
			int id = 0;
			long sum = 0;
			for (int i=0; i<n; i++) {
				if (sum+w[i] > p) {
					sum = w[i];
					id++;
				}else {
					sum += w[i];
				}
				if (id == k)
					break;
			}
			if (id == k)
				left = p+1;
			else
				right = p;
		}
		System.out.println(left);

		stdIn.close();
	}
}

Measured memory_bytes: 64656
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/PCK/Prelim/0361?year=2017

#include <bits/stdc++.h>

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;

    cout << x + y - __gcd(x, y) + 1 << endl;
    return 0;
}

/*
 * 端点を除いて考える。
 * 縦x-1本，横y-1本の直線すべてと交点をもつ。
 * 重複分はgcd(x,y)-1個。これらに端点を加えると
 * (x-1)+(y-1)-(gcd(x,y)-1)+2
 * =x+y-gcd(x,y)+1個
 *
 */


Measured memory_bytes: 3104
// AOJ 0212
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;

const int INF = 10000000;

int c, n, m, s, d;	
std::vector<P> G[101];
int dist[101][11];

int dijkstra( int s )
{
	std::fill( (int*)dist, (int*)(dist+101), INF );
	dist[s][0] = 0;
	std::priority_queue<PP, std::vector<PP>, std::greater<PP> > pque;
	pque.push( PP( P( s, 0 ), 0 ) );
	while( !pque.empty() )
	{
		PP p = pque.top(); pque.pop();
		int v = p.first.first, cost = p.first.second, tic = p.second;

		if( dist[v][tic] < cost )
			continue;

		rep( i, G[v].size() )
		{
			P &e = G[v][i];

			if( dist[e.first][tic] > dist[v][tic]+e.second )
			{
				dist[e.first][tic] = dist[v][tic]+e.second;
				pque.push( PP( P( e.first, dist[e.first][tic] ), tic ) );
			}
		}

		if( tic < c ) rep( i, G[v].size() )
		{
			P &e = G[v][i];

			if( dist[e.first][tic+1] > dist[v][tic]+e.second/2 )
			{
				dist[e.first][tic+1] = dist[v][tic]+e.second/2;
				pque.push( PP( P( e.first, dist[e.first][tic+1] ), tic+1 ) );
			}
		}
	}

	return *std::min_element( dist[d], dist[d]+11 );
}

int main()
{
	while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d )
	{
		rep( i, 101 )
			G[i].clear();

		rep( i, m )
		{
			int a, b, f;
			scanf( "%d%d%d", &a, &b, &f );
			G[a].push_back( P( b, f ) );
			G[b].push_back( P( a, f ) );
		}

		printf( "%d\n", dijkstra( s ) );
	}

	return 0;
}

Measured memory_bytes: 1144
public class Main {
    public static void main(String args[]) {
        for(int i = 1; i <= 9; i++) {
            for(int j = 1; j <= 9; j++) {
                // ?¨??????????
                System.out.println(""+i+'x'+j+'='+(i*j));
            }
        }
    }
}

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

int main() {
  string w;
  cin >> w;
  if (w == "Sunny") {
    cout << "Cloudy" << endl;
  }
  if (w == "Cloudy") {
    cout << "Rainy" << endl;
  }
  if (w == "Rainy") {
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int W,H,x,y,r,f;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  f=0;
  if(x+r>W)f=1;
  if(y+r>H)f=1;
  if(r>x)f=1;
  if(r>y)f=1;

  if(f==0){printf("Yes\n");}
  else{printf("No\n");}
  return 0;
}

Measured memory_bytes: 584
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    string s = inp1;
    string t = inp1;

    cout << t << s << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main (void) {
    ll X;
    ll Y;
    ll Z;
    ll ans = 0;

    cin >> X >> Y >> Z;

    for (ll i = 1; i <= X; i++) {
        if (Y * i + Z * (i + 1) <= X) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int A,B,num=0;
vector<int>p,q;

void dfs(int n,int dp[],int cnt,bool seen[]){

    // for(int i=1;i<=n;i++){
    //     if(seen[i]) cout <<"o";
    //     else cout << "x";
    // }
    //cout << endl;
    for(int i=1;i<n+1;i++){
        if(!seen[i]){
            seen[i]=true;
            dp[cnt] = i;
            dfs(n,dp,++cnt,seen);
            cnt--;
            seen[i] = false;
        }
        
    }
    if(cnt==n){
        num++;
        //cout << num << endl;
        //for(int i=0;i<n;i++) cout << dp[i] << " ";
        //cout << endl;
        bool judge = true;
        for(int i=0;i<n;i++){
            if(p[i] != dp[i]){
                judge = false;
                break;
            }
            
        }
        if(judge) A = num;
        judge = true;
        for(int i=0;i<n;i++){
            if(q[i] != dp[i]){
                judge = false;
                break;
            }
        }
        if(judge) B = num;

    }
    
}

int main(){
    int n;
    cin >> n;
    q.reserve(n);
    p.reserve(n);

    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        p.push_back(a);
    }
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        q.push_back(a);
    }
    int a[n];
    bool seen[n+1];
    memset(seen,false,sizeof(seen));

    dfs(n,a,0,seen);

    cout << abs(A-B) << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())

A = list(map(int, input().split()))

C = list(set(A))

B = len(C) 
x = B - K

d = {}

for i in A:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

d = sorted(d.items(), key=lambda x:x[1])

ans = 0
count = 0

if x<=0:
    print('0')
else:
    for key, value in d:
        ans = ans + value
        count = count + 1
        if count == x:
            print(ans)
            break

Measured memory_bytes: 49816
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
 { 
	
	public static void main (String[] args)
	 {
Scanner scan=new Scanner(System.in);

	    
	    int a=scan.nextInt();
	    int b=scan.nextInt();
	    int c=scan.nextInt();
	   int k=scan.nextInt();
	   int i=0;
	   int sum=0;
	   if(k>=a)
	  { sum+=a;
		  k=k-a;
	  }
	  else
	    {sum=k;
			k=0;
		}
		if(k>=b)
		k=k-b;
		else k=0;
		if(k>=c)
		sum=sum-c;
	    else sum=sum-k;
	   
	System.out.println(sum);
   
   }
	   
	 }



Measured memory_bytes: 35776
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for aa in range(a+1) :
	for bb in range(b+1) :
		for cc in range(c+1):
			ans = aa * 500 + bb * 100 + cc * 50
			if ans == x :
				count += 1
print(count)


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

s = input().rstrip()
n = len(s)

s1 = s[:(n - 1) // 2]
s2 = s[(n + 3) // 2 - 1:]

if s == s[::-1] and s1 == s1[::-1] and s2 == s2[::-1]:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 38384
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
count = 0
for i in range(N-1):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k] - X[j][k])**2
        if float.is_integer(dist ** (1/2)):
            count += 1
print(count)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,k,s;
int main(){
	cin>>n>>k>>s;
	for(int i=0;i<k;i++)
	cout<<s<<" ";
	n-=k;
	if(s<=n){
		for(int i=0;i<n;i++)
		cout<<s+1<<" ";
	}else
	for(int i=0;i<n;i++)
	cout<<1<<" ";
	re 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,a[100][100]={};
  long long b,c,ans=0,d=1;
  cin>>n;
  for(int i=1;i<=n;i++){
    b=i;
    while(b>9){
      b/=10;
    }
    c=i%10;
    if(b==c){
      ans++;
      if(a[c][b]!=0){
      /*/for(int j=0;j<a[c][b];j++)
        d*=2;/*/
      ans+=a[c][b]*2;
      d=1;
      }
    }
    if(b!=c && a[c][b]!=0){
       /*/for(int j=0;j<a[c][b];j++)
        d*=2;/*/
      ans+=a[c][b]*2;
      d=1;
    }
    a[b][c]++;
  }
  cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 384
fun main(args:Array<String>):Unit {
  val sc = java.util.Scanner(System.`in`)
  val n = sc.nextInt()
  println((1..n).filter { it % 2 == 1 }.filter { v ->
    (1..v).asSequence().filter { v % it == 0 }.count() == 8
  }.count())
}

Measured memory_bytes: 31648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////

int main() {
	string S, T;
	cin >> S >> T;
	bool flag = false;
	bool ok = true;
	for (int i = S.size()-T.size(); i >= 0; --i) {
		ok = true;
		if (S[i] == '?' || S[i] == T[0]) {
			for (int j = i; j < i + T.size(); ++j) {
				if (S[j] == '?' || S[j] == T[j - i]) {
					continue;
				}
				else {
					ok = false;
					break;
				}
			}
			if (ok) {
				for (int j = i; j < i + T.size(); ++j) {
					S[j] = T[j - i];
				}
				flag = true;
				break;
			}
		}
	}
	if (flag) {
		for (int i = 0; i < S.size(); ++i) {
		    if (S[i] == '?') {
				S[i] = 'a';
			}
		}
		cout << S << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}
	return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 998244353;

const int MAXN = 2e2 + 5;

pii pp[MAXN];

ll st2[MAXN];

int cross(int i, int j, int k){
	return (pp[j]._1 - pp[i]._1) * (pp[k]._2 - pp[i]._2) - (pp[k]._1 - pp[i]._1) * (pp[j]._2 - pp[i]._2);
}

int used[MAXN][MAXN];

vi tmp;

ll get_val(int n){
	ll ans = st2[n];
	ans = (ans - 1 - n + MOD) % MOD;
	return ans;
}

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n){
		scanf("%d%d",&pp[i]._1, &pp[i]._2);
	}
	st2[0] = 1;
	REPN(i, 1, n){
		st2[i] = (st2[i - 1] * 2ll) % MOD;
	}
	
	ll ans = get_val(n);
	//printf("%lld\n", ans);
	REP(i, 0, n){
		REP(j, i + 1, n){
			if (used[i][j]){
				continue;
			}
			tmp.clear();
			REP(k, 0, n){
				if (cross(i, j, k) == 0){
					tmp.pb(k);
				}
			}
			REP(k, 0, SZ(tmp)){
				REP(l, k + 1, SZ(tmp)){
					used[tmp[k]][tmp[l]] = 1;
				}
			}
			
			ll delta = get_val(SZ(tmp));
			ans = (ans - delta + MOD) % MOD;
			//printf("%d %d %lld\n", i, j, ans);
		}
	}	
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 384
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N;
    cin >> N;
    llong ans=0;
    vector<llong> P(N,0);
    llong temp;
    for(int i=0; i<P.size(); i++){
        cin >> P[i];
    }
    for(int i=0; i<N-1; i++){
        if(P[i]==(i+1)){
            temp = P[i];
            P[i] = P[i+1];
            P[i+1] = temp;
            ans++;
        }
    }
    if(P[P.size()-1]==(P.size())){
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3660
n = int(input())
record=[[[0 for r in range(10)] for f in range(3)] for b in range(4)]
for i in range(n):
    b,f,r,v = [int(x) for x in input().split()]
    record[b-1][f-1][r-1]+=v
for b in range(4):
    for f in record[b]: print(" "+" ".join([str(x) for x in f]))
    if b != 3:
        print("#"*20)

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

int main()
{
  int n;
  cin >> n;
  vector<int> b(n - 1), a(n);
  for (int i = 0; i < n - 1; i++)
  {
    cin >> b[i];
  }
  int ans = b[0] + b[n - 2];
  //cout << ans << endl;
  for (int i = 0; i < n - 2; i++)
  {
    ans += min(b[i], b[i + 1]);
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

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

  vector<int> six;
  six.push_back(1);
  for(int i=6;i<=N;i*=6)  six.push_back(i);
  vector<int> nine;
  nine.push_back(1);
  for(int i=9;i<=N;i*=9)  nine.push_back(i);

  int ans=N;
  for(int i=0;i<=N;i++){
    int si=i;
    int ni=N-i;
    int count=0;
    for(int j=six.size()-1;j>=0;j--){
      count+=si/six.at(j);
      si%=six.at(j);
    }
    for(int j=nine.size()-1;j>=0;j--){
      count+=ni/nine.at(j);
      ni%=nine.at(j);
    }
    ans=min(ans,count);
  }
  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<int, pair<int, int>> piii;
//loop
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//STL
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

const int INF = 1e9;
int H, W, K;

bool valid(int x, int y)
{
    return (x >= 0 && x < H && y >= 0 && y < W);
}

void Main()
{
    cin >> H >> W >> K;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    // 0始まりとする
    x1--;
    y1--;
    x2--;
    y2--;

    // 各方角での移動量 (0: 北, 1: 南, 2: 西, 3: 東)
    int dx[] = {1, -1, 0, 0};
    int dy[] = {0, 0, -1, 1};

    // グリッド読み込み
    vector<string> grid(H);
    REP(i, H)
    {
        cin >> grid.at(i);
    }

    // 各グリッドへの到達可能な最短水かき回数
    vector<vector<int>> scores(H, vector<int>(W, INF));

    priority_queue<piii, vector<piii>, greater<piii>> que;
    que.push(MP(0, MP(x1, y1)));
    while (!que.empty())
    {
        // 最短経路を取得
        piii p = que.top();
        que.pop();
        // ここまでの最短水かき回数
        int score = p.first;
        // 現在の座標
        int x = p.second.first, y = p.second.second;

        // ゴールについていれば、距離を出力して終了
        if (x == x2 && y == y2)
        {
            cout << score << endl;
            return;
        }

        // 各方角で、各座標毎の距離を算出
        REP(i, 4)
        {
            FOR(d, 1, K)
            {
                // 移動先の座標
                int nx = x + dx[i] * d;
                int ny = y + dy[i] * d;

                // グリッドの範囲内かつ移動可能かチェック
                // 移動不可能の場合、それ以上進めない。故にこの方角での探索を終了する
                if (!valid(nx, ny))
                {
                    break;
                }
                if (grid.at(nx).at(ny) == '@')
                {
                    break;
                }

                // 計算済みの最短水かき回数より少ない回数で移動できるとき
                if (scores.at(nx).at(ny) > score + 1)
                {
                    // 最短水かき回数を更新
                    scores.at(nx).at(ny) = score + 1;
                    // 次点での最短水かき回数候補に追加
                    que.push(MP(score + 1, MP(nx, ny)));
                }
                // 計算済みの最短水かき回数と同一ならば、さらに移動して探索続行
                else if (scores.at(nx).at(ny) == score + 1)
                {
                    continue;
                }
                // 計算済みの最短水かき回数よりも、必要な水かき回数が多い場合は探索終了。
                // なぜならば、以降の移動経路では最短水かき回数とはなり得ないため。
                else
                {
                    break;
                }
            }
        }
    }

    // ゴールへとたどり着けない場合
    cout << -1 << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 12172
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int x[100009];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>x[i];
  }
  x[0]=0;
  x[n+1]=0;
  n+=2;

  int sum=0;
  for(int i=0;i<n-1;i++){
    sum+=abs(x[i]-x[i+1]);
  }
  for(int i=1;i<n-1;i++){
    cout<<sum-abs(x[i]-x[i-1])-abs(x[i]-x[i+1])+abs(x[i-1]-x[i+1])<<endl;
  }
  return(0);
}


Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main()
{
    int L,R,n;
    cin>>L>>R>>n;
    int x=R-L+1;
    int L1=L;
    int cont=0;
    for(int i=0;i<x;i++)
    {
        if((L1+i)%n==0)
        {
            cont++;
        }
    }
   cout<<cont;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
//#include <vector>

int main(int argc, char* argv[])
{
    char str0[202]={0};
    scanf("%s", str0);

    char str1[101]={0};
    scanf("%s", str1);

    long len = strlen(str0);

    long i;
    for(i=0; i<len; i++) {
        str0[len+i]=str0[i];
    }
    for(i=0; i<len; i++) {
        if( strncmp( str0+i, str1, len ) == 0 )
            break;
    }
    if(i<len) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s;
  cin>>t;
  if(t.size()>s.size()){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }
  int a=0;
  for(int i=s.size()-t.size();i>=0;i--){
    int che=1;
    for(int j=i;j<i+t.size();j++){
      if(s[j]==t[j-i] || s.at(j)=='?'){
        continue;
      }
      else{
        che=0;
        break;
      }
    }
    if(che==1){
      for(int j=i;j<i+t.size();j++){
        s[j]=t[j-i];
      }
      a=1;
      break;
    }
  }
  if(a==1){
    for(int i=0;i<s.size();i++){
      if(s.at(i)=='?') s.at(i)='a';
    }
    cout<<s<<endl;
  }
  else cout<<"UNRESTORABLE"<<endl;
}

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

int main() {
    int a, b;

    for(int i = 0; i < 250; i++){
      a = 0, b = -1;
      cin >> a >> b;

      if(a + b == -1){
        break;
      }
      else{
        int digit = 0;
        int sum = a + b;
        while(sum > 0){
          sum = sum / 10;
          digit += 1;
        }
        cout << digit << endl;
      }
    }
    
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int a, p;
  cin >> a >> p;
  p += a * 3;
  cout << p / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		Integer[] a = arrayInteger(sc, n);
		sc.close();
		Arrays.sort(a, Comparator.reverseOrder());
		long ans = 0;
		for (int i = 0; i < n; i++) {
			if (i < k) {
				ans += 0;
			} else {
				ans += a[i];
			}
		}
		System.out.println(ans);
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static Integer[] arrayInteger(Scanner sc, int n) {
		Integer[] array = new Integer[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}

Measured memory_bytes: 94976
/*
[abc138] F - Coincidence
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_D = 64;
const ll MOD = 1e9 + 7;

ll L, R;
ll memo[MAX_D][2][2][2];

ll f(int d, int m, int l, int r) {
    if (d == -1) {
        return m == 1;
    }
    if (memo[d][m][l][r] >= 0) {
        return memo[d][m][l][r];
    }

    ll ret = 0;
    for (int a = 0; a < 2; a++) {
        for (int b = 0; b < 2; b++) {
            if ((l && a < ((L >> d) & 1)) || (r && b > ((R >> d) & 1)) ||
                (a > b) || (!m && a != b)) {
                continue;
            }
            int nm = m || (a & b);
            int nl = l && (((L >> d) & 1) == a);
            int nr = r && (((R >> d) & 1) == b);
            (ret += f(d - 1, nm, nl, nr)) %= MOD;
        }
    }
    return memo[d][m][l][r] = ret;
}

ll solve() {
    memset(memo, -1, sizeof(memo));
    return f(MAX_D - 1, 0, 1, 1);
}

int main() {
    cin >> L >> R;

    cout << solve() << endl;

    return 0;
}


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

using namespace std;

int main() {
  int N, K, Q;

  cin >> N >> K >> Q;

  vector<int> P(N, 0);
  for (int i = 0; i < Q; i++) {
    int A;
    cin >> A;
    P[A-1] += 1;
  }

  for (int i = 0; i < N; i++) {
    int p = K - (Q - P[i]);
    if (p <= 0) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
n = int(input())
x = list(map(int, input().split()))

y = sorted(x)

median1 = y[n // 2 - 1]
median2 = y[n // 2]

# print(y, median1, median2)

if median1 == median2:
    for i in range(n):
        print(median1)
else:
    for i in range(n):
        if x[i] <= median1:
            print(median2)
        else:
            print(median1)

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

max_A = max(A)
table = [False]*(max_A+1)
for i in A:
    if table[i] == False:
        table[i] = True
    else:
        table[i] = -1

mem = []        
for i in A:
    if table[i] == -1:
        table[i] = True
        mem.append(i)

for i in range(1, max_A+1):
    if table[i] == True:
        n = 2
        while i*n < max_A+1:
            table[i*n] = False
            n += 1

for i in mem: 
    if table[i] == True:
        table[i] = False
        
print(table.count(True))

Measured memory_bytes: 33232
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		int[][] nums = new int[3000][2];
		int temp;
		int count = 0;
		Scanner s = new Scanner(System.in);
		for(int i =0;i<3000;i++) {
			nums[i][0] = s.nextInt();
			nums[i][1]= s.nextInt();
			if(nums[i][0]>=0 && nums[i][1]>=0 && nums[i][0]<=10000 && nums[i][1]<=10000) {
			if(nums[i][0]>nums[i][1]) {
				temp = nums[i][0];
				nums[i][0] = nums[i][1];
				nums[i][1] = temp;
				
			}
			if(nums[i][0]==0 && nums[i][1]==0) {
				count = i;
				break;
			}
			}
		}
		
		for(int j=0;j<count;j++) {
			System.out.println(nums[j][0]+" "+nums[j][1]);
		}
	}

}

Measured memory_bytes: 36340
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_153
{
    class E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] hn = ReadInts();
            int h = hn[0];
            int n = hn[1];
            int[][] abs = new int[n][];
            for (int i = 0; i < n; i++)
            {
                abs[i] = ReadInts();
            }
            int[] dp = new int[h + 1];
            for (int i = 0; i <= h; i++)
            {
                dp[i] = int.MaxValue / 4;
            }
            dp[h] = 0;
            for (int i = h; i > 0; i--)
            {
                for (int j = 0; j < n; j++)
                {
                    int next = Max(i - abs[j][0], 0);
                    dp[next] = Min(dp[next], dp[i] + abs[j][1]);
                }
            }
            WriteLine(dp[0]);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using namespace std;

#define ll long long
#define M 1005000
#define ii pair<ll, ll>
#define fi first
#define se second



int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x = (int)log10(i) + 1;
        if (x&1) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}


long long int N;
long long int ans;
long long int H, W;
long long int K;

long long int dp[101][13333];
long long int num[101];

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	for (int i = 0; i < 101; i++)dp[i][0] = 1;
	for (int i = 1; i <= N; i++)cin >> num[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10001; j++) {
			dp[i + 1][j] += dp[i][j];
			dp[i + 1][j] %= MOD;
			dp[i + 1][j + num[i + 1]] += dp[i][j];
			dp[i + 1][j + num[i + 1]] %= MOD;
		}
	}
	for (int i = 10000; i >= 0; i--) {
		//if (dp[N][i])cout << i << endl;
		if (i % 10 && dp[N][i]) {
			cout << i << endl;
			return 0;
		}
	}
	cout << "0\n";
	return 0;
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
#define int long long
#define N 200000
using namespace std;
int n, mod = (int)(1e9 + 7);

string s;

int dp[N][2];

int solve(int i, int flag)
{
	if(i >= n) return 1;

	if(dp[i][flag] != -1) return dp[i][flag];

	if(flag == 1) // SEM RESTRICOES	
	{
		return  dp[i][flag] = (3*solve(i + 1, 1))%mod;
	}
	else
	{
		if(s[i] == '0') return  dp[i][flag] = solve(i + 1, 0);

		return  dp[i][flag] = (solve(i + 1, 1) + 2*solve(i + 1, 0))%mod;
	}
}

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

	memset(dp, -1, sizeof dp);

	cin>>s;

	n = s.size();

	cout<<solve(0, 0)<<"\n";
}

Measured memory_bytes: 8272
d=input().split()
for _ in range(int(input())):
 t, f =[d.index(s)for s in input().split()]
 n = [(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])


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

#define ff first
#define ss second

struct job {
	ll duration;
	ll deadline;
};

bool mysort(const job& lhs, const job& rhs) {
	return (lhs.deadline == rhs.deadline) ? (lhs.duration < rhs.duration) : (lhs.deadline < rhs.deadline);
}

int main()
{
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<job> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i].duration >> A[i].deadline;
	}

	sort(A.begin(), A.end(), mysort);
	int timer = 0;
	bool valid = 1;
	for (int i = 0; i < N; ++i) {
		timer += A[i].duration;

		if (timer > A[i].deadline) {
			valid = 0;
			break;
		}
	}

	if (valid) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3456
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(H: int, N: int, A: "List[int]"):
    if H > sum(A):
        no()
    else:
        yes()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(H, N, A)


if __name__ == '__main__':
    main()


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

inline int read(int&x){
	char c11=getchar();x=0;while(!isdigit(c11))c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();return x;
}

const int N=101000;
int a[N],b[N],n,c1,c2;

int main(){
	read(n);
	for(int i=1;i<=n;++i)b[i]=read(a[i]);
	sort(b+1,b+n+1);
	for(int i=1;i<=n;++i)
		if(i&1)
			{if(!((lower_bound(b+1,b+n+1,a[i])-b)&1))++c1;}
		else
			{if((lower_bound(b+1,b+n+1,a[i])-b)&1)++c2;}
	printf("%d\n",max(c1,c2));
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define mod 1000000007

bool compare(ll a, ll b)
{
    return a > b;
}

int main() {
    fio;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n, compare);
    ll ans = a[0];
    ll k = n - 1, index = 1;
    while (k > 2) {
        ans += (2 * a[index]);
        k = k - 2;
        index++;
    }
    if (k == 2) {
        ans += a[index];
    }
    cout << ans << endl;
}

Measured memory_bytes: 5112
#include<bits/stdc++.h> 
using namespace std;
int main(int argc, char const *argv[])
{
   int x, n;
   cin >> x >> n;
   vector<int> f(105, 0);
   for (int i = 0; i < n; ++i)
   {
       int num;
       cin >> num;
       f[num] = 1;
   }
   set<int> s;
   for (int i = 0; i < 105; ++i)
   {
       if (!f[i])
        s.insert(i);
   }
   int cd = INT_MAX, ans = -1;
   for (int num: s)
   {
        if (abs(num - x) < cd)
        {
            cd = abs(num - x);
            ans = num;
        }
   }
   cout << ans;
   return 0;
}

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

int main()
{
    string a, b;
    bool ans = false;
    cin >> a >> b;
    int l = a.size();

    for (int i = 0; i < l; i++) {
        int cnt = 0;
        bool sw = true;

        for (int j = 0; j < l; j++) {
            if (sw && i + j < l && a[i + j] == b[j]) cnt++;
            else sw = false;

            if (sw == false && i + j >= l && a[i + j - l] == b[j]) cnt++;
        }

        if (cnt == l) ans = true;
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int h, w, m, u, v;
    cin >> h >> w >> m;
    unordered_map<int, unordered_set<int>> row;
    unordered_map<int, unordered_set<int>> col;
    for(int i = 0; i < m; i++) {
        cin >> u >> v;
        row[u].insert(v);
        col[v].insert(u);
    }
    map<int, vector<int>> freq_r;
    map<int, vector<int>> freq_c;
    for(auto& [r, c]: row)  {
        freq_r[c.size()].push_back(r);
    }
    for(auto& [c, r]: col) {
        freq_c[r.size()].push_back(c);
    }
    int num_r = prev(freq_r.end())->first;
    auto rs = prev(freq_r.end())->second;
    int num_c = prev(freq_c.end())->first;
    auto cs = prev(freq_c.end())->second;
    int ans = num_r + num_c - 1;
    for(int r: rs) {
        for(int c: cs) {
            if (row[r].count(c) == 0) {
                cout << (ans+1) << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return  0;
}


Measured memory_bytes: 100460
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
//set<ll> s;
//vll v;
ll x;
ll t[51];
ll p[51];
ll recur(ll x,int level)
{
    if(level==0)
    {
        if(x<=0)
        return 0;
        else
        return 1;
    }
   if(x<=(t[level-1]+1))
   {
       return recur(x-1,level-1);
   }
   else
   {
       return p[level-1]+1+recur(x-2-t[level-1],level-1);
   }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	cin>>x;
	t[0]=1;
	p[0]=1;
	for(int i=1;i<51;i++)
	{
	    t[i]=2*t[i-1]+3;
	    p[i]=2*p[i-1]+1;
	}
	cout<<recur(x,n);
}

Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
sys.setrecursionlimit(10**6)

def main():
    maxn = 1005
    maxv =  maxn * (maxn-1) // 2
    to = [[] for _ in range(maxv)] # 頂点間の辺の情報
    id = [[[] for _ in range(maxn)] for _ in range(maxn)] # 試合のid=DAGの頂点番号
    
    def toId(i,j): # 選手idから試合idを返す関数
        if i > j: # i,jが逆になっても試合idは同じ
            i,j = j,i
        return id[i][j]

    visited = [False]*maxv
    calculated = [False]*maxv
    dp = [1]*maxv # Vからスタートしたときの最長経路。頂点の個数ベースで経路の長さを数えるので、初期値は1

    def dfs(v):
        if visited[v]:
            if not calculated[v]:
                return -1 # 計算が終わっていない頂点を2度訪れるのはループがあるということ
            return dp[v]
        visited[v] = True
        for u in to[v]: # 全ての辺をなめる
            res = dfs(u)
            if res == -1: return -1 # ループがあれば-1を返す
            dp[v] = max(dp[v], res+1)
        calculated[v] = True
        return dp[v]

    n = int(input())
    a = [nl() for _ in range(n)]
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1 # 選手idを0始まりに変換
    V = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                id[i][j] = V
                V += 1 # 0から順に各試合にidを割り振る
    for i in range(n):
        for j in range(n-1):
            a[i][j] = toId(i,a[i][j]) # 選手idを試合id(頂点番号)に置き換える
        for j in range(n-2): # 頂点間の依存関係はn-2個
            to[a[i][j+1]].append(a[i][j])
    ans = 0
    for i in range(V):
        res = dfs(i)
        if res == -1:
            print('-1') # ループがあれば-1を返す（問題文の指示）
            return
        ans = max(ans, res)
    print(ans)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 246256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(m)]

ans = []
for man in ab:
    min_dis = float("inf")
    place = 0
    for i in range(m):
        cp = cd[i]
        dis = abs(cp[0] -man[0]) + abs(cp[1] -man[1])

        if dis < min_dis:
            min_dis = dis
            place = i + 1

    ans += [place]

for i in ans:
    print(i)

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

int main(){
    ll n,X;
    cin >> n >> X;
    vector<ll> x(n);
    rep(i,n){
        cin >> x[i];
        x[i] -= X;
    }
    long long g = abs(x[0]);
    rep(i,n) g = __gcd(g,abs(x[i]));
    cout << g << endl;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m a 
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(N); rep(i, N) cin >> a[i];
 
  ll ans = 0;

  ll cnt = 0;
  rep1(i, N - 1) {
    if(a[i] <= a[i - 1]) {
      cnt ++;
      chmax(ans, cnt);
    } else {
      cnt = 0;
    }
  }

  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  long long A,B,X;
  cin>>A>>B>>X;
  
  
  long long ans=B/X;
  if(A==0){
    ans++;
  }
  else{
    ans=ans-(A-1)/X;
  }
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
int count = 0;
string s;
cin >> s;

for(int i = 0;i<3;i++){
	if(s[i] == s[i+1])
		count++;
}

if(count == 0)
	cout<< "Good"<<endl;
else
cout<<"Bad"<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
   int a,b;cin>>a>>b;
   cout<<a*b<<endl;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main()
{
	int n, a; scanf ("%d", &n); while (n--){
		scanf ("%d", &a);
		if (a % 2 == 0){
			if (a % 3 == 0 || a % 5 == 0);
			else{
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int main()
{
  int N,max=0,i,sum=0;
  scanf("%d", &N);
  int Array[N];
  for(i=0;i<N;i++){
    Array[i]=0;
    scanf("%d",&Array[i]);
    if(max<Array[i]){
      sum+=max;
      max=Array[i];
    }else{
      sum+=Array[i];
    }
  }
  sum+=max/2;
  printf("%d",sum);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
using namespace std;

int main(){
	int n;
	vector <double> v;
	double a,ans;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	ans=v[0];
	for(int i=1;i<n;i++){
		ans=(ans+v[i])/2;
	}
	cout<<setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+6;
int a[maxn];
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=n;i>=2;i--)
	{
		if(a[i]<a[i-1])
		{
			a[i-1]--;
		}
	}
	int flag=1;
	for(int i=1;i<n;i++)
	{
		if(a[i]>a[i+1]) flag=0;
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
 } 

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,K;
	cin >> N >> K;
	if(K % 2 == 1) {
      	int ret = pow(N / K,3);
		cout << ret << endl;
	}
	else {
      	int ret = pow(N / K,3) + pow(N / (K / 2) - N / K,3);
		cout << ret << endl;
	}
}

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

int main(){
	int n;
  	cin >> n;
  	double ans = 2 * n * M_PI;
  	cout << ans << endl;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string S,T;
 cin >> S >>T;
  map<char,char> ma,ima;
  bool flag = true;
  
  for(int i = 0;i<S.size();i++){
    char s = S[i];
    char t = T[i];
    if(ima.count(t)){
      if(ima[t] != s) flag = false;
    }
    if(ma.count(s)){
      if(ma[s] != t) flag = false;
    }
    ma[s] = t;
    ima[t] = s;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No"<<endl; 
}

Measured memory_bytes: 776
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n, m;
	cin >> n >> m;
	int a,ans=0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a >= m)ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256