akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define chmin(x,y) x = min(x,y)
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<int>> dist(n, vector<int> (n, INF));
    rep(i, n) dist[i][i] = 0;
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        dist[a][b] = dist[b][a] = c;
    }
    rep(k,n)rep(i,n)rep(j,n) chmin(dist[i][j], dist[i][k]+dist[k][j]);
    vector<vector<int>> dist2(n, vector<int>(n,INF));
    rep(i,n)rep(j,n) {
        if (dist[i][j] <= l) dist2[i][j] = 1;
    }
    rep(k,n)rep(i,n)rep(j,n) chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
    int Q;
    cin >> Q;
    rep(i, Q) {
        int s, t;
        cin >> s >> t;
        --s; --t;
        if (dist2[s][t] == INF) puts("-1");
        else cout << dist2[s][t] - 1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 4328
#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 pb push_back
#define mp make_pair
#define pr pair<int, int>
#define x first
#define y second
using namespace std;

template<typename T>
void read(T& n){
	char ch; int sign = 1;
	while (!isdigit(ch = getchar())) if (ch == '-') sign = -1;
	n = ch - '0';
	while (isdigit(ch = getchar())) n = n * 10 + ch - '0';
	n *= sign;
}
typedef long long ll;
const int INF = 1e9 + 7;
const int N = 122;
int n, h, w;
int a[N*N], ans[N][N];

int main(){
	read(h), read(w), read(n);
	rep(i, 1, n) read(a[i]);
	int x = 1, y = 0, dir = 1;
	for (int i = 1; i <= n; ++i){
		rep(j, 1, a[i]){
			y += dir;
			if (y > w) x++, y--, dir *= -1;
			if (y <= 0) x++, y++, dir *= -1;
			ans[x][y] = i;
		}
	}
	rep(i, 1, h) rep(j, 1, w) printf("%d%c", ans[i][j], " \n"[j == w]);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  ll N;
  string S;
  set<string> snum;
  cin >> N;
  
  rep(i,N){
    cin >> S;
    snum.insert(S);
  }
  
  cout << snum.size() << endl;
  
}

Measured memory_bytes: 19220
A,B,C,X,Y = list(map(int,input().split()))

if A + B < 2 * C:
    ans = A*X+B*Y
else:
    if X <= Y:
        ans = C * 2 * X
        if 2*C <= B:
            ans += 2*C*(Y-X)
        else:
            ans += B * (Y-X)
    else:
        ans = C * 2 * Y
        if 2*C <= A:
            ans += 2*C*(X-Y)
        else:
            ans += A * (X-Y)

print(ans)


Measured memory_bytes: 61940
#include <iostream>

int main() {
    int a, b, c, x;
    long long ans = 0;
    std::cin >> a >> b >> c >> x;
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            for (int k = 0; k <= c; ++k) {
                if (i * 500 + j * 100 + k * 50 == x) {
                    ++ans;
                }
            }
        }
    }
    std::cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

vector<ll> a;

map<ll, ll> mp;
ll sum;

void solve() {
  ll b,c; cin >> b >> c;
  sum -= mp[b]*b;
  sum += mp[b]*c;
  mp[c] += mp[b]; 
  mp[b] = 0;
  printf("%lld\n", sum);
}

int main() {
  int n; cin >> n;
  a.resize(n);
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  int q; cin >> q;
  rep(i,q) solve();
  return 0;
}

Measured memory_bytes: 10176
n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))

max = 2000

def solve(x,y):
    if x==n:
        S[y] = 1
    else:
        solve(x+1,y)
        if y+A[x] < max+1:
            solve(x+1,y+A[x])
            
S = [0 for i in range(max+1)]

solve(0,0)
    
for i in range(m):
    if S[B[i]] == 1:
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

///////////////////////////
#define INF 1000000009
#define MAX_V 1000000
typedef pair<ll, ll> p;
struct edge{ll to, cost;};
std::vector<std::vector<edge> > G(MAX_V);
priority_queue<p, std::vector<p>, greater<p> > que; //class, inner, compair
std::vector<ll> d(MAX_V+1, INF);
void dijkstra(int start){
  d[start]=0;
  que.push(p(0, start));
  while(!que.empty()){
    p p_now=que.top(); que.pop();
    ll v = p_now.second;
    if(d[v]<p_now.first) continue;
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      if(d[e.to]>d[v]+e.cost){
        d[e.to]=d[v]+e.cost;
        que.push(p(d[e.to], e.to));
      }
    }
  }
}
/////////////////////////////////////////////
int main(int argc, char const *argv[]) {
  int H, W, K, ans = 0, dist=1000000007;
  int N = 810;
  pair<int, int> Start;
  std::cin >> H >> W >> K;
  std::vector<string> room(H);
  for(int i=0;i<H;i++){
    std::cin >> room[i];
    for(int j=0;j<W;j++) if(room[i][j]=='S') Start=make_pair(i, j);
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(room[i][j]!='#'){
        if((i==0?false:room[i-1][j]!='#')) G[i*N+j].push_back(edge{(i-1)*N+j, 1});
        if((j==0?false:room[i][j-1]!='#')) G[i*N+j].push_back(edge{i*N+(j-1), 1});
        if((i==H-1?false:room[i+1][j]!='#')) G[i*N+j].push_back(edge{(i+1)*N+j, 1});
        if((j==W-1?false:room[i][j+1]!='#')) G[i*N+j].push_back(edge{i*N+(j+1), 1});
      }
    }
  }
  dijkstra(Start.first*N+Start.second);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(d[i*N+j]<=K) {
        dist = min({dist, i, j, W-j-1, H-1-i});
      }
    }
  }
  ans = 1 + dist/K + (dist%K!=0?1:0);
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 81664
package main

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

