akhauriyash/Code-Regression huggingface dataset:
# coding:utf-8

import sys

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


class WeightedUnionFind:
    __slots__ = ['nodes', 'weight']

    def __init__(self, size: int) -> None:
        self.nodes = [-1] * size  # ノードの値が負の場合ルートを表し、値は木のランクを表す
        self.weight = [0] * size  # ノードx -> ルート(ノードx)への重みを表す

    # 検索
    def find(self, x: int) -> int:
        if self.nodes[x] < 0:
            return x
        else:
            parent = self.find(self.nodes[x])
            self.weight[x] += self.weight[self.nodes[x]]
            self.nodes[x] = parent
            return parent

    # 併合
    def unite(self, x: int, y: int, w: int) -> bool:
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x == root_y:
            return self.diff_weight(x, y, w)
        else:
            rank_x = -self.nodes[root_x]
            rank_y = -self.nodes[root_y]
            if rank_x < rank_y:
                self.nodes[root_x] = root_y
                self.weight[root_x] = w + self.weight[y] - self.weight[x]
            else:
                self.nodes[root_y] = root_x
                self.weight[root_y] = -w + self.weight[x] - self.weight[y]

                if rank_x == rank_y:
                    self.nodes[root_x] += -1

            return True

    # def is_same(self, x: int, y: int) -> bool:
    #     return self.find(x) == self.find(y)

    def diff_weight(self, x: int, y: int, w: int) -> int:
        return self.weight[x] - self.weight[y] == w


n, m = LI()
uf = WeightedUnionFind(n)
for _ in range(m):
    l, r, d = LI()
    l -= 1
    r -= 1
    if not uf.unite(l, r, d):
        print('No')
        exit()
print('Yes')


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

int main(){
    ll N;
    ll A, B;
    cin >> N;
    cin >> A >> B;

    ll C;
    C = A + B;
    ll ans;

    ans = N/C*A;
    ans += min(N%C, A);
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import collections

n = int(input())
lst = list(map(int, input().split()))

even = []
odd = []
for n, i in enumerate(lst):
    if n % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

counter_odd = collections.Counter(odd)
counter_odd = counter_odd.most_common()

counter_even = collections.Counter(even)
counter_even = counter_even.most_common()


if counter_odd[0][0] != counter_even[0][0]:
    print(len(odd) - counter_odd[0][1] + len(even) - counter_even[0][1])
elif len(counter_odd) == len(counter_even) == 1:
    print(len(odd))
elif len(counter_odd) == 1:
    print(len(even) - counter_even[1][1])
elif len(counter_even) == 1:
    print(len(odd) - counter_odd[1][1])
elif counter_odd[1][1] + counter_even[0][1] > counter_even[1][1] + counter_odd[0][1]:
    print(len(odd) - counter_odd[1][1] + len(even) - counter_even[0][1])
else:
    print(len(odd) - counter_odd[0][1] + len(even) - counter_even[1][1])

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

using ll = long long;

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

    ll n,k;
    cin>>n>>k;

    ll l=n%k;

    if(l>k/2)cout<<k-l<<"\n";
    else cout<<l<<"\n";

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    u32 N;
    cin >> N;
    u32 min_value = N;
    u32 sum = 0;
    for (u32 i = 0; i < N; i++) {
        u32 P;
        cin >> P;
        if (P <= min_value) {
            min_value = P;
            sum++;
        }
    }
    cout << sum << endl;

}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split(' ')))

a.sort()

b = set(a)

if len(b) > 3:
	print("No")
	exit()

if len(b) == 1:
	s = a[0]
	if s^s == s:
		print("Yes")
	else:
		print("No")
	exit()
if N % 3 != 0:
	print("No")
	exit()
n = N//3

if len(b) == 2:
	s = a[0]
	t = a[-1]
	if s^s == t and s^t == s:
		if a.count(s) == 2*n and a.count(t) == n:
			print('Yes')
			exit()
		else:
			print('No')
			exit()
	s,t = [t,s]
	if s^s == t and s^t == s:
		if a.count(s) == 2*n and a.count(t) == n:
			print('Yes')
			exit()
		else:
			print('No')
			exit()
	print('No')
	exit()
if len(b) == 3:
	s,t,u = list(b)
	if s^t == u and s^u == t and t^u == s:
		if a.count(s) == n and a.count(t) == n and a.count(u) == n:
			print('Yes')
			exit()
	print('No')
	exit()
print('No')
exit()



Measured memory_bytes: 14228
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i

count = 0
(0..a).each do |a_i|
  (0..b).each do |b_i|
    (0..c).each do |c_i|
      count += 1 if 500 * a_i + 100 * b_i + 50 * c_i == x
    end
  end
end

puts count


Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template<long long mod>
struct mint {
private:
    long long x;
public:
    mint(long long x = 0) :x((mod + x) % mod) {}
    mint(std::string &s) {
        long long z = 0;
        for (int i = 0; i < s.size(); i++) {
            z *= 10;
            z += s[i] - '0';
            z %= mod;
        }
        this->x = z;
    }
    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) {
        long long n = mod - 2;
        mint<mod> u = 1, b = a;
        while (n > 0) {
            if (n & 1) {
                u *= b;
            }
            b *= b;
            n >>= 1;
        }
        return *this *= u;
    }
    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 operator/(const mint &a) const {
        mint res(*this);
        return res /= a;
    }
    friend std::ostream& operator<<(std::ostream &os, const mint &n) {
        return os << n.x;
    }
    bool operator==(const mint &a) const {
        return this->x == a.x;
    }
};

