akhauriyash/Code-Regression huggingface dataset:
/* it was worth becoming a chemist */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 2e6 + 5;


int n;
ll a[MAXN], x;


int main() {	
    
    cin >> n >> x;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort (a + 1, a + 1 + n);
    int res = 0;
    for (int i = 1; i <= n; i++) {
        if (i == n) {
            if (a[i] == x) res++;
            continue;
        }
        if (a[i] <= x) {
            x -= a[i];
            res++;
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
N, A, B, C = gets.chomp.split.map(&:to_i)
$bamboos = Array.new(N) { gets.chomp.to_i }.sort

$ret = []
def dfs(depth, v)
  if depth == N
    calc(v)
    return
  end
  0.upto(3) do |i|
    v[depth] = i
    dfs(depth + 1, v)
  end
end

def calc(v)
  mp = 0
  # 一個も割り当てのない採集成果物があってはならない
  if (v & [0,1,2]).length != 3
    return nil
  end
  lengths = Array.new(4) { 0 }
  v.each_with_index do |which, i|
    if lengths[which] === 0
      lengths[which] = $bamboos[i]
    else
      lengths[which] += $bamboos[i]
    end
  end
  mp += (v.count(0) + v.count(1) + v.count(2) - 3) * 10

  mp += (A - lengths[0]).abs
  mp += (B - lengths[1]).abs
  mp += (C - lengths[2]).abs
  $ret.push mp
end

dfs( 0, [])
puts $ret.min

Measured memory_bytes: 2356
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; long long x; cin >> N >> x; long long arr[N]; 
    for(int i=0 ;i<N; i++){
        cin >> arr[i] ;
    }
    sort(arr , arr+N);
    int answer = 0;
    for(int i=0; i<N; i++){
        if(arr[i] == x){
            x = 0; answer++;
        }else if(arr[i] < x){
            if(i != N-1){
                x-=arr[i]; answer++;
            }
        }
    }
    cout << answer << endl;
}


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

int main(int argc, char* argv[])
{
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;

  std::string judge = "No";
  if ((std::fabs(a-b) <= d && std::fabs(b-c) <= d) ||
      (std::fabs(a-c) <= d)) {
    judge = "Yes";
  }

  std::cout << judge << std::endl;
  return 0;
}


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

int main(){
    int a;
    int b;
    char op;
    while(true){
        cin >> a>> op >> b;
        if(op == '+'){
            cout << a+b << endl;
        }
        if(op == '-'){
            cout << a-b << endl;
        }
        if(op == '*'){
            cout << a*b << endl;
        }
        if(op == '/'){
            cout << a/b << endl;
        }
        if(op == '?'){
            break;
        }
    }
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<int, int>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}

int main(){
	char c;
	cin >> c;
	if (c >= 'a' && c <= 'z'){
		cout << 'a' << endl;
	}
	else{
		cout << 'A' << endl;
	}
	


}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    mat F(N, vec(10));
    mat P(N, vec(11));
    REP(i,0,N) {
        REP(j,0,10) cin >> F[i][j];
    }
    REP(i,0,N) {
        REP(j,0,11) cin >> P[i][j];
    }

    ll m = -INF, sum = 0;
    vector<bool> G(10);
    vec C(N);
    REP(i,1,1<<10) {
        REP(j,0,10) G[j] = (((i >> j) & 1) == 1);
        sum = 0;
        REP(j,0,N) {
            C[j] = 0;
            REP(k,0,10) C[j] += (F[j][k] && G[k]);
            sum += P[j][C[j]];
        }
        m = MAX(m,sum);
    }
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 3628
import java.util.Scanner;

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

    int h = sc.nextInt();
    int n = sc.nextInt();

    int total = 0;
    for(int i = 0; i < n; i++){
      total += sc.nextInt();
      if( total >= h ){
        break;
      }
    }

    if( total < h ){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}


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

int main(){
  int n;
  cin >> n;
  int h[n];
  rep(i,n)cin >> h[i];
  int ans = 0;
  int x = 0;
  rep(i,n-1){
    if(h[i]>=h[i+1])ans++;
    else ans = 0;
    x = max(x,ans);
  }
  cout << x << endl;
}


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

using namespace std;

int main() {
	
	string s, t;
	cin >> s >> t;

	int counter = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			counter++;
		}
	}
	
	cout << counter << endl;


	return 0;
}

Measured memory_bytes: 3916
x = int(input())
a = int(x**(1/2))
max_ = -1

i = 2

while i <= a:
    j = 2
    while i**j <= x:
        if max_ <= i**j:
            max_ = i**j
        j += 1
    i += 1

if max_ < 0:
    print(1)
else:
    print(max_)

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

