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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        
        char s[][] = new char[H][W];
        for(int i = 0; i < H; i++) {
            s[i] = sc.next().toCharArray();
        }
        
        boolean isAllOK = true;
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if( s[i][j] == '.' ) continue;
                
                boolean isOK = false;
                if( 0 <= i-1 && s[i-1][j] == '#' ) {
                    isOK = true;
                }
                if( i+1 < H && s[i+1][j] == '#' ) {
                    isOK = true;
                }
                if( 0 <= j-1 && s[i][j-1] == '#' ) {
                    isOK = true;
                }
                if( j+1 < W && s[i][j+1] == '#' ) {
                    isOK = true;
                }
                
                if( !isOK ) {
                    isAllOK = false;
                }
            }
        }
        
        System.out.println( (isAllOK) ? "Yes" : "No" );
    }
}


Measured memory_bytes: 35736
import sys
import queue

N = 3
f= ''.join(sys.stdin.readline().split())
f+= ''.join(sys.stdin.readline().split())
f+= ''.join(sys.stdin.readline().split())

dd = [[-1, 0], [0, -1], [1, 0], [0, 1]]

Q = queue.Queue()
V = dict()

Q.put([f,f.index('0'),0])
V[f] = True

while not Q.empty():
    u = Q.get()
    if u[0] == '123456780':  break
    sx, sy = u[1]//N, u[1]%N
    for dx, dy in dd:
        tx, ty = sx+dx, sy+dy
        if tx<0 or ty<0 or tx>=N or ty>=N: continue
        v = u[:]
        n1, n2 = u[1], tx*N+ty
        v[1] = n2
        if n1>n2: n1, n2 = n2, n1
        v[0] = v[0][0:n1]+v[0][n2]+v[0][n1+1:n2]+v[0][n1]+v[0][n2+1:]
        if not V.get(v[0], False):
            V[v[0]] = True
            v[2] += 1                                                    
            Q.put(v)

print(u[2])


Measured memory_bytes: 34416
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<cstring>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<numeric>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll dp[101000];
int vis[101000];
ll n,k;
vector<int>q[101000];
struct node
{
    int x,bb;
};
void solve(int x)
{
    queue<node>s;
    node now;
    int num=q[x].size();
    for(int i=0;i<q[x].size();i++)
    {
        now.x=q[x][i];
        now.bb=x;
        dp[now.x]-=num;
        num--;
        s.push(now);
    }
    node x1;
    int qqq=0;
    while(!s.empty())
    {
        now=s.front();
        s.pop();
        int num=q[now.x].size();
        for(int i=0;i<q[now.x].size();i++)
        {
            if(now.bb==q[now.x][i])
                continue;
            int nowx=q[now.x][i];
            dp[nowx]-=num;
            x1.x=nowx,x1.bb=now.x;
            num--;
            s.push(x1);

            qqq++;
        }

    }
    ll ans=1;
    for(int i=1;i<=n;i++)
    {
        ans*=dp[i];
        ans%=1000000007;
    }
    cout<<ans<<endl;
//    cout<<qqq<<endl;
}

int main()
{
    cin>>n>>k;
    ll a,b;
    for(int i=1;i<n;i++)
    {
        scanf("%lld%lld",&a,&b);
        q[a].push_back(b);
        q[b].push_back(a);
        dp[i]=k;
    }
    dp[n]=k;
            solve(1);

}


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

using namespace std;

int main(int argc, char const *argv[])
{
    int n, K;
    cin >> n >> K;
    vector<int> h(n + 1);

    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }

    vector<int> dp(n + 1);

    h[0] = 1001001001;
    dp[0] = 0;
    dp[1] = 0;

    for (int i = 2; i <= n; i++)
    {
        dp[i] = 1001001001;
    }

    for (int i = 1; i < n; i++)
    {
        for (int k = 1; k <= K; k++)
        {
            if (i + 1 >= k)
                dp[i + 1] = min(dp[i + 1 - k] + abs(h[i + 1] - h[i + 1 - k]), dp[i + 1]);
        }
    }

    /*
    for(int i =0; i <= n;i++){
        cout << dp[i] << endl;
    }
    */

    cout << dp[n] << endl;
    return 0;
}


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

int main()
{
	int N, A, B;
	while (cin >> N >> A >> B)
	{
		string str;
		cin >> str;
		int b = 0;
		int cnt = 0;
		for (int i = 0; i < N; ++i)
		{
			if (cnt >= A + B)
				cout << "No" << endl;
			else
			{
				if (str[i] == 'a')
				{
					cout << "Yes" << endl;
					++cnt;
				}
				else if (str[i] == 'b')
				{
					++b;
					if (b <= B)
					{
						cout << "Yes" << endl;
						++cnt;
					}
					else
						cout << "No" << endl;
				}
				else
					cout << "No" << endl;
			}		
		}
	}
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    int n;cin >> n;
    vector<ll> a(n),b(n),c(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];
    for(int i=0; i<n; i++) cin >> c[i];
    ll ans=0;
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    for(int i=0; i<n; i++){
        ll up=lower_bound(a.begin(),a.end(),b[i])-a.begin();
        ll down=c.end()-upper_bound(c.begin(),c.end(),b[i]);
        ans+=up*down;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2688
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)*}
    };
}

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64
    }

    let x_abs = x.abs();
    let num = (x_abs / d).abs();
    if num >= k {
        println!("{}", x_abs - d * k);
    } else {
        let a = (x_abs - d * num).abs();
        let b = (x_abs - d * (num + 1)).abs();
        if (k - num) % 2 == 0 {
            println!("{}", a);
        } else {
            println!("{}", b);
        }
    }
}

