akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define MX LLONG_MAX
#define MN LLONG_MIN

const ll mod=1e9+7;
const ll N=1e5+5;
 
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}          
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll modinv(ll a,ll m);

int32_t main()                  
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x;
    cin>>n>>x;
    ll a[n];
    for(ll i=0;i<n;i++)
        cin>>a[i];
    ll d = 0;
    ll ans = 1;
    for(ll i=0;i<n;i++)
    {
        d = d + a[i];
        if(d>x)
            break;
        ans++;
    }
    cout<<ans;
    return 0;
}  
void EE(ll a,ll b,ll &co1,ll &co2)
{
    if(a%b==0)
    {
        co1=0;
        co2=1;
        return;
    }
    EE(b,a%b,co1,co2);
    ll tmp=co1;
    co1=co2;
    co2=tmp-co2*(a/b);
}
ll modinv(ll a,ll m)
{
    ll x,y;
    EE(a,m,x,y);
    if(x<0) x+=m;
    return x;
}

Measured memory_bytes: 256
try:
    while True:
        n=int(input())
        m=1000-n
        i=0
        if m==1000:
            break
        else:
            i+=m//500
            m=m%500
            i+=m//100
            m=m%100
            i+=m//50
            m=m%50
            i+=m//10
            m=m%10
            i+=m//5
            m=m%5
            i+=m
        print(i)
except EOFError:
    pass


Measured memory_bytes: 5588
N = int(input())
words = []

isOK = True
for i in range(N):
  word = input()
  if word in words:
    print("No")
    isOK = False
    break
  if len(words) > 0:
    if words[-1][-1] != word[0]:
      print("No")
      isOK = False
      break
  words += [word]


if isOK:
  print("Yes")

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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
const int inf = 1e9, maxn = 2e5, mod = 998244353;

