akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M);

    rep(i,M) cin >> A[i];

    // 初期化
    ll match[10] = {2,5,5,4,5,6,3,7,6};
    vector<string>dp(11000,"-");
    dp[0] = "";

    // DP ループ
    rep(i,N){
        if (dp[i] == "-") continue;
        for (auto a : A){
            string s1=dp[i+match[a-1]];
            string s2=dp[i] + (char)('0' + a);
            if(s1.size()<s2.size())dp[i+match[a-1]]=s2;
            else if(s1.size()==s2.size()&&s1<s2)dp[i+match[a-1]]=s2;
            else {
                dp[i + match[a - 1]] = dp[i + match[a - 1]];
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 43776
#include <stdio.h>

int main()
{
	char ch;
	while(1){
		scanf("%c", &ch);
		if( ch == '\n') break;
		else if('a' <= ch && ch <= 'z') printf("%c", ch - 32);
		else if('A' <= ch && ch <= 'Z') printf("%c", ch + 32);
		else printf("%c", ch);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  int n,m;
  cin >> n;
  map<string,int> ma;
  rep(i,n){
    string s;
    cin >> s;
    if(ma.count(s))ma[s]++;
    else ma[s]=1;
  }
  cin >> m;
  rep(i,m){
    string s;
    cin >> s;
    if(ma.count(s))ma[s]--;
    else ma[s]=-1;
  }
  int ans=0;
  for(auto i:ma)
    ans=max(ans,i.second);
  cout << ans << endl;
}
  
  

Measured memory_bytes: 3600
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

void solve()
{
	int sum = 0;
	string str;
	while(cin >> str)
	{
		int n = str.size();
		for(int i = 0; i < n; ++i)
		{
			string s;
			if('0' <= str[i] && str[i] <= '9')
			{
				while(i < n && '0' <= str[i] && str[i] <= '9')
				{
					s += str[i];
					++i;
				}
			}
			int size = s.size();
			char* c = new char[size];
			for(int j = 0; j < size; ++j)
			{
				c[j] = s[j];
			}
			sum += atoi(c);
			delete c;
		}
	}
	cout << sum << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, k;
    cin >> n >> k;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    ll in1 = 0;
    rep(i, n){
        if(a[i] == 1){
            in1 = i;
            break;
        }
    }
    ll ans = 0;
    ll i = in1;
    while(i > 0){
        i -= k-1;
        ans++;
    }
    in1 += -i;
    i = in1;
    while(i < n-1){
        i += k-1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int H[N];
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  bool f=true;
  
  for(int i=N-1;i>0;i--){
    if(H[i-1] > H[i]+1){
      f=false;
      break;
    }
    else if(H[i-1] == H[i]+1){
      H[i-1] -= 1;
    }
  }
  cout << (f?"Yes":"No") <<endl;
  
}

Measured memory_bytes: 640
n = int(input())
B = [int(x) for x in input().split()]

ans = [0]*n

for i in range(n-1):
    if B[i] >= B[i+1]:
        ans[i] = 1

cnt = 0
a = 0
for j in range(n):
    
    if ans[j] == 1:
        cnt += 1
    else:
        a = max(a,cnt)
        cnt = 0

print(a)

Measured memory_bytes: 19948
'use strict';

function main(input) {
  let str = input.split('\n')[0];
  const words = ['dream', 'dreamer', 'erase', 'eraser'];

  while (str) {
    let flg = false;
    words.forEach(word => {
      let len = word.length;
      if (str.substr(-len, len) === word) {
        str = str.substr(0, str.length - len);
        flg = true;
        return;
      }
    });

    if (!flg) {
      break;
    }
  }

  str ? console.log('NO') : console.log('YES');
}

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


Measured memory_bytes: 10040
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int>score(n);
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin >> score[i];
		sum += score[i];
	}
	sort(score.begin(), score.end());
	for(int i = 0; (i < n && sum % 10 == 0); i++){
		if(score[i]%10 != 0)sum -= score[i];
		//cout << sum << endl;
	}
	if(sum % 10 == 0) sum = 0;
	cout << sum << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = sys.stdin.readline

def main():
    n = int(input())
    As = [int(input()) for i in range(n)]
    sAs = sorted(As)
    mn1 = sAs[-1]
    mn2 = sAs[-2]
    for i in range(n):
        if As[i] == mn1:
            print(mn2)
        else:
            print(mn1)
    return 

if __name__ == '__main__':
    main()

Measured memory_bytes: 85836
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print('F')
        continue
    if m + f >= 80:
        print('A')
        continue
    if m + f >= 65:
        print('B')
        continue
    if m + f >= 50:
        print('C')
        continue
    if m + f >= 30:
        if r >= 50:
            print('C')
        else:
            print('D')
        continue

    print('F')


Measured memory_bytes: 5592
#include<stdio.h>
int main(){
  double a;
  int b;
  double t;
  int count;
  double ans;
  int i_ans;

  scanf("%lf", &a);
  scanf("%d", &b);
  scanf("%lf", &t);
  t = t + 0.5;
  count = t / a;
  ans = count * b;
  i_ans = (int) ans;
  printf("%d\n", i_ans);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

lli power(lli n,lli a)
{
	lli res=1;
	while(n)
	{
		if(n%2)
			a*=a;
		res*=a;
		n>>=1;	
	}	
	cout<<res<<endl;
	return res;
}

int main()
{
	fastio;
	lli n,d,i;
	cin>>n>>d;
	lli a,b,ans=0;
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(sqrt(a*a+b*b)<=d)
			ans++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3688
/*
	0583:Common Divisors
*/
#include	<iostream>
#include	<algorithm>

using namespace std;

int main(void) {
	int num;
	int a, b, c;
	int kmin;
	
	cin >> num;
	
	if(num == 2) {
		cin >> a >> b;
		
		kmin = min(a, b);
		for(int i = 1; i < kmin; i++) {
			if(a % i == 0 && b % i == 0) {
				cout << i << endl;
			}
		}
		if(a % kmin == 0 && b % kmin == 0) {
			cout << kmin << endl;
		}
	} else {
		cin >> a >> b >> c;
		
		kmin = min(a, min(b, c));
		for(int i = 1; i < kmin; i++) {
			if(a % i == 0 && b % i == 0 && c % i == 0) {
				cout << i << endl;
			}
		}
		if(a % kmin == 0 && b % kmin == 0 && c % kmin == 0) {
			cout << kmin << endl;
		}
	}
	
	return 0;
}

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

using LL = long long;

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

    LL x, y, z, res;

    cin >> x >> y >> z;

    for (res = 50000; res > 0; res--)
    {
        if (y * res + z * (res + 1) <= x)
        {
            break;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
a= list(map(int,input().split()))
b= list(map(int,input().split()))

waribiki=[]

for _ in range(M):
    waribiki.append(list(map(int,input().split())))

MIN=min(a)+min(b)

for wari in waribiki:
    x=wari[0]-1
    y=wari[1]-1
    value=wari[2]
    total=a[x]+b[y]-value
    if(total < MIN):
        MIN=total

print(MIN)




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

using namespace std;
using ll = long long;

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

	int now = 0;
	int res = 1;
	for (int i = 0; i < N; ++i) {
		now = now + L[i];
		if (now > X) { break; }
		++res;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
import java.util.Arrays;

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

        int[] array = new int[3];

        for(int i=0;i<3;i++){
        String str = scan.next();
        array[i] = Integer.parseInt(str);
        }

        Arrays.sort(array);

        System.out.println(array[0] + " " + array[1] + " " + array[2]);
    }
}


Measured memory_bytes: 26156
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, W = reads()

items = [[] for _ in range(4)]
w1, v1 = reads()
items[0].append(v1)

for _ in range(N-1):
  w, v = reads()
  items[w-w1].append(v)

psums = []
for u in range(4):
  items[u].sort()
  items[u].reverse()
  psums.append([0] +list(accumulate(items[u])))

ans = 0
for p in product(*(range(len(items[u])+1) for u in range(4))):
  if sum((w1+u)*p[u] for u in range(4)) <= W:
    ans = max(ans, sum(psums[u][p[u]] for u in range(4)))
print(ans)

  

Measured memory_bytes: 44524
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define in read()
#define re register
#define fur(i,a,b) for(re int i=a;i<=b;++i)
#define fdr(i,a,b) for(re int i=a;i>=b;--i)
#define cl(a,b) memset(a,b,sizeof(a))
#define jinitaimei signed
#define int long long
inline int read()
{
	int x=0;
	char ch=getchar();
	for(;!isalnum(ch);ch=getchar());
	for(;isalnum(ch);ch=getchar()) x=x*10+ch-'0';
	return x;
}
const int xx=1e5+1612;
int to[xx][18];
int x[xx],n,L;
inline void init()
{
	n=in;
	fur(i,1,n) x[i]=in;
	L=in;
	int j=n;
	to[n][0]=j;
	fdr(i,n-1,1)
	{
		while(x[j]-x[i]>L) --j;
		to[i][0]=j;
	}
	fur(k,1,17) fur(i,1,n) to[i][k]=to[to[i][k-1]][k-1];
}
inline int power(int b,int k)
{
	int res=1;
	for(;k;k>>=1,b=b*b) if(k&1) res=res*b;
	return res;
}
inline void sol(int a,int b)
{
	if(a>b) swap(a,b);
	int j=a,g=17;
	int ans=0;
	while(j<b)
	{
		while(to[j][g]>b&&g) --g;
		if(b==n) while(to[j][g]==b&&g) --g;
		j=to[j][g];
		ans+=power(2,g);
	}
	printf("%lld\n",ans);
}
jinitaimei main()
{
	init();
	int T=in;
	while(T--) sol(in,in);
	return 0;
}

Measured memory_bytes: 15616
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			// 何故かintにすると一部表記が狂うようでクリアできない
			// (Integer.parseUnsignedInt使用)
			long x = sc.nextLong();

			System.out.println(toPaddedBinaryString(x));
			System.out.println(toPaddedBinaryString(~x));
			System.out.println(toPaddedBinaryString(x<<1));
			System.out.println(toPaddedBinaryString(x>>1));
		}
	}
	/**
	 * 0パディングするのである
	 * @param bin バイナリするlong
	 * @return
	 */
	public static String toPaddedBinaryString(long bin) {
		String result = String.format("%32s", Long.toBinaryString(bin)).replaceAll(" ", "0");
		if(result.length()>32)
			return result.substring(result.length()-32);
		return result;
	}
}


Measured memory_bytes: 26404
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

// int count1(string x){
//   //string s = to_string(x);
//   int cnt = 0;
//   rep (i,x.size()){
//     if (x[i]=='1') cnt++;
//   }
//   return cnt;
// }



  








int main() {
  ll n,cnt = 0;
  cin >> n;
  string s;
  cin >> s;
  string copy = s;
  ll leftw=0,redc;
  rep (i,n-1){
    if (copy[i]=='W' && copy[i+1]=='R'){
      leftw++;
      copy[i+1]='W';
      redc++;
    }
    else if(copy[i]=='R') redc++;
  }
  string hako="";
  rep (i,redc){
    hako += 'R';
  }
  for (ll i = redc;i < n;i++){
    hako += 'W';
  }

  for (ll i = 0;i < n;i++){
    if (hako[i] != s[i]) cnt++;
  }
  cnt /= 2;

  if (cnt <= leftw) cout << cnt << endl;
  else cout << leftw << endl;
}



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

int main(){

    int a,b,c;
    cin >> a >> b >> c;
    int d = a/b;
    int r = a%b;
    cout << d << " " << r <<" "<< fixed << setprecision(6) << (double)a/(double)b << endl;    
}



Measured memory_bytes: 3256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

struct S {
    string s;
    int p,i;
};

void solve() {
    int n;
    cin >> n;
    vector<S> s(n);
    REP(i,0,n) {
        cin >> s[i].s >> s[i].p;
        s[i].i = i+1;
    }
    sort(all(s), [](auto &l, auto &r) {
        return l.s == r.s ? l.p >= r.p : l.s < r.s;
    });
    REP(i,0,n) cout << s[i].i << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int t,x;
    cin>>t>>x;
    printf("%.10f\n",(double)t/(double)x);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n,q;cin >> n >> q;
    vector<int> a(n,0);
    a[0] = 1;
    int t = 0;
    for (int i = 0; i < q; i++) {
        int x,y;cin >> x >> y;
        x--,y--;
        if(x==t||y==t){
            if(x-1>=0) a[x-1]=true;
            if(x+1<n) a[x+1]=true;
            if(y-1>=0) a[y-1]=true;
            if(y+1<n) a[y+1]=true;
            t = t^x^y;
        }
        if(t-1>=0) a[t-1]=true;
        if(t+1<n) a[t+1]=true;
        swap(a[x],a[y]);
        if(t-1>=0) a[t-1]=true;
        if(t+1<n) a[t+1]=true;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char *argv[])
{
  int n, k, i;
  int *w;
  int max = 0, sum = 0;
  int P_st, P_ed, P_center, k_st, k_ed, k_center, p[3];
 
  scanf("%d", &n);
  scanf("%d", &k);
  w = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d", &w[i]);
    sum += w[i];
    if (max < w[i]) max = w[i];
  }
 
  P_st = max - 1;
  P_ed = sum;
  p[0] = 0;
  p[1] = 0;
  k_st = 1;
  k_ed = 1;
  for (i = 0; i < n; i++) {
    if (p[1] + w[i] > P_ed) {
      k_ed++;
      p[1] = 0;
    }
    p[1] += w[i];
  }
  k_st = 100001;
 
  while (1) {
    P_center = (P_st + P_ed) / 2;
    p[2] = 0;
    k_center = 1;
    for (i = 0; i < n; i++) {
      if (p[2] + w[i] > P_center) {
    if (p[2] == 0) {
      k_center = 100001;
      break;
    }
    k_center++;
    p[2] = 0;
      }
      p[2] += w[i];
    }
    if (k_center > k) {
      P_st = P_center;
      k_st = k_center;
    } else {
      P_ed = P_center;
      k_ed = k_center;
    }
    if (P_ed - P_st <= 1) break;
  }
 
  printf("%d\n", P_ed);
 
  free(w);
 
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll a[100005];
ll ans;
ll gcd(ll a,ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main(void){
    cin>>n;
    cin>>a[0];
    ans=a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        ans=gcd(ans,a[i]);
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define debug(var) cout << #var << ": " << var << endl;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
using ll = long long;
using ull = unsigned long long;
using vvint = vector<vector<int>>;
constexpr ll mod = 1e9 + 7;

int main() {

  int N; cin >> N;
  vector<int> v(N);
  rep(i, N)cin >> v[i];
  sort(v.begin(), v.end());

  double ans = v[0];

  for (int i = 1; i < N; i++) {
	ans = (ans + v[i]) / 2;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <cstdlib>
#define PI acos(-1.0)
#define ll long long int
#define db double
#define ull unsigned long long int
#define Fill(x,y) memset(x,y,sizeof(x))
#define bug printf("!!!!!!\n");
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
using namespace std;
const db eps = 1e-6;
const int inf = 0x3f3f3f3f; //用这个可以直接mem
const ll INF = 1e18;
const int mod = 1e9+7;
const int maxn = 1e5+5;
int cas=1;
void solve()
{
    string s;
    cin >> s;
    string ans = "2018";
    ans += s.substr(4, 6);
    cout << ans << endl;
}
int main()
{
   //  freopen("in.txt","r",stdin);
    //  freopen("out.txt","w",stdout);
    int t = 1 ;
    //scanf("%d",&t);
    while(t--){
       // printf("Case %d: ", cas++);
        solve();
        //printf("\n");
    }
}









Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Reader.init(System.in);
		StringBuffer output=new StringBuffer("");
		PrintWriter out=new PrintWriter(System.out);
		int n=Reader.nextInt();
		int w=Reader.nextInt();
		long ans=0;
		long[][] arr=new long[n][2];
		for(int i=0;i<n;i++) {
			arr[i][0]=Reader.nextLong();arr[i][1]=Reader.nextLong();
		}
		long[][] val=new long[2][100001];
		for(int i=0;i<=1;i++) Arrays.fill(val[i], (long)Math.pow(10, 15));
		val[0][0]=0;
		val[1][0]=0;
		
		for(int i=0;i<n;i++) {
			int v=(int)arr[i][1];
			int last=1-i%2;
			int now=i%2;
			for(int j=0;j+v<100001;j++) {
				val[now][j+v]=Math.min(val[last][j+v], val[last][j]+arr[i][0]);
			}
			for(int j=0;j<100001;j++) val[last][j]=val[now][j];
		}
		for(int i=100000;i>=0;i--) {
			if(val[i%2][i]<=w) {
				ans=i;break;
			}
		}
		output.append(ans);
		out.write(output.toString());
		out.flush();
	}

}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
 
    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }
 
    /** get next word */
    static String nextLine() throws IOException{
    	return reader.readLine();
    }
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    
    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


Measured memory_bytes: 24520
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;



public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<ArrayList<Edge>> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for(int i = 0; i < n-1; i++) {
			int u = sc.nextInt()-1;
			int v = sc.nextInt()-1;
			int w = sc.nextInt();
			
			list.get(u).add(new Edge(v, w));
			list.get(v).add(new Edge(u, w));
		}
		int[] col = new int[n];
		dfs(0, -1, 0, list, col);
		
		for(int i=0; i < n; i++) {
			System.out.println(col[i]);
		}
	}
	 static void dfs(int v, int parent, int color, ArrayList<ArrayList<Edge>> edge, int[] col) {
			col[v] = color;
			for(Edge e : edge.get(v)) {
				if (e.to == parent)
					continue;
				if (e.cost % 2 == 0) {
					dfs(e.to, v, color, edge, col);
				} else {
					dfs(e.to, v, 1 - color, edge, col);
				}
			}
	 }
}
class Edge implements Comparable<Edge> {
	int to;
	int cost;
 
	public Edge(int to, int cost) {
		this.to = to;
		this.cost = cost;
	}
 
	@Override
	public int compareTo(Edge e) {
		return this.cost - e.cost;
	}
}

Measured memory_bytes: 117044
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;

public class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int n = Integer.parseInt(scanner.nextLine());
		Deque<Integer> stack = new ArrayDeque<>();
		stack.offer(0);
		String[] str = scanner.nextLine().split(" ");
		int x = 0;

		for(int i = 0; i < n; i++){
			x = Integer.parseInt(str[i]);
			Deque<Integer> temp = new ArrayDeque<>(stack);
			int size = temp.size();
			for(int j = 0; j < size; j++){
				int a = x + temp.poll();
				stack.offer(a);
			}
// 			System.out.println(stack);
		}

		int q = Integer.parseInt(scanner.nextLine());
		String[] m_i = scanner.nextLine().split(" ");
		for(int i = 0; i < q; i++){
			if(stack.contains(Integer.parseInt(m_i[i]))){
				System.out.println("yes");
			}else{
				System.out.println("no");
			}
		}

	}
}

Measured memory_bytes: 82188
#!/usr/bin/env python3
s = str(input())

mod = 2019

div_memo = [0 for _ in range(mod)]

num = 0
d = 1
for n in reversed(s):
    num += int(n)*d
    num %= 2019
    div_memo[num] += 1
    d *= 10
    d %= 2019

ans = 0
for i in range(len(div_memo)):
    ans += div_memo[i]*(div_memo[i]-1)//2

ans += div_memo[0]
print(int(ans))


Measured memory_bytes: 9172
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}
int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double tmp = (a * a * b / 2);
  if (x <= tmp) {
    cout << setprecision(12)
         << atan((a * b * b) / (2 * x)) * 180 / 3.14159265358979323846 << endl;
  } else {
    double calc = atan((2 * (b - (x / (a * a)))) / a);
    cout << setprecision(12) << calc * 180 / 3.14159265358979323846 << endl;
  }

  return 0;
}


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


