akhauriyash/Code-Regression huggingface dataset:
num = int(input())

mat = [[0 for i in range(num)] for j in range(num)]

for i in range(num):
    arr = list(map(int,input().split()))
    
    if  arr[1] >= 1:
        for j in range(len(arr)-2):
            m = arr[j+2]
            
            mat[i][m-1] += 1

    else:
        pass

for i in range(num):
    print(*mat[i])


Measured memory_bytes: 6392
n, k = map(int, input().split())

mod = 10 ** 9 + 7

ans = 0
for i in range(k, n + 2):
    # 等差数列の和 項数*(初項+末項)/2
    min = i * (0 + (i - 1)) // 2
    max = i * ((n - (i - 1)) + n)  // 2
    ans += (max - min) + 1
    ans %= mod
    
print(ans)


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

typedef long long ll;
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  if(n%k==0){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }
  return 0;
}



Measured memory_bytes: 256
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc153_a.cpp
 * time   : Sat May  2 19:00:25 2020
 * quest  : A - Serval vs Monster
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int h, a;
  cin >> h >> a;
  cout << ((h % a) ? h / a + 1 : h / a) << "\n";
  return 0;
}


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

using namespace std;

#define int long long
#define pii pair<int, int>
#define pb push_back
vector<int> v;
int k;
signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    cin >> k;
    queue<int> q;
    for(int i = 1; i <= 9; i++) q.push(i);
    while(q.size()) {
        if(v.size() == k) break;
        int t = q.front();
        v.pb(t);
        q.pop();
        for(int i = 0; i <= 9; i++) {
            if(abs(t%10 - i) <= 1) {
                q.push(t * 10 + i);
            }
        }
    }
    sort(v.begin(), v.end());
    cout << v[k - 1] << endl;

    return 0;
}



Measured memory_bytes: 2676
#include<stdio.h>
int N;
#define N 8
#define FREE -1
#define NOT_FREE 1
void input();
void putQueen(int);
void printBoard();
int row[N],col[N],dpos[2*N-1],dneg[2*N-1],a[N][N];

int main(){
  input();
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      a[i][j]=-1;
    }
  }
  
  int n,c,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&c,&k);
    a[c][k]=1;
  }
  
  putQueen(0);
  return 0;
}


void putQueen(int i){
  int j;
  if(i==N){
    printBoard();
    return ;
  }
  
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)continue;
  row[i]=j;
  col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
  putQueen(i+1);
  col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
  
}


void input(){
  int i;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<N*2-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
    
  }
  
}


void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(a[i][j]==1){
	if(row[i]!=j)return;
      }
      
    }
    
  }
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    
    printf("\n");
  }
  
}




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

int main() {
    int N,M;
    cin>>N>>M;
    vector<int> H(N);
    rep(i,N){
        cin>>H.at(i);
    }
    vector<int> d(N);
    rep(i,M){
        int A,B;
        cin>>A>>B;
        if(H.at(A-1)>H.at(B-1)){
            d.at(B-1)-=1000000000000;
        }
        else if(H.at(A-1)<H.at(B-1)){
            d.at(A-1)-=1000000000000;
        }
        else{
            d.at(A-1)-=1000000000000;
            d.at(B-1)-=1000000000000;
        }

    }
    int good=0;
    rep(i,N){
        if(d.at(i)==0){
            good++;
        }
    }
    cout<<good<<endl;
}

Measured memory_bytes: 4004
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

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

    unordered_map<ll,bool> mp;

    for(int i = 0; i < n; i++){
        mp[a[i]] = true;
    }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(n-j < ans){
                break;
            }
            ll dist = a[j] - a[i];
            ll prev = a[i];
            ll tmp = 1;
            while(true){
                if(mp.find(prev+dist) == mp.end()){
                    break;
                }
                prev += dist;
                tmp++;
            }
            if(tmp > ans){
                ans = tmp;
            }
        }
    }

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


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

using namespace std;

int64_t gcd(int64_t one, int64_t other) {
    int64_t tmp;
    while (one != 0) {
        tmp = one;
        one = other % one;
        other = tmp;
    }
    return other;
}

int64_t get_winner(int64_t one, int64_t other) {
    int64_t winner = 0;
    if (one > other) swap(one, other);
    if (other % one == 0) {
        winner = min(one, other);
    } else {
        winner = gcd(one, other);
    }
    return winner;
}

int main(int argc, char *argv[]) {
    //
    //  ふたつの値が対戦した場合
    //  小さい方が大きい方の約数の場合、小さい方が最小値
    //  約数でない場合、最大公約数が最小値
    //

    int N;
    cin >> N;

    vector<int64_t> arr;
    int64_t cur;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        arr.push_back(cur);
    }
    sort(arr.begin(), arr.end());

    int64_t w = INT_MIN;
    for (int j = 0; j < N - 1; j++) {
        int64_t one = 0;
        int64_t other = 0;
        if (j == 0) {  // 最初の場合
            one = arr[0];
            other = arr[1];
            w = get_winner(one, other);
        } else {
            one = w;
            other = arr[j + 1];
            w = get_winner(one, other);
        }
    }
    cout << w << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