int main() {
  int R; cin >> R;
  string ans;
  if (R < 1200) {
    ans = "ABC";
  }
  else if (R < 2800) {
    ans = "ARC";
  }
  else {
    ans = "AGC";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		long[] a = new long[n];
		int mcnt = 0;
		for(i=0; i<n; i++) {
			a[i] = parseLong(sc.next());
			if(a[i]<0) {
				mcnt++;
				a[i]=-a[i];
			}
		}
		sc.close();
		Arrays.parallelSort(a);
		long sum=0;
		for(i=1; i<n; i++) {
			sum+=a[i];
		}
		out.println(mcnt%2==0?sum+a[0]:sum-a[0]);
	}
}


Measured memory_bytes: 47476
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        char[] s=sc.next().toCharArray();
        char[] s2=sc.next().toCharArray();
        for(int i=0;i<n;i++)System.out.print(s[i]+""+s2[i]);
    }
}


Measured memory_bytes: 23252
n = int(input())
a = [0] * n
x = [[0] * n for i in range(n)]
y = [[0] * n for i in range(n)]

for i in range(n):
    a[i] = int(input())
    for j in range(a[i]):
        x[i][j], y[i][j] = map(int, input().split())
        x[i][j] -= 1


def check(honest):
    for i in range(n):
        if not honest[i]:continue
        for j in range(a[i]):
            if y[i][j] == 1 and not honest[x[i][j]]:return False
            if y[i][j] == 0 and honest[x[i][j]]:return False
    return True
        
def dfs(honest):
    if len(honest) == n:
        if check(honest):
            return sum(honest)
        else:
            return 0
    return max(dfs(honest + [True]),
               dfs(honest + [False]))
    
print(dfs([]))
        

Measured memory_bytes: 50904
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int x;
  cin>>x;
  if(x>=2400){
    cout<<1<<endl;
    return 0;
  }
  rep(i,25){
    rep(j,25){
      rep(k,25){
        rep(l,25){
          rep(m,25){
            rep(n,25){
              if(i*100+j*101+k*102+l*103+m*104+n*105==x){
                cout<<1<<endl;
                return 0;
              }
            }
          }
        }
      }
    }
  }
  cout<<0<<endl;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#include <algorithm>

int main(){
  int n;
  cin >> n;
  if(n == 1)
    cout << "Hello World" << endl;
  else{
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
  }
}

Measured memory_bytes: 256
while(<STDIN>){
	chomp;
    @line = split(/ /, $_);
    $K = $line[0];
    $A = $line[1]; # Aビスケット -> 1円
    $B = $line[2]; # Bビスケット <- 1円
}

if ($B - $A <= 2) {
	$Ans = $K+1;
} else {
	if ($K+1 - $A < 2) {
		$Ans = $K+1;
    } else {
    	if (($K+1 - $A)%2 == 0) {
        	$Ans = ($B - $A) * ($K+1 - $A)/2 + $A
        } else {
        	$Ans = ($B - $A) * int(($K+1 - $A)/2) + $A + 1
        }
    }
}
#print "48518828981938099\n";
print "$Ans\n";


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

