akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;



void solve(){

  ll x=0,y=0,c=0,ans=0;
  ll n,m,k;
  cin>>n >> k;
  x = n;
  n%=k;
  x = min({x,n,abs(n-k)});
  c(x);

}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //int T;cin >> T;while (T--)
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

using namespace std;

struct TRAMP{
	char mark;
	int number;
};

int main(){
	int n,min;
	char buf[3];
	scanf("%d",&n);

	TRAMP selectArray[n],bubbleArray[n];

	for(int i = 0; i < n; i++){
		scanf("%s",buf);
		selectArray[i].mark = buf[0];
		selectArray[i].number = buf[1] - '0';
		bubbleArray[i] = selectArray[i];
	}

	for(int i = n-1; i >= 0; i--){
		for(int j = 0; j < i; j++){
			if(bubbleArray[j].number > bubbleArray[j+1].number) swap(bubbleArray[j], bubbleArray[j+1]);
		}
	}

	for(int i = 0; i < n-1; i++){
		min = i;
		for(int j = i+1; j < n; j++){
			if(selectArray[j].number < selectArray[min].number){
				min = j;
			}
		}
		if(i != min){
			swap(selectArray[i],selectArray[min]);
		}
	}

	for(int i = 0; i < n-1; i++) printf("%c%d ",bubbleArray[i].mark,bubbleArray[i].number);
	printf("%c%d\n",bubbleArray[n-1].mark,bubbleArray[n-1].number);
	printf("Stable\n");
	for(int i = 0; i < n-1; i++) printf("%c%d ",selectArray[i].mark,selectArray[i].number);
	printf("%c%d\n",selectArray[n-1].mark,selectArray[n-1].number);

	int p;
	for(p=0; p < n; p++){
		if(selectArray[p].number != bubbleArray[p].number || selectArray[p].mark != bubbleArray[p].mark)
			break;
	}
	if(p == n){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}

	return 0;
}



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

int tonum(char *s) {
	int ret = 0;
	for (int i = 0; i < 8; i++)
		ret = ret*10 + s[i] - '0';
	return ret;
}

int main() {
	int n; cin >> n;
	char s[9];
	for (int i = 0; i < n; i++) {
		cin >> s;
		sort(s, s+8);
		int a = tonum(s);
		sort(s, s+8, greater<char>());
		int b = tonum(s);
		cout << (b-a) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int check(string str)
{
    // Compute sum of digits
    int n = str.length();
    int digitSum = 0;
    for (int i=0; i<n; i++)
        digitSum += (str[i]-'0');

    // Check if sum of digits is divisible by 9.
    return (digitSum % 9 == 0);
}

// Driver code
int main()
{
    string str;
    cin >> str;
    check(str)?  cout << "Yes" : cout << "No ";
    return 0;
}


Measured memory_bytes: 3920
// 2019/07/11
// AtCoder Beginner Contest 078 - B

#include <bits/stdc++.h>
using namespace std;

int main() {
    int x, y, z, wkw, ans;
    cin >> x >> y >> z;
    wkw = y + z * 2;
    ans = 1;
    while(wkw < x){
        wkw = wkw + y + z;
        ans = ans + 1;
    }
    if(wkw != x){
        ans = ans - 1;
    }
    cout << ans;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();
		int q = sc.nextInt();
		C c = new C();
		// Pair[] ps = { new Pair(3, 2), new Pair(1, 41), new Pair(3, 4) };
		// Arrays.sort(ps, c);
		// System.out.println(Arrays.toString(ps));
		Queue<Pair> queue = new PriorityQueue<Pair>(1000 * 1000, c);
		Map<Integer, Pair> map = new HashMap<Integer, Pair>();
		for (int i = 0; i < q; i++) {
			int a = sc.nextInt();
			int v = sc.nextInt();
			if (!map.containsKey(a)) {
				Pair p = new Pair(a, v);
				map.put(a, p);
				queue.add(p);
			} else {
				Pair p = map.get(a);
				queue.remove(p);
				p.b += v;
				queue.add(p);
			}
			// System.out.println(queue);
			Pair pp = queue.peek();
			System.out.println(pp.a + " " + pp.b);
		}

	}

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().run();

	}

}

class C implements Comparator<Pair> {

	@Override
	public int compare(Pair o1, Pair o2) {
		// TODO 自動生成されたメソッド・スタブ
		if (o1.b == o2.b) {
			return o1.a - o2.a;
		}
		return o2.b - o1.b;
	}

}

class Pair {
	public int a;
	public int b;

	Pair(int a, int b) {
		this.a = a;
		this.b = b;
	}

	public String toString() {
		return a + " " + b;
	}
}

Measured memory_bytes: 109512
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
 
