akhauriyash/Code-Regression huggingface dataset:
def func(V, W):
    for k in range(V):
        for i in range(V):
            w_ik = W[i][k]
            for j, (w_ij, w_kj) in enumerate(zip(W[i], W[k])):
                W[i][j] = min(w_ij, w_ik + w_kj)

V, E = map(int, input().split())
W = [[float("inf")] * V for _ in range(V)]

for i in range(V):
    W[i][i] = 0

for _ in range(E):
    s, t, d = map(int, input().split())
    W[s][t] = d

func(V, W)

for i in range(V):
    if W[i][i] < 0:
        print("NEGATIVE CYCLE")
        exit()

for temp in W:
    print(" ".join(list(map(str, temp))).upper())
    

    



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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

const int N = 1e2+34;
int h[N];

void solve() {
    int n, k; scanf("%d%d", &n, &k);
    for (int i = 0; i < k; ++i) {
	int d; scanf("%d", &d);
	for (int j = 0; j < d; ++j) {
	    int a; scanf("%d", &a);
	    ++h[a-1];
	}
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
	ans += !h[i];
    }
    printf("%d", ans);
    
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3856
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if ((a*b) % 2 == 0) {
        cout << "Even" << endl;
    }
    else {
        cout << "Odd" << endl;
    }
    return 0;
}


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

int main(){
    int ans=0,sum=0;
    int n;
    int a,b,c,d;
    
    cin >>n>>a>>b>>c>>d;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << min(b*((n+a-1)/a),d*((n+c-1)/c)) << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}



Measured memory_bytes: 3096
from sys import setrecursionlimit

setrecursionlimit(10 ** 8)


def main(x, k, d):
    for i in range(k):
        if abs(x + d) < abs(x - d):
            x = x + d
        else:
            x = x - d

        if abs(x - d) > abs(x) and abs(x + d) > abs(x):
            if (k - i - 1) % 2 == 1:
                if abs(x - d) < abs(x + d):
                    x = x - d
                else:
                    x = x + d
            break

    print(abs(x))


def sub(x, k, d):
    print(abs(x) - d * k)


a, b, c = map(int, input().split())

if abs(a) - b * c >= 0:
    sub(a, b, c)
else:
    main(a, b, c)


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

int main() {
  int A, B, C, D, D1, D2;
  cin >> A >> B >> C >> D;
	D1 = A + B; //左
    D2 = C + D; //右
      if (D1 == D2) {
        cout << "Balanced" << endl;
      }
  		else if (D1 > D2) {
          cout << "Left" << endl;
        }
  		else if (D1 < D2) {
          cout << "Right" << endl;
        }
  
  
      
  // ここにプログラムを追記
}

Measured memory_bytes: 256
import Data.List

main = do
    xs <- map read . words <$> getLine :: IO [Int]
    n <- readLn :: IO Int
    print $ f xs n

f :: [Int] -> Int -> Int
f xs 0 = sum xs 
f xs n = f (init sorted ++ [2 * last sorted]) (n-1)
    where 
        sorted = sort xs

Measured memory_bytes: 508
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n-1];
        int ans = 0;
        for (int i = 0; i < n-1; i++) {
            b[i] = sc.nextInt();
            if(i == 0) ans += b[0];
            else ans += Math.min(b[i-1], b[i]);
        }
        if(2 <= n)ans += b[n-2];
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 23124
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
n=int(input())
ans=[[0,0,0] for i in range(3)]

for i in range(n):
  s=int(input())
  count=-1
  for T in [A,B,C]:
    count+=1
    if s in T:
      
      ans[count][T.index(s)]=1
for i in range(3):
  if ans[i]==[1,1,1]:
    print("Yes")
    exit()
for i in range(3):
  if [ans[j][i] for j in range(3)]==[1,1,1]:
    print("Yes")
    exit()
if [ans[0][0],ans[1][1],ans[2][2]]==[1,1,1]:
  print("Yes")
  exit()
if [ans[0][2],ans[1][1],ans[2][0]]==[1,1,1]:
  print("Yes")
  exit()
