akhauriyash/Code-Regression huggingface dataset:
class Dice(list):
    def __init__(self, *args):
        super().__init__(*args)
        tmp = self[::]
        self._fix_position()
        self.hash = hash(tuple(self))
        self[::] = tmp

    def roll(self, command):
        if command == 'N':
            self[0], self[1], self[5], self[4] = self[1], self[5], self[4], self[0]
        elif command == 'S':
            self[0], self[1], self[5], self[4] = self[4], self[0], self[1], self[5]
        elif command == 'W':
            self[0], self[3], self[5], self[2] = self[2], self[0], self[3], self[5]
        elif command == 'E':
            self[0], self[3], self[5], self[2] = self[3], self[5], self[2], self[0]

    def spin(self, repeat=1):
        for _ in range(repeat):
            self[3], self[1], self[2], self[4] = self[1], self[2], self[4], self[3]

    def _fix_position(self):
        self._min_num_to_top()
        self._min_side_num_to_front()

    def _min_num_to_top(self):
        idx = self.index(min(self))
        if idx == 0:
            pass
        elif idx == 1:
            self.roll('N')
        elif idx == 2:
            self.roll('W')
        elif idx == 3:
            self.roll('E')
        elif idx == 4:
            self.roll('S')
        elif idx == 5:
            self.roll('N')
            self.roll('N')

    def _min_side_num_to_front(self):
        idx = self.index(min(self[3], self[1], self[2], self[4]))
        if idx == 1:
            pass
        elif idx == 2:
            self.spin(1)
        elif idx == 3:
            self.spin(3)
        elif idx == 4:
            self.spin(2)

    def __hash__(self):
        return self.hash

    def __eq__(self, other):
        return hash(self) == hash(other)


def solve():
    n = int(input())
    dices = set(Dice(map(int, input().split())) for _ in range(n))
    return 'Yes' if n == len(dices) else 'No'


if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 6828
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	int mx = -1;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			mx = max(mx, abs(A[i] - A[j]));
		}
	}
	cout << mx;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
    int n,x,y;
    ll a=1,b=1;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        ll mid=max(a/x,b/y);
        while(mid*x<a||mid*y<b)mid++;
        a=mid*x;
        b=mid*y;
    }
    cout<<a+b<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int N;
	cin >> N;

	int total_count = 0;
	for(int i=1;i<=N;i++){
		int count = 0;
		for(int j=1;j<=i;j++){
			if(i%j == 0){
				count ++;
			}
		}
		if(count==8 && i%2!=0){
			total_count++;
		}
	}

	cout << total_count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <vector>
#include <climits>
 
int main() {
	// your code goes here
  int n;
  cin>>n;
  vector<vector<int>> val(n , vector<int> (3 , 0));
  for(int i=0;i<n;i++){
    cin>>val[i][0]>>val[i][1]>>val[i][2];
    
  }
  vector<vector<int>> dp(n , vector<int> (3 , 0));
  
  dp[0][0]=val[0][0];
  dp[0][1]=val[0][1];
  dp[0][2]=val[0][2];
  for(int i=1;i<n;i++){
  	dp[i][0]=val[i][0]+max(dp[i-1][1],dp[i-1][2]);
  	dp[i][1]=val[i][1]+max(dp[i-1][0],dp[i-1][2]);
  	dp[i][2]=val[i][2]+max(dp[i-1][1],dp[i-1][0]);
  }
  cout<< max(max(dp[n-1][0],dp[n-1][2]),dp[n-1][1]);
  return 0;
	
}


Measured memory_bytes: 14028
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#define endl '\n'
using namespace std;
typedef long long int ll ;
const ll mod =1000000007;
ll pre[200005];
int main()
{
  string s;
  cin>>s;
  ll cnt1=0; ll cnt2=0;
    ll arr[s.size()+2]={0}; 
  for(int i=0;i<s.size()-1;i++)
  {
     if(s[i]=='R' && s[i+1]=='L'){
         
         cnt2=i+1;
         for(int j=i+1;j<s.size();j++){
             if(s[j]=='L') cnt2=j;
             else break;
         }
        //  cout<<cnt1<<" "<<cnt2<<endl;
         arr[i]+=(i-cnt1)/2; arr[i+1]+=(i-cnt1)/2;
         if((i-cnt1) % 2 ==1) arr[i+1]++; 
         arr[i]++; arr[i+1]++;
        //  cout<<"sd "<<arr[i]<<" "<<arr[i+1]<<endl;
         arr[i]+=(cnt2-i-1)/2;
         arr[i+1]+=(cnt2-i-1)/2;
         if((cnt2-i-1) % 2 ==1) arr[i]++;
         i=cnt2;
         cnt1=i+1;
        //  cout<<i<<endl;
         
     }
  }
  for(int i=0;i<s.size();i++) cout<<arr[i]<<" ";
    
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, arr[100001], a, out = 0, cnt = 0;
	cin >> n;
	fill(arr, arr + 100001, 0);
	for(int i=0; i<n; i++){
		cin >> a;
		arr[a]++;
	}
	for(int i=1; i<=1e5; i++){
		if(arr[i] == 1) out++;
		else if(arr[i] >= 2){
			if(arr[i]%2 == 0) cnt++;
			out++;
		}
	}
	if(cnt % 2) out--;
	cout << out;
}


