akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> A(N+1), B(N);
  rep(i, N+1) cin >> A[i];
  rep(i, N) cin >> B[i];
  ll num = 0;
  rep(i, N) {
    if(A[i] >= B[i]) {
      A[i] -= B[i];
      num += B[i];
    } else {
      num += A[i];
      B[i] -= A[i];
      A[i] = 0;
      if(A[i+1] >= B[i]) {
        A[i+1] -= B[i];
        num += B[i];
      } else {
        num += A[i+1];
        B[i] -= A[i+1];
        A[i+1] = 0;
      }
    }
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(200010)

n, m = map(int, input().split())
a = [int(input()) for i in range(m)]
b = [0]*(n+1)
dp = [-1]*(n+1)
for e in a:
    b[e] = 1
dp[0] = 1


def solve(k):
    if(b[k] == 1):
        return 0
    if(dp[k] != -1):
        return dp[k]
    if(k < 0):
        return 0
    tmp = solve(k-1)+solve(k-2)
    dp[k] = tmp % 1000000007
    return tmp


print(solve(n) % (1000000007))


Measured memory_bytes: 91944
#include "bits/stdc++.h"
using namespace std;
#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define RREP(i, a, b) for (ll i = (b - 1); a <= i; i--)
#define F first
#define S second
typedef long long ll;

const int INF = 1e9 + 7;
const long long LLINF = 1e18;

// 42~
ll n;
ll field[501][501];
int main() {
    while(cin>>n, n){
        REP(i, 0, 501) REP(j, 0, 501) field[i][j]=-1;
        field[250][250]=0;

        REP(k, 0, n-1){
            ll num, d;
            cin>>num>>d;

            REP(i, 0, 501){
                bool flag=false;
                REP(j, 0, 501){
                    if(field[i][j]==num){
                        if(d==0) field[i][j-1]=k+1;
                        else if (d==1) field[i-1][j]=k+1;
                        else if(d==2) field[i][j+1]=k+1;
                        else field[i+1][j]=k+1;
                        flag=true;

                        break;
                    }
                }
                if(flag) break;
            }
        }

        ll mnx=1000, mxx=0, mny=1000, mxy=0;
        REP(i, 0, 501){
            REP(j, 0, 501){
                if(field[i][j]!=-1){
                    mnx=min(mnx, j);
                    mxx=max(mxx, j);
                    mny=min(mny, i);
                    mxy=max(mxy, i);
                }
            }
        }
        mxx++;
        mxy++;
        cout<<mxx-mnx<<" "<<mxy-mny<<endl;
    }
    return 0;
}


Measured memory_bytes: 4956
# include<iostream>
# include<cstdio>
using namespace std;
char str[10];
int n,l=0,r,s,t,m,g;
int get(int x)
{
	printf("%d\n",x);
	fflush(stdout);
	scanf("%s",&str);
	int ret=0;
	if(str[0]=='F')  ret=1;
	else if(str[0]=='M')  ret=-1;
	return ret;
}
int main()
{
	cin>>n;
	r=n;
	s=get(0),t=s;
	if(s==0)  return 0;
	while(1)
	{
		m=(l+r)/2;
		g=get(m);
		if(g==0)  return 0;
		if(m%2==l%2)
		{
			if(s==g)  l=m,s=g;
			else  r=m,t=g;
		}
		else
		{
			if(s!=g) l=m,s=g;
			else  r=m,t=g;
		}
	}
	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
 
long long s[100005];
 
int main()
{
    int n,k;
    cin>>n>>k;
    long long maxn=99999999999;
    for(int i=0;i<n;i++)
    {
    	cin>>s[i];
	}
	sort(s,s+n);
	for(int i=0;i<n-k+1;i++)
	{
		maxn=min(maxn,s[i+k-1]-s[i]);
	}
	cout<<maxn;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define tp          tuple<int,int,int>
#define fastio      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
int main() {
    ll a , b , c , d;
    cin>>a>>b>>c>>d;
    ll x = a*c;
    ll y = a*d;
    ll z = b*c;
    ll p = b*d;
    cout<<max({x , y , z , p})<<'\n';
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 1, sizeof(s))
#define ms0(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
#define maxn 1000000
bool mark[maxn];
int pri[maxn];
int a[55000];
void ola(){
	for (int i = 2; i * i < maxn; i++){
		for (int j = 2; j <= i; j++){
			mark[i * j] = 0;
		}
	}
	int t = 0;
	for (int i = 2; i < maxn; i++){
		if(mark[i]){
			pri[t++] = i;
		}
	}
}
bool ispri(int n){
	int temp = pri[maxn / 2];
	int left = 0, right = maxn - 1;
	while (left <= right){
		temp = (right + left) / 2;
		int mid = pri[temp];
		if(n > mid){
			left = temp + 1;
		}
		else if (n < mid){
			right = temp - 1;
		}
		else{
			return 1;
		}
	}
	return 0;
}

int main(int argc, char * argv[]) 
{
	mark[0] = 0;
	mark[1] = 0;
	int ans[11][100];
	int cnt[11];
	int flag;
	ms0(cnt);
	ms(mark);
	ola();
	int n;
	cin >> n;
	for (int i = 0; i <= maxn; i++){
		int t = pri[i] % 10;
		ans[t][cnt[t]] = pri[i];
		cnt[t]++;
		if (cnt[t] >= n){
			flag = t;
			break;
		}
	}
	for (int i = 0; i < n; i++){
		if (!i) cout << ans[flag][i];
		else cout << " " << ans[flag][i];
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 5120
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,d,h,i,j,k,l,r,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> l >> r >> d;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	for(i=l;i<=r;i++) {
		if (i%d == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
import itertools

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
              #if (d[i][k] != float("INF")) and (d[k][j] != float("INF")):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
        #print(d)
    return d

N, M ,R = map(int, input().split())
r = list(map(int, input().split()))
rr = list(itertools.permutations(r, R))
ab = [[10 ** 10] * N for i in range(N)]
for i in range(N):
  ab[i][i] = 0
  
for i in range(M):
  a, b, c = list(map(int, input().split()))
  ab[a - 1][b - 1] = c
  ab[b - 1][a - 1] = c
  
ans = warshall_floyd(ab)  
#print(rr)
#print(ans)
#2 ** 8
answer = 10 ** 12
for i in rr:
  now = 0
  #print(i)
  for j in range(R - 1):
    now += ans[i[j] - 1][i[j + 1] - 1]
    
  answer = min(answer, now)  
  
print(answer)



    
    
    



Measured memory_bytes: 74876
package main

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	io := newIo()
	n := io.nextInt()

	A := make([]int, n+2)
	for i := 0; i < n; i++ {
		A[i+1] = io.nextInt()
	}

	cstMax := 0
	for i := 0; i < n+1; i++ {
		cstMax += abs(A[i+1] - A[i])
	}

	for i := 1; i < n+1; i++ {
		ans := cstMax
		ans -= abs(A[i+1]-A[i]) + abs(A[i]-A[i-1])
		ans += abs(A[i+1] - A[i-1])

		io.println(ans)
	}
	io.flush()
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) flush() {
	_ = io.writer.Flush()
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}

func (io *io) print(a ...interface{}) {
	fmt.Fprint(io.writer, a...)
}

func (io *io) println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}


Measured memory_bytes: 6656
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N = I()
A = LI()
mod = 10**9+7
s = sum(A)
s %= mod

a = s**2-sum(A[i]**2 for i in range(N))
a %= mod
a *= pow(2,mod-2,mod)
a %= mod

print(a)


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

int n,k;
perm parts[26];

inline perm prod(perm a, perm b){
  perm res(n);
  rep(i,n)res[i] = a[b[i]];
  return res;
}

inline ll lcm(ll a, ll b){ return a/__gcd(a,b)*b; }

inline ll cycle(perm p){
  ll res = 1;
  rep(i,n){
    ll cur = p[i], len = 1;
    while(cur != i){
      cur = p[cur]; len++;
    }
    res = lcm(res,len);
  }
  return res;
}

perm parse(int& p, const string& s){
  perm res(n);
  rep(i,n)res[i] = i;

  while(p<(int)s.size()){
    if(isalpha(s[p])){
      res = prod(res, parts[s[p]-'A']);
      p++;
    }else{
      ll num = 0;
      while(isdigit(s[p]))num = num*10LL + (ll)(s[p++]-'0');

      perm tmp;
      if(isalpha(s[p]))tmp = parts[s[p++]-'A'];
      else tmp = parse(++p,s);
      ll c = cycle(tmp);
      num %= c;
      
      rep(azu,num)res = prod(res,tmp);
    }
    if(p==(int)s.size() || s[p++] == ')')return res;
  }

  return res;
}

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

  rep(azu,k){
    perm p(n);
    rep(i,n)p[i] = i;

    char c; int h,g;
    cin >> c >> h;

    rep(i,h-1)rep(j,n-1){
      cin >> g;
      if(g == 1)swap(p[j],p[j+1]);
    }
    
    parts[c-'A'] = p;
  }

  int e;
  cin >> e;
  rep(azu,e){
    string exp;
    cin >> exp;

    int p = 0;
    perm ans = parse(p,exp);    
    rep(i,n)cout << ans[i]+1 << " \n"[i==n-1];
  }
}

Measured memory_bytes: 1264
#include <stdio.h>
 
using namespace std;
 
int main(){
    int r,c,sum,total_sum = 0;
    scanf("%d %d",&r,&c);
    int table[r+1][c+1];
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c+1; j++){
            table[i][j] = 0;
        }
    }
 
    for(int i = 0; i < r; i++){
        sum = 0;
        for(int j = 0; j < c; j++){
            scanf("%d",&table[i][j]);
            sum += table[i][j];
            table[r][j] += table[i][j];
        }
        table[i][c] = sum;
        total_sum += sum;
    }
    table[r][c] = total_sum;
 
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            printf("%d ",table[i][j]);
        }
        printf("%d\n",table[i][c]);
    }
}


