akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<string>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
#define pb push_back
#define fi first
#define sc second
#define mp make_pair
typedef pair<double,double> pdd;
#define UNION_FIND_MAX_N 10000

struct edge{
	int u,v;
	double cost;
};

bool cmp(edge e,edge f){
	return e.cost<f.cost;
}

int par[UNION_FIND_MAX_N],rank[UNION_FIND_MAX_N];

void union_find_init(int n){
	for(int i=0;i<n;++i){
		par[i]=i;
		rank[i]=0;
	}
}

int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y){
		return;
	}else if(rank[x]<rank[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rank[x]==rank[y]){
			++rank[x];
		}
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

double dist(pdd p,pdd q){
	return sqrt((p.fi-q.fi)*(p.fi-q.fi)+(p.sc-q.sc)*(p.sc-q.sc));
}

edge e[30000];
int n,m;

double kruskal(){
	sort(e,e+m,cmp);
	union_find_init(n);
	double r=0;
	for(int j=0;j<m;++j){
		if(!same(e[j].u,e[j].v)){
			unite(e[j].u,e[j].v);
			r+=e[j].cost;
		}
	}
	return r;
}

int main(){
	double cs=0;
	pdd p[10000];
	cin>>n>>m;
	for(int i=0;i<n;++i){
		cin>>p[i].fi>>p[i].sc;
	}
	for(int j=0;j<m;++j){
		int s,t;
		cin>>s>>t;
		double c=dist(p[--s],p[--t]);
		e[j]=((edge){s,t,-c});
		cs+=c;
	}
	cout<<fixed<<setprecision(3)<<cs+kruskal()<<endl;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int A, B, C, X; cin >> A >> B >> C >> X;
  
  int ans = 0;
  rep(i,A+1) {
    rep(j,B+1) {
      rep(k,C+1) {
        if(500*i +100*j +50*k == X) ans++;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int a,x;
  char str[100],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  x=atoi(p);
  p=strtok(NULL," \n");
  a=atoi(p);
  
  if(x>=a){
    printf("10\n"); 
  }else{
    printf("0\n");
  }
  
  
  return 0;
}

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

namespace ABC156A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NR = Console.ReadLine().Split(' ');
            int N = int.Parse(NR[0]);
            int R = int.Parse(NR[1]);
            if (N >= 10)
            {
                Console.WriteLine(R);
            }
            else
            {
                Console.WriteLine(R + 100 * (10 - N));
            }
        }
    }
}


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

using namespace std;

int main() {
	int m, h;
	string s, tmp;

	while (cin >> s, s[0] != '-') {
		cin >> m;
		for (int i = 0; i < m; ++i) {
			cin >> h;
			tmp = s.substr(0, h);
			s.erase(0, h);
			s += tmp;
		}
		cout << s << endl;
	}

	return 0;
}


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

typedef complex<double> P;
typedef pair<P,P> L;

const double EPS = 1e-8;

//円
struct Circle{
  P c; //中心点
  double r; //半径
  Circle(P c=P(0,0), double r=0):c(c),r(r){}
};

//円と円の交点
vector<P> getIntersectCC(Circle c1, Circle c2){
  vector<P> res;
  double r1 = c1.r, r2 = c2.r, d;
  P p1 = c1.c, p2 = c2.c;
  d = abs(p1-p2);

  if(d < EPS && abs(r1-r2) < EPS) return res; //円１と円２が同じ場合（無限個になるため除外）
  if(r1 + r2< d - EPS || d + EPS < abs(r1-r2)) return res; //交わらない

  double a = (r1*r1 - r2*r2 + d*d) / (2*d);
  double h = sqrt(max(r1*r1 - a*a, 0.0));
  P tmp1 = p1 + a / d * (p2-p1);
  P tmp2 = h / d * (p2-p1);

  if(abs(tmp2) < EPS) res.push_back(tmp1);
  else {
    res.push_back(P(real(tmp1) - imag(tmp2), imag(tmp1) + real(tmp2)));
    res.push_back(P(real(tmp1) + imag(tmp2), imag(tmp1) - real(tmp2)));
  }
  return res;
}

int n, x[10], y[10], l[10];

bool check(double h){
  
  Circle c[10];
  
  vector<P> points;
  
  for(int i=0;i<n;i++){
    
    P p = P( 1.0 * x[i], 1.0 * y[i] );
    double r = sqrt( l[i] * l[i] - h * h );
    
    c[i] = Circle( p, r );
    
    points.push_back(p);
    
  }  
  
  for(int i=0;i<n;i++){
    
    for(int j=i+1;j<n;j++){
      
      vector<P> r = getIntersectCC( c[i], c[j] );
      
      for(int k=0;k<(int)r.size();k++) points.push_back(r[k]);
      
    }
    
  }
  
  for(int i=0;i<(int)points.size();i++){
    
    int flag = true;
    
    for(int j=0;j<n;j++){
      
      double len1 = c[j].r;
      double len2 = abs( points[i] - c[j].c );
      
      if( len1 + EPS < len2 ) flag = false;
	
    }
    
    if( flag ) return true;
    
  }  
  
  return false;
}

void solve(){
  
  int minl = 300;
  
  for(int i=0;i<n;i++) minl = min( minl, l[i] );  

  double L = 0, R = minl;
  int cnt = 100;
  
  while( cnt-- ){
    
    double M = ( L + R ) / 2.0;
    
    if( check(M) == true ) L = M;
    else R = M;
    
  }
  
  printf("%.8f\n", L );
  
}

signed main(){
  
  while(1){
    
    cin>>n;
    if(!n) break;
  
    for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>l[i];
  
    solve();
  
  }
  
  return 0;
}



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

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

int main(){
	int A, B ,C;
	cin >> A >> B >> C;
	int X, Y;
	cin >> X >> Y;
	LL ans=10000000000;
	rep(i,X+1){
		LL sum=0;
		sum+=A*i+C*(X-i)*2;
		if((X-i)<Y) sum+=B*(Y-(X-i));
		ans=min(ans,sum);
	}
	rep(i,Y+1){
		LL sum=0;
		sum+=B*i+C*(Y-i)*2;
		if((Y-i)<X) sum+=A*(X-(Y-i));
		ans=min(ans,sum);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.nextLine();
		String b = "No";
		String[] ar = a.split("");
		if(ar[0].equals(ar[1])) {
			if(ar[2].equals(ar[3])){
				b = "Yes";
			}
		}else if(ar[0].equals(ar[2])) {
			if(ar[1].equals(ar[3])){
				b = "Yes";
			}
		}else if(ar[0].equals(ar[3])) {
			if(ar[1].equals(ar[2])){
				b = "Yes";
			}
		}
		if(ar[0].equals(ar[1]) &&ar[0].equals(ar[2])&&ar[0].equals(ar[3])) {
			b = "No";
		}
			System.out.println(b);

	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef vector<vector<double> > vvd;

int main(){

    int x, a, b;
    cin >> x >> a >> b;

    cout << (x-a)%b << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
*a, = map(int, input().split())

dp = [[0] *  N for _ in range(N)]
for i in range(N): dp[i][i] = a[i]

for j in range(1, N):
    for i in range(j-1, -1, -1):
        dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1])

print(dp[0][N-1])

Measured memory_bytes: 135168
/*
 * Code be weshen zyk :'(
 */
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define S second
#define F first
#define pb push_back

using ii = pair<int, int>;
using ll = long long;
using db = long double;

const int N = 18, K = 205, MOD = 1e9 + 7;
const int MX = 1e8;
const int blkSz = 320;
int a[1 << N];
int n;
ii dp[N][1 << N];
bool vis[N][1 << N];
ii solve(int bit, int mask) {
	if (bit == n)
		return ii(a[mask], 0);
	ii &ret = dp[bit][mask];
	if(vis[bit][mask])
		return ret;
	vis[bit][mask] = 1;
	ret = solve(bit + 1, mask);
	if(mask >> bit & 1){
		auto x = solve(bit + 1, mask ^ (1 << bit));
		if(x.F > ret.F)
			ret.S = ret.F, ret.F = x.F;
		else if(x.F > ret.S)
			ret.S = x.F;
		if(x.S > ret.S)
			ret.S = x.S;
	}
	return ret;
}
int main() {
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif

	cin >> n;

	for(int i = 0; i < ( 1 << n ); i++)
		cin >> a[i];

	int ans = 0;

	for(int i = 1; i < (1 << n); i++){
		ans = max(ans, solve(0,i).F + solve(0,i).S);
		cout << ans << '\n';
	}

	return 0;
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

typedef complex<double> P;

double dot(P a, P b) {
    return real(conj(a) * b);
}

P projection(P x, P d) {
    return dot(x, d) * d / abs(d) / abs(d);
}

P reflection(P x, P d) {
    P t = projection(x, d);
    return t + t - x;
}

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

    double x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    P p0(x0, y0), p1(x1, y1);
    int q;
    cin >> q;
    while (q--) {
        double x2, y2;
        cin >> x2 >> y2;
        P p2(x2, y2);
        P a = reflection(p2 - p0, p1 - p0) + p0;
        printf("%.10f %.10f\n", a.real(), a.imag());
    }

}

Measured memory_bytes: 3356
#include <iostream>
using namespace std;
char evaluate(const int& m, const int& f, const int& r) {
    if(m == -1 || f == -1) return 'F';
    if(m + f >= 80) return 'A';
    if(m + f >= 65) return 'B';
    if(m + f >= 50) return 'C';
    if(m + f >= 30) {
        if(r >= 50) return 'C';
        return 'D';
    }
    return 'F';
}
int main() {
    int m, f, r;
    while(true) {
        cin >> m >> f >> r;
        if(m == -1 && f == -1 && r == -1) break;
        cout << evaluate(m, f, r) << endl;
    }
    return 0;
}


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

int data[1111][12][22];

int main(){

  int cnt = 0;
  for(int i=1;i<1111;i++){
    for(int j=1;j<11;j++){
      for(int k=1;k<21;k++){
	if(k == 20 && i%3 && !(j%2)) break;
	cnt++;
	data[i][j][k] = cnt;
      }
    }
  }

  int n, y, m, d;
  cin >> n;

  for(int i=0;i<n;i++){
    cin >> y >> m >> d;
    cout << data[1000][1][1] - data[y][m][d] << endl;
  }

}

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

using namespace std;

int main(){
    int T=1;
    for (int t=1; t<=T; t++){
        long long n, d;
        cin >> n >> d;
        long long count = 0;
        for (int i=0; i<n; i++){
            long long x, y; cin >>x >> y;
            if((x*x) + (y*y)<= d*d) count++;
        }
        cout<< count<< endl;
    }
    return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  vector<int> ans;
  bool flag = true;
  while (flag) {
    if (N == 0) break;
    if (N < M) {
      ans.emplace_back(N);
      break;
    }
    for (int i=M; i>0; i--) {
      if (S.at(N-i) == '0') {
        N = N-i;
        ans.emplace_back(i);
        break;
      }
      if (i == 1) flag = false;
    }
  }
  if (flag) {
    reverse(ans.begin(), ans.end());
    for (int i=0; i<ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
  else cout << -1 << endl;
}

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

typedef pair<int, int> P;

char maze[1001][1001];
int H,W;
int sx[1001*1001];
int sy[1001*1001];
int d[1001][1001];

int blackNum = 0;

int ans = 0;

int way[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};

int bfs(){
	queue<P> que;
	for(int i=0;i<blackNum;i++){
		que.push(P(sx[i],sy[i]));
	}
	while(que.size()){
		P p = que.front(); que.pop();
		for(int i=0;i<4;i++){
			int nx = p.first+way[i][0], ny = p.second+way[i][1];
			if(nx>=1&&nx<=H&&ny>=1&&ny<=W&&maze[nx][ny]!='#'&&d[nx][ny]==-1){
				que.push(P(nx,ny));
				d[nx][ny] = d[p.first][p.second] + 1;
				if(ans<d[nx][ny]) ans = d[nx][ny];
			}
		}
	}
	return 0;
}

int main() {
	// your code goes here
	char g;
	scanf("%d%d",&H,&W);
	scanf("%c",&g);
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			scanf("%c",&maze[i][j]);
			d[i][j] = -1;
			if(maze[i][j]=='#'){
				sx[blackNum] = i;
				sy[blackNum] = j;
				blackNum++;
				d[i][j] = 0;
			}
		}
		scanf("%c",&g);
	}
	bfs();
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 21136
N,Y = gets.split.map(&:to_i)

i, j, k = -1, -1, -1

ans = []

(0..N).each do |n|
  (0..N - n).each do |h|
      sum = 10000*n + 5000*h + 1000*(N - n - h)
      i, j, k = n, h, N - n - h if Y == sum
  end
end

puts "#{i} #{j} #{k}"

Measured memory_bytes: 1788
import math

a, b, C = map(float, input().split())
S =  0.5 * a * b * math.sin(C * math.pi / 180)
L = a + b + (a ** 2 + b ** 2 - 2 * a * b * math.cos(C * math.pi / 180)) ** 0.5
h = 2 * S / a

print("%f\n%f\n%f" % (S, L, h))


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

int main() {
	int N, M, R, A, B, C, ans = INT_MAX;
	cin >> N >> M >> R;
	vector<int> r(R);
	for (int& i : r) cin >> i;
	sort(r.begin(), r.end());
	vector<vector<int>> a(N, vector<int>(N, INT_MAX));
	for (int i = 0; i < N; i++) a[i][i] = 0;
	for (int i = 0; i < M; i++) {
		cin >> A >> B >> C;
		a[A - 1][B - 1] = C;
		a[B - 1][A - 1] = C;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (a[j][i] == INT_MAX) continue;
			for (int k = 0; k < N; k++) {
				if (a[i][k] == INT_MAX) continue;
				a[j][k] = min(a[i][k] + a[j][i], a[j][k]);
			}
		}
	}
	do {
		int b = 0;
		for (int i = 1; i < R; i++) b += a[r[i - 1] - 1][r[i] - 1];
		ans = min(b, ans);
	} while (next_permutation(r.begin(), r.end()));
	cout << ans;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
  val (N, M) = readInts()
  val A = readInts().sorted()
  val BC = (1..M).map { readInts() }.sortedByDescending { it[1] }
  val A2 = mutableListOf<Int>()
  BC.forEach {
    val (B, C) = it
    repeat(B) {
      A2.add(C)
      if (A2.size >= N) return@forEach
    }
  }

  var sum = 0L
  for (i in 0 until N) {
    sum += Math.max(A[i], A2.getOrNull(i) ?: 0)
  }
  println(sum)
}

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


Measured memory_bytes: 104632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>A(N);
  int Sum=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    Sum^=A[i];
  }
  for(int i=0;i<N;i++){
    cout<<(Sum^A[i])<<" ";
  }
}

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

