akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    ll ans = LINF;
    REP(k,2){
        for(ll h=1;h<H;h++){
            ll S1 = h * W;
            //横に分ける
            ll h2 = H - h;
            ll S2 = (h2/2) * W;
            ll S3 = (h2 - (h2/2)) * W;
            if(S2 > 0 && S3 > 0) chmin(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
            //縦に分ける
            ll w = W / 2;
            S2 = h2 * w;
            S3 = h2 * (W - w);
            if(S2 > 0 && S3 > 0) chmin(ans,max({S1,S2,S3}) - min({S1,S2,S3}));
        }
        swap(H,W);
    }
    
    cout << ans << endl;
}


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

typedef long long ll; 
#define sz(a) ((int)(a.size()))
#define all(a) a.begin(),a.end()

const int mod=1e9+7; 
int mul(int a, int b){
  return (ll)a*b%mod; 
}
void add_self(int &a, int b){
  a+=b; 
  if(a>= mod) a-=mod; 
}
void mul_self(int &a, int b){
  a=(ll)a*b%mod; 
}
void sub_self(int &a, int b){
  a-=b; 
  if(a<0) a+=mod;
}
int exp(int a, int b){
  int ret=1; 
  while(b){
    if(b%2){
      mul_self(ret,a); 
    }
    mul_self(a,a); 
    b/=2; 
  }
  return ret; 
}
//--------------------------------------------------

vector<int> L,R; 
int dp[65][2][2][2]; 
int rec(int pos, int ly, int gx, int ms){
  if(pos==sz(R)) return 1; 
  if(dp[pos][ly][gx][ms]!=-1) return dp[pos][ly][gx][ms]; 
  int ret=0; 
  for(int y=0;y<=1;y++){
    for(int x=0;x<=1;x++){
      if(y>=x){
        if( ms ){
          if((y<R[pos] || ly) && (x>L[pos] || gx)){
            add_self(ret,rec(pos+1,1,1,ms)); 
          }
          else if((y<R[pos] || ly) && (x==L[pos])){
            add_self(ret,rec(pos+1,1,0,ms)); 
          }
          else if((y==R[pos]) && (x>L[pos] || gx)){
            add_self(ret, rec(pos+1,0,1,ms)); 
          }
          else if(y==R[pos] && x==L[pos]){
            add_self(ret,rec(pos+1,0,0,ms)); 
          }
        }
        else if(x==y){
          if((y<R[pos] || ly) && (x>L[pos] || gx)){
            add_self(ret,rec(pos+1,1,1,y==1)); 
          }
          else if((y<R[pos] || ly) && (x==L[pos])){
            add_self(ret,rec(pos+1,1,0,y==1)); 
          }
          else if((y==R[pos]) && (x>L[pos] || gx)){
            add_self(ret, rec(pos+1,0,1,y==1)); 
          }
          else if(y==R[pos] && x==L[pos]){
            add_self(ret,rec(pos+1,0,0,x==1)); 
          }
        }
      }
    }
  }
  return dp[pos][ly][gx][ms]=ret; 
}

void solve(){
  ll l,r; cin>>l>>r; 
  while(r){
    R.push_back(r%2); 
    r>>=1; 
  }
  while(l){
    L.push_back(l%2); 
    l>>=1; 
  }
  while(sz(L)<sz(R)) L.push_back(0); 
  reverse(all(R)); 
  reverse(all(L)); 
  memset(dp,-1,sizeof(dp)); 
  int ans=rec(0,0,0,0); 
  cout<<ans<<endl; 
}

int main(){
  clock_t beg=clock(); 
  solve(); 
  clock_t end=clock(); 
  fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC); 
}

Measured memory_bytes: 256
def myAnswer(N:int,T:int,A:int,H:list) -> int:
   ans = 0
   s = 10**10
   for n,x in enumerate(H):
      tmp = T - x * 0.006
      if(s >= abs(A - tmp)):
         ans = n+1
         s = abs(A - tmp)
   return ans


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   T,A = map(int,input().split())
   H = list(map(int,input().split()))
   print(myAnswer(N,T,A,H[:]))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