vector<int> G[1000000];
vector<int> ans;
int ord[1000000], low[1000000];
bool vis[1000000];
void dfs(int v, int p, int &k){
	vis[v] = true;
	ord[v] = k++;
	low[v] = ord[v];
	bool isArticulation = false;
	int ct = 0;
	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) ans.push_back(v);
}

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	int k = 0;
	for (int i = 0; i < n; i++){
		if (!vis[i]) dfs(i, -1, k);
	}
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++) cout << ans[i] << endl;
}

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

int main() {
	int W, H;
	while (cin >> W >> H) {
		if (W == 0) return 0;
		vector<vector<int> > V(H, vector<int>(W));
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) cin >> V[i][j];
		}
		int ANS = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (V[i][j] == 1) {
					ANS++;
					queue<pair<int, int> > Q;
					Q.push({ i, j });
					V[i][j] = 0;
					while (!Q.empty()) {
						pair<int, int> P = Q.front();
						Q.pop();
						for (int k = -1; k <= 1; k++) {
							for (int l = -1; l <= 1; l++) {
								int NX = P.first + k, NY = P.second + l;
								if (0 <= NX && NX < H && 0 <= NY && NY < W) {
									if (V[NX][NY] == 1) {
										V[NX][NY] = 0;
										Q.push({ NX, NY });
									}
								}
							}
						}
					}
				}
			}
		}
		cout << ANS << endl;
	}
}


Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main(){

    string str;
    cin>>str;

    vector<int> nums(str.size());

    transform(str.begin(),str.end(),nums.begin(),[](char ch) {return ch- '0';});

    bool flag=true;
    int before_num;

    for(int i=0;i<nums.size();i++){
        if(flag){
            if(i==0) before_num=nums[i];
            else{
                if(nums[i]==before_num){
                    flag=false;
                    cout<<"Bad"<<endl;
                }
                before_num=nums[i];
            }
        }
    }

    if(flag) cout<<"Good"<<endl;

    //for(int i=0;i<nums.size();i++) cout<<nums[i];

    return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
 PROGRAM-ID.     TEST121.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
  01 INP        PIC X(10).
  01 H1         PIC 9(2).
  01 W1         PIC 9(2).
  01 H2         PIC 9(2).
  01 W2         PIC 9(2).
  01 WANS       PIC 9(4).
  01 ANS        PIC ZZZ9.

 PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO H1 W1.

  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO H2 W2.

  COMPUTE WANS = (H1 - H2) * (W1 - W2).
  MOVE WANS        TO ANS.
  DISPLAY ANS.
 STOP RUN.

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a[100001],b[100001],s[100001];
	
	for(int i=2;i<=100000;i++)  
	a[i]=1;
	
	for(int i=2;i<=int(sqrt(100000));i++)
    {
		if(a[i]==1)
		for(int j=i+i;j<=100000;j+=i)  
		a[j]=0;
    }
    
    b[1]=0;b[2]=0;
    for(int i=3;i<=100000;i++)
    if(a[i]==1&&a[(i+1)/2]==1)
	b[i]=1;
    
    s[1]=0;s[2]=0;
    for(int i=3;i<=100000;i++)
       s[i]=s[i-1]+b[i];
    
    int q,l,r;
    cin>>q;
    
    for(int i=1;i<=q;i++)
    {
		cin>>l>>r;
    	cout<<s[r]-s[l-1]<<endl;
    }
    return 0;
}

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

int i,r=0;
string a;


int main(){
    cin>>a;
    for(i=0;i<=a.length();i++){
        if(a[i]=='+'){
            r=r+1;
        }
        else if(a[i]=='-'){
            r=r-1;
        }
    }
    cout<<r;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    string s;
    cin>>s;
    ll n=s.length();
    ll n0=(n-1)/2;
    if(s.substr(0,n0)==s.substr(n0+1,n0)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		long N=sc.nextLong();
		long X=sc.nextLong();
		long sum=0;
		if(X>N/2) {
			X=N-X;
		}
		long big=N-X;
		long mini=X;
		sum=N;
		while(true) {
			if(big%mini!=0) {
				sum+=mini*2*(big/mini);
				long tmp=mini;
				mini=big%mini;
				big=tmp;
			}
			else {
				sum+=mini*((big/mini)*2-1);
				break;
			}
		}
		pl(sum);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


Measured memory_bytes: 23124
#include <iostream>

int main(int argc, const char* argv[]) {

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);  std::cout.tie(NULL);

    int a, b, c;
    std::cin >> a >> b >> c;

    int ct = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            ct++;
        }
    }
    std::cout << ct << "\n";

    return 0;

}



