akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<stdbool.h>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<set>
#include<string>
typedef long long ll;
using namespace std;
int t[110][110] = { 0 };


int main(){
	int h, w, n;
	cin >> h >> w;
	cin >> n;
	vector<int>a(n + 1);
	int j = 0;
	int k = 0;
	bool flag = true;
	for (int i = 1;i <= n;i++)cin >> a[i];
	for (int i = 1;i <= n;i++) {
		while (a[i] != 0) {
			if (flag) {
				t[j][k] = i;
				k++;
				a[i]--;
				if (k == w) {
					j++;
					k--;
					flag = false;
				}
			}
			else {
				t[j][k] = i;
				k--;
				a[i]--;
				if (k == -1) {
					j++;
					k++;
					flag = true;
				}
			}
		}
	}
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			if (j != w - 1)cout << t[i][j] << " ";
			else cout << t[i][j] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.util.stream.Collectors;
 
 
public class Main {
    public static void main(String[] args) {
    	
        Scanner scanner=new Scanner(System.in);
        
        int N = scanner.nextInt();
        String s = scanner.next();
        
        int East = 0;
        int West = 0;
        
        for(int i=0;i<N;i++)
        	if(s.charAt(i)=='E')
        		East++;
        West = N - East;
        
        int ans = East;
        int count = East;
        
        for(int i=0;i<N;i++){
        	if(s.charAt(i)=='E')
        		count--;
        	//System.out.print(count);
        	if(0<i&&s.charAt(i-1)=='W')
        		count++;
        	//System.out.println(count);
        	if(count<ans)
        		ans = count;
        }
        
        System.out.println(ans);
 
 
    }
 
}


Measured memory_bytes: 28756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   ll x, k, d;
   cin>>x>>k>>d;

   x=abs(x);
   ll tk=x/d;
   if(tk>=k){
      x-=k*d;
      cout<<x<<endl;
      return 0;
   }
   x-=tk*d;
   k-=tk;

   if(k%2==0){
      cout<<x<<endl;
      return 0;
   }
   else{
      x=abs(x-d);
      cout<<x<<endl;
      return 0;
   }

   return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  ll a[n];
  ll ab=-1;
  rep(i,n){
    cin >> a[i];
    ab=max(ab,abs(a[i]));
  }
  ll x=-1;
  int idx=-1;
  rep(i,n){
    if(abs(a[i])==ab){
      x=a[i];
      idx=i;
    }
  }
  cout << 2*(n-1) << endl;
  if(x>=0){
    rep(i,n){
      if(i!=idx){
        cout << idx+1 << ' ' << i+1 << endl;
      }
    }
    rep(i,n-1){
      cout << i+1 << ' ' << i+2 << endl;
    }
  }else{
    rep(i,n){
      if(i!=idx){
        cout << idx+1 << ' ' << i+1 << endl;
      }
    }
    for(int i=n-2;i>=0;i--){
      cout << i+2 << ' ' << i+1 << endl;
    }
  }
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=3e5+9;
int n,m,k,has,v[20];
char a[8][8],g[8][8];

void clean(){
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            a[i][j]=g[i][j];
        }
    }
}

void c(int r,int c){
    if(c!=-1){
        for(int i=0;i<n;i++){
            if(a[i][c]=='#')a[i][c]='.';
        }
     }
     if(r!=-1) {
        for(int i=0;i<m;i++){
            if(a[r][i]=='#')a[r][i]='.';
        }
    }
}

bool ok(){
    int has=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(a[i][j]=='#')has++;
        }
    }
    return has==k;
}

int main()
{
/*#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif*/
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    vector<pair<int,int>>v;
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>g[i][j];
        }
    }
    int ans=0;
    int tot=n+m;
    for(int i=0;i<n;i++){
        v.push_back({0,i});
    }
    for(int i=0;i<m;i++){
        v.push_back({1,i});
    }
    for(int mask=0;mask<(1<<tot);mask++){
        clean();
        for(int i=0;i<tot;i++){
            if((mask>>i)&1){
                int rr=v[i].first;
                int who=v[i].second;
                if(rr==0){
                    c(who,-1);
                }
                else {
                    c(-1,who);
                }
            }
        }
        if(ok())ans++;
    }
    cout<<ans<<'\n';



    return 0;
}



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

int S[3][4010];
int main()
{
    int n; cin>>n;
    string s; cin>>s;

    for(int i=0; i<n; ++i)
        for(int j=0; j<3; ++j)
            S[j][i+1]=S[j][i]+(s[i]%3==j);

    long res=0;
    for(int i=0; i<n; ++i) {
        for(int j=i+1; j<n; ++j) {
            if (s[i]!=s[j]) {
                int x=3^(s[i]%3)^(s[j]%3);
                res+=S[x][n]-S[x][j];

                int k=j+j-i;
                if (k<n and s[k]%3==x) --res;
            }
        }
    }
    cout<<res<<endl;
}


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