func main() {
	wtr := bufio.NewWriter(os.Stdout)
	var N int
	var S, T string
	fmt.Scan(&N)
	fmt.Scan(&S, &T)
	ans := ""
	for i := 0; i < N; i++ {
		ans += string(S[i]) + string(T[i])
	}
	fmt.Println(ans)
	wtr.Flush()
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
bool isPalindrome(string str, int begin, int end)
{
    while (begin <= end)
    {
        if (str[begin] == str[end])
        {
            begin++;
            end--;
        }
        else
            return false;
    }
    return true;
}
int main(){
	while(cin>>s1){
		int n=s1.size();
		if(isPalindrome(s1,0,n-1)==false){
			cout<<"No"<<endl;
		}else{
			if(isPalindrome(s1,0,((n-1)/2)-1)==false){
				cout<<"No"<<endl;
			}else{
				if(isPalindrome(s1,((n+3)/2)-1,n-1)==false){
					cout<<"No"<<endl;
				}else{
					cout<<"Yes"<<endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
            
    int cou = 0;
      for(int i=0; i<=n; i++) {
    	for(int j=0; j<=n; j++) {
    		if(i*4+j*7==n) {
    	cou++;
    		}
    	}
    }
      if(cou>0){
      System.out.println("Yes");
      }else{
      System.out.println("No");
    }
}
}

Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
vector<int> vec(3);
cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
sort(vec.begin(),vec.end());
int ans = vec.at(0) + vec.at(1) + vec.at(2) * 10;
cout << ans << endl;



return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct P
{
    //string r;
    int x,y;

    bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
       return x>a.x;
//        return z>a.z;
    }
};
struct S
{
    //double a;
    int x,y;
};
//vector<P> v[33110];

int a,b,c,i,k,d,n,m,e,dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};
int l[2][8111];
int o[2];
//int dx[10]={1,0,1,-1,-1,0},dy[10]={0,1,1,1,-1,-1};

//long long x,y,z[555555];
//P u[1222];
int j[2][4010][8333];
//priority_queue<int,vector<int>,greater<int> > q,q1;
//stack<int> s,s1;


//deque<int> de;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int > p;
string r,r1;
//char r[10010];

bool as(P a,P b)
{

    return a.y>b.y;
}

int f(int i,int n,int m)
{
    if(max(m,-m)>r.size()) return 0;
    if(n==0&&m==0) return 1;
    if(n==0) return 0;
    if(j[i][n][max(m,-m)]>=0) return j[i][n][max(m,-m)];
    return j[i][n][max(m,-m)]=max(f(i,n-1,m-l[i][n]),f(i,n-1,m+l[i][n]));
}

int main()
{
    cin>>r;
    scanf("%d %d",&a,&b);
    //a=max(a,-a);
    b=max(b,-b);
    int t=0;
    for(;t<r.size()&&r[t]!='T';t++)
        a--;
    a=max(a,-a);
    for(;t<r.size();t++)
    {
        if(r[t]=='T') i++,i%=2;
        else
        {
            if(t==0||r[t-1]=='T') o[i]++,l[i][o[i]]=1;
            else l[i][o[i]]++;
        }
    }
    //for(int t=1;t<=o[0];t++)
      //  printf("%d ",l[0][t]);
    memset(j,-1,sizeof(j));
    if(f(0,o[0],a)&&f(1,o[1],b)) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 261504
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int kakko(int ,string);
int main(){
  int n ,shou=0 ,chu=0;
  string s;
  while( 1 ){
    getline(cin ,s);
    n = s.size();
    if( s[0] == '.' ){
      break;
    }
    kakko(n ,s);
  }
}


int kakko(int n ,string s){
  int shou=0 ,chu=0 ,flag=0;
  stack<int> jun; // 括弧の順番を調べる
  jun.push(0);
  for( int i=0 ; i<n ; i++ ){
    switch(s[i]){ // ( ,[の数を求める
    case '(':
      shou++;
      jun.push(1); // 入った順を記憶
      break;
      
    case '[':
      chu++;
      jun.push(2); // 入った順を記憶
      break;
      
    case ')':
      if( jun.top() == 1 || jun.top() == 0 ){ // 順どおりなら
	shou--;
	jun.pop();
      }
      else{
	flag = 1;
      }
      break;
      
    case ']':
      if( jun.top() == 2 || jun.top() == 0 ){ // 順どおりなら
	chu--;
	jun.pop();
      }
      else{
	flag = 1;
      }
      break;
      
    default:
      continue;
      break;
    }
    
    if( shou < 0 || chu < 0 || flag == 1 ){ 
      cout << "no" << endl;
      return 0;
    }
  }
  
  if( shou == 0 && chu == 0 ){ // 対応してたら
    cout << "yes" << endl;
  }
  else{ // 対応してなかったら
      cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 1180
import java.util.Scanner;

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

        while(true) {
            int H = scan.nextInt(), W = scan.nextInt();
            if(H == 0 && W == 0) break;
            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    if(i == 0 || j == 0 || i == H -1 || j == W -1) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }

    }
}

Measured memory_bytes: 32276
def root(x):
  if data[x]<0:return x
  else:
    data[x]=root(data[x])
    return data[x]
def unite(x,y):
  x,y=root(x),root(y)   
  if x!=y:
    if data[x]>data[y]:x,y=y,x
    data[x]+=data[y]
    data[y]=x
from collections import*
r=range
h,*s=open(0)
h,w=map(int,h.split())
data=[-1]*h*w
for i in r(h):
  for j in r(w):
    if i+1<h and s[i][j]!=s[i+1][j]:
      unite(i*w+j,-~i*w+j)
    if j+1<w and s[i][j]!=s[i][j+1]:
      unite(i*w+j,i*w+j+1)
d=defaultdict(lambda:[0,0])
for i in r(h*w):d[root(i)][s[i//w][i%w]<'.']+=1
print(sum(i*j for i,j in d.values()))

Measured memory_bytes: 70000
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }
 

fn main(){
    input!{
        A: u64,
        B: u64,
    }
    
    println!("{}", 
        if (A*B)%2 == 0{
            "Even"
        }else{
            "Odd"
        }
    );
}


Measured memory_bytes: 4352
package main

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

func pow(x, n, m int64) int64 {
	if n == 0 {
		return 1
	}
	if n&1 == 0 {
		r := pow(x, n/2, m)
		return r * r % m
	}
	return x * pow(x, n-1, m) % m
}

func main() {
	r := bufio.NewReader(os.Stdin)

	m := int64(1e9) + 7
	var n int
	fmt.Fscan(r, &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a[i])
	}

	var ans int64
	for i := 0; i < 60; i++ {
		var cnt int64
		for j := 0; j < n; j++ {
			if a[j]>>uint(i)&1 == 1 {
				cnt++
			}
		}
		cnt = cnt * (int64(n) - cnt) % m
		ans += pow(2, int64(i), m) * cnt % m
		ans %= m
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5760
import itertools



def resolve():
    N,C=map(int,input().split())
    cost=[[int(i) for i in input().split()] for j in range(C)]
    count=[[0 for i in range(C)] for i in range(3)]
    grid=[[int(i)-1 for i in input().split()] for j in range(N)]
    for i in range(N):
        for j in range(N):
            count[(i+j)%3][grid[i][j]]+=1
    seq=list(range(C))
    mx=2**29
    for i in itertools.permutations(seq,3):
        temp=0
        temp+=sum([cost[j][i[0]]*count[0][j] for j in range(C)])
        temp+=sum([cost[j][i[1]]*count[1][j] for j in range(C)])
        temp+=sum([cost[j][i[2]]*count[2][j] for j in range(C)])
        mx=min(mx,temp)
    print(mx)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 49116
x=int(input())
if 400<=x<=599:
    print(8)
elif 600<=x<=799:
    print(7)
elif 800<=x<=999:
    print(6)
elif 1000<=x<=1199:
    print(5)
elif 1200<=x<=1399:
    print(4)
elif 1400<=x<=1599:
    print(3)
elif 1600<=x<=1799:
    print(2)
else:
    print(1)

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

// ■■■■■■■■■■■■■■■■headerここまで■■■■■■■■■■■■■■■■

int main() {

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int t1 = h1 * 60 + m1;
    int t2 = h2 * 60 + m2;

    cout << (t2 - t1 - k) << endl;

    return 0;

}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n,m;
cin>>n>>m;
ll ans =0;
if(m<n*2){
    ans+=(ll)floor(m/2);
}
else{
    ans+=n;
    m-=n*2;
    ans+=(ll)floor(m/4);
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int N, c=0;

	cin >> N;
	while(1){
		if((N%3)==0){N = N/3;}
		else{N = (N/3)+1;}
		c++;
		if(N==1){break;}
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
typedef pair<ll,ll> pairs;


struct {
    bool operator()(const pairs &a , const pairs & b )const
    {   
		if(a.second != b.second)
		{
			//名前はalphabet順
			return a.first < b.first;
		}
		else
		{
			//特典は高い順
			//Trueが先になる
			return a.first > b.first;
		} 
    }   
} customSort;
//末尾に宣言で実体

int main()
{
    ll N,X;

    ll ima = 0;
    ll kigen = 0;

    string res = "Yes";
    string tmp;

    cin >> N;
    vector <pairs> p(N);


    REP(i,N)
    {
        cin >> p[i].second >> p[i].first;
    }

    sort(p.begin(),p.end());

    REP(i,N)
    {
        //kigenとima
        ima += p[i].second;
        kigen = p[i].first;

        if( ima > kigen)
        {
            res = "No";
            break;
        }
    }

    cout << res << endl;

}



Measured memory_bytes: 3328
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
inline void Fail(){printf("0");exit(0);}

const int maxn=200005;
int n,ans;
int p[maxn],pos[maxn],r[maxn],l[maxn];

int main(){
	scanf("%d",&n);
	REP(i,n)scanf("%d",&p[i]),pos[p[i]]=i;
	r[n]=1;
	for(int i=n-1;i>=1;i--)if(pos[i+1]>pos[i])r[i]=r[i+1]+1;else r[i]=1;
//	REP(i,n)cout<<r[i]<<endl;
	REP(i,n)ans=max(ans,r[i]);
	printf("%d",n-ans);
	return 0;
}

/*
Input:
-----------------
Output:
*/

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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=2e5+5;
int n,m;
set<int>Set[N];
bool ok(int k)
{
	int x=1,y=1;
	while(1)
	{
		auto it=Set[y].lower_bound(x);
		if(it!=Set[y].end()&&*it<=k)return 1;
		++x;
		if(x>=k)break;
		if(y<m&&!Set[y+1].count(x))++y;
	}
	return 0;
}

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	int cnt;
	cin>>n>>m>>cnt;
	while(cnt--)
	{
		int x=read(),y=read();
		Set[y].insert(x);
	}
	int l=0,r=n+1;
	while(l+1!=r)
	{
		int mid=(l+r)/2;
		if(ok(mid))r=mid;
		else l=mid;
	}
	cout<<r-1;	
}


Measured memory_bytes: 18944
#include <iostream>
using namespace std;
void qs(int*, int);

int main() {
	//int n;
	//cin >> n;
	//int *a=new int[n];
	int a[5];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	qs(a, 4);
	for (int i = 4; i > 0; i--)
		cout << a[i] << " ";
	cout << a[0]<<endl;
	return 0;
}


void qs(int *a, int e){
	if (e == 0)
		return;
	int t;
	if (e == 1) {
		if (a[0] > a[1]) {
			t = a[0];
			a[0] = a[1];
			a[1] = t;
		}
		return;
	}
	int p = a[0], lp = -1, rp = e + 1,s=0;
	if (p < a[1])
		p = a[1];
	while (1){
		while (1){
			lp++;
			if (lp == e) {
				qs(a, e - 1);
				return;
			}
			if (lp == rp) {
				s = 2;
				break;
			}
			if (a[lp] >= p)
				break;
		}
		if (s == 0) {
			while (1) {
				rp--;
				if (rp == 0) {
					qs(a + 1, e - 1);
					return;
				}
				if (lp == rp) {
					s = 1;
					break;
				}
				if (a[rp] < p)
					break;
			}
		}
		if (s == 1) {
			qs(a, lp-1);
			qs(a + lp, e - lp);
			return;
		}
		if (s == 2) {
			qs(a, rp - 1);
			qs(a + rp, e - rp);
			return;
		}
		t = a[lp];
		a[lp] = a[rp];
		a[rp] = t;
	}
}


Measured memory_bytes: 3088
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

bool odd(ll x) {
	ll ct = 0;
	while(x) {
		ct++ ;
		x/=10;
	} 
	return(ct%2 == 1) ;
}
int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  ll ct  =0;
  for(ll i = 1; i <= n; i++) {
  	if(odd(i)) {
  		ct++;
  	}
  }
  cout << ct ;
  return 0;
} //good night.

Measured memory_bytes: 256
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
bool cmp(pii a,pii b){
    if(b.F==a.F) return a.S<b.S;
    return a.F>b.F;
}
void solve(){
    ll n,m,a,b;
    cin>>n>>m;
    vi v[N];
    rep(i,1,n){
        cin>>a>>b;
        v[a].pb(b);
    }
    // sort(all(v),cmp);
    ll ans=0;
    // vi vis(m+1,0);
    priority_queue <ll> pq;
    rep(i,1,m){
        if(sz(v[i])){
        rep(j,0,sz(v[i])-1){
            pq.push(v[i][j]);
        }
        }
        if(!pq.empty()){
        ans+=pq.top();
        pq.pop();
        }
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
#define MOD 1000000007

ll m[200010],p[200010];
int mcnt,pcnt;
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	rep(i,0,n){
		int t;
		scanf("%d",&t);
		if(t>=0)p[pcnt++]=t;
		else m[mcnt++]=-t;
	}
	//正の数・負の数をそれぞれソート
	sortup(m,mcnt);
	sortup(p,pcnt);
	
	//K==Nのとき
	if(k==n){
		ll ans=1;
		rep(i,0,mcnt)ans=ans*(MOD-m[i])%MOD;
		rep(i,0,pcnt)ans=ans*p[i]%MOD;
		printf("%lld",ans);
		return 0;
	}
	
	//Kが奇数かつ負のみのとき
	if(k%2==1&&mcnt==n){
		ll ans=1;
		rep(i,0,k)ans=ans*(MOD-m[i])%MOD;		
		printf("%lld",ans);
		return 0;
	}
	
	ll ans=1;
	while(k){
		// 負の数を2個とる or 正の数を1個とる
		if(k>=2 && mcnt>=2 &&(pcnt<=1 || (pcnt>=2 && m[mcnt-1]*m[mcnt-2]>=p[pcnt-1]*p[pcnt-2]))){
			ans=ans*m[--mcnt]%MOD;
			ans=ans*m[--mcnt]%MOD;
			k-=2;
		}else{
			ans=ans*p[--pcnt]%MOD;
			k--;
		}
	}
	printf("%lld",ans);
}


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

int main(){
    int A,B;
    cin>>A>>B;
    string s;
    cin>>s;
    bool check = true;
    for(int i=0;i<s.size();i++){
        if(i<A&&s[i]=='-') check = false;
        else if(i==A&&s[i]!='-') check=false;
        else if(A<i&&s[i]=='-') check=false;
    }
    if(check) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = II()
    dp = [inf for i in range(n + 1)]
    ans = [1]
    x = 6
    while x <= n:
        ans.append(x)
        x = x * 6
    x = 9
    while x <= n:
        ans.append(x)
        x = x * 9
    ans.sort()
    for i in ans:
        dp[i] = 1
    for i in range(1, n + 1):
        if not i in ans:
            a = bisect.bisect_left(ans, i)
            for k in range(a):
                #print(i,ans[k], a)
                dp[i] = min(dp[i - ans[k]] + 1, dp[i])
    print(dp[n])

    return

#D
def D():
    n, c = LI()
    D = LIR(c)
    C = LIR_(n)
    CL = list(itertools.permutations(range(c), 3))
    ans = inf
    amari0 = [0 for i in range(30)]
    amari1 = amari0[::1]
    amari2 = amari0[::1]
    for y in range(n):
        for x in range(n):
            amari = (x + y) % 3
            if amari == 0:
                amari0[C[y][x]] += 1
            if amari == 1:
                amari1[C[y][x]] += 1
            if amari == 2:
                amari2[C[y][x]] += 1
    for c0, c1, c2 in CL:
        ansb = 0
        for i in range(c):
            ansb += D[i][c0] * amari0[i]
            ansb += D[i][c1] * amari1[i]
            ansb += D[i][c2] * amari2[i]
        ans = min(ans, ansb)

            
    print(ans)

    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()


Measured memory_bytes: 8416
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int N;
	int[] A;
	int minj,key;
	int count=0;
	
	public void input(){
		N=sc.nextInt();
		A = new int[N];
		for(int i=0; i<N; i++){
			A[i]=sc.nextInt();
		}
	}
	
	public void selectionsort(){
		for(int i=0; i<N-1; i++){
			minj=i;
			for(int j=i; j<=N-1; j++){
				if(A[j] < A[minj]){
					minj = j;
				}
			}
			key = A[i];
			A[i] = A[minj];
			A[minj] = key;
			if(i != minj) count++;
		}
	}
	
	public void output(){
		System.out.print(A[0]);
		for(int i=1; i<N; i++){
			System.out.print(" "+A[i]);
		}
		System.out.println("\n"+count);
	}
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.input();
		obj.selectionsort();
		obj.output();
	}
}



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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int N, K;
	cin >> N >> K;
	cout << (N%K == 0 ? 0 : 1) << endl;

	return 0;
}


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

int main(){
  int x, a;
  cin >> x >> a;
  if(x < a) cout << 0 <<endl;
  else cout << 10 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[200005],ans=0x7fffffffffll,p[200005],l,r;
int main()
{
	long long n,m,i,j;
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	{
		cin>>a[i];
		p[a[i]]=i;
	}
	for (i=1;i<=n;)
	{
		j=i;
		while (j<n&&p[j]<p[j+1]) j++;
		ans=min(ans,n-(j-i+1));
		i=j+1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
  	cout << "Left" << endl;
  }else if (A + B == C + D) {
  	cout << "Balanced" << endl;
  }else {
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define mod 1e9
int a[200005],b[200005];
int32_t main() {
	int n,i;
	string s;
	cin>>s;
	n=s.length();
	a[n]=b[n]=0;
	for(i=n-1;i>=0;i--)
	{	
		a[i]=a[i+1];
		b[i]=b[i+1];
		if(s[i]=='W')
			a[i]++;
		else b[i]++;
	}
	int ans=0;
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='B')
		{
			ans+=a[i];
		}	
	}
	
	cout<<ans;
}
						

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
	int A,B,C;
	SCD3(A,B,C);

	int ans = 0;
	ans = max({10*A + B + C,A+10*B+C,A+B+10*C});
	PRINTD(ans);
}

Measured memory_bytes: 256
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())-1
print(l[k])

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>

int main() {
	int m, f, r;
	char rank[5][2] = {"A", "B", "C", "D", "F"};
	int flug;
	while (1) {
		scanf("%d%d%d", &m, &f, &r);
		if (m + f + r == -3)break;
		if (m + f >= 80) flug = 0;
		else if (m + f >= 65) flug = 1;
		else if (m + f >= 50) flug = 2;
		else if (m + f >= 30 && r >= 50) flug = 2;
		else if (m + f >= 30 && r <= 50) flug = 3;
		else flug = 4;
                if(m==-1||f==-1) flug = 4;
		printf("%s\n", rank[flug]);
	}
	return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		System.out.println(a+b >= 10 ? "error" : a+b);
		scanner.close();
	}
}


Measured memory_bytes: 22100
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.Xml;

namespace hello_world
{
	class Program
	{

		static void Main(string[] args)
		{
			string[] h = Console.ReadLine().Split(' ');
			int k = int.Parse(h[0]);
			int n = int.Parse(h[1]);
			string[] hh = Console.ReadLine().Split(' ');
			int[] h1 = new int[n];
			int[] ma = new int[n];
			for (int i = 0; i < n; i++)
				h1[i] = int.Parse(hh[i]);
			for(int i = 1; i < n; i++)
			{
				ma[i] = h1[i] - h1[i - 1];
			}
			int maa = k - h1[n - 1] + h1[0];
			var list = new List<int>();
			list.AddRange(ma);
			list.Add(maa);
			int Out= list.Max();
			Console.WriteLine(k - Out);
			

		}
	}

}

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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<long long>
#define inf 1000000100
#define infll 1LL << 50

int main()
{
    int n;
    cin >> n;
    int mx = 0, mn = inf;
    while(n--)
    {
        int a;
        cin >> a;
        mx = max(a, mx);
        mn = min(a, mn);
    }
    cout << mx - mn << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
#define MP  make_pair
using namespace std;
typedef long long ll;

int even_vx[]={1,0,-1,-1,-1,0},even_vy[]={0,-1,-1,0,1,1};
int odd_vx[]={1,1,0,-1,0,1},odd_vy[]={0,-1,-1,0,1,1};

bool isbl[102][102];
bool isvis[102][102];
int W,H;
int kabe[102][102];
int solve(int x,int y){
    isvis[x][y]=true;
    int *vx,*vy;
    if(y%2==0){
        vx=even_vx;
        vy=even_vy;
    }else{
        vx=odd_vx;
        vy=odd_vy;
    }
    int ret=0;
    for(int i=0;i<6;i++){
        int nx=x+vx[i],ny=y+vy[i];
        if(0<=nx&&nx<=W+1&&0<=ny&&ny<=H+1){
            if(isbl[nx][ny]){
                ret++;
                kabe[x][y]++;
            }
            else if(!isvis[nx][ny]) ret+=solve(nx,ny);
        }
    }
    return ret;
}
int main(){
    scanf("%d%d",&W,&H);
    for(int i=0;i<=H+1;i++){
        for(int j=0;j<=W+1;j++){
            kabe[i][j]=0;
            isbl[i][j]=false;
            isvis[i][j]=false;
        }
    }
    int now;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            scanf("%d",&now);
            if(now==1) isbl[j+1][i+1]=true;
        }
    }
    int len=0;
    for(int i=0;i<=W+1;i++){
        if(!isvis[i][0]){
            len+=solve(i,0);
        }
        if(!isvis[i][H+1]) len+=solve(i,H+1);
    }
    for(int i=0;i<=H+1;i++){
        if(!isvis[0][i]) len+=solve(0,i);
        if(!isvis[W+1][i]) len+=solve(W+1,i);
    }
    printf("%d\n",len);
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))
ans = 0
L = [0] * N
R = list()
for i in range(N):
  R.append(i-A[i])
  if(i+A[i]<=N-1):
    L[i+A[i]] += 1