int main() {
  char a, b;
  cin >> a >> b;
  char ans = 'H';
  if(a == 'H') ans = b;
  else if(b == 'H') ans = 'D';
  
  cout << ans << endl;
  return 0;
  
}

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

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

    string S;
    cin >> S;

    int ans = 0;

    for(int i = 0; i < 3; i++) {
        if(S[i] == '1') ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
public class Main {

  private static void solve() {
    String s = next();
    String t = next();
    int a = ni();
    int b = ni();
    String u = next();

    if (u.equals(s)) {
      a--;
    } else {
      b--;
    }
    System.out.println(a + " " + b);


  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



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

int main() {
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible";
	else cout << "Impossible";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

それぞれ3で割ってみて、どれか一つでも余りが0ならばおｋ
......ところで、なんで缶の中身丸ごと与えているんですかね、一部持っておけばいいのに
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"

#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}

#define SHOW(x) std::cout << #x << " = " << x << std::endl;

inline int safe_mul(int x, int y) __attribute__ ((warn_unused_result));

int main()
{
//    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);

    int n = 0;
    cin >> n;
    int sum = 0;
    int mn = 1000000000;
    while (n--)
    {
        int cur;
        cin >> cur;
        sum += cur;
        if (cur % 10)
            mn = min(cur, mn);
    }
    if (sum % 10 == 0)
        sum -= mn;
    cout << max(sum, 0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[5],i;
  for(i=0;i<5;i++){
    cin>>a[i];}
  for(i=0;i<5;i++){
    if(a[i]==0)cout<<i+1;
  }
  return 0;
}

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

#define ll long long
#define ppi pair<int, int>
#define pb push_back
#define vi vector<int>
#define fi first
#define se second
#define forn(n) for(ll i = 0; i < n; i++)
#define forx(x,n) for(ll i = x; i < n; i++)

using namespace std;
vi G[100001];
int N,M;
bool vis[100001];
int P[100001], out;

int dfs(int v, int d)
{
	vis[v] = true;
	for(auto x : G[v])
	   {
	   	  if(!vis[x])
	   	  	P[v] = max(P[v], dfs(x,v));
		  else P[v] = max(P[v], P[x]+1);
	   }
	return P[v]+1;
	
}
int main()
{
	ios_base::sync_with_stdio(false);
	P[0] = -1;
 	cin >> N >> M;
	forn(M)
	{
		int a, b;
		cin >> a >> b;
		G[a].pb(b);
	}
 //	forx(1,N+1) if(!B[i].size()) s.pb(i);
 	forx(1,N+1) dfs(i, 0);
 	forx(1,N+1) out = max(P[i], out);
 	cout << out;
 	
}

Measured memory_bytes: 8320
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int a, n;
vector<int> x;
ll dp[55][55][3000];
// i番までの数字でj個選択し、合計sum
ll calc(int i, int j, int sum) {
    if(dp[i][j][sum] >= 0)
        return dp[i][j][sum];
    if(i >= n && double(sum)/j == a)
       return 1;
    else if(i >= n && double(sum)/j != a)
        return 0;
    ll ret1 = calc(i+1, j+1, sum+x[i]) + calc(i+1, j, sum);
    return dp[i][j][sum] = ret1;
}
int main(){
    memset(dp, -1, sizeof(dp));
    cin >> n >> a;
    for(int i=0;i<n;i++) {
        int xi;
        cin >> xi;
        x.push_back(xi);
    }
    ll ans = calc(0, 0, 0);
    cout << ans << endl;
}


Measured memory_bytes: 71296
S = input()
ACGT = ['A','C','G','T']
NS = []
for i in S:
    if i in ACGT:
        NS.append('A')
    else:
        NS.append(' ')
L = ''.join(NS).split()
max_l = 0
for l in L:
    max_l = max(max_l, len(l))
print(max_l)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define M 1000000007

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

   vector<ll> sa(n);
   sa[n-1]=a[n-1];
   for(int i=n-2; i>=0; i--) sa[i]=(sa[i+1]+a[i])%M;

   ll cnt=0;
   rep(i, n-1){
      cnt=(cnt+a[i]*sa[i+1])%M;
   }

   cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 5636
var input = "";
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (chunk) => {
  input += chunk;
});
process.stdin.on("end", () => {
  input = input.split("\n");
  main();
});

function main(){
    const nums = input[0].split(" ");
    const N = Number(nums[0]);
    const K = Number(nums[1]); 
    console.log(Math.ceil( (N-K) / (K-1) ) + 1);
}

Measured memory_bytes: 8268
#include<iostream>
using namespace std;
int main()
{
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int sum1=h1*60+m1;
	int sum2=h2*60+m2;
	int sum=sum2-sum1-k;
	if(sum<=0){
		cout<<"0"<<endl;
	}
	else {
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 3620
function main(input){
    let lines =input.split("\n");
    let count = parseInt(lines.shift());
    let score = new Array(2).fill(0);
    for(let i=0;i<count;i++){
        let words = lines[i].split(" ");
        let sorted = new Array(...(Object.create(words).sort()));
        if(words[0]===words[1]){
            score[0]++;
            score[1]++;

        }else if(words.join("") === sorted.join("")){
            score[1]+=3;
        }else{
            score[0]+=3;
        }
    }
    console.log(score.join(" "));
}

main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 18320
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main()
{
	const int MAX_N = 200000;
	int n;
	cin >> n;
	int a[MAX_N];

	// 最大の数と二番目の数を調べる
	int maxInA = 0;
	int secondInA = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];

		// 最大の更新
		if (a[i] >= maxInA)
		{
			secondInA = maxInA;
			maxInA = a[i];
		}
		// 二番目の更新
		else if (a[i] >= secondInA)
		{
			secondInA = a[i];
		}
	}

	for (int i = 0; i < n; i++)
	{
		// 最大値のときは二番目を出力
		if (a[i] == maxInA)
			cout << secondInA << endl;
		else
			cout << maxInA << endl;
	
	}


	return 0;
}



Measured memory_bytes: 2432
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
#include <cmath>
#include <math.h>
#include <array>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
#define DEBUG_VIS(x) cerr<<"vis "<<x<<endl;
#define DEBUG_REACH cerr<<"reach here"<<endl;
#define DEBUG_SEQ(x) cerr<<x<<" ";
#define SET_ZERO(x) memset(x,0,sizeof(x));
#define SET_NEGONE(x) memset(x,-1,sizeof(x));
#define SET_INF(x) memset(x,127,sizeof(x));
#define SET_NEGINF(x) memset(x,128,sizeof(x));
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
typedef unsigned int uint;
const int maxn = 4e3 + 10;
template <class T> T mymin(const T a,const T b){return a < b ? a : b;}
template <class T> T mymax(const T a,const T b){return a > b ? a : b;}
int N,dp[maxn][maxn],costb[maxn][maxn],costw[maxn][maxn];
int ball[maxn][2],pos[maxn][maxn];

int main(){
    FAST_IO
    cin>>N;
    N *= 2;
    for(int i = 1; i <= N; i++){
        char c;
        int id;
        cin>>c>>id;
        ball[i][0] = (c == 'B');
        ball[i][1] = id;
        pos[ball[i][0]][ball[i][1]] = i;
    }
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= N / 2; j++){
            costb[i][j] = costb[i - 1][j];
            costw[i][j] = costw[i - 1][j];
            if(ball[i - 1][1] > j) ball[i - 1][0] == 0 ? costw[i][j]++ : costb[i][j]++;
        }
    }
    SET_INF(dp);
    dp[0][0] = 0;
    for(int i = 0; i <= N / 2; i++){
        for(int j = 0; j <= N / 2; j++){
            int u = pos[0][i + 1],v = pos[1][j + 1];
            dp[i + 1][j] = min(dp[i + 1][j],dp[i][j] + costw[u][i + 1] + costb[u][j]);
            dp[i][j + 1] = min(dp[i][j + 1],dp[i][j] + costw[v][i] + costb[v][j + 1]);
        }
    }
    cout<<dp[N / 2][N / 2]<<endl;
    return 0;
}


Measured memory_bytes: 190080
import java.util.*;
//import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A[][][];
        A=new int[4][3][10];
        for(int i=0;i<N;i++){
            int a[];
            a=new int[4];
            for(int j=0;j<4;j++) a[j]=sc.nextInt();
            A[a[0]-1][a[1]-1][a[2]-1]+=a[3];
        }
        for(int i=0;i<4;i++){
            for(int j=0;j<3;j++){
                System.out.print(" ");
                for(int k=0;k<10;k++){
                    System.out.print(A[i][j][k]);
                    if(k!=9) System.out.print(" ");
                    else System.out.println();
                }
            }
            if(i!=3) System.out.println("####################");
        }
    }
}