long long gcd(long long a, long long b) {
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
int main() {
  long long a, b, c, d;
  cin>>a>>b>>c>>d;


  long long lcm = c * d / gcd(c, d);
  long long ans = b - a + 1 - (b / c - (a - 1)/ c)
    - (b / d - (a - 1)/ d)
    + (b / lcm - (a - 1) / lcm);
  cout<<ans<<endl;

}

Measured memory_bytes: 256
S = input()
l = 0
b = 0
k = 0
sum = 0
for i in range(len(S)):
    k += 1
    if i == len(S)-1 or (S[i] != S[i+1]):
        sum += k * (k + 1) / 2
        if S[i] =="<":
            l = k
            k = 0
        if S[i] ==">":
            b = k
            k = 0
            sum -= min(l, b)

print(int(sum)) 

Measured memory_bytes: 4212
#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 int MAX_N = 112345;
int a[MAX_N];

int main2() {
  int N = nextInt();
  int K = nextInt();
  REP(i, N) a[i] = nextInt();
  sort(a, a+N);
  int ans = a[N-1] - a[0];
  for (int i = 0; i + K <= N; i++) {
    chmin(ans, a[i+K-1] - a[i]);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

using namespace std;

int main()
{
   int n;
   cin >> n;
   string a, b;
   cin >> a >> b;
   for(int i = 0; i < n; i++)
   {
     cout << a[i] << b[i];
   }
   cout << '\n';
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

public class Solution
{
    public static void Main()
    {
        var s = Console.ReadLine();
        bool match = false;
        match |= Regex.IsMatch(s, "^.*keyence$");
        match |= Regex.IsMatch(s, "^k.*eyence$");
        match |= Regex.IsMatch(s, "^ke.*yence$");
        match |= Regex.IsMatch(s, "^key.*ence$");
        match |= Regex.IsMatch(s, "^keye.*nce$");
        match |= Regex.IsMatch(s, "^keyen.*ce$");
        match |= Regex.IsMatch(s, "^keyenc.*e$");
        match |= Regex.IsMatch(s, "^keyence.*$");

        if (match)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 14272
#include<stdio.h>
int main(){
int i,j,b=0;
char a[20][20];
for(i=0;i<20;i++){
for(j=0;j<20;j++){
a[i][j]='0';
}
}
while(scanf("%c",&a[4][4])!=EOF){
for(i=4;i<12;i++){
for(j=4;j<12;j++){
if(i!=4 || j!=4){
scanf("%c",&a[i][j]);
}
}
scanf("\n");
}
scanf("\n");
for(i=4;i<12;i++){
for(j=4;j<12;j++){
if(a[i][j]=='1' && a[i][j+1]=='1' && a[i+1][j]=='1' && a[i+1][j+1]=='1'){
printf("A\n");
b++;
}
else if(a[i][j]=='1' && a[i+1][j]=='1' && a[i+2][j]=='1' && a[i+3][j]=='1'){
printf("B\n");
b++;
}
else if(a[i][j]=='1' && a[i][j+1]=='1' && a[i][j+2]=='1' && a[i][j+3]=='1'){
printf("C\n");
b++;
}
else if(a[i][j]=='1' && a[i+1][j-1]=='1' && a[i+1][j]=='1' && a[i+2][j-1]=='1'){
printf("D\n");
b++;
}
else if(a[i][j]=='1' && a[i][j+1]=='1' && a[i+1][j+1]=='1' && a[i+1][j+2]=='1'){
printf("E\n");
b++;
}
else if(a[i][j]=='1' && a[i+1][j]=='1' && a[i+1][j+1]=='1' && a[i+2][j+1]=='1'){
printf("F\n");
b++;
}
else if(a[i][j]=='1' && a[i][j+1]=='1' && a[i+1][j-1]=='1' && a[i+1][j]=='1'){
printf("G\n");
b++;
}
if(b==1){
break;
}
}
if(b==1){
break;
}
}
b=0;
for(i=0;i<20;i++){
for(j=0;j<20;j++){
a[i][j]='0';
}
}
}
return 0;
}


Measured memory_bytes: 1932
#include <iostream>
#include <vector>
#include <limits>

using namespace std;
using MatrixGraph = vector<vector<int>>;

const int infinity = numeric_limits<int>::max();
const int no_label = -1;

vector<int> calc_shortest_path(MatrixGraph matrix_graph, int started_label) {
  vector<int> min_costs(matrix_graph.size(), infinity);
  vector<bool> is_visits(matrix_graph.size(), false);

  min_costs[started_label] = 0;

  while(true) {
    int min_cost_adjacency_label = no_label;
    int min_cost_adjacency_weight = infinity;
    for(int i = 0; i < matrix_graph.size(); i++) {
      if(is_visits[i]) {
        continue;
      }

      if(min_costs[i] < min_cost_adjacency_weight) {
        min_cost_adjacency_label = i;
        min_cost_adjacency_weight = min_costs[i];
      }
    }
    if(min_cost_adjacency_label == no_label) {
      break;
    }

    is_visits[min_cost_adjacency_label] = true;

    for(int i = 0; i < matrix_graph.size(); i++) {
      if(matrix_graph[min_cost_adjacency_label][i] == infinity) {
        continue;
      }

      if(min_costs[min_cost_adjacency_label] + matrix_graph[min_cost_adjacency_label][i] < min_costs[i]) {
        min_costs[i] = min_costs[min_cost_adjacency_label] + matrix_graph[min_cost_adjacency_label][i];
      }
    }
  }

  return min_costs;
}

int main() {
  int vertex_num;
  cin >> vertex_num;
  MatrixGraph matrix_graph(vertex_num, vector<int>(vertex_num, infinity));

  for(int i = 0; i < vertex_num; i++) {
    int label, degree;
    cin >> label >> degree;
    for(int j = 0; j < degree; j++) {
      int adjacency_label;
      int adjacency_weight;
      cin >> adjacency_label >> adjacency_weight;
      matrix_graph[label][adjacency_label] = adjacency_weight;
    }
  }

  vector<int> min_consts = calc_shortest_path(matrix_graph, 0);

  for(int i = 0; i < min_consts.size(); i++) {
    cout << i << ' ' << min_consts[i] << endl;
  }
}



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(b==1){
    cout << 0 << endl;
  }
  else if(b<=a){
    cout << 1 << endl;
  }
  else{
    cout << 1+(b-2)/(a-1) << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  char c;
  cin >> c;
  if ('a' <= c && c <= 'z') {
    cout << 'a' << endl;
  } else {
    cout << 'A' << endl;
  }
  return 0;
}

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

using namespace std;
const int mod = 1e9 + 7;
int n;
int a[200];
int mypow(int x, int n) {
    if (n == 0) return 1;
    int g = mypow(x, n / 2);
    g = 1ll * g * g % mod;
    if (n & 1) g = 1ll * g * x % mod;
    return g;
}
int f[200][200];
int good[5][5];
int b[200];
int ll[200], rr[200];
long long geomprog(int b, int k) {
    if (k <= 0) return 1;
    return mypow(b, k + 1) - 1;
}
int solve(int l, int r) {
    for (int j = l; j <= r; j++) b[j] = a[j];
    sort(b + l, b + r + 1);
    int c = 1, k = 0;
    for (int i = l; i <= r; i++) {
        if (b[i] != b[i - 1]) {
            k++;
            ll[k] = c;
            rr[k] = b[i] - 1;
            c = b[i];
        }
    }
    f[l][0] = 2;
    for (int j = 1; j <= k; j++)
        if (rr[j] < a[l]) f[l][j] = (geomprog(2, a[l] - ll[j]) - geomprog(2, a[l] - rr[j] - 1) + mod) % mod;
    for (int i = l; i < r; i++)
    for (int j = 0; j <= k; j++)
        if (f[i][j] != 0) {
            if (j == 0) {
                if (a[i] >= a[i + 1]) {
                    f[i + 1][0] += 2ll * f[i][j] % mod;
                    if (f[i + 1][0] >= mod) f[i + 1][0] -= mod;
                }
                else {
                    f[i + 1][0] += 2ll * f[i][j] % mod;
                    if (f[i + 1][0] >= mod) f[i + 1][0] -= mod;
                    for (int t = 1; t <= k; t++)
                        if (ll[t] >= a[i] && rr[t] < a[i + 1]) {
                            int c = (geomprog(2, a[i + 1] - ll[t]) - geomprog(2, a[i + 1] - rr[t] - 1) + mod) % mod;
                            f[i + 1][t] += 1ll * c * f[i][j] % mod;
                            if (f[i + 1][t] >= mod) f[i + 1][t] -= mod;
                        }
                }
            }
            else {
                if (rr[j] < a[i + 1]) {
                    int c = 1;
                    if (a[i + 1] > a[i]) c = mypow(2, a[i + 1] - a[i]);
                    f[i + 1][j] += 1ll * f[i][j] * c % mod;
                    if (f[i + 1][j] >= mod) f[i + 1][j] -= mod;
                }
                else {
                    f[i + 1][0] += 2ll * f[i][j] % mod;
                    if (f[i + 1][0] >= mod) f[i + 1][0] -= mod;
                }
            }
        }
    int s = 0;
    for (int j = 0; j <= k; j++) {
        s += f[r][j];
        if (s >= mod) s -= mod;
    }
    return s;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    good[0][3] = good[3][0] = 1;
    good[1][2] = good[2][1] = 1;
    good[1][1] = good[2][2] = 1;
    for (int i = 1; i <= n; i++) cin >> a[i];
    long long c = 1; int prv = 0;
    a[n + 1] = 1;
    for (int i = 1; i <= n + 1; i++) {
        if (a[i] == 1) {
            if (i != n + 1) c = c * 2 % mod;
            if (prv + 1 <= i - 1) c = c * solve(prv + 1, i - 1) % mod;
            prv = i;
        }
    }
    cout << c << "\n";
    return 0;
}


Measured memory_bytes: 384
while True:
    h, w = map(int,input().split())
    if h == w == 0:
        break
    for i in range(h):
        for j in range(w):
            if i == 0 or i == (h-1):
                print("#",end="")
            else:
                if j == 0 or j == (w-1):
                    print("#",end="")
                else:
                    print(".",end="")
        print()
    print()


Measured memory_bytes: 7004
#入力はn人のx,yに分けないといけない
n = int(input())
a = []
x = [[] for i in range(n)]
y = [[] for i in range(n)]
for i in range(n):
    a.append(int(input()))
    for j in range(a[i]):
        xx, yy = (int(i) for i in input().split())
        x[i].append(xx)
        y[i].append(yy)

testimony = [[2]*n for i in range(n)]

for i in range(n):
    for j in range(a[i]):
        if (y[i][j] == 1):
            testimony[i][x[i][j] - 1] = 1#正直者ならtestimonyのxの位置に正直者である1を置く
        elif(y[i][j] == 0):
            testimony[i][x[i][j]-1] = 0#さっきの反対

ans = 0
for i in range(2**n):#2**n通りの「正直者」と「不親切な人」の全パターンを列挙
    bit_list = []
    for j in range(n):
        if ((i >> j) & 1):
            bit_list.append(1)#正直者なら
        else:
            bit_list.append(0)
    flag = 1
    #列挙した中からtestimony[k][l]と一致するのを探し、さらにその中からbit_listの最大値を求める
    for k in range(n):
        if(bit_list[k] == 1):
            for l in range(n):
                if(testimony[k][l] != 2):#２(デフォルト状態じゃないとき)
                    if(testimony[k][l] != bit_list[l]): #yの人の証言と食い違っていたらflagを0にする
                        flag = 0
                        break
    
    if(flag == 1):
        ans = max(sum(bit_list),ans)
print(ans)

Measured memory_bytes: 3188
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] group = {-1,0,2,0,1,0,1,0,0,1,0,1,0};
        if(group[x]==group[y])System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21844
s=str(input())
X="abcdefghijklmnopqrstuvwxyz"
Y=[]
for i in range(len(X)):
    Y.append(X[i])
for i in range(len(X)):
    if X[i] in s:
        Y.remove(X[i])


if len(Y)==0:
    print("None")

else:
    print(Y[0])
        


Measured memory_bytes: 9132
#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>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
	mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
	mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
	mint operator+(const mint a) const {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
 		return a;
	}

	// For prime mod.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

vvll g;

mint dfs(ll s) {
    mint ret = 1;
    for(auto i : g[s]) {
        ret *= dfs(i);
    }
    return ret + 1;
}

void solve() {
    ll n;
    cin >> n;
    vpll p;
    for(ll i = 0; i < n; i++) {
        ll x, d;
        cin >> x >> d;
        p.push_back(make_pair(x, d));
    }
    sort(p.begin(), p.end(), greater<pll>());
    g = vvll(n);
    priority_queue<pll, vpll, greater<pll>> q;
    for(ll i = 0; i < n; i++) {
        ll x = p[i].first, d = p[i].second;
        while(!q.empty() && q.top().first < x + d) {
            g[i].push_back(q.top().second);
            q.pop();
        }
        q.push(make_pair(x, i));
    }
    mint ans = 1;
    while(!q.empty()) {
        ans *= dfs(q.top().second);
        q.pop();
    }
    cout << ans.x << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 23916
import java.util.*;
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 D = sc.nextInt();
      	
       	boolean flg=true;
      	for(;flg==true;){
          C=C-B;
         if(C<=0){
         System.out.println("Yes");
         flg=false;
           break;
         }
          A=A-D;
          if(A<=0){
         System.out.println("No");
         flg=false;
         }
         }
        
		
		
	}
}

Measured memory_bytes: 27084
n,d = map(int,input().split())
zahyo = []
count = 0
for i in range(n):
    zahyo.append(list(map(int,input().split())))
for a in range(n):
    for b in range(n):
        if a<=b:
            break
        else:
            p = 0
            for i in range(d):
                p += (zahyo[a][i]-zahyo[b][i])**2
            if p**0.5 == int(p**0.5):
                count += 1
print(count)

Measured memory_bytes: 3188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Abhilash Mandaliya
 */
public class Main {
    public static void main (String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader( inputStream );
        PrintWriter out = new PrintWriter( outputStream );
        TaskD solver = new TaskD();
        solver.solve( 1, in, out );
        out.close();
    }

    static class TaskD {
        public void solve (int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] nums = new int[n];
            for ( int i = 0; i < n; i++ ) {
                nums[i] = in.nextInt() - 1;
            }
            int cnt = 0;
            for ( int i = 0; i < n; i++ ) {
                if ( nums[i] == i ) {
                    cnt++;
                    i++;
                }
            }
            out.println( cnt );
        }

    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar;
        private int snumChars;

        public InputReader (InputStream st) {
            this.stream = st;
        }

        public int read () {
            if ( snumChars == - 1 )
                throw new InputMismatchException();
            if ( curChar >= snumChars ) {
                curChar = 0;
                try {
                    snumChars = stream.read( buf );
                } catch ( IOException e ) {
                    throw new InputMismatchException();
                }
                if ( snumChars <= 0 )
                    return - 1;
            }
            return buf[curChar++];
        }

        public int nextInt () {
            int c = read();
            while ( isSpaceChar( c ) ) {
                c = read();
            }
            int sgn = 1;
            if ( c == '-' ) {
                sgn = - 1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while ( ! isSpaceChar( c ) );
            return res * sgn;
        }

        public boolean isSpaceChar (int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == - 1;
        }

    }
}

Measured memory_bytes: 23504
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
int32_t main(){
	if(fopen("input.txt", "r"))
	freopen("input.txt", "r", stdin),
	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n;
	cin >> n;
	int a[n],f[n+1]={0},ans=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		f[a[i]]++;
	}
	for(int i=0;i<=n;i++){
		if(f[i]<2)continue;
		ans+=f[i]*(f[i]-1)/2;
	}
	for(int i=0;i<n;i++){
		int t=f[a[i]];
		cout << ans-t*(t-1)/2+(t-1)*(t-2)/2 << endl;
	}
}

Measured memory_bytes: 5760
use std::collections::BTreeMap;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    let k: i32 = read();
    let q: i32 = read();
    let a: Vec<i32> = (0..q).map(|_| read()).collect();

    let mut map = BTreeMap::new();

    for &a_i in a.iter() {
        *map.entry(a_i).or_insert(0) += 1;
    }

    for i in 1..n + 1 {
        if k - q + map.get(&i).unwrap_or(&0) > 0 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4732
#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <assert.h>
#include <bitset>
#include <string>
#include <cstdio>
#include <math.h>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
using namespace std;

#define int64 long long
#define mp make_pair
#ifdef _DEBUG
const int N = 500;
#else
const int N = 300000;
#endif

const int64 INF = 1e18;

string s;
int n, cnt[26];

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> s;
	n = s.length();
	for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
	int64 ans = 1ll * n * (n + 1) / 2 + 1;
	for (int i = 0; i < 26; i++) ans -= 1ll * cnt[i] * (cnt[i] + 1) / 2;
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
MOD = 10**9+7
n, k = map(int, input().split())
a = list(map(int, input().split()))

cnt1 = 0
for i in range(len(a)-1):
    for j in range(i, len(a)):
        if a[i] > a[j]:
            cnt1 += 1

a2 = a * 2
cnt2 = 0
for i in range(len(a)):
    for j in range(len(a), len(a2)):
        if a2[i] > a2[j]:
            cnt2 += 1

print((cnt1 * k + cnt2 * k * (k-1) // 2) % MOD)


Measured memory_bytes: 41836
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a*b > c*d){
        printf("%d\n",a*b);
	} else {
        printf("%d\n",c*d);
	}
	return 0;
}


Measured memory_bytes: 3764
#include<stdio.h>

/*
//Q4 time
int main(void){
    
    int data;
    int a,b,c;
    
    scanf("%d",&data);
    
    a = data / 3600;
    
    b = (data % 3600) / 60;
    
    c = (data % 3600) % 60;
    
    printf("%d:%d:%d",a,b,c);
    
    return 0;
}

*/

/*
int main(void){
    
    int a,b;
    
    scanf("%d%d",&a,&b);
    
    if(a < b){
        printf("a < b\n");
    }else if(b < a){
        printf("a > b\n");
    }else{
         printf("a == b\n");
    }
}
*/

int main(){
    
    int a,b,c;
    
    scanf("%d%d%d",&a,&b,&c);
    
    if(a < b && b < c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
}


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

const int INF = 1<<30;

int main() {
  int n, m;
  string s;
  cin >> n >> m >> s;
  vector<int> dp(n+1,INF);
  dp[n] = 0;
  queue<int> q;
  q.push(0);
  for (int i = n-1; i >= 0; --i) {
    while (1) {
      if (q.size() == 0) {
        puts("-1");
        return 0;
      }
      if (q.front() != INF && q.size() <= m) break;
      q.pop();
    }
    if (s[i] == '0') dp[i] = q.front()+1;
    q.push(dp[i]);
  }

  vector<int> ans;
  int x = 0;
  int rest = dp[0];
  while (x < n) {
    --rest;
    int i = 1;
    while (dp[x+i] != rest) ++i;
    ans.push_back(i);
    x += i;
  }
  rep(i,ans.size()) {
    printf("%d%c", ans[i], i==int(ans.size())-1?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 1528
from numpy import cumsum
from collections import Counter
from math import factorial
N = int(input())
A = [int(i) for i in input().split()]
B = sorted(cumsum(A))
C = Counter(B)
def comb(n,r):
    ret = 1
    for i in range(n-r+1,n+1):
        ret *= i
    return ret//factorial(r)
ans = 0
for k in C.keys():
    if k == 0:
        ans += comb(C[k], 2)
        ans += C[k]
    else:
        if C[k] >= 2:
            ans += comb(C[k], 2)
print(ans)

Measured memory_bytes: 50080
n,a,b = map(int, input().split())

def digit_sum(num):
    sum = 0
    i = 1
    while num > 0:
        mod = num % (10**i)
        num = int(num / (10**i))
        sum += mod
    return sum

sum = 0
for i in range(n):
    t = digit_sum(i+1)
    if (t >= a) and (t <= b):
        sum += i+1
print(sum)


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

string s;
char y[20];
int x[20];

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		y[i] = s[i];
		x[i] = ctoi(y[i]);
	}
	int min = 99999999;
	for (int i = 0; i <= s.size() - 3; i++) {
		int temp = x[i] * 100 + x[i + 1] * 10 + x[i + 2];
		temp = abs(temp - 753);
		if (min > temp)min = temp;
	}
	cout << min << endl;
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int a = s[0]*10+s[1] - '0'*10 - '0';
    int b = s[2]*10+s[3] - '0'*10 - '0';

    if (a > 12 || a == 0) {
        if (b > 12 || b == 0) {
            cout << "NA" << endl;
        } else {
            cout << "YYMM" << endl;
        }
    } else {
        if (b > 12 || b == 0) {
            cout << "MMYY" << endl;
        } else {
            cout << "AMBIGUOUS" << endl;
        }
    }
    return 0;
}

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

signed main(){
	int K,N; cin>>K>>N;
	vector<int> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	vector<int> dist(N);
	for(int i=1;i<N;i++)dist[i]=A[i]-A[i-1];
	dist[0]=K-(A[N-1]-A[0]);
	sort(dist.begin(),dist.end());
	reverse(dist.begin(),dist.end());
	cout<<K-dist[0]<<endl;
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {

    private static class SP {
        int id;
        String S;
        int P;

        SP(int id, String S, int P) {
            this.id = id;
            this.S = S;
            this.P = P;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<SP> SPs = new ArrayList<>();
        for (int n = 0; n < N; n += 1) {
            String S = sc.next();
            int P = sc.nextInt();
            SPs.add(new SP(n + 1, S, P));
        }

        SPs.sort((SP1, SP2) -> {
           int dictOrder = SP1.S.compareTo(SP2.S);
           if (dictOrder != 0) {
               return dictOrder;
           } else {
               return Integer.compare(SP2.P, SP1.P);
           }
        });

        for (SP sp : SPs) {
            System.out.println(sp.id);
        }
    }

}


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

int main() {
    string S;  cin >> S;
    int ans = 0;
    int l = 0, r = S.size() - 1;
    while(l < r) {
        if(S[l] == S[r]) {
            ++l, --r;
        } else if(S[l] == 'x') {
            ++l, ++ans;
        } else if(S[r] == 'x') {
            --r, ++ans;
        } else {
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <set>
using namespace std;
int main(void){
    string s, t;
    cin >>s>>t;
    int ans = 0;
    for(int i=0; i<3; i++){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

int main()
{
	vector<int> v(3);
	REP(i,3)cin >> v[i];
	sort(ALL(v));
	int k;cin >> k;
	REP(i,k)v[2] *= 2;
	ll sum = 0;
	REP(i,3)sum += v[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
hs = gets.split.map &:to_i

is_ok = true

diffs = []

(0 .. hs.size - 2).each{ |i|
	diffs << hs[i] - hs[i+1]
}

is_sub = false

diffs.each{ |diff|
#	puts diff, is_sub
	if diff > 1 || (diff == 1 && is_sub) then
		is_ok = false
		break
	elsif diff == 1 then
		is_sub = true
	elsif diff < 0
		is_sub = false
	end
}

if is_ok then
	puts 'Yes'
else
	puts 'No'
end


Measured memory_bytes: 9476
#include"bits/stdc++.h"

#define rep(i, N) for(int i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



class mint {
public:
	ll value;
	mint(ll n) :value((n%mod+mod)%mod) {}
	mint() :value(0) {}

	mint pow(ll n) {
		if (n == 1)return *this;

		mint res = mint(value * value).pow(n / 2);
		if (n % 2 == 1)res.value *= value;
		return res;
	}
	mint inv() { return pow(mod - 2); }

	mint operator-() { return mint(-value); }
	mint operator+(mint other) { return mint(value + other.value); }
	mint operator-(mint other) { return *this - other; }
	mint operator*(mint other) { return mint(value * other.value); }
	mint operator/(mint other) { return (*this) * other.inv(); }
	mint operator+=(mint other) {
		*this = *this + other;
		return *this;
	}
	mint operator-=(mint other) {
		*this = *this - other;
		return *this;
	}
	mint operator*=(mint other) {
		*this = *this * other;
		return *this;
	}
	mint operator/=(mint other) {
		*this = *this / other;
		return *this;
	}
};

ll sum(ll from, ll to) {
	return (from + to) * (to - from + 1) / 2;
}

int main(void) {
	int N, K; cin >> N >> K;
	
	mint ans=0;

	for (ll i = K; i <= N + 1; i++) {
		ll l = sum(0, i-1), m = sum(N + 1 - i, N);
		ans += m - l + 1;
	}

	cout << ans.value << endl;

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main(){
    char x ;
    cin >> x ;
    if(x <= 'Z'){
        cout << 'A' << endl;
    }
    else {
        cout << 'a' << endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100009],b[100009],c[100009];
long long x[100009],y[100009];

int main(){
  long long ans=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n;i++)cin>>c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  for(int i=0;i<n;i++){
    int idx=upper_bound(b,b+n,a[i])-b;
    x[idx]++;
  }
  for(int i=0;i<n;i++){
    int idx=upper_bound(c,c+n,b[i])-c;;
    y[i]=n-idx;
  }
  for(int i=0;i<n-1;i++){
    x[i+1]+=x[i];
  }
  for(int i=0;i<n;i++){
    ans+=x[i]*y[i];
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  ll K,L=0,T=0,cnt=1;
  string S;
  cin>>S>>K;
  bool CAN=true,TUG=true;
  ll e=0,q=0;
  
  if(S.size()==1){
    cout<<K/2<<endl;
    return 0;
  }
  
  for(int i=0; i<S.size(); ++i){
      if(i==S.size()-1){
        if(CAN){
          e=cnt;
          CAN=false;
        }
        q=cnt;
        L+=cnt/2;
        cnt=1;
      }
    
      else if(S.at(i)!=S.at(i+1)){
        if(CAN){
          e=cnt;
          CAN=false;
        }
        TUG=false;
        L+=cnt/2;
        cnt=1;
      }
      else if(S.at(i)==S.at(i+1)){
        cnt++;
      }
  }
  
  if(S.at(0)==S.at(S.size()-1)){
    if(e%2==1 && q%2==1) T++;
  }
  
  if(TUG){
    cout<<(S.size()*K)/2<<endl;
    return 0;
  }
  
  cout<<L*K+T*(K-1)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=3005;
const ll mod=1e9+7,inv2=5e8+4;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,m,a[N],b[N],f[N*2];
int main()
{
	n=read(); m=read();
	clr(f, 0); f[0]=0;
	
	for(int i=1; i<=n; i++){
		a[i]=read(); b[i]=read();
	}
	
	for(int i=1; i<=n; i++)
	  for(int j=i+1; j<=n; j++)
	    if(a[i]>a[j]) swap(a[i], a[j]),swap(b[i], b[j]);
	
	for(int i=1; i<=n; i++){
//		a[i]=read(); b[i]=read();
//		if(a[i]>=m) continue;
		for(int j=m-1; j>=0; j--){
			f[j+a[i]]=max(f[j+a[i]], f[j]+b[i]);
		}
	}
//	for(int i=1; i<=n; i++){
////		a[i]=read(); b[i]=read();
//		if(a[i]<m) continue;
//		for(int j=m-1; j>=0; j--){
//			f[j+a[i]]=max(f[j+a[i]], f[j]+b[i]);
//		}
//	}
	int ans=0;
	for(int i=0; i<=6000; i++) ans=max(ans, f[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min({abs(a-b)+abs(b-c),abs(b-a)+abs(a-c),abs(a-c)+abs(c-b)})<<endl;
}


Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def factorial_mod(N, MOD):
    ret = 1
    for n in range(1, N + 1):
        ret *= n
        ret %= MOD
    return ret


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    if abs(N - M) > 1:
        print(0)
        exit()

    if M == N:
        n = factorial_mod(N, MOD)
        m = factorial_mod(M, MOD)
        print((2 * n * m) % MOD)
    else:
        n = factorial_mod(N, MOD)
        m = factorial_mod(M, MOD)
        print((n * m) % MOD)


if __name__ == '__main__':
    main()


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

int main()
{
	long long int a,b,v,w,t;
	cin>>a>>v>>b>>w>>t;
	long long int g=t*(v-w);
	if(g>=abs(b-a))
		cout<<"YES";
	else
		cout<<"NO";
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl b(1e5 + 10, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    b[a]++;
  }
  ll ans = 0;
  rep2(i, 1, 1e5) {
    ll now = b[i - 1] + b[i] + b[i + 1];
    ans = max(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4056
#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            for j in range(k):
                if s[i:i+j+1] not in li:
                    count += 1
                    li.append(s[i:i+j+1])
li.sort()
print(li[k-1])

Measured memory_bytes: 3064
#include <stdio.h>

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void){
  int a;
  int minimam = 10;
  int ans = 0;

  for(int i = 0;i < 5;i++){
    scanf("%d",&a);
    if(a%10 != 0)
      minimam = min(minimam,a%10);
    while(a%10 != 0) a++;
    ans += a;
  }

  printf("%d",ans+minimam-10);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s,d[10];
	cin>>s;
	int i,j,a,b;
	a=s.size();
	int c[a-2];
	for(i=0;i<a-2;i++)
	{
		for(j=i;j<i+3;j++)
		{
			d[i]=d[i]+s[j];
		}
		c[i]=abs(753-stoi(d[i]));
	}
	sort(c,c+(a-2));
	cout<<c[0]<<endl;
	
}

Measured memory_bytes: 3600