akhauriyash/Code-Regression huggingface dataset:
from collections import deque
class Dinic:
    """Dinic Algorithm: find max-flow
       complexity: O(EV^2)
    """
    class edge:
        def __init__(self, to, cap, rev):
            self.to, self.cap, self.rev = to, cap, rev

    def __init__(self, V, E, source, sink):
        """ V: the number of vertexes
            E: adjacency list
            source: start point
            sink: goal point
        """
        self.V = V
        self.E = [[] for _ in range(V)]
        for fr in range(V):
            for to, cap in E[fr]:
                self.E[fr].append(self.edge(to, cap, len(self.E[to])))
                self.E[to].append(self.edge(fr, 0, len(self.E[fr])-1))
        self.maxflow = self.dinic(source, sink)

    def dinic(self, source, sink):
        """find max-flow"""
        INF = float('inf')
        maxflow = 0
        while True:
            self.bfs(source)
            if self.level[sink] == -1:
                return maxflow
            self.itr = [0] * self.V
            while True:
                flow = self.dfs(source, sink, INF)
                if flow > 0:
                    maxflow += flow
                else:
                    break            

    def dfs(self, vertex, sink, flow):
        """find augmenting path"""
        if vertex == sink:
            return flow
        for i in range(self.itr[vertex], len(self.E[vertex])):
            self.itr[vertex] = i
            e = self.E[vertex][i]
            if e.cap > 0 and self.level[vertex] < self.level[e.to]:
                d = self.dfs(e.to, sink, min(flow, e.cap))
                if d > 0:
                    e.cap -= d
                    self.E[e.to][e.rev].cap += d
                    return d
        return 0

    def bfs(self, start):
        """find shortest path from start"""
        que = deque()
        self.level = [-1] * self.V
        que.append(start)
        self.level[start] = 0
        
        while que:
            fr = que.popleft()
            for e in self.E[fr]:
                if e.cap > 0 and self.level[e.to] == -1:
                    self.level[e.to] = self.level[fr] + 1
                    que.append(e.to)        

V, E = map(int, input().split())
edge = [[] for _ in range(V)]
for _ in range(E):
    u, v, cap = map(int, input().split())
    edge[u].append((v, cap))
print(Dinic(V, edge, 0, V-1).maxflow)

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

using namespace std;

int main(void){

    int n;

    cin >> n;

    vector<pair<int, int>> stu(n);

    for(int i = 0;i < n;i++){
        int a;
        cin >> a;
        stu[i] = make_pair(a, i+1);
    }

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

    for(int i = 0;i < n;i++){
        cout << stu[i].second << " ";
    }
    cout << endl;

    return 0;
}

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

int main() {

  int H, W;
  cin >> H >> W;

  vector<vector<string>> answer(H, vector<string>(W));

  for (int i = 0; i < H; i++) {
    string S;
    cin >> S;
    for (int j = 0; j < W; j++) {
      answer[i][j] = S[j];
    }
  }

  vector<int> dx = {1, 0, -1, 0, 1, -1, -1, 1};
  vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1};

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (answer[i][j] == ".") {
        int count = 0;
        for (int d = 0; d < 8; d++) {
          int i_ = i + dy[d];
          int j_ = j + dx[d];
          if (i_ < 0 || H <= i_) {
            continue;
          }
          if (j_ < 0 || W <= j_) {
            continue;
          }
          if (answer[i_][j_] == "#") {
            count++;
          }
        }
        answer[i][j] = to_string(count);
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << answer[i][j];
    }
    cout << endl;
  }

}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
    int X, A, B;

    scanf("%d %d %d", &X, &A, &B);
    // printf("%d %d %d", X, A, B);

    if(B<=A){
      printf("delicious\n");
    }else if(A+1<=B && A+X>=B){
      printf("safe\n");
    }else{
      printf("dangerous\n");
    }

    return 0;
}


Measured memory_bytes: 128
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

n,m = Ri()
ver     = [True]*(n+1)
h = Ri()
h = [0]+h
for i in range(m):
    a,b = Ri()
    if h[a] > h[b]:
        ver[b] = False
    elif h[a] < h[b]:
        ver[a] = False
    else:
        ver[a] = False
        ver[b] = False
cnt=  0
for i in range(1,n+1):
    if ver[i] == True:
        cnt+=1
print(cnt)

Measured memory_bytes: 85232
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
  int i,ans=0;
  string s,t="CODEFESTIVAL2016";
  cin >> s;
  for (i=0;i<16;i++) if (s[i]!=t[i]) ans++;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i > b; i--)
#define repll(i, a, b) for (ll i = a; i < b; i++)

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

  int n;
  cin >> n;

  int h = (int)n / 100;
  int t = (int)(n - 100 * h) / 10;
  int o = (int)(n - 100 * h - 10 * t);

  if (h == 7 || t == 7 || o == 7)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


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