int32_t main()
{
	int n;
	cin >> n;
	int x[n];
	for(int i = 0; i < n; i++) cin >> x[i];
	int ans = 1e17;
	for(int k = 1; k <= 100; k++)
	{
		int calc = 0;
		for(int i = 0; i < n; i++)
		{
			int tt = (x[i]-k)*(x[i]-k);
			calc += tt;
		}
		ans = min(ans,calc);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    const ll INF = LLONG_MAX;
    ll n, s, ans = INF;
    cin >> n >> s;
    if(n == s){
        ans = n + 1;
    }
    if(n > s){
        for(ll i = 1; i*i <= n - s; ++i){
            if((n - s) % i == 0){
                ll j = (n - s) / i;
                ll a = min(i, j);
                ll b = max(i, j) + 1;
                ll c = n - a*b;
                if(c == s - a&&c >= 0 && c < b){
                    smin(ans, b);
                }
            }
        }
    }

    vll dig;
    for(ll b = 2; b*b <= n; ++b){
        dig.clear();
        ll m = n, num = 0, sm = 0;
        while(m > 0){
            dig.push_back(m%b);
            m /= b;
        }
        reverse(all(dig));
        each(d, dig){
            num = num*b + d;
            sm += d;
        }
        if(num == n && sm == s){
            smin(ans, b);
        }
    }

    if(ans != INF)cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
function main(input){
input=input.split("\n");
var X=input[0];
var a=Math.floor(X/500);
var b=Math.floor((X-a*500)/5);
var kotae=a*1000+b*5;

console.log(kotae);


}

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

Measured memory_bytes: 29596
import sys
for line in sys.stdin:
    appendStrs = []
    line = line.strip()
    for i in range(0, len(line) ) :
        if line[i] == "@" :
            appendStrs.append((line[i:i+3], "".join([ line[i+2] for _ in range(0, int(line[i+1]) )]))) ;
    for a in appendStrs :
        line = line.replace(*a, 1)
    print(line)



Measured memory_bytes: 5612
// 問題URL
// https://atcoder.jp/contests/abc155/tasks/abc155_b

import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer a = Integer.parseInt(scanner.next());
        Integer[] b = new Integer[a];

        // 合計値
        List<Integer> total = new ArrayList<Integer>();

        boolean  flag = false;
        for(int i =0; i < a; i++) {
            b[i] = Integer.parseInt(scanner.next());
            if (b[i] % 2 == 0) total.add(b[i]);
        }

        for(int i =0; i < total.size(); i++) {
            if (!(total.get(i) % 3 == 0 || total.get(i) % 5 == 0)) {
                flag = true;
                break;
            }
        }

        if (flag) {
            System.out.println("DENIED");
        } else{
            System.out.println("APPROVED");
        }
    }
}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<cstdio>
#include<ctime>
#include<vector>

#define endl '\n'
#define ll long long
#define ull unsigned ll
#define x first
#define y second

using namespace std;

multiset<long long>a;