for r in R:
  if(r > 0):
    ans += L[r]
print(ans)

Measured memory_bytes: 104352
#include "bits/stdc++.h"
using namespace std;
using ll=long long;

#include <vector>
#include <functional>

template <typename T,typename E>
struct LazySegmentTree{
   using F=std::function<T(T,T)>;
   using G=std::function<T(T,E,int,int)>;
   using H=std::function<T(E,E)>;

   int n;
   std::vector<T> dat;
   std::vector<E> laz;
   const F f;
   const G g;
   const H h;
   const T d1;
   const E d0;

   LazySegmentTree(int n_,const F f,const G g,const H h,const T d1,const E d0):f(f),g(g),h(h),d1(d1),d0(d0)
   {
      n=1;
      while(n_>n) n<<=1;
      dat.assign(2*n,d1);
      laz.assign(2*n,d0);
   }

   void set(int k,const T &x){
      dat[k+n]=x;
   }
   void eval(int k,int l,int r){
      if(laz[k]==d0) return;
      dat[k]=g(dat[k],laz[k],l,r);
      if(k<n){
         laz[2*k]=h(laz[2*k],laz[k]);
         laz[2*k+1]=h(laz[2*k+1],laz[k]);
      }
      laz[k]=d0;
   }
   void update(int a,int b,E x,int k=1,int l=0,int r=-1){
      if(r<0) r=n;
      eval(k,l,r);
      if(r<=a||b<=l) return;
      if(a<=l&&r<=b){
         laz[k]=h(laz[k],x);
         eval(k,l,r);
      }
      else{
         update(a,b,x,2*k,l,(l+r)/2);
         update(a,b,x,2*k+1,(l+r)/2,r);
         dat[k]=f(dat[2*k],dat[2*k+1]);
      }
   }
   T query(int a,int b,int k=1,int l=0,int r=-1){
      if(r<0) r=n;
      eval(k,l,r);
      if(r<=a||b<=l) return d1;
      if(a<=l&&r<=b) return dat[k];
      T vl=query(a,b,2*k,l,(l+r)/2);
      T vr=query(a,b,2*k+1,(l+r)/2,r);
      return f(vl,vr);
   }
};