int main() {
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(n,k);
    rep(i,q){
        int idx = 0;
        cin >> idx;
        a[idx-1] ++;
    }
    rep(i,n){
        a[i] -= q;
        if(a[i]>0)printf("Yes\n");
        else printf("No\n");
    }

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000100

int main(){
	
	int N;
	cin>>N;
	
	vector<int> D(N);
	for(int i=0;i<N;i++){
		cin>>D[i];
	}
	
	if(D[0]!=0){
		cout<<0<<endl;
		return 0;
	}
	
	sort(D.begin(),D.end());
	if(D.size()>1&&D[1]==0){
		cout<<0<<endl;
		return 0;
	}
	
	map<int,int> mp;
	for(int i=0;i<N;i++){
		mp[D[i]]++;
	}
	
	int ans = 1;
	
	for(int i=1;i<=N;i++){
		for(int j=0;j<mp[i];j++){
			ans = mod(ans * mp[i-1]);
		}
	}
	
	cout<<ans<<endl;
	
    return 0;
}


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

int main(){
  int n; cin >> n;
  for (int i = 1; i <= n; i++){
    if ((int) (i * 1.08) == n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
import re
def isSet(r,l):
    while True:
        if not(l): return
        if l[0]==r:
            del l[0]
            return l
        elif l[0]=='(' or l[0]=='[':
            x = ')' if l[0]=='(' else ']'
            del l[0]
            l = isSet(x,l)
        else: return None
t = []
while True:
    s = input()
    if s=='.': break
    l = list(re.sub(r'[a-zA-Z. ]+','',s))
    while True:
        if not(l): break
        if l[0]==')' or l[0]==']':
            l = None
            break
        r = ')' if l[0]=='(' else ']'
        del l[0]
        l = isSet(r,l)
    print('yes' if l==[] else 'no')

Measured memory_bytes: 7636
class UnionFind:
    def __init__(self,N):
        self.par=[i for i in range(N+1)]
        self.rank=[0 for _ in range(N+1)]
    
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    
    def same_check(self,x,y):
        return self.find(x)==self.find(y)
    
    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

n,m=map(int,input().split())
s=list(map(int,input().split()))
l=UnionFind(n)
for i in range(m):
    x,y=map(int,input().split())
    l.union(x,y)
cnt=0
for i in range(n):
    if l.same_check(s[i],i+1):
        cnt+=1
print(cnt)

Measured memory_bytes: 13812
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;

int main()
{
    ll n;
    cin>>n;
    vector<ll> pref(n+1);
    vector<ll> a(n+1);
    vector<vector<ll> > dp(n+1,vector<ll> (n+1,0));
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        pref[i]=pref[i-1]+a[i];
    }
    for(ll i=0;i<=n;i++)
    {
        dp[i][i]=0;
    }
    for(ll i=n;i>=1;i--)
    {
        for(ll j=i+1;j<=n;j++)
        {
            dp[i][j]=min(dp[i+1][j],dp[i][j-1])+pref[j]-pref[i-1];
            for(ll k=i+1;k<j;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+pref[j]-pref[i-1]);
            }
           
        }
    }
    cout<<dp[1][n]<<endl;
}

Measured memory_bytes: 4900
import collections

q = collections.deque(range(1, 10))

K = int(input())

for i in range(K):
    x = q.popleft()
    if i + 1 == K:
        print(x)
        exit()
    if x % 10 != 0:
        q.append(x * 10 + x % 10 - 1)
    q.append(10 * x + x % 10)
    if x % 10 != 9:
        q.append(10 * x + x % 10 + 1)


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


int main() {

    ll n  ,i ;
    cin >> n ;
    vector<ll>v(n) , a(n) , b(n) ;
    for (i = 0 ; i< n ;i++) cin >> v[i] ;
    a= v ;
    sort(a.begin(),a.end()) ;
    map<ll,ll>pos1 ,pos2 ;
    for ( i = 0 ; i< n ; i++) {
        pos1[a[i]] = i%2 ;
        pos2[v[i]] = i%2 ;
    }

    ll ans = 0 ;
    for (i = 0 ; i< n ; i++) {
        if (pos1[v[i]]!=pos2[v[i]]) ans++ ;
    }
    cout << ans/2 << endl ;




    return 0 ;
}


Measured memory_bytes: 17152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
 
ll n, k, p[5050], c[5050], ans = -1e18;
vector<ll> v;
 
void dfs(int u, int k){
	v.push_back(u);
	if(p[u] == k) return;
	dfs(p[u], k);
}
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> k;
	for(int i=1;i<=n;i++) cin >> p[i];
	for(int i=1;i<=n;i++) cin >> c[i];
 
	for(int i=1;i<=n;i++){
		dfs(i, i);

		ll sum = 0;
 
		if(k >= v.size()){
			sum = 0;
			for(int j=0;j<v.size();j++) sum += c[v[j]] * (k / v.size());
			for(int j=0;j<k % v.size();j++){
				sum += c[v[j]];
				ans = max(ans, sum);
			}

			sum = 0;
			for(int j=0;j<v.size();j++) sum += c[v[j]] * (k / v.size() - 1);
			for(int j=0;j<v.size();j++){
				sum += c[v[j]];
				ans = max(ans, sum);
			}
		}
 
		sum = 0;
		for(int j=0;j<min(k, (long long)v.size());j++){
			sum += c[v[j]];
			ans = max(ans, sum);
		}
		v.clear();
	}
 
	cout << ans;
}

Measured memory_bytes: 4068
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int MAX_N = 10;

int v[MAX_N][MAX_N];

int my[] = {0, 1, 1, -1}, mx[] = {1, -1, 0, 1}, N, c = 1;

void solve(int y, int x, int d, int num, int pd, int pl, int len, int cnt){
  if(y >= N || x >= N || y < 0 || x < 0) return ;
  v[y][x] = num;
  if(N % 2 == 0 && y + 1 == N && x == 0){ pd = -1; len -= 2; pl = -1; d = 0; }
  if(N % 2 == 1 && y == 0 && x + 1 == N){ pd = -1; len -= 2; pl = -1; d = 2; }
  if(d == 0 || d == 2) solve(y + my[d], x + mx[d], (pd == 1 ? (d + pd) % 4 : (d + pd < 0 ? 3 : d + pd)), num + 1, pd, pl, len, 0);
  else solve(y + my[d], x + mx[d], (cnt >= len ? (pd == 1 ? (d + pd) % 4 : (d + pd < 0 ? 3 : d + pd)) : d), num + 1, pd, pl, (cnt >= len ? len + pl : len), (cnt >= len ? 0 : cnt + 1));
}

int main() {
  while(cin >>N && N){
    cout <<"Case " <<c++ <<":" <<endl;
    memset(v, 0, sizeof(v));
    solve(0, 0, 0, 1, 1, 1, 0, 0);
    REP(i, N){
      REP(j, N) printf("%3d", v[i][j]);
      cout <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,i,a[100000],b[100000],k,cnt;
int main(){
  for(cin>>n;i<n;i++)cin>>a[i];
  while(true){
    k=a[k]-1;cnt++;b[k]++;
    if(b[k]>1){
      cout<<-1<<endl;break;
    }
    if(k==1){
      cout<<cnt<<endl;break;
    }
  }
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#define  int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    vector<int> v(n+1,0);
    v[0]=2;
    v[1]=1;
    for(int i=2;i<=n;i++){
        v[i]=v[i-1]+v[i-2];
    }
    cout<<v[n]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x, sum=0, mx = 0;
	for(int i=0; i<n; i++)
	{
		cin>>x;
		sum += x;
		mx=max(x,mx);
	}
	int ans = sum - mx;
	if(ans>mx)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}


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

typedef long long ll;

int main(){
  ll N;cin >> N;
  vector<vector<ll>> F(N,vector<ll>(10));
  for(ll i = 0;i < N;i++){
    for(ll j = 0;j < 10;j++){
      cin >> F[i][j];
    }
  }
  vector<vector<ll>> P(N,vector<ll> (11));
  for(ll i = 0;i < N;i++){
    for(ll j = 0;j < 11;j++){
      cin >> P[i][j];
    }
  }
  ll ans = -2000000000000;
  for(int i = 1;i < (1 << 10);i++){
    ll res = 0;
    vector<bool> frag(10,0);
    bitset<10> S(i);
    for(int j = 0;j < 10;j++){
      if(S.test(j)){
        frag[j] = 1;
      }
    }
    vector<int> cnt(N);
    for(int j = 0;j < N;j++){
      for(int k = 0;k < 10;k++){
        if(F[j][k] == 1 && frag[k]){
          cnt[j]++;
        }
      }
    }
    for(int j = 0;j < N;j++){
      res += P[j][cnt[j]];
    }
    ans = max(res,ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
A=[[0]*m for i in range(n)]
for i in range(n):
  A[i]=list(map(int,input().split()))
B=[0]*m
for i in range(n):
  B[A[i][0]-1]+=1
a=0
b=0
for i in range(m):
  if B[i]>a:
    a=B[i]
    b=i
ans=a
C=[b+1]
i=0
while i<=m-2:
  B=[0]*m
  for j in range(n):
    for k in range(m):
      if A[j][k] not in C:
        B[A[j][k]-1]+=1
        break
  a=0
  b=0
  for l in range(m):
    if B[l]>a:
      a=B[l]
      b=l
  if ans>a:
    ans=a
  C.append(b+1)
  i=i+1
print(ans)

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

int solve(int n,int m){
    pair<int,int> s[10000];
    int ans=0;
    for(int i=0;i<n;i++){
        scanf("%d",&s[i].second);
        scanf("%d",&s[i].first);
        ans+=s[i].first*s[i].second;
    }
    sort(s,s+n);
    reverse(s,s+n);
    for(int i=0;i<n&&m>0;i++){
        if(m>s[i].second){
            ans-=s[i].first*s[i].second;
            m-=s[i].second;
        }else{
            ans-=s[i].first*m;
            m=0;
        }
    }
    return ans;
}

int main(){
    while(1){
        int n,m;
        scanf("%d %d",&n,&m);
        if(n==0&&m==0) return 0;
        printf("%d\n",solve(n,m));
    }
}

Measured memory_bytes: 1104
from collections import Counter
from itertools import product

from functools import reduce
import operator
int_product = lambda it: reduce(operator.mul,it,1)

# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n

def divisors(n):
    factors = prime_factors(n)
    factors = Counter(factors)
    pows = tuple(factors.values())
    factors = tuple(factors.keys())
    for pp in product(*(range(p+1) for p in pows)):
        yield int_product(f**p for f,p in zip(factors,pp))


N = int(input())
res = 0
for d in divisors(N):
    m = d-1
    if m > 0 and N//m == N%m:
        res += m

print(res)

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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    int N,A,B;
    cin >> N >> A >> B;
    
    if((B-A)%2 == 0){
        cout << "Alice" << endl;
    }else{
        cout << "Borys" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <queue>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
int const sigma = 16;
int v[1 + nmax];
int dp[1 + (1 << sigma)];

int _add(int &mask, int bit){
  if(bit == 0)
    return 0;
  int cost = 0;
  if(mask & (1 << bit))
    cost = 1;
  mask ^= (1 << bit);
  return cost;
}

vector<pair<int,int>> g[1 + (1 << sigma)];

void computedp(){
  for(int mask = 0; mask < (1 << sigma); mask += 2)
    for(int i = 1; i < sigma; i++)
      for(int j = i + 1; j < sigma; j++)
        if((mask & (1 << i)) && (mask & (1 << j)))
          for(int h = 1; h < sigma; h++){
            int mask2 = mask ^ (1 << i) ^ (1 << j);
            int cost = _add(mask2, i ^ h) + _add(mask2, j ^ h) + 1;
            g[mask2].push_back({mask, cost});
          }

  for(int mask = 0; mask < (1 << sigma); mask++)
    dp[mask] = nmax;
  dp[0] = 0;

  queue<int> q;
  q.push(0);

  while(0 < q.size()){
    int node = q.front();
    q.pop();
    for(int h = 0; h < g[node].size(); h++){
      int to = g[node][h].first;
      int cost = g[node][h].second;
      if(dp[node] + cost < dp[to]) {
        dp[to] = dp[node] + cost;
        q.push(to);
      }
    }
  }
}

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

  int n;
  cin >> n;
  for(int i = 1; i < n; i++){
    int x, y, cost;
    cin >> x >> y >> cost;
    ++x;
    ++y;
    v[x] ^= cost;
    v[y] ^= cost;
  }
  int mask = 0;
  int result = 0;

  for(int i = 1; i <= n; i++){
    if(v[i] == 0)
      continue;
    int bit = (1 << v[i]);
    if(mask & bit)
      result++;
    mask ^= bit;
  }
  computedp();

  cout << result + dp[mask];
  return 0;
}


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

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

  for(int i=0; i<N; i++){
    string S1, S2;
    cin >> S1 >> S2;
    int l1 = S1.length(), l2 = S2.length();

    string S; int carry = 0;
    for(int i=0; i<max(l1, l2)+1; i++){
      if(i < l1 && i < l2){
        int s1 = S1[l1-1-i] - '0', s2 = S2[l2-1-i] - '0';
        char a = (s1+s2+carry) % 10 + '0';
        S.push_back(a);
        if(s1+s2+carry >= 10) carry = 1;
        else carry = 0;
      } else if (i == max(l1, l2)){
        if(carry == 1) S.push_back('1');
      } else if (i >= l1){
        int s2 = S2[l2-1-i] - '0';
        char a = (s2+carry) % 10 + '0';
        S.push_back(a);
        if(s2+carry >= 10) carry = 1;
        else carry = 0;
      } else if(i >= l2){
        int s1 = S1[l1-1-i] - '0';
        char a = (s1+carry) % 10 + '0';
        S.push_back(a);
        if(s1+carry >= 10) carry = 1;
        else carry = 0;
      }
    }
    reverse(S.begin(), S.end());

    if(S.length()>80){
      cout << "overflow" << endl;
    } else {
      cout << S << endl;
    }
  }
}
  
  


Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
map<string,int>q;
int n,ans;
string s;
signed main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		if(q[s]==0)
		ans++;
		q[s]=1;
	}
	printf("%lld",ans);
	return 0;
}

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

int main() {

  while( true ) {

    char s;
    cin >> s;
    if ( s == '#' ) break;

    vector< vector< pair< long long int, char > > > v;

    for ( long long int p = 0; p < 4; p++ ) {
      vector< pair< long long int, char > > vp;
      for ( long long int t = 0; t < 13; t++ ) {

	string in;
	cin >> in;

	long long int k = in[0] - '0';
	if ( in[0] == 'A' ) {
	  k = 14;
	}else if ( in[0] == 'K' ) {
	  k = 13;
	}else if ( in[0] == 'Q' ) {
	  k = 12;
	}else if ( in[0] == 'J' ) {
	  k = 11;
	}else if ( in[0] == 'T' ) {
	  k = 10;
	}

	vp.push_back( make_pair( k, in[1] ) );

      }
      v.push_back( vp );
    }

    long long int cnt = 0;
    long long int k = 0;

    for ( long long int t = 0; t < 13; t++ ) {

      char suit = v[k][t].second;
      for ( long long int i = 0; i < 4; i++ ) {
	if ( v[i][t].second == s ) suit = s;
      }
      long long int win = -1;
      long long int max_num = -1;
      for ( long long int i = 0; i < 4; i++ ) {
	if ( v[i][t].second == suit && v[i][t].first > max_num ) {
	  win = i;
	  max_num = v[i][t].first;
	}
      }

      if ( win == 0 || win == 2 ) cnt++;
      k = win;

    }

    if ( cnt > 6 ) {
      cout << "NS " << cnt - 6 << endl;
    }else {
      cout << "EW " << 7 - cnt << endl;
    }

  }

  return 0;

}

Measured memory_bytes: 1196
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    size_t n = s.size();
    size_t m = t.size();
    int flag = -1;
    for (size_t i = 0; i < min(n, m); ++i) {
        if (s[i] > t[i]) {
            flag = 0;
            break;
        }
        else if (s[i] < t[i]) {
            flag = 1;
            break;
        }
    }
    if (flag == -1) flag = (n < m);
    cout << (flag ? "Yes" : "No") << endl;

    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> lo = new ArrayList<Integer>();
        
        for (int i = 0; i < N; i++) {
            int t = sc.nextInt();
            list.add( t);
            lo.add( t);
        }
        Collections.sort(list);
        int max = list.get(N-1);
        int smax = -1;
        boolean fl_dmax = false;
        if(list.get(N-2) == max)    fl_dmax = true;
        for(int i=list.size()-1; i>=0; i--) {
            if(list.get(i) < max) {
                smax = list.get(i);
                break;
            }
        }

        for (int i = 0; i < lo.size(); i++) {
            if( lo.get(i) != max ) {
                System.out.println(max);
            }else{
                System.out.println( fl_dmax? max: smax );
            }
        }
    }
}


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

using namespace std;

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

#define ff first
#define ss second

const double PI = 3.141592653589;

const int maxn = 1e5+10;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a,b,h,m;
	cin >> a >> b >> h >> m;
	double rad = 2*PI*(h/12.0+(m/60.0/12.0)-m/60.0);
	double prod1 = (2*a*b*cos(rad));
	double ans = (a*a) + (b*b) - prod1;
	cout.precision(20);
	cout << fixed << sqrt(ans) << '\n';
	return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  int counter = 0;
  for (int i = 0; i < N; i++) {
    if(vec.at(i)>=K)
      counter++;
  }
  
  cout << counter <<endl;

}


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

    int ans = 0;
    FOR(i, 1, N + 1)
    {
        if (to_string(i).size() % 2 == 1) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ful = sum(B)

for i in range(N-1):
  if (A[i+1]-A[i]) == 1:
    ful += C[A[i]-1]

print(ful)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
const ll inf = 1e18;
int main(){
    int n,m,r; cin >> n >> m >> r;
    vector<int> t(r);
    rep(i,r) {
        cin >> t[i];
        t[i]--;
    }    
    vector<ll> a(m),b(m),c(m);
    vector<vector<ll>> d(n, vector<ll> (n, inf));
    rep(i,m){
        ll a,b,c; cin >> a >> b >> c;
        a--; b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(d[i][k] == inf || d[k][j] == inf) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    ll ans = inf;
    ll tmp = 0;
    vector<int> v(r);
    iota(ALL(v), 0);
    do{
        tmp = 0;
        FOR(i,1,r) tmp += d[t[v[i-1]]][t[v[i]]];
        ans = min(ans, tmp);
    } while(next_permutation(ALL(v)));
    cout << ans << endl;
}

Measured memory_bytes: 1024
l,r=map(int,input().split())
if r-l>=2019 :
    print(0)
else:
    min=float("INF")
    for i in range(r-l):
        for j in range(i+1,r-l+1):
            if (l+i)*(l+j)%2019<min:
                min=(l+i)*(l+j)%2019
    print(min)


Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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


Measured memory_bytes: 256
n,m,v,p=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A,reverse=True)
B=[0]
for i in range(n):
  B.append(B[-1]+A[i])
#print(B)
ok = -1
ng = n
if p>=1:
  while ng-ok > 1:
    mid = (ok+ng) // 2 # 平均(小数切り捨て)
    #print(mid)
    if mid<p:
      ok=mid
      #print(0)
    elif n-(mid+1)+p>=v:
      if A[p-1]<=A[mid]+m:
        ok=mid
        #print(1)
      else:
        ng=mid
        #print(2)
    else:
      if A[mid]+m>=A[p-1]:
        a=m*(v-n-p+mid+1)
        b=A[mid]+m
        q=p-1
        if (mid+1-p)*b-(B[mid]-B[q])>=a:
          ok=mid
          #print(3)
        else:
          ng=mid
          #print(4)
      else:
        ng=mid
        #print(5)
  print(ok+1)

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

#define GET_MACRO(a, b, c, d, NAME, ...) NAME
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REP2(i, a) REP3(i, 0, a)
#define REP3(i, a, b) REP4(i, a, b, 1)
#define REP4(i, a, b, s) for (int i = (a); i < (int)(b); i += (s))
#define REPR(...) GET_MACRO(__VA_ARGS__, REPR4, REPR3, REPR2)(__VA_ARGS__)
#define REPR2(i, a) REPR3(i, 0, a)
#define REPR3(i, a, b) REPR4(i, a, b, 1)
#define REPR4(i, a, b, s) for (int i = (b)-1; i >= (int)(a); i -= (s))
#define ALL(c) (c).begin(), (c).end()
#define DUMP(x) (std::cerr << #x << ':' << ' ' << x << '\n')
#define TMPL_T template <typename T>
#define TMPL_TU template <typename T, typename U>
#define mut auto
#define let const auto

using Int = long long;
// clang-format off
namespace extio {
std::string delimiter=" ",pdelimiter=" ";
std::string bracket_b="",bracket_e="";
void chdelim(const std::string&s){delimiter=s;}
void chpdelim(const std::string&s){pdelimiter=s;}
void chbracket(const std::string&b,const std::string&e){bracket_b=b,bracket_e=e;}
TMPL_T  void pcont(std::ostream&os,const T&x){int c=0;for(const auto&a:x){if(c++)os<<delimiter;os<<a;}}
TMPL_TU void ppair(std::ostream&os,const std::pair<T,U>&p){os<<bracket_b<<p.first<<pdelimiter<<p.second<<bracket_e;}
}
namespace std {
TMPL_T ostream& operator<<(ostream&os,const vector<T>&x){extio::pcont(os,x);return os;}
TMPL_T ostream& operator<<(ostream&os,const set<T>&x){extio::pcont(os,x);return os;}
TMPL_T ostream& operator<<(ostream&os,const multiset<T>&x){extio::pcont(os,x);return os;}
TMPL_T ostream& operator<<(ostream&os,const deque<T>&x){extio::pcont(os,x);return os;}
TMPL_TU ostream& operator<<(ostream&os,const map<T,U>&x){extio::pcont(os,x);return os;}
TMPL_TU ostream& operator<<(ostream&os,const pair<T,U>&x){extio::ppair(os,x);return os;}
}
TMPL_TU inline bool chmax(T&x,U a){return x<a&&(x=a,1);}
TMPL_TU inline bool chmin(T&x,U a){return a<x&&(x=a,1);}

inline int in(){int x;std::cin>>x;return x;}

struct Initializer_ {
  Initializer_(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(0);
    std::cout << std::setprecision(10);
    std::cerr << std::setprecision(10);
  }
} precalc;
// clang-format on
// }}}

using namespace std;

signed main() {
  int a, b;
  while (cin >> a >> b) {
    cout << to_string(a + b).size() << endl;
  }
  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x,h,w) (y) < 0 || (h) <= (y) || (x) < 0 || (w) <= (x)
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

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

    ll ans = a.back(), now = a.back();
    rFOR(i, 0, n - 1) {
        if (a[i] < now - 1) {
            cout << "-1\n";
            return 0;
        }
        else if (now - 1 < a[i]) {
            now = a[i];
            ans += a[i];
        }
        else {
            --now;
        }
    }
    if (0 < now) {
        cout << "-1\n";
        return 0;
    }
    cout << ans << "\n";
}


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

using namespace std;

const long double PI = acos(-1);

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long n;

    cin >> n;

    cout <<fixed << setprecision(12);

    cout << 2*PI*n << '\n';

    return 0;

}



