akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int ac = 83, mod = 1e9;
bool A[ac][ac][ac * ac * 2];
ll B[ac][ac];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> B[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			int x; cin >> x;
			B[i][j] -= x;
		}
	A[0][1][ac * ac] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			for (int k = ac; k < ac * ac * 2 - ac; k++)
			{
				if (A[i - 1][j][k - B[i][j]]) A[i][j][k] = 1;
				if (A[i - 1][j][k + B[i][j]]) A[i][j][k] = 1;
				if (A[i][j - 1][k - B[i][j]]) A[i][j][k] = 1;
				if (A[i][j - 1][k + B[i][j]]) A[i][j][k] = 1;
			}
		}
	int b = 1e9;
	for (int i = 0; i < ac * ac * 2; i++)
		if (A[n][m][i]) b = min(b, abs(i - ac * ac));
	cout << b << '\n';
}



Measured memory_bytes: 91008
package main

import (
	"fmt"
	"math"
)

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func main(){
	var X, K, D int
	fmt.Scan(&X, &K, &D)

	X = abs(X)

	if abs(X)/D >= K {
		X -= D * K
		fmt.Println(X)
		return
	}

	if abs(X)/D > 0 {
		K -= abs(X)/D
		X -= (abs(X)/D) * D
	}

	if K%2 == 0 {
		fmt.Println(X)
	}else{
		fmt.Println(abs(X-D))
	}
}

Measured memory_bytes: 1840
#include <cstdio>
#include <algorithm>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define forw(i, a, b) for (int i = a; i <= b; ++i)

const int mod = 1e9 + 7;
const int NR = 4010;

int n, m, K;
int f[NR][NR];

int main() {
	scanf("%d%d%d", &n, &m, &K);
	int N = n + m + 2, ans = 0;
	f[0][0] = 1; iter(i, n) f[0][i] = 1;
	iter(i, N) {
		forw(j, 0, n) {
			f[i][j] = (f[i - 1][j] - (j - K < 0 ? 0 : f[i - 1][j - K]) + mod) % mod;
			if (j) f[i][j] = (f[i][j] + f[i][j - 1]) % mod;

			int t = i * (K - 1) - j;
			if (j > 0 && j % (K - 1) == n % (K - 1) && t <= m - 1 && t % (K - 1) == (m - 1) % (K - 1)) {
				ans = (0ll + ans + f[i - 1][j - 1] - (j - K < 0 ? 0 : f[i - 1][j - K]) + mod) % mod;
//				printf("!%d %d\n", i, j);
			}

		//	printf("f[%d][%d]=%d\n", i, j, f[i][j]);
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 62080
#include <iostream>
#include <map>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	bool res = true;
	map<string,bool> memo;
	char prev;
	for (int i = 0; i < N; ++i) {
		string str;
		cin >> str;
		if (i == 0 ||(!memo[str] && str[0] == prev)) {
			memo[str] = true;
			prev = str[str.length()-1];
		}
		else {
			res = false;
		}
	}
	
	if (res) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;


int main(){
	string s;
	cin>>s;
	int n=0;
	for(int i=0;i<=1;i++){
		if(s[i]!=s[i+1]) n=1;
		}
		if(n==0){
			OUT("No");
		}else{
			OUT("Yes");
		}
	return 0;
}

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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29

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

vector<tuple<string,int,int>> lis;

for(int i=0;i<n;i++){
string a;
int b;
cin >> a>>b;
lis.push_back(make_tuple(a,-b,(i+1)));
}
sort(lis.begin(),lis.end());
for(tuple<string,int,int> temp:lis)
cout << get<2>(temp) <<"\n";



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool PN(T x)
{
  if (x <= 1)
    return false;
  if (x == 2)
    return true;
  for (int i = 2; i < sqrt(x) + 1; i++)
    if (x % i == 0)
      return false;
  return true;
}

const long long MOD = 1e9+7;

void solve()
{
  string a, b; cin >> a >> b;
  int asize = a.size(), bsize = b.size();
  if(asize > bsize) {
    cout << "GREATER" << endl;
    return ;
  }
  else if(asize < bsize) {
    cout << "LESS" << endl;
    return ;
  }
  int i = 0;
  while(i < asize){
    if(a[i]-'a' > b[i]-'a'){
      cout << "GREATER" << endl;
      return;
    } else if(a[i] - 'a' < b[i]-'a') {
      cout << "LESS" << endl;
      return;
    } else {
      i++;
    }
  }
  cout << "EQUAL" << endl;

}

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

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

const int DIM = 4e2 + 5;
const int MOD = 1e9 + 7;

int dp[DIM][DIM], aux[DIM][DIM], arr1[DIM], arr2[DIM];

int main( void ) {
    
    int n, c;
    cin >> n >> c;
    
    for( int i = 1; i < DIM; i ++ )
        aux[i][0] = 1;
    
    for( int j = 1; j <= c; j ++ )
        for( int i = 1; i < DIM; i ++ )
            aux[i][j] = ( 1LL * aux[i][j - 1] * i ) % MOD;
        
    for( int j = 0; j <= c; j ++ )
        for( int i = 1; i < DIM; i ++ )
            aux[i][j] = ( aux[i][j] + aux[i - 1][j] ) % MOD;
    
    for( int i = 1; i <= n; i ++ )
        cin >> arr1[i];
    for( int i = 1; i <= n; i ++ )
        cin >> arr2[i];
    
    for( int i = 1; i <= n; i ++ ) {
        int x = arr1[i], y = arr2[i];
        
        for( int j = 0; j <= c; j ++ ) {
            if( i == 1 )
                dp[i][j] = ( aux[y][j] - aux[x - 1][j] + MOD ) % MOD;
            else {
                for( int k = 0; k <= j; k ++ )
                    dp[i][j] = ( dp[i][j] + ( 1LL * dp[i - 1][j - k] * ( ( aux[y][k] - aux[x - 1][k] + MOD ) % MOD ) ) % MOD ) % MOD;
            }
        }
    }
    
    cout << dp[n][c] << endl;
    return 0;
}

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

int main(){
    int H, W;

    while(1){
        cin >> H >> W;

        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
                cout << "#";
                if (j == W - 1) cout << endl;  
            }

            if (i == H - 1) cout << endl;
        }
        if (H == 0 && W == 0)break;
    }
}


Measured memory_bytes: 3088
S = input()
memo = 0

if S[0] == "A":
    for i in range(2,len(S)-1):
        if S[i] == "C":
            memo = i
            break
    if memo > 0:
        S = S[1:]
        S = S[:memo-1] + S[memo:]
        if S.islower():
            print("AC")
            exit()
print("WA")

Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    int n;
    int cnt = 0;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0, j = n - 1; i < j;)
    {
        if (s[i] != 'W')
        {
            i++;
            continue;
        }
        if (s[j] != 'R')
        {
            j--;
            continue;
        }
        i++, j--, cnt++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3376
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

// グラフ用ヘッダ

typedef double Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight) :
        src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int n,a,b;
