akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a,b;

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

    if((a+b)%3==0)
        printf("Possible\n");
    else if (a%3==0)
        printf("Possible\n");
    else if (b%3==0)
        printf("Possible\n");
    else
        printf("Impossible\n");


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	double a=sc.nextDouble();
	double b=sc.nextDouble();
	double c=sc.nextDouble();
	double d=sc.nextDouble();
	System.out.println(Math.sqrt(Math.pow(a-c,2)+Math.pow(b-d,2)));
	}
}



Measured memory_bytes: 27876
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)

#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long ll;
const int N = 2e5+1 , M = 5e5+1, OO = 0x3f3f3f3f,MOD = 1e9+7;
char str[N];
ll freq[N];
int main()
{
  int n;
  ll p,ans=0;
  scanf("%d%lld",&n,&p);
  scanf("%s",str);
  
  if(p==2 || p==5)
    for(int i=n-1;~i;--i)
    {
      int d = str[i]-'0';
      if((d%p) ==0) ans+=(i+1);
    }

  else
  {
    ll num=0,base=1;
    freq[num]++;
    for(int i=n-1;~i;--i)
    {
      int d = str[i]-'0';
      num=(num%p+(d%p*base%p)%p)%p;
      base=(base%p*10%p);
      freq[num]++;
    }
    for(int i=0;i<p;++i) ans+=(freq[i])*(freq[i]-1)/2;
  }
  printf("%lld\n",ans);
  
  
  
  #ifdef _LOCAL_DEFINE  
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

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

using namespace std;

const int N = 15;

void cmax(int& x, int y) {
  if (x < y) {
    x = y;
  }
}

int n, m, dist[N][N], value[1 << N], dp[1 << N][N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  int sum = 0;
  for (int i = 0, a, b, c; i < m; ++i) {
    cin >> a >> b >> c;
    --a;
    --b;
    dist[a][b] = dist[b][a] = c;
    sum += c;
  }
  int all = 1 << n;
  for (int i = 1; i < all; ++i) {
    int p = 0;
    while (!(i >> p & 1)) {
      ++p;
    }
    value[i] = value[i ^ (1 << p)];
    for (int j = 0; j < n; ++j) {
      if (j != p && (i >> j & 1)) {
        value[i] += dist[p][j];
      }
    }
  }
  memset(dp, 0xc0, sizeof dp);
  for (int i = 1; i < all; ++i) {
    if ((i & 1) && !(i >> n - 1 & 1)) {
      dp[i][0] = value[i];
    }
  }
  for (int i = 1; i < all; ++i) {
    for (int j = 1; j < n; ++j) {
      if (i >> j & 1) {
        for (int k = (i - 1) & i; k; k = (k - 1) & i) {
          if ((k & 1) && !(k >> j & 1)) {
            for (int l = 0; l < n; ++l) {
              if ((k >> l & 1) && dist[j][l]) {
                cmax(dp[i][j], dp[k][l] + value[i ^ k] + dist[j][l]);
              }
            }
          }
        }
      }
    }
  }
  int answer = 0;
  for (int i = 1; i < all; ++i) {
    cmax(answer, dp[i][n - 1]);
  }
  cout << sum - answer << '\n';
  return 0;
}

Measured memory_bytes: 2304
while True:
  a,op,b = input().split()
  if op == "?":
    break
  elif op == "+":
    print (int(a) + int(b))
  elif op == "-":
    print (int(a) - int(b))
  elif op == "*":
    print (int(a) * int(b))
  else:
    print (int(int(a) / int(b)))


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

int main(){
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  
  if(a >= k) cout << k << endl;
  else if(a + b >= k){ cout << a << endl;}
  else  {long long tmp = a - (k - (a + b) );
    cout <<  tmp << endl;
}}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    int X, N;
    cin >> X >> N;
    if (N == 0) {
        cout << X << endl;
        return 0;
    }
    vector<pair<int, int>> ans;
    vector<bool> num(100, false); 
    rep(i, N) {
        int p;
        cin >> p;
        num[p-1] = true;
    }
    rep2(i, -100, 101) {
        if(i < 0) {
            ans.push_back(make_pair(abs(i+1-X), i+1));
            continue; 
        }
        if(!num[i]) {
            ans.push_back(make_pair(abs(i+1-X), i+1));
        }
    }
    sort(ans.begin(), ans.end());
    cout << ans[0].second << endl;
}

Measured memory_bytes: 3604
package main

import (
  "fmt"
  "math"
)

func main() {
  var i1, i2 int
  fmt.Scan(&i1, &i2)
  
  add_num := i1 + i2
  sub_num := i1 - i2
  times_num := i1 * i2
  
  max_num := max([]int{add_num, sub_num, times_num})

  fmt.Println(max_num)
}