Measured memory_bytes: 3808
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

template<class Len = int>
class Dijkstra {
 private:
  int n;
  std::vector<std::vector<std::pair<int, Len> > > edges;
 public:
  explicit Dijkstra(int n) : n(n), edges(n) {}

  void add_edge(int from, int to, Len cost) {
    edges[from].push_back(std::pair<int, Len>(to, cost));
  }

  std::vector<Len> solve(int source) {
    const Len inf = 1e16;
    typedef std::pair<Len, int> pi;
    std::vector<Len> d(n, inf);
    std::priority_queue<pi, std::vector<pi>, std::greater<pi> > que;
    que.push(pi(0, source));
    while (!que.empty()) {
      pi p = que.top();
      que.pop();
      int idx = p.second;
      if (d[idx] <= p.first) {
        continue;
      }
      d[idx] = p.first;
      for (int j = 0; j < edges[idx].size(); ++j) {
        que.push(pi(p.first + edges[idx][j].second, edges[idx][j].first));
      }
    }
    return d;
  }
};

void solve(istream &ccin = cin, ostream &ccout = cout) {

  ll n;
  ccin >> n;
  Dijkstra<ll> dij(n);
  rep(i, n - 1) {
    ll a, b, c;
    ccin >> a >> b >> c;
    --a;
    --b;
    dij.add_edge(a, b, c);
    dij.add_edge(b, a, c);
  }
  ll q, k;
  ccin >> q >> k;
  --k;
  vector<ll> v = dij.solve(k);
  rep(i, q) {
    ll x, y;
    ccin >> x >> y;
    --x;
    --y;
    ccout << v[x] + v[y] << endl;
  }

}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 11120
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int N,M;
    cin >> N >> M;
    int ans[N]={};
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--,y--;
        ans[x]++,ans[y]++;
    }
    rep(i,N) cout << ans[i] << endl;
}

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