//pow
template<typename T, typename U>
T pow(T k, U n, T unity = 1) {
    while (n > 0) {
        if (n & 1) {
            unity *= k;
        }
        k *= k;
        n >>= 1;
    }
    return unity;
}

int main() {
    int n, k; cin >> n >> k;
    constexpr int MOD = 1e9 + 7;
    mint<MOD> ans = 0;
    vector<mint<MOD>> cnt(k + 1);
    cnt[k] = 1;
    for (int i = k - 1; i >= 1; i--) {
        cnt[i] += pow(mint<MOD>(k / i), n);
        for (int j = i + i; j <= k; j += i) {
            cnt[i] -= cnt[j];
        }
    }
    for (int i = 0; i < k; i++) {
        ans += cnt[i + 1] * (i + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4052
function Main(s) {
  var s = s.split("\n")[0].split(" ").map(e => e*1);
  var backet = new Array(s[1]).fill(0);
  var check = s[0] % s[1], a = s[0];
  backet[check] = 1;
  while(backet[check] < 2) {
    s[0] += a;
    check = s[0] % s[1];
    backet[check]++;
  }
  console.log(backet[s[2]] >= 1 ? "YES":"NO");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>

using namespace std;

typedef long long ll;

const ll prime = 10000000000 + 7;

/*
vector<int> z_algorithm(const string& s) {
	vector<int> prefix(s.size());
	for (int i = 1, j = 0; i < s.size(); i++)
	{
		if (i + prefix[i - j] < j + prefix[j]) {
			prefix[i] = prefix[i - j];
		}
	}
}
*/

struct UnionFind {
	vector<ll> par;
	vector<ll> rank;

	UnionFind(ll n) {
		par = vector<ll>(n);
		rank = vector<ll>(n);
		for (ll i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}

	ll root(ll x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return root(par[x]);
		}
	}

	bool is_same(ll x, ll y) {
		return (root(x) == root(y));
	}

	void connect(ll x, ll y) {
		if (!is_same(x, y)) {
			ll x1, y1;
			x1 = root(x);
			y1 = root(y);
			if (rank[x1] < rank[y1]) {
				par[x1] = y1;
			}
			else if (rank[x1] > rank[y1]) {
				par[y1] = x1;
			}
			else {
				par[x1] = y1;
				rank[y1]++;
			}
		}
	}
};

int main() {

	ll n;
	cin >> n;
	bool yes = false;

	for (ll i = 1; i < 10; i++)
	{
		for (ll j = 1; j < 10; j++)
		{
			if (i * j == n) {
				yes = true;
				break;
			}
		}
	}

	if (yes) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int ans = 1;
  for(int i=1; i<n; i++) if(s[i]!=s[i-1]) ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3712
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val first = List.fill(n)(sc.nextInt).toVector
  val second = List.fill(n)(sc.nextInt).toVector
  
  println((1 to n).toSeq.map(e => (first.take(e) ++ second.drop(e - 1)).sum).max)
}

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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

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

int main() {
  cout << setprecision(18);
  double R;

  cin >> R;
  cout << R * 6.28318530717958623200 << endl;
}

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

using namespace std;
typedef long long ll;
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair 
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
const ll INF=1000000000000000;

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;}

vector<ll> G[500050];//辺

ll cnt=1;
ll N;
bool visited[500050];
bool calculated[500050];

vector<vector<ll>> g(1005,vector<ll>(1005,0));
ll d[500050];
ll game(ll x,ll y){
	if(x>y) swap(x,y);
	//x<y
	if(g[x][y]!=0) return g[x][y];
	else return g[x][y]=cnt++;
}

ll dfs(ll x){
	if(visited[x]){
		if(!calculated[x]) return -1;
		return d[x];
	}
	visited[x]=true;

	d[x]=0;
	for(auto u:G[x]){
		if(dfs(u)==-1) return -1;
		chmax(d[x],d[u]+1);
	}

	calculated[x]=true;
	return d[x];
}

int main(){
	cin>>N;
	vector<vector<ll>> A(N+1,vector<ll>(N));
	rep1(i,N){
		rep1(j,N-1) cin>>A[i][j];
	}
	vector<ll> dfs_list;
	rep1(i,N){
		if(A[A[i][1]][1]==i){
			d[game(i,A[i][1])]=1;
			dfs_list.pb(game(i,A[i][1]));
		}
	}
	rep1(i,N){
		rep1(j,N-1){
			A[i][j]=game(i,A[i][j]);
		}
		rep1(j,N-2){
			G[A[i][j+1]].pb(A[i][j]);//試合に辺を張る
		}
	}
	ll ans=0;
	rep1(i,N){
		ll res=dfs(A[i][N-1]);
		if(res==-1){
			cout<<-1;
			return 0;
		}
		chmax(ans,res+1);
	}
	cout<<ans;
}


Measured memory_bytes: 48384
#include <bits/stdc++.h>
#define INT(name) int name; scanf("%d",&name);
#define VINT(name,n) vector<int> name(n); for(int i = 0;i < n;i++) scanf("%d",&name[i]);
#define ll long long
#define ull unsigned long long

using namespace std;

int minute;
int cube[30];

void flop(int j){
	if(j != 8){
		swap(cube[15],cube[14]);
		swap(cube[0],cube[27]);
		swap(cube[1],cube[28]);
		swap(cube[2],cube[29]);
		swap(cube[18],cube[20]);
		flop(j+1);
		swap(cube[15],cube[14]);
		swap(cube[0],cube[27]);
		swap(cube[1],cube[28]);
		swap(cube[2],cube[29]);
		swap(cube[18],cube[20]);

		swap(cube[17],cube[12]);
		swap(cube[6],cube[21]);
		swap(cube[7],cube[22]);
		swap(cube[8],cube[23]);
		swap(cube[9],cube[11]);
		flop(j+1);
		swap(cube[17],cube[12]);
		swap(cube[6],cube[21]);
		swap(cube[7],cube[22]);
		swap(cube[8],cube[23]);
		swap(cube[9],cube[11]);

		swap(cube[20],cube[9]);
		swap(cube[0],cube[23]);
		swap(cube[3],cube[26]);
		swap(cube[6],cube[29]);
		swap(cube[15],cube[17]);
		flop(j+1);
		swap(cube[20],cube[9]);
		swap(cube[0],cube[23]);
		swap(cube[3],cube[26]);
		swap(cube[6],cube[29]);
		swap(cube[15],cube[17]);

		swap(cube[18],cube[11]);
		swap(cube[2],cube[21]);
		swap(cube[5],cube[24]);
		swap(cube[8],cube[27]);
		swap(cube[12],cube[14]);
		flop(j+1);
		swap(cube[18],cube[11]);
		swap(cube[2],cube[21]);
		swap(cube[5],cube[24]);
		swap(cube[8],cube[27]);
		swap(cube[12],cube[14]);
	}

	int temp = cube[0];
	for(int i = 0;i < 9;i++)
		if(cube[i] != temp) return;

	temp = cube[9];
	for(int i = 9;i < 12;i++)
		if(cube[i] != temp) return;

	temp = cube[12];
	for(int i = 12;i < 15;i++)
		if(cube[i] != temp) return;

	temp = cube[15];
	for(int i = 15;i < 18;i++)
		if(cube[i] != temp) return;

	temp = cube[18];
	for(int i = 18;i < 21;i++)
		if(cube[i] != temp) return;

	temp = cube[21];
	for(int i = 21;i < 30;i++)
		if(cube[i] != temp) return;

	if(minute > j) minute = j;
}

int main(int argc, char const *argv[]){
	INT(repeat)
	for(int r = 0;r < repeat;r++){
		minute = 9;
		for(int i = 0;i < 30;i++)
			scanf("%d",&cube[i]);
		flop(0);
		printf("%d\n",minute);
	}

	return 0;
}

Measured memory_bytes: 1188
#include <iostream>
 
using namespace std;
long long table[200001];
long long accum1[200002];
long long accum2[200002];
int main() {
    int N;
    cin >> N;
    int A[200001];
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N; i++) {
        table[A[i]]++;
    }
 
    {
    long long acc = 0;
    for (int i=1; i<=200000; i++) {
        acc += table[i] * (table[i]-1) / 2;
        accum1[i] = acc;
    }
    }
 
    {
    long long acc = 0;
    for (int i=200000; i>=0; i--) {
        acc += table[i] * (table[i]-1) / 2;
        accum2[i] = acc;
    }
    }
 
    for (int k=0; k<N; k++) {
        int rem = A[k];
        cout << accum1[rem-1] + accum2[rem+1] + (table[rem]-1) * (table[rem]-2) /2 << endl;
    }
    return 0;
}
 

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

#define sz(o) ((int)o.size())
#define all(o) o.begin(), o.end()
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define repr(i, a, b) for(int i = (a); i >= (b); i--)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define EPS 1e-9
#define PI 3.1415926535
#define ff first
#define ss second
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<pi> vpi;


void solve(int testcase) {
    string s;
    cin >> s;
    int n = sz(s);
    if(s[0] != 'A'){
        cout << "WA";
        return;
    }
    int o = 0, j;
    rep(i, 2, n-2){
        o += s[i] == 'C';
        if(s[i] == 'C') j = i;
    }
    if(o != 1){
        cout << "WA";
        return;
    }
    rep(i, 1, n-1){
        if(s[i] >= 'A' and s[i] <= 'Z' and i != j){
            cout << "WA";
            return;
        }
    }
    cout << "AC";
}

int main() {
//    #ifdef VPAL
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(20);
    clock_t b = clock();
    int t = 1;
    //cin >> t;
    rep(tt, 1, t) solve(tt);
    clock_t e = clock();
    cerr << (double(e - b) / CLOCKS_PER_SEC) << " sec";
    return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

n = gets.to_i
a = gets.split.map(&:to_i).sort
dd = Hash.new { false }
t = a.tally

if a[0] == 1
  if t[1] > 1
    puts 0
  else
    puts 1
  end
  exit
end
max = a.last
a.each do |e|
  next if dd[e]

  i = 2
  loop do
    x = i * e
    break if x > max

    dd[x] = true
    i += 1
  end
end
c = 0
a.each do |e|
  c += 1 if !dd[e] && t[e] == 1
end

puts c


Measured memory_bytes: 73608
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,n;
    cin>>k>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int ans = k-a[n-1]+a[0];
    for(int i=0;i<n-1;i++)
    {
        ans = max(ans,a[i+1]-a[i]);
    }
    cout<<k-ans<<"\n";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int x, a;
    cin >> x >> a;
    if(x<a) out(0);
    else out(10);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int y,m,d; 
    char c1,c2;
    cin>>y>>c1>>m>>c2>>d;
    cout<<(m<5? "Heisei":"TBD")<<endl;
}


Measured memory_bytes: 256
x=list(input())
num=[]
s="S"
cnt=len(x)
for i in range(len(x)):
    if x[i]==s:
        cnt=i
        break
cnt2=0
for i in range(cnt,len(x)):
    if x[i]!=s:
        if s=="T":
            s="S"
        else:
            s="T"
        num.append(cnt2)
        cnt2=1
    else:
        cnt2+=1
num.append(cnt2)
ans=0
num3=0
if len(num)%2==1:
    del(num[-1])
for i in range(len(num)//2):
    if num[-2*(i+1)]>=num[-2*i-1]+num3:
        ans+=(num[-2*i-1]+num3)*2
        num3=0
    else:
        ans+=(num[-2*(i+1)])*2
        num3=num[-2*i-1]+num3-num[-2*(i+1)]
print(len(x)-ans)


Measured memory_bytes: 11420
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;


int sum[2][2000][2000];


int getScore(int i, int x, int y, int k) {
    if (x < 0 || y < 0 || x - k + 1 >= 2 * k || y - k + 1 >= 2 * k)
        return 0;

    int x1 = min(x - k, 2 * k - 1);
    int y1 = min(y, 2 * k - 1);

    int x2 = min(x, 2 * k - 1);
    int y2 = min(y - k, 2 * k - 1);

    int x3 = min(x - k, 2 * k - 1);
    int y3 = min(y - k, 2 * k - 1);

    x = min(x, 2 * k - 1);
    y = min(y, 2 * k - 1);

    int score = sum[i][x][y];

    if (x1 >= 0 && y1 >= 0)
        score -= sum[i][x1][y1];

    if (x2 >= 0 && y2 >= 0)
        score -= sum[i][x2][y2];

    if (x3 >= 0 && y3 >= 0)
        score += sum[i][x3][y3];

    return score;
}


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

    REP(i, n) {
        int xi, yi;
        string ci;
        cin >> xi >> yi >> ci;

        if (ci[0] == 'B')
            xi += k;
        if (xi % (2 * k) >= k) {
            xi += k;
            yi += k;
        }

        sum[0][xi % k][yi % (2 * k)]++;
    }

    REP(p, 2) REP(q, 2 * k) REP(r, 2 * k)
        sum[p][q][r] += (q > 0 ? sum[p][q - 1][r] : 0) + (r > 0 ? sum[p][q][r - 1] : 0) - (q > 0 && r > 0 ? sum[p][q - 1][r - 1] : 0);

    int best = 0;

    REP(p, 2 * k) REP(q, 2 * k) {
        int current = 0;

        int index = 0;
        REP(i, 5) REP(j, 5) {
            current += getScore(index, p - 2 * k + k * i, q - 2 * k + k * j, k);
            index ^= 1;
        }

        best = max(best,current);
    }
    
    cout << best << endl;
    
    return 0;
}


Measured memory_bytes: 31488
numbers = [int(s) for s in input().split()] #0:赤, 1:緑, 2:青
K = int(input())
for i in range(K):
    if(numbers[2] <= numbers[0]):
        numbers[2] *= 2
    elif(numbers[1] <= numbers[0]):
        numbers[1] *= 2
    elif(numbers[2] <= numbers[1]):
        numbers[2] *= 2
    else:
        break
if(numbers[1] > numbers[0] and numbers[2] > numbers[1]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
using ll = long long;
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;
}
void factorization(long long n,map<long long ,long long>& mp){
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n /= i;
        }
     }
     if(!(n == 1)) mp[n]++;
}
int main() {
    ll n;
    cin >> n;
    map<ll, ll> mp;
    factorization(n, mp);
    ll cnt = 0;
    for(auto i:mp){
        long long ans=(-1+sqrtl(8*i.second+1))/2;
        cnt += ceil(ans);

    }
    cout << cnt << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007

int main(){
    int h,w;
    cin>>h>>w;
    char map[110][110];
    bool bani[110]={},banj[110]={};
    rep(i,0,h){
        scanf("%s",map[i]);
        bool f=1;
        rep(j,0,w){
            if(map[i][j]=='#'){
                f=0;
                break;
            }
        }
        if(f)bani[i]=1;
    }
    rep(i,0,w){
        bool f=1;
        rep(j,0,h){
            if(map[j][i]=='#'){
                f=0;
                break;
            }
        }
        if(f)banj[i]=1;
    }
    rep(i,0,h){
        if(bani[i])continue;
        rep(j,0,w){
            if(banj[j])continue;
            else cout<<map[i][j];
        }
        puts("");
    }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func sum(n []int) int {
	ans := 0
	for _, v := range n {
		ans += v
	}
	return ans
}

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

func main() {
	var n int
	fmt.Scan(&n)
	w := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&w[i])
	}

	ans := 10000
	for i := 1; i <= n; i++ {
		if abs(sum(w[i:])-sum(w[:i])) < ans {
			ans = abs(sum(w[i:]) - sum(w[:i]))
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define KMAX 202
using namespace std;
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int main(){
  int K,dp[KMAX][KMAX] = {},ans = 0;
  cin >> K;
  for (int i = 1; i <= K; ++i)
  {
    for (int j = 1; j <= K; ++j)
    {
      for (int k = 1; k <= K; ++k)
      {
        ans += gcd(i,gcd(j,k));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
// warm heart, wagging tail,and a smile just for you!
//
//                            ▒█████▒▒
//                             ██████████▒
//                             ▒████████████▒
//                            ██████████████████
//                           ████████████████████▒
//                          ▒██████████████████████▒
//                          ▒███████████████████████
//                      ▒████▒▒▒▒▒▒█████████████████▒
//                    ███▒▒▒▒▒▒██████████████████████▒▒▒
//                  ▒██▒▒███████████████████████▒▒▒▒▒██████
//                 ▒█████████████████████████▒▒▒▒▒▒█████████▒
//                 ▒█████████████████████▒▒▒▒▒▒██████████████
//                  ▒████         ████▒▒▒▒▒████         ████▒
//              ▒█████▒    ████    ▒▒▒▒███████    ████    ██████▒
//            ▒██▒▒▒▒▒    ██████    █████████    ██████    ██▒▒▒██▒
//           █████████   ████████   █████████   ████████   ▒▒▒▒█████
//          ▒█████████    ██████    ████████▒    ██████    █████████
//          ▒██████████    ████    █████▒▒▒▒▒▒    ████    ██████████
//           ████████████        ▒▒▒▒▒▒▒████████        ███████████▒
//       ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒
//     ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒
//   ▒▒▒▒▒▒▒▒▒██████████████                         ███████▒▒▒▒███████████
//   █████████████████████████                     ███████▒▒▒██████████████▒
//   █████████████████████████████             ███████▒▒▒██████████████████▒
//   ██████████████████████████████████████████████████████████████████████
//    ██████████████████████████████████████████████████████████████████▒
//      ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int k,a,b;
  cin >> k >> a >> b;

  if(k<=a) cout << 1 << endl;
  else{
    if(a-b <= 0) cout << -1 << endl;
    else cout << (k-a)/(a-b)*2 + 1 + ((k-a)%(a-b)>0)*2 << endl;
  }

  return 0;
}

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

typedef long long int ll;

int main(){
  ll X,Y;
  cin >> X >> Y;
  if(abs(X) >= abs(Y)){
    if(abs(X) == abs(Y)){
      cout << 1 << endl;
    }else if(X >= 0 && Y >= 0){
     cout << min(X+Y+1,X-Y+2) << endl;
   }else if(X >= 0 && Y < 0){
     cout << Y+X+1 << endl;
   }else if(X < 0 && Y >= 0){
     if(Y == 0){
       cout << abs(X) - Y << endl;
     }else{
     cout << abs(X) - Y + 1<< endl;
     }
   }else if(X < 0 && Y < 0){
     cout << abs(X) - abs(Y) << endl;
   }
  }else{
    if(X >= 0 && Y >= 0){
     cout << Y-X << endl;
   }else if(X >= 0 && Y < 0){
     cout << abs(Y) - X +1<< endl;
   }else if(X < 0 && Y >= 0){
     cout << Y - abs(X) + 1 << endl;
   }else if(X < 0 && Y < 0){
     cout << abs(Y) - abs(X) + 2 << endl;
   }
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int a[52] = {0};
	char b[4] = {'S','H','C','D'};
	int d, n;
	char c;
	int e, f;

	scanf("%d", &n);
	for (f = 0; f < n; f++)
	{
		scanf(" %c %d", &c, &d);
		for (e = 0; b[e] != c; e++)
		{
			d += 13;
		}
		a[d - 1] = 1;
	}

	for (f = 0; f < 4; f++)
	{
		for (e = 0; e < 13; e++) 
		{
			if (a[f * 13 + e] == 0) 
			{
				printf("%c %d\n", b[f], e + 1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1860
readlines.each do |l|
  x1,y1,x2,y2,xq,yq = l.split(",").map(&:to_f)
  if y1==y2
    xr = xq
    yr = yq + (y1-yq)*2
  elsif x1==x2
    xr = xq + (x1-xq)*2
    yr = yq
  else
    a = -(x2-x1)/(y2-y1)
    b = -xq*a + yq
    c = (y2-y1)/(x2-x1)
    d = -x1*c + y1
    x = (d-b)/(a-c)
    xr = xq + (x-xq)*2
    yr = a*xr + b
  end
  puts "#{xr} #{yr}"
end

Measured memory_bytes: 6132
#include<bits/stdc++.h>
#define N (500009)
using namespace std;

int n,ans,f[N],g[N],Next[N];
char s[N];

void Build_Next(char s[],int a[])
{
	int k=0; memset(Next,0,sizeof(Next));
	for (int i=2; i<=n; ++i)
	{
		while (k && s[k+1]!=s[i]) k=Next[k];
		if (s[k+1]==s[i]) k++;
		Next[i]=k;
	}
	for (int i=1; i<=n; ++i) if (!Next[i] || i%(i-Next[i])) a[i]=1;
}

int main()
{
	cin>>s+1; n=strlen(s+1);
	Build_Next(s,f);
	reverse(s+1,s+n+1);
	Build_Next(s,g);
	if (f[n]) {puts("1\n1"); return 0;}
	for (int i=1; i<=n; ++i)
		if (f[i] && g[n-i]) ans++;
	if (!ans) printf("%d\n1\n",n);
	else printf("2\n%d\n",ans);
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std ;
#define pb push_back
#define ll long long
ll n , m , k ;
const ll N= 200007 ;
ll vis[N] , v[N] ;

int main() {

    ll n , k ,i;
    cin >> n >> k ;
    for (i = 0 ; i< n ; i++) {cin >> v[i] ;v[i]-- ; }
    vis[0] =1 ;
    vector<ll>cy ;
     i= 0 ;
    while(1) {
       if (vis[v[i]]==2) break ;
       if (vis[v[i]]==1) cy.pb(v[i]) ;
       if (vis[v[i]]==0) { k-- ; if (k==0) {cout << v[i]+1 << endl ; return 0 ;} }
       vis[v[i]]++ ;
      // cout << v[i] << ' ' ;
       i = v[i] ;
    }
    k-- ;
    k%=cy.size() ;
 //   for (auto it : cy) cout << it << ' ' ;
  //  cout << k << ' ' << cy.size() << endl ;
     cout << cy[k]+1 << endl ;


    return 0 ;
 }


Measured memory_bytes: 8268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[] hate = new boolean[10];
		for(int i=0;i<m;i++) {
			hate[sc.nextInt()] = true;
		}
		LOOP: for(int x=n;;x++) {
			String s = String.valueOf(x);
			for(int i=0;i<s.length();i++) {
				if (hate[s.charAt(i)-'0']) {
					continue LOOP;
				}
			}
			System.out.println(x);
			return;
		}
	}

}


Measured memory_bytes: 14280
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

int main(){
  int A, B; cin >> A >> B;
  A--; B--;

  char ans[100][100];
  for (int i = 0; i < 100; i++){
    for (int j = 0; j < 100; j++){
      if (i < 50) ans[i][j] = '#';
      else ans[i][j] = '.';
    }
  }
  
  int cnt = 0, I = 0, J = 0;

  int di[3] = {-1, 0, 1}, dj[3] = {-1, 0, 1};
  while (cnt < A){
    bool flag = true;

    for (int i = 0; i < 3; i++){
      for (int j = 0; j < 3; j++){
        if (0 <= I + di[i] && I + di[i] < 100 && 0 <= J + dj[j] && J + dj[j] < 100){
          if (ans[I + di[i]][J + dj[j]] == '.'){
            flag = false;
          }
        }
      }
    }
    
    if (flag == true){
      cnt++; ans[I][J] = '.';
    }

    if (J == 99){
      I++; J = 0;
    }else{
      J++;
    }
  }
  
  cnt = 0; I = 51; J = 0;
  while (cnt < B){
    bool flag = true;

    for (int i = 0; i < 3; i++){
      for (int j = 0; j < 3; j++){
        if (0 <= I + di[i] && I + di[i] < 100 && 0 <= J + dj[j] && J + dj[j] < 100){
          if (ans[I + di[i]][J + dj[j]] == '#'){
            flag = false;
          }
        }
      }
    }
    if (flag == true){
      cnt++;
      ans[I][J] = '#';
    }

    if (J == 99){
      I++; J = 0;
    }else{
      J++;
    }
  }
  
  cout << 100 << " " << 100 << endl;
  for (int i = 0; i < 100; i++){
    for (int j = 0; j < 100; j++){
      cout << ans[i][j];
    }
    cout << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 256
// Problem : E - Divisible Substring
// Contest : AtCoder - AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,p;
    string s;
    cin>>n>>p>>s;
    int ans = 0;
    if(p == 2 || p == 5){
        for(int i=0;i<n;i++){
            if((s[i]-'0')%p == 0) ans += i+1;
        }
    } else {
        mi m;
        m[0]++;
        int cur = 0, p10 = 1;
        for(int i=n-1;~i;i--){
            cur = (cur+(s[i]-'0')*p10)%p;
            ans += m[cur];
            m[cur]++;
            p10 = (p10*10)%p;
        }
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4132
# coding: utf-8

days = [
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday",
]

months = [
  31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
]

loop do
  m, d = gets.chomp.split(" ").map{|s| s.to_i}
  break if m == 0

  date = 3
  0..(m - 1).times do |i|
    date += months[i]
  end
  date += d
  puts "#{days[date %= days.length]}"
end

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

string calcAddition( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "0", t = "0";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    for( int i = s.size() - 1; i >= 1; i-- )
    {
        s[i] += t[i] - '0';
        if( s[i] > '9' )
        {
            s[i] -= 10;
            s[i-1]++;
        }
    }
    return s[0] == '0' ? s.substr( 1, s.size() ) : s;
}

string calcSubtraction( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "", t = "";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    if( s < t )
    {
        string temp = s;
        s = t;
        t = temp;
    }

    for( int i = s.size() - 1; i >= 0; i-- )
    {
        if( s[i] < t[i] )
        {
            s[i] += 10;
            if( s[i-1] >= '1' )
                s[i-1]--;
            else
            {
                int j = i - 1;
                while( s[j] == '0' )
                    s[j--] += 9;
                s[j]--;
            }
        }
        s[i] -= ( t[i] - '0' );
    }
    if( s.size() == 1 )
        return s;
    return s[0] == '0' ? s.substr( 1, s.size() ) : s;
}

int main()
{
    string a, b;

    cin >> a >> b;

    int as = a.size(), bs = b.size();
    string s = a.substr( 1, as ), t = b.substr( 1, bs );
    int ss = s.size(), ts = t.size();

    if( a[0] == '-' && b[0] == '-' )
        cout << "-" << calcAddition( s, t ) << endl;
    else if( a[0] >= '0' && b[0] >= '0' )
        cout << calcAddition( a, b ) << endl;
    else if( a[0] == '-' )
    {
        if( ss > bs || ss == bs && s > b )
            cout << "-";
        cout << calcSubtraction( s, b ) << endl;
    }
    else
    {
        if( as < ts || as == ts && a < t )
            cout << "-";
        cout << calcSubtraction( a, t ) << endl;
    }
    return 0;
}




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

using ll = long long;

ll solve(ll A, ll B, ll C)
{
    if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) return 0;
    else return min({A*B, A*C, B*C});
}

int main()
{
    int A, B, C; cin >> A >> B >> C;
    cout << solve(A, B, C) << endl;
}


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


int main()
{
   int n,m;
  cin>>n>>m;
  
  vector<int>s(m);
  char c[m];
  
  rep(i,m)
  {
     cin>>s[i]>>c[i];
  }

for(int x=0;x<1000;x++)
{
   string a = to_string(x);
   if(a.size()!=n) continue;
  
   bool ok = true;
   for(int i=0;i<m;i++)
   {
       if(a[s.at(i)-1] != c[i]) ok = false;
 
   }
  if(ok)
  {  
    cout<<x<<endl;
    return 0;
  }
}

cout<<-1<<endl;
  
  return 0;

}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

struct N {
  ll a, b, c;
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, y, z;
  cin >> x >> y >> z;
  int n = x + y + z;
  vector<N> ns(n);
  for (int i = 0; i < n; i++)
    cin >> ns[i].a >> ns[i].b >> ns[i].c;
  sort(ns.begin(), ns.end(),
       [](const N &l, const N &r) { return l.a - l.b < r.a - r.b; });
  ll lsum = 0, rsum = 0, lssm = 0, rssm = 0;
  multiset<ll> ls, rs, lunused, runused;
  for (int i = 0; i < y; i++) {
    lsum += ns[i].b;
    lunused.insert(ns[i].b - ns[i].c);
  }
  for (int i = y; i < n; i++) {
    rsum += ns[i].a;
    rs.insert(ns[i].c - ns[i].a);
  }
  while (rs.size() > z) {
    runused.insert(-*rs.begin());
    rs.erase(rs.begin());
  }
  for (auto &i : rs) {
    rssm += i;
  }

  ll ans = lsum + rsum + lssm + rssm;

  for (int k = y; k < n - x; k++) {
    lsum += ns[k].b;
    rsum -= ns[k].a;
    if (rs.find(ns[k].c - ns[k].a) != rs.end()) {
      rs.erase(rs.find(ns[k].c - ns[k].a));
      rssm -= ns[k].c - ns[k].a;
    } else {
      rssm -= *rs.begin();
      rs.erase(rs.begin());
    }
    lunused.insert(ns[k].b - ns[k].c);
    lssm += -*lunused.begin();
    ls.insert(-*lunused.begin());
    lunused.erase(lunused.begin());
    ans = max(ans, lsum + rsum + lssm + rssm);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
    string a;
    while (cin >> a) {
        int counter = 0;
        int counter2 = 0;
        int i = 0;
        while (a.find("JOI", i) != string::npos) {
            counter++;
            i = a.find("JOI", i)+1;
        }
        i = 0;
        while (a.find("IOI", i) != string::npos) {
            counter2++;
            i = a.find("IOI", i)+1;
        }
        cout << counter << endl << counter2 << endl;
    }
    return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int par[100001] = {};
vector<int> nodes[100001];
bool visited[100001] = {};

void toposort(int s, vector<int> &order){
    visited[s] = true;
    for(auto to: nodes[s]){
        if(visited[to]) continue; //探索済み -> スキップ
        toposort(to, order);
    }
    //再帰を抜け出すときにorderに追加
    order.push_back(s);
}

int main(void){
    vector<int> order;
    int N, M; cin >> N >> M;
    rep(i, N-1+M){
        int a, b; cin >> a >> b;
        nodes[a].push_back(b);
    }
    for(int i = 1; i <= N; i++){
        if(!visited[i]) toposort(i, order);
    }
    reverse(order.begin(), order.end());
    rep(i, order.size()){
        for(auto to: nodes[order[i]]){
            par[to] = order[i];
        }
    }
    for(int i = 1; i <= N; i++) cout << par[i] << endl;
    return 0;
}

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

int main()
{
    int a , b , c;
    int d, e, f;
    cin >> a >> b >> c;
    if (a > b) {
        int t = a;
        a = b;
        b = t;
    }
    if (c < a) {
        int t = c;
        c = b;
        b = a;
        a = t;
    }
    else if (b < c);
    else {
        int t = c;
        c = b;
        b = t;
    }

    cout << c * 10 + a + b;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int N = Integer.parseInt(br.readLine());
            String strSplit[] = br.readLine().split(" ");
            int Li[] = new int[N];
            int maxNumber = 0;
            int maxNumberIndex = 0;
            for(int i=0; i<N; i++){
                int L = Integer.parseInt(strSplit[i]);
                if(maxNumber < L){
                    maxNumber = L;
                    maxNumberIndex = i;
                }
                Li[i] = L;
            }
            
            int sum = 0;
            for(int i=0; i<N; i++){
                if(i != maxNumberIndex){
                    sum = sum + Li[i];
                }
            }

            if(sum > maxNumber){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 32680
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()) {
			int N = sc.nextInt();
			int[] a = new int[N];
			for(int i = 0; i < N; i++) {
				a[i] = sc.nextInt();
			}
			int ans = 0;
			for(int i = 1; i < N; i++) {
				if(a[i] == a[i - 1]) {
					ans++;
					i++;
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 23764
def main():
    n, m = map(int, input().split())
    p = (m+1)//2
    q = m//2
    l = 0
    r = 2*p-1
    for i in range(p):
        print(l+1, r+1)
        l += 1
        r -= 1
    l = 2*p
    r = l+2*q
    for i in range(q):
        print(l+1, r+1)
        l += 1
        r -= 1


main()

Measured memory_bytes: 70212
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>

#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong n;
    cin >> n;
    vector<llong> dp(n,0);
    vector<llong> h(n,0);
    for(int i=0; i<h.size(); i++){
        cin >> h[i];
    }
    for(int i=1; i<dp.size(); i++){
        if(i==1){
            dp[1] = abs(h[1]-h[0]); 
            continue;
        }
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[dp.size()-1] << endl;
    return 0;
}





Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
int main(){
  char b;
  cin >> b;
  switch(b){
    case 'A':
      b='T';
      break;
    case 'T':
      b='A';
      break;
    case 'G':
      b='C';
      break;
    case 'C':
      b='G';
      break;
  }
  cout << b << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>

#define YJSP 114514

using namespace std;

int N;	//????????°
int K;	//??????????????°
int M;	//???????????°
int S;	//???????????¬??\???
int P;	//?????????
int Q;	//????´????

int zd[100000];	//??????????????????????????¢
long long cost[100000];	//0??????????????????????????????

int AB[200000][2];	//???????????\?¶??????¨???

int main(){
	int i,j;
	int a,b;
	bool change;

	cin>>N>>M>>K>>S;
	cin>>P>>Q;

	//????????¢???????????????
	for(int i=0;i<N;i++){
		zd[i]=YJSP;
		cost[i]=-1;
	}
	cost[0]=0;

	//???????????\???
	for(i=0;i<K;i++){
		cin>>a;a--;
		zd[a]=0;
	}
	//????????\???
	for(i=0;i<M;i++){
		cin>>a>>b;a--;b--;
		AB[i][0]=a;AB[i][1]=b;
	}
	//zd??????
	do{
		change=false;
		for(i=0;i<M;i++){
			for(j=0;j<2;j++){
				//a??????b
				a=AB[i][j];b=AB[i][1-j];
				if(zd[a]+1<zd[b]){
					zd[b]=zd[a]+1;
					change=true;
					break;
				}
			}
		}
	}while(change);

	//???????????¢??????
	do{
		change=false;
		for(i=0;i<M;i++){
			for(j=0;j<2;j++){
				//a??????b
				a=AB[i][j];b=AB[i][1-j];
				if(cost[a]==-1) continue;
				if(zd[b]==0) break;	//??????????????¨?????\?¶??????????
				int yado;	//?????£???
				if(b==N-1){
					yado=0;
				}else{
					yado=(zd[b]<=S)?Q:P;
				}
				if(cost[b]==-1 || cost[a]+yado<cost[b]){
					cost[b]=cost[a]+yado;
					change=true;
					break;
				}
			}
		}
	}while(change);

	cout<<cost[N-1]<<endl;

	return 0;
}

Measured memory_bytes: 5764
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int i,n,m;
vector<int>adj[60];
scanf("%d %d",&n,&m);
while(m--){
    int u,v;
    scanf("%d %d",&u,&v);
    adj[u].push_back(v);
    adj[v].push_back(u);
}
for(i=1;i<=n;++i){
    printf("%d\n",adj[i].size());
}


    return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
struct SAComp{
	const int h,*g;
	SAComp(const int h, const int* g) : h(h), g(g) {}
	bool operator()(const int a, const int b){
		return a == b ? false : g[a] != g[b] ? g[a] < g[b] : g[a+h] < g[b+h];
	}
};
vector<int> buildSA(string &t){
	int n=t.size();
	int g[n],b[n];
	vector<int>suff(n);
	for(int i=0;i<n;i++)suff[i]=i,g[i]=t[i];
	b[0]=b[n-1]=0;
	sort(suff.begin(),suff.end(),SAComp(0,g));
	for(int h=1;b[n-1]!=n-1;h<<=1){
		SAComp comp(h,g);
		sort(suff.begin(),suff.end(),comp);
		for(int i=0;i<n-1;i++)b[i+1]=b[i]+comp(suff[i],suff[i+1]);
		for(int i=0;i<n;i++)g[suff[i]]=b[i];
	}
	return suff;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin>>s;
	s+='$';
	int n=s.size();
	vector<int>suff=buildSA(s);
	vector<pair<char,int>>sorted(n);
	for(int i=0;i<n;i++)sorted[i]={s[(suff[i]-1+n)%n],i};
	sort(sorted.begin(),sorted.end());

	int T;
	//for(cin>>T;T--;){
		string q;
		cin>>q;
		int start=0,stop=n,idx=q.size()-1;
		for(;idx>=0;idx--){
			pair<char,int> ql={q[idx],start},qr={q[idx],stop};
			start=lower_bound(sorted.begin(),sorted.end(),ql)-sorted.begin();
			stop=lower_bound(sorted.begin(),sorted.end(),qr)-sorted.begin();
			if(start==stop)break;
		}
		if(idx<0){
			{vector<int>v;for(;start<stop;start++)v.push_back(suff[start]);sort(v.begin(),v.end());for(auto &e:v)printf("%d\n",e);}
			//puts("1");
		}else{
			//puts("0");
		}
	//}
}

Measured memory_bytes: 28320
N = gets.to_i
W = N.times.map { gets.chomp }

h = {}
last = ''
heswrong = false
W.each do |w|
  if (!last.empty? && w[0] != last) || h.has_key?(w)
    heswrong = true
    break
  end
  last = w[-1]
  h[w] = 1
end

if heswrong
  puts 'No'
else
  puts 'Yes'
end

Measured memory_bytes: 1788
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	var sum int
	for i := 0; i < 2; i++ {
		if a >= b {
			sum += a
			a--
		} else {
			sum += b
			b--
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512