Measured memory_bytes: 640
///IN THE NAME OF ALLAH
    #include<bits/stdc++.h>
    using namespace std;
    int Arr[20000],Arr2[20000];
    long long cnt,cnt2;
    int main(){
     int n;
     cin >> n;
     for(int i=0;i<n;i++)
       cin >> Arr[i];
     for(int i=0;i<n;i++)
       cin >> Arr2[i];
     for(int i=0;i<n;i++)
      if(Arr[i]<Arr2[i]){
       cnt+=(Arr2[i]-Arr[i])/2;
     }else if(Arr[i]>Arr2[i]) cnt+=(Arr2[i]-Arr[i]);
     //cout<<cnt2<<" "<<cnt<<endl;
     if(cnt>=0)
      cout<<"Yes";
     else cout<<"No";
    }


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
    int k,n;
    cin>>k>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int minn=999999999;
    for(int i=1;i<=n;i++){
        if(i==1){
            minn=min(minn,a[n]-a[1]);
        }
        minn=min(minn,a[i-1]+k-a[i]);
    }
    cout<<minn;
    return 0;
}


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

int main() {
    int64_t n;
    cin >> n;
    vector<pair<int64_t, int64_t>> p;
    for (auto& e : { 3, 2, 1 }) {
        for (int i = 0; i < n; i++) {
            int pp;
            cin >> pp;
            p.emplace_back(pp, e);
        }
    }
    sort(begin(p), end(p));
    int64_t a = 0, b = 0, c = 0;
    for (auto& e : p) {
        switch (e.second) {
        case 3:
            a++;
            break;
        case 2:
            b += a;
            break;
        case 1:
            c += b;
            break;
        }
    }
    cout << c << endl;
}


Measured memory_bytes: 10604
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
    if i % 2 == 0 and A[i] % 2 == 1:
        ans += 1
print(ans)

