akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 1;
	rep(i, s.size() - 1) {
		if (s[i] != s[i + 1])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
    string S; cin >> S;
    int R=0;
    for (int i=0;i<S.size();i++) R+=(S[i]-'0');
    int B = S.size() - R;
    cout << 2*min(B,R) << endl;
}

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

int get_num(string str){
  int res=0;
  for(int i=0;i<str.size();i++) res=res*10+str[i]-'0';
  return res;
}

int main(){
  int ans;
  cin>>ans;
  while(1){
    string str;
    cin>>str;
    if(str[0]=='+')cin>>str, ans+=get_num(str);
    else if(str[0]=='-')cin>>str,ans-=get_num(str);
    else if(str[0]=='*')cin>>str,ans*=get_num(str);
    else if(str[0]=='/')cin>>str,ans/=get_num(str);
    else break;
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>

using namespace std;

int main()
{
    int A,B,C;
    cin >> A >> B>>C;
    
    if (A == 5 && B == 5 && C == 7) cout << "YES";
    else if (A == 5 && B == 7 && C == 5) cout << "YES";
    else if (A == 7 && B == 5 && C == 5) cout << "YES";
    else cout << "NO";
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long long N, K;

    cin >> N >> K;
    long long comb = 1;

    for(long long i = 0; i < N; i++){
        if(i == 0){
            comb = comb*K;
        }else{
            comb = comb*(K - 1);
        }
    }
    
    cout << comb << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
	static int H,W;
	static int f[][];
	static int dx[]={1,-1,0,0};
	static int dy[]={0,0,1,-1};
	static int cnt;
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			W=in.nextInt();
			H=in.nextInt();
			if((W|H)==0)
				return;
			int sw=-1;
			int sh=-1;
			f=new int[H][W];
			cnt=0;
			for(int i=0;i<H;i++)
			{
				String s=in.next();
				for(int j=0;j<W;j++)
				{
					if(s.charAt(j)=='#')
						f[i][j]=1;
					else
						f[i][j]=0;

					if(s.charAt(j)=='@')
					{
						sw=j;
						sh=i;
					}
				}
			}
			System.out.println(dfs(sw,sh));
		}
	}

	static  int dfs(int w,int h)
	{
		cnt++;
		f[h][w]=1;
		for(int i=0;i<4;i++)
		{
			int nw=dx[i]+w;
			int nh=dy[i]+h;
			if(nw>=0&&nw<W&&nh>=0&&nh<H&&f[nh][nw]==0)
				dfs(nw,nh);
		}
		return cnt;
	}
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 27140
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <iostream>
#include <algorithm>
using namespace std;

const int maxn = 200005;
const int shift = 200005;

int N, ans = 2147483647;
char ss[maxn][5];
int X[maxn], Y[maxn];
set<int> rx[200005], uy[200005];
set< pair<int, int> > dxay[500005], rxay[500005], rxmy[500005], uxmy[500005];

int main()
{
	for(int i = 0;i <= 500000;++i)
	{
		if(i <= 200000)
		{
			rx[i].clear();
			uy[i].clear();
		}
		dxay[i].clear();
		rxay[i].clear();
		rxmy[i].clear();
		uxmy[i].clear();
	}
	scanf("%d", &N);
	for(int i = 1;i <= N;++i)
	{
		scanf("%d%d%s", &X[i], &Y[i], ss[i]);
		if(ss[i][0] == 'U')
			rxay[X[i] + Y[i]].insert(make_pair(X[i], Y[i]));
		else if(ss[i][0] == 'D')
		{
			uy[X[i]].insert(Y[i]);
			rxmy[X[i] - Y[i] + shift].insert(make_pair(X[i], Y[i]));
		}
		else if(ss[i][0] == 'L')
		{
			uxmy[X[i] - Y[i] + shift].insert(make_pair(X[i], Y[i]));
			rx[Y[i]].insert(X[i]);
			dxay[X[i] + Y[i]].insert(make_pair(X[i], Y[i]));
		}
	}

	for(int i = 1;i <= N;++i)
	{
		if(ss[i][0] == 'U')
		{
			//cerr << X[i] << " " << uy[X[i]].size() << endl;
			if(uy[X[i]].size() > 0)
			{
				set<int>::iterator it;
				it = uy[X[i]].lower_bound(Y[i]);
				if(it != uy[X[i]].end() && *it > Y[i])
					ans = min(ans, abs(*it - Y[i]) * 5);
			}
			if(uxmy[X[i] - Y[i] + shift].size() > 0)
			{
				set< pair<int, int> >::iterator it;
				it = uxmy[X[i] - Y[i] + shift].lower_bound(make_pair(X[i], Y[i]));
				if(it != uxmy[X[i] - Y[i] + shift].end() && (*it).first > X[i])
					ans = min(ans, abs((*it).second - Y[i]) * 10);
			}
		}
		else if(ss[i][0] == 'R')
		{
			if(rxay[X[i] + Y[i]].size() > 0)
			{
				set< pair<int, int> >::iterator it;
				it = rxay[X[i] + Y[i]].upper_bound(make_pair(X[i], Y[i]));
				if(it != rxay[X[i] + Y[i]].end() && (*it).first > X[i])
					ans = min(ans, abs(Y[i] - (*it).second) * 10);
			}
			if(rxmy[X[i] - Y[i] + shift].size() > 0)
			{
				set< pair<int, int> >::iterator it;
				it = rxmy[X[i] - Y[i] + shift].upper_bound(make_pair(X[i], Y[i]));
				if(it != rxmy[X[i] - Y[i] + shift].end() && (*it).first > X[i])
					ans = min(ans, abs((*it).second - Y[i]) * 10);
			}
			if(rx[Y[i]].size() > 0)
			{
				set<int>::iterator it;
				it = rx[Y[i]].upper_bound(X[i]);
				if(it != uy[X[i]].end() && *it > X[i])
					ans = min(ans, abs(*it - X[i]) * 5);
			}
		}
		else if(ss[i][0] == 'D')
		{
			if(dxay[X[i] + Y[i]].size() > 0)
			{
				set< pair<int, int> >::iterator it;
				it = dxay[X[i] + Y[i]].upper_bound(make_pair(X[i], Y[i]));
				if(it != dxay[X[i] + Y[i]].end() && (*it).first > X[i])
					ans = min(ans, abs((*it).second - Y[i]) * 10);
			}
		}
	}

	if(ans == 2147483647)
		printf("SAFE\n");
	else
		printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 139248
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N+1];
		for(int i = 0;i < N;i++) {
			A[i] = sc.nextInt();
		}
		sc.close();

		int[] L = new int[N+1];
		int[] R = new int[N+1];
		L[0] = 0;
		R[N] = 0;
		for(int i = 0;i < N;i++) {
			L[i+1] = gcd(L[i],A[i]);
		}
		for(int i = N-1;i > 0;i--) {
			R[i] = gcd(R[i+1],A[i]);
		}
		int[] M = new int[N];
		int result = 0;
		for(int i = 0;i < N;i++) {
			M[i] = gcd(L[i],R[i+1]);
			result = Math.max(result, M[i]);
		}
		System.out.println(result);
	}

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