using namespace std;
const int MAX=1e5;
int n,m,a,b,dp[MAX+2];
vector<int> adj[MAX+2];

int solve(int u){
if(dp[u]!=-1) return dp[u];
int ans=0;
for(int i=0;i<adj[u].size();i++){
    ans=max(ans,solve(adj[u][i])+1);
}
return dp[u]=ans;
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        adj[a].push_back(b);
    }
    int ans=0;
    memset(dp,-1,sizeof dp);
    for(int i=1;i<=n;i++){
        if(dp[i]==-1){
            ans=max(ans,solve(i));
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 8192
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;


#if 0

const int N = 200;

int main(void) {
  int k;
  cin >> k;
  VI dp(N);
  dp[0] = 0;
  REP(i, 1, N) {
    set<int> seen;
    REP(j, 1, (i / k) + 1) {
      seen.insert(dp[i - j]);
    }
    int mex = 0;
    while (seen.count(mex)) mex++;
    dp[i] = mex;
  }
  cerr << "nim[" << k << "]:";
  REP(i, 0, N) {
    cerr << " " << dp[i];
  }
  cerr << endl;
}

#else

ll g_two(ll a, ll k) {
  ll c = a / k;
  ll d = a % k;
  while (d != 0 && c != 0) {
    d %= c + 1;
    if (d == 0) return c;
    d -= c + 1;
    d += k;
    c -= 1;
  }
  return c;
}

ll g(ll a, ll k) {
  // DEBUGP(a);
  if (a % k == 0) {
    return a / k;
  }
  if (a < k) {
    return 0;
  }
  if (k >= 40000) {
    return g_two(a, k);
  }
  return g(a - a / k - 1, k);
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VL a(n), k(n);
  ll gru = 0;
  REP(i, 0, n) {
    cin >> a[i] >> k[i];
    ll val = g(a[i], k[i]);
    if (0) {
      DEBUGP(a[i]);
      DEBUGP(k[i]);
      DEBUGP(val);
    }
    gru ^= val;
  }
  cout << (gru == 0 ? "Aoki" : "Takahashi") << endl;
}

#endif


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

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

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

        vector<ll> a(n);
        rep (i, n) cin >> a[i];

        vector<int> o(n);
        iota(o.begin(), o.end(), 0);
        sort(o.begin(), o.end(), [&](int i, int j) { return a[i] > a[j]; });

        auto dp = make_v(n + 1, n + 1, 0LL);
        rep (s, n) rep (i, s + 1) {
                int j = s - i;
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[o[s]] * abs(o[s] - i));
                dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a[o[s]] * abs(o[s] - (n - 1 - j)));
        } 

        ll ans = 0LL;
        rep (i, n) ans = max(ans, dp[i][n - i]);

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 34676
#include <iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
const int maxN = 3005;
int dp[maxN][maxN];
pair<int, int> parent[maxN][maxN];
int main ()
{
    string s = "0", t = "1", y, x;
    cin >> y >> x;
    s += y;
    t += x;
    int n = y.length();
    int m = x.length();
    // dp[i][j] = maxmm subsequence so far
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            
            vector<int> listOptions;
            listOptions.push_back(dp[i - 1][j]);
            listOptions.push_back(dp[i][j - 1]);
            if (s[i] == t[j])
            {
                listOptions.push_back(dp[i - 1][j - 1] + 1);
            }
            else
            {
                listOptions.push_back(dp[i - 1][j - 1]);
            }
            
            auto it = max_element(listOptions.begin(), listOptions.end());
            dp[i][j] = *it;
            if (it - listOptions.begin() == 0)
            {
                parent[i][j] = make_pair(i - 1, j);
            }
            else if (it - listOptions.begin() == 1)
            {
                parent[i][j] = make_pair(i, j - 1);
            }
            else
            {
                parent[i][j] = make_pair(i - 1, j - 1);
            }
            
           
        }
    }
    // for (int i = 0; i <= n; ++i) {
    //     for (int j = 0; j <= m; ++j ) {
    //         cout << dp[i][j] << " \t";
    //     }
    //     cout << endl;
    // }

    // for (int i = 0; i <= n; ++i) {
    //     for (int j = 0; j <= m; ++j) {
    //         cout << parent[i][j].first << " " << parent[i][j].second << " \t";
    //     }
    //     cout << endl;
    // }
    int ans = dp[n][m];
    int inI = n, inJ = m;
    int inI1, inJ1;
    string q = "";
    while(inI != 0 || inJ != 0) 
    {
       inI1 = parent[inI][inJ].first;
       inJ1 = parent[inI][inJ].second;

       if (inI1 == inI - 1 && inJ1 == inJ - 1 && s[inI] == t[inJ])
       {
           q += s[inI];
       }

       inI = inI1;
       inJ = inJ1;
    }
    reverse(q.begin(), q.end());
    cout << q <<endl;
    return 0;
}

