akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

int main() {
  std::string s;
  std::cin >> s;
  for (int i = 0; i < 19; i++) {
    if (i == 5 || i == 13)std::cout << " ";
    else std::cout << s[i];
  }
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a,p;
  cin >> a >> p;
  cout << (a*3+p)/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y,z;
  int cnt=0;
  cin >> x >> y >> z;
  while(1){
    x-=z;
    if(x<=0)break;
    x-=y;
    if(x<=0)break;
    else if(x>=z)cnt++;
  }
  cout << cnt << 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++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  int x, n;
  cin >> x >> n;
  vi p(n);
  vector<bool>h(102);
  rep(i,n) cin >> p[i];
  rep(i,n){
    h[p[i]] = true;
  }
  pair<int,int>ans(10000000,-1);
  for(int i=0; i<=101; i++){
    if(h[i])continue;
    ans = min(ans, pair<int,int>(abs(x-i), i));
  }
  cout << ans.second << endl;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int count(vector<vector<bool> > v,int h,int w){
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(v[i][j])ans++;
        }
    }
    return ans;
}

int main(){
    int h,w,k;
    
    cin>>h>>w>>k;
    vector<vector<bool> > c(h ,vector<bool> (w,false));

    rep(i,h){
        string tmp;
        cin>>tmp;
        rep(j,w){
            if(tmp[j]=='#'){c[i][j]=true;}
        }
    }

    int ans = 0;
    for (int bit = 0; bit < (1<<h); ++bit) {
        // Hを全探索
        vector<vector<bool> > c1 = c;
        for (int i = 0; i < h; ++i) {
            if (bit & (1<<i)) rep(j,w)c1[i][j]=false;
        }

        
        for (int bit1 = 0; bit1 < (1<<w); ++bit1) {
        // Wを全探索
            vector<vector<bool> > c2 = c1;
            for (int i = 0; i < w; ++i) {
                if (bit1 & (1<<i)) rep(j,h)c2[j][i]=false;        
            }

            if(k == count(c2,h,w)){
                ans++;
                // rep(q,h){
                //     rep(p,w)cout<<c2[q][p];
                //     cout<<""<<endl;
                // }  
            }
        }
        
    }

    cout<<ans;

    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long sum = 0;
    for(int i = 1; i <= n; i++){
      if(i%3!=0 && i%5 != 0){
        sum += i;
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 35800
#include <iostream>

typedef long long ll;

int main(){
   const int n = 5;
   ll N;
   std::cin >> N;
   ll A[n];
   ll min = 1000000000000000;
   for(int i=0; i<n; ++i){
      std::cin >> A[i];
      if(min>A[i]){
	 min = A[i];
      }
   }

   ll ans = 0;
   ans = N/min + n - 1;
   ans += N%min>0 ? 1 : 0;

   std::cout << ans << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
  
#define MAX 500
  
using namespace std;
 
int main(void){
    while(1){
        int w, h, t, p; cin >> w >> h >> t >> p;
        if(!w && !h && !t && !p) break;

        int kami[MAX][MAX]={0};
        for(int i=0; i<h; i++){
            fill(kami[i], kami[i]+w, 1);
        }
  
        int origin_x = 0, origin_y =0;
        for(int k=0; k<t; k++){
            int d, c; cin >> d >> c;
            int dist = 1;
            if(d == 1){
                for(int j=origin_x+c; j<origin_x+(2*c); j++){
                     for(int i=origin_y; i<MAX; i++){
                        kami[i][j] += kami[i][j-dist];
                    }
                    dist += 2;
                }
                origin_x += c;
            } else{
                for(int i=origin_y+c; i<origin_y+(2*c); i++){
                    for(int j=origin_x; j<MAX; j++){
                        kami[i][j] += kami[i-dist][j];
                    }
                    dist += 2;
                }
                origin_y += c;
            }
        }
          
        for(int k=0; k<p; k++){
            int x, y; cin >> x >> y;
            cout << kami[origin_y+y][origin_x+x] << endl;
        }
    }
  
    return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	int n;cin>>n;
	int h[101];
	h[0]=0;
	rep1(i,n) cin>>h[i];
	int ans=0;
	for(int i=1;i<=100;i++){
		bool f=false;
		for(int j=1;j<=n;j++){
			if(!f&&h[j]>=i) {ans++;f=true;}
			else if(f&&h[j]<i) {f=false;}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  string s;
  string::size_type t;
  cin >> n;
  getchar();
  while (n--) {
    getline(cin, s);
    t = 0;
    while ((t = s.find("Hoshino", t)) != string::npos) {
      s[t + 6] = 'a';
      t += 1;
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int N,X,T,a;
    cin >> N >> X >> T;
    // たこ焼きを焼く回数
  	if(N%X==0){
      a = N/X;
    }else{
      a = N/X + 1;
    }
    
    // 出力
    cout << a * T << endl;
    return 0;
}

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

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

int main()
{
	int N, K, mi = 1e9, ma = 1;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		mi = min(mi, A[i]);
		ma = max(ma, A[i]);
	}
	if (N == 1) {
		cout << (A[0] == K ? "POSSIBLE" : "IMPOSSIBLE") << endl;
		return 0;
	}
	int g = abs(A[1] - A[0]);
	for (int i = 2; i < N; i++) {
		g = gcd(g, abs(A[i] - A[0]));
	}
	if (K <= ma && ((mi == K && ma == K) || abs(K - A[0]) % g == 0)) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
			int W = sc.nextInt();
        	int H = sc.nextInt();
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	int r = sc.nextInt();
        
        
		if(x-r < 0 || x+r>W){
		System.out.println("No");
		}else if(y-1 < 0 || y+1 > H){
			System.out.println("No");
		}else{
        System.out.println("Yes");
        }		sc.close();
	}
}



Measured memory_bytes: 26228
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    ll A,B,C,D,N;
    ll ans=0;
    ll X[4];
    string S[4];
int main(){
    cin>>A>>B>>C>>D;
    cout<<(A-C)*(B-D);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void){

	unsigned long long a, b, c, amari, itizi;

	cin >> a >> b;

	c = a*b;

	if(a < b){
		itizi = a;
		a = b;
		b = itizi;
	}

	amari = a % b;

	while(amari != 0){

		a = b;
		b = amari;
		amari = a % b;

	}

	cout << c/b << endl;

return 0;
}

Measured memory_bytes: 256
def bubble(ary)
  flg = true
  n = ary.length

  while flg
    flg = false
    (n - 1).downto(1) do |i|
      next if ary[i][1].to_i >= ary[i - 1][1].to_i
      ary[i], ary[i - 1] = ary[i - 1], ary[i]
      flg = true
    end
  end

  ary
end

def selection(ary)
  n = ary.size

  n.times do |i|
    minj = i
    i.upto(n - 1) do |j|
      minj = j if ary[minj][1].to_i > ary[j][1].to_i
    end
    ary[i], ary[minj] = ary[minj], ary[i]
  end

  ary
end

gets

input = gets.chomp.split

b_ary = bubble(input.dup)
s_ary = selection(input.dup)

puts b_ary * ' ', 'Stable', s_ary* ' '
puts b_ary == s_ary ? 'Stable' : 'Not stable'

Measured memory_bytes: 6880
#include<iostream>
#include<string>
using namespace std;
int main(){
long i,l,n=0;
string s;
while(cin>>s){
l=s.size();
for(i=0;i<l/2;i++)if(s[i]!=s[l-1-i])break;
if(i>=l/2)n++;
}
cout<<n<<endl;
return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

struct dice {
    int u,s,e,w,n,d;

    void command(char com){
        if(com == 'E'){
            int tmp = u;
            u = w;
            w = d;
            d = e;
            e = tmp;
        }
        else if(com == 'S'){
            int tmp = n;
            n = d;
            d = s;
            s = u;
            u = tmp;
        }
        else if(com == 'N'){        
            int tmp = u;
            u = s;
            s = d;
            d = n;
            n = tmp;
        }
        else if(com == 'W'){
            int tmp = u;
            u = e;
            e = d;
            d = w;
            w = tmp;        
        }
    }
};

int main(){
    dice D;
    scanf("%d%d%d%d%d%d", &D.u, &D.s, &D.e, &D.w, &D.n, &D.d);

    string com;
    cin >> com;
    rep(i,com.size())D.command(com[i]);
    
    cout << D.u << endl;
    //printf("%d %d %d %d %d %d\n", D.u, D.s, D.e, D.w, D.n, D.d);

    return 0;
}


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

int main() {
  string s;
  ll k;
  cin >> s >> k;
  char c;
  for (int i = 0; i < k; i++) {
    c = s[i];
    if (s[i] != '1') {
      break;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
using System.Collections.Generic;
using static System.Console;
using static System.Math;

class Program {
	static void Main() {
		var N = NextInt();
		var K = NextInt();
		var ans = 0;

		for (var i = 0; i < N; i++) {
			var x = NextInt();
			ans += 2 * Min(x, K - x);
		}
		WriteLine(ans);
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}


Measured memory_bytes: 11220
#include <stdio.h>
#include <math.h>

int main () {
    int n, a[1005];
    double ans=0,m=0;
    for (;;)
    {
        scanf("%d",&n);
        if (n==0) return 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d",&a[i]);
            m+=a[i];
        }
        m/=(double)n;
        for (int i = 0; i < n; i++)
        {
            ans+=pow((a[i]-m),2);
        }
        printf("%.8lf\n",sqrt(ans/(double)n));
        ans=0;m=0;
    }
    
    

}


Measured memory_bytes: 2056
n = int(input())
H = list(map(int,input().split()))[::-1]

cur = H[0]
ans = 'Yes'

for i,h in enumerate(H[1:-1],1):
	if cur < h:
		if abs(cur-h) >= 2:
			ans = 'No'
			break
	else:
		cur = h

print(ans)

Measured memory_bytes: 15020
// finish date: 2018/03/13

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    map<int, int> A, B;
    vi arr(N);
    int in;
    vl sumA(N + 1, 0), sumB(N + 1, 0);
    rep(i, N) {
        cin >> in;
        A[in]++;
        sumA[0] += in;
    }
    rep(i, N) {
        cin >> arr[i];
    }
    rep(i, N) {
        cin >> in;
        B[in]++;
        sumB[0] += in;
    }

    rep(i, N) {
        sumA[i + 1] = sumA[i] + max(arr[i], A.begin()->first) - A.begin()->first;
        if (arr[i] > A.begin()->first) {
            A[arr[i]]++;
            A.begin()->second--;
            if (A.begin()->second == 0) A.erase(A.begin()->first);
        }

        sumB[i + 1] = sumB[i] + min(arr[N - 1 - i], B.rbegin()->first) - B.rbegin()->first;
        if (arr[N - 1 - i] < B.rbegin()->first) {
            B[arr[N - 1 - i]]++;
            B.rbegin()->second--;
            if (B.rbegin()->second == 0) B.erase(B.rbegin()->first);
        }
    }

    ll ma = LONG_LONG_MIN;
    rep(i, N + 1) {
        ma = max(ma, sumA[i] - sumB[N-i]);
    }
    cout<<ma<<endl;

    return 0;
}

Measured memory_bytes: 11520
N, M = [int(x) for x in input().split()]
s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = [int(x) for x in input().split()]

ans = [None] * N
exists = True

for i in range(M):
    if N > 1 and s[i] == 1 and c[i] == 0:  # 2桁以上の数字の1桁目が0
        exists = False
    elif ans[s[i] - 1] == None:
        ans[s[i] - 1] = str(c[i])
    elif ans[s[i] - 1] == str(c[i]):
        continue
    else:
        exists = False
        break

if exists:
    if N == 1:
        if ans[0] == None:  ans[0] = "0"
    else:
        if ans[0] == None:  ans[0] = "1"
        for j in range(1, N):
            if ans[j] == None:  ans[j] = "0"
    ans = "".join(ans)
else:
    ans = "-1"

print(ans)


Measured memory_bytes: 38384
H,N = map(int,input().split())
dp = [float('INF')]*(H+1)
dp[0]=0
for _ in range(N):
    a,b = map(int,input().split())
    for i in range(1,H+1):
        dp[i]=min(dp[max(i-a,0)]+b,dp[i])

print(dp[-1])

Measured memory_bytes: 49884
#include <iostream>
using namespace std;
#define brk system("pause");

const int N = 1001;
const int mod = 1e9 + 7;
int a[N][N], dp[N][N];

main()
{
	ios::sync_with_stdio(0);
	
	int n, m;
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			char ch; cin >> ch;
			if(ch == '.')
				a[i][j] = 1;
			dp[i][j] = a[i][j];
		}
	}
	
	for(int i = 2; i <= n; i++)
		if(dp[i][1]) dp[i][1] = dp[i - 1][1];
	
	for(int i = 2; i <= n; i++)
		if(dp[1][i]) dp[1][i] = dp[1][i];
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 2; j <= m; j++)
		{
			if(a[i][j])
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
		}
	}
	
	cout << dp[n][m] << endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long double ld;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
1~i番目までの商品を用いて重みをj以下にするときの価値の最大値p[i][j]
*/

int p[110][10100];

void solve(){

    int N,W;
    cin >> N >> W;
    int v[1010];
    int w[1010];
    rep(i,N){
        cin >> v[i+1] >> w[i+1];
    }
    rep(i,W+1){
        p[0][i]=0;
    }
    rep(i,N+1){
        p[i][0]=0;
    }
    for(int i=1; i<=N; i++){
        for(int j=1; j<=W; j++){
            if(j>=w[i]) p[i][j]=max(p[i-1][j], p[i-1][j-w[i]]+v[i]);
            else p[i][j]=p[i-1][j];
        }
    }

    /*
    rep(i,N+1){
        rep(j,W+1){
            cout << p[i][j] << " ";
        }
        cout << endl;
    }
    */

    cout << p[N][W] << endl;

}

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



Measured memory_bytes: 7156
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		
		if(Objects.equals(str.charAt(2), str.charAt(3)) && Objects.equals(str.charAt(4), str.charAt(5))) {
			System.out.println("Yes");
		}else{
			System.out.println("No");
		};
		
		
	}
}

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

int main() {
	string key;
	string ring[128];
	int n;
	int ans = 0;

	cin >> key;
	cin >> n;

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

	for(int i = 0; i < n; i++) {
		if(ring[i].find(key) != string::npos)
			ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1220
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    l = list(map(int, input().split()))
    if max(l) < sum(l)-max(l):
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

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

		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();

		int count=0;
		for(int i=a;i<=b;i++){
			if(c%i==0)	count++;
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 26192
// D - Recording

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int rec[100001];
vector<pair<int, int>> plan[30];

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

	int s, t, c;
	for (int i=0; i<N; i++) {
		cin >> s >> t >> c;
		c--;
		plan[c].push_back(make_pair(s, t));
	}

	for (int i=0; i<C; i++) {
		sort(plan[i].begin(), plan[i].end());

		int prev_t = -1;
		for (auto p : plan[i]) {
			int s = p.first;
			int t = p.second;
			if (s == prev_t) {
				rec[prev_t]++;
			} else {
				rec[s-1]++;
			}
			rec[t]--;
			prev_t = t;
		}
	}

	int ans = 0;
	for (int i=1; i<100001; i++) {
		rec[i] = rec[i-1] + rec[i];
		ans = max(ans, rec[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1920
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define VECV(a,n,m) vector<vector<int>> a(n, vector<int>(m));
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin>>S;
  int N=S.length();
  rep(i,N){
	S.replace(i,1,"x");
  }
  cout<<S<<endl;
}


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

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}

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

    if(n>=k){
        if(n%k==0)ans=0;
        else ans=min(n%k,abs(n%k-k));
    }
    else ans=min(k-n,n);

    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<iostream>

int main(){
	int N,A[200000];
  int max=0;
  int max2=0;
  int flag=0;
  scanf("%d",&N);
 for(int i=0;i<=N-1;i++){
 	scanf("%d",&A[i]);
   if(A[i]>max){
     max2=max;
   		max=A[i];
   }
   if(A[i]>max2){
     if(A[i]!=max){
   		max2=A[i];
   	}
   }
 }
  for(int k=0;k<=N-1;k++){
  	if(A[k]==max){
    	flag++;
    }
  }
 for(int j=0;j<=N-1;j++){
 	if(A[j]!=max){
    	printf("%d\n",max);
    }
   else{
     if(flag>1){
     printf("%d\n",max);
     }
     else{
     	printf("%d\n",max2);
     }
     }
 }
}

Measured memory_bytes: 2432
# 10_*
class Dice:
    def __init__(self, label: list):
        self.top, self.front, self.right, self.left, self.back, self.bottom = label

    def roll(self, direction: str):
        if direction == "N":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.front,
                self.bottom,
                self.right,
                self.left,
                self.top,
                self.back,
            )
        elif direction == "W":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.right,
                self.front,
                self.bottom,
                self.top,
                self.back,
                self.left,
            )
        elif direction == "S":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.back,
                self.top,
                self.right,
                self.left,
                self.bottom,
                self.front,
            )
        elif direction == "E":
            self.top, self.front, self.right, self.left, self.back, self.bottom = (
                self.left,
                self.front,
                self.top,
                self.bottom,
                self.back,
                self.right,
            )

    def output_top(self):
        print(self.top)

    def get_top_front(self):
        return f"{self.top} {self.front}"

    def print_right(self):
        print(self.right)


# 10_A
# (*label,) = map(int, input().split())
# dice = Dice(label)
# for i in input():
#     dice.roll(i)
# dice.output_top()

# 10_B
(*label,) = map(int, input().split())
dice = Dice(label)
q = int(input())
for _ in range(q):
    t, f = map(int, input().split())
    for i in "EEEN" * 2 + "EEES" * 2 + "EEEN" * 2:
        if f"{t} {f}" == dice.get_top_front():
            dice.print_right()
            break
        dice.roll(i)


Measured memory_bytes: 5620
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(cal(sc.nextInt(),0));
	}

	private static int cal(int n, int cnt) {
		if (n < 6) return cnt + n;
		else if (n < 9) return cnt + 1 + n % 6;
		int tmp6 = 6;
		int tmp9 = 9;
		while (n >= tmp6 * 6) {
			tmp6 *= 6;
		};
		while (n >= tmp9 * 9) {
			tmp9 *= 9;
		};
		return Math.min(cal(n-tmp6,cnt+1), cal(n-tmp9,cnt+1));
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
signed main(){
  long long n,sum=0,j;
  vector <int> a;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>j;
    sum+=j;
    a.push_back(j);
  }
  sort(a.begin(),a.end());
  cout<<a[0]<<' '<<a[n-1]<<' '<<sum<<'\n';
  return(0);
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string s;
    cin >> s;
    cout << s.substr(0, s.size() - 8) << endl;
    return 0;
}


Measured memory_bytes: 3596
import java.{util => ju}
import scala.collection.{mutable => mu}
import MyPredef._


object Main extends App {
    val H,W = nextLong
    var h=Math.min(H,W)
    var w=Math.max(H,W)
    //val h=Math.max(H,W)
    //val w=Math.min(H,W)
    //val h=H
    //val w=W
    
    val res = if(h%3==0||w%3==0){
        0
    }else{
        var res = h
        
        (Math.max(w/3,0) to Math.min(w,w/3+1)).foreach(x => {
            val wx = w-x
            val h0 = h/2
            val h1 = h-h/2
            val can = Seq(x*h,wx*h0,wx*h1)
            res = Math.min(res,can.max-can.min)
        })
         
        (Math.max(h/3,0) to Math.min(h,h/3+1)).foreach(x => {
            val hx = h-x
            val w0 = w/2
            val w1 = w-w/2
            val can = Seq(x*h,hx*w0,hx*w1)
            res = Math.min(res,can.max-can.min)
        })
        //*
        h=Math.max(H,W)
        w=Math.min(H,W)
        //*/
        //*
        (Math.max(w/3,0) to Math.min(w,w/3+1)).foreach(x => {
            val wx = w-x
            val h0 = h/2
            val h1 = h-h/2
            val can = Seq(x*h,wx*h0,wx*h1)
            res = Math.min(res,can.max-can.min)
        })
        //*/
        //*
        (Math.max(h/3,0) to Math.min(h,h/3+1)).foreach(x => {
            val hx = h-x
            val w0 = w/2
            val w1 = w-w/2
            val can = Seq(x*h,hx*w0,hx*w1)
            res = Math.min(res,can.max-can.min)
        })
        //*/
        
        res
    }
    
    println(res)
}


object MyPredef {
  @inline def rep(n: Int, f: => Unit): Unit = { var c = 0; while (c < n) { f; c += 1 } }
  @inline def rep(n: Int, f: Int => Unit): Unit = { var c = 0; while (c < n) { f(c); c += 1 } }

  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}
object MyArray {
  def fillT[T : scala.reflect.ClassTag](dimX: Int, dimY: Int)(f: => T): Array[Array[T]] = {
    val arrs = Array.ofDim[T](dimX, dimY)
    for {
      y <- (0 until dimY)
      x <- (0 until dimX)
    } {
      arrs(x)(y) = f
    }
    arrs
  }
}

Measured memory_bytes: 25544
#include<stdio.h>
int main() {
	int i,n,k,s,f;
	while (1) {
		f = 0;
		scanf("%d", &n);
		if (n == 0)break;
		s = n + 1;
		for (i = 0; i < n; i++) {
			scanf("%d", &k);
			if (k == 0) {
				s--;
			}
			if (k >= 2)f = 1;
		}
		if (f == 0) {
			printf("NA\n");
		} else {
			printf("%d\n",s);
		}
	}
	return 0;
}


Measured memory_bytes: 2720
n = int(input())
h = list(map(int,input().split()))
a = [0]*n
a[1] = abs(h[1]-h[0])
for i in range(2,n):
  a[i] = min(abs(h[i]-h[i-1]) + a[i-1], abs(h[i]-h[i-2]) + a[i-2]) 
print(a[-1])

Measured memory_bytes: 13980
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    m = {}

    for i in a:
        if i not in m:
            m[i] = 1
        else:
            m[i] += 1
    
    ans = 0

    for key in m:
        if m[key] >= 2:
            ans += m[key] * (m[key] - 1) // 2
    
    for i in range(n):
        if m[a[i]] >= 2:
            print(ans - (m[a[i]] * (m[a[i]] - 1) // 2 - (m[a[i]] - 1) * (m[a[i]] - 2) // 2))
        else:
            print(ans)

Measured memory_bytes: 26140
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

using namespace std;

struct UF {
  vector<int> data;
  int nDistinct;
  UF() {}
  UF(int n) : data(n, -1), nDistinct(n) {}
  void init(int n) { data.assign(n, -1); nDistinct = n; }
  int size(void) const { return nDistinct; }
  int rootOf(int a) { return data[a] >= 0 ? data[a] = rootOf(data[a]) : a; }
  int count(int a) { return -data[rootOf(a)]; }
  bool isSameGroup(int a, int b) { return rootOf(a) == rootOf(b); }
  bool unify(int a, int b) {
    int ra = rootOf(a), rb = rootOf(b);
    if(ra == rb) return false;
    if(data[ra] < data[rb]) swap(ra, rb);
    data[rb] += data[ra]; data[ra] = rb; --nDistinct;
    return true;
  }
};

int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  UF uf(n);
  REP(i, m) {
    int a, b, z;
    scanf("%d%d%d", &a, &b, &z);
    --a;
    --b;
    uf.unify(a, b);
  }
  printf("%d\n", uf.size());
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <complex>
#include <cstring>
#include <cfloat>
#include <iomanip>
#include <stack>
#include <bitset>


using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define bitcount(n) __builtin_popcountll(n)
#define pii pair<int, int>


typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 200000 + 7;
const int M = 103;
const int inf = 1e9 + 7;
const long long linf = 1ll * inf * (inf - 1);
const double pi = acos(-1);
const double eps = 1e-6;
const bool multipleTest = false;



int a[N], x[N];
int n;

bool check(int val) {
    for(int i = 1; i < 2 * n; ++i) {
        x[i] = (a[i] >= val);
    }
    
    if (x[n] == x[n + 1] || x[n] == x[n - 1]) return x[n];
    
    int r = n + 1;
    while (r < 2 * n && x[r] != x[r - 1]) ++r;
    int l = n - 1;
    while (l > 0 && x[l] != x[l + 1]) --l;
    
    if (l == 0 && r == 2 * n) {
        if (n & 1) return x[n];
        else return x[n] ^ 1;
    }
    
    if (l == 0) return x[r];
    if (r == 2 * n) return x[l];
    
    if (x[l] == x[r]) return x[l];
    
    if (n - l < r - n) return x[l];
    else return x[r];
}

void solve(){
    cin >> n;
    for(int i = 1; i < 2 * n; ++i) scanf("%d", a + i);
    
    
//    for(int i = 2; i < 2 * n - 1; ++i) cout << check(i) << " ";
//    puts("");
    
    int lo = 2, hi = 2 * n - 2, res = 1;
    while (lo <= hi) {
        int g = (lo + hi) >> 1;
        if (check(g)) {
            res = g;
            lo = g + 1;
        } else hi = g - 1;
    }
    
    cout << res;
    
    
}

void createTest() {
    freopen("in.txt", "w", stdout);
    int n = 10;
    cout << n << "\n";
    set<int> st;
    for(int i = 1; i < 2 * n; ++i) st.insert(i);
    
    for(int i = 1; i < 2 * n; ++i) {
        int u = rand() % 200000;
        ft(st) it = st.lower_bound(u);
        if (it == st.end()) --it;
        printf("%d ", *it);
        st.erase(it);
    }
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    clock_t t1 = clock();
#endif
//    createTest();
//    return 0;
//    freopen("out.txt", "w", stdout);
    
    
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    
    for(int i = 0; i < Test; ++i) {
//        printf("Case #%d: ", i + 1);
        solve();
    }
    
#ifdef _LOCAL_
    cout<<"\n" << 1.0 * (clock() - t1) / CLOCKS_PER_SEC<<endl;
#endif
    
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
typedef long long ll;
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++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);



int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> cnt(n);
    rep(i,n) {
        cin >> s[i];
        rep(j,n) {
            if (s[i][j]=='1') {
                ++cnt[i];
            }
        }
    }
    int ans=0;
    
    bool flag=1;
    rep(e,n) {
        vector<int> d(n,-1);
        queue<int> q;
        q.push(e);
        d[e]=0;
        while (!q.empty()) {
            int i=q.front();
            q.pop();
            rep(j,n) {
                if (s[i][j]=='1') {
                    if (d[j]==-1) {
                        d[j]=d[i]+1;
                        q.push(j);
                    } else if ((d[i]+1-d[j])%2==1) flag=0;
                }
            }
        }
        int tans=0;
        rep(i,n) tans=max(tans,d[i]+1);
        rep(i,n) {
            if (d[i]==-1) ++tans;
        }
        ans=max(ans,tans);
    }
    
    if (flag) cout << ans << endl;
    else cout << -1 << endl;
    


    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = 1e9 + 7;

int main2() {
  int N = nextInt();
  ll K = nextInt();
  vector<int> A(N);
  REP(i, N) A[i] = nextInt();
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    {
      ll x = 0;
      for (int j = 0; j < i; j++) {
        if (A[j] < A[i]) x++;
      }
      ll KK = (K * (K-1) / 2) % MOD;
      ans += x * KK;
      ans %= MOD;
    }
    {
      ll x = 0;
      for (int j = i+1; j < N; j++) {
        if (A[j] < A[i]) x++;
      }
      ll KK = (K * (K+1) / 2) % MOD;
      ans += x * KK;
      ans %= MOD;
    }
  }
  ans %= MOD;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a=n/1000,b=(n-(n/1000)*1000)/100,c=(n-(n/100)*100)/10,d=n%10;
    if((a==b&&b==c)||(b==c&&c==d)){
      cout<<"Yes"<<endl;
    }
  else{
    cout<<"No"<<endl;
  }
}






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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	ll a , b , c ; 
	cin >> a >> b >> c ; 
	ll l = a*a + b*b + c*c + 2*a*b - 2*b*c - 2*a*c ; 
	ll r = 4 *a*b ; 
	if(a > c || b > c) {
		cout <<"No";
		return 0 ;
	}
	//cout << l << " " << r << endl ; 
	if(l > r) 
		cout << "Yes"; 
	else
		cout << "No" ; 
	return 0 ; 
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	string s[n];int a[n];
	rep(i,n)cin>>s[i]>>a[i];
	vector<int> ord(n);
	iota(ord.begin(),ord.end(),0);
	sort(ord.begin(),ord.end(),[&](int x,int y){
		if(s[x]==s[y])return a[x]>a[y];
		return s[x]<s[y];
	});
	rep(i,n){
		cout<<ord[i]+1<<endl;
	}
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,K, a[100];
ll ans[5050],mk;
vector<pll> av;
ll i,j,k;
int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &a[i]);
    }
    mk = -1;
    fornum(i,0,K+1){
        pll minns = mp(99999,-1);
        fornum(j,0,N){
            if(mk!=j&&a[j]<minns.first){
                minns = mp(a[j],j);
            }
        }
        if(minns.first==0)
            break;
        
        fornum(j,0,N){
            if(j!=mk&&j!=minns.second){
                ans[k] = j + 1;
                k++;
                a[j]--;
            }
        }
        mk = minns.second;
        ans[k]=mk+1;
        k++;
        a[mk]--;
    }
    if(i!=K+1){
        printf("-1");
        return 0;
    }
    printf("%lld\n", k);
    fornum(i,0,k){
        printf("%lld ", ans[i]);
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
// # define INF (1 << 29)
/* ちゃんと考えてわかって実装 */

const int MAX_N = 100;
const int MAX_V = 1000;
const ll INF = 1000000000000000001;

int main(void){
    int n, w;
    cin >> n >> w;
    vector<ll> Wgt(n+1), Val(n+1);
    for(int i=1; i<=n; i++){
        cin >> Wgt[i] >> Val[i];
    }

    ll dp[n+1][MAX_N * MAX_V + 1]; // dp[i][j] = i番目までの品物から価値がj以下となるように選んだ時の重さの最小値
    for(int i=0; i<=n; i++){
        for(int j=0; j<=MAX_N*MAX_V; j++){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    for(int i=1; i<=n; i++){
        for(int j=0; j<=MAX_N*MAX_V; j++){
            if(j - Val[i] >= 0){
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-Val[i]]+Wgt[i]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    ll ans = 0;
    for(int i=0; i<=MAX_N*MAX_V; i++){
        if(dp[n][i] <= w) ans = i;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 79104
import java.util.Scanner;
import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long result = 0;
    char[] cs;
    String s;
    Map<String, Integer> map = new HashMap<String, Integer>();
    for(int i = 0, n = sc.nextInt(); i < n; i++) {
      cs = sc.next().toCharArray();
      Arrays.sort(cs);
      s = new String(cs);
      if (map.containsKey(s)) {
        result += map.get(s);
        map.put(s, map.get(s) + 1);
      } else
        map.put(s, 1);
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 54028
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder {
    class Program {
        static void Main(string[] args) {
            string[] buf = Console.ReadLine().Split(' ');
            int n = int.Parse(buf[0]);
            int m = int.Parse(buf[1]);
            int ans = 0;

            if (m != 0) {
                for (int i = m - 1; i != 0; i--) {
                    ans += i;
                }

            }

            if (n != 0) {
                for (int i = n - 1; i != 0; i--) {
                    ans += i;
                }

            }

            Console.WriteLine(ans);


        }

    }

}


Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace D_ABC136
{
    class MainClass
    {

        //        static int[] s;
        static string s;

        public static void Main(string[] args)
        {
            s = ReadLine();
            var sl = new List<int>();
            int n = s.Length;
            int before = 0;
            int cnt = 0;
            var grpl = new List<int[]>();
            for (int i = 0; i < n; i++)
            {
                cnt++;
                if (s[i] == 'R')
                {
                    sl.Add(0);
                    if (before == 1)
                    {
                        int[] gr = new int[2] { cnt-1, i };
                        grpl.Add(gr);
                        cnt = 1;
                    }
                }
                else
                {
                    sl.Add(1);
                    if(i==n-1){
                        int[] gr = new int[2]{cnt,i+1};
                        grpl.Add(gr);
                        cnt = 0;
                    }
                }
                before = sl[i];
            }
            var ansl = new List<int>();
/* 
            foreach(int[] item in grpl){
                WriteLine("{0} {1}",item[0],item[1]);
            }*/
            

            int idx = 0;


            for (int i = 0; i < n ; i++)
            {
                if (sl[i] == 0 && sl[i + 1] == 1)
                {
                    int[] divs = grpl[idx];
                    idx++;
                    int div = divs[0];
                    if (div % 2 == 0)
                    {
                        ansl.Add(div / 2);
                        ansl.Add(div / 2);
                        i++;
                    }
                    else
                    {
                        int new0 = i - (divs[1]-divs[0]);
                        //WriteLine("new0 : {0} ",new0);
                        if (new0%2==1)
                        {
                            ansl.Add(div / 2);
                            ansl.Add(div / 2 + 1);
                        }
                        else
                        {
                            ansl.Add(div / 2 + 1);
                            ansl.Add(div / 2);
                        }
                        i++;
                    }

                }
                else
                {
                    ansl.Add(0);
                }


            }

            for (int i = 0; i < ansl.Count; i++)
            {
                if (i == ansl.Count - 1)
                {
                    WriteLine(ansl[i]);
                }
                else
                {
                    Write("{0} ", ansl[i]);
                }
            }
        }
    }
}


Measured memory_bytes: 22748
#include <bits/stdc++.h>
#define MN 201
#define pb push_back
#define mp make_pair
using namespace std;
int h,w;
int a[55][55];
int dx[4] = {0,1,0,-1},dy[4] = {1,0,-1,0};
int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char tmp; cin>>tmp;
            if(tmp=='#') a[i][j] = 1;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]){
                int cnt = 0;
                for(int k=0;k<4;k++){
                    int tmpx = i+dx[k];
                    int tmpy = j+dy[k];
                    if(tmpx>=0 && tmpx<h && tmpy>=0 && tmpy<w){
                        if(a[tmpx][tmpy]){
                            cnt++; break;
                        }
                    }
                }
                if(!cnt){
                    cout<<"No"<<'\n';
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<'\n';
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
mod=10**9+7
ans=1
#Combination 1 O()
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb=Combination(10**6)

if n-1<=k:
    print(comb(2*n-1,n)%mod)

else:
    for i in range(1,k+1):
        ans+=(comb(n,i)*comb(n-1,i))
        ans%=mod
    print(ans%mod)

Measured memory_bytes: 121852