akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
 
    int n;
    cin >> n;
 
    pair<int, int> data[n];
 
    for(int i = 0; i < n; i++) {
        cin >> data[i].first >> data[i].second;
    }
    
 
    double sol = 0;
    for(int r = 0; r < 100; r++) {
        random_shuffle(data, data + n);
        for(int i = 0; i < n; i++) {
            double x = data[i].first, y = data[i].second, c = sqrt(pow(x, 2) + pow(y, 2));
            for(int j = 0; j < n; j++) {
                if(i == j) continue;
                x += data[j].first;
                y += data[j].second;
                double length = sqrt(pow(x, 2) + pow(y, 2));
                if(length > c) c = length;
                else {
                    x -= data[j].first;
                    y -= data[j].second;
                }
            }
            sol = max(c, sol);
        }
    }
 
    cout << fixed << setprecision(20) << sol << endl;
 
    return 0;
}

Measured memory_bytes: 256
#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 <cstring>

using namespace std;
int parent[100000];
vector<int> edge[100000];

int main(){
  int N,M;
  scanf("%d%d",&N,&M);
  int n_deg[N];
  memset(n_deg,0,sizeof(n_deg));
  for(int i=0; i<N+M-1;i++){
     int A,B;
     scanf("%d%d",&A,&B);
     A--;B--;
     edge[A].push_back(B);
     n_deg[B]++;
  }
  //cout <<"input finished: "<< N <<": "<< M<<endl;
  int root=0;
  while(n_deg[root]!=0) root++;
  memset(parent,0,sizeof(parent));
  parent[root]=-1;
  queue<int> q;
  q.push(root);
  while(q.size()!=0){
     int cur = q.front();
     q.pop();
     for(int i=0; i < (int)edge[cur].size(); i++){
        int next = edge[cur][i];
        n_deg[next]--;
        if(n_deg[next]==0){
           q.push(next);
           parent[next]=cur;
        }
     }
  }
  for(int i=0; i<N; i++){
     printf("%d\n", parent[i]+1);
  }
  return 0;
}


Measured memory_bytes: 7040
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())

tmp = make_divisors(N)
if(len(tmp)%2==0):
    print((tmp[-1]-1)+(tmp[-2]-1))
else:
    print((tmp[-1]-1)+(tmp[-1]-1))


Measured memory_bytes: 38896
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void printMap(int** map){
	for(int y=0;y<8;y++){
		for(int x=0;x<8;x++) printf("%4d",map[y][x]);
		cout << endl;
	}
	getchar();
}

int countUpPanel(int** map,int x,int y,int color,int w, int h){
	int sum=0;
	if(!(x>=0 && y>=0 && x<w && y<h)) return 0;
	if(map[y][x]!=color)return 0;
	else{
		map[y][x]=0;
		sum++;
	}
	sum+=countUpPanel(map,x+1,y,color,w,h);
	sum+=countUpPanel(map,x-1,y,color,w,h);
	sum+=countUpPanel(map,x,y+1,color,w,h);
	sum+=countUpPanel(map,x,y-1,color,w,h);
	
	return sum;
}

void exchangePanel(int** map,int x,int y,int color,int c,int w, int h){
//	printf("nbb?,%d,%d,%d,%d\n",x,y,color,c);
	if(!(x>=0 && y>=0 && x<w && y<h)) return ;
	if(map[y][x]!=c)return ;
	if(map[y][x]==color)return ;
	else map[y][x]=color;
	exchangePanel(map,x+1,y,color,c,w,h);
	exchangePanel(map,x-1,y,color,c,w,h);
	exchangePanel(map,x,y+1,color,c,w,h);
	exchangePanel(map,x,y-1,color,c,w,h);
	
}

