akhauriyash/Code-Regression huggingface dataset:
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}
int x = 0, y = 0, z = 0,n = 0;
asas;
cncn;
//BEGIN OF CODE.
int main(void){
	int a, b;
	cin >> a >> b;
	if ((a * b) % 2 == 0) {
		cout << "Even" << rt;
	}
	else cout << "Odd" << rt;
	please AC;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;



int main()
{
    string oioi = "";
    string ioio = "";

    for (int i = 0; i < 50001; i++)
    {
        oioi += "01";
        ioio += "10";
    }

    string S;
    
    cin >> S;

    int len = int(S.length());

    string oioi_p = oioi.substr(0, len);
    string ioio_p = ioio.substr(0, len);

    int oi_c = 0;
    int io_c = 0;

    for (int i = 0; i < len; i++)
    {
        if (S[i] == oioi_p[i])
        {
            oi_c += 1;
        }
        else if (S[i] == ioio_p[i])
        {
            io_c += 1;
        }
    }
    cout << min(oi_c, io_c) << endl;
}

Measured memory_bytes: 896
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

x = int(input())

while True:
    if is_prime(x):
        break
    x += 1

print(x)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String pre = "";
		String str = "";
		String ans = "Yes";

		for (int i = 0; i < n; i++) {
			str = sc.next();
			if (i > 0 && (!pre.substring(pre.length() - 2, pre.length() - 1).equals(str.substring(0, 1))
					|| pre.contains("*" + str + "*"))) {
				ans = "No";
			} else {
				pre += "*" + str + "*";
			}
		}

		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
const int INF=100100100;
int main(){
  int n, m;
  cin >> n >> m;
  
  vector<vector<int>> to(n);
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    a--,b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  
  vector<int> dist(n,INF);
  dist[0]=0;
  vector<int> pre(n, -1);
  queue<int> q;
  q.push(0);
  
  while(!q.empty()){
    int v = q.front(); q.pop();
    for(int u : to[v]){
      if(dist[u]!=INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
   
    cout << "Yes" << endl;
  for(int i=1; i<n; i++){
    cout << pre[i]+1 << endl;
  }
    return 0;
  }

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

int main(){
    string S, T;
    cin >> S >> T;

    bool ans = false;
    for(int i=0;i<S.size();i++){
        if(S[i] == T[0]){
            bool flag = true;
            for(int j=i;j<S.size()+i;j++){
                if(S[j%S.size()] != T[j-i]){
                    flag = false;
                    break;
                }
            }

            if(flag){
                ans = true;
                break;
            }
        }
    }

    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
a=[]
for i in range(3):
  a1,a2,a3=map(int,input().split())
  a.append(a1)
  a.append(a2)
  a.append(a3)
n=int(input())
for i in range(n):
  b=int(input())
  for j in range(9):
    if a[j]==b:
      a[j]=0
if a[0]==0 and a[1]==0 and a[2]==0:
  print("Yes")
elif a[3]==0 and a[4]==0 and a[5]==0:
  print("Yes")
elif a[6]==0 and a[7]==0 and a[8]==0:
  print("Yes")
elif a[0]==0 and a[3]==0 and a[6]==0:
  print("Yes")
elif a[1]==0 and a[4]==0 and a[7]==0:
  print("Yes")
elif a[2]==0 and a[5]==0 and a[8]==0:
  print("Yes")
elif a[0]==0 and a[4]==0 and a[8]==0:
  print("Yes")
elif a[2]==0 and a[4]==0 and a[6]==0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int N,A,B,C;

void dfs(int n,int x,int y, vector<int> &ans,int a, int b, int c, vector<int> &l) {
  if (n == N) {
    if (a == 0 || b == 0 || c == 0) return;
    y += abs(A - a) + abs(B - b) + abs(C - c);
    ans[x] = y;
    return;
  }
  dfs(n+1, x*4+0, y, ans, a, b, c, l);
  dfs(n+1, x*4+1, y+10, ans, a+l[n], b, c, l);
  dfs(n+1, x*4+2, y+10, ans, a, b+l[n], c, l);
  dfs(n+1, x*4+3, y+10, ans, a, b, c+l[n], l);

  return;

}
int main() {
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  rep(i,N) cin >> l[i];
  vector<int> ans(100000,1e9);

  dfs(0,0,-30,ans,0,0,0,l);

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

  cout << ans[0] << endl; 
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define PI 3.14159265358979323846
ll N;
pll yxv[111];
vector<pair<double, ll>> rv;

double ans;
ll i, j, k;
int main(){
    scanf("%lld",&N);
    fornum(i,0,N){
        ll x,y,xi,yi;
        scanf("%lld%lld", &x, &y);
        yxv[i] = {y, x};
        rv.push_back({atan2(y, x), i});
    }
    sort(rv.begin(), rv.end());
    
    j = 0;
    fornum(i,0,N){
        pll yx = {0,0};

        fornum(j, 0,N){
            ll jj = rv[(i+j) % N].second;
            yx.first += yxv[jj].first;
            yx.second += yxv[jj].second;
            double aa = (double)yx.first * yx.first + (double)yx.second * yx.second;
            if(aa>ans){
                ans = aa;
            }
        }
    }
    printf("%.12lf", sqrt(ans));

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  long a,b,n,ans=0,cnt=0;
  while(scanf("%d %d",&a,&b)!=EOF){
    n=a+b;
    if( cnt > 200 ) break;
    while(n>0){
      n/=10;
      ans++;
    }
    cnt++;
    printf("%d\n",ans);
    ans=0;
  }
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  int count = 0;
  int N = S.size();
  
  for(int i=0; i<N; i+=2){
    if(S.at(i)=='R'||S.at(i)=='U'||S.at(i)=='D'){
      count++;
    }
  }
  for(int i=1; i<N; i+=2){
    if(S.at(i)=='L'||S.at(i)=='U'||S.at(i)=='D'){
      count++;
    }
  }
  
  if(count == N){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
    // Input
    char S[3]; scanf("%s",&S[0]);
    // Output
    int T[3] = {S[0], S[1], S[2]}, check = 0;

    sort(T, T + 3);
    if (T[0] < T[1] && T[1] < T[2]) check = 1;

    printf("%s\n", check ? "Yes" : "No");
    return 0;
}

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

int main() {
    
    string s,t;
    int co=0;

    cin>>s>>t;

    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i])  co++;
    }

    cout<<co<<endl;

    return 0;
}

Measured memory_bytes: 3900
import sys
from random import randint
from datetime import datetime

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())) for _ in range(n)]

def randomize(n):
    return [ randint(1, 26) for _ in range(n) ]

def get_now():
    dt = datetime.now()
    return dt.second + dt.microsecond/1000000

def main():
    start = get_now()
    end = get_now()
    # 開催日数
    D = ii()
    # 満足度の下がりやすさ
    C = lmi()
    # 得られる満足度
    S = lmif(D)
    # 最後に開かれた日付
    last = [0]*26
    # 開催するコンテスト
    T = [ i%26+1 for i in range(D) ]

    def scoring():
        score = 0
        for i in range(D):
            score += S[i][T[i]-1]
            for j in range(26):
                score -= C[j] * (i - last[j])
        return score

    max_score = 0
    ans = T.copy()
    while end - start < 1.95:
        idx, value = randint(0, D-1), randint(1, 26)
        old = T[idx]
        T[idx] = value
        score = scoring()
        if max_score < score:
            ans = T.copy()
            max_score = score
        else:
            T[idx] = old
        # print(*T, score, max_score)
        end = get_now()
    print(*ans, sep='\n')

main()


Measured memory_bytes: 9952
import sys

input = sys.stdin.readline
n, k = map(int, input().split())
h_list = []
for _ in range(n):
    h = int(input())
    h_list.append(h)
h_list.sort()
ans = 10**9
for i in range(n-k+1):
    ans = min(ans, h_list[i+k-1]-h_list[i])
print(ans)


Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
bool f(int* a, int n, int m)
{
    int t=n, i;
    while(*(a+t)==m)
    {
    t--;
    if(t<=0)
    break;
    }
    if(t<=0)
    return false;
    else
    {
    *(a+t)+=1;
    for(i=t+1;i<=n;i++)
    *(a+i)=*(a+t);
    return true;
    }
}
int main() {
    
    int n, m, q, a[100], i, b[100], c[100], d[100], ma=0, dap[11]={}, imsidap;
    cin>>n>>m>>q;
    for(i=1;i<=q;i++)
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    
    for(i=1;i<=n;i++)
    dap[i]=1;
    imsidap=0;
     for(i=1;i<=q;i++)
        {
            imsidap+=d[i]*(dap[b[i]]-dap[a[i]]==c[i]);
        }
        
        
        if(imsidap>ma)
        ma=imsidap;
    while(f(dap, n, m))
    {
        imsidap=0;
        
        for(i=1;i<=q;i++)
        {
            imsidap+=d[i]*(dap[b[i]]-dap[a[i]]==c[i]);
        }
        
        
        if(imsidap>ma)
        ma=imsidap;
    }
    
    
    
    
    
    
    
    cout<<ma;
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main()
{
  int x, y;   //two natural numbers
  int temp, r;   //Variable to store temporarily

  //input of two natural numbers
  scanf("%d%d", &x, &y);

  //error processing
  if( 1 > x || x > 1000000000 || 1 > y || y > 1000000000 ) printf("範囲外です。\n");

  else{
    if( x < y ){
      temp = x;
      x = y;
      y = temp;
    }

    //Use euclidean algorithm
    while( ( r = x % y ) != 0 ){
      x = y;
      y = r;
    }
    printf("%d\n", y);
  }

  return 0;
}

Measured memory_bytes: 592
import sys
input = sys.stdin.readline

def main():
    X, Y = map(int, input().split())
    t = X + Y
    MOD = int(1e9) + 7
    
    if t%3 != 0:
        print(0)
        return
    
    kai = [1] * (1 + (X + Y) // 3)
    for i in range(1, len(kai)):
        kai[i] = (kai[i-1] * i) % MOD

    t //= 3
    ans = 0
    for a in range(t+1):
        if (X - a) % 2 == 0 and (X - a)//2 == Y - 2*a:
            b = Y - 2*a
            ans += kai[a+b] * pow(kai[a], MOD-2, MOD) * pow(kai[b], MOD-2, MOD)
            ans %= MOD
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 29300
import java.util.Arrays;
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		long ans = 0;

		int o = a*x + b*y;			//各ピザ

		int mi = Math.min(x, y);
		int ma = Math.max(x, y);
		int oo = 0;
		if(mi == x){
			oo = 2*c*mi +b*(ma-mi); 
		}else{
			oo = 2*c*mi +a*(ma-mi); 
		}
		int ooo = 2*c*ma;
		int[] data = {o,oo,ooo};
		Arrays.sort(data);
		
		System.out.println(data[0]);


	}





}

class UnionFind{
	int[] parent;
	public UnionFind(int N){
		this.parent = new int[N];
		for(int i = 0; i < N;i++){
			parent[i] = i;
		}
	}
	public int root(int x){			//根要素を取得
		if(parent[x] == x){			//初期状態
			return x;
		}else{
			return parent[x] = root(parent[x]);    	//再帰によって根を取得
		}
	}
	public void unite(int x,int y){ 	//統合メソッド
		if(same(x,y)){					//同じ根なら終了
			return;
		}
		int xroot = root(x);
		int yroot = root(y);
		parent[xroot] = yroot;			//統合
		return;

	}

	public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
		return(root(x) == root(y));
	}
}