int main() {
    string S; cin >> S; int x=S.size();
    char c='a';
    vector<bool> app(x);
    rep(i,x) app[i]=0;
    rep(i,26){
        rep(j,x) {
            if(S[j]==c){
                app[i]=1;
            }
        }
        if(app[i]==0) {
            cout << c << endl;
            break;
        }
        c++;
    }
    if(app[25]==1) {
        cout << "None" << endl;
    }
}

Measured memory_bytes: 512
//Volume0-0088
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	//declare
	private static HashMap<Character,String> CtoS = new HashMap<Character,String>();
	private static HashMap<String,Character> StoC = new HashMap<String,Character>();

	public static void main(String[] args) {

		int    mod;
		char[] ch;
		String s;

		//initialize
		initMap();

        //input
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        	ch = sc.nextLine().toCharArray();

        	//calculate
        	s = "";
        	for(int i=0;i<ch.length;i++){
        		s += CtoS.get(ch[i]);
        	}
        	mod = s.length() % 5;
        	if(mod > 0){
        		for(int i=0;i<5-mod;i++){
        			s += "0";
        		}
        	}

        	//output
        	for(int i=0;i<s.length();i+=5){
        		System.out.print(StoC.get(s.substring(i, i+5)));
        	}
        	System.out.println();
        }
	}

	private static void initMap(){

		//initialize CtoS.
		CtoS.put(' ', "101");
		CtoS.put('\'',"000000");
		CtoS.put(',', "000011");
		CtoS.put('-', "10010001");
		CtoS.put('.', "010001");
		CtoS.put('?', "000001");
		CtoS.put('A', "100101");
		CtoS.put('B', "10011010");
		CtoS.put('C', "0101");
		CtoS.put('D', "0001");
		CtoS.put('E', "110");
		CtoS.put('F', "01001");
		CtoS.put('G', "10011011");
		CtoS.put('H', "010000");
		CtoS.put('I', "0111");
		CtoS.put('J', "10011000");
		CtoS.put('K', "0110");
		CtoS.put('L', "00100");
		CtoS.put('M', "10011001");
		CtoS.put('N', "10011110");
		CtoS.put('O', "00101");
		CtoS.put('P', "111");
		CtoS.put('Q', "10011111");
		CtoS.put('R', "1000");
		CtoS.put('S', "00110");
		CtoS.put('T', "00111");
		CtoS.put('U', "10011100");
		CtoS.put('V', "10011101");
		CtoS.put('W', "000010");
		CtoS.put('X', "10010010");
		CtoS.put('Y', "10010011");
		CtoS.put('Z', "10010000");

		//initialize StoC.
		StoC.put("00000",'A');
		StoC.put("00001",'B');
		StoC.put("00010",'C');
		StoC.put("00011",'D');
		StoC.put("00100",'E');
		StoC.put("00101",'F');
		StoC.put("00110",'G');
		StoC.put("00111",'H');
		StoC.put("01000",'I');
		StoC.put("01001",'J');
		StoC.put("01010",'K');
		StoC.put("01011",'L');
		StoC.put("01100",'M');
		StoC.put("01101",'N');
		StoC.put("01110",'O');
		StoC.put("01111",'P');
		StoC.put("10000",'Q');
		StoC.put("10001",'R');
		StoC.put("10010",'S');
		StoC.put("10011",'T');
		StoC.put("10100",'U');
		StoC.put("10101",'V');
		StoC.put("10110",'W');
		StoC.put("10111",'X');
		StoC.put("11000",'Y');
		StoC.put("11001",'Z');
		StoC.put("11010",' ');
		StoC.put("11011",'.');
		StoC.put("11100",',');
		StoC.put("11101",'-');
		StoC.put("11110",'\'');
		StoC.put("11111",'?');
	}
}

