akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int main(void) {
    int h[300],w[300];
    int a,b,c,d,i,n;
    a=0;
    b=0;
    while(1){
    	scanf("%d %d",&h[a],&w[b]);
    	c=h[a];
    	d=w[b];
    	if(c==0&&d==0){
    		break;
    	}
    	for(i=1;i<c+1;i++){
    		for(n=i;n<d+i;n++){
    			if(n%2==1){
    			printf("#");
    		}else{
    			printf(".");
    		}
    		}
    		printf("\n");
    	}
    	printf("\n");
    	a++;b++;
    }
	return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>

int main(void) {
	int x, y, i, j;
	
	while(1){
	scanf("%d %d", &x, &y);
	for(i = 0; i < x; i++){
		for(j = 0; j < y; j++){
			putchar('#');
			
		}
		putchar('\n');
	}
	if(x == 0 && y == 0){
		break;
	}
	putchar('\n');
	}
	return 0;
}

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

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

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

const int N = 2e5+23;
const int mod = 1e9+7;

long long f[N];

long long binpow(long long b, long long e) {
  if (!e) return 1;
  if (e&1) return b*binpow(b, e-1)%mod;
  return binpow(b*b%mod, e/2);
}

long long C(int n, int k) {
  return f[n] * binpow(f[k], mod-2) % mod * binpow(f[n-k], mod-2) % mod;
}

void solve() {
  int n, k; scanf("%d%d", &n, &k);
  f[0] = 1;
  for (int i = 1; i < N; ++i) f[i] = f[i-1] * i % mod;
  long long ans = 0;
  for (int i = 0; i <= min(n-1, k); ++i) {
    ans = (ans + C(n, i)*C(n-1, i)%mod) % mod;
  }
  printf("%lld", ans);
}

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


Measured memory_bytes: 5356
n = int(input())
a = 0
Ans_list = []
alpha = ["a","b","c","d","e","f","g","h","i",'j',"k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
qq = n % 26
if qq == 0:
    qq = 26
Ans_list.insert(0,qq)
b = n - qq
for i in range(10000):
    po = b // 26
    po2 = po % 26
    if po2 == 0:
        po2 = 26
    Ans_list.insert(0,po2)
    b = po - po2
    if b <= 0:
        break
Ans = ""
if n <= 26:
    del Ans_list[0]
for i in range(len(Ans_list)):
    Ans = Ans +  alpha[Ans_list[i]-1]
print(Ans)

Measured memory_bytes: 9160
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}


fn main() {
    let x = input!(i64);

    let mut t = 1;
    loop {
        if t * (t + 1) / 2 >= x {
            println!("{}", t);
            break;
        }
        t += 1;
    }
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main(void){
	int a[100000];
	int b;
	int c;
	int k;
	int l;
	int m;
	int n;
	int p;
	int q;
	long long s;
	int t;
	int x;
	int y;
	int z;
	s = 1;
	scanf("%d", &n);
	for (int i = 2; i <= n; i++){
		p = i;
		k = 1;
		x = n;
		b = 0;
		for (int j = 2; j < p; j++){
			if (p%j == 0)k = 0;
		}
		if (k == 1){
			for (; x != 0;){
				x = x / p;
				b = b + x;
			}
			b++;
			s = s*b;
			s = s % 1000000007;
		}
	}
	printf("%lld\n", s);
	return 0;
}

Measured memory_bytes: 128
from collections import Counter
from itertools import combinations

N, X, Y = map(int, input().split(' '))

c = Counter()
for i, j in combinations(range(1, N + 1), r=2):
    c[min(j - i, abs(X - i) + 1 + abs(j - Y))] += 1

for n in range(1, N):
    print(c[n])


Measured memory_bytes: 9652
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] a = new long[N+1];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextLong();
        }
        long tmp = 0L;
        long hunt = 0L;
        for (int i = 0; i < N; i++) {
            long b = sc.nextLong();
            long capa = b + tmp;
            if (a[i] <= capa) {
                if (a[i] <= tmp) {
                    tmp = b;
                } else {
                    tmp = b + tmp - a[i];
                }
                hunt += a[i];
            } else {
                hunt += b + tmp;
                tmp = 0L;
            }
        }
        if (a[N] <= tmp) {
            hunt += a[N];
        } else {
            hunt += tmp;
        }
        System.out.println(hunt);
    }
}

Measured memory_bytes: 65484
a=int(input())
x=[]
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
if a==1:
	print(0)
else:
	x=factorization(a)
	t=len(x)
	k=0
	n=1
	ans=0
	for i in range(t):
		k=x[i][1]
		n=1
		while k>=n:
			ans=ans+1
			k=k-n
			n=n+1

	print(ans)

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

