akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef double ld;

int main()
{
	fastio
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, w;
	cin >> n >> w;

	vii arr(n);
	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;

		arr[i] = {a, b};
	}

	vector<vll> dp(n + 1, vll(w + 1, 0));

	for (int i = 1; i <= n; i++)
	{
		for (int wei = 1; wei <= w; wei++)
		{
			if (arr[i - 1].fi > wei)
			{
				dp[i][wei] = dp[i - 1][wei];
			}
			else
			{
				dp[i][wei] = max(
				                 arr[i - 1].se + dp[i - 1][wei - arr[i - 1].fi],
				                 dp[i - 1][wei]
				             );
			}
		}
	}

	cout << dp[n][w];

	return 0;

}

Measured memory_bytes: 82716
n=int(input())
d=[]

for i in range(n):
    tmp=[int(j) for j in input().split()]
    d.append(tmp)

ans=[[0]*n for i in range(n)]

for i in range(n):
    for j in range(i+1,n):
        ans[i][j]=d[i][j]

for i in range(n):
    for j in range(i+1,n):
        for k in range(n):
            if i==k or j==k:
                continue
            if d[i][j]>d[i][k]+d[k][j]:
                print(-1)
                exit()
            elif d[i][j]==d[i][k]+d[k][j]:
                ans[i][j]=0
res=0
for i in range(n):
    res+=sum(ans[i])
print(res)


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int M,K;

    Scd2(M,K);

    int m = M;
    int N = 1;
    while( m-- ) N <<= 1;

    if( K == 0 ){
        Rep(i,N){
            printf ("%d %d%c", i, i, (i==N-1) ? 10 : ' ' );
        }
    }else if( M >= 2 && K < N ){
        vector<int> ans(N*2,0);
        Rep(i,N){
            ans[i] = i + (i >= K);
        }
        ans[N-1] = 0;
        ans[N] = K;
        Rep(i,N-1){
            ans[N*2-1-i] = i + (i >= K);
        }
        ans[N*2-1] = K;
        Rep(i,N*2){
            printf ("%d%c", ans[i], i == N*2-1 ? 10 : ' ');
        }
    }else{
        printf ("%d\n", -1 );
    }

    return 0;
}



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

int main(void){
  int money = 100000, weeks;
  cin >> weeks;
  for(int i = 0; i < weeks; i++){
    money += (money / 100) * 5;
    int underTp = money % 1000;
    if(underTp != 0){
      money -= underTp;
      money += 1000;
    }
  }
  cout << money << endl; 
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
	
	public static int gcd(int x, int y) {
		
		if(y == 0) {
			
			return x;
			
		} else {
			
			return gcd(y, x%y);
			
		}
		
	}
	

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		int x = in.nextInt();
		int y = in.nextInt();
		
		int result = gcd(x, y);
		System.out.println(result);
		
		in.close();

	}

}


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

typedef long long ll;

int main(){
    int l, a;
    cin >> l;
    vector<ll> dp(5, 0);
    for(int i = 0; i < l; i++){
        cin >> a;
        vector<ll> next(5);
        next[0] = dp[0] + a;
        next[1] = min(dp[0],dp[1]) + a%2 + 2*(a==0);
        next[2] = min({dp[0], dp[1], dp[2]}) + (1-a%2);
        next[3] = min({dp[0], dp[1], dp[2], dp[3]}) + a%2 + 2*(a==0);
        next[4] = *min_element(dp.begin(), dp.end()) + a;
        dp = next;
    }
    cout << *min_element(dp.begin(), dp.end()) << endl;
    return 0;
}

Measured memory_bytes: 384
package main
import(
  "fmt"
)
func main(){
  var n, i int
  fmt.Scan(&n)
  a:=make([]int, n)
  b:=make([]int, n)
  for i=0;i<n;i++{
    fmt.Scan(&a[i])
  }
  for i=0;i<n;i++{
    fmt.Scan(&b[i])
  }
  ans:=0
  for i=0;i<n;i++{
    if a[i]>b[i]{
      ans+=a[i]-b[i]
    }
  }
fmt.Println(ans)
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a += b;
    if (a >= MOD)
        a -= MOD;
}

int mul(int a, int b) {
    return (long long) a * b % MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    int sum = 0, ret = 0;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        add(ret, mul(sum, a));
        add(sum, a);
    }
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <math.h>

int main()
{
    double x1, y1, x2, y2;
    scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);

    printf("%lf\n", (double)hypot(x1-x2, y1-y2));

    return 0;
}

