akhauriyash/Code-Regression huggingface dataset:
import glob



# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\143\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def resolve(self):
        N = int(self.input_data())
        S = self.input_data()

        slimes = list(S)

        tmp = ""
        result = 0

        for slime in slimes:
            if tmp == slime:
                continue
            else:
                result += 1
                tmp = slime

        print(str(result))

solver = C(REL_PATH)
solver.exec_resolve()

Measured memory_bytes: 4980
#include <iostream>
using namespace std;
int main()
{
    string s,t;cin>>s>>t;
    if(s==t) cout<<"Yes";
    else{
            char tmp,change;
            for(int j=0;j<s.size();j++){
            tmp=s[s.size()-1];
            for(int i=s.size()-1;i>0;i--){
                    change=s[i];
                    s[i]=s[i-1];
                    s[i-1]=change;
            }
            s[0]=tmp;
            if(s==t){cout<<"Yes";return 0;}
            }
            cout<<"No";
    }
    return 0;
}


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

int H, W, K;
int M[3000][3000];
long dp[3000][3000][4];

int main() {
  cin >> H >> W >> K;
  int r, c, v;
  for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) M[i][j] = 0;
  for (int i = 0; i < K; i++) {
    cin >> r >> c >> v; r--; c--; M[r][c] = v;
  }
  dp[0][0][0] = 0;
  dp[0][0][1] = dp[0][0][2] = dp[0][0][3] = M[0][0];
  for (int i = 1; i < H; i++) {
    for (int k = 0; k <= 3; k++) {
      dp[i][0][k] = dp[i-1][0][3];
      if (k > 0) dp[i][0][k] = max(dp[i][0][k], dp[i-1][0][3] + M[i][0]);
    }
  }
  for (int j = 1; j < W; j++) {
    for (int k = 0; k <= 3; k++) {
      dp[0][j][k] = dp[0][j-1][k];
      if (k > 0) dp[0][j][k] = max(dp[0][j][k], dp[0][j-1][k-1] + M[0][j]);
    }
  }
  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      for (int k = 0; k <= 3; k++) {
        dp[i][j][k] = max(dp[i-1][j][3], dp[i][j-1][k]);
        if (k > 0) dp[i][j][k] = max(dp[i][j][k],
          max(dp[i-1][j][3], dp[i][j-1][k-1]) + M[i][j]);
      }
    }
  }
  cout << dp[H-1][W-1][3] << endl;
}

Measured memory_bytes: 319800
#include <bits/stdc++.h>
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define MAX 500005
 #include<iomanip>
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define x first
 #define y second
using namespace std;
int gcd(int a, int b);
  
int power(int x, unsigned int y, unsigned int m)
{
    if (y == 0)
        return 1;
    int p = power(x, y/2, m) % m;
    p = (p * p) % m;
  
    return (y%2 == 0)? p : (x * p) % m;
}
ll modInverse(int a, int m)
{
    int g = gcd(a, m);
   
    {
        // If a and m are relatively prime, then modulo inverse
        // is a^(m-2) mode m
      
             return power(a, m-2, m);
    }
}
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
 /*  ll n,k;
    cin>>n>>k;
    ll a[100005]={0};
    fore(i,0,n)cin>>a[i];
    ll p[100005]={0};
    p[0]=a[0];
    for(ll i=1;i<n;i++)
    {
        p[i]=p[i-1]+a[i];
    }
    ll ans=0,m=0;
    for(ll i=1;i<n;i++)
    {
        ll l,r;
        l=1;ll mid;
        r=i;
        while(l<=r)
        {
             mid=(l+r)>>1;
            ll sum=p[i]-p[mid-1];
            ll d=i-mid+1;
            if(a[i]*d-sum<=k && d>ans)
            {
                r=mid-1;
                ans=d;
                m=a[mid];
                cout<<a[i]<<endl;
            }
            else
            {
                l=mid+1;
            }
        }
        
    }
    cout<<ans<<" "<<m<<endl;*/
 int32_t main()
{
    Need_for_speed(activated);
//    satisfy
//    {}
    string a;
    cin>>a;
    for(ll i=0;i<a.length();i++)cout<<"x";
    
    return 0;
    }



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

struct Tree {
  int parent;
  int depth;
  string type;
  vector<int> children;
};