int main() {
	int N, k, max=0;
	string S, a, b, c;
	cin >> N >> S;
	for(int i=1;i<N-1;i++){
		a = S.substr(0,i);
		b = S.substr(i,N-i);
		sort(a.begin(),a.end());
		a.erase(unique(a.begin(),a.end()),a.end());
		sort(b.begin(),b.end());
		b.erase(unique(b.begin(),b.end()),b.end());
		c = a+b;
		sort(c.begin(),c.end());
		k=0;
		for(int i=0;i<c.length()-1;i++)if(c[i]==c[i+1])k++;
		if(max<k)max=k;
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
A=[[0,0,0],[0,0,255],[0,255,0],[0,255,255],[255,0,0],[255,0,255],[255,255,0],[255,255,255]]
B=['black','blue','lime','aqua','red','fuchsia','yellow','white']
while(l=gets)!="0\n"do puts A.length.times.map{|i|[A[i].zip(l[1..-1].unpack("a2a2a2").map{|e|e.to_i(16)}).map{|e|(e[0]-e[1])**2}.reduce(&:+),B[i]]}.min[1]end

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

using namespace std;

int main()
{
    int n;
    string s;
    cin >> n;
    int ca=0,cw=0,ct=0,cr=0;
    while(n--)
    {
        cin >> s;
        if(s=="AC")
            ca++;
        if(s=="WA")
            cw++;
        if(s=="TLE")
            ct++;
        if(s=="RE")
            cr++;
    }
    cout << "AC x " << ca << "\n" << "WA x " << cw << "\n" << "TLE x " << ct << "\n" << "RE x " << cr << "\n";
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int keta(int n)
{
    int cnt = 0;
    while (n)
    {
        n /= 10;
        cnt++;
    }
    return cnt;
}

int main()
{
    int n;
    cin >> n;
    int ans = 0;

    rep2(i, 1, n + 1)
    {
        int cnt = 0, tmp = i;
        rep2(j, 1, i + 1)
        {
            if (tmp % j == 0 && i % 2 == 1)
            {
                cnt++;
            }
        }
        if (cnt == 8)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

vector<vector<int>> g;
vector<int> c, d;
int cIndex = 1;
int ans;

void dfs(int now, int prev) {
	for (auto v : g[now]) {
		if (v == prev) {
			continue;
		}

		if (cIndex >= c.size()) {
			break;
		}

		d[v] = c[cIndex];
		ans += c[cIndex];
		cIndex++;

		dfs(v, now);
	}
}

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

	int n;
	cin >> n;

	g.resize(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	c.resize(n);
	for (auto &v : c) {
		cin >> v;
	}
	sort(rbegin(c), rend(c));


	int maxIndegree = 0, start = 0;
	for (int i = 0; i < n; i++) {
		if (maxIndegree < g[i].size()) {
			maxIndegree = g[i].size();
			start = i;
		}
	}

	d.resize(n);
	d[0] = c[0];
	dfs(0, -1);
	
	cout << ans << endl;
	for (int i = 0; i < d.size(); i++) {
		if (i) cout << " ";
		cout << d[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1408
n, m = map(int, input().split())
d = {i:[] for i in range(1, n)}
for _ in range(m):
    a, b = map(int, input().split())
    d[a].append(b)
ans = "IMPOSSIBLE"
for dd in d[1]:
    if n in d[dd]:
        ans = "POSSIBLE"
        break
print(ans)

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

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        double[] s = Console.ReadLine().Split().Select(double.Parse).ToArray();
        List<double> h = Console.ReadLine().Split().Select(x => s[0] - double.Parse(x)*0.006).ToList();
        Console.WriteLine(FindClosestIndex(h, s[1]));
    }
    static int FindClosestIndex(List<double> list, double value) {
        double closest = list.Aggregate((x, y) => Math.Abs(x-value) < Math.Abs(y-value) ? x : y);
        return list.IndexOf(closest) + 1;
    }
}

Measured memory_bytes: 13408
unittest
{
	assert( [ "ASSA" ].parse.expand.solve == "Yes" );
	assert( [ "STOP" ].parse.expand.solve == "No" );
	assert( [ "FFEE" ].parse.expand.solve == "Yes" );
	assert( [ "FREE" ].parse.expand.solve == "No" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	s.sort();
	return ( s[ 0 ] == s[ 1 ] && s[ 1 ] != s[ 2 ] && s[ 2 ] == s[ 3 ] ) ? "Yes" : "No";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	void set(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

int main(){

	int W,H;
	scanf("%d %d",&W,&H);

	Info outer,inner;

	outer.set(0,0);
	inner.set(1,0);

	int ans = 0;

	int N;
	scanf("%d",&N);

	int tmp;
	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);

		if(tmp == 0){

			if(outer.row == 0 && outer.col < W-1){
				outer.col++;
			}else if(outer.col == W-1 && outer.row < H-1){
				outer.row++;
			}else{ // outer.row == H-1
				outer.col--;
			}

		}else{

			if(inner.row == 1 && inner.col < W-2){
				inner.col++;
			}else if(inner.col == W-2 && inner.row < H-2){
				inner.row++;
			}else{ //inner.row == H-2
				inner.col--;
			}
		}

		if(inner.col == outer.col && abs(inner.row-outer.row) == 1){
			ans++;
		}else if(inner.row == outer.row && outer.col == inner.col+1){
			ans++;
		}
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A>>B;
  if(A < B)
    cout<<B+B-1<<endl;
  else if(A > B)
    cout<<A+A-1<<endl;
  else
    cout<<A+B<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int n;
    cin >> n;
    double ans = 0;
    for(int i = 0;i < n;i++){
        double x;
        string s;
        cin >> x >> s;
        if(s == "JPY"){
            ans += x;
        }else{
            ans += x*380000;
        }
    }
    printf("%.8f\n",ans);

    return 0;
}

Measured memory_bytes: 256
#A問題
import collections
N=int(input())
S=str(input())
Slist=list(S)
c = collections.Counter(Slist)
d = c.most_common()
dlen=len(d)
count=1
for i in range(dlen):
    count*=(d[i][1]+1)
count-=1
count%=1000000007
print(count)

Measured memory_bytes: 4340
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define cases int tc;cin>>tc;while(tc--)
#define N 100003
#define M 11
#define inf LLONG_MAX
#define SPEED ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//int mod=1e9+7;
//int mod=998244353;
vector<int> g[M];

signed main()
{
    SPEED

    int n,m;
    cin>>n>>m;
    int i,j,k,s;
    vector<int> p;p.clear();p.resize(m);
    for(i=1;i<=m;++i)
    {
        cin>>k;
        while(k--)
        {
            cin>>s;
            g[s].pb(i);
        }
    }
    for(i=0;i<m;++i)
        cin>>p[i];
    
    vector<int> cnt;
    int ans=0;
    for(i=0;i<(1LL<<n);++i)
    {
        j=i;
        k=1;
        cnt.clear();cnt.resize(m);
        while(j)
        {
            if(j%2)
            {
                for(auto it:g[k])
                    cnt[it-1]^=1;
            }
            
            ++k;
            j>>=1;
        }
        
        ans+=(cnt==p);
    }
    
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
#define int long long
#define double long double
#define fst first
#define snd second
#define fr(s,n,i) for(int i=s;i<n;i++)
#define times(n) for(int i=0;i<n;i++)
#define fr_(s,n,i) for(int i=s;i>=n;i--)
#define srt(v) sort(v.begin(), v.end());
#define upr(v, aim, ind) int ind; ind=(int)distance(v.begin(), upper_bound(v.begin(),v.end(), aim))
#define sz(v) (int)v.size()
#define ers(v, i) v.erase(v.begin() + i)
#define last(v) v[sz(v) - 1]
#define swp(v, i, j) int buf = v[j]; v[j] = v[i]; v[i] = buf
#define shout(a) cout << a << endl
#define dshout(a) printf("%.16Lf\n", a)
#define pr pair<int, int>
#define vi vector<int>
#define vp vector<pair<int, int>>
#define vd vector<double>
#define vdd vector<vd>
#define mx(a, b) a = max(a, b)
#define mn(a, b) a = min(a, b)
#define mulM(a,b,c) a = a * b % c
#define squM(a,b) a = a * a % b
#define mpr(a,b) make_pair(a,b)
#define iinp(a) int a; cin >> a
#define sinp(a) string a; cin >> a
#define dinp(a) double a; cin >> a
#define ios() ios_base::sync_with_stdio(0);cin.tie(0)

int MOD = 1000000007;
int INF = ~(1LL << 63);

int powM(int base, int exp){
    int ret = 1;
    int buf = base;
    while(exp > 0){
        if(exp & 1){
            ret *= buf;
        }
        squM(buf, MOD);
        exp >>= 1;
    }
    return ret;
}
int combM(int a, int b){
    if(b == 0){
        return 1;
    }
    if(a-b < b){
        return combM(a, a-b);
    }
    int ans = 1;
    fr(1,b+1,i){
        ans *= a + 1 - i;
        ans /= i;
    }
    return ans;
}
void solve();
signed main() {
    ios();
    solve();
    return 0;
}

int calc(int num, int l, int r){
    if(r < 0){
        return calc(num, abs(r), abs(l));
    }
    if(l > 0){
        return (r+l)*num/2;
    }
    return calc(abs(l), 1, l) + calc(r, 1, r);
}

struct Task{
    int place, time;
    bool operator>(const Task & an) const{
        return time > an.time;
    }
};






void solve(){
    iinp(H);iinp(W);
    int h,w;
    cin >> h >> w;

    shout(H * W - h * W - w * H + h * w);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int N,i;
    scanf("%d", &N);
    if(N < 0 && N > 100){
      return 0;
    }
    int A[N];
    for(i=0;i<N;i++){
      scanf("%d", &A[i]);
      if(A[i] < 0 && A[i] > 1000){
        return 0;
      }
      if((A[i]%2) == 0){
        if((A[i]%3) != 0 && (A[i]%5 != 0)){
          printf("DENIED");
          return 0;
        }
      }
    }
    for(i=0;i<N;i++){
    }
    printf("APPROVED");
    return 0;
    //printf("\n");
}


Measured memory_bytes: 1676
/* 
   AOJ 2253
   Brave Force Story
   2015/9/22
*/

#include<stdio.h>
#include<limits.h>
#define OBJ_MAX 300
#define TURN_MAX 30
#define COO_MAX 5000
#define DIR 6

struct coordinates
{
  int x, y;
};

struct visited
{
  int x, y, rest_turn;
};

int dir[DIR][2] = {{1, 0}, {0, -1}, {-1, -1}, {-1, 0}, {0, 1}, {1, 1}};
struct visited visited_table[COO_MAX];
int cnt = 0;


int can_go(int x, int y, int obj_n, int turn, struct coordinates* coordinates_table)
{
  int i;
  for(i = 0; i < obj_n; i++)
    {
      if(x == coordinates_table[i].x && y == coordinates_table[i].y)
	{
	  return 0;
	}
    }
  for(i = 0; i < cnt; i++)
    {
      if(visited_table[i].x == x && visited_table[i].y == y)
  	{
	  if(visited_table[i].rest_turn >= turn)
	    {
	      return 0;	      
	    }
	  else
	    {
	      visited_table[i].rest_turn = turn;
	      return 1;
	    }
  	}

    }
  visited_table[cnt].x = x;
  visited_table[cnt].y = y;
  visited_table[cnt].rest_turn = turn;
  cnt++;
  return 1;
}

void dfs_cnt(int x, int y, int turn_n, int obj_n, struct coordinates* coordinates_table)
{
  int i, next_x, next_y;

  coordinates_table[obj_n].x = x;
  coordinates_table[obj_n].y = y;
  obj_n++;

  if(turn_n <= 0)
    {
      return ;
    }
  for(i = 0; i < DIR; i++)
    {
      next_x = x + dir[i][0];
      next_y = y + dir[i][1];

      if(can_go(next_x, next_y, obj_n, turn_n, coordinates_table))
	{
	  dfs_cnt(next_x, next_y, turn_n - 1, obj_n, coordinates_table);
	}
    }
}

int main(void)
{
  int i, start_x, start_y, turn_n, obj_n;
  struct coordinates coordinates_table[COO_MAX];

  while(1)
    {
      cnt = 0;
      scanf("%d %d", &turn_n, &obj_n);
      if(turn_n == 0 && obj_n == 0)
	{
	  break;
	}
      for(i = 0; i < obj_n; i++)
	{
	  scanf("%d %d", &coordinates_table[i].x, &coordinates_table[i].y);
	}
      scanf("%d %d", &start_x, &start_y);
      visited_table[cnt].x = start_x;
      visited_table[cnt].y = start_y;
      visited_table[cnt].rest_turn = 0;
      cnt++;
      dfs_cnt(start_x, start_y, turn_n, obj_n, coordinates_table);
      printf("%d\n", cnt);
    }
  return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n;
	cin >> n;
	vector<ll> s(n);
	rep(i, n) cin >> s[i];

	ll ans = 0LL;

	rep(unit, 1, n){
		ll cur = 0LL;
		int from = 0, to = n - 1;
		while(1){
			from += unit;
			to -= unit;
			if(from >= n - 1) break;
			if(to <= unit) break;
			if(to <= from and to % unit == 0) break;
			cur += s[from];
			cur += s[to];
			chmax(ans, cur);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
from collections import*
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
  ans^=i
a=dict(Counter(a))
ak=list(a.keys())
if len(a)==1 and ak[0]!=0:ans=1
elif len(a)==2 and a.get(0)!=n//3:ans=1
elif len(a)==3 and not(a[ak[0]]==a[ak[1]]==a[ak[2]]==n//3):ans=1
elif len(a)>3:ans=1
print(['Yes','No'][ans>0])

Measured memory_bytes: 106872
package main

import (
        "fmt"
)

func solution(n, x, t int) int {
        if n%x == 0 {
                return (n / x) * t
        }
        return (n/x + 1) * t
}

func main() {
        var n, x, t int
        fmt.Scan(&n, &x, &t)
        fmt.Println(solution(n, x, t))
}

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

//rep(i,n) : for(int i=0 ; i < n ; i++) : i=0 ~ n-1
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
//reps(i,n) : for(int i=1 ; i <= n ; i++) : i=1 ~ n
#define reps(i, n) for (int i = 1; i##_len = (n); i <= i##_len; ++i)
//ALL(x) : sort(v.begin(), v.end()); == sort(ALL(v));
#define ALL(x) (x).begin(), (x).end()
//pb
#define pb push_back
//SZ(x)
#define SZ(x) ((int)(x).size)

using namespace std;

//DP用の関数　chminとchmax
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;
}

//INF
const long long INF = 1LL << 60;

const int MAX_N = 110000;

// DP テーブル
long long memo[MAX_N];

//メモ化DPの必要があるらしいのでメモ化再帰する
int rec(int n)
{
    if (n == 0)
        return 0; //終端条件 満たすべき額が0になったら終わり
    if (memo[n] != -1)
        return memo[n]; //すでに探索済みなら終わり
    int res = n;        //金額の残量=1だけで構成したときの枚数=最大枚数

    //1,6^1,6^2,...を試す(n以下)
    //pow6が１回の引きおとし額、1から順に総額n以下で探索
    //あるnのとき残額を最小化する引き落とし額をメモしていく
    for (int pow6 = 1; pow6 <= n; pow6 *= 6)
    {
        res = min(res, rec(n - pow6) + 1);//ここでrec使用
    }
    //ここで言っているのは6^x+yと1+yは等価であるということ
    //いまのnに対してn-pow6を再帰recに渡し、各ループでのn-pow6に対する最小resを返す

    //1,9^1,9^2,...
    //6系列で探索したresが残っているので９のときさらに小さくできるか調べている
    for(int pow9=1; pow9<=n;pow9*=9)
    {
        res=min(res,rec(n-pow9)+1);//ここでrec使用
    }
    //6系列で書いたことと同じことを9についてもやる
    //6,9両方について、現在のnに対する最小引き落とし回数を調べることができた

    //結果のres(枚数)を記録
    //再帰することで標準入力のnより小さい金額についてもメモされていることになる
    return memo[n]=res;
        
}

int main()
{
    int N;
    scanf("%d",&N);
    // DP テーブル全体を初期化 (最小化問題なので INF に初期化)
    rep(i, MAX_N) memo[i] = -1;

    cout << rec(N) << endl;

}


Measured memory_bytes: 4224
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)                
                
    divisors.sort()
    return divisors

def check(n,divisors):
    for i in divisors:
        if n % i == 0:
            k  = n
            while True:
                n = n / i

                if n == 1:
                    return k

                if n % i != 0:
                    return 0
     

n = int(input())
divisors = make_divisors(n)
count = 0

divisors.pop(0)

ds = []

for a in divisors:
    result = check(a,divisors)
    if result != 0:
        ds.append(result)
    
for divisor in ds:
    if n % divisor == 0:
        n = n / divisor
        count += 1

print(count)

Measured memory_bytes: 9512
s = input()
# ans = 0
# DNA = ['A', 'C', 'G', 'T']
# count = 0
# for i in range(len(s)):
#     c = s[i]
#     if c in DNA:
#         count += 1
#     else:
#         ans = max(ans, count)
#         count = 0
#     if i == len(s) - 1:
#         ans = max(ans, count)
# print(ans)

N = len(s)
ans = 0
for i in range(N):
    for j in range(i, N):
        if all(c in ['A', 'G', 'C', 'T'] for c in s[i : j + 1]):
            ans = max(ans, j - i + 1)
print(ans)

Measured memory_bytes: 38256
#include <stdio.h>
int main(void) {
	int i,max=0;
	double v[50];
	for(i=0;i<50;i++){
		int ret=scanf("%lf",&v[i]);
		if(ret==EOF) break;
		if(i>max) max=i;
	}
	int N[50];
	double t[50],t2[50],y[50],n[50];
	for(i=0;i<=max;i++){
		t[i]=v[i]/9.8;
		t2[i]=t[i]*t[i];
		y[i]=4.9*t2[i];
		n[i]=(y[i]+5.0)/5.0;
		N[i]=n[i]+1.0;
		printf("%d\n",N[i]);
	}
	return 0;
}



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

int main(void)
{
    //string a,b;
    //int a,b;
    char a,b;
    int i;
    cin>>a>>b;
    if(a-'0'>b-'0') cout<<">";
    else if(a-'0'<b-'0') cout<<"<";
    else cout<<"=";
    return 0;
}



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

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

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
constexpr int MAX = 2000200;
constexpr double EPS = 1E-11;

using namespace std;

int main() {
	string s; cin >> s;
	
	int N = s.size();
	int count = 0;

	for (int i = 2; i < N; i += 2) {
		int half = (N - i) / 2;
		for (int j = 0; j < half; j++) {
			if (s[j] != s[half + j]) {
				break;
			}
			else if (j == half - 1) {
				cout << half * 2 << endl;
				return 0;
			}
		}
	}
	
	//cout << count << endl;
	//cout << s.substr(2, 5) << endl;


	//if (j == half - 1)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

struct Edge{
  int to,id;
  Edge(int to,int id): to(to),id(id) {}
};
vector<Edge>node[59];
vector<int>r;
ll bits[29];

bool dfs(int now,int last,int g){
  if(now==g){
    return 1;
  }
  rep(i,node[now].size()){
    int next=node[now][i].to;
    int id=node[now][i].id;
    if(next==last)continue;
    if(dfs(next,now,g)){
      r.emplace_back(id);
      return 1;
    }
  }
  return 0;
}

int main(){
  int n,m;
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    node[a].emplace_back(b,i);
    node[b].emplace_back(a,i);
  }
  cin>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    r=vector<int>();
    dfs(a,-1,b);
    rep(j,r.size()){
      bits[i]|=1ll<<r[j];
    }
  }
  ll ans=0;
  rep(i,1<<m){
    ll mask=0;
    rep(j,m){
      if(i>>j&1)mask|=bits[j];
    }
    int bcnt=__builtin_popcountll(mask);
    ll sum=1;
    rep(i,n-1-bcnt){
      sum*=2;
    }
    if(__builtin_popcount(i)%2)sum=-sum;
    ans+=sum;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
h,w,k = map(int,input().split())
c = []
for i in range(h):
  c.append(input())

ans = 0
for i in range(1<<h):
  for j in range(1<<w):
    cnt = 0
    for y in range(h):
      if (i>>y)&1:
        continue
      for x in range(w):
        if (j>>x)&1:
          continue
        if c[y][x] == '#':
          cnt += 1
    if cnt == k:
      ans += 1
print(ans)

Measured memory_bytes: 73632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i=0; i< n; i++)
using namespace std;


int main() {
	int n,a; cin >> n>> a;
	if (500 * n >= a) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
	
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

li cnt[2];

int main() {
    li a, b, k;
    cin >> a >> b >> k;
    li now = min(a, b);
    li cnt = 0;
    while (1) {
        if (a % now == 0 && b % now == 0) {
            cnt++;
            if (cnt == k) {
                cout << now << endl;
                return 0;
            }
        }
        now--;
    }


    return 0;
}

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



signed main() {
 int n;
 cin>>n;
 int x[n],y[n],mx[n][n],my[n][n];

 for(int i=0;i<n;i++){
     cin>>x[i]>>y[i];
 }
 int ans=n,c;
 for(int i=0;i<n;i++){
     for(int j=i+1;j<n;j++){
         mx[i][j]=x[i]-x[j];
         mx[j][i]=-1*mx[i][j];
         my[i][j]=y[i]-y[j];
         my[j][i]=-1*my[i][j];
  
     }
    mx[i][i]=0;
    my[i][i]=0;
 }
 for(int i=0;i<n;i++){
     for(int j=i+1;j<n;j++){
         c=n;
        
           
             for(int i0=0;i0<n;i0++){
             for(int j0=i0+1;j0<n;j0++){
                 if(abs(mx[i][j])==abs(mx[i0][j0])&&abs(my[i][j])==abs(my[i0][j0])&&mx[i][j]*my[i][j]==mx[i0][j0]*my[i0][j0]){
                     c--;
                     
                 }
             }
       
         ans=min(ans,c);
         }
         
         
     }
 }

cout<<ans;
 
   

      return 0;

}


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

long long choose2(long long n){
  return n*(n - 1)/2;
}

int main(){
  int n;
  cin >> n;
  vector<int> A(n),cnt(n);
  for(int i = 0;i < n;i++){
    cin >> A.at(i);
  }
  for(int i = 0;i < n;i++){
    A.at(i)--;
  }
  /**/
  for(int i = 0;i < n;i++){
    cnt.at(A.at(i))++;
  }
  /*全部たす*/
  long long total = 0;
  for(int i = 0;i < n;i++){
    total += choose2(cnt.at(i));
  }
  /*答える*/
  for(int i = 0;i < n;i++){
    long long ans = total;
    ans -= choose2(cnt.at(A.at(i)));
    ans += choose2(cnt.at(A.at(i)) - 1);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4096
n = gets.to_i
a = gets.split.map(&:to_i)
flag = 1
a.each do |an|
  if an % 2 == 0
    if an % 3 != 0 && an % 5 != 0
      flag = 0
      break
    end
  end
end
(flag == 1) ? (puts "APPROVED"):(puts "DENIED")


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

ll gcd(ll a,ll b){
    ll r;
    if(a>b)return gcd(b,a);
    while(r=b%a){
        b=a;
        a=r;
    }
    return a;
}

int main(void) {
    int n;
    cin>>n;
    ll res=1;
    rep(i,n){
        ll tmp;
        cin>>tmp;
        res = res / gcd(res, tmp) *tmp;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,M;
  cin>>N>>M;
  vector<queue<int>> A(N);
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      int a;
      cin>>a;
      A[i].push(a-1);
    }
  }
  int ans=N;
  vector<bool> B(M,true);
  for(int i=0;i<M;i++){
    map<int,int> D;
    for(int j=0;j<N;j++)
      if(!A[j].empty())
        D[A[j].front()]++;
    if(D.size()==0)
      break;
    vector<pair<int,int>> C(0);
    for(pair<int,int> p:D)
      C.push_back({p.second,p.first});
    sort(C.begin(),C.end());
    reverse(C.begin(),C.end());
    for(int i=0;i<C.size() && C[0].first==C[i].first;i++)
      B[C[i].second]=false;
    for(int j=0;j<N;j++)
      while(!A[j].empty() && !B[A[j].front()])
        A[j].pop();
    ans=min(ans,C[0].first);
  }
  cout<<ans<<endl;
}

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

enum{UP,RIGHT,DOWN,LEFT};
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int n;

bool adja(bool data[100][100],int y,int x,int dir){
	int left=(dir+3)%4,right=(dir+1)%4;
	if(  x+dx[left ]>=0 && y+dy[left ]>=0 && x+dx[left ]<n && y+dy[left ]<n && data[y+dy[left ]][x+dx[left ]]==true )return true;
	if(  x+dx[right]>=0 && y+dy[right]>=0 && x+dx[right]<n && y+dy[right]<n && data[y+dy[right]][x+dx[right]]==true )return true;
	return false;
}

int main(){
	int a;
	cin>>a;
	bool f=false;
	rep(i,a){
		if(f)cout<<endl;
		f=true;
		bool data[100][100]={};
		cin>>n;
		
		int dir = UP;
		int y=n-1,x=0;
		
		int change_d_times = 0;
		while(1){
			data[y][x]=true;
			int ddx = x+dx[dir], ddy = y+dy[dir];
			if( ddx>=0 && ddy>=0 && ddx<n && ddy<n && !data[ddy][ddx] && !(ddx+dx[dir]>=0 && ddy+dy[dir]>=0 && ddx+dx[dir]<n && ddy+dy[dir]<n && data[ddy+dy[dir]][ddx+dx[dir]]==true) && !adja(data,ddy,ddx,dir) ){
				data[ddy][ddx]=true;
				change_d_times=0;
				x = ddx , y = ddy;
			}
			else{
				dir = (dir+1)%4;
				change_d_times++;
			}
			if(change_d_times>=5)break;
		}
		rep(i,n){
			rep(j,n){
				if(data[i][j])cout<<"#";
				else cout<<" ";
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    map<string,int> mp;
    mp["SUN"] = 6;
    mp["MON"] = 0;
    mp["TUE"] = 1;
    mp["WED"] = 2;
    mp["THU"] = 3;
    mp["FRI"] = 4;
    mp["SAT"] = 5;

    string s;
    cin >> s;
    if(s == "SUN")
    cout << 7;
    else
    cout << mp["SUN"] - mp[s];
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2 + 2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1], R[n2];

  for ( int i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( int i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i = 0, j = 0;
  for ( int k = left; k < right; k++ ) {
    cnt++;
    if ( L[i] <= R[j] ) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right) {
  if ( left+1 < right ) {
    int mid = (left + right) / 2.0;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main() {
  int A[MAX], n, i;
  cnt = 0;

  cin >> n;
  for ( int i = 0; i < n; i++) cin >> A[i];

  mergeSort(A, n, 0, n);
  
  for ( int i = 0; i < n; i++) {
    if ( i ) cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}


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

int main(){
    vector<int> data;
    int N;
    cin>>N;

    for(int i=0;i<N;i++){
        int W;
        cin>>W;
        if(i==0) data.push_back(W);
        else data.push_back(W+data.at(i-1));
    }

    int sum=data.at(N-1);

    int ans=sum;

    for(int i=0;i<N;i++){
        if(abs(data.at(i)*2-sum)<ans) ans=abs(data.at(i)*2-sum);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int n,m;
  cin>>n>>m;
  vector<long int> h(n),c(n);
  for(int i=0;i<n;i++){
    c.at(i)=1;
    cin>>h.at(i);
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    if(h.at(a-1)>h.at(b-1)) c.at(b-1)=0;
    else if(h.at(a-1)<h.at(b-1)) c.at(a-1)=0;
    else{
      c.at(b-1)=0;
      c.at(a-1)=0;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=c.at(i);
  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define repb(i, n, a) for (int i = (n - 1); i >= (a); i--)
#define all(x) x.begin(), x.end()
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define pb push_back
#define mp make_pair
#define fir first
#define sec second

void change(char &pre, char &now) {
    if (now == '0') {
        pre = '1';
    } else {
        pre = '0';
    }
}

int main() {
    string S;
    cin >> S;
    int len = S.size();
    char now, pre = S[0];
    int ans1 = 0, ans2 = 0;
    rep(i, 1, len) {
        now = S[i];
        if (pre == now) {
            change(pre, now);
            ans1++;
        } else {
            pre = now;
        }
    }
    pre = S[len - 1];
    repb(i, len - 1, 0) {
        now = S[i];
        if (pre == now) {
            change(pre, now);
            ans2++;
        } else {
            pre = now;
        }
    }
    co(min({ans1, ans2}));
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N;cin>>N;
    string s;cin>>s;
    string str1="";
    string str2="";
    int max=0;
    int count;
    set<char>s1,s2;
    for(int i=1;i<N;i++){
        count=0;
        for(int j=0;j<i;j++){
            s1.insert(s.at(j));
        }
        for(int j=i;j<N;j++){
            s2.insert(s.at(j));
        }
        for(auto value:s1){
            if(s2.count(value)){
                count++;
            }
        }
        if(max<=count)max=count;
        s1.clear();
        s2.clear();
        
    }
    cout<<max<<endl;
}

Measured memory_bytes: 3620
// 若 x 为有用的，则比 x 大的都是有用的。可简单证明，想想就懂！
#include <bits/stdc++.h>
#define rep(i, x, y) for (long long i = x; i <= y; i++)
using namespace std;

const int N = 5e3 + 10;
int n, K, a[N], rest, f[N];

int main() {
    cin >> n >> K;
    int flag = 0;
    rep(i, 1, n) {
        cin >> a[i];
        a[i] = min(a[i], K), rest += a[i];
        if (a[i] < K) flag = 1;
    }
    if (!flag) { puts("0"); return 0; }
    sort(a + 1, a + n + 2);
    f[0] = 1;
    for (int i = n + 1; i >= 1; i--) {
        bool ff = 0;
        for (int j = K - 1; j >= max(K - rest, 0); j--)
            if (f[j]) { ff = 1; break; }
        if (!ff) { printf("%d\n", i - 1); break; }
        for (int j = K; j >= a[i]; j--) f[j] |= f[j - a[i]];
        rest -= a[i];
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

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

    int n;cin>>n;
    int h[100005];
    _fi(n) cin>>h[i];

    int dp[100005] = {};
    dp[1] = abs(h[0]-h[1]);
    for(int i = 2;i < n;i++) dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
    cout << dp[n-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

int n,m;

class UnionFind{
private:
    vector<int> par,height,size;
public:
    UnionFind(int n){
        par.resize(n);
        REP(i,n){
            par[i] = i;
        }
        height.resize(n,0);
        size.resize(n,1);
    }
    int root(int x){
        if(par[x]==x){
            return x;
        }else{
            par[x] = root(par[x]);
            return par[x];
        }
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x==y)return;
        if(height[x]<height[y]){
            par[x]=y;
            size[y]+=size[x];
        }else{
            par[y]=x;
            size[x]+=size[y];
            if(height[x]==height[y])height[x]++;
        }
    }
    int cnt(int x){
        x=root(x);
        return size[x];
    }
};

int main(){
    cin >> n >> m;
    vector<int> p(m);
    vector<int> a(m);
    vector<int> b(m);
    
    REP(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<ll> res(m);
    res[m-1]=(ll)n*(n-1)/2;
    
    UnionFind uf(n);
    for(int i=m-1;i>=1;--i){
        int r1 = uf.root(a[i]);
        int r2 = uf.root(b[i]);
        if(r1!=r2){
            res[i-1] = res[i]-(ll)uf.cnt(a[i])*uf.cnt(b[i]);
            uf.unite(a[i],b[i]);
        }else{
            res[i-1] = res[i];
        }
    }
    REP(i,m){
        put(res[i]);
    }
    return 0;
}


Measured memory_bytes: 4480
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int min = 1000000000;
        for (int i = 0; i < s.length() - 2; i++) {
            int tmp = Integer.parseInt(s.substring(i, i + 3));
            int diff = Math.abs(753 - tmp);
            if (diff < min) {
                min = diff;
            }
        }
        System.out.println(min);
    }
}

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


void testcase(){
    int n;
    cin >> n;
    vector<int> input(n);
    for(int i = 0; i < n; i++) cin >> input[i];

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int k = i + 1; k < min(i + 3, n); k++){
            dp[k] = min(dp[k], dp[i] + abs(input[i] - input[k]));
        }
    }
    cout << dp[n - 1];
}

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

#ifdef AKP
    freopen("in.txt","r", stdin);
#endif

    int t = 1;
    //cin >> t;
    while(t--){
        testcase();
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n,qsw[300005],qse[300005],mn=1e9;
char s[300005];
int main()
{
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='E')
		{
			qse[i]=qse[i-1]+1;
			qsw[i]=qsw[i-1];
		}else
		{
			qse[i]=qse[i-1];
			qsw[i]=qsw[i-1]+1;
		}
	}
	mn=min(mn,qsw[n-1]);
	mn=min(mn,qse[n]-qse[1]);
	for(int i=2;i<n;i++)
	{
		mn=min(mn,qsw[i-1]+qse[n]-qse[i]);
	}
	printf("%d\n",mn);
}

Measured memory_bytes: 6440
import sys

K = int(sys.stdin.readline().strip())

exists = set()
v = 7
if v % K == 0:
    print(1)
    sys.exit()
v %= K
for i in range(K):
     v = (v * 10 + 7) % K
     if v == 0:
        print(i+2)
        sys.exit()
     if v in exists:
        print(-1)
        sys.exit()
     exists.add(v)

Measured memory_bytes: 156916
def solve(n, l):
    m = max(l)
    l.remove(m)
    t = sum(l)
    if t > m:
        print("Yes")
    else:
        print("No")

def main():
    n = int(input())
    l = list(map(int, input().split()))
    solve(n, l)        

main()    

Measured memory_bytes: 3060
import java.util.*;

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

    int result ;

    if(a <= b){
      if( a <= b && b <= a + W ){
        result = 0 ;
      }else{
        result = Math.min( Math.abs( b - a ) , Math.abs( b - (a + W) )  );
      }
      System.out.println(result);
    }else{
      if( b <= a && a <= b + W ){
        result = 0 ;
      }else{
        result = Math.min( Math.abs( a - b ) , Math.abs( a - (b + W) )  );
      }
      System.out.println(result);
    }
  }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n, A, a[100000];
	cin >> n;
	int i;
	for (i = 0; i < n; i++) {
		cin >> A; a[i] = A;
	}
	sort(a, a + n); int ma = -1; int check;
	for (i = 0; i < n; i++) {
		int t = min(a[i], a[n - 1] - a[i]);
		if (t > ma) {
			ma = t;
			check = a[i];
		}
	}
	cout << a[n-1] << " "<<check << endl;
	return 0;
}


Measured memory_bytes: 640
import numpy as np
import sys
read = sys.stdin.read
n, m = map(int, input().split())
xyz = np.array(read().split(), dtype=np.int64).reshape(n, 3).T
ans = 0
for i in range(2):
  for j in range(2):
    for k in range(2):
      L = np.array([xyz[0] * (-1)**i, xyz[1] * (-1)**j, xyz[2] * (-1)**k])
      A = L.sum(axis=0).tolist()
      t = sum(sorted(A, reverse=True)[:m])
      ans = max(ans, t)
print(ans)

Measured memory_bytes: 12500
import math
a,b,h,m = map(int, input().split())

ARG = 30 * h + 0.5 * m - 6*m
arg = min(abs(ARG), 360 - abs(ARG))

print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(arg))))

Measured memory_bytes: 9292
import java.util.*;
public class Main {
	public static ArrayList<Integer> list = new ArrayList<Integer>();
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int q = stdIn.nextInt();
		for(int i = 0; i < q; i++) {
			int n = stdIn.nextInt();
			int ans = solv((long)n);
			System.out.println(ans);
		}
	}
	
	public static int solv(Long n) {
		HashMap<Long,Boolean> map = new HashMap<Long,Boolean>();
		Long tmp = n;
		String tmpS = String.valueOf(tmp);
		int count = 0;
		while(true) {
			Long max = 0L;
			if(tmpS.length() == 1) {
				return count;
			}
			for(int i = 1; i < tmpS.length(); i++) {
				String sbt1 = tmpS.substring(0, i);
				String sbt2 = tmpS.substring(i, tmpS.length());
				
				Long sbi1 = Long.parseLong(sbt1);
				Long sbi2 = Long.parseLong(sbt2);
				
				if(sbi1 * sbi2 > max) {
					max = sbi1 * sbi2;
				}
			}
			if(map.containsKey(max)) {
				return -1;
			}
			tmpS = String.valueOf(max);
			count++;
		}
		
	}
}

Measured memory_bytes: 24832