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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(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 compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int K=in();
    int ans;ans=0;
    REP(i,N){
        int a;
        cin>>a;
        if(a>=K)ans++;
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    long long n, m;
    cin >> n >> m;
    long long ans = min(n, m / 2);
    m -= ans * 2;
    if (m < 0) m = 0;
    ans += m / 4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0) {
                break;
            }
            for (int i = 0; i < H;i++) {
                for (int j = 0; j < W; j++) {
                System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();

        }
    }
}


Measured memory_bytes: 33084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define endl "\n"
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/
int n,m;
int x1,y11,x2,y2;
char s[1005][1005];
int vis[1005][1005];
int st[1000005];
vector<pair<int,int> >v[1000005];
struct trip{
    int a;int b;int c;
};
void dfs(int i,int j,int k)
{
    if(vis[i][j]!=0)return;
    vis[i][j]=k;
    v[k].pb({i,j});
    if(i+1<n && s[i+1][j]=='.')dfs(i+1,j,k);
    if(i-1>=0 && s[i-1][j]=='.')dfs(i-1,j,k);
    if(j-1>=0 && s[i][j-1]=='.')dfs(i,j-1,k);
    if(j+1<m && s[i][j+1]=='.')dfs(i,j+1,k);

    return;
}

void bfs(int i,int j,int val)
{
    queue<trip>q;
    q.push({i,j,val});
    while(!q.empty()){
    trip tmp=q.front();
    q.pop();
    int p=vis[tmp.a][tmp.b];
    if(st[p]!=-1)continue;
    st[p]=tmp.c;
    for(auto it:v[p])
    {
         int x=it.F,y=it.S;
         for(int i1=x-2;i1<=x+2;i1++)
         {
            for(int j1=y-2;j1<=y+2;j1++)
            {
                if(i1>=0 && j1>=0 && i1<n && j1<m && s[i1][j1]=='.' && st[vis[i1][j1]]==-1)
                    q.push({i1,j1,tmp.c+1});
            }
         }

    }}
    return;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);  
    
     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
      
  cin>>n>>m;
  cin>>x1>>y11;
  x1--;y11--;
  cin>>x2>>y2;
  x2--;y2--;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
        cin>>s[i][j];
    }
  }

  memset(vis,0,sizeof(vis));
  memset(st,-1,sizeof(st));
 // f(i,0,1000005)v[i].clear();

  int k=0;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<m;j++)
    {
        if(s[i][j]=='.' && vis[i][j]==0)
            {
                k++;
                dfs(i,j,k);
            }
    }
  }

  bfs(x1,y11,0);
  cout<<st[vis[x2][y2]]<<endl;

} 


Measured memory_bytes: 42672
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

B = sorted(A, reverse=True)
maxA = B[0]
maxB = B[1]
idx = A.index(maxA)
for i in range(N):
    if i == idx:
        print(maxB)
    else:
        print(maxA)


Measured memory_bytes: 14112
#include<iostream>
#include<vector>
#include<limits>
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;

int main()
{
  vector<int> hts;
  hts.push_back(0);  // left endpoint is height 0
  int ht = 0;
  string map;
  cin >> map;
  for(char c : map) {
    if (c == '/') hts.push_back(++ht);
    else if (c == '\\') hts.push_back(--ht);
    else if (c == '_') hts.push_back(ht);
  }

  vector<int> lmaxes = hts;
  int lmax=hts.front();
  for (size_t i=0; i<lmaxes.size(); ++i) {
    lmax = max(lmax, hts[i]);
    lmaxes[i] = lmax;
  }

  vector<int> rmaxes = hts;
  int rmax=hts.back();
  for (int i=(int)lmaxes.size()-1; i>=0; --i) {
    rmax = max(rmax, hts[i]);
    rmaxes[i] = rmax;
  }

//  cout << "Heights: ";
//  for (auto hi = hts.begin(); hi!=hts.end(); ++hi) cout << *hi << " ";
//  cout << endl;

  vector<double> vols;
  double current_vol=0;
  bool flood=false;
  int fstart;
  for(size_t i=0; i<hts.size()-1; ++i) {
    if(min(lmaxes[i],rmaxes[i+1])>min(hts[i], hts[i+1])) {
      if (not flood) {
        flood = true;
        fstart = hts[i];
      }
      if(hts[i]!=hts[i+1]) current_vol += 0.5;
      current_vol += min(lmaxes[i], rmaxes[i+1]) - max(hts[i], hts[i+1]);
    } 
    if (hts[i+1]==fstart and current_vol) {
      vols.push_back(current_vol);
      current_vol=0;
      flood=false;
    }
  }
  if (current_vol) vols.push_back(current_vol);

  cout << setprecision(0) << fixed;
  cout << accumulate(vols.begin(), vols.end(), 0) << endl;  // total volume
  cout << vols.size(); // number of floods
  for (auto v : vols) cout << " " << v;  // print volume of each flood
  cout << endl;
}