int solvePuzzle(int** map,int objectiveColor,int crrentColor,int round,int w,int h){
	int res=0;
	int resres=0;
	
//	cout << "flop:" << crrentColor << "round:" << round << endl;
//	printMap(map);


	if(round>=5){
		res=0;
		res=countUpPanel(map,0,0,objectiveColor,w,h);
/*		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]==objectiveColor) res++;
			}
		}
		if(res==11){
			printMap(map);
			getchar();
		}*/
		return res;
	}
	else{
		int **mapTemp = new int*[8];
		for(int i=0;i<8;i++) mapTemp[i]=new int[8];
	
		if(round==4){
			for(int y=0;y<8;y++){
				for(int x=0;x<8;x++) mapTemp[y][x]=map[y][x];
			}
	
			exchangePanel(map,0,0,objectiveColor,map[0][0],w,h);
			res=solvePuzzle(map,objectiveColor,objectiveColor,round+1,w,h);

			for(int y=0;y<8;y++){
				for(int x=0;x<8;x++) map[y][x]=mapTemp[y][x];
			}
		}
		else{
			resres=0;
			res=0;
			for(int i=1;i<=6;i++){
				for(int y=0;y<8;y++){
					for(int x=0;x<8;x++) mapTemp[y][x]=map[y][x];
				}
//				printf("naa?,%d,%d,%d\n",i,map[0][0],objectiveColor);
				exchangePanel(map,0,0,i,map[0][0],w,h);
				resres=solvePuzzle(map,objectiveColor,i,round+1,w,h);
				if(resres>=res) res=resres;
				for(int y=0;y<8;y++){
					for(int x=0;x<8;x++) map[y][x]=mapTemp[y][x];
				}
			}
		}
		for(int i=0;i<8;i++) delete [] mapTemp[i];
		delete [] mapTemp;


	}
	
	return res;
}

int main(void){
	int scale=8;
	int h,w,c;
	int status;

	int** map = new int*[8];
	for(int i=0;i<8;i++) map[i]=new int[8];
	while(true){
		cin >> h;
		cin >> w;
		cin >> c;
		if(h==0) break;
		for(int i=0;i<8;i++){
			for(int j=0;j<8;j++){
				map[j][i]=0;
			}
		}
		for(int j=0;j<h;j++){
			for(int i=0;i<w;i++){
				cin >> map[j][i];
			}
		}

		int res=0;
		
		res=solvePuzzle(map,c,0,0,w,h);
		cout << res << endl;
	}

	for(int i=0;i<8;i++) delete [] map[i];
	delete [] map;

	return 0;
}

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

const double pi = acos(-1);

int main(){ 
  double a,b,x; cin >> a >> b >> x;
  
  if( a*a*b <= 2*x){
    cout << fixed << setprecision(10) <<  (atan2(2*a*a*b-2*x,a*a*a)*180.0)/pi << endl; 
  }
  else{
    cout << fixed << setprecision(10) << (atan2(a*b*b,2*x)*180.0)/pi << endl; 
  }
  return 0;
}

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

int main() {
  long N, P;
  string S;
  cin >> N >> P >> S;
  reverse(S.begin(), S.end());

  if (10 % P == 0) {
    long ans = 0;
    for (long i = 0; i < N; i++) {
      if ((S.at(i) - '0') % P == 0) ans += N - i;
    }
    return cout << ans << "\n", 0;
  }

  vector<long> V(P);
  long sum = 0;
  V.at(sum)++;
  for (long i = 0, dig = 1; i < N; i++, dig = dig * 10 % P) {
    sum += (S.at(i) - '0') * dig;
    sum %= P;
    V.at(sum)++;
  }
  long ans = 0;
  for (auto v : V) ans += v * (v - 1) / 2;
  cout << ans << "\n";
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    int min = 10010010;
    rep(i, n){
        if(p[i] > min){
            continue;
        }else{
            ans++;
        }
        if(min > p[i]){
            min = p[i];
        }
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4036
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

void swap(int &a, int &b){
  int tmp = a;
  a = b;
  b = tmp;
  return;
}

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n){
    int t;
    cin >> t;
    t--;
    p[i] = t;
  } 
  int ans = 0;
  for(int i = 0; i < n; ++i){
    if(p[i] == i){
      ans++;
      i++;
    }
  }
  cout << ans << endl;
}


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

int main() {
  // input
  int N;
  cin >> N;
  int A[110];
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  // sort desc
  sort(A, A + N, greater<int>());

  int a = 0;
  int b = 0;
  for(int i = 0; i < N; ++i) {
    if(i%2==0) a += A[i];
    else b += A[i];
  }

  cout << a - b << endl;

}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}

int f(ll now, int bit, int N) {
    if (now > N) return 0;
    int ret = bit == 7;
    ret += f(now * 10 + 3, bit | (1 << 0), N);
    ret += f(now * 10 + 5, bit | (1 << 1), N);
    ret += f(now * 10 + 7, bit | (1 << 2), N);
    return ret;
}

