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

using namespace std;

typedef long long ll;

int N, M;
vector<int> dp;
vector<vector<int>> adj;

int longest_path(int v) {
    if (dp[v] == -1) {
        dp[v] = 0;
        for (int w : adj[v])
            dp[v] = max(dp[v], 1 + longest_path(w));
    }
    return dp[v];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M;
    adj.resize(N + 1);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        adj[x].push_back(y);
    }
    dp.assign(N + 1, -1);
    int result = 0;
    for (int v = 1; v <= N; v++)
        result = max(result, longest_path(v));
    cout << result << endl;
}


Measured memory_bytes: 8192
#include<stdio.h>
int main (){
  int A,B;
  scanf("%d %d",&A,&B);
 
  if(A==B)printf("Draw");
  else if(A==1)printf("Alice");
 else if(B==1)printf("Bob"); 
  else if(A>B)printf("Alice");
  else printf("Bob");
  return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    string inf(s.size(), '}');
    string ans = inf;
    for(int i = 0; i + t.size() <= s.size(); i++){
        int f = 1;
        for(int j = 0; j < t.size(); j++){
            if(s[i+j] != '?' && s[i+j] != t[j]) f = 0;
        }
        if(!f) continue;
        string tmp = s;
        for(int j = 0; j < t.size(); j++) tmp[i+j] = t[j];
        for(int j = 0; j < s.size(); j++){
            if(tmp[j] == '?') tmp[j] = 'a';
        }
        ans = min(ans, tmp);
    }
    cout << (ans == inf ? "UNRESTORABLE" : ans) << endl;
    return 0;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())

if A - K >= 0:
  A = A - K
  print(A, B)
else:
  if B - (K - A) >= 0:
    B = B - (K - A)
    A = 0
    print(A, B)
  else:
    A = 0
    B = 0
    print(A, B)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());

    cout << abs(a[0] - a[1]) + abs(a[1] - a[2]) << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int[] sumDays = {-1, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335};
    String[] weeks = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};
    String out = "";
    while (scanner.hasNext()) {
      int month = scanner.nextInt();
      int day = scanner.nextInt();
      if (month == 0) {
        break;
      }
      out += weeks[(sumDays[month] + day) % 7] + "\n";
    }
    System.out.print(out);
  }
}

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

using namespace std;

int mat[110][110];