int main() {
    ll k;
    cin >> k;
    const int n = 50;
    cout << n << endl;
    vector<ll> a(n);
    for (int i = 0; i < n; i++){
        ll a = k % n;
        ll b = k / n;
        ll d = i + b;
        if (i < a) d += 50 - a + 1;
        else
            d -= a;
        cout << d << (i == n-1 ? "\n" : " ");
    }
}

Measured memory_bytes: 256
import sys
from bisect import bisect
from operator import itemgetter
def main():
    b=sys.stdin.buffer
    n,d,a=map(int,b.readline().split())
    m=map(int,b.read().split())
    c=[0]*(n+1)
    z=sorted(zip(m,m),key=itemgetter(0))
    y=[x for x,_ in z]
    s=0
    for i,(x,h)in enumerate(z):
        c[i]+=c[i-1]
        h-=c[i]
        t=-h//a
        if t>0:t=0
        c[i]-=t*a
        c[bisect(y,x+d+d)]+=t*a
        s-=t
    print(s)
main()

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

#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)),  __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgm() {;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); }
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
const int inf = 1e18;

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

   int n;
   cin >> n;
   vector <int> v(n);
   for (auto &i : v)
      cin >> i;
   int res = 1;
   sort (v.begin(), v.end());
   for (int i = 0; i < n; i++) {
      if (v[i] > 0 && res > 0 && (v[i] > inf / res || res > inf / v[i])) {
         cout << -1 << '\n';
         return 0;
      }
      res *= v[i];
   }

   cout << res << '\n';


   return 0;
}

Measured memory_bytes: 3988
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! {
      _n: i64,
   }
   if _n == 0 {
      println!("0");
      return;
   }

   let mut n = _n;
   let mut mt: Vec<i8> = vec![];
   let mut t = 1;
   let mut two = 2;
   while n != 0 {
      if n % two != 0 {
         n -= t;
         mt.push(1);
      } else {
         mt.push(0);
      }
      two *= 2;
      t *= -2;
   }

   mt.reverse();
   for m in mt {
      print!("{}", m);
   }
   println!("");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 25
#define INF (1<<29)
 
struct Edge{
  int to,cost;
  Edge(int to,int cost) : to(to),cost(cost) {}
};
 
int V,maxi,start,sum;
int dist[MAX_N];
bool leaf[MAX_N],visited[MAX_N];
vector<Edge> G[MAX_N];
 
void getStart(int v,int d){
  for(int i = 0 ; i < (int)G[v].size() ; i++){
    Edge e = G[v][i];
    if(!leaf[e.to] && dist[e.to] == INF){
      dist[e.to] = d + e.cost;
      sum += e.cost*2;
      getStart(e.to,d+e.cost);
    }
  }
}

int getTreeDiameter(int v){
  int res = 0;
  for(int i = 0 ; i < (int)G[v].size() ; i++){
    Edge e = G[v][i];
    if(!visited[e.to]){
      visited[e.to] = true;
      if(!leaf[e.to]){
        res = max(res,e.cost+getTreeDiameter(e.to));
      }
    }
  }
  return res;
}
 