void solve() {
    int N;
    cin >> N;
    cout << f(0, 0, N) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  ll n; cin >> n;
  vector<ll> ans;
  rep(i, n) {
    ll a; cin >> a;
    a = -a;
    // ans 内で a を超える最小の値を a に変える。そのような数字がない場合は a を末尾に追加する
    auto itr = upper_bound(ALL(ans), a);
    if (itr == ans.end()) ans.push_back(a);
    else *itr = a;
  }

  cout << ans.size() << endl;

  return 0;
}


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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;



int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

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

    vector<int> v = { 1, 2, 3 };
    for (int x : v) {
        if (a != x && b != x)
            cout << x << endl;
    }

    return 0;
%>

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

typedef long long ll;
#define debug(x) cout << #x << ": " << (x) << endl
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define INF ((1 << 16)-1)
#define MOD (1000000007)
#define print(arr, n) REP(i, n) cout << arr[i] << " ";

int train_map[501][501];
int cumsum[501][501];

int main() {
//    std::ifstream in("../arg.txt");
//    std::cin.rdbuf(in.rdbuf());

    int N, M, Q;
    cin >> N >> M >> Q;

    int l, r;
    REP(i, M){
        cin >> l >> r;
        train_map[l][r] += 1;
    }

    REPN(i, 1, N+1){
        REPN(j, 1, N+1){
            cumsum[i][j] = train_map[i][j] + cumsum[i][j - 1] + cumsum[i - 1][j] - cumsum[i - 1][j - 1];
        }
    }

    int p, q;
    REP(i, Q){
        cin >> p >> q;
        cout << (cumsum[q][q] - cumsum[p-1][q]) << endl;

    }

    return 0;
}




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

#define rep(i, j) for(int i=0; i < (int)(j); i++)
template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

const int INF = 1 << 30;

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

enum block {
    EMPTY = 0,
    OBSTACLE,
    START,
    GOAL
};

class Solver {
  public:
    int H, W;
    tuple<int, int> go(int y, int x, vector<vector<int>> &G, int dir) {
        bool moved = false;
        while(true) {
            int ny = y + dy[dir], nx = x + dx[dir];
            if(ny < 0 or H <= ny or nx < 0 or W <= nx) return make_tuple(ny, nx);
            if(G[ny][nx] == GOAL) return make_tuple(ny, nx);
            if(G[ny][nx] == OBSTACLE) {
                if(not moved) return make_tuple(-1, -1); // (y, x)?????£????????§????????????                
                G[ny][nx] = EMPTY;
                return make_tuple(y, x);
            }            
            y = ny;
            x = nx;
            moved = true;
        }
    }
    int dfs(int y, int x, vector<vector<int>> G, int depth) {
        if(depth > 10) return INF;
        int res = INF;
        rep(dir, 4) {
            int ny, nx;
            auto GG = G;
            tie(ny, nx) = go(y, x, GG, dir);
            if(ny < 0 or H <= ny or nx < 0 or W <= nx) continue;
            if(GG[ny][nx] == GOAL) return depth;
            set_min(res, dfs(ny, nx, GG, depth + 1));
        }
        return res;
    }
    
    bool solve() {
        cin >> W >> H;
        if(not W and not H) return false;
        vector<vector<int>> G(H, vector<int>(W));
        rep(i, H) cin >> G[i];

        int x, y;
        rep(yy, H) rep(xx, W) if(G[yy][xx] == START) {
            y = yy;
            x = xx;
            break;
        }

        int ans = dfs(y, x, G, 1);
        cout << (ans == INF ? -1 : ans) << endl;
        
        return true;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        Solver s;
        if(not s.solve()) break;
    }
    return 0;
}

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

using namespace std;

int h,w,n;
int num[100010];
int MAP[110][110];
int x,y,d;

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

int main(){
	memset(MAP,0,sizeof(MAP));
	d = 0;
	scanf("%d %d %d",&h,&w,&n);
	for(int i=1;i<=n;i++)
		scanf("%d",num+i);
	x = y = 1;
	int cnt = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=num[i];j++){
			MAP[x][y] = i;
			if(++cnt == w*h)
				break;
			while(x+dir[d][0] > h 
				|| y+dir[d][1] > w 
				|| y+dir[d][1] <= 0 
				|| x+dir[d][0] <= 0
				|| MAP[x+dir[d][0]][y+dir[d][1]])
				d++,
				d%=4;
			x += dir[d][0];
			y += dir[d][1];
		}
	}
	for(int i=1;i<=h;i++,printf("\n")){
		printf("%d",MAP[i][1]);
		for(int j=2;j<=w;j++)
			printf(" %d",MAP[i][j]);
	}
	
	return 0;
}

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

