akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<cstring> 
#include<cstdlib>
#include<set>
#include<vector>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
const int inf =9999999;
const double pi =4.0*atan(1.0);
int main()
{     int a,b,h,m;
	cin>>a>>b>>h>>m;
	double minute=(m*1.0/60)*2*pi;
	double hour=h*1.0/12*2*pi+(minute/12);
	printf("%.11lf",sqrt(a*a+b*b-2*a*b*cos(fabs(minute-hour))));

    
	
}
	 
		
	  	
	  
	  


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

bool hoge(long a) {
    long s = 0;
    string c = to_string(a);
    for (int i = 0; i < c.size(); i++) {
        s += c[i] - '0';
    }
    if (a % s == 0) return true;
    return false;
}

int main() {
    long s;
    cin >> s;
    if (hoge(s)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main(){
    long long n;
    cin>>n;
    long long ans=n*(n+1)/2;
    ans-=(n/5)*(n/5+1)/2*5;
    ans-=(n/3)*(n/3+1)/2*3;
    ans+=(n/15)*(n/15+1)/2*15;
    printf("%lld\n",ans);

}



Measured memory_bytes: 3740
open String
let () = Scanf.scanf "%s %s %s\n"
	(fun a b c ->
    let alen = length a in
    let blen = length b in
    let al = a.[alen-1] in
    let bf = b.[0] in
    let bl = b.[blen-1] in
    let cf = c.[0] in
    Printf.printf "%s\n" (if al = bf && bl = cf then "YES" else "NO"))

Measured memory_bytes: 384
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

A1, A2 = A1 * T1, A2 * T2
B1, B2 = B1 * T1, B2 * T2


if A1 + A2 == B1 + B2:
    print('infinity')
    exit()


if A1 + A2 < B1 + B2:
    A1, A2, B1, B2 = B1, B2, A1, A2
D = (A1 + A2) - (B1 + B2)
Remain = B1 - A1

print(max(0, Remain // D * 2 + (Remain % D != 0)))


Measured memory_bytes: 3064
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long e = Long.parseLong(sc.next());
        sc.close();
        long min = Math.min(a, Math.min(b, Math.min(c, Math.min(d, e))));
        long ans = n / min + 4;
        if (n % min != 0) {
            ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
SA = input()
SB = input()
SC = input()

indexA = 0
indexB = 0
indexC = 0
turn = 'A'
winner = ''
while 1:
    if turn == 'A':
        if indexA == len(SA):
            winner = 'A'
            break
        if SA[indexA] == 'a':
            turn = 'A'
        elif SA[indexA] == 'b':
            turn = 'B'
        elif SA[indexA] == 'c':
            turn = 'C'
        indexA += 1
    elif turn == 'B':
        if indexB == len(SB):
            winner = 'B'
            break
        if SB[indexB] == 'a':
            turn = 'A'
        elif SB[indexB] == 'b':
            turn = 'B'
        elif SB[indexB] == 'c':
            turn = 'C'
        indexB += 1
    elif turn == 'C':
        if indexC == len(SC):
            winner = 'C'
            break
        if SC[indexC] == 'a':
            turn = 'A'
        elif SC[indexC] == 'b':
            turn = 'B'
        elif SC[indexC] == 'c':
            turn = 'C'
        indexC += 1
print(winner)

Measured memory_bytes: 9192
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;


int main()
{
    fast;
    ll n , m , tot = 0;
    vector < int > a;
    cin >> n >> m;
    for(int i = 1; i<=n; i++){
        int b; cin >> b; a.push_back(b);
        tot += b;
    }
    double need = (tot*1.0 / (4*m));
    int to = 0;
    for(auto v : a){
        if((double)v >= need){
            to++;
        }
    }
    if(to >= m)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
/*



*/


Measured memory_bytes: 256
INF = 2**30
N, M, X = map(int, input().split())
C = [0] * N
A = []
for i in range(N):
    A.append([])

for i in range(N):
    line = list(map(int, input().split()))
    C[i] = line[0]
    for j in range(M):
        A[i].append(line[j+1])
ans = INF

for bit in range(2**N):
    sum = 0
    skill = [0] * M
    for i in range(N):
        if (bit >> i) & 1:
            sum += C[i]
            for j in range(M):
                skill[j] += A[i][j]
    ok = True
    for j in range(M):
        if skill[j] < X:
            ok = False
    if ok:
        ans = min(ans, sum)
if ans == INF:
    ans = -1
print(ans)


Measured memory_bytes: 68356
#include<stdio.h>
int main(void)
{
	int N,M,A[2001],B[2001],x,sum=0,i,j;
	scanf("%d%d",&N,&M);
	for(i=0;i<M;i++){
		scanf("%d%d",&A[i],&B[i]);
	}
	for(i=0;i<M;i++){
		for(j=i+1;j<M;j++){
			if(A[i]<A[j]){
				x=A[i];
				A[i]=A[j];
				A[j]=x;
			}
		}
	}
	for(i=0;i<M-1;i++){
		if(A[i]<N){
			sum+=N-A[i];
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 2752
#include<cstdio>
#include<cstring>
#include<algorithm>
struct node{
	int x,y,xh;
	bool operator <(const node&a)const{
		return x<a.x;
	}
}a[100010],b[100010];
struct edge{
	int d,d1,dat;
	bool operator <(const edge&a)const{
		return dat<a.dat;
	}
}e[300010];
int n,cnt,f[100010];
long long ans;
inline bool cmp(const node&a,const node&b){return a.y<b.y;}
template<class T>
inline void read(T&a){
	char c=getchar();
	for(a=0;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
}
inline int gf(int x){return f[x]==x?x:f[x]=gf(f[x]);}
int main(){
	read(n);for(int i=1;i<=n;i++)f[i]=i;
	for(int i=1;i<=n;i++)read(a[i].x),read(a[i].y),a[i].xh=i,b[i]=a[i];
	std::sort(a+1,a+1+n);std::sort(b+1,b+1+n,cmp);
	for(int i=1;i<n;i++)e[++cnt]=(edge){a[i].xh,a[i+1].xh,a[i+1].x-a[i].x};
	for(int i=1;i<n;i++)e[++cnt]=(edge){b[i].xh,b[i+1].xh,b[i+1].y-b[i].y};
	std::sort(e+1,e+1+cnt);
	for(int i=1;i<=cnt;i++)
		if(gf(e[i].d)!=gf(e[i].d1)){
			int fx=gf(e[i].d),fy=gf(e[i].d1);
			f[fx]=fy;ans+=e[i].dat;
		}
	printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>
#include <ios>
#include <iomanip>

#define INF 200000000
#define MOD 1000000007

using namespace std;

int main()
{
    string s;
    cin >> s;
    int now = s[0];
    int ans = 0;
    for (int i = 0; i < s.length() - 1; i++)
    {
        if (s[i] == '1' && s[i + 1] == '0')
        {
            continue;
        }
        else if (s[i] == '0' && s[i + 1] == '1')
        {
            continue;
        }
        else
        {
            if (s[i] == '0')
            {
                s[i + 1] = '1';
                ans++;
            }
            else
            {
                s[i + 1] = '0';
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	int width;//?????????????????????
	int height;//????????????????????????
	//????????????????????¨???????????¢??°
	void printData(int crowd[][]){
		for(int i = 0;i <height;i++){
			for(int j = 0;j < width;j++){
				if(j < width-1){
					System.out.print(crowd[j][i]+" ");					
				}else{
					System.out.print(crowd[j][i]);						
				}
			}
			System.out.println();
		}	
	}
	//?????¨??????????????????????¬?????????????????????????????????????
	void calcCrowd(int crowd[][]){
		for(int i = 0;i <height;i++){
			for(int j = 0;j < width;j++){
				for(int k = width-1;k >= 0;k--){
					if(crowd[k][i] == 0 && crowd[j][i] == -1 && k < j){
						crowd[j][i] = j-k;
					}
				}
			}
		}		
	}
	void doIt(){
		Scanner sc = new Scanner(System.in);
		this.height = sc.nextInt();
		this.width = sc.nextInt();
		String c[] = new String[height];
		int crowd[][] = new int[width][height];
		for(int i = 0; i < height;i++){
			c[i] = sc.next();
		}
		for(int i = 0;i <height;i++){
			for(int j = 0;j < width;j++){
				if(c[i].charAt(j) == 'c'){
					crowd[j][i] = 0;
				}else{
					crowd[j][i] = -1;	
				}
			}
		}
		calcCrowd(crowd);
		printData(crowd);
	}
	public static void main(String[] args) {
		new Main().doIt();
	}

}

Measured memory_bytes: 32796
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 300000 + 10;

struct Node {
  int mx, ps;
  void set(int v) {
    mx += v; ps += v;
  }
} T[MAXN << 2];
char s[MAXN];
int a[MAXN], n, q;

#define lson (rt<<1)
#define rson (rt<<1|1)
#define mid ((l+r)>>1)

void build(int rt, int l, int r) {
  T[rt].ps = 0;
  if (l + 1 == r) {
    T[rt].mx = a[l];
    return;
  }
  build(lson, l, mid); build(rson, mid, r);
  T[rt].mx = min(T[lson].mx, T[rson].mx);
}

void psd(int rt) {
  T[lson].set(T[rt].ps);
  T[rson].set(T[rt].ps);
  T[rt].ps = 0;
}

void ins(int rt, int l, int r, int L, int R, int v) {
  if (L <= l && R >= r) {T[rt].set(v); return;}
  psd(rt);
  if (L < mid) ins(lson, l, mid, L, R, v);
  if (R > mid) ins(rson, mid, r, L, R, v);
  T[rt].mx = min(T[lson].mx, T[rson].mx);
}

vector<int> can;
void get(int rt, int l, int r, int L, int R) {
  if (L <= l && R >= r) {
    can.push_back(rt);
    return;
  }
  psd(rt);
  if (L < mid) get(lson, l, mid, L, R);
  if (R > mid) get(rson, mid, r, L, R);
}

int ask(int rt, int l, int r) {
  if (l + 1 == r) {
    if (T[rt].mx >= 2) return l;
    else return r;
  }
  psd(rt);
  if (T[rson].mx >= 2) return ask(lson, l, mid);
  else return ask(rson, mid, r);
}

int main() {
  while (scanf("%d%d", &n, &q) == 2) {
    scanf("%s", s);
    int n = strlen(s);
    set<int> rhs;
    for (int i = 0; i < n; ++ i) {
      if (i) a[i] = a[i - 1];
      else a[i] = 0;
      if (s[i] == '(') a[i] ++;
      else a[i] --;
      if (s[i] == ')') rhs.insert(i);
    }
    build(1, 0, n);
    for (int i = 0; i < q; ++ i) {
      int x; scanf("%d", &x); -- x;
      if (s[x] == '(') {
        s[x] = ')'; rhs.insert(x);
        ins(1, 0, n, x, n, -2);
        x = *rhs.begin(); rhs.erase(x);
        s[x] = '(';
        ins(1, 0, n, x, n, 2);
      }
      else {
        s[x] = '('; rhs.erase(x);
        ins(1, 0, n, x, n, 2);
        can.clear();
        get(1, 0, n, 0, x + 1);
        int rt(-1);
        for (auto &p: can) if (T[p].mx < 2) rt = p;
        if (rt == -1) x = 0;
        else {
          int l(0), r(n);
          vector<int> bit;
          for (int p = rt; p > 1; p >>= 1) {
            bit.push_back(p & 1);
          }
          reverse(bit.begin(), bit.end());
          for (auto &p: bit) {
            if (p) l = (l + r) >> 1;
            else r = (l + r) >> 1;
          }
          x = ask(rt, l, r);
        }
        s[x] = ')'; rhs.insert(x);
        ins(1, 0, n, x, n, -2);
      }
      printf("%d\n", x + 1);
    }
  }
  return 0;
}

Measured memory_bytes: 18408
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,m,h1,m1,k;
	cin>>h>>m>>h1>>m1>>k;
	int a=(h1*60+m1*1)-(h*60+m*1)-k;
	cout<<a;
	return 0;
}

Measured memory_bytes: 3652
a=int(input())
s=input()
d=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E"]
S=list(s)
for i in range(len(S)):
  z=d.index(S[i])
  S[i]=d[z+a]
print("".join(S))



Measured memory_bytes: 3188
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <forward_list>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cstdint>
#include <iomanip>
#include <tuple>
#include <random>

typedef unsigned long long int ull;
typedef long long int ll;

using namespace std;

int main(void) {
    string s;
    cin >> s;
    int ret = 0;
    for(char e:s)if(e == '1')ret++;
    cout << ret << endl;
}



Measured memory_bytes: 256
def monthable? number
  (1..12).include? number
end

s = gets.chomp
former = s.slice(0..1).to_i
latter = s.slice(2..3).to_i

if monthable? former
  if monthable? latter
    puts "AMBIGUOUS"
  else
    puts "MMYY"
  end
else
  if monthable? latter
    puts "YYMM"
  else
    puts "NA"
  end
end

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

typedef long long ll;

int main()
{
    ll A, B, C, K;
    ll a, b, c;
    cin >> A >> B >> C >> K;
    if (abs(A - B) > 1000000000000000000)
    {
        cout << "unfair " << endl;
        return 0;
    }
    if (K % 2 != 0)
    {
        cout << B - A << endl;
    }
    else
    {
        cout << A - B << endl;
    }
}


Measured memory_bytes: 3636
using System;

class train
{
    public static void Main()
    {
        while (true)
        {
            var t = Console.ReadLine();
            if (t == null) break;
            var s = t.Split(',');
            var L = Array.ConvertAll(s, int.Parse);
            int v1 = L[10], v2 = L[11], k1 = 0, k2 = 0, answer = 0;
            double Length;

            for (int i = 0; i <= 9; i++) { k1 += L[i]; }
            Length = v1 * k1 / (double)(v1 + v2);
            k2 = 0;
            for (int i = 0; i <= 9; i++)
            {
                if ((double)k2 < Length && Length <= (double)(k2 + L[i]))
                { answer = i + 1; break; }
                k2 += L[i];
            }
            Console.WriteLine(answer);
        }
    }
}

Measured memory_bytes: 8996
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())

using namespace std;
typedef long long  ll;

vector<int> cost = {0,2,5,5,4,5,6,3,7,6};

const int N = 1e4 + 4;

int memo[N] , n , m;
vector<int> A;

int solve(int remk){
    if(!remk)
        return 0;

    int &ret = memo[remk];
    if(~ret)
        return ret;

    ret = -inf;
    for(int x : A){
        if(remk >= cost[x])
            ret = max(ret , 1 + solve(remk - cost[x]));
    }
    return ret;
}
int cur = -1;

void printpath(int remk){
    if(!remk){
        cout << "\n";
        exit(0);
    }

    for(int x : A){
        if(remk >= cost[x] && 1 + solve(remk - cost[x]) == cur){
            cout << x;
            --cur;
            printpath(remk - cost[x]);
            break;
        }
    }
}
int main(){
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    cin >> n >> m;

    A.resize(m);
    for(int &x : A)
        cin >> x;

    sort(all(A) , greater<int>());

    memset(memo , -1 , sizeof memo);

    cur = solve(n);

    printpath(n);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int n, k ,c;
	cin >> n >> k >> c;
    string s;
    cin >> s;
    auto getPositions = [&]() {
        vector<int> res;
        for (int i = 0; i < n && res.size() < k;) {
            if (s[i]=='o') {
                res.push_back(i);
                i += c+1;
            } else {
                ++i;
            }
        }
        return res;
    };
    vector<int> l, r;
    l = getPositions();
    reverse(s.begin(), s.end());
    r = getPositions();
    rep(i,k) r[i] = n-1-r[i];
    reverse(s.begin(), s.end());

    rep(i,k) {
        if (l[i]==r[k-1-i]) cout << l[i]+1 << endl;
    }
 
	return 0;
}


Measured memory_bytes: 3468
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')



def solve():
    
    # for _ in range(ii()):

    
    a=si()
    b=si()
    c=0
    for i in range(len(a)):
        if a[i]!=b[i]:
            c+=1
    print(c)
    










        
if __name__ =="__main__":

    if path.exists('input.txt'):
        sys.stdin=open('input.txt', 'r')
        sys.stdout=open('output.txt','w')
    else:
        input=sys.stdin.readline
    solve()


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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

typedef long long ll;

using namespace std;

int main ()
{
  long long H,W;
  cin >> H >> W;

  if (H == 1 || W == 1)
  {
    cout << 1 << endl;
    return 0;
  }
    

  if (H%2 == 0)
    cout << W * (H/2) << endl;
  else if (W%2 == 0)
    cout << H * (W/2) << endl;
  else
    cout << W * (H/2) + W/2 + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 3572
def solve():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)    #  降順で整列

    score_of_Alice = 0
    score_of_Bob = 0

    for i in range(N):
        if i % 2 == 0:
            score_of_Alice += a[i]
        else:
            score_of_Bob += a[i]

    print(score_of_Alice - score_of_Bob)

solve()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll MOD = 1000000007;
const double PI = acos(-1);
//or-> ||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main(){
	IO_STREAM;
	ll N;
	ll ans;
	string s;
	cin>>N;
	map<char,ll>cnt;
	rep(i,0,N){
		cin>>s;
		if(s[0]=='M'){
			cnt[s[0]]++;
		}
		else if(s[0]=='A'){
			cnt[s[0]]++;
		}
		else if(s[0]=='R'){
			cnt[s[0]]++;
		}
		else if(s[0]=='C'){
			cnt[s[0]]++;
		}
		else if(s[0]=='H'){
			cnt[s[0]]++;
		}
	}
	ans=0;
	ans+=cnt['M']*cnt['A']*cnt['R'];
	ans+=cnt['M']*cnt['A']*cnt['C'];
	ans+=cnt['M']*cnt['A']*cnt['H'];
	ans+=cnt['M']*cnt['R']*cnt['C'];
	ans+=cnt['M']*cnt['R']*cnt['H'];
	ans+=cnt['M']*cnt['C']*cnt['H'];
	ans+=cnt['A']*cnt['R']*cnt['C'];
	ans+=cnt['A']*cnt['R']*cnt['H'];
	ans+=cnt['A']*cnt['C']*cnt['H'];
	ans+=cnt['R']*cnt['C']*cnt['H'];
	DBG("","","","");
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
 
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)
    return divisors
 
 
tmp = [0]*(N+1)
b = [0]*N
ball_num = 0
ball_box = []
for i in reversed(range(N)):
    if a[i] == 0:
        if (tmp[i+1]%2) == 0:
            continue
        else:
            ball_box.append(i+1)
            ball_num += 1
            val = make_divisors(i+1)
            for elms in val:
                tmp[elms] += 1
    elif a[i] == 1:
        if (tmp[i+1]%2) == 0:
            ball_box.append(i+1)
            ball_num += 1
            val = make_divisors(i+1)
            for elms in val:
                tmp[elms] += 1
        else:
            continue
 
print(ball_num)
if ball_num != 0:
    print(*ball_box)

Measured memory_bytes: 71784
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long MOD = 1e9 + 7;

int main() {
    int H, W, white = 0;
    cin >> H >> W;
    const int dx[4] = {1, 0, -1, 0};
    const int dy[4] = {0, 1, 0, -1};
    vector<vector<char>> m(H, vector<char>(W));
    rep(i, H) rep(j, W) {
        cin >> m[i][j];
        if(m[i][j] == '.') white++;
    }
    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int, int>> que;
    dist[0][0] = 0;
    que.push(make_pair(0, 0));
    while(!que.empty()) {
        pair<int, int> cp = que.front();
        int x = cp.second, y = cp.first;
        que.pop();
        rep(di, 4) {
            int nx = x + dx[di];
            int ny = y + dy[di];
            if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
            if(m.at(ny).at(nx) == '#') continue;

            if(dist.at(ny).at(nx) == -1) {
                que.push(make_pair(ny, nx));
                dist.at(ny).at(nx) = dist.at(y).at(x) + 1;
            }
        }
    }

    if(dist[H - 1][W - 1] == -1)
        cout << -1 << endl;
    else
        cout << white - dist[H - 1][W - 1] - 1 << endl;
}

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

int n, w;
int arr[105][2];
unsigned long long dp[100005][105];
int main() {
    cin >> n >> w;
    for(int i = 1; i <= n; i++) {
        cin >> arr[i][0] >> arr[i][1];
    }
    for(int i = 1; i <= w; i++) {
        for(int j = 1; j <= n; j++) {
            dp[i][j] = dp[i][j-1];
            if(i >= arr[j][0]) {

                dp[i][j] = max(dp[i][j], (dp[i - arr[j][0]][j-1] + arr[j][1]));
            }
        }
    }

    cout << dp[w][n] ;
    return 0;
}


Measured memory_bytes: 82304
#include <iostream>
#include <math.h>
#include <algorithm>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;

int main(void){
    int ans=0,N;
    string n;

    cin >> N;

    FOR(i,1,N+1){
        n = to_string(i);
        if(n.length() % 2 == 1)
            ans++;
    }
    cout << ans << endl;

    return 0;
}

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    for i in 0..s.len() - 1 {
        if s[i] == s[i + 1] {
            println!("{} {}", i + 1, i + 2);
            return;
        }
    }
    for i in 0..s.len() - 2 {
        if s[i] == s[i + 2] {
            println!("{} {}", i + 1, i + 3);
            return;
        }
    }
    println!("-1 -1");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import static java.lang.System.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int a=sc.nextInt(), b=sc.nextInt(), c=sc.nextInt(), x=sc.nextInt(), y=sc.nextInt();
		int total = 0;
		if (a+b > 2*c) { //ABピザを買う必要あり
			total += 2*c*(Math.min(x,y));
			if (x > y) {
				total += (x-y)*a;
			}
			else if (x < y) {
				total += (y-x)*b;
			}
			int total2 = 2*c*(Math.max(x,y));
			out.println(Math.min(total,total2));
		}
		else {
			total = a*x + b*y;
			out.println(total);
		}
	}
}

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

int main(){
    int n;
    cin>>n;
    double ll = inf, lm = inf,lr = inf;
    double rl = -inf,rm = -inf, rr = -inf;
    double dd = inf, dm = inf, du = inf;
    double uu = -inf,um = -inf, ud = -inf;
    rep(i,n){
        double x,y;
        cin>>x>>y;
        char c;
        cin>>c;
        if(c=='U'){
            lm = min(lm,x);
            rm = max(rm,x);
            du = min(du,y);
            uu = max(uu,y);
        }
        if(c=='D'){
            lm = min(lm,x);
            rm = max(rm,x);
            dd = min(dd,y);
            ud = max(ud,y); 
        }
        if(c=='L'){
            ll = min(ll,x);
            rl = max(rl,x);
            dm = min(dm,y);
            um = max(um,y); 
        }
        if(c=='R'){
            lr = min(lr,x);
            rr = max(rr,x);
            dm = min(dm,y);
            um = max(um,y); 
        }
    }
    double S = longinf;
    rep(i,400000000){
        double cur = 0.5 * i;
        double minx = min({lm, ll-cur,lr+cur});
        double maxx = max({rm, rl-cur,rr+cur});
        double miny = min({dm, dd-cur,du+cur});
        double maxy = max({um, ud-cur,uu+cur});
        S = min((maxx-minx)*(maxy-miny),S);
    }
    cout<<fixed<<setprecision(12)<<S<<endl;
    return 0;
}

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

int main(){
	ll x,y;
	cin >> x >> y;
	ll ans = 0;
	while(x <= y){
		x *= 2;
		ans++;
	}
	cout << ans << endl;
    return 0;
}



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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    priority_queue<int> que;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        que.push(a);
    }
    for(int i = 0; i < m; ++i){
        int a = que.top();
        que.pop();
        a /= 2;
        que.push(a);
    }
    ll ans = 0;
    while(!que.empty()) {
        ans += que.top();
        que.pop();
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <unordered_set>

using namespace std;


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

  if (a == 0) {
    cout << b / x + 1 << endl;
  } else {
    long o = (a - 1) / x;
    long p = b / x;
    cout << p - o << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long

ll dp[1002][1002],mod=1e9+7;

ll noofways(ll i,ll j,string s[])
{
    if(i==0 && j==0)
        return 1;

    if(dp[i][j]!=-1)
        return dp[i][j];

    ll c1,c2;
    c1=c2=0;
    if(i>=1 && s[i-1][j]!='#')
        c1=noofways(i-1,j,s);
    if(j>=1 && s[i][j-1]!='#')
        c2=noofways(i,j-1,s);

    return dp[i][j]=(c1+c2)%mod;
}

void test_case()
{
    memset(dp,-1,sizeof(dp));
    ll h,w;
    cin>>h>>w;
    string s[h];
    for(ll i=0;i<h;i++)
    {
        cin>>s[i];
    }
    cout<<noofways(h-1,w-1,s);
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


Measured memory_bytes: 9344
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;
const int MAXN = 100010;
int nowarn;

int n;

namespace Tree {
	int head[MAXN], nxt[MAXN<<1], to[MAXN<<1], c[MAXN<<1], eidx = 0;
	void init() {
		memset( head, -1, sizeof(head) );
	}
	void adde( int u, int v, int w ) {
		to[eidx] = v, c[eidx] = w, nxt[eidx] = head[u], head[u] = eidx++;
		to[eidx] = u, c[eidx] = w, nxt[eidx] = head[v], head[v] = eidx++;
	}
}

int center, size[MAXN], cmaxsz = 1e9;
ll ans = 0;

void dfs( int u, int fa ) {
	using namespace Tree;
	size[u] = 1;
	int maxsz = 0;
	for( int i = head[u]; ~i; i = nxt[i] ) {
		int v = to[i];
		if( v == fa ) continue;
		dfs(v, u), size[u] += size[v];
		maxsz = max(maxsz, size[v]);
		ans += (ll)min(size[v], n - size[v]) * 2 * c[i];
	}
	maxsz = max(maxsz, n - size[u]);
	if( maxsz < cmaxsz ) center = u, cmaxsz = maxsz;
}

int main() {
	nowarn = scanf( "%d", &n );
	Tree::init();
	for( int i = 0; i < n-1; ++i ) {
		int u, v, w;
		nowarn = scanf( "%d%d%d", &u, &v, &w );
		Tree::adde(u, v, w);
	}
	dfs(1, 0), ans = 0;
	dfs(center, 0);
	int minc = 1e9;
	for( int i = Tree::head[center]; ~i; i = Tree::nxt[i] ) {
		int v = Tree::to[i];
		if( n % 2 == 0 && size[v] == n/2 ) {
			minc = Tree::c[i];
			break;
		}
		minc = min(minc, Tree::c[i]);
	}
	printf( "%lld\n", ans - minc );
	return 0;
}


Measured memory_bytes: 8576
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const [N, Q] = nextIntArray()
    const s = next()
    let l = []
    let r = []
    let agg = new Array(N).fill(0)
    let sum = 0
    agg[0] = 0
    for(let i = 1; i<N; i++){
        if(s[i] == "C" && s[i-1] == "A"){
            sum++
        }
        agg[i] = sum
    }
    let ans = []
    while(hasNext()){
        let tmp = nextIntArray()
        ans.push(agg[tmp[1]-1] - agg[tmp[0]-1])
    }

    console.log(ans.join("\n"))
}
Main()


Measured memory_bytes: 57576
/*
AOJ 0558 Cheese

?¢???????H * W?????°?????????N????\¶?????\?????????????????§??¬??????1-N????\¶????????????????????????????´????????????????????????\???????\¶??????
???????????????????????????????§???¶???1?????????????????\???????\¶?????????????¢????1???????????\????????????????¬???????
????????????????????¬????????§??????????????????????\¶??????
????????????????????°??°????????????????¢????????????????????\???????????????¶??´1????????????????¢??????????????????°???
??°??°??\????????¶???????????°??\??\???????\¶??????????\¶?????¶??´?????????????????????????\¶???????°???¨??¶???

?????\????¬¬??????????????´??°H(1 <= H <= 1000)???W(1 <= W <=1000)???N(1 <= N <= 9)???
??????H???W????????°?????? ???.???????????°??? ???X??????????¢??????????S?????????????´???? 1-N??£??¨??¬??????1-N????\¶????????\??????
 */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define TR(it, c) for(typeof(c.begin()) it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }

const int N=1024;
int h, w, n;
char b[N][N];
int dist[N][N];
int tx[10], ty[10];
int dx[4] = { -1, 0, 1, 0 };
int go(int x1, int y1, int x2, int y2) {
  CLR(dist, -1);
  dist[x1][y1] = 0;
  queue<PII> q;
  q.push(PII(x1, y1));
  while (!q.empty() && dist[x2][y2] == -1) {
    x1 = q.front().first, y1 = q.front().second;
    q.pop();
    REP(dir, 4) {
      int x = x1 + dx[dir], y = y1 + dx[dir^1];
      if (x < 0 || x >= h || y < 0 || y >= w) continue;
      if (dist[x][y] != -1 || b[x][y] == 'X') continue;
      dist[x][y] = dist[x1][y1] + 1;
      q.push(PII(x, y));
    }
  }
  return dist[x2][y2];
}

int main(int argc, char *argv[]) {
  while (scanf("%d%d%d", &h, &w, &n) == 3) {
    REP(i, h) scanf("%s", b[i]);
    REP(i, h) REP(j, w) {
      if (b[i][j] == 'S') tx[0] = i, ty[0] = j;
      else if (b[i][j] >= '1' && b[i][j] <= '9') {
        tx[b[i][j]-'0'] = i;
        ty[b[i][j]-'0'] = j;
      }
    }
    int ans = 0;
    REP(i, n) ans += go(tx[i], ty[i], tx[i+1], ty[i+1]);
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 6316
#include <iostream>
#include <cstdio>
using namespace std;
string s;
int c[1000006];
long long calc(int x){
    return 1LL * x * (x + 1) / 2 ;
}
int main(){
    cin >> s;
    int n = s.length(), m = 1;
    c[m] = 1;
    for (int i = 1; i < n; ++ i)
        if (s[i] == s[i - 1])
            ++ c[m];
        else
            c[++ m] = 1;
    long long ans = s[0] == '>' ? calc(c[1]) : 0;
    for (int i = s[0] == '>' ? 2 : 1; i <= m; i += 2){
        ans += calc(c[i] - 1) + (i < m ? calc(c[i + 1] - 1) : 0);
        ans += max(c[i], c[i + 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1796
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(long.Parse);
            var sCount = read.ElementAt(0);
            var cCount = read.ElementAt(1);

            if (cCount <= sCount * 2)
            {
                Console.WriteLine(cCount / 2);
            }
            else
            {
                cCount -= sCount * 2;
                Console.WriteLine(sCount + cCount / 4);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

ll x[100000];
ll v[100000];
ll Lmax[100000];
ll Rmax[100000];

int main()
{
	int N;
	ll C, ans = 0, L = 0, R = 0;

	cin >> N >> C;
	rep(i, N) cin >> x[i] >> v[i];

	rep(i, N) {
		L += v[i];
		if (i == 0) Lmax[i] = L - x[i];
		else Lmax[i] = max(Lmax[i - 1], L - x[i]);
		ans = max(ans, L - x[i]);
	}

	rrep(i, N) {
		R += v[i];
		if (i == N - 1) Rmax[i] = R - (C - x[i]);
		else Rmax[i] = max(Rmax[i + 1], R - (C - x[i]));
		ans = max(ans, R - (C - x[i]));
	}

	L = 0;
	rep(i, N - 1) {
		L += v[i];
		ans = max(ans, L - x[i] * 2 + Rmax[i + 1]);
	}

	R = 0;
	rrepc(i, N - 1, 1) {
		R += v[i];
		ans = max(ans, R - (C - x[i]) * 2 + Lmax[i - 1]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Describe
"""
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    data = []
    for i in range(m):
        p, y = map(int, input().split())
        data.append([p, y, i])
    # print(data)
    data_sorted = sorted(data, key=itemgetter(0, 1))
    # print(data_sorted)

    p, y, i = 0, 0, 0
    p_prev = 0 
    x = 1 # initialize
    codes = []
    for p, y, i in data_sorted:
        # initialize if new prefecture, increment if not
        if p != p_prev:
            x = 1
        else:
            x += 1
        code = '{:06d}{:06d}'.format(p, x)
        codes.append([i, code])
        p_prev = p
    # print(codes)

    codes_sorted = sorted(codes, key=itemgetter(0))
    # print(codes_sorted)

    for i, code in codes_sorted:
        print(code)
        
main()


Measured memory_bytes: 42976
import sys
from fractions import gcd
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = gcd(A[0], A[1])
    for a in A[2:]:
        ans = gcd(ans, a)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16280
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
if n == 1:
    for x in range(10):
        xs = str(x)
        for i in range(m):
            if int(xs[sc[i][0]-1]) != sc[i][1]:
                break
        else:
            print(x)
            break
    else:
        print(-1)
elif n == 2:
    for x in range(10,100):
        xs = str(x)
        for i in range(m):
            if int(xs[sc[i][0]-1]) != sc[i][1]:
                break
        else:
            print(x)
            break
    else:
        print(-1)
else:
    for x in range(100,1000):
        xs = str(x)
        for i in range(m):
            if int(xs[sc[i][0]-1]) != sc[i][1]:
                break
        else:
            print(x)
            break
    else:
        print(-1)

Measured memory_bytes: 3064
# coding: utf-8

# 5問目

n,a,b = map(int,input().split())
d_sum = 0


def kakuketa_wa(x):
    sum = 0

    if x < 10:
        return x
    else:
        a = [int(j) for j in list(str(x))]
        for k in a:
            sum += k
        return sum


for i in range(1,n+1):
    if (a <= kakuketa_wa(i)) and (kakuketa_wa(i) <= b):
        d_sum += i


print(d_sum)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    SS(ll,N,M)
    vl A(M), B(M);
    rep(i,M)cin >> A[i] >> B[i], --A[i], --B[i];
    UnionFind uf(N);
    
    ll cur = N * (N-1) / 2;
    vl res;
    rep(i,M){
        res.push_back(cur);
        ll a = A[M-1-i], b = B[M-1-i];
        if (uf.same(a, b)) continue;

        ll sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.unite(a, b);
    }
    reverse(res.begin(), res.end());
    
    rep(i,res.size()) cout << res[i] <<endl;
}

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

int main() {
    int n, largest = -1, second_largest = -1;
    int A[200002];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        if (A[i] > largest) largest = A[i];
        else if (A[i] > second_largest) second_largest = A[i];
    }
    for (int i = 0; i < n; i++) {
        if (A[i] == largest) cout << second_largest << endl;
        else cout << largest << endl;
    }
}

Measured memory_bytes: 2432
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

typedef long long ll;

ll x, y;

int main() {
	cin >> x >> y;

	ll b = (y - 2 * x) / 2;
	ll a = (x * 4 - y) / 2;

	if (a * 2 + b * 4 == y && a >= 0 && b >= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3624
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  static int[] A;
        static void Main(string[] args)
        {
          //入力を受け取る
          var N = long.Parse(Console.ReadLine());
          
          var march = new long[5];
          
          for(int i = 0; i < N; i++){
            var str = Console.ReadLine();
            var sento = str[0];
            
            if(sento == 'M'){
              march[0]++;
            }else if(sento == 'A'){
              march[1]++;
            }else if(sento == 'R'){
              march[2]++;
            }else if(sento == 'C'){
              march[3]++;
            }else if(sento == 'H'){
              march[4]++;
            }
          }
          
          
          
          long ans = 0;
          for(int i = 0; i < 3 ;i++){
            for(int j = i+1; j < 4 ;j++){
              for(int k = j+1;k < 5 ;k++){
                //Console.WriteLine("i:"+i+"j:"+j+"k:"+k);
                ans += march[i]*march[j]*march[k];
              }
            }
          }
          
          Console.WriteLine(ans);
        }
  
}


Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t;
    cin >> t;
    rep(_,t){
        ll n;
        cin >> n;
        vector<ll> k(n),l(n),r(n);
        rep(i,n) cin >> k[i] >> l[i] >> r[i];
        ll ans = 0;
        vector<vector<ll>> p(n+1),m(n+1);
        rep(i,n){
            ans += min(l[i],r[i]);
            if (l[i] > r[i]){
                p[k[i]].push_back(l[i]-r[i]);
            }
            if (l[i] < r[i]){
                m[n-k[i]].push_back(r[i]-l[i]);
            }
        }
        priority_queue<ll,vector<ll>,greater<ll>> q;
        rep(i,1,n+1){
            for (ll s:p[i]) q.push(s);
            while (q.size() > i){
                q.pop();
            }
        }
        ll d = q.size();
        rep(i,d){
            ans += q.top();
            //PRINT(q.top());
            q.pop();
        }
        rep(i,1,n+1){
            for (ll s:m[i]) q.push(s);
            while (q.size() > i){
                q.pop();
            }
        }
        d = q.size();
        rep(i,d){
            ans += q.top();
            //PRINT(q.top());
            q.pop();
        }
        PRINT(ans);
    }
}


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

int main(){
	int n;
  cin >> n ;
  int cont = 0;
  
  for( int i = 0; i < n; i++){
    int d1,d2;
    cin >>d1 >> d2;
    if(d1==d2) cont ++;
    if(d1!=d2) cont =0;
    if(cont == 3) break;
  }
  if (cont ==3) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define pi 3.1415926535897
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define mod1 998244353
#define inf 1000000000000000000
#define inf1 1000000000
#define endl '\n'
vector<ll> adj[100005];
ll visited[100005];
vector<ll> topsort;
ll dp[100005];
void dfs(ll v)
{
	visited[v]=1;
	for(auto it:adj[v])
	{
		if(!visited[it])
			dfs(it);
	}
	topsort.pb(v);
	return;
}
int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=m;i++)
	{
		ll a,b;
		cin>>a>>b;
		adj[a].pb(b);
	}
	for(ll i=1;i<=n;i++)
	{
		if(!visited[i])
			dfs(i);
	}
	reverse(topsort.begin(),topsort.end());
	for(auto it:topsort)
	{
		for(auto it1:adj[it])
		{
			dp[it1]=max(dp[it1],dp[it]+1);
		}
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
		ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10228