int t[8]; // size n
Graph g;
double dp[32][1<<9];

double inf = 1e100;
string solve(){
    priority_queue<tuple<double,int,int>> q;
    rep(i,32)rep(j,1<<9) dp[i][j] = inf;
    dp[a][0] = 0;
    // -d,v,use
    q.emplace(0,a,0);
    while(q.size()){
        dump(q.size());
        double d; int v,use;
        tie(d,v,use) = q.top(); q.pop();
        dump(d,v,use);
        d = -d;
        if(dp[v][use] > d) continue;
        for(const Edge& e : g[v]){
            rep(i,n){
                if(use>>i & 1) continue;
                double nd = d+e.weight/t[i];
                int nu = use | (1<<i);
                if(dp[e.dst][nu] > nd){
                    dp[e.dst][nu] = nd;
                    q.emplace(-nd, e.dst, nu);
                }
            }
            // {
            //     double nd = d + e.weight;
            //     if(dp[e.dst][use] > nd){
            //         dp[e.dst][use] = nd;
            //         q.emplace(-nd, e.dst, use);
            //     }
            // }
        }
    }

    double ans = *min_element(dp[b],dp[b]+(1<<n));
    if(ans != inf){
        char buf[100];
        sprintf(buf, "%.10lf", ans);
        return buf;
    } else {
        return "Impossible";
    }
}

int main(){
    while(cin>>n && n){
        int m,p;
        cin>>m>>p>>a>>b;
        rep(i,n) cin >> t[i];
        g.assign(m+1,{});
        rep(i,p){
            int x,y,z; cin >> x >> y >> z;
            g[x].eb(x,y,z);
            g[y].eb(y,x,z);
        }
        cout << solve() << endl;
    }
}

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

int main(void)
{
    int N;
    cin >> N;
    int residue = N % 1000;
    int change = 0;
    if(residue > 0){
        change =  1000 - residue;
    }
    cout << change << endl;

    return 0;
}


Measured memory_bytes: 3632
def nums():
    return list(map(int,input().split(" ")))
def num():
    return int(input())

"""
a,b = nums()
if a <= 9 and b <= 9:
    print(a * b)
else:
    print(-1)
"""

n = num()
qq = []
for i in range(10):
    for j in range(10):
        qq.append(i * j)
if n in qq:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include <iostream>