int main()
{
    //freopen("in.in", "r", stdin);
    int n, w, h;
    cin >> h >> w >> n;
    int ii = 1, jj = 0;
    int dir = 1;
    int a = 0, ind = 0;
    while(1)
    {
        jj += dir;
        if(jj == 0 || jj == w + 1)
        {
            jj -= dir;
            dir = -dir;
            ii++;
            if(ii == h + 1)
                break;
        }
        if(a <= 0)
        {
            ind++;
            cin >> a;
        }
        a--;
        mat[ii][jj] = ind;
    }
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            cout << mat[i][j] << ' ';
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N, M, Q = map(int, input().split())
    a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
        a[i] -= 1
        b[i] -= 1

    ans = 0

    def dfs(seq):
        nonlocal ans
        if len(seq) == N:
            score = 0
            for i in range(Q):
                if seq[b[i]] - seq[a[i]] == c[i]:
                    score += d[i]
            ans = max(ans, score)
            return

        score = 0
        start = seq[-1] if seq else 1
        for n in range(start, M + 1):
            seq.append(n)
            dfs(seq)
            seq.pop()

    dfs([1])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define int long long

signed main(){
	int N; cin >> N;
	bool ok = false;
	if(N%10 == 9) ok = true;
	if(N >= 90) ok = true;
	if(ok) cout <<  "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        int[] num = new int[4];
        for (int i = 0; i < 4; i++) {
            num[i] = s.charAt(i) - '0';
        }
        for (int bit = 0; bit < (1 << 3); bit++) {
            int sum = num[0];
            String ans = "" + num[0];
            for (int j = 0; j < 3; j++) {
                if ((bit & (1 << j)) != 0) {
                    sum += num[j + 1];
                    ans += "+" + num[j + 1];
                } else {
                    sum -= num[j + 1];
                    ans += "-" + num[j + 1];
                }
            }
            if (sum == 7) {
                ans += "=7";
                System.out.println(ans);
                return;
            }
        }
    }
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

const double eps=1e-5;
const LL INF=1e15;

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

    LL sum=0,ans=0,aans=INF;
    bool f=0;
    vector<LL> a(n);
    REP(i,n)
        cin>>a[i];

    REP(j,2)
    {
        f=j==1;
        sum=0;
        ans=0;
        FOR(i,0,n)
        {
            sum+=a[i];
            if(f)
            {
                if(sum>=0)
                {
                    ans+=1+sum;
                    sum=-1;
                }
            }
            else
            {
                if(sum<=0)
                {
                    ans+=1-sum;
                    sum=1;
                }
            }
            f=!f;
        }
        aans=min(aans, ans);
    }
    cout<<aans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define Max(a,b) ((a>b)?a:b)
#define Min(a,b) ((a<b)?a:b)
const int N=101000;
int n,used[N][2];
struct NODE{int d,u;}rec[2][2];
int main(){
	int i,j;
	scanf("%d",&n);
	memset(used,0,sizeof(used));memset(rec,0,sizeof(rec));
	for (i=1;i<=n;++i) {
		int x;scanf("%d",&x);used[x][i%2]++;
		if (used[x][i%2]>rec[i%2][0].d){
			rec[i%2][0].d=used[x][i%2];rec[i%2][0].u=x;
		}else {
			if (used[x][i%2]>rec[i%2][1].d){
				rec[i%2][1].d=used[x][i%2];rec[i%2][1].u=x;
			}
		}
	}
	int ans=0;
	if (rec[0][0].u!=rec[1][0].u) ans=n-(rec[0][0].d+rec[1][0].d);
		else{
			ans=n-Max((rec[0][1].d+rec[1][0].d),rec[0][0].d+rec[1][1].d);
	    }
	//printf("%d %d %d %d\n",rec[0][0].d,rec[0][1].d,rec[1][0].d,rec[1][1].d);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123456
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;

//initialization here
//

//
//initialization finish


// your function is here
//

//
// your function finished

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//

	int a,b,c,d;
	cin >> a>>b>>c>>d;

	Print(min(a,b)+min(c,d));

	//
	// your code finished


	return 0;
}

Measured memory_bytes: 256
xy = list(map(int, input().split()))
x = list(xy[i] for i in range(0, 4, 2))
y = list(xy[i] for i in range(1, 4, 2))
x1 = x[1]-x[0]
y1 = y[1]-y[0]
print(x[1]-y1, y[1]+x1, x[0]-y1, y[0]+x1)



Measured memory_bytes: 9152
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
        A[i] -= i+1;
    }
    sort(all(A));
    if (N % 2 == 1) {
        ll ans = 0;
        ll med = A[(N-1)/2];
        rep(i, N) {
            ans += abs(A[i] - med);
        }
        print(ans);
    } else {
        ll ans1 = 0;
        ll med = A[N/2];
        rep(i, N) {
            ans1 += abs(A[i] - med);
        }
        ll ans2 = 0;
        med = A[N/2-1];
        rep(i, N) {
            ans2 += abs(A[i] - med);
        }
        print(min(ans1, ans2));
    }
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;

  vector<vector<bool>> g(n, vector<bool>(n, true));
  vvi d(n, vi(n, INF));
  REP(i, n) {
    REP(j, n) {
      chmin(d[i][j], i);
      chmin(d[i][j], j);
      chmin(d[i][j], n-1-i);
      chmin(d[i][j], n-1-j);
    }
  }
  ll ans = 0;
  vi dr = {-1, 1, 0, 0};
  vi dc = {0, 0, -1, 1};
  REP(_, n*n) {
    int p; cin >> p;
    p--;
    int r = p / n, c = p % n;
    g[r][c] = false;
    ans += d[r][c];
    int now = INF;
    REP(i, 4) {
      int nr = r + dr[i], nc = c + dc[i];
      if(!(0 <= nr && nr < n && 0 <= nc && nc < n)) {
        now = 0;
        break;
      }
      chmin(now, d[nr][nc] + g[nr][nc]);
    }
    priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> pq;
    pq.push({now, {r, c}});
    d[r][c] = now;
    while(!pq.empty()) {
      pair<int, P> tmp = pq.top(); pq.pop();
      int now = tmp.first;
      int r = tmp.second.first;
      int c = tmp.second.second;
      REP(i, 4) {
        int nr = r + dr[i], nc = c + dc[i];
        if(!(0 <= nr && nr < n && 0 <= nc && nc < n)) continue;
        if(d[nr][nc] > now + g[r][c]) {
          d[nr][nc] = now + g[r][c];
          pq.push({now+g[r][c], {nr, nc}});
        }
      }
    }

    /*
    cout << "D" << endl;
    REP(i, n) {
      cout << d[i] << endl;
    }
    cout << "G" << endl;
    REP(i, n) {
      cout << g[i] << endl;
    }
    cout << endl;
     */
  }
  cout << ans << endl;
}
