Measured memory_bytes: 50696
import java.util.*;
class Main {
	static int INF = -10000000;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			int[] a = new int[n];
			for(int i = 0; i < n; i++) {
				a[i] = stdIn.nextInt();
			}
			long max = INF;
			for(int i = 0; i < n; i++) {
				long sum = 0;
				for(int j = i; j < n; j++) {
					sum += a[j];
					if(max < sum) {
						max = sum;
					}
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 26420
d = {0:"S", 1:"H", 2:"C", 3:"D"}
l = [[0 for _ in range(13)]for _ in range(4)]
n = int(input())
for _ in range(n):
  m, i = input().split()
  i = int(i)
  if m == "S":
    l[0][i-1] = 1
  elif m == "H":
    l[1][i-1] = 1
  elif m == "C":
    l[2][i-1] = 1
  elif m == "D":
    l[3][i-1] = 1
for m in range(4):
  for n in range(13):
    if l[m][n] == 0:
      print("{} {}".format(d[m], n+1))


Measured memory_bytes: 5608
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;
set<string> S;
 
void Work()
{
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++)
    {
        if(s[i] == '?' || s[i] == t[0])//如果字符相等
        {
            string tmp = s;              //构造判断子串之前的字符
            for(int j = 0; j < i; j++)
                if(tmp[j] == '?')
                    tmp[j] ='a';    
            bool can = false;
            for(int j = 0; j < lent; j++)    //判断是否为子串
            {
 
                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])  //字符匹配
                    break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can)
            {
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';//处理匹配后的字符
                S.insert(tmp);  //压入容器
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << *S.begin() << endl;
}
int main()
{
    cin >> s >> t;
    Work();
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;

int N, M;
vector<bool> issafe; // issafe[v] := v が壊れていないかどうか

int main() {
    cin >> N >> M;
    issafe.assign(N+1, true);
    for (int i = 0; i < M; ++i) {
        int a; cin >> a;
        issafe[a] = false; // a 段目は壊れてる
    }

    // DP テーブル
    vector<int> dp(N+1, 0); // 各段について 0 で初期化しておく

    // 初期条件
    dp[0] = 1;
    if (issafe[1]) dp[1] = 1;

    // ループ
    for (int n = 2; n <= N; ++n) {
        if (issafe[n-1]) dp[n] += dp[n-1]; // n-1 段目が安全なら
        if (issafe[n-2]) dp[n] += dp[n-2]; // n-2 段目が安全なら
        dp[n] %= MOD; // 1000000007 で割る
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 1000000007
using namespace std;
typedef long long ll;

int main(){
  int w, h, n; cin >> w >> h >> n;
  vector<vector<int>> paint_map(h, vector<int>(w, 0));
  rep(i, 0, n){
    int x, y, a;  cin >> x >> y >> a;
    switch(a){
      case 1:
      rep(i, 0, h)  rep(j, 0, x)  paint_map[i][j]=1;
      break;
      case 2:
      rep(i, 0, h)  rep(j, x, w)  paint_map[i][j]=1;
      break;
      case 3:
      rep(i, 0, y)  rep(j, 0, w)  paint_map[i][j]=1;
      break;
      case 4:
      rep(i, y, h)  rep(j, 0, w)  paint_map[i][j]=1;
      break;
    }
  }
  int ans = 0;
  for(int y=0; y<h; y++){
    for(int x=0; x<w; x++){
      if(paint_map[y][x]==0)  ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math

S = int(input())

x3 = 0
y3 = 0
S_root = math.floor(S ** (1/2))
x1 = min(S_root + 1, 10 ** 9)
y2 = min(S_root + 1, 10 ** 9)
x2 = 1
y1 = (x1 * y2) - S

print(x1, y1, x2, y2, x3, y3)


Measured memory_bytes: 38384
from collections import deque

H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]

def bfs(grid, start):
    distance = [[-1] * W for _ in range(H)]
    queue = deque([start])
    distance[start[1]][start[0]] = 0#start地点を0に
    
    while queue:#queueにたまっている間は処理を続ける
        x, y = queue.popleft()#今いる地点をpop
        
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):#左右上下に進むパターンをそれぞれ考える
            next_x, next_y = x+i, y+j#次に行く地点
            
            if 0 <= next_x < W and 0 <= next_y < H:#次の地点が範囲内にある場合
                if grid[next_y][next_x] == '.' and distance[next_y][next_x] == -1:#次の地点が壁ではなくかつ訪れたことがない場合
                    distance[next_y][next_x] = distance[y][x] + 1#訪れた印として現在までの距離に1を足す
                    queue.append((next_x, next_y))#訪れる先をqueueに詰めとく
        
        if not queue:#最後にqueueをpopし終えてなくなったら最後に出力
            return distance[y][x]
        
answer = 0
for i in range(H):#y
    for j in range(W):#x
        #スタート地点を決める
        
        if S[i][j] == '#':#スタート地点が壁
            continue

        tmp = bfs(S, (j, i))#このスタート地点での一番遠い距離
        
        if tmp > answer:#最大の距離
            answer = tmp

print(answer)   

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

	int N;
	Scd(N);

	char s[123133];
	char t[123133];

	Scs(s);
	Scs(t);

	vector<int> dp(256);

	int mod = 1000000007;

	dp[s[0]]++;

	Repe(i,N-1,1){
		dp[s[i]] += dp[t[i]];
		if( dp[s[i]] >= mod ) dp[s[i]] -= mod;
	}

	printf( "%d\n", dp[t[N-1]] );
	

	return 0;
}

/*
abbaba
baabab
-11010
--1111
---212
----32
-----5
*/




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

// マクロ
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

int main() {

	int N, A;

	cin >> N >> A;

	cou((N % A == 0 ? N / A : N / A + 1));

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define INF 1000000000000
using namespace std;
using ll=long long;
using ld=long double;
using vs=vector<string>;


int main() {
    ll n,d,ans;
    ans=0;
    cin>>n>>d;
    vector<ll> x(n);
    vector<ll> y(n);
    rep(i,n){
        cin>>x[i]>>y[i];
        if(sqrt(pow(x[i],2)+pow(y[i],2))<=d){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6396
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	long long n,k;
	cin >> n >> k;
	long long ans;
	if(n>k){
		ans=abs(n-k*((n+k-1)/k));
	}else if(n==k){
		ans=0;
	}else{
		ans=min(n,abs(n-k));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
int a,b,i,j;
scanf("%d %d",&a,&b);
int mat[a][b],vec[b],ans[a];
for(i=0;i<a;i++){
   ans[i]=0;
}
for(i=0;i<a;i++){
   for(j=0;j<b;j++){
      scanf("%d",&mat[i][j]);
   }
}
for(i=0;i<b;i++){
   scanf("%d",&vec[i]);
}
for(i=0;i<a;i++){
   for(j=0;j<b;j++){
      ans[i]=ans[i]+mat[i][j]*vec[j];
   }
}
for(i=0;i<a;i++){
   printf("%d\n",ans[i]);
}
return 0;
}

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

int main(){
    int n;
    while(cin >> n,n){
        int plnum = 1,fl = 0;
        string line;
        cin >> line;
        vector <int> pl(n+1,0);
        for(int i=0;i<100;i++,plnum++){
            if(plnum > n) plnum = 1;
            if(line[i] == 'M') pl[plnum]++;
            else if(line[i] == 'S'){
                fl += pl[plnum] + 1;
                pl[plnum] = 0;
            }
            else if(line[i] == 'L'){
                pl[plnum] += fl + 1;
                fl = 0;
            }
        }
        sort(pl.begin()+1,pl.end());
        for(int i=1;i<=n;i++) cout << pl[i] << " ";
        cout << fl << endl;
    }
}

Measured memory_bytes: 1224
import sys
S = input()
if S[0] != "A":
  print("WA")
  sys.exit()

if S[1:].count('C') != 1:
  print("WA")
  sys.exit()

Cindex = S.find("C")
if Cindex < 2 or Cindex > len(S)-2:
  print("WA")
  sys.exit()
  
T = 'a' + S[1:]
T = T[0:Cindex] + "c" + T[Cindex+1:]

if T.islower():
  print("AC")
else:
  print("WA")

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

#define MOD 1000000007LL
const long long INF = 1LL << 60;
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))

typedef long long ll;

typedef struct Child{
    ll a;
    ll idx;
}child;

int ascend(const void *n,const void *m){
    if(((child *)n)->a > ((child *)m)->a)return -1;
    if(((child *)n)->a < ((child *)m)->a)return 1;
    if(((child *)n)->idx > ((child *)m)->idx)return -1;
    if(((child *)n)->idx < ((child *)m)->idx)return 1;
    return 0;
}
int N;
ll DP[2048][2048];
child A[2048];
ll assign(ll start,ll finish){
    if(start>finish) return 0;
    if(DP[start][finish]!=-1) return DP[start][finish];
    ll i = (start-1)+(N-finish);
    DP[start][finish] = MAX(assign(start+1,finish)+A[i].a*llabs(start-A[i].idx),DP[start][finish]);
    DP[start][finish] = MAX(assign(start,finish-1)+A[i].a*llabs(finish-A[i].idx),DP[start][finish]);
    return DP[start][finish];
}

int main(){
    scanf("%d",&N);
    for(int i=0;i<2048;i++)for(int j=0;j<2048;j++)DP[i][j]=-1;
    for(int i = 0;i<N;i++){
        scanf("%lld",&A[i].a);
        A[i].idx=i+1;
    }
    qsort(A,N,sizeof(A[0]),ascend);
    printf("%lld\n",assign(1,N));
    return 0;
}

Measured memory_bytes: 34720
a+=(`fold -w1|sort -u`)
y=`echo ${a[*]}|egrep -o 'S|N'|wc -l`
x=`echo ${a[*]}|egrep -o 'W|E'|wc -l`
test $y -eq 0 -o $y -eq 2&&test $x -eq 0 -o $x -eq 2&&echo Yes||echo No

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

const int MAXN = 305;
const int mod = (int) 1e9 + 7;

int n, m;
vector<pair<int,int>> en[MAXN];
long long dp[MAXN][MAXN][MAXN];
long long ans;

bool badPair(int a, int b) {
    return a > 0 && b > 0 && a == b;
}

int main() {

    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int l, r, x;
        scanf("%d %d %d", &l, &r, &x);
        l--; r--;
        en[r].push_back({l, x});
    }

    // memset(dp, -1, sizeof(dp));

    dp[0][0][0] = 1;
    for (int lr = 0; lr <= n; lr++)
        for (int lg = 0; lg <= n; lg++)
            for (int lb = 0; lb <= n; lb++) {
                if (badPair(lr, lg) || badPair(lr, lb) || badPair(lg, lb))
                    continue;

                int a = lr, b = lg, c = lb;
                if (a > b)
                    swap(a, b);
                if (b > c)
                    swap(b, c);
                if (a > b)
                    swap(a, b);

                bool bad = false;
                if (c - 1 >= 0) {
                    for (int i = 0; i < sz(en[c - 1]); i++) {
                        int can = en[c - 1][i].second;
                        int from = en[c - 1][i].first;
                        if (can == 1) {
                            if (b - 1 >= from) {
                                bad = true;
                                break;
                            }
                        } else if (can == 2) {
                            if (a - 1 >= from || b - 1 < from) {
                                bad = true;
                                break;
                            }
                        } else {
                            if (!(a - 1 >= from)) {
                                bad = true;
                                break;
                            }
                        }
                    }
                }
                if (bad) {
                    dp[lr][lg][lb] = 0;
                    continue;
                }

                if (c == n)
                    ans = (ans + dp[lr][lg][lb]) % mod;
                else {
                    dp[c + 1][lg][lb] = (dp[c + 1][lg][lb] + dp[lr][lg][lb]) % mod;
                    dp[lr][c + 1][lb] = (dp[lr][c + 1][lb] + dp[lr][lg][lb]) % mod;
                    dp[lr][lg][c + 1] = (dp[lr][lg][c + 1] + dp[lr][lg][lb]) % mod;
                }
            }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 219392
#include<bits/stdc++.h>
using namespace std;
int x[50],y[50];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
			scanf("%d",&x[i]);
	for(int i=0;i<n;i++)
			scanf("%d",&y[i]);
	int xs=0,ys=0;
	for(int i=0;i<n;i++)
	{
		if(x[i]>y[i])
		{
			xs+=x[i];
			ys+=y[i];
		}
	}
	printf("%d",xs-ys);
	return 0;
}

Measured memory_bytes: 256
#include <atcoder/twosat>
#include <iostream>

int main()
{
    int N, D;
    std::cin >> N >> D;

    std::vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++) {
        std::cin >> X[i] >> Y[i];
    }

    atcoder::two_sat ts(N);
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (std::abs(X[i] - X[j]) < D) {
                ts.add_clause(i, true, j, true);
            }
            if (std::abs(X[i] - Y[j]) < D) {
                ts.add_clause(i, true, j, false);
            }
            if (std::abs(Y[i] - X[j]) < D) {
                ts.add_clause(i, false, j, true);
            }
            if (std::abs(Y[i] - Y[j]) < D) {
                ts.add_clause(i, false, j, false);
            }
        }
    }

    if (not ts.satisfiable()) {
        std::cout << "No" << '\n';
        return 0;
    }

    std::cout << "Yes" << '\n';
    const auto ans = ts.answer();
    for (int i = 0; i < N; i++) {
        std::cout << (ans[i]? Y[i] : X[i]) << '\n';
    }
}

Measured memory_bytes: 3744
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            if (iN % 2 == 1) { iN *= 2; }

            // 出力
            System.Console.WriteLine("{0}", iN.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ff(i, x, y) for(int i = x;i <= y;i++)
#define fs(i, x, y) for(int i = x;i >= y;i--)
using namespace std;
typedef long long ll;
ll p = 5333, mod = 1e9 + 7, ans;
map<ll, int>mp;
char s[1000100];
int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    ll now = 0;
    ff(i, 1, n) {
        now = ((now + s[i] - 'a' + 1) % mod) * p;
        now = now % mod;
        if(!mp.count(now)) {
            mp.clear();
            mp[now] = 1;
            now = 0;
            ans++;
        }
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
kane=1000
#Nが所持金、Aが株価
#最初は、とりあえず最安値で購入（単価が上がる直前までの最小値）。その後は最高値で売（単価が下がる直前までの最大値）
mini=A[0]
maxi=0
jyoutai="buy"
num=0
#株だけ持ったままま、売却条件を満たさず最後まで行ってしまったとき→NG。買うときは、買値より高い値が今後存在しうるときのみにする
#購入条件を満たさず、買わないで最後まで行ってしまったとき→これはOK。最終的な利益は最大だから
for i in range(1,N):
    #購入時
    if jyoutai=="buy":
        if A[i]<mini:#最小値を更新
            mini=A[i]
        elif A[i]==mini and num>0:#株を持っていて値段が変わらないとき
            pass
        #elif A[i]>=mini and num==0 and A[i]<max(A[i+1:]):#最小値を更新しない&株を持っていない＆売れる見込みがあるなら購入
        elif A[i]>=mini and num==0:#最小値を更新しない&株を持っていないなら購入
            num=kane//mini
            kane=kane%mini
            jyoutai="sell"
            maxi=A[i]
        #もし最後に、
    #売却時
    elif jyoutai=="sell":
        if A[i]>maxi:#最大値を更新
            maxi=A[i]
        elif A[i]==maxi and num==0:#株を持っていなくて値段が変わらないとき
            pass
        elif A[i]<=maxi and num>0:#最大値を更新しない&株を持っている売却
            kane+=num*maxi
            num=0
            jyoutai="buy"
            mini=A[i]
if num>0:
    kane+=num*maxi
print(kane)

    


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 105;
int N, K;

vector<string> ans;

void pushAns(int a, int b) {
  ans.push_back(to_string(a) + " " + to_string(b));
}

void makeG(int base, int pos)
{
  FOR(n,pos,N+1) {
    FOR(m,base,n) {
      pushAns(n,m);
    }
  }
}

int S[MAX_N];

signed main()
{
  cin >> N >> K;
  if(K == 0) {
    makeG(1,1);
    cout << ans.size() << endl;
    REP(n,ans.size()) {
      cout << ans[n] << endl;
    }
    return 0;
  }

  int sumS = (N-1)*(N-2)/2;

  if(K > sumS) {
    cout << -1 << endl;
    return 0;
  }

  FOR(n,2,N+1) {
    S[n] = n-2;
    pushAns(1,n);
  }

  for(int n = N; 3 <= n; n--) {
    int p = 2;
    while(sumS > K && S[n] > 0) {
      S[n]--;
      sumS--;
      pushAns(n,p);
      p++;
    }
  }

  cout << ans.size() << endl;
  REP(n,ans.size()) {
    cout << ans[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int k, i;
  int counter = 0;

  scanf("%d", &k);


  for(i = 1; i <= k; i++){
    if(k % 2 == 0){ 
      if(i % 2 == 0){
	counter += k / 2;
      }
      else{
	counter += k / 2;
      }
    }
    else{
      if(i % 2 == 0){
	counter += k / 2 + 1;
      }
      else{
	counter += k / 2;
      }
    }
  }

  printf("%d\n", counter / 2);
  
  return 0;
}

Measured memory_bytes: 128
def is_stable(bubble, selection, _N):
    for i in range(N):
        if bubble[i][0] != selection[i][0]:
            return False
    return True


def bubble(N_input, A_input):
    count = 0
    flag = 1
    _A = list(A_input)

    while flag:
        flag = 0
        for i in range(N_input-1, 0, -1):
            _A_i = int(_A[i][1])
            _A_i_1 = int(_A[i-1][1])

            if _A_i < _A_i_1:
                _A[i], _A[i-1] = _A[i-1], _A[i]

                flag = 1
                count += 1

    return _A


def selection(inN, inA):
    _A = list(inA)

    for i in range(0, inN-1, 1):
        minj = i
        for j in range(i+1, inN, 1):
            if int(_A[j][1]) < int(_A[minj][1]):
                minj = j
        _A[i], _A[minj] = _A[minj], _A[i]

    return _A


N = int(input())
# A = list(map(int, input().split()))
A = input().split()
# print(N, A)

A_bubble = bubble(N, A)
A_bubble_str = map(str, A_bubble)
print(' '.join(A_bubble_str))
print('Stable')

A_selection = selection(N, A)
A_selection_str = map(str, A_selection)
print(' '.join(A_selection_str))
if is_stable(A_bubble, A_selection, N):
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 5608
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    ans = sum(b)
    for i in range(1, len(a)):
        if a[i] == a[i - 1] + 1:
            ans += c[a[i - 1] - 1]
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
/*
Author : N_o_o_B
Created : April 22 2020 22:28:22 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int a,b;
    cin >> a >> b;
    int ans=-1;
    rep(i,1,10000){
        int c = i*0.08;
        int d = i*0.1;
        if(a==c and b==d) {if(ans==-1) ans = i;}
    }
    cout << ans << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n;
    cin >> n;

    lli a, b, c, d;
    lli x, y;

    lli flag = 0;

    for (lli i = 0; i < n; i++) {
        cin >> x >> y;
        if (flag == 0 || x + y > a) {
            a = x + y;
        }
        if (flag == 0 || x + y < b) {
            b = x + y;
        }
        if (flag == 0 || x - y > c) {
            c = x - y;
        }
        if (flag == 0 || x - y < d) {
            d = x - y;
        }
        flag = 1;
    }

    lli ans = max(a - b, c - d);
    cout << ans << endl;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 3640
K=int(input())


ANS=[[[] for _ in range(10)] for _ in range(10)]
for i in range(10):
    ANS[0][i].append(str(i))
for i in range(1,10):
    for j in range(10):
        if 1<=j and j<=8:
            for k in [j-1,j,j+1]:
                for v in ANS[i-1][k]:
                    ANS[i][j].append(str(j)+v)
        elif j==0:
            for k in [j,j+1]:
                for v in ANS[i-1][k]:
                    ANS[i][j].append(str(j)+v)
        elif j==9:
            for k in [j-1,j]:
                for v in ANS[i-1][k]:
                    ANS[i][j].append(str(j)+v)

X=[]
for i in range(10):
    for j in range(1,10):
        for k in ANS[i][j]:
            X.append(int(k))
X.sort()
print(X[K-1])    

Measured memory_bytes: 25944
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

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

	vector<int32_t> x(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> x[i];
	}

	int32_t res = numeric_limits<int32_t>::max();
	for (int32_t i = 0; i < N - K + 1; i++) {
		int32_t _min = x[i];
		int32_t _max = x[i + K - 1];
		int32_t _res;
		if (_min <= 0 && _max <= 0)
			_res = -_min;
		else if (_min >= 0 && _max >= 0)
			_res = _max;
		else {
			if (abs(_min) < abs(_max))
				_res = abs(_min) * 2 + abs(_max);
			else
				_res = abs(_max) * 2 + abs(_min);
		}
		res = min(res, _res);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re

def main():
    A, B = map(int, input().split())
    S = input()

    pattern = r"\A[0-9]{{{}}}-[0-9]{{{}}}\Z".format(A, B)
    ok = re.fullmatch(pattern, S)

    print("Yes" if ok else "No")

if __name__ == "__main__": main()


Measured memory_bytes: 3188
#include <iostream>
#define rep(i,a) for (int i = 0; i < (a); i++)
using namespace std;

int n, m, l, s, e;
int L[100], T[100], dp[1 << 17];

int main(void){
    while (cin >> n, n) {
        rep(i, 1 << 17) dp[i] = 0;
        rep(i, n) {
            cin >> m >> l;
            L[i] = l;
            int t = 0;
            rep(j, m) {
                cin >> s >> e;
                t |= (1 << (e-6)) - (1 << (s-6));
            }
            T[i] = t;
        }
        
        int mx = 1;
        rep(i,n) {
            rep(bit, mx) {
                if ((bit & T[i]) == 0 && dp[bit]) {
                    dp[bit | T[i]] = max(dp[bit | T[i]], dp[bit] + L[i]);
                    mx = max(mx, (bit | T[i]) + 1);
                }
                dp[T[i]] = max(dp[T[i]], L[i]);
                mx = max(mx, T[i]+1);
            }
        }
        int ans = 0;
        rep(i, 1 << 17) ans = max(ans, dp[i]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1672
import sys

x,n = map(int,input().split())
if n == 0:
	print(x)
	sys.exit()
p = list(map(int,input().split()))
p.sort()

num = 0
ans = 10 ** 9
for i in range(102):
	if num < len(p) and i == p[num]:
		num += 1
		continue
	if ans > abs(x-i):
		ans = abs(x-i)
		res = i

print(res)


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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

void printv(vector<auto> const& s) {
  REP(i, s.size()) {
    cout << s[i] << endl;
  }
}

void print(auto const s) {
  cout << s << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  ll n, k; cin >> n >> k;
  vector<pair<ll, ll>> p(n);
  REP(i, n) {
    cin >> p[i].fi >> p[i].se;
  }

  sort(ALL(p));

  ll cnt = 0;
  REP(i, n) {
    if(p[i].se >= k) {
      cout << p[i].fi << endl;
      break;
    }
    k -= p[i].se;
  }
}


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	string alphabet = "abcdefghijklmnopqrstuvwxyz";
	int mincount = 100;
	for(int i = 0; i < alphabet.size(); i++)
	{
		string st = s;
		int count = 0;
		while(true)
		{
			bool done = true;
			for(int j = 0; j < st.size(); j++)
			{
				if(st[j] != alphabet[i])
				{
					done = false;
				}
			}
			if(done)
			{
				break;
			}else{
				for(int j = 0; j < st.size() - 1; j++)
				{
					if(st[j + 1] == alphabet[i])
					{
						st[j] = st[j + 1];
					}
				}
				st = st.substr(0, st.size() - 1);
				count++;
			}		
		}
		if(count < mincount) mincount = count;
	}
	cout << mincount << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	char s[1024], t[1024];
	int i, j, max, cnt;

	fgets(s, sizeof(s), stdin);
	fgets(t, sizeof(t), stdin);

	for ( i = 0; i < strlen(s); i++ ) {
		if ( s[i] == '\n' || s[i] == '\r' ) {
			s[i] = '\0';
		}
	}
	for ( i = 0; i < strlen(t); i++ ) {
		if ( t[i] == '\n' || t[i] == '\r' ) {
			t[i] = '\0';
		}
	}

	max = 0;
	for ( i = 0; i <= (strlen(s) - strlen(t)); i++ ) {
		cnt = 0;
		
		for ( j = 0; j < strlen(t); j++ ) {
			if ( s[i+j] == t[j] ) {
				cnt++;
			}
			//printf("%c == %c : cnt = %d\n", s[i+j], t[j], cnt);
		}
		if ( max < cnt ) {
			max = cnt;
		}
	}

	printf("%lu\n", strlen(t) - max);

	return 0;
}


Measured memory_bytes: 1644
#include<iostream>
using namespace std;
int main()
{
  int k;
  cin>>k;
  string s;
  cin>>s;
  if (s.size()<=k)
    cout<<s;
  else {
    for (int i=0;i<k;i++)
      cout<<s[i];
    cout<<"...";
  }
  return 0;
}


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

int main(){
  string A,B;
  cin >> A>>B;
  
  if(A.size() > B.size()){cout << "GREATER"; return 0;}
  else if(A.size() < B.size()){cout <<"LESS"; return 0;}
  else {
    for(int i = 0; i < A.size(); i++){
      if(A.at(i) > B.at(i)){cout << "GREATER"; return 0;}
      else if(A.at(i) < B.at(i)){cout << "LESS"; return 0;}
      
    }
    
  }
  cout << "EQUAL" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(void){

    int K;cin>>K;
    int sum = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
               sum += __gcd(__gcd(i, j), k);
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 3624
def splitting_pile(N: int, A: list)->int:
    snuke, raccoon = A[0], sum(A[1:])

    min_diff = abs(snuke-raccoon)
    for a in A[1:-1]:
        snuke += a
        raccoon -= a
        min_diff = min(min_diff, abs(snuke-raccoon))

    return min_diff


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = splitting_pile(N, A)
    print(ans)


Measured memory_bytes: 24820
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int m,d,sum=0;
  cin>>m>>d;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=d;j++){
      if(j/10>=2 && j%10>=2 && (j/10)*(j%10)==i) sum++;
    }
  }
  cout<<sum<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  long int n,s,a,b,c,d,e,f,g;
  scanf("%ld", &n);
  s=(n*(n+1))/2;
  a=3*(n/3);
  b=5*(n/5);
  c=15*(n/15);
  d=((3+a)*(n/3))/2;
  e=((5+b)*(n/5))/2;
  f=((15+c)*(n/15))/2;
  g=s+f-d-e;
  printf("%ld", g);
  return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;
    vl as(n);
    cin>>as;

    ll ans = 0;
    rep(i, n - 1) {
        ans += as[i] / 2;
        as[i] %= 2;
        ll m = min(as[i], as[i + 1]);
        ans += m;
        as[i] -= m;
        as[i + 1] -= m;
    }
    ans += as.back() / 2;
    cout<<ans<<endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<cmath>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

int main(){

long long N;
cin>>N;
long long ans;
ans=INF;
for(long long i=sqrt(N);i>0;i--){
    if(N%i==0){
        ans=min(i-1+(N/i)-1,ans);
    }
}
cout<<ans<<endl;
 return 0;
}
/*
10

5

50

13

10000000019

10000000018

*/

Measured memory_bytes: 256
#include <iostream>

int main()
{
    for ( int i = 0; true; ++i )
    {
        int x;
        std::cin >> x;

        if ( x == 0 ) { break; }

        std::cout
            << "Case " << (i+1) << ": " << x
            << std::endl;
    }

    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  cout << n / 3;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    auto a = make_v(N, N, 0LL);
    REP(i, 0, N) {
        REP(j, 0, N) {
            cin >> a[i][j];
        }
    }
    vector<ll> dp(1 << N, 0LL);
    REP(i, 0, 1 << N) {
        ll sum = 0;
        REP(t, 0, N) {
            REP(s, 0, t) {
                if (((i >> t) & 1) && ((i >> s) & 1)) {
                    sum += a[t][s];
                }
            }
        }
        dp[i] = max(dp[i], sum);
        for (int j = i; j > 0; j = (j - 1) & i) {
            dp[i] = max(dp[i], dp[j] + dp[i & (~j)]);
        }
    }
    cout << dp[(1 << N) - 1] << endl;
    return 0;
}


Measured memory_bytes: 896
use v5.26; # strict say state biwise
use List::Util qw/sum/;

my @s;
{
  chomp (my $in = <STDIN>);
  @s = split '', $in;
}
my @h;
my $p10 = 1;
$h[0] = 1;
my $cur = 0;
for my $i (1..scalar(@s)) {
  my $t = $s[-$i];
  $cur = ($cur + $t * $p10) % 2019;
  $h[$cur]++;
  $p10 = $p10 * 10 % 2019;
}
my $ans = sum(map {$_ * ($_ - 1) / 2} @h); 
say $ans;

Measured memory_bytes: 21244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dp[3010][3010] = {0};
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 main()
{
    char s[3010],t[3010];
    scanf("%s%s",s,t);
    int x = strlen(s),y = strlen(t);
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            if (s[i] == t[j])
            {
                chmax(dp[i + 1][j + 1], dp[i][j] + 1);
            }
            chmax(dp[i + 1][j + 1], dp[i + 1][j]);
            chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        }
    }
    string k = "";
    int i = x, j = y;
    while (i && j)
    {
        if (dp[i][j] == dp[i - 1][j])
        {
            i--;
        }
        else if (dp[i][j] == dp[i][j - 1])
        {
            j--;
        }
        else
        {
            k = s[i - 1] + k;
            i--;
            j--;
        }
    }
    char l[3030] = {""};
    for(int i = 0; i < k.size(); i++){
        l[i] = k[i];
    }
    printf("%s\n",l);
}

Measured memory_bytes: 35584
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<cmath>
#include<functional>
#include<numeric>
//#include<>
using namespace std;

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define REPS(i, n) for(int i=1;i<=(int)(n);i++)
#define RREP(i, n) for(int i=(int)n-1;i>=0;i--)
#define RREPS(i, n) for(int i=(int)n;i>0;i--)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, m;

int main(){
	ios::sync_with_stdio(false);
	while(cin >> n){
		if(!n)break;
		int m,p;
		cin>>m>>p;
		vector<int> a(n);
		REP(i,n)
			cin>>a[i];
		ll sum=accumulate(ALL(a),0ll);
		cout<<(a[m-1]?sum*(100-p)/a[m-1]:0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1192