akhauriyash/Code-Regression huggingface dataset:
#include<iostream>//基本
#include<algorithm>//min,maxとか
#include<vector>//配列
#include<string>//文字化
#include<cmath>//
#include<map>//map<int,int>toka
#include<iomanip>//
#include<numeric>//
#include<queue>//
#include<functional>//
#include<tuple>//3tuizyounokumidemoOK
#include<math.h>//
#include<bitset>//
#include<stack>//
#include<set>//新しいものしか受け取らない配列
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define ld long double
#define sec setprecision　//小数点以下何位まで知りたいか
#define mod 1000000007
#define pi 3.1415926
using namespace std;
int gcd(int a, int b)//最大公約数
{if (a % b == 0)	return(b);
	else return(gcd(b, a % b));}
int lcm(int a, int b)//最小公倍数
{return a * b / gcd(a, b);}
ll pow(ll a, ll b) {ll k = b % 30000, h = b / 30000, s = 1;
	rip(i, 30000)s = (s * a) % mod; ll j = 1;
	if (h != 0)rip(i, h)j = j * s % mod;
	if (k != 0)rip(i, k)j = j * a % mod;
	return(j);}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>a(n);
	int maxx = 0;
	rip(i, n)cin >> a[i], maxx = max(maxx, a[i]);
	int gg = a[0];
	rip(i, n)gg = gcd(gg, a[i]);
	if (k <= maxx && k % gg == 0)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

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


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

  string S;
  cin >> S;

  if (S.size() <= K) {
    cout << S << endl;
  } else {
    cout << S.substr(0, K) << "..." << endl;
  }

  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

#define rep(i,n) for(int (i)=0;(i)<(n); ++(i))
using namespace std;

int main() {
    int n, x, t;
    cin >> n >> x >> t;

    int count = 0;

    while(count*x < n) {
        count++;
    }

    cout << count*t << endl;
    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int ar[3][3];
    int y=1;
    for (int i=0;i<3;i++)
    {
        for (int j=0;j<3;j++)
        {
            cin>>ar[i][j];
        }
    }
    for (int i=0;i<2;i++)
    {
        if (ar[i][0]-ar[i][1]!=ar[i+1][0]-ar[i+1][1]||ar[i][1]-ar[i][2]!=ar[i+1][1]-ar[i+1][2])
        {
            y=0;
        }
    }
    if (y==0)printf ("No\n");
    else printf ("Yes\n");
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
	int k, x;
	scanf("%d%d", &k, &x);
	if (500 * k >= x) printf("Yes\n");
	else printf("No\n");
}



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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x; cin >> x;
	string res = "ai1333";
	REP(i, x / 100)res += '3';
	cout << res << endl;
}


Measured memory_bytes: 3184
#include <stdio.h>
int main(void)
{
long long int n,a,b,x,min,max,num;
scanf("%lld %lld %lld",&n,&a,&b);
x=b-a;
if(x<0){
  num=0;
}else if(x==0){
  num=1;
}else if(n==1){
  num=0;
}else{
  min=(a*(n-1))+b;
  max=a+(b*(n-1));
  num=max-min+1;
}
printf("%lld",num);

return 0;
}

Measured memory_bytes: 128
def main():
    from heapq import heapify, heappush, heappop
    from math import floor
    n, m = list(map(int, input().split(' ')))
    a = list(map(int, input().split(' ')))
    a = [x*(-1) for x in a]
    heapify(a)
    for _ in range(m):
        x = floor(-heappop(a)/2)*(-1)
        heappush(a, x)
     
    print(-sum(a))
main()

Measured memory_bytes: 15148
#include <stdio.h>

int main()
{
 char st[10005];
 int i;
 int stlen=0;
 int alphabet[26];
 char ch;
 int none=0;

 for(i=0;i<26;i++) alphabet[i]=0;
 
 for(i=0;i<10000;i++)
 {
  scanf("%c",&st[i]);
  if((st[i]<'a')|(st[i]>'z')) break;
  stlen++;
  alphabet[st[i]-'a']++;
 }

 for (i=0;i<26;i++)
 {
   if(alphabet[i]==0)
   {
     ch = i+'a';
     printf("%c\n",ch);
     none=1;
     break;
   }
 }

 if(none==0) printf("None\n");

 return 0;
}


Measured memory_bytes: 128
n = int(input())
p = list(map(int, input().split()))
count = 0

n_slist = sorted(range(n+1)[1:])

for i in range(n):
    if p[i] != n_slist[i]:
        count += 1

if count > 2:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3060
#include <stdio.h>
 