Measured memory_bytes: 4484
class Node
  attr_reader :val, :child
  attr_accessor :d, :f
  def initialize(i, child)
    @val = i
    @child = child
    @d = nil
    @f = nil
  end
end

class Graph
  attr_accessor :node
  def initialize(n)
    @node = Array.new(n)
  end
  def depth_first_search(i, t)
    return t if @node[i].d
    @node[i].d = t
    t += 1
    @node[i].child.each{|ch|
      t = depth_first_search(ch-1, t)
    }
    @node[i].f = t
    return t + 1
  end
  def print
    @node.size.times{|i|
      puts "#{@node[i].val} #{@node[i].d} #{@node[i].f}"
    }
  end
end

n = gets.to_i
graph = Graph.new(n)
n.times{
  i, *child = gets.split.map(&:to_i)
  child.shift
  graph.node[i-1] = Node.new(i, child)
}
t = 1
0.upto(n-1){|i|
  t = graph.depth_first_search(i, t)
}
graph.print

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

using namespace std;

int main(){
	string s;
	while(cin >> s, s != "#"){
		vector<string> v;
		vector<pair<int, int> > same;
		for(int i=0; i< s.size(); i++) for(int j=i+1; j < s.size(); j++) if(s[i] == s[j]) same.push_back(make_pair(i, j));
		for(unsigned long long S = 0; S < (1<<s.size()); S++){
			if(s[0] != 'a' && !(S >> s.size()-1 & 1)) continue;
			bool possible = true;
			bool used[26] = {0};
			used[0] = true;
			string t = s;

			for(int j=0; j < s.size(); j++){
				if(S >> j & 1){
					if(t[s.size()-j-1] == 'z'){possible = false; break;}
					t[s.size()-j-1]++;
				}
			}
			if(!possible) continue;
			string p = t;
			for(int j=0; j < t.size(); j++) if(!used[t[j]-'a']){used[t[j]-'a'] = true; t[j]--;}
			if(s == t) v.push_back(p);
		}
		cout << v.size() << endl;
		if(v.size() <= 10){
			for(int i=0; i < v.size(); i++) cout << v[i] << endl;
		}
		else {
			for(int i=0; i < 5; i++) cout << v[i] << endl;
			for(int i=v.size()-5; i < v.size(); i++) cout << v[i] << endl;
		}
	}
}

Measured memory_bytes: 2348
#pragma GCC optimize("Ofast")

#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;

// エラトステネスの篩で素因数分解
// https://qiita.com/DaikiSuyama/items/6462d8b167d6e1eb0cc9
// forループでintを使うとおそらくi*jで死ぬからもう全部int64

constexpr int64_t pn = 1; //prime_number

void sieve(vector<int64_t> &prime_check, int64_t mn){
    int64_t th = sqrt(mn) + 1;
    for(int64_t i=2; i < th; ++i){
        if(prime_check[i]==pn){
            for(int64_t j=i; j<=mn/i; ++j){
                prime_check[j*i]=i;
            }
        }
    }
}

