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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void) {
  while (true) {
    int h, w;
    cin >> h >> w;
    if (!h && !w)
      break;

    int answ = INF, ansh = INF;
    for (int hh = 150; hh >= 1; hh--) {
      for (int ww = 150; ww >= 1; ww--) {
        if (ww <= hh)
          continue;
        if (ww <= w && hh <= h)
          continue;
        // cout << "j:" << hh << " i:" << ww << endl;
        if (hh * hh + ww * ww > h * h + w * w) {
          //(ansh, answ)??¨(hh, ww)??§(hh, ww)?????????????°?????????£????????´??°
          if (ansh * ansh + answ * answ > hh * hh + ww * ww ||
              ansh * ansh + answ * answ == hh * hh + ww * ww && ansh > hh) {
            //cout << "a h:" << hh << " w:" << ww << endl;
            ansh = hh;
            answ = ww;
          }
        }
        if (hh * hh + ww * ww == h * h + w * w) {
          //cout << "b h:" << hh << " w:" << ww << endl;
          if (h < hh) {
            //cout << "h:" << hh << " w:" << ww << endl;
            ansh = hh;
            answ = ww;
          }
        }
      }
    }

    cout << ansh << " " << answ << endl;
  }
  return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>
int main(void) {
    int q,c,a,n,i,j,count;
    scanf("%d",&q);
    for (i=0; i<q; i++) {
        count=0;
        scanf("%d%d%d",&c,&a,&n);
        if (c<=a&&c<=n) {
            count+=c;
            a-=c,n-=c,c=0;
        } else if (a<=c&&a<=n) {
            count+=a;
            c-=a,n-=a,a=0;
        } else {
            count+=n;
            c-=n,a-=n,n=0;
        }
        if (2*a<=c) {
            count+=a;
            c-=2*a,a=0;
        } else {
            count+=c/2;
            a-=c/2,c=0;
        }
        count+=c/3;
        printf("%d\n",count);
    }
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;

int main(){
  int n=0;
  int a[10];
  int ans=0;
  cin>>n;
  //  while(scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9])){
  for(int j=0;j<n;j++){
    for(int k=0;k<10;k++){
      cin>>a[k];
    }
    ans=0;
    int l=0,r=0;
    for(int i=0;i<10;i++){
      if(i==0){
	l=a[i];
      }
      else{
	int ma=max(l,r);
	int mi=min(l,r);
	if(a[i]>ma){
	  if(l==ma){
	    l=a[i];
	  }
	  else{
	    r=a[i];
	  }
	}
	else if(mi<a[i]&&a[i]<ma){
	  if(l==mi){
	    l=a[i];
	  }
	  else{
	    r=a[i];
	  }
	}
	else{
	  break;
	}
      }
      if(i==9){
	ans=1;
      }
    }

    if(ans==1){
      cout<<"YES\n";
    }
    else{
      cout<<"NO\n";
    }
  }
  return 0;
}


      

Measured memory_bytes: 0
N, M = map(int, input().split())
cakes = []

for i in range(N) :
    x, y, z = map(int, input().split())
    cakes.append((x, y, z))
    
perms = []

def genperms(s) :
    if len(s) == 3 :
        perms.append(list(s))
    else :
        genperms(s + "0")
        genperms(s + "1")

genperms("")

max_sum = -1 * (10**20)
for p in perms : 
    l = []
    for c in cakes :
        cd1, cd2, cd3 = 1 if p[0] == "1" else -1,  1 if p[1] == "1" else -1,  1 if p[2] == "1" else -1
        l.append(cd1 * c[0] + cd2 * c[1] + cd3 * c[2])
        
    l_s = sorted(l, reverse=True)
    # print("DBG : ", sum(l_s[:M]))
    max_sum = max(max_sum, sum(l_s[:M]))

print(max_sum)
        


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int inp[100010];
int dp[100010];

int main(){

    int n;
    cin>>n;

    for(int i = 0; i < n; i++) {
        cin>>inp[i];
    }

    dp[0] = 1;
    int mx = 1;

    for(int i = 1; i < n; i++) {
        if(inp[i] <= inp[i-1]) {
            dp[i] = dp[i-1] + 1;
        } else dp[i] = 1;
        mx = max(mx, dp[i]);
    }

    cout<<mx-1<<endl;


}


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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 2010, mod = 1e9 + 7;

int n, k;
LL f[N][N];

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n; i ++ ) f[i][0] = 1;
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= i; j ++ )
			f[i][j] = (f[i - 1][j] + f[i - 1][j - 1]) % mod;
	
	for (int i = 1; i <= k; i ++ )
		cout << f[k - 1][i - 1] * f[n - k + 1][i] % mod << endl;
	return 0;
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;