Measured memory_bytes: 3444
H, W, K = map(int, input().split())
C = [list(input()) for _ in range(H)]

ans = 0
def check(h, w):
    global ans
    tmp = 0
    for i in range(H):
        for j in range(W):
            if h[i] and w[j] and C[i][j] == "#":
                tmp += 1
    ans += 1 if tmp == K else 0

def dfs(h,w,hidx,widx):
    if hidx < H:
        for i in range(2):
            dfs(h+[i],w,hidx+1,widx)
    elif widx < W:
        for i in range(2):
            dfs(h,w+[i],hidx,widx+1)
    else:
        check(h, w)
    return


dfs([],[],0,0)
print(ans)


Measured memory_bytes: 69616
import math
def calc_distance(c1,c2):
  sum1 = 0
  for a1,a2 in zip(c1,c2):
    sum1 += (a1-a2)**2
  
  return math.sqrt(sum1)

def is_it_int(num):
  
  if num/int(num)==1:
    return True
  else:
    return False
#input
n,d = map(int,input().split())
list_of_coordinates = []
for i in range(n):
  list_of_coordinates.append(list(map(int,input().split())))

#solve
ans = 0
for i in reversed(range(n)):
  for j in range(i):
    if is_it_int(calc_distance(list_of_coordinates[i],list_of_coordinates[j])):
      ans += 1
      