/*

-RMinimumQ and RUpdateQ
f=[](T x,T y){ return min(x,y); };
g=[](T x,E y,int l,int r){ return y; };
h=[](E x,E y){ return y; };

-RSumQ and RAddQ
f=[](T x,T y){ return x+y; };
g=[](T x,E y,int l,int r){ return x+(r-l)*y; };
h=[](E x,E y){ return x+y; };

-RAddQ and RMinimumQ
f=[](T x,T y){ return min(x,y); };
g=[](T x,E y,int l,int r){ return x+y; };
h=[](E x,E y){ return x+y; };

-RSumQ and RUpdateQ
f=[](T x,T y){ return x+y; };
g=[](T x,E y,int l,int r){ return (r-l)*y; };
h=[](E x,E y){ return y; };

*/

int main(){
   int n,q;
   cin>>n>>q;
   using T=ll;
   using E=ll;
   auto f=[](T x,T y){ return x+y; };
   auto g=[](T x,E y,int l,int r){ return x+(r-l)*y; };
   auto h=[](E x,E y){ return x+y; };
   LazySegmentTree<ll,ll> seg(n,f,g,h,0,0);
   for(int i=0;i<q;++i){
      int com;
      cin>>com;
      int s,t,x;
      cin>>s>>t;
      s--,t--;
      if(com==0){
         cin>>x;
         seg.update(s,t+1,x);
      }
      else{
         cout<<seg.query(s,t+1)<<endl;
      }
   }
}