bool mon(int x) {
  if(x<01) return false;
  if(x>12) return false;
  else return true;
}

int main() {
  int n, m;
  scanf("%02d%02d", &n, &m);
  if(mon(n)&&mon(m)) cout << "AMBIGUOUS";
  else if(mon(n)) cout << "MMYY";
  else if(mon(m)) cout << "YYMM";
  else cout << "NA";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
_ = int(input())
c = input()

count = 0
if "W" in c and "R" in c:
  left_w = c.find("W")
  right_r = c.rfind("R")
  while left_w < right_r:
    c = c[:left_w] + "R" + c[left_w+1:right_r] + "W" + c[right_r+1:]
    count += 1
    left_w = c.find("W")
    right_r = c.rfind("R")
print(count)

Measured memory_bytes: 9872
def main():
    N = int(input())
    T = list(map(int, input().split()))
    V = list(map(int, input().split())) + [0]

    CT = [0 for x in range(N+1)]  # cumulative time
    M = [float('inf') for x in range(len(T))]

    count = 0
    ct = 0
    for t, v in zip(T, V[:N]):
        CT[count] = ct
        ct += t
        count += 1
    CT[N] = ct

    for n in range(N):
        for i in range(n+1):
            M[i] = min(M[i], V[n+1] + (CT[n+1] - CT[i]))


    now = 0
    S = 0
    for q in range(len(T)):
        future = M[q]
        restriction = V[q]
        for s in range(T[q]*2):
            future -= 0.5
            pnow = now
            now = min(min(future, restriction), now + 0.5)
            S += (now + pnow)/4

    print(S)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

#define MAX 100000
#define NIL -1 

struct Node{int p, l, r; };

struct Node T[MAX];
int n, D[MAX];

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p == NIL)printf("root, ");
  else if (T[u].l == NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i==0)printf("%d",c);
    else printf(", %d",c);
  }

  printf("]\n");
}

int rec(int u, int p){
  D[u] = p;
  if(T[u].r != NIL)rec(T[u].r,p);
  if(T[u].l != NIL)rec(T[u].l,p+1);
}

int main(){
  int i, j, d, v, c, l, r;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;

  for(i=0;i<n;i++){
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p == NIL)r = i;
  }

  rec(r,0);
  
 for(i=0;i<n;i++)print(i);

 return 0;
}





Measured memory_bytes: 6468
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  string S,T; cin>>S>>T;
  ll N=S.size();
  map<char,char> mp,rmp;
  
  rep(i,N){
    if(!mp.count(S[i])) mp[S[i]]=T[i];
    else if(mp[S[i]]!=T[i]) {cout<<"No"<<endl; return 0;}
    if(!rmp.count(T[i])) rmp[T[i]]=S[i];
    else if(rmp[T[i]]!=S[i]) {cout<<"No"<<endl; return 0;}
  }
  
  cout<<"Yes"<<endl;
  
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

int h, w;
char s[51][51];

bool dfs() {
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') {
				bool f = false;
				for (int k = 0; k < 4; k++) {
					int nx = i + dx[k];
					int ny = j + dy[k];
					if (!(0 <= nx && nx < h)) continue;
					if (!(0 <= ny && ny < w)) continue;
					if (s[nx][ny] == '#') {
						f = true;
					}
				}
				if (!f) return false;
			}
		}
	}
	return true;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	cin >> h >> w;
	rep(i, h) rep(j, w) {
		cin >> s[i][j];
	}

	if (dfs()) {
		out("Yes");
	}
	else {
		out("No");
	}

	return 0;
}

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

typedef long long ll;

ll dp[1001][1001];
ll m = 1000000007;
char a[1001][1001];
int H, W;

int main()
{
    dp[1][0] = 1LL;
    scanf("%d %d", &H, &W);
    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            char tmp;
            scanf(" %c", &tmp);
            a[i][j] = tmp;
            if (tmp == '.')
            {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % m;
            }
        }
    }
    printf("%lld\n", dp[H][W]);
    return 0;
}