print(ans)
      

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int c[105];
int main(){
    int n;
    cin >> n;
    pair<int,int> a[n];
    pair<int,int> b[n];
    for(int i=0;i<n;i++){
        cin >> a[i].second >> a[i].first;
        a[i].first *= -1;
    }
    for(int i=0;i<n;i++)cin >> b[i].first >> b[i].second;
    sort(a,a+n);
    sort(b,b+n);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i].second<b[j].first && -a[i].first<b[j].second && c[j]==0){
                c[j]++;
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

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

struct xyh {
  int x, y, h;
};

vector<xyh> survey;
vector<xyh> pyramid(101 * 101);

void init(int n)
{
  for (int i = 0; i < n; i++) {
    cin >> survey[i].x >> survey[i].y >> survey[i].h;
  }
  for (int y = 0; y <= 100; y++) {
    for (int x = 0; x <= 100; x++) {
      pyramid[101 * y + x] = {x, y, 0};
    }
  }
}

void check1()
{
  for (auto&& p : pyramid) {
    if (p.h < 0) continue;
    for (auto&& s : survey) {
      if (s.h == 0) continue;
      if (p.h == 0) {
        p.h = abs(p.x - s.x) + abs(p.y - s.y) + s.h;
      } else {
        if (p.h != abs(p.x - s.x) + abs(p.y - s.y) + s.h) {
          p.h = -1;
          break;
        }
      }
    }
  }
}

void check0()
{
  for (auto&& p : pyramid) {
    if (p.h < 0) continue;
    for (auto&& s : survey) {
      if (s.h != 0) continue;
      if (p.h > abs(p.x - s.x) + abs(p.y - s.y)) {
        p.h = -1;
        break;
      }
    }
  }
}

int main()
{
  int n;
  cin >> n;

  survey.resize(n);

  init(n);
  check1();
  check0();

  for (auto&& p : pyramid) {
    if (p.h > 0) {
      cout << p.x << " " << p.y << " " << p.h << endl;
      break;
    }
  }
}


Measured memory_bytes: 384
import itertools

n = int(input())
s = input()

s_l = list(map(int, s))
# print(s_l)

l = [i for i in range(10)]
ans = 0
for v1, v2, v3 in itertools.product(l, repeat=3):
    # print(f"{v1} {v2} {v3}")

    # print(v1) 
    if not v1 in s_l:
        continue
    else:
        index1 = s_l.index(v1)
    
    # print(f"index1 : {index1}")
    # print(s_l[index1 + 1:])
    
    s_l_1 = s_l[index1 + 1:]
        
    if not v2 in s_l_1:
        continue
    else:
        index2 = s_l_1.index(v2)
        
    s_l_2 = s_l_1[index2 + 1:]
        

    if not v3 in s_l_2:
        continue
    

    # print(f"{v1} {v2} {v3}")
    ans += 1
print(ans)
    

Measured memory_bytes: 10420
#include <stdio.h>
int main() {
	char s[20];
	int n=0;
	scanf("%s", s);
	for (int i = 0; i < strlen(s); i++) {
		if (s[i] == 'x')n++;
	}
	puts(n >= 8?"NO":"YES");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	vector< ll > A(N);
	vector< ll > B(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];
	priority_queue< pair< ll, ll > > q;
	rep(i, N) q.push(make_pair(B[i], i));
	ll ans = 0;
	while (!q.empty()) {
		pair< ll, ll > p = q.top();
		q.pop();
		int i = p.second;
		int i1 = ((p.second - 1) % N + N) % N;
		int i2 = (p.second + 1) % N;
		if (B[i] == A[i])
			continue;
		if (B[i] < A[i]) {
			ans = -1;
			break;
		}
		int tmp = (B[i] - A[i]) / (B[i1] + B[i2]);
		//cout << i << " " << B[i1] << endl;
		if (tmp == 0) {
			ans = -1;
			break;
		}
		ans += tmp;
		B[i] -= tmp * (B[i1] + B[i2]);
		if (B[i] != A[i]) {
			q.push(make_pair(B[i], i));
		}
	}
	bool f = true;
	rep(i, N) if (A[i] != B[i]) f = false;
	cout << (f ? ans : -1) << endl;
	return 0;
}

Measured memory_bytes: 9584
#include <stdio.h>

int main(void){
	char r;
	long x, count = 0;

	scanf("%ld", &x);

	r = x % 11;
	if(r > 6)
		count = 2*(x / 11) + 2;
	else if(r > 0)
		count = 2*(x / 11) + 1;
	else
		count = 2*(x / 11);
	printf("%ld", count);

	return 0;
}


Measured memory_bytes: 128
function Main(input) {
  input=input.split("\n");
  if(input[input.length-1]===''){
    input.pop();
  }
  const N=input[0].split(' ')[0]-0;
  const R=input[0].split(' ')[1]-0;
  if(N>=10){
    console.log(R);
  }else{
    console.log(R+100*(10-N));
  }
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  



  


Measured memory_bytes: 30428
import numpy as np
N = int(input())
A = list(map(int,input().split()))
A = [A[i] - i - 1 for i in range(N)]

A = np.array(A)

k = int(np.median(A))

ans = 0
for i in range(N):
    ans += abs(A[i] - k)

print(ans)

Measured memory_bytes: 49516
public class Main {
	public static void main(String[] args) {
		final String EOF = "END_OF_TEXT";

		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			sc.useDelimiter("\\s|\\n|\\r");
			int cnt = 0;
			String word = sc.next();
			String text = sc.next();

			while (!text.equals(EOF)) {
				cnt = text.equalsIgnoreCase(word) ? ++cnt : cnt;
				text = sc.next();
			}
			System.out.println(cnt);
		}
	}
}


Measured memory_bytes: 26112
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

constexpr int INF = 1e8;
constexpr int MOD = 1e9+7;
constexpr int ESP = 1e-9;
constexpr double PI = acos(-1);

vector<int> e[2000];
bool used[2000];

int dfs(int v, int k) {
    used[v] = true;
    int ret = 0;
    for (auto x: e[v]) if (!used[x]) {
        ret += dfs(x,k-1);
    }
    return ret + (k <= 0);
}

int main(void) {
    int i, j, n, k;
    cin >> n >> k;
    REP (i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    int ans = INF;
    int res[2000];
    REP (i,n) {
        REP (j,n) used[j] = false;
        used[i] = true;
        int sum = 0;
        for (auto x: e[i]) {
            res[x] = dfs(x,k/2);
            sum += res[x];
        }
        REP (j,n) used[j] = false;
        used[i] = true;
        int ma = 0;
        for (auto x: e[i]) ma = max(ma,res[x] - dfs(x,(k+1)/2));
        sum -= ma;
        ans = min(ans,sum);
    }
    cout << ans << endl;
    return 0;
}


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


int main(){
  	int N;
  cin >> N;
  int p[N];
  int up[N];
  for (int i=0;i<N;i++){
    	cin >> p[i];
    	up[i]=p[i];
  }
  sort(up,up+N);
  int f=0;
  for (int i=0;i<N;i++){
  	if (up[i]!=p[i]) f++;
  }
  if (f==0 || f==2)
    cout << "YES" << endl;
  else 
    cout << "NO" << endl;
}

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

namespace ABC054B___Template_Matching
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            List<string> nImage = new List<string>();
            List<string> mImage = new List<string>();
            for (int index = 1; index <= n; index++)
            {
                nImage.Add(Console.ReadLine());
            }
            for (int index = 1; index <= m; index++)
            {
                mImage.Add(Console.ReadLine());
            }

            string result = "No";

            if (ContainBInA(nImage, mImage))
            {
                result = "Yes";
            }

            Console.WriteLine(result);
        }


        public static bool ContainBInA(List<string> nImage, List<string> mImage)
        {
            bool res = false;
            int n = nImage.Count;
            int m = mImage.Count;


            //row pattern number
            int rowPattern = n - m + 1;

            //col pattern number
            int colPattern = n - m + 1;

            //search row
            for (int rowIndex = 0; rowIndex < rowPattern; rowIndex++)
            {
                //search col
                for (int colIndex = 0; colIndex < colPattern; colIndex++)
                {
                    //select target in nImage
                    int startCol = colIndex;
                    //int endCol = colIndex + m - 1;
                    int startRow = rowIndex;
                    int endRow = rowIndex + m - 1;

                    int mImageRow = 0;

                    bool result = true;
                    for (int index = startRow; index <= endRow; index++)
                    {
                        if (nImage[index].Substring(startCol, m)!=mImage[mImageRow])
                        {
                            result = false;
                        }
                        mImageRow++;
                    }


                    if (result)
                    {
                        return true;


                    }



                }
            }


            return res;
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
 
// #define int            long long int 
#define vi             vector<int>
#define mod            1000000007
#define MAX            INT_MIN
#define MIN            INT_MAX
#define ff             first
#define ss             second
#define pb             push_back
#define bs             binary_search    // binary_search(a,a+n,x);
#define mp             make_pair
#define pii            pair<int,int>
#define pqb            priority_queue<int>
#define lower(x)         transform(x.begin(), x.end(), x.begin(), ::tolower);           
#define upper(x)          transform(x.begin(), x.end(), x.begin(), ::toupper);
#define lb             lower_bound      // lower_bound(a,a+n,x) - a; => For Index
#define up             upper_bound      // upper_bound(a,a+n,x) - a; => For Index       
#define floop(x,n)       for(int i=x;i<n;i++)
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define ps(x,y)        fixed<<setprecision(y)<<x         
#define FIO            ios_base::sync_with_stdio(false); cin.tie(NULL);
                  
void c_p_c()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif   
 
}
 
void solution()
{
    string s;
    cin>>s;

    int sum = 0;

    floop(0,s.length())
    {
        sum+=s[i]-'0';
    }

    if(sum%9==0)
        cout<<"Yes"<<endl;

    else
        cout<<"No"<<endl;
}
 
int32_t main()
{
    c_p_c();
 
    // int t;
    // cin>>t;
 
    // while(t--)
    // {
        solution();
    //}
 
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;
int main() {
  int nums[MAX], n;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> nums[i];
  int max_v = -2000000000;
  int min_n = nums[0];
  for(int i = 1; i < n; i++) {
    max_v = max(max_v, nums[i]-min_n);
    min_n = min(min_n, nums[i]);
  }
  cout << max_v << "\n";
  return 0;
}


Measured memory_bytes: 3892
#include <iostream>
#include <algorithm>
using namespace std;
int a[200100];
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int r, x, d;
	while (cin >>r>>d>>x)
	{
		int n = 10;
		while (n--)
		{
			x = r * x - d;
			cout << x << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit

setrecursionlimit(10**8)


def dp_solve(k, h, dp):
    if dp[k] < inf:
        return dp[k]
    if k == 1:
        dp[1] = abs(h[1]-h[0])
        return dp[1]
    if k == 2:
        dp[2] = min(abs(h[2]-h[1])+abs(h[1]-h[0]), abs(h[2]-h[0]))
        return dp[2]

    dp[k] = min(dp_solve(k-1, h, dp) + abs(h[k]-h[k-1]),
                dp_solve(k-2, h, dp)+abs(h[k]-h[k-2]))
    return dp[k]


if __name__ == "__main__":
    n = int(input())
    h = list(map(int, stdin.readline().split()))
    inf = float('inf')
    dp = [inf]*n

    print(dp_solve(n-1, h, dp))


Measured memory_bytes: 94084
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200001


int main(){	
	
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	vector<char> ans; 
	vector<string> sa(n);
	//map<string,int> mp;
	for(int i=0;i<n;i++){
		cin>>sa[i];
		//mp[sa[i]]+=1;
	}

	for(int i=0;i<n;i++){
		string s=sa[i];
		if(s=="AB"){
			if(a==0&&b==0){
				break;
			}
			else{
				if(a>b){
					a--;
					b++;
					ans.push_back('B');
				}
				else if(a==b){
					if(i+1<n){
						if(sa[i+1]=="BC"){
							b++;
							a--;
							ans.push_back('B');
						}
						else{
							b--;
							a++;
							ans.push_back('A');
						}

					}
					else{
					b--;
					a++;
					ans.push_back('A');
					}
				}
				else{
					b--;
					a++;
					ans.push_back('A');
				}
			}
		}
		else if(s=="BC"){
			if(c==0&&b==0){
				break;
			}
			else{
				if(c>b){
					c--;
					b++;
					ans.push_back('B');
				}
				else if(c==b){
					if(i+1<n){
						if(sa[i+1]=="AB"){
							b++;
							c--;
							ans.push_back('B');
						}
						else{
							b--;
							c++;
							ans.push_back('C');
						}

					}
					else{
					b--;
					c++;
					ans.push_back('C');
					}
				}
				else{
					b--;
					c++;
					ans.push_back('C');
				}
			}
			

		}
		else{

			if(a==0&&c==0){
				break;
			}
			else{
				if(a>c){
					a--;
					c++;
					ans.push_back('C');
				}
				else if(a==c){
					if(i+1<n){
						if(sa[i+1]=="BC"){
							c++;
							a--;
							ans.push_back('C');
						}
						else{
							c--;
							a++;
							ans.push_back('A');
						}

					}
					else{
					c--;
					a++;
					ans.push_back('A');
					}
				}
				else{
					c--;
					a++;
					ans.push_back('A');
				}
			}

		}
		
	}

	if(ans.size()!=n){
		cout<<"No"<<endl;
	}
	else{
		cout<<"Yes"<<endl;
		for(auto x: ans)
			cout<<x<<endl;
	}
	
}

Measured memory_bytes: 6672
#include<bits/stdc++.h>
//#define int long long
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, char r) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << r << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

void Yay(bool b) {
	if (b)say("Yay!");
	else say(":(");
}

template<typename T>
void maxi(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T& a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<typename T>
vector<vector<T>> fill_vector(int h, int w, T val) {
	vector<vector<T>> ret;
	vector<T> v(w, val);
	rep(h)ret.push_back(v);
	return ret;
}

template<typename T>
T max(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())maxi(ret, v[i]);
	return ret;
}

template<typename T>
T min(vector<T> v) {
	T ret = v[0];
	Rep(1, v.size())mini(ret, v[i]);
	return ret;
}

bool comp(int a, int b) {
	if (a % 10 == 0)return false;
	if (b % 10 == 0)return true;
	return a % 10 < b % 10;
}

signed main() {
	int ans = 0;
	int Min = 10;
	rep(5) {
		makei(a);
		ans += a % 10 == 0 ? a : (a / 10 + 1) * 10;
		if (a % 10 != 0) mini(Min, a % 10);
	}
	if (Min == 10)say(ans);
	else say(ans - 10 + Min);
};


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main
{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String march = "MARCH";
    TreeMap<Character,Integer> mp = new TreeMap<Character, Integer>();
    for(int i = 0; i<5; i++){
      mp.put(march.charAt(i), 0); 
    }
    for(int i = 1; i<=N; i++){
      String s = sc.next();
      mp.put(s.charAt(0), mp.containsKey(s.charAt(0)) ? mp.get(s.charAt(0))+1 : 1);
    }
    long ans = 0;
    for(int i = 0; i<5; i++){
      for(int j = i+1; j<5; j++){
        for(int k = j+1; k<5; k++){
            ans += 1L * mp.get(march.charAt(i)) * mp.get(march.charAt(j)) * mp.get(march.charAt(k));
        }
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 58536
import numpy as np
 
N, W = map(int,input().split())
 
dp = np.zeros(W+1, dtype=int)
 
for i in range(N):
    w, v = map(int,input().split())
    a = dp[:-w] + v
    b = dp[w:]
    m = np.maximum(a,b)
    dp[w:] = m

print(dp[-1])

Measured memory_bytes: 17108
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void Switches()
{
  int n;
  int m;
  cin >> n >> m;
  vector<vector<int>> s(m, vector<int>(n,0));
  vector<int> p(m);
  vector<int> k(m);
  for (int i = 0; i < m; i++)
  {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) cin >> s[i][j];
  }
  for (int i = 0; i < m; i++) cin >> p[i];
  
  vector<int> sw(n,0);
  int count = 0;
  int ans = 0;
  while (count < pow(2, n))
  {
    int now = n - 1;
    if (count < 2) sw[now] = count % 2;
    else
    {
      int c = count;
      while (c / 2 > 0)
      {
        sw[now] = c % 2;
        c = c / 2;
        now--;
      }
      sw[now] = c;
    }

    for (int i = 0; i < m; i++)
    {
      int on = 0;
      for (int j = 0; j < k[i]; j++) if (sw[s[i][j] - 1] == 1)on++;

      if (on % 2 != p[i])break;
      if (i + 1 == m) ans++;
    }
    count++;
  }
  
  cout << ans << endl;
  return;
}

int main()
{
  Switches();
}

Measured memory_bytes: 256
def main():    
    import bisect
    import sys
    input = sys.stdin.readline
    n,q = map(int,input().split())
    l = [list(map(int,input().split())) for i in range(n)]
    l = sorted(l,key = lambda x: x[2])
    d = [int(input()) for i in range(q)]

    ans = [-1]*q
    skip = [-1]*q
    for s,t,x in l:
        le = bisect.bisect_left(d,s-x)
        ri = bisect.bisect_left(d,t-x)
        while le < ri:
            if skip[le] == -1:
                ans[le] = x
                skip[le] = ri
                le += 1
            else:
                le = skip[le]

    for i in ans:
        print(i)
if __name__ == "__main__":
    main()

Measured memory_bytes: 109152
import math

a, b, x = map(int, input().split())

in1 = 2*(a*b-x/a)/(a**2)
in2 = a*(b**2)/(2*x)

ans1 = math.degrees(math.atan(in1))
ans2 = math.degrees(math.atan(in2))

if x > (a**2)*b/2:
    ans = ans1
else:
    ans = ans2

print(ans)

Measured memory_bytes: 3064
s = list(input())
ans = 0
for i in range(len(s)):
    s.pop()
    if len(s)%2==1:
        continue
    else:
        i = 0
        while i < len(s)//2:
            if s[i]!=s[i+len(s)//2]:
                break
            
            if i==len(s)//2-1:
                ans = len(s)
            
            i += 1
        if ans > 0:
            break
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    if(a*n<=b) out(a*n);
    else out(b);
}


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

int main()
{
  int N, K;
  cin >> N >> K;
  int H[100005] = {};
  for (int i = 1; i<= N; i++)
  {
    cin >> H[i];
  }
  
  int cost[100005] = {};
  
  cost[1] = 0;
  cost[2] = abs(H[2] - H[1]);
  /*
  cost[3] = min(cost[1] + abs(H[3] - H[1]), cost[2] + abs(H[3] - H[2]));
  cost[4] = min(cost[1] + abs(H[4] - H[1]), cost[2] + abs(H[4] - H[2]), 
                cost[3] + abs(H[4] - H[3]));
  cost[5] = min(cost[1] + abs(H[5] - H[1]), cost[2] + abs(H[5] - H[2]), 
                cost[3] + abs(H[5] - H[3]), cost[4] + abs(H[5] - H[4]));
  
  cost[K] = min(cost[1] + abs(H[K] - H[1]), cost[2] + abs(H[K] - H[2]), ...
                cost[K-2] + abs(H[K] - H[K-2]), cost[K-1] + abs(H[K] - H[K-1]));
  cost[K+1] = min(cost[1] + abs(H[K+1] - H[1]), cost[2] + abs(H[K+1] - H[2]), ...
                cost[K-1] + abs(H[K+1] - H[K-1]), cost[K] + abs(H[K+1] - H[K]));
  cost[K+2] = min(cost[2] + abs(H[K+2] - H[2]), cost[3] + abs(H[K+2] - H[3]), ...
                cost[K] + abs(H[K+2] - H[K]), cost[K+1] + abs(H[K+2] - H[K+1]));
  */
  
  for (int j = 3; j <= N; j++)
  {
    cost[j] = 1000000000;
    int mn;
    if (j <= K) mn  = 1;
    else mn = j - K;
    for (int x = mn; x < j; x++)
    {
      cost[j] = min(cost[j], cost[x] + abs(H[j] - H[x]));
    }
  }
  
  cout << cost[N] << endl;
  
  return 0;
}

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

int main() {
  long long n;
  cin>>n;
  vector<int>a(1000002);
  for(long long i=2;i<=1000000;i++){
    while(true){
      if(n%i==0){
        a[i]++;
        n/=i;
      }
      else break;
    }
    if(n==1) break;
  }
  if(n!=1) a[1000001]=1;
  long long ans=0;
  for(int i=2;i<=1000001;i++){
    int j=1;
    while(true){
      if(a[i]>=j){
        ans++;
        a[i]-=j;
      }
      else break;
      j++;
    }
  }
  if(ans==0 && n>=2) cout<<1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 7216
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long i64;

int main()
{
	int n;
	vector<pair<int,int>> ws;

	scanf("%d", &n);
	ws.resize(n);
	for(int i = 0; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		ws[i] = {b, a};
	}

	sort(ws.begin(), ws.end());

	bool ok = true;
	i64 sum = 0;

	for(int i = 0; i < n; i++) {
		sum += ws[i].second;
		if(sum > ws[i].first) {
			ok = false;
		}
	}

	printf("%s\n", ok ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC161D

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll K; cin >> K;
  queue<ll> q;
  for(ll i = 1; i <=9; i++){
    q.push(i);
  }
  ll cnt = 1;
  while(1){
    ll ans = q.front(); q.pop();
    if(ans%10 != 0) q.push(ans*10+(ans%10-1));
    q.push(ans*10+ans%10);
    if(ans%10 != 9) q.push(ans*10+ans%10+1);
    if(cnt == K){
      cout << ans << endl;
      return 0;
    }
    cnt++;
  }
}

Measured memory_bytes: 4780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strV = null;

		while((strV = parseStdin()) != null) {
			double	dV = Double.parseDouble(strV);
			int		nN = (int)Math.ceil((dV * dV / 98.0)) + 1;
			System.out.println(nN);
		}
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 17068
n = int(input())
A = list(map(int, input().split()))
print(*A)
for i in range(1, n):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print(*A)



Measured memory_bytes: 5980
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <unordered_set>
#include <unordered_map>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/multi_array.hpp>

using namespace std;

#if 0
// memo
abs()

start_with(str, "hoge");
ends_with(str, "hoge");

std::sort(d.begin(), d.end());
d.erase(std::unique(d.begin(), d.end()), d.end());
#endif

using namespace boost;
using namespace boost::algorithm;


void dfs(const boost::multi_array<bool, 2>& mat,
         int u, int N, int& count, int prev,
         std::bitset<8> not_visited)
{
    not_visited[u] = false;

    if (not_visited.none()) {
        ++count;
        return;
    }
    for (size_t v = 0; v < N; ++v) {
        if (mat[u][v]) {
            if (v == prev) {
                continue;
            }
            if (!not_visited[v]) {
                continue;
            }
            dfs(mat, v, N, count, u, not_visited);
        }
    }
}


int main()
{
    int N, M;

    std::cin >> N >> M;

    boost::multi_array<bool, 2> mat(boost::extents[N][N]);

    for (size_t i = 0; i < M; ++i) {
        int a, b;
        std::cin >> a >> b;
        --a;
        --b;
        mat[a][b] = mat[b][a] = true;
    }

    int count = 0;
    std::bitset<8> not_visited;
    for (size_t i = 0; i < N; ++i) {
        not_visited[i] = true;
    }
    dfs(mat, 0, N, count, -1, not_visited);

    std::cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2005;
int n,a[N],d[N],vis[N];vector<int>g[N];
void dfs(int k1){
	vis[k1]=1;
	for(int i=1;i<=n;++i)if(!vis[i]&&__gcd(a[k1],a[i])>1)g[k1].push_back(i),++d[i],dfs(i);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i)if(!vis[i])dfs(i);
	for(int i=1;i<=n;++i)for(int j=n;j>=1;--j)if(!d[j]){
		printf("%d ",a[j]);for(auto k:g[j])--d[k];
		d[j]=-1;break;
	}
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int main() {

  int M;
  int N;
  cin >> N >> M;
  int ans;
  vector<int> s(M);
  vector<char> c(M), n(9);
  REP(i, M){
    cin >> s[i] >> c[i];
    s[i]--;
  }
  string _n;
  
  if(N == 3){
     _n = "100";
  } else if(N == 2){
     _n = "10";
  }else {
     _n = "0";
  }
  
  vector<int> y(3, 0);
  REP(i, M){
    if(s[i] == 0 && c[i] == '0' && N != 1){
      _n = "-1";
      break;
    }else {
      if(y[s[i]] != 0 && _n[s[i]] != c[i]){
        _n = "-1";
        break;
      } 
      // cout << s[i] << " ";
      _n[s[i]] = c[i];
      y[s[i]]++;
    }
  }
  // if(M == 0)_n = "0";

  cout << stoi(_n) << endl;
 

    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    s.append(input())
m = int(input())
t = []
for i in range(m):
    t.append(input())
#内包表記で辞書を作成
#list(set(s))で重複を取り除いたlistを取得
num_s = {key: 0 for key in list(set(s))}
for i in num_s.keys():
    num_s[i] = s.count(i)
for i in num_s.keys():
    num_s[i] -= t.count(i)
#valueの値が最大となるkeyを取得
ans = max(num_s.values())
if ans < 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp; 
int ans=1e9,ret;
int main(){
	int n,X;
	cin>>X>>n;
	for(int i=1;i<=n;i++){
		int x;cin>>x;mp[x]=114514;
	}
	for(int i=-200;i<=200;i++){
		if(mp[i]<1919 && abs(i-X)<ans)ans=abs(i-X),ret=i; 
	}
	cout<<ret;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{
  gearup;
  int n,q; cin >> n >> q;
  vvl G(n);
  rep(i,n-1){
    int a,b; cin >> a >> b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vb visited(n);
  vl cost(n);
  rep(i,q){
    int node,co; cin >> node >> co;
    cost[--node]+=co;
  }
  queue<int> que;
  que.push(0);
  visited[0] = true;
  while(!que.empty()){
    int node = que.front();
    que.pop();
    for(auto nv:G[node]){
      if(visited[nv])continue;
        cost[nv]+=cost[node];
        que.push(nv);
        visited[nv] = true;
    }
  }
  rep(i,n)out(cost[i]);
}


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

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (s == "Cloudy") {
    cout << "Rainy" << endl;
  } else if (s == "Rainy") {
    cout << "Sunny" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int n;
    while(scanf("%d",&n),n){
        int m;
        scanf("%d",&m);
        int a,b;
        int ans = 0;
        for(int i = 0;i < m; i++){
            scanf("%d%d",&a,&b);
            ans += b-a;
        }
        if(ans >= n)printf("OK\n");
        else {
            printf("%d\n",(n-ans));
        }
    }
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define EPS (1e-8)
#define x p.real()
#define y p.imag()
using namespace std;
typedef complex <double> point;
struct po{
  point p;
  double l;
  po(){x=y=l=0;};
  po(double a,double b,double c){x=a,y=b,l=c;}
  po(point a,double b){p=a,l=b;}
};
int n;
po bal[10];
double Abs(po a){return (a.x*a.x+a.y*a.y+a.l*a.l);}

po get_po(po a,po b){
  if(a.l>b.l) swap(a,b);
  double D=Abs(po(a.p-b.p,0));
  if(a.l*a.l+D<=b.l*b.l)return a;
  
  double t=(a.l*a.l+D-b.l*b.l)/(2*sqrt(D));
  point vec=b.p-a.p;
  vec=(vec/abs(vec))*t+a.p;
  return po(vec,sqrt(a.l*a.l-t*t));
}

po BinarySearch(double l,po b){
  double L=0,Y,R=l,h;
  int cnt=50;
  while(cnt--){
    Y=(L+R)/2;
    h=sqrt(l*l-Y*Y);
    if(Abs(po(b.x,Y-b.y,h))-b.l*b.l<=EPS) R=Y;
    else L=Y;
  }
  return po(0,Y,h-EPS);
}

bool check(po a){
  for(int i=0;i<n;i++)
    if(Abs(po(a.p-bal[i].p,a.l))-bal[i].l*bal[i].l>EPS)return 0;
  return 1;
}

double solve(){
  if(n==1)return bal[0].l;
  double res=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      po a=get_po(bal[i],bal[j]);
      for(int k=0;k<n;k++){
	point p=bal[i].p-a.p,q=bal[k].p-a.p;
	q*=conj(p)/abs(p);
	po b=BinarySearch(a.l,po(q,bal[k].l));
	b.p=b.p*p/abs(p)+a.p;
	if(check(b))res=max(res,b.l);
      }
    }
  return res;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++) cin>>bal[i].x>>bal[i].y>>bal[i].l;
    printf("%.8f\n",solve());
  }
  return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"
#define MOD 1000000007

typedef long lint;
typedef pair<lint, lint> P;
bool lessPair(const P& l, const P& r){return l.second < r.second;}
bool morePair(const P& l, const P& r){return l.second > r.second;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    lint N; cin >> N;
    vector<lint> A(N);
    vector<lint> B(N);
    vector<P> SUM(N);

    REP(i, N) {
      lint x,y; cin >> x; cin >> y;
      A[i] = x;
      B[i] = y;
      SUM[i] = P(i, x+y);
    }

    sort(SUM.begin(),SUM.end(),  morePair);

    lint res=0;

    REP(i, N) {
      if(i%2 == 0) {
        res += A[SUM[i].first];
      } else {
        res -= B[SUM[i].first];
      }
    }

    PRINT(res);

    return 0;
}


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

int N, M;
map<string, int> s;

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string x;
        cin >> x;
        s[x]++;
    }
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        string x;
        cin >> x;
        s[x] --;
    }

    int ans=0;

    for (auto itr = s.begin(); itr != s.end(); itr++)
    {
        ans = max(ans,s[itr->first]);
    }
    
    cout << ans << endl;

    return 0;
}


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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    auto n = load<int>();
    auto reward = loadMany<int>(n);
    auto dyn = array<vector<vector<long long>>, 2>{
        vector<vector<long long>>(n+1, vector<long long>(n+1)),
        vector<vector<long long>>(n+1, vector<long long>(n+1))
    };
    for (auto i=0; i<n; ++i)
        dyn[0][i][i] = 0ll, dyn[1][i][i] = 0ll;
    for (auto l=1; l<=n; ++l) {
        for (auto i=0; i+l<=n; ++i) {
            dyn[0][i][i+l] = max(
                reward[i] + dyn[1][i+1][i+l],
                reward[i+l-1] + dyn[1][i][i+l-1]
            );
            dyn[1][i][i+l] = min(
                dyn[0][i+1][i+l] - reward[i],
                dyn[0][i][i+l-1] - reward[i+l-1]
            );
        }
    }
    cout << dyn[0][0][n] << '\n';
}


Measured memory_bytes: 141184
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

temp = [T-i*0.006 for i in H]

ans = 0
mindt = 100000
for i in range(N):
    if abs(A-temp[i])<mindt:
        ans=i+1
        mindt=abs(A-temp[i])
        
print(ans)

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

int main(){
    int n;
    std::cin >> n;
    std::string s;
    std::cin >> s;
    long long int count = 0;

    std::vector<long long int> rgbCount(3);
    for (auto& rgb : s)
    {
        if (rgb == 'R')
        {
            ++rgbCount[0];
        }
        else if (rgb == 'B')
        {
            ++rgbCount[1];
        }
        else
        {
            ++rgbCount[2];
        }
    }

    for (int i = 1; i <= n; ++i)
    {
        for (int j = i + 1; j <= n; ++j)
        {
            int k = 2 * j - i;
            if (k > n)
            {
                continue;
            }
            if (s[i - 1] == s[j - 1])
            {
                continue;
            }
            else if (s[j - 1] == s[k - 1])
            {
                continue;
            }
            else if (s[k - 1] == s[i - 1])
            {
                continue;
            }
            ++count;
        }
    }
    std::cout << rgbCount[0] * rgbCount[1] * rgbCount[2] - count << std::endl;
    return 0;
}

Measured memory_bytes: 3616