Measured memory_bytes: 43108
import copy

def j(n):
    if n:print("yes")
    else:print("no")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)
n = ip()
print((n-1)*n//2)

Measured memory_bytes: 3440
#include <iostream>
#include <vector>
#include <complex>
#define X real()
#define Y imag()
using namespace std;
typedef complex<double> P;
typedef vector<P> Pol;

double Area(Pol pol){
	int size=pol.size();
	double x,y,sum=0;
	for(int i=0;i<size;i++){
		x=pol[i%size].X-pol[(i+1)%size].X;
		y=pol[i%size].Y+pol[(i+1)%size].Y;
		sum+=x*y;
	}
	return abs(sum/2.0);
}

int main(void){
	int n;
	int j=1;
	while(cin >> n ,n){
		double area;
		Pol pol;
		P tmp;
		for(int i=0;i<n;i++){
			cin >> tmp.X >> tmp.Y;
			pol.push_back(tmp);
		}
		area=Area(pol);
		cout.precision(1);
		cout << j++ <<" " << fixed<< area << endl;
	}
	return 0;
}

Measured memory_bytes: 1300
def search(table, x, y, depth, max_depth):

    if depth == max_depth:
        return True

    if x < 0 or x >= 10 or y < 0 or y >= 10:
        return False

    if depth >= 0 and table[x][y][depth] == 0:
        return False

    if search(table, x-2, y-1, depth+1, max_depth):
        return True
    if search(table, x-2, y, depth+1, max_depth):
        return True
    if search(table, x-2, y+1, depth+1, max_depth):
        return True

    if search(table, x-1, y-2, depth+1, max_depth):
        return True
    if search(table, x, y-2, depth+1, max_depth):
        return True
    if search(table, x+1, y-2, depth+1, max_depth):
        return True

    if search(table, x+2, y-1, depth+1, max_depth):
        return True
    if search(table, x+2, y, depth+1, max_depth):
        return True
    if search(table, x+2, y+1, depth+1, max_depth):
        return True

    if search(table, x-1, y+2, depth+1, max_depth):
        return True
    if search(table, x, y+2, depth+1, max_depth):
        return True
    if search(table, x+1, y+2, depth+1, max_depth):
        return True


while True:
    px,py = [int(i) for i in input().split()]
    if px == 0 and py == 0:
        break

    table = [[[0 for i in range(10)] for j in range(10)] for k in range(10)]

    n = int(input())
    N = [int(i) for i in input().split()]
    traps = []

    for i in range(0, len(N), 2):
        x = N[i]
        y = N[i+1]
        prx = max(x-1, 0)
        pry = max(y-1, 0)
        pox = min(x+1, 9)
        poy = min(y+1, 9)

        d = int(i//2)
        table[prx][pry][d] = 1
        table[prx][y][d] = 1
        table[prx][poy][d] = 1
        table[x][pry][d] = 1
        table[x][y][d] = 1
        table[x][poy][d] = 1
        table[pox][pry][d] = 1
        table[pox][y][d] = 1
        table[pox][poy][d] = 1

    if search(table, px, py, -1, n):
        print("OK")
    else:
        print("NA")




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

using namespace std;
using namespace chrono;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()

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

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define JD
// #define TIME

/******************************************************************************************************************************/


const ll inf = 2e18;
const ll mod = 1e9+7;
const ll N = 1e6+3;


int main()
{
    auto start_time = Clock;
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif

    
    int x;
    cin>>x;
    cout<<(!x);



    

    auto end_time = Clock;
    #ifndef TIME
    	return 0;
    #endif
	cout << "\nTime elapsed: "
	<< (double)duration_cast<milliseconds>(end_time-start_time).count() 
	<< "ms";


    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            List<int> mochis = new List<int>();
            for (int i = 0; i < N; i++)
            {
                mochis.Add(int.Parse(Console.ReadLine()));
            }
            mochis.Sort();
            int ret = 1;
            for (int i = 0; i < mochis.Count - 1; i++)
            {
                if (mochis[i] <  mochis[i + 1])
                {
                    ret++;

                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int n,k;
	cin>>n>>k;
	vector<mp> a;
	int p,c=1;
	string s;
	cin>>s;
	p = s[0]-'0';
	int f = p;
	for(int i=1;i<n;i++){
		int b=s[i]-'0';
		
		if(b!=p){
			a.push_back(mp(c,p));
			c=0;
		}
		c++;
		p=b;
	}
			a.push_back(mp(c,p) );
	//		for(int i=0;i<a.size();i++)cout<<a[i].first<<' '<<a[i].second<<endl;;
			int sum=0;
		int cnt=0;
		int res = 0;
		int last=0;
		for(int j=0;j<a.size()&&cnt<=k;j++){
			if(a[j].second==0)cnt++;
			if(cnt==k+1)break;
			res+=a[j].first;
			last = j;
		}
		sum= max(sum,res);
		int st=0;
		if(a[0].second==0){
			st++;
			res-=a[0].first;
			if(last+1<a.size()){
				res+=a[last+1].first;
				last++;
			}
			if(last+1<a.size()) {
				res+=a[last+1].first;
				last++;
			}

		}
		sum = max(sum,res);
		for(int i=st;i<a.size()&&last<a.size();i+=2){
			res-=a[i].first;
			res-=a[i+1].first;
			if(last+1<a.size()){
				res+=a[last+1].first;
				last++;
			}
			if(last+1<a.size()){
				res+=a[last+1].first;
				last++;
			}
		sum = max(sum,res);

		}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 2548
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


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

    int ans = n;
    int cur = 1;
    bool constructable = false;
    for (int i=0; i<n; i++) {
        if (a[i] == cur) {
            cur++;
            ans--;
            constructable = true;
        }
    }

    if (constructable) cout << ans << endl;
    else cout << "-1" << endl;

    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<ios>
#include<cmath>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<assert.h>
#include<bitset>
#include<tuple>
#include<climits>
#include<deque>
#include<utility>
#include<unordered_map>
#include<unordered_set>
#include<iterator>
#include<sstream>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define l     long
#define ll    long long
#define nitro ios_base::sync_with_stdio(false);cin.tie(0);
#define vi    vector<int>
#define pub   push_back
#define puf   push_front
#define pob   pop_back
#define pof   pop_front
#define PI    3.1415926535897932384626433
#define endl  '\n'
#define gap   ' '
int main()
{
    nitro
    string s;cin>>s;
    for(int i=0;i<s.size();i+=2)
    {
        if(s.substr(i,2)!="hi") {cout<<"No";return 0;}
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    set<string> dict;
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        string o, str;
        cin >> o >> str;
        if (o == "find")
        {
            if (dict.count(str) == 1)
                cout << "yes" << endl;
            else
                cout << "no" << endl;
        }
        else
        {
            dict.emplace(str);
        }
    }

    return 0;
}


Measured memory_bytes: 32060
function main(input) {
  const inputs =input.split('\n')
  const [N] = inputs[0].split(' ').map(Number)
  const A = inputs[1].split(' ').map(Number)
  const len = A.length
  const slen = (new Set(A)).size
  console.log(len === slen ? 'YES' : 'NO')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())


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

//最大公約数2つ
int gcd(int a, int b){
   if (a%b == 0){
       return(b);
   } else{
       return(gcd(b, a%b));
   }
}

//最大公約数3つ
int gcd(int a, int b, int c){
   if (gcd(a,b)%c == 0){
       return(c);
   } else{
       return(gcd(c, gcd(a,b)%c));
   }
}


int main() {
    ll K, ans = 0;
    cin >> K;

    //ΣΣΣgcd(a,b,c) 愚直?
    for(int a = 1; a <= K; ++a){
        for(int b = 1; b <= K; ++b){
            for(int c = 1; c <= K; ++c){
                ans += gcd(a,b,c);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<complex>
#include<vector>

using namespace std;

int nx[]={0,1,0,-1};
int ny[]={0,1,0,-1};
//*****************************************


int main(void){

    int s;
    int m=0;
    scanf("%d",&s);

    vector<int> index(1000100,0);
    index[0]=s;

    for(int i=1; i<1000100;i++)
    {
        
        if(index[i-1]%2==0)
        {
            index[i]=index[i-1]/2;

        }
        else
        {
            index[i]=3*index[i-1]+1;
        }

        for(int j=0 ; j<i ; j++){
            if(index[i]==index[j])
            {
                m=i+1;
                break;
            }
            
        }
        //cout<<index[i]<<"\n";

        if(m!=0){
            break;
        }


    }

    cout << m <<"\n";

    return 0;
}





Measured memory_bytes: 4096
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (a > b) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  vi a(n);

  rep(i, n) cin >> a[i];
  ll ans = 0;

  rep2(i, 1, n-1) {
    if (a[i] < a[i-1]) {
      ans += a[i-1] - a[i];
      a[i] = a[i-1];
    }
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3968
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define rep(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define min3(a,b,c)     min(a,min(b,c))



int main(){ FastIO;

char c;cin>>c;
if((int)c<95) cout<<"A";
else cout<<"a";

}

Measured memory_bytes: 3580
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		HashMap<Character, TreeSet<Integer>> place = new HashMap<>();
		for (int i = 'a'; i <= 'z'; i++) {
		    place.put((char)i, new TreeSet<>());
		}
		for (int i = 0; i < s.length; i++) {
		    place.get(s[i]).add(i);
		}
		String t = sc.next();
		Integer cur = 0;
		long times = 0;
		for (char c : t.toCharArray()) {
		    if (place.get(c).size() == 0) {
		        System.out.println(-1);
		        return;
		    }
		    cur = place.get(c).ceiling(cur);
		    if (cur == null) {
		        times++;
		        cur = place.get(c).ceiling(0);
		    }
		    cur++;
		}
		System.out.println(times * s.length + cur);
   }
}


Measured memory_bytes: 48116
#include<cstdio>

int main(){
    int m,f,r;
    for(int i = 0; i < 50; i++){
        scanf("%d %d %d",&m,&f,&r);
        int s;
        if(m == -1 && f == -1 && r == -1){
            break;
        }
        s = m + f;
        if(m == -1 || f == -1){
            printf("F\n");
        }
        else if(s >= 80){
            printf("A\n");
        }
        else if(s >= 65 && s < 80){
            printf("B\n");
        }
        else if(s >= 50 && s < 65){
            printf("C\n");
        }
        else if(s >= 30 && s < 50){
            if(r >= 50){
                printf("C\n");
            }
            else{
                printf("D\n");
            }
        }
        else if(s < 30){
            printf("F\n");
        }
    }
}


Measured memory_bytes: 2596
/**
*    author:  yuya1234
*    created: 14.07.2020 10:43:39
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

  vector<string> v;
  string tmp;
  REP(i,3){
    cin>>tmp;
    v.emplace_back(tmp);
  }

  int idx=0;
  char card;
  for(;;)
  {
    card=v[idx][0];
    if(SZ(v[idx])>1)v[idx]=v[idx].substr(1);
    else if(SZ(v[idx])==1)v[idx]="";
    else break;
    if(card=='a')idx=0;
    else if(card=='b')idx=1;
    else idx=2;
  } 

  cout<<(char)('A'+idx)<<endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    ll n;
    cin >> n;
    for (int i = floor(sqrt(n)) + 1; i >= 1; i--)
    {
        if (n % i == 0)
        {
            cout << i + n / i - 2 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
N = int(input())
s = [input() for _ in range(N)]
M = int(input())
t = [input() for _ in range(M)]
ans = 0
for word in set(s):
    if word not in t:
        ans = max(ans, s.count(word))
    else:
        ans = max(ans, s.count(word) - t.count(word))
print(ans)


Measured memory_bytes: 3060
import math

class Point:
	def __init__(self, x, y):
		self.x = x
		self.y = y

	def distance(self, other):
		return math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2)

if __name__ == "__main__":
	N = int(input())
	points = []
	d = 0
	for _ in range(N):
		x, y = map(int, input().split())
		q = Point(x, y)
		for p in points:
			d += q.distance(p)
		points.append(q)
	print(2.0 / float(N) * d)

Measured memory_bytes: 3064
// JOI1.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

int main()
{
	int day;
	double japan_day, math_day, japan_max, math_max;

	scanf("%d", &day);
	scanf("%lf", &japan_day);
	scanf("%lf", &math_day);
	scanf("%lf", &japan_max);
	scanf("%lf", &math_max);

	int a = ceil(japan_day / japan_max);
	int b = ceil(math_day / math_max);

	int max;
	if (a > b) {
		max = a;
	}
	else {
		max = b;
	}

	printf("%d\n", day - max);

	return 0;
}

Measured memory_bytes: 1064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int w,h,n;


int sol(int y,int x,char data[100][100],int dy,int dx){
    int c=1;
    while(1){
        if( y+dy*c>=0 && y+dy*c<h && x+dx*c>=0 && x+dx*c<w && data[y+dy*c][x+dx*c]==data[y][x] && data[y][x]!='.'){
            c++;
        }
        else break;
    }
    return c-1;
}

int del(char data[100][100]){
    int ret=0;
    char delmap[100][100]={};
    
    rep(i,h){
        rep(j,w){
            int a=sol(i,j,data,-1,0);
            int b=sol(i,j,data,1,0);
            int c=sol(i,j,data,0,-1);
            int d=sol(i,j,data,0,1);
            
            if(a+b+1>=n || c+d+1>=n){
                delmap[i][j]='*';
            }
        }
    }
    rep(i,h) rep(j,w) if(delmap[i][j]=='*')data[i][j]='.',ret++;
    
    return ret;
}


void fall(char data[100][100]){
    for(int count=0;count<h+1;count++){
        for(int i=h-2;i>=0;i--){
            rep(j,w){
                if( data[i+1][j]=='.' ){
                    swap( data[i][j] , data[i+1][j] );
                }
            }
        }
    }
    
}



bool solve(char data[100][100]){
    int sum=0;
    rep(i,h) rep(j,w) if(data[i][j]!='.')sum++;
    
    int c=0;
    while(1){
        fall(data);
        int res=del(data);
        c+=res;
        if(res==0)break;
    }
    
    if(sum==c)return true;
    else return false;
}



int main() {
    cin>>h>>w>>n;
    
    char data[100][100]={};
    rep(i,h) rep(j,w) cin>>data[i][j];
    
    int d[2]={-1,1};
    rep(i,h){
        rep(j,w){
            rep(k,2){
                if(i>=0 && i<h && j+d[k]>=0 && j+d[k]<w){
                    char copy[100][100]={};
                    rep(i,h) rep(j,w) copy[i][j]=data[i][j];
                    
                    swap( copy[i][j+d[k]] , copy[i][j] );
                    
                    if(solve(copy)){
                        cout<<"YES"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"NO"<<endl;
    
    return 0;
}

Measured memory_bytes: 3116
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,m,ans;
vector<pair<int,int> > v[55];
bool u[55];
void dfs(int x,int no)
{
	u[x]=true;
	for(int i=0;i<v[x].size();i++)
		if(!u[v[x][i].first]&&v[x][i].second!=no)
			dfs(v[x][i].first,no);
}
int f(int no)
{
	for(int i=1;i<=n;i++)
		u[i]=false;
	dfs(1,no);
	for(int i=1;i<=n;i++)
		if(!u[i])
			return false;
	return true;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(make_pair(b,i));
		v[b].push_back(make_pair(a,i));
	}
	for(int i=1;i<=m;i++)
		if(!f(i))
			ans++;
	cout<<ans;
	return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  rep(i, S.size()){
    S.at(i)=S.at(i)+N;
    if(S.at(i)>'Z') S.at(i)=S.at(i)-26;
  }
  cout << S << endl;
}

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

int main(){

    int N;
    cin >> N;
    vector<int> h(N);
    rep(i,N)cin >> h[i];
    vector<int> dp(N,INF);
    dp[0] = 0;
    rep(i,N-1){
        dp[i+1] = min(dp[i+1],dp[i] + abs(h[i+1] - h[i]));
        if(i < N-2){
            dp[i+2] = min(dp[i+2],dp[i] + abs(h[i+2] - h[i]));
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int cnt[105],tot;
int main(){
	int n,k,m,i,j,a;
	scanf("%d%d",&n,&k);
	for(i=1;i<=k;i++){
		scanf("%d",&m);
		for(j=1;j<=m;j++){
			scanf("%d",&a);
			cnt[a]++;
		}
	}	
	for(i=1;i<=n;i++)
		if(cnt[i])tot++;
	printf("%d\n",n-tot);
	return 0;
	} 

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

int main() {
  string A, B;
  cin >> A >> B;
  int d = 0;
  
  for (int i = 0; i < A.size(); i++) {
    if (A.at(i) != B.at(i)) {
      d++;
    }
  }

  cout << d << endl;
}


Measured memory_bytes: 3928
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstdio>
#include <cmath>
#include<map>
#include <utility>
using namespace std;
//Emory "L" Blein
#define ll long long


int main() {
    int res=0;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a+b)>(c+d))cout<<"Left";
    else if((a+b)<(c+d))cout<<"Right";
    else cout<<"Balanced";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>

using namespace std;
#define N 4
#define N2 16

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle {
  int f[N2], space, MD;
  int cost;

  bool operator < ( const Puzzle &p ) const {
    for ( int i = 0; i < N2; i++ ) {
      if ( f[i] == p.f[i] ) continue;
      return f[i] < p.f[i];
    }
    return false;
  }
};
struct State {
  Puzzle puzzle;
  int estimated;
  bool operator < (const State &s) const {
    return estimated > s.estimated;
  }
};

int getAllMD(Puzzle pz) {
  int sum = 0;
  for ( int i = 0; i < N2; i++ ) {
    if ( pz.f[i] == N2 ) continue;
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

int astar(Puzzle s) {
  priority_queue<State> PQ;
  s.MD = getAllMD(s);
  s.cost = 0;
  map<Puzzle, bool> V;
  Puzzle u, v;
  State initial;
  initial.puzzle = s;
  initial.estimated = getAllMD(s);
  PQ.push(initial);
  while ( !PQ.empty() ) {
    State st = PQ.top(); PQ.pop();
    u = st.puzzle;

    if ( u.MD == 0 ) return u.cost;
    V[u] = true;

    int sx = u.space / N;
    int sy = u.space % N;

    for ( int r = 0; r < 4; r++ ) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if ( tx < 0 || ty < 0 || tx >= N || ty >= N ) continue;
      v = u;

      v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
      v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];

      swap(v.f[sx * N + sy], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if ( !V[v] ) {
        v.cost++;
        State news;
        news.puzzle = v;
        news.estimated = v.cost + v.MD;
        PQ.push(news);
      }
    }
  }
  return -1;
}

int main() {
  for ( int i = 0; i < N2; i++ )
    for ( int j = 0; j < N2; j++ )
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);

  Puzzle in;

  for ( int i = 0; i < N2; i++ ) {
    cin >> in.f[i];
    if ( in.f[i] == 0 ) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  cout << astar(in) << endl;

  return 0;
}






Measured memory_bytes: 257656
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define dF3(i,a,b) for(int i=(a)-1;i>=(b);--i)
using namespace std;typedef long long ll;typedef double ld;int INF=0x3f3f3f3f;int INF2=0x7fffffff;ll LNF=0x3f3f3f3f3f3f3f3f;ll LNF2=0x7fffffffffffffff;

int n,x,c;
bitset<4000000> St;

int main(){
	scanf("%d",&n);
	St[0]=1;
	F(i,1,n) scanf("%d",&x), St|=St<<x;
	x=St.count();
	F(i,0,4000000){
		if(St[i]) ++c;
		if(c==x/2+1) {printf("%d",i); return 0;} 
	}
	return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
    public static long combination(int n,int k){
        if(n==0)
            return 0;
        if(k==0)
            return 1;
        else
            return combination(n,k-1)*(n-k+1)/k;

    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int n=sc.nextInt();
        int a[]=new int[n];
        int b[]=new int[201001];
        int c[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
            b[a[i]]++;
        }
        long m=0;
        for(int i=0;i<b.length;i++) {
            m += Main.combination(b[i],2);
        }
        for(int i=0;i<n;i++){
            long v=m-Main.combination(b[a[i]],2)+Main.combination(b[a[i]]-1,2);
            System.out.println(v);

        }

    }
}

Measured memory_bytes: 103336