Measured memory_bytes: 9088
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a >= 10 | b >= 10) {
        		System.out.println(-1);
        } else {
        		System.out.println(a*b);
        }
    }
}

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

using namespace std;

const int N = 1e5 + 5;
int n, a[N][3], dp[N][3];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 

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

	dp[1][0] = a[1][0];
	dp[1][1] = a[1][1];
	dp[1][2] = a[1][2];

	for(int i=2;i<=n;++i)
		for(int j=0;j<3;++j){
			int val = 0;

			for(int k=0;k<3;++k)if(k != j)
				val = max(val, dp[i - 1][k] + a[i][j]);
			dp[i][j] = val;
		}

	int ans = max(dp[n][0], dp[n][1]);
	ans = max(ans, dp[n][2]);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <string>

#define pb push_back
#define ll long long
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define mp make_pair
using namespace std;


#include <iostream>
using namespace std;

char c[200200];
string s;
stack <char> st, st2;


int main(){

	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);


	scanf("%s", c);
	s = c;

	for(int i=0; i<s.size(); i++){
		if(st.empty()) st.push(s[i]);
		else{
			if(st.top() == 'S' && s[i] == 'T'){
				st2.push(s[i]);
				st.pop();
			}
			else{
				st.push(s[i]);
			}
		}
	}

	printf("%d\n", st.size());
	// fclose(stdin);
	// fclose(stdout);
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>

int main(){
  int i, j, k, N, key;
  int A[100];
  
  scanf("%d",&N);
  if(N < 1 || N > 100){
    fprintf(stderr,"Please enter the number of elements in the range from 1 to 100.(1st line)\n");
    exit(1);
  }
    
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
    
    if(A[i] < 0 || A[i] > 1000){
      fprintf(stderr,"Please enter the element in the range from 0 to 1000. (2nd line :%d)\n",i+1);
      exit(2);
    }
  }

  for(k = 0; k < N-1; k++){
      printf("%d ",A[k]); 
    }
    printf("%d\n",A[k]);
    
  for(i = 1; i < N; i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;

    for(k = 0; k < N-1; k++){
      printf("%d ",A[k]); 
    }
    printf("%d\n",A[k]);

  }

  return 0;
}




Measured memory_bytes: 2140
//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
using ld = long double;
 
const ll inf = 1e18;
const int N = 3 * 1e2 + 10;

ll res;
ll a[N], h[5];

ld dp[N][N][N];

void solve(){
    ll n, x;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> x;
        ++h[x];
    }
    for(int k = 0; k < N; ++k){
        for(int j = 0; j < N; ++j){
            for(int i = 0; i < N; ++i){
                if(i + j + k == 0 or i + j + k > n) continue;
                ld ws = 1.0 * (n - i - j - k) / n;
                ld pi = 1.0 * i / n;
                ld pj = 1.0 * j / n;
                ld pk = 1.0 * k / n;
                dp[i][j][k] = 1;
                if(i)   dp[i][j][k] += pi * dp[i - 1][j][k];
                if(j)   dp[i][j][k] += pj * dp[i + 1][j - 1][k];
                if(k)   dp[i][j][k] += pk * dp[i][j + 1][k - 1];
                dp[i][j][k] = dp[i][j][k] / (1 - ws);   
            }
        }
    }
    cout << fixed << setprecision(10) << dp[h[1]][h[2]][h[3]];
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro

Measured memory_bytes: 450816
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000
#define LLINF 100000000000000
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define VSORT(v) sort(v.begin(), v.end());
#define fi first
#define se second
#define out(x) cout << x << endl;
int dx[] = {1, 0, -1, 0}, dy[] = { 0,1,0,-1 };
ll MOD = 1000000007;
struct edge {
	ll from, to, cost;
};

long long dp[1000005]={0};