int main()
{
  int N, ans = 0;
  cin >> N;
  vector<float> v(N);

  for (int i = 0; i < N; ++i) cin >> v[i];

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

  for (int i = 0; i < N - 1; ++i) {
    v[i + 1] = (v[i + 1] + v[i]) / 2;
  }

  cout << v[N - 1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <string.h>

typedef long long ll;
using namespace std;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;

const double EPS = 1e-8;

int main()
{
	ll x=0,N,max=0,temp=0;
	char S[100];

	cin >> N;
	cin >> S;
	
	for(int i=0;i<N;i++){
		if(S[i]=='I'){
			x++;
		}else if(S[i]=='D'){
			x--;
		}

		if(x>=max){max=x;}
	}

	cout << max;

	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		double a = Double.parseDouble(s.next());
		double b = Double.parseDouble(s.next());
		double c = Double.parseDouble(s.next());

		
		double h = b * Math.sin(Math.toRadians(c));
		double S = a * h / 2;
		double a1 = b * Math.cos(Math.toRadians(c));
		double a2 = a - a1;
		double d = Math.sqrt(Math.pow(a2, 2) + Math.pow(h, 2));
		double L = a + b + d;
		System.out.println(String.format("%.8f", S));
		System.out.println(String.format("%.8f", L));
		System.out.println(String.format("%.8f", h));
	}

}

Measured memory_bytes: 17328
h,w,m=map(int,input().split())
hlist=[0]*(h+1)
wlist=[0]*(w+1)
cnt=set()


for i in range(m):
  a,b=map(int,input().split())
  hlist[a]+=1
  wlist[b]+=1
  cnt.add((a,b))


hcnt,wcnt=max(hlist),max(wlist)


hhh=[i for i,v in enumerate(hlist) if v==hcnt]
www=[i for i,v in enumerate(wlist) if v==wcnt]


for i in hhh:
  for j in www:
    if not (i,j) in cnt:
      print(hcnt+wcnt)
      exit()


print(hcnt+wcnt-1)


Measured memory_bytes: 176756
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int ab, bc, ca;
  cin >> ab >> bc >> ca;
  cout << bc * ab / 2 << endl;
}


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

int main() {
    int n, m;
    std::cin >> n >> m;

    auto works = std::vector<std::vector<uint64_t> >(m, std::vector<uint64_t>());

    for(int i = 0; i < n; ++i) {
        int a, b;
        std::cin >> a >> b;
        --a;
        if(a < m) {
            works[a].push_back(b);
        }
    }

    auto available_works = std::priority_queue<uint64_t>();

    uint64_t answer = 0;

    for(const auto w: works) {
        for(auto b: w) {
            available_works.push(b);
        }

        if(!available_works.empty()) {
            answer += available_works.top();
            available_works.pop();
        }
    }

    std::cout << answer << std::endl;

    return 0;
}


Measured memory_bytes: 5632
import sys
N, *AB = [int(x) for x in input().split()]
As, Bs, Ag, Bg = map(lambda x : x - 1, AB)
S = input()
for (s, g) in [(As, Ag), (Bs, Bg)]:
    if '##' in S[s : g + 1]:
        print("No")
        sys.exit()

if Bg < Ag:  # AがBを飛び越える必要がある
    if '...' not in S[Bs - 1 : Bg + 2]:
        print("No")
        sys.exit()

print("Yes")

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

using namespace std; 

int main()
{
	int cc=0;
	string c;
	cin>>c;
	for(int i=0;i<c.size();i++)
	{
		if((i+1)%2==0)
		{
			if(c[i]=='L'||c[i]=='U'||c[i]=='D')
				cc++;
				
		}
		else
		{
			if(c[i]=='R'||c[i]=='U'||c[i]=='D')
				cc++;
		}
	}
	if(cc==c.size())
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;		
}




Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		String s=nextLine();
		String t=nextLine();
		if(t.length()==s.length()+1 && t.substring(0,t.length()-1).equals(s))
			out.println("Yes");
		else
			out.println("No");
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 32580
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,k;

