akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int S = int.Parse(input);
            int h = S/3600;
            int m = S/60%60;
            int s = S%60;
            Console.WriteLine(h + ":" + m + ":" + s);
        }
    }
}


Measured memory_bytes: 17928
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  vector<long long> multi(4);
  
 multi.at(0) = a * c;
 multi.at(1) = a * d;
 multi.at(2) = b * c;
 multi.at(3) = b * d;
  
    sort(multi.begin(), multi.end()); 
    reverse(multi.begin(), multi.end());
    
  cout << multi.at(0) << endl;
  
  
}

Measured memory_bytes: 3616
#include<cstdio>
#include<algorithm>
#define MN 100001
using namespace std;

int t,n,ans=0,b,a[MN],bo;
int main(){
	scanf("%d%d",&n,&b);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for (int i=1;i<n;i++)
	if (b>=a[i]) b-=a[i],ans++;
	if (b==a[n]) ans++;
	printf("%d\n",ans);
} 

Measured memory_bytes: 128
import bisect
import sys
sys.setrecursionlimit(500000)

def LIS(lis):

    seq = []

    for c in lis:
        ind = bisect.bisect_left(seq,c)

        if ind == len(seq):
            seq.append(c)
        else:
            seq[ind] = c

    return len(seq)


N = int(input())

a = list(map(int,input().split()))

lis = [ [] for i in range(N) ]

for i in range(N-1):

    u,v = map(int,input().split())
    u -= 1
    v -= 1

    lis[u].append(v)
    lis[v].append(u)

ans = [None] * N

def dfs(v,p,ln):

    ind = bisect.bisect_left(ln,a[v])

    if ind == len(ln):
        mt = None
        ln.append(a[v])
    else:
        mt = ln[ind]
        ln[ind] = a[v]

    ans[v] = len(ln)

    for nex in lis[v]:

        if nex != p:
            dfs(nex,v,ln)

    if mt == None:
        del ln[-1]
    else:
        ln[ind] = mt

    return

dfs(0,0,[])

for i in range(N):
    print (ans[i])
    


Measured memory_bytes: 223268
"""
dp[i][j]　=> i行目j列目がゴールの場合の最大値
"""
def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*(C) for _ in range(R)]

    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[0]*4 for _ in range(C)]
    dp[0][1] = items[0][0]
    for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i==0 and j == 0:
                continue

            if i!=0:
                #上から入る場合のシミュレート
                dp[j][0] = max(dp[j])
                if v:
                    dp[j][1] = dp[j][0]+v

            if j!=0:
                #左から入る場合のシミュレート
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v:
                    #itemが存在する場合の処理
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k-1]+v,dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
    print(max(dp[-1]))
main()


Measured memory_bytes: 145868
#include <iostream>

using namespace std;

