akhauriyash/Code-Regression huggingface dataset:
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std; 


inline void solve() {
    int  n,cnt=0 ; 
    cin >> n ; // 32400 
    vi div(98,0);
    for (int i=2;i<=n;i++){
    	int k = i;
    	for (int j=2;j*j <= k;j++){
    		while (k%j == 0){
    			div[j]++ ; 
    			k /= j ; 
    			if (div[j] == 2) cnt++;
    		}
    	}
    	if (k > 1) {
    		div[k]++;
    		if (div[k] == 2) cnt++; 
    	} 
    } 
    vi c(cnt,0); 
    for (int i=2,j=0;i<=97;i++) { 
    	if (div[i]>1) c[j++] = div[i]; 
    } 
    sort(all(c));
    int ans = 0 ;
    for (int i=0;i<cnt;i++) { 
    	if (c[i]>=74) ans++;
    	for (int j=i+1;j<cnt;j++) { 
    		if (c[i]>=4 and c[j]>=14) ans++;
    		if (c[j]>=4 and c[i]>=14) ans++;
    		if (c[i]>=2 and c[j]>=24) ans++;
    		if (c[j]>=2 and c[i]>=24) ans++;
    		for (int k=j+1;k<cnt;k++) { 
    			if (c[i]>=4) ans += 3 ; 
    			else if (c[j]>=4) ans++ ; 
    		}
    	}
    }
    co (ans);
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC159 C - Maximum Volume
// 2020.06.27

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  double L; cin >> L;
  double ans = (L/3)*(L/3)*(L/3);
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n, x; cin >> n >> x; std::vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i]; sort(begin(a), end(a));
	
	int c = n;
	for(int i = 0; i < n; i++) x -= a[i];
	cout << c + (x / a[0]) << endl;
	return 0;
}


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

/******************************\
 * The solution is at the top *
 *                            *
 *   Created by : azhar556    *
\******************************/

public class Main {
    static void solve() {
		int N = ni();
		int L = ni();
		int[] arr = new int[N];
		int tot = 0;
		for (int i = 0; i < N; i++) {
			arr[i] = L + (i + 1) - 1;
			tot += arr[i];
		}
		arr = radixSort(arr);
		if (Math.abs(arr[0]) < Math.abs(arr[N - 1])) {
			tot -= arr[0];
		}
		else {
			tot -= arr[N - 1];
		}
		out.println(tot);
    }    

    public static void main(String[] args) {
        long time = System.currentTimeMillis();
        int t;// = ni();
        t = 1;
        while (t-- > 0) solve(); 
        err.println("Time elapsed : " + (System.currentTimeMillis() - time) / 1000F + " s.");
        err.close(); out.close();
    }

	static int[] radixSort(int[] f){ return radixSort(f, f.length); }
	static int[] radixSort(int[] f, int n)
	{
		int[] to = new int[n];
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
			int[] d = f; f = to;to = d;
		}
		{
			int[] b = new int[65537];
			for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
			for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
			int[] d = f; f = to;to = d;
		}
		return f;
	}

    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static PrintWriter err = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err)));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer token;
    
    static boolean hasMoreTokens () {
        String sample = null;
		try {
			sample = br.readLine();
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		return sample == null ? false : true;
    }

    static String ns() {
        while (token == null || !token.hasMoreTokens()) {
            try {
                token = new StringTokenizer(br.readLine());
            }
            catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return token.nextToken();
    }
    static char nc() {
        return Character.valueOf(ns().charAt(0));
    }
    static int ni() {
        return Integer.parseInt(ns());
    }
    static double nd() {
        return Double.parseDouble(ns());
    }
    static long nl() {
        return Long.parseLong(ns());
    }
}
// Collections Arrays Math
// Vector HashSet TreeSet HashMap TreeMap ArrayDeque 

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  double kakuritu=0.0;
  for(int i=0;i<N;i++){
    int tokuten=i+1;
    int kai=0;
   while(tokuten<K){
     tokuten*=2;
     kai++;
   }
    if(kai!=0){
      kakuritu+=((1.0/N)*(1/pow(2,kai)));
    }else{
     kakuritu+=(1.0/N);
    }
  }
 cout<<setprecision(13)<<kakuritu<<endl;
}

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

using ll = long long;
const ll INF = (ll)1e18;

template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