func max(nums []int) int {
    if len(nums) == 0 {
        panic("funciton max() requires at least one argument.")
    }
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Max(float64(res), float64(nums[i])))
    }
    return res
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;

signed main() {
  int N;
  cin >> N;
  
  vector<int> T(N);
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> T.at(i) >> A.at(i);
  
  int nowT = T.at(0);
  int nowA = A.at(0);
  
  for( int i = 1; i < N; i++ ){
    int nT = nowT/T.at(i);
    int nA = nowA/A.at(i);
    if( nowT%T.at(i) != 0 ) nT++;
    if( nowA%A.at(i) != 0 ) nA++;
    int n = max(nT, nA);
    nowT = n*T.at(i);
    nowA = n*A.at(i);
  }
  
  cout << nowT+nowA << endl;

    
  
  
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{

		public static void main(String[] args) {

					Scanner sc = new Scanner(System.in);
					int n = sc.nextInt();
					List<List<Integer>> A = new ArrayList<>();
					for (int i = 0; i <= n; i++) {
						List<Integer> a = new ArrayList<>();
						A.add(a);
					}
					int z = sc.nextInt();
					for (int i = 0; i < z; i++) {
						int q = sc.nextInt();
						if (q == 0) {
							int x = sc.nextInt();
							int t = sc.nextInt();
							List<Integer> a = A.get(x);
							a.add(t);
						}
						if (q == 1) {
							int x = sc.nextInt();
							if (A.get(x).size()!= 0) {
								System.out.println(A.get(x).get(0));
							}
						}
						if (q == 2) {
							int x = sc.nextInt();
							if (A.get(x).size()!= 0) {
							A.get(x).remove(0);
							}
						}
					}
					sc.close();
				}
	}


Measured memory_bytes: 168416
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    int n, k; cin >> n >> k;
    int x[n]; rep(i,n) cin >> x[i];

    int ans = 0;
    rep(i,n) ans += 2 * min(abs(x[i]), abs(x[i] - k));
    out(ans);
    
    return 0;
}






Measured memory_bytes: 256
S = list(input())
K = set()
G = set()
a = 0
flag = 0
for i in S:
  f = a % 2
  if f == 1:
    K.add(S[a])
  else:
    G.add(S[a])
  a += 1 
  
for k in K:
  if k == "R":
    flag = 1
    
for g in G:
  if g == "L":
    flag = 1
    
if flag == 1:
  print("No")
else:
  print("Yes")

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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

int a, b, n, ans;

int dig(int x)
{
	int ret = 0;
	while(x){ret += x%10;x/=10;}
	return ret;
}

