akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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);
    int n;
    cin >> n;
    const int INF = INT32_MAX;
    int ans = INF;
    vector<pair<int,int>> xp,xm,yp,ym; //x,y
    rep(i,n) {
        int x,y;
        char u;
        cin >> x >> y >> u;
        if(u == 'U') yp.emplace_back(x,y);
        if(u == 'R') xp.emplace_back(x,y);
        if(u == 'D') ym.emplace_back(x,y);
        if(u == 'L') xm.emplace_back(x,y);
    }
    //正面衝突 y方向
    map<int, set<int>> ym_map; //ym_map[x] = yの集合
     for(auto p: ym) {
         ym_map[p.first].insert(p.second);
     }
    for(auto p_yp: yp) {
        int x = p_yp.first;
        int y = p_yp.second;
        auto nearest  = ym_map[x].lower_bound(y);
        if(nearest != ym_map[x].end()) chmin(ans, (*nearest - y)*5);
    }
    //正面衝突 x方向
    map<int, set<int>> xm_map; //xm_map[y] = xの集合
     for(auto p: xm) {
         xm_map[p.second].insert(p.first);
     }
    for(auto p_xp: xp) {
        int x = p_xp.first;
        int y = p_xp.second;
        auto nearest  = xm_map[y].lower_bound(x);
        if(nearest != xm_map[y].end()) chmin(ans, (*nearest - x)*5);
    }
    
    //直角に衝突
    map<int, set<int>> yp2; //[y+x] = xの集合
    map<int, set<int>> yp3; //[y-x] = xの集合
    for(auto p: yp) {
        int x = p.first;
        int y = p.second;
        yp2[y+x].insert(x);
        yp3[y-x].insert(x);
    }

    map<int, set<int>> ym2; //[y+x] = xの集合
    map<int, set<int>> ym3; //[y-x] = xの集合
    for(auto p: ym) {
        int x = p.first;
        int y = p.second;
        ym2[y+x].insert(x);
        ym3[y-x].insert(x);
    }

    for(auto p: xp) {
        int x = p.first;
        int y = p.second;
        auto nearest1  = ym3[y-x].lower_bound(x);
        if(nearest1 != ym3[y-x].end()) chmin(ans, (*nearest1 - x)*10);
        auto nearest2  = yp2[x+y].lower_bound(x);
        if(nearest2 != yp2[x+y].end()) chmin(ans, (*nearest2 - x)*10);
    }

    for(auto p: xm) {
        int x = p.first;
        int y = p.second;
        auto nearest1  = ym2[x+y].upper_bound(x);
        if(nearest1 != ym2[x+y].begin()) {
            nearest1--;
            chmin(ans, (x-*nearest1)*10);
        }
        auto nearest2  = yp3[y-x].upper_bound(x);
        if(nearest2 != yp3[y-x].begin()) {
            nearest2--;
            chmin(ans, (x-*nearest2)*10);
        }
    }
    if(ans == INF) cout << "SAFE" <<endl;
    else cout << ans << endl;
}


Measured memory_bytes: 88064
N,M = map(int,input().split())
d = {}
for i in range(1,N+1):
    d[i] = 0

for i in range(M):
    a,b = map(int,input().split())
    d[a] += 1
    d[b] += 1

for i in range(1,N+1):
    print(d[i])


Measured memory_bytes: 38384
#include<iostream>

using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if( a < b && a < c && b <= c ){
    cout << a << " " << b << " " << c << endl;
  } else if( b <= a && b <= c && a <= c ){
    cout << b << " " << a << " " << c << endl;
  } else if( c <= b && c <= a && b <= a ){
    cout << c << " " << b << " " << a << endl;
  } else if( a <= c && a <= b && c <= b ){
    cout << a << " " << c << " " << b << endl;
  } else if( b <= c && b <= a && c <= a ){
    cout << b << " " << c << " " << a << endl;
  } else if( c <= b && b <= a && b <= a  ){
    cout << c << " " << b << " " << a << endl;
  } 

    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, a[210][3];
int f[210][110];
int sum[210];

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 3){
			cin >> a[i][j];
			f[i][a[i][j]]++;
		}
	}
	REP(k, 3){
		REP(i, n){
			bool f = 0;
			FOR(j, i + 1, n){
				if (a[i][k] == a[j][k]){
					f = 1;
					a[j][k] = 0;
				}
			}
			if (f)a[i][k] = 0;
		}
	}
	REP(i, n){
		REP(j, 3){
			sum[i] += a[i][j];
		}
		cout << sum[i] << endl;
	}
}