int main(){
  int N,a,b,c;
  while(cin >> N,N){
    for(int i = 0 ; i < N ; i++){
      G[i].clear();
      visited[i] = leaf[i] = false;
    }
    for(int i = 0 ; i < N-1 ; i++){
      cin >> a >> b >> c; a--; b--;
      G[a].push_back(Edge(b,c));
      G[b].push_back(Edge(a,c));
    }
    for(int i = 1 ; i < N ; i++){
      leaf[i] = (G[i].size() == 1);
    }
    sum = maxi = start = 0;
    fill(dist,dist+N,INF);
    dist[0] = 0; getStart(0,0);
    visited[start] = true;
    cout << sum-getTreeDiameter(start) << endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <vector>
#include <ctype.h>

const int MAX_SIZE = 1000;
char field[MAX_SIZE + 1][MAX_SIZE + 1];

const int STEP_NUM = 4;
const int STEP[STEP_NUM][STEP_NUM] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

using Position = std::pair<int,int>;

const int MAXN = 10;
Position locations[MAXN];
 
int H, W, N;

int get_shortest_distance(Position &start, Position &goal)
{
	bool is_visit[MAX_SIZE + 1][MAX_SIZE + 1]={};
	is_visit[start.first][start.second]=true;

	std::vector<Position> frontier(1,start);
	for(int step=0;step<W*H;step++)
	{
		std::vector<Position> next_frontier;
		for(auto p:frontier)
			for(int i=0;i<STEP_NUM;i++)
			{
				int nx = p.first+STEP[i][0];
				int ny = p.second+STEP[i][1];
				if(nx==goal.first && ny==goal.second)	return step+1;
				if(nx<0 || H<=nx) 		continue;
				if(ny<0 || W<=ny) 		continue;
				if(field[nx][ny]=='X') 	continue;
				if(is_visit[nx][ny]) 	continue;
				next_frontier.push_back(std::make_pair(nx,ny));
				is_visit[nx][ny] = true;
			}
		frontier = next_frontier;
	}
	return -1;
}

int solve()
{
	int total_step = 0;
	for(int i=1;i<N+1;i++)
		total_step += get_shortest_distance(locations[i-1],locations[i]);
	return total_step;
}

int main()
{
	scanf("%d %d %d", &H, &W, &N);
	for(int i=0; i<H; i++)
		scanf("%s", field[i]);
	for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		{
			if(field[i][j]=='S')
				locations[0] = std::make_pair(i,j);
			if(isdigit(field[i][j]))
				locations[field[i][j]-'0'] = std::make_pair(i,j);
		}
	printf("%d\n", solve());
	return 0;
}

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

void solve (int test_case) {
   int n ;
   cin >> n ;
   map<int , int> m ;
   long long sum = 0 ;
   for(int i = 0 ; i < n ; ++i) {
      int a ;
      cin >> a ;
      sum += a ;
      ++m[a] ;
   }
   int q ;
   cin >> q ;
   while (q--) {
      int b , c ;
      cin >> b >> c ;
      m[c] += m[b] ;
      int changes = m[b] ;
      m[b] = 0 ;
      sum -= (1LL*b*changes) ;
      sum += (1LL*c*changes) ;
      cout << sum << '\n' ;
   }
}

int main () {
   ios_base::sync_with_stdio(false) ;
   cin.tie(NULL) ;
   cout.tie(NULL) ;
   int tc = 1 ;
   //cin >> tc ;
   for (int i = 1 ; i <= tc ; ++i) {
      solve(i) ;
   }
}


Measured memory_bytes: 8072
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std; 
 
#define NOT_FOUND -1
#define rep(i,n) for(int i=0;i<(int)(n); i++)
#define ll long long
/*for文のマクロ定義
rep(i,回数){
    処理
}
*/
 
void swap(int *a, int *b){
	*b=*a-*b;
	*a-=*b;
	*b+=*a;
}
 
int sosu_judge(int N){
	/*素数ならば1
	  素数でなければ0を返す
	*/
	int i,j;
 
	if(N==2)   return 1;
	if(N%2==0) return 0;
 
	for(i=3;i<N && N%i!=0;i+=2);
 
	if(i>=N) return 1;
	
	return 0;
}
 
int factorial(int N){  //Nの階乗を求める関数
	int ans=1;
 
	while(N--) ans*=(N+1);
	return ans;
}
 
//クイックソートをする関数
void q_sort(int a[], int first, int last){
    int i,j;
    int x,t;
 
    x = a[(first + last) / 2];
    i = first; j=last;
 
    while(1){
        while( a[i] < x) i++;
        while( x < a[j]) j--;
        
        if( i >= j) break;
        
        swap(&a[i],&a[j]);
        i++; j--;
    }
    if(first < i-1) q_sort(a, first,i-1 );
    if(last > j+1)  q_sort(a, j+1,  last);
}
 
int b_search(int target, int array[],int right, int left){
    /*二分探索を行う関数である。
      戻り値は探索したい値の格納されている位置である。
      もし値が存在しない場合、NOT_FOUND(-1)を返す
    */
    int mid;
    while(left<right){
        mid=(right+left)/2;
        if(array[mid]<target) left =mid+1;
        else                  right=mid;
    }
    if(array[mid]==target) return mid;
    return NOT_FOUND;
}

//最大公約数を求める関数
int gcd(int a,int b){
    if(a%b == 0){
        return(b);
    }
    else{
        return(a*b/gcd(a,b));
    }
}
//最小公倍数を求める
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
 
unsigned long combination(int n, int r){
    /*nCrの値を求める関数である。
      値が巨大になる可能性があるため、戻り地はunsigned longである
    */
    int i,j;
    unsigned long a[17];
 
    if(n-r<r) r=n-r;
    if(r==0 ) return 1;
    if(r==1 ) return n;
    if(r>17 ) return 0;
    for(i=1;i<r;i++) a[i]=i+2;
    for(i=3;i<=n-r+1;i++){
        a[0]=i;
        for(j=1;j<r;j++)a[j]+=a[j-1];
    }
    return a[r-1];
}

int main(){
    int N,K;
    cin>>N>>K;
    int X[N];
    int len[2]={};
    int mid;

    rep(i,N) cin>>X[i];

    rep(i,N){
        mid=min(X[i],K-X[i]);
        len[0]+=mid;
    }
    cout<<len[0]*2<<endl;

    return 0;
}


Measured memory_bytes: 256
n,w=map(int,input().split())
dp=[[0 for _ in range(w+1)] for _ in range(n+1)]
for i in range(n):
    vi,wi=map(int,input().split())
    for j in range(w+1):
        if(j >= wi):
            dp[i+1][j] =max(dp[i][j-wi]+vi,dp[i][j])
        else:
            dp[i+1][j] =dp[i][j]
#    print(dp[i+1])
print(dp[n][w])


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;

    reverse(s.begin(), s.end());
    vector<int> sum(n + 1, 0);
    rep(i, n + 1) {
        if (s[i] == '0') sum[i] = 0;
        else sum[i] = sum[i - 1] + 1;
    }
    vector<int> ans;
    int now = 0;
    while (now != n) {
        int next = now + m;
        if (s[next] == '1') {
            next -= sum[next];
            if (now == next) {
                cout << -1 << endl;
                return 0;
            }
        }
        if (next > n) {
            next = n;
        }
        int distance = next - now;
        ans.push_back(distance);
        now = next;
    }

    reverse(ans.begin(), ans.end());
    for (int i : ans) {
        cout << i << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 1528
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF (1145141919)
using namespace std;

typedef struct
{
	int mi;
	int ma;
	int f;
} CLOTHES;

CLOTHES clothes[1000];
int T[1000];
int dp[1000][1000];

int main()
{
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < 1000; i++){
		dp[0][i] = 0;
	}
	
	int D, N;
	
	scanf("%d %d", &D, &N);
	
	for (int i = 0; i < D; i++){
		scanf("%d", &T[i]);
	}
	
	for (int i = 0; i < N; i++){
		scanf("%d %d %d", &clothes[i].mi, &clothes[i].ma, &clothes[i].f);
	}
	
	for (int i = 0; i < D; i++){
		for (int j = 0; j < N; j++){
			for (int k = 0; k < N; k++){
				if (T[i] >= clothes[k].mi && T[i] <= clothes[k].ma && dp[i][j] != -1){
					if (i > 0){
						dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abs(clothes[j].f - clothes[k].f));
					}
					else {
						dp[i + 1][k] = 0;
					}
				}
			}
		}
	}
	
	int maxi = -INF;
	
	for (int i = 0; i < N; i++){
		maxi = max(maxi, dp[D][i]);
	}
	
	printf("%d\n", maxi);
	
	return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  // ll a, b;
  ll n;
  cin >> n;
  string s; cin >> s;
  ll result = INF;
  bool judge = true;
  vector<ll> a(n);
  vector<ll> b(n);
  a[0] = 0; b[n-1] = 0;
  for(i = 1; i < n; i++){
    a[i] = a[i - 1];
    if(s[i - 1] == 'W'){
      a[i]++;
    }
  }
  for(i = n-2; i >=0; i--){
    b[i] = b[i+1];
    if(s[i+1] == 'E'){
      b[i]++;
    }
  }
  for(i=0;i<n;i++){
    chmin(result,a[i]+b[i]);
  }
  
  cout << result << endl;

  /*
  vector<ll> a(n);
  for(i = 0; i < n; i++)
    cin >> a[i];
  //for(i = 0; i < n; i++)
  */
  
  /*
  if(judge)
    //cout << "Yes" << endl;
    //cout << "YES" << endl;
    //cout << "Yay!" << endl;
  else
    //cout << "No" << endl;
    //cout << "NO" << endl;
    //cout << ":(" << endl;
  */
  
  //cout << result << endl;

  return 0;
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod

int solve(int l, int r, int al, int ar, vec &A){
    if(r == l + 1) return 0;
    int m = INF;
    FOR(k, l + 1, r) Min(m, solve(l, k, al, al + ar, A) + solve(k, r, al + ar, ar, A) + A[k] * (al + ar));
    return m;
}


signed main(){

    int N; cin >> N;
    vec A(N); cin >> A;
    int ans = solve(0, N - 1, 1, 1, A) + A[0] + A[N - 1];
    Out(ans);

    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(){
  int a, b, c, t;
 
  scanf("%d %d %d", &a,&b,&c);
  if(a > b){
    t=a;
    a=b;
    b=t;
  }
  if(b > c){
   t=b;
   b=c;
   c=t;
  }
  if(a > b){
    t=a;
    a=b;
    b=t; 
  }
  printf("%d %d %d\n", a,b,c);
  return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int dp[200][200][200];
signed main(){
	int a,b,c;cin>>a>>b>>c;
	memset(dp,0x3f,sizeof(dp));
	dp[a][b][c]=0;
	rep(i,150)rep(j,150)rep(k,150){
		if(dp[i][j][k]==INF)continue;
		int a[]={i,j,k};
		rep(I,3){
			int b[]={a[0],a[1],a[2]};
			b[I]+=2;
			dp[b[0]][b[1]][b[2]]=min(dp[b[0]][b[1]][b[2]],dp[i][j][k]+1);
		}
		rep(I,1<<3){
			if(__builtin_popcount(I)!=2)continue;
			int b[]={a[0],a[1],a[2]};
			rep(j,3){
				if(I>>j&1)b[j]++;
			}
			dp[b[0]][b[1]][b[2]]=min(dp[b[0]][b[1]][b[2]],dp[i][j][k]+1);
		}
	}
	int Min=INF;
	rep(i,200){
		Min=min(Min,dp[i][i][i]);
	}
	cout<<Min<<endl;
}

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

int main(){
    int n, m, l, a, b;
    int A[101][101] = {};
    int B[101][101] = {};
    long C[101][101] = {};
    
    cin >> n >> m >> l;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a;
            A[i][j] = a;
        }
    }
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= l; j++){
            cin >> b;
            B[i][j] = b;
        }
    }
    for(int i = 1; i <= l; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= m; k++){
                C[j][i] += A[j][k] * B[k][i];
            }
            
        }
    }
   
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= l; j++){
            if( j != 1){
                cout << " ";
            }
            cout << C[i][j];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3260
#include <cstdio>
using namespace std;

int main (void)
{
	int m, f, r, go;

	while (scanf("%d %d %d", &m, &f, &r)!= EOF && m!=-1 || f!=-1 || r!=-1){
		go = m+f;
		if (m == -1 || f == -1 || go < 30)
			printf("F\n");
		else{
			if (go >= 80)
				printf("A\n");
			else if (go >= 65)
				printf("B\n");
			else if (go >= 50)
				printf("C\n");
			else if (go >= 30){
				if (r >= 50)
					printf("C\n");
				else
					printf("D\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1016
# coding: utf-8
# Your code here!

# 入力
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

# 初期値
score = 0

# K個のグループに分ける
string = ['' for i in range(K)]

for i in range(N) : 
    string[i%K] += T[i]
    
# 動的計画法を使用, 0:r, 1:s, 2:p
for h in range(K) : 
    n = len(string[h])
    
    dp = [[0 for j in range(3)] for i in range(n)] 
    
    for i in range(n) : 
        if i==0 : 
            if string[h][i] == 'r' : 
                dp[i][2] += P
            elif string[h][i] == 's' : 
                dp[i][0] += R
            elif string[h][i] == 'p' : 
                dp[i][1] += S
        else : 
            if string[h][i] == 'r' : 
                dp[i][0] = max(dp[i][0], max(dp[i-1][1], dp[i-1][2]))
                dp[i][1] = max(dp[i][1], max(dp[i-1][0], dp[i-1][2]))
                dp[i][2] = max(dp[i][2], max(dp[i-1][0], dp[i-1][1])+P)
            elif string[h][i] == 's' : 
                dp[i][0] = max(dp[i][0], max(dp[i-1][1], dp[i-1][2])+R)
                dp[i][1] = max(dp[i][1], max(dp[i-1][0], dp[i-1][2]))
                dp[i][2] = max(dp[i][2], max(dp[i-1][0], dp[i-1][1]))
            elif string[h][i] == 'p' : 
                dp[i][0] = max(dp[i][0], max(dp[i-1][1], dp[i-1][2]))
                dp[i][1] = max(dp[i][1], max(dp[i-1][0], dp[i-1][2])+S)
                dp[i][2] = max(dp[i][2], max(dp[i-1][0], dp[i-1][1]))
                    
    score += max(dp[i][0], dp[i][1], dp[i][2])

print(score)

Measured memory_bytes: 17964
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    
    ll n=max(x,y);
    ll mn=LLINF;
    rep(i,n+1){
        ll sum=i*c*2;
        ll nx=max(0ll,x-i);
        ll ny=max(0ll,y-i);
        sum+=nx*a;
        sum+=ny*b;
        chmin(mn,sum);
    }
    cout1(mn)
}

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

using namespace std;
typedef long long ll;

int main(){
    int n, k;
    string s;
    cin >> n;
    cin >> s >> k;
    char c = s[k-1];
    for (int i = 0; i < n; i++)
    {
        if(c==s[i]){
            cout << s[i];
        }
        else cout <<'*';
    }
    cout << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void) {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> ds(n);

  for(int i = 0; i < n; ++i) {
    vector<int> a(d);
    for (int j = 0; j < d; ++j) {
      cin >> a[j];
    }
    ds[i] = a;
  }

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      int sqdist = 0;

      for (int k = 0; k < d; ++k) {
        int t = ds[i][k]-ds[j][k];
        sqdist += t*t;
      }

      int dist = (int)(sqrt(sqdist));
      if (dist*dist == sqdist) {
        ++cnt;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
              int count=1;
		Scanner sc = new Scanner(System.in);
		int x;
		while((x=sc.nextInt()) != 0){
		    System.out.printf("Case %d: %d\n",count++,x);
		}
	}
}


Measured memory_bytes: 66660
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

#define lint long long
#define MAX 100'000
int main() {
	
	string S;  cin >> S;
	int one = 0;
	int zero = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == '1') {
			one++;
		}
		else {
			zero++;
		}
	}

	cout << S.size() -( max(one, zero) - min(one, zero)) << endl;
	return 0;

}

Measured memory_bytes: 512
# C Vacation

n = int(input())
h_list = [[int(x) for x in input().split()] for i in range(n)]

dp = [[float("-Inf")] * n for i in range(3)]

dp[0][0] = h_list[0][0] 
dp[1][0] = h_list[0][1]
dp[2][0] = h_list[0][2]
for i in range(1,n,1):
    dp[0][i] = max(dp[1][i-1] + h_list[i][0], dp[2][i-1] + h_list[i][0])
    dp[1][i] = max(dp[2][i-1] + h_list[i][1], dp[0][i-1] + h_list[i][1])
    dp[2][i] = max(dp[0][i-1] + h_list[i][2], dp[1][i-1] + h_list[i][2])
    
print(max(dp[0][n-1],dp[1][n-1],dp[2][n-1]))

Measured memory_bytes: 36172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())

int main() {
  int H,W,M;
  cin >> H >> W >> M;
  vector<pii> B(M);
  vi cntH(H, 0), cntW(W,0);
  vector<bool> canH(H,false), canW(W,false);
  rep(i,M) {
    int h,w;
    cin >> h >> w;
    h--; w--;
    B[i] = {h,w};
    cntH[h]++;
    cntW[w]++;
  }
  int mh = 0, mw = 0;
  ll cnth = 0, cntw = 0;
  rep(i,H) {
    mh = max(mh, cntH[i]);
  }
  rep(i,W) {
    mw = max(mw, cntW[i]);
  }
  rep(i,H) {
    if (mh == cntH[i]) {
      canH[i] = true;
      cnth++;
    }
  }
  rep(i,W) {
    if (mw == cntW[i]) {
      canW[i] = true;
      cntw++;
    }
  }
  ll c = cnth * cntw;
  rep(i,M) {
    int h,w;
    h = B[i].first;
    w = B[i].second;
    if (canH[h] && canW[w])
      c--;
  }
  print((c<=0)?mh+mw-1:mh+mw);
  return 0;
}

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

const int M = 2005;
const ll p = 1e9+7;

ll n, m, k;
ll ans = 0;
ll dp[4005][2005];
ll part[4005][2005];

int main() {
    cin >> n >> m >> k;
    int l = (n+m-1)/(k-1);
    dp[0][0] = 1;
    for (int i = 1; i < 2005; ++i)
        part[0][i] = 1;

    for (int i = 1; i <= l; ++i) {
        for (int j = 0; j <= m; ++j) {
            dp[i][j] = (p+part[i-1][j+1]-part[i-1][max(0LL, j+1-k)])%p;
        }

        for (int j = 0; j <= m+1; ++j)
            part[i][j] = (j == 0) ? 0 : part[i][j-1]+dp[i][j-1];
    }

    for (int i = 1; i <= l; ++i)
        ans = (ans + dp[i][m-1])%p;
    if (m >= k && m%(k-1) == 1%(k-1)) {
        ans = (ans + p - 1)%p;
    }

    cout << ans << endl;
}

Measured memory_bytes: 125696
H,W,M=map(int, input().split())
nrow=[0]*H
ncol=[0]*W
xycoord=[]

for _ in range(M):
	h,w=map(int, input().split())
	nrow[h-1]+=1
	ncol[w-1]+=1
	xycoord+=[[w-1,h-1]]

#ncol=collections.Counter(xcoord)
#nrow=collections.Counter(ycoord)

a=max(nrow)
b=max(ncol)
row_cand=set([i for i, x in enumerate(nrow) if x == a])
col_cand=set([i for i, x in enumerate(ncol) if x == b])


flag=0
for i in xycoord:
	if (i[0] in col_cand) and (i[1] in row_cand):
		flag+=1

if flag<(len(col_cand)*len(row_cand)):
	print(max(nrow)+max(ncol))
else:
	print(max(nrow)+max(ncol)-1)



# 2darray [[0] * 4 for i in range(3)]
# import itertools

Measured memory_bytes: 103176
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;

struct edge {
	int to;ll cost;
	edge(int t,ll c):to(t),cost(c) {}
};

//int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

//-----------------------------------------------------------------------------

int n,a[100];

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

	cin>>n;
	REP(i,n) cin>>a[i];
	ll mi=LINF;
	FOR(i,-100,201) {
		ll sum=0;
		REP(j,n) {
			sum+=(a[j]-i)*(a[j]-i);
		}
		mi=min(mi,sum);
	}
	cout<<mi<<endl;

	return 0;
}


Measured memory_bytes: 256
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, x, y; cin >> n >> x >> y;
    --x, --y;
    vector<int> ans(n + 1, 0);
    rep(i, n) {
        queue<int> que;
        vector<int> dist(n, -1);
        dist[i] = 0;
        que.push(i);
        while(!que.empty()) {
            int v = que.front(); que.pop();
            if(v == x) {
                if(dist[y] == -1) {
                    que.push(y);
                    dist[y] = dist[v] + 1;
                }
            }
            if(v == y) {
                if(dist[x] == -1) {
                    que.push(x);
                    dist[x] = dist[v] + 1;
                }
            }
            for(int i = -1; i <= 1; i += 2) {
                int nv = v + i;
                if(nv >= 0 && nv < n && dist[nv] == -1) {
                    que.push(nv);
                    dist[nv] = dist[v] + 1;
                }
            }
        }
        rep(j, n) {
            if(i == j) continue;
            ans[dist[j]] ++;
        }
    }
    for(int k = 1; k <= n - 1; ++k) {
        cout << ans[k] / 2 << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return (x % MOD) * (m % MOD) % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    int N, K;
    cin >> N >> K;
    vector<int> v(K+1);

    int ans = 0;
    RREP(i,K) {
        if (i == 0) break;
        int g = modpow(K/i,N);
        for (size_t j = i*2; j <= K; j += i)
        {
            g = mod(g-v[j]);
        }
        // cerr << g << endl;
        ans = mod(ans+modm(g,i));
        v[i] = g;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define endl '\n'
#define _USE_MATH_DEFINES
using namespace std;

int main() {
	
	ios::sync_with_stdio(false);
    cin.tie(0);
    
    int i,n,k,ans = 0;
    cin>>n>>k;
    int price[n];
    
    for(i = 0;i<n;i++){
    	cin>>price[i];
	}
	sort(price,price+n);
	for(i = 0;i<k;i++){
		ans += price[i];
	}
	cout<<ans;
    
	return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<assert.h>
typedef long long ll;
ll gcd(ll a,ll b){
	return b?gcd(b,a%b):a;
}
void exgcd(ll a,ll b,ll&x,ll&y){
	if(!b){
		x=1;
		y=0;
		return;
	}
	exgcd(b,a%b,y,x);
	y-=a/b*x;
}
int phi(int n){
	int i,s=n;
	for(i=2;i*i<=n;i++){
		if(n%i==0){
			s=s/i*(i-1);
			while(n%i==0)n/=i;
		}
	}
	if(n>1)s=s/n*(n-1);
	return s;
}
int pow(int a,ll b,int p){
	int s=1;
	while(b){
		if(b&1)s=(ll)s*a%p;
		a=(ll)a*a%p;
		b>>=1;
	}
	return s;
}
ll solve(int a,int m){
	if(m==1)return 100;
	int p,g,ay;
	ll t,x,y;
	p=phi(m);
	g=gcd(m,p);
	t=solve(a,g);
	ay=pow(a,t,m);
	exgcd(p,m,x,y);
	ay-=t%p;
	if(ay<0){
		x=-x;
		ay=-ay;
	}
	x=((ay/g*x%m+m)%m)*p+t%p;
	t=(ll)m/g*p;
	while(x<100)x+=t;
	return x;
}
void work(){
	int a,m;
	scanf("%d%d",&a,&m);
	printf("%lld\n",solve(a,m));
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--)work();
}

Measured memory_bytes: 256
#include<stdio.h>

int queue[202];
int front=0;
int rear=0;
int parent[202];
int f[202][202];

int search(int nn,int num,int **rc,int goal){
  int i,j,flag=1,flag2;
  if(rc[nn][goal]!=0){
    parent[goal]=nn;
    return 1;
  }
  for(i=0;i<num-1;i++){
    if(rc[nn][i]!=0){
	flag=1;
	for(j=0;j<rear;j++){
	  if(i==queue[j])  flag=0;
	}
	if(flag){
	  queue[rear]=i;
	  rear++;
	  parent[i]=nn;
	}
    }
  }
  
  flag2=0;
  front++;
  while(front<rear&&flag2==0){
    flag2= search(queue[front],num,rc,goal);
    front++;
  }
  return flag2;
}

int main(){
  int n,i,j,temp,a[100],b[100],c[100],d[100],flag[100]={},sum=0,max=0,m[202][202]={};
  int flow,*rc[202];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a[i],&b[i]);
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&c[i],&d[i]);
  }

  for(i=1;i<=n;i++) {
    m[0][i]=1;
    m[i+n][2*n+1]=1;
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(a[i]<c[j]&&b[i]<d[j]) m[i+1][n+j+1]=1;
    }
  }

  front=0;
  queue[0]=0;
  rear=1;

  for(i=0;i<2*n+2;i++) rc[i]=m[i];

  flow=search(0,2*n+2,rc,2*n+1);

  while(flow!=0){
    for(i=0;i<(2*n+2);i++)
	for(j=0;j<(2*n+2);j++)
	  f[i][j]=0;
    i=(2*n+2)-1;
    do{
	rc[parent[i]][i]-=flow;
	rc[i][parent[i]]+=flow;
	i=parent[i];
    }while(i!=0);
    sum+=flow;
    front=0;
    queue[0]=0;
    rear=1;
    flow=search(0,2*n+2,rc,2*n+1);
  }
  printf("%d\n",sum);
}