void prime_factorize(const vector<int64_t> &prime_check, vector<int64_t> &prime, int64_t n){
    if(prime_check[n]==pn){
        prime.emplace_back(n);
        return;
    }
    prime.emplace_back(prime_check[n]);
    prime_factorize(prime_check, prime, (int64_t)(n/prime_check[n]));
    return;
}

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

    int64_t n;
    cin >> n;
    vector<int64_t> prime_check(n+1, pn); //0からnまで

    sieve(prime_check, n);

    int64_t count = 0;

    for(int k=1; k <= n; ++k){
        vector<int64_t> prime;
        map<int64_t, int64_t> prime_map;
        prime_factorize(prime_check, prime, k);
        for(auto&& i : prime){
            prime_map[i]++;
        }
        int64_t num_divisors = 1;
        for(auto&& kv : prime_map){
            if(kv.first!=1){
                num_divisors *= kv.second + 1;
            }
        }
        count += k * num_divisors;
    }

    cout << count << "\n";
    return 0;
}

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

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


N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(N):
    if A[i]==1:
        count+=1
a=A[0]
for i in range(1,N):
    a=math.gcd(a,A[i])
if N>=78500+count and a==1:
    print("setwise coprime")
elif N>=78500+count and a>1:
    print("not coprime")
else:
    flag=True
    num_list=[0 for i in range(10000000)]
    for i in range(N):
        if A[i]>1:
            list_=factorization(A[i])
            for b,d in list_:
                if num_list[b]!=0:
                    flag=False
                else:
                    num_list[b]+=1
    if flag==True and a==1:
        print("pairwise coprime")
    elif flag==False and a==1:
        print("setwise coprime")
    else:
        print("not coprime")

Measured memory_bytes: 273276
#include<stdio.h>
#include<math.h>
int main(void)
{
	long long int a,b,x,c=0;
	long long int i;
	scanf("%lld %lld %lld",&a,&b,&x);
	if(a%x==0){
		printf("%lld\n",(b/x)-(a/x)+1);
	}
	else{
		printf("%lld\n",(b/x)-(a/x));
	}
	return 0;
}

Measured memory_bytes: 128
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;

public class Playground
{
    private static int[] item1;
    private static int[] item2;

    public static void Main(string[] args)
    {
        Input();
        Method();
        System.Console.ReadLine();
    }

    private static void Input()
    {
        Console.ReadLine();
        item1 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Console.ReadLine();
        item2 = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    }

    private static void Method()
    {
        int sum = item2.Aggregate(0, (cnt, elem) =>
            cnt + (Array.BinarySearch(item1, elem) >= 0 ? 1: 0)
        );

        System.Console.WriteLine(sum);
    }
}

Measured memory_bytes: 20504
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	s := 0
	for i := 1; i <= n; i++ {
		s += i
		if n <= s {
			d := s - n
			for j := 1; j <= i; j++ {
				if j == d {
					continue
				}
				fmt.Println(j)
			}
			return
		}
	}
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		//Input
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());

		ArrayList<restaurant> list = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			String city = sc.next();
			int score = Integer.parseInt(sc.next());
			restaurant r = new restaurant(i+1, city, score);
			list.add(r);
		}

		sc.close();

		Collections.sort(list, new myComp());

		for(restaurant r : list) {
			System.out.println(r.no);
		}

	}


}

class restaurant {
	int no;
	String city;
	int score;

	restaurant(int no, String city, int score){
		this.no = no;
		this.city = city;
		this.score = score;
	}
}

class myComp implements Comparator<restaurant>{

	@Override
	public int compare(restaurant r1, restaurant r2) {
		if(r1.city.compareTo(r2.city) > 0) {
			return 1;
		}else if(r1.city.compareTo(r2.city) < 0) {
			return -1;
		}else {
			if(r1.score < r2.score) {
				return 1;
			}else {
				return -1;
			}
		}
	}

}