template <typename Iterator> void printVec(Iterator begin, Iterator end)
{
  Iterator it = begin;
  std::cout << *it;
  it++;
  for (; it != end; it++) { std::cout << " " << *it; }
  std::cout << std::endl;
}

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

  if(N == 3){
    print(2, 5, 63);
  }else if(N == 4){
    print(2, 3, 4, 9);
  }else if(N == 5){
    print(2, 3, 4, 6, 9);
  }else{
    ll sum = 0LL;
    ll idx8 = 0LL;
    ll idx9 = 0LL;
    std::vector<ll> vans(N);
    std::vector<ll> va(4);
    va[0] = 2LL;
    va[1] = 3LL;
    va[2] = 4LL;
    va[3] = 6LL;
    for (ll i = 0; i < N; i++) {
      vans[i] = 6 * (ll)(i / 4) + va[i % 4];
      sum += vans[i];
      if (vans[i] == 8) idx8 = i;
      if (vans[i] == 9) idx9 = i;
    }
    ll mod_num = sum % 6;
    if (mod_num == 2) {
      vans[idx8] = 6 * (ll)(1 + N / 4);
    } else if (mod_num == 3) {
      vans[idx9] = 6 * (ll)(1 + N / 4);
    } else if (mod_num == 5) {
      vans[idx9] = 6 * (ll)(N / 4) + 4;
    }
    printVec(vans.begin(), vans.end());
  }
  return 0;
}


Measured memory_bytes: 512
n,k,s=gets.split.map &:to_i
if s-(n-k)>=1
a=[s-(n-k)]+[1]*(n-k)
b=n.times.map{|i|a[i%a.size]}
puts b*" "
else
a=[s]*k+[s+1]*(n-k)
puts a*" "
end

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