int main()
{
    string S, T;
    cin >> S >> T;

    int cnt = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] != T[i])
        {
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3912
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,M = MI()
X,Y = LI(),LI()
mod = 10**9+7

r = sum((i*(N-i)*(X[i]-X[i-1])) % mod for i in range(1,N))
r %= mod

ans = 0
for i in range(1,M):
    ans += r*i*(M-i)*(Y[i]-Y[i-1]) % mod
    ans %= mod

print(ans)


Measured memory_bytes: 97196
import itertools

n,k = map(int,input().split())
x = list(map(int,input().split()))

pos = [0]
neg = []
for i in x:
    if i<0:
        neg.append(-i)
    else:
        pos.append(i)
neg = [0] + neg[::-1]

# negを往復する場合
neg_twice = []
for i in range(min(len(neg),k)):
    neg_twice.append(neg[i]*2)
for i in range(len(neg_twice)):
    if k-i<len(pos):
        neg_twice[i] += pos[k-i]
    else:
        neg_twice[i] = float('inf')
# posを往復する場合
pos_twice = []
for i in range(min(len(pos),k)):
    pos_twice.append(pos[i]*2)
for i in range(len(pos_twice)):
    if k-i<len(neg):
        pos_twice[i] += neg[k-i]
    else:
        pos_twice[i] = float('inf')
print(min(pos_twice+neg_twice))


Measured memory_bytes: 15636
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
chk = True
s = sum(A)
for i in range(m):
    if A[i] >= s/(4*m):
        pass
    else:
        chk = False
if chk == True:
    print('Yes')
else:
    print('No')

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

using namespace std;

int main(){
  string s;
  cin >> s;
  if (s[0]==s[1]&&s[0]==s[2])cout << "Yes" <<endl;
  else if (s[1]==s[2]&&s[1]==s[3])cout << "Yes" <<endl;
  else cout << "No" << endl;
  return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll N, H, W;
    cin >> N >> H >> W;
    ll ans = 0;
    REP(i, N)
    {
        ll a, b;
        cin >> a >> b;
        if (a >= H && b >= W)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int countDivisors(int n) 
{ 
    int cnt = 0; 
    for (int i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
int main(){
	int n;
	cin>>n;
	int count=0;
	for(int i=1;i<n;i++){
		int temp=n-i;
		int ctr=countDivisors(temp);
		count += ctr;
	}
	cout<<count<<'\n';
	
	
	return 0;
}


Measured memory_bytes: 3676
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int A, B, X;
	cin >> A >> B >> X;
	if (A <= X && X <= A + B)cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    if sum(a*b for (a,b) in zip(A[i],B))+C > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	double n;
	cin >> n;
	vector<double> a(n);
	for( auto &i : a ) cin >> i;
	double avg = ( accumulate( a.begin(), a.end(), 0.0 ) ) / n;
	double mini = 100000.0;
	for( int i = 0; i < n; ++i ){
		mini = min(mini, abs(a[i]-avg));
	}
	for( int i = 0; i < n; ++i ){
		if( abs(a[i]-avg) == mini ){
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x, y, crane, turtle;
	bool result = false;
	cin >> x >> y;
	if (y % 2 == 1) {
		result = false;
	} else {
		crane = y / 2;
		turtle = y / 4;
		if (x > crane || x < turtle) {
			result = false;
		} else {
			turtle = 0;
			while (crane >= 0) {
				if (crane + turtle == x) {
					result = true;
					break;
				}
				crane -= 2;
				turtle++;
			}
		}
	}
	if (result) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3632
n=int(input())
*a,=map(int,input().split())
mod=10**9+7
col=[0]*(n+1)
col[0]=3

ans=1

for i in range(n):
    ans*=col[a[i]]
    col[a[i]]-=1
    col[a[i]+1]+=1
    ans%=mod

print(ans%mod)


Measured memory_bytes: 87392
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>
#include <string.h>

using std::endl;
using std::string;

#define ll long long int
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 123456789012345
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std

ll N;
string data[123];


int main()
{
	IN >> N;

	LEP(a, N)
	{
		IN >> data[a];
	}

	for (int a = 0; a < N; ++a)
	{
		for (int b = a + 1; b < N; ++b)
		{
			if (data[a] == data[b])
			{
				OUT << "No" << endl;
				return 0;
			}
		}
	}

	for (int a = 1; a < N; ++a)
	{
		if (data[a - 1][data[a - 1].length() - 1] != data[a][0])
		{
			OUT << "No" << endl;
			return 0;
		}
	}

	OUT << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;
const ll MOD = 1e9+7;

bool comp(P &lhs, P &rhs)
{
	if(lhs.first==rhs.first)
		return lhs.second>rhs.second;
	else
		return lhs.first<rhs.first;
}

int main()
{
	map<P,int> mp;
	P p[100];
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;
		int f;
		cin>>s>>f;
		p[i]=P(s,f);
		mp[p[i]]=i+1;
	}
	sort(p,p+n,comp);
	for(int i=0;i<n;i++)
		cout<<mp[p[i]]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main() {
    int A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
        cout << "Possible";
    } else {
        cout << "Impossible";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	vector<pair<string, pair<int, int>>> r_list(N, make_pair("", make_pair(0, 0)));

	for (int i = 0; i < N; i++)
	{
		cin >> r_list[i].first >> r_list[i].second.first;
		r_list[i].second.second = i + 1;
	}

	sort(r_list.begin(), r_list.end(), [](const pair<string, pair<int, int>>& l, const pair<string, pair<int, int>>& r)
	{
		if (l.first == r.first) return l.second.first > r.second.first;
		return l.first < r.first;
	});

	for (int i = 0; i < N; i++)
	{
		cout << r_list[i].second.second << "\n";
	}

	return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int GCD(int A, int B){
  if (A < B) swap(A, B);
  while (A % B != 0){
    A %= B; swap(A, B);
  }
  return B;
}

bool Judge_Prime(int num){
  if (num == 1) return false;
  for (int i = 2; i * i <= num; i++){
    if (num % i == 0) return false;
  }
  return true;
}

int N, A[int(1e6+5)];
vector <int> Prime = {2};
map <int, bool> used;

int main(){
  for (int i = 3; i <= 1e3; i += 2){
    if (Judge_Prime(i)) Prime.push_back(i);
  }

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

  int G = A[0];
  for (int i = 0; i < N; i++) G = GCD(G, A[i]);

  if (G > 1){
    cout << "not coprime" << endl;
    return 0;
  }

  for (int i = 0; i < N; i++){
    int num = A[i];
    for (int j : Prime){
      if (num % j != 0) continue;
      if (used[j]){
        cout << "setwise coprime" << endl;
        return 0;
      }
      used[j] = true;
      while (num % j == 0) num /= j;
    }
    if (num > 1){
      if (used[num]){
        cout << "setwise coprime" << endl;
        return 0;
      }
      used[num] = true;
    }
  }

  cout << "pairwise coprime" << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//char ch;
//string S, T, U;
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

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

    cin>>n>>h>>w;
    forr(i,n)
    {
        cin>>x>>y;
        if((x-h)>=0 && (y-w)>=0)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#define int long long
using namespace std;

const int INF = 1e10;
const int ZERO = 0;
int gcd(int a,int b) {
	if(a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
	int r = a % b;
	while(r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
signed main() {
	int N,K;
	cin >> N >> K;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	int A = vec.at(0);
	if(K > A) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		int G = vec.at(0);
		for(int i = 1;i < N;i++) {
			G = gcd(G,vec.at(i));
		}
		if(G == 1) {
			cout << "POSSIBLE" << endl;
		}
		else if(K % G == 0) {
			cout << "POSSIBLE" << endl;
		}
		else {
			cout << "IMPOSSIBLE" << endl;
		}
	}
}	



Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
int main(){
    int i;
    int max=0;
    int k,n;
    cin>>k>>n;
    vector <int> a;
    rep(i,n){
        int t;
        cin>>t;
        a.push_back(t);
    }
    rep(i,n-1){
        int temp=a[i+1]-a[i];
        if(max<temp){
            max=temp;
        }
    }
    if(((k-a[n-1])+a[0])>max){
        cout<<k-((k-a[n-1])+a[0])<<endl;
        return 0;
    }else{
        cout<<k-max;
    }
}


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

int main(){
	string S;
  	int a = 1e9,z = 0;
  	cin >> S;
  	for(int i=0;i<S.size();i++){
      if(S[i]=='A') a = min(a,i);
      if(S[i]=='Z') z = max(z,i);
    }
  	cout << z-a+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int ans = 0;
  int sum =0;
  for(int i =0;i<n;i++){
    char s;
    cin >> s;
    if( s =='I'){
      sum++;
      ans  = max(sum,ans);
    }
    else{
      sum--;
    }
  }
  cout << ans;
      
}

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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
	int N;

	cin >> N;
	vector<int> X( N );
	vector<int> Y( N );
	UnionFind uf( N );
	map<int, int> xmap;
	map<int, int> ymap;
	for( int i = 0; i < N; i++ ) {
		cin >> X[i] >> Y[i];
		if( xmap.count( X[i] ) ) {
			uf.unionSet( i, xmap[ X[i] ] );
		}
		xmap[ X[i] ] = i;
		if( ymap.count( Y[i] ) ) {
			uf.unionSet( i, ymap[ Y[i] ] );
		}
		ymap[ Y[i] ] = i;
	}

	vector<set<int>> xset( N );
	vector<set<int>> yset( N );
	for( int i = 0; i < N; i++ ) {
		xset[ uf.root( i ) ].insert( X[i] );
		yset[ uf.root( i ) ].insert( Y[i] );
	}
	long long ans = 0;
	for( int i = 0; i < N; i++ ) {
		ans += (long long)xset[i].size() * yset[i].size();
	}
	ans -= N;

	cout << ans << endl;
}


Measured memory_bytes: 20224
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
struct node{
    int a;
    vi to;
    vi edge_id;
};
int K;
void dfs(int v, int p, vector<node> &nodes, vi &color, int p_color){
    K=max(K,(int)nodes[v].to.size());
    int color_id=1;
    for (int i = 0; i < nodes[v].to.size(); i++){
        int v_to=nodes[v].to[i];
        if(v_to==p)continue;
        if(color_id==p_color)color_id++;
        color[nodes[v].edge_id[i]]=color_id;
        dfs(v_to, v, nodes, color, color_id);
        color_id++;
    }
}
int main() {
    int N;
    cin>>N;
    K=0;
    vector<node> nodes(N);
    vi color(N-1,0);
    for (int i = 0; i < N-1; i++){
        int u,v;
        cin>>u>>v;u--;v--;
        nodes[u].to.push_back(v);
        nodes[v].to.push_back(u);
        nodes[u].edge_id.push_back(i);
        nodes[v].edge_id.push_back(i);
    }
    dfs(0,-1,nodes,color,0);
    cout<<K<<endl;
    for(int x : color)cout<<x<<endl;
}

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

int main() {

  int n;
  cin >> n;

  string c = "0123456789";

  for ( int i = 0; i < n; i++ ) {

    string input1,input2;
    cin >> input1 >> input2;
    if ( input1.size() > 80 || input2.size() > 80 ) {
      cout << "overflow" << endl;
      continue;
    }

    string ans = "";

    int k = 0;
    for ( int j = 0; j < 80; j++ ) {

      int x = input1.size()-1-j;
      if ( x >= 0 ) {
	k += input1[x] - '0';
      }
      int y = input2.size()-1-j;
      if ( y >= 0 ) {
	k += input2[y] - '0';
      }
      ans = c[k%10] + ans;
      k /= 10;

    }

    if ( k != 0 ) {
      cout << "overflow" << endl;
    }else {
      bool flag = true;
      for ( int i = 0; i < ans.size(); i++ ) {
	if ( ans[i] == '0' && flag ) continue;
	flag = false;
	cout << ans[i];
      }
      if ( flag ) cout << "0";
      cout << endl;
    }

  }

  return 0;

}

Measured memory_bytes: 1212
n,m = map(int, input().split()) 
h_list = list(map(int, input().split())) 

connected_list = [ [] for _ in range(n) ]
for i in range(m):
    a,b = map(int, input().split()) 
    a-=1
    b-=1
    connected_list[a].append(b)
    connected_list[b].append(a)

res_cnt = 0
for tenbo_i in range(n):
    h = h_list[tenbo_i]
    connecteds = connected_list[tenbo_i]
    res = True
    for c_tenbo_i in connecteds:
        cmp_h = h_list[c_tenbo_i]
        if h <= cmp_h:
            res = False
            break
    if res:
        res_cnt+=1

print(res_cnt)

Measured memory_bytes: 29368
def pow_mod(MOD, a, n):
    ret = 1
    while n != 0:
        if n % 2 == 1: ret = ret * a % MOD
        a = a * a % MOD
        n //= 2
    return ret

def fac(n):
    MOD = 1000000007
    ret = 1
    for i in range(1, n + 1):
        ret = ret * i % MOD
    return ret

def fac_gen(first, last):
    MOD = 1000000007
    ret = fac(first)
    yield ret
    for i in range(first + 1, last):
        ret = ret * i % MOD
        yield ret

def build_comb_list(f, m, K):
    MOD = 1000000007
    v = pow_mod(MOD, f[m - K * 2] * f[0], MOD - 2)
    for i in range(m - K, -1, -1):
        f[i] *= v
        v = v * i % MOD

def solve_dp(n, k, comb):
    MOD = 1000000007
    dp = [1] * (n + 1)
    for i in range(2, n + 1):
        ci = (i - 1) * (k - 1)
        v = 0
        for j, c in zip(range(i), comb[ci:ci + i]):
            v = (v + dp[j] * c) % MOD
            dp[j] = v
        dp[i] = v
    return dp[n] * fac(n) % MOD

def solve(n, k):
    if n == 1 or k == 1: return 1
    m = n * k
    comb = list(fac_gen(k - 2, m - 1))
    build_comb_list(comb, m - 2, k - 2)
    return solve_dp(n, k, comb)


n, k = (int(s) for s in input().split(' '))
print(solve(n, k))


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

struct Rest {
    int n;
    int p;
    std::string s;
};

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

    std::string S;
    int P;
    std::vector<Rest> l;
    for (int i = 0; i < N; ++i) {
        std::cin >> S >> P;
        l.push_back({i + 1, P, S});
    }

    std::sort(l.begin(), l.end(), [](const auto& lhs, const auto& rhs) {
        if (lhs.s != rhs.s) {
            return lhs.s < rhs.s;
        } else {
            return lhs.p > rhs.p;
        }
    });

    for (const Rest& rest : l) {
        std::printf("%d\n", rest.n);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int,int> >
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = 1e9+7;
const LL INF = 1LL<<60;
const double eps = 1e-13;

LL a[500009];
LL rs[500009];

int main(){
	DRI(n);
	REP(i,n){
		scanf("%lld",&a[i]);
		rs[i+1]=rs[i]+a[i];
	}
	LL ans=INF;
	rs[n+1]=rs[n];
	REPP(i,1,n){
		ans=min(ans,abs(rs[i]-(rs[n]-rs[i])));
	}
	printf("%lld",ans);
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int x;
  cin >> x;
  int n500, n5;
  n500 = x / 500;
  x -= 500 * n500;
  n5 = x / 5;
  cout << int(1000 * n500 + 5 * n5) << endl;
  return 0;
}


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

int main(){
    int n;
    while(cin >> n, n){
        int age, count[7] = {0, 0, 0, 0, 0, 0, 0};
        while( n-- > 0 ){
            cin >> age;
            if( age <= 60 ) count[age/10]++;
            else count[6]++;
        }
        for(int i = 0; i < 7; i++){
            cout << count[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e6+1;
 
typedef long long ll;
typedef long double ld;

ll spf[N]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<N; i++) 
        spf[i] = i; 
  
    for (ll i=4; i<N; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<N; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<N; j+=i)             
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
vector<ll> getFactorization(ll x) 
{ 
    vector<ll> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 
void test_case()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    sieve();
    for(ll i = 0; i < n; i++)
    {
    	cin >> v[i];
    }
    vector<bool> done(N, 0);
    bool flag = 0;
    for(ll i = 0; i < n; i++)
    {
    	vector<ll> p = getFactorization(v[i]);
    	for(ll j = 0; j < p.size(); j++)
    	{
    		if(done[p[j]])
    		{
    			flag = 1;
    			break;
    		}
    	}
    	for(ll j = 0; j < p.size(); j++)
    	{
    		done[p[j]] = 1;
    	}
    	if(flag)
    		break;
    }
    if(!flag)
    {
    	cout << "pairwise coprime\n";
    	return;
    }
    ll gg = v[0];
    for(int i = 1; i < n; i++)
    {
    	gg = __gcd(gg, v[i]);
    }
    if(gg == 1)
    {
    	cout << "setwise coprime\n";
    	return;	
    }
    cout << "not coprime\n";


}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


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

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

    if (abs(a-b)>1)
        cout << 2*max(a,b)-1;
    else if (a==b)
        cout << 2*a;
    else
        cout << a+b;    
    return 0;
}

Measured memory_bytes: 256
c11c12c13=input()
c21c22c23=input()
if c11c12c13[0]==c21c22c23[2] and c11c12c13[1]==c21c22c23[1] and  c11c12c13[2]==c21c22c23[0]:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
//
//  main.cpp
//  contest
//
//  Created by S M HEMEL on 27/1/18.
//  Copyright © 2018 Eastern University. All rights reserved.
//

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string s,s1;
    cin >> s >> s1;
        int la=(int)s.size();
        int lb=(int)s1.size();
        sort(s.begin(),s.end());
        sort(s1.begin(),s1.end());
        if(s[0]<s1[lb-1]) return 0 * puts("Yes");
        else if(s[0]>s1[lb-1]) return 0 * puts("Yes");
        if(s[0]==s[la-1]&&s1[0]==s1[lb-1]&&s[0]==s1[0]){
            if(lb>la) return 0 * puts("Yes");
            else return 0 * puts("No");
        }
        int k=0;
        for(int i=0;i<la;i++)
            for(int j=0;j<lb;j++)
                if(s1[j]>s[i]){
                    k++;
                    break;
                    }
        if(k==la) puts("Yes");
        else puts("No");
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p.at(i);

    int answer = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (p.at(i) == i + 1)
        {
            answer++;
            swap(p.at(i), p.at(i + 1));
        }
    }
    if (p.at(n - 1) == n)
    {
        answer++;
        swap(p.at(n - 1), p.at(n - 2));
    }
    cout << answer << endl;
}

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

using namespace std;

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

  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    ans += s[i] == t[i];
  }
  cout << ans << '\n';
  return 0;
} 

Measured memory_bytes: 256
N = int(input())
T, A = [int(i) for i in input().split()]
candidates = [int(i) for i in input().split()]

def calcDiffAveTemp(height):
    temp = T - (height * 0.006)
    diffA = abs(A-temp)
    return diffA

diffs = [calcDiffAveTemp(h) for h in candidates]

print(diffs.index(min(diffs))+1)


Measured memory_bytes: 3060
n,m=map(int,input().split())
if m==1 and n==1:
  s,c=map(int,input().split())
  print(c)
elif m!=0:
  p=0
  a=[-1 for s in range(n)]
  for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
      p+=1
      break
    elif a[s-1]==-1 or a[s-1]==c:
      a[s-1]=c
    else:
      p+=1
      break

  if p==0:
    num=0
    for i,j in enumerate(reversed(a)):
      if j == -1 and i+1 ==len(a):
        j=1
      elif j == -1:
        j=0
      num += j*(10**i)
    print(num)
  else:
    print(-1)
else:
  if n==1:
    print(0)
  elif n ==2:
    print(10)
  else:
    print(100)

Measured memory_bytes: 3064
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use im_rc::HashMap;


#[fastout]
fn main() {
    input! {
    n: usize,
    mut s: [Chars; n]
    }
    let mut map = HashMap::new();
    for i in 0..n {
        s[i].sort();
        map.entry(s[i].iter().collect::<String>()).and_modify(|e| *e += 1).or_insert(1);
    };
    let mut ans:usize = 0;
    for i in map.keys() {
        let t  = map[i];
        ans += t * (t - 1) / 2;
    }
    println!("{}", ans);
}



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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long double PI2 = 6.28318530717958623200;
    int r;
    cin >> r;
    cout << fixed << setprecision(15) << r * PI2 << endl; 
    return 0;
}

Measured memory_bytes: 3724
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); sc.nextLine();
		boolean flg = true;
		int cnt = 0;
		for(int i=0;i<n;i++) {
			String[] s = sc.nextLine().split(" ");
			if( s[0].equals("(") ) cnt += Integer.parseInt(s[1]);
			if( s[0].equals(")") ) cnt -= Integer.parseInt(s[1]);
			if( cnt < 0 ) flg = false;
		}
		if( flg && cnt == 0 ) System.out.println("YES");
		else System.out.println("NO");
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 26152
#include <iostream>
#include <algorithm>
using namespace std;
int n;
string ss;
int main()
{
    cin>>n>>ss;
    int ans=1;
    for(register int i=1;i<n;i++)
        if(ss[i]!=ss[i-1]) ans++;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "Yes";
const string NO  = "No";

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

    int n;
    bool flg = false;

    cin >> n;

    while (n != 0) {
        if (n % 10 == 9) {
            flg = true;
            break;
        }
        n /= 10;
    }

    cout << (flg ? YES : NO) << endl;

    return 0;
}



Measured memory_bytes: 256
package main

import "fmt"

var x, y int

func main() {
	fmt.Scan(&x, &y)

	flug := false

	for a := 0; a < x+1; a++ {
		b := x - a
		if 2*a+4*b == y {
			flug = true
			break
		}
	}

	if flug {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

Measured memory_bytes: 1768
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    cnt=10**5
    m=len(format(cnt, 'b'))
    dp=[[-1 for j in range(n)] for i in range(m+1)]
    for j in range(n):
        if s[j]=='L':
            dp[0][j]=j-1
        else:
            dp[0][j]=j+1
    
    for i in range(m):
        for j in range(n):
            dp[i+1][j]=dp[i][dp[i][j]]
    
    after=[]
    for j in range(n):
        i=0
        nn=cnt
        cur_j=j
        while nn>0:
            if ((nn&1)==1):
                cur_j=dp[i][cur_j]
            nn>>=1
            i+=1
        after.append(cur_j)

    ans=[0]*n
    for j in range(n):
        ans[after[j]] += 1
    print(*ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 24448
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
ans = 1
flag = 0
if a[-1] == 0:
    print(0)
else:
    for i in a:
        ans *= i
        if ans > 10**18:
            flag +=1
            break
    if flag>0:
        print(-1)
    else:
        print(ans)

Measured memory_bytes: 21656
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(void){
	
	int n,a,b,c;
	int max=-1000000000;
	
	scanf("%d",&n);
	scanf("%d",&c);
	int min=c;
	for(int i=1;i<n;i++){
		scanf("%d",&a);
		b=a-min;
		if(max<b) max=b;
		if(min>a) min=a;
	}
	
	printf("%d\n",max);
	
	return 0;
}


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

#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

int main(){
    string s;cin>>s;
    int ok1=s[2]==s[3];
    int ok2=s[4]==s[5];

    if(ok1&&ok2)cout<<"Yes";
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#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>

#if __cplusplus >= 201103L
#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>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

int main(){
  string A, B, C;
  cin >> A >> B >> C;
  cout << char(A[0] - 32) << char(B[0] - 32) << char(C[0] - 32) << endl;
}


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

const int MOD = (int)1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  int count=0;
  for(int i=0;i<N;i++){
    if(A.at(i)%2==1)  count++;
  }
  if(count%2==0)  cout << "YES" << endl;
  else  cout << "NO" << endl;

  return 0;
}


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

int main() {
  string d;
  cin >>d ;

  if(d=="25"){
    cout <<"Christmas" <<endl;
  }
  if(d=="24"){
    cout <<"Christmas Eve" <<endl;
  }
  if(d=="23"){
    cout <<"Christmas Eve Eve" <<endl;
  }
  if(d=="22"){
    cout <<"Christmas Eve Eve Eve" <<endl;
  }
}





Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;


int main()
{
	int q, n, i, time;
	string name;
	queue<pair<string, int> > Q;
    scanf("%d", &n);
    scanf("%d", &q);
    for(i=0;i<n;i++)
    {
    	cin >> name>> time;
    	Q.push(make_pair(name, time));
	}
	pair<string, int> u;
	i = 0;
	while(!Q.empty())
	{
		u = Q.front();
		Q.pop();
		if(u.second>q)
		{
		    u.second -= q;
		    Q.push(u);
		    i += q;
		} 
		else 
		{
			i += u.second;
			cout << u.first << " ";
			//printf("%s ", u.first);
			printf("%d\n", i);
		}
	}
    //printf("%lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 6488
import sys, math
from functools import lru_cache
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    a = list(mi())
    b = list(mi())
    K = sum(b) - sum(a)

    if sum(max(0, (b[i]-a[i]+1)//2) for i in range(N)) <= K:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 10932
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt      ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  mem(a,b)   memset(a,b,sizeof(a))
ll k, m, dp[102][5005], a[102];
ll calcu(ll i, ll w){
    if(i>=k)return 0;
    if(dp[i][w]!=-1)return dp[i][w];
    ll x=0, y=0;
    if(w+a[i]<=m){
        x=a[i]+calcu(i+1, w+a[i]);
    }
    else{
        y=calcu(i+1, w);
    }
    return dp[i][w]=max(x, y);
}

int main()
{
    fastt;
    ll n, i, j, x, y, p=0, s=0, h, f=0;
    m=0;
    cin>>n>>k;

    mem(dp, -1);
    for(i=0; i<k; i++){
        cin>>a[i];
        m+=a[i];
    }
    if(k==1){
        cout<<max(0LL, n-1);
        return 0;
    }
    s=m;
    m/=2;
    x=calcu(0, 0);
    p=s-2*x;
    cout<<max(p-1, 0LL)<<endl;
    return 0;
}



Measured memory_bytes: 7568
#include <stdio.h>
#include <math.h>
#include<stdlib.h>
void insertionSort(int A[],int N,int g,int *cnt){
    int i,j;
    int v;
    
    for(i=g;i<N;i++){
        v=A[i];
        j=i-g;
        while(j>=0&&A[j]>v){
            A[j+g]=A[j];
            j=j-g;
            (*cnt)++;
        }
        A[j+g]=v;
    }
}
int main(void){
    int i;
    int N;
    scanf("%d",&N);
    int A[N];
    for(i=0;i<N;i++)scanf("%d",&A[i]);
    
    int cnt=0;
    int m=0;
    int g=N/2;
    int *G;
    G=(int*)malloc(sizeof(int));
    while(g!=0){
        G=(int*)realloc(G,sizeof(int)*(m+1));
        G[m]=g;
        m++;
        g=g/2;
    }
    if(m==0){
        G[0]=1;
        m++;
    }
    printf("%d\n",m);
    printf("%d",G[0]);
    for(i=1;i<m;i++)printf(" %d",G[i]);
    printf("\n");
    
    for(i=0;i<m;i++){
        insertionSort(A,N,G[i],&cnt);
    }
    printf("%d\n",cnt);
    for(i=0;i<N;i++)printf("%d\n",A[i]);

    return 0;
}


Measured memory_bytes: 5592
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int S = Integer.parseInt(sc.next());
        final int W = Integer.parseInt(sc.next());
        




        
        out.println(S <= W ? "unsafe" : "safe");
        
        out.flush();
    }
}

Measured memory_bytes: 35824
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100010],f[100010][2]={};
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	f[1][0]=-a[1];
	f[1][1]=a[1];
    for (int i=2;i<=n;i++)
	{
	    f[i][0]=max(f[i-1][0]+a[i],f[i-1][1]-a[i]);
		f[i][1]=max(f[i-1][0]-a[i],f[i-1][1]+a[i]);
    }
    cout<<f[n][1];
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
			if (i != 0) {
				arr[i] += arr[i - 1];
			}
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			ans = Math.max(ans, arr[i]);
			ans += x;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = scanner.nextInt();

    long c1 = 0;
    long sum = 0;
    for (int i = 0; i < n; i++) {
      sum += a[i];
      if (i % 2 == 0 && sum <= 0) {
        long d = 1 - sum;
        c1 += d;
        sum += d;
      } else if (i % 2 == 1 && sum >= 0){
        long d = sum + 1;
        c1 += d;
        sum -= d;
      }
    }

    long c2 = 0;
    sum = 0;
    for (int i = 0; i < n; i++) {
      sum += a[i];
      if (i % 2 == 0 && sum >= 0) {
        long d = sum + 1;
        c2 += d;
        sum -= d;
      } else if (i % 2 == 1 && sum <= 0){
        long d = 1 - sum;
        c2 += d;
        sum += d;
      }
    }

    System.out.println(Math.min(c1, c2));
  }
}


Measured memory_bytes: 51460
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	ll n;
    cin >> n;
	int ans = 0;
	ll z[4] = {0, 3, 5, 7};
	for( int a = 0; a < 4; ++a )
	for( int b = 0; b < 4; ++b )
	for( int c = 0; c < 4; ++c )
	for( int d = 0; d < 4; ++d )
	for( int e = 0; e < 4; ++e )
	for( int f = 0; f < 4; ++f )
	for( int g = 0; g < 4; ++g )
	for( int h = 0; h < 4; ++h )
	for( int i = 0; i < 4; ++i ){
		int flag[4] = {0, 0, 0, 0};
		ll pow = 1;
		++flag[a]; ++flag[b]; ++flag[c]; ++flag[d]; ++flag[e]; ++flag[f]; ++flag[g]; ++flag[h]; ++flag[i];
		for( int j = 0; j < 9-flag[0]; ++j ) pow *= 10;
		ll sfd = 100000000*z[a]+10000000*z[b]+1000000*z[c]+100000*z[d]+10000*z[e]+1000*z[f]+100*z[g]+10*z[h]+z[i];
		if( flag[1] && flag[2] && flag[3] && n >= sfd && sfd <= pow ) ++ans;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main(){
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<endl;
	return 0;
}


Measured memory_bytes: 3592
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FDistributeNumbers {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int k = 38;
      int n = 1407;
      //int k = 4;
      //int n = 13;

      int p = k-1;
      cout << n << ' ' << k << endl;

      vector<int> ret[n];
      for(int i=0; i<n-1; i++) {
        ret[i/p].push_back(i);
      }
      for(int i=0; i<p+1; i++) {
        ret[i].push_back(n-1);
      }
      int idx = p+1;

      for(int d=0; d<p; d++) {
        int m = d;
        for(int i=0; i<p; i++) {
          for (int j = 0; j < p; j++) {
            ret[idx].push_back(j*p+m);
            m += i;
            m %= p;
          }
          ret[idx].push_back(n-2-i);
          idx++;
        }
      }

      rep(i, n) {
        for(auto e: ret[i]) {
          cout << e+1 << ' ';
        }
        cout << '\n';
      }
    }
};

signed main() {
  FDistributeNumbers solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 4028
N, M = list(map(int, input().split()))
K = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

ans = 0

for i in range(2**N):
    light = [0]*M #ライトがすべて光っているか判定
    for j in range(M):
        on = 0 #ライトに接続しているonのスイッチの数
        for k in K[j]: #各ライトに接続しているスイッチk
            if (i>>(k-1))&1: #スイッチのon/offを確認
                on += 1
        if on%2 == P[j]: #onスイッチ数%2が点灯の条件と一致しているか確認
            light[j] = True
    if all(light): #全てのライトが点灯しているか確認
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <complex>
#include <iomanip>
using namespace std;

int main(){
  int n;
  while(cin>>n&&n!=-1){
    complex<double> p(1.0,0.0),q(0.0,1.0);
    for(int i=1;i<n;++i) p+=p*q/abs(p);
    cout<<fixed<<setprecision(2)<<p.real()<<'\n'<<p.imag()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <string>

using namespace std;
using ll = long long;



//void input() {
//
//}

bool solve() {
    set<pair<ll, ll>> pairs;
    vector<ll> counts(4, 0);
    for (ll i = 0; i < 3; i++) {
        ll a, b;
        cin >> a >> b;
        if (a > b)
            swap(a, b);
        if (pairs.find({a, b}) != pairs.end()) {
            return false;
        }
        pairs.insert({a,b});
        counts[a-1]++;
        counts[b-1]++;
    }
    ll c2 = 0, c1 = 0;
    for (auto c : counts) {
        if (c == 1) c1++;
        if (c == 2) c2++;
    }
    return (c1 == 2 and c2 == 2);
}

int main() {
    //    input();
    
    cout << (solve() ? "YES" : "NO") << endl;
    
    return 0;
}



Measured memory_bytes: 256