int main() {
  int n;
  cin >> n;
  Tree trees[n];
  for (int i = 0; i < n; i++) {
    trees[i].parent = -1;
  }
  for (int i = 0; i < n; i++) {
    int id;
    cin >> id;
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int child;
      cin >> child;
      trees[id].children.push_back(child);
      trees[child].parent = id;
    }
  }

  for (int i = 0; i < n; i++) {
    if (trees[i].parent == -1) {
      trees[i].type = "root";
    } else if (trees[i].children.size() == 0) {
      trees[i].type = "leaf";
    } else {
      trees[i].type = "internal node";
    }
  }

  for (int i = 0; i < n; i++) {
    string node_type = trees[i].type;
    int depth = 0;
    int index = i;
    while (node_type != "root") {
      index = trees[index].parent;
      depth++;
      node_type = trees[index].type;
    }
    trees[i].depth = depth;
  }
  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": ";
    cout << "parent = " << trees[i].parent << ", ";
    cout << "depth = " << trees[i].depth << ", ";
    cout << trees[i].type << ", ";
    cout << "[";
    for (int j = 0; j < trees[i].children.size(); j++) {
      cout << trees[i].children[j];
      if (j != trees[i].children.size()-1) cout << ", ";
    }
    cout << "]" << endl;
  }

  return 0;
}



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

using namespace std;

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

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5;

ll n, dp[N][2];

vector<ll> G[N];

ll solve(int u, int c, int p) {
    ll& ret = dp[u][c];
    if (~ret)
        return ret;

    // make it white

    ret = 1;
    for (auto to : G[u]) {
        if (to == p)
            continue;
        (ret *= solve(to, 0, u)) %= MOD;
    }

    if (c == 0) { // make it black
        ll cur = 1;
        for (auto to : G[u]) {
            if (to == p)
                continue;
            ((cur *= solve(to, 1, u)) %= MOD);
        }
        ret = (ret + cur) % MOD;
    }

    return ret;
}

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

    cin >> n;

    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

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

    cout << solve(0, 0, -1) << endl;
}

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

int M, A, X, N, D, E;
int bil[105], i;