int main() {
	// your code goes here
	int a,b,c,k,i,j;
	cin>>a>>b>>c;
	cin>>k;
	
    while(k)
	{
		if(b>a)
		break;
		else
		{
			b=2*b;
			k--;
		}
	}
	
	while(k)
	{
		c=2*c;
			k--;
	}
	
	if(a<b&&b<c)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

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

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second


int main() {
	ll n, a, b, h[100010];
	cin >> n >> a >> b;
	for (int i = 0;i < n;i++) {
		cin >> h[i];
	}
	ll l = 0, r = INF2;
	while (r - l > 1) {
		ll mid = (l + r) / 2, sum = 0;
		for (int i = 0;i < n;i++) {
			sum += max((ll)0, (h[i] - mid + (a - b) - 1) / (a - b));
		}
		if (sum <= (mid + b - 1) / b)r = mid;
		else l = mid;
	}
	cout << (r + b - 1) / b << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;

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

    int ans = 0;
    for(int i = 0; i < 60; i++){
        if(x <= y){
            ans++;
            x *= 2;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>                                             
using namespace std;
 
long long n, a, b;
long long ans;
 
int main(){
  cin >> n >> a >> b;
  if(a > b) ans = 0;
  else if(n == 1){ 
    if(a != b) ans = 0;
    else ans = 1;
  }else ans = (n-2)*(b-a)+1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h) cin >> g[i];
    auto g2 = g;

    rep(i, h) rep(j, w) {
        if (g[i][j] == '#') continue;
        int cnt = 0;

        rep(k, 8) {
            int y = i + dy[k];
            int x = j + dx[k];
            if (y >= 0 && y < h && x >= 0 && x < w) {
                if (g[y][x] == '#') cnt++;
            }
        }

        g2[i][j] = '0'+cnt;
    }

    rep(i, h) cout << g2[i] << endl;
    return 0;
}

Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll x;cin>>x;
  for(ll i=-500;i<=500;i++){
    for(ll j=-500;j<=500;j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int k;
int cnt=0;
string ans="";
void recurse(string search){
    for(char c='a';c<='z';c++){
        if(ans!="")return;
        if(s.find(search+c)!=string::npos){
            cnt++;
            if(cnt==k)ans=search+c;
            recurse(search+c);
        }
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>s>>k;
    recurse("");
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<vector<int>> A(n);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++){
    int s;
    cin >> s;
    if (s == 0){
      int t, x;
      cin >> t >> x;
      A[t].push_back(x);
    }
    if (s == 1){
      int t;
      cin >> t;
      for (int i = 0; i < A[t].size(); i++){
        cout << A[t][i];
        if (i < A[t].size() - 1){
          cout << ' ';
        }
      }
      cout << endl;
    }
    if (s == 2){
      int t;
      cin >> t;
      A[t].clear();
    }
  }
}


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

int main()
{
  string s;
  cin>>s;
  int n=s.length();
  int ans=0;
  int i;
  if(n%2==0)
  {
    for(i=0;i<n/2;i++)
    {
      if(s.at(i)!=s.at(n-1-i))ans++;
    }
  }
  else
  {
    for(i=0;i<n/2;i++)
    {
      if(s.at(i)!=s.at(n-1-i))ans++;
    }
  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
s = gets.chomp
n = s.size - 1
sum = 0

(2**n).times do |i|
  f = s.dup
  tmp = -1

  format("%0#{n}d", i.to_s(2)).each_char.with_index(1) do |c, idx|
    f.insert(idx + (tmp += 1), '+') if c == '1'
  end

  sum += f.split('+').map(&:to_i).inject(:+)
end

puts sum

Measured memory_bytes: 2044
n = int(input())
a = list(map(int, input().split()))
d = sum(a)
L = d/2
s = 0

for i in range(n):
    s += a[i]
    new_d = abs(L-s)
    if new_d < d:
        d = new_d
    else:
        break

print(int(2*d))


Measured memory_bytes: 26220
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    ts, xs, ys = [0], [0], [0]

    for i in range(n):
        ti, xi, yi = map(int, input().split())
        ts.append(ti)
        xs.append(xi)
        ys.append(yi)

    for j in range(n):
        dt = ts[j + 1] - ts[j]
        dxy = (xs[j + 1] - xs[j]) + (ys[j + 1] - ys[j])

        if (-dt <= dxy <= dt) and (dt % 2 == dxy % 2):
            pass
        else:
            print('No')
            exit()

    print('Yes')


if __name__ == '__main__':
    main()


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  else if(b==c) cout << a << endl;
  else cout << b << endl;
}

Measured memory_bytes: 3556
#--Common Raccoon vs Monster

hp, number = map(int, input().split(" "))
attack = [int(i) for i in input().split(" ")]

total = sum(attack)

if (total >= hp):
  print("Yes")
  exit()
else:
  pass

for i in range(number):
  damage = total - (attack[i])
  if (damage >= hp):
    print("Yes")
    exit()
  else:
    pass

print("No")


Measured memory_bytes: 13964
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		// Input are two integers separated from a space
		int x = input.nextInt();
		int y = input.nextInt();
		// Need to see if there's a clean division or remainder
		int r = 0;
		
		// Start with simple case, they equal
		if (x == y) { System.out.println(x);}
		else if (x >= y) {
			while (x % y > 0) {
				r = x % y;
				x = y;
				y = r;
			}
			System.out.println(r);
		}
		else {
			while (y%x >0) {
				r = y % x;
				y = x;
				x = r;
			}
			System.out.println(r);
		}

	}

}



Measured memory_bytes: 26252
n = int(input())
S = [input() for _ in range(n)]
ans = [0] * 4
l = ["AC","WA","TLE","RE"]
for s in S:
    if s == "AC":
        ans[0]+= 1
    elif s == "WA":
        ans[1]+= 1
    elif s == "TLE":
        ans[2]+=1
    else:
        ans[3]+=1
for i in range(4):
    print("{}  x {}".format(l[i],ans[i]))


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N, A, B;
vector<ll> P;

signed main()
{
    cin >> N >> A >> B;
    P.assign(N, 0);
    REP(i, N) { cin >> P[i]; }
    ll cand[3] = {};
    REP(i, N) {
        if(P[i] <= A) { cand[0]++; }
        else if(A < P[i] && P[i] <= B) { cand[1]++; }
        else { cand[2]++; }
    }
    printf("%lld\n", min({cand[0], cand[1], cand[2]}));
    return 0;
}


Measured memory_bytes: 256
# すげぇこんがらがるのでまずは落ち着く
# Cを使う場合とC"だけ"を遣う場合と使わない場合で分ける
a, b, c, x, y = map(int, input().split())
t = (x - y) * a if x > y else(y - x) * b
print(min(a * x + b * y, 2 * c * min(x, y) + t, 2 * c * max(x, y)))


Measured memory_bytes: 38256
#include<stdio.h>
#include<string.h>

#define MAXLEN 10

int main(){
  int a, b;
  char s[MAXLEN+1], t[MAXLEN+1], u[MAXLEN+1];
  
  scanf("%s %s", s, t);
  scanf("%d %d", &a, &b);
  scanf("%s", u);
  
  if(strcmp(s, u) == 0){
    a--;
  }else{
    b--;
  }
  
  printf("%d %d", a, b);
  return 0;
}

Measured memory_bytes: 128
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=400+19;

int I[N],O[N],fa[N],vis[N];
int n,a,b,c,d,H,x,y;

int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
void Union(int x,int y){
	x=getf(x),y=getf(y);
	if (x!=y) fa[x]=y;
}

int main(){
	For(i,0,N) fa[i]=i;
	n=IN(),H=IN();
	For(i,1,n+1){
		a=IN(),b=IN(),c=IN(),d=IN();
		if (c==0) x=a+H;else x=c;
		if (d==0) y=b;else y=d+H;
		O[x]++;
		I[y]++;
		Union(x,y);
		//printf("%d %d\n",x,y);
	}
	For(i,0,N){
		if (O[i]>I[i]) if (i<=H) return puts("NO"),0;else vis[getf(i)]=1;
		if (O[i]<I[i]) if (i>H) return puts("NO"),0;
	}
	For(i,0,N) if (I[i]||O[i]) if (!vis[getf(i)]) return puts("NO"),0;
	puts("YES");
}

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

const int ac = 83, mod = 1e9;
bool A[ac][ac][ac * ac * 2];
ll B[ac][ac];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> B[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			int x; cin >> x;
			B[i][j] -= x;
		}
	A[0][1][ac * ac] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			for (int k = max(0ll, B[i][j]); k < ac * ac * 2 - max(0ll, B[i][j]); k++)
			{
				if (A[i - 1][j][k - B[i][j]]) A[i][j][k] = 1;
				if (A[i - 1][j][k + B[i][j]]) A[i][j][k] = 1;
				if (A[i][j - 1][k - B[i][j]]) A[i][j][k] = 1;
				if (A[i][j - 1][k + B[i][j]]) A[i][j][k] = 1;
			}
		}
	int b = 1e9;
	for (int i = 0; i < ac * ac * 2; i++)
		if (A[n][m][i]) b = min(b, abs(i - ac * ac));
	cout << b << '\n';
}



Measured memory_bytes: 91008
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#define ll long long
#define MAX 20000000000
#define MOD 1000000007

int main(void){
char s[101];
scanf("%s",s);
printf("%c",s[0]);
printf("%d",strlen(s)-2);
printf("%c\n",s[strlen(s)-1]);
 return 0;
}

Measured memory_bytes: 128
n, w = map(int, input().split())

weight = []
value = []

for i in range(n):
    wi, vi = map(int, input().split())
    weight.append(wi)
    value.append(vi)

v_sum = sum(value)

dp = [[10**12 for _ in range(v_sum+1)] for i in range(n)]

for i in range(n):
    if i == 0:
        dp[i][0] = 0
        dp[i][value[0]] = weight[0]
    else:
        for k in range(v_sum+1):
            if k < value[i]:
                dp[i][k] = dp[i-1][k]
            else:
                dp[i][k] = min(dp[i-1][k], dp[i-1][k-value[i]]+weight[i])

for i in range(v_sum, -1, -1):
    if dp[n-1][i] <= w:
        print(i)
        exit()


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

int arr[9000];
vector<int> v[3];

int main(void) {
    int n;
    scanf("%d\n",&n);
    memset(arr,-1,sizeof(arr));
    for(int i=0;i<n;i++) {
        char x;
        scanf("%c",&x);
        if (x=='R') {
            arr[i]=0;
            v[0].push_back(i);
        }
        if (x=='G') {
            arr[i]=1;
            v[1].push_back(i);
        }
        if (x=='B') {
            arr[i]=2;
            v[2].push_back(i);
        }
    }
    long long ret=0;
    for(int i=0;i<n;i++) {
        int color=arr[i];
        for(int j=i+1;j<n;j++) {
            if (color==arr[j]) {
                continue;
            }
            int nc=arr[j];
            int nnc;
            for(int k=0;k<3;k++) {
                if (k!=color&&k!=nc) {
                    nnc=k;
                    break;
                }
            }
            int val=v[nnc].end()-upper_bound(v[nnc].begin(),v[nnc].end(),j);
            if (arr[j+j-i]==nnc) {
                val--;
            }
            ret+=val;
        }
    }
    printf("%lld",ret);
}

Measured memory_bytes: 3864
import sys
def main():
    input = sys.stdin.readline
    N,K=map(int, input().split())
    z=h=0
    for i in range(1,N+1):
        if i%K==0:
            z+=1
        elif K&1==0 and i%K==K>>1:
            h+=1
    ans=z**3
    ans+=h**3
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[N];
		for (int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			c[i]=sc.nextInt();
		}

		int[][] dp = new int[N+1][3];
		dp[0][0]=0;
		for (int i=0;i<N;i++) {
			dp[i+1][0]=Math.max(dp[i][1]+a[i],dp[i][2]+a[i]);
			dp[i+1][1]=Math.max(dp[i][0]+b[i],dp[i][2]+b[i]);
			dp[i+1][2]=Math.max(dp[i][0]+c[i],dp[i][1]+c[i]);
		}
		int max=0;
		for (int i=0;i<3;i++) {
			max=Math.max(max,dp[N][i]);
		}
		System.out.println(max);
	}
}

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