Measured memory_bytes: 1248
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<set>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp(const P a,const P b){
  return a.second < b.second;
}
int main()
{
  ll j,N,M,res=0,cut=0,now=-1,ind;
  P p[100002];
  p[100001] = P(99999999,0);
  cin >> N >> M;
  REP(i,M)
    cin >> p[i].first >> p[i].second;
  sort(p,p+M);
  set<int> sets;
  ind =0;
  for(int i=1;i<=N;i++){
    if(sets.count(i)){
      sets.clear();
      res++;
    }
    while(1){
      if(ind >= M || p[ind].first != i){
        break;
      }else{
        sets.insert(p[ind].second);
      }
      ind++;
    }
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



Measured memory_bytes: 2816
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
using namespace std;

const int INF=100000000;
int warshall_floyd(int a,int b,vector< vector<int> >& vi,int V);

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	while(cin>>n>>k&&n!=0&&k!=0){
		vector< vector<int> > wf(n+1,vector<int>(n+1));
		for(int i=1; i<n+1; ++i){
			for(int j=1; j<n+1; ++j){
				if(i==j){
					wf[i][j]=0;
				} else {
					wf[i][j]=INF;
				}
			}
		}
		for(int i=0; i<k; ++i){
			int s;
			cin >> s;
			if(s==0){
				int a,b;
				cin >> a >> b;
				if(wf[a][b]<INF){
					cout << wf[a][b] << "\n";
				} else {
					cout << -1 << "\n";
				}
			} else if(s==1){
				int c,d,e;
				cin >> c >> d >> e;
				if(e<wf[c][d]){
					wf[c][d]=e;
					wf[d][c]=e;
					warshall_floyd(1,1,wf,n);
				}
			}
		}
	}
	return 0;
}

int warshall_floyd(int a,int b,vector< vector<int> >& vi,int V){
	for(int k=1; k<=V; ++k){
		for(int i=1; i<=V; ++i){
			for(int j=1; j<=V; ++j)
				vi[i][j]=min(vi[i][j],vi[i][k]+vi[k][j]);
		}
	}
	return vi[a][b];
}

Measured memory_bytes: 1276
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	public void run(){
        Scanner scan = new Scanner(System.in);
        int[][] dx = {{0,1,2},{0,3,6},{0,4,8},{1,4,7},{3,4,5},{6,7,8},{2,4,6},{2,5,8}};
        int fl = 0;
        int t = 0;
        while(scan.hasNext()){
            String str = scan.nextLine();
            if(str.equals("0")){
            	break;
            }
            str += scan.nextLine() + scan.nextLine();
            fl = 0;
            for(int i = 0;i < 8;i++){
                t = 0;
                for(int j = 0;j < 3;j++){
                	switch(str.charAt(dx[i][j])){
                	case 'w':
                		t += 1;
                		break;
                	case 'b':
                		t += 9;
                		break;
                		default:
                			break;
                	}
                }
                if(t == 3){
                    fl = 1;
                    break;
                }else if(t == 27){
                    fl = 2;
                    break;
                }
            }
            System.out.println((fl == 0)?"NA":(fl == 1)?"w":"b");
        }
    }
}

Measured memory_bytes: 17284
// Running Offline
// g++ tester.cpp
// ./a.out
// #include "/Users/manasgupta/Desktop/stdc++.h"

 #include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pi pair<int,int>
#define pb push_back
#define fi first
#define se second
// #define mp make_pair
#define inf 1e9
#define EPS 1e-6
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FILEIO(name1, name2) \
    freopen(name1".txt","r",stdin); \
    freopen(name2".txt","w",stdout);

const int N=300005;
const int mod = 119 << 23 | 1;

int power(int a, int b, int c)
{
	int res=1;
	while (b)
	{
		if (b&1) res=(res*a)%c;
		a=(a*a)%c;
		b=b>>1;
	}
	return res;
}

int n,k;
int a[N][3];
int dp[N][3]={0};

signed main()
{
	IOS;
	cin>>n;
	for (int i=0; i<n; i++)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for (int i=1; i<n; i++)
	{
		for (int j=0; j<3; j++)
		{
			for (int k=0; k<3; k++)
			{
				if (j!=k)
				{
					dp[i][j]=max(dp[i][j], dp[i-1][k]+a[i][j]);
				}
			}
		}
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
    return 0;
}





Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int N,ans=1;
ll A[112345];
map<int,int> m;

ll dp[112345][2];
signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];
    if(N==2){
        cout<<max(A[0],A[1])<<endl;
        return 0;
    }


    dp[1][0]=__gcd(A[1],A[0]);
    dp[1][1]=A[1];
    for(int i=2;i<N;i++){
        dp[i][0]=max(__gcd(dp[i-1][0],A[i]),dp[i][0]);
        dp[i][1]=max({__gcd(dp[i-1][1],A[i]),dp[i-1][0],dp[i][1]});

    }

    dp[1][1]=A[0];
    for(int i=2;i<N;i++){
        dp[i][0]=max(__gcd(dp[i-1][0],A[i]),dp[i][0]);
        dp[i][1]=max({__gcd(dp[i-1][1],A[i]),dp[i-1][0],dp[i][1]});
    }

    cout<<dp[N-1][1]<<endl;


 
}