Measured memory_bytes: 664
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for(int i=0; i<M; i++) {
        cin >> B.at(i);
    }

    int ans = 0;
    for(int j=0; j<N; j++) {
        int tmp = 0;
        for(int i=0; i<M; i++) {
            int A;
            cin >> A;
            tmp += A * B.at(i);
        }
        tmp += C;
        if(tmp > 0) {
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
ll i,mx,n,j,x,res,d,y,sm,b,c;
const int N = 1e5 + 5;
vector <ll> v[N],ans(N),v2;
string s;
ll a[N];
ll dp[N];
ll go(ll idx , ll n)
{
    ll xx = INT_MAX , yy = INT_MAX ;
    if(idx == n - 1) return 0;
    if(dp[idx] != -1) return dp[idx];
    if(idx+1 < n )
    xx = abs (a[idx] - a[idx + 1]) + go( idx + 1 , n);
    if(idx+2 < n)
    yy = abs (a[idx] - a[idx + 2]) + go( idx + 2 , n);

    return dp[idx] = min(yy , xx);


}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    cin >> n ;
    for( i = 0; i < n; i++) {
        cin >> a[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << go( 0 , n);

    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int arr_wield[100001],arr_throw[100001];
bool mycompare(const int &a,const int &b)
{
	return a>b;
}
int main()
{
	int n,h=0,i,count=0,ans=0,pos_w=0,pos_t=0;
	scanf("%d %d",&n,&h);
	for(i=0;i<n;i++)
	{
		scanf("%d %d",&arr_wield[i],&arr_throw[i]);
	}
	sort(arr_wield,arr_wield+n,mycompare);
	sort(arr_throw,arr_throw+n,mycompare);
	while(h>0)
	{
		if(arr_throw[pos_t]>arr_wield[0])
		{
			h-=arr_throw[pos_t++];
			ans++;
		}
		else
		{
			ans+=h/arr_wield[0];
			ans+=h%arr_wield[0]==0?0:1;
			break;
		}
	}
    printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
X,Y = map(int,input().split())
p = 2*Y - X
q = 2*X - Y
x = -1
y = -1
e = 10**9 + 7
if p >= 0:
    if p%3 == 0:
        x = p//3
if q >= 0:
    if q%3 == 0:
        y = q//3

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, 10**6 + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if x == -1 or y == -1:
    ans = 0
else:
    z = x + y
    ans = cmb(z,x,e)
print(ans)

Measured memory_bytes: 121848
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    string S;
    cin >> S;
    int K; cin >> K;
    int N = S.size();
    set<string> st;
    REP(i,N) {
        for(int cnt = 1; cnt <= N-i && cnt <= K; cnt++) {
            //cout << S.substr(i,cnt) << endl;
            st.insert(S.substr(i,cnt));
        }
    }
    vector<string> res;
    for(auto s : st) {
        res.push_back(s);
    }
    if(N == 1) cout << S[0] << endl;
    else {
        sort(res.begin(),res.end());
        cout << res[K-1] << endl;
    }
}

Measured memory_bytes: 5020
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    long k;
    cin >> k;
    if (k%2==0 or k%5==0)
    {
        cout << -1 << endl;
        return 0;
    }
    long M[10000000];
    M[0] = 7%k;
    if (M[0]==0)
    {
        cout << 1 << endl;
        return 0;
    }
    
    for (int i = 1; i < 10000000; i++)
    {
        M[i] = (( (M[i-1]%k)*(10%k) )%k + 7%k)%k;
        if (M[i]==0)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 11404
/*input
5 10 0
1 2
1 3
1 4
1 5
3 2
2 4
2 5
4 3
5 3
4 5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

vector<vector<int>> adj;
vector<bool> visited;
vector<int> comp;

void dfs(int v, int c)
{
	comp[v] = c;
	visited[v] = 1;
	for(int i = 0; i < adj[v].size(); i++) if(!visited[adj[v][i]]) dfs(adj[v][i], c);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, k; cin >> n >> m >> k;
    vector<vector<int>> block(n);
    vector<int> compsize(n, 0);
    adj.resize(n);
    visited.resize(n);
    comp.resize(n);
    for(int i = 0; i < n; i++) visited[i] = 0;
    for(int i = 0; i < m; i++)
    {
    	int a, b; cin >> a >> b;
    	a--; b--;
    	adj[a].push_back(b);
    	adj[b].push_back(a);
    }
    for(int i = 0; i < k; i++)
    {
    	int c, d; cin >> c >> d;
    	c--; d--;
    	block[c].push_back(d);
    	block[d].push_back(c);
    }
    int cnt = 0;
    for(int i = 0; i < n; i++) if(!visited[i])
    {
    	dfs(i, cnt);
    	cnt++;
    }
    for(int i = 0; i < n; i++) compsize[comp[i]]++;
    for(int i = 0; i < n; i++)
    {
    	int ans = compsize[comp[i]] - adj[i].size() - 1;
    	for(int j = 0; j < block[i].size(); j++) if(comp[i] == comp[block[i][j]]) ans--;
    	cout << ans << ' ';
    }

    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool p = 0;
  if(a == b || b == c || c == a) {
    if(a != b || b != c) {
      p = 1;
    }
  }
  if(p) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3600
#include<stdio.h>
#define MAX 10001

 int par[MAX],rank[MAX];

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

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

 int unite(int x,int y){
               x=find(x);
               y=find(y);

               if(x==y)return;

               if(rank[x]<rank[y]){par[x]=y;}
               else {
                     par[y]=x;
                     if(rank[x]==rank[y]){rank[x]++;}
                     }
               }


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

 int main(){
        int n,q,com,i,x,y;
        scanf("%d%d",&n,&q);
        init(n);
        for(i=0;i<q;i++){
                    scanf("%d%d%d",&com,&x,&y);

                    if(com==0){unite(x,y);}
                    else 
                          {if(same(x,y)){printf("1\n");}
                           else {printf("0\n");}
                          }
                    }
        return 0;
        }



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

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int A, B, C;
    cin >> A >> B >> C;

    cout << A * B / 2 << endl;

    return 0;
}


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

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll lcm(ll x, ll y) {
    return x / GCD(x, y) * y;//先に割り算をして掛けられる数を小さくして掛け算を行う
}

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    A--; B--; C--; D--;

    string S;
    cin >> S;
    bool ans = true;
    if (C < D)
    {
        for (int i = A; i < D; i++)
        {
            if (S[i] == '#' && S[i + 1] == '#')
            {
                cout << "No" << endl;
                return 0;
            }
             
        }
        cout << "Yes" << endl;
        return 0;
        
    }else if (C > D)
    {
        
        for (int i = A; i < C; i++)
        {
             if (S[i] == '#' && S[i + 1] == '#')
            {
                cout << "No" << endl;
                return 0;
            }
            
        }
        for (int i = B - 1; i < D; i++)
        {
            if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.')
            {
                cout << "Yes" << endl;
                return 0;
            }
            
        }
        
        cout << "No" << endl;
        
    }

    
    
    
    
    
     
    return 0;

}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int n, ans = 0, mini, to;
struct node
{
	int x, y;
	bool type, flag;
}po[205];
bool cmp(node a, node b) {return a.x < b.x;}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &po[i].x, &po[i].y);
		po[i].type = false;
		po[i].flag = false;
	}//red
	for (int i = 1; i <= n; i++)
	{
		scanf("%d%d", &po[i + n].x, &po[i + n].y);
		po[i + n].type = true;
	}//blue
	sort(po + 1, po + n * 2 + 1, cmp);
	for (int i = 1; i <= n * 2; i++)
		if (po[i].type)
		{
			mini = -1, to = -1;
			for (int j = 1; j < i; j++)
				if (!po[j].type && !po[j].flag && po[j].y < po[i].y && po[j].y > mini)
					mini = po[j].y, to = j;
			if (to != -1) po[to].flag = true, ans++;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;

typedef long long ll;

priority_queue<pair<ll, ll> > Q;

int main(void)
{
	ll x, y, a, b, c, i, p, q, r, ans = 0;

	scanf("%lld %lld %lld %lld %lld", &x, &y, &a, &b, &c);
	for (i = 1; i <= a; i++)
	{
		scanf("%lld", &p);
		Q.push(make_pair(p, 1));
	}
	for (i = 1; i <= b; i++)
	{
		scanf("%lld", &q);
		Q.push(make_pair(q, 2));
	}
	for (i = 1; i <= c; i++)
	{
		scanf("%lld", &r);
		Q.push(make_pair(r, 3));
	}

	ll one = 0, two = 0, three = 0;
	while (one + two + three < x + y)
	{
		pair<ll, ll> top = Q.top(); Q.pop();

		if (top.second == 1)
		{
			if (one >= x)
				continue;
			one++;
			ans += top.first;
		}
		else if (top.second == 2)
		{
			if (two >= y)
				continue;
			two++;
			ans += top.first;
		}
		else
		{
			three++;
			ans += top.first;
		}
	}

	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 10220
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int ans;
		
		if ((n - k) >= 0) {
			ans = k * x + (n - k) * y;
		} else {
			ans = n * x;
		}
		
		System.out.println(ans);	
	}
}


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

const char pics[] = { 'S', 'H', 'C', 'D' };

int main() {

	int n;
	bool cards[4][13];
	char pc;
	int pi, r;

	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 13; ++j) {
			cards[i][j] = false;
		}
	}

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> pc >> r;
		for (int j = 0; j < 4; ++j) {
			if (pc == pics[j]) {
				pi = j;
				break;
			}
		}
		cards[pi][r - 1] = true;
	}
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 13; ++j) {
			if (!cards[i][j]) {
				cout << pics[i] << " " << j + 1 << endl;
			}
		}
	}

	return 0;
}

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

int main(){

    int N,num[200],cnt = 0;
    int out = 1;
    cin >> N;
   
    for(int i=0; i<N; i++){

        cin >> num[i];

    }

    while(out)
    {
        for(int i=0; i<N; i++){

            if(num[i]%2) out = 0;                      
             num[i] =num[i]/2;           
        }
          ++cnt;
    }
    cout << cnt-1 << '\n';
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

long long a[100005];

int main()
{
	int n, k;
	long long ans = 0x3f3f3f3f;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	for (int i = 1; i + k - 1 <= n; i++)
	{ 
		int l = i, r = i + k - 1;    
		ans = min(ans, a[r] - a[l] + min(abs(a[l]), abs(a[r]))); 
	}  
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

class Solution {
public:
	int powerSocket(int a, int b) {
		const int nRequired = (b - 1);
		const int effect = (a - 1);
		return (nRequired + effect - 1) / effect;
	}
};

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

	Solution sol;
	int ans = sol.powerSocket(a, b);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N,C=map(int,input().split())
s=[list(map(int,input().split())) for i in range(C)]
t=[[0]*C for i in range(3)]
ll,kk=[],[[0]*C for i in range(3)]
for k in range(N):
    for i,j in enumerate(list(map(int,input().split()))):
        t[(i+k)%3][j-1]+=1
for j in range(3):
    for i in range(C):
        for k in range(C):
            kk[j][k]+=(s[i][k]*t[j][i])
from itertools import permutations
ans=10**9
for i,j,k in permutations(range(C),3):
    p=kk[0][i]+kk[1][j]+kk[2][k]
    ans=min(ans,kk[0][i]+kk[1][j]+kk[2][k])
print(ans)

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s;
    cin >> t;
    ll res = 0;
    REP(i, 3)
    {
        if (s[i] == t[i])
        {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

ll func(ll n){
  ll ans = 0;
  rep(i,40) {
    ll freq = 1LL<<(i+1);
    if(i==0) {
      ll num = (n+1)/freq;
      if(num%2==1) ans += 1;
      continue;
    }
    if((n+1)%freq>(freq/2) && ((n+1)%freq)%2==1) {
      ans += 1LL<<i;
    }
  }
  return ans;
}


int main () {
  ll a,b;cin>>a>>b;
  ll reta = func(a-1),retb = func(b);
  //  cout<<reta<<" "<<retb<<endl;
  ll ans = reta^retb;
  cout<<ans<<endl;
}


Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	int ans = 0;
	if (n >= 9) {
		ans += 9;
		if (n >= 999) {
			ans += (999 - 99);
			if (n >= 99999) {
				ans += (99999 - 9999);
			}
			else {
				ans += max(0, n - 10000 + 1);
			}
		}
		else {
			ans += max(0, n - 100 + 1);
		}
	}
	else {
		ans += n;
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll a,b,c,k; cin >> a >> b >> c >> k;
	ll s = 0;
	if(k){
	    ll m = min(a,k);
	    s += m;
	    a -= m;
	    k -= m;
	}
	
// 	cout << s << endl;
	if(k){
	    ll m = min(b,k);
	    a -= m;
	    k -= m;
	}
	
// 	cout << s << endl;
	
	if(k){
	    ll m = min(c,k);
	   // cout << m << " " << k << endl;
	    s -= m;
	    a -= m;
	    k -= m;
	}
	
	cout << s << endl;
}

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        try {
            String inputData[] = br.readLine().split(" ");
            int sum = 0;
            int row = Integer.parseInt(inputData[0]), column = Integer.parseInt(inputData[1]);
            String data[][] = new String[row][column];
            String data2[] = new String[column];
            // data
            for (int i = 0; i < row; i++) {
                data[i] = br.readLine().split(" ");
            }
            // data2
            for (int i = 0; i < column; i++)
                data2[i] = br.readLine();

            for (int i = 0; i < row; i++) {
                for (int j = 0; j < column; j++) {
                    sum = sum + Integer.parseInt(data[i][j]) * Integer.parseInt(data2[j]);
                }
                System.out.printf("%d\n", sum);
                sum = 0;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 27748
#include<bits/stdc++.h>
#define   ll    long long int
#define   sz    200010

using namespace std;

ll num[sz];
ll id=1;

void make(ll x)
{
    if(x>1000000000)return;

    num[id]=x;
    id++;

    ll a=x*10+5;
    ll b=x*10+7;
    ll c=x*10+3;

    make(a);
    make(b);
    make(c);
}

ll ara[sz];

int main()
{
    ll n,i,j,k,a,b,c,x,y,d,p,m;

    make(7);
    make(5);
    make(3);

    j=1;

    for(i=1;i<id;i++)
    {
        a=0;
        b=0;
        c=0;

        k=num[i];

        while(k>0)
        {
            x=k%10;
            k=k/10;
            if(x==3)a=1;
            else if(x==5)b=1;
            else if(x==7)c=1;
        }

        if(a==1 && b==1 && c==1)
        {
            ara[j]=num[i];
            j++;
        }
    }

    m=j-1;

    sort(ara+1,ara+m+1);

    cin>>n;
    c=0;

    for(i=1;i<=m;i++)
    {
        if(ara[i]>n)break;
        else
            c++;
    }


    cout<<c<<endl;

    return 0;

}


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

int main(void)
{
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int ans;
  ans = min(B,D) - max(A,C);
  if(ans<0) ans = 0;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
int n=0;
struct Dia{
int a=0;
int b=0;
int c=0;
};
Dia a[100002];
int pd[100002][4];
long long int func(int dia, int anterior){
if(pd[dia][anterior]!=-1) return pd[dia][anterior];
if(dia==n) return 0;
else if(anterior==1) return pd[dia][anterior]=max(a[dia].b+func(dia+1, 2), a[dia].c+func(dia+1, 3));
else if(anterior==2) return pd[dia][anterior]=max(a[dia].a+func(dia+1, 1), a[dia].c+func(dia+1, 3));
else if(anterior==3) return pd[dia][anterior]=max(a[dia].b+func(dia+1, 2), a[dia].a+func(dia+1, 1));
else return pd[dia][anterior]=max(a[dia].a+func(dia+1, 1), max(a[dia].b+func(dia+1, 2), a[dia].c+func(dia+1, 3)));
}
int main(){
scanf("%d", &n);
for(int i=0; i<n; ++i){
scanf("%d %d %d", &a[i].a, &a[i].b, &a[i].c);
for(int j=0; j<4; ++j)
pd[i][j]=-1;
}
long long int resp=func(0, 0);
printf("%lld", resp);

return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	int a, b,ans=0;
	cin >> a >> b ;
	for (int i = 0; i < 2; i++){
		if (a <= b){
			ans += b;
			b--;
		}
		else{
			ans += a;
			a--;
		}
	}
	cout << ans << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  if(64 <= n) cout << 64 << endl;
  else if(32 <= n) cout << 32 << endl;
  else if(16 <= n) cout << 16 << endl;
  else if(8 <= n) cout << 8 << endl;
  else if(4 <= n) cout << 4 << endl;
  else if(2 <= n) cout << 2 << endl;
  else cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 998244353;
const int IMAX = 200010;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
	int comb(int A, int B) {
		return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
	}
} f;

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


	int N, M, K;
	cin >> N >> M >> K;

	if (M == 1) {
		if (K == N - 1) co(1);
		else co(0);

		return 0;
	}
	if (N == 1) {
		co(M);
		return 0;
	}

	ll kotae = 0;
	rep(k, K + 1) {

		ll tmp = modpow(M - 1, N - k - 1) * f.comb(N - 1, k) % mod;
		tmp *= M;
		tmp %= mod;
		kotae += tmp;
	}

	co(kotae% mod);



	Would you please return 0;
}

Measured memory_bytes: 6000
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};

int main(){
    ll n,k;
	cin >> n >> k;
	vll x(n);
	ll ans = 0;
	rep(i,n) {
		cin >> x[i];
		ans += 2 * min(x[i], abs(k-x[i]));
	}
	cout << ans << endl;
}  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  if(s.size()==2) std::cout << s << '\n';
  else{
    reverse(all(s));
    std::cout << s << '\n';
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 1234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N, a[212345];
LL b[212345], ans;
std::set<LL>memo;

int main()
{
    in >> N;
    rep(i, N)
    {
        in >> a[i + 1];
        b[a[i + 1]] = (i + 1);
    }
    
    memo.insert(0);
    memo.insert(N + 1);
    rep(i, N)
    {
        auto it = memo.lower_bound(b[i + 1]);
        auto r = *it, l = *(--it);
        ans += (r - b[i + 1])*(b[i + 1] - l)*(i + 1);
        memo.insert(b[i + 1]);
    }
    
    out << ans << std::endl;
    
	return 0;
}

Measured memory_bytes: 12800
import sys

def main():
	tate = int(raw_input())
	result = []
	for i in range(1, tate+1):
		result.append(i)

	yoko = int(raw_input())

	for line in sys.stdin.readlines():
		x1, x2 = map(int, line.split(","))
		x1 -= 1
		x2 -= 1
		temp = result[x2]
		result[x2] = result[x1]
		result[x1] = temp

	for num in result:
		print num
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 4220
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc109_d
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			List<int[]> list = new List<int[]>();
			int[,] map = new int[x[0], x[1]];
			for (int i = 0; i < x[0]; i++)
			{
				int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
				for (int j = 0; j < x[1]; j++)
				{
					map[i, j] += a[j];
				}
				for (int j = 0; j < x[1]; j++)
				{
					if (!(i == x[0] - 1 && j == x[1] - 1))
					{
						if (map[i, j] % 2 == 1)
						{
							map[i, j]--;
							if (j + 1 < x[1])
							{
								map[i, j + 1]++;
								list.Add(new int[] { i + 1, j + 1, i + 1, j + 2 });
							}
							else
							{
								map[i + 1, j]++;
								list.Add(new int[] { i + 1, j + 1, i + 2, j + 1 });
							}
						}
					}
				}
			}
			Console.WriteLine(list.Count);
			foreach (var item in list)
			{
				Console.WriteLine(string.Join(" ", item));
			}
		}
	}
}

Measured memory_bytes: 30252
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Main {

  private static final String[] MM = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"};

  public static void main(String[] args) {

    String sDate = null;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      sDate = br.readLine();
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

    String numOne = sDate.substring(0, 2);
    String numTwo = sDate.substring(2, 4);

    boolean isOne = false;
    boolean isTwo = false;

    for (int i = 0; i < MM.length; i++) {

      if (isOne == false && MM[i].equals(numOne)) {
        isOne = true;
      }

      if (isTwo == false && MM[i].equals(numTwo)) {
        isTwo = true;
      }
    }

    if (isOne && isTwo) {
      System.out.print("AMBIGUOUS");
    } else if (isOne == false && isTwo == false) {
      System.out.print("NA");
    } else if (isOne) {
      System.out.print("MMYY");
    } else if (isTwo) {
      System.out.print("YYMM");
    }
  }
}


Measured memory_bytes: 20948
N,M = map(int,input().split())
A = []
for i in range(N):
  A.append(list(input()))
B = []
for j in range(M):
  B.append(list(input()))
for k in range(N-M+1):
  for l in range(N-M+1):
    cnt = 0
    if B[0][0:M] == A[k][l:l+M]:
      p = k
      q = l
      for m in range(M):
        if B[m][0:M] == A[p+m][q:q+M]:
          cnt += 1
        if cnt == M:
          print('Yes')
          exit()
print('No')

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k; cin >> n >> k;
    int res = k;
    rep(i,n-1) {
        res *= k-1;
    }
    cout << res << "\n";
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using std::cout;
using std::endl;
using std::cin;
using std::string;
using std::reverse;
using std::replace;
string Replace(string str, int a, int b, string p) {
	str.replace(a, b-a+1, p);
	return str;
}

string Reverse(string str, int a, int b) {
	reverse(str.begin() + a, str.begin() + b + 1);
	return str;
}

void Print(string str, int a, int b) {
	cout << str.substr(a, b-a+1) << endl;
}

int main() {
	string str;		// ?????????
	string stat;	// ??????????´???¨
	int stat_num;	// ???????????°
	int a, b;	// ??????????????¨
	string p;	// replace??¨
	cin >> str;
	cin >> stat_num;

	for (size_t i = 0; i < stat_num; i++)
	{
		cin >> stat;
		if (stat == "print") {
			cin >> a;
			cin >> b;
			Print(str, a, b);
		}
		else if (stat == "reverse")
		{
			cin >> a;
			cin >> b;
			str = Reverse(str, a, b);
		}
		else
		{
			cin >> a;
			cin >> b;
			cin >> p;
			str = Replace(str, a, b, p);
		}
	}
	return 0;
}

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

bool member[101],smaller;
int ans = 102,x,b,n,distancemin = 200;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>x>>n;
	for(int i = 0;i < n;i++){
		cin>>b;
		member[b] = true;
	}
	for(int i = 0;i <= 101;i++){
		if(!member[i]){
			if(abs(x - i) < distancemin){
				distancemin = abs(x - i);
				if(ans < x) smaller = true;
				if((ans > x && !smaller) || ans <= x)
				ans = i;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3584
import math
N,M=(map(int,input().split()))
a=0
if N>=2:
    x=math.factorial(N)/(math.factorial(N-2)*2)
    a=a+x
if M>=2:
    y=math.factorial(M)/(math.factorial(M-2)*2)
    a=a+y
if a!=0:
    print(int(a))
else:
    print('0')

Measured memory_bytes: 9200
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
#define N 100100

int main()
{
   int  a[N],b[N];
   int  c[N];
   int  n;
    cin>>n;
   for (int i=1;i<=n;i++)
       cin>>a[i];
    for (int i=1;i<=n;i++)
        cin>>b[i];
    for (int i=1;i<=n;i++)
        cin>>c[i];

    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
   sort(c+1,c+1+n);
    ll w,v,ans=0;
   for (int i=1;i<=n;i++)
{
   w=(lower_bound(a+1,a+n+1,b[i])-a)-1;
   v=n+1-(upper_bound(c+1,c+n+1,b[i])-c);
  ans+=w*v;
}
    cout << ans << endl;
       return 0;
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int h, w;
  cin >> h >> w;
  int cou = 0;
  rep(i, 0, h) {
    string s;
    cin >> s;
    rep(j, 0, w) if(s[j] == '#') cou++;
  }
  if(cou == h + w - 1) cout << "Possible\n";
  else cout << "Impossible\n";
}


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

class Program {
    static void Main(string[] args) {
        //入力
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();

        //計算
        //[0, i)の黒の数を計算する
        int[] v_black = new int[N + 1];
        for (int i = 0; i < N; i++) {
            v_black[i + 1] += v_black[i];
            if (S[i] == '#') {
                v_black[i + 1]++;
            }
        }

        //[0, i)の白の数を計算する
        int[] v_white = new int[N + 1];
        for (int i = 0; i < N; i++) {
            v_white[i + 1] += v_white[i];
            if (S[i] == '.') {
                v_white[i + 1]++;
            }
        }

        //回答となる数値
        int ans = 999999999;


        //検証
        for (int i = 0; i < N; i++) {
            int now = v_black[i] + (v_white[N] - v_white[i + 1]);
            ans = Math.Min(ans, now);
        }

        //出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13280
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    int n,q,b[100000],i,j,flag=0,min,max,meet[50000],count,person,now=0;
    long long int t,a[100000],tmp,point[50000];
    scanf("%d%lld%d",&n,&t,&q);
    for(i=0; i<n; i++){
        scanf("%lld%d",&a[i],&b[i]);
        if(flag==0){
            if(b[i]==1){
                flag=1;
                count=0;
                meet[count]=i;
            }
        }else{
            if(b[i-1]==1 && b[i]==2){
                point[count]=(a[i-1]+a[i])/2;
            }else if(b[i-1]==2 && b[i]==1){
                count++;
                meet[count]=i;
            }
            if(b[i]==2 && i==n-1){
                count++;
                meet[count]=n;
            }
        }
    }
    for(i=0; i<q; i++){
        scanf("%d",&person);
        flag=0;
        person--;
        for(j=now; j<count; j++){
            if(person<meet[0]){
                tmp=a[person]-t;
                printf("%lld\n",tmp);
                now = j;
                flag=1;
                break;
            }else if(person>=meet[j] && person<meet[j+1]){
                if(llabs(point[j]-a[person]) > t){
                    tmp=(b[person]==1)?(a[person]+t):(a[person]-t);
                }else{
                    tmp=point[j];
                }
                printf("%lld\n",tmp);
                now = j;
                flag = 1;
                break;
            }
        }
        if(flag==0){
            tmp=a[person]+t;
            printf("%lld\n",tmp);
        }
    }
    return 0;
}


Measured memory_bytes: 4164
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(void)
{
    int a,b,x;
    int ans;
    cin>>a>>b>>x;
    ans=b/x;
    if(a%x==0)ans-=a/x-1;
    else ans-=a/x;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair <int,int> pii;

const int RLEN=1<<18|1;
inline char nc() {
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
	char ch=nc(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
	return i*f;
}

const int N=500*501;
int n,a[N],x[N],p[N];
multiset <pii> s;

int main() {
	n=rd();
	for(int i=1;i<=n;i++) {
		x[i]=rd();
		if(a[x[i]]) {puts("No"); exit(0);}
		a[x[i]]=i;  
		if(i!=1) s.insert(pii(x[i],i-1));
	}
	int head=1; while(a[head]) ++head;
	while(s.size()) {
		pii lim=*s.begin(); s.erase(s.begin());
		for(int j=1;j<=lim.second;++j) {
			if(head>lim.first) {puts("No"); exit(0);}
			a[head++]=lim.second+1;
			while(a[head]) ++head;
		}
	} s.clear(); 
	for(int i=1;i<=n;i++) s.insert(pii(x[i],n-i));
	while(s.size()) {
		pii lim=*s.begin(); s.erase(s.begin());
		if(head<=lim.first) {puts("No"); exit(0);}
		for(int j=1;j<=lim.second;++j) {
			a[head++]=n-lim.second;
			while(a[head]) ++head;
		}
	}
	puts("Yes");
	for(int i=1;i<=n*n;i++) printf("%d ",a[i]); 
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(){
int n,m,l,i,j,k;
scanf("%d %d %d",&n,&m,&l);
int a[n][m],b[m][l];
long c[n][l];
for(i=0;i<n;i++){
   for(j=0;j<m;j++){
      scanf("%d",&a[i][j]);
   }
}
for(j=0;j<m;j++){
   for(k=0;k<l;k++){
      scanf("%d",&b[j][k]);
   }
}
for(i=0;i<n;i++){
   for(k=0;k<l;k++){
      c[i][k]=0;
   }
}
for(i=0;i<n;i++){
   for(j=0;j<m;j++){
      for(k=0;k<l;k++){
         c[i][k]=c[i][k]+a[i][j]*b[j][k];
      }
   }
}
for(i=0;i<n;i++){
   for(k=0;k<l;k++){
      printf("%ld",c[i][k]);
      if(k!=l-1) printf(" ");
   }
   printf("\n");
}
return 0;
}

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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m, tmp, p, x;
    vector<int> t;
    cin >> n;
    for(ll i=0;i<n;i++) {
        cin >> tmp;
        t.push_back(tmp);
    }
    int alltime = accumulate(all(t), 0);
    cin >> m;
    for(ll i=0;i<m;i++) {
        cin >> p >> x;
        cout << alltime - t[p-1] + x << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
bool mp[10][10];
int memo[10][10];
int ans = 0;

void chack() {
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++) {
      memo[i][j] = 0;
      for(int k=i;k<5;k++) {
	if(mp[k][j] == 1) memo[i][j]++;
	else break;
      }
    }
 
}

void check() {

  for(int k=0;k<5;k++) {
    
    for(int i=0;i<5;i++){
      int cnt = 0;  
      int min1 = 100;
      
    for(int j=i;j<5;j++) {
      if(mp[k][j] == 0) break;
      cnt++;
      min1 = min(min1,memo[k][j]);
      if(ans < min1 * cnt) ans = min1*cnt;
    }
  }
  }
      
}


int main() {

  int n;
  cin >> n;

  for(int i=0;i<n;i++) {


    for(int i=0;i<5;i++) 
      for(int j=0;j<5;j++)
	cin >> mp[i][j];

    ans = 0;
    chack();
    check();

    cout << ans << endl;

  }

  return 0;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-

def solve():
    N = int(input())
    if any(((N//i)*i==N) and (1<=N//i<=9) for i in range(1, 10)):
        return 'Yes'
    else:
        return 'No'
        
if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <list>
 
struct Point{
  int x;
  int y;
};
struct Pair{
  Point red;
  Point blue;
};
 
int N;
std::list<Point> reds;
std::list<Point> blues;
std::list<Pair> pairs;
typedef std::list<Point>::iterator ItP;
 
bool cmpYDescendant(const Point &left, const Point &right) {
    return left.y > right.y;
}
 
bool cmpXAscendant(const Point &left, const Point &right) {
    return left.x < right.x;
}
 
int main(){
	Point p;
  	std::cin>>N;
  	for(int i=0;i<N;i++){
      std::cin>>p.x>>p.y;
      reds.push_back(p);
    }
  	for(int i=0;i<N;i++){
		std::cin>>p.x>>p.y;
      	blues.push_back(p);
    }
  	reds.sort(cmpYDescendant);
  	blues.sort(cmpXAscendant);
  	ItP it_b = blues.begin();
  	while(it_b != blues.end()) {
        bool found = false;
        ItP it_r = reds.begin();
 
        while(it_r != reds.end()) {
            if ((*it_r).x < (*it_b).x && (*it_r).y < (*it_b).y) {
                Pair p;
 
                found = true;
                p.red = *it_r;
                p.blue = *it_b;
                pairs.push_back(p);
                reds.erase(it_r);
                break;
            }
 
            ++it_r;
        }
 
        ++it_b; 
       
    }
 
    std::cout << pairs.size() << std::endl;
}

Measured memory_bytes: 256