akhauriyash/Code-Regression huggingface dataset:
import math
x=int(input())
listp=[]
z=math.log10(x)
z=z+1
rem=0
n=x
for i in range(int(z)):
    n!=0
    rem=n%10
    listp.append(int(rem))
    n=n/10
    

p=sum(listp)
z=int(p)
if (x%z==0):
    print('Yes')
else:
    print('No')


    
    

    


Measured memory_bytes: 3060
// B - Digits
#include <bits/stdc++.h>
using namespace std;

int main(){
    long n;
    int k;
    cin >> n >> k;
    int cnt = 1;
    while(1){
        if(n <= k-1) break;
        n/=k;
        // cout << n << endl;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int bMinusA = b - a;
    
    if (a >= b) {
      System.out.println("delicious");
    } else if (bMinusA <= x) {
      System.out.println("safe");
    } else {
      System.out.println("dangerous");
    }
  }
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

	int a;
	cin>>a;
	vector<pair<string,int>> v;
	map<string,int> m;
	int mx=0;
	forr(i,0,a)
	{
		string s;
		cin>>s;
		m[s]++;
		if(m[s]>=mx)	{mx=max(mx,m[s]); mx=m[s];}
	}
	for(auto const x: m)
	{
		if(x.second==mx)	v.push_back({x.first,1});
	}
	sort(v.begin(),v.end());
	for(auto const x: v)	cout<<x.first<<'\n';
	return 0;	
}

Measured memory_bytes: 27504
#include <stdio.h>
#include <math.h>

int main(void) {
	
	int d,s,i;
	
	while(scanf("%d",&d)!=EOF){
		s=0;
		for(i=d;i<600;i+=d){
			s+=d*i*i;
		}
		printf("%d\n",s);
	}

	return 0;
}

Measured memory_bytes: 596
n = int(input())
xy = []
idx = [None]*n
ys = [None]*n
ans = [None]*n
accumn = [None]*n
for i in range(n):
    x, y = map(int, input().split())
    idx[x-1] = i
    ys[x-1] = y-1
accumn[0] = ys[0]
for i in range(1, n):
    accumn[i] = min(accumn[i-1], ys[i])

b = 0
for i in range(n):
    if accumn[i]==n-i-1:
        for j in range(b, i+1):
            ans[idx[j]] = i-b+1
        b = i+1
print(*ans, sep='\n')

Measured memory_bytes: 37320
#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 EPS (1e-15)
#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--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll K, A, B, ans = 0;

	cin >> K >> A >> B;

	if (B - A <= 2 || K <= A - 1) ans = K + 1;
	else {
		K -= A - 1;
		ans = A + (K / 2) * (B - A) + K % 2;
	}

	cout << ans << endl;

	return 0;
}


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

typedef long long ll;

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

using namespace std;

struct UnionFind{
    vector<int> parent;
    vector<int> sizes;

    UnionFind(int n) : parent(n),sizes(n,1){
        for(int i=0;i<n;i++) parent[i] = i;
    }

    int root(int x){
        if(parent[x] ==  x) return x;
        return root(parent[x]);
    }

    bool group(int x,int y){
        if(root(x) == root(y)) return true;
        else return false;
    }

    void Union(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return ;
        if(sizes[rx] >= sizes[ry]){
            parent[ry] = rx;
            sizes[rx] += sizes[ry];
        }
        else {
            parent[rx] = ry;
            sizes[ry] += sizes[rx];
        }
        return ;
    }

    int renketu(int x){
        return sizes[root(x)];
    }
};