// x / d + 1 または x / d または k 回移動した後の位置となる


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  ll N;cin>>N;
  int t=N%10;
  if(((t==2 || t==4) || (t==5 || t==7)) || t==9) cout<<"hon"<<endl;
  if((t==0 || t==1) || (t==6 || t==8)) cout<<"pon"<<endl;
  if(t==3)cout<<"bon"<<endl;
}

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

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

  vector<ll> m(n + 1);

  for (int i = 1; i <= n; i++) {
    int mul = 1;
    while (mul * i <= n) {
      m[mul * i]++;
      mul++;
    }
  }

  ll total = 0;

  rep(i, n) {
    int k = i + 1;
    total += k * m[k];
  }

  cout << total << endl;

  return 0;
}


Measured memory_bytes: 81396
suits = ['S', 'H', 'C', 'D']
table = [[False] * 14 for i in range(4)]

N = int(input())
for _i in range(N):
    mark, num = input().split()
    num = int(num)

    if mark == 'S':
        table[0][num] = True
    if mark == 'H':
        table[1][num] = True
    if mark == 'C':
        table[2][num] = True
    if mark == 'D':
        table[3][num] = True

for i in range(4):
    for j in range(1, 14):
        if not table[i][j]:
            print(f'{suits[i]} {j}')


Measured memory_bytes: 5616
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Dec 27 13:13:05 2018
//
package main

import (
  "fmt"
)

func max(arr... int)int{
	ret := 0
	for i := range arr{
		if ret < arr[i] {
			ret = arr[i]
		}
	}
	return ret
}

func pow2(n int)int{
	if n == 0{
		return 1
	}
	return 2 * pow2(n-1)
}

func main(){
	var A, B, C int
	var K int
	fmt.Scan(&A, &B, &C)
	fmt.Scan(&K)

	fmt.Println(A+B+C-max(A,B,C) + pow2(K)*max(A,B,C))
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x,a,b;
    cin>>x>>a>>b;
    int d1=abs(x-a);
    int d2=abs(x-b);
    if(d1<d2)
        cout<<"A\n";
    else
        cout<<"B\n";
    return 0;
}
/**

**/


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

int main()
{
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    S[K-1] = S[K-1] + 32;

    cout << S << endl;
    return 0;
}

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

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
typedef long long ll;

/* 2010/00/00 問題 -----  ABC 050 B /Link http://abc050.contest.atcoder.jp/tasks/abc050_b */
/* -----解説等-----
問題:oisinoお姉ちゃんは、あるプログラミングコンテストの決勝を控えています。
このコンテストでは、N 問の問題が用意されており、それらには 1~N の番号がついています。
joisinoお姉ちゃんは、問題 i(1≦i≦N) を解くのにかかる時間が Ti 秒であることを知っています。

また、このコンテストでは、M 種類のドリンクが提供されており、1~M の番号がついています。
そして、ドリンク i(1≦i≦M) を飲むと、脳が刺激され、問題 Pi を解くのにかかる時間が Xi 秒になります。
他の問題を解くのにかかる時間に変化はありません。

コンテスタントは、コンテスト開始前にいずれかのドリンクを 1 本だけ飲むことができます。
joisinoお姉ちゃんは、それぞれのドリンクについて、それを飲んだ際に、全ての問題を解くのに何秒必要なのかを知りたくなりました。 全ての問題を解くのに必要な時間とは、それぞれの問題を解くのにかかる時間の合計です。 あなたの仕事は、joisinoお姉ちゃんの代わりにこれを求めるプログラムを作成することです。

ans:
問題の制約から添え字がごちゃごちゃしているが
総和をとってドリンクの部分を差をとって訂正するだけ。

*/

int N;
int T[100000];
int M;
int P[100000], X[100000];
ll sum = 0, ans = 0;

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

    cin >> N;
    FOR(i, 0, N) {
        cin >> T[i];
        sum += T[i];
    }

    cin >> M;
    FOR(i, 0, M) {
        cin >> P[i] >> X[i];
        ans = sum-T[P[i]-1]+X[i];
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    for(int i=0;i<2;i++){
        for(int j=0;j<2-i;j++){
            if(a[j]>a[j+1]){
                int esc = a[j];
                a[j] = a[j+1];
                a[j+1] = esc;
            }
        }
    }
    
    cout << a[0] << " " << a[1] << " " << a[2] << endl;
}