class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	string s;
	cin>>s;
	for(int i=0;i<3;i++)
	    if(s[i]==s[i+1]){ cout<<"Bad"; return 0; }
	cout<<"Good";    
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node
{
    int key;
    Node *right, *left, *parent;
};

Node *NIL, *root;

void insert(int key){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = key;
    z->left = NIL;
    z->right = NIL;
    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    z->parent = y;

    if (y == NIL)
    {
        root = z;
    }
    else {
        if (z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
        
    }
}

void find(int x){
    Node *y = root;
    while (y != NIL)
    {
        if (x == y->key )
        {
            cout << "yes" << endl;
            return;
        }
        else if (y->key < x)
        {
            y = y->right;
        }
        else
        {
            y = y->left;
        }
    }
    cout << "no" << endl;
    
}
void preorder(Node *root){
    if(root == NIL) return;
    cout << " " << root -> key;
    preorder(root->left);
    preorder(root->right);
}

void Inorder(Node *root){
    if(root == NIL) return;
    Inorder(root->left);
    cout << " " << root -> key;
    Inorder(root->right);
}

int main(){
    int n, key;
    string com;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> com;
        if (com[0] == 'i')
        {
            cin >> key;
            insert(key);
        }
        else if (com[0] == 'f')
        {
            cin >> key;
            find(key);
        }
        
        else
        {
            Inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
        
    }
    

}


Measured memory_bytes: 21912
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

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

  ll ans = 1LL<<59;
  for(int bit = 0; bit < (1<<n); bit++){
    ll now = a[0], money = 0;
    int cnt = 1;
    for(int i = 1; i < n; i++){
      if((bit>>i)&1){
        cnt++;
        if(now < a[i]){
          now = a[i];
        }else{
          money += now - a[i] + 1;
          now++;
        }
      }else{
        if(now < a[i]){
          now = a[i];
        }
      }
    }
    if(cnt == k) ans = min(ans, money);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

char a,b;
inline void solve(){
  IN2(a,b);
  OUT(a==b?"H":"D");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

int main(){
	int N;
	cin >> N;
	string W[N];
	cin >> W[0];

	for (int i = 1; i < N; i++) {
		cin >> W[i];
		if (W[i-1].back() != W[i].front()) {
			cout << "No" << endl;
			return 0;
		}
		rep(j,i) {
			if (W[i] == W[j]) {
			cout << "No" << endl;
			return 0;
			}
		}
	}
	
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll N , A , B ;
  cin >> N >>  A >> B;
  if(A > B) {
    cout << 0 << endl;
    return 0;
  }
  if(A==B){
    cout << 1 << endl;
    return 0;
  }
  if(N == 1){
    cout << 0 << endl;
    return 0;
  }
  cout <<  (A+(N-1)*B)-(B+(N-1)*A)+1 << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)

#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 6;

int n,a[maxn] , b[maxn];

bool IsMan(int x){
    x += n;
    x %= n;
    cout << x << endl;
    string s;
    cin >> s;
    if(s[0] == 'V'){
        exit(0);
    }
    return s[0] == 'M';
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    if(fopen(taskname".INP","r")){
//		freopen(taskname".INP", "r",stdin);
//		freopen(taskname".OUT", "w",stdout);
//    }
    cin >> n;
    int l = 0 , h = n / 2;
    bool first = IsMan(0);
    while(l <= h){
        int mid = l + h >> 1;
        if(IsMan(mid * 2) == first)l = mid + 1;
        else h = mid - 1;
    }
    l *= 2;
    IsMan(l + 1);
    IsMan(l - 1);
}



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

struct	QS {
	long L=0;
	long R=0;
};

int     main() {
	string	S;
	cin >>S;
	int N=S.size();
	vector<long> P3(N+1);
	P3.at(0)=1;
	for (int i=1; i<=N; i++) 
		P3.at(i)=(P3.at(i-1)*3)%1000000007;
	// Q
	vector<QS> Q(N);
	Q.at(0).L=0;
	for (int i=1; i<N; i++) {
		Q.at(i).L=Q.at(i-1).L;
		if ('?'==S.at(i-1)) Q.at(i).L++;
	}
	Q.at(N-1).R=0;
	for (int i=N-2; i>=0; i--) {
		Q.at(i).R=Q.at(i+1).R;
		if ('?'==S.at(i+1)) Q.at(i).R++;
	}
	// A
	vector<int> A(N, 0);
	A.at(0)=0;
	for (int i=1; i<N; i++) {
		A.at(i)=A.at(i-1);
		if ('A'==S.at(i-1)) A.at(i)++;
	}
	// C
	vector<int> C(N, 0);
	C.at(N-1)=0;
	for (int i=N-2; 0<=i; i--) {
		C.at(i)=C.at(i+1);
		if ('C'==S.at(i+1)) C.at(i)++;
	}
	long SSS=0;
	for (int i=1; i<N-1; i++) {
		if ('A'==S.at(i)) continue;
		if ('C'==S.at(i)) continue;
		long LL = A.at(i)*P3.at(Q.at(i).L);
		LL %= 1000000007;
		if (Q.at(i).L>0) {
			LL += Q.at(i).L * P3.at(Q.at(i).L-1);
			LL %= 1000000007;
		}
		long RR = C.at(i)*P3.at(Q.at(i).R);
		RR %= 1000000007;
		if (Q.at(i).R>0) {
			RR += Q.at(i).R * P3.at(Q.at(i).R-1);
			RR %= 1000000007;
		}
		SSS += (LL*RR)%1000000007;
		SSS %= 1000000007;
	}
	cout << SSS << endl;
	return 0;
};


Measured memory_bytes: 3584
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: [usize; 5],
        k: usize
    }

    if a[4] - a[0] > k {
        println!(":(");
    } else {
        println!("Yay!");
    }
}


Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x,0))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