int main(){
    int N,M,K;
    cin >> N >> M >> K;
    vector<int> nakayosi(N,0);
    vector<int> block(N,0);
    UnionFind uf(N);
    for(int i=0;i<M;i++){
        int a,b;
        cin >> a >> b;
        nakayosi[--a]++;nakayosi[--b]++;
        uf.Union(a,b);
    }
    for(int i=0;i<K;i++){
        int a,b;
        cin >> a >> b;
        if(uf.group(--a,--b)){
            block[a]++;block[b]++;
        }
    }
    for(int i=0;i<N;i++){
        cout << uf.renketu(i)-nakayosi[i]-1-block[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
from collections import deque
import sys
input = sys.stdin.readline

S_deque = list(input())
S_deque = deque(S_deque[:-1])
Q = int(input())

top_flag = 1 # 0なら末尾、1なら最初

for _ in range(Q):
  item = list(input().split())
  if item[0] == '1':
    if top_flag == 0:
      top_flag = 1
    else:
      top_flag = 0

  else:
    in_flag = top_flag + int(item[1])
    if in_flag % 2 == 0:
      S_deque.appendleft(item[2])
    else:
      S_deque.append(item[2])

if top_flag == 0:
  S_deque.reverse()
else:
  pass

print(''.join(S_deque))

Measured memory_bytes: 8532
#include<stdio.h>

int main(){

  int a = 0;
  int b = 0;
  int c = 0;
  int cnt = 0;
  int x = 0;

  scanf("%d %d %d",&a,&b,&c);

  for( x = a; x <= b; x++){
    if(c % x == 0)
      cnt++;
  }
  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 2744
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x7fffffff
const int N = 100000+5;
const int Mod = 1e9+7;
map<string,int>mp;
int n,m,T,t;
stringstream ss;
string s;
vector<int>G[N];

 int main() {
    scanf("%d",&n);
    int cnt = 0;
    for(int i = 1;i <= n;i++) {
        m = n-i;
        for(int j = 1;j*j <= m;j++) {
            if(m%j==0) {
                cnt++;
                if(m/j!=j) cnt++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
 }


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

const int N = 1e5 + 33;
int t[N],dp[N],n, k;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;	
	for(int i = 1; i <= n; i++) {
		cin >> t[i];	
	}
	fill(dp , dp + n + 3, (int)1e9 + 33);
	dp[0] = dp[1] = 0;
	for(int i = 1; i <= n; i++) {	
		for(int j = 1; j <= k; j++) {
			if(i - j < 1)
				continue;
			dp[i] = min(dp[i], abs(t[i] - t[i - j]) + dp[i - j]);
		}
	}	
	cout << dp[n];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,c,d,flag=0;
  cin>>a>>b>>c>>d;
  while(a>0 && c>0)
  {
      if(flag==0)
      {
          c=c-b;
          flag=1;
      }
      else
      {
          a=a-d;
          flag=0;
      }
  }
  if(a>0)
    cout<<"Yes";
  else
  cout<<"No";
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    int n, m; cin >> n >> m;
    cout << n * m << "\n";
}



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

using namespace std;

int main()
{
    int  a[3][3];
    int n;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)cin >>a[i][j];
    }
    cin >>n;
    int b[n];
    for(int i=0;i<n;i++)cin >>b[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(b[i]==a[j][k])a[j][k]=-1;
            }
        }
    }
    vector<int >c(8,0);
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(a[i][j]!=-1)c[i]=1;
        }
    }
     for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(a[j][i]!=-1)c[i+3]=1;
        }
    }
    for(int i=0;i<3;i++){
        if(a[i][i]!=-1)c[6]=1;
    }
    c[7]=1;
    if(a[0][2]==-1&&a[1][1]==-1&&a[2][0]==-1)
        c[7]=0;
    bool ch=false;
    for(int i=0;i<8;i++){
        if(c[i]==0)ch=true;
    }
    if(ch)cout << "Yes"<< endl;
    else cout << "No"<< endl;
    return 0;
}


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

const int N = 3e3; 

int n;
bool seen[N][N];
ld p[N], dp[N][N];

ld solve(int i = 1, int head = 0) {
	if (i == n + 1) return (2 * head > n ? 1.0 : 0.0);
	if (seen[i][head]) return dp[i][head];
	seen[i][head] = 1;
	ld ans = 0;
	ld ret1 = solve(i + 1, head + 1) * p[i];
	ld ret2 = solve(i + 1, head) * (1.0 - p[i]);
	ans += ret1;
	ans += ret2;
	return dp[i][head] = ans;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	cin >> n;
	for (int i = 1; i <= n; ++i) 
		cin >> p[i];
	cout << fixed << setprecision(10);
	cout << solve() << "\n";
	return 0;
}


