akhauriyash/Code-Regression huggingface dataset:
m = gets.chomp.to_i
a = []
a = gets.split.map(&:to_i)
 
t = 0
u = 0
v = 0
for i in 0..a.length-1
 if a[i] > 0
     t += 1
 elsif a[i] < 0
     u += 1
 else
     v = 1
 end
end
#p t
#p u
#p v
n = 0
x = 10**9
for i in 0..a.length-1
 n += a[i].abs
 if x >=a[i].abs
     x = a[i].abs
 end
 #p x
end
#p n
#p x
if (u)%2 == 0
    puts n
elsif v > 0
    puts n
else
    puts n - 2*x
end

Measured memory_bytes: 8588
#include<stdio.h>
     
int main(void) {
    int count[3], i;
    for (i=0;i<3;i++) {
        scanf("%d", &count[i]);
    }
    for (i=0;i<2;i++) {
        if(count[i+1]<=count[i]) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}



Measured memory_bytes: 2020
#include<bits/stdc++.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{

        int n;
        cin>>n;
        int a[n],m;
        for(m=0;m<n;m++)
        {
            scanf("%d",&a[m]);
        }

        int i=0,j=n-1,d;

        int s=a[i],p=a[j],u=0,v=n-1;


        while(j>i)
        {
                if(u!=i)
                {
                    s=s+a[i];
                    u=i;
                }

                if(v!=j)
                {
                    p=p+a[j];
                    v=j;
                }

                if(s>p) j--;

                else i++;

        }

        d=abs(s-p);
        cout<<d<<endl;


        return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    x,y = map(int, readline().split())

    ans = 0

    d = {}
    d[1] = 300000
    d[2] = 200000
    d[3] = 100000

    if x in d:
        ans += d[x]
    
    if y in d:
        ans += d[y]

    if x == 1 and y == 1:
        ans += 400000
    
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let k: usize = s.next().unwrap().parse().unwrap();
	let h: Vec<i64> = s.take(n).map(|a| a.parse().unwrap()).collect();
	let mut dp = vec![vec![std::i64::MAX; n - k + 1]; n + 1];
	dp[0][0] = 0;
	for i in 0..n {
		for j in 0..n - k {
			let mut x = std::i64::MAX;
			for k in 0..=i {
				let v = dp[k][j].saturating_add(std::cmp::max(
					0,
					h[i] - k.checked_sub(1).and_then(|i| Some(h[i])).unwrap_or(0),
				));
				if v < x {
					x = v;
				}
			}
			dp[i + 1][j + 1] = x;
		}
	}
	println!("{}", (0..=n).map(|i| dp[i][n - k]).min().unwrap());
}


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

