akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int H, W, K;
string S[20];
int s[20][1010];


int sum(int x1, int y1, int x2, int y2){
    return s[y2][x2]-s[y1][x2]-s[y2][x1]+s[y1][x1];
}


int msum(int x1, int x2, int bit){
    int m = 0;
    int pre = 0;
    rep(i, 0, H-1) if((bit>>i)&1) chmax(m, sum(x1, pre, x2, i+1)), pre = i+1;
    return max(m, sum(x1, pre, x2, H));
}


signed main(){
    cin >> H >> W >> K;
    rep(i, 0, H) cin >> S[i];

    rep(i, 0, H) rep(j, 0, W) s[i+1][j+1] = s[i][j+1]+s[i+1][j]-s[i][j]+S[i][j]-'0';

    int ans = INF;
    rep(i, 0, 1<<(H-1)){
        int c = __builtin_popcount(i);
        int pre = 0;
        while(pre < W){
            int l = pre+1, r = W+1;
            while(r-l > 1){
                int m = l+(r-l)/2;
                if(msum(pre, m, i) <= K) l = m;
                else r = m;
            }
            if(msum(pre, l, i) <= K) c++;
            else { c = INF; break; }
            pre = l;
        }
        chmin(ans, c-1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
typedef pair<ll,ll> P;
bool isPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    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;
}
int main(){
    ll x;
    cin >> x;
    while(!isPrime(x)) x++;
    PRINT(x);
}


Measured memory_bytes: 256
import java.io.*;
 
class Main {
    public static void main(String[] args) {
        BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        try {
            int n = Integer.parseInt( kb.readLine() );
            
            int num, cnt = 0;
            int i, j;
            boolean isprime = true;
            for( i=0; i<n; i++ ) {
            	isprime = true;
            	num = Integer.parseInt( kb.readLine() );
            	for( j=2; j<=(num/j); j++ ) {
            		if( 0 == num%j ) {
            			isprime = false;
            			break;
            		}
            	}
            	if( isprime ) {
            		cnt++;
            	}
            }
            
            System.out.println( cnt  );
             
            kb.close();
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

Measured memory_bytes: 22756
#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define D                double
#define F                first
#define S                second
#define pb               push_back
#define pf               push_front
#define MP               make_pair
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define it(it,mp)        for(auto it=mp.begin() ; it!=mp.end() ; it++)
#define IOS              ios_base :: sync_with_stdio(false); cin.tie(NULL);
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
typedef long long int                   ll;
typedef pair<int,int>                   PII;
int dx[] =  {1, -1, 1, -1, 2, 2, -2, -2};
int dy[] = {2, 2, -2, -2, 1, -1, 1, -1};
int main()
{
    IOS
    // READ(0test.txt);
    vector<int>v ;
    for(int i=1 ; i<=9 ; i++){
        v.pb(i) ;
    }
    int n ;
    cin >> n ;
    for(int i=1 ; i<10 ; i++){
        for(int j=1 ; j<10 ; j++){
            if(i*j==n){
                return cout<<"Yes",0;
            }
        }
    }
    cout<<"No";

}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

const int N = 2e5 + 5;
vector<v32> adj(N, v32());
int vis[N], tym[N], tot, node;

void dfs(int i, int &cycle)
{
	vis[i] = 1;
	tym[i] = tot++;
	for (int j : adj[i])
	{
		if (!vis[j])
			dfs(j, cycle);
		else
		{
			cycle = (tym[i] - tym[j] + 1);
			node = j;
			return;
		}
	}
}

void solve()
{
	ll n, k;
	cin >> n >> k;
	v64 arr(n + 1, 0);
	for (int i = 1; i < n + 1; i++)
	{
		cin >> arr[i];
		adj[i].push_back(arr[i]);
	}
	int cycle = 0;
	tot = 0;
	node = -1;
	dfs(1, cycle);
	assert(cycle && node != -1);
	db(node, cycle);
	int curr = 1;
	while (curr != node && k--)
		curr = arr[curr];
	if (k > 0)
	{
		k %= cycle;
		while (k--)
			curr = arr[curr];
	}
	cout << curr << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 29588
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main()
{
    int n,ans=0,before=-2;
    cin>>n;
    vector<int> a(n),b(n),c(n-1);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n-1) cin>>c[i];
    for(int i:a)
    {
        i--;
        ans+=b[i];
        if(i==before+1) ans+=c[before];
        before=i;
    }
    cout<<ans;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
typedef long long int lli;
using namespace std;

int main()
{
  int N,M;
  scanf("%d%d",&N,&M);

  int A,B;
  
  vector<pair<int,int>> pr;
  
  REP(i,N)
    {
      scanf("%d%d",&A,&B);

      pr.push_back(make_pair(A,B));
      
    }

  sort(ALL(pr));

  int cnt = 0;
  int nbtl = 0;
  int ind = 0;
  lli money = 0;
  
  while( cnt < M )
    {

      money += pr[ind].first;
      ++ cnt;
      ++ nbtl;

      if( nbtl == pr[ind].second )
	{
	  ++ ind;
	  nbtl = 0;
	  
	}
      
    }

  printf("%lld\n",money);
  


}


Measured memory_bytes: 1400
//ΔAGC035B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 111111;
int n,m,a[N],b[N],f[N],c[N];
vector<int> v[N];
int fnd(int x){
	if(f[x]==x)
		return x;
	return f[x]=fnd(f[x]);
}
void dfs(int u,int fa){
	int i,o,x;
	for(i=0;i<v[u].size();i=i+1){
		o=v[u][i];
		x=u^a[o]^b[o];
		if(x==fa)
			continue;
		dfs(x,u);
		if(c[x]){
			if(b[o]==x)
				swap(a[o],b[o]);
		}
		else{
			if(b[o]==u)
				swap(a[o],b[o]);
			c[u]^=1;
		}
	}
}
int main()
{
	int i,x,y;
	scanf("%d%d",&n,&m);
	if(m&1){
		cout<<-1;
		return 0;
	}
	for(i=1;i<=n;i=i+1)
		f[i]=i;
	for(i=1;i<=m;i=i+1){
		scanf("%d%d",&x,&y);
		a[i]=x,b[i]=y;
		if(fnd(x)==fnd(y))
			c[x]^=1;
		else{
			v[x].push_back(i);
			v[y].push_back(i);
			f[fnd(x)]=fnd(y);
		}
	}
	dfs(1,0);
	for(i=1;i<=m;i=i+1)
		printf("%d %d\n",a[i],b[i]);
	return 0;
}

Measured memory_bytes: 15488
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};



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


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int wish[4001][4001];

int getsum(int sx, int sy, int tx, int ty){
        assert(sx <= tx && sy <= ty);
        int res = wish[tx][ty];
        if (0 < sx) res -= wish[sx-1][ty];
        if (0 < sy) res -= wish[tx][sy-1];
        if (0 < sx && 0 < sy) res += wish[sx-1][sy-1];
        return res;
}

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

    int N, K;
    cin >> N >> K;
    REP(i, 4*K)REP(j, 4*K) wish[i][j] = 0;

    REP(i, N){
        int x, y;
        char c;
        cin >> x >> y >> c;
        if(c == 'B'){
            wish[x%(2*K)][y%(2*K)]++;
            wish[x%(2*K) +(2*K)][y%(2*K)]++;
            wish[x%(2*K)][y%(2*K) +(2*K)]++;
            wish[x%(2*K) +(2*K)][y%(2*K) +(2*K)]++;
        }else{
            wish[(x+K)%(2*K)][y%(2*K)]++;
            wish[(x+K)%(2*K) +(2*K)][y%(2*K)]++;
            wish[(x+K)%(2*K)][y%(2*K) +(2*K)]++;
            wish[(x+K)%(2*K) +(2*K)][y%(2*K) +(2*K)]++;
        }
    }

    REP(x, 4*K)REP(y, 4*K-1) wish[x][y+1] += wish[x][y];
    REP(y, 4*K)REP(x, 4*K-1) wish[x+1][y] += wish[x][y];

    int ans = -1;
    REP(x, 2*K)REP(y, 2*K){
        int tmp = getsum(x, y, x+K-1, y+K-1) + getsum(x+K, y+K, x+(2*K)-1, y+(2*K)-1);
        ans = max(ans, tmp);
    }

    // REP(x, 4*K){
    //     REP(y, 4*K) cout << wish[x][y];
    //     cout << "\n";
    // }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 62720
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n){return REPS(n).map(i->getInt());}
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int n=getInt(),p[]=new int[n];
		for(int l=n*(n-1)/2;l>0;--l) {
			int a=getInt()-1,b=getInt()-1,pa=getInt(),pb=getInt();
			if(pa>pb)
				p[a]+=3;
			else if(pa<pb)
				p[b]+=3;
			else {
				++p[a];
				++p[b];
			}
		}
		AtomicInteger c=new AtomicInteger(0);
		int r[]=new int[n];
		REPS(1,n).boxed()
				.collect(Collectors.groupingBy(i->p[i-1]))
				.entrySet().stream()
				.sorted(Entry.comparingByKey(Comparator.reverseOrder()))
				.map(Entry::getValue)
				.forEach(o->{
					c.incrementAndGet();
					for(int i:o)
						r[i-1]=c.get();
					c.addAndGet(o.size()-1);
				});
		Arrays.stream(r).forEach(System.out::println);
	}
}

Measured memory_bytes: 46304
#include <iostream>

int triangle(int x, int y, int z)
{
	int a = x * x;
	int b = y * y;
	int c = z * z;
	return (a + b - c) * (b + c - a) * (c + a - b);
}

int main()
{
	int N, x, y, z;
	
	std::cin >> N;
	
	for(int i = 0; i < N; i++){
		std::cin >> x >> y >> z;
		if ( triangle(x, y, z) == 0 ){
			std::cout << "YES" << std::endl;
		} else {
			std::cout << "NO" << std::endl;
		}
	}
	
	return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, c, d;
  	cin >> a >> b >> c >> d;
  	if (a + b == c + d) {
    	cout << "Balanced" << '\n';
    	return 0;
    }
  	cout << (a + b > c + d ? "Left" : "Right") << '\n';
    return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  map<ll,ll> mp;
  for(int i=0;i<4;i++){
    ll tmp;
    cin >> tmp;
    mp[tmp]++;
  }
  if(mp[1]&mp[9]&mp[7]&mp[4]) cout << "YES\n";
  else cout <<"NO\n";
}


Measured memory_bytes: 256
//Teleporter 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,k;cin>>n>>k;
    vector<int>a(n);
    rep(i,0,n){
        int t;cin>>t;
        a[i]=t-1;
    }
    map<int,int>m{};
    int g=a[0],kai=0;
    m[0]++;
    vector<int>ni;
    while(m[g]<2){
        kai++;
        if(kai==k){
            cout<<g+1<<nnn;
            return 0;
        }
        m[g]++;
        if(m[g]==2)ni.pb(g);
        g=a[g];
    }
    int c=0,o=0;
    for(auto i:m){
        if(i.second==2)c++;
        else if(i.second==1)o++;    
    }
    k-=o;k%=c;
    cout<<ni[k]+1<<nnn;
    return 0;
}

Measured memory_bytes: 14796
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i)
const int N = 2005 ;
const int flg[4][2] = {{0, 1}, {0, - 1}, {1, 0}, {- 1, 0}} ;
using namespace std ;