Measured memory_bytes: 2560
N, Y = map(int, input().split())

count = 0
x, y, z = -1, -1, -1
for i in range(N+1):
  for j in range(N+1):
    if i + j > N:
      continue
    if Y - (10000*i + 5000*j) == 1000*(N - i - j):
      x, y, z = i, j, (N - i -j)
      break
      
print(x, y, z)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    string s;
    cin >> s;
    int dir = 0, ans = 0, state = 0;
    for(auto c: s){
        if(c == 'R'){
            (++dir) %= 4;
            if(dir == (state+1)%4){
                state = dir;
                if(dir == 0) ++ans;
            }
            else if(dir == 0) state = 0;
        }
        else{
            (dir += 3) %= 4;
            if(dir == 0) state = 0;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 3340
#include <iostream>
using namespace std;
int main()
{
	int n;
	int h[30];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int count = 1;
	for (int i = 1; i < n; i++) {
		bool ch = true;
		for (int j = 0; j < i ; j++) {
			if (h[j] > h[i]) { ch = false; }
		}
		if (ch) { count++; }
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define PI 3.1415926535
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;


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 up(int a, int b) {
    return (a + a % b) / b;
}

void swap(string s) {
    int low = 0;
    int high = s.length() - 1;
    while (low < high) {
        char tmp = s[low];
        s[low] = s[high];
        s[high] = tmp;
        low++;
        high--;
    }
}

template<class T>  T gcd(T a, T b) {
    while (a % b != 0) {
        T tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

template<class T> T lcm(T a, T b) {
    if (a == b) return b;
    T g = gcd(a, b);
    return (a / g) * b;
}


int main() {
    double r;
    cin >> r;
    cout << 2.0 * r * PI << endl;
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  bool cnt = false;
  cin >> A>>B;
  string s;
  cin >> s;
  for(int i = 0;i<A;i++){
    if(s.at(i) != '-'){
      cnt = false;
    }
    else{
      cnt = true;
      break;
    }
  }
  if(s.at(A) != '-'){
    cnt = true;
  }
  for(int i = A+1;i<A+B+1;i++){
    if(s.at(i) == '-'){
      cnt = true;
      break;
    }
  }
  if(cnt == true){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if(A+B>C+D)
    cout << "Left" << endl;
  else if(A+B==C+D)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int h;
    int a;
    cin >> h >> a;

    int ans = h / a;
    if(h%a != 0){
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

# assert len(a) == n, "length doesn't match n"

"""
n = # of products
m = # of products to be selected
a = votes for product 1 >= i >= n
"""

minimum_vote = sum(a) / (4 * m)
# print(minimum_vote)

eligible = list(filter(lambda x: x >= minimum_vote, a))
# print(eligible)

if len(eligible) >= m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define ll long long

using namespace std;

int n;
vector<pair<ll, ll>> v;

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
    return atan2(a.second, a.first) < atan2(b.second, b.first);
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        pair<ll, ll> p; scanf("%lld%lld", &p.first, &p.second);
        if (p.first || p.second) v.push_back(p);
    }
    n = (int)v.size();
    // sort by slope
    sort(v.begin(), v.end(), cmp);
    ll ans = 0;
    // enumerate each vector as start
    for (int i = 0; i < n; i++) {
        int j = i; ll x = 0, y = 0;
        for (int k = 0; k < n; k++) {
            // just pick all vector and maintain ans directly
            x += v[j].first; y += v[j].second;
            ans = max(ans, x * x + y * y);
            if (++j == n) j = 0;
        }
    }
    printf("%.15f\n", sqrt(ans));

    return 0;
}

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

#define N 100000

int main(){
	char S[N+1];
	int i,r=0,b=0,ans;
	scanf("%s",&S);
	for(i=0;i<N;i++){
		if(S[i]=='\0')break;
		if(S[i]=='0')r++;
		else b++;
	}
	if(r<b)ans= r*2;
	else ans = b*2;
	printf("%d\n",ans);
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> cnt(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    ++cnt[a-1];
    ++cnt[b-1];
  }
  for (int i = 0; i < N; ++i) {
    cout << cnt[i] << endl;
  }
}

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

int main() {
  int n,W; cin>>n>>W;
  vector<int> w(n),v(n);
  rep(i, n) cin>>w[i]>>v[i];

  vector<vector<ll>> dp(n+1, vector<ll>(W+1, 0));
  rep(i, n) {
    rep(j, W+1) {
      if (j-w[i]>=0) dp[i+1][j]=max(dp[i][j], dp[i][j-w[i]]+v[i]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  cout<<dp[n][W]<<endl;
}


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

int main(){
	int wdp[30]={};
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	wdp[a]=1;
	wdp[b]=1;
	for(int i=0;i<30;++i){
		for(int j=0;j<30;++j){
			if(a*i+b*j<30)wdp[a*i+b*j]=1;
			else break;
		}
	}
	int sdp[1501]={};
	sdp[c]=1;
	sdp[d]=1;
	for(int i=0;i<1501;++i){
		for(int j=0;j<1501;++j){
			if(c*i+d*j<1501)sdp[c*i+d*j]=1;
			else break;
		}
	}
	double p=0;
	pair<int,int>ans(100*a,0);
	for(int i=1;i<30;++i){
		for(int j=0;j<1501;++j){
			if(wdp[i]&&sdp[j]){
				if(100*i+j<=f && j<=i*e){
					if(p<double(j)/(100*i+j)){
						p=double(j)/(100*i+j);
						ans=make_pair(100*i+j,j);
					}
				}
			}
		}
	}
	printf("%d %d\n",ans.first,ans.second);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e10+10;

/*----------------------------------------------*/

signed main(){
  int n;
  cin>>n;
  vi a(n);
  rep(i,n) cin>>a[i];
  int sw=0;
  rep(i,n){
    int minj=i;
    FOR(j,i,n-1){
      if(a[j]<a[minj]) minj=j;
    }
    if(minj!=i){
      int v=a[i];
      a[i]=a[minj];
      a[minj]=v;
      sw++;
    }
  }
  rep(i,n){
    if(i) cout<<" ";
    cout<<a[i];
  }
  cout<<endl;
  cout<<sw<<endl;
  return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	int *x = new int[N];
	for (int i = 0; i < N; i++)
		cin >> x[i];
	long sum = 0;
	for (int i = 0; i < N; i++) {
		sum += 2 * min(x[i], abs(x[i] - K));
	}
	cout << sum << endl;
	delete[] x;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=998244353;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

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

    ll ans=0;
    for(ll a=1;a<=n-1;a++){
        ans+=(n-1)/a;
    }

    cout<<ans<<endl;
}

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

struct mydata{
    long long x, y, z;
};

int main() {
    long long n, m;
    cin >> n >> m;
    vector<mydata> a(n);
    for(int i = 0; i <n ; i++){
        cin >> a[i].x >> a[i].y >> a[i].z;
    }
    long long ans = -(1LL << 60);
    for(int i = 0; i<8 ; i++){
        vector<long long> vec;
        for(int j = 0; j<n ;j++){
            long long sum = 0;
			for (int k = 0; k < 3; k++) {
			    long long temp;
		        if(k == 0)
		            temp = a[j].x;
		        else if(k == 1)
		            temp = a[j].y;
		        else
		            temp = a[j].z;
			    if ((i / (1 << k)) % 2 == 0){ 
			        sum += temp; 
			    }
			    else{
			        sum -= temp;
			    }
			}
			vec.push_back(sum);
        }
        
        sort(vec.begin(), vec.end());
        reverse(vec.begin(), vec.end());
        long long res = 0;
        for(int i = 0 ; i<m ; i++)
            res += vec[i];
        ans = max(ans, res);
    }
    
    cout<<ans<<endl;
    return 0;
    
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, M; cin >> N >> M;
	Graph G(N);
	vector<int>d(N, 0);
	rep(i, 0, M) {
		int x, y; cin >> x >> y;
		--x; --y;
		G[x].push_back(y);
		d[y]++;
	}

	//topologicalSort
	stack<int> st;
	rep(i, 0, N) {
		if (d[i] == 0) {
			st.push(i);
		}
	}
	vector<int>vec;
	while (!st.empty()) {
		int node = st.top();
		st.pop();
		vec.push_back(node);
		for (auto p : G[node]) {
			d[p]--;
			if (d[p] == 0)st.push(p);
		}
	}
	
	//dp
	vector<int>dp(N, -1);
	rep(i, 0, vec.size()) {
		int k = vec[i];
		if (dp[k] == -1) {
			dp[k] = 0;
		}
		for (auto e : G[k]) {
			chmax(dp[e], dp[k] + 1);
		}
	}
	int ans = 0;
	rep(i, 0, dp.size()) {
		chmax(ans, dp[i]);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 7032
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
n = int(input())
a = [int(x) for x in input().split()]
sum = 0
G=1
for elem in a:
    G=lcm(G,elem)
for elem in a:
  sum+=G//elem
print(sum%1000000007)

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


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

    int n=S.size();

    for(int i=0;i<n;i++){
        cout<<'x';
    }
    return 0;
}

Measured memory_bytes: 256
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                       *
 *          Fortis Fortuna Adiuvat                                       * 
 *                          "Fortune Favours the bold"                   *
 *                                                                       *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define vll vector<int>
#define pb push_back
#define pll pair<int, int>
#define w(t) int t; cin >> t; while(t--)
#define print(x,y) cout << x << " " << y << endl
#define deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define setbits(x) __builtin_popcountll(x)
#define endl "\n"

template <typename T>
void write(vector<T> &a) {        
    for(auto it = a.begin(); it != a.end(); it++)
        cout << *it << " ";
    cout << endl;}
void random(int nMin, int nMax, int n){
    srand(time(0));
    for(int i = 0; i < n; i++){
        double var = nMin + (int)((double)rand() / ((double)RAND_MAX+1) * (nMax-nMin+1));cout << var << " ";}cout << endl;
}
///////////Helper Functions///////////


////////////Main Method///////////////
int32_t main()
{
//////////////////////////////////////////////////////////
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cout << setprecision(15);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
//////////////////// Code Here ///////////////////////////    
{
    int k; cin >> k;

    if(fmod(k, 2) == 0 || fmod(k, 5) == 0)
    {
        cout << -1 << endl;
        return 0 ;
    }

    int tmp = -1;
    int count = 0;

    while(tmp != 0)
    {
        if(tmp == -1)
            tmp = 0;

        tmp = (tmp*10 + 7) % k;
        count++ ;
    }

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

Measured memory_bytes: 3768
N = int(input())
result = 0

for i in range(1, N+1):
    if i%2 == 0:
            continue
            
    count = 0
    for j in range(1, i+1):
        if i % j == 0:
            count += 1
    if count == 8:
        result += 1

print(result)

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

const int N = 1e5+5;
int n;
int a[N];
int dp[N];

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

    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];

    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(int i = 2; i < n; i++)
        dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));

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

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<long long>mon(N+1,0);
  for(int i=0;i<N+1;i++){
    cin >> mon[i];
  }
  
  vector<long long>ysa(N,0);
  for(int i=0;i<N;i++){
    cin >> ysa[i];
  }
  
  long long ans = 0;
  
  for(int i=0;i<N;i++){
    if(mon[i] >= ysa[i]){
      ans += ysa[i];
      ysa[i] = 0;
    }
    else{
      ans += mon[i];
      ysa[i] -= mon[i];
      if(mon[i + 1] >= ysa[i]){
        ans += ysa[i];
        mon[i + 1] -= ysa[i];
      }
      else{
        ans += mon[i + 1];
        mon[i + 1] = 0;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

 

Measured memory_bytes: 1792
#!/usr/bin/env python3

def main():
    N, S = map(str, open(0).read().split())
    N = int(N)
    if not N % 2 == 0:
        print('No')
    else:
        if (S[0:N//2] == S[-(-N//2):]):
            print('Yes')
        else:
            print('No')


main()

Measured memory_bytes: 2940
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
vector<int> v[200008]; int dis[200008];
void bfs()
{
	queue<int> q;
	for(int i=1;i<=200005;i++) dis[i]=123456;
	dis[1]=0;q.push(1);
	while(q.empty()==0)
	{
		int a=q.front();
		q.pop();if(dis[a]==2) break;
		for(int i=0;i<v[a].size();i++)
		{
			int b=v[a][i];
			if(dis[a]+1<dis[b]) dis[b]=dis[a]+1,q.push(b);
		}
	}
}
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int n,m;cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;cin>>a>>b;v[a].push_back(b);v[b].push_back(a); 
	}
	bfs();
	if(dis[n]<=2) cout<<"POSSIBLE";else cout<<"IMPOSSIBLE";cout<<endl;
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int MinimumNumIncreasingSubsequences(vector<ll> arr,int n)
{
    multiset<ll> last;

    // last element in each  increasing subsequence
    // found so far
    for (int i = 0; i < n; i++) {

        // here our current element is arr[i]
        multiset<ll>::iterator it = last.lower_bound(arr[i]);

        // iterator to the first element larger
        // than or equal to arr[i]
        if (it == last.begin())

            // if all the elements in last larger
            // than or to arr[i] then insert it into last
            last.insert(arr[i]);

        else {
            it--;

            // the largest element smaller than arr[i] is the number
            // before *it which is it--
            last.erase(it); // erase the largest element smaller than arr[i]
            last.insert(arr[i]); // and replace it with arr[i]
        }
    }
    return last.size(); // our answer is the size of last
}
int main()
{
	IOS;
    cout.precision(30);
    int n; cin >> n; vector<ll> A(n,0);
    for (int i=0;i<n;i++)
    {
        cin >> A[i];
    }
    ll ans=MinimumNumIncreasingSubsequences(A,n);
    cout << ans;
    return 0;
}


Measured memory_bytes: 6528
from collections import defaultdict
n,k = map(int, input().split())
a = list(map(lambda z:int(z)-1, input().split()))
if k <= n:
    now = 0
    for i in range(k):
        now = a[now]
    print(now+1)
    exit()
root = [0]
use = [-1 for _ in range(n)]
use[0] = 0
now = 0
l = -1
for i in range(1,n+1):
    now = a[now]
    if use[now] == -1:
        use[now] = i
    else:
        k -= i
        l = i - use[now]
        break
k %= l
for i in range(k):
    now = a[now]
print(now+1)


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


int main(){
    int n,k;
    cin >> n>>k;
    ll sum=0;
    sum+=pow(n/k,3);
    if(k%2==0){
        sum+=pow((n+k/2)/k,3);
    }
    
    cout << sum << endl;
    
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

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

    LL res = 0;
    int cnt = 1;
    rep(i, t + 1) {
        if (i == a * cnt) {
            res += b;
            // cout << "!" << endl;
            cnt++;
        }
    }
    cout << res <<endl;
    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
bool f[53][53];
bool check(int n,int m){
	return f[n-1][m]||f[n+1][m]||f[n][m-1]||f[n][m+1];
}
int main(){
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	memset(f,0,sizeof(f));
	char c;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c;
			if(c=='#') f[i][j]=true;
			else f[i][j]=false;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(f[i][j]&&!check(i,j)){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
  int N, K;

  cin >> N >> K;

  vector<ll> H(N);
  for (int i = 0; i < N; i++){
    cin >> H[i];
  }

  sort(H.begin(), H.end());

  ll ans = 0;
  for (int i = 0; i < N - K; i++) {
    ans += H[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    int ans = t.size();

    for(int start = 0; start <= s.size() - t.size(); start ++)
    {
        int diff = 0;

        for(int i = 0; i < t.size(); i ++)
        {
            if(t[i] != s[start + i])
            {
                diff ++;
            }
        }
        ans = min(ans, diff);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
s = input()
small = [chr(i+97) for i in range(26)]
count = 0
for i in range(len(s)):
    if i == 0:
        if s[i] == 'A':
            continue
        else:
            print("WA")
            break
    elif i == 1:
        if not s[i] in small: 
            print("WA")
            break
    elif i == len(s)-1:
        if not s[i] in small:
            print("WA")
            break
    else:
        if s[i] == 'C':
            count += 1
        elif not s[i] in small:
            print("WA")
            break
else:
    if count == 1:
        print("AC")
    else:
        print("WA")


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#define INF 1000000000
#define MAX 2000000

int size = 0;
int A[MAX];

void maxHeapinsert(int);
void heapIncreaseKey(int,int);
int heapExtractMax(void);
int left(int);
int right(int);
void maxHeapify(int);

int main() {

  int key,max;
  char str[10];
  
  while(1) {
    
    scanf("%s",str);

    if(str[0] == 'i') {
      scanf("%d",&key);
      maxHeapinsert(key);
    }
    
    if(str[2] == 'd')
      break;
    
    if(str[0] == 'e') {
      max = heapExtractMax();
      printf("%d\n",max);
    }
  }

  return 0;
}



void maxHeapinsert(int key)
{
  size++;
  A[size] = -INF;
  heapIncreaseKey(size,key);
}


void heapIncreaseKey(int i,int key)
{
  int temp;
  if(key < A[i]) {
    exit(0);
  }

  A[i] = key;
  while(i > 1 && A[i/2] < A[i]) {

    temp = A[i];
    A[i] = A[i/2];
    A[i/2] = temp;
    i = i/2;
  }

}



int heapExtractMax(void)
{
  int max;
  if(size < 1) {
    exit(1);
  }
  
  max = A[1];
  A[1] = A[size];
  size--;
  maxHeapify(1);

  return max;
}

int left(int i)
{
  return 2*i;
}

int right(int i)
{
  return 2*i + 1;
}

void maxHeapify(int i)
{
  int l,r,largest,temp;
  l = left(i);
  r = right(i);

  if(l <= size && A[l] > A[i])
    largest = l;
  else
    largest = i;
  
  if(r <= size && A[r] > A[largest])
    largest = r;

  if(largest != i) {
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
  
}



Measured memory_bytes: 5632
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n, m;
int w[10][10];

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		w[u][v] = w[v][u] = 1;
	}

	VI V;
	for (int i = 1; i <= n; i++) V.push_back(i);

	int total = 0;
	do {
		if (V[0] != 1) continue;
		int ok = 1;
		for (int i = 0; i < n - 1; i++) ok &= w[V[i]][V[i + 1]];
		total += ok;
	} while (next_permutation(ALL(V)));

	printf("%d\n", total);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
	int t;
	cin>>t;
	vector<int>v(t);
	for(int i=0;i<t;i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	double sum=v[0];
	for(int i=1;i<t;i++){
		sum=(sum+v[i])/2;
	}
	printf("%.10f\n",sum);
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> field = new ArrayList<>(Arrays.asList(0,0,0));
		long scoreCount = 0;
		int outCount = 0;
		try {
			int gameNumber = Integer.parseInt(br.readLine());
			while (0 < gameNumber) {
				String line = br.readLine();
				if(line.equals("HIT")) {
					if(field.get(2)==1) {
						scoreCount++;
					}
					field.remove(2);
					field.add(0, 1);
				}else if(line.equals("OUT")) {
					outCount++;
					if (outCount == 3) {
						System.out.println(scoreCount);
						scoreCount = 0;
						outCount = 0;
						field = new ArrayList<>(Arrays.asList(0,0,0));
						gameNumber--;
					}
				}else if(line.equals("HOMERUN")) {
					scoreCount += 1 + field.stream().filter(base -> base==1).count();
					field = new ArrayList<>(Arrays.asList(0,0,0));
				}
			}
			System.exit(0);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 30508
#include<iostream>
#include<string>
#include<vector>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
 
int main(){
  fastIO;
  int h,w;
  cin>>h>>w;
  
  for(int i=0;i<h;i++){
    char s[101];
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  char c[3];
  cin >> c;
  sort(c, c+3);
  if(c[0]=='a' && c[1]=='b' && c[2]=='c')cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1))
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S = "CODEFESTIVAL2016";
	string T;
	cin >> T;
	int ans = 0;
	rep(i, S.size())if (S[i] != T[i])ans++;
	cout << ans << endl;
}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  ll a,b,v,w;
  cin >> a >> v;
  cin >> b >> w;
  ll t; cin >> t;

  string ans;
  if(v < w){
    ans = "NO";
  } else {
    if(abs(a-b) > abs(v-w) * t){
      ans = "NO";
    } else {
      ans = "YES";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
N = int(input())
a = list(map(int, input().split()))

## 高々 N(N-1)/2　< 2 * 10^10 のため何とかなる...?
mod = 10**9 + 7

'''
sum = 0
for i in range(N-1):
    for j in range(i+1,N):
        sum += a[i]*a[j]

ans = sum % mod
print(ans)
'''

### a1　は a2~an(= S)までの和を必要とする. a2 は S - a2 (=S). a3 は S - a3...

s = 0
for i in range(N):
    s += a[i]

sum = 0
for i in range(N-1):
    s -= a[i]
    sum += a[i]*s

ans = sum % mod
print(ans)

Measured memory_bytes: 30960
from collections import deque
while True:
    w,h=map(int,input().split())
    if w==0 and h==0:
        exit()
    field=[input().split() for i in range(h)]
    
    option=deque()
    for i in range(h):
        for j in range(w):
            if field[i][j]=="1":
                option.append([i,j])
                break
        else:
            continue
        break
    completed=[[0]*w for i in range(h)]
    cnt=1
    while option:
        y,x=option.pop()
        completed[y][x]=cnt
        for dy,dx in ((-1,0),(1,0),(0,-1),(0,1),(-1,-1),(1,-1),(-1,1),(1,1)):
            if 0<=y+dy<=h-1 and 0<=x+dx<=w-1 and field[y+dy][x+dx]=="1" and completed[y+dy][x+dx]==0:
                ny=y+dy
                nx=x+dx
                option.append([ny,nx])
        if len(option)==0:
            for i in range(h):
                for j in range(w):
                    if field[i][j]=="1" and completed[i][j]==0:
                        option.append([i,j])
                        cnt+=1
                        break
                else:
                    continue
                break
    ans=0
    for i in completed:
        tmp=max(i)
        ans=max(ans,tmp)
    print(ans)



Measured memory_bytes: 6568
#include<stdio.h>
int main()
{
	int n,i,a[30];
	while(~scanf("%d",&n))
	{for(i=1;i<=n;i++)
	 scanf("%d",&a[i]);
	 int ans=0;
	 for(i=2;i<n;i++)
	 {if(a[i]<a[i+1]&&a[i]>a[i-1])
	  ans+=1;
	  if(a[i]>a[i+1]&&a[i]<a[i-1])
	  ans+=1;
	 }
	 printf("%d\n",ans);
	}
}

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

using namespace std;

#define int long long

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &t : a) {
		char c;
		cin >> c;
		if (c == 'R') t = 0;
		if (c == 'G') t = 1;
		if (c == 'B') t = 2;
	}	
	vector<vector<int>> c(3, vector<int>(n + 1));
	for (int j = 0; j < 3; j++) {
		c[j][n] = 0;
		for (int i = n - 1; i >= 0; i--) {
			c[j][i] = c[j][i + 1] + (a[i] == j);
		}
	}
	// cerr << -1 << endl;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] == a[j]) continue;
			// cerr << i << ' ' << j << endl;
			int cr = c[3 - a[i] - a[j]][j + 1];
			int dl = j - i;
			if (j + dl < n && a[j + dl] == 3 - a[i] - a[j]) cr--;
			ans += cr;
		}
	}
	cout << ans << endl;
}


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

int main(){
  int64_t a,b;
  cin >> a >> b;
  if(a+b==0) cout << "Zero" << endl;
  if(a+b>0) cout << "Positive" << endl;
  if(a+b<0){
    if(abs((a-b)%2)==1) cout << "Positive" << endl;
    else cout << "Negative" << endl;
  }
}

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

int main(){
    int N; cin >> N;
    int A[200200], B[200200];
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
    }


    bool flag=true;
    for(int i=0; i<N; i++){
        if(A[i]!=B[i]) flag =false;
    }
    if(flag){cout << 0 << endl; return 0;}

    long long ans=0;
    for(int i=0; i<N; i++){
        ans += A[i];
    }
    int min_num=INT_MAX;
    for(int i=0; i<N; i++){
        if(B[i]<A[i]){
            min_num=min(min_num, B[i]);
        }
    }
    cout << ans-min_num << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define ALL(n) begin(n), end(n)

int main()
{
  long long N, cnt = 0, num = 1;
  cin >> N;
  rep(i, N)
  {
    long long a;
    cin >> a;
    if (a != num)
      cnt++;
    else
      num++;
  }
  if (num == 1)
    cout << -1 << endl;
  else
    cout << cnt << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

NN = [-1] * N
NN[0] = 0

i = 0
num = 0

while True:
    num += 1
    i = A[i] - 1
    if NN[i] != -1:
        n1 = NN[i]
        break
    NN[i] = num

n_ = num - n1

if K > n1:
    K -= n1
    t = NN.index(n1 + K % n_) + 1
    print(t)
else:
    t = NN.index(K) + 1
    print(t)


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

int main(){
	while(1){
		string s1,s2;
		cin >> s1;
		if(s1 == ".") return 0;
		cin >> s2;
		string s11[201], s22[201];
		for(int i=0;i<201;i++){
			s11[i] = "."; s22[i] = ".";
		}
		int now1=0,now2=0;
		for(int i=0;i<(int)s1.length();i++){
			if(s1[i] == '"'){
				now1++;
				s11[now1] = "";
			}else s11[now1] += s1[i];
		}
		for(int i=0;i<(int)s2.length();i++){
			if(s2[i] == '"'){
				now2++;
				s22[now2] = "";
			}else s22[now2] += s2[i];
		}
		int d=0;
        int maxnow;
        if(now1 < now2) maxnow = now2;
        else maxnow = now1;
		for(int i=0;i<maxnow+1;i++){
			if(s11[i] != s22[i]){
				if(i&1){
					d++;
				}else d+=2;
			}
		}
		if(d==0)cout<<"IDENTICAL";
		else if(d==1)cout<<"CLOSE";
		else cout<<"DIFFERENT";
		cout<<"\n";
	}
}


Measured memory_bytes: 3168
import Control.Monad
import Control.Applicative

combinations :: Int -> [a] -> [[a]]
combinations 0 _ = [[]]
combinations _ [] = []
combinations n (x:xs) = (map (x:) (combinations (n-1) xs)) ++ (combinations n xs)

solve :: [Int] -> String
solve [n, x] =
   show $ length [nc3 | nc3<-combinations 3 [1..n], sum nc3==x]

main =
    mapM_ putStrLn =<< map solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = takeWhile (not . all (== 0)) . map (map read . words)

Measured memory_bytes: 5432
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

char win(char c) {
    switch(c) {
        case 'r': return 'p';
        case 's': return 'r';
        case 'p': return 's';
    }
    return 0;
}

int main() {
    int n, k; cin >> n >> k;
    int r, s, p; cin >> r >> s >> p;
    string t; cin >> t;
    int m['z'+1];
    m['r'] = r;
    m['s'] = s;
    m['p'] = p;

    vector<char> hist(n, 0);
    int score = 0;
    rep(i, k) {
        score += m[win(t[i])];
        hist[i] = win(t[i]);
    }
    FOR(i, k, n) {
        if(hist[i-k] != win(t[i])) {
            score += m[win(t[i])];
            hist[i] = win(t[i]);
        }
    }

    cout << score << endl;
    return 0;
}


Measured memory_bytes: 512