#define input_i(x) scanf("%d", &x)
#define input_lli(x) scanf("%lld", &x)
#define input_s(x) scanf("%s", x)

#define BUFSIZE 1001

int main(int argc, char const *argv[]) {
    int N;
    input_i(N);
    int ans= N * N * N;

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

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

int main() {
    int n;
    std::cin >> n;
    std::vector<int> num(n);
    std::vector<int> X(100005, 0);
    for (int i = 0; i < n; ++i) {
        int c;
        std::cin >> c;
        ++X[c + 1];
        ++X[c];
        ++X[c + 2];
    }
    int max = 0;
    for (int i = 0; i < 100005; ++i) {
        max = std::max(max, X[i]);
    }
    std::cout << max;
}

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

using namespace std;
#define  ll  long long
#define f first
#define s second
#define matrix vector<vector<ll>>
#define zero(n,m) matrix(n , vector<ll>(m,0))
#define one(n,m) matrix(n , vector<ll>(m,1))
#define pii pair< ll , pair<ll,ll> >
const int N = 1e3+5;

ll n,m,stX,stY,enX,enY,dx[4]={0,0,1,-1} , dy[4]={1,-1,0,0} , cost[N][N];
char a[N][N];

bool isValid(int i , int j)
{
    if (i<1 || i>n || j<1 || j>m || a[i][j]=='#') return 0;
    return 1;
}

ll dijs()
{
    priority_queue<pii , vector<pii> , greater<pii> > q;
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=m; j++)
            cost[i][j] = 1e18;
    }

    cost[stX][stY]=0;
    q.push({0 , {stX,stY} });

    while(q.size())
    {
        ll i = q.top().s.f , j=q.top().s.s , magic = q.top().f;
        q.pop();
        if (cost[i][j] < magic) continue;

        for(int k=0; k<4; k++)
        {
            int ii=i+dx[k] , jj=j+dy[k];
            if (isValid(ii,jj) && cost[ii][jj] > magic)
            {
                cost[ii][jj] = magic;
                q.push({cost[ii][jj] , {ii,jj}});
            }
        }

        int st=i-2 , stj=j-2 , en=i+2 , enj=j+2;
        for(int k=st; k<=en; k++)
        {
            for(int kk=stj; kk<=enj; kk++)
            {
                if (isValid(k,kk) && cost[k][kk] > magic+1)
                {
                    cost[k][kk] = magic+1;
                    q.push({cost[k][kk] , {k,kk}});
                }
            }
        }
    }
    if (cost[enX][enY] == 1e18) cout << "-1\n";
    else cout << cost[enX][enY] << "\n";
    return 0;
}

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

    cin >> n >> m;
    cin >> stX >> stY >> enX >> enY;

    for(int i=1; i<=n; i++)
    {
        string s;
        cin >> s;
        for(int j=1; j<=m; j++)
            a[i][j] = s[j-1];
    }

    dijs();

    return 0;
}