Measured memory_bytes: 512
ss=gets.strip.split('')
sq = ss.join('').squeeze

def rle s
  s.each_char.inject([]) do |memo, c| 
     memo.last && c == memo.last.last ? memo.last[0] += 1 : memo << [1, c]
     memo
  end
end

def summ(n)
  (0..n).to_a.inject(:+)
end


rl = rle(ss.join(''))

result=0

if rl.first.last=='>'
  result += summ(rl.first.first)
  rl.shift
end

if rl.length > 0 && rl.last.last=='<'
  result += summ(rl.last.first)
  rl.pop
end

#p rl
rl.map(&:first).each_slice(2){|l,r|
  ll,rr = [l, r].minmax
  result += (summ(ll-1) + summ(rr))
}

p result

Measured memory_bytes: 89780
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    int K, N;
    cin >> K >> N ;
    int A[N];
    rep(i,0,N) {
        cin >> A[i];
    }
    
    int diff = 0;
    rep(i,0,N) {
        if (i!=N-1) {
            diff = max(diff,A[i+1]-A[i]);
        }
        else {
            diff = max(diff,A[0]+K-A[i]);
        }
    }

    cout << K-diff << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   ___debug::instance

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const multiset<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace ___debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	ld v = fetch<ld>();
	cout << fixed << setprecision(12) << (v * 6.28318530717958623200) << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 3808