int n, m, q, fa[N * N], f[N][N], Gx[N][N], Gy[N][N];
char ch[N][N] ;
bool vis[N][N] ;

void dfs(int x, int y) {
	int p = (x - 1) * m + y ;
	vis[x][y] = true ;
	rep(i, 0, 3) {
		int vx = x + flg[i][0], vy = y + flg[i][1] ;
		if (vx < 1 || vx > n || vy < 1 || vy > m) continue ;
		if (ch[vx][vy] == '0') continue ;
		if (vis[vx][vy]) continue ;
		int v = (vx - 1) * m + vy ;
		fa[v] = p ;
		dfs(vx, vy) ;
	}
}

int main() {
	scanf("%d%d%d", &n, &m, &q) ;
	rep(i, 1, n) scanf("%s", ch[i] + 1) ;
	rep(i, 1, n) rep(j, 1, m)
		if (ch[i][j] == '1' && !vis[i][j]) dfs(i, j) ;
	
	rep(i, 1, n) rep(j, 1, m) if (ch[i][j] == '1') {
		++ f[i][j] ;
		int x = i, y = j, u = (i - 1) * m + j;
		int v = fa[u] ;
		if (v) {
			int vx = (v - 1) / m + 1, vy = (v - 1) % m + 1 ;
			if (vy == y) ++ Gx[min(x, vx)][y] ; else
				++ Gy[x][min(y, vy)] ;
		}
	}
	rep(i, 2, n) rep(j, 1, m) {
		f[i][j] += f[i - 1][j] ;
		Gx[i][j] += Gx[i - 1][j] ;
		Gy[i][j] += Gy[i - 1][j] ;
	}
	rep(i, 1, n) rep(j, 2, m) {
		f[i][j] += f[i][j - 1] ;
		Gx[i][j] += Gx[i][j - 1] ;
		Gy[i][j] += Gy[i][j - 1] ;
	}
 	int x1, y1, x2, y2 ;
	rep(i, 1, q) {
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2) ;
		int ret = f[x2][y2] - f[x1 - 1][y2] - f[x2][y1 - 1] + f[x1 - 1][y1 - 1] ;
		if (x1 < x2) {
			-- x2 ;
			ret -= Gx[x2][y2] - Gx[x1 - 1][y2] - Gx[x2][y1 - 1] + Gx[x1 - 1][y1 - 1] ;
			++ x2 ;
		}
		if (y1 < y2) {
			-- y2 ;
			ret -= Gy[x2][y2] - Gy[x1 - 1][y2] - Gy[x2][y1 - 1] + Gy[x1 - 1][y1 - 1] ;
		}
		printf("%d\n", ret) ;
	}
	return 0 ;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int result = 0;
            for (int x = 0; x < array.Length - 1; x++)
            {
                for (int y = x + 1; y < array.Length; y++)
                {
                    result += array[x] * array[y];
                }
            }

            Console.WriteLine(result);
        }

    }
}