int main() {
	long long h;
    cin>>h;
    long long now = 1;
    long long cnt =1;
    if(h==1){
        cout<<"1"<<endl;
        return 0;
    }
    while(true){
        now=now*2+1;
        cnt = cnt*2+1;
        if(now>=h) break;
    }
    cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
using namespace std;
long long int a[100002];
int main()
 {
	long long int n,i,j,k,l=1,m=0;
	string s;
	cin>>n;   
	for(i=0;i<n;i++)
	   {
	       cin>>a[i];
	   }
	for(i=0;i<n;i++)
	   {
	       if(a[i]==i+1)
	         {
	             k=a[i];
	             a[i]=a[i+1];
	             a[i+1]=k;
	             m++;
	         }
	   }
	cout<<m;   
	return 0;
}

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

int main()
{
  int H,W;
  
  while(1)
  {
    cin >> H >> W;
    if(H==0&&W==0)
      break;
    
    for(int a=1;a<=H;a++)
    {
      for(int b=1;b<=W;b++)
      {
        cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3020
#include <iostream>
#include <string>
#include <set>

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

	std::set<std::string> s;
	for(int i = 0; i < n; ++i){
		std::string temp;
		std::cin >> temp;
		s.insert(temp);
	}

	std::cout << s.size() << std::endl;
	
	return 0;
}


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

int main(){
  int n; cin>>n;
  vector<int> h(n);
  for (int i=0; i<n; i++) cin>>h[i];
  
  int max_h=0;
  bool ans=true;
  for (int j=0; j<n; j++){
    if (max_h>=h[j]+2) ans=false;
    max_h=max(max_h,h[j]);
  }
  cout<<(ans ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 640
from collections import defaultdict


N,P = map(int, input().split())

if N == 1:
    print(P)
    exit()

d = defaultdict(int)


num = 2

while num * num <= P:
    while P % num == 0:
        d[num] += 1
        P //= num
    num += 1

ans = 1
for k in d.keys():
    ans *= pow(k, d[k] // N)

print(ans)


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

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> p(n,0);
	for(size_t i = 0; i<k; i++)
	{
		int d;
		cin>>d;
		for(size_t ii = 0; ii<d; ii++)
		{
			int a;
			cin>>a;
			p[a-1] = i+1;
		}
	}
	int ans = n;
	for(size_t i = 0; i<n; i++)
	{
		if(p[i]!=0)
		{
			ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
n = int(input())
a = list(map(int,input().split()))

x=0
y=0
a.sort()
i=len(a)-1
while (i>0):
  if a[i-1]==a[i]:
    x=y
    y=a[i]
    i-=2
  else:
    i-=1
  if x>0:
    break

print(x*y)


Measured memory_bytes: 14252
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let l: String = read();
    let bits: Vec<bool> = l.chars().map(|c| c == '1').collect();
    let ln = bits.len();

    let mut pows: Vec<u64> = vec![1; ln];
    for i in 1..ln {
        pows[i] = (3 * pows[i - 1]) % 1000000007;
    }

    let mut tmp = 1;
    for i in 0..ln {
        if bits[ln - 1 - i] {
            tmp = (2 * tmp + pows[i]) % 1000000007;
        }
    }

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


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
int main (void){
    char *S[1];
    char *s1 = "Sunny";
    char *s2 = "Rainy";
    char *s3 = "Cloudy";
    scanf("%s",S);

    if(strcmp(S,s1)== 0){
        printf("Cloudy\n");
    }else if(strcmp(S,s2)==0){
        printf("Sunny\n");
    }else if(strcmp(S,s3)==0){
        printf("Rainy\n");
    }
    return 0;
}


Measured memory_bytes: 128
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- readLn
  ws <- replicateM n $ fmap words getLine
  putStrLn $ unwords $ map (show . sum) $ transpose $ map judge ws
    where judge [a, b] | a > b = [3, 0]
                       | a < b = [0, 3]
                       | otherwise = [1, 1]

Measured memory_bytes: 4256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;

#define io(F) string t_="";ifstream fin(t_+F+".in");ofstreamfout(t_+F+".out")
#define qio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define graph unordered_map<int, unordered_set<int>>
typedef long long ll;

int main() {
	qio; string s; cin >> s;
	if(count(s.begin(), s.end(), '7')) println("Yes");
	else println("No");
}


Measured memory_bytes: 3660
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include<bitset>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

const int MAX_YEAR=7368791;

int Solve(int m,int n){
  std::bitset<MAX_YEAR+10> will_flourish(0);
  int itr=m;
  for(int i=0;i<n;i++){
    while(will_flourish[itr]){
      itr++;
    }
    int using_bamboo=itr;
    for(int y=using_bamboo;y<=MAX_YEAR;y+=using_bamboo){
      will_flourish[y]=true;
    }
  }
  while(will_flourish[itr]){
    itr++;
  }
  return itr;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  while(1){
    int m,n;
    cin>>m>>n;
    if(m==0&&n==0){
      break;
    }
    cout<<Solve(m,n)<<endl;
  }


  return 0;
}



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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,W=MI()
    N=I()
    a=LI()
    ans=[[0]*W for _ in range(H)]
    num=0
    
    for k in range(H*W):
        i=k//W
        j=k%W
        if i%2==1:
            j=W-1-j
        if a[num]==0:
            num+=1
        ans[i][j]=num+1
        a[num]-=1
        
    for i in range(H):
        print(' '.join(map(str, ans[i])))
            
        
        

main()


Measured memory_bytes: 40560
def main():
    N = int(input())
    A = list(map(int, input().split()))
    answer = True
    for a in A:
        if not a % 2:
            if a % 3 and a % 5:
                answer = False
                break
    print("APPROVED" if answer else "DENIED")


if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
std::vector<int> A['   '];
int N, M, S['   '], B, L, R, I;
void U(int z, int u) {
  while (z <= N)
    S[z] += u, z += z & -z;
}
main() {
  ~scanf("%d%d", &M, &N);
  for (; ~scanf("%d%d", &L, &R);)
    A[R - L + 1]
        .push_back(L);
  for (L = 1; L <= N; L++) {
    B = M;
    for (I = L; I <= N; I += L) {
      R = I;
      while (R)
        B += S[R], R -= R & -R;
    }
    for (int u : A[L])
      U(u, 1), U(u + L, -1), M--;
    printf("%d\n", B);
  }
}

Measured memory_bytes: 53760
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: String,
    }

    println!("{}", n.replace("1", "0").replace("9", "1").replace("0", "9"));
}


Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <iomanip>
#include <cstdlib>
#include <climits>
#include <set>
using namespace std;

//関数getinputdata宣言
vector<vector<string>> getinputdata();
vector<vector<int>> getinputdata2();
vector<vector<double>> getinputdata3();

void abc129_a(vector<vector<int>> v) {

   int p = v[0][0];
   int q = v[0][1];
   int r = v[0][2];
   
   int pq=p+q;
   int pr=p+r;
   int qr=q+r;
   
   cout << min(min(pq,pr),qr)<<endl;




}

int main() {

    //    vector<vector < string>> vec_arr_result;
    vector<vector<int>> vec_arr_result;
    vec_arr_result = getinputdata2();

    abc129_a(vec_arr_result);

    return 0;
}

//関数getinputdata実装

vector<vector<double>> getinputdata3() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<double>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<double> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atof(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;
}

//関数getinputdata実装

vector<vector<int>> getinputdata2() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector<int>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<int> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(atoi(ret.c_str()));
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;


}

//関数getinputdata実装

vector<vector < string >> getinputdata() {

    string str;
    string ret;
    stringstream ss;
    vector<string> v1;
    vector<vector < string>> vec_arr;

    //標準入力から入力がある間ループ処理でvector配列にデータ格納
    while (getline(cin, str)) {

        v1.push_back(str);

    }

    //stringstreamを利用してvector配列v1をスペースで分解処理
    for (string s : v1) {

        vector<string> array_data;
        ss << s;

        while (!ss.eof()) {

            ss >> ret;

            array_data.push_back(ret);
        }

        //vector配列に追加
        vec_arr.push_back(array_data);

        //バッファクリア
        ss.str("");
        //ストリームクリア
        ss.clear(stringstream::goodbit);

    }

    return vec_arr;

}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> digs; 
  int difs = 0;
  string ans = "Yes";
 
  while (N) {
    digs.push_back(N % 10);
    N /= 10;
  }
  
  if (digs[0] != digs[1]) {
    if (digs[1] == digs[2] && digs[2] == digs[3]) ans = "Yes";
    else ans = "No";
  } else if (digs[2] != digs[3]) {
    if (digs[0] == digs[1] && digs[1] == digs[2]) ans = "Yes";
    else ans = "No";
  } else {
    if (digs[1] == digs[2]) ans = "Yes";
    else ans = "No";
  }
  
  cout << ans << endl;
}


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

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

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


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

	vector<string> ans(h, string(w, '0'));

	REP(i, h)
		REP(j, w)
		if ((i < b) == (j < a))
			ans[i][j] = '1';

	REP(i, h)
		cout << ans[i] << endl;
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main() {
    // string str;
    char str;
    // cin >> str;
    int Alpha[26] = {0};
    while((str = getchar()) != EOF) {
        // for(int i = 0; i < str.length(); i++) {
        // if(str[i] >= 'A' && str[i] <= 'Z') {
        //     Alpha[str[i]-'A']++;
        // }
        // if(str[i] >= 'a' && str[i] <= 'z') {
        //     Alpha[str[i]-'a']++;
        // }
        // }
        if(str >= 'A' && str <= 'Z') Alpha[str-'A']++;
        if(str >= 'a' && str <= 'z') Alpha[str - 'a']++;
    }
    char alpha = 'a';
    for(int i = 0; i < 26; i++) {
        cout << alpha << " : " << Alpha[i] << endl;
        alpha++;
    }
    // getline(cin, str);
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=308;
const int mod=1e9+7;
const int inf=0x7fffffff;
int n;
LL mp[maxn][maxn];
bool flag[maxn][maxn];
int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
            scanf("%lld",&mp[i][j]);
    bool ans=true;
    LL sum=0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            for(int k=1; k<=n; k++)
            {
                if(mp[j][k]>mp[j][i]+mp[i][k])ans=false;
                if(mp[j][i]!=0&&mp[i][k]!=0&&j!=k&&mp[j][k]==mp[j][i]+mp[i][k])
                    flag[j][k]=true;
            }
        }
    }
    if(!ans)
    {
        printf("-1\n");
        return 0;
    }
    for(int i=1; i<=n; i++)
        for(int j=1; j<i; j++)
            if(!flag[i][j]) sum+=mp[i][j];
    printf("%lld\n",sum);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;


int main()
{
    FAST
    ll l,r,d;cin>>l>>r>>d;
    ll ans=0;
    f(i,l,r+1) if(i%d==0) ans++;
    cout<<ans;
}


Measured memory_bytes: 3580
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class DKThK {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<int> ans(n*n, -1);
      vector<P> vec;
      rep(i, n) {
        int x; cin >> x;
        x--;
        vec.emplace_back(x, i+1);
        ans[x] = i+1;
      }
      sort(all(vec));

      int now = 0;
      rep(i, n) {
        int p = vec[i].first;
        int q = vec[i].second;
        int loop = q-1;
        while(loop--) {
          while(now < n*n && ans[now] != -1) {
            now++;
          }
          if (now >= p) {
            cout << "No" << endl;
            return;
          }
          ans[now] = q;
          now++;
        }
      }

      reverse(all(vec));
      now = n*n-1;
      rep(i, n) {
        int p = vec[i].first;
        int q = vec[i].second;
        int loop = n-q;
        while(loop--) {
          while(now >= 0 && ans[now] != -1) {
            now--;
          }
          if (now <= p) {
            cout << "No" << endl;
            return;
          }
          ans[now] = q;
          now--;
        }
      }

      cout << "Yes" << endl;
      rep(i, n*n) {
        cout << ans[i] << ' ';
      }
      cout << endl;

    }
};

signed main() {
  DKThK solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

void solve_abc152() {
	ll n;
	cin >> n;

	ll ans = 0;

	ll sento, matsubi;
	ll map[11][11] = { {0} };
	rep(i, n) {
		sento = (i+1) / pow(10, (ll)log10(i+1));
		matsubi = (i + 1) % 10;
		map[sento][matsubi]++;
	}

	rep(i, 10) {
		rep(j, 10) {
			ans += map[i][j] * map[j][i];
		}
	}

	cout << ans << "\n";
}

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

	solve_abc152();

	return 0;
}

Measured memory_bytes: 256
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	ll l,r,d;cin>>l>>r>>d;
	ll cnt=0;
	rep(i,l,r+1) cnt+=(i%d==0);
	cout<<cnt<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 3648
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl toInt >>= print

solve :: Int -> Int
solve n = n * (n+1) `div` 2

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine


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

typedef pair<int, int> P;

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

	vector<P> f(N);
	vector<P> s(N);

	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		f[i].first = b;
		f[i].second = a;
	}

	for (int i = 0; i < N; i++) {
		int c, d;
		cin >> c >> d;
		s[i].first = c;
		s[i].second = d;
	}
	
    sort(f.begin(),f.end());
    sort(s.begin(),s.end());

	int count = 0;
	for (int i = 0; i < N; i++) {
		for (int j = f.size()-1; j >=0; j--) {
			if (s[i].first >= f[j].second && s[i].second >= f[j].first) {
				count++;
				f.erase(f.begin() + j);
				break;
			}
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256