Measured memory_bytes: 148096
#include<bits/stdc++.h>
using namespace std;
unsigned long long n,m;
int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	if(n >= m / 2)
		cout << m / 2 << endl;
	else
		cout << (n + m / 2) / 2 << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
    int a,sum=1,sum2=1;
    cin >> a;
    for(int i=1; i<a; i++){
        sum*=2;
        if(sum>a){
            for(int j=1; j<i; j++){
                sum2*=2;
            }
            cout << sum2 << endl;
            return 0;
        }
        else if(sum==a){
            cout << sum << endl;
            return 0;
        }
    }
}


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

int N;
int a[3]; 
int b,c,d;

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    b = a[0]*a[0];
    c = a[1]*a[1];
    d = a[2]*a[2];
    if ( b + c == d ) {
    cout << "YES" << endl;
    } else {
    cout << "NO" << endl;
    }
  }
  
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

string s;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin  >> s;
    int n = s.size();
    rep(i, n - 1) {
      string tmp;
      rep(j, 2) tmp += s[i + j];
      if (tmp == "AC") {
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;

}


Measured memory_bytes: 256
def resolve():
    n,k=map(int,input().split())
    S=input()
    lr=0
    rl=0
    score=0
    for i in range(n-1):
        score+=(S[i]==S[i+1])
        lr+=(S[i]=="L" and S[i+1]=="R")
        rl+=(S[i]=="R" and S[i+1]=="L")
    print(score+min(k,lr)+min(k,rl))
resolve()

Measured memory_bytes: 39920
#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int main(){
    string s;cin>>s;
    int n=s.length();
    int ans=INF;
    for(int i=0;i<n-2;i++){
        int a=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        ans=min(ans,abs(a-753));
    }
    cout<<ans<<endl;
    return 0;
}   

Measured memory_bytes: 256
N = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(N):
  s = input()
  if s == "AC":
    AC += 1
  elif s == "WA":
    WA += 1
  elif s == "TLE":
    TLE +=1
  else:
    RE += 1
    
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

Measured memory_bytes: 9208
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define P 1000000007

long f(long a){
	long s=1;
	while(a!=0) s=s*(a--)%P;
	return s;
}

int main(void){
	int n, m;
	scanf("%d%d", &n, &m);
	if(n+1<m || m+1<n){
		puts("0");
	}else{
		printf("%d\n", f(n)*f(m)*((n==m)+1)%P);
	}
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int h, w, arr[2005][2005], hori[2005][2005], vert[2005][2005];

int main() {
    cin >> h >> w;
    for (int i=0; i<h; i++) {
        string a;
        cin >> a;
        for (int j=0; j<w; j++)
            arr[i][j] = (a[j] == '#' ? -1 : 0);
    }
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (arr[i][j] == -1) {
                int k = j-1;
                while (k>=0 && arr[i][k] == 0)
                    hori[i][k--] = hori[i][j-1];
            } else {
                hori[i][j] = (arr[i][j] == -1 ? 0 : !j || arr[i][j-1] == -1 ? 1 : hori[i][j-1]+1);
            }
        }
        int k = w-1;
        while (k>=0 && arr[i][k] == 0)
            hori[i][k--] = hori[i][w-1];
    }
    for (int i=0; i<w; i++) {
        for (int j=0; j<h; j++) {
            if (arr[j][i] == -1) {
                int k = j-1;
                while (k>=0 && arr[k][i] == 0)
                    vert[k--][i] = vert[j-1][i];
            } else {
                vert[j][i] = (arr[j][i] == -1 ? 0 : !j || arr[j-1][i] == -1 ? 1 : vert[j-1][i]+1);
            }
        }
        int k = h-1;
        while (k>=0 && arr[k][i] == 0)
            vert[k--][i] = vert[h-1][i];
    }
    int maxi = 0;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (hori[i][j] && vert[i][j]) maxi = max(maxi, hori[i][j]+vert[i][j]-1);
        }
    }
    cout << maxi << endl;
}