Measured memory_bytes: 109296
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/

struct UnionFind {
	vector<int> d; //iが子ならd[i]は親のidでiが親ならd[i]は -サイズ
	UnionFind(int n): d(n, -1) {}
	int find(int x) {
		if (d.at(x) < 0)return x;//親なら自分自身の番号を返す
		else return d.at(x) = find(d.at(x)); //経路圧縮　メモ化
	}
	bool unite(int x, int y) { //voidでもいいが、くっつけられるか判定できた方が嬉しいときもある
		x = find(x); y = find(y); //根同士をくっつけるため
		if (x == y) return false;//統合できない(しない)
		if (-d.at(x) < -d.at(y)) swap(x, y);
		d.at(x) += d.at(y); //親のサイズの更新 サイズが大きい方に小さい方を統合
		d.at(y) = x;//yは親ではなくなったのでyの親をｘに設定
		return true;//統合できた
	}
	int size(int x) {return -d.at(find(x));}
	bool same(int x, int y) {return find(x) == find(y);}
};

/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


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

	//UnionFind ufs('z' + 5), uft('z' + 5);

	UnionFind ufs(S.size()+5), uft(S.size()+5);

	vector<vector<int>> vs('z' + 5), vt('z' + 5);

	REP(i, S.size()) {vs[S[i]].push_back(i);}
	REP(i, S.size()) {vt[T[i]].push_back(i);}

	FOR(i, 'a', 'z') REP(j, vs[i].size()-1)  ufs.unite(vs[i][j], vs[i][j + 1]) ;

	FOR(i, 'a', 'z') REP(j, vt[i].size()-1)  uft.unite(vt[i][j], vt[i][j + 1]) ;

	bool ok=true;
	
	REP(i,S.size()){
		if(ufs.find(i)!=uft.find(i))ok=false;
	}

	YesNo(ok);







	return 0;
}