in COM(int x){
  in y =(in)(x);
  in ret=y*(y-1ll)/2ll;
  return ret;
}

int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
  cin>>n;
  vector<vector<char>> a(n,vector<char>(10));
  rep(i,n)rep(j,10) cin>>a[i][j];
  rep(i,n) sort(all(a[i]));
  sort(all(a));
  //vector<int> c(0);
  int i=0;
  int cnt=0;
  in ans=0ll;
  while(i<n-1){
     if(a[i]==a[i+1]){
     	cnt ++;
     } 
    else if(cnt){
      ans +=COM(cnt+1); 
      //c.push_back(cnt+1);
      cnt =0;
    }
    i ++;
  }
  if(cnt) ans +=COM(cnt+1);
 //n=c.size();
  //in ans=0ll;
  //rep(j,n) ans +=COM(c[j]);
  //rep(i,n) cout<<c[i]<<endl;
  cout<<ans<<endl;
  //rep(j,3){rep(i,10) cout<<a[j][i];cout<<endl;}
}


Measured memory_bytes: 8832
import java.util.Scanner;

import com.sun.org.apache.xpath.internal.operations.Equals;

class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		String S = scan.next();
		
		if(S.equals("SUN")){
			System.out.println("7");
		}else if(S.equals("MON")){
			System.out.println("6");
		}else if(S.equals("TUE")){
			System.out.println("5");
		}else if(S.equals("WED")){
			System.out.println("4");
		}else if(S.equals("THU")){
			System.out.println("3");
		}else if(S.equals("FRI")){
			System.out.println("2");
		}else if(S.equals("SAT")){
			System.out.println(1);
		}
		

	}

}