struct Vector
{
    int x, y;
    Vector(int _x = 0, int _y = 0) : x(_x), y(_y) {}
};
int operator * (Vector a, Vector b)
{
    return a.x * b.x + a.y * b.y;
}
int operator % (Vector a, Vector b)
{
    return a.x * b.y - a.y * b.x;
}
Vector operator - (Vector a)
{
    return Vector(-a.x, -a.y);
}
bool operator == (Vector a, Vector b)
{
    return ((a * b) > 0) && ((a % b) == 0);
}
void solve(int ci)
{
     ic(n)
     int cp = 26, cl = 1, am = 26;
     while(cp < n) am *= 26, cp += am, cl++;
     n -= (cp - am);
     //cout << n << '\n';
     string ans;
     int p = 1;
     f(cl)
     {
         char c = 'a' + ((n - 1) / p) % 26;
         p *= 26;
         ans += c;
     }
     reverse(all(ans));
     cout << ans;

}
main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    //cin >> t;
    f(t) solve(i + 1);
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
  char c11,c12,c13,c21,c22,c23,c31,c32,c33;
  cin >> c11 >> c12 >> c13 >> c21 >> c22 >> c23 >> c31 >> c32 >> c33;
  cout << c11 << c22 << c33;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i,j;
    char moji[1200];


    for(i=0; i<1200; i++){
        scanf("%c",&moji[i]);
        if(moji[i]=='\n')break;
        if(moji[i]>='a'&&moji[i]<='z')moji[i]=moji[i]-32;
        else if(moji[i]>='A'&&moji[i]<='Z')moji[i]=moji[i]+32;

    }
    for(j=0; j<i; j++){
        printf("%c",moji[j]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2044
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
 
public class Main {

  static final int INF = 1000000001;
  static final int N = 500000;
  static int n, c;
  static int a[], L[], R[];

  public static void merge(int l, int m, int r) {
    int i, j, k;
    int nl = m - l;
    int nr = r - m;

    for (i=0; i<nl; i++) L[i] = a[l + i];
    for (i=0; i<nr; i++) R[i] = a[m + i];
    L[nl] = R[nr] = INF;

    i = j = 0;
    for (k=l; k<r; k++) {
      c++;
      if (L[i] <= R[j])
        a[k] = L[i++];
      else
        a[k] = R[j++];
    }
  }

  static void merge_sort(int l, int r) {
    if (l + 1 < r) {
      int m = (l+r)/2;
      merge_sort(l, m);
      merge_sort(m, r);
      merge(l, m, r);
    }
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    n = Integer.parseInt(sc.next());
    a = new int[n];
    L = new int[n];
    R = new int[n];
    for (int i=0; i<n; i++)
      a[i] = Integer.parseInt(sc.next());

    merge_sort(0, n);
    for (int i=0; i<n; i++)
      System.out.print(String.valueOf(a[i]) + ( (i==n-1) ? '\n' : ' ' ));
    System.out.println(c);
  }
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll dfs(vl &dp, vl &a, int b) {
	if (dp[b] != -1)return dp[b];
	ll ret = 0;
	for (int i = b;i>0; i = ((i - 1)&b)) {

		ret = max(ret, a[i] + dfs(dp, a, b^i));

	}
	return dp[b] = ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vvl v(n, vl(n));
	REP(i, n)REP(j, n)cin >> v[i][j];
	vl a(1 << n, 0);
	REP(k, 1 << n) {
		REP(i, n)REP(j, n) {
			if ((k&(1 << i)) && (k&(1 << j))) {
				a[k] += v[i][j];
			}
		}
		a[k] /= 2;
	}
	vl dp(1 << n, -1);
	dp[0] = 0;
	dfs(dp, a, (1 << n) - 1);
	cout << dp[(1 << n) - 1] << endl;
}

Measured memory_bytes: 1280
#include<stdio.h>

int main(void){
    int A = 0;
    int B = 0;
    int i = 0, j = 0;


    scanf("%d %d", &A, &B);
    if(B == 1){
        printf("%d", 0);
        return 0;
    }

    while(1){
        if(B<=A){
            i++;
            break;
        }
        B = B-(A-1);
        i++;
    }

    printf("%d", i);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
int main(){
    int n,x,y;
    cin>>n>>x>>y;
    int cnt[2010]={};
    //min{|j−i|,|X−i|+1+|j−Y|,|Y −i|+1+|j−X|}
    rep(i,1,n+1)rep(j,i+1,n+1){
        cnt[min(j-i,abs(x-i)+1+abs(y-j))]++;;
    }
    rep(i,1,n){
        cout<<cnt[i]<<endl;
    }
}

Measured memory_bytes: 256
from sys import stdin
import heapq
def main():

    input = stdin.readline

    K = int(input())

    h = []
    
    for i in range(1,10):
        heapq.heappush(h,i)
    
    for i in range(K):
        ans = heapq.heappop(h)

        if ans % 10 != 0:
            heapq.heappush(h,ans * 10 + (ans % 10 - 1))
        heapq.heappush(h,ans*10 + (ans%10))
        if ans % 10 != 9:
            heapq.heappush(h,ans * 10 + (ans % 10 + 1))
    
    print(ans)

if __name__ == "__main__":
    main()

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

int main(){
    
    int x;
    cin >> x;
    if(x<=599){
        cout<<8<<'\n';
    }else if(x<=799){
        cout<<7<<'\n';
    }else if(x<=999){
        cout<<6<<'\n';
    }else if(x<=1199){
        cout<<5<<'\n';
    }else if(x<=1399){
        cout<<4<<'\n';
    }else if(x<=1599){
        cout<<3<<'\n';
    }else if(x<=1799){
        cout<<2<<'\n';
    }else{
        cout<<1<<'\n';
    }

    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<queue>
#include<map>
using namespace std;
long long s[200005],ts[200005],in[200005];
void p(int pos)
{
	while(pos<=200003)
	{
		in[pos]+=1;
		pos+=pos&(-pos);
	}
	
}
long long sum(int n)
{
	long long sum=0;
	while(n>0)
	{
		sum+=in[n];
		n-=n&(-n);
	}
	return sum;
}
int main()
{

	int n,k,x;
	long long ans=0;
	memset(s,0,sizeof(s));
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)  	
	{
		scanf("%d",&x),s[i]=x-k+s[i-1],ts[i]=s[i];
		if(s[i]>=0)
		ans++;
		}
	sort(ts+1,ts+1+n);
	int size=unique(ts+1,ts+1+n)-ts+1;
	for(int i=1;i<=n;i++)   s[i]=lower_bound(ts+1,ts+1+size,s[i])-ts;
	memset(in,0,sizeof(in));
	for(int i=1;i<=n;i++)
		{
			ans+=sum(s[i]);
			p(s[i]);
		}
	
	printf("%lld\n",ans);
	return 0;
 } 

Measured memory_bytes: 4992
def popcount(x):
    c = 0
    while x > 0:
        if x & 1:
            c += 1
        x = x >> 1
    return c

def f(A):
    MOD = (10 ** 9) + 7
    n = len(A)

    dp = [0] * (1 << n)
    dp[0] = 1

    for mask in range((1 << n) - 1):
        a = popcount(mask)
        for b in range(n):
            if A[a][b] and not (mask & (1 << b)):
                m2 = mask ^ (1 << b)
                dp[m2] += dp[mask]
                if dp[m2] > MOD:
                    dp[m2] -= MOD

    return dp[(1 << n) - 1]

assert f([[0, 1, 1], [1, 0, 1], [1, 1, 1]]) == 3

n = int(input())
A = []
for _ in range(n):
    R = list(map(int, input().split()))
    A.append(R)

ans = f(A)
print(ans)


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		


int main() {

	ll n, c;
	cin >> n >> c;

	VLL x(n), v(n);

	REP(i, n)cin >> x[i] >> v[i];

	VLL y(n), z(n);
	y[0] = v[0];
	z[n - 1] = v[n - 1];
	FOR(i, 1, n)y[i] = y[i - 1] + v[i];
	for (int i = n - 2; i >= 0; i--) z[i] = z[i + 1] + v[i];

	ll ans = 0;

	REP(i, n) {
		y[i] -= x[i];
		z[i] -= c - x[i];
		chmax(ans, y[i]);
		chmax(ans, z[i]);
	}


	FOR(i, 1, n)y[i] = max(y[i], y[i - 1]);
	for (int i = n - 2; i >= 0; i--)z[i] = max(z[i], z[i + 1]);

	REP(i, n - 1) {
		ans = max(ans, y[i] + z[i + 1] - min(x[i], c - x[i + 1]));
	}

	cout << ans << endl;


	return 0;

}


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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) { 
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) { 
        return -par[root(x)];
    }
};

int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	pair<int,int> ab[m];
	for (int i = 0; i < m; ++i)
	{
		cin>>ab[i].first>>ab[i].second;
		--ab[i].first;--ab[i].second;
	}
	reverse(ab,ab+m);
	long long now=(long long)n*(n-1)/2LL,ans[m];
	UnionFind uf(n);
	for (int i = 0; i < m; ++i)
	{
		ans[i]=now;
		if (uf.issame(ab[i].first,ab[i].second))
		{
			continue;
		}
		now-=(long long)uf.size(ab[i].first)*uf.size(ab[i].second);
		uf.merge(ab[i].first,ab[i].second);
	}
	reverse(ans,ans+m);
	for (auto v:ans)
	{
		cout<<v<<endl;
	}
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string n;
  int c=0;
  cin>>n;
  if(n[0]==n[2]){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=500005,INF=1<<30,D=900;
int N,Q;
int A[MAX],cnt[MAX],ans[MAX];
int sum=0,l=-1,r=-1;

struct dat{
    int l;
    int r;
    int id;
};

vector<dat> S;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>Q;
    for(int i=0;i<N;i++) cin>>A[i];
    
    S.resize(Q);
    for(int i=0;i<Q;i++){
        cin>>S[i].l>>S[i].r;
        S[i].id=i;
        S[i].l--;S[i].r--;
    }
    
    sort(all(S),[](auto a,auto b){
        if(a.l/D==b.l/D) return a.r<b.r;
        return a.l/D<b.l/D;
    });
    
    for(int i=0;i<Q;i++){
        while(S[i].r<r){
            cnt[A[r]]--;
            if(cnt[A[r]]==0) sum--;
            r--;
        }
        while(S[i].r>r){
            cnt[A[r+1]]++;
            if(cnt[A[r+1]]==1) sum++;
            r++;
        }
        
        while(S[i].l<l){
            cnt[A[l-1]]++;
            if(cnt[A[l-1]]==1) sum++;
            l--;
        }
        while(S[i].l>l){
            cnt[A[l]]--;
            if(cnt[A[l]]==0) sum--;
            l++;
        }
        
        ans[S[i].id]=sum;
    }
    
    for(int i=0;i<Q;i++) cout<<ans[i]<<"\n";
}


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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	long long x, d, k;
	cin >> x >> k >> d;
	x = abs(x);
	long long div = x / d;
	if (k >= div)
	{
		k -= div;
		x -= div * d;
		k %= 2;
	}
	cout << abs(x - k * d);
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int N;
    static int K;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        A = sc.nextIntArray(N);
        System.out.println( solve() );
    }

    private static long solve() {
        int[] dupe = new int[N+1];
        for (int i = 0; i < N; i++) {
            dupe[A[i]]++;
        }
        Arrays.sort(dupe);

        int start = -1;
        for (int i = 0; i < dupe.length; i++) {
            if( dupe[i] != 0 ) {
                start = i;
                break;
            }
        }

        int k = N+1 - start;

        if( k <= K ) return 0;

        long ans = 0;
        for (int i = 0; i < k-K; i++) {
            int index = i + start;
            ans += dupe[index];
        }
        return ans;
    }

    static class FastScanner {

        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 45780
X = list(map(int,input().split()))

A = X[0]
B = X[1]
C = X[2]
D = X[3]


n = 0
while C>0:
  C = C-B
  n += 1

m = 0
while A>0:
  A = A-D
  m += 1

if n<=m:
  print("Yes")
else:
  print("No")

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


time= int(input())
#tmp = input()
#time = list(map(lambda a: int(a), tmp))
#print(time)
s= time%60
time//=60
m= time%60
h=time//60

out=""
out+=str(h)+":"+str(m)+":"+str(s)
print(out)





Measured memory_bytes: 5592
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,b,ave:Integer;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(a);
    Readln(b);

    if frac((a+b)/2)<>0 then
      ave:=(a+b) div 2 +1
    else
      ave:=(a+b) div 2;
    Writeln(ave);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


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

struct Node {
    int key;
    struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

void insert(int k){
    struct Node *y = NIL;
    struct Node *x = root;
    struct Node *z;

    z = (struct Node *)malloc(sizeof(struct Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    

    while(x!= NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        } else{
            x = x->right;
        }
    }
    
    z->parent = y;
    if(y == NIL){
        root = z;
    } else{
        if( z->key < y->key){
            y->left = z;
        } else{
            y->right = z;
        }
    }

}

void find(int key){
    struct Node *x = root;

    while(x != NIL){
        if(x->key > key){
            x = x->left;
        } else if(x->key < key) {
            x = x->right;
        } else{
            printf("yes\n");
            return;
        }
    }

    printf("no\n");
}

void inorder(struct Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(struct Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, i, x;
    char com[10];
    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s", com);
        if(com[0] == 'i'){
            scanf("%d", &x);
            insert(x);
        } else if(com[0] == 'f'){
            scanf("%d", &x);
            find(x);
        } else{
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");

        }
    }

    return 0;
}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO

    int n;
    string s;

    cin >> n >> s;

    int ans = 0;
    for(int i = 0; i < n - 2; i++) {
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
    }
    cout << ans;

}









Measured memory_bytes: 256
/**
     **author : _KMS_
     **created : 05-03-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =6e5,MOD=2e9;
typedef long long ll;

int main() {
      
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   bool f=0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
         int a;
         cin>>a;
         if(a%2==0)
         {
               if(a%3==0||a%5==0)continue;
               else f=1;
         }
   }
   if(!f)cout<<"APPROVED"<<endl;
   else cout<<"DENIED"<<endl;
   
   return 0;
}

Measured memory_bytes: 256
w,h,x,y = map(int,input().split())
#最大の面積を求める
ans = (w * h) /2
#xとy共に偶数かつ2で割った時の数値がx,yと同じになる場合1を出力するようにする
#それ以外は0を出力させる
if w / 2 == x and h / 2 == y:
  num = 1
else:
  num = 0
print(ans,num)

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string a, b, c;
  cin >> a >> b >> c;

  for(int i = 0; i < a.length(); i++){
    a[i] += ('A'-'a');
  }

  for(int i = 0; i < b.length(); i++){
    b[i] += ('A'-'a');
  }
  for(int i = 0; i < c.length(); i++){
    c[i] += ('A'-'a');
  }

  cout << a[0] << b[0] << c[0] << endl;
  return 0;
}


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

using namespace std;

inline int gcd ( int a, int b )
{
  int c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}
int main(){
    int n,k;
    int a[122222] = {};
    cin >> n >> k;
    string ng = "IMPOSSIBLE";
    string ok = "POSSIBLE";
    int t;
    int m = 1;
    for(int i = 0;i<n;++i){
        cin >> t;a[i]=t;
        if (m<t)m=t;
        if(t==k){
            cout << ok <<endl;return 0;
        }
    }

    if(m<k){
        cout << ng<<endl;return 0;
    }
    int g = gcd(a[0],a[1]);
    for(int i = 2;i<n;++i){
        g = gcd(g,a[i]);
    }
    for(int i=0;i<n;++i){
        if(a[i]>k && (a[i]-k)%g==0){
            cout << ok<<endl;
            return 0;
        }
    }
    cout << ng;
    return 0;
}

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

template
<
    typename TYPE,
    std::size_t SIZE
>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;

#define REP(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))



int main()
{
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int d  = pow(2,k);
    ll ans = max({a*d+b+c,a+b*d+c,a+b+c*d});
    cout << ans << endl;
}

Measured memory_bytes: 256
from math import ceil, floor

h, w = map(int, input().split())

if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    def calc_diff_a(h, w):
        a = ceil(h / 3) * w
        b = (h - ceil(h / 3)) * floor(w / 2)
        c = (h - ceil(h / 3)) * ceil(w / 2)
        diff = max(a, b, c) - min(a, b, c)
        a = floor(h / 3) * w
        b = (h - floor(h / 3)) * floor(w / 2)
        c = (h - floor(h / 3)) * ceil(w / 2)
        diff = min(diff, max(a, b, c) -min(a, b,c))
        return diff
    def calc_diff_b(h, w):
        a = ceil(h / 3) * w
        b = floor((h - ceil(h / 3)) / 2) * w
        c = ceil((h - ceil(h / 3)) / 2) * w
        diff = max(a, b, c) - min(a, b, c)
        a = floor(h / 3) * w
        b = floor((h - floor(h / 3)) / 2) * w
        c = ceil((h - floor(h / 3)) / 2) * w
        diff = min(diff, max(a, b, c) - min(a, b, c))
        return diff

    print(min(calc_diff_a(h, w), calc_diff_a(w, h), calc_diff_b(h, w), calc_diff_b(w, h)))



Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

#define mod 1000000007
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

int main(){
    ll N, D;
    cin >> N >> D;
    D=D*D;
    vector<ll> x(N), y(N);
    ll count = 0;
    rep(i, N){
        cin >> x[i] >> y[i];
        if(x[i]*x[i]+y[i]*y[i]<=D) count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 6372
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long n, i, a, m;
    cin>>n;
    m = n - 1;
    for(int i = 2;i <= sqrt(n);i++)
    {
        if(n % i == 0)
        {
            a = n/i + i - 2;
            if(a < m)
                m = a;
        }
    }
    cout<<m;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define long long long
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

template<class T>
void dump(const T &a) {
  for (int i = 0 ; i < a.size(); ++i) {
    cout << a[i] << (i+1 < a.size() ? ' ' : LF);
  }
}

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

  int N; cin >> N;
  vector<int> a(N);

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

  vector<int> b = a;

  if (prev_permutation(ALL(a))) dump(a);
  dump(b);
  if (next_permutation(ALL(b))) dump(b);

  return 0;
}




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

int main()
{
	char c;
	// string op;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
	{
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 3640
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

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

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();

        int minCost = 10001;

        for(int i=0; i<n; i++){
            int cost = sc.nextInt();
            int time = sc.nextInt();

            if(time <= t){
                minCost = Math.min(minCost, cost);
            }
        }

        if(minCost == 10001) System.out.println("TLE");
        else System.out.println(minCost);
    }
}


Measured memory_bytes: 23764
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#ifdef PERVEEVM_LOCAL
    #define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
    #define debug(x) 238;
#endif

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define NAME "File"

using ll = long long;
using ld = long double;

#ifdef PERVEEVM_LOCAL
    std::mt19937 rnd(238);
#else
    std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 110;
const int W = 100100;

ll dp[N][W];
int w[N], v[N];

void run() {
    int n, m;
    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &w[i], &v[i]);
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < W; ++j) {
            dp[i][j] = -1;
        }
    }
    dp[0][0] = 0;

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            dp[i][j] = dp[i - 1][j];

            if (j - w[i] >= 0 && dp[i - 1][j - w[i]] != -1) {
                dp[i][j] = std::max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i <= m; ++i) {
        ans = std::max(ans, dp[n][i]);
    }

    printf("%lld\n", ans);
}

int main(void) {
    // freopen(NAME".in", "r", stdin);
    // freopen(NAME".out", "w", stdout);

    auto start = std::chrono::high_resolution_clock::now();
    run();
    auto end = std::chrono::high_resolution_clock::now();

    #ifdef PERVEEVM_LOCAL
        std::cerr << "Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
                  << " ms" << std::endl;
    #endif

    return 0;
}


Measured memory_bytes: 86272
#include <stdio.h>

typedef struct {
	int num;
	int dis;
} DATA;

int main(void)
{
	int i;
	int n, p, d1, d2;
	int max;
	
	DATA data[10000];
	
	while (scanf("%d", &n), n){
		max = 0;
		for (i = 0; i < n; i++){
			scanf("%d %d %d", &p, &d1, &d2);
			data[i].num = p;
			data[i].dis = d1 + d2;
			max = (data[max].dis < (d1 + d2))? i : max;
		}
		
		printf("%d %d\n", data[max].num, data[max].dis);
	}
	
	return (0);
}

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


using namespace std;

int main(){
        string s;
        const string ref = "CODEFESTIVAL2016";
        cin >> s;
        int c = 0;
        for(int i=0; i<ref.size(); ++i){
                if(ref[i] != s[i]) ++c;
        }
        cout << c << endl;
        return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <ctype.h>

typedef struct str {
    int len;
    char s[80];
} str;

int comp(str* a, str* b)
{
    if (a->len<b->len) return -1;
    if (a->len>b->len) return 1;
    return strcmp(a->s, b->s);
}
    
void init(str* a) { a->len=0; memset(a->s, 0, sizeof(a->s)); }
void copy(str* a, str* b)
{
    a->len=b->len;
    memcpy(a->s, b->s, sizeof(a->s));
}
void add(int x, str* a)
{
    int i=a->len;
    for(i=a->len;i>0;--i) a->s[i]=a->s[i-1];
    a->s[0]=x;
    (a->len)++;
}

int c[80][80], w, h;
str memo[80][80];

str* func(int i, int j)
{
    str res;
    if (memo[i][j].len>0) return &memo[i][j];

    init(&res);
    if (i+1<h && c[i+1][j]>=0) {
        str t;
        copy(&t, func(i+1, j));
        if (comp(&res, &t)<0) copy(&res, &t);
    }
    if (j+1<w && c[i][j+1]>=0) {
        str t;
        copy(&t, func(i, j+1));
        if (comp(&res, &t)<0) copy(&res, &t);
    }
    add(c[i][j], &res);
    copy(&memo[i][j], &res);
    return &memo[i][j];
}

int main(void)
{
    while (scanf("%d%d", &w, &h), w) {
        int i, j;
        str res;
        memset(c, -1, sizeof(c));
        for(i=0;i<h;++i) {
            char s[80];
            scanf("%s", s);
            for(j=0;j<w;++j) if (isdigit(s[j])) c[i][j]=s[j];
        }

        for(i=0;i<h;++i) for(j=0;j<w;++j) init(&memo[i][j]);
        for(i=0;i<h;++i) for(j=0;j<w;++j)
            if (c[i][j]>'0' && !memo[i][j].len) func(i, j);

        init(&res);
        for(i=0;i<h;++i) for(j=0;j<w;++j)
            if (comp(&res, &memo[i][j])<0) copy(&res, &memo[i][j]);

        puts(res.s);
    }
    return 0;
}

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

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

const int INF=1e9;
const int MOD=1e9+7;

int main(){
    ll K; cin >> K;
    ll res=7%K;
    if(res==0){
        cout << 1 << endl;
        return 0;
    }
    for(int i=1;i<10000000;i++){
        res=(res*10+7)%K;
        if(res==0){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

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

typedef long long ll;

const int kMaxN = 100;

int N;
int A[2][kMaxN];
int ans = 0;

int c = 0;

int main() {
  cin >> N;
  REP(j, N) { cin >> A[0][j]; }
  REP(j, N) { cin >> A[1][j]; }

  c += A[0][0];
  REP(j, N) { c += A[1][j]; }
  ans = c;
  REP(j, N-1) {
    c = c + A[0][j+1] - A[1][j];
    ans = max(ans, c);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<lint> a(n); for (int i = 0; i < n; i++) cin >> a[i];
  VV<> g(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v; cin >> u >> v, u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (n == 2) return cout << (a[0] == a[1] ? "YES" : "NO") << '\n', 0;
  V<> d(n, -1);
  for (int r = 0; r < n; r++) if (g[r].size() > 1) {
    queue<int> q;
    d[r] = 0; q.push(r);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      for (int i : g[v]) if(d[i] == -1) {
        d[i] = d[v] + 1; q.push(i);
      }
    }
    break;
  }
  int h = *max_element(d.begin(), d.end());
  VV<> vs(h + 1);
  for (int i = 0; i < n; i++) vs[d[i]].push_back(i);
  for (int i = h - 1; i >= 0; i--) for (int v : vs[i]) if (g[v].size() > 1) {
    lint m = -1, s = 0;
    for (int c : g[v]) if (d[c] == d[v] + 1) {
      m = max(m, a[c]);
      s += a[c];
    }
    if (i > 0) {
      if (max(m, (s + 1) / 2) <= a[v] and a[v] <= s) a[v] = 2 * a[v] - s;
      else return cout << "NO" << '\n', 0;
    } else {
      if (2 * a[v] != s) return cout << "NO" << '\n', 0;
    }
  }
  cout << "YES" << '\n';
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

lin n;
lin s[200002];

int main(void)
{
    cin >> n;
    s[0] = 0;
    rep(i, n)
    {
        lin a;
        cin >> a;
        s[i+1] = s[i] + a;
    } 

    lin res = 0;

    sort(s, s + n + 1);

    s[n + 1] = s[n] - 1;

    lin count = 1;

    loop(i, 1, n + 2)
    {
        if(s[i] != s[i - 1])
        {
            res += count * (count - 1) / 2;
            count = 0;
        }
        count++;
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int mapto[200];
int card[4][20];
int point[2];

int main() {
  mapto['S'] = 0;
  mapto['H'] = 1;
  mapto['D'] = 2;
  mapto['C'] = 3;
  mapto['2'] = 0;
  mapto['3'] = 1;
  mapto['4'] = 2;
  mapto['5'] = 3;
  mapto['6'] = 4;
  mapto['7'] = 5;
  mapto['8'] = 6;
  mapto['9'] = 7;
  mapto['T'] = 8;
  mapto['J'] = 9;
  mapto['Q'] = 10;
  mapto['K'] = 11;
  mapto['A'] = 12;
  char c;
  while (scanf(" %c ", &c), c != '#') {
    int trump = mapto[(int)c];
    point[0] = point[1] = 0;
    REP(i, 4) {
      REP(j, 13) {
        char d, s;
        scanf(" %c %c ", &d, &s);
        int num = mapto[(int)d];
        int suit = mapto[(int)s];
        card[i][j] = num + suit * 13;
      }
    }
    int parent = 0;
    REP(i, 13) {
      int psuit = card[parent][i] / 13;
      int winner = 0;
      int maxvalue = -1;
      REP(j, 4) {
        int num = card[j][i] % 13;
        int suit = card[j][i] / 13;
        int value = num;
        if (suit == psuit) { value += 100; }
        if (suit == trump) { value += 1000; }
        if (value > maxvalue) {
          maxvalue = value;
          winner = j;
        }
      }
      point[winner % 2]++;
      parent = winner;
    }
    if (point[0] > point[1]) {
      printf("NS %d\n", point[0] - 6);
    } else {
      printf("EW %d\n", point[1] - 6);
    }
  }
}

Measured memory_bytes: 0
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    ll n = 1e9 + 7;
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    map <ll, ll> m;
    for (ll i = b; i <= a+1; i++){
        ans += (a*i - i*(i-1) + 1)%n;
    }
    cout << ans%n;
    return 0;
}




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

// 内部定数
#define D_MAX_SIZE		50										// 最大サイズ
#define D_MASS_BLACK	'#'										// 黒マス

// 内部変数
static int siH;													// 高さ
static int siW;													// 幅
static char sc2Mass[D_MAX_SIZE][D_MAX_SIZE + 5];				// マス

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 黒マス判定
int
fChkMassBlack(
	int piRow					// <I> 行 0～
	, int piCol					// <I> 列 0～
)
{
	// 範囲チェック
	if (piRow < 0 || siH <= piRow) {
		return -1;
	}
	if (piCol < 0 || siW <= piCol) {
		return -1;
	}

	// 黒マス判定
	if (sc2Mass[piRow][piCol] == D_MASS_BLACK) {	// 黒マス
		return 0;
	}

	return -1;
}

// マス判定
int
fChkMass(
)
{
	int i, j, liRet;

	for (i = 0; i < siH; i++) {
		for (j = 0; j < siW; j++) {

			// 黒マス判定
			if (sc2Mass[i][j] != D_MASS_BLACK) {	// 黒マス以外
				continue;
			}

			// 右方向
			liRet = fChkMassBlack(i, j + 1);
			if (liRet == 0) {						// 黒マス
				continue;
			}

			// 左方向
			liRet = fChkMassBlack(i, j - 1);
			if (liRet == 0) {						// 黒マス
				continue;
			}

			// 上方向
			liRet = fChkMassBlack(i + 1, j);
			if (liRet == 0) {						// 黒マス
				continue;
			}

			// 下方向
			liRet = fChkMassBlack(i - 1, j);
			if (liRet == 0) {						// 黒マス
				continue;
			}

			// 黒マスなし
			return -1;
		}
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i, liRet;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 高さ・幅取得
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &siH, &siW);

	// マス取得
	for (i = 0; i < siH; i++) {
#ifdef D_TEST
		fgets(sc2Mass[i], sizeof(sc2Mass[i]), szpFpT);
#else
		fgets(sc2Mass[i], sizeof(sc2Mass[i]), stdin);
#endif
	}

	// マス判定
	liRet = fChkMass();

	// 結果セット
	if (liRet == 0) {
		sprintf(lc1Out, "Yes\n");
	}
	else {
		sprintf(lc1Out, "No\n");
	}

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
using ll = long long;
using ui = unsigned int;


int main() {
    int N;
    cin >> N;
    vector<ll> A;
    ll s = 0;
    for (int i=0; i<N; i++) {
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
        s += tmp;
    }
    vector<ll> X(N);
    X[0] = s;
    for (int i = 1; i < N-1; i+=2)
    {
        X[0] -= 2*A[i];
    }
    
    for (int i = 1; i < N; i++)
    {
        X[i] = 2 * A[i-1] - X[i-1];
    }

    for (auto e : X) {
        cout << e << " ";
    }
    cout << "\n";
}

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	N := nextInt()
	s := nextString()

	s += string(s[0])
	starts := [][]string{{"S", "S"}, {"S", "W"}, {"W", "S"}, {"W", "W"}}
	for _, start := range starts {
		animals := make([]string, N+2)
		animals[0] = start[0]
		animals[1] = start[1]
		for i := 1; i <= N; i++ {
			if animals[i] == "S" {
				if s[i] == 'o' {
					if animals[i-1] == "S" {
						animals[i+1] = "S"
					} else {
						animals[i+1] = "W"
					}
				} else {
					if animals[i-1] == "S" {
						animals[i+1] = "W"
					} else {
						animals[i+1] = "S"
					}
				}
			} else {
				if s[i] == 'o' {
					if animals[i-1] == "S" {
						animals[i+1] = "W"
					} else {
						animals[i+1] = "S"
					}
				} else {
					if animals[i-1] == "S" {
						animals[i+1] = "S"
					} else {
						animals[i+1] = "W"
					}
				}
			}
		}

		if animals[0] == animals[N] && animals[1] == animals[N+1] {
			fmt.Println(strings.Join(animals[:N], ""))
			return
		}
	}

	fmt.Println(-1)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()

	return sc.Text()
}

// ---------- Input.


Measured memory_bytes: 6144
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using System.Threading.Tasks;
class MainClass : Scanner
{
    static void Main()
    {
        long N = RLong();
        long max = 3500;
        for (long h = 1; h < max; h++)
        {
            for (long n = h; n < max; n++)
            {
                long ans = long.MaxValue;
                int lb = 0, ub = 3501;
                while (ub - lb > 1)
                {
                    var w = (lb + ub) / 2;
                    ans = N * (n * w + w * h + h * n) - 4 * h * n * w;
                    if (ans > 0) lb = w;
                    else ub = w;
                }
                ans = N * (n * ub + ub * h + h * n) - 4 * h * n * ub;
                if (ans == 0)
                {
                    WriteLine($"{h} {n} {ub}");
                    return;
                }
            }
        }
    }
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

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

int main(void){
  int A,B,C,X;
  int ans = 0;

  scanf("%d%d%d%d",&A,&B,&C,&X);

  for(int i = 0;i <= A;i++){
    for(int j = 0;j <= B;j++){
      for(int k = 0;k <= C;k++){
        if(500*i+100*j+50*k == X){
          ans++;
        }
      }
    }
  }

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

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}



int main() {
    ll N,ans;
    cin >> N;
    ans = (N-1)*N/2;

    cout << ans << endl;
    
    
    return 0;
    

}

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

int main(){
  int n, x, t;
  cin >> n >> x >> t;
  int time;
  if(n%x==0) time = n / x;
  else time = n / x + 1;
  int ans = time * t;
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
import math
a,b,h,m=map(float,input().split(" "))

h=h%12
th_h=30*h+0.5*m
th_m=6*m
theita=abs(th_h-th_m)
if theita<180:
    print('%.20f'%math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(theita))))
elif theita>180:
    theita=360-theita
    print('%.20f'%math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(theita))))
else:
    print(a+b)


Measured memory_bytes: 9460