int main() {
  int n;
  string str;

  cin >> n;
  cin >> str;

  vector<int> vW(n+1,0),vE(n+1,0);

  for(int i=0;i<n;i++){
    vW[i+1]+=vW[i];
    if(str[i]=='W') vW[i+1]++;
    vE[i+1]+=vE[i];
    if(str[i]=='E') vE[i+1]++;
  }

  int ans=999999999;
  int now;

  for(int i=0;i<n;i++){
    now=vW[i]+(vE[n]-vE[i+1]);
    if(ans>now) ans=now;
  }


  cout << ans << endl;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,V[200];
double anss;
ll i, j, k, ans;
int main(){
    scanf("%lld", &N);
    anss = 0;
    fornum(i,0,N){
        scanf("%lld", &V[i]);
    }
    sort(V, V + N);
    anss = V[0];
    fornum(i,1,N){
        anss = (anss + V[i]) / 2;
    }
    printf("%.12lf", anss);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int ans=0;
  FOR(i,1,n+1){
	  ans+=i;
  }
  cout<<ans<<endl;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

string S;
int idx;
int N, M;
string alphas;
int curr;

struct ConsumeException{};

void consume(char c) {
  if(idx >= N) throw ConsumeException();
  if(S[idx] != c) throw ConsumeException();
  idx ++;
}

bool try_consume(char c) {
  try {
    consume(c);
  } catch(ConsumeException e) {
    return false;
  }
  return true;
}

int E();

int convert(string const& b) {
  int n = b.size();
  int ret = 0;
  for(int i=0; i<n; i++) {
    ret *= 2;
    assert(isdigit(b[i]));
    ret += b[i] - '0';
  }
  return ret;
}

string B() {
  string ret;
  while(1) {
    if(S[idx] == '0') ret += '0';
    else if(S[idx] == '1') ret += '1';
    else break;
    idx++;
  }
  return ret;
}

int Nu() {
  if(try_consume('0')) return 0;
  consume('1');
  return convert("1" + B());
}

int F() {
  if(try_consume('-')) {
    return -F();
  }
  else if(try_consume('(')) {
    int r = E();
    consume(')');
    return r;
  }
  else {
    return Nu();
  }
}

int T() {
  int num1 = F();
  while(try_consume('*')) {
    int num2 = F();
    num1 *= num2;
  }
  return num1;
}

int E() {
  int term1 = T();
  while(1) {
    bool cont = 0;
    while(try_consume('+')) {
      cont = 1;
      int term2 = T();
      term1 += term2;
    }
    while(try_consume('-')) {
      cont = 1;
      int term2 = T();
      term1 -= term2;
    }
    if(!cont) break;
  }
  return term1;
}

bool Q() {
  int expr1 = E();
  consume('=');
  int expr2 = E();
  return expr1 == expr2 && idx == N;
}

int main() {

  string T = "01+-*()=";
  sort(T.begin(), T.end());
  string RS; cin >> RS;
  N = RS.size();
  for(auto c: RS) if(isalpha(c)) alphas.push_back(c);
  sort(alphas.begin(), alphas.end());
  alphas.erase(unique(alphas.begin(), alphas.end()), alphas.end());
  M = alphas.size();

  if(M > T.size()) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 0;
  set<string> st;
  do {
    S = RS;
    rep(i, N) {
      if(isalpha(S[i])) S[i] = T[alphas.find(S[i])];
    }
    if(!st.count(S)) {
      st.insert(S);
      idx = curr = 0;
      try { ans += Q(); } catch (...) {}
    }
  } while(next_permutation(T.begin(), T.end()));
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7636
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (sb-int:defconstant-eqx OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0))
    #'equal)
  #+swank (ql:quickload '(:cl-debug-print :fiveam) :silent t)
  #-swank (set-dispatch-macro-character
           #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil nil t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;;;
;;; Body
;;;

(defun main ()
  (let* ((sx (read))
         (sy (read))
         (tx (read))
         (ty (read)))
    (loop repeat (- tx sx) do (write-char #\R))
    (loop repeat (- ty sy) do (write-char #\U))
    (loop repeat (- tx sx) do (write-char #\L))
    (loop repeat (- ty sy) do (write-char #\D))
    (write-char #\D)
    (loop repeat (+ 1 (- tx sx)) do (write-char #\R))
    (loop repeat (+ 1 (- ty sy)) do (write-char #\U))
    (write-char #\L)
    (write-char #\U)
    (loop repeat (+ 1 (- tx sx)) do (write-char #\L))
    (loop repeat (+ 1 (- ty sy)) do (write-char #\D))
    (write-char #\R)
    (terpri)))

#-swank (main)


Measured memory_bytes: 20708
#include <iostream>
#include <map>
#include <sstream>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.baseballchamp", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){
		int n;
		stringstream ssn(str);
		ssn >> n;
		
		if (n == 0 ){
			break;
		} // end if
		
		multimap< pair<int,int>, char > rank;
 
		int i,j;
		for (i = 0; i < n; ++i){
			getline (cin, str );
			char name;
			int in;
			int win = 0, lose = 0;
			
			stringstream ss(str);
			ss >> name;
			
			for (j = 0; j < n - 1; ++j){
				ss >> in;
				switch (in ){
					case 0: ++win; break;
					case 1: ++lose; break;
//					case 2: ++draw; break;
				} // end switch
			} // end for
			rank.insert (make_pair (make_pair (-win, lose ),name ) );
		} // end for
		
		multimap<pair <int, int> ,char >::iterator it = rank.begin();
			
		for (; it != rank.end(); ++it ){
//			cout << (*it).first.first << ' ' << (*it).first.second << ' ';
			cout << (*it).second << endl;
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;

int N;

void dfs(string s, char mx){
if(s.length() == N){
printf("%s\n", s.c_str());
} else {
for(char c='a';c<=mx;c++){
dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
}
}
}
int main(void){
cin >> N;
dfs("", 'a');
return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
int main(void){
    int x, y;
while(1){
 scanf("%d %d", &x, &y);
 if(x==0&&y==0){
 break;
     
 }
 else if(x>y){
     printf("%d %d\n",y,x);
     
 }
 else{
     printf("%d %d\n",x,y);
 }
 
}
 return 0;
}



Measured memory_bytes: 2104
#2:42

x1, y1, x2, y2 = map(int, input().split())

dx = x2 - x1
dy = y2 - y1

x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-7
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll ret(ll num) {
    ll res = 1;
    ll res1 = 1;
    ll res2 = 1;
    ll now = powl(num, 0.2);
    
    for(int i = 0; i<5; ++i) {
        res *= now;
        res1 *= now+1;
        res2 *= now-1;
    }
    
    if(res==num) return now;
    if(res1==num) return now+1;
    if(res2==num) return now-1;
    return INT_MAX;
}

int32_t main() {
    fastio
    ll x;
    cin>>x;
    for(int i = 0; i<=5000; ++i) {
        ll cur = pow(i, 5);
        ll t = ret(cur+x);
        if(t!=INT_MAX) {
            if(i==2051)
            cout<<x+cur<<endl;
            cout<<t<<" "<<i<<endl;
            return 0;
        }

        ll t2 = 0;
        if(cur>x) t2 = ret(cur-x);
        else t2 = ret(x-cur);
        if(t2!=INT_MAX) {
            if(cur>x) {
                cout<<t2<<" "<<i<<endl;
            }
            else {
                cout<<t2<<" "<<-i<<endl;
            }
            return 0;
        }
    }
}

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

int main() {
  int64_t H,M;
  cin >> H;
  cin >> M;
  int64_t ans;
  if ((H==1) || (M==1)) ans=1;
  else if ((H*M)%2==1) ans=((H*M)/2)+1;
  else ans=(H*M)/2;
  cout << ans << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using T = tuple<Int, Int, char, Int, string>;
  vector<T> vt;
  for(Int i=0;i<n;i++){
    Int v,w,d;
    char t;
    string s;
    cin>>v>>w>>t>>d>>s;
    vt.emplace_back(v,w,t,d,s);
  }
  sort(vt.begin(),vt.end());
  for(Int i=0;i<n;i++){
    Int v,w,d;
    char t;
    string s;
    tie(v,w,t,d,s)=vt[i];
    cout<<v<<" "<<w<<" "<<t<<" "<<d<<" "<<s<<endl;
  }
  return 0;
}



Measured memory_bytes: 13060
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    return

#C
def C():
    n = II()
    s = S()
    dp = [0 for i in range(n)]
    for num,si in enumerate(s):
        if si == "E":
            dp[num] = dp[num-1]+1
        else:
            dp[num] = dp[num - 1]
    ans = float("INF")
    a = max(dp)
    for i in range(n):
        ans = min(ans,  a - dp[i] + i - dp[i] + (s[i] == "E"))
    
    print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38640
import java.io.*;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n_cards = Integer.parseInt(br.readLine());
		
		boolean[] S = new boolean[14];
		boolean[] H = new boolean[14];
		boolean[] C = new boolean[14];
		boolean[] D = new boolean[14];
		
		for (int i = 0; i < n_cards; i++) {
			String sz_input = br.readLine();
			String[] sz_type = sz_input.split(" ");
			int n_number = Integer.parseInt(sz_type[1]);
			
			switch (sz_type[0]) {
			case "S":
				S[n_number] = true;
				break;
			case "H":
				H[n_number] = true;
				break;
			case "C":
				C[n_number] = true;
				break;
			case "D":
				D[n_number] = true;
				break;
			}
		}
		

		for (int i = 1; i < 14; i++) {
			if (S[i] == false) {
				System.out.println("S " + i);
			}
		}
		for (int i = 1; i < 14; i++) {
			if (H[i] == false) {
				System.out.println("H " + i);
			}
		}
		for (int i = 1; i < 14; i++) {
			if (C[i] == false) {
				System.out.println("C " + i);
			}
		}
		for (int i = 1; i < 14; i++) {
			if (D[i] == false) {
				System.out.println("D " + i);
			}
		}
	}
}

Measured memory_bytes: 24468
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,k = li()
a = list(li())

a_cum = [0] + list(accumulate(a))
sm_lst = []
for i in range(n+1):
    for j in range(i+1,n+1):
        sm_lst.append(a_cum[j] - a_cum[i])
        
pop = sm_lst
ans = 0
for bit in range(40,-1,-1):
    yes=[]
    no=[]
    
    for s in pop:
        if s & (1<<bit):
            yes.append(s)
        else:
            no.append(s)
            
    if len(yes) >= k:
        ans += (1<<bit)
        pop = yes
        

print(ans)
    

Measured memory_bytes: 29180
package main

import (
        "fmt"
)

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

        judge := func(T int, N int) bool {
                if (T-N) < 0 || (T-N)%2 != 0 {
                        return false
                }
                T -= N
                return true
        }

        preT := 0
        preX := 0
        preY := 0
        possible := 0
        for i := 0; i < N; i++ {
                var t, x, y int
                fmt.Scan(&t, &x, &y)
                t -= preT
                x -= preX
                y -= preY
                if !judge(t, x+y) {
                        possible += 1
                }
                preT = t
                preX = x
                preY = y
        }
        if possible == 0 {
                fmt.Println("Yes")
        } else {
                fmt.Println("No")
        }
}


Measured memory_bytes: 5504
#include <cstdio>
#include <iostream>
#include <vector>
#include<bits/stdc++.h>
using namespace std;

int main() {
    int h, n;
    scanf("%d %d", &h, &n);
    int L[1000][2];
    for (int i=0; i<n; i++) {
        scanf("%d %d", &L[i][0], &L[i][1]);
    }
    vector<long> dp(h+1);
    
    for (int i=1; i<h+1; i++) {
        long long tmp = LLONG_MAX;
        for (int j=0; j<n; j++) {
            long x = L[j][0] > i ? L[j][1] : dp[i-L[j][0]] + L[j][1];
            // if (i == 1 && j == 0) {
            //     tmp = x;
            // }
            if (x < tmp) {
                tmp = x;
            }
        }
        dp[i] = tmp;
    }
    // cout << "moo" << endl;
    cout << dp[h] << endl;

    return 0;
}

Measured memory_bytes: 384
"use strict";

const main = (input) => {
    const spi = input.split('\n');
    const [n, m] = spi[0].split(' ').map(e => Number(e));
    const a = spi[1].split(' ').map(e => Number(e));

    const sum = a.reduce((x, y) => x += y);

    if (n - sum < 0) console.log(-1);
    else console.log(n - sum);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 30604
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [A[i]-B[i] for i in range(N)]
C = sorted(C)
if sum(C) < 0:
  print(-1)
else:
  if C[0] >= 0:
    print(0)
  else :
    cnt = 0
    point = 0
    for i in range(N):
      if C[i] < 0 :
        cnt+=1
        point += C[i]
      else :
        break
    for i in range(N):
      cnt+=1
      point += C[-1-i]
      if point>=0:
        print(cnt)
        break

Measured memory_bytes: 18356
#include<set>
#include<iostream>
#include<ctime>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<functional>
#include<string.h>
#include<limits.h>
#define P pair<int,int>
using namespace std;

int s[5001];
P k[1000];
vector<int>c[1000];
int d[1000];
int x[1000];
int dp[1000];
void DFS(int a) {
	for (int i : c[a]) {
		d[i] = d[a] + 1;
		DFS(i);
	}
}
signed main() {
	int n; cin >> n;
	for (int i = 1; i < n; i++) {
		int a; cin >> a; a--;
		c[a].push_back(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	DFS(0);
	for (int i = 0; i < n; i++) {
		k[i] = { d[i],i };
	}
	sort(k, k + n, greater<P>());
	for (int i = 0; i < n; i++) {
		int t = k[i].second;
		int sum = 0;
		int n = 0;
		for (int j : c[t]) {
			sum += min(x[j], dp[j]);
			n += max(x[j], dp[j]);
		}
		if (sum > x[t]) { puts("IMPOSSIBLE"); return 0; }
		memset(s, 0, sizeof(s));
		for (int j : c[t]) {
			for (int l = x[t]; l >= max(x[j], dp[j]) - min(x[j], dp[j]); l--) {
				s[l] = max(s[l], s[l - (max(x[j], dp[j]) - min(x[j], dp[j]))] + (max(x[j], dp[j]) - min(x[j], dp[j])));
			}
		}
		dp[t] = n-s[x[t]];
	}
	puts("POSSIBLE");
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());

		long result = 0;
		for (int a = 1; a < n; a++) {

			if (n % a == 0) {
				result += n / a - 1;
			} else {
				result += n / a;
			}
		}

		System.out.println(result);

	}
}


Measured memory_bytes: 35712
n, m = map(int, input().split())
ks = []
for i in range(m):
    ks.append(list(map(int, input().split())))
p = list(map(int, input().split()))

n_pattern = 2 ** n
count = 0
for i in range(n_pattern):
    for j in range(m):
        current = 0
        for k in range(ks[j][0]):
            current += 2 ** (ks[j][k + 1] - 1)
        mod = bin(i & int(current)).count('1') % 2
        if mod != p[j]:
            break
        if j == m - 1:
            count += 1
print(count)


Measured memory_bytes: 3064
import math
K = int(input())
cnt = 0
tmp = 0
for a in range(1, K+1):
    for b in range(1, a+1):
        for c in range(1, b+1):
            if a==b==c:
                tmp = math.gcd(a, b)
                cnt += math.gcd(tmp, c)
            elif a!=b!=c!=a:
                tmp = math.gcd(a, b)
                cnt += 6*math.gcd(tmp, c)
            else:
                tmp = math.gcd(a, b)
                cnt += 3*math.gcd(tmp, c)

print(cnt)

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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造

//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  UnionFind(int N) : UF(N) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    UF.at(rx) = ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false; // 1や0,-1は素数ではない
  }
  if (x == 2) {
    return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false; // 割れたら素数じゃない
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  string S;
  cin >> S;
  vector<char> ANS;
  for (int i = 0; i < int(S.size()); i++) {
    if (S.at(i) != 'B') {
      ANS.push_back(S.at(i));
    }
    else if (ANS.size() != 0) {
      ANS.pop_back();
    }    
  }
  for (int i = 0; i < int(ANS.size()); i++) {
    cout << ANS.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
 
using namespace std;
 
long long sum[400000];
int main(){
 
long long ans = 1LL << 62;
 
int n; cin >> n;
 
for(int i = 0; i < n; i++){
cin >> sum[i];
if(i) sum[i] += sum[i-1];
}
 
for(int i = 0; i < n - 1; i++){
long long tot = abs(sum[n-1] - 2*sum[i]);
ans = min(ans, tot);
}
cout << ans << endl;
 
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int cards[]  = {1, 0, -1};
        int counts[] = new int[3], n, maxValue;

        for(int i = 0; i < counts.length; i++) {
            counts[i] = scan.nextInt();
        }
        n = scan.nextInt();

        maxValue = 0;
        for(int i = 0; i < counts.length; i++) {
            if(n >= counts[i]) {
                maxValue += cards[i] * counts[i];
                n -= counts[i];
            } else {
                maxValue += cards[i] * n;
                n = 0;
            }
        }

        System.out.println(maxValue);
        scan.close();
        return;
    }
}

Measured memory_bytes: 35560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

vector<vector<int>> G;
map<pair<int, int>, int> color;
vector<P> vp;
 


int main(){
    int n;
    cin >> n;
    G.resize(n);
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
        vp.push_back(P(a, b));
    }
    ll k = 0;
    queue<int> q;
    vector<int> seen(n, 0);
    vector<int> par_col(n);
    seen[0] = 1;
    q.push(0);
    while(!q.empty()){
        int p = q.front();
        q.pop();
        int col = 1;
        chmax(k, (ll)G[p].size());
        for(auto i: G[p]){
            if(seen[i]) continue;
            if(col == par_col[p]) col++;
            par_col[i] = col;
            color[make_pair(p, i)] = col;
            color[make_pair(i, p)] = col;
            col++;
            q.push(i);
        }
      	seen[p] = 1;
    }

    cout << k << endl;

    for(auto v: vp){
        cout << color[v] << endl;
    }

}

Measured memory_bytes: 20084
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#define inf pow(10, 9)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int H, W;
  ci(H, W);
  ve<ve<char>> A(H, ve<char>(W));
  queue<pair<int, int>> Q;
  ve<ve<int>> n(H, ve<int>(W, inf));
  ve<pair<int, int>> C;
  rep(i, H){
    rep(j, W){
      ci(A.at(i).at(j));
      if(A.at(i).at(j) == '#'){
        Q.push(mp(i, j));
        n.at(i).at(j) = 0;
      }
    }
  }
  ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};
  wh(sz(Q)){
    int x = Q.front().ft, y = Q.front().sc;
    Q.pop();
    rep(j, 4){
      int ax = x + dx.at(j), ay = y + dy.at(j);
      if(ax < 0 || H <= ax || ay < 0 || W <= ay){
        con;
      }
      if(n.at(ax).at(ay) != inf){
        con;
      }
      if(A.at(ax).at(ay) != '#'){
        Q.push(mp(ax, ay));
        n.at(ax).at(ay) = n.at(x).at(y) + 1;
      }
    }
  }
  int a = 0;
  rep(i, H){
    rep(j, W){
      a = max(a, n.at(i).at(j));
    }
  }
  co(a);
}


Measured memory_bytes: 13456
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

ans = 0
memo = {}
memoset = set()
def dfs(i, time):
    if i==N-1:
        return time
    c, s, f = CSF[i]
    if time<s:
        time = s
    elif time%f!=0:
        time = (time//f+1)*f
    if (time, i) in memoset:
        return memo[(time, i)]
    T = dfs(i+1, time+c)
    memo[(time, i)] = T
    memoset.add((time, i))
    return T

for i in range(N-1):
    print(dfs(i, 0))
print(0)

Measured memory_bytes: 36668
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100010
int main(){
    int n,m,h[N],ma[N];
    cin>>n>>m;
    for(int i=1;i<=n;i++){
      cin>>h[i];
	  ma[i]=0;
    }
    for(int i=0;i<m;i++){
      int a,b;
	  cin>>a>>b;
	  ma[a]=max(ma[a],h[b]);
	  ma[b]=max(ma[b],h[a]);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
      ans += h[i]>ma[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4436
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
signed main() {
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	rep(i, n) {
		if (i % 2 == 0 && s[i] == 'p')ans--;
		else if (i % 2 == 1 && s[i] == 'g')ans++;
	}
	cout << ans << endl;
	endre;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long int
#define fr(i,x,y) for(int i=x;i<y;i++)
#define f(n) for(int i=0;i<n;i++)
#define ff(m) for(int j=0;j<m;j++)
#define F(x) for(auto it:x)
#define in insert
#define pb push_back
#define pi pair<int,int>
#define si second
#define fi first
#define show_(x) cerr<<"-> "<<#x<<endl;F(x){cerr<<it<<" ";}cout<<endl;
#define show(x) cerr<<#x<<"-> "<<x<<endl;
//#define start_routine cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int begtime = clock();
//#define end_routine int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0;
#define FILEIO freopen("F:\\inout\\input.txt", "r", stdin); freopen("F:\\inout\\output.txt", "w", stdout);
using namespace std;
void print(int a[],int n){f(n){cout<<a[i]<<" ";}cout<<endl;}
int m(int x){return x%1000000007;} 
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int p(int a,int b){if(b==0)return 1;int t=p(a,b/2); if(b%2==0)return t*t; else return a*t*t; } 
//strlen(s.c_str());  set <int, greater<int>> s; numeric_limits<double>::max()
//---------------------------------------------------------------------------------------------------------------------------------------------
 int t[100000];


signed main(){
	//FILEIO
	//cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	int a[n];
	f(n){
		cin>>a[i];
	}
	sort(a,a+n);
	if(n%2==1){
		cout<<0<<endl;
		return 0;
	}
	int sum=0;
	sum+=(a[n/2]-a[n/2-1]);
	cout<<sum<<endl;

	

	
	
	






	return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>

#define MAX 100000

int parent(int i){
	return i/2;
}
int left(int i){
	return 2 * i;
}
int right(int i){
	return 2 * i + 1;
}

int main(){
  int h,i,A[MAX+1];

  scanf("%d",&h);
  for(i = 1; i <= h; i++) scanf("%d",&A[i]);

  for(i = 1; i <= h; i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= h) printf("left key = %d, ",A[left(i)]);
    if(right(i) <= h) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}


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

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

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

  sort(L, L+N);

  int ans = 0;
  for (int i = 0; i < N-2; i++) {
    for (int j = i+1; j < N-1; j++) {
      if (L[i]==L[j]) continue;
      for (int k = j+1; k < N; k++) {
        if (L[i]==L[k]) continue;
        if (L[j]==L[k]) continue;
        if (L[i]+L[j]>L[k]) {
          ans++;
        } else {
          break;
        }
      }
    }
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);



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

	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];

	int start = 0;
	for (; start < n&&a[start] == 0; start++);
	if (start == n) {
		cout << n*2-1 << endl;
		return 0;
	}



	

	int ans1 = 0;
	int sum = a[0];
	if (sum <= 0) {
		sum = 1;
		ans1 += abs(a[0]) + 1;
	}
	REP(i, 1, n) {
		int newsum = sum + a[i];
		if (newsum == 0) {
			ans1++;
			sum = (sum / abs(sum))*-1;
		}
		else if ((sum / abs(sum))*(newsum / abs(newsum)) == 1) {
			ans1 += abs(newsum) + 1;
			sum = (newsum / abs(newsum))*-1;
		}
		else sum = newsum;
	}

	int ans2 = 0;
	sum = a[0];
	if (0 <= sum) {
		sum = -1;
		ans2 += abs(a[0]) + 1;
	}
	REP(i, 1, n) {
		int newsum = sum + a[i];
		if (newsum == 0) {
			ans2++;
			sum = (sum / abs(sum))*-1;
		}
		else if ((sum / abs(sum))*(newsum / abs(newsum)) == 1) {
			ans2 += abs(newsum) + 1;
			sum = (newsum / abs(newsum))*-1;
		}
		else sum = newsum;
	}


	cout << min(ans1,ans2) << endl;

	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>

int main()
{
    int n;
    std::map<std::string,int> mp;

    std::cin>>n;
    for(int i=0;i<n;i++)
    {
        std::string tmp;
        std::cin>>tmp;
        mp[tmp]++;
    }
    std::cout<<"AC x "<<mp["AC"]<<std::endl;
    std::cout<<"WA x "<<mp["WA"]<<std::endl;
    std::cout<<"TLE x "<<mp["TLE"]<<std::endl;
    std::cout<<"RE x "<<mp["RE"]<<std::endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public Main() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int index;
			int index2;
			int a;
			int b;
			int r;
			int r0;
			int result;
			result=0;
			r0=10;
			Map <Integer,Integer> map= new HashMap<Integer,Integer> ();
			for(index=0;index<5;index++) {
				a = sc.nextInt();
				map.put(index,a);
				r = a%10;
				if(r==0) {
					r=10;
				}
				b=a+10-r;;
				result=result+b;
				if(r<r0) {
					r0=r;
				}
			}
			sc.close();
			// 
			if(r0<10) {
				result=result+r0-10;
			}
			else {
			}
			// 出力

			System.out.println(result);
	}
}

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

cnt = 0

for i in range(N):
    if i+1 != a[i] and i+1 == a[a[i]-1]:
        a[a[i]-1] = 0
        a[i] = 0
    else:
        pass

print(a.count(0) // 2)

Measured memory_bytes: 20664
#include<string>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<ios>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<type_traits>
#include<random>
#include<vector>
#include<map>


using namespace std;

bool flag = 0;

vector<bool> used;

int connect[10][10] = {};

int co;

int N,M;

void tansaku(int x,int depth)
{
	used[x] = 1;
	if(depth==N-1)
	{
		co = co + 1;
		used[x] = 0;
		return;
	}
	for(int i=0;i<N;i++)
	{
		if(connect[x][i]==1 && used[i]==0)
		{
			tansaku(i,depth+1);
		}
	}
	used[x] = 0;

}

int main()
{
	cin >> N >> M;
	vector<int> a(M);
	vector<int> b(M);
	for(int i=0;i<N;i++)
	{
		used.push_back(0);
	}
	for(int i=0;i<M;i++)
	{
		cin >> a[i] >> b[i];
		a[i] = a[i] - 1;
		b[i] = b[i] - 1;
		connect[a[i]][b[i]] = 1;
		connect[b[i]][a[i]] = 1;
	}
	co = 0;
	tansaku(0,0);
	cout << co << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s;
  cin >> s;
  ll n=s.size();
  map<char,ll> cnt;
  for(ll i=0;i<n;i++) {
    if(i==0) {
      if(s[i]!='A') {
        cnt['C']+=10;
      }
    }
    else if(i==1||i==n-1) {
      if(s[i]>='A'&&s[i]<='Z') {
        cnt['C']+=10;
      }
    }
    else if(i>=2&&i<n-1) {
      cnt[s[i]]++;
      if(s[i]!='C'&&s[i]>='A'&&s[i]<='Z') {
        cnt['C']+=10;
      }
    }
  }
  if(cnt['C']==1) {
    cout << "AC" << endl;
  }
  else {
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n,m,l,k = 0;
    cin >> n >> m >> l;
    for(m;m <= l;m++){
        if(m % n == 0) {cout << "OK" << endl; k++; break;}
    }
    if(k == 0) cout << "NG" << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    long long min = a[0], max = a[0], sum = 0;
    for(int i = 0; i < n; i++){
        if(min > a[i]) min = a[i];
        if(max < a[i]) max = a[i];
        sum += a[i];
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#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 = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
int dp[242321],a[242321],ans = 0;


int main() {
	ll n,a;
	cin >> n;
	REPR(i, sqrt(n)) {
		if (n % i == 0) {
			a = log10(n / i + 1) + 1;
			cout << a << endl;
			break;
		}
	}
}


Measured memory_bytes: 512
def divisors(n):
    d=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            d.append(i)
            if i!=n//i:
                d.append(n//i)
    d.sort()
    return d
n=divisors(int(input()))
if len(n)%2==0:
    print(n[len(n)//2-1]+n[len(n)//2]-2)
else:
    print(n[len(n)//2]*2-2)

Measured memory_bytes: 38896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template<typename Monoid>
struct SegmentTree{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;      // モノイドに対して二項演算を行う関数オブジェクト
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1){
        sz = 1;
        while(sz < n)   sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x){
        seg[k + sz] = x;
    }

    void build(){
        for(int k = sz - 1; k > 0; --k){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    void update(int k, const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k >>= 1){
            seg[k] = f(seg[k << 1], seg[k << 1 | 1]);
        }
    }

    Monoid query(int a, int b){
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1){
            if(a & 1)   L = f(L, seg[a++]);
            if(b & 1)   R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const{
        return seg[k + sz];
    }
};

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

    int n, q;
    string s;
    cin >> n >> s >> q;
    SegmentTree<bitset<26>> seg(n, [](bitset<26> b1, bitset<26> b2){return b1 | b2;}, 0);
    for(int i = 0; i < n; ++i){
        bitset<26> bs = 1 << (s[i] - 'a');
        seg.set(i, bs);
    }
    seg.build();
    for(int i = 0; i < q; ++i){
        int type;
        cin >> type;
        if(type == 1){
            int p;
            char ch;
            cin >> p >> ch;
            --p;
            bitset<26> bs = 1 << (ch - 'a');
            seg.update(p, bs);
        }
        else{
            int l, r;
            cin >> l >> r;
            --l;
            bitset<26> bs = seg.query(l, r);
            cout << bs.count() << '\n';
        }
    }
}

Measured memory_bytes: 9116
import java.util.Scanner;


public class Main {

	public static void main(String[] args)  {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());

		Long ans = 0l;

		for(int i = 1 ; i <= n  ; i++) {
			for(int j = 1 ; j <= n  ; j++) {
				for(int k = 1 ; k <= n  ; k++) {
					int tmp= (int) gcd(i,j);
					ans += gcd(tmp,k);
				}
			}
		}


		System.out.println(ans);
	}

	private static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
		if(n == 0) return m;
		return gcd(n, m % n);
	}
}


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

using namespace std;
using ll = long long;
ll pow(ll n, ll m);
int main() {
	ll n, m;
	cin >> n >> m;
	ll k;
	k=pow( n,  m);
	cout << k << endl;
	
	
}
ll pow(ll n, ll m) {
	ll res = 1;
	int z = 1000000007;
	while (m > 0) {
		if (m & 1) {
			res *= n;
			res = res%z;
		}
		n = n*n;
		n = n%z;
		m >>= 1;
	}
	return res;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,k,q,x;
   cin >> n >> k >> q;
   vector<int> val(n+1,0);
   f(i,0,q){
      cin >> x;
      val[x]++;
   }
   int sm = 0;
   f(i,1,n+1) sm+=val[i];
   f(i,1,n+1){
      int kk = k-(sm-val[i]);
      if(kk<=0){
         cout << "No\n";
      }else{
         cout << "Yes\n";
      }
   }
   return 0;
}

Measured memory_bytes: 1408
s = input()

ans = 0
cnt = 0
for i in s:
    if i == "g":
        if cnt >= 1:
            cnt -= 1
            ans += 1
        else:
            cnt += 1
    else:
        if cnt >= 1:
            cnt -= 1
        else:
            cnt += 1
            ans -= 1

print(ans)

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

int cal(int a, int b, int c, int d, int op1, int op2, int op3)
{
	int ans = 0;
	if (op1 == 1)
		ans = a + b;
	else
		ans = a - b;
	if (op2 == 1)
		ans = ans + c;
	else
		ans = ans - c;
	if (op3 == 1)
		ans = ans + d;
	else
		ans = ans - d;

	return ans;
}
int main()
{
	int n, a[4], box, op1, op2, op3;
	int b[3] = { 0 };

	cin >> n;

	for (int i = 1; i <= 4; i++){
		a[4 - i] = n % 10;
		n = n / 10;
	}

	/*for (int i = 0; i < 4; i++)
		cout << a[i];*/

	for (int i = 0; i < 2; i++){
		op1 = i;
		for (int j = 0; j < 2; j++){
			op2 = j;
			for (int k = 0; k < 2; k++){
				op3 = k;
				box = cal(a[0], a[1], a[2], a[3], op1, op2, op3);
				if (box == 7)
				{
					b[0] = op1;
					b[1] = op2;
					b[2] = op3;
				}
			}
		}
	}

	for (int i = 0; i < 3; i++){
		cout << a[i] << (b[i] ? '+' : '-');
	}
	cout << a[3] << "=7\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
 

int main(){
	int n;
	string s;
	while(cin>>n && n > 0){
		cin>>s;
		vi a(n, 0), b(n, 0);
		for(int i = 0; i < n; i++) {
			cin>>a[i]>>b[i];
			--a[i];
			--b[i];
		}
		for(int i = n-1; i >= 0; i--){
			int c = s[a[i]]-'a';
			int d = s[b[i]]-'a';
			c = (c + b[i]-a[i]) % 26;
			d = (d + b[i]-a[i]) % 26;
			s[b[i]] = (char)(c+'a');
			s[a[i]] = (char)(d+'a');
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1208