int main () {
    cin >> N >> M >> X;
    for (int i=1;i<=M;i++){
        cin >> bil[i];
    }
    D=0;
    E=0;
    for (int i=1;i<X;i++){
        for (int j=1;j<=M;j++){
            if (i==bil[j]){
                D++;
            }
        }
    }
    for (int i=X+1;i<=N;i++){
        for (int j=1;j<=M;j++){
            if (i==bil[j]){
                E++;
            }
        }
    }
    if (D<E){
        cout << D << endl;
    }else{
        cout << E << endl;
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
inline int getint(){
    char c=getchar();int x=0;bool p=0;
    while((c>'9'||c<'0')&&c!='-')c=getchar();
    if(c=='-')p=1,c=getchar();
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    if(p)x=-x;return x;
}
int main(){
	int r,g,b,n,ans=0;
	cin>>r>>g>>b>>n;
	for(int i=0;i<=n;++i){
		if(i*r>n)break;
		for(int j=0;j<=n;++j){
			if(i*r+j*g>n)break;
			if((n-i*r-j*g)%b==0)++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, M;
vector<ll> E[100000];
bool visited[100000][2];

pll dfs(ll v, ll s) {
  visited[v][s] = true;

  pll ret = pll(1 - s, s);
  for(ll u : E[v]) if(!visited[u][1 - s]) {
    pll tmp = dfs(u, 1 - s);
    ret.fi += tmp.fi;
    ret.se += tmp.se;
  }
  return ret;
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, M) {
    ll A, B;
    cin >> A >> B; A--; B--;
    E[A].push_back(B);
    E[B].push_back(A);
  }

  REP(i, 0, N) REP(j, 0, 2) visited[i][j] = false;
  pll p = dfs(0, 0);

  if(p.fi == N && p.se == N) {
    cout << N * (N - 1) / 2 - M << endl;
  } else {
    cout << p.fi * p.se - M << endl;
  }
}


Measured memory_bytes: 8704
import sys
import numpy as np
input = sys.stdin.readline

try:
    inp = list(input().split())
    #listA<-[1,2,2,3,1]
    #print(listA)
    #ここに逐次処理を書けばいいと思う。
except:
    quit();
    #または、quit(),os.exit()をして止める。

try:
    h = list(map(int, input().split()))
    #listA<-[1,2,2,3,1]
    #print(listA)
    #ここに逐次処理を書けばいいと思う。
except:
    quit();
    #または、quit(),os.exit()をして止める。

N=int(inp[0])
K=int(inp[1])

dp=[0]*N

dp=np.array(dp)
h=np.array(h)

for j in range(1,N):
    bnum=max(0,j-K)
    dp[j]=np.min(np.abs(h[bnum:j]-h[j]) + dp[bnum:j])

print(dp[N-1])



Measured memory_bytes: 22872
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;
using ll=long long;
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}

constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}

int main() {
ll x,y;
ll ans=0;
cin >> x>>y;

if(x>=0&&y>=0){
  if(x<y){ans=abs(x,y);}else{ans=2+abs(x,y);}
}
if(x>=0&&y==0){
  if(x<y){ans=abs(x,y);}else{ans=1+abs(x,y);}
}
if(x>=0&&y<0){
  ans=1+abs(x,-y);
}
if(x<0&&y>0){
  ans=1+abs(-x,y);
}
if(x<0&&y==0){
  ans=abs(-x,y);
}
if(x<0&&y<0){
  if(x<y){
    ans=abs(x,y);
  }else{ans=2+abs(x,y);}

}


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


Measured memory_bytes: 256
// you**can**do**anything :)  
#include <bits/stdc++.h>
#include<iostream> 
#include<algorithm> 
#include<vector> 
#define ll long long
const int maxn=5e5+10;
char s[maxn];
using namespace std;
int main() {
 ll c,n,mm=0;
 cin>>c>>n ;
 ll a[n]={0};
 for(int i=0 ;i<n ;i++){
 	cin>>a[i];
 
 }
sort(a,a+n);
ll int total=0 ,la ,lw;
for(int i=n-1 ;i>0 ;i--){
if(mm<(a[i]-a[i-1]) ){
	mm=a[i]-a[i-1];
	la=a[i]; lw=a[i-1];
}

}
ll distance=(c-la)+(lw-a[0]);

cout<<c-max( mm ,a[0]+c-a[n-1] ) ;  //youssef ahmed ali amer**
}

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

int main() {
  int A,B,C,K,E;
  cin >>A>>B>>C>>K;
  if(K>=A+B){
    E=2*A+B-K;
    cout<<E<<endl;
  }
  else if(A<=K && K<B){
      cout <<A<<endl;
    }
  else{
    cout<<K <<endl;
  }
}
  


Measured memory_bytes: 3580
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main() {
  int m1, d1, m2, d2;
  readf (" %d %d %d %d", &m1, &d1, &m2, &d2);
  writeln (m1 != m2 ? 1 : 0);
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> dp(100001);
  dp[0] = 0;
  for (int i = 1; i <= 100000; i++)
    dp[i] = INT32_MAX;
  for (int i = 1; i <= N; i++)
  {
    for (int j = 1; j <= i; j *= 6)
      dp[i] = min(dp[i], dp[i - j] + 1);
    for (int j = 1; j <= i; j *= 9)
      dp[i] = min(dp[i], dp[i - j] + 1);
  }
  cout << dp[N] << endl;
  return 0;
}

Measured memory_bytes: 640
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()


da = []
daa = []

for i in range(n):
    x,y = m()

    da.append([x+y,x,y])
    daa.append([x-y,x,y])

da.sort()
daa.sort()

print(max(abs(da[0][0]-da[-1][0]),abs(daa[0][0]-daa[-1][0])))


Measured memory_bytes: 129544
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class CRectangle {
public:

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int H, W, h, w; cin >> H >> W >> h >> w;

      if (H%h == 0 && W%w == 0) {
        cout << "No" << endl;
        return;
      }

      cout << "Yes" << endl;
      bool tr = false;
      if (H%h == 0) {
        tr = true;
        swap(H, W);
        swap(h, w);
      }

      vector<int> sumh(H+1);
      sumh[0] = 0;
      for(int i=1; i<h; i++) {
        sumh[i] = 10000;
      }
      for(int i=h; i<=H; i++) {
        sumh[i] = sumh[i-h]-1;
      }

      vector<int> vec(H);
      rep(i, H) {
        vec[i] = sumh[i+1] - sumh[i];
      }

      vector<vector<int>> mat(H, vector<int>(W));
      rep(i, H) {
        rep(j, W) {
          mat[i][j] = vec[i];
        }
      }

      if (tr) {
        rep(j, W) {
          rep(i, H) {
            cout << mat[i][j] << ' ';
          }
          cout << '\n';
        }
      } else {
        rep(i, H) {
          rep(j, W) {
            cout << mat[i][j] << ' ';
          }
          cout << '\n';
        }
      }

    }
};

signed main() {
  CRectangle solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main()
{
	int n,a;

	cin >> n;

	int r = 1;

	while (r < 10)
	{
		if (n % r == 0)
		{
			a = n / r;
			if (a < 10) break;
		}

		r++;
	}

	if(r != 10) cout << "Yes" << endl;
    else cout << "No" << endl;
  
	return 0;
}

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

int main() 
{
  int a[5], b[5], c[5], m, t = 0;
  for (int i = 0; i < 5; i++)
  {
    cin >> a[i];
    b[i] = a[i] / 10;
    t += b[i];
    c[i] = a[i] % 10;
    if (c[i] != 0)
      t++;
    else
      c[i] = 10;
  }
  m = min({c[0],c[1],c[2],c[3],c[4]});
  t = (t - 1) * 10 + m;
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
int main()
{
	int a[10010],n,i,min=20000000,max=-20000000;
	long long int sum = 0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
		if(a[i]<min)
			min=a[i];
		if(a[i]>max)
			max=a[i];
	}
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}


Measured memory_bytes: 2120
N = int(input())

AC_count = 0
WA_count = 0
TLE_count = 0
RE_count = 0

for i in range(N):
  s = input()
  if s == 'AC':
    AC_count += 1
  elif s == 'WA':
    WA_count += 1
  elif s == 'TLE':
    TLE_count += 1
  elif s == 'RE':
    RE_count += 1
    
print("AC x {}".format(AC_count))
print("WA x {}".format(WA_count))
print("TLE x {}".format(TLE_count))
print("RE x {}".format(RE_count))
  

Measured memory_bytes: 9204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int ame[3][101];
int dp[3][101];
int main(){
  int n;cin >> n;
  rep(i,n) cin >> ame[0][i];
  rep(i,n) cin >> ame[1][i];
  dp[0][0] = ame[0][0];
  dp[1][0] = dp[0][0] + ame[1][0];

  for (int i = 0;i < 2;i++){
    for (int j = 0; j < n;j++){
      if (i == 0) dp[i][j+1] = max(dp[i][j+1],dp[i][j]+ame[i][j+1]);
      else dp[i][j+1] = max(dp[i-1][j+1]+ame[i][j+1],dp[i][j]+ame[i][j+1]);
    }
  }
  //rep(i,2){
  //  rep(j,n) cout << dp[i][j];
  //  cout << endl;
  //}
  cout << dp[1][n-1] << endl;

  

  return 0;

}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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);
    int H,W,N; cin >> H >> W >> N;
    if (H<W) swap(H,W);
    cout << (N+H-1)/H << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define ill long long 
using namespace std;

int main() {
  ill n, c = 0;
  cin >> n;
  rep(i, 0, n+1) {
    if(!(i % 3 == 0 || i % 5 == 0)) {
      c += i;
    }
  }
  cout << c;
}

Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n;
  string s;
  cin >> n >>  s;
  
  int cnt = 0;
  for (int i = 0; i <= n-3; i++) {
    if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') {
      cnt++;
    }
  }
  
  cout << cnt << endl;
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> a(n);rep(i,n)std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int a,b,c;
    std::cin >>a>>b>>c;
    if(a+b+c>21)std::cout << "bust" << std::endl;
    else std::cout << "win" << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


ll twocnt(ll n) {
  ll res=0;
  while(n%2==0) {res++; n>>=1;}
  return res;
}

ll a[MAX*10];
ll tc[MAX*10];

int main(void) {
  ll i, j, k, l;
  
  ll N;
  cin >> N;
  string s;
  cin >> s;
  
  for(i=0; i<N; i++) a[i]=s[i]-'0'-1;
  
  for(i=1; i<=N; i++) tc[i]=tc[i-1]+twocnt(i);
  
  ll m=0;
  for(i=0; i<N; i++) {
    ll c=tc[N-1]-tc[i]-tc[N-1-i];
    m^=(a[i]&1)*(c==0);
  }
  
  
  if(m) {
    pt(1); return 0;
  }else {
    for(i=0; i<N; i++) {
      if(a[i]==1) {
        pt(0); return 0;
      }
    }
    
    for(i=0; i<N; i++) a[i]>>=1;
    
    m=0;
    for(i=0; i<N; i++) {
      ll c=tc[N-1]-tc[i]-tc[N-1-i];
      m^=(a[i]&1)*(c==0);
    }
    
    if(m) pt(2);
    else  pt(0);
    
  }
  
  
}




Measured memory_bytes: 17028
#include<stdio.h>
#include<stdlib.h>
int linearSearch(int*,int,int);

int main(){
  int i;
  int n,q,s[100000],t[100000];
  int count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&t[i]);
  for(i=0;i<q;i++) count+=linearSearch(s,t[i],n);
  printf("%d\n",count);
  
  return 0;
}