Measured memory_bytes: 3212
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  if(((a>=0||b>=0)&&c>=0&&d>=0) || (a>=0&&b>=0&&(c>=0||d>=0)))
    cout<<max(a,b)*max(c,d)<<endl;
  else if(((a<0||b<0)&&c<0&&d<0) || (a<0&&b<0&&(c<0||d<0)))
    cout<<min(a,b)*min(c,d)<<endl;
  else if((a>=0&&b>=0)&&(c<0&&d<0) || (a<0&&b<0)&&(c>=0&&d>=0))
    cout<<max(max(a,b)*min(c,d),min(a,b)*max(c,d))<<endl;
  else if(( (a<0&&b>=0)||(a>=0&&b<0) )&&( (c<0&&d>=0)||(c>=0&&d<0) ))
    cout<<max(min(a,b)*min(c,d),max(a,b)*max(c,d))<<endl;
  else
    cout<<0<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int n; cin >> n;
  int d[n];
  int circle[25];
  MEMSET(circle,0);
  int ref = 0;
  ++circle[0];
  FOR(i,0,n-1) cin >> d[i];
  sort(d,d+n);
  FOR(i,0,n-1) {
    if(d[i]==0 || d[i]==12){
      ++circle[d[i]];
    } else if(ref%2==0) {
      ++circle[d[i]];
      ++ref;
    } else {
      ++circle[(24-d[i])%24];
      ++ref;
    }
  }

  int ans = 24;

  FOR(i,0,23){
    FOR(j,0,23){
      if(circle[i]!=1 || circle[j]!=1) continue;
      if(i==j) continue;

      chmin(ans,abs(i-j));

      // cout << i << " " << j << " " << ans << endl;
    }
  }

  FOR(i,0,23){
    if(circle[i]>1) ans = 0;
  }

  cout << ans << endl;
  


}


Measured memory_bytes: 256
def mxmn(ls,m):
	global n
	s1,s2 = 0, 0
	for i in range(m):
		s1 += (n-i)*ls[-i-1]
		s2 += (n-i)*ls[i]
	return s1,s2

def f(ls,m,s):
	global n
	count = 0
	if m > 0:
		mx,mn = mxmn(ls,m)
		if mx < s or mn > s: return 0
		elif mx == s or mn == s: return 1
		for i in range(len(ls)):
			lls = ls[:]
			a = (n-m+1)*lls.pop(i)
			if s-a < 0:	break
			else: count += f(lls,m-1,s-a)
		return count
	else:
		return 1 if s == 0 else 0
			
ls = [i for i in range(10)]
while True:
	try:
		n,s = map(int, raw_input().split())
		print f(ls,n,s)
	except:
		break

Measured memory_bytes: 4260
#include<map>
#include<queue>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=4e3+100;
int n;
double a,f[maxn][maxn];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		scanf("%lf",&a);
		for(int j=1;j<=i;j++)
			f[i][j]=f[i-1][j-1]*a+f[i-1][j]*(1-a);
		f[i][0]=f[i-1][0]*(1-a);
	}
	double ans=0;
	for(int i=1;i<=n;i++){
		if(i>n-i) ans+=f[n][i];
	}
	printf("%.11lf\n",ans);
	return 0;
}


Measured memory_bytes: 94592
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
int a,b;cin>>a>>b;

int size=0;
int x;
x=0;
while(x*x<a-1)x++;
size=max(size,x);
x=0;
while(x*x<b-1)x++;
size=max(size,x);
size=2*size+1;

vector<vector<int>>GRID(size,vector<int>(2*size));

for(int i=0;i<size;i++)for(int j=size;j<2*size;j++)GRID[i][j]=1;

int cnt;

cnt=a-1;
for(int i=1;i<size;i+=2)for(int j=1;j<size;j+=2){
if(cnt==0)break;
GRID[i][j]=1;
cnt--;
}
cnt=b-1;
for(int i=1;i<size;i+=2)for(int j=1;j<size;j+=2){
if(cnt==0)break;
GRID[i][size+j]=0;
cnt--;
}

cout<<size<<" "<<2*size<<endl;
for(int i=0;i<size;i++){
for(int j=0;j<2*size;j++){
cout<<(GRID[i][j]?'.':'#');
}
cout<<endl;
}

return 0;
}


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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void nope() {
    cout << -1 << "\n";
    exit(0);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    string s; 
    cin >> s;
    int n = s.length();
    if(s[0] != '1' || s[n-1] != '0') {
        cout << "-1\n";
        return 0;
    }
    if(n == 2) {
        cout << "1 2\n";
        return 0;
    }
    if(n == 3) {
        if(s[1] == '0') nope();
        cout << "1 2\n2 3\n";
        return 0;
    }
    int chain = 0;
    forn(i, n/2){	
    	if(s[i] != s[n-2-i]) nope(); 
    	if(s[i] == '1') {
    		if(i != n-2-i)
    			chain += 2;
    		else 
    			++chain;
    	}
    }
    forn(i, chain) 
    	cout << i+1 << " " << i+2 << "\n";
    int num = 2;
    int lst = 0;
    ++chain;
    forab(i, 1, n-1) {
    	if(s[i] == '1') { 
            forab(j, 1, i - lst -1) {
    			++chain;
    			cout << num << " " << chain << "\n";
    		}
    		lst = i;
    		++num;
    	}
    }
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=150;
pair<int , int > p[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        p[i].F=x;
        p[i].S=y;
    }
    bool q=0;
    for(int i=0;i<n-2;i++){
        if(p[i].F == p[i].S && p[i+1].F == p[i+1].S && p[i+2].F==p[i+2].S){
            q=1;
        }
    }
    if(q){
        printf("Yes");
    }
    else{
        printf("No");
    }
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    vector<int> A(N);
    for_(i,0,N) {
        cin >> A[i];
        A[i] -= i + 1;
    }

    sort(ALL(A));
    int b = A[N/2];
    lint ans = 0;
    for_(i,0,N) ans += abs(A[i] - b);
    cout << ans << endl;
}

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