Measured memory_bytes: 47360
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}int n,sum = 0,m,a,b,q,x;
template <typename T>
struct BIT {
    int n;             // 要素数
    vector<T> bit[2];  // データの格納先
    BIT(int n_) { init(n_); }
    void init(int n_) {
        n = n_ + 1;
        for (int p = 0; p < 2; p++) bit[p].assign(n, 0);
    }
    void add_sub(int p, int i, T x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[p][idx] += x;
        }
    }
    void add(int l, int r, T x) {  // [l,r) に加算
        add_sub(0, l, -x * (l - 1));
        add_sub(0, r, x * (r - 1));
        add_sub(1, l, x);
        add_sub(1, r, -x);
    }
    T sum_sub(int p, int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[p][idx];
        }
        return s;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
};
int main() {
    cin >> n >> q; BIT<int> bit(n);
    rep(i, q) {
        cin >> a >> b >> m;
        if (a == 0) {
            bit.add_sub(0,b, m);
        }
        else {
            cout << bit.sum(m) - bit.sum(b - 1) << endl;
        }
    }
}


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

int main()
{
    int n, ans;
    cin >> n;
    if(n >= 100){
        ans = n % 100;
        ans = ans % 10;
    }
    else if(n < 100 && n >= 10) ans = n % 10;
    else ans = n;
    if(ans == 3) cout << "bon" << endl;
    else if(ans == 0 || ans == 1 || ans == 6 || ans == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0 ;
}


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

int main() {
  string x1,x2,x3;
  char c1,c2,c3;
  cin >> x1 >> x2 >> x3;
  c1 = x1.at(0);
  c2 = x2.at(0);
  c3 = x3.at(0);
  cout << c1 << c2 << c3 << endl;
  return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
n = int(input())
a = list(map(int, input().split()))
data = []
for i in range(1,n+1):
    for j in range(a[i-1]):
        data.append(str(i))

ans = []
for i in range(h):ans.append([])

count = 0
for i in range(h):
    for j in range(w):
        ans[i].append(data[count])
        count+=1

count = 0

for i in ans:
  if(count%2==0):print(' '.join(i))
  else:print(' '.join(list(reversed(i))))
  count+=1

Measured memory_bytes: 71956
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c) \
    for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\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;
}

typedef long long lint;

using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d;
    // lint max=0;
    cin >> d;
    vector<int> c(26), ans(d);
    vector<vector<int>> s(d, vector<int>(26));
    vector<int> last(26, 0);
    rep(i, 26) cin >> c[i];
    rep(i, d) rep(j, 26) cin >> s[i][j];
    rep(i, d) {
        auto a = s[i];
        map<int, int, greater<int>> m;
        rep(j, 26) { m.emplace(a[j] + (d - last[j]) * c[j], j); }
        ans[i] = (*m.begin()).second;
        last[ans[i]] = i + 1;
    }
    rep(i, d) cout << ans[i] + 1 << endl;
}

Measured memory_bytes: 3688
#include <stdio.h>
#include <math.h>
double x1, yy1, x2, y2, x3, y3;
double px, py, R;

void calc() {
	double sinA, sinB, sinC, cosA, cosB, cosC, sin2A, sin2B, sin2C;
	double a, b, c;

	a = sqrt(pow(x1 - x2, 2) + pow(yy1 - y2, 2));
	b = sqrt(pow(x2 - x3, 2) + pow(y2 - y3, 2));
	c = sqrt(pow(x3 - x1, 2) + pow(y3 - yy1, 2));

	cosA = (b * b + c * c - a * a) / (2 * b * c);
	cosB = (c * c + a * a - b * b) / (2 * c * a);
	cosC = (a * a + b * b - c * c) / (2 * a * b);
	sinA = sqrt(1 - cosA * cosA);
	sinB = sqrt(1 - cosB * cosB);
	sinC = sqrt(1 - cosC * cosC);

	sin2A = 2 * sinA * cosA;
	sin2B = 2 * sinB * cosB;
	sin2C = 2 * sinC * cosC;

	R = a / (2 * sinA);
	px = (sin2A * x3 + sin2B * x1 + sin2C * x2) / (sin2A + sin2B + sin2C);
	py = (sin2A * y3 + sin2B * yy1 + sin2C * y2) / (sin2A + sin2B + sin2C);
}