int main(int argc, char *argv[]) {
  long a, b;
  std::cin >> a >> b;

  if (a == 0 || b == 0)
    std::cout << "Zero" << std::endl;

  long x = a / std::abs(a);
  long y = b / std::abs(b);

  if (x * y < 0)
    std::cout << "Zero" << std::endl;
  else if (a < 0) {
    if ((std::abs(b - a) + 1) % 2 == 0)
      std::cout << "Positive" << std::endl;
    else
      std::cout << "Negative" << std::endl;
  } else
    std::cout << "Positive" << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	int k;
  	cin >> k;
  	if(k%2==0 || k%5==0)
    {
      cout << "-1";
    }
  	else
    {
      int ans = 1, cur = 7%k;
      while(cur!=0)
      {
        cur = cur*10+7;
        cur%=k;
        ans++;
      }
      cout << ans;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vector<tuple<int,int,int>> CSF;
	int c,s,f;
	rpz(i,N-1){
		cin>>c>>s>>f;
		CSF.emplace_back(c,s,f);
	}


	vi ans(N);
	rpz(i,N-1){
		tie(c,s,f) = CSF[i];
		// printf("i %d c %d s %d f %d\n", i,c,s,f);//
		ans[i] = s + c;
		rp(j,i+1,N-1){
			int c2,s2,f2; tie(c2,s2,f2) = CSF[j];
			// printf("j %d c2 %d s2 %d f2 %d\n", j,c2,s2,f2);//
			// printf("着 %d\n",ans[i]);//
			int ss = (ans[i]+f2-1)/f2*f2;
			ss = max(ss, s2);
			// printf("発 %d\n",ss);//
			ans[i] = ss + c2;
			// printf("着２ %d\n",ans[i]);//
			// printf("ans %d\n",ans[i]);puts("--");//
		}
	}

	rpz(i,N) cout<< ans[i] <<endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,K;
    cin>>N>>K;
    vector<int> A(N);
    rep(i,N)cin>>A.at(i);
    vector<bool> dp(200005);
    rep(i,K+1)dp[i]=false;
    rep(i,K+1){
        if(dp[i])continue;
        rep(j,N){
            dp[i+A.at(j)]=true;
        }
    }
    if(dp[K])cout<<"First"<<endl;
    else cout<<"Second"<<endl;
}

Measured memory_bytes: 3644
X = int(input())
# X = a**5 - b**5 
#   = (a-b)(a**4 + a**3 * b + a**2 * b**2 + a * b**3 + b**4)
# よって、X は　a-b　の倍数 X%(a-b) = 0

# a**5  = b**5 + X
#   a   = ( b**5 + X )**(1/5)
# X< 10**9 を満たす a,bの最大値は、120 , 119
flag = False
for ai in range(-119,120):
    for bi in range(-120,119):
        if ai - bi != 0 and X > (ai - bi):
            if X % (ai - bi) == 0:
                if ai**5 - bi**5 ==X:
                    print(int(ai),int(bi))
                    flag = True
                    break
        else:
            if ai**5 - bi**5 ==X:
                print(int(ai),int(bi))
                flag = True
                break
    if flag:
        break

Measured memory_bytes: 9148
import java.io.IOException;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next(),16);
    int b = Integer.parseInt(sc.next(),16);
    String answer = "=";
    if(a>b){
      answer = ">";
    }else if(a<b){
      answer = "<";
    }
    System.out.println(answer);
    }
  }


Measured memory_bytes: 23252
from collections import defaultdict
s = input().split()
n = int(s[0]) 
m = int(s[1])
graph = defaultdict(set)
for i in range(m):
    s = input().split(" ")
    graph[int(s[0])].add(int(s[1]))
    graph[int(s[1])].add(int(s[0]))

visited = [False] * (n+1)

def bfs (node):
    queue = [node]  
    ans = 0
    visited[node] = True
    while queue:
        root = queue.pop()
        ans +=1
        
        for child in graph[root]:
            if not visited[child]:
                queue.append(child)
                visited[child]  =True
    return ans

ans  = 0
for i in range(1, n+1):
    if not visited[i]:
        ans = max(ans, bfs(i))
print( ans)