const ll tenPowEighteen = 1000000000000000000;

int main()
{
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr[i];

        if(arr[i] == 0)
        {
            cout<<0;
            return 0;
        }
    }

    ll ans = 1;
    ll flg = 0;
    for(ll i=0;i<n;i++)
    {
        if(arr[i]<=tenPowEighteen/ans)
        {
            ans *= arr[i];
        }
        else
        {
            cout<<-1;
            return 0;
        }
    }

    if(flg) cout<<-1;
    else    cout<<ans;

    return 0;
}


Measured memory_bytes: 4380
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    string S; cin >> S;
    int N = S.size();
    vector<vector<int>> g(N/2+1);
    int M; cin >> M;
    for(int i=0;i<M;i++){
        int L, R; cin >> L >> R;
        --L; --R;
        if(L >= N/2){
            L = N-1-L;
            R = N-1-R;
            swap(L, R);
        } else if(R >= N/2){
            if(L == N-1-R) continue;
            if(L < N-1-R){
                R = N-2-R;
            } else {
                --L;
                R = N-1-R;
                swap(L, R);
            }
        }
        R = min(R+1, N/2);
        g[L].push_back(R);
        g[R].push_back(L);
    }
    vector<int> dif(N, 0);
    vector<int> reach(N, -1);
    vector<int> next(N, -1);
    for(int i=0;i<=N/2;i++){
        if(reach[i] != -1) continue;
        reach[i] = i;
        queue<int> qu; qu.push(i);
        while(!qu.empty()){
            int s = qu.front(); qu.pop();
            for(auto& t : g[s]){
                if(reach[t] != -1) continue;
                reach[t] = i;
                qu.push(t);
            }
        }
        int cur = i;
        for(int j=i+1;j<=N/2;j++){
            if(reach[j] != i) continue;
            next[cur] = j;
            cur = j;
        }
    }
    int sum = 0;
    for(int i=0;i<N/2;i++){
        sum += dif[i];
        int rot = (S[N-1-i] - S[i] - sum % 26 + 52) % 26;
        if(rot != 0 && next[i] == -1){
            cout << "NO" << endl;
            return 0;
        }
        sum += rot;
        dif[next[i]] = -rot;
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 4864
#include<cstdio>
long long n,a,b;
int main(){
	scanf("%lld %lld %lld",&n,&a,&b);
	if(n>1&&b>=a||(n==1&&a==b))printf("%lld\n",a+b*(n-1)-(b+a*(n-1))+1);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a + b + c == 17 && a * b * c == 175){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 35676
//given n integers and an integer m such that n>m then there exits a pair
//(a-b) such that (a-b)%m==0


#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
const ll M=1000000007;
void solve(){
int r,c,m;
cin>>r>>c>>m;
int ans1=0,ans2=0,id1,id2;
map<int,int>p,q;
map<pair<int,int>,int>mp1;
for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    mp1[{x,y}]=-1;
    p[x]++;
    q[y]++;
   if(ans1<p[x]){
    ans1=p[x],id1=x;
   }
    if(ans2<q[y]){
    ans2=q[y],id2=y;
   }
}
vector<int>v1,v2;
for(auto i:p){
    if(i.second==ans1)v1.push_back(i.first);
}
for(auto i:q){
    if(i.second==ans2)v2.push_back(i.first);
}
ll ans=ans1+ans2-1;
for(auto i:v1){
    for(auto j:v2){
        if(mp1[{i,j}]!=-1){
            ans++;
            cout<<ans;
            return ;
        }
    }
}
cout<<ans;


}

int main(){
 int t=1;
 //cin>>t;
 while(t--){
        solve();
        cout<<endl;
 }
}


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

int main() {
  vector<vector<int>> A(3,vector<int>(3));
  vector<vector<int>> B(3,vector<int>(3));
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        if(A.at(i).at(j) == x) B.at(i).at(j) = 1;
      }
    }
  }
  bool ans = false;
  for(int i = 0; i < 3; i++){
    int cnt = 0;
    for(int j = 0; j < 3; j++){
      cnt += B.at(i).at(j);
    }
    if(cnt == 3) ans = true;
  }
  for(int j = 0; j < 3; j++){
    int cnt = 0;
    for(int i = 0; i < 3; i++){
      cnt += B.at(i).at(j);
    }
    if(cnt == 3) ans = true;
  }
  int cnt = 0;
  for(int i = 0; i < 3; i++){
    cnt += B.at(i).at(i);
  }
  if(cnt == 3) ans = true;
  cnt = 0;
  for(int i = 0; i < 3; i++){
    cnt += B.at(i).at(2-i);
  }
  if(cnt == 3) ans = true;
  puts(ans ? "Yes":"No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod= 1e9+7;
long double pi = acosl(-1);
const int inf = 1e9;
const int nmax = 1e5+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;


vector<int>g[nmax];
int arr[nmax];

int sarch(int lo, int hi, int x){
    if(g[lo].back()<x) return lo;
    if(g[hi].back()>=x) return hi+1;
    while(hi>lo){
        int mid=(hi+lo)/2;
        if(g[mid].back()>=x) lo=mid+1;
        else hi=mid;
    }
    return hi;
}

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

    int n;
    cin>>n;
    for(int i=1; i<=n; i++) cin>>arr[i];
    g[1].push_back(arr[1]);
    int sz=1;
    for(int i=2; i<=n; i++){
        int x = arr[i];
        int idx = sarch(1,sz,x);
        g[idx].push_back(x);
        sz=max(sz, idx);
    }
    cout<<sz;
}
/*
9
1 5 0 9 2 6 6 7 8
*/


