akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace  std;

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();
    vector<vector<int>> vvnLcsDP(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

Measured memory_bytes: 6896
n = int(input())
old_t = 0
old_x, old_y = 0, 0
ok = True
for i in range(n):
    t, x, y = map(int, input().split())
    if ok:
        dt = t - old_t
        dx = abs(x - old_x)
        dy = abs(y - old_y)
        if dt < dx+dy:
            ok = False
            break
        else:
            if dt % 2 == 0:
                if (dx + dy) % 2 != 0:
                    ok = False
                    break
            else:
                if (dx + dy) % 2 == 0:
                    ok = False
                    break
        old_t = t
        old_x = x
        old_y = y
if ok:
    print('Yes')
else:
    print('No')


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

int main(){
  //入力
  int A,B,Q;
  cin>>A>>B>>Q;
  vector<int64_t> s(A);
  vector<int64_t> t(B);
  vector<int64_t> x(Q);
  for(int i=0;i<A;++i) cin>>s.at(i);
  for(int j=0;j<B;++j) cin>>t.at(j);
  for(int k=0;k<Q;++k) cin>>x.at(k);

  //ソート
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());

  //最短距離の候補を高々8つ作って最小値を出力
  for(int k=0;k<Q;++k){

    vector<int64_t> s_near(2,1e11),t_near(2,1e12);
    int64_t ans=1e11;

    if(x.at(k)>s.at(0)){
      s_near.at(0)=*(lower_bound(s.begin(),s.end(),x.at(k))-1);
    }
    if(x.at(k)<s.at(A-1)){
      s_near.at(1)=*(lower_bound(s.begin(),s.end(),x.at(k)));
    }
    if(x.at(k)>t.at(0)){
      t_near.at(0)=*(lower_bound(t.begin(),t.end(),x.at(k))-1);
    }
    if(x.at(k)<t.at(B-1)){
      t_near.at(1)=*(lower_bound(t.begin(),t.end(),x.at(k)));
    }


    for(int i=0;i<2;++i){
      for(int j=0;j<2;++j){
        ans=min(ans,min(abs(x.at(k)-s_near.at(i))+abs(s_near.at(i)-t_near.at(j)),abs(x.at(k)-t_near.at(j))+abs(s_near.at(i)-t_near.at(j))));
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3712
#include <iostream>
using namespace std;
int main(void){
  char a,b,c;
  cin >> a >> b >> c;
  int ans = 0;
  if(a == '1') ans++;
  if(b == '1') ans++;
  if(c == '1') ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn =2e5+5;
const int mod=10000019;
const int inf=0x3f3f3f;
char a[maxn];
int b[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    int ans=7%n;
    for(int i=1; i<1e6; i++)
    {
        if(ans==0)
        {
            printf("%d\n",i);
            return 0;
        }
        ans=(10*ans+7)%n;
    }
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 3772
from collections import Counter


n = int(input())
s = input()
count = Counter(s)

ans = count["R"] * count["G"] * count["B"]
for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k > n - 1:
            break
        if s[i] != s[j] != s[k] != s[i]:
            ans -= 1

print(ans)

Measured memory_bytes: 73572
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int main()
{
	long long n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	
	long long ans = 0;
//	if (n > (a + b)) {
		long long dist = a + b;
		long long r = n % dist;
		long long count = n / dist;
		ans = a * count;
		if (r >= a)
			ans = ans + a;
		else
			ans = ans + r;
//	} else if (n > a) {
//		ans = a;
//	} else if (n <= a) {
//		ans = n;
//	}
	
	printf("%lld\n", ans);
	
	
	
			
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 0;
const int M = 1e9+7;

void modMul(int &a, int b) {
    (a *= b) %= M;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; cin>>n>>m;
    int poss = 1;
    V<int> a(n), b(m);
    V<int> rOf(n*m, -1), cOf(n*m, -1);
    F(i,n) {
        cin>>a[i];
        a[i]--;
        if (rOf[a[i]] != -1)
            poss = 0;
        else
            rOf[a[i]] = i;
    }
    F(i,m) {
        cin>>b[i];
        b[i]--;
        if (cOf[b[i]] != -1)
            poss = 0;
        else
            cOf[b[i]] = i;
    }
    H(rOf) H(cOf)
    H(poss)
    int usedC = 0, usedR = 0;
    D(v,n*m) {
        P("value "<<v+1)
        int freeCells = usedC*usedR - (n*m-1-v);
        H(freeCells)
        if (rOf[v] == -1 && cOf[v] == -1) {
            P("A")
            modMul(poss, freeCells);
        } else if (rOf[v] == -1) {
            P("B")
            modMul(poss, usedR);
        } else if (cOf[v] == -1) {
            P("C")
            modMul(poss, usedC);
        }
        H(poss)
        
        if (rOf[v] != -1)
            usedR++;
        if (cOf[v] != -1)
            usedC++;
        P("")
    }
    cout<<poss<<"\n";
}

Measured memory_bytes: 15872
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

  ll N , x; cin >> N >> x;
  vector<ll> a ;
  rep(i,N){
    ll inp; cin >> inp;
    a.pb(inp);
  }

  ll ans = 0;
  rep(i,N){
    if(i==0){
      if(a[i] > x){
	ll del = a[i] -x;
	del = max((ll)0, del);
	ans += del;
	a[i]-= del;
      }
    }
    else{
      ll del = (a[i] + a[i-1]) -x;
      del = max((ll) 0, del);
      ans += del;
      a[i] -= del;
    }
  }

  cout << ans << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
const int v=1e3;int n,m,a,b,s,q[v][v];
main()
{
	cin>>n>>m>>a>>b;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;s+=q[i][j]=(i%a||j%b)?v:-(a*b-1)*v-1,j++);
	if(s<=0)return 0&puts("No");puts("Yes");
	for(int i=1;i<=n;i++,puts(""))for(int j=1;j<=m;printf("%d ",q[i][j]),j++);
}


Measured memory_bytes: 3584
#!/bin/env ruby

s = STDIN.readlines
n = s[0]
a = s[1].split(" ").map(&:to_i)

count = 0

a.each_index do |i|
  if i+1 == a[i]
  else
    count = count + 1
  end
end

if count > 2
  puts "NO"
else
  puts "YES"
end


Measured memory_bytes: 3836
a,b = map(int,input().split())
s = input()

ans = 'Yes'
for i in range(a):
    if s[i] == '-':
        ans = 'No'
if s[a] != '-':
    ans = 'No'
for i in range(b):
    if s[a+i+1] == '-':
        ans = 'No'

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c<=0){
            puts("Yes");
            return 0;
        } 
        a -= d;
        if(a<=0){
            puts("No");
            return 0;
        }
    }
    return 0;
}

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

// Author - Kevin Mathew
// Birla Institute of Technology, Mesra

void te(){
	ll a, b;
	cin >> a >> b;

	if(b % a == 0){
		cout << a + b << "\n";
	}
	else
		cout << b - a << "\n";
}

int main()
{
	// freopen("input.txt", "r", stdin);		//Comment
	// freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	te();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define loop(vals,times) for(vals=0;vals<times;vals++)
#define reg(time) for(int val=0;val<time;val++)
#define space <<" "<<
using namespace std;

int main()
{
    int n;
    set<string> dic;
    
    cin>>n;
    reg(n){
        string c,w;

        cin>>c>>w;
        if(c=="insert"){
        dic.insert(w);
        }
        if(c=="find"){
            
        if(dic.count(w)!=1)cout<<"no"<<endl;
         else cout<<"yes"<<endl;
        }
    }
}



Measured memory_bytes: 32148
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    cin >> s;
    int ans = 0;

    for(int i=0; i<s.size(); i++){
        if(s[i]=='+') ans ++;
        else ans--;
    }
    cout << ans << endl;

    return 0;
}


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

int main(int argc, char const *argv[])
{
    int n,*p,MAX,min;
    cin>>n;
    p=new int[n];
    for(int i=0;i<n;i++)    cin>>*(p+i);
    MAX=*(p+1)-*p;
    min=*p;
    for(int i=1;i<n;i++)
    {
        MAX=((*(p+i)-min)>=MAX?*(p+i)-min:MAX);
        min=(*(p+i)<=min?*(p+i):min);
    }
    cout<<MAX<<endl;
    delete []p;
    //system("pause");
    return 0;
}



Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

unsigned int A, B, K;
void solve() {
    bool t=true;
    for (int i=0; i<K; i++) {
        if (t) {
            // Takahashi
            if (A%2 == 1) {
                --A;

            }
            int tmp = A/2;
            B += tmp;
            A = tmp;
            
        } else {
            // Aoki
            if (B%2 == 1) {
                --B;
            }
            int tmp = B/2;
            A += tmp;
            B = tmp;
        
        }
        t = !t;
    }
    std::cout << A << ' ' << B << std::endl;
}

int main() {
    std::cin >> A >> B >> K;
    solve();
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

class State {
public:
  int pos;
  int cost;
  int prev_hand;
  int prev_pos;
  State(int _p,int _c) : pos(_p),cost(_c),prev_hand(-1000),prev_pos(-1000) {}
  State(int _p,int _c,int _ph,int _pp) : pos(_p),cost(_c),prev_hand(_ph),prev_pos(_pp) {}
  bool operator<(const State& s) const{
    return cost < s.cost;
  }
  bool operator>(const State& s) const{
    return cost > s.cost;
  }
};

struct DP{
  int cost;
  int prev_hand;
  int prev_pos;
  DP(int _c,int _ph,int _pp) : cost(_c),prev_hand(_ph),prev_pos(_pp){}
  DP() : cost(INF),prev_hand(-1000),prev_pos(-1000){}
};

int main(){
  int total_cells;
  while(~scanf("%d",&total_cells)){
    int dice[7];
    for(int i=1;i<=6;i++){
      scanf("%d",dice + i);
    }
    int start,goal;
    scanf("%d %d",&start,&goal);
    int stage[303];
    for(int i=1;i<=total_cells;i++){
      scanf("%d",stage + i);
    }
    
    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(start,0,-1000,-1000));

    DP dp[303];

    while(!que.empty()){
      State s = que.top();
      que.pop();

      if(dp[s.pos].cost <= s.cost) continue;

      dp[s.pos].cost = s.cost;
      dp[s.pos].prev_hand = s.prev_hand;
      dp[s.pos].prev_pos = s.prev_pos;

      for(int i=1;i<=6;i++){
        int dx1 = s.pos + dice[i];
        int dx2 = s.pos - dice[i];

        if(1 <= dx1 && dx1 <= total_cells){
          dx1 += stage[dx1];
          que.push(State(dx1,s.cost + 1,i,s.pos));
        }
        if(1 <= dx2 && dx2 <= total_cells){
          dx2 += stage[dx2];
          que.push(State(dx2,s.cost + 1,-i,s.pos));
        }
      }
    }

    vector<int> hands;
    int prev_x = goal;
    for(int round = 0;round <= 3000;round++){
      hands.push_back(dp[prev_x].prev_hand);
      prev_x = dp[prev_x].prev_pos;
      if(prev_x == start) break;
    }

    reverse(hands.begin(),hands.end());

    int hand_idx = 0;
    for(int round = 0;round <= 3000;round++){
      int num;
      scanf("%d", &num);
      
      if(num != abs(hands[hand_idx])){
        printf("0\n"); fflush(stdout);
      }

      else if(num == abs(hands[hand_idx])){
        if(hands[hand_idx] > 0){
          printf("1\n"); fflush(stdout);
        }
        else{
          printf("-1\n"); fflush(stdout);
        }
        hand_idx++;
      }

      if(hand_idx >= hands.size()) break;
    }
  }
}

Measured memory_bytes: 1308
A, B, K = list(map(int, input().split()))

res = set()

for i in range(K):
    num = A+i
    if A <= num <= B:
        res.add(num)
    num = B-i
    if A <= num <= B:
        res.add(num)

for num in sorted(res):
    print(num)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    std::ios::sync_with_stdio(false);
    int n;
    string s;
    cin>>n>>s;
    int ans=0,now=0;
    rep(i,0,n-1){
        if(s[i]=='I')
            now++;
        else now--;
        ans=max(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int r, d, x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x << endl;
	}
}


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

struct Edge {
    int to, coin;
    int64_t cost;
    Edge(int _to, int _coin, int64_t _cost) : to(_to), coin(_coin), cost(_cost) {}
};

const int MAX = 2525;
const int64_t INF = 1e18;

int main() {
    int N, M, S;
    cin >> N >> M >> S;
    vector<vector<Edge>> G(N);
    for(int i = 0; i < M; ++i) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        G[u].emplace_back(v, a, b);
        G[v].emplace_back(u, a, b);
    }
    vector<int> C(N), D(N);
    for(int i = 0; i < N; ++i) cin >> C[i] >> D[i];

    using V = tuple<int64_t, int, int>;
    priority_queue<V, vector<V>, greater<V>> que;
    vector<vector<int64_t>> dist(N, vector<int64_t>(MAX + 1, INF));
    S = min(S, MAX);
    dist[0][S] = 0;
    que.emplace(0, S, 0);

    auto push = [&](int v, int coin, int64_t cost) {
        if(coin >= 0 and dist[v][coin] > cost) {
            dist[v][coin] = cost;
            que.emplace(cost, coin, v);
        }
    };
    while(!que.empty()) {
        auto[cost, coin, cur] = que.top(); que.pop();
        for(auto &e : G[cur]) push(e.to, coin - e.coin, cost + e.cost);
        push(cur, min(coin + C[cur], MAX), cost + D[cur]);
    }

    for(int i = 1; i < N; ++i) cout << *min_element(dist[i].begin(), dist[i].end()) << '\n';
    return 0;
}


Measured memory_bytes: 6280
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;


int main(){
  ll h,w,k;cin>>h>>w>>k;
  vector<string> g(h);
  vvll ans(h,vll(w,0));
  ll tmp=1;
  rep(i,0,h){
    cin>>g[i];
    rep(j,0,w){
      
      if(g[i][j]=='#'){
        ans[i][j]=tmp;
        tmp++;
      }
    }
  }
  rep(i,0,h){
    rep(j,1,w){
      if(ans[i][j]==0){
        ans[i][j]=ans[i][j-1];
      }
    }
  }
  rep(i,0,h){
    drep(j,w-2,0){
      if(ans[i][j]==0){
        ans[i][j]=ans[i][j+1];
      }
    }
  }
  rep(i,0,w){
    rep(j,1,h){
      if(ans[j][i]==0){
        ans[j][i]=ans[j-1][i];
      }
    }
  }
  rep(i,0,w){
    drep(j,h-2,0){
      if(ans[j][i]==0){
        ans[j][i]=ans[j+1][i];
      }
    }
  }
  rep(i,0,h){
    rep(j,0,w){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }
}




Measured memory_bytes: 4512
def d_good_grid(N, C, D, c):
    # cの各要素は、0-indexedに対応するため入力から1引いている
    import collections
    import itertools

    # マスを (i+j)%3 で同一視したとき、
    # 同一視できるマスのそれぞれは最初何色で塗られているか
    colors = [collections.defaultdict(int) for _ in range(3)]
    for i, row in enumerate(c):
        for j, color in enumerate(row):
            colors[(i + j) % 3][color] += 1

    # strangeness[k][c]は値kで同一視できるマスをすべて色cで塗ったときの違和感の和
    strangeness = []
    for k in range(3):
        tmp = []
        for c in range(C):
            total = 0
            for color, num in colors[k].items():
                total += D[color][c] * num
            tmp.append(total)
        strangeness.append(tmp)

    # 色の一覧から3色選び、同一視できるマス3種をそれらで塗ってみる
    # 違和感が一番低かったものが解
    ans = float('inf')
    for c1, c2, c3 in itertools.permutations(range(C), 3):
        ans = min(ans, strangeness[0][c1] + strangeness[1][c2] + strangeness[2][c3])
    return ans

N, C = [int(i) for i in input().split()]
D = [[int(i) for i in input().split()] for j in range(C)]
c = [[int(i) - 1 for i in input().split()] for j in range(N)]
print(d_good_grid(N, C, D, c))

Measured memory_bytes: 5748
N, M = map(int, input().split())
A = [str(i) for i in range(1 * 10 ** (N - 1), 1 * 10 ** N)]
if N == 1:
  A.append('0')
for i in range(M):
  t = list(map(int, input().split()))
  A = [A[j] for j in range(len(A)) if int(A[j][t[0] - 1]) == t[1]]
print(-1 if (not A) == True else min(A))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
 
int main(){
    ll N;
  	ll ans = 0;
  	cin >> N;
  	vector<ll> A(N);
  	rep(i,N){
      cin >> A[i];
    }
  	rep(i,N){
      ans++;
      while(i+1<N&&A[i]==A[i+1]) i++;
      if(i==N-1) break;
      if(A[i]<=A[i+1]){
      	while(i+1<N&&A[i]<=A[i+1]) i++;
    	}else{
     	 while(i+1<N&&A[i]>=A[i+1]) i++;
    	}
      
    }
  	cout << ans << endl;
}

Measured memory_bytes: 1024
S = int(input())

T = []

runrun = 0

difference = 1000

while S != 0:
	T.append(S%10)
	S = S//10

for j in range(len(T)-2):
	runrun = T[j+2]*100 + T[j+1]*10 + T[j]
	difference = min(difference, abs(runrun-753))


print(difference)


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

int N,M;
int S[15];
int D[100];
int dp[1<<15];
int G[1<<15][100];
int F[1<<15];//sum ohuton
int T[100];

#define INF 1145141919
int main()
{
  while(true)
    {
      scanf("%d%d",&N,&M);
      if(N==0&&M==0)return 0;
      rep(i,N)scanf("%d",&S[i]);
      rep(i,M)scanf("%d",&D[i]);

      rep(i,1<<N)dp[i]=INF;
	
      dp[0]=0;
      rep(i,M)dp[0]+=D[i];
      rep(i,M)G[0][i]=0;
      rep(i,1<<N)
	{
	  F[i]=0;
	  rep(j,N)
	    {
	      if(i>>j&1)F[i]+=S[j];
	    }
	  //printf("%d ",F[i]);
	}
      //printf("\n");
      rep(i,1<<N)
	{
	  rep(j,N)
	    {
	      if((i>>j&1)==0)continue;
	      int k=1<<j^i;

	      int cnt=0; //hukai sum
	      rep(r,M)
		{
		  T[r]=G[k][r];//nukumori kyokyu
		  if(G[k][r]==F[k] && abs(F[k]-D[r])>abs(F[i]-D[r]))
		    {
		      T[r]=F[i];
		    }
		  cnt+=abs(T[r]-D[r]);
		}
	      if(cnt<dp[i])
		{
		  dp[i]=cnt;
		  rep(r,M)
		    {
		      G[i][r]=T[r];
		    }
		}
	    }
	}
      /*rep(i,1<<N)
	{
	  if(i==2||i==6||i==7||i==15)
	    {
	      printf("%d %d\n",i,dp[i]);
	      rep(r,M)
		{
		  printf("%d ",G[i][r]);
		}
	      printf("\n");
	    }
	    }*/	    
      printf("%d\n",dp[(1<<N)-1]);
    }
}

Measured memory_bytes: 16260
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long p = sc.nextLong();
        sc.close();

        if(n == 1){
            System.out.println(p);
            return;
        }

        int mn = 1000100;
        int[] num = new int[mn];
        int cur = 2;
        while(p >= cur){
            if(p % cur == 0){
                p /= cur;
                num[cur]++;
            }else{
                cur++;
            }
            if(cur >= mn) break;
        }

        int ans = 1;
        for(int i=1; i<mn; i++){
            if(num[i] >= n){
                ans *= Math.pow(i, (num[i] / n));
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 26068
import java.util.*;
import java.lang.*;
import java.io.*;

class Information{
	int x,y,h;
	public Information(int x, int y, int h){
		this.x = x;
		this.y = y;
		this.h = h;
	}
	
	
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Information[] info = new Information[N];
        for(int n=0;n<N;n++){
        	int x = sc.nextInt();
        	int y = sc.nextInt();
        	int h = sc.nextInt();
        	info[n] = new Information(x,y,h);
        }
        
        for(int cx=0;cx<=100;cx++)for(int cy=0;cy<=100;cy++){
        	int minH = 1;
        	int maxH = 1000000000+200;
        	boolean ok = true;
        	for(Information i:info){
        	    if(i.h==0){
        	    	int Hbound = Math.abs(i.x-cx)+Math.abs(i.y-cy);
        	    	if(minH>Hbound)ok = false;
        	    	maxH = Hbound;
        	    }else{
        	    	int H = Math.abs(i.x-cx)+Math.abs(i.y-cy)+i.h;
        	    	if(minH>H||maxH<H) ok=false;
        	    	else{
        	    		minH = H;
        	    		maxH = H;
        	    	}
        	    }
        	}
        	if(ok){
        		System.out.println(cx+" "+cy+" "+minH);
        		//return;
        	}
        }
    }
}


Measured memory_bytes: 22708
#include <cstdio>
int h, w, cnt;
char a[55][55];
int main() {
	int i, j, x, y;
	scanf("%d%d", &h, &w);
	for(i=1; i<=h; i++) scanf("%s", &a[i][1]);
	for(i=1; i<=h; i++, puts("")) for(j=1; j<=w; j++) {
		if(a[i][j]=='#') {printf("#"); continue;}
		cnt = 0;
		for(x=i-1; x<=i+1; x++) for(y=j-1; y<=j+1; y++) if(a[x][y]=='#') cnt++;
		printf("%d", cnt);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define ld long double
 
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin >> n;
    set<int> s;
    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        s.insert(x);
    }
    cout << ((s.size() == n) ? "YES\n" : "NO\n"); 
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
#define MAX_N 1002
using namespace std;
struct node{int x,y;};
char _map[MAX_N][MAX_N];
int dp[MAX_N][MAX_N];
int ox[]={0,0,1,-1};
int oy[]={1,-1,0,0};
int S_x,S_y;
int h,w,cnt;

node make_node(int x,int y){
    node t;
    t.x=x,t.y=y;
    return t;
}
void solve(){
    queue<node> que;
    int step=0;

    for(int i=1;i<=cnt;i++){
        que.push(make_node(S_x,S_y));
        _map[S_x][S_y]='.';
        memset(dp,-1,sizeof(dp));
        dp[S_x][S_y]=step;
        while(!que.empty()){
            node t=que.front();que.pop();
            if(_map[t.x][t.y]=='0'+i){
                step=dp[t.x][t.y];
                S_x=t.x,S_y=t.y;
                break;
            }
            for(int j=0;j<4;j++){
                int x=t.x+ox[j];
                int y=t.y+oy[j];
                if(0<=x&&x<h&&0<=y&&y<w&&_map[x][y]!='X'&&dp[x][y]==-1){
                    que.push(make_node(x,y));
                    dp[x][y]=dp[t.x][t.y]+1;
                }
            }
        }
        while(!que.empty()) que.pop();
    }

    printf("%d\n",step);
}

int main()
{
    while(scanf("%d%d%d",&h,&w,&cnt)!=EOF){
        for(int i=0;i<h;i++)
            scanf("%s",_map[i]);
        for(int j=0;j<h;j++)
            for(int k=0;k<w;k++)
                if(_map[j][k]=='S')
                    S_x=j,S_y=k,j=h,k=w;
        solve();
    }
    return 0;
}


Measured memory_bytes: 7592
import math

K = int(input())

gcd2 = [[0 for i in range(K)] for i in range(K)]

for i in range(K):
    for j in range(K):
        gcd2[i][j] = math.gcd(i+1,j+1)

sum = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            sum += math.gcd(gcd2[i][j],k+1)

print(sum)


Measured memory_bytes: 9440
#include<bits/stdc++.h>
#define REP(n)    for(int i = 0; i < (n); ++i)
#define RREP(n)   for(int i = (n); i >= 0; --i)
#define FOR(m, n) for(int i = (m); i < (n); ++i)
#define SZ(x)       ( (int)(x).size() )
#define BIT(n)      ( 1LL << (n) )
#define EXIST(x)    ( (x).find()		!= (x).end() )
#define DEBUG(n)    cerr << #n << " : " << n << '\n';
#define PB  push_back
#define UB  upper_bound			//k <
#define LB  lower_bound			//k	<= 
#define F   first
#define S   second
#define INF 1.0e9


using namespace std;

typedef long long			ll;
typedef pair<int, int>		pii;
typedef pair<long			long, long long>   pll;
typedef vector<int>			vi;
typedef vector<double>		vd;
typedef vector<long long>   vll
;

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

int r_up(const int a, const int b){ return (a + b - 1) / b; }

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

struct UFT{
  vi	p;
  UFT(){}
  UFT(int N)       { p.resize( N, -1 ); }
  int	par(int a)   { if( p[a] >= 0 ){ p[a]  = par( p[a] ); return p[a]; } return a;  }
  int size(int a)  { return -p[par(a)]; }
  bool	same(int a, int b) { return par(a)	 == par(b); }
  void unite(int	a, int b){
	a													  = par(a);  b = par(b);
	if( a == b ) return;
	if( size(a) < size(b) ) swap(a,b);
	p[a]												 -= size(b);
	p[b]												  = a;
  }
};

int main(){
  int n,k;cin>>n>>k;
  vll h(n);
  REP(n)cin>>h[i];
  sort(h.begin(),h.end());
  ll ans=INF;
  FOR(0,n-k+1){
	chmin(ans,h[i+k-1]-h[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

int main() {
	LL a, b, c, k;
	
	cin>>a>>b>>c>>k;
	
	LL sum = 0;
	if(k>0 && k >= a) {
		sum += a;
		k-=a;
		if(k > 0 && k>= b) {
			k-=b;
		} else k = 0;
		
		if(k > 0 && k>= c) {
			sum -= c;
			k-=c;
		} else {
			sum -= k;
			k=0;
		}
	} else {
		sum = k;
	}
	
	cout<<sum<<endl;

    return 0;
}



Measured memory_bytes: 3620
import math
MAX=104729
ROOT=int(math.sqrt(MAX))

#素数以外をはじく
prime=[True for i in range(MAX+1)]

def prime_list(prime):
    #2は除外
    for i in range(2,MAX,2):
        prime[i]=False
    #要素を持つか
    for x in range(3,ROOT+1):
        if prime[x]==True:
            for j in range(x*x,MAX,x):
                prime[j]=False
                
prime_list(prime)

total=[0 for g in range(MAX)]
def append(total):
    j=total[1]=2
    for i in range(3,len(prime)):
        if prime[i]==True:
            total[j]+=total[j-1]+i
            j+=1

append(total)


while True:
    n=int(input())
    if n==0:
        break
    print(total[n])





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

const int N = (20) + 5;
int a[N][N];

int main() { // claudio van
  int H, W; scanf("%d %d", &H, &W);
  int h, w; scanf("%d %d", &h, &w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < W; ++j) {
      a[i][j] = 1;
    }
  }
  for (int i = 0; i < w; ++i) {
    for (int j = 0; j < H; ++j) {
      a[j][i] = 1;
    }
  }
  int ans = H * W;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      ans -= a[i][j];
    }
  }
  printf("%d\n", ans);
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N, K;
  long long mood = 1000000007;
  long long ans = 0;
  cin >> N >> K;
  if(N + 1 == K){
    ans = 1;
  }else{
    long long start = 0, end = 0;
    for(int j = 0; j <= N; j++){
      start += j;
    }
    end = start;
    for(int i = N + 1, q = N, qq = 0; i >= K; i--, q--, qq++){
      ans += (start - end) + 1;
      start -= qq;
      end -= q;
      if(ans >= mood){
        ans %= mood;
      }
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		String numStr = sc.next();
		int K = sc.nextInt();
		
		int len = numStr.length();
		
		//dp[i][j][k] 上からi桁まで見て、そこまでで非零をj回使い、
		//k = 0 : そこまでNと一致している場合 k = 1 : そこまででk以下が確定しているとき
		int dp[][][] = new int[len + 1][K + 1][2];
		dp[0][0][0] = 1;
		
		for(int i = 0; i < len; i++) {
			int tmpNum = numStr.charAt(i) - '0';
			for(int j = 0; j <= K; j++) {
				for(int k = 0; k <= 1; k++) {
					for(int l = 0; l <= 9; l++) {
						int nextI = i + 1;
						int nextJ = j;
						if(l > 0) {
							nextJ++;
							if(nextJ > K) {
								continue;
							}
						}
						int nextK = k;
						if(k == 0) {
							if(l > tmpNum) {
								continue;
							}
							if(l < tmpNum) {
								nextK = 1;
							}
						}
						
						dp[nextI][nextJ][nextK] += dp[i][j][k];
					}
				}
			}
		}
		
		//debug
		/*
		for(int i = 0; i <= K; i++) {
			for(int j = 0; j <= len; j++) {
				System.out.print(dp[j][i][0]+" ");
			}
			System.out.println();
		}
		for(int i = 0; i <= K; i++) {
			for(int j = 0; j <= len; j++) {
				System.out.print(dp[j][i][1]+" ");
			}
			System.out.println();
		}
		*/
		System.out.println(dp[len][K][0] + dp[len][K][1]);
	}
}


Measured memory_bytes: 27084
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
w = ils(n, "input()")
ans = 1
if len(set(w)) != n:
    ans = 0
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        ans = 0
print("Yes" if ans else "No")

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

using namespace std;

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

	auto seen = set<int>{};
	while (K--) {
		int D; cin >> D;

		seen.insert(D);
	}

	auto search = true;
	auto i = N;
	while (search) {
		auto haha = true;
		for (auto j = i; j > 0; j /= 10) {
			if (seen.count(j % 10)) {
				haha = false;
				break;
			}
		}

		search = !haha;
		++i;
	}

	cout << i - 1 << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int n,m,a=1;;
    scanf("%d%d",&n,&m);
    for(;n>0;--n){
        if(a<=m){
            a+=a;
        } else {
            a+=m;
        }
    }
    printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define jkl int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    ll n, k;
    bool d[12] = {};
    ll D;
    cin >> n >> k;
    REP(i, k){
        cin >> D;
        d[D] = true;
    }
    ll ans = n;
    ll now;
    bool f;
    while(1){
        f = true;
        now = ans;
        while(now > 0){
           if(d[now % 10]){
               f = false;
               break;
           }
           now /= 10;
        }
        if(f){
            print(ans);
            break;
        }
        ans++;
    }
}



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

using namespace std;

int main(int argc, char const* argv[]) {
  int n, k;
  cin >> n;
  cin >> k;

  string s;
  cin >> s;

  long count = 0;
  char flag = s[0];
  for (int i = 0; i < n; i++) {
    if (s[i] == flag)
      continue;
    else if (k > 0) {
      //cout << i << " ";
      int j = i;
      char vert = s[i];
      while (s[j] == vert && j < n) {
        s[j] = flag;
        j++;
      }
      k--;
      count++;
      i = j;
    }
  }

  //cout << s << endl;

  long happy = 0;
  if (s[0] == s[1] && s[0] == 'R')
    happy++;
  if (s[n - 1] == s[n - 2] && s[n - 1] == 'L')
    happy++;
  for (int i = 1; i < n - 1; i++) {
    if (s[i] == 'R') {
      if (s[i + 1] == 'R')
        happy++;
    }
    if (s[i] == 'L') {
      if (s[i - 1] == 'L')
        happy++;
    }
  }

  cout << happy << endl;

  return 0;
}


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


using namespace std;
double pi=3.14159265358979323846264338;
long long sum;
long long ma;
long long n,k,st,x,t;
long long arr[200001];
string s;
long long pr(long long a, long long b){
	long long k=1;
	if(b==0)return 1;
	
	for(int i=0;i<b;i++)k=k*10;
	return k;
}

bool che(long long a){
	long long cur=0;
	for(int i=0;i<n;i++){
		cur+=(arr[i]+a-1)/(a)-1;
	}
	if(cur<=k)return true;
	return false;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>arr[i];
	k=arr[0];
	x=0;
	for(int i=1;i<n;i++){
		k=max(arr[i],k);
		x+=k-arr[i];
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 5192
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int a=s.nextInt();
		int b=s.nextInt();
		int h=s.nextInt();
		
		System.out.print((a+b)*h/2);

	}

}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cstdio>
#define MAXN 2000005
#define LL long long
#define mod 1000000007
using namespace std;

int n;
LL fac[MAXN], inv[MAXN], ans, last;

int main()
{
    scanf("%d", &n);
    fac[0]=fac[1]=1; inv[0]=inv[1]=1;
    for(int i=2; i<=n; i++) fac[i]=(fac[i-1]*i)%mod;
    for(int i=2; i<=n; i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2; i<=n; i++) inv[i]=inv[i-1]*inv[i]%mod;
    for(int i=(n+1)/2; i<n; i++)
    {
        LL com=fac[i-1]*inv[n-i-1]%mod*inv[2*i-n]%mod;
        LL temp=com*fac[i]%mod*fac[n-i-1]%mod;
        ans=(ans+(mod+temp-last)%mod*i)%mod;
        last=temp;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 18688
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int a,b,c;cin>>a>>b>>c;
  int x;
  x = a*b/2;
  if(x>b*c/2){x=b*c/2;}
  if(x>a*c/2){x=a*c/2;}
  cout<<x<<endl;

}

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

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define debug(a) cerr << #a << ": " << a << endl
#define umii unordered_map<int64_t,int64_t>
#define ftt int t;cin>>t;for(int tt=1;tt<=t;++tt)
#define forr(i,n) for((i)=1;(i)<=(n);(i)++)
#define Rev(v) reverse(v.begin(),v.end());
#define Sort(v) sort(v.begin(),v.end());
#define mem(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<"\nhi"<<x<<"\n"
#define pq priority_queue<int>
#define dbg cout<<"\nhi\n"
#define sayy cout<<"YES\n"
#define sayn cout<<"NO\n"
#define int long long
#define double long double
#define pii pair<int,int>
#define mii map<int,int>
#define vb vector<bool>
#define vi vector<int>
#define eb emplace_back
#define nl cout<<"\n"
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define sp <<" "<<
#define se second
#define fi first

const int MOD = 1000000007;
const double PI = 3.1415926535898;
const int LIM = 100005;

using namespace std;

int fpow( int x,int y) {
    int temp;
    if(y == 0)
        return 1;
    temp = fpow(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;}

int gcd(int a,int b) {
    if(b==0)return a;
    return gcd(b,a%b);}

void sieve(int n) {
     bool prime[5*LIM];
     memset(prime, true, sizeof(prime));
     for (int p=2; p*p<=n; p++)
          if (prime[p] == true)
               for (int i=p*p; i<=n; i += p)
                    prime[i] = false;
     prime[1]=0;}

inline int read(){
    int p=1,ans=0;
    char ch=getchar();
    while(ch<48||ch>57)
    {
        if(ch=='-')p=-1;
        ch=getchar();
    }
    while(ch>=48&&ch<=57)
    {
        ans=(ans<<3)+(ans<<1)+ch-48;
        ch=getchar();
    }
    return ans*p;
}

unsigned long long fun(unsigned long long n)
{
    return (n*(n+1))/2;
}

/*int cnt, sum = 0, mid, mx = -1e17, mn = 1e17, a[2*LIM];
int n, m, d, t, i, j, k, l, r, x, y, z;
bool f, f1, f2;
string s;*/

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


int32_t main()
{

    vi v(5);
    for(int &x : v)
        cin>>x;
    auto itr = find(v.begin(),v.end(),0);
    cout<<itr - v.begin() + 1;
     return 0;
}





Measured memory_bytes: 3600
#include<stdio.h>
#include<string.h>
int main(){
  int a,b,flag=0,i,j;
  char s[110],t[110];
  scanf("%s",s);
  scanf("%s",t);
  a=strlen(s);
  for(i=0;i<a;i++){
    for(j=0;j<a;j++){
      if(s[(i+j)%a]!=t[j])
        break;
    }
    
    if(j==a){
      flag=1;
      break;
    }
  }
  if(flag)
    printf("Yes\n");
  else
    printf("No\n");
}

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

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI crowd(360);
  REP(diesirae, 0, n) {
    int m, d, v, s;
    cin >> m >> d >> v >> s;
    int dat = 30 * (m - 1) + d - 1;
    VI eff(360, 0);
    REP(i, 0, v) {
      eff[(dat + i) % 360] = s;
    }
    REP(i, 0, s) {
      int &r = eff[(dat - i + 360 + 359) % 360];
      r = max(r, s - i - 1);
    }
    REP(i, 0, s) {
      int &r = eff[(dat + v + i + 360) % 360];
      r = max(r, s - i - 1);
    }
    REP(i, 0, 360) {
      crowd[i] = max(crowd[i], eff[i]);
    }
  }
  int mi = 10000;
  REP(i, 0, 360) {
    mi = min(mi, crowd[i]);
  }
  cout << mi << endl;
}

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <numeric>
#include <queue>
#include <stack>

using namespace std;
using ll = long long;

int main() {

	ll q, h, s, d, n, X;

	cin >> q >> h >> s >> d;
	cin >> n;

	X = min(2 * q, h);
	X = min(2 * X, s);

	cout << min(d*(n / 2) + X*(n % 2), n*X) << endl;
	return 0;
}

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

void max_self(long long& a , long long b){
    a = std::max(a , b);
}

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

    int n , W;
    std::cin >> n >> W;

    std::vector<long long> dp(W + 1);
    //dp[i] = maximum total value of items with total weight exactly
    for(int item = 0 ; item < n ; ++item){
        int weight , val;
        std::cin >> weight >> val;
        for(int weight_used = W - weight ; weight_used >= 0 ; --weight_used){
            max_self(dp[weight_used + weight] , dp[weight_used] + val);
        }
    }

    long long sol = 0;
    for(int i = 0 ; i <= W ; ++i){        
        max_self(sol , dp[i]);
    }    

    std::cout << sol << '\n';

}

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

int main() {
	int N, M;
	cin >> N >> M;
	int	total;
	total = (N + M) * (N + M - 1) / 2;
	cout << total - N * M;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    int ans = 0;
    switch(x){
    case 1:
        ans += 100000;
    case 2:
        ans += 100000;
    case 3:
        ans += 100000;
    }
    switch(y){
    case 1:
        ans += 100000;
    case 2:
        ans += 100000;
    case 3:
        ans += 100000;
    }
    ans += 400000 * (x * y == 1);
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <assert.h>
#include <cstdio>

// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

inline bool chmin(ll &a, ll b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

inline bool chmax(ll &a, ll b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//桁数取得
template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}
//整数乗
ll llpow(ll a, ll n)
{
    if (n == 0)
    {
        return 1;
    }
    else
    {
        ll rep = a;
        for (ll i = 1; i < n; i++)
        {
            rep *= a;
        }
        return rep;
    }
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

template <typename T>
T amarinasi(T a, T b)
{
    if (a % b == 0)
    {
        return a / b;
    }
    else if (a % b > 0)
    {
        return a / b + 1;
    }
    else
    {
        return a / b - 1;
    }
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------
const double pi = 3.14159265358979323846264;
map<ll, map<ll, ll>> rensou;
map<ll, bool> tansakuzumi;
vector<ll> dist(100010, infll);
vector<vector<ll>> g(100010, vector<ll>());
bool dame = false;
void dfs(ll v)
{
    tansakuzumi[v] = true;
    for (auto f : g[v])
    {
        if (dist[f] == infll)
        {
            dist[f] = dist[v] + rensou[v][f];
        }
        else
        {
            if (dist[f] != dist[v] + rensou[v][f])
            {
                dame = true;
            }
        }
        if (tansakuzumi[f] == true)
        {
            continue;
        }
        dfs(f);
    }
}

int main()
{
    ll n, m;
    cin >> n >> m;

    for (ll i = 0; i < m; i++)
    {
        ll l, r, d;
        cin >> l >> r >> d;
        g[l - 1].push_back(r - 1);
        g[r - 1].push_back(l - 1);
        rensou[l - 1][r - 1] = d;
        rensou[r - 1][l - 1] = -1 * d;
    }
    for (ll i = 0; i < n; i++)
    {
        if (tansakuzumi[i] == false)
        {
            dist[i] = 0;
            dfs(i);
        }
    }
    if (dame)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

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

int gcd(int x, int y){
    if(x < y) swap(x, y);
    while(y > 0){
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(){
    int k;
    cin >> k;
    ll sum = 0;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632