int main()
{
	#ifdef MPS
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
	#endif
	sf("%d",&n);
	ans = inf;
	fo(a,1,n-1) 
	{
		b = n - a;
		ans = min(ans, dig(a) + dig(b));
	}
	pf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <map>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    map<char,long long> mp;
    for(int i = 0; i < N; i++){
        if(S[i][0] == 'M') mp['M']++;
        if(S[i][0] == 'A') mp['A']++;
        if(S[i][0] == 'R') mp['R']++;
        if(S[i][0] == 'C') mp['C']++;
        if(S[i][0] == 'H') mp['H']++;
    }
    long long ans = mp['R']*mp['C']*mp['H'];
    ans += mp['M']*mp['A']*mp['R'] + mp['M']*mp['A']*mp['C'] + mp['M']*mp['A']*mp['H'];
    ans += mp['M']*mp['R']*mp['C'] + mp['M']*mp['R']*mp['H'] + mp['M']*mp['C']*mp['H'];
    ans += mp['A']*mp['R']*mp['C'] + mp['A']*mp['R']*mp['H'] + mp['A']*mp['C']*mp['H'];
    cout << ans << endl;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+5,mod=1e9+7;
ll f[N],invf[N];
ll C(int n,int m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
ll c1,c2,r1,r2;
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
ll g(ll x,ll y)
{
    ll ans=0;
    for(int i=1;i<=x;i++)
        ans=(ans+C(i+y+1,i+1))%mod;
    return ans;
}
int main()
{
    f[0]=f[1]=invf[0]=invf[1]=1;
    for(int i=2;i<N;i++) f[i]=f[i-1]*i%mod,invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    for(int i=2;i<N;i++) invf[i]=invf[i-1]*invf[i]%mod;
    scanf("%lld%lld%lld%lld",&r1,&c1,&r2,&c2);
    ll ans=g(r2,c2)-g(r1-1,c2)-g(r2,c1-1)+g(r1-1,c1-1);
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


Measured memory_bytes: 31488
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  tmp = input[1].split(" ");
  h = new Array(N);
  for(var i=0;i<N;i++){
    h[i]=parseInt(tmp[i]);
  }
  var mins=new Array(N).fill(Math.pow(10,9)+1);
  mins[0]=0;
  mins[1]=Math.abs(h[1]-h[0]);
  for(var i=2;i<N;i++){
    for(var j=Math.max(0,i-K);j<i;j++){
      mins[i]=Math.min(mins[j]+Math.abs(h[i]-h[j]),mins[i]);
    }

  }
  var ans = mins[N-1];
  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 27824
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
using ll=long long;

#define loop(var,start,stop,step) for(long long var=start;var<stop;var+=step)

using vi=vector<int>;
using vl=vector<long long>;

#define fio  cin.tie(nullptr); ios::sync_with_stdio(false); cout.tie(nullptr);
#define nl cout<<endl;

int main()
    {
        fio;
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<max({a*c,b*d,a*d,b*c})<<endl;
        return 0;
    }


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int N;

void search(string s, int count) {
	int L = s.size();

	if (L==N) {
		ce(s);
		return;
	}

	fx(count) {
		char c = ('a' + x);
		search(s+c,x==count-1?count+1:count);
	}


}

int main()
{
	cin >> N;

	search("",1);

    return 0;
}



Measured memory_bytes: 1536
r,c=map(int,input().split())
cc=[]
for l in range(c+1):
    cc.append(0)
    
for i in range(r):
    rr=list(map(int,input().split()))

    x=0
    for j in rr:
        x+=j
    rr.append(x)
    print(*rr)
    
    for k in range(c+1):
#        print(rr[k])
        cc[k]+=rr[k]
    
print(*cc)


        
    
    
        


Measured memory_bytes: 5628
n = input()
E0 = {}
V = set()
for i in xrange(n):
    ipt = map(int, raw_input().split())
    r = ipt[0]; k = ipt[1]; T = ipt[2:]
    E0[r] = T
    V.add(r)
E = {v: {} for v in V}
for v in V:
    for t in E0[v]:
        E[v][t] = 1
MAX = 10**18
for k in V:
    for i in V:
        for j in V:
            if k in E[i] and j in E[k]:
                E[i][j] = min(E[i].get(j, MAX), E[i][k] + E[k][j])
p = input()
for i in xrange(p):
    s, d, v = map(int, raw_input().split())
    print "NA"*(v <= E[s].get(d, MAX))or E[s][d]+1

Measured memory_bytes: 7444
N, M = map(int, input().split())

city_list = [0 for i in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    city_list[a-1] += 1
    city_list[b-1] += 1

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


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  float a[n];
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  float sum = 0;
  sort(a, a+n);
  sum = a[0] + a[1];
  sum/=2;
  for(int i = 2; i<n ; i++){
    sum += a[i];
    sum /= 2;
  }
  cout<<sum;
}

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

int main() {
    int N, K;
    string S;
    cin >> N >> S >> K;

    for(int i=0; i<S.size(); ++i) {
        if(S[i] == S[K - 1]) cout << S[i];
        else cout << '*';
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val c = sc.next()
    println(problem174d(n, c))
}

fun problem174d(n: Int, c: String): Int {
    var c = c.toCharArray()
    var w = 0
    var r = 0
    for (i in 0 until n) {
        if (c[i] == 'W') w++ else r++
    }
    var count = 0
    for (i in r until n) {
        if (c[i] == 'R') count++
    }
    return count
}

Measured memory_bytes: 41480
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;
int main()
{
	int a, b, c;
	int cnt = 0;
	cin >> a >> b >> c;
	for (int i = a; i<= b; i++){
		if (c % i == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;
}



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

#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;
using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

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

int main() {
    ll N;
    cin >> N;
    map<pair<ll, ll>, pair<ll, ll>> ms;
    ll zz = 0;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;

        if (a == 0 && b == 0) {
            ++zz;
            continue;
        } else if (a == 0 || b == 0) {
            if (a == 0) {
                b = 1;
                if (ms.find(make_pair(0, 1)) == ms.end()) {
                    ms.emplace(make_pair(0, 1), make_pair(1, 0));
                } else {
                    ++ms[make_pair(0, 1)].first;
                }
            } else {
                a = 1;
                if (ms.find(make_pair(0, 1)) == ms.end()) {
                    ms.emplace(make_pair(0, 1), make_pair(0, 1));
                } else {
                    ++ms[make_pair(0, 1)].second;
                }
            }
        } else if ((a < 0 && b > 0) || (a > 0 && b < 0)) {
            swap(a, b);
            a = abs(a);
            b = abs(b);
            ll div = gcd_ll(min(a, b), max(a, b));
            a /= div;
            b /= div;

            if (ms.find(make_pair(a, b)) == ms.end()) {
                ms.emplace(make_pair(a, b), make_pair(0, 1));
            } else {
                ++ms[make_pair(a, b)].second;
            }
        } else {
            a = abs(a);
            b = abs(b);
            ll div = gcd_ll(min(a, b), max(a, b));
            a /= div;
            b /= div;

            if (ms.find(make_pair(a, b)) == ms.end()) {
                ms.emplace(make_pair(a, b), make_pair(1, 0));
            } else {
                ++ms[make_pair(a, b)].first;
            }
        }
    }

    cpp_int ans = 1;
    for (auto &x : ms) {
        ll num1 = x.second.first;
        ll num2 = x.second.second;
        cpp_int tmp1 = 1;
        rep(i, num1) { tmp1 *= 2; }
        cpp_int tmp2 = 1;
        rep(i, num2) { tmp2 *= 2; }
        ans *= (tmp1 + tmp2 - 1) % mod;
        ans %= mod;
    }

    ans += zz;
    ans = (ans + mod - 1) % mod;

    cout << ans << endl;
}

Measured memory_bytes: 19260
main=do
 [n,k]<-map read.words<$>getLine
 let m=n*(n-1)`div`2-k
 if m<n-1then print(-1)else print m>>(mapM_ putStrLn$take m[show i++" "++show j|i<-[1..n],j<-[2..n],i<j])

Measured memory_bytes: 1020
N = int(input())
takoyaki = list(map(int, input().split(" ")))

cure = 0
for i in range(N):
  #print(i)
  for k in range(i, N-1):
    #print(i, k)
    cure = cure + takoyaki[i] * takoyaki[k+1]

print(cure)



Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> dp;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

int main()
{
    IOS;
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll a[n][3];
    memset(a,0,sizeof a);
    repf(i,0,n)
    {
        repf(j,i+1,n)
        {
            if(s[i]==s[j]) continue;
            ll c1;
            if(s[j]=='R') c1=0;
            else if(s[j]=='G') c1=1;
            else c1=2;
            a[i][c1]++;
        }
    }
    ll ans=0;
    repf(i,0,n)
    {
        ll c1;
        if(s[i]=='R') c1=0;
        else if(s[i]=='G') c1=1;
        else c1=2;
        repf(j,i+1,n)
        {
            if(s[i]==s[j]) continue;
            ll c2;
            if(s[j]=='R') c2=0;
            else if(s[j]=='G') c2=1;
            else c2=2;
            repf(k,0,3) 
            {
                if(k!=c1 && k!=c2) ans+=a[j][k];
            }
            ll l=j-i;
            if(j+l<n && s[i]!=s[j+l] && s[j]!=s[j+l]) ans--;
        }
    }
    cout<<ans<<endl;
}     


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int cost[10000][10000];
int dp[10000];

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

    int W, H, K, N;
    cin >> W >> H >> K >> N;
    rep(i, H) rep(j, W) cost[i][j] = 1;
    rep(i, N) {
        int c, r;
        cin >> c >> r;
        c--; r--;
        cost[r][c] = 2;
    }

    if (K < (W + 1) / 2) {
        cout << -1 << endl;
        return 0;
    }

    if (H == 1) {
        cout << 0 << endl;
        return 0;
    }

    int n1 = 0, n2 = 0;
    for (int i = 2; i < H; i += 2) {
        dp[0] = cost[i - 1][0];
        if (W >= 3) dp[2] = min(dp[0] + cost[i - 1][2], 2 * cost[i - 1][1]);
        for (int j = 4; j < W; j += 2) {
            dp[j] = min(dp[j - 2] + cost[i - 1][j], dp[j - 4] + 2 * cost[i - 1][j - 1]);
        }
        int t2 = dp[W - 1] - (W + 1) / 2;
        int t1 = (W + 1) / 2 - t2;
        n1 += t1;
        n2 += t2;
    }

    int r = K - (W + 1) / 2;
    int t = min(r, n2);
    n2 -= t;
    r -= t;
    int u = min(r, n1);
    n1 -= u;
    r -= u;

    cout << 1 * n1 + 2 * n2 << endl;

}

Measured memory_bytes: 393764
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

#define PI 3.14159265358
typedef long long ll; 
typedef long double ld; 

int main() {
	int a, b, c, k, ans = 0, t;
	cin >> a >> b >> c >> k;
	if(a < k) {
		t = k - a;
		ans = k - t;
		k = t;
		if(b < k) {
			t = k - b;
			k = t;
			k *= -1;
			ans += k;
		}
	} else {
		t = a - k;
		ans = a - t;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3620
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

#ifdef DEBUG
#include <fmt/format.h>
#endif
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using s64 = int64_t;
using u64 = uint64_t;
// }}}

int N;
vector<int> A;

int cut(int start)
{
    int idx = start + 1;
    for(; idx < N && A[idx] == A[start]; ++idx)
        ;
    if(idx == N) return idx;

    if(A[idx] > A[start]) {
        for(; idx < N && A[idx] >= A[idx-1]; ++idx)
            ;
        return idx;
    }
    else {
        for(; idx < N && A[idx] <= A[idx-1]; ++idx)
            ;
        return idx;
    }
}

void solve()
{
    int cnt = 0;

    int idx = 0;
    for(;;) {
        ++cnt;
        idx = cut(idx);
        if(idx >= N) break;
    }

    cout << cnt << "\n";
}

int main()
{
    cin >> N;
    A.resize(N);

    REP(i, N) {
        cin >> A[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <limits>

int main() {
  double x1, y1, x2, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;

  int q;
  std::cin >> q;

  std::cout << std::fixed;
  std::cout << std::setprecision(std::numeric_limits<double>::max_digits10);
  for (int i = 0; i < q; ++i) {
      double x, y;
      std::cin >> x >> y;

      double num = -(x2 - x1) * (x1 - x) - (y2 - y1) * (y1 - y);
      double den = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
      double t = num / den;
      
      double u = x1 + t * (x2 - x1);
      double v = y1 + t * (y2 - y1);
      std::cout << u << " " << v << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll Q=1000000007;
const double PI=3.14159265358979323846;

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans=0;
  for(int i=0;i<=999;i++){
    int M=i;
    vector<char> X(3,' ');
    X[0] = (M%10) + '0';
    M /= 10;
    X[1] = (M%10) + '0';
    M /= 10;
    X[2] = (M%10) + '0';
    int cur=0;
    for(int j=0;j<N;j++){
      if(X[cur] == S[j]){
        cur ++;
      }
      if(cur == 3){
        ans ++;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from inspect import currentframe
from sys import exit, stderr

tokens = []
cur = 0
def debug(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???') + str(id(arg)) +' = '+repr(arg) for arg in args), file=stderr)
def parse_expr():
    global cur
    if tokens[cur] == "=":
        return
    lhs = parse_mul()
    while(tokens[cur] == "+" or tokens[cur] == "-"):
        if tokens[cur] == "+":
            cur += 1
            lhs += parse_mul()
        elif tokens[cur] == "-":
            cur += 1
            lhs -= parse_mul()
        # debug(lhs, cur)
    return lhs

def parse_mul():
    global cur
    lhs = parse_term()
    while(tokens[cur] == "*" or tokens[cur] == "/"):
        if tokens[cur] == "*":
            cur += 1
            lhs *= parse_term()
        elif tokens[cur] == "/":
            cur += 1
            divisor = parse_term()
            if lhs < 0 and lhs % divisor != 0:
                lhs //= divisor
                lhs += 1
            else:
                lhs //= divisor
    return lhs

def parse_term():
    global cur
    if tokens[cur].isdigit():
        lhs = int(tokens[cur])
        cur += 1
        while(tokens[cur].isdigit()):
            lhs *= 10
            lhs += int(tokens[cur])
            cur += 1
    elif tokens[cur] == "(":
        cur += 1
        lhs = parse_expr()
        if tokens[cur] != ")":
            raise Exception("not closed")
        cur += 1
    return lhs

N = int(input())
for _ in range(N):
    src = list(str(input()))
    tokens = [tok for tok in src if tok != " "]
    cur = 0

    print(parse_expr())



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

int main() {
	int i,j,k,m,n,tab[200010];
	cin>>n;
	for (i=1;i<=n;i++)
	 cin>>tab[i];
	if (n==1)
	{
		cout<<tab[1]<<"\n";
		return 0;
	}
	//case ganjil
	if (n%2==1)
	{
		k=n;
		while (k>=1)
		{
			cout<<tab[k]<<" ";
			k-=2;
		}
		k=2;
		while (k<n)
		{
			if (k==n-1)
			 cout<<tab[k]<<"\n";
			else
			 cout<<tab[k]<<" ";
			k+=2;
		}
		return 0;
	}
	k=n;
	while (k>1)
	{
		cout<<tab[k]<<" ";
		k-=2;
	}
	k=1;
	while (k<n)
	{
		if (k==n-1)
		 cout<<tab[k]<<"\n";
		else
		 cout<<tab[k]<<" ";
		k+=2;
	}
	return 0;
}

Measured memory_bytes: 2944
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N, K = map(int, input().split())
Hs = list(map(int, input().split()))
Hs.sort(reverse=True)
Hs = Hs[K:]
print(sum(Hs))




Measured memory_bytes: 28988
using System;

namespace _157b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] Array_A = new int[3,3];
            int[] Array_A1 = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int[] Array_A2 = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int[] Array_A3 = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            Array_A[0,0] = Array_A1[0];
            Array_A[0,1] = Array_A1[1];
            Array_A[0,2] = Array_A1[2];
            Array_A[1,0] = Array_A2[0];
            Array_A[1,1] = Array_A2[1];
            Array_A[1,2] = Array_A2[2];
            Array_A[2,0] = Array_A3[0];
            Array_A[2,1] = Array_A3[1];
            Array_A[2,2] = Array_A3[2];
            int N = int.Parse(Console.ReadLine());
            int[] b = new int[N];
            bool result = false;
            for(int i = 0; i < N ; i++){
                b[i] = int.Parse(Console.ReadLine());
            }
            //穴を開ける
            for(int i =0; i<3;i++){
                for(int j=0;j<3;j++){
                    for(int k = 0; k<N;k++){
                        if(Array_A[i,j]==b[k]){
                            Array_A[i,j] = 0;
                        }
                    }
                }
            }

            for(int i = 0;i<3;i++){
                //行チェック
                if(Array_A[i,0] + Array_A[i,1]+Array_A[i,2] == 0){
                    result = true;
                    break;
                    //列チェック
                }else if(Array_A[0,i] + Array_A[1,i]+Array_A[2,i] == 0){
                    result = true;
                    break;
                }else{

                }
            }
            if(Array_A[0,0] + Array_A[1,1] + Array_A[2,2] == 0){
                result = true;
            }else if(Array_A[2,0] + Array_A[1,1] + Array_A[0,2] == 0){
                result = true;
            }else{

            }
            Console.WriteLine(result?"Yes":"No");
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
	
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
	
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
	
class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
	
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}
	
bool solve() {
	int r; cin >> r;
	cout << 3 * r * r  << endl;
}
	
signed main() {
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 764
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int64 _abs(int64 x) {
    if (x < 0) return -x;
	return x;
}

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<int64> a(n);
	for (int i = 0; i < n; ++i) {
	    cin >> a[i];
	}
	int64 sum = 0;
	for (int i = 0; i < n; ++i) {
	    sum += a[i];
	}
	int64 ans = _abs(sum - 2 * a[0]);
	int64 cur = 0;
	for (int i = 0; i + 1 < n; ++i) {
	    sum -= a[i];
		cur += a[i];
		ans = min(ans, _abs(sum - cur));
	}
	
	cout << ans << endl;
	

    return 0;
}


Measured memory_bytes: 1792
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;  typedef long long ll;   char __buf[1<<18],*__c=__buf,*__ed=__buf;
inline int qr(){
	int ret=0,f=0,c=getchar();
	while(!isdigit(c)) f|=c==45,c=getchar();
	while( isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}
const int maxn=1e5+5;
int data[maxn],n;
ll dp[maxn][3];

int main(){
	memset(dp,0xcc,sizeof dp);
	n=qr();
	for(int t=1;t<=n;++t) data[t]=qr();
	dp[0][0]=0;
	for(int t=1;t<=n;++t){
		if(data[t]>0){
			dp[t][0]=max({dp[t][0],dp[t-1][0]+data[t],dp[t-1][1]+data[t],dp[t-1][2]+data[t]});
			dp[t][1]=max({dp[t][1],dp[t-1][1]-data[t],dp[t-1][2]-data[t]});
			dp[t][2]=max({dp[t][2],dp[t-1][2]+data[t]});
		}else{
			data[t]=-data[t];
			dp[t][0]=max({dp[t][0],dp[t-1][0]-data[t],dp[t-1][1]-data[t],dp[t-1][2]-data[t]});
			dp[t][1]=max({dp[t][1],dp[t-1][0]-data[t],dp[t-1][1]+data[t],dp[t-1][2]+data[t]});
			dp[t][2]=max({dp[t][2],dp[t-1][1]+data[t],dp[t-1][2]+data[t]});
		}
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
	return 0;
	
}



Measured memory_bytes: 2944
n,m,l = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(m)]
c = [[0 for _ in range(l)] for __ in range(n)]
for i in range(n):
  for j in range(l):
    c[i][j] = sum([a[i][k]*b[k][j] for k in range(m)])
for ci in c:
  print(*ci)


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

int N,K;
 
bool check(int x,vector<int> d){
  int tmp;
  while (x > 0) {
    tmp = x % 10;
    for (int i = 0; i < K; i++) {
      if (tmp == d.at(i)) return false;
    }
    x /= 10;
  }
  return true;
}
 
int main() {
 
  cin >> N >> K;
  vector<int> d(K);
 
  for (int i = 0; i < K; i++) {
    cin >> d.at(i);
  }
 
  int i = N;
  while (1) {
    if (check(i,d)) {
      cout << i << endl;
      return 0;
    }
    i++;
  }
 
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<int, int>

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  int mn = 1000000, mx = -1000000;
  REP(i, n){
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
  }
  if(mn >= 0){
    cout << n-1 << endl;
    REP(i, n-1) cout << i+1 << " " << i+2 << endl;
  }
  else if(mx <= 0){
    cout << n-1 << endl;
    REP(i, n-1) cout << n-i << " " << n-i-1 << endl;
  }
  else if(abs(mn) < abs(mx)){
    int ind = 0;
    REP(i, n){
      if(a[i] == mx) ind = i;
    }
    int ans = n-1;
    REP(i, n){
      if(a[i]<0) ans++;
    }
    cout << ans << endl;
    REP(i, n){
      if(a[i] < 0) cout << ind+1 << " " << i+1 << endl;
    }
    REP(i, n-1) cout << i+1 << " " << i+2 << endl;
  }
  else{
    int ind = 0;
    REP(i, n) if(a[i] == mn) ind  = i;
    int ans = n-1;
    REP(i, n){
      if(a[i]>0) ans++;
    }
    cout << ans << endl;
    REP(i, n){
      if(a[i] > 0) cout << ind+1 << " " << i+1 << endl;
    }
    REP(i, n-1) cout << n-i << " " << n-i-1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		int result = 0;
		for(int i = 0; i < s.length(); i++){
		    if(s.charAt(i) == '+'){
		        result++;
		    }else{
		        result--;
		    }
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 22992
from sys import exit, stdin
# stdin = open("input.txt")

if __name__ == "__main__":
    N = int(stdin.readline().rstrip())
    cords = [(int(t), int(x), int(y)) 
            for t, x, y in 
            [stdin.readline().rstrip().split() for i in range(N)]]

    dist = lambda x, y: abs(x) + abs(y)
    
    for t, x, y in cords:
        if dist(x, y) > t:
            # no way!
            print("No")
            exit(0)
        
        if not (x + y) % 2 == t % 2:
            print("No")
            exit(0)
    
    print("Yes")


Measured memory_bytes: 80476
#include <stdio.h>
int main(){ 
 
     char search[21], word[21]; 
     int count=0; 
     int i; 
     scanf("%s", search); 
     while(1){ 
         scanf(" %s", word); 
         if(strcmp(word, "END_OF_TEXT")==0)break; 
         for(i=0;word[i]!='\0';i++){ 
             word[i]=tolower(word[i]); 
         } 
         if(strcmp(word, search)==0){ 
             count++; 
         } 
     } 
     printf("%d\n", count); 
     return 0; 
 } 


Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define MOD 1000000007
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
int n,k;
int dp[100002];
int final(vi &a,int i){
	if(i==0)return 0;
	if(dp[i]!=-1)return dp[i];
	else{
		int cost = INF;
		for(int j = i-1;j>=0 && j>=i-k;j--){
			cost = min(cost,abs(a[i]-a[j])+final(a,j));
		}
		return dp[i] = cost;
	}
}

int main() {
    // your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n >> k;
    vi a(n);

    for(int i = 0;i<n;i++)cin >> a[i];
    for(int i = 0;i<100002;i++)dp[i]=-1;
    int out = final(a,n-1);
    cout << out << "\n";
    return 0;
}

Measured memory_bytes: 11840
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll g = m/2;
	if(g>n)
	{
		ll y = (g-n)/2;
		n+=y;
	}
	cout<<min(n,g)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int i,j,k;
  int s[1228],n,r;
  j=0;
  for(i=3;i<10000;i+=2){
    r=(int)sqrt(i)+1;
    for(k=3;k<r;k+=2)
      if(i%k==0)
	r=0;
    if(r){
      s[j]=i;
      j++;
    }
  }
  j=0;
  for(i=1;i<1228;i++){
    if(s[i]-s[i-1]==2){
      s[j]=s[i];
      j++;
    }
  }
  for(;;){
    scanf("%d",&n);
    if(n==0)
      break;
    for(i=204;s[i]>n;i--);
    printf("%d %d\n",s[i]-2,s[i]);
  }
  return 0;
}

Measured memory_bytes: 0
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = list(iss())
    t = S[::2].count("0") + S[1::2].count("1")
    print(min(t, len(S) - t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4308
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<n+1;i++)

using namespace std;
using std::swap;

vector<long long int> v;
vector<long long int> w;



int main() {
	int N, M;
	int ans = 0;
	cin >> N >> M;
	vector<vector<int>> m(N);
	if (M > 0) {
		rep(i, M) {
			int s, c;
			cin >> s >> c;
			if (N != 1 && s == 1 && c == 0) {
				cout << -1 << "\n";
				return 0;
			}
			m[s - 1].push_back(c);
		}
		rep(i, N) {
			if (m.at(i).size() >= 2) {
				rep(j, m.at(i).size() - 1) {
					if (m[i][j] != m[i][j + 1]) {
						cout << -1 << "\n";
						return 0;
					}
				}
			}
		}
	}
	if (N != 1) {
		if (m.at(0).size() == 0)m[0].push_back(1);
		rep(i, N) {
			if (m.at(i).size() == 0) continue;
			else {
				ans += m[i][0] * pow(10, N - i - 1);
			}
		}
	}
	else { 
		if(m.at(0).size() == 0)m[0].push_back(0);
		ans += m[0][0];
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
#include <iomanip>
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 int mod=1e9+7;

int main() {
 map<int,int>k;
 int N;
 cin>>N;
 for(int i=0;i<N-1;i++){
   int a;
   cin>>a;
   k[a]++;
 }
for(int i=1;i<=N;i++){
  cout<<k[i]<<endl;
}
 return 0;  
}

Measured memory_bytes: 12972
#include<iostream>
using namespace std;
int main()
{
  long int h,a;
  cin>>h>>a;
  long i;
  for(i=0;;i++)
  {	
    h=h-a;
    if(h <= 0 )
    { 
      	cout<<i+1;
		break;
    }
  }
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#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;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


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



int main() {

	int c[3][3];

	REP(i, 3) {
		REP(j, 3) {
			cin >> c[i][j];
		}
	}

	

	if (c[1][0] - c[0][0] == c[1][1] - c[0][1] && c[1][0] - c[0][0] == c[1][2] - c[0][2]) {
		if (c[2][0] - c[0][0] == c[2][1] - c[0][1] && c[2][0] - c[0][0] == c[2][2] - c[0][2]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

class union_find {
private:
	vector<int> uf;

public:
	union_find(int n):uf(n, -1) {}

	inline int find(int x) {
		return uf[x] < 0 ? x : uf[x] = find(uf[x]);
	}

	inline void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y)
			return;

		if(uf[x] > uf[y])
			swap(x, y);

		else if(uf[x] == uf[y])
			--uf[x];

		uf[y] = x;
	}

	inline bool same(int x, int y) {
		return find(x) == find(y);
	}
};

struct edge {
	int a, b, cost;
	edge(int a, int b, int cost):a(a), b(b), cost(cost) {}
};

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

	constexpr long long mod = 10007;

	for(int n; cin >> n && n;) {
		vector<edge> es;
		es.reserve(n);

		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < 2; ++j) {
				int to, cost;
				cin >> to >> cost;
				if(to < i) continue;
				es.emplace_back(i, to, cost);
			}
		}

		union_find uf(n);
		for(int i = 0; i < n; ++i) {
			uf.unite(es[i].a, es[i].b);
		}

		unordered_map<int, pair<int, int>> num;

		for(int i = 0; i < n; ++i) {
			const int group_id = uf.find(es[i].a);
			pair<int, int>& tmp = num[group_id];

			if(tmp.first < es[i].cost) {
				tmp = make_pair(es[i].cost, 1);
			}
			else if(tmp.first == es[i].cost) {
				++tmp.second;
			}
		}

		long long ans = 1;
		for(const auto& element : num) {
			ans *= element.second.second;
			ans %= mod;
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1340
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 黒のコマを表す文字 */
	private static final char BLACK = '#';

	/** 上下左右の座標を表す配列 */
	private static final int[] X = { 0, 1, 0, -1 };
	private static final int[] Y = { 1, 0, -1, 0 };

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt(), w = scanner.nextInt();
			boolean[][] s = new boolean[h][w];
			IntStream.range(0, h).forEach(i -> {
				char[] t = scanner.next().toCharArray();
				IntStream.range(0, w).forEach(j -> s[i][j] = (t[j] == BLACK));
			});
			for (int i = 0; i < h; i++) {
				KOMA: for (int j = 0; j < w; j++) {
					if (s[i][j]) {
						for (int k = 0; k < X.length; k++) {
							int newX = i + X[k];
							int newY = j + Y[k];
							if ((newX >= 0) && (newX < h) && (newY >= 0) && (newY < w)) {
								if (s[newX][newY]) {
									continue KOMA;
								}
							}
						}
						System.out.println("No");
						return;
					}
				}
			}
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 28628