Measured memory_bytes: 10516
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
    Node *cur = nil->next;  // 番兵の次の要素からたどる
    while (cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList() {
    Node *cur = nil->next;
    int isf = 0;
    while (1){
        if (cur == nil) break;
        if (isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t) {
    if (t == nil) return;   // tが番兵の場合は処理しない
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst() {
    deleteNode(nil->next);
}

void deleteLast() {
    deleteNode(nil->prev);
}

void deleteKey(int key) {
    // 検索したノードを削除
    deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    // 番兵の直後に要素を追加
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main() {
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i=0; i<n; i++) {
        scanf("%s%d", com, &key);   // より高速な入力関数を使用
        if (com[0] == 'i') {
            insert(key);
            np++; size++;
        }
        else if (com[0] == 'd') {
            if (strlen(com) > 6) {
                if (com[6] == 'F') deleteFirst();
                else if (com[6] == 'L') deleteLast();
            }
            else {
                deleteKey(key); nd++;
            }
            size--;
        }
    }
    printList();
    return 0;
}


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

A,B,M = map(int,input().split())
AA = list(map(int,input().split()))
BB = list(map(int,input().split()))

ans = min(AA)+min(BB)

for i in range(M):
    x,y,c = map(int,input().split())
    tmp = AA[x-1]+BB[y-1]-c
    ans = min(ans,tmp)
    
print(ans)

Measured memory_bytes: 66848
#include<cstdio>

using namespace std;

int main(){
  long long int n;
  scanf("%lli",&n);

  long long int r[n];
  for(int i = 0; i < n; i++){
    scanf("%lli",&r[i]);
  }

  long long int max_dst = -10000000000;
  long long int min_r = r[0];

  for(int i = 1; i < n; i++){
    if(max_dst < r[i] - min_r){
      max_dst = r[i] - min_r;
    }
    if(min_r > r[i]){
      min_r = r[i];
    }
  }

  printf("%lli\n",max_dst);

  return 0;
}



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

int main(){
int N;
cin >> N;
vector<int> l(N);
rep(i,N)
cin >> l.at(i);
int a, b, c;
long long int ans =0;
  int sk=0;
  int kari=0;

sort(l.begin(), l.end());
  
rep(i, N-2){
a = l[i];
  
  
  rep2(k, i+1, N-1){
    if(k > i+1 && b == l[k]){
      kari --;
      if(kari>=0)
      ans += kari;
    continue; 
    }
b = l[k];
    sk=0;
    
  kari=0;
    
rep2(j, k+1, N){
  if(sk ==1)
    continue;
  c = l[j];
if(a+b<=c){
  sk++;
  continue;
}
    else {
      ans ++;
      kari++;
  }
  
  
  }
  }
}
    
cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring> 
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
	ll x,y;
}a[200005];
ll dp[35][200005],x,ans=0,y,sum=0,u[200005],cnt=0,n,cnt2=0,t,res;
const ll inf=1e9;
bool cmp(node a,node b)
{
	//if(a.y==0&&b.y==0)return a.x<b.x;
	return b.y*(1ll-a.x)+b.x<a.y*(1ll-b.x)+a.x;
}
ll minn(ll x,ll y)
{
	if(y>t)return x;
	if(x==-1)return y;
	return min(x,y);
}
int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%lld%lld",&n,&t);
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&x,&y);
		x++;
		if(x==1)u[++cnt2]=y;
		else
		{
			cnt++;
			a[cnt].x=x;
			a[cnt].y=y;
		}
	}
	sort(a+1,a+cnt+1,cmp);
	sort(u+1,u+cnt2+1);
	for(int i=0;i<cnt;i++)
	{
		for(int j=0;j<34;j++)
		{
			if(dp[j][i]==-1)continue;
			dp[j][i+1]=minn(dp[j][i+1],dp[j][i]);
			dp[j+1][i+1]=minn(dp[j+1][i+1],a[i+1].x*(dp[j][i]+1ll)+a[i+1].y);
		}
	}
	for(int j=0;j<34;j++)
	{
		if(dp[j][cnt]==-1)continue;
		sum=j;res=dp[j][cnt];
		for(int i=1;i<=cnt2;i++)
		{
			if(res+1+u[i]<=t)
			{
				res+=1+u[i];
				sum++;
			}
			else break;
		}
		ans=max(ans,sum);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 57984
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <utility>

using namespace std;

int main(){
	int N, T; cin >> N >> T;
	int tmp_ar_time_h = -1, tmp_ar_time_m = -1;

	vector<pair<string, int> > ans;

	for (int i = 0; i < N; i++) {
		int st_time_h, st_time_m;
		int ar_time_h, ar_time_m;
		string st_name, ar_name;
		scanf("%d:%d", &st_time_h, &st_time_m);
		cin >> st_name;
		scanf("%d:%d", &ar_time_h, &ar_time_m);
		cin >> ar_name;

		// cout << st_time << st_name << ar_time << ar_name << endl;

		if (tmp_ar_time_h == -1 || tmp_ar_time_m == -1) {
			tmp_ar_time_h = ar_time_h;
			tmp_ar_time_m = ar_time_m;
			continue;
		}

		int dh = st_time_h - tmp_ar_time_h;
		int dm = st_time_m - tmp_ar_time_m;

		int d = 60*dh + dm;

		if (d >= T) {
			ans.push_back(make_pair(st_name, d));
		}

		tmp_ar_time_h = ar_time_h;
		tmp_ar_time_m = ar_time_m;
	}

	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}

	return 0;
}

Measured memory_bytes: 1268
#include <iostream>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
using namespace std;
const long long N=100005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int addition(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res+a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int32_t main()
{
    IOS;
    // pre();
    // fill(isprime,true);
    int n;
    cin>>n;
    if(n<2){
        cout<<0;
    }else{
        int ans = power(10,n,mod);
        // ans%=mod;
        // ans*=n;
        // ans%=mod;
        // ans*=(n-1);
        // ans%=mod;
        ans+=power(8,n,mod);
        ans%=mod;
        ans-= (2*power(9,n,mod))%mod;
        ans = (ans+mod)%mod;
        cout<<(ans)%mod;
    }
}

Measured memory_bytes: 3636
from collections import defaultdict
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = list(map(int, input().split()))

  dic = defaultdict(int)
  for a in A:
    dic[a] += 1

  C2 = lambda N: int(N * (N-1) / 2)

  sum_ = 0
  for key in dic.keys():
    sum_ += C2(dic[key])

  for i in range(N):
    print( sum_ - (C2(dic[A[i]]) - C2(dic[A[i]]-1)) )


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 109624
use std::io;


fn main() {
    let n = read_one::<f64>();
    let an = read::<f64>();
    let avg = an.iter().sum::<f64>() / n;
    /* sort for PartialOrd...
    let mut ans = an.iter().enumerate()
        .map(|(i, a)| (i, (a - avg).abs()))
        .collect::<Vec<(usize, f64)>>();
    ans.sort_by_key(|a| a.1);
    */
    let mut id = 0;
    let mut score = 1000.0;
    for (i, a) in an.iter().enumerate() {
        let s = (a - avg).abs();
        if s < score {
            id = i;
            score = s;
        }
    }
    println!("{:?}", id);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
n,k = map(int, input().split())
d = []
A= []
c = []
 
for i in range(k):
    d.append(int(input()))
    A.append(list(map(int, input().split())))
 
for j in range(k):
    for m in range(d[j]):
        c.append(A[j][m])
 
print(n-len(set(c)))

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

using namespace std; 

int main(){

	int H , W;
	int h , w;
	
	cin >> H >> W >> h >> w;
	
	int counter = H * W;
	
	counter = counter - W * h - w * H + ( h * w ) ;
	
	cout << counter << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;

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

	ll N;
	cin >> N;
	vector<ll> a(N);
	rep(i, N) {
		cin >> a[i];
	}

	sort(a.begin(), a.end(), greater<ll>());

	rep(i, N) {
		if (i % 2 == 0) {
			ans += a[i];
		}
		else {
			ans -= a[i];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

  int num;
  while(cin >> num){
    //making graph
    if(num == 0) break;
    int wid, hei;
    cin >> wid >> hei;

    int data[wid+1][hei+1];

    for(int i = 0; i < wid+1; i++){
      for(int j = 0; j < hei+1; j++){
	data[i][j] = 0;
      }
    }

    for(int i = 0; i < num; i++){
      int x, y;
      cin >>x >> y;
      data[x][y] = 1;
    }
    //end

    //start search
    int x, y;
    cin >> x >> y;
    int max = 0;

    for(int i = 1; i < wid+2-x; i++){
      for(int j = 1; j < hei+2-y; j++){
	int sum = 0;
	for(int l = i; l < i+x; l++){
	  for(int k = j; k < j+y; k++){
	    if(data[l][k] == 1) sum++;
	  }
	  if(sum > max) max = sum;
	}
      }
    }
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 0
(let* ((a (read))
       (lst (loop :repeat a :collect (read)))
       (a1 0)
       (a2 0)
       (a4 0))
  (mapcar (lambda (n)
            (cond ((= 0 (mod n 4)) (incf a4))
                  ((= 0 (mod n 2)) (incf a2))
                  (t (incf a1)))) lst)
  (if (= 0 a2)
      (incf a4)
      nil)
  (if (<= 0 (- a4 a1))
      (princ "Yes")
      (princ "No")))

Measured memory_bytes: 59752
S = str(input())
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]
cnt = 0
s_pre = ""
s_pro = ""
for q in Q:
    if q[0] == "1":
        cnt += 1
    else:
        if (int(q[1])+cnt)%2 == 1:
#             S = q[2] + S
            s_pre = q[2] + s_pre
        else:
            s_pro = s_pro + q[2]
#             S = S + q[2]

S = s_pre + S + s_pro
if cnt%2==1:
    S = list(S)
    S.reverse()
print("".join(S))

Measured memory_bytes: 42860
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//----------------------------------------------------------------------

#define MAX 1000

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

  if (n != 1 && m != 1) {
	ans = n * m - (2 * n + 2 * m - 4);
  }
  else if (n == 1 && m == 1) {
	ans = 1;
  }
  else {
	ans = n * m - 2;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    int N; string S; cin>>N>>S;
    vector<int> vec(N);
    int E_cnt=0;
    for (int i = 0; i < N; ++i) {
        if(S[i]=='E') E_cnt++;
        vec[i] = E_cnt;
    }
    int minimum = E_cnt-vec[0];
    for (int i = 1; i < N; ++i) {
        int tmp = i-vec[i-1] + (E_cnt-vec[i]); //西向き　＋　東向き
        minimum = min(minimum, tmp);
    }

    cout<<minimum<<endl;

    return 0;
}

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

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

  vector<long long> luka_number = {2, 1};  
  for (int i = 0; i < N; i++) {
    luka_number.push_back(luka_number.at(i+1)+luka_number.at(i));
  }

  cout << luka_number.at(N) << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <functional>
#include <string>
#include <cassert>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

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

  int N;

  std::vector<int> a; // a_i

  cin >> N;

  a.resize(N);

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

  int minus2_id = -1, minus2_num = 0, minus1_id = -1;

  std::vector<int> ans;

  for (int i = 0; i < N; ++i) {
    if (a[i] == 2) {
      ans.push_back(i + 1);
    }
    else if (a[i] == -2) {
      minus2_id = i + 1;
      minus2_num++;
      ans.push_back(i + 1);
    }
    else if (a[i] == -1 && minus1_id == -1) {
      minus1_id = i + 1;
    }
  }

  if (minus2_num % 2 == 1) {
    if (minus1_id != -1) {
      ans.push_back(minus1_id);
    }
    else {
      for (int i = 0; i < N; ++i) {
        if (ans[i] == minus2_id) {
          ans.erase(ans.begin() + i);
          break;
        }
      }
    }
  }

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

  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 3224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.InputMismatchException;


public class Main {
	
	private static int[][] cache;
	private static int[] r;
	private static int[] c;
	

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

		int n = sc.nextInt();
		r = new int[n];
		c = new int[n];

		for (int i = 0; i < n; i++) {
			r[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}

		// ボトムアップ型１
		cache = new int[n][n];
		for (int i = 0; i < n; i++) {
			Arrays.fill(cache[i], Integer.MAX_VALUE);
			cache[i][i] = 0;
		}

		for (int l = 1; l < n; l++) {
			for (int i = 0; i + l < n && i < n; i++) {
				int j = i + l;
				for (int k = 0; k < l; k++) {
					cache[i][j] = Math.min(cache[i][j], cache[i][i + k] + r[i] * r[i+k+1] * c[j] + cache[i + k + 1][j]);
				}
			}
		}
		int ret = cache[0][n -1];
		
		System.out.println(ret);
		
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		InputStreamReader isr;
		BufferedReader br;
		StreamTokenizer st;

		private Scanner() {
		}

		Scanner (InputStream in) {
			isr = new InputStreamReader(in);
			br = new BufferedReader(isr);
			st = new StreamTokenizer(br);
		}

		String next() throws RuntimeException  {
			try {
				if (st.nextToken() != StreamTokenizer.TT_WORD) {
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return st.sval;
		}

		int nextInt() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return (int)st.nval;
		}

		void close() {
		}
	}
}

Measured memory_bytes: 19908
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N, D;
	cin >> N >> D;
	cout << (N+2*D) / (2*D+1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <locale>
#include <string>

using namespace std;

int main() {
	string numstr;
	
	cin >> numstr;
	while ( numstr  != "0") {
		int sum =0;
		for(int i=0;i<numstr.size();i++) {
			sum += numstr[i] - '0';
		}
		cout << sum <<endl;
		cin >> numstr;
	}

	return 0;
}


Measured memory_bytes: 3184
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
  temp=list()
  temp.append(p[i-1])
  temp.append(p[i])
  temp.append(p[i+1])
  if p[i]==sorted(temp)[-2]:
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main()
{
  ll n, k;
  cin >> n >> k;
  
  if(k == 0){
    cout << n * n << endl;
    return 0;
  }

  ll ans = 0;
  for(ll i = 0; i <= n; i++){
    if(i > k){
      ans += n / i * (i - k);
      ans += max(0LL, (n % i) - k + 1);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
val Int.topDigit: Int
  get() = this.toString()[0].toString().toInt()
val Int.bottomDigit: Int
  get() = this % 10

fun main(args: Array<String>) {
  val N = readInt()

  // N が 2 桁までは定義通り
  if (N < 100) {
    var cnt = 0
    for (A in 1..N) {
      for (B in 1..N) {
        if (A.topDigit == B.bottomDigit && B.topDigit == A.bottomDigit) cnt++
      }
    }
    println(cnt)
    return
  }

  // N が 3 桁以上は工夫する
  val NStr = N.toString()
  val NCenterNum = NStr.substring(1 until NStr.length - 1).let { if (it.isEmpty()) 0 else it.toLong() }
  val NTopDigit = N.topDigit
  val NBtmDigit = N.bottomDigit

  // 戻り値: 特定の A に対する B のパターン数
  fun f(A: Int): Long {
    val AStr = A.toString()
    val topDigit = A.topDigit
    val btmDigit = A.bottomDigit

    if (btmDigit == 0) return 0L

    var cnt = 0L
    // B が 1 桁
    if (topDigit == btmDigit) cnt++
    // B が 中間桁
    var d = 1
    repeat(NStr.length - 2) {
      cnt += d
      d *= 10
    }
    // B が 最大桁
    if (btmDigit > NTopDigit) return cnt
    if (btmDigit < NTopDigit) return cnt + d
    if (topDigit > NBtmDigit) return cnt + NCenterNum
    return cnt + NCenterNum + 1
  }

  var sum = 0L
  for (n in 1..N) {
//    println("$n, ${f(n)}")
    sum += f(n)
  }
  println(sum)
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
void Yes(){
  cout << "Yes" << endl;
}
void YES(){
  cout << "YES" << endl;
}
void No(){
  cout << "No" << endl;
}
void NO(){
  cout << "NO" << endl;
}
int main(){
  int i,A,B,K;
  cin >> A >> B >> K;
  
  for(i=min(A,B);i>0;i--){
  	if(A%i == 0 && B % i == 0 ){
    	K--;
        if(K==0) cout << i << endl;
    }
  }
}

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

using namespace std;

int main(){
    int n;
    cin>>n;
    if(n<10){
        if(n==3)cout<<"bon"<<endl;
        else if(n==0||n==1||n==6||n==8)cout<<"pon"<<endl;
        else{cout<<"hon"<<endl;}
    }
    if(n>=10 && n<=999){
        n=n%10;
        if(n==3){cout<<"bon"<<endl;}
        else if(n==0||n==1||n==6||n==8){cout<<"pon"<<endl;}
        else{cout<<"hon"<<endl;}

    }

    return 0;
}

Measured memory_bytes: 3612
while (True):
    code=list(map(int,input().split()))
    if(code[0]==-1 and code[1]==-1 and code[2]==-1):
        break
    sum=code[0]+code[1]    
    if(code[0]==-1 or code[1]==-1):
        print("F")
    elif(sum>=80):
        print("A")
    elif(sum>=65):
        print("B")
    elif(sum>=50):
        print("C")
    elif(sum<30):
        print("F")
    elif(sum>=30 and code[2]>=50):
        print("C")
    else:
        print("D")

Measured memory_bytes: 7684
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

struct Card { char suit; int value; };

void printCards(const vector<Card>& cards) {
    for (int i = 0; i < cards.size(); i++) {
        cout << cards[i].suit << cards[i].value;
        if (i != cards.size() - 1) {
            cout << ' ';
        }
    }
    cout << endl;
}

void isStable(const vector<Card>& a, const vector<Card>& b) {
    vector<char> bucketA[9];
    vector<char> bucketB[9];
    for (auto& e : a) {
        bucketA[e.value - 1].push_back(e.suit);
    }
    for (auto& e : b) {
        bucketB[e.value - 1].push_back(e.suit);
    }
    bool stable = true;
    for (int i = 0; i < 9; i++) {
        if (bucketA[i] != bucketB[i]) {
            stable = false;
            break;
        }
    }
    if (stable) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
}

void BubbleSort(const vector<Card>& in) {
    auto cards = in;
    for (auto i = 0; i < cards.size(); i++) {
        for (auto j = cards.size() - 1; j > i; j--) {
            if (cards[j].value < cards[j - 1].value) {
                swap(cards[j], cards[j - 1]);
            }
        }
    }
    printCards(cards);
    isStable(in, cards);
}

void SelectionSort(const vector<Card>& in) {
    auto cards = in;
    for (auto i = 0; i < cards.size(); i++) {
        int minj = i;
        for (auto j = i; j < cards.size(); j++) {
            if (cards[j].value < cards[minj].value) {
                minj = j;
            }
        }
        swap(cards[i], cards[minj]);
    }
    printCards(cards);
    isStable(in, cards);
}

int main(int argc, const char * argv[]) {
    int n;
    scanf("%d\n", &n);

    vector<Card> cards;
    for (int i = 0; i < n; i++) {
        char s;
        int v;
        if (i != n - 1) {
            scanf("%c%d ", &s, &v);
        } else {
            scanf("%c%d", &s, &v);
        }
        cards.push_back({s, v});
    }

    BubbleSort(cards);
    SelectionSort(cards);

    return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl
#define int long long
#define double long double
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


void chmin(string &a,string b){
  if(a[0] == '!'){
    a = b;
    return;
  }
  
  if(a.size() != b.size()){
    if( a.size() > b.size() ) a = b;
    return;
  }
  if(a > b) a = b;
}

int n;
string s;
vector<int> Idx[26];

int dfs(int idx){
  static int mem[200010];
  static int used[200010]={};
  if(idx == n) return 0;
  if(idx >= 0 && used[idx]++) return mem[idx];
  
  int res =1e9;
  for(int i=0;i<26;i++){
    int to = (*upper_bound(Idx[i].begin(), Idx[i].end(), idx));
    Min(res, (1 + dfs(to)));
  }
  if(idx == -1) return res;
  return mem[idx] = res;
}

string dfs2(int idx){
  if(idx == n) return "";
  
  typedef tuple<int,int,int> T;
  vector<T> To;
  for(int i=0;i<26;i++){
    char ch = 'a' + i;
    int to = (*upper_bound(Idx[i].begin(), Idx[i].end(), idx));
    To.push_back(T(dfs(to), ch, to));
  }
  
  sort(To.begin(),To.end());
  int len, ch, to; tie(len, ch, to) = To[0];
  return (char)ch + dfs2(to);
}


signed main(){
  //cin.tie(0);
  //ios_base::sync_with_stdio(0);
  //cout << fixed << setprecision(12);
  srand((unsigned) time(NULL));

  cin>>s;
  n = s.size();

  for(int i=0;i<n;i++) Idx[s[i] - 'a'].push_back(i);
  for(int i=0;i<26;i++) Idx[i].push_back(n);

  string ans = dfs2(-1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 12164
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
const ll MOD=1000000007;

int main(){
  string K;
  int D;
  cin >> K >> D;

  int d=K.size();

  vector<vector<ll>> p(d+1,vector<ll>(D,0));
  p[0][0]=1;
  for (int i = 1; i < d+1; i++){
    //cout << i << ":";
    for (int j = 0; j < D; j++){
      for (int k = 0; k < 10; k++){
        p[i][j]+=p[i-1][((j-k)%D+D)%D];
        p[i][j]%=MOD;
      }
      //cout << p[i][j] << " ";
    }
    //cout << endl;
  }

  ll ans=0;
  ll s=0;  
  for(int i=0;i<d;i++){
    for(int j=0;j<(K[i]-'0');j++){
      ans+=p[d-i-1][(D-(s+j)%D)%D];
      ans%=MOD;
    }
    s+=K[i]-'0';
  }

  if(s%D==0) ans++;

  cout << (ans-1+MOD)%MOD << endl;

  return 0;
}


Measured memory_bytes: 8448
#define isFile 0
#include <iostream>
#include <math.h>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <stack>
#include <iomanip>
#include <map>
#include <set>
#include <utility>
#include <cstdlib>
#include <fstream>
#include <stdio.h>
#include <utility>
#include <ctype.h>
#include <cassert>
#include <list>
#include <numeric>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef long long int lli;
 
// #define mp make_pair 
#define pb push_back
#define pf push_front
#define ed cout << endl
#define PI acos(-1)
#define NAME "choose"
// #define name "choose"
#define all(x) x.begin(),x.end()
#define F first 
#define S second
#define T third
#define mk make_pair
#define sz(x) int(x.size())
#define repi(a, b) for (int i = a; i < b; i ++)
#define repj(a, b) for (int j = a; j < b; j ++)
#define yes cout << "yes"
#define no cout << "no"
 
const ll MOD = 1e7 + 9;
const long double EPS = 3e-16;
const ll MAXN = 2e5 + 7;
const ll INF = 1e9;
 
void file(){
    freopen(NAME".in", "r", stdin);
    if (isFile) freopen(NAME".out", "w", stdout);
}


void solve(){
  int n;
  cin >> n;
  set<string> s;
  for (int i = 0; i < n; i ++){
    string t;
    cin >> t;
    s.insert(t);
  }
  cout << s.size();ed;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  // file();
  int t = 1;
  // cin >> t;
  while(t--){
    solve();
  }

  return 0;
}
    


Measured memory_bytes: 19124
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  int N,K;
  cin >> N >> K;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int h;
    cin >> h;
    if (h >= K)++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//お勉強中

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 22;
char dn[dm], * di = dn;
char C[10];
int keta = 0;
inline void putint(int X) {
	keta = 0;
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}
inline void putmae() {
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint();
	int n = 1 << N;
	int dp1[1 << 18], dp2[1 << 18];
	rep(i, n) {
		dp1[i] = getint();
		dp2[i] = 0;
	}

	rep(k, N) {
		int m = 1 << k;
		int m2 = ~(1 << k);
		for (int j = n - 1 & m2; j >= 0; j = j - 1 & m2) {
			int i = j | m;
			int k = min(dp1[i], dp1[j]);
			dp1[i] = max(dp1[i], dp1[j]);
			dp2[i] = max(dp2[i], k);
			dp2[i] = max(dp2[i], dp2[j]);
		}
	}

	int saidai = 0;
	rep1(i, n - 1) {
		if (saidai < dp1[i] + dp2[i]) {
			saidai = dp1[i] + dp2[i];
			putint(saidai);
		}
		else putmae();
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 9216
#include <stdio.h>

int R,C;
int osen[10][10000],max;

void func(int hako[10],int now){
	if(now==R){
		int val=0,i,j;
		//ツ板スツ転
		for(i=0;i<R;i++){
			if(hako[i]==1){
				for(j=0;j<C;j++){
					if(osen[i][j]==1){
						osen[i][j]=0;
					}
					else {
						osen[i][j]=1;
					}
				}
			}
		}
		//ツ青板つヲツづゥ
		for(i=0;i<C;i++){
			int count=0,j;
			
			for(j=0;j<R;j++){
				if(osen[j][i]==0){
					count++;
				}
			}
			if(count<=R/2){
				val+=(R-count);
			}
			else {
				val+=count;
			}
		}
		if(val>max){
			max=val;
		}
		
		//ツ板スツ転
		
		for(i=0;i<R;i++){
			if(hako[i]==1){
				for(j=0;j<C;j++){
					if(osen[i][j]==1){
						osen[i][j]=0;
					}
					else {
						osen[i][j]=1;
					}
				}
			}
		}
	}
	else {
		hako[now]=1;
		func(hako,now+1);
		hako[now]=0;
		func(hako,now+1);
	}
	
}

int main(void)
{
	
	while(scanf("%d%d", &R, &C),R,C){
		int i,j;
		int hako[10]={0};
		
		for(i=0;i<R;i++){
			for(j=0;j<C;j++){
				scanf("%d", &osen[i][j]);
			}
		}
		func(hako,0);
		printf("%d\n",max);
		max=0;
	}
	return 0;
}

Measured memory_bytes: 1152
//#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <time.h>
//#include <sstream>
//#include <queue>

using namespace std;


int main(){

	int n;
	double ax, ay, bx, by, cx, cy;
	double A, B, C,S2;
	double x, y,r;

	cin >> n;

	while (n--){
		cin >> ax >> ay >> bx >> by >> cx >> cy;

		A = (bx - cx)*(bx - cx) + (by - cy)*(by - cy);
		B = (cx - ax)*(cx - ax) + (cy - ay)*(cy - ay);
		C = (bx - ax)*(bx - ax) + (by - ay)*(by - ay);
		S2 = A*(B + C - A) + B*(C + A - B) + C*(A + B - C);

		x = (A*(B + C - A)*ax + B*(C + A - B)*bx + C*(A + B - C)*cx) / S2;
		y = (A*(B + C - A)*ay + B*(C + A - B)*by + C*(A + B - C)*cy) / S2;

		r = sqrt((x - ax)*(x - ax) + (y - ay)*(y - ay));

		printf("%.3f %.3f %.3f\n", x, y, r);
	}
}

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

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			if(n==0) break;
			Plant[] pl = new Plant[n];
			for(int i=0; i<n; i++){
				pl[i] = new Plant(
						in.next()
						, in.nextInt()
						, in.nextInt()+in.nextInt()+in.nextInt()
						, in.nextInt()+in.nextInt()
						, in.nextInt()
						, in.nextInt()
						, in.nextInt());
			}
			Arrays.sort(pl);
			for(Plant p: pl) System.out.println(p.name);
			System.out.println("#");
		}
	}
}

class Plant implements Comparable<Plant>{
	double cost;
	String name;
	public Plant(String name, int p, int abc
			, int de, int f, int s, int m){
		double time = abc+de*m;
		double get = f*s*m-p;
		cost = get/time;
		this.name = name;
	}
	
	@Override
	public int compareTo(Plant o) {
		int res =  Double.compare(o.cost, cost);
		if(res != 0) return res;
		return name.compareTo(o.name);
	}
}

Measured memory_bytes: 37780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))


const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);
const ld dif = 'a' - 'A';

string s;
int n, k;

int main(){
    cin >> n >> k >> s;
    if (s[k-1] <= 'Z') s[k-1] = (s[k-1] + dif);
    cout << s;
    return 0;
}


Measured memory_bytes: 256
# 2019/05/06
# AtCoder Beginner Contest 086 - C

# Input
n = int(input())

# Init
wt = 0
wx = 0
wy = 0
postra_flg = True

for i in range(n):
    t, x, y = map(int, input().split())
    et = t - wt
    dist = abs(x - wx) + abs(y - wy)
    remt = et - dist
    
    # Case Too far or Odd
    if remt < 0 or remt % 2 == 1:
        postra_flg = False
        break

if postra_flg == True:
    ans = "Yes"
else:
    ans = "No"

# Output
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    int tot = 0;
    REP(i, N) tot ^= a[i];
    REP(i, N){
        cout << (tot ^ a[i]) << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 4048
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

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

        // 入力
        int s = sc.nextInt();
        int w = sc.nextInt();
        //String s = sc.next();

        // 処理
        String out = "safe";
        if (w >= s) {
            out = "unsafe";
        }

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 35772
// Iroha and Haiku

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int p[3];
	cin >> p[0] >> p[1] >> p[2];

	sort(p, p+3);
	if (p[0] == 5 && p[1] == 5 && p[2] == 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<cstdio>
using namespace std;
#define res register int
typedef long long ll;
typedef long double ld;
const int INF=0x3f3f3f3f;
inline int read(){
	char ch=getchar();int s=0,f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+(ch^48);ch=getchar();}
	return s*f;
}
vector<ll> lunlun;
ll q[int(1e7)];
void pre(){
	int r=0,l=1;
	for(int i=1;i<10;++i)q[++r]=i;
	while(r>l){
		ll x=q[l++];
		lunlun.push_back(x);
		if(x>1e10)return;
		ll k=x%10;
		q[++r]=x*10ll+k;
		if(k!=0)q[++r]=x*10ll+k-1;
		if(k!=9)q[++r]=x*10ll+k+1;
	}
}
int main(){
	pre();
	sort(lunlun.begin(),lunlun.end());
	int k=read();
	cout<<lunlun[k-1]<<endl;
	return 0;
}


Measured memory_bytes: 8176
#include<bits/stdc++.h>
using namespace std;
#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pii> >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>M;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n
const int mod=1e9+7;
const int sze=1e5+2;
const int inf= (int)(1e19+10LL);
int dx[2]={1,0};
int dy[2]={0,1};
int n,m;
char str[102][102];
void solve()
{
  sl(n);sl(m);
  for(int i=1;i<=n;i++){
	  for(int j=1;j<=m;j++){
		  sl(str[i][j]);
	  }
  }
  vector<vector<int>> dp(n+1, vector<int>(m+1, inf));
  dp[1][1]=(str[1][1]=='.')?0:1;
  for(int i=1;i<=n;i++){
	  for(int j=1;j<=m;j++){
		  for(int dir=0;dir<2;dir++){
	           int nx=i+dx[dir];
	           int ny=j+dy[dir];
	           if(!(nx<=n && ny<=m))continue;
	           if(str[i][j]=='.' && str[nx][ny]=='#'){
				   dp[nx][ny]=min(dp[nx][ny],dp[i][j]+1);
			   }	
			   else{
				   dp[nx][ny]=min(dp[nx][ny],dp[i][j]);
			   }	  
			  
		  }
	  }
	  
  }
  cout<<dp[n][m]<<endl;
  
  
}
 
signed main(){
   int test=1;
   //sl(test);
   while(test--){
      solve();
 
   }
  return 0;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
  static int A[] = new int[2000000];
  static int H = 0;

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

		for(;;){
			String s = sc.next();
			if(s.equals("end")) break;
			if(s.equals("insert")){
				int k = sc.nextInt();
				insert(k);
			} else if(s.equals("extract")){
        out.println(heapExtractMax(A));
      }
		}

		sc.close();
	}

  static void insert(int key){
    H++;
    A[H] = (int)Double.NEGATIVE_INFINITY;
    heapIncreaseKey(A, H, key);
  }

  static void heapIncreaseKey(int A[], int i, int key){
    if(key<A[i]){
      return;
    }

    A[i] = key;
    int tmp = 0;

    while(i > 1 && A[parent(i)] < A[i]){
      tmp = A[i];
      A[i] = A[parent(i)];
      A[parent(i)] = tmp;
      i = parent(i);
    }
  }

  static int heapExtractMax(int A[]){
    if(H<1){
      return Integer.MIN_VALUE;
    }

    int max = A[1];
    A[1] = A[H--];
    maxHeapify(A, 1);

    return max;
  }

  static void maxHeapify(int[] A, int i) {
    int leftId = i * 2;
    int rightId = i * 2 + 1;
    int largest = 0;

    if (leftId <= H && A[leftId] > A[i]) {
	    largest = leftId;
    } else {
      largest = i;
    }

    if (rightId <= H && A[rightId] > A[largest]) {
      largest = rightId;
    }

    if (largest != i) {
      int tmp = A[i];
      A[i] = A[largest];
      A[largest] = tmp;
      maxHeapify(A, largest);
    }
  }

  static int parent(int i){
    return i/2;
  }

}



Measured memory_bytes: 555548
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>

using namespace std;

deque<int> dll;

void printList( )
{
	deque<int>::iterator itr = dll.begin( );
	deque<int>::iterator itrE = dll.end( );
	for( ; itr!=itrE; itr++ ) {
		cout<<*itr;
		if( itr != itrE-1 ) cout<<' ';
	}
	cout<<endl;
}
	
int main()
{
	int n;
	ios::sync_with_stdio( false );
	cin>>n;
	
	string cmd;
	int key;
	for( int i=0; i<n; i++ ) {
		cin>>cmd;
		if( "insert" == cmd ) {
			cin>>key;
			dll.push_front( key );
		} else if( "deleteFirst" == cmd ) {
			dll.pop_front( );
		} else if( "deleteLast" == cmd ) {
			dll.pop_back( );
		} else if( "delete" == cmd ) {
			cin>>key;
			deque<int>::iterator itr = dll.begin( );
			itr = find( dll.begin( ), dll.end( ), key );
			if( itr != dll.end( ) ) dll.erase( itr );
		}
	}
	printList( );

    return 0;
}

Measured memory_bytes: 5320
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;

int main(){
	
	int n,h,w;
	while(cin>>n){
		if(n!=0){
		int sw=0;
		vector< vector<int> >c(n+2,vector<int>(n+2));
		for(int i=0;i<n;i++){
				w=0;
			for(int j=0;j<n;j++){
				cin>>c[i][j];
				w+=c[i][j];
			}
			c[i][n]=w;
			sw+=w;
		}
		for(int i=0;i<n;i++){
			h=0;
			for(int j=0;j<n;j++){
			h+=c[j][i];
		}
			c[n][i]=h;
		}
		c[n][n]=sw;
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++)
			printf("%5d",c[i][j]);
			cout<<endl;
		}
		
		
	}
		else
			break;
	}
		
	
}

Measured memory_bytes: 1248