int main(){
    int n;
    cin>>n;
    int temp;
    for(int i=0;i<n;i++){
        cin>>temp;
        a.insert(temp);
    }
    multiset<long long>::iterator i=a.end();
    i--;
    long long q=0,w=0;
    int c;
    while(1){
        c=a.count(*i);
        if(c>=2){
            if(q==0)q=*i;
            else {
                w=*i;
                break;
            }
            c=2;
            while(c-- && i!=a.begin())i--;

        }
        if(i==a.begin())break;
        i--;
    }
    cout<<q*w<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define rep2(i,a,n) for (int i = a; i < n; i++)
using namespace std;
string S;
int main() {
    cin >> S;
    int ans = 0;
    int cur = 0;
    for(auto s : S) {
        if(s == 'A' || s == 'C' || s == 'G' || s == 'T') {
            cur++;
            if(cur >= ans) {
                ans = cur;
            }
        } else {
            cur = 0;
        }

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


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

string a,b="CF"; 
int al,bl;

int main(){
    getline(cin,a);
    al=a.length();
    for(int i=0;i<al;i++)
        if(a[i]==b[bl]){ 
            bl++;
            if(bl==2)  
                break;
        }
    if(bl==2) cout<<"Yes"; else cout<<"No";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long ssum[200200];
long long x[200200];
int main()
{
  int N;
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>x[i];
  for(int i=N-1;i>=0;i--)
    ssum[i]=(ssum[i+1]+x[i])%MOD;
  long long ans=0;
  for(int i=0;i<N;i++)
  {
    long long tmp=x[i]*ssum[i+1]%MOD;
    ans=(ans+tmp)%MOD;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6676
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,d;   cin>>n>>m;
  d=n*m;
  
  if(d&2!=1){ 
    cout<<"Odd"<<"\n";
  } else {
    cout<<"Even"<<"\n";
  }
return 0;
}

Measured memory_bytes: 256
#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, K;
    cin >> N >> K;

    string S;
    cin >> S;

    S[K - 1] = 'a' + S[K - 1] - 'A';
    cout << S << endl;
}


Measured memory_bytes: 256
def kruskal():
    '''
    最小全域木のコストを求める
    '''
    cost = 0
    edge.sort()

    for c, u, v in edge:
        if same(u, v):
            continue
        union(u, v)
        cost += c

    return cost


def find(x):
    '''
    xの根を求める
    '''
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def union(x, y):
    '''
    xとyの属する集合を併合する
    '''
    x = find(x)
    y = find(y)
    
    if x == y:
        return False

    if par[x] > par[y]:
        x, y = y, x

    par[x] += par[y]
    par[y] = x
    return True


def same(x, y):
    '''
    xとyが同じ集合に属するかを判定する
    '''
    return find(x) == find(y)


n = int(input())
x, y = [], []
for i in range(n):
    tmp_x, tmp_y = map(int, input().split())
    x.append([tmp_x, i])
    y.append([tmp_y, i])

x.sort()
y.sort()
edge = []
for i in range(n-1):
    edge.append([x[i+1][0]-x[i][0], x[i+1][1], x[i][1]])
    edge.append([y[i+1][0]-y[i][0], y[i+1][1], y[i][1]])

par = [-1] * n
print(kruskal())

Measured memory_bytes: 133296
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    if(a == 0){
        cout << 0;
        return 0;
    }
    ll x = (n) / (a + b);
    ll ca = x * a;
    n -= (x * (a + b));
    if(n == 0){
        cout << ca;
    }else{
        if(n >= a) ca += a;
        else ca += n;
        cout << ca;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll r; cin >> r;
	cout << r * r * 3 << endl;
}


Measured memory_bytes: 3552
#include <stdio.h>
 int main(){
 int minj,i,j,n,tmp;
 int count=0;

 scanf("%d",&n);
 int A[n];

 for(i=0; i<n; i++)
 scanf("%d",&A[i]);

 for(i=0; i<=n-1; i++){
  minj = i;
    for(j=i; j<=n-1; j++){
      if(A[j]<A[minj]){
        minj = j;
      }
    }

if(A[i]>A[minj]){
    tmp = A[i];
    A[i] = A[minj];
    A[minj] = tmp;
    count++;
}

  }

for(i=0; i<n; i++){
if(i!=n-1)printf("%d ",A[i]);
else {
  printf("%d\n",A[i]);
}
}
printf("%d\n",count);

return 0;
 }



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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> happy(n,vector<int>(3));
    rep(i,n) cin>>happy[i][0]>>happy[i][1]>>happy[i][2];
    vector<vector<ll>> dp(n,vector<ll>(3,-INF));
    rep(i,3) dp[0][i] = happy[0][i];
    for(int i=1;i<n;i++){
        rep(j,3){
            rep(k,3){
                if(k==j) continue;
                dp[i][j] = max(dp[i][j],dp[i-1][k]+happy[i][j]);
            }
        }
    }
    ll ans = 0;
    rep(i,3) ans = max(ans,dp[n-1][i]);
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int s,w;
    cin >> s >> w;
    if(s<=w){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec u(n),v(n);
  for(ll i=0;i<n-1;i++) {
    cin >> u[i] >> v[i];
  }
  ll ans=0;
  for(ll i=1;i<=n;i++) {
    ans+=(n-i+1)*i;
  }
  for(ll i=0;i<n-1;i++) {
    ll mi=min(u[i],v[i]);
    ll mx=max(u[i],v[i]);
    ans=ans-(n-mx+1)*(mi);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6348
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = a.group_by { |ai| ai }
ans = 0
b.each do |_k, v|
  c = v.count
  ans += c * (c - 1) / 2
end
n.times do |i|
  d = b[a[i]].count - 1
  puts ans - d
end

Measured memory_bytes: 40324
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


def main():
    X, Y = map(int, input().split())

    if (2 * X - Y) % 3 != 0 or (2 * Y - X) % 3 != 0:
        return print(0)

    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3

    MOD = 10 ** 9 + 7  # 法
    N = a + b  # N!までモジュラ逆数を計算する O(N)
    fact = [1, 1]  # fact[n] = (n! mod MOD)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod MOD)
    inv = [0, 1]

    for i in range(2, N + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    def cmb(n, r, p):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n - r] % p

    n = a + b  # 総数
    r = min(a, b)  # 選ぶ数
    # nCr = n! * r!^-1 * (n-r)!^-1
    print(cmb(n, r, MOD))


if __name__ == '__main__':
    main()


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

set<int> s1,s2;
int n,m,k,nw,ansn,la;
char str1[1000010],str2[1000010],ans[2000010];
set<int>::iterator it1,it2,itt;

int main()
{
	scanf("%d%d%d",&n,&m,&k),s1.clear(),s2.clear();
	for (scanf("%s",str1),nw=0; nw<n; nw++) if (str1[nw]=='1') s1.insert(n-nw-1);
	for (scanf("%s",str2),nw=0; nw<m; nw++) if (str2[nw]=='1') s2.insert(m-nw-1);
	s1.insert(4000000),s2.insert(4000000);
	for (int i=min(n,m); i; i--) if (str1[n-i]=='1'&&str2[m-i]=='1')
	{
		it1=s1.find(i-1),it2=s2.find(i-1),nw=k;
		while (it1!=s1.end()&&it2!=s2.end())
		{
			la=(*it1);
			itt=it1,it1++,s1.erase(itt);
			itt=it2,it2++,s2.erase(itt);
			if ((*it1)<(*it2))
			{
				nw-=((*it1)-la);
				if (nw<0) {s1.insert((*it1)+nw),s2.insert((*it1)+nw); break;}
				s2.insert(*it1);
				for (itt=it1,it1++; it1!=s1.end(); itt=it1,it1++)
					if ((*itt)+1==(*it1)) s1.erase(itt);
					else {it1=s1.insert((*itt)+1).first,s1.erase(itt); break;}
				if (it1==s1.end()) it1=s1.insert((*itt)+1).first,s1.erase(itt);
				it2=s2.find(*it1);
			} else
			{
				nw-=((*it2)-la);
				if (nw<0) {s1.insert((*it2)+nw),s2.insert((*it2)+nw); break;}
				s1.insert(*it2);
				for (itt=it2,it2++; it2!=s2.end(); itt=it2,it2++)
					if ((*itt)+1==(*it2)) s2.erase(itt);
					else {it2=s2.insert((*itt)+1).first,s2.erase(itt); break;}
				if (it2==s2.end()) it2=s2.insert((*itt)+1).first,s2.erase(itt);
				it1=s1.find(*it2);
			}
		}
	}
	ansn=0;
	for (itt=s1.begin(),nw=0; itt!=s1.end(); itt++)
	{
		if ((*itt)==4000000) break;
		for (int j=1; j<=(*itt)-nw; j++) ans[++ansn]='0';
		ans[++ansn]='1',nw=(*itt)+1;
	}
	for (int i=ansn; i; i--) putchar(ans[i]);
	puts(""),ansn=0;
	for (itt=s2.begin(),nw=0; itt!=s2.end(); itt++)
	{
		if ((*itt)==4000000) break;
		for (int j=1; j<=(*itt)-nw; j++) ans[++ansn]='0';
		ans[++ansn]='1',nw=(*itt)+1;
	}
	for (int i=ansn; i; i--) putchar(ans[i]);
	return puts(""),0;
}

Measured memory_bytes: 91392
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    ll h,w;
    cin>>h>>w;
    char s[55][55];
    rep(i,h+2){
        s[0][i]='.';
        s[w+1][i]='.';
    }
    rep(i,w+2){
        s[i][0]='.';
        s[i][h+1]='.';
    }
    //printf("\n%s\n",s[h+1]);
    rep(i,h){
        scanf("%s",s[i+1]+1);
        strcat(s[i+1],".");
    }
    bool f_field=0;
    //rep(i,h+2) printf("%s\n",s[i]);
    ll ix[4] = {1,0,-1,0};
    ll jy[4] = {0,1,0,-1};
    rep(i,h) rep(j,w){
        if(s[i+1][j+1]=='#'){        
            bool ff=0;
            rep(k,4){
                if(s[i+1+ix[k]][j+1+jy[k]]=='#') ff=1;
            }
            if(!ff) f_field=1;
        }
    }
    if(f_field) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  string S, T;
  cin >> S >> T;
  ll A, B;
  cin >> A >> B;
  string U;
  cin >> U;
  if (S == U) {
    cout << A - 1 << " ";
  } else {
    cout << A << " ";
  }

  if (T == U) {
    cout << B - 1 << endl;
  } else {
    cout << B << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  
  vll A(N);
  rep(i, N) {
    cin >> A[i];
  }
  
  vll acc(N + 1);
  unordered_map<ll, vector<int>> vtois;
  
  vtois.emplace(acc[0], vi());
  vtois[acc[0]].push_back(0);
  
  rep(i, N) {
    acc[i + 1] = acc[i] + A[i];
    if(vtois.find(acc[i + 1]) == vtois.end()) {
      vtois.emplace(acc[i + 1], vi());
    }
    
    vtois[acc[i + 1]].push_back(i + 1);
  }
  
  ll ct = 0;
  
  //0はそれ自体でカウント
  //それ以外は、-と+でセット
  while(true) {
    auto itr = vtois.begin();
    if(itr == vtois.end()) break;
    auto pr = *itr;
    ll n = pr.second.size();
    ct += n * (n - 1) / 2;
    vtois.erase(pr.first);
  }
  
  fin(ct);
  /*
  rep(i, N) {
    //累積和の差が0になるところを探す
    ll tofind = -acc[i + 1];
    if(vtois.find(tofind) != vtois.end()) {
      for(int idx : vtois[tofind]) {
        if(idx < i + 1) {
          //1つずつ数えるのはTLE
          ct ++;
        }
      }
    }
  }*/
}

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

int main()
{
	int a, b, c = 0;
	int result = 0;;

	std::cin >> a >> b >> c;

	if (b > a * c)
	{
		result = c;
	}
	else
	{
		result = b / a;
	}

	std::cout << result << std::endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  ll N, M; scanf("%lld %lld", &N, &M);
  ll ans = 0;
  if (2 * N >= M) {
    ans = M / 2;
  }
  else {
    ans = N + max(0LL, M - 2 * N) / 4;
  }
  printf("%lld\n", ans);
  return 0;
}


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

int factor_2(int x){
    int res = 0;
    while(x > 0){
        if(x % 2 == 0){
            res++;
            x /= 2;
        }else{
            return res;
        }
    }
    return res;
}
int main()
{
    bool flag = false;
    int cnt = 0;
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cnt += factor_2(a[i]);
    }

    cout << cnt << endl;

}

Measured memory_bytes: 3636
N = int(input())
A = list(map(int, input().split()))

t = [0] * (N + 1)
ans = 0
for i in range(N):
    sa = i - A[i]
    if sa >= 0:
        ans += t[sa]
    wa = i + A[i]
    if wa < N:
        t[wa] += 1

print(ans)


Measured memory_bytes: 92792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int, bool>>> vp(n, vector<pair<int, bool>>());
  rep(i, n){
    int m;
    cin >> m;
    rep(j, m){
      int x, y;
      cin >> x >> y;
      x--;
      bool f = (y == 1);
      vp.at(i).push_back({x, f});
    }
  }
  int ans = 0;
  rep2(bit, 1, 1 << n){
    bool add = false;
    int co = 0;
    rep(i, n){
      if((bit & (1 << i)) != 0){
        co++;
        for(auto p : vp.at(i)){
          if(p.second == true){
            if((bit & (1 << p.first)) == 0) add = true;
          }else{
            if((bit & (1 << p.first)) != 0) add = true;
          }
        }
      }
    }
    if(add == false){
      ans = max(ans, co);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k, a, b; cin >> k >> a >> b;
    ll sum = 1;
    while(sum < a && k > 0)
    {
        sum++; k--;
    }
    if(b - a <= 2)
    {
        sum += k;
        cout << sum << endl;
        return 0;
    }
    if(k % 2 != 0) sum++, k--;
    sum += (b - a) * (k / 2);
    cout << sum << endl;
    return 0;
}



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

using namespace std;

int ans(int a, int b, int c)
{
    int avail = a - b;
  
    return max(0, c - avail);
}

int main(void)
{
  int a,b,c;
  
  cin >> a >> b >> c;
  
  cout << ans(a,b,c) << endl;
  
  return 0;
}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
long  long int inv(ll num) {
        
        int bits= log2(num)+1;
        //cout<<bits<<"\n";
        long long int all_one= (1ll<<bits)-1;
       // cout<<all_one<<"\n";
        return num^all_one;
        
    }


ll pow_5(ll a)
{
	return a*a*a*a*a;
}

void solve(ll x)
{
	
	for(ll i=-1000;i<=1000;i++)
		for(ll j=-1000;j<=1000;j++)
		{
			ll ans= pow_5(i)-pow_5(j);
			
				if(ans==x)
				{
					cout<<i<<" "<<j<<"\n";
					return;
				}

		}

}
int main()
{
	FASTIO;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif*/
	
	ll x;
	 cin>>x;
	 solve(x);

	return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll D;
    cin >> D;
    vector<ll> vec(26);
    rep(i,26){
        cin >> vec[i];
    }
    vector<vector<ll> > happiness(D, vector<ll>(26));
    rep(i,D){
        rep(j,26){
            cin >> happiness[i][j];
        }
    }
    vector<ll> sad(26,0);
    rep(j,26){
        sad[j] += vec[j];
    }
    rep(i,D){
        ll sadistic_per_day = 0;
        rep(j,26){
            sadistic_per_day += sad[j];
        }
        ll minus_point = 0;
        ll t = 0;
        minus_point -= sadistic_per_day;
        ll max_point = minus_point;
        rep(j,26){
            if (max_point <= minus_point + sad[j] + happiness[i][j]){
                t = j + 1;
                max_point = minus_point + sad[j] + happiness[i][j];
            }
        }
        rep(j,26){
            sad[j] += vec[j];
        }
        sad[t - 1] = 0;
        cout << t << endl;
    }
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m;
  cin >> n >> m;
  vector<ll> st_x(n), st_y(n), ck_x(m), ck_y(m);
  REP(i,n) cin >> st_x[i] >> st_y[i];
  REP(i,m) cin >> ck_x[i] >> ck_y[i];
  REP(i,n){
    ll min_d = 1e18;
    int min_ind;
    REP(j,m){
      ll dis = abs(st_x[i]-ck_x[j])+abs(st_y[i]-ck_y[j]);
      if(dis < min_d){
        min_d = dis;
        min_ind = j+1;
      }
    }
    cout << min_ind << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
import re, bisect

N, Q = map(int, input().split())
S = input()

l = []
r = []
for _ in range(Q):
    l_tmp, r_tmp = map(int, input().split())
    l.append(l_tmp - 1)
    r.append(r_tmp - 1)

# SのうちACが現れるインデックスを全て保存しておき、そこを含むかどうかを判定する

match_index_list = [m.span() for m in re.finditer('AC', S)]
match_first_index_list = []

for i in range(len(match_index_list)):
    match_first_index_list.append(match_index_list[i][0])

match_last_index_list = [x+1 for x in match_first_index_list]

for question in range(Q):
    print(bisect.bisect_right(match_last_index_list, r[question]) - bisect.bisect_left(match_first_index_list, l[question]))

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int v = 1, ans = 0;
  for (int x : {a,b,c}) {
    int add = min(x,k);
    ans += add*v;
    k -= add;
    v--;
  }
  cout << ans << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  if(N%2!=0){
    b.at(N/2)=a.at(0);
    for(int i=0; i<N/2; i++){
      b.at(N/2+1+i)=a.at(i*2+1);
      b.at(N/2-1-i)=a.at(i*2+2);
    }
  }
  else{
    for(int i=0; i<N/2; i++){
      b.at(N/2+i)=a.at(i*2);
      b.at(N/2-1-i)=a.at(i*2+1);
    }
  }
  for(int i=0; i<N; i++) cout << b.at(i) << ' ';
  cout << endl;
}

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

int isPrime(int);

int main(){

    int i,j,n,num;
    int count=0;
    int a;

scanf("%d",&n);

while(n>0){
    scanf("%d",&num);
    a=isPrime(num);
    if(a==1) count++;
    n--;
}

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

return 0;
}

int isPrime(int x){
    
    int i;

    if(x==2) return 1;

    if(x<2||x%2==0) return 0;

    for(i=2;i<=sqrt(x);i++){
        if(x%i==0) return 0;
    }

return 1;

}

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

int n,m;
long long arr[200001];

int main(){
	cin>>n;
	for(int i = 1;i <= n;i++){
		cin>>arr[i];
	}
	sort(arr + 1, arr + n + 1);
	for(int i = 1;i <= n - 1;i++){
		if(arr[i] == arr[i + 1]){
			cout<<"NO"<<endl;
			break;
		}
		else{
			m++;
		}
	}
	if(m == n - 1){
		cout<<"YES"<<endl;
	}
}



Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
using namespace std;
const int MOD=1e9+7;
struct mint{int x;mint(int x=0):x(x){}};
inline mint operator+  (mint a,mint b){return a.x+b.x<MOD?a.x+b.x:a.x+b.x-MOD;}
inline mint operator-  (mint a){return MOD-a.x;}
inline mint operator-  (mint a,mint b){return a+-b;}
inline mint operator*  (mint a,mint b){return 1LL*a.x*b.x%MOD;}
inline mint operator<< (mint x,int y){mint r=1;for(;y;y>>=1,x=x*x)if(y&1)r=r*x;return r;}
inline mint operator~  (mint x){return x<<MOD-2;}
inline mint operator/  (mint a,mint b){return a*~b;}
inline mint&operator+= (mint&a,mint b){return a=a+b;}
inline mint&operator-= (mint&a,mint b){return a=a-b;}
inline mint&operator*= (mint&a,mint b){return a=a*b;}
inline mint&operator<<=(mint&x,int y){return x=x<<y;}
inline mint&operator/= (mint&a,mint b){return a=a/b;}
#define MN 50
mint f[MN+5][MN*2+5][MN*2+5],ans;int a[MN*2+5];
int main()
{
	int n,i,j,k,l,tj,tk;
	for(scanf("%d",&n),i=1;i<n<<1;++i)scanf("%d",&a[i]);
	sort(a+1,a+n+n);
	for(f[1][1][1]=i=1;i<n;++i)for(j=1;j<i+i;++j)for(k=1;k<=j;++k)if(f[i][j][k].x)
	{
		tj=j+(a[n+i-1]!=a[n+i]);tk=k;
		if(a[n-i+1]!=a[n-i])++tj,++tk;
		for(l=1;l<=tj;++l)(l>tk?f[i+1][tj-l+tk+1][tk+1]:f[i+1][tj-max(tk-l-1,0)][l])+=f[i][j][k];
	}
	for(i=1;i<n+n;++i)for(j=1;j<=i;++j)ans+=f[n][i][j];
	printf("%d",ans);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    ll a, b;
    cin >> a >> b;
    ll x = 0, y = abs(a - b);

    rep(i, N - 2){
        ll h;
        cin >> h;
        ll tpy = y;
        y = min(x + abs(h - a), y + abs(h - b));
        x = tpy;

        ll tpb = b;
        b = h;
        a = tpb;
    }

    print(y);

    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

class Printable a where
  format :: a -> String

instance Printable Int where
  format = show

instance Printable Integer where
  format = show

instance Printable Double where
  format = show

instance Printable Float where
  format = show

instance Printable Char where
  format = show

instance Printable String where
  format x = x

instance Printable Bool where
  format = show

put :: Printable a => a -> IO ()
put = putStr . format

putLn :: Printable a => a -> IO ()
putLn = putStrLn . format

putList :: Printable a => [a] -> IO ()
putList [a] = put a
putList (a:as) = do
  put a
  putStr " "
  putList as

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [x] <- readInt
  if x `elem` [3, 5, 7]
    then put "YES"
    else put "NO"


Measured memory_bytes: 380
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
signed main(){
	int n;cin>>n;int sb[N];int sum=0;map<int,int>kk;
	for(int i=1;i<=n;i++){cin>>sb[i];sum+=sb[i];kk[sb[i]]++;
	} int t;cin>>t;
	while(t--){
		int a,b;cin>>a>>b;kk[b]+=kk[a];
		sum+=(b-a)*kk[a];kk[a]=0;
		cout<<sum<<"\n";
	}
}

Measured memory_bytes: 10160
#include <iostream>
	#include <stdio.h>
	#include <cmath>
	#include <algorithm>
	#include <climits>
	#include <vector>
	#include <iomanip>
	#include <string>
	#include <queue>
	#include <numeric>
	#include <functional>
	#include <array>
	#include <map>
	#include <set>

	using namespace std;
	using P = pair<int, int>;
	using T = tuple<int, int, int>;

	long long MOD = 1000000007;
	long long dp[100005][4];

	int kumi[1000][999];
	bool kyou[1000][1000005];
	int shintyoku[1000];

	int doneCount = 0;
	queue<int>nextDay;

	bool compare_by_second(pair<int, int> a, pair<int, int> b) {
		if (a.second != b.second) {
			return a.second < b.second;
		}
		else {
			return a.first < b.first;
		}
	}

	bool calc(int N, int i,int j) {
		bool success = false;
		if (kyou[j][i] || N - 1 <= shintyoku[j])return success;
		int aite = kumi[j][shintyoku[j]] - 1;
		if (kumi[aite][shintyoku[aite]] - 1 == j && !kyou[aite][i] && shintyoku[aite] < N) {
			//成立
			success = true;
			shintyoku[j]++;
			shintyoku[aite]++;
			kyou[j][i] = true;
			kyou[aite][i] = true;
			nextDay.push(j);
			nextDay.push(aite);
			if (N - 1 <= shintyoku[j])doneCount++;
			if (N - 1 <= shintyoku[aite])doneCount++;
		}
		return success;
	}

	int main() {

		int N;
		cin >> N;


		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N-1; ++j) {
				cin >> kumi[i][j];
			}
			shintyoku[i] = 0;
		}

		int ans = 0;
		//一日ずつ進める
		for (int i = 0; i < 1000000;++i) {
			bool success = false;
			//自分
			if (i == 0) {
				for (int j = 0; j < N; ++j) {
					bool s = calc(N, i, j);
					if (s) {
						success = true;
					}
				}
			}
			else {
				int size = nextDay.size();
				for (int j = 0; j < size; ++j) {
					int current = nextDay.front();
					nextDay.pop();
					bool s = calc(N, i, current);
					if (s) {
						success = true;
					}
				}
			}
			if (!success) {
				ans = -1;
				break;
			}
			if (N <= doneCount) {
				ans = i + 1;
				break;
			}
		}

		cout << ans << endl;
	}


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

using namespace std;

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

	int n;
	cin >> n;
	string name;
	int score;
	vector< tuple<string, int, int> > res;
	for (int i = 0; i < n; i++) {
		cin >> name >> score;
		res.emplace_back(name, -score, i + 1);
	}
	sort(res.begin(), res.end());
	for (int i = 0; i < n; i++) {
		int id;
		tie(ignore, ignore, id) = res[i];
		cout << id << endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);ios::sync_with_stdio(false);

ll id[1010][1010] = {};
ll dp[1000010] = {};
bool visited[1000010];

vector<vector<ll>> e(1000010, vector<ll>(0));

ll toid(ll x, ll y)
{
    if (y > x)
        swap(x, y);
    return id[x][y];
}

ll tsort(ll x)
{ //与えられた場所から、更新済みか、行く先がない場所まで更新する
    if (visited[x])
    {
        if (dp[x] == -1)
            return INF;
        else
            return dp[x];
    }

    visited[x] = true;

    ll res = 0;
    rep(i, siz(e[x]))
    {
        res = max(res, tsort(e[x][i]) + 1);
    }

    dp[x] = res;

    return dp[x];
}

signed main()
{
    rep(i, 1000010)
    {
        dp[i] = -1;
        visited[i] = false;
    }

    ll n, ans = 0, cnt = 0;
    cin >> n;

    rep(i, n) rep(j, n - 1)
    {
        if (j >= i)
            continue;

        id[i + 1][j + 1] = cnt;
        //cout << i + 1 << " " << j + 1 << " " << cnt << endl;
        cnt++;
    }

    rep(i, n)
    {
        ll now, mae, x;
        rep(j, n - 1)
        {
            cin >> x;
            now = toid(i + 1, x);
            if (j > 0)
            {
                e.at(mae).pb(now);
                //cout << mae << " " << now << endl;
            }
            mae = now;
        }
    }

    rep(i, cnt)
    {
        ans = max(ans, tsort(i) + 1);
        if (ans >= INF)
        {
            puts("-1");
            return 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 56064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	l := nextLine()
	var head, tail string
	n := len(l)
	if n % 2 == 0 {
		head = l[0:n/2]
		tail = l[n/2:n]
	} else {
		head = l[0:n/2]
		tail = l[n/2+1:n]
	}
	cnt := 0
	for i, v := range(tail) {
		if v != rune(head[n/2-i-1]) {
			cnt = cnt + 1
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 640
s = input()
t = input()

diff = 0
min_diff = len(t)

for cnt_s in range(0, len(s) - len(t)+1):
    diff = 0
    for cnt_t in range(0, len(t)):
        if s[cnt_s + cnt_t] != t[cnt_t]:
            diff += 1
    if min_diff > diff:
        min_diff = diff

print(min_diff)


Measured memory_bytes: 9068
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <tuple>
#include <utility>

int testcase_ends() {
  size_t T, P, R;
  scanf("%zu %zu %zu", &T, &P, &R);
  if (T == 0 && P == 0 && R == 0) return 1;

  std::vector<std::vector<int>> a(T, std::vector<int>(P, -1));
  for (size_t i = 0; i < R; ++i) {
    size_t t, p;
    int time;
    char m;
    scanf("%zu %zu %d %c%*s", &t, &p, &time, &m);
    --t, --p;
    if (m == 'W') {
      --a[t][p];
      continue;
    }
    ++a[t][p];
    a[t][p] = -1200 * a[t][p] + time;
  }

  std::vector<std::tuple<int, int, size_t>> b;
  for (size_t i = 0; i < T; ++i) {
    int penalty = 0;
    int accepted = 0;
    for (size_t j = 0; j < P; ++j) {
      if (a[i][j] >= 0) {
        penalty += a[i][j];
        ++accepted;
      }
    }
    b.emplace_back(accepted, -penalty, -(i+1));
  }
  std::sort(b.rbegin(), b.rend());

  for (auto const& t: b) {
    int a, b, c;
    std::tie(a, b, c) = t;
    printf("%d %d %d\n", -c, a, -b);
  }
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2748
s = gets.chomp.chars

def danceable? arr
  arr.each.with_index(1) do |tap, i|
    return false if i.odd? && %w(L).include?(tap)
    return false if i.even? && %w(R).include?(tap)
  end

  return true
end

puts danceable?(s) ? 'Yes' : 'No'

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	string s,t;
	cin>>s>>t;
	int ct=0;
	forr(i,0,s.size())
	{
		if(s[i]!=t[i])
			ct++;
	}
	cout<<ct;
	
	return 0; 	
}

Measured memory_bytes: 3784
#include <iostream> 
#include <vector> 
#include <algorithm> 
using namespace std; 
int main() 
{ 
	int n;
	cin >> n;
	vector<int> L(n);
    for(int i=0;i<n;i++){
        cin>>L.at(i);
    }
    sort(L.begin(), L.end());
    int ans =0;
    for(int b=0;b<n;b++){
        for(int a=0;a<b;a++){
            int ab = L[a]+L[b];
            int r = lower_bound(L.begin(),L.end(),ab)-L.begin();
            int l = b+1;
            ans += r-l;
        }
    }
   
    cout << ans << endl; 

    return 0; 
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define INF -1
#define ll long long
using namespace std;

int main()
{
	int h, a, tmp;
	int sum = 0;
	cin >> h >> a;

	for (int i = 0; i < a; i++) {
		cin >> tmp;
		sum += tmp;
	}

	

	if (sum < h) {
		cout << "No";
	} else {
		cout << "Yes";
	}

	return 0;
}

Measured memory_bytes: 256
n=int(input())
point=[]
x_1,y_1=[int(i) for i in input().split(" ")]
 
for _ in range(n-1):
    x,y=[int(i) for i in input().split(" ")]
    point.append([x-x_1,y-y_1])
a=0
for i in range(n-2):a+=point[i][0]*point[i+1][1] - point[i][1]*point[i+1][0]
print(a*0.5)

Measured memory_bytes: 7756
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)
#define REP(i,b)

int main(){
  string s;
  cin>>s;
  for(int i=0;i<4;i++){
    cout<<s[i];
  }
  cout<<' ';
  for(int i=4;i<s.size();i++){
    cout<<s[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	x,y,z = readline() |> split |> parseMap
	if x<y
		println(0)
	elseif x<y+2z
		println(1)
	else
		println(div(x-z,y+z))
	end
end

main()

Measured memory_bytes: 111572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll Mxn=1e9;
vector<ll> dp(100005, -1);
vector<ll> v(1e5+1);
ll n, k;

ll frog(ll i) {
	if (i == n-1) return 0;
	if (i >= n) return Mxn;
	if (dp[i] !=-1) return dp[i];
	ll left = frog(i+1) + abs(v[i]-v[i+1]);
	ll right=Mxn;
	if (i+2<n) right=frog(i+2) + abs(v[i]-v[i+2]);
	return dp[i]=min(left, right);
}

int main() {
	cin >> n;
	for (ll i=0; i<n; ++i) cin>>v[i];
	cout << frog(0);

	return 0;
}


Measured memory_bytes: 7920