Measured memory_bytes: 22996
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    long long N, ans(0); std::cin >> N;
    for(int i(1); i <= N; ++i){
        long long n(N/i);
        ans += i * n * (n + 1) / 2;
    }
    std::cout << ans << std::endl;
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int len = s.size();
    for(int i=0;i<len-1;i++){
        if(s[i]=='A'&&s[i+1]=='C'){cout << "Yes" << endl;
        return 0;}
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  set<ll> st;
  ll m = n-1;

  if(m != 1) st.insert(m);
  for(ll i = 2; i*i <= m; i++){
    if(m%i) continue;
    st.insert(i);
    st.insert(m/i);
  }

  st.insert(n);
  for(ll i = 2; i*i <= n; i++){
    if(n%i) continue;
    m = n;
    while(m % i == 0) m /= i;
    if(m%i == 1) st.insert(i);

    m = n;
    ll d = n/i;
    while(m % d == 0) m /= d;
    if(m%d == 1) st.insert(d);
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;

int reward(int rank)
{

    switch (rank)
    {
    case 3:
        return 100000;
        break;
    case 2:
        return 200000;
    case 1:
        return 100000 * 3;
        break;
    }
    return 0;
}

int main(int argc, char const *argv[])
{
    int x, y;
    cin >> x >> y;

    int ret = 0;
    if (x == 1 && y == 1)
    {
        ret += 400000;
    }
    ret += reward(x) + reward(y);
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

fun main(args: Array<String>) {
   readLine()!!.toInt()
   var s= readLine()!!.toString()
   var slen = s.length
   var x = slen % 2
   if(x == 0){
   var slen2 = slen / 2
   var ssub = s.substring(0,slen2)
   var lastsub = s.substring(slen2,slen)
   if(ssub == lastsub){
      println("Yes")
   }else{println("No")}
   
   
   
   } else {
      println ("No")
   }





}

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

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
//const ll INF = (1LL << 60);
//const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/

/******** User-defined Function *******/


/**************************************/

/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    int a=0,b=0,c=0,d=0;
    rep(i,n){
      string s; cin >> s;
      if(s=="AC") a++;
      else if(s=="WA") b++;
      else if(s=="TLE") c++;
      else d++;
    }

    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
    
  
    return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 3648
r1, c1, r2, c2 = map(int, input().split())

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**6+2):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

def memo_comb(n, r, mod=MOD):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

def g(r, c):
  res = 0
  for i in range(r+1):
    res += memo_comb(i+c+1, i+1)
    res %= MOD
  
  return res

ans = g(r2, c2) - g(r2, c1-1) - g(r1-1, c2) + g(r1-1, c1-1)
ans %= MOD
print(ans)

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

struct eT
{
	void setd ( int _u, int _v, int _l )
	{
		u = _u, v = _v, last = _l;
	}

	int u, v, last;
}edge[MAXN*2];

int n, m;
int ke, la[MAXN];
int kc, ans[MAXN];
bool vis[MAXN];

void init ();
void input ();
void work ();

void dfs ( int beg );



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d%d", &n, &m );
	int u, v;
	ke = 0;
	INIT ( la, -1 );
	lp ( i, 0, m ){
		scanf ( "%d%d", &u, &v );
		edge[ke].setd ( u, v, la[u] );
		la[u] = ke++;
		edge[ke].setd ( v, u, la[v] );
		la[v] = ke++;
	}
}

void work ()
{
	// main work

	kc = 0;
	dfs ( 1 );
	reverse ( ans+1, ans+kc+1 );
	--kc;
	dfs ( 1 );

	printf ( "%d\n", kc );
	lpi ( i, 1, kc ) printf ( "%d ", ans[i] );
	putchar ( '\n' );
}



void dfs( int beg )
{
	int now = beg;
	bool flag = true;
	while ( flag ){
		flag = false;
		vis[now] = true;
		ans[++kc] = now;
		for ( int i = la[now]; ~i; i = edge[i].last ){
			if ( !vis[edge[i].v] ){
				now = edge[i].v;
				flag = true;
				break;
			}
		}
	}
}

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

using namespace std;

string s, t;

int main(){
	cin >> s >> t;
	int aux[s.size()+1][t.size()+1];

	for(int i=0; i<=s.size(); i++){
		for(int j=0; j<=t.size(); j++){
			if(i==0 || j==0){
				aux[i][j] = 0;
			}
			else if(s[i-1] == t[j-1]){
				aux[i][j] = aux[i-1][j-1] + 1;
			}
			else{
				aux[i][j] = max(aux[i-1][j], aux[i][j-1]);
			}
		}
	}

	string lcs;
	int i=s.size(), j=t.size();
	while(i!=0 && j!=0){
		if(aux[i][j]-1 == aux[i-1][j-1] && aux[i-1][j] == aux[i-1][j-1] && aux[i][j-1] == aux[i-1][j]){
			lcs = s[i-1] + lcs;
			i--; j--;
		}
		else if(aux[i][j] == aux[i-1][j-1] && aux[i-1][j] == aux[i-1][j-1] && aux[i][j-1] == aux[i-1][j]){
			i--; j--;
		}
		else if(aux[i][j]-1 == aux[i-1][j-1] && aux[i][j-1] == aux[i][j]){
			j--;
		}
		else if(aux[i][j]-1 == aux[i-1][j-1] && aux[i-1][j] == aux[i][j]){
			i--;
		}
	}

	cout << lcs << endl;
}

Measured memory_bytes: 35456
n,k = map(int,input().split())
ans = 0
if k % 2 == 1:
    count = n//k
    print(count**3)
else:
    a = (n//k)**3
    count = 0
    for i in range(n//k+1):
        if k*i+k//2 <= n:
            count += 1
    print(count**3+a)

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arr(a,n);
  int tot=f_sum(a);
  if(tot%10!=0){
    prt(tot);
    return 0;
  }
  int ans=0;
  rep(i,n){
    if(a[i]%10!=0){
      chmax(ans, tot-a[i]);
    }
  }
  prt(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n, m; cin >> n >> m;
    priority_queue<int> que;
    rep(i, n) {
        int k; cin >> k;
        que.push(k);
    }

    rep(i, m){
        int k = que.top(); que.pop();
        que.push(k/2);
    }
    ll ans = 0;
    while(!que.empty()){
        ans += que.top(); que.pop();
    }
    pr(ans);
    return 0;}

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

string str;
bool change[30];
vector<string> en;
vector<string> fr;

void solve(){
	int n = str.size();
	int ans = 0;
	fr.clear();
	en.clear();
	string s, tmp;
	rep(i,(1<<n)){
		int I = i;
		s = str;
		memset(change,0,30);
		bool ok = true;
		rep(j,n){
			if(I&1){
				if(s[j] == 'z'){
					ok = false;
					break;
				}
				s[j] += 1;
			}
			I >>= 1;
		}
		if(!ok) continue;
		tmp = s;
		rep(j,n){
			if(change[s[j]-'a'] == false && s[j] != 'a'){
				change[s[j]-'a'] = true;
				s[j]--;
			}
			if(str[j] != s[j]){
				ok = false;
				break;
			}
		}
		if(ok){
			ans++;
			fr.push_back(tmp);
			en.push_back(tmp);
			sort(fr.begin(),fr.end());
			sort(en.begin(),en.end(),greater<string>());
			if(fr.size() > 10){
				fr.pop_back();
				en.pop_back();
			}
		}
	}
	cout << ans << endl;
	if(ans <= 10){
		rep(i,ans){
			cout << fr[i] << endl;
		}
	} else{
		rep(i,5) cout << fr[i] << endl;
		rep(i,5) cout << en[4-i] << endl;
	}
}

int main(){
	while(cin >> str){
		if(str == "#") break;
		solve();
	}
}

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

int main() {
    long long a, b, x;
    cin >> a >> b >> x;

    if ((a % x) != 0) {
        cout << (b/x) - (a/x) << endl;
    } else {
        cout << (b/x) - (a/x) + 1 << endl;
    }

    return 0;
}

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

using namespace std;
using ll =long long;
using db = double;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;

ll ans;
//ここから書き始める
int main()
{
	cout << setprecision(10);
	int n ;
	cin >>n ;
	For(i,1,10){
		For(j,1,10){
			if(i*j==n){
				coY();
				return 0;
			}
		}
	}
	coN();


}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (a, b): (i32, i32) = read();
    if a*b%2 == 0 {
        println!("Even");
    } else {
        println!("Odd");
    }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    string a[n], b[m];
    bool match = false;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    // cout << "in" << endl;
    for (int y = 0; y < n - m + 1; y++) {
        for (int x = 0; x < n - m + 1; x++) {
            bool match_part = true;
            for (int i = 0; i < m; i++) {
                if (a[y + i].substr(x, m) != b[i]) {
                    match_part = false;
                    break;
                }
            }
            if (match_part) match = true;
        }
    }
    if (match) cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;

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

    int w,h,x,y,r;
    bool valid;
    cin >> w >> h >> x >> y >> r;
    valid = true;
    if (x + r > w || x-r < 0 || y+r>h || y-r <0) {
        valid = false;
    }
    if (valid) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e20;

signed main(){
    int N;cin>>N;
    if(N<1200)cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
static const int MAX_N = 200000;
typedef long long int ll;

int N, K; ll L;
int a[MAX_N];

int main(){
	cin >> N >> K >> L;
	for(int i = 0; i < N; i++) cin >> a[i];

	int lb = -1, ub = MAX_N + 1;
	while(ub - lb > 1){
		int mid = (ub + lb) / 2;
		int j = 0;
		int cnt = 0;
		ll sum = 0LL;
		for(int i = 0; i < N; i++){
			for(;j < N && cnt < K; j++){
				if(a[j] <= mid) cnt++;
			}
			if(cnt >= K) sum += N - j + 1;
			if(a[i] <= mid) cnt--;
		}
		if(sum >= L) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
	return 0;
}



Measured memory_bytes: 3856
package main

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

func main() {
	sc = initScanner(os.Stdin)
	a, b, c, k := scanInt(sc), scanInt(sc), scanInt(sc), scanInt(sc)
	fmt.Println(resolve(a, b, c, k))
}

/*
a          b          c             a-b
b+c        c+a        a+b           b-a
2a+b+c     a+2b+c     a+b+2c        a-b
2a+3b+3c   3a+2b+3c   3a+3b+2c      b-a
6a+5b+5c   5a+6b+5c   5a+5b+6c      a-b
*/
func resolve(a, b, c, k int) string {
	ans := 0
	if k%2 == 0 {
		ans = a - b
	} else {
		ans = b - a
	}

	return strconv.Itoa(ans)
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStringSlice(sc *bufio.Scanner, n int) []string {
	ss := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		ss[i] = sc.Text()
	}

	return ss
}


Measured memory_bytes: 1780
S = list(input()) * 2
K = int(input())
Len_S2 = len(S)
Len_S1 = Len_S2 // 2
count1 = 0
count2 = 0
tmp = all(c == S[0] for c in S[:Len_S1:])
for i in range(Len_S2-1):
    if S[i] == S[i+1]:
        if i < Len_S1 - 1:
            count1 += 1
        if i < Len_S2:
            count2 += 1
        S[i+1] = "1"
diff = count2 - count1
if tmp and K >= 3 and Len_S1 % 2 != 0:
    print((count1 + (diff - 1) * (K-1)) + (1 * (K // 2)))
else:
    print(count1 + diff * (K-1))


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long wa=0;
		long[] bxs=new long[N];
		long tmp1=0;
		long tmp2=0;
		long tmp3=0;
		long tmp4=0;
		for(int i=0; i<N; i++) {
			bxs[i]=sc.nextLong();
		}
		Arrays.sort(bxs);
		if(bxs.length%2==1) {
			long genzai1=bxs[bxs.length/2];
			long genzai2=bxs[bxs.length/2];
			tmp1=0;
			tmp2=0;
			for(int i=0; i<bxs.length/2; i++) {
				tmp1+=Math.abs(genzai1-bxs[N-1-i])+Math.abs(bxs[N-1-i]-bxs[i]);
				tmp2+=Math.abs(genzai2-bxs[i])+Math.abs(bxs[i]-bxs[N-1-i]);
				genzai1=bxs[i];
				genzai2=bxs[N-i-1];
			}
			System.out.println(Math.max(tmp1, tmp2));
		}

		else if(bxs.length%2==0) {
			long genzai1=bxs[bxs.length/2];
			long genzai2=bxs[bxs.length/2];
			tmp1=0;
			tmp2=0;
			for(int i=0; i<bxs.length/2-1; i++) {
				tmp1+=Math.abs(genzai1-bxs[N-1-i])+Math.abs(bxs[N-1-i]-bxs[i]);
				tmp2+=Math.abs(genzai2-bxs[i])+Math.abs(bxs[i]-bxs[N-1-i]);
				genzai1=bxs[i];
				genzai2=bxs[N-i-1];
			}
			tmp1+=Math.abs(genzai1-bxs[N/2-1]);
			tmp2+=Math.abs(genzai2-bxs[N/2-1]);


			long genzai3=bxs[bxs.length/2-1];
			long genzai4=bxs[bxs.length/2-1];
			tmp3=0;
			tmp4=0;
			for(int i=0; i<bxs.length/2-1; i++) {
				tmp3+=Math.abs(genzai3-bxs[N-1-i])+Math.abs(bxs[N-1-i]-bxs[i]);
				tmp4+=Math.abs(genzai4-bxs[i])+Math.abs(bxs[i]-bxs[N-1-i]);
				genzai3=bxs[i];
				genzai4=bxs[N-i-1];
			}
			tmp3+=Math.abs(genzai3-bxs[N/2]);
			tmp4+=Math.abs(genzai4-bxs[N/2]);
			System.out.println(Math.max(Math.max(tmp1, tmp2), Math.max(tmp3, tmp4)));
		}
	}
}

Measured memory_bytes: 60524
#include <bits/stdc++.h>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
using boost::algorithm::split;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using boost::multiprecision::cpp_dec_float_50;
#define rep(i, n) for(int i = 0; i < n; ++i)

int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  rep(i, n) cin >> arr[i];
  sort(arr.begin(), arr.end());
  double res = arr[0];
  rep(i, n) res = (res + arr[i]) / 2.0;
  cout << res << endl;
}


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

int main(){
  int64_t n,k;
  cin >>n>>k;
  int64_t ans=0;
  vector<int64_t>a(n+1,0);
  int64_t tmp;
  for(int i=0;i<n;i++){
    cin >>tmp;
    a.at(i+1)=a.at(i)+tmp+1;
  }
  for(int i=k;i<n+1;i++){
    ans=max(ans,a.at(i)-a.at(i-k));
  }
  cout << fixed << setprecision(19)<<(double)(ans)/2<<endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> x(n,0);
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    vector<int> s = x;
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++){
        if(x[i] == s.back()){
            s.pop_back();
            cout << s.back() << endl;
            s.push_back(x[i]);
        }else{
            cout << s.back() << endl;
        }
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 3200
#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 = 1e9;

int main() {
  int a, b, k;
  cin >> a >> b >> k;

  int m = min(a, b);
  int ans = 0;
  int cnt = 0;
  for (int i = m; i >= 1; --i) {
    if (a % i == 0 && b % i == 0) {
      cnt++;
      if (cnt == k) {
        ans = i;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        while(true){
        	int n = sc.nextInt();
        	if(n==0) break;
        	
            String[] s = new String[n];
            int[][] a = new int[n][3];
            for (int i=0;i<n;i++) {
                s[i] = sc.next();
                for (int j=1;j<n;j++) a[i][sc.nextInt()]++;
                a[i][2] = i;
            }
            Arrays.sort(a, new Comparator<int[]>(){
                public int compare(int[] o1, int[] o2) {
                    if (o1[0] == o2[0]) {
                        if (o1[1]==o2[1]){
                        	return o1[2] - o2[2];
                        }else{
                        	return o1[1] - o2[1];
                        }
                    }
                    return o2[0] - o1[0];
                }
            });
            for(int i=0;i<n;i++) System.out.println(s[a[i][2]]);
        }
    }
}

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

using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

int main (){
    int N,M;
    cin >> N >> M;
    M *= 2;
    int x[150];
    cinf(M, x)//道路並べるやつ2Mこ
    int y[150] = {};//なんばんめ何個か並べるやつ
    REP(i, M){
        REPS(j,N)
            if(x[i] == j){
                y[j]++;
            }

    }
  	M /= 2;
    REPS(i,N){
        cout << y[i] << endl;
    }
    return 0;
}

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

int main(){
    double x1,x2,y1,y2,s,dis;
    cin >> x1 >> y1 >> x2 >> y2;
    s=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    dis=sqrt(s);
    printf("%lf\n",dis);
    return 0;
}
 


Measured memory_bytes: 3296