Measured memory_bytes: 13396
import numpy as np
n, W = map(int, input().split())
dp = np.zeros((n,W+1), dtype='int64')

for i in range(n):
    w, v = map(int , input().split())

    # print("left", dp[i, :w])
    # print("right", dp[i-1, :w])
    dp[i, :w] = dp[i-1, :w]
    dp[i, w:] = np.fmax(dp[i-1, w:], dp[i-1,:W-w+1]+v)

    # print(dp[i])
print(dp[n-1][W])


Measured memory_bytes: 91924
#include<stdio.h>
int main(void)
{
    int n,cnt,num,i;
    scanf("%d",&n);
    cnt=0; num=n-1;
    for(i=1;i<n;i++){
        while(num*i>=n) num--;
        cnt+=num;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
#include<stdlib.h>
int main(){
int i;
char *s=(char *)malloc(1000000001*sizeof(char));
scanf("%s",s);
int num=atoi(s);
int sum=0;
for(i=0;s[i]!='\0';i++){
  sum+=s[i]-'0';
}
if(num%sum==0) printf("Yes");
else printf("No");

return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

struct UnionFind{
	vector<int> par;//par[i]:=(0以上の場合,iの親. 0未満の場合はiを含むグループのサイズ).
	int num;		//num:=(Number of groups).
	
	UnionFind(int n):par(n,-1),num(n){}//Constructor.
	
	void reset(int n){par.assign(n,-1), num=n;}
	int root(int x){return (par[x]<0)?x:par[x]=root(par[x]);}//Recrusion.
	int size(int x){return -par[root(x)];}
	bool same(int x,int y){return root(x)==root(y);}
	bool unite(int x,int y){
		x=root(x), y=root(y);
		if(x==y) return false;//Do nothing.
		if(size(x)<size(y)) swap(x,y);//Merge technique.
		par[x]+=par[y];
		par[y]=x;
		num--;
		return true;
	}
};

int main(){
	int n;
	int m,k;
	cin>>n>>m>>k;
	
	UnionFind fri(n);
	vi ans(n,0);
	REP(i,m){
		int a,b;
		cin>>a>>b;
		a--, b--;
		fri.unite(a,b);
		ans[a]--;
		ans[b]--;
	}
	
	REP(i,k){
		int c,d;
		cin>>c>>d;
		c--, d--;
		if(fri.same(c,d)){
			ans[c]--;
			ans[d]--;
		}
	}
	
	REP(i,n) ans[i]+=fri.size(i)-1;
	
	line(ans);
}

Measured memory_bytes: 1664
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<String> list = new ArrayList<String>();
		boolean flag = false;
		char s = '0';

		first: for(int i = 0; i < n; i++) {
			list.add(sc.next());
			if(list.size() > 1) {
				if(s != list.get(i).charAt(0)) {
					break;
				}for(int j = 0; j < i; j++) {
					if(list.get(j).equals(list.get(i))) {
						break first;
					}
				}
			}
			s = list.get(i).charAt(list.get(i).length()-1);
			if(i == n-1)flag = true;
		}
		if(flag) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

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

    vector<pair<ll, ll>> L(n);
    rep(i,n) {
        ll a, b;
        cin >> a >> b;
        L[i] = make_pair(b, a);
    }
    sort(L.begin(), L.end());


    ll tot = 0;
    for (auto p : L) {
        ll a = p.second;
        ll x = p.first;
        tot += a;
        if (tot > x) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;



    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b,c;
  cin >> a;
  
  if(a<1200){
    cout << "ABC" <<endl;
  }else if(a<2800){
	cout << "ARC" <<endl;
  }else{
	cout <<"AGC" <<endl;
  }
  
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;

signed main(){
    int n;
    cin>>n;
    ll k;
    cin>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
    }
    vector<int> c(n,-1);
    int now=0;
    int cnt=0;
    c[0]=cnt;
    while(cnt<k){
        now=a[now];
        cnt++;
        if(c[now]==-1)c[now]=cnt;
        else {
            k-=c[now];
            k%=cnt-c[now];
            while(k>0){
                now=a[now];
                k--;
            }
            cout<<now+1<<endl;
            return 0;
        }
    }
    cout<<now+1<<endl;
}

Measured memory_bytes: 4844
from fractions import gcd
n,m = [int(x) for x in input().split()]
s = input()
t = input()

def f(n,m):
    return n*m // gcd(n,m) 

ans = f(n,m)

if s[::ans//m] == t[::ans//n]:
    print(ans)
else:
    print(-1)

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



int main() {
    ll N,A,B;
    cin>>N>>A>>B;
    ll x=N/(A+B),y=N%(A+B);
    ll ans=x*A;
    ans+=min(y,A);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}

int main(){
    int n,m; scanf("%d%d",&n,&m);
    vector<int> h(n+1);
    for(int i=1;i<=n;i++) scanf("%d",&h[i]);
    vector<int> G[n+1];
    for(int i=1;i<=m;i++){
        int u,v; scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    ll cnt=0;
    for(int i=1;i<=n;i++){
        bool ok=1;
        for(auto v:G[i])
            if(h[i]<=h[v]){
                ok=0;
                break;
            }
        if(ok) cnt++;
    }
    printf("%lld\n",cnt);
}


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

int main(){
	int H,W;
  cin>>H>>W;
  for(int i=0;i<W;i++)
    cout<<"#";
  cout<<"##"<<endl;
  vector<char> str(W);
  for(int i=0;i<H;i++){
    cout<<"#";
  	for(int j=0;j<W;j++){
      cin>>str.at(j);
      cout<<str.at(j);
    }
    cout<<"#"<<endl;
  }
  for(int i=0;i<W;i++)
    cout<<"#";
  cout<<"##"<<endl;
}

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    string s;
    cin >> s;
    s[1]='R'^'B'^s[1];
    cout << s << endl;
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e3 + 13;
int n, ans, x;
bool mark[maxN];
vector<int> vec;
int main () {
    cin >> n;
    for (int i = 0; i < n; i++) {
	int a;
	cin >> a;
	x ^= a;
	a = __builtin_ctz(a);
	mark[a] = 1;
    }

    while (x) {
	vec.push_back(x % 2);
	x /= 2;
    }
    int indx = vec.size() - 1;
    int lst = 0;
    while (vec.size()) {
	int u = vec.back();
	vec.pop_back();
	if (u != lst) {
	    if (!mark[indx])
		return cout << -1 << endl, 0;
	    else
		ans++;
	}
	indx--;
	lst = u;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# t = "abcdefghijklmnopqrstuvwxyz"
s = input()
t = set(list(s))
ans = 1000
for i in t:
    S = s
    c = 0
    while len(set(S))!=1:
        c+=1
        ts = ""
        for  j,k in zip(S,S[1:]):
            if j == i or k == i:
                ts+=i
            else:
                ts+=k
        S = ts
    ans = min(ans,c)
    # print(c)

print(ans)




Measured memory_bytes: 41836
n,m=list(map(int,input().split(' ')))
s=[]
for i in range(0,m):
    s.append(list(map(int,input().split(' '))))
K=[0]*n
for i in s:
    a,b=i
    if K[a-1]==0 and b==0:
        K[a-1]=-1
    if K[a-1]==0:
        K[a-1]=b
    if K[a-1]!=b and b!=0:
        print(-1)
        quit()
for i in s:
    a,b=i
    if K[a-1]==0 and b==0:
        K[a-1]=-1
    if K[a-1]!=b and b!=0:
        print(-1)
        quit()
if n>2:
    if K[0]==-1:
        print(-1)
        quit()
    if K[0]==K[1]==-1:
      print(-1)
      quit()
    if K[1]==-1:
        K[1]=0
    if K[2]==-1:
        K[2]=0
    if K[0]==0:
        K[0]=1
    print(K[0]*100+K[1]*10+K[2])
if n==2:
    if K[1]==-1:
        K[1]=0
    if K[0]==-1:
        print(-1)
        quit()
    if K[0]==0:
      K[0]=1
    print(K[0]*10+K[1])
if n==1:
    if K[0]==-1:
        print(0)
        quit()
    print(K[0])

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define vi vector
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000007
#define pb push_back
#define ll long long int
#define db double
#define all(v) v.begin(),v.end()
#define inf 10000000000


using namespace std;

/*

ll expo(ll n){
    ll t;
    if(n==0)return 1;
    else if(n==1) return 2;
    t=expo(n/2);
    if(n%2){
        return t*t*2;
    }
    else return t*t;
}

//ffrom geek for geek
ll exponentMod(ll A, ll B, ll C)  
{  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
    ll y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (ll)((y + C) % C);  
}

*/
/*
class dsu{
public:    
vi<ll> v;


void init(ll n){
    v.assign(n+1,-1);
}

 
ll dsufind(ll x){
    if(v[x]<0){
        return x;
    }
    v[x]=dsufind(v[x]);
    return v[x];
}
 
void dsujoin(ll x,ll y){
    x=dsufind(x);
    y=dsufind(y);
    
    if(x==y)
    return;
    if(v[x]>v[y])swap(x,y);
    v[y]+=v[x];
    v[x]=y;
}

};
*/



int main(){
    IOS;
    ll t;
    t=1;
   //cin>>t;
    while(t--){
       ll x;
       cin>>x;
       if(x==0)
       cout<<1<<"\n";
       else{
           cout<<0<<"\n";
       }
    }    
    return 0;
} 

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int timex = 0;

int n;

string *color = new string[n];

int *d = new int[n];

int *f = new int[n];

int c[100][100];

void dfs(int u){
  color[u] = "glay";
  d[u] = ++timex;


  for(int v = 0; v < n; v++){
    if(c[u][v] == 1 && color[v] == "white"){
      dfs(v);
    }
  }

color[u] = "black";
f[u] = ++timex;



}

int main(){

  cin >> n;

  color = new string[n];

  d = new int[n];

  f = new int[n];


  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      c[i][j] = 0;
    }
  }

  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int v;
      cin >> v;
      c[i][v - 1] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    color[i] = "white";
  }

  for(int i = 0; i < n; i++){
    if(color[i] == "white"){
      dfs(i);
    }
  }



  for(int i = 0; i < n; i++){
    cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
  }




  return 0;
}



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

int main() {
  int N,count=0;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  } 
  sort(vec.begin(),vec.end());
  if(N%2==1){
    for(int i=0;i+1<N;i+=2){
      count+=vec[i+2]-vec[i+1];
    }
    count+=vec[0];
  }
  else{
    for(int i=0;i+1<N;i+=2){
      count+=vec[i+1]-vec[i];
    }
  }
  cout<<count<<endl;
}

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

signed main() {
  int s;
  cin >> s;
  
  set<int> kazu;
  kazu.insert(s);
  
  for( int i = 2; i <= 1000000; i++ ){
    if( s % 2 == 0 ){ //偶数
      s /= 2;
    }else{ //奇数
      s = 3*s + 1;
    }
    if( kazu.count(s) ){
      cout << i << endl;
      return 0;
    }else{
      kazu.insert(s);
    }
  }
  
}



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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; string s;
	cin >> n >> s;
	map<pair<string,string>, ll> cnt1, cnt2;
	REP(i, 1 << n) {
		string a, b;
		REP(j, n) {
			if ((1 << j)&i)a.push_back(s[j]);
			else b.push_back(s[j]);
		}
		cnt1[{a, b}]++;
	}
	REP(i, 1 << n) {
		string a, b;
		REP(j, n) {
			if ((1 << j)&i)a.push_back(s[2*n-1-j]);
			else b.push_back(s[2*n-1-j]);
		}
		cnt2[{a, b}]++;
	}
	ll ans = 0;
	for (auto k : cnt1) {
		string a = k.first.first, b = k.first.second;
		ans += k.second*cnt2[{b, a}];
	}
	cout << ans << endl;
}

Measured memory_bytes: 108288
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=1e5+9;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    cout<<count(s.begin(),s.end(),'1');
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>

using namespace std;

int main(void){

  
  int N;
  vector<int> H;
  int ans = 0;
  
  cin >> N;

  for(int i=0; i < N ; i++){
    int tmp;
    cin >> tmp;
    H.push_back(tmp); 
  }

 int i = 0;
 int count = 0;
while(i < N-1){
  if( H.at(i) >= H.at(i+1)){
    count++;
    i++;
  }else{
    i++;
    if(ans < count){
      ans = count;
    }
    count = 0;
  }
}

  if(ans < count){
      ans = count;
    }


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




Measured memory_bytes: 892
# Your code here!
n=gets.to_i


array=[2,3,5,7,11,13,17,19,23,29,31]
array2=[0,0,0,0,0,0,0,0,0,0,0]
array3=[[2,0],[3,0],[5,0],[7,0],[11,0],[13,0],[17,0],[19,0],[23,0],[29,0],[31,0]]


j=1
k=j+1
n.times{

loop{
    i=0
11.times{
    if j%array[i]==0
        j=j/array[i]
        array3[i][1]+=1
        break
    
 else
        i+=1
    end
    
    
    
}
if j==1 
    break
end

if  i==11 && array3.flatten.include?(j)
    nnn=array3.flatten.index(j)
    array3[nnn/2][1]+=1
    break
elsif  i==11
   array3<<[j,1]
   break
end


}


j=k
k=k+1


}





answer=1
kk=0
array3.length.times{
    answer=answer*(array3[kk][1]+1)
    answer=answer%1000000007
    kk+=1
}


puts answer




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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s;
	set<string> myset;
    cin >> n;
    for(int i=0;i<n;i++){
        cin>>s;
        myset.insert(s);
    }
    cout<<myset.size()<<endl;
    return 0;
}

Measured memory_bytes: 19228
#include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <cmath>
    #include <map>

    #define ll long long
    #define mod 1000000007
    using namespace std;

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        ll n,x;
        cin>>n>>x;
        ll m[n+1],sum=0;
        for(int i=0;i<n;i++) { cin>>m[i]; sum+=m[i]; }
        x-=sum;
        ll ans=n;
        sort(m,m+n);
        ans+=(x/m[0]);
        cout<<ans<<"\n";
        return 0;
    }

Measured memory_bytes: 256
import bisect
def LIS():
    L[0] = A[0]
    length = 1
    for i in range(1, N):
        if L[length-1] < A[i]:
            L[length] = A[i]
            length += 1
        else:
            j = bisect.bisect_left(L, A[i])
            L[min(length-1, j)] = A[i]
    return length

def LISDesc():
    L[0] = A[-1]
    length = 1
    for i in range(N-2, -1, -1):
        if L[length-1] <= A[i]:
            L[length] = A[i]
            length += 1
        else:
            j = bisect.bisect_right(L, A[i])
            L[min(length-1, j)] = A[i]
    return length

INFTY = 10**13
N = int(input())
A = [int(input()) for i in range(N)]
L = [INFTY for i in range(N)]
ans = LISDesc()
print(ans)


Measured memory_bytes: 7864
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
const int M = 100000;

int main()
{
	int a, b;
	cin >> a >> b;
	double d;
	d = (double)a / (double)b;
	cout << fixed;
	cout << a / b << " " << a%b << " " <<setprecision(8)<< d << endl;
	return 0;
}

Measured memory_bytes: 3292
// Problem Code: abc176_b

#include <iostream>
#include <string>

using namespace std;

string is_multiple(string N) {
	int sum = 0;
	for (char& c: N)
		sum += c - '0';
	return (sum % 9 == 0) ? "Yes" : "No";
}

int main() {
	string N;
	cin >> N;
	cout << is_multiple(N);
	return 0;
}

Measured memory_bytes: 3912
using System;

class Program
{
  static void Main(string[] arg)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    
    if(a + b == c || a + c == b || b + c == a) Console.WriteLine("Yes");
    else Console.WriteLine("No");
  }
}