int main() {

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

	int ans = INF;

	REP(i, 101) {
		int cur = 0;
		REP(j, n) {
			cur += (x[j] - i)*(x[j] - i);
		}
		ans = min(ans, cur);
	}
	cout << ans << endl;


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"

struct edge{
  ll from, to, cost;
  edge(){}
  edge(ll t, ll c){ to = t; cost = c;}
  edge(ll f, ll t, ll c){ from = f; to = t; cost = c;}
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll L;
  cin >> L;
  ll N = 0;
  ll tmp = 1;
  while(tmp <= L){
    tmp <<= 1;
    N++;
  }
  vector<edge> ans(0);
  for(int i = 1; i < N; i++){
    ll cost = 1 << (N - 1 - i);
    ans.push_back(edge(i, i+1, 0));
    ans.push_back(edge(i, i+1, cost));
  }
  //以上で2^(N-1)-1まで表せる
  ll extra = (L-1) - ((1<<(N-1)) - 1);
  ll base = 1 << (N-1);
  for(int i = N-1; i >= 0; i--){
    if((extra >> i) & 1){
      ans.push_back(edge(1, N-i, base));
      base += (1<<i);
    }
  }
  cout << N << ' ' <<  ans.size() << endl;
  for(auto x: ans) cout << x.from << ' ' << x.to << ' ' << x.cost << endl;
}

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

int main() {
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll sum = 0;
  for (int i = 1; i < n; i++) {
    ll dai = 0;
    if (a[i - 1] > a[i]) {
      dai = a[i - 1] - a[i];
      sum += dai;
      a[i] += dai;
    }
  }

  cout << sum << endl;
  return 0;
}


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

int main(){
	long long a=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		a+=s[i]-48;
	}
	if(a%9==0){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3744
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

class Main{
    static double mod = 1e9+7;

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Library lib = new Library();
        int[][] c = new int[3][3];
        int[] rate = new int[2];
        for (int i=0;i<3;i++){
            for (int j=0;j<3;j++){
                c[i][j] = sc.nextInt();
            }
        }
        for (int i=1;i<3;i++){
            rate[i-1] = c[0][i] - c[0][i-1];
        }
        for (int i=1;i<3;i++){
            for (int j=1;j<3;j++){
                if (c[i][j]-c[i][j-1]!=rate[j-1]){
                    System.out.println("No");
                    return;
                }
            }
        }
        for (int i=1;i<3;i++){
            rate[i-1] = c[i][0] - c[i-1][0];
        }
        for (int i=1;i<3;i++){
            for (int j=1;j<3;j++){
                if (c[j][i]-c[j-1][i]!=rate[j-1]){
                    System.out.println("N0");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
}

class Library{
    static long a;
    static long b;

    public static long gcd(long a,long b){
        Library lib = new Library();
        if (a<b){
            lib.swap(a,b);
        }
        if (b==0){
            return a;
        } else {
            return gcd(b,a%b);
        }
    }

    public static void swap(long a,long b){
        long x = a;
        a = b;
        b = x;
        return;
    }
}

Measured memory_bytes: 22608
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  int n = s.size(), sm = 0;
  for(int i = 0; i < n; i++){
    if(s[i] != t[i]){
      sm++;
    }
  }
  
  cout << sm << "\n";
}

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

int main() {
    int N;
    cin >> N;
    vector <int> X(N);
    for (int i=0; i<N; i++) cin >> X.at(i);
    double ans=10000000;
    for (int i=0; i<100; i++) {
        double tmp=0;
        for (int j=0; j<N; j++) {
            tmp += pow(X.at(j)-i, 2);
        }
        ans = min(ans, tmp);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};
int n,m;
ll k;
ll x[200002]={},d[200002]={};

ll BinarySearch(ll i2){
	int left=0,right=m+1,mid;
	while(right-left>1){
		mid=(right+left)/2;
		if(d[mid]+i2>k)right=mid;
		if(d[mid]+i2<k)left=mid;
		if(d[mid]+i2==k)return mid;
	}
	return left;
}
int main() {

	cin>>n>>m>>k;

	rep(i,n){
		int a;
		cin>>a;
		x[i+1]+=a;
		x[i+1]+=x[i];
	}
	rep(i,m){
		int b;
		cin>>b;
		d[i+1]+=b;
		d[i+1]+=d[i];
	}

	ll ans=0;
	for(int i=0; i<n+1; i++){
		if(x[i]>k)continue;

		ll q=i;
		ans=max(q,ans);
		ans=max(ans,BinarySearch(x[i])+i);
	}
	cout<<ans<<endl;

	return 0;
}


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

int main() {
  int n;
  int ans = 0;
  cin >> n;
  vector<int> a(n);
  rep(i ,n){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if(a[n / 2 - 1] == a[n /2]){
    cout << 0 << endl;
    return 0;
  }else {
    for (int i = a[n / 2 - 1] + 1; i <= a[n / 2]; i++){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    int arr[n+1];
    for(int i=1;i<=n;i++)
        cin >> arr[i];
    int dp[n+1];
    for(int i=0;i<=n;i++)
        dp[i] = INT_MAX;
    dp[1] = 0;
    dp[2] = abs(arr[1]-arr[2]);
    for(int i=3;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(i-j>=1){
                dp[i] = min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));                
            }
            else
                continue;
        }
    }
    cout << dp[n] << "\n"; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){
    lint d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d)cout<<"Yes";
   else cout<<"No";

  }
      

Measured memory_bytes: 3680
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h> 
#include <iostream>
#include <map>
#include <cmath>
#include<set>
#include <vector>
#include<bitset>
#include <string>
#include<queue>
#include <algorithm>
#include<set>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define vl vector<long long >;
//#define rep(i,a,b) for(int i=a;i<b;++i)
//typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,int>ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;
const int N=1e5+5;
int A[N];
#define INF 10000
int dp[N]={0};
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

/*void show(vi v,int valeur){
    int count=0;
    
    rep(i,0,(int)v.size()){
        ++count;
        cout<<v[i]<<" " ;
        if(count==valeur){cout<<"\n";count=0;}
    }
}*/
 int main() {
        ios_base::sync_with_stdio(false); cin.tie(NULL);int n,k;
  //ll ans=0;
  cin>>n>>k;
  rep(i,0,n){
      cin>>A[i];
  }
  dp[1]=abs(A[1]-A[0]);
  dp[0]=0;
  
  rep(i,2,n){
      dp[i]=1000000000;
      for(int j=1;j<=k;++j){
          if((i-j)>=0) dp[i]=min(dp[i],abs(A[i]-A[i-j])+dp[i-j]);
      }
    // cout<<dp[i]<<"\n";
  }
  cout<<dp[n-1];
   return 0;
 }



Measured memory_bytes: 4416
calc :: [Int] -> Int -> [Int]
calc _ 0  = []
calc xs n = abs (sum (take n xs) - sum (drop n xs)) : calc xs (n - 1)

main :: IO ()
main = do
  n <- readLn :: IO Int
  xs <- map read . words <$> getLine :: IO [Int]
  print $ minimum $ calc xs n


Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

ll mod=1000000007;

int main() {
	int N;
	cin >> N;
	int whol=0;
	whol |= (1<<N);
	vector<vector<int>> a(N, vector<int>(N)), prep(N+1);
	for(int i=0; i<N; ++i){
	    for(int j=0; j<N; ++j){
	        cin >> a[i][j];
	    }
	}
	for(int i=0; i<whol; ++i){
	    int cnt=0, p=i;
	    while(p>0){
	        cnt += p%2;
	        p /= 2;
	    }
	    prep[cnt].push_back(i);
	}
	vector<ll> dp(whol, 0);
	dp[0]=1;
	for(int i=0; i<N; ++i){
	    for(int s=0; s<N; ++s){
	        if(a[i][s]){
	            for(int t=0; t<prep[i].size(); ++t){
	                if(!((prep[i][t])&(1<<s))){
	                    dp[(prep[i][t])|(1<<s)]=(dp[(prep[i][t])|(1<<s)]+dp[prep[i][t]])%mod;
	                }
	            }
	        }
	    }
	}
	cout << dp[whol-1] << endl;
	return 0;
}


Measured memory_bytes: 26896
#include <bits/stdc++.h>
using namespace std;
int main()
{   int n;
	cin >> n;
	int v[n], c[n], sum=0;
	for (int i=0; i<n; i++)
	{	cin >> v[i];
	}
	for (int i=0; i<n; i++)
	{   cin >> c[i];
	}
	for (int i=0; i<n; i++)
	{	if (v[i]-c[i]>0)
		{  sum += v[i]-c[i];
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#ai <= min(bi-1,bi) and a1 <= b1

n = int(input())
b = list(map(int,input().split()))
a = 0
for i in range(n):
  if i == 0:
    a += b[0]
  elif i == n-1:
    a += b[n-2]
  else:
    a += min(b[i-1:i+1])
print(a)


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

int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    
    printf("%.15f ",(double)(w) * (double)(h) / (double)(2));
    if (w % 2 == 0 && h % 2 == 0 && x == w / 2 && y == h / 2) cout << 1;
    else cout << 0;
}


Measured memory_bytes: 256
n = int(input())

cnt = [0] * n
for x in range(1, int(n ** 0.5) + 1):
    for y in range(1, int(n ** 0.5) + 1):
        for z in range(1, int(n ** 0.5) + 1):
            num = (x + y) ** 2 - x * y + z * (x + y + z)
            if num <= n:
                cnt[num - 1] += 1
print(*cnt, sep="\n")


Measured memory_bytes: 9712
def main():
    N, *A = map(int, open(0).read().split())
    A.sort()
    if N % 2 == 0:
        s, l = A[:N//2], A[N//2:]
        ans = 2*(sum(l) - sum(s))
        ans += s[-1] - l[0]
        print(ans)
        return

    sep1 = (N + 1)//2
    s1, l1 = A[:sep1], A[sep1:]
    # print(s1, l1)
    ans1 = 2*(sum(l1) - sum(s1))
    ans1 += s1[-1] + s1[-2]

    sep2 = sep1 - 1
    s2, l2 = A[:sep2], A[sep2:]
    # print(s2, l2)
    ans2 = 2*(sum(l2) - sum(s2))
    ans2 -= l2[0] + l2[1]

    print(max(ans1, ans2))

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        
        System.out.println(a < b && b < c ? "Yes" : "No");
    }
}

// ３つの整数a, b, cを読み込み、それらが a < b < cの条件を満たすならば"Yes"を、満たさないならば"No"を出力するプログラムを作成して下さい。
// Sample Input 1
// 1 3 8
// Sample Output 1
// Yes
// Sample Input 2
// 3 8 1
// Sample Output 2
// No



Measured memory_bytes: 26132
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;

int main(){
    int a[5]; 
    int i;
    for(i = 0; i < 5; i++){
        cin >> a[i];
    }
    int sum = 0;
    int max = 0;
    int temp;
    for(i = 0; i < 5; i++){
        temp = 10 - (a[i] % 10);
        if(temp == 10) temp = 0;
        sum += a[i] + temp;
        if(max < temp){
            max = temp;
        }
    }
    sum -= max;
    cout << sum << endl;

    return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++) {
        cin >> d.at(i);
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            ans += d.at(i) * d.at(j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve():
  n,d = (int(i) for i in input().split())
  query = []
  judge = []
  for i in range(1,2001):
    judge.append((i**2))
  
  for i in range(n):
    x = list(int(i) for i in input().split())
    query.append(x)
  ans = 0
  for i in range(n):
    for j in range(n):
      if (i!=j):
        checker = 0
        for k in range(d):
         checker += (query[j][k]-query[i][k])**2
        if checker in judge:
          ans += 1
  print(ans//2)
solve()

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    cin >> N;
    V<ll> a(N);
    rep(i, N) cin >> a[i];
    ll ans = 0;

    while (true) {
        ll cnt = 0;
        rep(i, N) { cnt += a[i] / N; }
        if (cnt == 0) {
            break;
        }
        rep(i, N) {
            ll x = a[i] / N;
            a[i] -= x * N;
            a[i] += cnt - x;
        }
        ans += cnt;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
int main() {
  double *x = new double[1001];
  double *y = new double[1001];
  int i, n;
  long sum2 = 0, sum3 = 0;
  double D1 = 0, D2 = 0, D3 = 0, Dm = 0;
  cin >> n;
  for(i = 0; i < n; i++) {
	cin >> x[i];
  }
  for(i = 0; i < n; i++) {
	cin >> y[i];
  }
  
  for(i = 0; i < n; i++) {
	D1 += abs(x[i] - y[i]);
	
	sum2 += pow(abs(x[i] - y[i]), 2);
	sum3 += pow(abs(x[i] - y[i]), 3);
	
	if(i == 0) {
	  Dm = abs(x[i] - y[i]);
	}
	else {
	  if(abs(x[i] - y[i]) > Dm) {
		Dm = abs(x[i] - y[i]);
	  }
	}
  }
  D2 = sqrt(sum2);
  D3 = cbrt(sum3);
  printf("%lf\n%lf\n%lf\n%lf\n", D1, D2, D3, Dm);
  return 0;
}

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

ll a[405];
ll dp[405][405];
ll sum[405];
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        sum[i] = sum[i-1]+a[i];
    }
    for(int i=1;i<=n;i++) {
        dp[i][i] = 0;
    }
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            if(i!=j) dp[i][j] = 10000000000000;
        }
    }
    for(int l=2;l<=n;l++) {
        for(int i=1, j=i+l-1;j<=n;i++, j++) {
            for(int k=i;k<=j;k++) {
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]);
            }
        }
    }
    cout<<dp[1][n]<<endl;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder output = new StringBuilder();
	
	int H;
	int[] Array;

	public void input() {
		H = sc.nextInt();
		Array = new int[H+1];
		for(int i=1; i<=H; i++) {
			Array[i] = sc.nextInt();
		}
	}
	
	public void output() {
		int index;
		for(int i=1; i<H+1; i++) {
			output.append("node ").append( Integer.toString(i) );
			output.append(": key = ").append( Integer.toString(Array[i]) ).append(", ");
			//親がいるかどうかの判定
			index = i/2;
			if( !(index < 1) ) {output.append("parent key = ").append( Integer.toString(Array[index]) ).append(", ");}
			//左の子を持つかの判定
			index = 2 * i;
			if( !(index > H) ) {output.append("left key = ").append( Integer.toString(Array[index]) ).append(", ");}
			//右の子を持つかの判定
			index = 2 * i + 1;
			if( !(index > H) ) {output.append("right key = ").append( Integer.toString(Array[index]) ).append(", ");}
			output.append("\n");
		}
		System.out.print( output.toString() );
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.output();
	}
}



Measured memory_bytes: 26368
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <deque>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

  ll N; cin>>N;
  vector<ll> A(N);
  vector<ll> B(N);
  ll a_sum = 0;
  for(auto& a: A) {
    cin>>a;
    a_sum += a;
  }

  ll b_sum = 0;
  vector<ll> plus;
  ll minus_sum = 0;
  ll chg_count = 0;
  for(int i=0; i<N; i++) {
    int b; cin>>b;
    B[i] = b;
    b_sum += b;
    ll a_sub_b = A[i] - B[i];
    if(a_sub_b > 0) {
      plus.push_back(a_sub_b);
    }
    ll b_sub_a = B[i] - A[i];
    if(b_sub_a > 0) {
      minus_sum += b_sub_a;
      chg_count++;
    }
  }

  if(a_sum < b_sum) {
    cout << -1 << endl;
  } else {
    ll ans = chg_count;
    sort(plus.begin(), plus.end(), greater<ll>());
    for(int i=0; i<(int)plus.size(); i++) {
      if(minus_sum <= 0) {
        break;
      }
      ll p = plus[i];
      minus_sum -= p;
      ans++;
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 2428
#include"bits/stdc++.h"
using namespace std;

int Partition(vector<int>& A, int p, int r)
{
	int i = p - 1;
	int x = A.at(r);

	for (int j = p; j < r; j++)
	{
		if (A.at(j) <= x)
		{
			i++;
			swap(A.at(i), A.at(j));
		}
	}
	swap(A.at(i + 1), A.at(r));

	return i + 1;
}

void print(vector<int>& A, int index)
{
	for (int i = 0; i < A.size(); i++)
	{
		if (i) cout << " ";
		if (i == index) cout << "[";
		cout << A.at(i);
		if (i == index) cout << "]";
	}
	cout << endl;
}

int main(void)
{

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

	int index = Partition(A, 0, N-1);

	print(A, index);



	return 0;
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)cout<<"No";
    else if(a!=b&&b!=c&&c!=a)cout<<"No";
    else cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;


int selectionSort(int A[],int N){
    int i,j,t,sw = 0,minj;
    for(i = 0;i<N-1;i++){
        minj = i;
        for(j = i;j<N;j++){
            if(A[j] <A[minj]) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if(i != minj) sw++;
    }
    return sw;
}

int main(){
    int A[100],N,i,sw;
    
    scanf("%d",&N);
    for(i = 0;i < N;i++)scanf("%d",&A[i]);
    
    sw = selectionSort(A,N);
    
    for(i = 0;i<N;i++){
        if(i > 0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);
    
    return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 2e9 + 9;
const ll LINF = 1e18;
using namespace std;

int main(){
	int A, B, m;
	cin >> A >> B >> m;
	vector<int> a(A), b(B), c(m),d(m+1), x(m), y(m);

	for (int i = 0; i < A; i++)cin >> a.at(i);
	for (int i = 0; i < B; i++)cin >> b.at(i);
	for (int i = 0; i < m; i++)cin >> x.at(i) >> y.at(i) >> c.at(i);
	
	for (int i = 1; i < m + 1; i++) {
		d.at(i) = a.at(x.at(i-1)-1) + b.at(y.at(i-1)-1) - c.at(i-1);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	d.at(0) = a.at(0) + b.at(0);
	sort(d.begin(), d.end());
	cout << d.at(0) << endl;
	return 0;
}


Measured memory_bytes: 5640
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

from itertools import product
import copy

H,W,K = LI()
c = [list(map(str,input())) for _ in range(H)]

def count(S):
    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                ans += 1
    return ans

A = list(product([True,False],repeat=H))
B = list(product([True,False],repeat=W))

num = 0
for a in A:
    for b in B:
        S = copy.deepcopy(c)
        for i in range(H):
            if a[i]:
                for j in range(W):
                    S[i][j] = '?'
        for j in range(W):
            if b[j]:
                for i in range(H):
                    S[i][j] = '?'
        co = count(S)
        if co == K:
            num += 1

print(num)

Measured memory_bytes: 73712
def eratosthenes(n):
    prime = []
    limit = n**0.5
    numbers = [i for i in range(2,n+1)]
    while True:
        p = numbers[0]
        if limit <= p:
            return prime + numbers
        prime.append(p)
        numbers = [i for i in numbers if i%p != 0]
    return prime
p = eratosthenes(100003)
X = int(input())
for n in p:
    if X<=n:
        break
print(n)

Measured memory_bytes: 48048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
#define pb push_back
#define ll long long
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int main() 
{
    fast_io();
    int arr[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    int m1,d1; cin >> m1 >> d1;
    int m2,d2; cin >> m2 >> d2;
    if (d1 == arr[m1-1])
        cout << 1 << endl;
    else
        cout << 0 << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int K;
    cin >> K;

    int evenNum = K / 2;
    int oddNum = K - evenNum;

    p(evenNum * oddNum);

    return 0;
}

Measured memory_bytes: 256
def s(aa, b):
    return sum(abs(a - (b + i + 1)) for i, a in enumerate(aa))


def main():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = sorted(a - (i + 1) for i, a in enumerate(aa))
    if len(bb) % 2 != 0:
        b = bb[(len(bb) - 1) // 2]
    else:
        b = (bb[len(bb) // 2] + bb[len(bb) // 2 - 1]) // 2
    print(s(aa, b))


if __name__ == '__main__':
    main()


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

int main()
{
  int a,b;
  cin >> a >> b;
  if(a<=0 && 0<=b)cout << "Zero";
  else if(a>0)cout << "Positive";
  else if(!((b-a)%2))cout << "Negative";
  else cout << "Positive";
  cout << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		if(i%3!=0 && i%5!=0){
			ans+=i;
		}
	}
	cout<<ans<<endl;
  return(0);
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n,0);
	vector<int> b(n,0);
	for(int i = 0;i < n;i++)
	{
		cin >> a.at(i);
		if(i == 0)
		{
			b.at(i) = a.at(i);
		}
		else
		{
			b.at(i) = min(b.at(i-1),a.at(i));
		}
	}
	int c = 0;
	for(int i = 0;i < n;i++)
	{
		if(a.at(i) <= b.at(i))
		{
			c++;
		}
	}
	cout << c <<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
#define MAX 24

int A[5], k;
bool b = 0;

int main() {
    for ( int i = 0; i < 5; i++ ) {
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &k);
    
    for ( int i = 0; i < 5; i++ ) {
        for ( int j = i+1; j < 5; j++ ) {
            if ( A[j] - A[i] > k ) {
                b = 1;
            }
        }
    }
    
    if ( b ) {
        printf(":(\n");
    } else {
        printf("Yay!\n");
    }
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()
	x := scanInt()

	c := make([]int, n)
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		c[i] = scanInt()
		for j := 0; j < m; j++ {
			a[i][j] = scanInt()
		}
	}

	ans := 1<<63 - 1
	bitExhaustiveSearch(n, func(arr []bool) {
		sum := make([]int, m)
		cnt := 0
		for i := 0; i < n; i++ {
			if arr[i] {
				cnt += c[i]
				for j := 0; j < m; j++ {
					sum[j] += a[i][j]
				}
			}
		}
		f := true
		for i := 0; i < m; i++ {
			if sum[i] < x {
				f = false
			}
		}
		if f {
			ans = min(ans, cnt)
		}
	})

	if ans == 1<<63-1 {
		fmt.Fprintln(wr, -1)
	} else {
		fmt.Fprintln(wr, ans)
	}

}

func bitExhaustiveSearch(n int, fn func(a []bool)) {
	all := 1 << uint(n)
	a := make([]bool, n)
	for i := 0; i < all; i++ {
		for j := 0; j < n; j++ {
			if i>>uint(j)&1 == 1 {
				a[j] = true
			} else {
				a[j] = false
			}
		}
		fn(a)
	}
}


Measured memory_bytes: 2168
/********   In the name of Allah, the most gracious, the most merciful ********/
#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;

lli dp[110][100010],V[110];
int W[110];

lli knapsack(int n,int w)
{
    for (int i = 0; i <= w;i++)
        dp[0][i] = 0;
    for (int i = 0; i <= n;i++)
        dp[i][0] = 0;
    for (int i = 1; i <= n;i++)
    {
        for (int j = 1; j <= w;j++)
        {
            if(j-W[i]>=0)
            {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - W[i]] + V[i]);
            }
            else
                dp[i][j] = dp[i-1][j];
            //cout << setw(3)<<dp[i][j] <<setw(3);
        }
        //cout << endl;
    }
    return dp[n][w];
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, w;
    cin >> n >> w;
    for (int i = 1;i<=n;i++)
    {
        cin >> W[i] >> V[i];
    }
    lli ans = knapsack(n, w);
    cout << ans << endl;
}


Measured memory_bytes: 80256
from collections import Counter

N=int(input())
S=[input() for _ in range(N)]
S=Counter(S)
count=S.most_common()
count.sort(key=lambda x:x[0])
count.sort(key=lambda x:x[1], reverse=True)

n=count[0][1]
for i in range(len(count)):
  if n==count[i][1]:
    print(count[i][0])
  else:
    break

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

using namespace std;

int main(){
  int h, w, k;
  string s[8];
  cin >> h >> w >> k;
  for(int i=0;i<h;i++)cin >> s[i];
  int all=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#')all++;
    }
  }
  int ans=0;
  for(int ii=0;ii<(1<<h);ii++){
    for(int jj=0;jj<(1<<w);jj++){
      int cnt=0;
      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if((((ii>>i)&1==1)||((jj>>j)&1==1))&&(s[i][j]=='#'))cnt++;
        }
      }
      if(all-cnt==k)ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3588
#include <iostream> // cout, endl, cin

#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    ll ans = 0;
    string s ;
    int n;
    cin>>n>>s;
    vector<ll>R(n,0);
    vector<ll>G(n,0);
    vector<ll>B(n,0);
    int r = 0;
    int g = 0;
    int b = 0;
    for (int l = n - 1; l >= 0; --l) {
        if(s[l] == 'R'){
            r++;

        }else if(s[l] == 'G'){
            g++;

        }else if(s[l] == 'B'){
            b++;

        }
        R[l] = r;
        G[l] = g;
        B[l] = b;
    }

    for (int i = 0; i + 2 < n; ++i) {
        for (int j = i + 1; j + 1 < n; ++j) {
            if(s[i] == s[j]) continue;
            if(s[i] == 'R' && s[j] == 'G'){
                int sum = B[j+1];
                if(s[j+j-i] == 'B' && j+j-i<n && j+j-i >= 0) sum--;
                ans+= sum;
            }else if(s[i] == 'G' && s[j] == 'R'){
                int sum = B[j+1];
                if(s[j+j-i] == 'B' && j+j-i<n && j+j-i >= 0) sum--;
                ans+= sum;
            }
            else if(s[i] == 'G' && s[j] == 'B'){
                int sum = R[j+1];
                if(s[j+j-i] == 'R' && j+j-i<n && j+j-i >= 0) sum--;
                ans+= sum;
            }else if(s[i] == 'B' && s[j] == 'G'){
                int sum = R[j+1];
                if(s[j+j-i] == 'R' && j+j-i<n && j+j-i >= 0) sum--;
                ans+= sum;
            }else{
                int sum = G[j+1];
                if(s[j+j-i] == 'G' && j+j-i<n && j+j-i >= 0) sum--;
                ans+= sum;
            }


        }

    }


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


Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <queue>
#define llint long long
#define inf 100000000000000000

using namespace std;

struct edge{
	llint to, cap, rev;
	edge(llint a, llint b, llint c){
		to = a, cap = b, rev = c;
	}
};

int V, E;
vector<edge> G[105];
llint level[205], iter[205];

void bfs(llint s)
{
	for(int i = 0; i < V; i++) level[i] = inf;
	level[s] = 0;
	
	queue<int> Q;
	Q.push(s);
	while(Q.size()){
		int v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			int u = G[v][i].to;
			if(G[v][i].cap <= 0 || level[u] < inf) continue;
			level[u] = level[v] + 1;
			Q.push(u);
		}
	}
}

llint dfs(int v, llint f)
{
	if(v == V-1) return f;
	
	llint ret;
	for(int i = iter[v]; i < G[v].size(); i++){
		if(level[v] >= level[G[v][i].to] || G[v][i].cap <= 0) continue;
		ret = dfs(G[v][i].to, min(f, G[v][i].cap));
		if(ret > 0){
			G[v][i].cap -= ret;
			G[G[v][i].to][G[v][i].rev].cap += ret;
			return ret;
		}
	}
	return 0;
}

int main(void)
{
	cin >> V >> E;
	
	int a, b, c;
	for(int i = 0; i < E; i++){
		cin >> a >> b >> c;
		G[a].push_back((edge){b, c, G[b].size()});
		G[b].push_back((edge){a, 0, G[a].size()-1});
	}
	
	llint ans = 0, flow;
	while(1){
		bfs(0);
		if(level[V-1] >= inf) break;
		for(int i = 0; i < V; i++) iter[i] = 0;
		while(1){
			flow = dfs(0, inf);
			if(flow <= 0) break;
			ans += flow;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<std::vector<int>>
        d(n, std::vector<int>(n)),
        b(n, std::vector<int>(n, 1));
    std::vector<std::pair<int, int>> t(n*n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            int k; std::cin >> k;
            k--;
            t[i*n + j] = { k/n, k%n };
            d[i][j] = std::min({i, j, n - 1 - i, n - 1 - j});
        }
    }
    int ans = 0;
    std::deque<std::pair<int, int>> que;
    std::vector<int> dd = { 1, 0, -1, 0, 1 };
    for (const auto &p : t) {
        ans += d[p.first][p.second];
        d[p.first][p.second]--;
        b[p.first][p.second] = 0;
        que.emplace_back(p);
        while (!que.empty()) {
            auto q = que.front();
            que.pop_front();
            for (int i = 0; i < 4; i++) {
                int u = q.first + dd[i];
                int v = q.second + dd[i + 1];
                if (!(0 <= u && u < n)) continue;
                if (!(0 <= v && v < n)) continue;
                if (d[u][v] <= d[q.first][q.second] + b[u][v])
                    continue;
                d[u][v] = d[q.first][q.second] + b[u][v];
                que.emplace_back(u, v);
            }
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 7052
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 0, l, r;
  scanf("%lld%lld%lld%lld", &n, &k, &l, &r);
  ll a[n];
  for(j = 0; j < n; ++j) scanf("%lld", &a[j]);
  vector < pair<ll, ll> > v1, v2;
  for(i = 0; i < 1 << n / 2; ++i) {
    ll now = 0, nown = 0;
    for(j = 0; j < n / 2; ++j) if(1 << j & i) {
      nown++, now += a[j];
    }
    pair<ll, ll> p = make_pair(nown, now);
    v1.push_back(p);
  }
  for(i = 0; i < 1 << (n + 1) / 2; ++i) {
    ll now = 0, nown = 0;
    for(j = 0; j < (n + 1) / 2; ++j) if(1 << j & i) {
      nown++, now += a[n / 2 + j];
    }
    pair<ll, ll> p = make_pair(nown, now);
    v2.push_back(p);
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  vector < pair<ll, ll> >::iterator it;
  for(it = v1.begin(); it != v1.end(); ++it) {
    pair<ll, ll> p1 = make_pair(k - (*it).first, l - (*it).second);
    pair<ll, ll> p2 = make_pair(k - (*it).first, r - (*it).second);
    ans += upper_bound(v2.begin(), v2.end(), p2) - lower_bound(v2.begin(), v2.end(), p1);
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main(){
    //   #ifndef ONLINE_JUDGE
    //   freopen("in.txt","r",stdin);
    //    freopen("out.txt","w",stdout);
    //   #endif
    char s;
    int n;
    long long sum=0;

    cin>>n;
    int arr[n],ans[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int last=0;
    for(int i=0;i<n-1;i++) last^=arr[i];
    ans[n-1]=last;
    for(int i=n-1;i>0;i--){
        ans[i-1]= arr[i]^arr[i-1] ^ ans[i];
    }
    for(int i=0;i<n;i++) cout<<ans[i]<<" ";
    


   
    return 0;
}

Measured memory_bytes: 5068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_5_C_KochCurve
{
    class Program
    {
        struct Point { public double x, y; }
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            Point a, b;
            a.x = 0;
            a.y = 0;
            b.x = 100;
            b.y = 0;
            Console.WriteLine("{0:0.00000000} {1:0.00000000}", a.x, a.y);
            Koch(n, a, b);
            Console.WriteLine("{0:0.00000000} {1:0.00000000}", b.x, b.y);
        }

        static void Koch(int n, Point a, Point b)
        {
            if (n == 0)
            {
                return;
            }
            Point s, t, u;
            double th = Math.PI * 60.0 / 180.0; //度からラジアンへ単位を変換

            s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
            s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
            t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
            t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
            u.x = (t.x - s.x) * Math.Cos(th) - (t.y - s.y) * Math.Sin(th) + s.x;
            u.y = (t.x - s.x) * Math.Sin(th) + (t.y - s.y) * Math.Cos(th) + s.y;

            Koch(n - 1, a, s);
            Console.WriteLine("{0:0.00000000} {1:0.00000000}", s.x, s.y);
            Koch(n - 1, s, u);
            Console.WriteLine("{0:0.00000000} {1:0.00000000}", u.x, u.y);
            Koch(n - 1, u, t);
            Console.WriteLine("{0:0.00000000} {1:0.00000000}", t.x, t.y);
            Koch(n - 1, t, b);
        }
    }
}



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

using ll = long long;
const long long MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vector<double> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i) >> y.at(i);
    }

    double rate = 1.0;
    int LOOP = 1000000;
    double cx = 0, cy = 0;
    for (int l = 0; l < LOOP; l++) {
        double max_d = 0.0;
        double max_x = 0, max_y = 0;
        for (int i = 0; i < n; i++) {
            double dx = cx - x.at(i), dy = cy - y.at(i);
            double d = sqrt(dx * dx + dy * dy);
            if (max_d < d) {
                max_d = d;
                max_x = x.at(i);
                max_y = y.at(i);
            }
        }
        cx += (max_x - cx) * rate;
        cy += (max_y - cy) * rate;

        rate *= 0.999;
    }
    
    double max_d = 0;
    for (int i = 0; i < n; i++) {
        double dx = cx - x.at(i), dy = cy - y.at(i);
        double d = sqrt(dx * dx + dy * dy);
        max_d = max(max_d, d);
    }
    printf("%.10lf\n", max_d);
}   

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll H, W;
    cin >> H >> W;

    ll cnt = 0;
    rep (i, H) {
        rep (j, W) {
            char A;
            cin >> A;
            if (A == '#') {
                cnt++;
            }
        }
    }

    if (cnt == H+W-1) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256