Measured memory_bytes: 87776
a,b,c,d,e,f=map(int,input().split())
water=[]
suguar=[]
temp_3=0#砂糖水の量
temp_2=0#s砂糖の量を記録
ans=0#濃度を計算
temp=0
for i in range((f+1)//100):
    for j in range((f+1)//100):
        x=100*i*a+100*j*b
        if 1<=x<=f:
            water.append(x)
for i in range(f+1):
    for j in range(f+1):
        y=c*i+d*j
        if y<=f:
            suguar.append(y)
for i in water:
    for j in suguar:
        total=i+j
        if total<=f:
            if j<=i//100*e:
                ans=100*j/(i+j)
                if temp<=ans:
                    temp=ans
                    temp_2=total
                    temp_3=j
print(temp_2,temp_3)


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

def main():
  n = int(input())
  c = 0
  
  for i in range(n):
    x = i
    x += 1
    if x < 10:
      c += 1
    elif x >= 100 and x < 1000:
      c += 1
    elif x >= 10000 and x < 100000:
      c += 1
      
  print(c)




if __name__ == '__main__':
  main()


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;

int main() {
  int n,l; cin>>n>>l;
  vector<string> v(n);
  rep(i, n) {
    cin>>v[i];
  }
  sort(v.begin(), v.end());
  rep(i, n) {
    cout<<v[i];
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int n, m, f[N];
int found(int x) {
    return x==f[x] ? f[x] : (f[x] = found(f[x]));
}
int main() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) f[i] = i;
    for(int i = 0, u, v, w; i < m; i++) {
        cin >> u >> v >> w;
        int fu = found(u), fv = found(v);
        f[fu] = fv;
    }
    set<int> s;
    for(int i = 1; i <= n; i++) {
        s.insert(found(i));
    }
    cout << s.size() << '\n';
    return 0;
}

Measured memory_bytes: 5376
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,D,Q,K,R,W,H,P,L;
ll ans;
string S,T;
ll y[101010];
ll a[101010];
ll b[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll r[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};
char mp[1010][1010];
int main() {
    cin>>H>>W;
    queue<pair<ll,ll> > v;

    rep(i,0,H+2){
        rep(j,0,W+2){
            mp[i][j]='#';
        }
    }

    rep(i,1,H+1){
        rep(j,1,W+1){
            cin>>mp[i][j];
            if(mp[i][j]=='#'){
                v.push(make_pair(i,j));
            }
        }
    }
    
    ans=0;
    while(true){
        bool flg=true;
        ll size = v.size();
        rep(i,0,size){
            pair<ll,ll> num = v.front();
            v.pop();
            rep(j,0,4){
                if(mp[num.first+dx[j]][num.second+dy[j]]=='.'){
                    flg=false;
                    mp[num.first+dx[j]][num.second+dy[j]]='#';
                    v.push(make_pair(num.first+dx[j],num.second+dy[j]));
                }

            }
        }
        if(flg)break;
        ans++;
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 17588
<?php
$inputData = array_map('intval', explode(" ", fgets(STDIN)));

$minData[] = $inputData[0] + $inputData[1];
$minData[] = $inputData[2] + $inputData[1];
$minData[] = $inputData[1] + $inputData[2];
$minData[] = $inputData[0] + $inputData[2];

echo min($minData);

?>

Measured memory_bytes: 4728
#include<bits/stdc++.h>
#include<cstring>
#include<climits>
#include<queue>
#include<unordered_set>
#include<algorithm>
#include<iomanip>
#include <typeinfo> 
#include <set>
#define ll long long int
#include <iostream>
using namespace std;
int mat[1005][1005];
int main() {
       
       ll x,k,d,ans;
       cin>>x>>k>>d;
       ll val=abs(x);
       val=val/d;
       if(val>k){
       	ans=abs(x)-k*d;
       	//cout<<"1 ";
	   cout<<ans<<endl;
	   }
	   else{
	   	ll a,b;
	   	val=abs(x);
	   	a=val%d;b=d-val%d;
	   	//cout<<a<<" "<<b<<endl;
	   	if(((val-a)/d)%2 == (k%2)){
	   		cout<<a<<endl;
		   }
		   else{
		   	cout<<b<<endl;
		   }
	   	ans=abs(x)-d*val;
	   //cout<<"2 ";
	   }
		return 0;
}

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

typedef long long ll;

#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define AA(i) cout << i << endl;
#define AS(i) cout << i << " ";

const int INF = 1001001001;

const double PI = 3.14159;

using namespace std;

//vector<ll> memo(1000007, INF);

int main() {

    int n, k;
    cin >> n >> k;

    int p[n];
    rep(i, n) 
        cin >> p[i];

    sort(p, p+n);

    int sum = 0;
    rep(i, k) {
        sum += p[i];
    }

    AA(sum);
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#include <bitset>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9+7
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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

int main(){
    int n;
    cin >> n;
    vector<ll> l(n);
    for(int i=0;i<n;i++) cin >> l[i];
    sort(l.begin(),l.end());
    int ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]==l[j]||l[j]==l[k]||l[i]==l[k]) continue;
                ll lenij=l[i]+l[j];
                if(l[k]>=lenij) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
    string s[3];
    REP(i, 3) cin >> s[i];
    cout << "A"+string(1,s[1][0])+"C" << endl;
}


Measured memory_bytes: 256
S=input()

if S=="SUN":
  print(7)
elif S=="MON":
  print(6)
elif S=="TUE":
  print(5)
elif S=="WED":
  print(4)
elif S=="THU":
  print(3)
elif S=="FRI":
  print(2)
elif S=="SAT":
  print(1)

Measured memory_bytes: 3060
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
void fo (){fflush(stdout);}
using namespace std;

int main ()
{
  string x [3];
  cin >> x[0] >> x[1] >> x[2];
  for (int i =0 ; i < 3 ;i++)
  cout << x[i][i] ;
  
  //cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>

using namespace std;

int main() {
  stack<int> cars;
  int command;  //??\???????????????

  while(cin >> command) {
    if (command == 0) {
      cout << cars.top() << endl;
      cars.pop();
    } else {
      cars.push(command);
    }
  }

  return 0;
}

Measured memory_bytes: 1200
n,A,B,C,=map(int,input().split())
l=[int(input()) for i in range(n)]
INF=1e9

def dfs(i,a,b,c):
  if i==n:
    if min(a,b,c)>0:
      return abs(A-a)+abs(B-b)+abs(C-c)-30
    else:
      return INF
  ret0 = dfs(i+1,a,b,c)
  ret1 = dfs(i+1,a+l[i],b,c)+10
  ret2 = dfs(i+1,a,b+l[i],c)+10
  ret3 = dfs(i+1,a,b,c+l[i])+10
  return min(ret0,ret1,ret2,ret3)
 
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m; cin >> n >> m;
	vector<int> f(n + 1, 0), bad(n + 1, 0);
	for(int i = 0; i < m; i++){
		int x; cin >> x;
		bad[x] = 1;
	}
	f[0] = 1;
	const int mod = 1'000'000'007;
	for(int i = 1; i <= n; i++){
		if(bad[i]) continue;
		f[i] = f[i - 1];
		if(i >= 2) f[i] += f[i - 2];
		if(f[i] >= mod) f[i] -= mod;
	}
	cout << f[n] << endl;
	return 0;
}


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

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

int main() {
    ll N, M;
    cin >> N >> M;

    string S, T;
    cin >> S >> T;

    ll L = lcm(N, M);
    ll ln = L/N, lm = L/M;

    bool ok = true;

    rep(i, min(N/lm, M/ln)) {
        if (S[lm*i] != T[ln*i]) ok = false;
    }

    if (ok) cout << L << endl;
    else cout << -1 << endl;

    return 0;
}

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

int main(){
  string str;
  string s;
  int n;
  int cnt = 0;
  cin >> str;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    s += s;
    if(s.find(str) != string::npos){
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3124
d[150][120];j,s,t,m,n,*p;main(i){for(;scanf("%d%d",&n,&m)*n;printf("%d\n",s)){for(memset(d,9,7e4);t=m--;d[i][j]=d[j][i]=s)scanf("%d%d%d",&i,&j,&s);for(s=i=0;++i-n;s+=d[t=m][n])for(d[t][j=m=n]=0;j--;*p&&d[m][n]>*p?m=j:0)p=d[j]+n,*p=fmin(*p,p[t-n]);}}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> a = {0, 9, 81, 729, 6561, 59049, 6, 36, 216, 1296, 7776, 46656, 1}; //0は便宜上入れた
  
  vector<vector<int>> dp(13, vector<int>(n + 1));
  for(int i = 1; i < n + 1; i++){
    dp.at(0).at(i) = 1e9;
  }
  for(int i = 0; i < 13; i++){
    dp.at(i).at(0) = 0;
  }
  
  for(int i = 1; i < 13; i++){
    for(int j = 0; j < n + 1; j++){
      if(j < a.at(i)){
        dp.at(i).at(j) = dp.at(i - 1).at(j);
      }
      else{
        dp.at(i).at(j) = min(dp.at(i - 1).at(j), dp.at(i).at(j - a.at(i)) + 1);
      }
    }
  }
  
  cout << dp.at(12).at(n) << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    int arr[n];
    for(int i=0; i<n; i++)
        scanf("%d", arr+i);
    for(int i=n-2; i>=0; i--)
    {
        if(arr[i]>arr[i+1])
        {
            if((arr[i]-arr[i+1])>1)
            {
                printf("No\n");
                return 0;
            }
            else
                arr[i]--;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cassert>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

#define read_int(X) \
    ll X;           \
    scanf("%lld\n", &X);

#define read_two_int(X, Y) \
    ll X, Y;               \
    scanf("%lld %lld\n", &X, &Y);

#define read_three_int(X, Y, Z) \
    ll X, Y, Z;                 \
    scanf("%lld %lld %lld\n", &X, &Y, &Z);

#define read_four_int(X, Y, Z, W) \
    ll X, Y, Z, W;                \
    scanf("%lld %lld %lld %lld\n", &X, &Y, &Z, &W);

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

    std::cout << s;
    if (s[s.length() - 1] == 's')
    {
        printf("%c", 'e');
    }

    printf("%c\n", 's');
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  ll x;
  cin >> x;
  ll ans=0;
  ans+=(x/500)*1000;
  x-=(x/500)*500;
  ans+=(x/5)*5;
  cout << ans << endl;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

    int ans = 0;
    int now = 0;
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            now++;
            if(now > ans) ans = now;
        }else{
            now = 0;
        }
    }

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

Measured memory_bytes: 256
H,W,D = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(H)]
Q = int(input())
L_R = [list(map(int,input().split())) for i in range(Q)]
data = []
mod = [[0]]
for i in range(H):
    for j in range(W):
        data.append([A[i][j],i+1,j+1])

        
data.sort()

for i in range(H*W):
    if i <= D-1:
        mod.append([0])
    else:
        mod[(i%D)+1].append(mod[(i%D)+1][-1]+abs(data[i][1]-data[i-D][1])+abs(data[i][2]-data[i-D][2]))

for l,r in L_R:
    if l%D == 0:
        print(mod[D][(r//D)-1]-mod[D][(l//D)-1])
    else:
        print(mod[l%D][(r//D)]-mod[l%D][(l//D)])

Measured memory_bytes: 45728
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int mod=1e9+7;
struct M{ int a[3][3]; };
inline M operator * (const M &a,const M &b) {
	M ans={};
	for (int i=0;i<3;i++)
		for (int j=0;j<3;j++)
			for (int k=0;k<3;k++)
				ans.a[i][j]=(ans.a[i][j]+1LL*a.a[i][k]*b.a[k][j])%mod;
	return ans;
}
const M trans=(M){
	{
		{1,2,1},//0->0 不放 0->1 两个球挑一个放 0->2 两个一起放
		{0,1,1},//1->0 不合法 1->1 不放 1->2 放剩下的一个
		{1,2,2}//2->0 新建 2->1 新建并选一个放 2->2 不放或新建并放两个
	}
};
const M O=(M){
	{
		{1,2,1},
		{0,1,1},
		{0,0,1}
	}
};
int main()
{
	int n=gi(),m=gi(),i,x=-1,last,y;
	M a={},b;a.a[0][0]=1;
	for (i=1;i<=m;i++) {
		last=x;x=gi();
		y=x-last-1;b=trans;
		while (y) {
			if (y&1) a=a*b;
			b=b*b;y>>=1;
		}
		if (x!=n) a=a*O;
	}
	if (x!=n) {
		y=n-x-1;b=trans;
		while (y) {
			if (y&1) a=a*b;
			b=b*b;y>>=1;
		}
	}
	printf("%d\n",a.a[0][2]);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	long long int a[10000], min=1000000, max=-1000000, sum=0;
	int n, i;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%lld",&a[i]);
		if(a[i]<min){
			min=a[i];
		}
		if(a[i]>max){
			max=a[i];
		}
		sum+=a[i];
	}
	
	printf("%lld %lld %lld\n", min, max, sum);
	
	return 0;
}

Measured memory_bytes: 676
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5;
typedef long long ll;

int main(){
	int n;
  cin >> n;
  if(n >= 30) cout << "Yes";
  else cout << "No";
	return 0;
}


Measured memory_bytes: 3576
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define SIZE 100000
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
	inv[1] = 1;
	for (int i = 2; i <= SIZE; i++)
	{
		inv[i] = mod - (mod / i)*inv[mod%i] % mod;
	}
	kai[0] = invkai[0] = 1;
	for (int i = 1; i <= SIZE; i++)
	{
		kai[i] = kai[i - 1] * i%mod;
		invkai[i] = invkai[i - 1] * inv[i] % mod;
	}
}
ll com(ll a, ll b)
{
	if (b < 0 || a < b)return 0;
	return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}
int main()
{
	invinit();
	int n, a, b, c;
	scanf("%d%d%d%d", &n, &a, &b, &c);
	if (b % 2 != 0)
	{
		printf("0\n");
		return 0;
	}
	ll ans = 0;
	for (int i = 0; i <= c / 3; i++)
	{
		for (int j = 0; j <= min(a, c - i * 3); j++)
		{
			ll t = com(a + b / 2 + i, i)*com(a + b / 2, a) % mod*com(a, j) % mod;
			if (b > 0)t *= com(c - i * 3 - j + b / 2 - 1, b / 2 - 1);
			else if (c != i * 3 + j)t = 0;
			ans = (ans + t) % mod;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll *v;
ll n, k, q, m;
string s;

void solve(){
    cin >> n;
    unordered_map<string, ll> m;
    for(ll i = 1; i <= n; i++){
        cin >> s;
        m[s]++;
    }
    vector<string> ans;
    q = 0;
    for(auto i : m)
        q = max(q, i.second);
    for(auto i : m){
        if(i.second >= q){
            ans.push_back(i.first);
        }
    }
    sort(ans.begin(), ans.end());
    for(auto i : ans)
        cout << i << endl;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

using namespace std;

const int N = 1e5, M = 1e6 + 6, OO = 0x3f3f3f3f;

int n, arr[M], cum[M];
string num;
int main()
{
	scanf("%d", &n);
	for(int i = 1 ; i <= N; ++i)
	{
		num = to_string(i);
		if(num.size() % 2 != 0)	++arr[i];
		cum[i] = cum[i - 1] + arr[i];
	}
	cout << cum[n] << endl;
	return 0;
}

Measured memory_bytes: 4736
import sys
import re

l = sys.stdin.readline()
l = l.split(' ')
l = [int(str) for str in l]

h = l[0]
w = l[1]

if ( h == 1):
  print("1")
  exit(0)
if ( w == 1):
  print("1")
  exit(0)

out = 0
if( w % 2 == 0):
  if( h % 2 == 0):
    out = h*w/2
  else:
    out = h*w/2
else:
  if( h % 2 == 0):
    out = h*w/2
  else:
    out = h*(w-1)/2+(h+1)/2
  

print(out)
sys.stdout.flush()


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
// O( ( |V| + |E| ) * log|V| )
const int W = 0, B = 1;
//重み付き有効グラフの隣接リスト表現
vector<int> dijkstra(const vector<vector<pair<int, int>>> &g, int s) {
  int n = g.size();
  priority_queue<pair<int, int>> pq; // cost, node
  vector<int> color(n, W), d(n, INF);
  d[s] = 0;
  pq.push(make_pair(0, s));

  while (!pq.empty()) {
    pair<int, int> f(pq.top());
    pq.pop(); // d[v], v
    color[f.second] = B;

    if (d[f.second] < (-1) * f.first)
      continue; // 最小値を取り出し、それが最短でなければ無視

    rep(i, 0, g[f.second].size()) {
      pair<int, int> v(g[f.second][i]);
      if (color[v.first] != B && d[f.second] + v.second < d[v.first]) {
        d[v.first] = d[f.second] + v.second;
        pq.push(make_pair(
            d[v.first] * (-1),
            v.first)); // priority_queueはデフォルトで大きい値を優先するため-1を掛ける
      }
    }
  }
  return d;
}
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int h, w;
bool inrange(int x, int y) { return 0 <= x and x < h and 0 <= y and y < w; }
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  cin >> h >> w;
  vector<string> s(h);
  rep(i, 0, h) { cin >> s[i]; }
  vector<vector<pair<int, int>>> adj(h * w,
                                     vector<pair<int, int>>()); // node, cost
  auto idx = [&](int x, int y) { return x * w + y; };

  int black = 0, white = 0;
  rep(i, 0, h) rep(j, 0, w) {
    s[i][j] == '#' ? black++ : white++;
    if (s[i][j] == '#')
      continue;
    rep(k, 0, 4) {
      int x = i + dx[k], y = j + dy[k];
      if (not inrange(x, y) or s[x][y] == '#')
        continue;
      adj[idx(i, j)].push_back(make_pair(idx(x, y), 1));
    }
  }
  auto d = dijkstra(adj, 0);
  if (d[idx(h - 1, w - 1)] == INF) {
    cout << -1 << endl;
  } else {
    dump(white,d[idx(h-1,w-1)]);
    cout << white - d[idx(h - 1, w - 1)]-1 << endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
#define maxn 100010
int n,m,k,f[maxn],fn[maxn],cnt[maxn],tot[maxn],ans[maxn];;
int get_p(int v)
{
	if(f[v]==v)
		return v;
	else
	{
		f[v]=get_p(f[v]);
		return f[v];
	}
}
void merge(int v,int u)
{
	int t1=get_p(v);
	int t2=get_p(u);
	f[t2]=t1;
	return;
}
int main(){
	int i,j,a,b;
	scanf("%d%d%d",&n,&m,&k);
	for(i=1;i<=n;i++)
		f[i]=i;
	for(i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		cnt[a]++,cnt[b]++,merge(a,b);
	}
	for(i=1;i<=n;i++)
		f[i]=get_p(i);
	for(i=1;i<=n;i++)
		fn[f[i]]++;
	for(i=1;i<=k;i++){
		scanf("%d%d",&a,&b);
		if(f[a]==f[b])tot[a]++,tot[b]++;
	}
	for(i=1;i<=n;i++)
		ans[i]=fn[f[i]]-cnt[i]-tot[i]-1;
	for(i=1;i<n;i++)
		printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;
int read(){
	int x=0;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int n,m;
vector <int> e[N];
LL ans;
int vis[N],c[N];
int tot=0,size=0,sz=0;
int dfs(int x,int f){
	vis[x]=1;
	c[x]=f;
	sz++;
	int res=0;
	for (auto y : e[x])
		if (!vis[y])
			res|=dfs(y,f^1);
		else
			res|=c[x]==c[y];
	return res;
}
void solve(int x){
	if (e[x].empty())
		return;
	size++;
	tot+=dfs(x,0)^1;
}
LL _2(int x){
	return 1LL*x*x;
}
int main(){
	n=read(),m=read();
	for (int i=1;i<=m;i++){
		int a=read(),b=read();
		e[a].push_back(b);
		e[b].push_back(a);
	}
	memset(vis,0,sizeof vis);
	for (int i=1;i<=n;i++)
		if (!vis[i])
			solve(i);
	ans=_2(n)-_2(sz)+_2(size)+_2(tot);
	cout << ans;
	return 0;
}
//单点情况特殊考虑
/*
8 5
2 3
3 4
2 4
5 6
6 7
ans = 33

*/

Measured memory_bytes: 10368
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

a = LIST()

tmp = a[0]//2
for i in range(1, N):
	if abs(a[0]//2-a[i]//2) % gcd(a[0], a[i]) != 0:
		print(0)
		sys.exit()
	tmp = a[i]//2*tmp//gcd(a[i]//2, tmp)

print((M-tmp)//(tmp*2)+1)


Measured memory_bytes: 16296
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 

using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007



void Solve()
{	
	ll n,x,y;
	cin>>n>>x>>y;
	
	ll ans[n]={0};
	
	f(i,1,n)
	{
		f(j,i+1,n)
		{
			ll dist=j-i;
			dist=min(dist,abs(i-x)+abs(j-y)+1);
			ans[dist]++;
		}
	}
	f(i,1,n-1) cout<<ans[i]<<endl;	
}


signed main() 
{
	speed;
	
	ll q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}


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

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

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

int main()
{
  string original_s;
  cin >> original_s;
  string s = original_s;
  int ans = iINF;
  bool same = true;

  rep(i, s.size() - 1)
  {
    if (s[i] != s[i + 1])
      same = false;
  }

  if (same)
  {
    cout << 0 << endl;
    return 0;
  }

  rep(i, 26)
  {
    char tmp = 'a' + i;

    int tmp_ans = 0;

    bool ok = false;
    while (s.size() >= 1 || !ok)
    {
      rep(j, s.size() - 1)
      {
        if (s[j] == tmp || s[j + 1] == tmp)
        {
          s[j] = tmp;
        }
      }
      tmp_ans++;
      s = s.substr(0, s.size() - 1);

      ok = true;
      rep(j, s.size() - 1)
      {
        if (s[j] != s[j + 1])
          ok = false;
      }

      if (ok)
      {
        chmin(ans, tmp_ans);
      }
    }
    s = original_s;
  }

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

Measured memory_bytes: 256
import collections
n = int(input())
a = list(map(int,input().split()))
x = collections.Counter(a)
keys = []
values = []
b = list(set(a))
for i in b:
    z = x[i]
    keys.append(i)
    values.append(z*(z-1)//2)
s = sum(values)
d = dict(zip(keys,values))
for i in a:
    ans = s
    ans -= d[i]
    ans += (x[i]-1)*(x[i]-2)//2
    print(ans)

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

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<String> b = new ArrayList<>();
        for (int i = 0;i < n;++i){
            String s = sc.next();
            if(b.size() > 0){
                String s1 = b.get(b.size() - 1);
                if(s1.charAt(s1.length() - 1) != s.charAt(0)){
                    System.out.println("No");
                    return;
                }
            }
            if(b.contains(s)){
                System.out.println("No");
                return;
            }
            b.add(s);
        }
        System.out.println("Yes");
    }

}




Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

P f(int x) {
    int a = x%10;
    int b = 0;
    while(x) {
        b=x;
        x /= 10;
    }
    return P(a,b);
}
int main() {
    int n;
    cin >> n;
    map<P, int> freq;
    for(int i = 1; i<=n; i++) {
        P p = f(i);
        freq[p]++;
    }
    ll ans = 0;
    for(int i = 1; i<=n; i++) {
        P p = f(i);
        P q(p.second, p.first);
        ans += freq[q];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)


// a^n mod を計算する
long int modpow(long int a, long int n, long int mod) {
    long int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

long int modcomb(long int a, long int b, long int mod){
    long int res = 1;
    for(long int i = a; i > a - b; i--){
        res *= i % mod;
        res %= mod;
    }
    res %= mod;
    for(long int i = 1; i <= b; i++){
        long int i_inv = modpow(i, mod - 2, mod);
        res *= i_inv % mod;
        res %= mod;
    }
    res %= mod;
    // cout << res << endl;
    return res;
}


int main(){
    const long int mod = 1000000007;
    long int h, w;
    long int a, b;
    cin >> h >> w >> a >> b;
    long int ans = modcomb(h - 1 + w - 1, h - 1, mod);
    long int num1 = modcomb(h - a - 1, 0, mod);
    long int num2 = modcomb(a - 1 + w - 1, w - 1, mod);
    long int ans_ = 0;
    rep(i, b){
        // cout << num1 << " " << num2 << endl;
        ans_ += num1 * num2;
        ans_ %= mod;
        long int inv1 = modpow(i + 1, mod - 2, mod);
        long int inv2 = modpow(a - 1 + w - 1 - i, mod - 2, mod);
        // cout << "inv = " << inv1 << " " << inv2 << endl;
        num1 = (((num1 * (h - a + i)) % mod) * inv1) % mod;
        num2 = (((num2 * (w - i - 1)) % mod) * inv2) % mod;
    }
    ans += mod - ans_;
    ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> c(n-1), s(n-1), f(n-1);

    rep(i, n-1){
        cin >> c[i] >> s[i] >> f[i];
    }

    rep(i, n){
        ll t = 0;
        for(int j=i; j<n-1; j++){
            if(t < s[j]) t = s[j];
            else if (t%f[j] == 0);
            else t += f[j] - t%f[j];
            t += c[j];
        }
        cout << t << endl;
    }
}

Measured memory_bytes: 256