int main() {
	int n;
	int i;
//	double x1, y1, x2, y2, x3, y3;

	scanf("%d", &n);

	for (i = 0; i < n; ++i) {
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &yy1, &x2, &y2, &x3, &y3);
		calc();
		printf("%.3f %.3f %.3f\n", px, py, R);
	}

	return 0;
}

Measured memory_bytes: 664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int x, y;
    cin >> x >> y;
    set<int> a = {1, 3, 5, 7, 8, 10, 12};
    set<int> b = {4, 6, 9, 11};
    if(a.find(x) != a.end() && a.find(y) != a.end()) cout << "Yes" << endl;
    else if(b.find(x) != b.end() && b.find(y) != b.end()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
xys = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xys[i].append((x-1, y))

def digitsum(x):
    return bin(x).count('1')

ans = 0
for i in range(1<<n):
    ok = True
    for j in range(n):
        # if jth person may be honest, verify testimony of him.
        if (i>>j) & 1 == 1:
            for xy in xys[j]:
                x, y = xy
                if (i>>x) & 1 != y:
                    ok = False
                    break
        if not ok:
            break
    if ok:
        ans = max(ans, digitsum(i))
print(ans)

Measured memory_bytes: 42992
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> p(n);
  vector <int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    a[i] = i * n + 1;
    b[i] = (n - i) * n + 1;
  }
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
    b[p[i]] -= (n - 1 - i);
  }
  for (int i = 0; i < n; i++) {
    cout << a[i] << ' ';
  }
  cout << endl;
  for (int i = 0; i < n; i++) {
    cout << b[i] << ' ';
  }
}



