akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N, C;
int D[30][30];
int c[510][510];
int cnt[3][30];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> C;
  REP(i, C) REP(j, C) cin >> D[i][j];
  REP(i, N) REP(j, N) {
    cin >> c[i][j];
    c[i][j]--;
    cnt[(i+j)%3][c[i][j]]++;
  }
  int ans = INF;
  REP(i, C) REP(j, C) REP(k, C) {
    if (i == j || j == k || k == i) continue;
    int sum = 0;
    REP(l, C) sum += D[l][i]*cnt[0][l];
    REP(l, C) sum += D[l][j]*cnt[1][l];
    REP(l, C) sum += D[l][k]*cnt[2][l];
    chmin(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int ans=0;
    FOR(i,1,n+1){
        string t=to_string(i);
        int sum=0;
        REP(j,t.size()){
            sum+=stoi(t.substr(j,1));
        }
        if(a<=sum&&sum<=b){
            ans+=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		double sum = 0;
		for (int i = 0; i <a; i++) {
			int ai = s.nextInt();
			double val = 1.0/ai;
			sum=sum+val; 
		}
		System.out.println(1/sum);

	}

}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)


int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  ll h,n;
  cin >> h >> n;
  
  vll a(n);
  ll res=0;
  rep(i,0,n) {
    cin >> a[i];
    res+=a[i];
  }
  
  if(res>=h) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


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

int main(){
    int n;
    cin >>n;
    
    int a[100];
    for(int i=0;i<n;i++) cin >>a[i];
    
    for(int i =0;i<n-1-i;i++) swap(a[i],a[n-1-i]);
    
    for(int i =0;i<n;i++){
        if(i) cout<<" ";
        cout <<a[i];
        
    }
    cout <<endl;
    return 0;
} 
         


Measured memory_bytes: 3100
import java.util.Scanner;

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

		int a = stdIn.nextInt();
		int b = stdIn.nextInt();

		Clock clock = new Clock(stdIn.nextInt(), stdIn.nextInt());

		System.out.println(clock.getDist(a, b));

		stdIn.close();
	}
}

class Clock {
	private int h;
	private int m;

	public int getH() {
		return h;
	}

	public int getM() {
		return m;
	}

	public Clock(int h, int m) {
		this.h = h;
		this.m = m;
	}

	public double getAngle() {
		double bAngle = 6 * m;
		double aAngle = 30 * h + 0.5 * m;

		if (Math.abs(bAngle - aAngle) > 180) {
			return 360 - Math.abs(bAngle - aAngle);
		}
		return Math.abs(bAngle - aAngle);
	}

	public double getDist(int a, int b) {

		double angle = getAngle();

		if(angle == 0) {
			return Math.abs(a-b);
		}
		if(angle == 180) {
			return a+b;
		}

		return Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.PI * (getAngle() / 180)));
	}
}

Measured memory_bytes: 35840
n = int(input())
a = list(map(int, input().split()))
 
a_set = set(a)
 
if len(a_set) == 1:
    if sum(a_set) == 0:
        print('Yes')
    else:
        print('No')
elif len(a_set) == 2:
    x, y = sorted(a_set)
    if x == 0:
        if a.count(x) * 3 == n:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(a_set) == 3:
    x, y, z = a_set
    if a.count(x) == a.count(y) and a.count(y) == a.count(z):
        if x ^ y == z:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

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

int main(){
  long long K; 
  cin >> K;
  if (K % 2 == 0 || K % 5 == 0){
    cout << -1;
  } else {
    long long L = 9 * K;
    if (K % 7 == 0){
      L /= 7;
    }
  
    long long a = 10;
    long long n = 1;
    while (true){
      if (a % L == 1){
        break;
      } else {
        a = ((a % L) * 10) % L;
        n++;
      }
    }
  	cout << n;
  }
}

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

int M,N;
char S[2005],T[2005];
int dp[2001][2001];

int main(){
	scanf("%d%d%s%s",&M,&N,S,T); int res=0;
	for(int i=0;i<=M;i++) for(int j=0;j<=N;j++)
		if((i!=0&&S[i-1]=='I')||(j!=0&&T[j-1]=='I')) dp[i][j]=1;
	for(int i=1;i<=M;i++) for(int j=1;j<=N;j++){
		if(dp[i-1][j-1]>0&&S[i-1]!=T[j-1]) dp[i][j]=dp[i-1][j-1]+2;
		if(i>=2&&dp[i-2][j]>0&&S[i-2]=='O'&&S[i-1]=='I') dp[i][j]=max(dp[i][j],dp[i-2][j]+2);
		if(j>=2&&dp[i][j-2]>0&&T[j-2]=='O'&&T[j-1]=='I') dp[i][j]=max(dp[i][j],dp[i][j-2]+2);
		res=max(res,dp[i][j]);
	}
	printf("%d\n",res);
}

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

using namespace std;