main(){
  cin>>n>>k;

  if(k==1){
    cout<<0<<endl;
  }else{
    cout<<n-k<<endl;
  }

}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()
 
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int left = A + B;
  int right = C + D;
  if(left > right) cout << "Left";
  else if(left == right) cout << "Balanced";
  else cout << "Right";
  cout << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main(int argc, const char * argv[]) {

    int n,k;
    
    scanf("%d %d",&n,&k);
    
    int sum = k/1000-n;
    for(int i=0;9*i<=sum;i++){
        for(int j=0;j<=n-i;j++){
            
            
            if( 9*i+ 4*j == sum){
                printf("%d %d %d\n",i,j,n-i-j);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
    
    return 0;
}

Measured memory_bytes: 128
icase=0
if icase==0:
    n=int(input())
    xsum=0
    for i in range(n):
        xi,ui=input().split()
        if ui=="JPY":
            xsum=xsum+int(xi)
        else:
            xsum=xsum+float(xi)*380000
    print(xsum)
    

Measured memory_bytes: 2940
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]


def count(n, a, b):
    a0, a1, a2 = a
    b0, b1, b2 = b
    dp = [0] * (n + 1)
    for i in range(n + 1):
        c0 = dp[i - a0] + b0 if i - a0 >= 0 else 0
        c1 = dp[i - a1] + b1 if i - a1 >= 0 else 0
        c2 = dp[i - a2] + b2 if i - a2 >= 0 else 0
        dp[i] = max(i, c0, c1, c2)
    return dp[n]


print(count(count(N, A, B), B, A))


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

int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int sum=0;
  for(int j=0;j<N;j++){
    for(int i=0;i<j;i++){
      int t=vec.at(i)+vec.at(j);
      int r=lower_bound(vec.begin(),vec.end(),t)-vec.begin();
      int l=j+1;
      sum+=r-l;
    }
  }
  cout<<sum<<endl;
  
  
  
}

Measured memory_bytes: 3624
import java.util.Scanner;

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

		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		String[] s = new String[h];
		for (int i = 0; i < h; i++) {
			s[i] = sc.next();
		}

		char[][] c = new char[h][];

		for (int i = 0; i < h; i++) {
			c[i] = s[i].toCharArray();
		}

		String ans = "Yes";

		out: for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				boolean flg = false;

				if (c[i][j] == '#') {

					if (i != 0) {
						if (c[i - 1][j] == '#')
							flg = true;
					}
					if (i != h - 1) {
						if (c[i + 1][j] == '#')
							flg = true;
					}
					if (j != 0) {
						if (c[i][j - 1] == '#')
							flg = true;
					}
					if (j != w - 1) {
						if (c[i][j + 1] == '#')
							flg = true;
					}

					if (!flg) {
						ans = "No";
						break out;
					}
				}
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s, s1, s2, s3;
  cin >> s;
  s1 = s / 100;
  s2 = (s - s1 * 100) / 10;
  s3 = s - (s1 * 100 + s2 * 10);
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
    dinner = A[i] - 1
    ans += B[dinner]
    if i != N-1:
        if dinner + 1 == A[i+1] - 1:
            ans += C[dinner]

print(ans)

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

int INF = 100100101;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  if(s[0]!='A') {
    cout << "WA" << endl;
    return 0;
  }
  int flg = 0;
  for(int i = 1;i < s.length();i++){
   	if(s[i] == 'C' && 2 <= i && i <= s.length()-2){
      flg++;
    }
    else if('a' > (int)s[i] || (int)s[i] > 'z'){
      cout << "WA" << endl;
      return 0;
    }
  }
  if(flg != 1) {
    cout << "WA" << endl;
    return 0;
  }
  cout << "AC" << endl;
  return 0;
}

Measured memory_bytes: 256
// Author: 23forever
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;
const int MAXN = 100000;
const int MOD = 1e9 + 7;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';
  
  while (!isdigit(c)) {
    c = getchar();
    if (c == '-') w = -1;
  }

  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, k;
LL ans;

namespace tree {

const int MAXM = 2 * MAXN + 5;

struct Edge {
  int to, nxt;
  Edge() {}
  Edge(int _to, int _nxt) : to(_to), nxt(_nxt) {}
} edge[MAXM + 5];

int tot, head[MAXN + 5];

inline void addEdge(int u, int v) {
  edge[tot] = Edge(v, head[u]);
  head[u] = tot++;
  edge[tot] = Edge(u, head[v]);
  head[v] = tot++;
}

void init() {
  tot = 0;
  memset(head, -1, sizeof(head));
}

void dfs(int u, int fa, int cur) {
  int cnt = 0;

  for (int i = head[u]; ~i; i = edge[i].nxt) {
    int v = edge[i].to;
    if (v == fa) continue;

    int nxt = min(cur + 1, 2);
    ans = ans * (k - cnt - nxt) % MOD;
 
    ++cnt;
    dfs(v, u, nxt);
  }
}
 
} 