Measured memory_bytes: 896
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int n) {
    for (int i = 1; true; i++) {
      if ((i + 1) * (i + 1) > n) {
        return i * i;
      }
    }
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    out.println(solve(n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 22996
#include<stdio.h>

int main(){
  int A[20],B[20],N,i,sum = 0;
  scanf("%d",&N);
  for(i = 0;i < N;i++){
    scanf("%d",&A[i]);
  }
  for(i = 0;i < N;i++){
    scanf("%d",&B[i]);
  }
  for(i = 0;i < N;i++){
    if(A[i] > B[i]){sum += A[i]-B[i];}
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include <iostream> 
using namespace std;
int main(void)
{
	int s;
	cin >> s;
	int h, m;
	h = s / 3600;
	s = s-h * 3600;
	m = s / 60;
	s = s-m * 60;
	cout << h << ":" << m << ":" << s<<endl;
}


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

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

    vector<int> A(N);
    long long ans = 0;
    int minimum = INT_MAX;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] > 0)
        {
            ans += A[i];
            minimum = min(minimum, A[i]);
        }
        else
        {
            ans -= A[i];
            minimum = min(minimum, -A[i]);
        }
    }

    for (int i = 0; i < N - 1; i++)
    {
        if (A[i] < 0)
        {
            A[i + 1] *= -1;
        }
    }
    if (A.back() < 0)
    {
        ans -= 2 * minimum;
    }
    cout << ans << endl;
}


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

int main()
{
  vector<uint64_t> divisor;
  uint64_t n;
  cin >> n;
  for (uint64_t i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      divisor.push_back(i);
      divisor.push_back(n / i);
    }
  }
  uint64_t ans(0);
  for (auto&& d : divisor) {
    auto m = d - 1;
    if (m == 0) continue;
    if (n / m == n % m) ans += m;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
/* ex5_4
  kt125*/

#include<stdio.h>
#include<string.h>

int main(void){
    int count = 0, ans=0;
    char str[11], *ptr;
    scanf("%s", &str[0]);

    //'A','G','C','T'の全てを'#'に置き換える。
    for(int i= 0; i< strlen(str);i++){
        if(str[i] == 'A' || str[i] == 'C' ||
           str[i] == 'G' || str[i] == 'T'){
               str[i] = '#';
        }
    }
    ptr = str; //strの先頭アドレスをptrに渡す
    //連続する'#'の最大数ansを求める
    while(*ptr){
        if( *ptr == '#'){ 
            count++;
            if(ans < count) ans = count;
        }else{ //'#'以外の文字が出たらcountをリセット
            count = 0;
        }
        ptr++;
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const ll INF = 1e18 + 10;

int N, M, S, T;
vector<P> G[200005][3];
int dist[200005][3];

int main() {
    cin >> N >> M;
    rep(i,M) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        G[u][0].emplace_back(v, 1);
        G[u][1].emplace_back(v, 2);
        G[u][2].emplace_back(v, 0);
    }
    cin >> S >> T;
    --S, --T;
    rep(i,200005) rep(j,3) dist[i][j] = -1;
    queue<P> q;
    q.push(P(S,0));
    dist[S][0] = 0;
    while(!q.empty()) {
        auto cur = q.front();
        q.pop();
        int u = cur.first;
        int mod = cur.second;
        for( auto child : G[u][mod]) {
            int v = child.first;
            int mv = child.second;
            if (dist[v][mv] != -1) continue;
            dist[v][mv] = dist[u][mod] + 1;
            q.push(P(v,mv));
        }
    }
    if (dist[T][0] == -1) cout << "-1" << endl;
    else cout << dist[T][0]/3 << endl;
}

Measured memory_bytes: 29276
import sys

n,m=map(int,raw_input().split())
list1 = [[0 for i in range(m)]for i in range(n)]
list2 = [[0 for i in range(1)]for i in range(m)]
list3 = [[0 for i in range(1)]for i in range(n)]
for i in range(n):
	list1[i] = map(int,raw_input().split())
for i in range(m):
	list2[i] = map(int,raw_input().split())
for i in range(n):
	for j in range(1):
		for k in range(m):
			list3[i][j] += list1[i][k] * list2[k][j]
for i in range(n):
	for j in range(1):
			print'%d' %list3[i][j]

Measured memory_bytes: 6580
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
per=LI()
for i in range(n):
    per[i]-=1
points=LI()
ans=-inf
for i in range(n):
    val=0
    #res=[0 for j in range(n+1)]
    res=[]
    pos=per[i]
    inipos=per[i]
    count=0
    while True:
        val+=points[pos]
        pos=per[pos]
        if len(res)==0:
            res.append(val)
        else:
            res.append(max(res[-1],val))
        #res[count]=max(val,res[count-1])
        count+=1
        if pos==inipos:
            break
    loop=(val,count)
    #print(loop)
    #print(res)
    for x in range(len(res)):
        if loop[0]<=0:
            ans=max(ans,res[x])
        else:
            ans=max(ans,res[x]+loop[0]*((k-x-1)//loop[1]))
print(ans)
        
        
        
        
        
        
    
    
    
        
        
        
        
        
            
            

Measured memory_bytes: 77752
using System;

class Program{
	static void Main(string[] args){
    	int N = int.Parse(Console.ReadLine());
      	int K = int.Parse(Console.ReadLine());
      	int X = int.Parse(Console.ReadLine());
       	int Y = int.Parse(Console.ReadLine());
      
      	if(N>= K)
        {
          Console.WriteLine((K * X) + ((N - K) * Y));
        }else{
        	Console.WriteLine(N * X);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

const long long INF = 1LL << 60;
const int MAX_V = pow(10, 3) * 100 + 1;

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

    int MAX_N = N + 1;

    vector<long long> weight(MAX_N), value(MAX_N);
    for (int i = 0; i < N; ++i)
        cin >> weight[i] >> value[i];

    vector<vector<long long>> dp(MAX_N, vector<long long>(MAX_V, INF));

    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i)
    {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v)
        {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0)
                chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v)
    {
        if (dp[N][sum_v] <= W)
            res = sum_v;
    }
    cout << res << endl;
}


Measured memory_bytes: 80256
#include <stdio.h>

int main(void) {
    int a;
    int b;
    scanf("%d %d\n",&a,&b);
    
    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else if(a == b) {
        printf("a == b\n");
    }
}


Measured memory_bytes: 2036
// Problem : C - Walking Takahashi
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll x, k, d;
	cin >> x >> k >> d;
	x = llabs(x);
	ll ile = x / d;
	ll mod = (x % d);
	x = (x - min(ile, k) * d);
	k -= min(k, ile);
	if (k % 2 == 0) cout << abs(x);
	else cout << abs(x - d);
	return 0;
}
 


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace  std ;
typedef long l ;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c,d,e,x,i,j,n,t,m,k,y,s;
    ll arr[3] ;
    cin>>arr[0]>>arr[1]>>arr[2] ;
    sort(arr,arr+3);
    cout<<(arr[0]*arr[1])/2 ;
}

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

const ll MAXN = 200000;

ll N, ans=0, tmp=0;
vector<ll> A(MAXN, 0);
vector<vector<pair<ll,ll>>> G;

void dfs(ll now, ll pre, ll c) {
    A[now] = c;
    for(int i=0;i<G[now].size();i++) {
        if(G[now][i].first==pre) continue;
        else {
            if(G[now][i].second%2==1) dfs(G[now][i].first,now,1-c);
            else dfs(G[now][i].first,now,c);
        }
    }
}

signed main(){
    cin >> N;
    G.resize(N);
    for(int i=0;i<N-1;i++) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(make_pair(v,w));
        G[v].push_back(make_pair(u,w));
    }
    dfs(0,-1, 0);
    for(int i=0;i<N;i++) {
        cout << A[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10880
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD 1e9+7
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}

int main()
{
	fast
	int n;
	cin>>n;
	unordered_map <string,int> mp;
	REP(i,n)
	{
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<endl;
	cout<<"WA x "<<mp["WA"]<<endl;
	cout<<"TLE x "<<mp["TLE"]<<endl;
	cout<<"RE x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
ll power(ll x, ll y, ll p) { 
    ll res = 1;    x = x % p;  
    while(y > 0) {
        if(y & 1) res = (res*x) % p; 
        y = y>>1;    x = (x*x) % p; 
    } return res; 
}
int main()
{
    Imposter
    
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n,k;
        cin>>n>>k;
        ll p=k-(n%k);
        ll q=n%k;
        cout<<min(p,q)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

double cut(int r,int n,int i){
    double res=r*r-(r-r*(double)i/(double)n)*(r-r*(double)i/(double)n);
    return pow(res,0.5)*2;
}

int main(){
    int n;cin>>n;
    int a[n];
    ll sumr=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i>0) sumr+=a[i];
    }
    ll suml=a[0];
    ll ans=sumr-suml;
    for(int i=1;i<n-1;i++){
        suml+=a[i];
        sumr-=a[i];
        ans=min(ans,abs(suml-sumr));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#define M 100000

int p(int i) {
	return i / 2;
}

int l(int i) {
	return 2 * i;
}

int r(int i) {
	return 2 * i + 1;
}

int main(void) {
	int h, i, a[M + 1];
	scanf("%d",  &h);
	for (i = 1; i <= h; i++) {
		scanf("%d", &a[i]);
	}
	for (i = 1; i <= h; i++) {
		printf("node %d: key = %d, ", i, a[i]);
		if (p(i) >= 1) {
			printf("parent key = %d, ", a[p(i)]);
		}
		if (l(i) <= h) {
			printf("left key = %d, ", a[l(i)]);
		}
		if (r(i) <= h) {
			printf("right key = %d, ", a[r(i)]);
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2048
N = int(input())
a = []
former = 0
count = 0
for i in range(N):
    a = int(input())
    if former == 0:
        former = a%2
        count += a//2
    else:
        if a%2==0:
            if a!=0:
                former = 1
                count += a//2
            else:
                former = 0
        else:
            former = 0
            count += a//2+1 
    
    
print(count)
    

Measured memory_bytes: 44008
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n; cin >> n;
  vector<ll> a(n); cin >> a;
  vector<ll> Sl(n+1, 0), Sr(n+1, 0);
  rep(i, n) Sl[i+1] = Sl[i] + a[i];
  rrep(i, n) Sr[i] = Sr[i+1] + a[i];
  vector<vector<ll>> dp(n+1, vector<ll>(5, linf));
  dp[0][0] = 0;
  rep(i, n) {
    rep(j, 5) {
      if (dp[i][j] == linf) continue;
      // cout << i << " " << j << ": " << dp[i][j] << endl;
      if (j < 4) {
        chmin(dp[i][j+1], dp[i][j]);
      }
      // mode 0, 4
      if (j == 0 || j == 4) {
        chmin(dp[i+1][j], dp[i][j] + a[i]);
      }
      // mode 1, 3
      if (j == 1 || j == 3) {
        ll cost = a[i] == 0 ? 2 : a[i] == 1 ? 1 : a[i] % 2;
        chmin(dp[i+1][j], dp[i][j] + cost);
      }
      // mode 2
      if (j == 2) {
        ll cost = a[i] == 0 ? 1 : 1 - a[i] % 2;
        chmin(dp[i+1][j], dp[i][j] + cost);
      }
    }
  }
  ll ans = linf;
  rep(j, 5) chmin(ans, dp[n][j]);
  cout << ans << endl;
}


Measured memory_bytes: 19080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  cin >> N;
  vector <string>vec (N);
  for( long long i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  long long ans =1;
  sort(vec.begin(), vec.end());
    for( long long i =0; i <(N-1); i++){
      if(vec.at(i) != vec.at(i+1)){
        ans ++;
      }
    }
  cout << ans << endl;
}
        


Measured memory_bytes: 9596
def gcd(a, b):
    while a:
        b, a = a, b % a
    return b


s = 0
n = int(input())


for i in range(1, n+1):
    for j in range(i+1, n+1):
        for k in range(j+1, n+1):
            s += gcd(gcd(i,j), k)

for i in range(1, n+1):
    for j in range(i+1, n+1):
        s += gcd(i, j)

s = s*6 + int(0.5 * n * (n+1))
print(s)

Measured memory_bytes: 9140
#include<iostream>
#include<float.h>
#include<cfloat>
#include<string>
#include<ctype.h>
#include<algorithm>
#include<errno.h>
#include<cerrno>
#include<assert.h>
#include<cassert> 
#include<map>
#include<memory.h>
#include<cctype>
#include<ctype.h>
#include<math.h>
#include<vector> 
#include<cstdio> 
#include<set>
#include<string.h>
#include<stdio.h>
#include<new>
#include<memory>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
#define fo(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define br break
#define ct continue
#define pb push_back
#define pi 3.141592653589793238462643383279502884197169
#define F first
#define S second
#define pii pair<int,int>  
#define em empty()
#define vei vector<int>
#define ves vector<string>
#define qui queue<int> 
#define qu queue
using namespace std;
int main()
{int a,b,c;
 cin>>a>>b>>c;
 cout<<(a+b)*c/2; 
 system("pause");
 return 0;
}

Measured memory_bytes: 504
n = int(input())
a = []
i = 0
while i < n:
    a.append(int(input()))
    i += 1

#print(a)
#すべての要素が偶数なら負け
#＝一つでも奇数の要素があれば勝ち
result = 'second'
for j in a:
    if j % 2 != 0:
        result = 'first'
        break
print(result)

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

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

	if (b / a < c)
	{
		cout << b / a << endl;

	}
	else
	{
		cout << c << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define eps 1e-8
//#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 998244353;
long double PI = acosl(-1);
const ll infl = 3e18+100;
const int inf = 1e8+100;
const int nmax = 3000+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

int dp[nmax][nmax];
int a,b;
//
//ll nc2(ll x){
//    return x*(x-1)/2 % mod;
//}
//
//ll power(ll a, ll p, ll M = mod){
//    ll ret = 1, x = a;
//    while(p){
//        if(p%2) ret = (ret * x) % mod;
//        p/=2;
//        x = (x * x)%mod;
//    }
//    return ret;
//}

int recc(int n, int m){
    if(n<a or m<b) return 0;
    if(n==a and m==b) return 1;
    if(dp[n][m]!=-1) return dp[n][m];

    dp[n][m] = 1LL*recc(n,m-1)*n%mod +  1LL*recc(n-1,m)*m%mod - 1LL*recc(n-1, m-1)*(n-1)*(m-1)%mod ;
    dp[n][m] = (dp[n][m]%mod + mod)%mod;
    return dp[n][m];
}

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

    memset(dp, -1, sizeof dp);

    int c,d;
    cin>>a>>b>>c>>d;
    cout<<recc(c,d)<<"\n";

}


Measured memory_bytes: 39244