int linearSearch(int *s,int key,int n){
  int i=0;
  
  s[n] = key;
  while(s[i]!=key){
    i++;
    if(i==n) return 0;
  }
  return 1;
}



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

int main() {
  int N;
  cin >> N;
  vector A(N, 0);
  for (int i = 0, a; cin >> a; i++) A.at(i) = a - i - 1;
  sort(A.begin(), A.end());
  long m = A.at(N / 2), ans = 0;
  for (auto a : A) ans += abs(a - m);
  cout << ans << "\n";
}

Measured memory_bytes: 4044
import java.util.*;
import java.math.BigDecimal;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a/b + " "+ a%b + " " + String.format("%.10f", (double) a/b) );

    }
}


Measured memory_bytes: 26344
import numpy as np
ans=0
D=int(input())
C=np.array(list(map(int,input().split())))
last_day=np.array([0 for _ in range(26)])

for day in range(1,D+1):
    score=np.array(list(map(int,input().split())))
    tmp=C*(last_day-day)
    S=sum(tmp)
    for k in range(26):
        tmp[k]=score[k]+S-tmp[k]
    #今回行うコンテストで得られる
    idx=np.argmax(tmp)
    # ans=ans+score[idx]+np.sum(tmp)+abs(tmp[idx])
    last_day[idx]=day
    print(idx+1)


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