Measured memory_bytes: 2744
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e30
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, L, R, K, X,Y, A, B, C, Z;
ll ans;
string S;
ll a[200];
ll x[100000000];
ll y[100000000];
ll nowcost = 1;
ll twopow[202020];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll dp[1000001];
ll p[1000000];
ll pos[1000000];

int main() {
	cin>>N;
	rep(i,1,N+1){
		cin>>p[i];
	}
	rep(i,1,N+1){
		if(pos[p[i]-1]==0){
			pos[p[i]]=i;
		}else{
			pos[p[i]]=pos[p[i]-1];
		}
	}
	rep(i,1,N+1){
		dp[pos[i]]++;
		ans = max(ans,dp[pos[i]]);
	}
	cout<<N-ans<<endl;
	return 0;
}

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

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

        bool f[n][32];
        fill(f[0], f[n], false);

        rep(i, n) {
            int m; cin >> m;
            rep(j, m) {
                int t; cin >> t;
                f[i][t] = true;
            }
        }

        ll dp[n][31];
        fill(dp[0], dp[n], 0);
        rep(i, n) dp[i][0] = 1LL << i;
        int res = -1;

        for (int j=1; j<=30; ++j) {
            if (res != -1) break;
            rep(i, n) {
                if (!f[i][j]) {
                    dp[i][j] = dp[i][j-1];
                    continue;
                }
                rep(k, n) {
                    if (!f[k][j]) continue;
                    dp[i][j] |= dp[k][j-1];
                }
                if (dp[i][j] == (1LL<<n)-1) {
                    res = j;
                    break;
                }
            }
        }

        cout << res << endl;
    }
}

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