Measured memory_bytes: 12720
n = int(input())
s = input().split()
a = []
b = []
for i in range(n//2):
    b.append(s[i*2+1])
s = s[::2]
if n%2 == 0:
    b.reverse()
    print(" ".join(b+s))
else:
    s.reverse()
    print(" ".join(s+b))


Measured memory_bytes: 24948
#include <iostream>
#define rep(i, n) for (long long i = 0; i < (n); i++)
using namespace std;

typedef long long ll;

int main(){
  ll n, m;
  cin >> n >> m;
  ll sum = 0;
  ll a;
  rep(i, m){
    cin >> a;
    sum += a;
  }
  
  ll rem = n - sum;
  if (rem < 0)
    cout << -1 << endl;
  else
    cout << n - sum << endl;
  
  return 0;
}

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

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

    int ans = 0;
    int mi = 1001001001;
    for(int i=0; i<N; ++i) {
        if(A[i] < mi) ++ans;
        mi = min(mi, A[i]);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1024
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}



Measured memory_bytes: 2056
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

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

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,m;
	cin>>n>>m;
	int x;
	for(int i=0;i<m;i++)
	{
		cin>>x;
		n-=x;
	}
	if(n<0)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 3648
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	template<class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
		cerr << boolalpha << i; return *this;
	}

	template<class c, int=0> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
		return *this << range(begin(i), end(i));
	}

sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define watch(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int128 LLL;
typedef long long LLL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII > VP;
typedef vector<PLL > VPL;
typedef vector<double> VD;
typedef long double ld;

void solve(int ks) {
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d\n", a - b + 1);
}

int main()
{
#ifdef LOCAL
	double start_time = clock();
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif


	if (0) {
		int T;
		scanf("%d", &T);
		for (int ks = 1; ks <= T; ks++) solve(ks);
	}
	else {
		solve(0);
	}

#ifdef LOCAL
	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    cout << s.substr(0,3) << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
using namespace std;
int n,ans;

int main(){
	cin>>n;
	while(n>10){
		ans+=n%10;
		n/=10;
	}
	ans+=n;
	if(ans==1){
		ans=10;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int a[n+1],num=0,b[n+1];
	for(int i= 0;i<n ;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(b[i]!=a[i])
			num++;
		if(num==3){
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE -1

int X[N][N];
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];


void printboard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]==1){
        if(row[i]!=j){
          return;
        }
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
      printf("Q");
    }
    else{
      printf(".");
  }
  }
  printf("\n");
}
}

void initialize(){
 int i;
 for(i=0;i<N;i++){
   row[i]=FREE;
   col[i]=FREE;
 }

 for(i=0;i<2*N-1;i++){
   dpos[i]=FREE;
   dneg[i]=FREE;
 }
}

void recursive(int i)
{
  int j;
  if(i==N){
    printboard();return;
  }
  for(j=0;j<N;j++){
    if((col[j]==NOT_FREE)||(dpos[i+j]==NOT_FREE)||(dneg[i-j+N-1]==NOT_FREE)){
    continue;
  }
  row[i]=j;
  col[j]=NOT_FREE;
  dpos[i+j]=NOT_FREE;
  dneg[i-j+N-1]=NOT_FREE;
  recursive(i+1);
  col[j]=FREE;
  dpos[i+j]=FREE;
  dneg[i-j+N-1]=FREE;
  }
}
int main()
{
  int i,j,k,r,c;
  initialize();
  for(i=0;i<N;i++){
  for(j=0;j<N;j++){
  X[i][j]=-1;
}
}

  scanf("%d",&k);
  for(i=0;i<N;i++){
    scanf("%d%d",&r,&c);
    X[r][c]=1;
  }
  recursive(0);
  return 0;
}




Measured memory_bytes: 2112
int min(int a,int b)
{
	if(a>b)
	return b;
	if(a==b)
	return a;
}
main()
{
	int A1,A2,A3,mina,minb;
	 scanf("%d%d%d",&A1,&A2,&A3);
			int sum1=0,sum2=0,sum3=0;
			sum1=abs(A1-A2)+abs(A1-A3);
			sum2=abs(A2-A3)+abs(A2-A1);
			sum3=abs(A3-A1)+abs(A3-A2);
			mina=min(sum1,sum2);
			minb=min(sum2,sum3);
			printf("%d",min(mina,minb));
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <deque>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
const ll inf = 1e18;

ii a[200000];
void solve()
{
    int n;
    ii a[200000];
    cin >> n;
    for(int i=0; i<n; i++)
    {
        cin >> a[i].first >> a[i].second;
    }
    sort(a, a+n);
    int l, r;
    if(n%2==0)
        l = a[n/2].first+a[n/2-1].first;
    else
        l = a[n/2].first;
    for(int i=0; i<n; i++)
        swap(a[i].first, a[i].second);
    sort(a, a+n);
    if(n%2==0)
        r = a[n/2].first+a[n/2-1].first;
    else
        r = a[n/2].first;
    cout << r-l+1<< '\n';
    
}

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

Measured memory_bytes: 5216
import sys
read = sys.stdin.buffer.read
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)


def main():
    OFS = 100005
    N = int(input())
    G = [[] for _ in [0]*OFS*2]
    for line in readlines():
        x, y = map(int, line.split())
        y += OFS
        G[x].append(y)
        G[y].append(x)

    def dfs(v):
        if v < OFS:
            counter[0] += 1
        else:
            counter[1] += 1

        for u in G[v]:
            if visited[u]:
                continue
            visited[u] = 1
            dfs(u)

    visited = [0]*OFS*2
    ans = 0
    for i in range(OFS):
        if visited[i]:
            continue
        counter = [0]*2
        visited[i] = 1
        dfs(i)
        ans += counter[0] * counter[1]

    print(ans - N)


if __name__ == '__main__':
    main()

Measured memory_bytes: 106844
/*
1.heights = {0, 0, …… ,0}からスタート
2.以下をループ

手順1.heightsの各要素頭から1ずつ足していく
手順2.目標とする値とすでに一致している要素にぶつかったら1を足さずに求める答えをインクリメント
手順3.goalに一致してたら答えを返す
*/

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