Measured memory_bytes: 7088
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    K = int(input())
    S = input().strip()
    if len(S) <= K:
        print(S)
    else:
        print(S[:K]+'...')
    

if __name__ == '__main__':
    main()

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

int main() {
    int A[4][3][10] = {0};
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        A[b-1][f-1][r-1] += v;
    }

    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 10; k++){
                cout << ' ' << A[i][j][k];
            }
            cout << endl;
        }
        if (i < 3){
            cout << "####################" << endl;
        }
    }
}

Measured memory_bytes: 1164
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[N];
		double ans = 0;
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		int num = 1;
		for (int i = 1; i < N; i++) {
			num *= i;
		}
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (i == j) continue;
				ans += Math.sqrt(Math.pow(x[i]-x[j],2) + Math.pow(y[i]-y[j],2)) * num;
			}
		}
		ans /= num * N;
		System.out.println(ans);
	}


	public static long gcd(long a, long b) {
		long remainder = a % b;
		if (remainder == 0) {
			return b;
		} else {
			return gcd(b, remainder);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <bitset>
#include <cmath>
#include <utility>
#include <ctime>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x&(-x)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI acos(-1.0)
#define random(x) (rand()%x)+1
#define LL long long
#define Inf (1LL<<62)
#define inf 0x3f3f3f3f
#define eps 1e-12
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
using namespace std;
const int mod=1e9+7;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    //input;output;
    int m,n,p,sum,cnt[26],arr[10005];
    bool vis[105][105],visited[10005],flag;
    char matrix[105][105];
    while(~scanf("%d%d",&m,&n))
    {
        flag=true;
        p=sum=0;
        memset(arr,0,sizeof(arr));
        memset(cnt,0,sizeof(cnt));
        memset(vis,false,sizeof(vis));
        memset(visited,false,sizeof(visited));
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++)
                cin>>matrix[i][j],cnt[matrix[i][j]-'a']++;
        for(int i=1;i<=m;i++)
            for(int j=1;j<=n;j++)
            {
                if(!vis[i][j])
                {
                    vis[i][j]=true;
                    if(n-j+1!=j&&m-i+1!=i)
                    {
                        vis[i][n-j+1]=true;
                        vis[m-i+1][j]=true;
                        vis[m-i+1][n-j+1]=true;
                        arr[p++]=4;
                    }
                    else if(n-j+1!=j)
                    {
                        vis[i][n-j+1]=true;
                        arr[p++]=2;
                    }
                    else if(m-i+1!=i)
                    {
                        vis[m-i+1][j]=true;
                        arr[p++]=2;
                    }
                    else
                        arr[p++]=1;
                }
            }
        sort(arr,arr+p,cmp);
        sort(cnt,cnt+26,cmp);
        for(int i=0;i<26;i++)
        {
            if(!flag)
                break;
            flag=true;
            if(cnt[i]>0)
            {
                //cout<<cnt[i]<<endl;
                for(int j=0;j<p;j++)
                    if(cnt[i]>=arr[j]&&!visited[j])
                    {
                        visited[j]=true;
                        cnt[i]-=arr[j];
                    }
                if(cnt[i])
                {
                    flag=false;
                    break;
                }
            }
        }
        printf("%s\n",flag?"Yes":"No");
    }
    return 0;
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;


void solve(long long K, std::string S){
	int l = S.size();
	if(l <= K) {
		cout << S << endl;
	} else {
		string s = S.substr(0, K);
		cout << s << "..." << endl;
	}

}

int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}