int main(){
  int N;
  cin >> N;
  int a[N];

  int max = INT_MIN, min = INT_MAX;
  for(int i=0;i<N;i++){
    cin >> a[i];
    if(a[i] > max){
      max = a[i];
    }
    if(a[i] < min){
      min = a[i];
    }
  }
  cout << max - min << endl;
}

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


int main(){
    string s,t;
    cin >> s >>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());
    if(s<t) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 256
import math
def I():
  return input()
def II():
  return int(input())
def MII():
  return map(int, input().split())
def LMII():
  return list(map(int, input().split()))

n = II()
a, b = MII()

for i in range(a, b+1):
  
  if i % n == 0:
    print("OK")
    exit()
print("NG")


Measured memory_bytes: 62076
#[allow(unused_macros)]
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 ) * } } ; }
#[allow(unused_macros)]
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 ) * } } ; }
#[allow(unused_macros)]
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; 5],
        k: i64
    }

    let mut is_exists = false;
    for mask in bit_fixed_size_subsets(2, 5) {
        let pair = bit_filter(mask, &x);
        if (pair[0] - pair[1]).abs() > k {
            is_exists = true;
        }
    }
    println!("{}", if is_exists {":("} else {"Yay!"})
}

#[allow(dead_code)]
fn bit_fixed_size_subsets(k: usize, n: usize) -> Vec<usize> {
    let mut ret = vec![];
    let mut x: i64 = (1 << k as i64) - 1;
    while x < 1 << n {
        ret.push(x as usize);
        if k == 0 {
            break;
        }
        let t = x | (x - 1);
        x = (t + 1) | (((!t & -!t) - 1) >> (x.trailing_zeros() + 1));
    }
    ret
}

#[allow(dead_code)]
pub fn bit_filter<T: Clone>(mask: usize, v: &[T]) -> Vec<T> {
    let mut ret = vec![];
    for i in 0..v.len() {
        if (mask >> i) & 1 == 1 {
            ret.push(v[i].clone());
        }
    }
    ret
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long int
#define tc int t; cin>>t; while(t--)
int main() {
 //fastio
ll n,d;
cin>>n>>d;
ll mat[n][d];
for(int i=0;i<n;i++)
    for(int j=0;j<d;j++)
    cin>>mat[i][j];

    int count=0;
    for(int i=0;i<n;i++)
    {

        for(int j=i+1;j<n;j++)
        {   ll var=0;
            for(int k=0;k<d;k++)
            {
                var+=(mat[i][k]-mat[j][k])*(mat[i][k]-mat[j][k]);
            }
            ll a =sqrt(var);
            if(a*a==var)
                count++;
        }
    }
    cout<<count;
}





Measured memory_bytes: 256
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int n;
  rd(n);
  auto t = readln.split.to!(int[]);
  auto v = readln.split.to!(int[]);

  t.each!((ref _t) => (_t *= 2));
  v.each!((ref _v) => (_v *= 2));
  auto T = reduce!"a+b"(t), V = reduce!(max)(v);
  auto dp = new int[][](T + 1, V + 1);
  for (int i = 0; i <= T; i++) {
    for (int j = 0; j <= V; j++) {
      dp[i][j] = -1;
    }
  }
  dp[0][0] = 0;
  int tm = 0;
  foreach (i; 0 .. n) {
    foreach (j; tm .. (tm + t[i])) {
      for (int k = 0; k <= v[i]; k++) {
        if (dp[j][k] >= 0) {
          chmax(dp[j + 1][k], dp[j][k] + k * 2);
          if (k + 1 <= v[i]) {
            chmax(dp[j + 1][k + 1], dp[j][k] + k * 2 + 1);
          }
          if (k - 1 >= 0) {
            chmax(dp[j + 1][k - 1], dp[j][k] + k * 2 - 1);
          }
        }
      }
    }
    tm += t[i];
  }
  writefln("%.18f", dp[T][0] / 8.0);
}

void chmax(T)(ref T l, T r) {
  if (l < r)
    l = r;
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

#define FOR(i, a, b) for(int i = a; i<b; ++i)
#define FR(a, b) for(int i = a; i>=b;--i)
#define _upgrade cin.tie(0); ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define INF 1e16

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef pair<int, int> iPair;

const int MAX = 2e5+2;
const int M = 1e9+7;

ll x, res;
int main()
{
    _upgrade;
    cin>>x;
    res += (x/500)*1000;
    x %= 500;
    res += (x/5)*5;
    cout<<res;
    return 0;
}


Measured memory_bytes: 256
N,K,C = map(int,input().split())
S = input()
S_l = len(S)
from collections import deque
L = [0]*K
R = [0]*K

period = C
j = 0
for i in range(S_l):
  if j==K:
    break
  if S[i]=='x':
    period+=1
    continue
  else:
    if period<C:
      period+=1
      continue
    else:
      period=0
      L[j]=i
      j+=1
      
S = S[::-1]
period = C
j = 0
for i in range(S_l):
  if j==K:
    break
  if S[i]=='x':
    period+=1
    continue
  else:
    if period<C:
      period+=1
      continue
    else:
      period=0
      R[K-1-j] = S_l - 1 - i
      j+=1
      

for i,j in zip(L,R):
  if i==j:
    print(i+1)

Measured memory_bytes: 51788
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>b;
    cout<<max(max(a+b,a-b),a*b);
    return 0;
}


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