int main()
{
  int N;
  cin >> N;
  
  vector<int> goal(N);
  for(int i = 0; i < N; ++i)
  {
    cin >> goal.at(i);
  }
  
  vector<int> heights(N, 0);
  
  int cnt = 0;
  while(true)
  {
    if(heights == goal)
    {
      cout << cnt << endl;
      return 0;
    }
    
    bool hasAdded = false;
    for(int i = 0; i < N; ++i)
    { 
      if(heights.at(i) == goal.at(i) && hasAdded)
      {
        ++cnt;
        hasAdded = false;
        continue;
      }
      
      // 目標と一致してるけどそれまでに1足してない場合
      // 考えられるのは冒頭、もしくは直前の要素もすでに目標と一致しているケースの2つ
      if(heights.at(i) == goal.at(i))
      {
        hasAdded = false;
        continue;
      }
      
      ++heights.at(i);
      hasAdded = true;
      
      if(i == N - 1)
      {
        ++cnt;
        hasAdded = false;
        continue;
      }
    }  
  }
  
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);


int main(void)
{
    ll a,b,c,k; cin>>a>>b>>c>>k;
    ll m=max({a,b,c}),sum=a+b+c-m;
    rep(i,k) m*=2;
    sum+=m;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> h(N);
    for(auto& x: h) cin >> x;

    vector<ll> dp(N, 1e18);
    dp[0] = 0;
    for(int i=0; i<N-2; i++){
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
    }
    dp[N-1] = min(dp[N-1], dp[N-2]+abs(h[N-1]-h[N-2]));

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */
ll a[100010];
int n;

int main() {
    scanf("%d", &n);
    rep(i, n) scanf("%lld", &a[i]);
    ll ret = 0;
    ll mi = 1000000001;
    int cnt = 0;
    bool b = false;
    rep(i, n) {
        if (a[i] < 0) {
            cnt++;
        }
        if (a[i] == 0) {
            b = true;
        }
        mi = min(mi, abs(a[i]));
    }
    rep(i, n) {
        ret += abs(a[i]);
    }
    if (cnt % 2 == 1 && !b) {
        ret -= mi;
        ret -= mi;
    }
    printf("%lld\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int main(){
    int n,b,f,r,v,i,data[120];
    for(i=0;i<120;i++)data[i]=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        data[30*(b-1)+10*(f-1)+r-1]+=v;
    }
    for(i=0;i<120;i++){
        printf(" %d",data[i]);
        if(i%10==9)puts("");
        if(i<90&&i%30==29)puts("####################");
    }
}


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

long long n,a,b,t;
pair<long long,long long> ab[200100];

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        ab[i]=make_pair(b,a);
    }
    sort(ab,ab+n);
    t=ab[n-1].first;
    for(int i=n-1;i>=0;i--){
        t=min(t,ab[i].first);
        t-=ab[i].second;
        if(t<0){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
itn a, b;
void solve() {
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    if (a < 10 && b < 10) {
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

class Counting {
	unsigned long long p, n;
	vector<long long> invMemo, facMemo, facInvMemo;
public:
	Counting(unsigned long long nn, unsigned long long np) {
		p = np;
		n = nn;
		invMemo.resize(n + 1);
		facMemo.resize(n + 1);
		facInvMemo.resize(n + 1);
		facMemo[0] = 1;
		facMemo[1] = 1;
		facInvMemo[0] = 1;
		facInvMemo[1] = 1;
		invMemo[0] = 0;
		invMemo[1] = 1;
		for (unsigned long long i = 2; i <= n; i++) {
			invMemo[i] = p - (p / i)*invMemo[p%i] % p;
			facMemo[i] = (facMemo[i - 1] * i) % p;
			facInvMemo[i] = (facInvMemo[i - 1] * invMemo[i]) % p;
		}
	}
	unsigned long long fac(unsigned long long k) {
		return facMemo[k];
	}
	unsigned long long facInv(unsigned long long k) {
		return facInvMemo[k];
	}
	unsigned long long choose(unsigned long long n, unsigned long long k) {
		if (!(0 <= k && k <= n))
			return 0;
		return (((facMemo[n] * facInvMemo[k]) % p)*facMemo[n - k]) % p;
	}
	unsigned long long divide(unsigned long long a, unsigned long long b) {
		return (a * invMemo[b]) % p;
	}
	unsigned long long mod(unsigned long long a) {
		a %= p;
		if (a < 0) a += p;
		return a;
	}
	unsigned long long power(unsigned long long a, unsigned long long e) {
		unsigned long long ans = 1;
		for (; e > 0; e /= 2) {
			if (e % 2 != 0)
				ans = ans * a % p;
			a = a*a%p;
		}
		return ans;
	}
};

int main() {
	int n, ans = 0;
	vector<int> a;
	map<int, int> mp;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]]++;
	}
	int cnt = 0;
	for (auto it = mp.begin(); it != mp.end(); it++) {
		if (it->second >= 3)
			it->second = it->second - ((it->second -1) / 2) * 2;
		if (it->second == 2) {
			cnt++;
		}
	}
	ans = mp.size() - cnt%2;
	cout << ans << endl;
	//cin >> n;
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)

/* clang-format on */
int main() {
  ll n, k;
  scanf("%lli %lli", &n, &k);
  ll ans = 0;
  ans = (-(n + 1) * (n + 2) * (2 * n + 3) / 6) % MOD+MOD +
        k * (k - 1) * (2 * k - 1) / 6 % MOD +
        ((n + 1) * ((n + 1) * (n + 2) / 2 - k * (k - 1) / 2)) % MOD + n - k + 2;
  printf("%lli\n", ans % MOD);
  return 0;
}


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

int main()
{
	int H, W;
	scanf("%d%d", &H, &W);
	using vb = std::vector<bool>;
	using vvb = std::vector<vb>;
	using vi = std::vector<int>;
	using vvi = std::vector<vi>;

	vvb object(H + 2, vb(W + 2, true));
	vvi count(H + 2, vi(W + 2));
	for (int i{1}; i <= H; i++)
		for (int j{1}; j <= W; j++)
		{
			char tmp;
			scanf(" %c", &tmp);
			object[i][j] = tmp == '#';
			if (!object[i][j]) count[i][j]++;
		}

	for (int i{1}; i <= H; i++)
	{
		int start{1};
		for (int j{1}; j <= W; j++)
		{
			if (object[i][j])
			{
				start = j + 1;
				continue;
			}
			count[i][j] += j - start;
		}
	}
	for (int i{1}; i <= H; i++)
	{
		int start{W};
		for (int j{W}; j >= 1; j--)
		{
			if (object[i][j])
			{
				start = j - 1;
				continue;
			}
			count[i][j] += start - j;
		}
	}
	for (int i{1}; i <= W; i++)
	{
		int start{1};
		for (int j{1}; j <= H; j++)
		{
			if (object[j][i])
			{
				start = j + 1;
				continue;
			}
			count[j][i] += j - start;
		}
	}
	for (int i{1}; i <= W; i++)
	{
		int start{H};
		for (int j{H}; j >= 1; j--)
		{
			if (object[j][i])
			{
				start = j - 1;
				continue;
			}
			count[j][i] += start - j;
		}
	}
	int max{};
	for (int i{1}; i <= H; i++)
		for (int j{1}; j <= W; j++)
			max = std::max(max, count[i][j]);
	printf("%d\n", max);

	return 0;
}

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

int GCD(int A, int B)
{
  int a = A, b = B;
  while (a * b != 0  &&  a != 1  &&  b != 1)
  {
    if (a < b) b %= a;
    else a %= b;
  }
  if (a * b == 0) return max(a, b);
  else return 1;
}

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  
  int ans = GCD(A.at(0), A.at(1));
  for (int i = 2; i < N - 2; i++)
  {
    ans = GCD(ans, A.at(i));
    if (ans == 1) break;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
#
import sys
import math
import numpy as np
import itertools
# いくつか入力
n, k, c = (int(i) for i in input().split())  

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
m = list(input())

l=[-1]*n
r=[-1]*n

a=0
b=c
for i in range(n):
    if b>=c and m[i]=='o':
        b=0
        l[a]=i
        a += 1
    else:
        b += 1
    if a == k:
        break
a=k-1
b=c
for i in range(n-1,-1,-1):
    if b>=c and m[i]=='o':
        b=0
        r[a]=i
        a -= 1
    else:
        b += 1
    if a == k:
        break



answer=0
for i in range(n):
    if l[i] == r[i] and l[i]>=0:
        print(l[i]+1)






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

int main()
{
	int n, m;
	vector<string> a(100), b(100);
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a.at(i);
	}
	cin >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> b.at(i);
	}

	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		int temp = 0;
		for (int k = 0; k < n; ++k)
		{
			if (a.at(i) == a.at(k))
			{
				temp++;
			}
		}
		for (int k = 0; k < m; ++k)
		{
			if (a.at(i) == b.at(k))
			{
				temp--;
			}
		}

		ans = max(ans, temp);
	}

	cout << ans << endl;
}

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

using namespace std;

const int N = 1e5 + 10;
int dp[N];

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i + a[j] > k) {
        continue;
      }
      if (!dp[i]) {
        dp[i + a[j]] = 1;
      }
    }
  }
  cout << (dp[k] ? "First" : "Second");

  return 0;
}

Measured memory_bytes: 640