Measured memory_bytes: 21332
using System;
using System.Linq;
using System.Collections.Generic;

public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = input[0];
        var M = input[1];
        var s = Console.ReadLine();
        var ans = new int[100001];
        for(var i = 0;i < s.Length - 1;i++){
            if(s.Substring(i,2) == "AC"){
                ans[i + 1] = 1 + ans[i];
            }else{
                ans[i + 1] = ans[i]; 
            }
        }

        
        for(var i = 0;i < M;i++){
            var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = line[0];
            var b = line[1];
            
            Console.WriteLine(ans[b - 1] - ans[a - 1]) ;
        }
        
    }
}


Measured memory_bytes: 18612
#include <iostream>
#include <queue>
//#include <vector>
//#include <map>
//#include <algorithm>
using namespace std;
int N,M,A[1000007];
//vector<int> l;
//map<int,int> m;
priority_queue<int> q;
int main(void){
    cin >> N >> M;
    long long allsum=0,count=0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        allsum += A[i];
        int k = A[i];
        while(k>0){
            //m[k-k/2]+=1;
            //l.push_back(k-k/2);
            q.push(k-k/2);
            count++;
            k = k/2;
        }
    }
    //sort(l.begin(), l.end(), greater<int>());
    long long sum=0, c=0;
    //for(int i=0; i<M&&i<count; i++){
    //    sum += l[i];
    for(int i=0; i<M && i<count; i++){
        sum += q.top(); q.pop();
    }
    cout << allsum-sum << "\n";
}

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

