akhauriyash/Code-Regression huggingface dataset:
//Using vim gui now
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void solve(int case_number) {
	int k, a, b;
	cin >> k >> a >> b;
	while(a <= b) {
		if(a%k == 0) {
			cout << "OK" << endl;
			return;
		}
		a++;
	}
	cout << "NG" << endl;

}

int main() {
	int cases = 1;
//	cin >> cases;
	for(int i = 0; i < cases; i++)
		solve(i + 1);
	return 0;
}


Measured memory_bytes: 3052
def f(l):
  prev = l[0][0]
  memo = []
  for i in range(len(l)):
    next = l[i]
    if next[0] != prev or next in memo:
      return "No"
    prev = next[-1]
    memo.append(next)
  return "Yes"

N = int(input())
l = [input() for _ in range(N)]
print(f(l))

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

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

    for (int i = 0; i <= x; ++i)
    {
        int j = x - i;
        if (i * 2 + j * 4 == y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int ans[314514],sum[314514];
signed main(){
	int n;
	cin>>n;
	vector<int> a,u;
	map<int,int> mope;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
		u.pb(x);
		mope[x]++;
	}
	sort(u.begin(),u.end());
	u.erase( unique( u.begin(),u.end() ), u.end() );
	vector<int> cnt;
	cnt.pb(0);
	for(int i=0;i<u.size();i++){
		cnt.pb( mope[ u[i] ] );
	}
	sort(cnt.begin(),cnt.end());
	for(int i=1;i<=cnt.size();i++){
		sum[i] = sum[i-1] + cnt[i];
	}
	int cur = 0;
	for(int i=n;i>=1;i--){
		if( i >= cnt.size() ) ans[i] = 0;
		else{
			int start = cnt.size() - i;
			int ng = cnt.size(), ok = start; // start ~ ok can be same
			while( ng - ok > 1 ){
				int mid = ( ok + ng ) / 2;
				int num = mid - start + 1;
				int tmp = cnt[mid] * num - ( sum[mid] - sum[start-1] );
				if( tmp > cur ){
					ng = mid;
				}
				else{
					ok = mid;
				}
			}
			int amari = cur - cnt[ok] * (ok-start+1) + ( sum[ok] - sum[start-1] );
			ans[i] = cnt[ok] + amari/(ok-start+1);
			cur += cnt[start];
		}
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 33112
from itertools import permutations
from math import sqrt, factorial


def main():
    n = int(input())
    xy = []
    for _ in range(n):
        xy.append(list(map(int, input().split())))
    town = [i for i in range(n)]
    dist_sum = 0
    for p in permutations(town):
        for i in range(n - 1):
            dist_sum += sqrt((xy[p[i]][0] - xy[p[i + 1]][0]) ** 2 + (xy[p[i]][1] - xy[p[i + 1]][1]) ** 2)
    print(dist_sum / factorial(n))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
    int a, b, c, d, s;
    cin >> s;
    d=s%10;
    s=s/10;
    c=s%10;
    s=s/10;
    b=s%10;
    s=s/10;
    a=s;
    
    if(a+b+c+d==7) cout <<a<<"+"<<b<<"+"<<c<<"+"<<d<<"="<<7 << endl;
    else if(a+b+c-d==7) cout <<a<<"+"<<b<<"+"<<c<<"-"<<d<<"="<<7<<endl;
    else if(a+b-c+d==7) cout <<a<<"+"<<b<<"-"<<c<<"+"<<d<<"="<<7 <<endl;
    else if(a-b+c+d==7) cout <<a<<"-"<<b<<"+"<<c<<"+"<<d<<"="<<7 <<endl;
    else if(a+b-c-d==7) cout <<a<<"+"<<b<<"-"<<c<<"-"<<d<<"="<<7 <<endl;
    else if(a-b+c-d==7) cout <<a<<"-"<<b<<"+"<<c<<"-"<<d<<"="<<7 <<endl;
    else if(a-b-c+d==7) cout <<a<<"-"<<b<<"-"<<c<<"+"<<d<<"="<<7 <<endl;
    else if(a-b-c-d==7) cout <<a<<"-"<<b<<"-"<<c<<"-"<<d<<"="<<7 <<endl;
    return 0;
}


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

int main(void)
{
	int sx, sy, tx, ty, i;
	scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
	for (i = 0; i < abs(sx - tx); ++i) printf("R");
	for (i = 0; i < abs(sy - ty); ++i) printf("U");
	for (i = 0; i < abs(sx - tx); ++i) printf("L");
	for (i = 0; i < abs(sy - ty); ++i) printf("D");
	printf("D");
	for (i = 0; i < abs(sx - tx) + 1; ++i) printf("R");
	for (i = 0; i < abs(sy - ty) + 1; ++i) printf("U");
	printf("LU");
	for (i = 0; i < abs(sx - tx) + 1; ++i) printf("L");
	for (i = 0; i < abs(sy - ty) + 1; ++i) printf("D");
	printf("R");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
const double PI = acos(-1.0);
const long mod = 1000000007;
const long INF = 1e9 + 1;

int main() { 
  string s;
  cin >> s;
  int n = s.size();
  if(n == 1) {
    cout << s << endl;
    return 0;
  }
  long sum = 0;

  for(int bit = 0; bit < (1 << n-1); bit++) {
    int cnt = 0;
    for(int i = 0; i < n-1; i++) {
      sum += (s[n-1-i] - '0') * pow(10,cnt);
      if(bit & (1 << i)) {
        cnt = 0;
        if(i == n-2) sum += (s[0] - '0');
      }
      else {
        cnt++;
        if(i == n-2) sum += (s[0] - '0') * pow(10,cnt);
      }
    }
  }
  
  cout << sum << endl;
}


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

using namespace std;

const long long MOD = 1e9+7;
int main() {
    ios_base::sync_with_stdio(false);
    cout.precision(12);
    cout << fixed;
    cin.tie(0);

    int x;
    cin >> x;
    int z = (x - 400) / 200;
    z = 8 - z;
    cout << z << endl;

    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int a = 0;

        int cntL = 0;
        int cntR = 0;

        for (int i = 0; i < m; i++) {
            a = sc.nextInt();
            if (a < x)
                cntL++;
            else if (a < n)
                cntR++;
        }

        System.out.print(Math.min(cntL, cntR));
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll x,y;
  cin >> x >> y;
  if(x%y==0){
    cout << -1 << endl;
  }
  else
    cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

    int N, ans = 0;
    cin >> N;
    for(int i=1;i*i<=N;i++){
        if(N % i == 0){
            int div = N/i;
            if(div - i >= 2){
                ans += div-1;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

//2つの要素をまとめてソート、前の変数が優先。flag=0で小さい順、1で大きい順
void mysort2(vi &a,vi &b,ll flag){
  vector<pair<ll, ll>> p(a.size());
  REP(i,n){
    p[i].first=a[i];
    p[i].second=b[i];
  }
  sort(p.begin(),p.end());
  if (flag==1){
    reverse(p.begin(),p.end());
  }
  REP(i,n){
    a[i]=p[i].first;
    b[i]=p[i].second;
  }
  return;
}




int main(){
  ll ans=0;
  cin >> n ;
  vi a(n),b(n),c(n),d(n),e(n);
  REP(i,n){
    cin>>a[i];
    b[i]=i;
  }
  mysort2(a,b,1);
  ll r=n-1,l=0;

  REP(i,n){
    c[i]=a[i];
    d[i]=b[i];
  }


  for(ll i=0;i<n;i++){
    if (abs(r-b[i])>abs(b[i]-l)){
      ans+=abs(r-b[i])*a[i];
      c[r]=a[i];
      d[r]=b[i];
      r--;
    }else{
      ans+=abs(b[i]-l)*a[i];
      c[l]=a[i];
      d[l]=b[i];
      l++;
    }
  }




/*
  REP(i,n){
    cout<<c[i]<<"("<<d[i]<<")";
  }
  cout<<endl;
*/

  for(ll xxx=0;xxx<3;xxx++){


          r=n-1;l=0;
          for(ll i=0;i<n;i++){
            //cout<<c[r]<<" "<<c[l]<<endl;
            if (c[r]>c[l]){
              ll gk=c[r]*( abs(d[r]-l)-abs(d[r]-r) );
              //1こ右にずらす
              for(ll j=l;j<r;j++){
                gk+=c[j]*( abs(d[j]-(j+1))-abs(d[j]-j) );
              }
              if (gk>0){
                gk=c[r];
                ll dgk=d[r];
                //1こ右にずらす
                for(ll j=r-1;j>=l;j--){
                  c[j+1]=c[j];
                  d[j+1]=d[j];
                }
                c[l]=gk;
                d[l]=dgk;
                l++;
              }else{
                r--;
              }
              
            }else{

              ll gk=c[l]*( abs(d[l]-r)-abs(d[l]-l) );
              //1こ左にずらす
              for(ll j=l+1;j<=r;j++){
                gk+=c[j]*( abs(d[j]-(j-1))-abs(d[j]-j) );
              }
              if (gk>0){
                gk=c[l];
                ll dgk=d[l];
                //1こ左にずらす
                for(ll j=l;j<r;j++){
                  c[j]=c[j+1];
                  d[j]=d[j+1];
                }
                c[r]=gk;
                d[r]=dgk;
                r--;
              }else{
                l++;
              }
            }

          }



  }









/*
  REP(i,n){
    cout<<c[i]<<"("<<d[i]<<")";
  }
*/

  ans=0;
  REP(i,n){
    ans+=c[i]*abs(d[i]-i);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;

long long int search(long long int n, long long int x){
    if(n == 0 && x == 1){
        return 1;
    }else if(x == 1){
        return 0;
    }else if(x <= pow(2, n+1) - 2){
        return search(n-1, x-1);
    }else if(x == pow(2, n+1) - 1){
        return pow(2, n);
    }else if(x <= pow(2, n+2)-4){
        return pow(2, n) + search(n-1, x-pow(2, n+1)+1);
    }else{
        return pow(2, n+1) - 1;
    }
}

int main(){
    long long int n, x;
    cin >> n >> x;
    cout << search(n, x) << endl;
}

Measured memory_bytes: 512
using System;


class Sample
{
	public static void Main()
	{
		for (int i = 1; i < 10; i++)
		{
			for (int j = 1; j < 10; j++)
			{
				Console.WriteLine(i + "x" + j + "=" + (i * j));
			}
		}
	}
}

Measured memory_bytes: 9052
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 ll n; 
 vector<bool> seen ;
 vector<ll> ans ;
 ll cnt ;
void dfs( const Graph & g ,ll st ){
  seen[st]=1 ; ans[st]= cnt ; 
  cnt++ ;
  for( auto next : g[st]){
    if(seen[next]) continue ;
      
      dfs(g,next) ;
  }

}

 int main(){
  cin>>n ;
  Graph G(n) ;
  rep(i,n-1){
    ll a, b ; cin>>a>>b ;
    a-- ; b--; 
    G[a].pb(b) ;
    G[b].pb(a) ;
  }
  vector<ll> X(n) ;
  rep(i,n) cin>>X[i] ;
  sort(X.rbegin(),X.rend()) ;
  ll bns=0 ;
  rep(i,n-1)  bns+= X[i+1] ;
  seen.assign(n,false) ;
  ans.assign(n,0) ;
  cnt= 0 ;
  dfs(G,0) ;
  cout<<bns<<endl ;
  rep(i,n){
    if(i==n-1) cout<< X[ans[i]]<<endl ;
    else cout<<X[ans[i]]<<" " ;
  }
  
  return 0 ;
}




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

using namespace std;

#define PI 3.1415926535897932

//typedef long long ll;


int lcm(int a,int b) { return a*b/__gcd(a,b); }
//ll lcm(ll a,ll b) { return a*b/__gcd(a,b); }

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/


int main(){
    int mod=1000000007;
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%s\n",(a<9 && b<9)?"Yay!":":(");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b,c;
  int cnt=0;
  
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);

  for(;a<=b;a++){
    if(c%a==0){
      cnt++;
    }
  }

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

  return 0;
}

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

int main() {
int n;
int ans,ansmin=100000;
int yes=0,no=0;
  cin>> n;
  vector <int> s(n);
  for(int i=0; i<n; i++){
  cin >> s.at(i);
  }
  for(int i=1; i<=n; i++){
    yes=0;
    no=0;
    for(int t=0; t<i; t++){
      yes+=s.at(t);
    }for(int t=0; t<n-i; t++){
      no+=s.at(n-(t+1));
    }
    if(yes<=no){
      ans=(no-yes);
    }if(yes>no){
      ans=(yes-no);
    }
    ansmin=min(ansmin,ans);
  }
  cout << ansmin << endl;
}


Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N, M, X = map(int, input().split())
    C = []
    A = []
    for _ in range(N):
        B = list(map(int, input().split()))
        C.append(B[0])
        A.append(B[1:])
    answer = float("inf")
    for i in range(2 ** N):
        ans = [0] * M
        cnt = 0
        for j in range(N):
            if (i >> j) & 1:
                for m in range(M):
                    ans[m] += A[j][m]
                cnt += C[j]
        c = 0
        for m in range(M):
            if ans[m] >= X:
                c += 1
        if c == M:
            if cnt < answer:
                answer = cnt
    if answer == float("inf"):
        print(-1)
    else:
        print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9240
#include<iostream>
#include<cstdio>
using std::max;
inline void umx(int &a,int b){a=max(a,b);}
const int MAXN=105;

int n;
int mp[2][MAXN];

int main()
{
	int i,j;scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&mp[0][i]);
	for(i=1;i<=n;i++) scanf("%d",&mp[1][i]);
	int ans=0;
	for(i=1;i<=n;i++)
	{
		int res=0;
		for(j=1;j<=i;j++) res+=mp[0][j];
		for(j=i;j<=n;j++) res+=mp[1][j];
		umx(ans,res);
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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


int main() {

	int n;
	string sn;
	getline(cin, sn);
	n = atoi(sn.c_str());
	REP(i, n){
		string s;
		getline(cin, s);
		while (s.find("Hoshino") != string::npos){
			s[s.find("Hoshino") + 6] = 'a';
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;

typedef long long ll;

int n, d;
int v[102][102];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> d;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= d; ++j)
            cin >> v[i][j];
    int ans = 0;
    for(int i = 1; i <= n; ++i)
        for(int j = i+1; j <= n; ++j)
        {
            int dd = 0;
            for(int x = 1; x <= d; ++x)
                dd += (v[i][x] - v[j][x]) * (v[i][x] - v[j][x]);
            int rad = sqrt(dd);
            if(rad * rad == dd)
                ++ans;
        }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);

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

    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, k) {
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
using System;
class aoj
{
    static void Main()
    {
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            int[] b = new int[10];
            int[] c = new int[9];
            for (int i = 0; i < 10; i++)
            {
                string f = a[i].ToString();
                b[i] = int.Parse(f);
            }
            for (int i = 9; i > 0; i--)
            {
                for (int j = 0; j < i; j++)
                {
                    if (i % 2 == 0)
                    {
                        string d = (c[j] + c[j + 1]).ToString();
                        string f = d[d.Length-1].ToString();
                        b[j] = int.Parse(f);
                    }
                    else
                    {
                        string d = (b[j] + b[j + 1]).ToString();
                        string f = d[d.Length-1].ToString();
                        c[j] = int.Parse(f);
                    }
                }
            }
            Console.WriteLine(c[0]);
        }
    }
}

Measured memory_bytes: 9052
n, m = map(int, input().split())
li=[-1]*n

def find(x):
    if li[x] < 0:
        return x
    else:
        li[x] = find(li[x])
        return li[x]


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    else:
        li[x] += li[y]
        li[y] = x


def same(x, y):
    return find(x) == find(y)


for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    unite(a, b)

ans=0
for i in range(n):
    ans = max(ans,-li[i])

print(ans)










Measured memory_bytes: 81040
S = list(input())
T = list(input())

s_reversed = list(reversed(S))
T_reversed = list(reversed(T))
F = 0

for i in range(len(S)-len(T)+1):
    s = s_reversed[i:i+len(T)]
    flag = 0
    for j in range(len(T)):
        if s[j] == T_reversed[j] or s[j] == '?':
            continue
        else:
            flag += 1
            break
    if flag ==0:
        F += 1
        for j in range(len(T)):
            s_reversed[i+j] = T_reversed[j]
        break

if F ==0:
    print('UNRESTORABLE')
else:
    R = ''.join(list(reversed(s_reversed)))
    print(R.replace('?','a'))





Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
static class Program
{
	static IEnumerable<int[]> ReadInts(this TextReader reader, int count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	}
 
	static IEnumerable<long[]> ReadLongs(this TextReader reader, long count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
	}
	
	public static void Main(string[] args)
	{
		var n = int.Parse(Console.In.ReadLine());
		var a = Console.In.ReadInts(n).First();
		var buf = new int[n+1];
		var p = 0ul;
		for (var i = 0; i < n; ++i)
			p = p + (ulong)buf[a[i]]++;
		for (var i = 0; i < n; ++i)
			Console.WriteLine(p - (ulong)buf[a[i]] + 1);
	}
}

Measured memory_bytes: 33756
import sys
sys.setrecursionlimit(10 ** 6)
def dfs(v):
    gone = [False for i in range(n+1)]
    gone[0] = True
    stack = [v]
    gone[v] = True
    while stack:
        v = stack.pop()
        for w in graph[v]:
            if gone[w] == False:
                stack.append(w)
            gone[w] = True
    return (False in gone)

n,m = map(int,input().split())
graph = [[] for _ in range(n+1)]
lis = [list(map(int,input().split())) for i in range(m)]
ans = 0
for i in range(m):
    graph[lis[i][0]].append(lis[i][1])
    graph[lis[i][1]].append(lis[i][0])

for i in range(m):
    graph[lis[i][0]].remove(lis[i][1])
    graph[lis[i][1]].remove(lis[i][0])
    if dfs(1):ans += 1
    graph[lis[i][0]].append(lis[i][1])
    graph[lis[i][1]].append(lis[i][0])

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCoder
{
  class Program
  {
    static void Main(string[] args)
    {
      int N = int.Parse(Console.ReadLine());
      string[] ss = Console.ReadLine().Split(' ');
      List<int> ns = new List<int>();
      for(int i = 0; i < ss.Length; i++)
        ns.Add(int.Parse(ss[i]));
      ns.Sort();
      int amount = 0;
      int a = 0, b = 0;
      for(int i = N - 1; i >= 0; i -= 2)
      {
        a += ns[i];
        if(i - 1 >= 0)
          b += ns[i - 1];
      }
      Console.WriteLine(a - b);
      Console.ReadLine();
    }

  }
}

Measured memory_bytes: 27784
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
from bisect import bisect_left,bisect_right

def main():  
    N,P = map(int,input().split())
    A = list(map(int,input().split()))
    cnt1 = sum(a%2 == 1 for a in A)
    cnt0 = N - cnt1
    factorial = [1,1]
    for i in range(2,N + 1):
        factorial.append(factorial[-1]*i)
    
    nck = lambda n,k:factorial[n]//factorial[n - k]//factorial[k]

    ans = 0
    if P == 0:
        for i in range(0,cnt1 + 1,2):
            ans += nck(cnt1,i)
        ans *= pow(2,cnt0)
    else:
        for i in range(1,cnt1 + 1,2):
            ans += nck(cnt1,i)
        ans *= pow(2,cnt0)
    print(ans)
if __name__ == '__main__':
    main()

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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int w, h, n; cin >> w >> h >> n;
  
  int mat[h][w];
  rep(i, h) rep(j, w) mat[i][j] = 0;
  
  rep(i, n) {
    int x, y, a; cin >> x >> y >> a;

    if (a == 1) rep(k, h) rep(j, x) mat[k][j] = 1;
    else if (a == 2) rep(k, h) rep2(j, x, w-1) mat[k][j] = 1;
    else if (a == 3) rep(k, y) rep(j, w) mat[k][j] = 1;
    else rep2(k, y, h-1) rep(j, w) mat[k][j] = 1;
  }

  int ans = 0;
  rep(i, h) rep(j, w) ans += mat[i][j];

  cout << h * w - ans << endl;
  
  return (0);
}

Measured memory_bytes: 3652
# coding: utf-8

N = int(input())
row = [0 for i in range(N)]
row2 = [int(x) for x in input().split(" ")]

for i in range(N):
    row[row2[i] - 1] = i + 1

for i, x in enumerate(row):
    if i < N - 1:
        print(x, end=" ")
    else:
        print(x)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
const int SIZE = 200005;

int main(){
    int n, m;
    cin >> n >> m;
    int a[n];
    REP(i, n) cin >> a[i];
    int diff[SIZE] = {};
    int imos[SIZE] = {};
    REP(i, n-1){
        int s = a[i];
        int t = a[i+1];
        if(s<t){
            imos[s+1]++;
            imos[t]--;
        }else{
            imos[s+1]++;
            imos[1]++;
            imos[t]--;
        }
    }
    diff[1] = imos[1];
    for(int i=1;i<m;i++){
        diff[i+1] = diff[i] + imos[i+1];
    }
    REP(i, m)diff[i+1] *= -1;
    REP(i, n-1)diff[a[i+1]] += (a[i+1]-a[i]-1+m)%m;
    /*
    REP(i, m){
        cout << imos[i+1] << " ";
    }
    cout << endl;

    REP(i, m){
        cout << diff[i+1] << " ";
    }
    cout << endl;
    */
    ll res = 0;
    REP(i, n-1){
        res += min((a[i+1]-1+m)%m+1, (a[i+1]-a[i]+m)%m);
    }
    ll mi = res;
    REP(i, m-1){
        res += diff[i+1];
        mi = min(res, mi);
    }
    cout << mi << endl;
    return 0;
}

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

#define s first
#define e second

using point = pair<int, int>;
vector< point > p;
int r, c, n;
stack<int> stk;

bool bound(int y, int x){
    return (y == 0 || y == r) || (x == 0 || x == c);
}

int ctox(int y, int x){
    if(y == 0) return x;
    if(x == c) return c + y;
    if(y == r) return c + r + (c - x);
    if(x == 0) return c + r + c + (r - y);
}

int main(){
    scanf("%d%d%d",&r,&c,&n);
    for(int i=0;i<n;i++){
        int aa, bb, cc, dd;
        scanf("%d%d%d%d",&aa,&bb,&cc,&dd);
        if(bound(aa, bb) && bound(cc, dd)){
            int ss = ctox(aa, bb);
            int ee = ctox(cc, dd);
            p.push_back({min(ss, ee), max(ss, ee)});
        }
    }
    sort(p.begin(), p.end(), [&](const point &p1, const point &p2) -> bool{
         if(p1.s == p2.s) return p1.e > p2.e;
         else return p1.s < p2.s;
    });
    for(auto &pp: p){
        while(!stk.empty() && stk.top() <= pp.s){
            stk.pop();
        }
        if(!stk.empty() && pp.e > stk.top()){
            printf("NO\n");
            return 0;
        }
        stk.push(pp.e);
    }
    printf("YES\n");
    return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> num(9, 0);
    for(int i = 0; i < n; ++i){
        ll ai;
        cin >> ai;
        num.at(min(ai / 400, 8LL))++;
    }
    ll ans = 0;
    for(int i = 0; i < 8; ++i){
        ans += (num.at(i) > 0);
    }
    ll ansmin = max(1LL, ans);
    ll ansmax = ans + num.at(8);
    cout << ansmin << ' ' << ansmax << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 537427207;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    vector<queue<char>> qs(3);
    string a,b,c;cin>>a>>b>>c;
    rep(i,a.size())qs[0].push(a[i]);
    rep(i,b.size())qs[1].push(b[i]);
    rep(i,c.size())qs[2].push(c[i]);
    int next = 0;
    rep(i,a.size()+b.size()+c.size()){
        if(qs[next].empty()){cout<<(char)(next+'A')<<endl; return 0;}
        int bf = next;
        next = qs[next].front()-'a';
        qs[bf].pop();
    }
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

string s;
int K;

int main(){
  cin >> s >> K;
  for(auto&e : s) {
    int need = 'a' - e;
    if(need < 0) need += 26;
    if(K >= need) e = 'a' , K -= need;
  }
  int t = (s.back() - 'a' + K % 26) % 26;
  s[sz(s)-1] = 'a' + t;
  cout << s << endl;
  return 0;
}


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

int main(void) {
  int K, S;
  cin >> K >> S;

  int counter = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
      int Z = S - i - j;
      if (Z >= 0 && Z <= K) {
        counter++;
      }
    }
  }

  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
sum = 0
m = 10**9+7

for i in range(n):
  sum = sum+a[i]

#sum = sum%m
#sum = sum*sum
ans = 0
for i in range(n):
  ans = ans + sum*a[i]
  ans = ans - a[i]*a[i]
ans = ans//2%m

print(ans)

Measured memory_bytes: 94144
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

long long inv(int a, int p) { return a==1 ? 1 : (1-p*inv(p%a,a))/a+p; }
static const int MODVAL = 1000000007;
struct mint {
  int val;
  mint():val(0){}
  mint(int x):val(x%MODVAL) {}
  mint(size_t x):val(x%MODVAL) {}
  mint(long long x):val(x%MODVAL) {}
  mint& operator+=(mint y) { val+=y.val; if(val>=MODVAL) val-=MODVAL; return *this; }
  mint& operator-=(mint y) { val-=y.val; if(val<0) val+= MODVAL; return *this; }
  mint& operator*=(mint y) { val=(val*(long long)y.val)%MODVAL; return *this; }
  mint& operator/=(mint y) { val=(val*inv(y.val,MODVAL))%MODVAL; return *this; }
};
inline mint operator+(mint x, mint y) { return x+=y; }
inline mint operator-(mint x, mint y) { return x-=y; }
inline mint operator*(mint x, mint y) { return x*=y; }
inline mint operator/(mint x, mint y) { return x/=y; }
mint POW(mint x, long long n) { mint r(1); for(;n;x*=x,n>>=1) if(n&1) r*=x; return r; }
mint FAC(int n) { static vector<mint> FAC_(1,1);
  while(int(FAC_.size())<=n) FAC_.push_back(FAC_.back()*FAC_.size()); return FAC_[n]; }
inline mint CMB(int n, int k) { return k<0||n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
inline ostream& operator<<(ostream& os, mint a) { return os << a.val; }

const char *BASE = "ACGT";

bool isOK(char c1, char c2, char c3, char c4) {
  if(c2 == 'A' && c3 == 'G' && c4 == 'C') return false;
  if(c2 == 'G' && c3 == 'A' && c4 == 'C') return false;
  if(c2 == 'A' && c3 == 'C' && c4 == 'G') return false;
  if(c1 == 'A' && c3 == 'G' && c4 == 'C') return false;
  if(c1 == 'A' && c2 == 'G' && c4 == 'C') return false;
  return true;
}

int n;
bool visited[5][5][5][110];
mint memo[5][5][5][110];
mint solve(int ppp, int pp, int p, int pos) {
  mint &res = memo[ppp][pp][p][pos];
  if(!visited[ppp][pp][p][pos]) {
    visited[ppp][pp][p][pos] = true;
    if(pos == n) {
      res = 1;
    } else {
      res = 0;
      REP(c, 4) {
        if(isOK(BASE[ppp], BASE[pp], BASE[p], BASE[c])) {
          res += solve(pp, p, c, pos+1);
        }
      }
    }
  }
  return res;
}

int main(void) {
  cin >> n;
  memset(visited, 0, sizeof visited);
  mint res = solve(3, 3, 3, 0);
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e10;
int main()
{
    int a, b;
    cin >> a >> b;
    set<int> s;
    s.insert(1);
    s.insert(2);
    s.insert(3);
    s.erase(a);
    s.erase(b);
    cout << *s.begin() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define tezina first
#define vrednost second

using namespace std;

int n,w;
pair<int,ll> predmeti[110];
ll dp[100010][110];

int main()
{
	ios::sync_with_stdio(false);	
	cin.tie(0);
	
	cin>>n>>w;
	int t,v;
	for(int i=1;i<=n;i++)
	{
		cin>>t>>v;
		predmeti[i]=make_pair(t,v);
	}
	
	sort(predmeti,predmeti+n);
	for(int j=1;j<=n;j++)
		for(int i=1;i<=w;i++)
			if(predmeti[j].tezina<=i)
				dp[i][j]=max(dp[i][j-1],dp[i-predmeti[j].tezina][j-1]+predmeti[j].vrednost);
			else
				dp[i][j]=dp[i][j-1];
	
	cout<<dp[w][n];
	
	
	return 0;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    cout << "ABC";
    cout << N << endl;
}


Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	// Code for B - Christmas Eve Eve
	var N int
	fmt.Scanf("%d", &N)

	var P, sum, max int
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &P)
		sum += P
		if max < P {
			max = P
		}
	}
	fmt.Println(sum - max/2)
}


Measured memory_bytes: 1836
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct edge
{
	long long to; long long len;
	bool operator<(const edge& rhs) const {
		return len > rhs.len;
	}
};

ll const MAX = BIT(22);
ll dp[MAX] = {};
ll dp2[MAX] = {};
ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	return (x + y) % MOD;
}
ll mod_m(ll x, ll y) {
	return x * y%MOD;
}


ll bitcnt(ll x) {
	ll ans = 0;
	while (x > 0) {
		ans += (x & 1);
		x >>= 1;
	}
	return ans;
}

ll a[20][20];
	ll n;

ll f(ll bit) {
	ll v = (-bit) & bit;
	ll cnt = dp2[bit - v];
	ll j;
	REP(i, 0, n - 1) {
		if (v < BIT(i) && (BIT(i)&bit)>0) {
			cnt += a[i][j];
		}
		else if (v == BIT(i)) {
			j = i;
		}
	}
	dp2[bit] = cnt;
	return cnt;
}

int main() {
	cin >> n;
	REP(i, 0, n - 1) {
		REP(j, 0, n - 1) {
			cin >> a[i][j];		
		}
	}
	ll t = BIT(n) - 1;

	REP(bit, 1, t) {
		ll r = bitcnt(bit);
		if (r == 1) {
			continue;
		}
		/*
		REP(i, 0, n - 1) {
			REP(j, i + 1, n - 1) {
				if (((bit&BIT(i))>0) && ((bit&BIT(j))>0)) {
					//cnt = mod_p(cnt, a[i][j]);
					//cnt = (cnt + a[i][j]) % MOD;
					cnt += a[i][j];
				}
			}
		}
		*/
		ll cnt = max(ll(0), f(bit));
		/*
		REP(bit2, 1, s - 1) {
			ll subbit = 0;
			ll v = 0;
			REP(j, 0, n - 1) {
				if (bit & BIT(j)) {
					if (BIT(v) & bit2) {
						subbit += BIT(j);
					}
					v++;
				}
			}
			ll prebit = bit - subbit;
			cnt = max(cnt, dp[subbit] + dp[prebit]);
		}
		*/
		for (ll bit2 = (bit - 1)&bit; bit2 > 0; bit2 = (bit2 - 1)&bit) {
			ll subbit = bit - bit2;
			cnt = max(cnt, dp[bit2] + dp[subbit]);
		}
		dp[bit] = cnt;
	}
	cout << dp[t] << endl;

}

Measured memory_bytes: 2816
import sys,collections as cl,bisect as bs,math
from decimal import *
getcontext().prec = 50
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

abc = [chr(97+i) for i in range(10)]

po = cl.deque([["",-1],["",0]])
co = 0
fl = False
while True:
    kkk = po.popleft()
    if kkk[1] == -1:
        if len(po) == 0:
            exit()
        co += 1
        if co == n:
            fl = True
        po.append(["",-1])
    else:
        if fl:
            for i in range(kkk[1]+1):
                print(kkk[0]+abc[i])
        else:
            for i in range(kkk[1]+1):
                if i == kkk[1]:
                    po.append([kkk[0]+abc[i],kkk[1]+1])
                else:
                    po.append([kkk[0]+abc[i],kkk[1]])





Measured memory_bytes: 72020
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;

#define MOD 1000000007

typedef long long ll;

template<class T>inline bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
const ll INF=1LL<60;

int N;
ll W,weight[110],value[110];
ll dp[110][100100];

int main(){
	cin>>N>>W;
	for(int i=0;i<N;i++)cin>>weight[i]>>value[i];
	for(int i=0;i<N;i++){
		for(int sum_w=0;sum_w<=W;sum_w++){
			if(sum_w-weight[i]>=0){
				chmax(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
			}
			chmax(dp[i+1][sum_w],dp[i][sum_w]);
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}


Measured memory_bytes: 79360
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;

std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int main(){
    string s;
//    stringstream ss;
    int y,m,d;
    cin >> s;
    vector<string> vec;
    vec=split(s,'/');
    bool flag=true;
    for(int i=0;i<3;i++){
        int temp=atoi(vec[i].c_str());
        if(i==0)y=temp;
        if(i==1)m=temp;
        if(i==2)d=temp;
    }
    if(y==2019&&m>=5)cout << "TBD" <<endl;
    else cout << "Heisei" <<endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long
#define INF 10e9

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

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

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

int N;
int b[110];

int main () {
  cin >> N;
  Rep(i, N-1) {
    cin >> b[i];
  }

  int ans = 0;
  ans += b[0];
  ans += b[N-2];

  for (int k=0;k<N-2;++k) {
    ans += min(b[k], b[k+1]);
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
i,j,r,S[12],C[12];main(n){for(;~scanf("%d",&n);){for(r=i=0;i<n;)scanf("%d",C+i++);for(;!r++|memcmp(S,C,48);i=n)for(memcpy(S,C,48);i--;)for(C[i]=j=n;j--;)C[i]-=S[i]!=S[j];for(n&&printf("%d\n",r-2);++j<n;)printf("%d%c",S[j],j-n+1?32:10);}}

Measured memory_bytes: 0
#include<iostream>
#include<map>

using namespace std;

map<int,int> mp;

int main(void)

{
    long long int n,i,a;
    cin>>n;
    for(i = 0; i < n; i++){
        cin>>a;
        mp[a]++;
    }
    //cout<<mp.size();
    if(mp.size() == n){
        cout<<"YES\n";
    }
    else{
        cout<<"NO\n";
    }
    return 0;
}

Measured memory_bytes: 9600
import sys

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


M = 10 ** 9 + 7


def main():
    n = read_int()
    a = [read_str(), read_str()]
    res = 1
    last_vertical = None
    i = 0
    while i < n:

        vertical = a[0][i] == a[1][i]
        if i == 0:
            if vertical:
                res = 3
            else:
                res = 6
        else:
            if vertical:
                if last_vertical:
                    res *= 2
            else:
                if last_vertical:
                    res *= 2
                else:
                    res *= 3
        last_vertical = vertical
        if vertical:
            i += 1
        else:
            i += 2
        res %= M
    print(res)


main()


Measured memory_bytes: 3064
#include <stdio.h>

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    int h, w;

    scanf ( "%d%d", &h, &w );
    if ( h == 0 && w == 0 ) break ;

    for ( i = 0; i < h; ++i )
    {
      for ( j = 0; j < w; ++j )
      {
        if ( i == 0 || i == h - 1
          || j == 0 || j == w - 1 )
        {
          putchar ( '#' );
        }
        else
        {
          putchar ( '.' );
        }
      }
      puts ( "" );
    }
    puts ( "" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    int N, M; cin >> N >> M;
    vector<vector<int>> to(N);
    rep(i, M) {
        int s, t; cin >> s >> t; --s; --t;
        to[s].push_back(t);
    }

    vector<double> dp(N, 0.0);
    reprev(i, N-1) {
        double now = 0.0;
        for(auto j: to[i]) now += dp[j];
        now /= to[i].size();
        now += 1;
        dp[i] = now;
    }

    double ans = dp[0];

    rep(ni, N-1) {
        if(to[ni].size() == 1) continue;
        int nj = to[ni][0];
        for(auto j: to[ni]) {
            if(dp[j] > dp[nj]) nj = j;
        }

        auto now = [&](){
            vector<double> dp2(N, 0.0);
            reprev(i, N-1) {
                double now = 0.0;
                for(auto j: to[i]) {
                    if(i == ni && j == nj) continue;
                    now += dp2[j];
                }
                int deg = to[i].size();
                if(i == ni) --deg;
                now /= deg;
                now += 1;
                dp2[i] = now;
            }
            return dp2[0];
        }();

        chmin(ans, now);
    }

    cout << fixed << setprecision(10) << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long dp[200][20];
int main() {
    long long H, W, K;
    cin >> H >> W >> K;

    vector<long long> v;
    for (int mask = 0; mask < 1 << (W - 1); mask++) {
        bool check = true;
        for (int i = 0; i < (W - 1) - 1; i++) {
            if (mask & 1 << i && mask & 1 << (i + 1)) {
                check = false;
                break;
            }
        }
        if (check) v.push_back(mask);
    }

    dp[0][0] = 1;
    for (int i = 1; i <= H; i++) {
        for (int j = 0; j < v.size(); j++) {
            int mask = v[j];
            for (int k = 0; k < W; k++) {
                if (mask & 1 << k) {
                    dp[i][k] = (dp[i][k] + dp[i - 1][k + 1]) % M;
                } else if (mask & 1 << k - 1) {
                    dp[i][k] = (dp[i][k] + dp[i - 1][k - 1]) % M;
                } else {
                    dp[i][k] = (dp[i][k] + dp[i - 1][k]) % M;
                }
            }
        }
    }

    cout << dp[H][K - 1] << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def main():
    N, T = map(int, readline().rstrip().split())
    t = list(map(int, readline().rstrip().split()))
    d = [t[i] - t[i-1] for i in range(1, N)]
    ans = sum([min(T, e) for e in d])
    print(ans + T)


if __name__ == '__main__':
    main()

Measured memory_bytes: 25196
<?php
$A=[];
for($i=97;$i<123;$i++) $A[$i]=0;

while(1){
	$S=trim(fgets(STDIN));
	if(!$S){break;}

	foreach(str_split($S) as $c){
		$n=ord($c);
	        if(64<$n && $n<91) ++$A[$n+32];
	        elseif(96<$n && $n<123) ++$A[$n];
	}
}

for($i=97;$i<123;$i++) echo chr($i),' : ',$A[$i],PHP_EOL;

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

int main()
{
    int n, i, f=0;
    scanf("%d", &n);
    int a[n];

    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    sort(a, a+n);
    for(i=0; i<n-1; i++){
        if(a[i]==a[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1024
//IN THE NAME OF GOD;
//Test By Dev-C++5.11
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false
using namespace std;

ll bmm(ll a, ll b) {
	if (b == 0) return a;
	else return bmm(b, a%b);
}
ll kmm(ll a, ll b) {
	return(a*b) / bmm(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 2e5+5;

ll a,b;

int main() {
	isc;
	cin >> a >> b;
	if(a>9 || b>9)
		cout << -1;
	else
		cout << a*b;
	
	return 0;
}


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

int main() {
    int N;
    bool check = true;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        if (A % 2 == 0 && A % 3 != 0 && A % 5 != 0) {
            check = false;
            break;
        }
    }
    if (check) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back

using namespace std;
 
int main()
{
    
    ll n,m,k; cin>>n>>m>>k;
    vector<ll> a;
    vector<ll> b;
    for(int i = 0;i < n;i++){ll num; cin>>num; a.pb(num);}
    for(int i = 0;i < m;i++){ll num; cin>>num; b.pb(num);}
    
    ll t = 0,cnt = 0;
    stack<ll> s;
    ll i,j = 0;
    
    for(i = 0;(i < a.size()) && (t+a[i] <= k);i++){
        s.push(a[i]);
        t = t + a[i];
        cnt++;
    }
    
    while(j < b.size() && i >= 0){
        t = t + b[j];
        j++;

        while(t > k && s.empty() == false){
            i--;
            t = t - s.top();
            s.pop();
        }
        if(t <= k && i+j > cnt)
            cnt = i+j;
    }
    
    cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 8000