Measured memory_bytes: 3692
using System;


class Program
{
    static void Main()
    {
        string a = Console.ReadLine();
        char[] b = a.ToCharArray();
        for (int i = 0; i < b.Length; i++)
        {
            if (b[i] <= 'z' && b[i] >= 'a') b[i] -= ' ';
            else if (b[i] <= 'Z' && b[i] >= 'A') b[i] += ' ';
        }
        Console.WriteLine(b);
    }
}



Measured memory_bytes: 15844
def inpl(): return list(map(int, input().split()))

N, A, B, C, D = inpl()
S = input()

if A > B:
    A, B = B, A
    C, D = D, C

A, B, C, D = A-1, B-1, C-1, D-1
if C < D:
    if ("##" in S[A:C+1]) or ("##" in S[B:D+1]):
        print("No")
    else:
        print("Yes")

else:
    if (not "##" in S[A:C+1]) and (not "##" in S[B:D+1]) and ("..." in S[B-1:D+2]):
        print("Yes")
    else:
        print("No")

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

int main() {
  ll a, b, k; cin >> a >> b >> k;
  if (a - k > 0)
    cout << a - k << " " << b;
  else
    cout << 0 << " " << max(0ll, b - (k - a));
  return 0;
}

Measured memory_bytes: 256
//#include <bits\stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define ll long long
#define y1 bad_fdsaf
#ifdef Stetsyk
#define files freopen("input.txt", "r", stdin);
#else
#define files
#endif
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n, m, k;
int main(){
    files;
    cin >> n >> m >> k;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            if(i * m + j * n - 2 * i * j == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main() {
    int n,k;cin>>n>>k;
    double sm=0;
    double p[n];
    for (int i=0;i<n;i++) {
        cin>>p[i];
        if (i<k)
            sm+=(p[i]+1)/2;
    }
    double mx=sm;
    for (int i=k;i<n;i++) {
        sm=sm-(p[i-k]+1)/2+(p[i]+1)/2;
        mx=max(mx,sm);
    }
    cout<<fixed<<mx<<endl;
    return 0;
}

Measured memory_bytes: 1792