Measured memory_bytes: 6144
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin >>a>>b>>c;
  if(a<=c&&b>=c) cout <<"Yes\n";
  else cout <<"No\n";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i,j,n,flag=1,temp=0,num=0;

  scanf("%d",&n);

  int A[n];
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  i=0;
  while(flag){
    flag = 0;
    for(j=n-1;j>=i+1;j--)
      {
	if(A[j]<A[j-1])
	  {
	    temp = A[j];
	    A[j] = A[j-1];
	    A[j-1] = temp;
	    flag = 1;
	    num++;
	  }
      }
    i++;
  }
  for(j=0;j<n-1;j++)
    {
      printf("%d ",A[j]);
    }
  printf("%d\n",A[j]);
  printf("%d\n",num);
  return 0;
}

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



int main(){
    ll N,Q;
    cin >> N;
    map<ll,ll> map;
    vector<ll> A(N,0);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        map[A[i]]++;
    } 

    ll sum = 0;
    for(int i = 0; i < N; i++) sum += A[i];
    cin >> Q;
    vector<ll> B(Q,0);
    vector<ll> C(Q,0);
    for(int i = 0; i < Q; i++) cin >> B[i] >> C[i];

    ll ans;
    ans = sum;
    for(int i = 0; i < Q; i++){
        ans -= map[B[i]] * B[i];
        ans += map[B[i]] * C[i];
        map[C[i]] += map[B[i]];
        map[B[i]] = 0;
        cout << ans << endl;
    }

}

Measured memory_bytes: 11208
using System;

public class Program
{
    public static void Main(string[] args)
    {
        var n = long.Parse(Console.ReadLine());
        var result = n.Count();
        Console.WriteLine(result);
    }
}

public static class Extention
{
    public static long Count(this long num)
    {
        if (num == 1)
        {
            return 1;
        }
        return (num/2).Count() * 2 + 1;
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int f[9];

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        for(int i=1;i<=4;i++)
        {
                int x;
                cin>>x;
                f[x]++;
        }
        if(f[1] && f[9] && f[4] && f[7])
        {
                cout<<"YES\n";
        }
        else
        {
                cout<<"NO\n";
        }
        return 0;
}
/**


**/


Measured memory_bytes: 892
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int a,b,c;cin>>a>>b>>c;
	if(a==b && b==c) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

int main(void){
    long long N,K;
    cin>>N>>K;
    
    long long a[100001]={0};
    for(int i=0;i<N;i++){
        long long A,B;
        cin>>A>>B;
        a[A]+=B;
    }
    for(int i=1;i<100001;i++){
        K-=a[i];
        if(K<=0){cout<<i<<endl;break;}
    }
}


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


int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int mx = -1, sec = -1;
  rep(i, n)
  {
    cin >> a[i];
    sec = max(sec, a[i]);
    if (mx < sec)
      swap(mx, sec);
  }
  rep(i, n)
    if (mx == a[i])
      printf("%d\n", sec);
    else
      printf("%d\n", mx);
  return 0;
}

Measured memory_bytes: 2432
#include <iostream>
using namespace std;
#include <set>
#include <algorithm>
typedef long long ll;
const int N = 1e5+10;
int a[N];
int main()
{
	int n;
	cin >> n;
	
	for(int i = 1;i<=n;i++)
	{
		cin >> a[i];
	}
	ll sum = abs(a[1]-0);
	
	for(int i = 2;i<=n;i++)
	{
		sum +=abs(a[i]-a[i-1]);
	}
	
	sum+=abs(a[n]-0);
	
//	cout << sum << endl;
	for(int i = 1; i < n;i++)
	{
		ll res = sum - abs(a[i]-a[i-1])- abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1]);
		cout << res << endl;
	}
	
	cout << sum - abs(a[n]-a[n-1]) - abs(a[n]) + abs(a[n-1]);
	
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>