using namespace std;

int main() {
	string aa, bb;
	cin >> aa >> bb;
	int a = aa.size(), b = bb.size();
	if (a < b) {
		cout << "LESS";
	}
	else if (a > b) {
		cout << "GREATER";
	}
	else {
		if (aa[0] == bb[0]) {
			cout << "EQUAL";
		}
		else if (aa[0] < bb[0]) {
			cout << "LESS";
		}
		else {
			cout << "GREATER";
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
 #include <iostream>
 #include <vector>
 using namespace std;
 typedef long long ll;
 const int INF = 1 << 30;
 const ll INFll = 1ll << 60;
 
 int main() {
	 int n; cin >> n;
	 int sum = 0;
	 for (int i = 0; i < n; i++)
	 {
		 int l,r; cin >> l >> r;
		 sum += r - l + 1;
	 }
	 cout << sum << endl;
	 
 	return 0;
 }


Measured memory_bytes: 256
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll maxn = 1e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pll pair<ll, ll>
#define F first
#define S second

ll n, ans;

pll a[maxn], b[maxn], c[maxn];

int main(){
	fast_io;
	
	cin >> n;
	
	for(ll i = 0; i < n; i++){
		cin >> a[i].F >> a[i].S;
		a[i].S = -a[i].S;
	}
	
	sort(a, a + n);
	
	for(ll i = 0; i < n; i++){
		a[i].S = -a[i].S;
	}
	
	b[0] = a[0];
	
	for(ll i = 1; i < n; i++){
		b[i].F = max(b[i - 1].F, a[i].F);
		b[i].S = min(b[i - 1].S, a[i].S);
	}
	
	c[n - 1] = a[n - 1];
	
	for(ll i = n - 2; i > -1; i--){
		c[i].F = max(c[i + 1].F, a[i].F);
		c[i].S = min(c[i + 1].S, a[i].S);
	}
	
	ans = max(0ll, c[0].S - c[0].F + 1);
	
	for(ll i = 1; i < n; i++){
		ans = max(ans, max(0ll, b[i - 1].S - b[i - 1].F + 1) + max(0ll, c[i].S - c[i].F + 1));
	}
	
	for(ll i = 0; i < n; i++){
		a[i].F = -a[i].F;
		swap(a[i].F, a[i].S);
	}
	
	sort(a, a + n, greater<pll>());
	
	for(ll i = 0; i < n; i++){
		swap(a[i].F, a[i].S);
		a[i].F = -a[i].F;
	}
	
	b[0] = a[0];
	
	for(ll i = 1; i < n; i++){
		b[i].F = max(b[i - 1].F, a[i].F);
		b[i].S = min(b[i - 1].S, a[i].S);
	}
	
	c[n - 1] = a[n - 1];
	
	for(ll i = n - 2; i > -1; i--){
		c[i].F = max(c[i + 1].F, a[i].F);
		c[i].S = min(c[i + 1].S, a[i].S);
	}
	
	for(ll i = 1; i < n; i++){
		ans = max(ans, max(0ll, b[i - 1].S - b[i - 1].F + 1) + max(0ll, c[i].S - c[i].F + 1));
	}
	
	sort(a, a + n);
	
	b[0] = a[0];
	
	for(ll i = 1; i < n; i++){
		b[i].F = max(b[i - 1].F, a[i].F);
		b[i].S = min(b[i - 1].S, a[i].S);
	}
	
	c[n - 1] = a[n - 1];
	
	for(ll i = n - 2; i > -1; i--){
		c[i].F = max(c[i + 1].F, a[i].F);
		c[i].S = min(c[i + 1].S, a[i].S);
	}
	
	for(ll i = 1; i < n; i++){
		ans = max(ans, max(0ll, b[i - 1].S - b[i - 1].F + 1) + max(0ll, c[i].S - c[i].F + 1));
	}
	
	for(ll i = 0; i < n; i++){
		swap(a[i].F, a[i].S);
	}
	
	sort(a, a + n, greater<pll>());
	
	for(ll i = 0; i < n; i++){
		swap(a[i].F, a[i].S);
	}
	
	b[0] = a[0];
	
	for(ll i = 1; i < n; i++){
		b[i].F = max(b[i - 1].F, a[i].F);
		b[i].S = min(b[i - 1].S, a[i].S);
	}
	
	c[n - 1] = a[n - 1];
	
	for(ll i = n - 2; i > -1; i--){
		c[i].F = max(c[i + 1].F, a[i].F);
		c[i].S = min(c[i + 1].S, a[i].S);
	}
	
	for(ll i = 1; i < n; i++){
		ans = max(ans, max(0ll, b[i - 1].S - b[i - 1].F + 1) + max(0ll, c[i].S - c[i].F + 1));
	}
	for(ll i = 0; i < n; i++){
		a[i].F = a[i].S - a[i].F;
	}
	
	sort(a, a + n, greater<pll>());
	
	for(ll i = 0; i < n; i++){
		a[i].F = a[i].S - a[i].F;
	}
	
	b[0] = a[0];
	
	for(ll i = 1; i < n; i++){
		b[i].F = max(b[i - 1].F, a[i].F);
		b[i].S = min(b[i - 1].S, a[i].S);
	}
	
	c[n - 1] = a[n - 1];
	
	for(ll i = n - 2; i > -1; i--){
		c[i].F = max(c[i + 1].F, a[i].F);
		c[i].S = min(c[i + 1].S, a[i].S);
	}
	
	for(ll i = 1; i < n; i++){
		ans = max(ans, max(0ll, b[i - 1].S - b[i - 1].F + 1) + max(0ll, c[i].S - c[i].F + 1));
	}
	
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 4992
N, M = map(int, input().split())
A = set(int(input()) for _  in range(M))

MOD = 10**9 + 7

dp = [0]*(N+1)
dp[0] = 1

for i in range(1,N+1):
    if i in A:
        continue
    x = dp[i-1]
    if i > 1:
        x += dp[i-2]
    dp[i] = x%MOD
answer = dp[N]
print(answer)

Measured memory_bytes: 11884
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];
 
 

int main () {
    char C;
    cin >> C;

    cout << (char) (C+1) << endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld PI = acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
//const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    int n,m,a,b; cin >> n >> m;
    vii graph(n);
    rep(i,m) {
        cin >>a >>b;
        --a;--b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vi per(n-1);
    rep(i,n-1) per[i] = i+1;

    int ans = 0;
    do {
        for(int i = 0; i < n; ++i) {
            if(i==0) {
                bool can = false;
                for(auto u : graph[0]) if(u==per[0]) can = true;
                if(!can) break;
            }else {
                if(i==n-1) {
                    ++ans;
                    break;
                }
                bool can = false;
                for(auto u : graph[per[i-1]]) if(u==per[i]) can = true;
                if(!can) break;
            }
        }
    } while(next_permutation(all(per)));

    cout << ans << '\n';
}

Measured memory_bytes: 256
//The best is yet to come...
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 200001

ll par[maxn],p[maxn],size[maxn],sz[maxn];
map<pair<ll,ll>,ll >m;
ll find(ll x)
{
	if(par[x]==x)
	return x;
	return par[x]=find(par[x]);
}
ll f(ll x)
{
	if(p[x]==x)
	return x;
	return p[x]=f(p[x]);
}
int main()
{
	boost1;boost2;	
	ll i,j,n,m1,m2,x,y,xp,yp,xp1,yp1;
	cin>>n>>m1>>m2;

	for(i=1;i<=n;i++)
	{
		par[i]=i;
		size[i]=1;
	}	
	for(i=1;i<=m1;i++)
	{
		cin>>x>>y;
		xp=find(x);
		yp=find(y);
		if(xp==yp)
		continue;
		par[xp]=yp;
		size[yp]+=size[xp];
	}

	for(i=1;i<=n;i++)
	{
		p[i]=i;
		sz[i]=1;
	}
	for(i=1;i<=m2;i++)
	{
		cin>>x>>y;
		xp1=f(x);
		yp1=f(y);
		if(xp1==yp1)
		continue;
		p[xp1]=yp1;
		sz[yp1]+=sz[xp1];
	}
	for(i=1;i<=n;i++)
	{
		x=find(i);
		y=f(i);
		m[mp(x,y)]++;
	}
	for(i=1;i<=n;i++)
	{
		x=find(i);
		y=f(i);
		cout<<m[mp(x,y)]<<" ";
	}
	return 0;
}


Measured memory_bytes: 18176
#include<iostream>
using namespace std;
int main(){
    int n,ans;
    cin>>n;
    if(n<2)ans=n;
    else if(n<4)ans=2;
    else if(n<8)ans=4;
    else if(n<16)ans=8;
    else if(n<32)ans=16;
    else if(n<64)ans=32;
    else if(n<128)ans=64;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def dfs_visit(u):
    global n, M, d, f, time

    if color[u] == 'WHITE':
        color[u] = 'GRAY'
        time += 1
        d[u] = time

        for v in range(n):
            if M[u][v] == 0:
                continue
            if color[v] == 'WHITE':
                dfs_visit(v)

        color[u] = 'BLACK'
        time += 1
        f[u] = time


def dfs():
    global n, M, d, f, time

    for u in range(n):
        if color[u] == 'WHITE':  # 連結グラフとは限らないため。
            dfs_visit(u)

    for u in range(n):
        print('{} {} {}'.format(u+1, d[u], f[u]))


n = int(input())

M = [[0 for i in range(n)] for j in range(n)]
color = ['WHITE'] * n  # 各頂点の色を記録。ホワイト（未探索）、グレイ（探索中）、ブラック（探索ずみ）
d = [None] * n  # vを最初に発見した時間
f = [None] * n  # vの完了時刻
time = 0

for i in range(n):
    _ = list(map(int, input().split()))
    u = _[0] - 1  # 0オリジンに変換

    degree = _[1]
    for j in range(degree):
        v = _[j+2] - 1  # 0オリジンに変換
        M[u][v] = 1

# for row in M:
#     print(' '.join(map(str, row)))

dfs()



Measured memory_bytes: 5764
//
import java.math.*;
import java.util.*;
import java.io.*;
  
public class Main { 
  
    static BufferedReader in;
    static PrintWriter out = new PrintWriter(System.out);
    static String file = "../in";
    static int test = 10; // 0 for local testing, 1 for std input
    static int inf = 1_000_000, mod = 1_000_000_007;

    void swap(int[]ary, int i, int j)
    {
        int t = ary[i];
        ary[i] = ary[j];
        ary[j] = t;
    }
    
    String[] split() throws Exception
    {
        return in.readLine().split(" ");
    }

    int readInt() throws Exception
    {
        return Integer.valueOf(in.readLine());
    }

    int[] toIntArray() throws Exception
    {
        String[] sp = split();
        int n = sp.length;
        int[] ary = new int[n];
        for(int i = 0; i < n; i++) ary[i] = Integer.valueOf(sp[i]);
        return ary;
    }

    String reverse(String str)
    {
        return new StringBuilder(str).reverse().toString();
    }


    long pow(long a, int pow)
    {
        long res = 1;
        while(pow > 0)
        {
            if(pow % 2 != 0) {
                res *= a;
                res %= mod;
            }
            a = a * a;
            a %= mod;
            pow /= 2;
        }

        return res;
    }

    public static void main(String[] args) throws Exception
    {
        int _k = Integer.valueOf("1");
        if(test > 0) in = new BufferedReader(new InputStreamReader(System.in));
        else in = new BufferedReader(new FileReader(file));
        if(test < 0) {String[] str = in.readLine().split(" ");}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
        // System.out.println((-100 + 0) / 2);

        new Main().c();
        out.flush();
    }

    void c() throws Exception
    {
        int n = readInt();
        int[] ary = toIntArray();

        for(int i = 0; i < n; i++) ary[i] -= i;

        // need to find some B that's optimal - minimum
        // there must be a concavity somewhere
        // b lies within range ary[0] to ary[n - 1]
        // quite likely it's one of the points - medium

        Arrays.sort(ary);

        long sum = 0;

        int b = ary[n / 2];

        // if(n % 2 == 0) b = ary[n / 2];
        // else b = (ary[n / 2] + ary[(n + 1) / 2]) / 2;
        for(int i = 0;  i < n; i++)
        {
            sum += Math.abs(ary[i] - b);
        }
        out.println(sum);
    }
}

Measured memory_bytes: 62360
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define forn(i,n)for(ll i=0;i<(n);i++)
#define forn_rev(i,n)for(ll i=(n)-1;i>=0;i--)
#define for1n(i,n) for(ll i=1;i<=(n);i++)
#define ARRAY_SIZE(a) sizeof(a)/sizeof(*a)
#define MOD 1000000007
#define MAXN 100000

using namespace std;


void bfs(vector<vector<char>> &arr,ll &l,ll r,ll N,ll M){

    queue<pair<ll,ll>> q;
    q.push({l,r});
    while(!q.empty()){
        pair<ll,ll> a=q.front();

        q.pop();
        if(arr[a.first][a.second]=='.') arr[a.first][a.second]='B';
        char ch=arr[a.first][a.second];
        if(a.second>0 && arr[a.first][a.second-1]=='.') {
                q.push({a.first,a.second-1});
                if(ch=='B') arr[a.first][a.second-1]='W';
                else arr[a.first][a.second-1]='B';
        }
        if(a.second<M-1 && arr[a.first][a.second+1]=='.') {
                q.push({a.first,a.second+1});
                if(ch=='B') arr[a.first][a.second+1]='W';
                else arr[a.first][a.second+1]='B';
        }
        if(a.first>0 && arr[a.first-1][a.second]=='.') {
                q.push({a.first-1,a.second});
                if(ch=='B') arr[a.first-1][a.second]='W';
                else arr[a.first-1][a.second]='B';
        }
        if(a.first<N-1 && arr[a.first+1][a.second]=='.') {
                q.push({a.first+1,a.second});
                if(ch=='B') arr[a.first+1][a.second]='W';
                else arr[a.first+1][a.second]='B';
        }

    }

}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    ll T=1;
    //cin>>T;
    while(T--)
    {
        ll N;
        cin>>N;
        ll ans=0;
        for1n(i,N) for1n(j,N) for1n(k,N) ans+=__gcd(__gcd(i,j),k);
        cout<<ans;


    }





    return 0;
}

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

const ULL M = 1000000007;

ULL powm(ULL a, ULL i) {
    if (!i) return 1;
    if (i & 1) return powm(a * a % M, i >> 1) * a % M;
    return powm(a * a % M, i >> 1);
}

ULL F[10001], I[10001], iF[10001];

ULL C(ULL n, ULL r) { return F[n] * iF[r] % M * iF[n - r] % M; }
ULL P(ULL n, ULL r) { return F[n] * iF[n - r] % M; }
ULL H(ULL n, ULL r) { return C(r + n - 1, n - 1); }

struct Problem {

    void Solve() {
        F[0] = 1; for (UL i = 1; i <= 10000; i++) F[i] = F[i - 1] * i % M;
        I[1] = 1; for (UL i = 2; i <= 10000; i++) I[i] = M - M / i * I[M % i] % M;
        iF[0] = 1; for (UL i = 1; i <= 10000; i++) iF[i] = iF[i - 1] * I[i] % M;
        ULL N, K; cin >> N >> K;
        ULL dp[1001] = {};
        dp[N] = 1;
        rep(i, K) {
            for (UL j = N; j >= K - i; j--) {
                dp[j - K + i] += dp[j];
                dp[j - K + i] %= M;
            }
        }
        cout << dp[0] << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



Measured memory_bytes: 3344
#<33>
#(0)初期設定
from collections import deque
H, W = map(int,input().split())
S = []
count = 0
for h in range(H):
    A = list(input())#文字列のままリストの入れてやる
    for a in A:
        if a == ".":
            count += 1#白マスの数
    S.append(A)

#(1)DFS
mas = deque([(0, 0, 0)])
while mas: #キューが空になるまで続く
    y, x, n = mas.popleft()
    if (0 <= y <= H -1) and (0 <= x <= W -1):#範囲内か
        if S[y][x] == ".":
            S[y][x] = n
            mas.append((y + 1, x, n + 1))
            mas.append((y, x + 1, n + 1))
            mas.append((y - 1, x, n + 1))
            mas.append((y, x - 1, n + 1))

#(2)出力環境
short = S[H -1][W -1]
if short == ".": #キューが空になったのにゴールが書き換えられていない時
    print("-1")
else:
    print(count - (short + 1))



Measured memory_bytes: 9436
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<list>
using namespace std;

int main() {
	string s;
	cin >> s;
	for (int i = 0;i < s.size();i++) {
		if (s[i] == ',') {
			s[i] = ' ';
			cout << s[i];
		}
		else cout << s[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include<unordered_map>
#include <cassert>
#include <string>
#include <cstring>
#include<stack>
#include<list>
#include<queue>
using namespace std;
typedef long long int ll;
# define INF 0x3f3f3f3f
# define M 1000000007

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,q;
	cin>>n;
	int* arr = new int[n]();
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	cin>>q;
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		ans += arr[i];
	}
	unordered_map<int,int> mp;
	for(int i=0;i<n;i++)
	{
		mp[arr[i]]++;
	}
	int b,c;
	while(q--)
	{
		cin>>b>>c;
		ans = ans + (c-b)*mp[b];
		mp[c]+=mp[b];
		mp[b]=0;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 7528
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define PI            (acos(-1.0))
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,a,n)    for(int i=a;i<n;i++)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define w(t)          int t;cin>>t;while(t--)
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;

const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    int s;
    cin>>s;
    set<string>ss;
    while(s--)
    {
        string w;
        cin>>w;
        ss.insert(w);
    }
    cout<<SZ(ss)<<nl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    
    if(s[2]==s[3] && s[4]==s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3568
n,w = map(int,input().split())
s = []
check = [[0 for b in range(w+1)] for a in range(n)]
for i in range(n):
  s.append(list(map(int,input().split())))

for j in range(n): 
  for k in range(1,w+1):
    if k < s[j][1]: #現在チェック中の重量がkを超えるなら
      check[j][k] = check[j-1][k] #iの宝石を入れない場合の最大
    else:
      check[j][k] = max(check[j-1][k],check[j-1][k-s[j][1]]+s[j][0])   
print(max(check[n-1]))


Measured memory_bytes: 25852
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();
        if (s.length() <= k) {
            System.out.println(s);
            return;
        }
        System.out.println(s.substring(0, k) + "...");
    }

}


Measured memory_bytes: 38632
import sys
import os
from sys import stdin
import math

# stdin = open(os.path.dirname(__file__) + '/input.txt')  # local test
input = stdin.readline
sys.setrecursionlimit(20000000)


N = int(input())
i_6 = math.ceil(math.log(N, 6))
i_9 = math.ceil(math.log(N, 9))

dp = [9999999] * (N + 1)
dp[0] = 0

for i in range(N):
    for j in range(i_6 + 1):
        if (i + 6 ** j) > N:
            break
        if dp[i] < dp[i + 6 ** j]:
            dp[i + 6 ** j] = dp[i] + 1

    for k in range(i_9 + 1):
        if (i + 9 ** k) > N:
            break
        if dp[i] < dp[i + 9 ** k]:
            dp[i + 9 ** k] = dp[i] + 1

print(dp[N])


Measured memory_bytes: 42220
#include <stdio.h>
#include <stdlib.h>
static int cmp(const void *a, const void *b)
{
    return *((int *)a) - *((char *)b);
}
int main(int argc, char *argv[])
{
    char buf[512];
    int n, i, list[100] = {0};
    int max = 0;

    fgets(buf, sizeof(buf), stdin);
    n = atoi(buf);
    for ( i = 0; i < n; i++ ){
        fgets(buf, sizeof(buf), stdin);
        list[i] = atoi(buf);
        max += list[i];
    }
    qsort(list, n, sizeof(int), cmp);
    if ( max % 10 != 0 ){
        printf("%d\n", max);
        return 0;
    }
    for ( i = 0; i < n; i++ ){
        if ( (max-list[i]) % 10 != 0 ){
            printf("%d\n", max - list[i]);
            return 0;
        }
    }
    printf("0\n");
    return 0;
}


Measured memory_bytes: 128
#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>
#include <sstream>
#include <complex>

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 fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int d, n;
char field[110][110];

int main(){
	cin >> d;
	while (d--){
		REP(i, 110)REP(j, 110)field[i][j] = ' ';
		cin >> n;
		REP(i, n)field[i][0] = '#';
		int sx = 0, sy = 0;
		int w = n - 1;
		bool f = 0;
		while (w >= 2){
			if (f == 0){
				REP(i, w){
					sx++;
					field[sy][sx] = '#';
				}
				REP(i, w){
					sy++;
					field[sy][sx] = '#';
				}
				w -= 2;
				f = 1;
			}
			else{
				REP(i, w){
					sx--;
					field[sy][sx] = '#';
				}
				REP(i, w){
					sy--;
					field[sy][sx] = '#';
				}
				w -= 2;
				f = 0;
			}
		}
		if (w == 1){
			if (f == 0)field[sy][sx + 1] = '#';
			else field[sy][sx - 1] = '#';
		}
		REP(i, n){
			REP(j, n){
				cout << field[i][j];
			}
			cout << endl;
		}
		if (d > 0)cout << endl;
	}
}

Measured memory_bytes: 1164
#include<iostream>

using namespace std;

int main() {
	int a, b;
	char op;

	while (true) {
		cin >> a >> op >> b;

		switch (op) {
		case'+':
			cout << a + b << endl;
			break;
		case'-':
			cout << a - b << endl;
			break;
		case'*':
			cout << a*b << endl;
			break;
		case'/':
			cout << a / b << endl;
			break;
		default:
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(){
  int a,b,c=0;
  char s[4][20]={{"NA"},{"MMYY"},{"YYMM"},{"AMBIGUOUS"}};
  scanf("%2d%2d",&a,&b);
  if(0<a&&a<=12)c+=1;
  if(0<b&&b<=12)c+=2;
  printf("%s\n",s[c]);
  return 0;
}


Measured memory_bytes: 128
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable {
	public static void main(String[] args) {
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
	}

	int N;
	int M;
	int[] a;
	int[] b;
	ArrayList<Integer>[] g;
	boolean[][] go;
	int[][] ref;

	void dfs(int cur, int ori) {
		go[ori][cur] = true;
		for (int dst : g[cur]) {
			if (!go[ori][dst])
				dfs(dst, ori);
		}
	}

	void paint_min(int cur, int ori, int col, int[] min) {
		if (min[cur] > col)
			min[cur] = col;
		else
			return;
		for (int dst : g[cur]) {
			if (dst == ori)
				continue;
			paint_min(dst, ori, col, min);
		}
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		a = new int[M];
		b = new int[M];
		g = new ArrayList[N];
		ref = new int[N][N];
		for (int i = 0; i < N; ++i)
			for (int j = 0; j < N; ++j)
				ref[i][j] = -1;
		for (int i = 0; i < N; ++i)
			g[i] = new ArrayList<>();
		//N<=10^3
		//M<=2*10^5
		for (int i = 0; i < M; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			--a[i];
			--b[i];
			g[a[i]].add(b[i]);
			ref[a[i]][b[i]] = i;
		}
		go = new boolean[N][N];
		for (int i = 0; i < N; ++i)
			dfs(i, i);
		boolean[][] go2 = new boolean[N][N];
		int[] tmp = new int[N];
		for (int i = 0; i < N; ++i) {
			Arrays.fill(tmp, g[i].size());
			for (int j = 0; j < g[i].size(); ++j) {
				paint_min(g[i].get(j), i, j, tmp);
			}
			for (int j = 0; j < g[i].size(); ++j) {
				if (tmp[g[i].get(j)] != j) {
					go2[i][g[i].get(j)] = true;
				}
			}
			Arrays.fill(tmp, g[i].size());
			for (int j = g[i].size() - 1; j >= 0; --j) {
				paint_min(g[i].get(j), i, g[i].size() - 1 - j, tmp);
			}
			for (int j = g[i].size() - 1; j >= 0; --j) {
				if (tmp[g[i].get(j)] != g[i].size() - 1 - j) {
					go2[i][g[i].get(j)] = true;
				}
			}
		}
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < M; ++i) {
			if (!go[b[i]][a[i]] && !go2[a[i]][b[i]]) {
				pw.println("same");
			} else if (go[b[i]][a[i]] && go2[a[i]][b[i]]) {
				pw.println("same");
			} else {
				pw.println("diff");
			}
		}
		pw.close();
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 138732
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int f(int n) {
  int ans = 0;
  while (n % 2 == 0) {
    ans++;
    n /= 2;
  }
  return ans;
}

int main() {
  int N; cin>>N;
  int ans = 0;
  REP(i,N) {
    int	a; cin>>a;
    ans	+= f(a);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N,K = (int(x) for x in input().split())
S = input()
S = list(S)
if S[K-1] == "A":
    S[K-1] = "a"
elif S[K-1] == "B":
    S[K-1] = "b"
else:
    S[K-1] = "c"
S = "".join(S)
print(S)

Measured memory_bytes: 3060
A= int(input())
l=[]
for i in range(A):
   l.append(input())
print("AC"+" x "+str(l.count("AC")))
print("WA"+" x "+str(l.count("WA")))
print("TLE"+" x "+str(l.count("TLE")))
print("RE"+" x "+str(l.count("RE")))

Measured memory_bytes: 16320
#include<iostream>
#include<queue>
#include<vector>

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

const int INF = 1001001001;

int main(){
	ll n, k;cin >> n >> k;

	priority_queue<ll, vector<ll>, greater<ll>> q;
	ll tmp;
	tmp = n / k;
	n -= k * tmp;
	q.push(n);
	rep(i,3){
		n = abs(n-k);
		q.push(n);
	}
	ll ans = q.top();
	cout << ans << endl;

	return 0;
}

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




int main()
{
int n;
cin >> n;
vector<int> p(n);
rep(i,n)cin>>p[i];
int k = 0;
rep(i,n)if(p[i] != i + 1) k++;
if( k <= 2) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>

using namespace std;
typedef vector<int> vi;
#define ll long long

//次に小さい3, 5, 7のみで構成される数字に変える
void nexts(string& str){
	bool f = true;
	//全部'7'か調べる
	for(int i = 0 ; i < str.size() ; i++){
		if (str[i] != '7'){
			f = false;
			break;
		}
	}
	//全部'7'である時は位を1つ増やして全部'3'にする．
	if (f){
		for(int i = 0 ; i < str.size() ; i++){
			str[i] = '3';
		}
		str.push_back('3');
		return;
	}
	//'7' '5' '3'の差はどれも2なのでとりあえず一番右の位を2足す
	//後ろのfor文は繰上げの処理
	str[str.size()-1] += 2;
	for(int i=str.size()-1; str[i] == '9'; i--){
		str[i] = '3';
		str[i-1] += 2;
	}
	return;
}

//'7' '5' '3'がちゃんと全部含まれているかチェックする関数
//含まれていたらtrueを返す
bool find753(string& str){
	bool f7=false, f5=false, f3=false;
	for(int i = 0 ; i < str.size() ; i++){
		if (str[i] == '7') f7 = true;
		if (str[i] == '5') f5 = true;
		if (str[i] == '3') f3 = true;
	}
	return f7 * f5 * f3;
}

int main(){
	ll n, ans=0;
	cin >> n;
	string s;
	//3桁未満はありえないので"333"から列挙スタート
	for(int i=0; i < 3; i++){
        s.push_back('3');
    }
	//列挙している数字がnを超えてしまったらbreakする
	//それまでは753数ならansをインクリメントしてカウント
	while(true){
		nexts(s);
		if (stoll(s) > n){
			break;
		}
		if (find753(s)){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256