#include<cstdio>
using namespace std;
int main()
{
	int n,m,i,j,a[100],b[101],cnt[100];
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i++){
		cnt[i]=0;
	}
	for(i=0;i<m;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&b[j]);
			if(a[i]==b[j]){
				cnt[j]++;
			}
			else{
				cnt[a[i]]++;
			}
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",cnt[i]);
	}
	return 0;
}

	


Measured memory_bytes: 2704
import sys
import bisect


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    a, b, q = list(map(int, readline().split()))
    s = [int(readline()) for _ in range(a)]
    t = [int(readline()) for _ in range(b)]
    x = [int(readline()) for _ in range(q)]
    for xv in x:
        sp = bisect.bisect_left(s, xv)
        tp = bisect.bisect_left(t, xv)
        ss = s[sp] if sp == 0 else 10 ** 20 if sp == len(s) else s[sp-1]
        ss -= xv
        se = 10 ** 20 if sp == 0 else s[sp-1] if sp == len(s) else s[sp]
        se -= xv
        ts = t[tp] if tp == 0 else 10 ** 20 if tp == len(t) else t[tp-1]
        ts -= xv
        te = 10 ** 20 if tp == 0 else t[tp-1] if tp == len(t) else t[tp]
        te -= xv
        mt = 10 ** 20
        for sv in [ss, se]:
            for tv in [ts, te]:
                if sv * tv < 0:
                    mt = min(mt, abs(sv) + abs(tv) + min(abs(sv), abs(tv)))
                else:
                    mt = min(mt, max(abs(sv), abs(tv)))
        print(mt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 73176
from itertools import product
n = int(input())
cnt = 0
a = ['7', '5', '3']
for i in range(3, len(str(n)) + 1):
    for j in product(a, repeat=i):
        word = ''.join(j)
        if all(w in word for w in ['7', '5', '3']) and int(word) <= n:
            cnt += 1
print(cnt)

Measured memory_bytes: 3060
h,w = map(int,input().split())
s =[input() for i in range(h)]


for i in range(h):
  for j in range(w):
    count = 0 
    if s[i][j]==".":
      for k in [[0,1],[1,0],[-1,0],[0,-1],[1,1],[-1,-1],[1,-1],[-1,1]]:
        if 0<=k[0]+i<h and  0<=k[1]+j<w:
          if s[k[0]+i][k[1]+j]=="#":
            count = count +1
      s[i] = s[i][0:j]+str(count)+s[i][j+1:w]
      
for i in range(h):
  for j in range(w):
    print(s[i][j], end="")
  print()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int L,R,d;
    cin>>L>>R>>d;
    cout<<R/d-(L-1)/d<<endl;
}


Measured memory_bytes: 3628