print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace	std;
int main(){
	int x;
  	cin>>x;
  	int n=0,count=0;
  	bool bo1=false;
  if(x==2){
  	cout<<2<<endl;
  }
  else {
    while(true){
    	for(int i=2;i<=(x+n-1);i++){
        	if((x+n)%i==0){
            	
              	break;
            }
          	else if(i==(x+n-1)){
            	cout<<x+n<<endl;
              	bo1=true;
            }
        }
    	n++;
      	if(bo1){
        	break;
        }
    }
  }

}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c = inpl()
print(a*b//2)

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

int main() {
    int A, B, C;
    string r = "No";
    bool f = false;

    cin >> A >> B >> C;

    if((A == B)&&(A != C)) {
        f = true;
    } else if((A == C)&&(A != B)) {
        f = true;
    } else if((B == C)&&(B != A)) {
        f = true;
    }

    if(f) {
        r = "Yes";
    }

    cout << r << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define M 1000000000
int r,h[6000]={-M};
void g(){
  int i,j=0;
  for(i=0;i<=r;i++){
    if(i==1<<j){
      printf("\n");
      j++;
    }
    printf("%d ",h[i]);
  }
  } //*/
int main(){
  int ta[25]={0};
  int to[1000],ne[1000],co[1000];
  int a,b,c,d,e,i,j,k,l,n,m,mi;
  //int h[60]={-M};
  //for(i=r=1;i<60;i++)h[i]=M;
  scanf("%d %d",&n,&m);
  n++;
  for(i=1;i<=m*2;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    ne[i]=ta[a];
    to[i]=b;
    co[i]=c;
    ta[a]=i++;
    ne[i]=ta[b];
    to[i]=a;
    co[i]=d;
    ta[b]=i;
  }
  scanf("%d,%d,%d,%d",&e,&b,&c,&d);
  c-=d;
  a=e;
  for(l=0;l<2;l++){//printf("%d %d %d\n",a,b,r);
    int u[30];//,f[30]={0};//printf("%d\n",n);
    for(i=r=1;i<6000;i++)h[i]=M;
    for(i=0;i<n;i++)u[i]=M;//printf("%d\n",a);
    u[a]=0;//printf("s%d\n",h[0]);g();printf("\n");
    h[0]=-M;
    /*for(i=1;i<n;i++){printf("%d:\n",i);
      for(j=ta[i];j;j=ne[j])printf("%d ",to[j]);printf("\n");
      }*/
    for(i=1;1;i++){//printf("a\n");
      //f[a%=10]=1;//printf("%d:",a);//printf("f2%d:",f[2]);//printf("\n");
      for(j=ta[a];j;j=ne[j]){//printf("%d ",to[j]);
	if(u[to[j]]>u[a]+co[j]){
	  u[to[j]]=u[a]+co[j];//printf("u%d ",u[to[j]]);
	  for(k=r++;h[k/2]>u[to[j]]*30+to[j];k/=2)h[k]=h[k/2];
	  h[k]=u[to[j]]*30+to[j];//printf("h%d k%d ",h[k],k);
	}
      }//printf("\n");g();printf("\n");
      a=h[j=1]%30;
      d=h[--r];
      for(h[r]=M;d>h[j];j=mi){
	h[j]=h[mi=j*2];
	if(h[j]>h[j*2+1])h[j]=h[mi=j*2+1];
      }//printf("a==%d\n",a);
      if(r==1)break;
      h[j/2]=d;
    }
    c-=u[b];//printf("b%d\n",c);
    a=b;
    b=e;
  }
  printf("%d\n",c);
  return 0;
}
    

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,now=-INF,ans;
vector<pair<int,int>> v;

signed main() {
    cin >> n;
    rep(i,n) {
        int x,l;
        cin >> x >> l;
        v.pb(mp(x+l,-(x-l)));
    }
    sort(all(v));
    rep(i,n) {
        int s = -v[i].se, e = v[i].fi;
        if (now <= s) {
            now = e;
            ans++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
const int N=200005;
int n;
LD d,x,ans=0;
int main(){
	scanf("%d%Lf%Lf",&n,&d,&x);
	while (n>0){
		ans+=(1.0L*(2*n-1)*x+d+d)/2.0L;
		d+=1.0L*(5.0L*x+2.0L*d)/(2.0L*n);
		x+=2.0L*x/n;
		n--;
	}
	printf("%.12Lf",ans);
	return 0;
}

Measured memory_bytes: 256
<?php

$count = intval(trim(fgets(STDIN)));

$prime_count = 0;
for ($i = 0; $i < $count; $i++) {
    $num = intval(trim(fgets(STDIN)));
    if(is_prime($num)) {
        $prime_count++;
    }
}


echo $prime_count."\n";

function is_prime ($num) {
    if ($num == 2) {
        return true;
    } elseif ($num % 2 == 0) {
        return false;
    }
    
    for ($i = 3; $i <= sqrt($num); $i += 2) {
        if ($num % $i == 0) {
            return false;
        }
    }
    
    return true;
}
?>


Measured memory_bytes: 9252
N, M, X = map(int,input().split())

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

B=0
C=0

D=[]

for i in range(X,N):
    if i in A:
        B=B+1

D.append(B)
        
        
for i in range(X):
    if i in A:
        C=C+1

D.append(C)

print(min(D))



Measured memory_bytes: 3060
#include <iostream>
#include <stack>

using namespace std;

void solve()
{
	stack<int> Stack;
	int num;
	while(cin >> num)
	{
		if(num == 0)
		{
			cout << Stack.top() << endl;
			Stack.pop();
		}
		else
		{
			Stack.push(num);
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1200
use std::io::{BufRead, Write, stdin, stdout};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let mut split = s.split_whitespace();
    let n = split.next()
        .unwrap()
        .parse::<usize>()
        .unwrap();
    let m = split.next()
        .unwrap()
        .parse::<usize>()
        .unwrap();
    let ab = (0..n)
        .map(|_| {
            let mut s = String::new();
            input.read_line(&mut s).unwrap();
            let mut split = s.split_whitespace();
            let a = split.next()
                .unwrap()
                .parse::<i64>()
                .unwrap();
            let b = split.next()
                .unwrap()
                .parse::<i64>()
                .unwrap();
            (a, b)
        })
        .collect::<Vec<_>>();
    let cd = (0..m)
        .map(|_| {
            let mut s = String::new();
            input.read_line(&mut s).unwrap();
            let mut split = s.split_whitespace();
            let c = split.next()
                .unwrap()
                .parse::<i64>()
                .unwrap();
            let d = split.next()
                .unwrap()
                .parse::<i64>()
                .unwrap();
            (c, d)
        })
        .collect::<Vec<_>>();
    for (sx, sy) in ab {
        writeln!(output,
                 "{}",
                 cd.iter()
                     .map(|&(tx, ty)| (sx - tx).abs() + (sy - ty).abs())
                     .enumerate()
                     .min_by(|&(_, dist1), &(_, dist2)| dist1.cmp(&dist2))
                     .unwrap()
                     .0 + 1)
                .unwrap();
    }
}

fn main() {
    let stdin = stdin();
    let stdout = stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v = Vec::<u8>::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("2 2
2 0
0 0
-1 0
1 0\n",
             "2
1\n");
    }
    #[test]
    fn case2() {
        test("3 4
10 10
-10 -10
3 3
1 2
2 3
3 5
3 5\n",
             "3
1
2\n");
    }
    #[test]
    fn case3() {
        test("5 5
-100000000 -100000000
-100000000 100000000
100000000 -100000000
100000000 100000000
0 0
0 0
100000000 100000000
100000000 -100000000
-100000000 100000000
-100000000 -100000000\n",
             "5
4
3
2
1\n");
    }
}


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

#define ll long long

ll n, xi[1010], yi[1010], c[2], m, ans[40];
ll dx[]={1,-1,0,0};
ll dy[]={0,0,1,-1};
char ch[]={'R','L','U','D'};

void fuck(ll x,ll y,ll w){
    if (w>m) return;
    ll mn=1e100, d;
    for (int i=0;i<4;++i){
        ll t=abs(x+dx[i]*ans[w])+abs(y+dy[i]*ans[w]);
        if (t<mn) mn=t, d=i;
    }
    putchar(ch[d]);
    fuck(x+dx[d]*ans[w],y+dy[d]*ans[w],w+1);
}

int main(){
    cin>>n;
    for (int i=1;i<=n;++i){
        cin>>xi[i]>>yi[i];
        c[(xi[i]+yi[i])&1]++;
    }
    if (c[0]&&c[1]) return puts("-1"), 0;
    for (int i=31;i>=0;--i)
        ans[++m]=1ll<<i;
    if (c[0]) ans[++m]=1;
    cout<<m<<endl;
    for (int i=1;i<=m;++i) cout<<ans[i]<<' ';
    cout<<endl;
    for (int i=1;i<=n;++i){
        fuck(-xi[i],-yi[i],1);
        puts("");
    }
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    D = [a - b for a, b in zip(A, B)]
    # [0, 0, ..., 0]の数列に対し、「どれかを-2」「どれかを+1」をk回ずつやってDを作れるか？
    cnt_m2 = 0
    cnt_p1 = 0
    # 必要最低限な個数を計算
    for d in D:
        if d < 0:
            if d % 2 == 0:
                cnt_m2 += abs(d) // 2
            else:
                cnt_m2 += (abs(d) + 1) // 2
                cnt_p1 += 1
        elif d > 0:
            cnt_p1 += d
    # 基本的に「-2の回数」==「+1の回数」にできればYes。
    # ちなみに同じ数に対する操作として「-2の回数」:「+1の回数」=1:2 ならプラマイゼロで相殺されるので、
    # 相殺可能な操作を足して「-2の回数」==「+1の回数」にできればYes。
    # つまり cnt_m2 >= cnt_p1 ならYes。
    if cnt_m2 >= cnt_p1:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

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

int H, W;
int N;
int a[10005];
int grid[101][101];

int main()
{
    cin >> H >> W >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> a[i];
    }
    int r = 0;
    int c = 0;
    int c_inc = 1;
    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j < a[i]; ++j) {
            grid[r][c] = i;
            c += c_inc;
            if (c >= W) {
                c = W-1;
                r++;
                c_inc = -1;
            }
            if (c <= -1) {
                c = 0;
                r++;
                c_inc = 1;
            }
        }
    }
    for (int i = 0; i < H; ++i) {
        cout << grid[i][0];
        for (int j = 1; j < W; ++j) {
            cout << ' ' << grid[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l

string=input()
removeSize=len(string)-7
target="keyence"
pairs=list()
for idx in range(0,7):
    pair=[target[:idx],target[idx:]]
    pairs.append(pair)
result="NO"
for pair in pairs:

    if string[:len(pair[0])]==pair[0] and string[-len(pair[1]):]==pair[1]:
        result="YES"
print(result)















Measured memory_bytes: 3688
while True:
    values = input().split()
    n = int(values[0])
    x = int(values[1])
    ans = 0
    if n==0 and x==0:
        break
    else:
        for i in range(1, n+1):
            for j in range(1+i, n+1):
                for k in range(1+j, n+1):
                    if (i+j+k)==x:
                            ans += 1
        print(ans)



Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI acos(-1.0)
#define INF 10000000

typedef long long ll;

int n, a, b, c = 0;
vector< pair<int, int> > vpi;
bool f = 0;

int main() {
	while (cin >> n){
		if (!n)break;
		REP(i, n){
			cin >> b >> a;
			pair<int, int> pi;
			pi.first = a;
			pi.second = b;
			vpi.push_back(pi);
		}
		sort(ALL(vpi));
		REP(i, n){
			c += vpi[i].second;
			if (c > vpi[i].first){
				f = 1;
			}
		}
		f ? cout << "No\n" : cout << "Yes\n";
		c = 0;
		f = 0;
		vpi.clear();
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string,int> table;
int main () {
  string word, frequent, longest;
  size_t N=0; //??????????????????
  while (cin >> word) {
    table[word] += 1;
    if (table[word] > N) {
      N = table[word];
      frequent = word;
    }
    if (word.size() > longest.size()) longest = word;
  }
  cout << frequent << " " << longest << endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {  
    ll x,a,b;
    cin >> x >> a >> b;
    if(a>=b)cout << "delicious" << endl;
    else if(a+x>=b)cout << "safe" << endl;
    else cout << "dangerous" << endl;
}


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

int main() {
    string s;
    cin>>s;
    int A=s.at(0)-48, B=s.at(1)-48, C=s.at(2)-48, D=s.at(3)-48;

    if(A+B+C+D==7) cout<<A<<'+'<<B<<'+'<<C<<'+'<<D<<'='<<7<<endl;
    else if(A-B+C+D==7) cout<<A<<'-'<<B<<'+'<<C<<'+'<<D<<'='<<7<<endl;
    else if(A-B-C+D==7) cout<<A<<'-'<<B<<'-'<<C<<'+'<<D<<'='<<7<<endl;
    else if(A-B+C-D==7) cout<<A<<'-'<<B<<'+'<<C<<'-'<<D<<'='<<7<<endl;
    else if(A+B-C+D==7) cout<<A<<'+'<<B<<'-'<<C<<'+'<<D<<'='<<7<<endl;
    else if(A+B-C-D==7) cout<<A<<'+'<<B<<'-'<<C<<'-'<<D<<'='<<7<<endl;
    else if(A+B+C-D==7) cout<<A<<'+'<<B<<'+'<<C<<'-'<<D<<'='<<7<<endl;
    else if(A-B-C-D==7) cout<<A<<'-'<<B<<'-'<<C<<'-'<<D<<'='<<7<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define LL long long

#if 0
int main()
{
    LL n;
    cin >> n;

    LL fb_num = n / 15;
    LL amari = n % 15;

    LL sum = 0;
    for (LL i = 0; i < fb_num; ++i) {
        sum += (60 + 15 * 7 * i);
    }

    if (amari >= 3)
        sum+= 15 * fb_num + 3;
    if (amari >= 5)
        sum += 15 * fb_num + 5;
    if (amari >= 6)
        sum += 15 * fb_num + 6;
    if (amari >= 9)
        sum += 15 * fb_num + 9;
    if (amari >= 10)
        sum += 15 * fb_num + 10;
    if (amari >= 12)
        sum += 15 * fb_num + 12;
    if (amari >= 15)
        sum += 15 * fb_num + 15;

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

int main()
{
    LL n;
    cin >> n;

    LL sum = 0;
    for (LL i = 1; i <= n; ++i) {
        if ((i % 3 != 0) && (i % 5 !=0)) {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3620
N,x = map(int,input().split())

if x <= 2 or 2*N-x <= 2:

    if N == 2 and x == 2:
        print ("Yes")
        print ("1")
        print ("2")
        print ("3")

    elif N >= 3 and (x == 2):

        print ("Yes")
        notend = [True] * (2*N-1)
        lis = [0] * (2*N-1)

        lis[N-1] = x
        notend[x-1] = False
    
        lis[N] = x-1
        notend[x-1-1] = False

        ind = 0

        for i in range(2*N-1):

            if lis[i] == 0:
            
                while not notend[ind]:
                    ind += 1
    
                lis[i] = ind + 1
                notend[ind] = False
            

        for i in lis:
            print (i)

    elif N >= 3 and (x == 2*N-2):

        print ("Yes")
        notend = [True] * (2*N-1)
        lis = [0] * (2*N-1)

        lis[N-1] = x
        notend[x-1] = False
    
        lis[N] = x+1
        notend[x+1-1] = False

        ind = 0

        for i in range(2*N-1):

            if lis[i] == 0:
            
                while not notend[ind]:
                    ind += 1
    
                lis[i] = ind + 1
                notend[ind] = False
            

        for i in lis:
            print (i)  
        

    else:
        print ("No")
    
else:
    print ("Yes")
    notend = [True] * (2*N-1)
    lis = [0] * (2*N-1)

    lis[N-1] = x
    notend[x-1] = False

    lis[N] = x+1
    notend[x+1-1] = False

    lis[N-2] = x-2
    notend[x-2-1] = False

    lis[N+1] = x-1
    notend[x-1-1] = False

    lis[N-3] = x+2
    notend[x+2-1] = False

    ind = 0

    for i in range(2*N-1):

        if lis[i] == 0:
            
            while not notend[ind]:
                ind += 1

            lis[i] = ind + 1
            notend[ind] = False
            

    for i in lis:
        print (i)

        

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

using namespace std;

const int MAX = 100005;
int a[MAX][3];
int dp[MAX][3];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++){
      scanf("%d", &a[i][j]);
    }
  }
  dp[0][0] = a[0][0], dp[0][1] = a[0][1], dp[0][2] = a[0][2];
  for (int i = 1; i < n; i++) {
    dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = a[i][2] + max(dp[i-1][1], dp[i-1][0]);
  }
  printf("%d\n", max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}));
  return 0;
}


Measured memory_bytes: 6152
from collections import deque
N = int(input())


queue = deque(['3', '5', '7'])

ans = set([])
while queue:
    now_nums = queue.popleft()
    if now_nums in ans or int(now_nums) > N:
        continue
    if len(now_nums) >= 3 and '3' in now_nums and '5' in now_nums and '7' in now_nums:
        ans.add(now_nums)
    for next_num in ['3', '5', '7']:
        if int(now_nums + next_num) > N:
            continue
        queue.append(now_nums + next_num)
print(len(ans))


Measured memory_bytes: 13596
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -1e18
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}


void solve()
{
  
  char c;
  cin >> c;
  cout<<(char)(c+1)<<endl;

}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 3620
"""
kari1 = '7 7 5'
in1 = kari1.split()
"""
in1 = input().split()

sujiCNT = [0] * 10

for item in in1:
    sujiCNT[int(item)] = sujiCNT[int(item)] + 1

if sujiCNT[5] == 2 and sujiCNT[7] == 1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    
    long long int l,r;
    int ama=2020000;
    cin>>l>>r;
    
    
    if(r-l>=2019) cout<<0<<endl;
    else{
        l=l%2019; r=r%2019;
        
        if(l<r){
            for(int i=l;i<=r-1;i++){
                for(int j=i+1;j<=r;j++){
                    ama = min((i*j)%2019, ama);   
                    if(ama==0) break;
                }
            }
        }else if(l>r){
            for(int i=r;i<=l-1;i++){
                for(int j=i+1;j<=l;j++){
                    ama = min((i*j)%2019, ama);   
                    if(ama==0) break;
                }
            }
        }else{
            int i=l,j=r; 
            ama = min((i*j)%2019, ama);   
        }
        
        cout<<ama<<endl;
    }
    
    
    
    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    int cnt = 0;
    for(int i=0; i<N; i++) {
        int p;
        cin >> p;
        if(p != i+1) cnt++;
    }

    if(cnt <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import math
from operator import itemgetter

n,h = map(int,input().split())
a = [list(map(int, input().split())) for i in range(n)]

m = max(a)[0]

a.sort(key=itemgetter(1))
a.reverse()
i = 0
ans = 0
while a[i][1] > m:
    h-=a[i][1]
    ans +=1
    i+=1
    if h<=0:
        break
    if i==n:
        break

print(ans+math.ceil(max(h,0)/m))

Measured memory_bytes: 64856
using System;
using System.Linq;

namespace AtCoder.Problems
{
    public class ProblemB
    {
        public static void Main(string[] args)
        {
            var s = new SolveB();
            s.Solve();
        }

        public class Scanner
        {
            private string[] _s;
            private int _i;
            private readonly char[] _separators = new char[] {' '};

            public Scanner()
            {
                _s = new string[0];
                _i = 0;
            }

            public string Next()
            {
                if (_i < _s.Length) return _s[_i++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();
                _s = st.Split(_separators, StringSplitOptions.RemoveEmptyEntries);
                if (_s.Length == 0) return Next();
                _i = 0;
                return _s[_i++];
            }

            public int NextInt() => int.Parse(Next());
            public long NextLong() => long.Parse(Next());
            public ulong NextULong() => ulong.Parse(Next());
            public double NextDouble() => double.Parse(Next());

            public int[] GetIntArray(int n, int add = 0)
            {
                int[] array = new int[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextInt() + add;
                }
                return array;
            }

            public long[] GetLongArray(int n, long add = 0)
            {
                long[] array = new long[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextLong() + add;
                }
                return array;
            }

            public double[] GetDoubleArray(int n, double add = 0)
            {
                double[] array = new double[n];
                for (int i = 0; i < n; i++)
                {
                    array[i] = NextDouble() + add;
                }
                return array;
            }
        }
    }

    public class SolveB
    {
        public void Solve()
        {
            var cin = new ProblemB.Scanner();
            var n = cin.NextInt();
            var m = cin.NextInt();
            var a = cin.GetLongArray(m);
            

            var result = GetAnswer(n, m, a);
            Console.WriteLine(result);
        }

        public long GetAnswer(int n, int m, long[] a)
        {
            long reminder = n - a.Sum();
            return reminder >= 0 ? reminder : -1;
        }
    }
}

Measured memory_bytes: 28964
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int a,b; cin >> a >> b;
	ll ans=1e9;
	for(ll i=a;i<=b;i++){
		for(ll j=i+1;j<=b;j++){
			if(i%2019==0||j%2019==0){
				cout << 0 << endl;
				return 0;
			}
			ans=min(ans,i*j%2019);
		}
	}
	cout << ans << endl;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 1e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

inline ll SetID(ll P, ll x)
{
    return P * 1000000 + x;
}

inline string SetAns(int id)
{
    int i;
    string str;

    for (i = 0; i < 13; i++)
    {
        if (id / pow(10, i) == 0)
            break;  
    }

    REP(j, 12 - i)
        str.push_back(0);
    
    str.push_back(id);

    return  str;
}

int main(int argc, char const *argv[])
{
    int ans[20];
    int r, d, x2000;

    cin >> r >> d >> x2000;

    ans[0] = x2000;

    REP(i, 11)
    {
        ans[i+1] = r * ans[i] - d;
    }

    FOR(i, 1, 11) cout << ans[i] << endl;;

    return 0;
}


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

using namespace std;

set<int> mn,mx;

int data[200005];
unsigned long long ans=0;

int main()
{
  int n,i;

  scanf("%d",&n);
  for(int c=0;c<n;c++)
  {
    scanf("%d",&i);
    data[i]=c;
  }
  for(int c=1;c<=n;c++)
  {
    set<int>::iterator it;
    unsigned long long mncount,mxcount;

    it=mn.upper_bound(-data[c]);
    if (it==mn.end())mncount=data[c];
    else mncount=data[c]-(-(*it))-1;
    it=mx.upper_bound(data[c]);
    if (it==mx.end())mxcount=(n-1)-data[c];
    else mxcount=(*it)-data[c]-1;

    ans+=((mncount*mxcount)+(mncount+mxcount+1))*c;
    mn.insert(-data[c]);
    mx.insert(data[c]);
  }
  printf("%llu\n",ans);
}


Measured memory_bytes: 19840
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N, M;
  cin >> N >> M;

  vector <int> a(2 * M);
  //vector <int> b(M);
  rep(i,2 * M) cin >> a.at(i);

  vector <int> num(N);//都市iから伸びている道路の数
  rep(i,N){
    rep(j,2 * M){
      if (a.at(j) == i + 1) num.at(i) += 1;
    }
  }

  rep(i,N) cout << num.at(i) << endl;
}


Measured memory_bytes: 3616
# -*- coding: utf-8 -*-
"""
"""
import sys
from sys import stdin
from math import factorial
input = stdin.readline


def solve(n, x):
    ans = 0
    for a in range(1, n+1):
        for b in range(a+1, n+1):
            if b < (x - a - b) <= n:
                ans += 1
    return ans


def main(args):
    while True:
        n, x = map(int, input().split())
        if n == 0 and x == 0:
            break
        ans = solve(n, x)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5664
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Itr(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define setp(n) fixed << setprecision(n)
#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define All(a) (a.begin()),(a.end())
#define rAll(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll t,x;
	cin >> t >> x;
	cout << setp(12) << (lf)t/x << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


template <std::uint_fast64_t Modulus> 
struct ModInt {
    using u64 = std::uint_fast64_t;

    u64 a;

    constexpr ModInt(const long long x = 0) noexcept : a(x >= 0 ? x % Modulus : (Modulus - (-x) % Modulus) % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr ModInt operator+(const ModInt rhs) const noexcept {return ModInt(*this) += rhs;}
    constexpr ModInt operator-(const ModInt rhs) const noexcept {return ModInt(*this) -= rhs;}
    constexpr ModInt operator*(const ModInt rhs) const noexcept {return ModInt(*this) *= rhs;}
    constexpr ModInt operator/(const ModInt rhs) const noexcept {return ModInt(*this) /= rhs;}
    constexpr ModInt operator^(const long long rhs) const noexcept {return ModInt(*this) ^= rhs;}
    constexpr ModInt &operator+=(const ModInt rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr ModInt &operator/=(ModInt rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }
    constexpr ModInt &operator^=(long long exp) noexcept {
        ModInt rhs = a;
        a = 1;
        while (exp) {
            if (exp&1) *this *= rhs;
            exp >>= 1;
            rhs *= rhs;
        }
        return *this;
    }

    bool operator==(const ModInt &p) const {return a == p.a;}
    bool operator!=(const ModInt &p) const {return a != p.a;}

};

using mint = ModInt<MOD>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    mint ans = 1;
    while (N--) ans *= K--;
    cout << ans.a << ln;
}


Measured memory_bytes: 3172
#include <stdio.h>

int main() {
    int n,x,t,ans;
    scanf("%d %d %d",&n,&x,&t);
    if (n%x==0) ans = (n/x) * t;
    else ans = ((n/x) + 1) * t;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1736
use std::cmp::{max, min};

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let n = scan!(i64);

    let mut min_val = 1 << 60;
    for i in 1.. {
        if i * i > n {
            println!("{}", min_val);
            return;
        }
        if n % i != 0 {
            continue;
        }
        min_val = min(
            min_val,
            max(
                i.to_string().chars().count(),
                (n / i).to_string().chars().count(),
            ),
        )
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int,int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    string S;
    ll K;
    cin>>S>>K;
    bool ok=false;
    int answer;
    rep(i,K) {
        if(S[i]!='1') {
            cout<<S[i]<<endl;
            ok=true;
            break;
        }
    }
    if(ok==0) cout<<1<<endl;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    ll a, b, k;
    cin >> a >> b >> k;
    cout << max(ll(0), a - k) << " " << max(ll(0), min(b, b - (k - a))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);

	int A[100][100];
	int b[100];
	int Ab[100] = { 0 };

	int i, j;
	for (i = 0; i < n; ++i) {
		for (j = 0; j < m; ++j) {
			scanf("%d", &A[i][j]);
		}
	}
	for (i = 0; i < m; ++i) {
		scanf("%d", &b[i]);
	}

	for (i = 0; i < n; ++i) {
		for (j = 0; j < m; ++j) {
			Ab[i] += A[i][j] * b[j];
		}
	}

	for (i = 0; i < n; ++i) {
		printf("%d\n", Ab[i]);
	}
	
	return(0);
}


Measured memory_bytes: 2140
import java.util.*;

public class Main {
	public static void main(String[] args) {
		new Main().execute();
	}

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final long N = sc.nextLong();
		final long M = sc.nextLong();
		System.out.println(countCards(N, M));
		sc.close();
	}

	private long countCards(long n, long m) {
		if (n > m) {
			return countCards(m, n);
		}

		if (n == 1) {
			if (m == 1) {
				return 1;
			} else if (m == 2) {
				return 0;
			} else {
				return m - 2;
			}
		} else if (n == 2) {
			return 0;
		} else {
			return (n - 2) * (m - 2);
		}

	}

	private int testCode(int x, int y) {
		final int XSIZE = x;
		final int YSIZE = y;
		int[] a = { -1, 0, 1 };
		int[][] board = new int[XSIZE + 2][YSIZE + 2];

		for (int i = 0; i < XSIZE + 2; i++) {
			board[i][0] = -1;
			board[i][YSIZE + 1] = -1;
		}

		for (int i = 0; i < YSIZE + 2; i++) {
			board[0][i] = -1;
			board[XSIZE + 1][i] = -1;
		}

		for (int i = 1; i <= XSIZE; i++) {
			for (int j = 1; j <= YSIZE; j++) {
				for (int s : a) {
					for (int t : a) {
						if (board[i + s][j + t] >= 0) {
							board[i + s][j + t] += 1;
						}
					}
				}
			}
		}
		int cnt = 0;
		for (int i = 1; i <= XSIZE; i++) {
			for (int j = 1; j <= YSIZE; j++) {
				if (board[i][j] % 2 == 1) {
					cnt++;
				}
			}
		}
		printBoard(board);
		return cnt;
	}

	private void printBoard(int[][] board) {
		for (int i = 0; i < board.length; i++) {
			for (int j = 0; j < board[i].length; j++) {
				if (board[i][j] == -1) {
					System.out.print('x');
				} else {
					System.out.print(board[i][j]);
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 23124
#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 N,M;
    cin >> N >> M;
    vector<pair<int,int>> PY[N+1];
    rep(i,M){
        int P,Y;
        cin >> P >> Y;
        PY[P].push_back({Y,i}); // 何番目の市であるかの情報も持っておく.
    }
    vector<pair<int,int>> ans(M+1);
    for(int Pi=1;Pi<=N;Pi++){
        sort(PY[Pi].begin(),PY[Pi].end());
        for(int j=0;j<PY[Pi].size();j++){
            ans[PY[Pi][j].second] = {Pi,j+1}; //順番は1始まりなので+1.
        }        
    }
    for(int i=0;i<M;i++){
        //cout << setw(6) << setfill('0') << ans[i].first;
        //cout << setw(6) << setfill('0') << ans[i].second << endl;
        printf("%06d%06d\n",ans[i].first,ans[i].second);
    }
    return 0;
}

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

int main(){
    int n,q; cin >> n >> q;
    string s; cin >> s;
    vector<int> sum(n+1); //i文字目までの中のac
    for(int i = 1; i < n; i++){
        sum.at(i+1) = sum.at(i);
        if(s.at(i - 1) == 'A' && s.at(i) == 'C') sum.at(i + 1)++; 
    }
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        cout << sum.at(r) - sum.at(l) << endl;
    }

}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define mod 1e9+7
bool is_prime(ll x)
{     
       if(x<1)
       return false;
       
       for(ll i=2; i*i<=x; i++){
	     if(x%i==0)
	       return false;
	   }   
	   return true;
}
int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);    
    
     ll    x;
             cin>>x;
            
            while(!(is_prime(x)))
             x++;
               cout<<x; 
             
       
    }


Measured memory_bytes: 256
from collections import defaultdict
def main():
    N = int(input())
    vote = defaultdict(int)
    for i in range(N):
        vote[input()] += 1
    max_vote = max(vote.values())
    new_vote = sorted(list(vote.items()), key= lambda x : x[0])
    new_vote = sorted(new_vote, key= lambda x : x[1], reverse = True)
    for k, v in new_vote:
        if v == max_vote:
            print(k)
        else:
            break
if __name__ == "__main__":
    main()

Measured memory_bytes: 48476
#include<stdio.h>
#include<string.h>

struct saikoro{

    int Me[6] = {1, 2, 3, 4, 5, 6};
    int Size[6] = {0};
    int up, down;
    int south, east, west, north;
    int next_up, next_down, next_south, next_east, next_west, next_north;
public : 
    saikoro(){  //初期化
        up = Me[0];
        south = Me[1];
        east = Me[2];
        west = Me[3];
        north = Me[4];
        down = Me[5];
    }
    int gettop(){ return up; }
    void change(char ch){
        if(ch == 'S'){
        next_up = north;
        next_south = up;
        next_north = down;
        next_down = south;

        up = next_up;
        south = next_south;
        north = next_north;
        down = next_down;
        } else if(ch == 'N'){
        next_up = south;
        next_south = down;
        next_north = up;
        next_down = north; 

        up = next_up;
        south = next_south;
        north = next_north;
        down = next_down;
        } else if(ch == 'E'){
        next_up = west;
        next_east = up;
        next_west = down;
        next_down = east; 

        up = next_up;
        east = next_east;
        west = next_west;
        down = next_down;
        } else if(ch == 'W'){       
        next_up = east;
        next_east = down;
        next_west = up;
        next_down = west; 

        up = next_up;
        east = next_east;
        west = next_west;
        down = next_down;
        }
    }
    

};

int main(){

    saikoro S;
    for(int i=0; i<6; i++){
        scanf("%d", &S.Size[i]);
    }

    char str[100];
    scanf("%s", str);
    for(int i=0; i<strlen(str); i++){
        S.change(str[i]);
    }
    printf("%d\n", S.Size[S.gettop()-1]);
    return 0;
}


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

int main()
{
   int i,j,t,n,m,a,b,c;
   cin >> n >> m ;
   int arr[n+1];
   for(int i = 1 ; i <=n; i++)
   cin >> arr[i];
   int dp[n+1];
   dp[0] = 0;
   dp[1] = 0;
   dp[2] = abs(arr[2] - arr[1]);
   int min1 = INT_MAX;
   for(int i = 3 ;i<=n ;i++)
   {
     min1 = INT_MAX;
     for(int j = (i-m) ;j < i ; j++)
     {
         if(j>=1)
         {
             int temp = dp[j] + abs(arr[i] - arr[j]);
             if(min1 > temp)
             min1 = temp;
         }
     }
     dp[i] = min1;
     //cout<<dp[i]<<" ";
   }
   cout<<dp[n]<<endl;
   return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N;
      cin >> N;
            
      for(int i=0; i<N; i++){
        string S;
        cin >> S;
                
        if(S == "Y"){
        cout << "Four" << endl;
          break;
        }
        else if(i == N-1){
        cout << "Three" << endl;
        }
      }
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IO std::ios::sync_with_stdio(false);std::cin.tie(0)
#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 mset(s,_) memset(s,_,sizeof s)
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define mk make_pair
using namespace std;
const int maxn=1000010;
ll vp[maxn+10],p[maxn+10];
void prime(){
	  vp[0]=vp[1] = 1;    //0和1为合数
	for(ll i = 2; i < maxn; i++){
		if(!vp[i]) p[++p[0]] = i;        //p[]里面的是素数
		for(ll j = 1; j <=p[0] && i * p[j]<maxn; j++){
			vp[i * p[j]] = 1;
			if(i % p[j] == 0) break;
		}
	}
}
vector<ll>v;
void init(){
	for(ll i=1;i<=p[0];i++){
		for(ll j=p[i];j<=1000000000000;j*=p[i]){
			v.push_back(j);
		}
	}
}
int main(){
 prime();
 init();
 ll n;
 sort(v.begin(),v.end());
 while(cin>>n){
 int ans=0,w1=0;
 for(int i=0;i<v.size();i++){
 	if(n%v[i]==0) n/=v[i],ans++,vp[v[i]]=1;
	if(n<v[i]) break;
  }
		if(n>1000000) cout<<ans+1<<'\n';
		else cout<<ans<<'\n';
 }
}




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

using namespace std;
typedef long long ll;
ll n,W;
ll wt[100000+1],v[100000+1];
ll mo(ll x){
  if(x>0) return x;
  else return -x;
}
int main() {
  cin>>n>>W;
  ll dp[n+2][1000*n+1],ans=0;
  for(int i=0; i<n; i++) {
    for(int j=0; j<=1000*n; j++) dp[i][j]=INT_MAX;
  }
  for(int i=0; i<n; i++){
    cin>>wt[i]>>v[i];
    dp[i][0]=0;
  }  
  
  for(int i=0; i<n; i++){
    for(int j=1000*n; j>=0; j--){
      if (j - v[i] >= 0)
          dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + wt[i]);
      else
          dp[i + 1][j] = dp[i][j];
    }
  }
  for(int i=0; i<1000*n+1; i++)
    if(dp[n][i]<=W) ans=i;
  cout<<ans<<endl;
}

Measured memory_bytes: 79872