int main() {
	int N,L;
    cin >> N >> L;
    vector<string> a(N);
    for(int i=0;i<N;i++){
      cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    for(int i=0;i<N;i++){
      cout << a.at(i);
    }
    cout << endl;
}


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

using namespace std;


int main(){
	long long int N, Q;
	cin >> N >> Q;
	auto now = vector<long long int>(N, 1);
	string S;
	cin >> S;

	vector<pair<char, char>>Query(Q);
	for( size_t i = 0; i < Q; i++ ){
		cin >> Query[i].first >> Query[i].second;
	}
	long long int begin = -1, end = N;
	for( auto now = Query.rbegin(); now < Query.rend(); now++ ){
		auto ope = *now;
		if( 0 <= begin + 1 && begin + 1 < N&& ope.first == S[begin + 1] && ope.second == 'L' ){
			begin++;
		} else if( 0 <= begin && begin < N&&  ope.first == S[begin] && ope.second == 'R' ){
			begin--;
		}

		if( 0 <= end && end < N&& ope.first == S[end] && ope.second == 'L' ){
			end++;
		} else if( 0 <= end - 1 && end - 1 < N&&  ope.first == S[end - 1] && ope.second == 'R' ){
			end--;
		}
		if( begin + 1 == end ){
			break;
		}
	//cout << begin << " " << end << endl;
	}
	cout << end - begin - 1 << endl;
}


Measured memory_bytes: 2564
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int[] nums = sc.IntArray();

        nums = nums.OrderBy(i => i).ToArray();

        int answer = nums[2] - nums[0];

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <math.h>
using namespace std;
 
int main(){
    double glam;
    while(cin>>glam){
        if(glam<=48.0)cout<<"light fly"<<endl;
        else if(glam>48.0&&glam<=51.0)cout<<"fly"<<endl;
        else if(glam>51.0&&glam<=54.0)cout<<"bantam"<<endl;
        else if(glam>54.0&&glam<=57.0)cout<<"feather"<<endl;
        else if(glam>57.0&&glam<=60.0)cout<<"light"<<endl;
        else if(glam>60.0&&glam<=64.0)cout<<"light welter"<<endl;
        else if(glam>64.0&&glam<=69.0)cout<<"welter"<<endl;
        else if(glam>69.0&&glam<=75.0)cout<<"light middle"<<endl;
        else if(glam>75.0&&glam<=81.0)cout<<"middle"<<endl;
        else if(glam>81.0&&glam<=91.0)cout<<"light heavy"<<endl;
        else cout<<"heavy"<<endl;
    }
}

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

clues = [tuple(map(int, input().split()))
         for _i in range(n)]
good_clue = next(clue for clue in clues if clue[2] > 0)

centers = [(x, y)
           for x in range(101)
           for y in range(101)]
for cx, cy in centers:
    ch = good_clue[2] \
         + abs(good_clue[0] - cx) \
         + abs(good_clue[1] - cy)

    if all(h == max(ch - abs(x - cx) - abs(y - cy), 0)
           for x, y, h in clues):
        print(cx, cy, ch)
        break

Measured memory_bytes: 3700
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;

int main(void) {
    vector<ll> vec;
    ll n, y;
    ll i, j, k;
    cin >> n >> y;
    for(i=0; i<=min(y/1000, n); i++)
            vec.push_back(1000*i);

    sort(vec.begin(), vec.end());
    for(i=0; i<=min(y/10000, n); i++) {
        for(j=0; j<=min(y/5000, n); j++) {
            if(binary_search(vec.begin(), vec.end(), y-10000*i-5000*j) && i+j+(y-10000*i-5000*j)/1000==n) {
                printf("%lld %lld %lld", i, j, (y-10000*i-5000*j)/1000);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
}


Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define vp vector<P>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
const int mod = 1e9+7;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

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

//cout << fixed << setprecision(10) << y << endl;
struct edge {int to, cost;};
vector< vector<edge> > es;
const int MAX_N = 10010;

int main() {
    int n;
    cin >> n;
    vi A(n), B(n);
    REP(i, n) {
        cin >> A[i] >> B[i];
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (n % 2) {
        int a_mid = A[(n+1)/2-1];
        int b_mid = B[(n+1)/2-1];
        int ans = b_mid-a_mid+1;
        cout << ans << endl;
    } else {
        int a_mid = (A[n/2-1]+A[n/2]);
        int b_mid = (B[n/2-1]+B[n/2]);
        int ans = b_mid-a_mid+1;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4800
#include <stdio.h>
int n, p[21], i;
int main(void)
{
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
    }
    int ans;
    for (i = 1; i <= n - 2; i++)
    {
        if (p[i] < p[i - 1] && p[i] > p[i + 1] || p[i] < p[i + 1] && p[i] > p[i - 1])
        {
            ans += 1;
        }
    }
    printf("%d",ans);
    return 0;
}

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

int main(){
  int n,K;
  cin >> n >> K;
  vector<long> x(n),y(n);
  for(int i = 0;i < n;i++){
    cin >> x.at(i) >> y.at(i);
  }
  /*int common[n][n],common2[n][n],left[n],under[n];
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      common[i][j] = 0;
      common2[i][j] = 0;
      left[i] = 0;
      under[j] = 0;
    }
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      for(int k = 0;k < n;k++){
        if(x.at(k) < x.at(i) && y.at(k) < y.at(j)){
          common[i][j] += 1;
        }
      }
    }
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      for(int k = 0;k < n;k++){
        if(x.at(k) <= x.at(i) && y.at(k) <= y.at(j)){
          common2[i][j] += 1;
        }
      }
    }
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(x.at(j) < x.at(i)){
        left[i]++;
      }
    }
  }
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      if(y.at(j) < y.at(i)){
        under[i]++;
      }
    }
  }*/
  long result = 4000000000000000000;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < n;j++){
      for(int k = 0;k < n;k++){
        for(int l = 0;l < n;l++){
          int num = 0;
          for(int m = 0;m < n;m++){
            if(x.at(m) <= x.at(l) && x.at(m) >= x.at(k) && y.at(m) <= y.at(i) && y.at(m) >= y.at(j)){
              num++;
            }
          }
          if(num >= K && x.at(k) <= x.at(l) && y.at(j) <= y.at(i)){
            long area = (x.at(l) - x.at(k)) * (y.at(i) - y.at(j)); 
            //cout << num << ' ' << area << ' ' << y.at(i) << ' ' << y.at(j) << ' ' << x.at(k) << ' ' << x.at(l) << endl;
            //cout << "info" << common2[l][i] << ' ' << left[k] << ' ' << under[j] << ' ' << common[k][j] << endl;
            result = min(result,area);
          }
        }
      }
    }
  }
  cout << result << endl;
}


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

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 100005;

int n, m;
int f[N], t[N], c[N];
bool ok[N];
int res;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		c[i] = 1;
	ok[0] = 1;
	for (int i = 0; i < m; i++) {
		cin >> f[i] >> t[i];
		f[i]--, t[i]--;
		c[f[i]]--;
		c[t[i]]++;
		if (ok[f[i]]) {
			ok[t[i]] = 1;
			if (c[f[i]] == 0)
				ok[f[i]] = 0;
		}
	}
	for (int i = 0; i < n; i++)
		res += ok[i];
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>

int main()
{
  int aa, bb, cc, dd, ii = 0;
  scanf("%d %d %d %d", &aa, &bb, &cc, &dd);
  while(1)
  {
    ii++;
    if(cc <= ii * bb)
    {
      puts("Yes");
      return 0;
    }
    else if(aa <= ii * dd)
    {
      puts("No");
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1616
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
 
#define MAXN (100000)
#define MOD (1000000007)
 
uint64_t dp[61][2][2][2];
 
int main(void)
{
    uint64_t l,r,ans;
    scanf("%ld %ld",&l, &r);
    dp[60][0][0][0] = 1;
    for(int i=59;i>=0;i--)
    {
        int lb = (l>>i)&1;
        int rb = (r>>i)&1;
        for(int j=0;j<2;j++)for(int k=0;k<2;k++)for(int s=0;s<2;s++)
        {
            for(int x=0;x<2;x++)for(int y=0;y<2;y++)
            {
                int nj = j, nk = k, ns = s;
                if(x && !y) continue;
                if(!s && (x!=y)) continue;
                if(!s &&  x && y) ns = 1;
                if(!j && !x && lb) continue;
                if(!j && x && !lb) nj = 1;
                if(!k && y && !rb) continue;
                if(!k && !y && rb) nk = 1;
 
                dp[i][nj][nk][ns] += dp[i+1][j][k][s];
                dp[i][nj][nk][ns] %= MOD;
            }
        }
 
    }
    ans = 0;
    for(int j=0;j<2;j++)for(int k=0;k<2;k++)for(int s=0;s<2;s++)
    {
        ans = (ans + dp[0][j][k][s])%MOD;
    }
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
    int m,n,i,j;
    int a[100][100];
    int b[100];
    int c=0;
    scanf("%d %d", &m, &n);
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            scanf(" %d", &a[i][j]);
            //printf("%d ", a[i][j]);
        }
        //printf("\n");
    }
    for(i = 0; i < n; i++){
        scanf(" %d", &b[i]);
        //printf("%d\n", b[i]);
    }
    for(i = 0; i < m; i++, c=0){
        for(j=0;j<n; j++){
            c+=a[i][j]*b[j];
        }
        printf("%d\n", c);
    }
    return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int par[222222];
int dp[222222];
const int INF=int(1e9);
set<int> a[222222];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	string s; cin>>s;
	dp[n]=0;
	set<int> S; S.insert(n);
	a[0].insert(n);
	for(int i=n-1;i>=0;i--)
	{
		dp[i]=INF;
		if(s[i]=='1') continue;
		auto it = S.upper_bound(i+m);
		if(it==S.begin()) continue;
		it--;
		dp[i]=dp[(*it)]+1;
		a[dp[i]].insert(i);
		S.insert(i);
	}
	if(dp[0]>=INF){cout<<-1<<'\n'; return 0;}
	int cur=0;
	vi v;
	while(cur!=n)
	{
		int d = dp[cur];
		auto it = a[d-1].lower_bound(cur);
		v.pb((*it)-cur);
		cur=(*it);
	}
	for(int i=0;i<v.size();i++)
	{
		cout<<v[i];
		if(i+1<v.size()) cout<<' ';
	}
	cout<<'\n';
}


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

using namespace std;

const int maxn = 1e5 + 10;
char s[maxn];

int main()
{
  int n, k, a, b, c;
  scanf("%d%d", &n, &k);
  scanf("%d%d%d", &a, &b, &c);
  scanf("%s", s + 1);
  long long res = 0;
  for(int i = 1; i <= k; i ++)
  {
    char las = s[i];
	int cnt = 1;
    for(int j = i + k; j <= n; j += k)
    {
      if(s[j] == las) 
      {
        las = s[j];
		cnt ++;
        continue;
      }
      if(las == 'r') res += 1ll * c * ((cnt + 1) / 2);
      else if(las == 's') res += 1ll * a * ((cnt + 1) / 2);
      else if(las == 'p') res += 1ll * b * ((cnt + 1) / 2);
	  cnt = 1;
	  las = s[j];
    }
      if(las == 'r') res += 1ll * c * ((cnt + 1) / 2);
      else if(las == 's') res += 1ll * a * ((cnt + 1) / 2);
      else if(las == 'p') res += 1ll * b * ((cnt + 1) / 2);
  }
  printf("%lld\n", res);
  return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

ll dp[20005][256];

ll sqr(ll x) { return x * x; }

int main() {
    rep(i, 0, 256) dp[0][i] = 0x3f3f3f3f3f3f3f3fll;
    dp[0][128] = 0;
    for (;;) {
        int n, m; cin >> n >> m; if (!n) break;
        // reset dp matrix
        rep(i, 1, n + 1) rep(j, 0, 256) dp[i][j] = 0x3f3f3f3f3f3f3f3fll;
        vector<int> sig(n + 1);
        vector<int> diff(m);
        rep(i, 0, m) cin >> diff[i];
        rep(i, 1, n + 1) cin >> sig[i];
        rep(i, 1, n + 1) {
            rep(j, 0, m) {
                rep(k, 0, 256) {
                    int nv = k + diff[j];
                    if (nv < 0) nv = 0;
                    if (nv > 255) nv = 255;
                    dp[i][nv] = min(dp[i][nv], dp[i - 1][k] + sqr(nv - sig[i]));
                }
            }
        }
        ll ans = 0x3f3f3f3f3f3f3f3fll;
        rep(i, 0, 256) ans = min(ans, dp[n][i]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 43160
N,M=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(N)]
s=0
for j in [1,-1]:
    for k in [1,-1]:
        for m in [1,-1]:
            l=sorted(l,key=lambda x:(x[0]*j+x[1]*k+x[2]*m))[::-1]
            a=abs(sum([i[0] for i in l[:M]]))
            b=abs(sum([i[1] for i in l[:M]]))
            c=abs(sum([i[2] for i in l[:M]]))
            s=max(s,a+b+c)
print(s)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {

int a,b;
cin >> a>>b;
  int k=0;
vector<int> vec(b);
for (int i = 0; i < b; i++) {
  cin >> vec.at(i);
}
  int j=0;
while(j<b){k=k+vec.at(j);
          j++;} 
int o;
  o=a-k;
if(o>=0){cout<<o<<endl;}
  else{cout<<"-1"<<endl;}
}

Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 305
using namespace std;
bool debug=false;

int d[12][12];

void init(){
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(i==j) d[i][j]=0;
      else d[i][j]=INF;
    }
  }
}

void make(int n){
  int a,b,c;
  for(int i=0;i<n;i++){
    cin>>a>>b>>c;
    d[a][b]=c;d[b][a]=c;
  }
}

void wf(){
  for(int k=0;k<10;k++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
}

void solve(){
  int mini=INF,num;
  for(int i=0;i<=10;i++){
    int sum=0;
    for(int j=0;j<=10;j++){
      if(d[i][j]!=INF)sum+=d[i][j];
    }
    if(sum<mini&&sum!=0){
      mini=sum;
      num=i;
    }
  }
  cout<<num<<" "<<mini<<endl;
}

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    init();
    make(n);
    wf();
    solve();
  }
  return 0;
}

Measured memory_bytes: 3076
x = raw_input().split()
for i in range(2):
    if float(x[i]) > float(x[i+1]):
        x[i],x[i+1]=x[i+1], x[i]
    if float(x[0]) > float(x[1]):
        x[0],x[1]=x[1], x[0]
print " ".join(x)

Measured memory_bytes: 6328