int main() {
    int n, cards[4][13], i, j, number;
    char card;
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 13; j++) {
            cards[i][j] = 0;
        }   
    }   
    scanf("%d", &n);
    getchar();
    for (i = 0; i < n; i++) {
        scanf("%c %d", &card, &number);
        getchar();
        switch (card) {
            case 'S':
                cards[0][number - 1] = 1;
                break;
            case 'H':
                cards[1][number - 1] = 1;
                break;
            case 'C':
                cards[2][number - 1] = 1;
                break;
            case 'D':
                cards[3][number - 1] = 1;
                break;
        }   
    }   
    for (i = 0; i < 4; i++) {
        switch (i) {
            case 0:
                card = 'S';
                break;
            case 1:
                card = 'H';
                break;
            case 2:
                card = 'C';
                break;
            case 3:
                card = 'D';
                break;
        }   
        for (j = 0; j < 13; j++) {
            if (!cards[i][j]) {
                printf("%c %d\n", card, j + 1); 
            }   
        }   
    }   
    return 0;
}

Measured memory_bytes: 600
n,d = map(int, input().split())
a =[[int(x) for x in input().split()] for i in range(n)]
cnt =0
sei = [i*i for i in range(10000)]

for i in range(n):
  for j in range(i):
    dis = sum( [((a[i][k] - a[j][k] )*(a[i][k] - a[j][k])) for k in range(d)])
    if dis in sei:
        cnt +=1