using namespace std;

int main(){
  int mn;
  cin>>mn;
  int n=mn;
  int s=0,k=0;
  while(n>0){
    if(n%10!=0){
      if(k==0)k=n%10;
      else s+=n%10;
    }
    n/=10;
  }
  if(s!=0 || mn%10!=0)cout<<s+k<<endl;
  else cout<<k-1+10<<endl;
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		// 天気
		string a = Console.ReadLine().ToString();
		// スペース区切りの整数の入力
		if(a.Equals("Sunny")){
        	Console.WriteLine("Cloudy");
        }
        else if(a.Equals("Cloudy")){
        	Console.WriteLine("Rainy");
        }else{
        	Console.WriteLine("Sunny");
        }
	}
}

Measured memory_bytes: 11092
#!/usr/bin/env python3

def compare(a, b):
    return a == '?' or b == '?' or a == b

def solve(A, B, C):
    n, m, l = len(A), len(B), len(C)
    AB, AC, BC = [True]*(n+1), [True]*(n+1), []
    for i in range(n):
        for j in range(m):
            if i + j >= n:
                continue
            if not compare(A[i + j], B[j]):
                AB[i] = False
                break
    
    for i in range(n):
        for j in range(l):
            if i + j >= n:
                continue
            if not compare(A[i + j], C[j]):
                AC[i] = False
                break

    for i in range(n):
        for j in range(l):
            if i + j >= m:
                continue
            if compare(B[i + j], C[j]):
                continue
            break
        else:
            BC.append(i)
    for i in range(max(0,n-m)):
        BC.append(m+i)

    res = n + m + l
    for i in range(n+1):
        if AB[i]:
            for j in BC:
                if i + j >= n:
                    res = min(res, max(n, i + m, i + j + l))
                elif AC[i + j]:
                    res = min(res, max(n, i + m, i + j + l))
    return res

def main():
    a = input()
    b = input()
    c = input()
    ans = min(solve(a,b,c),solve(a,c,b),solve(b,a,c),solve(b,c,a),solve(c,a,b),solve(c,b,a))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 51560
import qualified Data.ByteString.Char8 as B

data YesNo = Yes | No deriving Show


solve :: B.ByteString -> YesNo
solve s = if u == B.reverse u && v == B.reverse v && s == B.reverse s then Yes else No
    where n = B.length s
          u = B.take ((n - 1) `div` 2) s
          v = B.drop ((n + 1) `div` 2) s

main :: IO ()
main = B.getLine >>= print . solve

Measured memory_bytes: 380
N = int(input())
W = list(map(int, input().split()))
 
sum_W = sum(W)
add_W = 0
 
for i in range(N):
   add_W += W[i]
   if add_W >= sum_W - add_W:
       print(min(abs(add_W - sum_W + add_W), abs(add_W - W[i] - sum_W + add_W - W[i])))
       break

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

int main(){

	int W,H,x,y,r;

	cin >> W >> H >> x >> y >> r;

	if ( r > x || x > W - r ){

		cout << "No" << endl;

		return 0;
	}

	if ( r > y || y > H - r){

		cout << "No" << endl;

		return 0;
	}

	else cout << "Yes" << endl;

	return 0;

}

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

int N, M;
vector<vector<int>> G;
vector<int> dp;

int f(int now){
  if(dp[now] != 1e9) return dp[now];
  int ans = 0;
  for(auto e:G[now]){
    ans = max(ans,f(e)+1);
  }
  dp[now] = ans;
  return ans;
}

int main(){
   cin >> N >> M;
   G.resize(N);
   dp.resize(N,1e9);
   rep(i,M){
     int x,y;
     cin >> x >> y;
     x--;y--;
     G[x].push_back(y);
   }
   int ans = 0;
    rep(i,N){
      ans = max(ans,f(i));
    }
    cout << ans << endl;
}

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

int main() {
	int a, b, s;
	cin >> a >> b;
	int i = 0;
	for (s = a;s <= b;s++) {
		if (s % 10== s / 10000&& s / 10 % 10== s / 1000 % 10)
			i++;
	}
	cout << i << endl;
}




Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M, K = map(int, input().split())
    num_friends = [0 for _ in range(N)]
    blocks = [[] for _ in range(N)]
    uf = UnionFind(N)

    for _ in range(M):
        a, b = map(int, input().split())
        num_friends[a-1] += 1
        num_friends[b-1] += 1
        uf.union(a-1, b-1)
    for _ in range(K):
        a, b = map(int, input().split())
        blocks[a-1].append(b-1)
        blocks[b-1].append(a-1)

    ans = []
    for i in range(N):
        cnt = uf.size(i) - 1 - num_friends[i]
        for j in blocks[i]:
            if uf.same(i, j):
                cnt -= 1
        ans.append(cnt)
    
    print(*ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 31864
#include <iostream>
#include <cstdio>
#include <set>
#include <string>
std::string str;
std::set<std::string> S;
int n;

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		std::cin >> str;
		S.insert(str);
	}
	printf("%d", S.size());
	return 0;
}