Measured memory_bytes: 7508
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i=0; i<n; i++) arr[i] = sc.nextInt();
        Arrays.sort(arr);

        int res = Integer.MAX_VALUE;

        for (int i=arr[0]; i<=arr[arr.length-1]; i++) {
            int tmp = 0;
            for (int j=0; j<arr.length; j++) {
                tmp += (int)Math.pow(i - arr[j], 2);
            }
            res = Math.min(res, tmp);
        }

        System.out.println(res);


    }

}



Measured memory_bytes: 22100
// HTTF.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define int LL
#define pb emplace_back
#define eb pb

using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 300;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
typedef pair<ld, ut> pld;

#define endl "\n" //インタラクティブでは消す
ut N, M, K, L, Q, D, H, W;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], maps2[SIZE2][SIZE2], answer = zero;
LL maps[SIZE2][SIZE2];
LL DP1[SIZE];
bool finished[SIZE2][SIZE2];
LL DP2[SIZE2][SIZE2];
LL DP3[SIZE3][SIZE3][SIZE3];
LL solve2(int h,int w) {
	if (h == 1 and w == 1) return 1;
	if (min(h, w) <= 0) return 0;
	if (maps[h][w]) return 0;
	if (finished[h][w]) return DP2[h][w];
	finished[h][w] = true;
	return DP2[h][w] = (solve2(h - 1, w) + solve2(h, w - 1))%p;
}
LL solve() {
	cin >> H >> W;
	REP(i, H) {
		string s;
		cin >> s;
		REP(j, s.size()) {
			maps[i+1][j+1] = s[j] == '#';
		}

	}
	cout << solve2(H, W)%p<<endl;
	return 0;
}




//!!!!!!!!!!!!!!!!!!!実装を詰める!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(0);
	solve();
	cin >> N;
	return 0;

}

Measured memory_bytes: 50944
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

W, H, x, y = l_inpl()

half = W * H / 2

if W == x*2 and H == y*2:
    ans = 1
else:
    ans = 0

print(half, ans)

Measured memory_bytes: 3700
import sys
import math

def input():
    return sys.stdin.readline().strip()

def main():
    k = int(input())
    sum = 0
    for a in range(k):
        for b in range(k):
            x = math.gcd(a+1,b+1)
            for c in range(k):
                y = math.gcd(x, c+1)
                sum += y
    print(sum)



main()

Measured memory_bytes: 9120
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

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


Measured memory_bytes: 256