Measured memory_bytes: 11092
# 配列の中がすべて奇数になるまでの試行回数最大値を求める
N = gets.strip.to_i
arr = gets.strip.split(' ').map(&:to_i)

def single_check target
  count = 0
  while target % 2 == 0
    target = target / 2
    count += 1
  end
  count
end

arr.select!{|v| v % 2 == 0}
total = 0
arr.each do |target|
  total += single_check target
end

puts total


Measured memory_bytes: 2428
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int num;
int X,Y;
vector<vector<char>> vec;
vector<vector<bool>> reg(Y,vector<bool>(X,0));
void search(int y,int x){
  //  cout<<"search"<<x <<" "<<y<<endl;
    bool h=0;
 //   reg[x][y]=0;
    if(x+1<X){
        if(reg[y][x+1]==1){
            num++;
          //  cout<<"count"<<endl;
            reg[y][x+1]=0;
            search(y,x+1);
            h=1;
        }
    }
    if(x-1>=0){
        if(reg[y][x-1]==1){
            num++;
         //   cout<<"count"<<endl;
            reg[y][x-1]=0;
            search(y,x-1);
            h=1;
            
        }
    }
    if(y+1<Y){
        if(reg[y+1][x]==1){
            num++;
          //  cout<<"count"<<endl;
            reg[y+1][x]=0;
            search(y+1,x);
            h=1;
            
        }
    }
    if(y-1>=0){
        if(reg[y-1][x]==1){
            num++;
          //  cout<<"count"<<endl;
            reg[y-1][x]=0;
            search(y-1,x);
            h=1;
            
        }
    }
    if(h==0){
     //   cout<<"OUT"<<endl;
    }
}
int main(){
    while(1){
        
        cin >> X >> Y;
        if(X==0 || Y==0){
            break;
        }
        num=0;
        vec.assign(Y,vector<char>(X,'0'));
        reg.assign(Y,vector<bool>(X,0));
        int start_x=0;
        int start_y=0;
      //  int c=0;
        for(int i=0;i<Y;i++){
            string s;
            cin >> s;
            for(int j=0;j<X;j++){
                vec[i][j]=s[j];
                if(s[j]=='@'){
                    start_x=j;
                    start_y=i;
                }
                else if(s[j]=='.'){
                    reg[i][j]=1;
                }else{
                 //   c++;
                }
            }
        }
         //   cout<<c<<endl;
       // cout<<start_x<<","<<start_y<<endl;
       search(start_y,start_x);
       cout<<num+1<<endl;
    }
}