Measured memory_bytes: 29672
from fractions import gcd

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

gcdl = [0] * n
gcdr = gcdl[:]

gcdl[0]  = a[0]
gcdr[-1] = a[-1] 

for i in range(1, n):
  gcdl[i] = gcd(a[i], gcdl[i - 1])

for i in range(n - 2, -1, -1):
  gcdr[i] = gcd(a[i], gcdr[i + 1])

max_gcd = max(gcdl[-2], gcdr[1])

for i in range(1, n - 1):
  temp_gcd = gcd(gcdl[i - 1], gcdr[i + 1])
  if temp_gcd > max_gcd:
    max_gcd = temp_gcd

print(max_gcd)

Measured memory_bytes: 16156
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
int A,B,C,D;
cin >> A >> B >> C >> D;
do {
C = C - B;
if(C <= 0){
break;
}
A = A - D;
}
while (A > 0 && C > 0);
if(C <= 0){
cout << "Yes";
}
if(A <= 0){
cout << "No";
}
return 0;
}

Measured memory_bytes: 3652
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return (a * b) // gcd(a, b)

def anti_division(n, c, d):
    return n - (n // c) - (n // d) + (n // lcm(c, d))

a, b, c, d = map(int, input().split())
print(anti_division(b, c, d) - anti_division(a - 1, c, d))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
vector <int> g[N];
ll vis[N],r[N];
ll p1=0;
void dfs(ll v,ll k){
    vis[v]=1;
    r[v]=k;
    for (auto u : g[v]){
        if (!vis[u]){
            dfs(u,3-k);
        }
        else{
            if (r[u]==r[v]) p1=1;
        }
    }
    return;
}
int32_t main(){
    ll n,m;
    cin >> n >> m;
    for (int i=1;i<=m;i++){
        ll u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    ll cnt=0;
    for (int i=1;i<=n;i++){
        if (g[i].size()==0){
            cnt++;
        }
    }
    ll ans=cnt*(n-cnt)*2+cnt*cnt;
    ll t0=0,t1=0;
    for (int i=1;i<=n;i++){
            p1=0;
        if (g[i].size()==0 || vis[i]) continue;
        dfs(i,1);
     //   cout << i << " " << p1 << endl;
        if (p1) t1++;
        else t0++;
    }
   // cout << ans << " " << t0 << " " << t1 << endl;
    ans+=2*t0+t1+t0*(t0-1)*2+(t1-1)*t1;
    ans+=t0*t1*2;
    cout << ans << endl;

}


Measured memory_bytes: 20696
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int s,w;
    cin>>s>>w;

    if ( s > w )
    {
        cout<<"safe"<<endl;
    }
    else
    {
        cout<<"unsafe"<<endl;
    }
    
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 3616
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
        
    int a,b;
    void solve()
    {
        cin>>a>>b;
        cout<<a*b<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
      {
        
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        
        // cin>>t;while(t--)
        solve();
        
      return 0;
      }

Measured memory_bytes: 3688
s = input()
n = len(s)
ans = [s[0]]
idx = 1
while idx < n:
    if s[idx] != ans[-1]:
        ans.append(s[idx])
        idx += 1
    else:
        if idx < n-1:
            ans.append(s[idx] + s[idx+1])
            idx += 2
        else:
            break

#print(ans)
print(len(ans))

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

int main() {
  int a,b;
  cin >> a >> b;
  if (a*b % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
  
  // ここにプログラムを追記
}

Measured memory_bytes: 256