ll xorAcumulate(ll n) {
  /*
  ll ret = 0;
  for (ll i = n / 4 * 4; i <= n; ++i) {
    ret ^= i;
  }
  */
	return ((n + 1) / 2 % 2) ^ (n % 2 ? 0LL : n);
//  return ret;
}

ll xorLR(ll l, ll r) {
  if (l == 0) return xorAcumulate(r);
  return xorAcumulate(r) ^ xorAcumulate(l - 1);
}

int main() { // claudio van
  ll a, b; scanf("%lld %lld", &a, &b);
  printf("%lld\n", xorLR(a, b));
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	bool f=0;
	for(int i=1;i<=1000;i++){
		if(a*i%b==c){
			f=1;break;
		}
	}
	puts(f?"YES":"NO"); 
	return 0;
}

Measured memory_bytes: 3600
while True:
    try:
        a=list(map(int,input().split()))
        #listA<-[1,2,2,3,1]
        #ここに逐次処理を書けばいいと思う。
        if a[0]==1:
            print(a[-1]*6000)
        elif a[0]==2:
            print(a[-1]*4000)
        elif a[0]==3:
            print(a[-1]*3000)
        else:
            print(a[-1]*2000)
        
    except:
        break;


Measured memory_bytes: 5600
// inputに入力データ全体が入る

function Main(input) {
//	S = input.split(" ");
	
S = input.trim().split("\n");
   // const S = arg[0];
//	console.log(S);
	if (S == 'Sunny'){console.log('Cloudy');
	               }
	      else if (S == 'Cloudy'){console.log('Rainy');}
	                           
	      
	           else if(S == 'Rainy') {console.log('Sunny');}
	            
	      

 
  	   }    //    1    
     
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

  