Measured memory_bytes: 3264
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum=1, cnt;

ll c=1e18;

ll a[1000000];
int main(){
	ll n;
	cin>>n;
	
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(ll i=0; i<n; i++){
		sum *=a[i];
		if(sum ==0){
			cout<<0<<endl;
			return 0;
		}
		
		if(i<n-1 && a[i+1]>c/sum ) {
			cout<<-1;
			return 0;
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 4420
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const double EPS = 1.0e-10;
const double PI = acos(-1.0);

class Point
{
public:
    double y, x;
    Point(){
        y = x = 0.0;
    }
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    Point(double theta){
        y = sin(theta);
        x = cos(theta);
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(double a) const{
        return Point(y * a, x * a);
    }
    Point operator/(double a) const{
        return Point(y / a, x / a);
    }
    double length() const{
        return sqrt(y * y + x * x);
    }
    double dist(const Point& p) const{
        return sqrt(pow(y - p.y, 2) + pow(x - p.x, 2));
    }
    double dot(const Point& p) const{
        return y * p.y + x * p.x; // |a|*|b|*cos慮
    }
    double cross(const Point& p) const{
        return x * p.y - y * p.x; // |a|*|b|*sin慮
    }
    double angle() const{
        return atan2(y, x);
    }
};

double polygonArea(const vector<Point>& p)
{
    int n = p.size();
    double ret = 0.0;
    for(int i=0; i<n; ++i)
        ret += p[i].cross(p[(i+1)%n]);
    return ret / 2.0;
}

int main()
{
    double r;
    Point center;
    int n;
    cin >> r >> center.x >> center.y >> n;

    vector<int> percent(n);
    for(int i=0; i<n; ++i)
        cin >> percent[i];

    vector<Point> p(n+1);
    p[0] = Point(PI/2) * r;
    int sum = 0;
    for(int i=0; i<n; ++i){
        sum += percent[i];
        p[i+1] = Point(PI/2 - 2*PI * (sum/100.0)) * r;
    }

    vector<double> initArea(n, 0.0);
    vector<double> area(n, 0.0);
    for(int i=0; i<n; ++i){
        initArea[i] = r * r * PI * (percent[i] / 100.0);
        if(percent[i] <= 50){
            area[i] = initArea[i];
            vector<Point> q(3);
            q[0] = Point(0, 0);
            q[1] = p[i+1];
            q[2] = p[i];
            area[i] -= polygonArea(q);
            q[0] = center;
            area[i] += polygonArea(q);

        }
    }

    int k = min_element(area.begin(), area.end()) - area.begin();
    if(area[k] < EPS)
        area[k] = r * r * PI - accumulate(area.begin(), area.end(), 0.0);

    for(int i=0; i<n; ++i){
        int ret = area[i] / initArea[i] * 100;
        cout << ret;
        if(i < n-1)
            cout << ' ';
        else
            cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
using namespace std;
int n=0, k=0, a[200000] = {}, sam, b[100000] = {}, roop = 0, save[100000] = {0}, ans[100000] = {}, w = 0;
int main(void){
	while (1){
	  //	int n=0, k=0, a[100000] = {}, sam, b[1000] = {}, roop = 0, save[1000] = {0}, ans[1000] = {}, w = 0;
		cin >> n >> k;
		if (n == 0 || k == 0)
		  return 0;
		for (int i = 0; i<k; i++){
			cin >> a[i];
		}
		
		sort(a, a + k);
		for (int i = 0; i<k; i++){
			if (a[i + 1] - a[i] == 1){
				sam++;
			}
			else if (a[i + 1] - a[i] != 1){
				b[roop] = sam+1;
				if(a[0]==0){
					if (a[i + 1] - a[i] == 2){
						save[w] = roop;
						w++;
					}
				}
				sam = 0;
				roop++;
			}
		}
		for (int i = 0; i <= roop; i++){
			if (save[i] != 0){
				ans[i] = b[save[i]];
				ans[i]+= b[save[i] + 1] + 1;
			}
		}
		sort(b, b + roop+1);
		sort(ans, ans + roop+1);
		if (ans[roop]>b[roop])
		cout << ans[roop] << endl;
		if (ans[roop] <= b[roop]){
			if(a[0]==0){
		       	cout << b[roop]+1 << endl;
			}
			else{
			cout << b[roop] << endl;
			}
		}
		
	}
	return 0;
}

Measured memory_bytes: 1684
# https://atcoder.jp/contests/abc079/tasks/abc079_d

# 各数字を1に書き換えるときの最小のコストを保持しておけば良い。
# どうやって最小のコストを保持する？→ダイクストラ的なdpを実装すれば良い
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix, lil_matrix
import numpy as np
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


H, W = read_ints()
C = csr_matrix(read_matrix(10))
A = read_matrix(H)

# ダイクストラDFでi→1の各点への最短経路を計算する。
D = dijkstra(C, directed=True)

ans = 0
for a in A:
    for aa in a:
        if abs(aa) == 1:
            continue
        ans += D[aa][1]

print(int(ans))


Measured memory_bytes: 17868
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) scanf("%d%d", &a[i], &b[i]);
	sort(begin(a), end(a)); sort(begin(b), end(b));

	i64 ans = 0;
	if(n & 1) {
		ans = b[n >> 1] - a[n >> 1] + 1;
	} else {
		i64 A = a[n / 2] + a[n / 2 - 1];
		i64 B = b[n / 2] + b[n / 2 - 1];
		ans = B - A + 1;
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin>>h[i];
    }
    int cnt=0;
    for(int i=0; i<n; i++){
        int m=0;
        for(int j=0; j<i; j++){
            m=max(m,h[j]);
        }
        if(h[i]>=m)cnt++;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
const int INF = 1001001001;

int a[12][12];

int main()
{
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> c(n);

	for (int i = 0; i < n; ++i)
	{
	    cin >> c[i];
		for (int j = 0; j < m; ++j) cin >> a[i][j];
	}
	//3 3 10
	// c{60,70,50} 縦i 横j
	//60 2 2 4
	//70 8 7 9
	//50 2 3 9
	int ans = INF;
	for (int s = 0; s <(1<<n); ++s) // sが0~7
	{
		int cost = 0;
		vector<int> d(m);
		for (int i = 0; i < n; ++i) 
		{
			if (s >> i & 1) //i=0 001 011 101 111のときにtrueを返す
			//i=1 010 011 110 111　の時true
				//i=2 100 101 110 111
			{
				cost += c[i]; 
				for (int j = 0; j < m; ++j) d[j] += a[i][j]; 
			}
		}
		// s=3の時、cost=c[0]+c[1]=130 d[0]=a[0][0]+a[1][0]=10 d[1]=a[0][1]+a[1][1]=9 d[2]=a[0][2]+a[1][2]=13
		bool ok = true;
		for (int j = 0; j < m; ++j) if (d[j] < x) ok = false; //false
		if (ok) ans = min(ans, cost); //すべてx以上という条件を満たしたらansの値をcostで更新
	}
	if (ans == INF) cout << -1 << endl; //1回も更新されなかった場合
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s; cin >> s;
    int cnt = 1;
    string prev = "";
    prev += s[0];
    for(int i = 1; i < s.size(); i++)
    {
        cnt++;
        string comp = "";
        comp += s[i];
        if(comp == prev)
        {
            if(i == s.size() - 1) cnt--;
            else
            {
                prev = "";
                prev += comp + s[i + 1];
                i++;
            }
        }
        else
        {
            prev = "";
            prev = s[i];
        }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main() {
    ll X, Y;
    cin >> X >> Y;

    int a = X;
    for(int i=1; ; i++) {
        X *= 2;
        if(X > Y) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3644