Measured memory_bytes: 3112
S=input()
new_S1=list(reversed(S))
new_S2=''.join(new_S1)
if S==new_S2:
    A=S[0:len(S)//2]
    new_A1 = list(reversed(A))
    new_A2 = ''.join(new_A1)
    B=S[len(S)//2+1:len(S)]
    new_B1 = list(reversed(B))
    new_B2 = ''.join(new_B1)
    if A==new_A2 and B==new_B2:
        print('Yes')
    else:
        print('No')
else:
    print('No')



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

S_array = [[int(s) for s in input()] for _ in range(N)]

# print(S_array)
# s_deg_array = [0] * N

# for i in range(N):
#     for j in range(i + 1, N):
#         if S_array[i][j] == 1:
#             s_deg_array[i] += 1
#             s_deg_array[j] += 1

ans_max = 0

for fp in range(N):
    ans = 0
    d = deque()
    d.append(fp)
    used_array = [-1] * N
    value_array = [-1] * N
    used_array[fp] = 1
    value_array[fp] = 1
    while len(d):
        p = d.popleft()
        v = value_array[p]
        # print(p, v)
        for i, s in enumerate(S_array[p]):
            if s == 0:
                continue
            if used_array[i] == -1:
                used_array[i] = 1
                value_array[i] = v + 1
                ans = max(ans, v + 1)
                d.append(i)
            else:
                if value_array[i] != v - 1 and value_array[i] != v + 1:
                    print(-1)
                    exit()
    ans_max = max(ans, ans_max)

print(ans_max)

Measured memory_bytes: 44508
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	pl := make([]int, n)
	ml := make([]int, n)
	pl[0] = nextInt()
	ml[0] = pl[0]

	cnt := 1 // 1は絶対にOK
	for i := 1; i < n; i++ {
		pl[i] = nextInt()
		ml[i] = min(ml[i-1], pl[i])
		if pl[i] == ml[i] {
			cnt++
		}
	}

	fmt.Println(cnt)

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

// ---- readfunc
func scanInit() {
	const cap = 1000 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 7456
var
   s:string;
   l,a,b,i:longint;
begin
   read(s); 
   l:=length(s);
   for i:=1 to l do if s[i]='Z'then b:=i;
   for i:=l downto 1 do if s[i]='A'then a:=i;
   writeln(b-a+1);
end.

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

int main() {
  int n;
  cin >> n;
  vector<string>data(n);
  unordered_map<std::string, int> mp;
  for(int i = 0;i < n;i++){
    cin >> data[i];
    if(i > 0){
      if(data[i-1][data[i-1].size()-1] != data[i][0]){
        cout << "No" << endl;
        return 0;
      }
    }
    auto itr = mp.find(data[i]);
    if( itr != mp.end() ) {
      cout << "No" << endl;
      return 0;
    } 
    else {
      mp[data[i]] = 1;
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;

class Point {
    public:
        double x, y;
        Point(double x = 0.0, double y = 0.0): x(x), y(y) {}

        Point operator + (Point p) { return Point(x + p.x, y + p.y); }
        Point operator - (Point p) { return Point(x - p.x, y - p.y); }
        Point operator * (double k) { return Point(x * k, y * k); }
        Point operator / (double k) { return Point(x / k, y / k); }

        double friend norm(Point p) { return p.x * p.x + p.y * p.y; }
        double friend abs(Point p) { return sqrt(norm(p)); }
};
typedef Point Vector;
struct Segment {
    Point p1, p2;
};

double dot(Segment s1, Segment s2) {
    Vector v1 = s1.p2 - s1.p1, v2 = s2.p2 - s2.p1;
    return v1.x * v2.x + v1.y * v2.y;
}

double cross(Segment s1, Segment s2) {
    Vector v1 = s1.p2 - s1.p1, v2 = s2.p2 - s2.p1;    
    return v1.x * v2.y - v1.y * v2.x;
}

int main(void) {
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        Segment s[2];
        for (int j = 0; j < 2; j++)
            cin >> s[j].p1.x >> s[j].p1.y >> s[j].p2.x >> s[j].p2.y;
        if (!cross(s[0], s[1])) cout << "2\n";
        else if (!dot(s[0], s[1])) cout << "1\n";
        else cout << "0\n";
    }
    return 0;
}


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

int main(void) {
     int n;
     cin >> n;
     int a,b;
     cin >> a >> b;

     for(int i=a; i<=b; i++){
         if(i%n==0){
             cout << "OK" << endl;
             return 0;
         }
     }

     cout << "NG";
   
      return 0;
}


Measured memory_bytes: 3608
import java.util.*;
public class Main{
   public static void main(String[] args) {
     Scanner sc = new Scanner(System.in);
     String  S = sc.next();
     boolean ans=true;
     String S1,S2;
     int n,i;
    
     n = S.length();
     S1=S.substring(0,(n-1)/2);
     S2=S.substring((n+3)/2-1,n);
     String[] s=S.split("",0);
     String[] s1=S1.split("",0);
     String[] s2=S2.split("",0);
     for(i=0;i<(n+1)/2;i++){
       if(!s[i].equals(s[n-i-1])){
         ans = false;
       }
     }
     n = S1.length();
     for(i=0;i<(n+1)/2;i++){
       if(!s1[i].equals(s1[n-i-1])){
         ans = false;
       }
     }
     n = S2.length();
     for(i=0;i<(n+1)/2;i++){
       if(!s2[i].equals(s2[n-i-1])){
         ans = false;
       }
     }
     if(ans){
       System.out.println("Yes");
     }else{
       System.out.println("No");

     }
   }
}


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

#define LL long long

vector<pair<int,int> > G[100009];
string ans[100009];

int get_len(int x){
	int val=0;
	while(x>0){
		val++;
		x/=10;
	}
	return val;
}

int main(){
	

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n,m;
	cin>>n>>m;

	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;

		G[x].push_back(make_pair(y,i));
	}
	

	for(int i=1;i<=n;i++){
		sort(G[i].begin(),G[i].end());
	}
	
	for(int i=1;i<=n;i++){
		for(int j=0;j<(int)G[i].size();j++){
			
			int idx = G[i][j].second;
			string res;
			int len = get_len(i);
			
			while(len<6){
				res.push_back('0');
				len++;
			}
			stack<int> st;
			int x=i;
			while(x>0){
				st.push(x%10);
				x/=10;
			}
			while(!st.empty()){
				res.push_back(st.top()+'0');st.pop();
			}

			len = get_len(j+1);
			while(len<6){
				res.push_back('0');
				len++;
			}
			x=j+1;
			while(x>0){
				st.push(x%10);
				x/=10;
			}
			while(!st.empty()){
				res.push_back(st.top()+'0');st.pop();
			}
			ans[idx] = res;
		}
	}
	for(int i=1;i<=m;i++){cout<<ans[i]<<endl;}
}

Measured memory_bytes: 13952
// 5/22
// 過去問ガリガリ
#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>;
using Graph = vector<vector<int>>;

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

    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    vector<int> v(N);
    rep(i, N) v[i] = i + 1;

    int count = 0;
    int ans = 0;
    do {
        if (P == v) ans += count;
        if (Q == v) ans -= count;
        count++;
    } while (next_permutation(v.begin(), v.end()));

    cout << abs(ans) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,k; cin>>n>>k;
    vector<ll> a(n),partsum(n+1,0);
    rep(i,n){
        ll x; cin>>x; a[i]=x%k;
        partsum[i+1]=a[i];
        partsum[i+1]+=partsum[i];
        partsum[i+1]%=k;
    }
    rep(i,n+1){
        partsum[i]-=i;
        if(partsum[i]<0){
            partsum[i]+=(abs(partsum[i]/k)+1)*k;
        }
        partsum[i]%=k;
    }
    //sort(partsum.begin(),partsum.end());
    ll ans=0;
    map<ll,ll> cnt;
    if(k==1){cout<<0<<endl; return 0;}
    rep(i,min(k,n+1))cnt[partsum[i]]++; 
    rep(i,n+1){
      	ans+=cnt[partsum[i]]-1;
        cnt[partsum[i]]--;
        if(i+k<n+1)cnt[partsum[i+k]]++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
#include<cstdio>
inline int in();
inline void wr(int);
const int N=(int)1e5+5;
int a[N];
inline int mx(int,int);
int main(int argc,char**argv){
	register int n=in();
	for(register int i=1;i<=n;++i)
		a[i]=in();
	register int ans=0;
	for(register int i=1;i<=n;++i){
		register int j;
		for(j=i+1;a[j-1]>=a[j]&&j<=n;++j);
		ans=mx(ans,j-1-i);i=j-1;
	}
	wr(ans),putchar('\n');
}
inline int mx(int x,int y){
	return x>y?x:y;
}
inline int in(){
	register char c=getchar();
	register int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(int x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll MOD = (ll)pow(10, 9) + 7;

int main(){
  ll N, K;
  cin >> N >> K;

  ll ans = 0;

  rep2(k, K, N + 2){
    ans += (ll)k * (ll)(2*N - k + 1) / 2 - (ll)k * (ll)(k - 1) / 2 + 1;
    ans %= MOD;
  }

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


Measured memory_bytes: 3632
import sys

read = sys.stdin.buffer.read


def main():
    N, K, *AF = map(int, read().split())
    A = AF[:N]
    F = AF[N:]

    A.sort()
    F.sort(reverse=True)

    ok = pow(10, 12)
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2

        k = 0
        for i in range(N):
            if A[i] * F[i] > mid:
                k += A[i] - mid // F[i]

        if k <= K:
            ok = mid
        else:
            ng = mid

    print(ok)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 121028
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;

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

  string s; cin >> s;
  int k; cin >> k;
  int n = s.size();
  char goal = 'z' + 1;

  rep(i, n) {
    int diff = s[i] == 'a' ? 0 : goal - s[i];
    if(i == n - 1) {
      if(k >= diff) {
        k -= diff;
        s[i] = 'a';
      }

      s[i] += k % 26;
    }
    else if(k >= diff) {
      k -= diff;
      s[i] = 'a';
    }
  }

  cout << s << endl;
}


Measured memory_bytes: 592
S = input()
T = input()

ans = 0
for i in range(len(S)-len(T)+1):
    tmp = 0
    pos = i
    for j in range(len(T)):
        if pos < len(S):
            if S[pos] == T[j]:
                tmp += 1
        pos += 1
    ans = max(tmp, ans)

print(len(T)-ans)

Measured memory_bytes: 73420
Imports System

Module practiceA
    Sub Main()
        Call test2()


    End Sub

    Sub test1()
        Dim K, i, A, B As Integer
        Dim arr(2) As String

        K = Console.ReadLine()
        arr = Split(Console.ReadLine())
        A = arr(0)
        B = arr(1)

        If A <= B Then

            While K * i <= 1000

                If K * i >= A And K * i <= B Then
                    Console.Write("OK")
                    Exit Sub
                Else
                    i = i + 1
                End If

            End While

        End If

        Console.Write("NG")

    End Sub

    Sub test2()
        Dim yokinn, X, year As Double

        yokinn = 100
        year = 0

        X = Console.ReadLine()

        While yokinn < X

            yokinn = Int(yokinn + yokinn * 0.01)

            year += 1

        End While

        Console.Write(year)


    End Sub

    Sub test3()
        Dim N, i, count As Integer

        count = 1

        N = Console.ReadLine()

        Dim stringlist(N - 1) As String

        For i = 0 To N - 1
            stringlist(i) = Console.ReadLine()
        Next i

        Dim uniqueFoods() As String = stringlist.Distinct.ToArray

        count = uniqueFoods.Length

        Console.WriteLine(count)

    End Sub


End Module

Measured memory_bytes: 28440
def five_antennas(a,n):
    kyori = a[n-1]
    for i in range(n-1):
        for j in range(n-1):
            if i != j:
                distance = abs(a[i] - a[j])
                if kyori < distance:
                    return ":("
    return "Yay!"

if __name__ == '__main__':
    a = []
    for i in range(6):
        a.append(int(raw_input()))

    print five_antennas(a,6)

Measured memory_bytes: 2568
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

vector<pii> pos[2][1000000];

int card[100000];
int tate[2][500];
int yoko[2][500];
int naname1[2];
int naname2[2];
bool mita[1000000];
int num[2];

int main() {
  int n,u[2],m;
  cin>>n>>u[0]>>u[1]>>m;
  REP(k,2) {
    REP(i,n)REP(j,n) {
      int a;cin >> a;a--;
      pos[k][a].push_back(pii(i,j));
    }
  }
  REP(i,m)cin>>card[i];

  if (n==1) u[0]*=4,u[1]*=4;
  REP(i,m) {
    card[i]--;
    if (mita[card[i]]) continue;
    mita[card[i]] = 1;

    int win = 0;
    REP(j,2) {
      FOR(it, pos[j][card[i]]) {
        int y=it->first,x=it->second;
        if (++yoko[j][y]==n) num[j]++;
        if (++tate[j][x]==n) num[j]++;
        if (x==y) {
          if (++naname1[j]==n) num[j]++;
        }
        if (x==n-y-1) {
          if (++naname2[j]==n) num[j]++;
        }
      }
      if (num[j]>=u[j]) win |= 1<<j;
    }
    // cout << card[i] << endl;
    // cout << num[0] << " " << num[1] << endl;
    if (win) {
      if (win == 1) cout << "USAGI" << endl;
      else if (win == 2) cout << "NEKO" << endl;
      else if (win == 3) cout << "DRAW" << endl;
      return 0;
    }
  }
  cout << "DRAW" << endl;
}

Measured memory_bytes: 29000
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int main() {
	int n;
	cin >> n;
	string d = "";

	char c;
	REP(i, n) {
		cin >> c;
		d += c;
	}

	vi ints(100000, 0);
	int l = d.size();
	FOR(i, 1, 5) {
		FOR(j, 0, l - i) {
			ints[toInt(d.substr(j, i))] = 1;
		}
	}

	REP(i, 10000) {
		if (!ints[i]) {
			cout << i << endl;
			break;
		}
	}

}

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

int main(void) {
	int n, i;
	cin >> n;
	int sec[8] = { 64,32,16,8,4,2,1 };
	for (i = 0; i <8; i++) {
		if (n >= sec[i]) break;
	}
	cout << sec[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
using namespace std;
int main()
{
	ll int n;
	cin>>n;
	ll int a[n],f[100005]={0},i,s=0;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		f[a[i]]++;
		s+=a[i];
	}
	ll int q;
	cin>>q;
	while(q--)
	{
		ll int b,c;
		cin>>b>>c;
		s+=f[b]*(c-b);
		f[c]+=f[b];
		f[b]=0;
		cout<<s<<endl;
	}
	
}
    
	
		

	
			

		


 







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

//#define DEBUG 1

//#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) iter(v) {pr(*it)} nl
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

int dp[305][305][305];

int32_t main()
{
    #ifdef DEBUG
    //freopen("C.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    string s;
    int K;
    cin >> s;
    cin >> K;
    int n = s.length();
    s = "3"+s;
    
    ms(dp,0);
    for (int i=1; i<=n; i++) {
        for (int k=0; k<=K; k++) {
            dp[k][i][i] = 1;
        }
    }
    
    for (int k=0; k<=K; k++) {
        for (int i=n; i>=1; i--) {
            for (int j=i; j<=n; j++) {
                //pr(i) pr(j) nl
                int v = 0;
                v = max(v, dp[k][i+1][j]);
                v = max(v, dp[k][i][j-1]);
                if (s[i] == s[j])
                    v = max(v, dp[k][i+1][j-1]+2-(i==j));
                else if (k > 0)
                    v = max(v, dp[k-1][i+1][j-1]+2-(i==j));
                dp[k][i][j] = v;
            }
        }
    }
    print2D(dp[0],n+1,n+1);
    int ans = dp[K][1][n];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 111104
N = int(input())
S = [input() for i in range(N)]

list = {}
for i in S:
  i=''.join(sorted(i))
  if i in list:
    list[i] = list[i] + 1
  else:
    list[i] = 1

count = 0
for i in list.values():
  n = i - 1
  count = count + int(((n * (n + 1)) / 2))
  
print(count)

Measured memory_bytes: 24976
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	string n;
	cin >> n;
	int l = n.size();
	int tot = 0;

	for (int i = 0; i < l; i++) {
		tot += n[i] - '0';
	}

	if (tot % 9 == 0) {
		cout <<"Yes"<< endl;
	}
	else {
		cout <<"No"<< endl;
	}

	return 0;
}

Measured memory_bytes: 3696
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0)); 
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int n,k;
int a[5010];

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    cin >> n >> k;
    int ans=0;
    rep(i,n) cin >> a[i];
    rep(i,n){
        int sum=k;
        rep(j,n) if(i!=j){
            if(sum>=a[j]) sum-=a[j];
        }
        if(sum>a[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ')
end


 A=lines[0][0].to_i+lines[0][1].to_i*lines[2][0].to_i
B=lines[1][0].to_i+lines[1][1].to_i*lines[2][0].to_i

if lines[0][0].to_i<lines[1][0].to_i
	if A>=B
 	  print 'YES'
	else
  	 print 'NO'
	end
end
if lines[0][0].to_i>lines[1][0].to_i
  a=lines[0][0].to_i-lines[0][1].to_i*lines[2][0].to_i
  b=lines[1][0].to_i-lines[1][1].to_i*lines[2][0].to_i
  if a<=b
    print 'YES'
  else
    print 'NO'
  end
end

Measured memory_bytes: 14248
#include<bits/stdc++.h>
using namespace std;
int main()
 {
    int t=1;
    while(t--){
        string s;
        cin>>s;
        int ans=0;
        int c=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='R')
            {
                c++;
                ans=max(ans,c);
            }
            else{
                c=0;
            }
        }
        cout<<max(ans,c);
    }
	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(){
  int i,j,n,a[100],temp,ans;
  while(1){
    ans = 0;
    scanf("%d",&n);
    if(n == 0){ break; }
    for(i = 0 ; i < n ; i++){
      scanf("%d",&a[i]);
    }
    for(i = 0 ; i < n ; i++){
      for(j = n-1 ; j > i ; j--){
	if(a[j] < a[j-1]){
	  temp = a[j];
	  a[j] = a[j-1];
	  a[j-1] = temp;
	  ans++;
	}
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
#define zmrl(x) (int)((x).size())
#define ahen(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n; cin>>n;
    string s;
    while (n--) s += "ACL";
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h, vector<char>(w));
    rep(i, h) rep(j, w) cin >> s[i][j];
    int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
    int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
    
    rep(i, h) {
        rep(j, w) {
            int cnt = 0;
            if (s[i][j] == '#') cout << '#';
            if (s[i][j] == '.') {
                rep(k, 8) {
                    int check_y = i + dy[k];
                    int check_x = j + dx[k];
                    if (check_y < 0 || check_y >= h || check_x < 0 || check_x >= w) continue;
                    if (s[check_y][check_x] == '#') ++cnt; 
                }
                cout << cnt;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		String s = scan.nextLine();
		String p = scan.nextLine();
		
		s = s + s;
		
		if(s.indexOf(p) != -1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}

}



Measured memory_bytes: 26296
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
#define REP(i, a, b) for(int i = int(a); i <= int(b); i++)
#define LOOP(i, v) for(int i = 0; i < v.size(); i++)
#define EPS 1e-9
#define INF 1e12
#define debug(x) cerr << "DEBUG : " << (#x) << " => " << (x) << endl

int main()
{
  int N, M, D, Q, L, R;
  int A[300][300];
  ii trouve[90001];
  int cost[90001];
  long long int cumule[90001][21];
  
  scanf("%d %d %d", &N, &M, &D);
  REP(i, 0, N-1) REP(j, 0, M-1)
  {
    scanf("%d", &A[i][j]);
    trouve[A[i][j]] = make_pair(i, j);
  }
  
  REP(i, 1, N*M)
  {
    int x1 = trouve[i].first;
    int y1 = trouve[i].second;
    if(i+D <= N*M)
    {
      int x2 = trouve[i+D].first;
      int y2 = trouve[i+D].second;
      cost[i] = max(x2-x1, x1-x2) + max(y2-y1, y1-y2);
      cumule[i][0] = cost[i];
    }
  }
  REP(j, 1, 20)
  {
    REP(i, 1, N*M)
    {
      long long int newi = i + (long long int)D*(1 << j);
      long long int interi = i + (long long int)D*(1 << (j-1));
      if(newi <= N*M)
      {
        cumule[i][j] = cumule[i][j-1] + cumule[interi][j-1];
        //fprintf(stderr, "%d %d : %lld\n", i, j, cumule[i][j]);
      }
    }
  }
  
  scanf("%d", &Q);
  REP(i, 1, Q)
  {
    scanf("%d %d", &L, &R);
    int enc = L;
    long long int ans = 0;
    int longueur = (R-L)/D;
    for(int j = 20; j >= 0; j--)
    {
      if(longueur & (1 << j))
      {
        ans = ans + cumule[enc][j];
        enc += D*(1 << j);
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 16896
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int a,b,k;
    cin >> a >> b >> k;
    for(int i=a;i<=b;i++){
        if(i < a+k || b-k < i) cout << i << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef struct{
  char str1[1001];
  char str2[1001];
} Set;
int LCS(Set);
int c[10010][10010];
int main(){
  int q,i;
  Set p;
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s%s",p.str1,p.str2);
    printf("%d\n",LCS(p));
      }
  return 0;
}
int LCS(Set p){
  int m,n,i,j;
  m=strlen(p.str1);
  n=strlen(p.str2);
  for(i=1;i<=m;i++)c[i][0]=0;
  for(j=1;j<=n;j++)c[0][j]=0;
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(p.str1[i-1]==p.str2[j-1]) c[i][j]=c[i-1][j-1]+1;
      else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
    }
  }
  /* for(i=0;i<=m;i++){
    for(j=0;j<=n;j++){
      printf("c[%d][%d]=%d\n",i,j,c[i][j]);
    }
    }*/
  return c[m][n];
}
  



Measured memory_bytes: 9764
#include <bits/stdc++.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

#include <iostream>
#include <string>
#include <algorithm>

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}
 
template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}



signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k;
    string s;
    
    cin >> n >> k >> s ;
    
    

    
    
    s[k-1] = tolower(s[k-1]);
  
    
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int flg = 0;
  vector<string> s(3);
  cin >> s[0] >> s[1] >> s[2];
  int i = 0;
  while (1){
    if(s[0].empty()&&i==0){
      flg = 0;
      break;
    }
    if(s[1].empty()&&i==1){
      flg = 1;
      break;
    }
    if(s[2].empty()&&i==2){
      flg = 2;
      break;
    }
    int tmp = i;
    i = s[i].front() - 'a';
    s[tmp].erase(0, 1);
    //cout << "----" + s[0] << endl << s[1] << endl << s[2] << endl;
  }
  if(flg==0){
    cout << "A" << endl;
  }else if(flg==1){
    cout << "B" << endl;
  }else{
    cout << "C" << endl;
  }
  return 0;
}

Measured memory_bytes: 3568
n, m = list(map(lambda x: int(x), input().split(' ')))
h = list(map(lambda x: int(x), input().split(' ')))

memo = {}

for i in range(m):
  a, b = list(map(lambda x: int(x), input().split(' ')))

  if not a in memo:
    memo[a] = h[b - 1]
  else:
    memo[a] = max(memo[a], h[b - 1])

  if not b in memo:
    memo[b] = h[a - 1]
  else:
    memo[b] = max(memo[b], h[a - 1])

count = 0

for i, v in memo.items():
  if h[i - 1] > v:
    count += 1

for i in range(1, n + 1):
  if not i in memo:
    count += 1

print(count)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long int ll;
typedef vector< pair<int, int> > vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef pair<int, int> pii;

const ll INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;

ll n, arr[nax];
int main()
{
    ios::sync_with_stdio(0);
    ll k;
    if(k == 0)
    {
        cout << 4 << endl;
        cout << 3 << " " << 3 << " " << 3 << " " << 3 << endl;
        return 0;
    }
    cin >> k;
    n = 50;
    ll times = k / n;
    ll cie = k % n;
    cout << n << endl;
    for(int i = 1; i <= n; i++)
        arr[i] = (n - 1) + times;

    for(int i = 1; i <= cie; i++)
    {
        arr[i] += n;
        for(int j = 1; j <= n; j++)
        {
            if(j == i) continue;
            arr[j]--;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        cout << arr[i] << " ";
        if(arr[i] > 1e16 + 1000)
            cout << "HOOLAAL" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

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

	if (x == 4 || x == 6 || x == 9 || x == 11) {
		X = 2;
	}
	else if (x == 2) {
		X = 3;
	}
	else {
		X = 1;
	}

	if (y == 4 || y == 6 || y == 9 || y == 11) {
		Y = 2;
	}
	else if (y == 2) {
		Y = 3;
	}
	else {
		Y = 1;
	}

	cout << ((X == Y) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
struct UF{
  int a[10001];
  void init(int x){
    for(int i=0;i<x;i++) a[i] = i;
  }
  void unite(int x,int y){
    int ax = find(x);
    int ay = find(y);
    if(ax > ay) a[ax] = ay;
    if(ay > ax) a[ay] = ax;
  }
  int find(int x){
    if(x != a[x]) a[x] = find(a[x]);
    return a[x];
  }
};
int main(){
  int n,q,b,c,d;
  UF uf;
  scanf("%d %d",&n,&q);
  uf.init(n);
  while(q--){
    scanf("%d %d %d",&b,&c,&d);
    if(b == 0) uf.unite(c,d);
    if(b == 1) printf("%d\n",uf.find(c)==uf.find(d));
  }
  return 0;
}

Measured memory_bytes: 2788
#
import sys
import math
import numpy as np
import itertools

# ひとつ入力
s = list(input())
# ひとつ入力
q = int(input())

t=0
a=[]
b=[]

for i in range(q):
    query = input().split()
#    print(query)
    if query[0]=='1':
        t = (t+1)%2
    else:
        if (t+int(query[1]))%2==0:
            b.append(query[2])
        else:
            a.append(query[2])
p=[]
#print(a,s,b)
if t == 0:
    a.reverse()
    p.extend(a)
    p.extend(s)
    p.extend(b)
else:
    b.reverse()
    s.reverse()
    p.extend(b)
    p.extend(s)
    p.extend(a)

for i in p:
    print(i,end="")
print("")



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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int N = 505;

int ans[N][N];
bool vis[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n;

void bfs(int x, int y) {
    ans[x][y]--;
    vis[x][y] = 1;

    queue<pii> que;
    que.push(pii(x, y));
    while (!que.empty()) {
        pii u = que.front(); que.pop();
        for (int i = 0; i < 4; i++) {
            int nx = u.first+dx[i], ny = u.second+dy[i];
            if (nx >= 1 && nx <= n && ny >= 1 && ny <= n) {
                if (ans[nx][ny] > ans[u.first][u.second]+!vis[nx][ny]) {
                    assert(ans[nx][ny] == ans[u.first][u.second]+!vis[nx][ny]+1);
                    ans[nx][ny] = ans[u.first][u.second]+!vis[nx][ny];
                    que.push(pii(nx, ny));
                }
            }
        }
    }
}

void solve() {

    scanf("%d", &n);

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            ans[i][j] = min(min(i, n-i+1), min(j, n-j+1));
        }
    }

    int o = 0;
    for (int i = 1; i <= n*n; i++) {
        int p;
        scanf("%d", &p);
        int x = (p-1)/n+1, y = (p-1)%n+1;
        // cout << x << ' ' << y << ' ' << ans[x][y] << endl;
        o += ans[x][y]-1;
        bfs(x, y);
    }
    printf("%d\n", o);
}

int main() {

    int T = 1;
    // scanf("%d", &T);
    while (T--) solve();

    return 0;
}

Measured memory_bytes: 4972
#include <stdio.h>
int main (int argc, char * argv[])
{
    int n,x;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        x = i;
        if(x % 3 ==0){
            printf(" %d",i);
        }else {
            while(x){
                if(x%10==3){
                    printf(" %d",i);
                    break;
                }
                x /=10;
            }
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2100
#include <iostream>

using namespace std;

int euqlid(int big, int small)
{
    int amari = big % small;
    int ans;
    if (amari == 0) return small;
    else ans = euqlid(small, amari);
    return ans;
}

int MaxMin(int num1, int num2, int flag)
{
    if (flag == 0) {
        return num1 >= num2 ? num1 : num2;
    } else {
        return num1 >= num2 ? num2 : num1;
    }
}

int gcd(int a, int b, int c)
{
    int ans;
    if (a >= b && a >= c) {
        if (b >= c) {
            int num1 = euqlid(a, b);
            ans = euqlid(MaxMin(num1, c, 0), MaxMin(num1, c, 1));
        } else {
            int num1 = euqlid(a, c);
            ans = euqlid(MaxMin(num1, b, 0), MaxMin(num1, b, 1));
        }
    } else if (b >= a && b >= c) {
        if (a >= c) {
            int num1 = euqlid(b, a);
            ans = euqlid(MaxMin(num1, c, 0), MaxMin(num1, c, 1));
        } else {
            int num1 = euqlid(b, c);
            ans = euqlid(MaxMin(num1, a, 0), MaxMin(num1, a, 1));
        }
    } else {
        if (a >= b) {
            int num1 = euqlid(c, a);
            ans = euqlid(MaxMin(num1, b, 0), MaxMin(num1, b, 1));
        } else {
            int num1 = euqlid(c, b);
            ans = euqlid(MaxMin(num1, a, 0), MaxMin(num1, a, 1));
        }
    }
    return ans;
}

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

    int a, b, c;
    int sum = 0;
    for (a = 1; a <= K; a++) {
        for (b = 1; b <= K; b++) {
            for (c = 1; c <= K; c++) {
                sum += gcd(a, b, c);
            }
        }
    }

    cout << sum;

    return 0;
}

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

int main() {
	int n,s=0,su=0;
	cin>>n;int a[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];su+=a[i];
	    if(i&1)
	    s+=a[i];
	}int f=su/2-s;
	cout<<2*f<<" ";
	for(int i=0;i<n-1;i++){
	cout<<2*(a[i]-f)<<" ";
	f=a[i]-f;}
	return 0;
}

Measured memory_bytes: 1664