Measured memory_bytes: 7372
#include<stdio.h>
int main()
{
    int N,Y;
    int num;
    while(scanf("%d%d",&N,&Y)!=EOF)
    {
        num=N%500;
        if(num>Y)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int cnt[30][55];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		for (char c : s) {
			cnt[c-'a'][i]++;
		}
	}
	string ans;
	for (int i = 0; i < 26; i++) {
		int mini = 100;
		for (int j = 0; j < n; j++)
			mini = min(mini, cnt[i][j]);
		for (int j = 0; j < mini; j++)
			ans += (char)('a'+i);
	}
	cout << ans << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int c;
    while(cin >> c)
    {
        if(c % 39 == 0) cout << "3C" << 39 << endl;
        else if(c % 39 < 10) cout <<"3C0" << c % 39 << endl;
        else cout << "3C" << c % 39 << endl;
    }

    return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	l := make([]int, N+1)
	r := make([]int, N+1)
	l[0] = 0
	for i := 0; i < N; i++ {
		l[i+1] = GCD(l[i], A[i])
	}
	r[N] = 0
	for i := N; i >= 1; i-- {
		r[i-1] = GCD(r[i], A[i-1])
	}
	max := -1
	for i := 0; i < N; i++ {
		max = Max(max, GCD(l[i], r[i+1]))
	}
	fmt.Println(max)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 6016
#include <stdio.h>

int main(){
    int x[4],a,b=0;
    scanf("%d",&a);
    for(int i=0;i<4;i++){
        x[i] = a%10;
        a/=10;
    }
    for(int i=1;i<4;i++){
        if(x[i] == x[i-1]) b++;
    }
    if(b!=0){
        printf("Bad");
    }
    else printf("Good");
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N,K;
    cin>>N>>K;
    vector<ll> H(N);
    rep(i,N) cin>>H.at(i);
    if(N<=K){
        cout<<0<<endl;
        return 0;
    }
    sort(ALLOF(H));
    ll ans=0;
    rep(i,N-K) ans+=H.at(i);
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n;
    cin >> n;
    vector<pair<ll,ll> > pvec;
    for (ll i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        pvec.push_back(make_pair(a,b));
    }
    sort(ALL(pvec),pairCompareSecond);
    ll c=0;
    for (ll i=0;i<n;i++){
        c+=pvec[i].first;
        if (c>pvec[i].second){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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


int main() {
  int n,k;
  scanf("%d %d", &n, &k);
  int i,j;
  int array[1000];
  for(i = 0; i < n; i++) {
    scanf("%d", array+i);
  }
int tmp;
  for (i=0; i<n; ++i) {
    for (j=i+1; j<n; ++j) {
      if (array[i] > array[j]) {
        tmp =  array[i];
        array[i] = array[j];
        array[j] = tmp;
      }
    }
  }

  int x = 0;
  for(i = 0; i < k; i++) {
    x += array[i];
  }
  printf("%d",x);
}


Measured memory_bytes: 1732
#include <stdio.h>
#include <vector>

int main(){
  int n;
  scanf("%d",&n);
  std::vector<int> vvec,cvec;
  vvec.reserve(50);
  cvec.reserve(50);
  for(int i=0;i<n;i++){
    int value;
    scanf("%d ",&value);
    vvec.push_back(value);
  }
  for(int i=0;i<n;i++){
    int value;
    scanf("%d ",&value);
    cvec.push_back(value);
  }
  int sum=0;
  for(int i=0;i<n;i++){
    int value = vvec[i]-cvec[i];
    if(value>0) sum += value;
  }
  printf("%d",sum);
  return 0;
}

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

int main(){
    int a,b,m;
    cin >> a >> b >> m;
    int p[a],q[b],x[m],y[m],c[m];
    for(int i = 0; i < a; i++){
        cin >> p[i];
    }
    for(int i = 0; i < b; i++){
        cin >> q[i];
    }
    for(int i = 0; i < m; i++){
        cin >> x[i] >> y[i] >> c[i];
    }
    int ans = 1000000000;
    for(int i = 0; i < m; i++){
        ans = min(ans,p[x[i]-1] + q[y[i]-1] - c[i]);
    }
    sort(p, p+a);
    sort(q, q+b);
    ans = min(ans,p[0]+q[0]);
    cout << ans << endl;
    return 0;
}

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

int A[444][444];
bool del[444];
int cnt[444];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i ++)
    for (int j = 1; j <= m; j ++) scanf("%d", &A[i][j]);
  int ans = n;
  for (int i = 1; i < m; i ++) {
    int Max = 0;
    memset(cnt, 0, sizeof cnt);
    for (int j = 1; j <= n; j ++)
      for (int k = 1; k <= m; k ++)
        if (!del[A[j][k]]) {
          cnt[A[j][k]] ++;
          Max = max(Max, cnt[A[j][k]]);
          break;
        }
    for (int j = 1; j <= m; j ++)
      if (Max == cnt[j]) {
        del[j] = 1; break;
      }
    ans = min(ans, Max);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        // string a = Console.ReadLine();
        int[] a = Read.ints();
        Console.WriteLine(a[0]%3==0||a[1]%3==0||(a[1]+a[0])%3==0?"Possible":"Impossible");
    }

    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a * b / gcd(a, b);
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (long i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 11348
import networkx as nx
n,m=map(int, input().split())
uf=nx.utils.UnionFind()
for _ in range(m):
    a,b=map(int, input().split())
    uf.union(a, b)
ans=1
for i in uf.to_sets():
    ans=max(ans,len(i))
print(ans)

Measured memory_bytes: 103424
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String[] array = new String[s.length()];
    int[] numbers = new int[s.length()];


    for(int i=0;i<s.length();i++){
      array = s.split("");
    }
    for(int i=0;i<s.length();i++){
      numbers[i] =Integer.parseInt(array[i]);
    }
    //for(int a: numbers){
      //System.out.println(a);
    //}
    int sub_min = Integer.MAX_VALUE;
    for(int i=0; i<s.length()-2;i++){
      int k = numbers[i]*100+numbers[i+1]*10+numbers[i+2];
      if(Math.abs(k-753)<sub_min){
        sub_min = Math.abs(k-753);
      }
    }

    System.out.println(sub_min);

  }

}

Measured memory_bytes: 21844
a, b = map(int, input().split())
# map関数:map(関数,リスト) リストのすべての要素に関数を適用する
# split関数:変数名.split() 変数を区切る
# split関数は文字列型の為、数字に認識させるためにintを入れる
answer = a * b

print(answer)

Measured memory_bytes: 9028
/// a.cpp

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < __typeof(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int Rmin = 2e9,Rmax = 0,Bmin = 2e9,Bmax = 0;
    int n;
    fi>>n;
    priority_queue < pii , vii , greater < pii > > q;
    multiset < int > s1,s2;
    while (n --)
    {
        int a,b;
        fi>>a>>b;
        if (a > b) swap(a,b);
        smin(Rmin,a);
        smin(Bmin,b);
        smax(Rmax,a);
        smax(Bmax,b);
        q.push(mp(a,b));
        s1.insert(a);
        s2.insert(b);
    }
    ll ans = 1ll * (Bmax - Bmin) * (Rmax - Rmin);
    while (!q.empty())
    {
        auto node = q.top();
        q.pop();
        s1.erase(s1.find(node.x));
        s1.insert(node.y);
        s2.erase(s2.find(node.y));
        s2.insert(node.x);
        smin(ans,1ll * (*s1.rbegin() - *s1.begin()) * (*s2.rbegin() - *s2.begin()));
        if (node.x >= node.y)
            break;
        q.push(mp(node.y,node.x));
    }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 20592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll n,m;
    cin >> n >> m;
    if(n==1||m==1){
        if(n==1&&m==1)cout << 1 << endl;
        else cout << max(n,m)-2 << endl;
    }else{
        ll ans = (n-2)*(m-2);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*  
    ┬┴┬┴┤(･_├┬┴┬┴ hiding from those WAs
*/

#include <bits/stdc++.h>
using namespace std;

void ngk(){
	long long n, a, b;
	cin >> n >> a >> b;
	long long ans = a * (n / (a + b)) + min(n % (a + b), a);
	cout << ans;
}

int main(int argc, char *argv[]){
    iostream::sync_with_stdio(0);
    int test = 1;
    while(test--){
        ngk();
    }
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
h = list(map(int, input().split()))
res = [1 for _ in range(N)]

for _ in range(M):
    a, b = map(int, input().split())
    if h[a-1] == h[b-1]:
        res[a-1] = 0
        res[b-1] = 0
    elif h[a-1] < h[b-1]:
        res[a-1] = 0
    else:
        res[b-1] = 0

print(sum(res))

Measured memory_bytes: 20120
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

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



int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll n, k;
    ll ans = -INF;
    cin >> n >> k;
    vector <int> p(n), c(n);
    rep(i, n) cin >> p[i]; // 順列
    rep(i, n) cin >> c[i]; // ポイント
    rep(i, n) p[i]--;

    rep(si, n) {
        int          x   = si; // スタート地点
        ll           tot = 0; // 繰り返し単位の合計
        vector <int> s; // 繰り返し単位のポイントの列
        while (1) {
            x = p[x];
            s.push_back(c[x]);
            tot += c[x];
            if (x == si) { break; }
        }
        int l = s.size();
        ll  t = 0;
        rep(i, l) {
            t += s[i];
            if (i + 1 > k) { break; }//ループを1周もできない場合打ち切り
            ll now = t;
            if (tot > 0) {//繰り返し単位の合計が正なら足せるだけ足しちゃう
                ll kurikaeshi = (k - (i + 1)) / l;
                now += kurikaeshi * tot;
            }
            ans = max(ans, now);
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9+7;
signed main() {
    int n,k;
    cin>>n>>k;
    int h[n];
    int dp[n];
    for(int i=0 ; i<n ; i++) cin>>h[i];
    dp[0]=0;
    for(int i=1 ; i<n ; i++) {
        dp[i]=inf;
        for(int j=1 ; j<=k ; j++) {
            if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n-1];
}


Measured memory_bytes: 4308
N, M = map(int, input().split())

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N <= 1:
  N_cnt = 0
else:
  N_cnt = combinations_count(N, 2)
  
if M <= 1:
  M_cnt = 0
else:
  M_cnt = combinations_count(M, 2)
  
print(N_cnt + M_cnt)
  

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


int main()
{
	ll n;
	cin>>n;
	char ar[n];
	for(int i=0;i<n;i++)
		cin>>ar[i];

	if(n%2 == 1)
		cout<<"No"<<endl;

	else
	{
		int flg = 0;
		for(int i=0;i<n/2;i++)
		{
			if(ar[i] != ar[n/2+i])
				{
					flg=1; break;
				}
		}
		if(flg == 1)
			cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main(){
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
    }
    vector<int> vb(1e6+9);
    bool flag1=true;
    bool flag2=true;
    rep(j,n){
        for(int i=1;i<=sqrt(a[j]);i++){
            if(a[j]%i==0){
                if(vb[i]>0||vb[a[j]/i]>0){
                    flag1=false;
                    break;
                }
                if(a[j]!=1)
                vb[a[j]/i]++;
                if(i!=1)
                vb[i]++;
            }
        }
    }
    int g=gcd(a[0],a[1]);
    rep(i,n){
        g=gcd(a[i],g);
        if(g==1){
            flag2=false;
            break;
        }
    }
    if(flag1){
        cout<<"pairwise coprime"<<endl;
        return 0;
    }
    else if(flag2==false){
        cout<<"setwise coprime"<<endl;
        return 0;
    }
    else{
        cout<<"not coprime"<<endl;
        return 0;
    }
}

Measured memory_bytes: 11096
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void dk()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int knapsack(int a[], int val[], int n, int k)
{
    int dp[k + 1][n + 1];
    for (int i = 0; i <= n; i++)
    {
        dp[0][i] = 1;
    }
    for (int i = 0; i <= k; i++)
    {
        dp[i][0] = 1;
    }
    for (int i = 1; i <= k; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (a[j - 1] <= i)
            {
                dp[i][j] = max(dp[i][j - 1], dp[i - a[j - 1]][j - 1] + val[j - 1]);
            }
            else
            {
                dp[i][j] = dp[i][j - 1];
            }
            //cout << dp[i][j] << " ";
        }
        //cout << endl;
    }
    return dp[k][n];
}
int32_t main()
{
    //dk();
    int n, k;
    cin >> n >> k;
    int val[n], a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> val[i];
    }
    int m = knapsack(a, val, n, k);
    cout << m-1;
    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    string S; cin >> S;
    int res = 0;
    int cnt = 0;
    for (int i=0;i<S.size();i++){
        if (S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T'){
            cnt++;
            res = max(res,cnt);
        }
        else cnt = 0;
    }    
    cout << res << endl;

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// << fixed << setprecision
// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;

  vector<P> vp;
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    vp.push_back(P(a, b));
  }

  vp.push_back(P(INF, INF));
  sort(vp.begin(), vp.end());

  int r = INF;
  int ans = 0;
  REP(i, m + 1) {
    P p = vp[i];

    if(p.first >= r) {
      ans++;
      r = p.second;
    } else {
      r = min(r, p.second);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 4200
N= input()
W= input()
n = int(N)
w = list(map(int, W.split()))
min_dif =999999
for i in range(n):
  dif = abs(sum(w[:i]) - sum(w[i:]))
  if dif < min_dif:
    min_dif = dif
print(min_dif)

Measured memory_bytes: 3060