char s[30];
int d[30],n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	if(n<26)
	{
		for(int i=1;i<=n;i++)
			d[s[i]-'a']=1;
		printf("%s",s+1); 
		for(int i=0;i<26;i++)
			if(!d[i]) {putchar('a'+i); break;}
		puts(""); return 0;
	}
	int j=26; while(s[j]<s[j-1]&&j>1) j--;
	if(j==1){ puts("-1"); return 0;}
	for(int i=1;i<j;i++)
		d[s[i]-'a']++;
	for(int i=1;i<j-1;i++) putchar(s[i]);
	for(int i=0;i<26;i++)
		if(!d[i]&&i>s[j-1]-'a') {putchar('a'+i); break;} puts("");
	return 0;
}

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

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> pnt(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int mode = 1; // 偶数:下る瞬間を見る
    for (int i = 0; i < n - 1; i++)
    {
        if (mode % 2 == 1 && a[i] < a[i + 1])
        {
            pnt[i] = 1; // kau
            mode++;
        }
        else if (mode % 2 == 0 && a[i] > a[i + 1])
        {
            pnt[i] = 2; //　uru
            mode++;
        }
    }
    pnt[n - 1] = 2;
    // print(a);
    // print(pnt);
    ll money = 1000;
    ll kb = 0;
    vector<ll> his;
    his.push_back(1000);

    for (int i = 0; i < n; i++)
    {
        if (pnt[i] == 1)
        {
            kb = money / a[i];
            money %= a[i];
        }
        else if (pnt[i] == 2)
        {
            money += kb * a[i];
            kb = 0;
            his.push_back(money);
        }
    }
    // print(his);
    sort(his.begin(), his.end());
    cout << his[his.size() - 1] << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

Measured memory_bytes: 3604
#include <iostream>

int main(){
    int n = 0;
    int m = 0;
    int a = 0;
    int sum = 0;

    std::cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        std::cin >> a;
        sum += a;
    }
    
    if (n >= sum)
    {
        std::cout << n - sum << std::endl;
    }
    else
    {
        std::cout << -1 << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;

int n,ans;
int a[100005],b[100005],c[100005];

signed main()
{
	cin>>n;
	n++;
	
	for(int i=1;i<=n;i++)
		cin>>a[i];
	
	b[1]=1,c[n]=a[n];
	for(int i=2;i<=n;i++)
		b[i]=(b[i-1]-a[i-1])*2;
	
	for(int i=n-1;i>=1;i--)
		c[i]=c[i+1]+a[i];
	
	for(int i=1;i<=n;i++)
		ans+=min(b[i],c[i]);
	
	for(int i=1;i<=n;i++)
		if(a[i]>b[i])
		{
			cout<<-1<<endl;
			return 0;
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5980
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(int i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int N;
vector<pair<int,int>> vt;
int main() {
	cin>> N;

	REP(i,1,N/2*2+1){
		REP(j,i+1,N/2*2+1){
			if(i+j!=N/2*2+1){
				vt.emplace_back(i,j);
			}
		}
	}
	if(N%2){
		REP(i,1,N){
			vt.emplace_back(i,N);
		}
	}
	p(vt.size());
	for(auto v:vt){
		p2(v.first, v.second);
	}
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=2e5+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,a[N],anc[N][20],mx[N][20];
vector<int> E[N];
void dfs(int u,int fa) {
    anc[u][0]=fa,mx[u][0]=u;
    for(int i=1;i<=19;i++) anc[u][i]=anc[anc[u][i-1]][i-1],mx[u][i]=max(mx[u][i-1],mx[anc[u][i-1]][i-1]);
    for(int v:E[u]) if(v!=fa) dfs(v,u);
}
void work(int u) {
    int pre_mx=0;
    for(int i=19;~i;i--)
        if(anc[u][i]&&mx[anc[anc[u][i]][0]][19]>max(pre_mx,mx[u][i])) chkmax(pre_mx,mx[u][i]),u=anc[u][i];
    ++a[u];
}
void dfs2(int u,int fa) {
    a[u]+=a[fa];
    for(int v:E[u]) if(v!=fa) dfs2(v,u);
}
int main() {
    n=gi();
    for(int i=1,u,v;i<n;i++) u=gi(),v=gi(),E[u].pb(v),E[v].pb(u);
    dfs(1,0);
    for(int i=1;i<=n;i++) work(i);
    dfs2(1,0);
    for(int i=2;i<=n;i++) printf("%d ",a[i]-1);
    return 0;
}


Measured memory_bytes: 53888
macro_rules! input {
    ($t:ty) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty ;) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ; $n:expr) => {
        (0..$n).map(|_|
            input!($t)
        ).collect::<Vec<_>>()
    };
}

fn main(){
    let a = input!(usize);
    let b = input!(usize);
    let h = input!(usize);
    println!("{}", (a+b)*h/2)
}

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

bool con(int x,int y,int z){
	int ch=x%2+y%2+z%2;
	bool dec;
	if(ch==0){
		dec=true;
	}else{
		dec=false;
	}
	return dec;
}

int main(){
	int a,b,c;cin>>a>>b>>c;
	int ans=0;
	bool ok=con(a,b,c);
	while(ok){
		int A=b/2+c/2;
		int B=a/2+c/2;
		int C=a/2+b/2;
		a=A;b=B;c=C;
		if(a==b&&b==c){
			ans=-1;
			break;
		}
		ok=con(a,b,c);
		ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    n = int(sys.stdin.readline())
    X = list(map(int,sys.stdin.readline().split()))
    ans = -1
    for i in range(1,max(X)+1):
        #print(i)
        ans_tmp = 0
        for j in X:
            ans_tmp += (j - i)**2
        #print(ans_tmp)
        if ans > ans_tmp or ans == -1:
            ans = ans_tmp
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N; cin>>N;
  vector<ll>A(100,0);
  for(int i=1; i<=N; i++){
    ll a=i%10;
    if(a==0) continue;
    ll temp=i,c;
    while(temp>=10) temp/=10;
    c=temp*10+a;
    A[c]++;
  }
  ll ans=0;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      ll a=i*10+j, b=i+j*10;
      ans+=A[a]*A[b];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

int n;
int a[200009];
vector<int> G[200009];

int ans[200009];
int dp[200009];

void dfs(int v, int p) {
    auto it = lower_bound(ALL(dp), a[v]);
    int x = *it;
    *it = a[v];
    ans[v] = lower_bound(ALL(dp), mod) - dp;
    for(int u : G[v]) {
        if(u != p) dfs(u, v);
    }
    *it = x;
}

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

    memset(dp, 0x3f, sizeof(dp));
    cin >> n;
    rep(i, n) cin >> a[i + 1];
    rep(i, n - 1) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1, -1);

    FOR(i, 1, n + 1) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 28356
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2 == 0 || b % 2 == 0)cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import random


class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down = self.down, self.top, self.faces[7 - self.faces.index(self.top)]
        elif direction == "S":
            self.top, self.up, self.down = self.up, self.faces[7 - self.faces.index(self.top)], self.top
        elif direction == "W":
            self.top, self.left, self.right = self.right, self.top, self.faces[7 - self.faces.index(self.top)]
        elif direction == "E":
            self.top, self.left, self.right = self.left, self.faces[7 - self.faces.index(self.top)], self.top
        else:
            raise ValueError("{} is not valid direction.".format(direction))


f = [int(i) for i in input().split()]
dice = Dice(*f)

n = int(input())
for i in range(n):
    top, down = [int(i) for i in input().split()]
    while dice.top != top:
        dice.roll(random.choice("NSWE"))
    if dice.down == down:
        print(dice.right)
    elif dice.right == down:
        print(dice.up)
    elif dice.up == down:
        print(dice.left)
    elif dice.left == down:
        print(dice.down)
    else:
        raise ValueError()



Measured memory_bytes: 8244
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int i;
  for(i=1;i<10000;i++){
    if(floor(i*0.08)==a && floor(i*0.1)==b){
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[109];
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) {
		for(int j = i - 1; j >= 0; j--) {
			if(a[j] > a[j + 1]) swap(a[j], a[j + 1]);
			else break;
		}
		for(int j = 0; j < n; j++) {
			if(j) cout << ' ';
			cout << a[j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3040
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void quick_sort(int[],int,int);
int partition(int[],int,int);

int main() {
    int n,k,i,d=0,e=0;
    scanf("%d %d ",&n,&k);
    int a[n],b[2000000];
    for(i=0;i<2000000;i++)
        b[i]=0;
    for(i=0;i<n;i++)
    {scanf("%d ",&a[i]);
     b[a[i]-1]++;}
    
    quick_sort(b,0,2000000-1);
    for(i=0;i<2000000;i++)
    {
       if(b[i]!=0)
            d++;
        
        
        
        
    }
    
    if(d>k)
    {
       int j=d-k;
        
        {
            for(i=0;i<2000000;i++)
      if(b[i]!=0 )
        {
          
          e+=b[i];
          j--;
          if(j==0)
              break;
              
          
      }
        }
        printf("%d",e);
    }
    else
        printf("0");
    return 0;
}
void quick_sort(int a[],int l,int u)
{
    int j;
    if(l<u)
    {
        j=partition(a,l,u);
        quick_sort(a,l,j-1);
        quick_sort(a,j+1,u);
    }
}
 
int partition(int a[],int l,int u)
{
    int v,i,j,temp;
    v=a[l];
    i=l;
    j=u+1;
    
    do
    {
        do
            i++;
            
        while(a[i]<v&&i<=u);
        
        do
            j--;
        while(v<a[j]);
        
        if(i<j)
        {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }while(i<j);
    
    a[l]=a[j];
    a[j]=v;
    
    return(j);
}



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

int main() {
  
  int H, W; cin >> H >> W; int count = 0;
  
  char table[H][W];
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char A; cin >> A;
      if (A == '#') count++;
    }
  }
  
  if (count == H + W - 1) cout << "Possible" << endl;
  
  else cout << "Impossible" << endl;
  
}

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

namespace Volume5_0556
{
	class Tile
	{
		static void Main(string[] args)
		{
			var inputData = GetInputData();

			var tileList = ListUpBrokenTiles(inputData);

			OutputData(tileList);
		}

		public enum colorPattern
		{
			Red = 1,
			Blue,
			Yellow,
			etc = 0
		}

		private static List<string> GetInputData()
		{
			var dataSet = "";
			var dataSets = new List<string>();
			var loopCount = 0;
			var lostTiles = 0;

			loopCount = 0;
			dataSet = Console.ReadLine();
			dataSets.Add(dataSet);
			dataSet = Console.ReadLine();
			lostTiles = int.Parse(dataSet);
			dataSets.Add(dataSet);

			while (loopCount != lostTiles)
			{
				dataSet = Console.ReadLine();
				dataSets.Add(dataSet);
				loopCount++;
			}

			return dataSets;
		}

		private static List<colorPattern> ListUpBrokenTiles(List<string> inputData)
		{
			var tileData = new List<colorPattern>();
			var muralSize = double.Parse(inputData[0]);
			var loopCounter = int.Parse(inputData[1]);
			var Row = 0;
			var Line = 0;
			var colorData = 0;

			for (int index = 2; index <= loopCounter + 1; index++)
			{
				Row = int.Parse(inputData[index].Split()[0]);
				Line = int.Parse(inputData[index].Split()[1]);

				Row = TargetShrink(Row, muralSize);
				Line = TargetShrink(Line, muralSize);

				if (Row >= Line)
				{
					colorData = Line % 3;
				}
				else
				{
					colorData = Row % 3;
				}

				switch (colorData)
				{
					case 0:
						tileData.Add(colorPattern.Yellow);
						break;
					case 1:
						tileData.Add(colorPattern.Red);
						break;
					case 2:
						tileData.Add(colorPattern.Blue);
						break;
					default:
						tileData.Add(colorPattern.etc);
						break;
				}
			}
			return tileData;
		}

		private static int TargetShrink(int data , double max)
		{
		var shrinkSize = Math.Round(max / 2);

			if (data > shrinkSize)
			{
				data = (int)shrinkSize * 2 - data;
				if (max % 2 == 0)
				{
					data++;
				}
			}

			return data;
		}

		private static void OutputData(List<colorPattern> tileList)
		{
			foreach (int i in tileList)
			{
				Console.WriteLine(i);
			}

		}
	}
}



Measured memory_bytes: 20084
const main = arg => {
    const input = arg.trim().split("\n");
    const str = String(input)
    let dig = Number(str[str.length-1])
    if([2,4,5,7,9].includes(dig)) console.log('hon')
    else if([0,1,6,8].includes(dig)) console.log('pon')
    else if(dig == 3) console.log('bon')
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

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

using namespace std;

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

void solve() {
  int l[3];
  cin >> l[0] >> l[1] >> l[2];
  sort(l, l+3);
  cout << (l[0] * l[1]) / 2 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


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

int main() {
  string s;
  cin>>s;
  int n = s.length();
  if (n % 2 == 1) {
    cout<<"No"<<endl;
    return 0;
  }
  for (int i=0; i<n-1; i+=2) {
    if (s[i] != 'h' || s[i+1] != 'i') {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();
    let mut cnt = 0;
    for c in s.chars() {
        if c == '1' {
            cnt += 1;
        }
    }

    println!("{}", cnt);
}


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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    stack<int> num;
    for(int i=1;i<101;i++){
      if(A%i==0 && B%i==0){
        num.push(i);
      }
    }

    int ans = 0; 
    rep(i,K-1){
        num.pop();
    }
    printl(num.top());
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int cnt = 0;
    while (b <= a) {
        b *= 2;
        ++cnt;
    }
    while (c <= b) {
        c *= 2;
        ++cnt;
    }
    if (cnt <= k) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3600
import collections
N=int(input())
A=list(map(int,input().split()))
S=collections.Counter(A)
s=list(S.values())
num=0
for i in s:
  num+=i*(i-1)/2
for i in A:
  tmp=S[i]-1
  ans=int(num-tmp)
  print(ans)
  

Measured memory_bytes: 26780
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<utility>	// wrap,pair
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR (i,n) for(int i=n;i>0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;

// 最大公約数（ユークリッドの互除法）
int GCD(int x, int y) {
	if (x > y) {
		swap(x, y);
	}
	int r = y % x;
	while (r != 0) {
		y = x;
		x = r;
		r = y % x;
	}
	return x;
}

// 最小公倍数
int LCM(int x, int y) {
	ll gcd = GCD(x, y);
	return x * y / gcd;
}

// 素数判定(素数ならtrue,合成数ならfalse)
bool IsPrime(int num) {
	if (num < 2) return false; // 0,1
	else if (num == 2) return true;	// 2
	else if (num % 2 == 0) return false; // 偶数

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false; // 割り切れたら素数ではない
	}
	return true; // 全部通ったら素数
}

// pairをsecond基準で昇順sort
// sort(vector_name.begin(),vector_name.end(),compare_by_b);
bool compare_by_b(pair<int, int>a, pair<int, int>b) {
	if (a.second != b.second) return a.second < b.second;
	else return a.first < b.first;
}

// 桁数を返す：unsigned(-の値をとらない)
unsigned Digit(unsigned num) {
	return log10(num) + 1;
}

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

int main(void) {

	int n, d;
	cin >> n >> d;
	int x[12][12];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) cin >> x[i][j];
	}
	
	int ans = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			int sum = 0;
			for (int k = 0; k < d; k++) {
				sum += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
			}
			if (ceil(sqrt(sum)) == floor(sqrt(sum))) ans++;
		}
	}
	cout << ans/2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <limits>
#include <vector>

using namespace std;

// ford-fulkerson
template <typename T>
struct MaxFlow {
  struct Edge {
    int to, rev;
    T cap;
    Edge(int to, int rev, T cap) : to(to), rev(rev), cap(cap) {}
  };
  vector<vector<Edge>> g;
  T inf;
  vector<int> visited;

  MaxFlow(int n) {
    g.resize(n);
    inf = numeric_limits<T>::max() / 3;
    visited.resize(n, false);
  }
  void add_edge(int from, int to, T cap) {
    g[from].emplace_back(to, g[to].size(), cap);
    g[to].emplace_back(from, (int)g[from].size() - 1, 0);
  }
  T dfs(int i, T curf, int sink) {
    if (i == sink) return curf;
    visited[i] = true;
    for (auto &&e : g[i]) {
      if (visited[e.to] or e.cap == 0) continue;
      auto tmpf = dfs(e.to, min(e.cap, curf), sink);
      if (tmpf > 0) {
        e.cap -= tmpf;
        g[e.to][e.rev].cap += tmpf;
        return tmpf;
      }
    }
    return 0; // 流せなかった
  }
  T ford(int source, int sink) {
    T maxf = 0;
    while (true) {
      fill(visited.begin(), visited.end(), false);
      auto f = dfs(source, inf, sink);
      if (f > 0) {
        maxf += f;
      } else {
        break;
      }
    }
    return maxf;
  }
};

#include <iostream>

int main() {

  int n, m;
  cin >> n >> m;
  MaxFlow<int> g(n);
  for (int i = 0; i < m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    g.add_edge(u, v, c);
  }
  cout << g.ford(0, n - 1) << endl;

  return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long 

const int N=1e5+5;

int n, m, s ,t;
int arrival[N], departure[N], ans[N], parent[N], arrival2[N], departure2[N];
vector<pair<int, pair<int, int> > > g[N];
bool vis[N];

void dijkstra(int source, int destination)
{
	for(int i=1;i<=n;i++)
	{
		arrival[i]=1e18;
		departure[i]=1e18;
	}
	arrival[source]=0;
	set<pair<int, int> > s;
	s.insert({0, source});
	while(!s.empty())
	{
		auto x = *(s.begin());
		s.erase(x);
		vis[x.second]=1;
		departure[x.second]=arrival[x.second];
		for(auto it:g[x.second])
		{

			if(arrival[it.first] > departure[x.second] + it.second.first)
			{
				s.erase({arrival[it.first], it.first});
				arrival[it.first]=departure[x.second] + it.second.first;
				s.insert({arrival[it.first], it.first});
				parent[it.first]=x.second;
			}
		}
	}
}

void dijkstra2(int source, int destination)
{
	for(int i=1;i<=n;i++)
	{
		arrival2[i]=1e18;
		departure2[i]=1e18;
	}
	arrival2[source]=0;
	set<pair<int, int> > s;
	s.insert({0, source});
	while(!s.empty())
	{
		auto x = *(s.begin());
		s.erase(x);
		vis[x.second]=1;
		departure2[x.second]=arrival2[x.second];
		for(auto it:g[x.second])
		{
			if(arrival2[it.first] > departure2[x.second] + it.second.second)
			{
				s.erase({arrival2[it.first], it.first});
				arrival2[it.first]=departure2[x.second] + it.second.second;
				s.insert({arrival2[it.first], it.first});
				parent[it.first]=x.second;
			}
		}
	}
}

int32_t main()
{
	IOS;
	cin>>n>>m>>s>>t;
	for(int i=1;i<=m;i++)
	{
		int u, v, w1, w2;
		cin>>u>>v>>w1>>w2;
		g[u].push_back({v, {w1, w2}});
		g[v].push_back({u, {w1, w2}});
	}
	dijkstra(s, t);
	dijkstra2(t, s);
	ans[n+1]=1e18;
	for(int i=n;i>=1;i--)
	{
		ans[i]=arrival[i] + arrival2[i];
		ans[i]=min(ans[i], ans[i+1]);
	}
	for(int i=1;i<=n;i++)
	{
		int cur=1e15-ans[i];
		cout<<cur<<" ";
	}
	return 0;
}   

Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
const int mod = 1e9+9;

const int ppt = 1e5+3;
int n;
int dp[ppt];
int a[ppt];
int f(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int jpr = abs(a[i]-a[i+1])+f(i+1);
	if(i!=n-2) jpr = min(jpr, abs(a[i]-a[i+2])+f(i+2));
	return dp[i]=jpr;
}
int main(){
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	memset(dp, -1, sizeof dp);
	cout<<f(0)<<endl;
	return 0;
}


Measured memory_bytes: 4096
#include<iostream>
#include<complex>
#include<vector>
using namespace std;
typedef complex < double > P;
typedef vector< P > G;
vector< G > g;
const double EPS = 1e-8;
const double INF = 1e12;
double cross(const P& a,const P& b){ //??????
  return imag(conj(a) * b);
}
double dot(const P& a,const P& b){ // ??????
  return real(conj(a) * b);
}
struct L: vector < P >{
  L(const P& a,const P& b){
    push_back(a);
    push_back(b);
  }
};
int ccw(P a,P b,P c){
  b -= a; c -= a;
  if(cross(b,c) > 0) return 1;
  if(cross(b,c) < 0) return -1;
  if(dot(b,c) < 0) return 2; // c--a--b
  if(norm(b) < norm(c)) return -2; // a--b--c
  return 0; // a--c--b
}
bool intersectSS(const L& s,const L& t){ //???????????? ??????:??????
  return ccw(s[0],s[1],t[0]) * ccw(s[0],s[1],t[1]) <= 0 &&
    ccw(t[0],t[1],s[0]) * ccw(t[0],t[1],s[1]) <= 0;
}
#define curr(P,i) P[i]
#define next(P,i) P[(i+1)%P.size()]
bool conteins(const G& Q, const P& p){
  bool in = false;
  for(int i = 0 ; i < Q.size() ; i++ ){
    P a = curr(Q,i) - p, b = next(Q,i) - p;
    if(imag(a) > imag(b)) swap(a,b);
    if(imag(a) <= 0 && 0 < imag(b) && cross(a,b) < 0) in = !in;
    if(cross(a,b) == 0 && dot(a,b) <= 0) return true;
  }
  return in;
}
bool intersect( int x, int y){ //???????????? g[x] == g[y]
  // g[x] or g[y] ?????????
  for(int i = 0 ; i < 4 ; i++ ){
    if(conteins(g[y],g[x][i]) || conteins(g[x],g[y][i])) return true;
  }
  // g[x] ??¨ g[y]???????????????
  for(int i = 0 ; i < 4 ; i++ ){
    for(int j = 0 ; j < 4 ; j++ ){
      if(intersectSS(L(curr(g[x],i),next(g[x],i)),L(curr(g[y],j),next(g[y],j)))) return true;
    }
  }
  return false;
}
//UnionFind
vector< int > rank, p;
void link(int x,int y){
  if(rank[x] > rank[y]) p[y] = x;
  else{
    p[x] = y;
    if(rank[x] == rank[y]) rank[y]++;
  }
}
void init(int size){
  rank.resize(size);
  p.resize(size);
  for(int i = 0 ; i < size ; i++ ){
    p[i] = i, rank[i] = 0;
  }
}
int findSet(int x){
  if(x != p[x]) p[x] = findSet(p[x]);
  return p[x];
}
void Union(int x,int y){
  link(findSet(x),findSet(y));
}
bool isSame(int x,int y){
  return findSet(x) == findSet(y);
}
 
int main(){
  int N, M;
  while(cin >> N , N){
    for(int i = 0 ; i < N ; i++ ){
      cin >> M;
      g.resize(M);
      init(M);
      for(int j = 0 ; j < M ; j++ ){
        for(int k = 0 ; k < 4 ; k++ ){
          P buff;
          cin >> buff.real() >> buff.imag();
          g[j].push_back(buff);
        }
      }
      for(int j = 0 ; j < M ; j++ ){
        for(int k = 0 ; k < j ; k++ ){
          if(!isSame( j, k) && intersect( j, k)) Union( j, k);
        }
      }
      int ret = 0;
      for(int j = 0 ; j < M ; j++ ){
        if(findSet(j) == j) ret++;
      }
      cout << ret << endl;
      g.clear();
    }
  }
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
using namespace std;
typedef pair <int,int> ii;
const ll MOD=1e9+7;
ll luythua(ll x,int y){
    if(y==0)return 1;
    ll k=luythua(x,y/2);
    return k*k%MOD*(y%2?x:1)%MOD;
}
ll C(int n,int k){
    if(n-k<k)k=n-k;
    ll res=1;
    for(int i=0;i<k;i++){
        res=res*(n-i)%MOD;
        res=res*luythua(i+1,MOD-2)%MOD;
    }
    return res;
}
int main() {
    int x,y;
    cin >> x >> y;
    if ((x+y)%3!=0||min(x,y)*2<max(x,y)) cout << 0;
    else {
        int k=abs(x-y);
        int bao = (x+y)/3;
        int hung=(bao-k)/2;
        cout<<C(bao,hung);
    }
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}
int main(){
  int n;cin>>n;
  
  cout<<2*n/gcd(2,n);
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int main() {
        //freopen("testcase", "r", stdin);

    int N, M;
    scanf("%d%d", &N, &M);
    vector<int> mask(N+1, 0);

    int a, b;
    while(M--){
        scanf("%d%d", &a, &b);
        mask[a]+=1;
        mask[b]+=1;
    }
    for(int i=0; i!=mask.size(); i++){
        if(mask[i]%2==1) {printf("NO\n"); return 0;}
    }
    printf("YES\n");
        return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    string s, t;
    cin >> s >> t;

    if (t.find(s) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3620
s = gets.chomp
q = gets.to_i

s1 = ''
s2 = s
reversed = false

q.times do
  t, f, c = gets.split

  if t.to_i == 1
    reversed = !reversed
    next
  end

  if (f.to_i == 1 && reversed) || (f.to_i == 2 && !reversed)
    s2 << c
  else
    s1 << c
  end
end

if reversed
  puts s2.reverse! << s1
else
  puts s1.reverse! << s2
end

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3+1, INF = 1e9;

int n, k, ans = INF, d[N][N];
vector<int> g[N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) d[i][j] = INF;
	for(int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i = 1; i <= n; i++) {
		queue<int> q;
		q.push(i);
		d[i][i] = 0;
		while(!q.empty()) {
			int u = q.front();
			q.pop();
			for(int v: g[u]) if(d[i][v] == INF) {
				d[i][v] = d[i][u] + 1;
				q.push(v);
			}
		}
	}
	if(k % 2) {
		for(int u = 1; u <= n; u++) for(int v: g[u]) {
			int cnt = 0;
			for(int i = 1; i <= n; i++) cnt += min(d[u][i], d[v][i]) > k/2;
			ans = min(cnt, ans);
		}
	} else {
		for(int v = 1; v <= n; v++) {
			int cnt = 0;
			for(int i = 1; i <= n; i++) cnt += d[v][i] > k/2;
			ans = min(cnt, ans);
		}
	}
	cout << ans;
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define REP(i,m,n) for (int i=m;i<n;i++)
#define FOR(i,m,n,a) for(int i=m;i<n;i+=a)
const ll MOD=1e9+7;
 
int n;
char p[100002];
bool ans[100002];
 
bool solve(){
  REP(i,2,n+2){
    if(p[i-1]=='o'){
      ans[i]=(ans[i-1])?ans[i-2]:(!ans[i-2]);
    }
    else{
      ans[i]=(ans[i-1])?(!ans[i-2]):ans[i-2];
    }
  }
 
  if(ans[0]==ans[n]&&ans[1]==ans[n+1]){
    REP(i,0,n){
      cout << (ans[i]?'S':'W');
    }
    cout << endl;
    return true;
  }
  return false;
}
 
int main(){
  cin >> n >> p;
  p[n]=p[0];p[n+1]=p[1];
 
  bool PAT[4][2]={{true,true},{true,false},{false,true},{false,false}};
  REP(i,0,4){
    ans[0]=PAT[i][0];
    ans[1]=PAT[i][1];
 
    if(solve()){
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

#define comp(a,b) a<b ? 1:0


int main(void){

    int w, h, x, y, r;

    //input
    scanf("%d %d %d %d %d",&w, &h, &x, &y, &r);

    if( w>0 && h>0 && r>0 ){
        if( r<=x && x<=(w-r) ){
            if( r<=y && y<=(h-r) ){
                printf("Yes\n");
            }
            else{
                printf("No\n");
            }
        }
        else{
            printf("No\n");
        }
    }
    else{
        printf("No\n");
    }

    return 0;

}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#define GROUND 0
#define WALL 500
#define INITIAL -1

int count();
void init();
void mark_n(int,int,int,int,int);
void mark_n_all(int);
bool isValidPoint(int,int);

using namespace std;
const int MAX_W = 20;
const int MAX_H = 20;
char floor_[MAX_W][MAX_H];
//floorツつセツづ算ツ術ツ甘鳴青板づ債ャツつエツづゥ
int step[MAX_W][MAX_H];
int width,height;

int main(){
  while(cin >> width >> height && width > 0){
    string line;
    int ix,iy;
    init();
    for(int i = 0; i < height; i++){
      cin >> line;
      for(int j=0; j < width ; j++){
	floor_[j][i] = line[j];
	if(line[j]=='@'){
	  step[j][i]=GROUND;
	  ix = j; iy = i;
	}else if(line[j]=='#'){
	  step[j][i]=WALL;
	}
      }
    }
    for(int k = 0; k < 300; k++){
      mark_n_all(k);
    }
    cout << count() << endl;
  }
}

int count(){
  int result =0;
  for(int i=0; i<height;i++){
    for(int j=0; j< width; j++){
      if(step[j][i] >= 0 && step[j][i] < WALL){
	result++;
      }
    }
  }
  return result;
}

void init(){
  for(int i=0; i<height;i++){
    for(int j=0; j< width;j++){
      step[j][i]=INITIAL;
    }   
  }
}

void mark_n(int n,int x,int y,int dx,int dy){
  int temp;
  for(int i =0; i< 4;i++){
    temp = dx;
    dx = dy;
    dy = -temp;
    if(isValidPoint(x+dx,y+dy) && step[x+dx][y+dy]==INITIAL){
      step[x+dx][y+dy] = n;
    }
  }
}

void mark_n_all(int n){
  for(int i = 0; i < height; i++){
    for(int j = 0; j < width ; j++){
      if(step[j][i]==n){
	mark_n(n+1,j,i,1,0);
      }
    }
  }
}

bool isValidPoint(int x,int y){
  if(x < 0 || x >=  width || y < 0 || y >= height){
    return false;
  }else{
    return true;
  }
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	map<int, int> P;
	for (int i = 0; i < N; i++) {
		for (int j = 2; j * j <= A[i]; j++) {
			if (A[i] % j == 0) {
				P[j]++;
				while (A[i] % j == 0) {
					A[i] /= j;
				}
			}
		}
		if (A[i] != 1) P[A[i]]++;
	}
	int MAX = 0;
	for (auto it = P.begin(); it != P.end(); it++) {
		MAX = max(MAX, it->second);
	}
	if (MAX <= 1) cout << "pairwise coprime" << endl;
	else if (MAX == N) cout << "not coprime" << endl;
	else cout << "setwise coprime" << endl;
}

Measured memory_bytes: 10904
/*
Hokudai Practice Contest 2014
A - King's Inspection

テδ「テッツ」ツソテδア@テδ?テδ鰻テδ円テδ嘉δ姪δ嘉δ・テδ?テδ鰻テδ嘉δ。テδ嘉δャ
テδィテδォテδ?つゥテδ?δ催δ??津δ?つ「テδ?δ暗δ嘉δ」テδ?テδ嘉δ」テδ?「ツ?ヲテδィ]テδ?つ。テδ??津δッテδコテδ・テ「ツ可・テδ?「ツ按妥δ?δ暗δ?δヲテδ?δ佚δ?
テδ嘉δ」テδ?テδ嘉δ」テδ?ッツ」ツソテδァテ?津δ・テつェテδ?「ツ按妥δ?δ暗δ?篠ゥテδ?ッツャツづδ?「ツ?ヲテδ?δ陛δ嘉δ、テδ厩テδ曳テδ?δεδィzテδ、テつャテδ?「ツ?堙δッテ「ツ按づδゥテδカテδ?δεδィzテδ、テつャテδ?ッツ」ツソテδァテ?津δ・テつェテδ?「ツ按妥δ?δ暗δッKテδウvテδ?「ツ?「テδ?「ツ??δ?δ暗δ?
(M-1)+1 -> 0, 0-1 -> (M-1)テδ?テδ?「ツ按?δ?つサテδ?δ暗δ?δ甘δ?つァテδ?「ツ?ヲテδ?「ツ按妥δ?δ暗δ?「ツ?ヲテδ?δ陛δ?テδィテδ凝δウ](%)テδ?ッツ」ツソテδウpテδ?つ「テδ?δ催δ??津δ?δ甘δ?つ「テδ?

テδゥテδサテδ、テ「ツ?佚δ・vテδゥZテδウテつ?δ?O(|s|)
テδ」テδ崚δ、テ「ツ?佚δ・vテδゥZテδウテつ?δ?O(n + |s|)
*/

#include<iostream>
#include<cctype>
using namespace std;

//a-zA-z -> テδィテδ。テδョテ「ツ??
int toInt(char a){
  if(islower(a))return a-'a';
  return a-'A'+26;
}

//テδィテδ。テδョテ「ツ??-> a-zA-Z
char toChar(int a){
  if(a<26)return 'a'+a;
  return 'A'+a-26;
}

//テδ「wテδェテδョ
const int M = 52;

int main(){
  int n,k[100];
  string s;

  while(cin >> n,n){
    for(int i=0;i<n;i++)cin >> k[i];
    cin >> s;

    for(int i=0;i<(int)s.size();i++){
      //テδィzテδ、テつャテδ?ッツ」ツソテδ鰻テδ円テδ嘉δ姪δ嘉δ・テδ?テδ鰻テδ嘉δ。テδ嘉δャテδ?「ツ按妥δ?δ暗δ?「ツ?ヲテδ?δ瀕odテδ?ッツ」ツソテδゥgテδ?つカテδ??津δウテつォテδ?つ「
      int tmp = toInt(s[i]) - k[i%n];
      //テδッテδ「テδェテδョテδ?「ツ?。テδ?「ツ??δ?δ凝δャテδヲテδ?δ暗δィテδ催δァテδ。テδ?δεδ?つソテδォSテδ?つサmodテδ?δεδゥテδ甘δ?δ凝δッテ仰堙δ?δ?(x%mod) + mod)%mod
      tmp = ((tmp%M) + M) % M;
      cout << toChar(tmp);
    }
    cout << endl;
  }
}

Measured memory_bytes: 1200
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
s = 0
if n % 2 == 0:
    s += a[0]
    for i in range((n - 2) // 2):
        s += a[i + 1] * 2
else:
    s += a[0]
    for i in range((n - 3) // 2):
        s += a[i + 1] * 2
    s += a[(n - 3) // 2 + 1]
print(s)

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

int main() {
	string s;
	cin >> s;
	if (!(s[0] == s[1] && s[1] == s[2] && s[0] == s[2])) 
		printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main()
{
	int i, count;
	bool f;
	string s;
	stringstream ss;

	getline(cin, s);
	ss.str("");
	count = 0;
	f = false;
	for (i = 0; i < s.size(); i++) {
		if (s[i]==' ' || s[i]==',' || s[i]=='.') {
			if (3<=count && count<=6) {
				if (f) cout<<" ";
				cout<<ss.str();
				f = true;
			}
			ss.str("");
			count = 0;
			continue;
		}
		count++;
		ss<<s[i];
	}
	cout<<endl;
	return 0;
}

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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(){
    int n;
    cin >> n;
    int xy[2][n];
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < n; j++){
            cin >> xy[i][j];
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        int sum1 = 0, sum2 = 0;
        for(int j = 0; j < i+1; j++){
            sum1 += xy[0][j];
        }
        for(int k = i; k < n; k++){
            sum2 += xy[1][k];
        }
        //cout << sum1 << " " << sum2 << endl;
        ans = max(ans, sum1 + sum2);
    }

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

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

int main(){
  int ash,asmi,ass,bsh,bsmi,bss,csh,csmi,css;
  int aeh,aemi,aes,beh,bemi,bes,ceh,cemi,ces;
  int ah=0,ami=0,as=0,bh=0,bmi=0,bs=0,ch=0,cmi=0,cs=0;
  cin>>ash>>asmi>>ass>>aeh>>aemi>>aes;
  cin>>bsh>>bsmi>>bss>>beh>>bemi>>bes;
  cin>>csh>>csmi>>css>>ceh>>cemi>>ces;
  ah=aeh-ash;
  ami=aemi-asmi;
  if(ami<0){
    ah=ah-1;
    ami=ami+60;
  }
  as=aes-ass;
  if(as<0){
    ami=ami-1;
    as=as+60;
  }
  if(ami<0){
    ah=ah-1;
    ami=ami+60;
  }

  bh=beh-bsh;
  bmi=bemi-bsmi;
  if(bmi<0){
    bh=bh-1;
    bmi=bmi+60;
  }
  bs=bes-bss;
  if(bs<0){
    bmi=bmi-1;
    bs=bs+60;
  }
  if(bmi<0){
    bh=bh-1;
    bmi=bmi+60;
  }

  ch=ceh-csh;
  cmi=cemi-csmi;
  if(cmi<0){
    ch=ch-1;
    cmi=cmi+60;
  }
  cs=ces-css;
  if(cs<0){
    cmi=cmi-1;
    cs=cs+60;
  }
  if(cmi<0){
    ch=ch-1;
    cmi=cmi+60;
  }

  cout<<ah<<" "<<ami<<" "<<as<<endl;
  cout<<bh<<" "<<bmi<<" "<<bs<<endl;
  cout<<ch<<" "<<cmi<<" "<<cs<<endl;

  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
using namespace std;
using ll = long long;

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

    int N; cin >> N;
    int count = 0;
    ll ans = 0, minA = 1LL << 30;
    for (int i = 0; i < N; i++) {
        ll A; cin >> A;
        minA = min(minA, abs(A));
        if (A < 0) count++;
        ans += abs(A);
    }
    cout << (count % 2 ? ans - minA * 2 : ans) << "\n";
}

Measured memory_bytes: 256
x = str(input())
if x == 'SSS':
  print(0)
elif x == 'SSR':
  print(1)
elif x == 'SRS':
  print(1)
elif x == 'RSR':
  print(1)
elif x == 'RSS':
  print(1)
elif x == 'SRR':
  print(2)
elif x == 'RRS':
  print(2)
else:
  print(3)

Measured memory_bytes: 9020
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[30005];
int main(){
for(int i=0;i<30005;i++)dp[i]=inf;
dp[0]=0;
ll h,n;
cin>>h>>n;
V<ll> a(n),b(n);
for(int i=0;i<n;i++)cin>>a[i]>>b[i];
for(int i=0;i<n;i++){
    for(int j=0;j<=30005;j++){
        if(j+a[i]<=30005&&dp[j]!=inf)chmin(dp[j+a[i]],dp[j]+b[i]);
    }
}
ll ans=inf;
for(int i=h;i<30000;i++)chmin(ans,dp[i]);
cout<<ans<<endl;
}

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

int main() {
  int a , b;
  cin >> a >> b;
  if ((a * b) % 2 == 0){
  	cout << "Even" << endl;
  }
  else if ((a * b) % 2 == 1){
  	cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int n;
long long a[200005],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]<a[i-1])
		{
		    ans+=abs(a[i]-a[i-1]);
			a[i]=a[i-1];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    if (s[i] == '+')
      ans++;
    else
      ans--;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ
int main()
{
    string a, b;
    cin >> a >> b;
    if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}

Measured memory_bytes: 256