void init() {
  tree::init();

  n = read(), k = read();
  for (int i = 1; i < n; ++i) {
    int u = read(), v = read();
    tree::addEdge(u, v);
  }
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
  //freopen("test.out", "w", stdout);
#endif
  init();

  ans = 1;
  tree::dfs(1, -1, 0);

  printf("%lld\n", ans * k % MOD);

  return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=4999999996000000001;
ll frac[200100];

ll modpow(ll a, ll n, ll mod){
    ll ret=1;
    while(n>0){
        if(n&1) ret=ret*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ret;
}

ll comb(ll n, ll r){
    ll res=1;
    res*=frac[n];
    res*=modpow(frac[r],MOD-2,MOD);
    res%=MOD;
    res*=modpow(frac[n-r],MOD-2,MOD);
    res%=MOD;
    return res;
}

int main(){
    frac[0]=1;
    for(int i=1;i<=200010;i++){
        frac[i]=frac[i-1]*i;
        frac[i]%=MOD;
    }
    int n,m,k;
    cin>>n>>m>>k;
    if(m==1){
        if(k==n-1){
            cout<<1<<endl;
        }else{
            cout<<0<<endl;
        }
        return 0;
    }
    ll ans=0;
    ll times=m;
    times*=modpow(m-1,n-1,MOD);
    times%=MOD;
    ans+=times;
    for(ll i=1;i<=k;i++){
        ll type=comb(n-1,i);
        times*=modpow(m-1,MOD-2,MOD);
        times%=MOD;
        ll buf=times*type;
        buf%=MOD;
        ans+=buf;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4708
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S = sys.stdin.readline()

	counter = 0
	if(S[0]!='k'):
		if(S[-8:-1]=='keyence'):
			print("YES")
		else:
			print("NO")
	elif(S[0]=="k" and S[-2]!="e"):
		if(S[0:7]=='keyence'):
			print("YES")
		else:
			print("NO")
	elif(S[0]=="k" and S[-2]=="e"):
		key = "keyence"
		f = False
		for i in range(1,7):
			if(key == str(S[0:i])+str(S[-8+i:-1])):
				print("YES")
				f = True
				break
		if f==False : print("NO")
	else:
		print("NO")

main()

Measured memory_bytes: 3064
s = input()
k = int(input())

sameword = [1]
for i in range(1, len(s)):
  if s[i] == s[i-1]:
    sameword[-1] += 1
  else:
    sameword.append(1)  
    
if len(sameword) == 1:
  print((sameword[0] * k) // 2) 
elif s[0] != s[-1]:
  change = 0    
  for seq in sameword:
    change += seq // 2
  print(change * k)
else:
  init = sameword[0]
  last = sameword[-1]
  change = 0
  for i in range(1, len(sameword)-1):
    change += sameword[i] // 2
  print(change * k + (init // 2) + (last // 2) + ((init + last) // 2) * (k - 1))




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

int eucl(int a, int b){
    if(a == 0){
        return b;
    }
    else
    {
        // cout << b << " "<< b%a << endl;
        return eucl(b % a, a);
    }
}

int main(){
    int N;
    cin >> N;
    std::vector<int> value(N);
    std::vector<int> gcd_r(N);
    std::vector<int> gcd_l(N);
    for(int i=0; i < N; i++){
        cin >> value.at(i);
    }

    gcd_l.at(0) = value.at(0);
    gcd_r.at(N-1) = value.at(N - 1);
    for(int i=1; i < N; i++){
        gcd_l.at(i) = eucl(value.at(i), gcd_l.at(i - 1));
    }
    for(int i=1; i < N; i++){
        gcd_r.at(N - i - 1) = eucl(value.at(N - i -1), gcd_r.at(N-i));
    }
    int max_gcd = gcd_r.at(1);
    int gcd_tmp;
    // for(int i=0; i < N; i++){
    //     cout << gcd_l.at(i) << " ";
    // }
    // cout << endl;
    // for(int i=0; i < N; i++){
    //     cout << gcd_r.at(i) << " ";
    // }
    // cout << endl;

    for(int i = 1; i <  N- 1; i++){
        gcd_tmp = eucl(gcd_l.at(i - 1), gcd_r.at(i + 1));
        max_gcd = max(max_gcd, gcd_tmp);
    }
    gcd_tmp = gcd_l.at(N - 2);
    max_gcd = max(max_gcd, gcd_tmp);

    cout << max_gcd << endl;
    return 0;
}


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

int main(){
    int n; scanf("%d", &n);
    int f = 1;
    for(int i =0 ; i<n; i++){
        int x; scanf("%d", &x);
        if(x&1) continue;
        else if(x%5==0 or x%3==0) continue;
        else f = 0;
    }
    printf("%s\n", f?"APPROVED":"DENIED");
    return 0;
}


Measured memory_bytes: 256
var input = require("fs").readFileSync("/dev/stdin", "utf8");

input = input.split('\n')

var seq = input[1].split(' ').map(x => parseInt(x))

var pause = 1;
var diffSign = 0;

for (var i = 1; i < seq.length; i++) {
    var nowSign = Math.sign(seq[i - 1] - seq[i])
    if (diffSign * nowSign < 0) {
        pause++;
        diffSign = 0;
    } else if (diffSign === 0) {
        diffSign = nowSign;
    }
}

console.log(pause)


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

int N;

void solve(){
    vector<int> n(N),d(N);
    vector<int> x(N,0),y(N,0);
    rep(i,N-1) cin >> n[i] >> d[i];
    int maxx=0,minx=0,maxy=0,miny=0;
    for(int i=0;i<N-1;i++){
        int xx = x[n[i]];
        int yy = y[n[i]];
        if(d[i]==0){
            xx--;
        }else if(d[i]==1){
            yy++;
        }else if(d[i]==2){
            xx++;
        }else if(d[i]==3){
            yy--;
        }
        x[i+1] = xx;
        y[i+1] = yy;
        maxx = max(maxx,xx);
        maxy = max(maxy,yy);
        minx = min(minx,xx);
        miny = min(miny,yy);
//        cout << x << " " << y << endl;
    }
    //cout << maxx << " " << minx << " " << maxy << " " <<miny << endl;
    cout << maxx-minx+1 << " " << maxy-miny+1 << endl;
}

int main(){
    while(cin>>N){
        if(N==0) break;
        solve();
    }
}

Measured memory_bytes: 3064
n = int(input())
s = {}
ans = 0
for i in range(n):
    a = input()
    a = ''.join(sorted(a))
    if a in s:s[a] +=1
    else: s[a] = 1
for i in s:
    a = s[i]
    ans += a*(a-1)//2
print(ans)

Measured memory_bytes: 17804
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",b+i);
	}
	std::sort(b,b+a);
	int D=b[a-1];
	bool ok=true;
	int now=-1;
	int ren=0;
	int fi=1;
	if(b[0]!=(D+1)/2)ok=false;
	for(int i=0;i<a;i++){
		if(now!=b[i]){
			if(now!=-1){
				if(b[i]!=now+1)ok=false;
				if(fi&&ren!=D%2+1)ok=false;
				
				if(!fi&&ren<2)ok=false;
				fi=0;
			}
			now=b[i];
			ren=1;
		}else ren++;
	}
	if(fi&&ren!=D%2+1)ok=false;
	if(!fi&&ren<2)ok=false;
	if(ok)printf("Possible\n");
	else printf("Impossible\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl

int main(){
    int N; cin>>N;
    int A[N];
    for(int i=0; i<N; i++){
        cin>>A[i];
        if(A[i]%2==0){
            if(A[i] % 3!=0 && A[i] % 5 !=0){
                cout<<"DENIED"<<endl;
                return 0;
            }
        }
    }
    cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7,MAX = 1e5;

int main()
{
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll ss = s.size();
	ll q;cin >> q;
	for(ll ii = 0 ;ii<q;ii++)
	{
		ll k;
		cin >> k;
		ll cntd=0,ans=0,cntm=0,cnt=0;
		for(ll i = 0;i<n;i++)
		{
			if(i-k>=0&&s[i-k]=='D')
			{
				cntd--;
				cnt -= cntm;
			}
			if(i-k>=0&&s[i-k]=='M')
			{
				cntm--;
			}
			if(s[i]=='D')
			{
				cntd++;
			}
			else if(s[i]=='M')
			{
				cntm++;
				cnt+=cntd;
			}
			else if(s[i]=='C')
			{
				ans+=cnt;
			}
			
		
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int n;
int cost[100005];
VVI g(100005, VI());

void dfs(int s){
	if(cost[s]) return;
	VI candi;
	for(auto v : g[s]){
		dfs(v);
		candi.PB(cost[v]);
	}
	sort(ALL(candi));
	rep(i,candi.size()){
		chmax(cost[s],candi[i]);
		cost[s]++;
	}
	return;
}


signed main(){
	cin>>n;
	reps(i,n-1){
		int a; cin>>a; a--;
		g[a].PB(i);
	}
	CLR(cost);
	dfs(0);
	rep(i,n) cerr<<cost[i]<<' ';
	cerr<<endl;
	cout<<cost[0]<<endl;
	return 0;
}


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

using namespace std;

struct node {
  int a;
  int b;
  int id;
};

int main() {
  int n;
  cin >> n;
  vector<node> vec(n);
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    vec[i] = {tmp, -tmp + i, i};
  }

  sort(vec.begin(), vec.end(),
       [](auto &lhs, auto &rhs) { return lhs.b < rhs.b; });

  long long cnt = 0;
  for (auto itr = vec.begin(); itr != vec.end(); ++itr) {
    auto c1 = [](auto &lhs, int rhs) { return lhs.b < rhs; };
    auto c2 = [](int lhs, auto &rhs) { return lhs < rhs.b; };
    auto itr1 = lower_bound(itr, vec.end(), itr->a + itr->id, c1);
    auto itr2 = upper_bound(itr, vec.end(), itr->a + itr->id, c2);
    cnt += itr2 - itr1;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 5640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char a, b;
    cin >> a >> b;
    //cout << (a ^ b) <<  endl;
    if ((a ^ b) == 0) {
        cout << "H" << endl;
    } else {
        cout << "D" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define push_back pb
#define make_pair mp
using ll =  long long;
const int INF = 0x3f3f3f3f;

int A, P;

void solve()
{
	cout << (A*3+P)/2 << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> A >> P;
	solve();
	return 0;
}

Measured memory_bytes: 256
# 参考：https://atcoder.jp/contests/abc146/submissions/10412733

from collections import deque

N = int(input())
# グラフ準備
graph = [[] for _ in range(N + 1)]
seq = []

for _ in range(N - 1):
    a, b = map(int, input().split())
    graph[a].append(b)
    seq.append(b)

# BFS

q = deque([1])
color = [0] * (N + 1)

while q:
    checking_parent = q.popleft()
    parent_color = color[checking_parent]
    c = 1
    for child in graph[checking_parent]:
        if c == parent_color:
            c += 1
        # 使用したcolorをchildの色として格納する
        color[child] = c
        c += 1
        # childを探索候補へ追加
        q.append(child)

print(max(color))
for i in range(N - 1):
    print(color[seq[i]])


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

int main(){
  int N,M,a=500000000,ans;
  cin >> N >>M;
  vector<pair<int,int>> st(N),ch(M);
  for(int i=0;i<N;i++){
    cin >> st.at(i).first >> st.at(i).second;
  }
  for(int i=0;i<M;i++){
    cin >> ch.at(i).first >> ch.at(i).second;
  }
  for(int i=0;i<N;i++){
   for(int j=0;j<M;j++){
     if(a>abs(st.at(i).first-ch.at(j).first)
        +abs(st.at(i).second-ch.at(j).second)){
       a = abs(st.at(i).first-ch.at(j).first)
        +abs(st.at(i).second-ch.at(j).second);
       ans = j+1;
     }
   }
    cout << ans <<endl;
    a = 500000000;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  // 10^18 くらいまでいける

// for DP
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 ll INF = 1LL << 60;

int main(){

  int A, B;
  cin >> A >> B;

  if (A<=8 && B<=8)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, a, b; string s;
    cin >> n >> a >> b >> s;
    ll cnt_a = 0, cnt_b = 0;
    rep(i, n){
        // 国内学生の場合
        if(s[i] == 'a'){
            if(cnt_a+cnt_b < a+b){ cnt_a++; Yes(); }
            else No();
        }
        // 海外学生の場合
        else if(s[i] == 'b'){
            if(cnt_a+cnt_b < a+b && cnt_b < b){ cnt_b++; Yes(); }
            else No();
        }
        // どちらでもない場合
        else No();
    }
}

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


int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int x=min(a,b);
  int y=(a+b)-n;
  if(y<0)y=0;
  cout << x << " " << y << endl;
  return 0;
}


Measured memory_bytes: 3552
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define MOD 1e9 + 7
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265359

template <typename T>
void printVector(string name, vector<T> vec)
{
    cout << name << ": ";
    rep(i, vec.size())
    {
        cout << vec[i] << " ";
    }
    cout << endl;
}

// 割る数の初期値
ll a = 2;
vector<ll> cal(ll n)
{
    vector<ll> rtn;

    while (n >= a * a)
    {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0)
        {
            rtn.pb(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }

    // 最後に残った n は素因数
    rtn.pb(n);
    return rtn;
}

void Main()
{
    int r, d, x2000;
    cin >> r >> d >> x2000;
    int xi = x2000;

    rep(i, 10)
    {
        cout << (r * xi - d) << endl;
        xi = (r * xi - d);
    }

    return;
}

signed main(void)
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int v[60];

int main()
{
    //freopen("file.in","r",stdin);
    //freopen("file.out","w",stdout);
    int mx=-1,n,poz;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[i]);
        if(abs(v[i])>mx) {mx=abs(v[i]);poz=i;}
    }
    printf("%d\n",2*n-2);
    for(int i=1;i<=n;i++)
        if(i!=poz) printf("%d %d\n",poz,i);
    if(v[poz]>=0) for(int i=2;i<=n;i++) printf("%d %d\n",i-1,i);
    else for(int i=n-1;i>=1;i--) printf("%d %d\n",i+1,i);
    return 0;
}


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

int main(){
long long n;
  cin>>n;
string ans="";
  while(n){
  n--;
    ans+='a'+n%26;
    n/=26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  return 0;
 }

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

#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vll = vector<ll>;
using vbool = vector<bool>;

struct myquery {
    int x, y, h;
    myquery(int x, int y, int h) : x(x), y(y), h(h) {}
};

int dist(int x1, int y1, int x2, int y2) {
    return abs(x1 - x2) + abs(y1 - y2);
}

int main() {
    int N;
    cin >> N;
    if (N == 1) {
        cout << 1000000000;
        return 0;
    }

    vector<vint> m = vector<vint>(101, vint(101, -1));
    vector<myquery> q, q_;
    REP(i, N) {
        int a, b, c;
        cin >> a >> b >> c;
        if (c != 0)
            q.pb(myquery(a, b, c));
        else
            q_.pb(myquery(a, b, c));
    }

    REP(y, 101) {
        REP(x, 101) {
            int h = q[0].h + dist(q[0].x, q[0].y, x, y);
            bool flag = true;
            for (auto i : q) {
                if (i.h != max(h - dist(i.x, i.y, x, y), 0))
                    flag = false;
            }
            for (auto i : q_) {
                if (i.h != max(h - dist(i.x, i.y, x, y), 0))
                    flag = false;
            }
            if (flag) {
                cout << x << " " << y << " " << h;
            }
        }
    }
}

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

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector <ll> v(n+1, 0);
  v.at(0) = 1;
  set <ll> s;
  rep(i, m) {
    ll a;
    cin >> a;
    s.insert(a);
  }
  rep(i, n) {
    if (s.count(i+1)) continue;
    if (i) {
      v.at(i+1) = v.at(i) + v.at(i-1);
    } else {
      v.at(i+1) = v.at(i);
    }
    v.at(i+1) %= mod;
  }
  cout << v.at(n) << endl;
}

Measured memory_bytes: 5760
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, M, P;

bool used[2501];
vector<int> con[2501];
vector<int> inv_con[2501];

void inv_func()
{
	queue<int> q1;
	q1.push(N);
	bool used_a[2501] = {};
	used_a[N] = true;

	while (q1.size() > 0)
	{
		int n = q1.front();
		q1.pop();

		for (int l : inv_con[n])
		{
			if (!used_a[l])
			{
				used_a[l] = true;
				q1.push(l);
			}
		}
	}

	queue<int> q2;
	q2.push(1);
	bool used_b[2501] = {};
	used_b[1] = true;

	while (q2.size() > 0)
	{
		int n = q2.front();
		q2.pop();
		for (int l : con[n])
		{
			if (!used_b[l])
			{
				used_b[l] = true;
				q2.push(l);
			}
		}
	}

	for (int i = 1; i <= N; i++)
	{
		used[i] = (used_a[i] && used_b[i]);
	}
}

struct edge 
{
	int from;
	int to;
	int cost;
	edge(int from, int to, int cost)
	{
		this->from = from;
		this->to = to;
		this->cost = cost;
	}
};

vector<edge> edges;

signed main()
{
	cin >> N >> M >> P;
	REP(i, M)
	{
		int a, b, c;
		cin >> a >> b >> c;
		con[a].push_back(b);
		inv_con[b].push_back(a);
		edges.push_back(edge(a, b, P - c));
	}

	inv_func();

	int side;
	int d[2501];

	REP(i, N + 1) d[i] = INT_MAX;
	d[1] = 0;

	for (int i = 0; i < N; i++) 
	{
		for (int j = 0; j < M; j++) 
		{
			edge e = edges[j];
			if (used[e.to] && used[e.from])
			{
				if (d[e.to] > d[e.from] + e.cost)
				{
					d[e.to] = d[e.from] + e.cost;
					if (i == N - 1)
					{
						cout << -1 << endl;
						return 0;
					}
				}
			}
		}
	}

	cout << MAX(0, -d[N]) << endl;
}




Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int n, k, x, y; cin >> n >> k >> x >> y;
	int ans = 0;
	if (n > k) {
		ans += k * x + (n - k) * y;
		cout << ans << "\n";
	}
	else cout << n * x << "\n";

	return 0;
}

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

#define all(x) x.begin(), x.end()
#define lc (i << 1)
#define rc (i << 1 | 1)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
int N, a[MN];
map<ll, ll> mp;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N;
    ll ret = 0;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        ret += mp[i - a[i]];
        mp[i + a[i]]++;
    }
    cout << ret << '\n';
    return 0;
}


Measured memory_bytes: 27104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var aaa = Console.ReadLine();
            var bbb = Console.ReadLine();

            if (aaa[0] == bbb[2] && aaa[1] == bbb[1] && aaa[2] == bbb[0])
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e2 + 1;

int N, M;

int e[MAX_N][MAX_N];

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

  REP(i, MAX_N)
    REP(j, MAX_N)
    if (i == j) e[i][j] == 0;
    else e[i][j] = INF;
  
  cin >> N >> M;
  vector< int > a(M);
  vector< int > b(M);
  vector< int > c(M);
  REP(i, M) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    e[a[i]][b[i]] = e[b[i]][a[i]] = c[i];
  }

  

  REP(k, N) {
    REP(i, N) {
      REP(j, N) {
	e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
      }
    }
  }

  int ans = 0;
  REP(i, M) {
    if (e[a[i]][b[i]] < c[i]) ans++;
  }

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



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

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

using namespace std;
struct Edge {
    int u;
    int v;
};
bool operator< (const Edge& e1, const Edge& e2) {
    return e1.u < e2.u || (e1.u == e2.u && e1.v < e2.v);
};
typedef vector<vector<int> > Graph;

void DFS(Graph &g, int u, int &clock, vector<int> &low, vector<int> &disc, vector<bool> &seen, vector<int> &parent, vector<Edge> &bridges) {
    stack<int> s;
    for(int v: g[u]) {
        if (! seen[v]) {
            clock++;

            disc[v] = clock;
            low[v] = clock;
            seen[v] = true;
            parent[v] = u;

            DFS(g, v, clock, low, disc, seen, parent, bridges);

            low[u] = min(low[u], low[v]);

            if (low[v] > disc[u])
                bridges.push_back(Edge{min(u, v), max(u, v)});
        } else if (v != parent[u]) {
            low[u]  = min(low[u], disc[v]);
        }
    }
}

int main () {
    int V, E;
    cin >> V >> E;

    Graph g(V);
    vector<Edge> bridges;

    FOR(i,E) {
        int s, t;
        cin >> s >> t;

        g[s].push_back(t);
        g[t].push_back(s);
    }
    int clock = 2;
    vector<int> low(V, 0);
    vector<int> disc(V, 0);
    vector<int> parent(V, -1);
    vector<bool> seen(V, false);
    disc[0] = 1;
    low[0] = 1;
    seen[0] = true;

    DFS(g, 0, clock, low, disc, seen, parent, bridges);

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

    for(Edge e: bridges)
        cout << e.u << " " << e.v << endl;
}



Measured memory_bytes: 12348
#include<bits/stdc++.h>
using namespace std;
int main(){
int r,c ;
cin>>r>>c;
char arr[r] [c];

for(int i=0;i<r; i++){
for(int j=0; j<c; j++)
cin>>arr[i] [j];
}

for(int i=0; i<c+2;i++)
cout<<"#";
cout<<endl;

for(int i=0;i<r; i++){
cout<<"#";
for(int j=0; j<c; j++)
cout<<arr[i] [j];
cout<<"#"<<endl;
}

for(int i=0; i<c+2;i++)
cout<<"#";
return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <map>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
map<ll,ll> memo[52];
void level(ll n){
  if(n==0){
    memo[n][0] = 1;
    memo[n][1] = 1;
  }else{
    level(n-1);
    memo[n][0] = 2*memo[n-1][0]+3;
    memo[n][1] = 2*memo[n-1][1]+1;
  }
}
ll patties(ll n,ll x){
  if(memo[n][0]<x) x = memo[n][0];
  if(n==0) return memo[n][1];
  else if(x==1) return 0;
  //cout << n << " "  << x << endl;
  if(memo[n-1][0]+1>=x){
    return patties(n-1,x-1);
  }else if(memo[n-1][0]+2==x){
    return memo[n-1][1]+1;
  }else{
    return memo[n-1][1]+1+patties(n-1,x-memo[n-1][0]-2);
  }
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,x;
  int a[LIMIT2]={0};
  string s;
  
  cin >> n >> x;
  level(n);
  result = patties(n,x);
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
//#include <intrin.h>

#define fore(i,a,b) for(int i = a; i < (b); i++)
#define fr(i,a,b) for(int i = a - 1; i >= b; i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define N 300005
#define inf 2000000000
#define EPS 1e-7
#define MOD (ll)1e15
#define __builtin_popcount(x) __popcnt(x)

using namespace std;

typedef long long ll;
typedef pair<int, int> pr;
typedef pair<int, pair<int, int>> tup;

inline void solve()
{
	int n;
	cin >> n;
	set<int> st;
	fore(i, 0, n)
	{
		int a;
		cin >> a;
		st.insert(a);
	}
	
	cout << (st.size() == n ? "YES" : "NO");
}

int main()
{
	fast;
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
}

Measured memory_bytes: 9600