Measured memory_bytes: 19404
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int[] l=new int[n];
		int[] r=new int[n];
		for(int i=0;i<n;i++){
			l[i]=scanner.nextInt();
			r[i]=scanner.nextInt();
		}
		sieve(100000);
		int[] cnt=new int[100001];
		for(int i=1;i<100001;i+=2){
			if(is_prime[i]&&is_prime[(i+1)/2]){
				cnt[i]++;
			}
		}
		for(int i=1;i<100001;i++){
			cnt[i]+=cnt[i-1];
		}
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<n;i++){
			sb.append(cnt[r[i]]-cnt[l[i]-1]+"\n");
		}
		System.out.println(sb);
	}
	
	static boolean[] is_prime;
	static private void sieve(int n) {
		is_prime = new boolean[n + 1];
		for (int i = 2; i <= n; i++) {
			is_prime[i] = true;
		}
		for (int i = 2; i <= n; i++) {
			if (is_prime[i]) {
				for (int j = i + i; j <= n; j += i) {
					is_prime[j] = false;
				}
			}
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 42164
#include <stdio.h>#include <stdio.h>
int main(){
    long long int N,K;
    scanf("%lld %lld",&N,&K);
    long long int m;
    m=1000000000+7;
    long long int dp[101][100001];
    long long int a[100001];
    long long int b[100001];
    long long int i;
    long long int j;
    long long int k;
    k=0;
    long long int l;
    long long int s;
    long long int c,d;
    long long int ans;
    ans=0;
    for(c=1;c<=N;c=d+1){
        d=N/(N/c);
        k=k+1;
        a[k]=c;
        b[k]=d;
    }
    dp[0][1]=1;
    for(i=1;i<=K;i++){
        l=0;
        s=0;
        for(j=k;j>=1;j--){
            if(l+1<=k&&a[l+1]*a[j]<=N){
                l=l+1;
                s=(s+dp[i-1][l])%m;
            }
            dp[i][j]=((b[j]-a[j]+1)*s)%m;
            if(i==K){
                ans=(ans+dp[K][j])%m;
            }
        }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 79744
-- import Prelude hiding (abs)
-- import Control.Monad
-- import Control.Arrow ((&&&))
-- import Data.List (nub, sort, group)
-- import Data.Maybe (fromMaybe)
-- import qualified Data.IntMap as M

main :: IO ()
main = do
    _ <- getLine
    as <- (map read . words) <$> getLine
    print $ solve as

-- |
solve :: [Int] -> Int
solve as = maximum as - minimum as


Measured memory_bytes: 1020
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

class UnionFindTree{
private:
  int _size;
  int* _parent;
  int* _rank;
public:
  UnionFindTree(int n){
    _size = n;
    _parent = new int[_size]();
    _rank = new int[_size]();
    for(int i = 0; i < _size; i++){
      _parent[i] = i;
      _rank[i] = 1;
    }
  }

  ~UnionFindTree(){
    delete[] _parent;
    delete[] _rank;
  }

  int find(int child){
    int next = _parent[child];
    if(next == child) return child;
    else return find(next);
  }

  bool same(int lhs,int rhs){
    lhs = find(lhs);
    rhs = find(rhs);
    return (lhs == rhs);
  }
  
  bool unite(int lhs,int rhs){
    lhs = find(lhs);
    rhs = find(rhs);
    if(same(lhs,rhs)) return false;
    
    if(_rank[lhs] < _rank[rhs]){
      _parent[lhs] = rhs;
    }
    else {
      _parent[rhs] = lhs;
      if(_rank[rhs] == _rank[lhs]) _rank[lhs]++;
    }
    return true;
  }

};

class State {
public:
  int _from,_to;
  double _distance;
  State(int from,int to,double distance)
    : _from(from),_to(to),_distance(distance) {}
  bool operator<(const State& s) const {
    return _distance < s._distance;
  }
  bool operator>(const State& s) const {
    return _distance > s._distance;
  }
};

int main(){
  int num_of_magical_piles;
  int num_of_magical_fences;
  while(~scanf("%d %d",
               &num_of_magical_piles,
               &num_of_magical_fences)){
    
    vector<P> piles;
    for(int pile_i = 0; pile_i < num_of_magical_piles; pile_i++){
      int x,y;
      scanf("%d %d",&x,&y);
      piles.push_back(P(x,y));
    }

    double sum = 0;
    priority_queue<State,vector<State>,less<State> > que;

    for(int fence_i = 0; fence_i < num_of_magical_fences; fence_i++){
      int from,to;
      scanf("%d %d",&from,&to);
      from--; to--;
      int from_x = piles[from].first;
      int from_y = piles[from].second;

      int to_x = piles[to].first;
      int to_y = piles[to].second;

      double distance = sqrt((double)((from_x - to_x) * (from_x - to_x)
                                      + (from_y - to_y) * (from_y - to_y)));
      sum += distance;
      que.push(State(from,to,distance));
    }

    UnionFindTree uft(num_of_magical_piles);
    double after_ruined = 0;
    while(!que.empty()){
      State s = que.top();
      que.pop();
      if(uft.same(s._from ,s._to)){
        continue;
      }
      uft.unite(s._from,s._to);
      after_ruined += s._distance;
    }
    printf("%lf\n",sum - after_ruined);
  }
}

Measured memory_bytes: 1732
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define mk make_pair
#define f first
#define s second
typedef pair<int,int> P;
int a[51][51],ax,bx,ay,by;
int dx1[]={1,0,-1,0};
int dy1[]={0,1,0,-1};
int dx2[]={-1,0,1,0};
int dy2[]={0,-1,0,1};
bool used[10000000];
int gethash(P q,P w){
  return q.f+q.s*52+w.f*52*52+w.s*52*52*52;
}
int main(){
  int w,h;
  while(cin>>w>>h,w){
    memset(used,0,sizeof(used));
    cin>>ax>>ay>>bx>>by;ax--,ay--,bx--,by--;
    r(i,h)r(j,w)cin>>a[i][j];
    used[gethash(P(ay,ax),P(by,bx))]=1;
    queue<pair<int,pair<pair<int,int>,pair<int,int> > > >q;
    q.push(mk(0,mk(mk(ay,ax),mk(by,bx))));
    while(!q.empty()){
      pair<int,pair<pair<int,int>,pair<int,int> > >p=q.front();q.pop();
      P p1=p.s.f,p2=p.s.s;
      if(p1==p2){
	cout<<p.f<<endl;
	goto L;
      }
      r(i,4){
	int x1=p1.s+dx1[i],x2=p2.s+dx2[i],y1=p1.f+dy1[i],y2=p2.f+dy2[i];
	if(x1<0||x1>=w)x1=p1.s;
	if(x2<0||x2>=w)x2=p2.s;
	if(y1<0||y1>=h)y1=p1.f;
	if(y2<0||y2>=h)y2=p2.f;
	if(a[y1][x1])x1=p1.s,y1=p1.f;
	if(a[y2][x2])x2=p2.s,y2=p2.f;
	if(!used[gethash(P(y1,x1),P(y2,x2))]){
	  used[gethash(P(y1,x1),P(y2,x2))]=1;
	  q.push(mk(p.f+1,mk(mk(y1,x1),mk(y2,x2))));
	}
      }
    }
    cout<<"NA"<<endl;L:;
  }
}

Measured memory_bytes: 13048
#include<bits/stdc++.h>
using namespace std;
const double PI=acos(-1.0);
int main(){
	int a,b,h,m;scanf("%d%d%d%d",&a,&b,&h,&m),m+=h*60;
	double A=PI*m/360,B=PI*m/30;
	printf("%.10lf",sqrt(a*a+b*b-2*cos(A-B)*a*b));
	return 0;
}

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

#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 ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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; }

const ll MRINF = 5000000000000000;

int main() {

  int A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << min(A, B) + min(C, D) << endl;
    

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

Measured memory_bytes: 3636
#include<bits/stdc++.h>
	#define int long long
	#define rep(i,m,n) for(int i=m;i<n;i++)
	#define repr(i,n,m) for(int i=n;i>=m ;i--)
	#define mod 1000000007
	#define float long double
	#define pb push_back
	#define mp make_pair
	#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
	using namespace std;
	 
	bool sortbysec(const pair<int,int> &a, 
	              const pair<int,int> &b) 
	{ 
	    return (a.second < b.second); 
	}
	bool sortinrev(const pair<int,int> &a,  
	               const pair<int,int> &b) 
	{ 
	       return (a.first > b.first); 
	}
	void swap(int *a,int *b)
	{
		int t=*a;
		*a=*b;
		*b=t;
	}
	void solve()
	{
		int n,k;
		cin>>k>>n;
		vector<int>v1,v2;
		rep(i,0,n)
		{
			int a;
			cin>>a;
			v1.pb(a);
		}
		v2.pb(v1[n-1]-v1[0]);
		rep(i,1,n)
		{
			v2.pb(k-v1[i]+v1[(i-1)]);
		}sort(v2.begin(),v2.end());
		cout<<v2[0];
	}
	signed main()
	{ 
		// #ifndef ONLINE_JUDGE
	 //   freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	 //   #endif  
	   int t=1; 	
	   //cin>>t;
	   while(t--)
	   {
	      solve();
	      cout<<"\n";
	   }
	   cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	  return 0;
	 }		

Measured memory_bytes: 5872