print(cnt)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
bool N, W, S, E;
int main() {
    cin>>s;

    REP(i, 0, s.size()){
        if(s[i]=='N') N=true;
        else if(s[i]=='W') W=true;
        else if(s[i]=='S') S=true;
        else E=true;
    }

    if((N && W && S && E) || (N && !W && S && !E) || (!N && W && !S && E)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-c) <= d) {
        cout << "Yes" << endl;
        return 0;
    }
    if(abs(a-b) <= d && abs(c-b) <= d) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}   

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a[10];
	int i=0,j=0;
	for(int i=0;i<10;i++)
	{
	    cin>>a[i];
	}
	for(i=0;i<3;i++)
	{
		for(j=0;j<9-i;j++)
		{
			if(a[j]>a[j+1])
			{
				int temp;
				temp=a[j+1];
				a[j+1]=a[j];
				a[j]=temp;
			}
		}
	 } 
	for(int i=9;i>6;i--)
	{
	    cout<<a[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){
 
  string s;
  cin>>s;
  vector<char> v;

  if(s.size()==1){ 
    cout<<"0"<<endl;
    return 0;
  }
  REP(i, s.size()-1){
    if(s[i] != s[i+1]) v.push_back(s[i]);
    if(i==s.size()-2) v.push_back(s[i+1]);
  }
  //if(v.size()!=1)
   cout<<v.size()-1<<endl;
  //else cout<<"0"<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define inf (1LL<<57)
#define PII pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
const long long mod = 1e9 + 7;
typedef unsigned long long ull;
using namespace std;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
#define DBG cerr << "debug here" << endl;
#define DBGV(vari) cerr << #vari<< " = "<< (vari) <<endl;
/*============================================================================
rk
Deependra Chourasia
IIT(ISM) DHANBAD
16je001916

============================================================================
*/


int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll n;cin>>n;
    
    vector<int> a(n),b(n),v(n);
    for(int i=0;i<n;i++)cin>>a[i],v[i]=a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    
    sort(v.begin(),v.end());
    
    // for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl;
    
    int x=-1,y=-1;
    int cnt=1;
    do{
        if(v == a & x== -1)x = cnt;
        if(v == b && y == -1)y = cnt;
        
        cnt++;
        
    }
    while(next_permutation(v.begin(),v.end()));
    
    cout<<abs(x-y)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int a[3][105];
	for(int i=0;i<2;i++){
		for(int j=0;j<n;j++){
			cin >> a[i][j];
		}
	}
	int ame = 0;
	int ans = 0;
	for(int i=0;i<n;i++){
		ame = 0;
		for(int j=0;j<=i;j++){
			ame += a[0][j];
		}
		for(int j=i;j<n;j++){
			ame += a[1][j];
		}
		ans = max(ans, ame);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}
 
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return mod(x, m);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m%MOD*COM(m-1,n)%MOD*modinv(m-n,MOD)%MOD;
}
 
int main()
{
  ll n,v[120000],u[120000],w[120000],uu[120000],ww[120000],uuu,www,uuuu,wwww;
  cin >> n;
  uuu=0;
  www=0;
  uuuu=594655422;
  wwww=654453664;
  rep(i,110000)u[i]=0;
  rep(i,110000)w[i]=0;
  rep(i,n)cin >> v[i];
  rep(i,n/2)u[v[2*i]]++;
  rep(i,n/2)w[v[2*i+1]]++;
  rep(i,110000)uu[i]=u[i];
  rep(i,110000)ww[i]=w[i];
  sort(ww,ww+110000);
  sort(uu,uu+110000);
  rep(i,110000)if(u[i]==uu[109999]){uuu++;
                                    uuuu=i;
                                   }
  rep(i,110000)if(w[i]==ww[109999]){www++;
                                    wwww=i;
                                   }
  if(uuu==1&&www==1&&uuuu==wwww)printf("%lld",n-max(uu[109998]+ww[109999],uu[109999]+ww[109998]));
  else printf("%lld",n-(uu[109999]+ww[109999]));
}

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

constexpr int mod = 1e9 + 7;

int main() {
    string t, b;
    cin >> t >> b;
    const int n = t.size(), m = b.size();

    vector<int> dp(m + 1);
    dp[0] = 1;
    for(int i = 0; i < n; ++i) {
        vector<int> nxt(m + 1);
        for(int j = 0; j < m; ++j) {
            if(t[i] == b[j]) {
                (nxt[j + 1] += dp[j]) %= mod;
            }
            (nxt[j] += dp[j]) %= mod;
        }
        (nxt[m] += dp[m]) %= mod;
        dp = move(nxt);
    }
    cout << dp.back() << endl;
}



Measured memory_bytes: 3200
h,w=map(int,input().split())
if h==1 or w==1:
    print(1)
    exit()
if h%2+w%2==0:
    print((h//2)*w)
elif h%2==1 and w%2==0:
    print((w//2)*h)
elif w%2==1 and h%2==0:
    print((h//2)*w)
else:
    print((h//2+1)*(w-w//2)+(h//2)*(w//2))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    int ans = 0;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {
        for (int j = 1; j <= s.size(); j++) {
            string t = s.substr(i, j);
            int cnt = 0;
            cnt += count(t.begin(), t.end(), 'A');
            cnt += count(t.begin(), t.end(), 'T');
            cnt += count(t.begin(), t.end(), 'C');
            cnt += count(t.begin(), t.end(), 'G');
            if (cnt == t.size() && cnt > ans) {
                ans = cnt;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {

  val Array(n,k) = readLine().split(" ").map(_.toInt)
  val h = readLine().split(" ").map(_.toInt)
  def solve() = {
    val dp = Array.fill(n)(Int.MaxValue)
    for(i <- 0 until n) {
      if(i == 0) dp(i) = 0
      else {
        val start = Math.max(0, i-k)
        for(j <- start until i) {
          dp(i) = Math.min(dp(i), dp(j) + (h(i) - h(j)).abs)
        }
      }
    }
    dp(n-1)
  }

  println(solve())

}



Measured memory_bytes: 62604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
string a[500];
string red[500];
string blue[500];
int main() {
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> a[i];
		red[i].resize(W);
		blue[i].resize(W);
		if (i % 2) {
			for (int j = 1; j < W; j++) red[i][j] = '#', blue[i][j] = '.';
			red[i][0] = '.';
			blue[i][0] = '#';
		}
		else {
			for (int j = 0; j + 1 < W; j++) red[i][j] = '.', blue[i][j] = '#';
			red[i][W - 1] = '#';
			blue[i][W - 1] = '.';
		}
		for (int j = 0; j < W; j++) if (a[i][j] == '#') red[i][j] = blue[i][j] = '#';
	}
	for (int i = 0; i < H; i++) {
		cout << red[i] << endl;
	}
	cout << endl;
	for (int i = 0; i < H; i++) {
		cout << blue[i] << endl;
	}
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,ans=0;
    cin>>n;
    vector<string> s(n);
    vector<int> t(n);
    for (int i = 0; i < n; i++)
    {
        cin>>s[i]>>t[i];
    }
    string x;
    cin>>x;
    bool flag=false;
    for (int i = 0; i < n; i++)
    {
        if(flag==true)
        {
            ans+=t[i];
        }
        else if(x==s[i])
        {
            flag=true;
        }
    }
    cout<<ans<<endl;
        
    return 0;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

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

int main()
{
  int x, n, tmp = 1, ans = 200;
  vector<int> p(100);
  bool flag = true;

  cin >> x >> n;
  for (int i = 0; i < n; i++)
  {
    cin >> p[i];
    if (p[i] == x)
      flag = false;
  }
  if (flag)
    ans = x;
  while (ans == 200)
  {
    flag = true;
    for (int i = 0; i < n; i++)
    {
      if (x + tmp == p[i])
        flag = false;
    }
    if (flag)
      ans = x + tmp;
    flag = true;
    for (int i = 0; i < n; i++)
    {
      if (x - tmp == p[i])
        flag = false;
    }
    if (flag)
      ans = x - tmp;
    tmp++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){

  int x, y, i;

  while ( 1 ) {

    cin >> x >> y ;

    if ( x==0 && y==0) break;
    if ( x < y ) cout << x <<" "<< y << "\n";
    else cout << y <<" "<< x << "\n";

  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> a(N);
  int div2 = 0;
  int div4 = 0;
  rep(i, N) {
    cin >> a[i];
    if (a[i] % 4 == 0) div4++;
    else if (a[i] % 2 == 0) div2++;
  }

  if (div2 == N) {
    cout << "Yes" << endl;
    return 0;
  }

  if (div4 == 0) {
    cout << "No" << endl;
    return 0;
  }

  if (div4 * 2 + 1 >= N) {
    cout << "Yes" << endl;
    return 0;
  }

  if (div4 * 2 + div2 >= N) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;

  return 0;
}


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

#define MAX 100

int main(void)
{
  int n,p,i,isi;
  int a[MAX];

  while(1)
    {
      scanf("%d %d",&n,&p);
      if(n==0)
	{
	  break;
	}
      else
	{
	  for(i=0;i<=n-1;i++)
	    {
	      a[i] = 0;
	    }
	  i = 0;
	  isi = p;
	  while(1){
	    if(isi!=0)
	      {
		isi = isi-1;
		a[i] = a[i]+1;
		
		if(isi==0 && a[i]==p)break;
	      }
	    else
	      {
		if(a[i]!=0)
		  {
		    isi = a[i];
		    a[i] = 0;
		  }
	      }
	    i++;
	    if(i>n-1)
	      {
		i = 0;
	      }
	  }
	  printf("%d\n",i);
	}
      
    }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    while(1){
        string s; cin >> s;
        int num = 0;
        if(s == "#") break;
        int a, b, c, d; cin >> a >> b >> c >> d;
        string str = "";
        for(int i = 0; i < (int)s.size(); i++){
            if(s[i] == 'b') str = str + "b";
            else if(s[i] != '/'){
                int val = stol(s.substr(i, 1));
                for(int i = 0; i < val; i++) str = str + ".";
            }else if(num == 0){
                num = (int)str.size();
            }
        }

        str[(a - 1) * num + (b - 1)] = '.';
        str[(c - 1) * num + (d - 1)] = 'b';

        string ans = "";
        for(int i = 0; i < (int)str.size(); i += num){
            string t = str.substr(i, num);
            t = t + "b";
            int val = 0;
            for(int j = 0; j < (int)t.size(); j++){
                if(t[j] == 'b'){
                    if(val != 0) ans = ans + to_string(val);
                    val = 0;
                    if(j != (int)t.size() - 1) ans = ans + "b";
                }else{
                    val++;
                }
            }

            ans = ans + "/";
        }

        cout << ans.substr(0, (int)ans.size() - 1) << endl;

    }
    return 0;
}




Measured memory_bytes: 3212
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007
using namespace std;
int main(){
    vector<int> num;
    int inputNum;
    while(true){
        cin>>inputNum;
        if(inputNum==0){
            break;
        }
        num.push_back(inputNum);
    }
    int n=num.size();
    rep(i,n){
        cout<<"Case "<<i+1<<": "<<num[i]<<endl;
    }
}


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

string rotate(string s){
  string rotated_s = s.at(s.size()-1) + s.substr(0, s.size()-1);
  return rotated_s;
}

int main() {
  string s,t;
  cin>>s>>t;
  if(s==t){
    cout<<"Yes"<<endl;
    return 0;
  }
  for(int i;i<(s.size()-1);i++){
    s=rotate(s);
    if(s==t){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    S = deque(sr())
    Q = ir()
    rev = 1
    for i in range(Q):
        T = list(sr().split())
        if int(T[0]) == 1:
            rev *= -1
        else:
            x, F, C = T
            if int(F) == 1:
                if rev == 1:
                    S.appendleft(C)
                else:
                    S.append(C)
            else:
                if rev == 1:
                    S.append(C)
                else:
                    S.appendleft(C)
    if rev == -1:
        S.reverse()
    print(*S, sep='')
resolve()

Measured memory_bytes: 12264
#グラフの連結成分を調べる
def Graph(ab):
    G=[[] for i in range(n)]
    for a,b in ab:
        G[a-1].append(b)
        G[b-1].append(a)
    return G

#BFS
from collections import deque, defaultdict
def bfs(G, v, p):
    q=deque()
    q.append((v, p, 0))

    while q:
        #qの先頭を取り出す
        V, P, C = q.popleft()
        next_color = 1 if C != 1 else 2
        for next_v in G[V - 1]:
            if next_v == P:continue
            if next_color == C:next_color += 1

            q.append((next_v, V, next_color))
            color[(V, next_v)] = next_color
            next_color += 1


n = int(input())
ab = [tuple(map(int,input().split())) for i in range(n - 1)]
color = defaultdict(lambda :1)

G = Graph(ab)
#print(G)
color_num = 0
for i in G:
    temp = len(i)
    if temp > color_num:color_num = temp

print(color_num)
bfs(G, 1, -1)

for i in ab:
    print(color[i])

Measured memory_bytes: 98008
#include "bits/stdc++.h"
using namespace std;
typedef int li;

const li inf = 1 << 29;

li dp[2000][2000];
li dp_maxx[2000];
li dp_maxy[2000];
li dp_max = -inf;

void update(const li x, const li y, const li v) {
    dp[x][y] = max(dp[x][y], v);
    dp_maxx[y] = max(dp_maxx[y], v);
    dp_maxy[x] = max(dp_maxy[x], v);
    dp_max = max(dp_max, v);
};

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

    li n;
    cin >> n;
    vector<li> xs(3 * n);
    for (int i = 0; i < 3 * n; ++i) {
        cin >> xs[i];
        xs[i]--;
    }

    for (int i = 0; i < n; ++i) {
        dp_maxx[i] = -inf;
        dp_maxy[i] = -inf;
        for (int j = 0; j < n; ++j) {
            dp[i][j] = -inf;
        }
    }

    update(xs[0], xs[1], 0);

    li offset = 0;
    for (int itr = 0; itr < n - 1; ++itr) {
        const li p = xs[2 + itr * 3];
        const li q = xs[2 + itr * 3 + 1];
        const li r = xs[2 + itr * 3 + 2];

        // add, use 3
        if (p == q && q == r) {
            offset++;
            continue;
        }

        vector<tuple<li, li, li>> updates;

        // add, use 2
        if (p == q || q == r || p == r) {
            li pair, rem;
            if (p == q) {
                pair = p;
                rem = r;
            } else if (q == r) {
                pair = q;
                rem = p;
            } else {
                pair = r;
                rem = q;
            }
            for (int k = 0; k < n; ++k) {
                updates.emplace_back(k, rem, dp[k][pair] + 1);
                updates.emplace_back(k, rem, dp[pair][k] + 1);
            }
        }

        // add, use 1
        updates.emplace_back(q, r, dp[p][p] + 1);
        updates.emplace_back(p, r, dp[q][q] + 1);
        updates.emplace_back(p, q, dp[r][r] + 1);

        // no-add, use 3
        // reusing the dp table to avoid O(n^2) updates.

        // no-add, use 2
        for (int k = 0; k < n; ++k) {
            updates.emplace_back(k, p, dp_maxx[k]);
            updates.emplace_back(k, p, dp_maxy[k]);
            updates.emplace_back(k, q, dp_maxx[k]);
            updates.emplace_back(k, q, dp_maxy[k]);
            updates.emplace_back(k, r, dp_maxx[k]);
            updates.emplace_back(k, r, dp_maxy[k]);
        }

        // no-add, use 1
        updates.emplace_back(p, q, dp_max);
        updates.emplace_back(p, r, dp_max);
        updates.emplace_back(q, r, dp_max);

        for (auto &upd: updates) {
            update(get<0>(upd), get<1>(upd), get<2>(upd));
        }
    }

    li ans = dp_max;
    for (int x = 0; x < n; ++x) {
        for (int y = 0; y < n; ++y) {
            if (x == y && y == xs[3 * n - 1]) {
                ans = max(ans, dp[x][y] + 1);
            }
        }
    }

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

Measured memory_bytes: 19400
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,W; cin >> N >> W;
    vector<ll> v(N),w(N);
    rep(i,N) cin >> v[i] >> w[i];

    vector<vector<ll>> dp(N+1, vector<ll>(10001,INF+1));
    dp[0][0] = 0;
    rep(i,N) {
        rep(j,10001) {
            if (j < v[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]] + w[i]);
        }
    }

    ll ans = 0;
    for (ll i = 10000; i >= 0; i--) {
        if (dp[N][i] <= W) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 10800
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define pii pair<int,int>
#define MOD 1000000007
#define int long long
using namespace std;
#define s second
#define f first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    cin>>a>>b;
    if(b>=a)
        cout<<"unsafe";
    else
    {
        cout<<"safe";
    }
    
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
vector<int>vt;
set<int>st;
map<string,int>mp;
unordered_map<string,int> umap; 
const long long MAX = 1e5;
const long long INF = 1e9;
const double pi = acos(-1);



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
  string s;
  cin>>s;
  mp[s]++;
  }
  int c=0;
  for(auto it:mp)
  {
    if(it.second)
    c++;
  }
  cout<<c<<endl;
  
  


    
   return 0;
}

Measured memory_bytes: 19200
def main():
    counts = [0, 0, 0, 0]
    for _ in range(3):
        v0, v1 = map(int, input().split())
        counts[v0 - 1] += 1
        counts[v1 - 1] += 1
    if max(counts) >= 3:
        print("NO")
    else:
        print("YES")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int N = 2e5 + 10;
VI e[N];
int cnt[N][2], dead[N];

int main() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    VI a(n);
    REP(i,n) a[i] = s[i] - 'A';
    REP(i,m){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    REP(i,n){
        for (int j : e[i]) cnt[i][a[j]]++;
    }

    queue<int> que;
    REP(i,n){
        if (cnt[i][0] == 0 || cnt[i][1] == 0){
            dead[i] = 1;
            que.push(i);
        }
    }

    while (!que.empty()){
        int x = que.front();
        que.pop();
        for (int next : e[x]){
            if (dead[next]) continue;
            cnt[next][a[x]]--;
            if (cnt[next][a[x]] == 0){
                dead[next] = 1;
                que.push(next);
            }
        }
    }

    bool ok = false;
    REP(i,n) if (!dead[i]) ok = true;
    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 13956
#include <iostream>

int main(){
    long long depo = 100;
    long long x;
    std::cin >> x;
    int count = 0;
    while(1){
        count++;
        depo += (depo/100);
        if(depo >= x){
            std::cout << count << std::endl;
            return 0;
        }
    }
}


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

# Input#
# n = int(input())
n, tar_w = map(int, input().split())

w = [-1]
v = [-1]

memo = [[-1] * (tar_w + 1) for i in range(n + 1)]

for i in range(tar_w + 1):
    memo[0][i] = 0


def dp(n, tar_w):
    if memo[n][tar_w] == -1:
        if tar_w < w[n]:
            memo[n][tar_w] = dp(n - 1, tar_w)
        else:
            memo[n][tar_w] = max(dp(n - 1, tar_w), dp(n - 1, tar_w - w[n]) + v[n])
    return memo[n][tar_w]


for i in range(n):
    w_in, v_in = list(map(int, input().split()))
    w.append(w_in)
    v.append(v_in)


ans = dp(n, tar_w)

print("{}".format(ans))


Measured memory_bytes: 167004
//#typedef int ll
// include
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <tuple>
// namespace
using namespace std;
// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
// const
const int inf = 1e9;
const int mod = ((int)1e9 + 7);
// loop
#define rep(i, n) for(int i = 0, i##_mx = n; i < i##_mx; i++)
#define brep(i, b, e) for(int i = b; i < e; i++)
#define erep(i, b, e) for(int i = b; i <= e; i++)
#define rrep(i, b, e) for(int i = b; i >= e; i--)
// STL
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
// function
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
void prime(vint& v, int n){brep(i, 2, n){bool fg = false; for(auto e : v){if(i % e == 0){fg = true;}} if(fg){continue;} v.pb(i);}}
void in(vint& v){for(auto& i : v){cin >> i;}}
void in(vll& v){for(auto& i : v){cin >> i;}}

signed main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll e = lcm(c, d);
    cout << b - a + 1 - (b / c - (a - 1) / c) - (b / d - (a - 1) / d) + (b / e - (a - 1) / e) << endl;
	
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n;
  cin >> n;
  vi p(n), s(n);
  re(i, n) {
    cin >> p[i];
    s[i] = p[i];
  }

  int cnt = 0;
  sort(all(s));
  re(i, n) {
    if(p[i] != s[i]) cnt++;
  }

  if(cnt == 0 || cnt == 2) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=5010,mod=998244353;

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

    int n,k; cin>>n>>k;
    string s; cin>>s;
    
    k=min(k,15);

    string ss=s, ans=s, tmp;
    reverse(ss.begin(),ss.end());
    ss=s+ss;
    
    for(int i=0;i<=n;i++){
	s=ss.substr(i,n);

	if(k==1){
	    ans=min(ans,s);
	    continue;
	}
	
	int cnt1=0,cnt2=0;
	while(cnt1<n && s[n-1-cnt1]==s.back()) cnt1++;
	cnt2=min(n, cnt1<<(k-1));
	tmp="";
	for(int i=0;i<cnt2;i++)
	    tmp+=s.back();
	if(cnt2<n){
	    tmp+=s.substr(cnt2-cnt1,n-cnt2);
	    reverse(tmp.begin()+cnt2,tmp.end());
	}
	ans=min(ans,tmp);
    }
    return cout<<ans<<endl,0;   
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

  set<string> sstr;
  for (int i = 1; i <= 5; i++) {
    for (int j = 0; j + i <= s.size(); j++) {
      sstr.insert(s.substr(j, i));
    }
  }

  int i = 1;
  for (auto x : sstr) {
    if (i == k) {
      cout << x << endl;
      return 0;
    }
    i++;
  }
}


Measured memory_bytes: 1664
import math


def calc_clock_distance():
    numbers = input().split(' ')

    a = float(numbers[0])
    b = float(numbers[1])
    h = float(numbers[2])
    m = float(numbers[3])

    angle_s = h * math.pi / 6.0 + (m * 2.0 * math.pi / 60.0 / 12.0)
    angle_l = m * math.pi / 30.0

    angle = math.fabs(angle_s - angle_l)

    print(math.sqrt(a * a + b * b - 2.0 * a * b * math.cos(angle)))


if __name__ == '__main__':
    calc_clock_distance()


Measured memory_bytes: 9444
#include <bits/stdc++.h>
using namespace std;
int main(){
  int i,j,k,b[1000001],c[1000001],a[200],n;
  for(i=0;a[i-1]<1000000;i++)a[i]=i*(i+1)*(i+2)/6;
  for(j=0;j<=1000000;j++)b[j]=c[j]=j;
  for(j=2;j<i;j++)for(k=a[j];k<=1000000;k++){
    b[k]=min(b[k],b[k-a[j]]+1);
    if(a[j]%2)c[k]=min(c[k],c[k-a[j]]+1);
  }
while(cin>>n,n)cout<<b[n]<<' '<<c[n]<<endl;
return 0;
}

Measured memory_bytes: 10856
#include<iostream>
#include<algorithm>
#define INF (1<<24)
using namespace std;
int W,H,mini,mini_x,mini_y,ny,nx,cost,ans;
string str;

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

char t[102][102];
bool vd[102][102];
int u[102][102];

int main(){
  while(cin>>W>>H){
    if(W==0&&H==0)break;
    for(int i=0;i<102;i++)for(int j=0;j<102;j++){
	t[i][j]='.';
	vd[i][j]=false;
	u[i][j]=INF;
      }

    for(int i=1;i<=H;i++){
      cin>>str;
      for(int j=1;j<=W;j++){
	t[i][j]=str[j-1];
	if(t[i][j]=='&')u[i][j]=0;
      }
    }
    /*
    for(int i=0;i<H+2;i++){
      for(int j=0;j<W+2;j++){
	cout<<t[i][j];
      }
      cout<<endl;
    }
    */

    while(1){
      mini=INF;
      for(int i=0;i<H+2;i++){
	for(int j=0;j<W+2;j++){
	  if(mini>u[i][j]&&vd[i][j]==false){
	    mini=u[i][j];
	    mini_y=i;
	    mini_x=j;
	  }
	}
      }

      if(mini==INF)break;

      vd[mini_y][mini_x]=true;

      //cout<<mini_y<<' '<<mini_x<<' '<<u[mini_y][mini_x]<<endl;

      
    

      for(int i=0;i<4;i++){
	ny=mini_y+dy[i];
	nx=mini_x+dx[i];
	if(ny<0||nx<0||ny>H+1||nx>W+1)continue;
	cost=((t[mini_y][mini_x]!='#'&&t[ny][nx]=='#')?1:0);

	if(u[ny][nx]>u[mini_y][mini_x]+cost){
	  u[ny][nx]=u[mini_y][mini_x]+cost;
	}
      }
    }

    ans=INF;
    for(int i=0;i<H+2;i++){
      ans=max(ans,u[i][0]);
      ans=max(ans,u[i][W+1]);	      
    }
    for(int i=0;i<W+2;i++){
      ans=min(ans,u[0][i]);
      ans=min(ans,u[H+1][i]);	      
    }
    cout<<ans<<endl;

  }
  return 0;
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[5000];

bool solve(int c){
  int dp[2][5010]={};
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    int nw=i%2,nt=(i+1)%2;
    for(int j=0;j<5010;j++)dp[nt][j]=0;
    for(int j=0;j<5010;j++){
      if(dp[nw][j]){
	dp[nt][j]=1;
	if(j+a[i]<5010&&i!=c)dp[nt][j+a[i]]=1;
      }
    }
  }
  for(int i=max(k-a[c],0);i<k;i++)
    if(dp[n%2][i])return true;
  return false;
}

int main(){
  cin>>n>>k;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  int lb=-1,ub=n,mid;
  //for(int i=0;i<n;i++)cout<<solve(i)<<endl;
  while(ub-lb>1){
    mid=(lb+ub)/2;
    (!solve(mid)?lb:ub)=mid;
  }
  cout<<lb+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std ;
int main(){
  int a ;
  cin >> a ;
  if (a%10==2 || a%10==4 || a%10==5 || a%10==7 || a%10==9) cout << "hon";
  else if (a%10==0 || a%10==1 || a%10==6 || a%10==8 ) cout << "pon";
  else cout <<"bon";
  }


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, a[4010];
    char c[4010];

    cin >> n;

    REP(i, n * 2)
    cin >> c[i] >> a[i];

    int dp[2010][2010];

    REP(i, n * 2 + 1)
    REP(j, n * 2 + 1)
    dp[i][j] = INT_MAX;

    dp[0][0] = 0;

    int w[2010][2010];
    int b[2010][2010];

    REP(i, n * 2)
    {
        int cnt = 0;
        int cnt_ = 0;
        bool e[2010] = {false};
        REP(j, i)
        {
            cnt += (c[j] == c[i] && a[i] < a[j]);
            if (c[j] != c[i])
                e[a[j]] = true, cnt_++;
        }

        int t = cnt + cnt_;
        for (int j = 0; j <= n; j++)
        {
            if (e[j])
                t--;

            if (c[i] == 'W')
                w[a[i]][j] = t;
            else
                b[a[i]][j] = t;
        }
    }

    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n; j++)
        {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + w[i + 1][j]);
            dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + b[j + 1][i]);
        }
    }

    cout << dp[n][n] << endl;

    return 0;
}

Measured memory_bytes: 47616
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}


// TODO: write
int main() {
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  
  int ans = 1;
  int old = a[0];
  bool isSecond = true;
  bool isBigger = false;
  rep(i,n){
    if(isSecond){
      if(old < a[i])isBigger = true;
      if(old > a[i])isBigger = false;
      if(old != a[i])isSecond = false;
    }else{
      if(isBigger && old > a[i]){
        ans++;
        isSecond = true;
      }
      if(!isBigger && old < a[i]){
        ans++;
        isSecond = true;
      }
    }
    old = a[i];
  }
  print(ans);
  return 0;
}



Measured memory_bytes: 640
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000003;
ll kai[1111111];
ll po(ll a, ll b)
{
	if (b == 0)return 1;
	ll z = po(a, b / 2);
	z = z*z%mod;
	if (b % 2 == 1)z = z*a%mod;
	return z;
}
ll inv(ll a)
{
	return po(a, mod - 2);
}
int main()
{
	kai[0] = 1;
	for (int i = 0; i < mod + 10; i++)kai[i + 1] = kai[i] * (i + 1) % mod;
	int q;
	scanf("%d", &q);
	for (int p = 0; p < q; p++)
	{
		int x, d, n;
		scanf("%d%d%d", &x, &d, &n);
		if (d == 0)
		{
			printf("%lld\n", po(x, n));
		}
		else
		{
			ll st = x*inv(d) % mod;
			ll go = st + n - 1;
			if (st <= mod&&mod <= go)printf("0\n");
			else
			{
				ll t = kai[go] * inv(kai[st - 1]) % mod;
				printf("%lld\n", t*po(d, n) % mod);
			}
		}
	}
}

Measured memory_bytes: 9464
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    if(A > 0){
        if(K >= A){
            ans += A;
            K -= A;
        }
        else {
            ans += K;
            K = 0;
        }
    }
    if(B > 0){
        if(K >= B){
            K -= B;
        }
        else {
            K = 0;
        }
    }
    
    ans -= K;
    
    cout << ans;
}

Measured memory_bytes: 3628
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

from fractions import gcd
a,b,c,d = iim()


def num(i):
    n = c*d//gcd(c,d)
    return i-i//c-i//d+i//n

print(num(b)-num(a-1))

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(long long (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()

int main() {
  int k,n;
  cin>>k>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int d=0;
  rep(i,n-1){
if(a[i+1]-a[i]>d){
  d=a[i+1]-a[i];
}
  }
 int cd=k+a[0]-a[n-1];
    cout<<k-max(d,cd)<<endl;    
return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 11

int k[MAXN], p[MAXN];
int switches[MAXN][MAXN];
int n,m;

int main() {
    cin >> n >> m;
    for(int i=0; i<m; i++) {
        cin >> k[i];
        for(int j=0; j<k[i]; j++) {
            cin >> switches[i][j];
            switches[i][j] --;
        }
    }

    
    for(int i=0; i<m; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for(int i=0; i< (1<<n); i++) {
        bool all_light = true;
        for(int j=0; j<m; j++) {
            int num_switch = 0;
            for(int l=0; l<k[j]; l++) {
                if ((i >> switches[j][l]) & 1) num_switch++;
            }
            if (num_switch%2 != p[j]) all_light = false;
            if (num_switch%2 != p[j]) all_light = false;
        }
        if ( all_light ) ans ++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  cin >> n;
  vecint ans(n + 1, 0);
  for (int k = 1; k <= n; k++) {
    for (int a = 2; a * a <= 2 * k; a++) {
      for (int b = 2; b * b <= 2 * k - a * a; b++) {
        int c2 = 2 * k - a * a - b * b;
        if (c2 < 0) continue;
        int c = sqrt(c2);
        if (c * c == c2) {
          int x = (a - b + c) / 2;
          int y = a - x;
          int z = c - x;
          if (min({x, y, z}) >= 1 &&
              x * x + y * y + z * z + x * y + y * z + z * x == k) {
            ans[k]++;
          }
        }
      }
    }
  }
  for (int k = 1; k <= n; k++) {
    cout << ans[k] << endl;
  }
}


Measured memory_bytes: 3572
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    S = input()
    T = input()
    len_s = len(S)
    len_t = len(T)
    ans = 1000
    for i in range(len_s-len_t+1):
        cunt = 0
        for j in range(len_t):
            if S[i+j] != T[j]:
                cunt += 1
        ans = min(ans, cunt)
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 67380