akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  bool CAN=true;
  
  if(abs(B-A)>T*(V-W)) CAN=false;
  
  if(CAN) COYE;
  else CONO;
  return 0;
}

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


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

    ll n,m;
    cin >> n >> m;
    vector<pair<ll, ll>> b(n);
    rep (i, n) {
        cin >> b[i].first >> b[i].second;
    }
    sort(ALL(b));
    ll ans=0;
    rep (i, n) {
        if (m > b[i].second) {
            m -= b[i].second;
            ans += b[i].first * b[i].second;
        }else{
            ans += m * b[i].first;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4760
size = gets.to_i
array = gets.split(" ").map(&:to_i)

def selection_sort(size, array)
  count = 0
  (size-1).times do |i|
    min = i
    (i+1..size-1).each do |j|
      next if array[j].nil?
      if array[j] < array[min]
        min = j
      end
    end
    if array[i] != array[min]
      copy_i = array[i]
      array[i] = array[min]
      array[min] = copy_i
      count += 1
    end
  end
  puts array.join(" "), count
end

selection_sort(size, array)


Measured memory_bytes: 6868
#include<algorithm>
#include <iostream>
using namespace std;
long long C;
int A[200000];
int main() {
    int N,K; cin >> N >> K;
	for(int i=0; i<N; i++) cin >> A[i];
	sort(A, A+N);
	for(int i=0; i<(N-K); i++) C += A[i];
    cout << C << endl;
    return 0;
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    long long A, B, K;
    cin >> A >> B >> K;

    long long t = min(A, K);
    A -= t;
    K -= t;

    long long t2 = min(B, K);
    B -= t2;

    cout << A << " " << B << endl;

    return 0;
}

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

int main(){
  ll l,r; cin >> l>> r;
  if(r-l>=2019){
    cout << 0 << endl;
    return 0;
  }
 
  
  
  ll ans = 2018;
 for(ll i=l; i<=r-1; i++){
   for(ll j=i+1;j<=r; j++){
     ans = min(ans,(i*j)%2019);
   }
 }
  cout << ans << endl;
  
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int culc(int X, int K){
    while(X / K > 0){
        if(X % K == 0) return X / K;
        int d = X / K;
        int di = X - d * K;
        int p = (di - 1) / (d + 1);
        X -= (p + 1) * (d + 1);
    }
    return X / K;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    int res = 0;
    for(int i = 0; i < N; i++){
        int A, K;
        cin >> A >> K;
        res ^= culc(A, K);
    }
    cout << (res == 0 ? "Aoki" : "Takahashi") << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,l,j,n;
    string a;
    scanf("%d",&n);
    getchar();
    for(i=1;i<=n;i++)
    {
        getline(cin,a);
        l=a.size();
        for(j=0;j<l-6;j++)
        {
            if(a[j]=='H' && a[j+1]=='o' && a[j+2]=='s' && a[j+3]=='h' && a[j+4]=='i' && a[j+5]=='n' && a[j+6]=='o')
            a[j+6]='a';
        }
       cout<<a<<endl;
    }
    return 0;
}



Measured memory_bytes: 3160
use proconio::input;

fn main() {
  input! {
    n: i32
  }

  println!("{}", match n % 10 {
    2 | 4 | 5 | 7 | 9 => "hon",
    0 | 1 | 6 | 8 => "pon",
    3 => "bon",
    _ => "_"
  });
}


Measured memory_bytes: 2148
#include<stdio.h>
#include<string.h>
#include<limits.h>

int main(){
	long long int n;
	int i,j;
	int num[11][11]={0};
	
	while(scanf("%lld",&n)!=EOF){
	
	for(i=9;i>=0;i--){
		num[0][i]=n%10;
		n=n/10;
	}
	
	for(i=0;i<=9;i++){
		for(j=0;j<9-i;j++){
			num[i+1][j]=num[i][j]+num[i][j+1];
			if(num[i+1][j]>=10)num[i+1][j]=num[i+1][j]%10;
		}
		
	}
		printf("%d",num[9][0]);
		printf("\n");
	}
	
return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> PL;

const int MOD=1000000007;
int INF=100100100;
int main(){
  LL n;cin>>n;
  if(n%2!=0){
    cout<<0<<endl;
    return 0;
  }
  n=n/2;
  LL ans=0;
  n=n/5;
  while(n>=1){
    ans+=n;
    n/=5;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,a[51],sum;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(res i=1;i<=n;++i) cin>>a[i],sum+=a[i];
	int tot=0;
	for(res i=1;i<=n;++i) tot+=a[i]*(sum-a[i]);
	cout<<tot/2<<'\n';
	cout<<flush;
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

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

const int MOD=1000000007;

int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  rep(i,n) cin>>a[i];
  ll ans=0;
  rep(i,60){
    ll X=0, Y=0;
    rep(j,n){
      if((a[j]>>i)&1){
        X++;
      }else{
        Y++;
      }
    }
    ll now=X*Y%MOD;
    rep(j,i){
      now=now*2%MOD;
    }
    ans+=now;
    ans%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	map<int, ll> mp;
	rep(i, n) {
		mp[i - a[i]]++;
	}
	ll ans = 0;
	rep(i, n) {
		mp[i - a[i]]--;
		ans += mp[i + a[i]];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 26576
n=int(input())
a=list(map(int,input().split()))
def InsertionSort(a,n):
    for i in range(n):
        v=a[i]
        j=i-1
        while j>=0 and v<a[j]:
            a[j+1]=a[j]
            j-=1
            a[j+1]=v
        print(*a)
InsertionSort(a,n)


Measured memory_bytes: 5980
import math
def main():
    d = int(input())
    th = 90

    eps = 10**(-12)
    x = y = ans = 0
    while True:
        x += math.cos(math.radians(th))
        y += math.sin(math.radians(th))
        ans += 1

        if abs(x) <= eps and abs(y) <= eps:
            print(ans)
            break
        else:
            th += d

if __name__ == "__main__":
    main()

Measured memory_bytes: 9480
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
p=list(map(int,input().split()))
if X not in p:
  print(X)
  exit()
else:
  for i in range(200):
    if X-i not in p:
      print(X-i)
      exit()
    elif X+i not in p:
      print(X+i)
      exit()
      
  

Measured memory_bytes: 9220
#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#define N 110000
#define L 100000
#define eps 1e-7
#define inf 1e9+7
#define db double
#define ll long long
#define ldb long double
using namespace std;
inline int read()
{
	char ch=0;
	int x=0,flag=1;
	while(!isdigit(ch)){ch=getchar();if(ch=='-')flag=-1;}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*flag;
}
struct lnk{int x,y;}p[N];
int f[N],cnt[N];
int main()
{
	for(int i=1;i<=3;i++)
	{
		p[i].x=read(),p[i].y=read();
		f[p[i].x]++;f[p[i].y]++;
	}
	for(int i=1;i<=4;i++)cnt[f[i]]++;
	if(cnt[1]==2&&cnt[2]==2)printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
const int INF = 1 << 28;
int n,m;
vector< vector<int> > cost;
vector<int> mincost;

vector<bool> used;
vector<pair<int,int> > edge;
int prim(){
  mincost = vector<int>(n);
  used = vector<bool>(n);
  for(int i = 0;i < n;i++){
	mincost[i] = INF;
	used[i] = false;
  }
  vector<int> keep_edge = vector<int>(n,INF);
  mincost[0] = 0;
  int res = 0;
  while(true){
	int v = -1;
	for(int u = 0;u < n;u++){
	  if(!used[u] && (v == -1 || mincost[u] < mincost[v]))v = u;
	}
	if(v == -1)break;
	used[v] = true;
	res += mincost[v];
	edge.emplace_back(v,keep_edge[v]);
	for(int u = 0;u < n;u++){
	  if(cost[u][v] < mincost[u]){
		keep_edge[u] = v;
		mincost[u] = cost[u][v];
	  }
	}
  }
  return res;
}
int main(){
  cin >> n >> m;
  cost = vector<vector<int> >(n,vector<int>(n,INF));
  
  for(int i = 0;i < m;i++){
	int f,t,c;
	cin >> f >> t >> c;
	f--;t--;
	cost[f][t] = c;
	cost[t][f] = c;
  }
  int res = prim();
  int sum_cost = 0;
  vector<pair<int,int> > small_tree = vector<pair<int,int> >( edge);
  vector<pair<int,int> > ans_keep;
  for(int i = 1;i < small_tree.size();i++){
	pair<int,int> tmp = small_tree[i];
	int tmp_c = cost[tmp.first][tmp.second];
	
    cost[tmp.first][tmp.second] = INF;
    cost[tmp.second][tmp.first] = INF;
	if(res != prim()){
	  int a,b;
	  a = (tmp.first < tmp.second ? tmp.first : tmp.second);
	  b = (tmp.first < tmp.second ? tmp.second : tmp.first);
	  ans_keep.emplace_back(a,b);
	  sum_cost += tmp_c;
	}
	cost[tmp.first][tmp.second] = tmp_c;
	cost[tmp.second][tmp.first] = tmp_c;
	
	

  }
  cout << ans_keep.size() << " " << sum_cost << endl;
  // sort(ans_keep.begin(),ans_keep.end());
  // for(pair<int,int> p : ans_keep){
  // 	cout << p.first << " " << p.second << endl;
  // 	}
  


  
  
  return 0;
}

Measured memory_bytes: 4112
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int H,W;
char G[1001][1001];
int ans=0;
int dh[4]={0,-1,0,1};
int dw[4]={1,0,-1,0};
queue< pair < pair<int,int> , int > > que;
int main(){
	cin >> H >> W;
	for(int i=0;i<H;i++)cin >> G[i];
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(G[i][j] == '#') que.push(make_pair(make_pair(i,j),0));
		}
	}
	
	while(!que.empty()){
		int h,w,t;
		h= que.front().first.first;
		w= que.front().first.second;
		t= que.front().second;
		que.pop();
		for(int i=0;i<4;i++){
			int hh=h+dh[i];
			int ww=w+dw[i];
			if(0<=hh && hh<H && 0<=ww & ww<W && G[hh][ww]=='.'){
				G[hh][ww]='#';
				que.push(make_pair(make_pair(hh,ww),t+1));
				ans=t+1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13328
l = input()
n = len(l)
ans = 0
t = 0
mod = 10**9 + 7
for i in range(n):
    if l[i] == "1":
        p = (pow(2, t, mod) * pow(3, n-i-1, mod))%mod
        ans += p
        ans %= mod
        t += 1
ans += pow(2, t, mod)
ans %= mod
print(ans)


Measured memory_bytes: 39536
N,A,B = [int(x) for x in input().split()]
if(N==1):
    if(A==B):
        print(1)
    else:
        print(0)
elif(N==2):
    if(A<=B):
        print(1)
    else:
        print(0)
else:
    print(max((N-2)*(B-A)+1,0))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main(){
	fast_io;
	ll n,W;
	cin>>n>>W;
	ll w[n];
	ll v[n];
	ll earlier[W+1],now[W+1];
	for (int i = 0; i < n; ++i){
		cin>>w[i]>>v[i];
	}
	if(n==1){
		cout<<v[0]<<"\n";
		return 0;
	}
	for (int i = 0; i < W+1; ++i){
		earlier[i]=now[i]=-1;
	}
	earlier[0]=0;
	earlier[w[0]]=v[0];
	ll ans=0;
	for (int i = 1; i < n; ++i){
		for (int j = 0; j < W+1; ++j){
			if(j>=w[i] && earlier[j-w[i]]!=-1)
				now[j]=max(now[j],v[i]+earlier[j-w[i]]);
		}
		for (int j = 0; j < W+1; ++j){
			earlier[j]=max(earlier[j],now[j]);
			now[j]=-1;
			if(i==(n-1))
				ans=max(ans,earlier[j]);
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std ;
typedef long long ll;
int main()
{
    string s,t;
    cin >> s >> t;
 
    ll i,j,k,sl=s.size(),tl=t.size(),cnt,ans=0;
    for(i=0; i<=sl-tl; i++)
    {
    	cnt=0;
    	for(j=i,k=0; k<tl; k++,j++)
    	{
    		if(s[j]==t[k])cnt++;
    	}
    	ans=max(ans,cnt);
    }  
    cout << tl-ans << endl;
    return 0;
}

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

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

using ll = long long;
using namespace std;

int
main ()
{
    int x, y, z;
    cin >> x >> y >> z;

    printf("%d %d %d\n", z, x, y);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int a[maxn];
int main(){
	int i,j,n,maxs=-1,max1=-1;
	cin>>n;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(maxs<a[i]){
			max1=maxs;
			maxs=a[i];
		}
		else if(max1<a[i]){
			max1=a[i];
		}
	}
	for(i=1;i<=n;i++){
		if(a[i]==maxs)printf("%d\n",max1);
		else printf("%d\n",maxs);
	}
	return 0;
}

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

def divisor(n):
    if n==1:return []
    ret = [n]
    for i in range(2,n+1):
        if i*i==n:
            ret.append(i)
        elif i*i > n:
            break
        elif n%i==0:
            ret.append(i)
            ret.append(n//i)
    ret.sort()
    return ret

ans = len(divisor(N-1))

for k in divisor(N):
    M = N
    while M%k==0:
        M//=k
    if M%k==1:
        ans += 1
print(ans)

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

int main(){
  int n,k;
  cin >> n >> k;
  if(n%k==0)cout << "0" << endl;
  else cout << "1" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>   //PBDS
#include <ext/pb_ds/tree_policy.hpp>       //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pi pair<int,int>
#define deb(x) cerr<<#x<<" : "<<x<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mi map<int,int>
#define PI   3.141592653589
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define f(i,x,n) for(int i=x;i<n;i++)
#define rf(i,x,n) for(int i=n-1;i>=x;i--)
#define check(x)   cerr<<#x<<" : "<<x<<endl;
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order                    //return iterator PBDS
#define ook order_of_key                     //return number :)) PBDS
#define baar exit(0)
#define INF 1000000000000000000
using namespace __gnu_pbds;
using namespace std;
signed main()
{
	fast
	int n,k;
	cin>>n>>k;
	vi v(n+1);
	int mod=998244353;
	vii v1;
	f(i,0,k)
	{
		int l,r;
		cin>>l>>r;
		v1.pb({l,r});
	}
	sort(all(v1));
	v[1]=1;
	f(i,1,n+1)
	{
		for(auto it:v1)
		{
			if(it.fi>i) break;
			if(it.se<i)
			{
				v[i]+=v[i-it.fi]-v[i-it.se-1];
			}
			else v[i]+=v[i-it.fi];
			v[i]%=mod;
		}
		v[i]+=v[i-1];
	}
	cout<<(v[n]-v[n-1]+mod+mod)%mod;
	return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; ++i) cin >> A[i];

    int M = 1001001001;
    bool cnt = false;
    bool zero = false;
    long long res = 0;

    for(int i=0; i<N; ++i) {
        res += abs(A[i]);
        M = min(M, abs(A[i]));
        if(A[i] < 0) cnt = !cnt;
        if(A[i] == 0) zero = true;
    }

    if(!cnt || zero) cout << res << endl;
    else cout << res - 2*M << endl;
}

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

int main(){
    int W;
    int H;
    int x;
    int y;
    int r;
    cin >> W >> H >> x >>y >>r;
    if(x+r <= W && y+r <= H && x-r>= 0 &&  y-r >= 0 ) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3116
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,l,r) for(int i=(r)-1,i##_left=(l);i>=i##_left;--i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define TIN(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#define VIND(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem,--_elem
#define OUT(x) cout << x;
#define OUTL(x) cout << x << endl;
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 (a>b) {a=b; return 1;} return 0;}
template<class T>
string join(vector<T>& v, string delim="") { ostringstream os; rep(i,v.size())i?os<<delim<<v[i]:os<<v[0]; return os.str(); }
#pragma endregion RegionDefs

void solve()
{
    IN(k);
    rep(i, k) cout << "ACL";
    cout << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys


def solve(s: str):
    print("%s%d%s" % (s[0], len(s) - 2, s[-1]))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import sys


def main():
    n, k = [int(s) for s in sys.stdin.readline().strip().split()]
    p = [int(s) for s in sys.stdin.readline().strip().split()]

    pd = [0.0] * n
    for i in range(n):
        tot = (p[i] + 1) * p[i] // 2
        ex = tot / p[i]
        pd[i] = ex

    cand = sum(pd[:k])
    ans = cand
    for i in range(k, n):
        cand += pd[i]
        cand -= pd[i-k]
        ans = max(ans, cand)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 71792
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m;
int main(){
	// int t;
	// while(){
		scanf("%d",&n);
		if(n>=30){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
		// for(int i=0; i<n; ++i){
		// 	scanf("%d",a+i);
		// }
	// }
}

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
inline void yesno(bool ok, string yes = "Yes", string no = "No") {cout << (ok?yes:no) << endl;}


signed main() {
    //my-code
    int K; cin >> K;
    string S; cin >> S;
    if (S.length() <= K) {
        cout << S << endl;
    } else {
        REP(i, K) {
            cout << S[i];
        }
        cout << "..." << endl;
    }

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3652
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

score = 0
for i in range(n):#012
    if i > 0 and a[i] == a[i-1] + 1:
        score += b[a[i]-1] + c[a[i-1]-1]
    else:
        score += b[a[i]-1]
print(score)

Measured memory_bytes: 3064
#include <cstdio>

using LL = long long;
const int MAXN = (int)1e5;

LL a[MAXN];

struct LinearBasis {
  static const int MAXL = 64;
  LL a[MAXL];

  LinearBasis() {
    for (int i = 0; i < MAXL; ++i) a[i] = 0;
  }

  void Add(LL vec) {
    for (int j = MAXL - 1; j >= 0 && vec > 0; --j) {
      if (((vec >> j) & 1) == 0) continue;
      if (a[j] > 0) {
        vec ^= a[j];  // a[j]!=0,就用a[j]消去t的第j位的1
        continue;
      }
      for (int k = 0; k < j; ++k) {
        if ((vec >> k) & 1) vec ^= a[k];
      }
      for (int k = j + 1; k < MAXL; ++k) {
        if ((a[k] >> j) & 1) a[k] ^= vec;
      }
      a[j] = vec;
      break;
    }    
  }

  void Build(LL *vec_array, int len) {
    for (int i = 0; i < len; ++i) Add(vec_array[i]);
  }

  void Merge(const LinearBasis &another) {
    for (int i = 0; i < MAXL; ++i) Add(another.a[i]);
  }

  LL GetMax() {
    LL res = 0;
    for (int i = MAXL - 1; i >= 0; --i) {
      res ^= a[i];
    }
    return res;
  }
};

LL solve(int n) {
  LL xor_sum = 0;
  for (int i = 0; i < n; ++i) xor_sum ^= a[i];

  LinearBasis lb;
  for (int i = 0; i < lb.MAXL; ++i) {
    if (((xor_sum >> i) & 1) == 0) continue;
    for (int j = 0; j < n; ++j) {
      if ((a[j] >> i) & 1) a[j] ^= (1LL << i);
    }
  }
  lb.Build(a, n);
  LL lb_max = lb.GetMax();
  // printf("xor_sum = %lld\n", xor_sum);
  // printf("lb_max = %lld\n", lb_max);

  return lb_max * 2 + xor_sum;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%lld", a + i);
  printf("%lld\n", solve(n));

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  int in;
  cin >> in;
  int A, B, C, D;
  A = (in / 1000) % 10;
  B = (in / 100) % 10;
  C = (in / 10) % 10;
  D = (in / 1) % 10;
  int result;
  for(int i=0; i<8; i++){
    int ans = A;
    if((i / 4) % 2 == 1) ans += B;
    else ans -= B;
    if((i / 2) % 2 == 1) ans += C;
    else ans -= C;
    if((i / 1) % 2 == 1) ans += D;
    else ans -= D;
    if(ans == 7){
      result = i;
      break;
    }
  }
  cout << A;
  if((result / 4) % 2 == 1) cout << '+';
  else cout << '-';
  cout << B;
  if((result / 2) % 2 == 1) cout << '+';
  else cout << '-';
  cout << C;
  if((result / 1) % 2 == 1) cout << '+';
  else cout << '-';
  cout << D;
  cout << "=7" << endl;;

  return 0;
}


Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10


# N個の部屋とM本の通路
N, M = [int(x) for x in stdin.readline().rstrip().split()]

route = [[] for _ in range(N+1)]

for _ in range(M):
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    route[A].append(B)
    route[B].append(A)


kyori_to_1 = [INF for _ in range(N+1)]
kyori_to_1[1] = 0

miti = [0 for _ in range(N+1)]
miti[0] = -1
miti[1] = -1

is_visited = [False for _ in range(N+1)]

# 幅優先探索
# 試すべき位置をキューで管理
que = deque([1])

# キューが空じゃなければ
while len(que) != 0:
    now = que.popleft()
    
    if is_visited[now]:
        continue

    is_visited[now] = True

    for place in route[now]:
        que.append(place)

        if kyori_to_1[now]+1 < kyori_to_1[place]:
            kyori_to_1[place] = kyori_to_1[now]+1
            miti[place] = now

if 0 in miti:
    print("No")
else:
    for i in range(1, N+1):
        if i == 1:
            print("Yes")
        else:
            print(miti[i])


Measured memory_bytes: 111520
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  long long a,b,c,d;
  cin>>a>>b>>c>>d;
  long long x=a*c;
  long long y=a*d;
  long long q=b*c;
  long long r=b*d;
  cout<<max({x,y,q,r})<<endl;
  
}

Measured memory_bytes: 3572
/*


*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<cmath>
#define ll long long
#define M 200010
#define mmp make_pair
using namespace std;
int read() {
	int nm = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
	return nm * f;
}
const int mod = 1000000007;
int n, a[M], pre[M], f[M];

void add(int &x, int y) {
	x += y;
	x -= x >= mod ? mod : 0;
}

int main() {
	n = read();
	for(int i = 1; i <= n; i++) a[i] = read();
	f[0] = 1;
	for(int i = 1; i <= n; i++) {
		if(pre[a[i]] && pre[a[i]] != i - 1) add(f[i], f[pre[a[i]]]);
		add(f[i], f[i - 1]);
		pre[a[i]] = i;
	}
	cout << f[n] << "\n";
	return 0;
}




Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
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);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int p[n];
	int ans = 0;
	REP(i, n) cin >> p[i];
	for (int i = 1; i < n-1; i++){
		if ((p[i-1] < p[i] and p[i] < p[i+1]) or p[i-1] > p[i] and p[i] > p[i+1]) ans++;
	}

	cout << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <list>
#include <set>
#include <map>
#define F first
#define S second
#define pb push_back
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vLL vector<LL>
#define vpint vector<pair<int, int>>
#define vpLL vector<pair<LL, LL>>
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fr(n) \
    for (int i = 0; i < n; i++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long LU;
const LL mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    LL x, ans = 0;
    cin >> x;
    ans += 1000 * (x / 500);
    x -= 500 * (x / 500);
    ans += 5 * (x / 5);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(void){
  int N;
  cin >> N;
  vector<long long> A;
  REP(i, N){
    int x; long long Lx;
    scanf("%d", &x);
    Lx = (long long) x;
    A.PB(Lx);
  }
  A.PB(0);

  long long ans = 0;
  REP(i, N){
    ans += A[i]/2;
    if(A[i]%2 == 1 && A[i+1] > 0){
      ans++;
      A[i+1]--;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

const int MAX_N = 2e5 + 10;
vector<int> g[MAX_N];

int cnt = 0, dp[MAX_N];
void dfs(int x, int p) {
    dp[x] = dp[p] + 1;
    if(dp[x] & 1) {cnt ++;}
    for(auto it : g[x]) {
        if(it == p) {continue;}
        dfs(it, x);
    }
}

int inv[MAX_N], ans[MAX_N];

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    for(int i = 0; i < n - 1; i ++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, 0);
    bool flag = false;
    if(cnt > n - cnt) {
        flag = true;
        cnt = n - cnt;
    }
    vector<int> left, leftl;
    if(cnt * 3 <= n) {
        int off = 3;
        for(int i = 1; i <= n; i ++) {
            if((flag && dp[i] % 2 == 0) || (!flag && dp[i] % 2 == 1)) {
                inv[off] = i;
                off += 3;
            } else {
                left.push_back(i);
            }
        }
        for(int i = 1; i <= n; i ++) {
            if(inv[i] == 0) {
                inv[i] = left.back();
                left.pop_back();
            }
        }
    } else {
        int off = 1;
        for(int i = 1; i <= n; i ++) {
            if(off <= n && ((flag && dp[i] % 2 == 0) || (!flag && dp[i] % 2 == 1))) {
                inv[off] = i;
                off += 3;
            } else {
                left.push_back(i);
            }
        }
        off = 3;
        for(auto i : left) {
            if(off <= n && ((flag && dp[i] % 2 == 0) || (!flag && dp[i] % 2 == 1))) {
                inv[off] = i;
                off += 3;
            } else {
                leftl.push_back(i);
            }
        }
        for(int i = 1; i <= n; i ++) {
            if(inv[i] == 0) {
                inv[i] = leftl.back();
                leftl.pop_back();
            }
        }
    }
    for(int i = 1; i <= n; i ++) {
        ans[inv[i]] = i;
    }
    for(int i = 1; i <= n; i ++) {
        cout << ans[i] << " ";
    }
    return 0;
}




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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long n, b, r;	
    cin >> n >> b >> r;
    cout << b * (n / (r + b)) + min((n % (r + b)), b) << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(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 pair<lint, lint> pll;

int main(){
    int n; lint x; cin >> n >> x;
    lint a[n]; rep(i, n) cin >> a[i];
    lint dp[n]; rep(i, n) dp[i] = 1e17;
    lint ans = 1e17;
    rep(i, n){
        lint t = 0;
        rep(j, n){
            int k = (j-i+n) % n;
            if(dp[j] > a[k]) dp[j] = a[k];
            t += dp[j];
        }
        if(ans > t + i*x) ans = t + i*x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <cstdlib> 
#include <algorithm>
#include <numeric>

using namespace std;
int main(){
  int N;
  int L[110];
  cin >> N;
  for (int i=0;i<N;i++) cin >>L[i];
  sort(L,L+N);
  int sum =accumulate(L,L+N-1,0);
  
  if (sum>L[N-1]){
    cout <<"Yes"<<endl;
  }else{
    cout <<"No"<<endl;
  }
  
}  

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

using namespace std;

const int nmax = 1e5 + 10;

int n;
int a[nmax];

int get_gcd(int a, int b) {
    while (b) {
        int r = a % b;
        a = b;
        b = r;
    }

    return a;
}

bool solve() {
    int even = 0, odd = 0;
    for (int i = 1; i <= n; ++i)
        (a[i] & 1) ? odd++ : even++;

    if (even&1) return 1;
    if (odd > 1) return 0;

    for (int i = 1; i <= n; ++i) {
        if (a[i] == 1) return 0;
        if (a[i]&1) a[i]--;
    }

    int gcd = a[1];
    for (int i = 2; i <= n; ++i)
        gcd = get_gcd(gcd, a[i]);
    for (int i = 1; i <= n; ++i)
        a[i] /= gcd;
    return solve() ^ 1;
}

int main()
{
   // freopen("input","r",stdin);
    //freopen("output","w",stdout);

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);

    if (solve()) printf("First\n");
    else printf("Second\n");

    return 0;
}


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

using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int i,j,k,l,m;
    int count = 0;
    int N;
    string S;
    cin >> N;
    cin >> S;
    vector<int> v(10);

    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            for(k=0;k<10;k++){
                m = 0;
                for(l=0;l<N;l++){
                    if(m==0){
                        if(ctoi(S[l]) == i) m++;
                    }else if(m==1){
                        if(ctoi(S[l]) == j) m++;
                    }else if(m==2){
                        if(ctoi(S[l]) == k){
                            count++;
                            break;
                        }
                    }
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define inf (int)(1e9)

int min(int a, int b){
	if(a < b){
		return a;
	}
	else{
		return b;
	}
}

int solve(int N, int R, int **d, int *r, int pre){
	int i, tmp, ans = inf;
	for(i = 0; i < R; i++){
		if(r[i] != -1){
			tmp = r[i];
			r[i] = -1;
//			printf("pre = %d, before:ans = %d\n", pre, ans);
//			printf("d[%d][%d] = %d\n", pre, r[i], d[pre][tmp]);
			ans = min(ans, solve(N, R, d, r, tmp) + d[pre][tmp]);
//			printf("pre = %d, after:ans = %d\n", pre, ans);
			r[i] = tmp;
		}
	}
	ans %= inf;
//	printf("pre = %d, ans = %d\n", pre, ans);
	return ans;
}

int main(){
	int N, M, R, A, B, C, i, j, k;
	scanf("%d%d%d", &N, &M, &R);
	int *r = (int *)malloc(sizeof(int) * R);
	for(i = 0; i < R; i++){
		scanf("%d", &r[i]);
	}
	int **d = (int **)malloc(sizeof(int *) * (N + 1));
	for(i = 0; i <= N; i++){
		d[i] = (int *)malloc(sizeof(int) * (N + 1));
		for(j = 0; j <= N; j++){
			if(i == j || i == 0 || j == 0){
				d[i][j] = 0;
			}
			else{
				d[i][j] = inf;
			}
		}
	}
	for(i = 0; i < M; i++){
		scanf("%d%d%d", &A, &B, &C);
		d[A][B] = C;
		d[B][A] = C;
	}
	for(k = 1; k <= N; k++){
		for(i = 1; i <= N; i++){
			for(j = 1; j <= N; j++){
				if(d[i][j] > d[i][k] + d[k][j]){
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}
/*	for(i = 0; i <= N; i++){
		for(j = 0; j <= N; j++){
			printf("%d  ", d[i][j]);
		}
		printf("\n");
	}
*/	printf("%d\n", solve(N, R, d, r, 0));
	return 0;
}

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

ll N, M;
Graph G;
vector<ll> deg;
ll dp[100010];

int main(int argc, char **argv)
{
	cin >> N >> M;
	G.assign(N, vector<ll>());
	deg.resize(N, 0);
	
	for (ll i = 0; i < M; ++i)
	{
		ll a, b; cin >> a >> b; --a, --b;
		G[a].push_back(b);
		++deg[b];
	}

	queue<ll> que;
	for (ll v = 0; v < N; ++v) if (deg[v] == 0) que.push(v);

	while (!que.empty())
	{
		ll cv = que.front(); que.pop();
		for (auto nv : G[cv])
		{
			--deg[nv];
			if (deg[nv] == 0)
			{
				que.push(nv);
				dp[nv] = max(dp[nv], dp[cv]+1);
			}
		}
	}

	ll res{0};
	for (ll i = 0; i < N; ++i) res = max(res, dp[i]);
	std::cout << res << std::endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//BEGIN CUT HERE
template<typename T>
struct BellmanFord{
  struct edge{
    int u,v;
    T w;
    edge(){}
    edge(int u,int v,T w):u(u),v(v),w(w){}
  };

  int n;
  vector< vector<int> > G;
  vector<int> used,reach;
  BellmanFord(int n):n(n),G(n),used(n,0),reach(n,0){}

  vector<edge> es;
  void add_edge(int u,int v,T c){
    es.emplace_back(u,v,c);
    G[u].emplace_back(v);
  }

  void dfs(int v){
    if(used[v]) return;
    used[v]=1;
    for(int u:G[v]) dfs(u);
  }

  T build(int from,int to,int &neg_loop){
    for(int i=0;i<n;i++){
      fill(used.begin(),used.end(),0);
      dfs(i);
      reach[i]=used[to];
    }
    const T INF = numeric_limits<T>::max();
    vector<T> ds(n,INF);
    ds[from]=0;
    for(int j=0;j<n;j++){
      bool update=0;
      for(auto e:es){
        if(!reach[e.u]||!reach[e.v]||ds[e.u]==INF) continue;
        if(ds[e.v]>ds[e.u]+e.w){
          ds[e.v]=ds[e.u]+e.w;
          update=1;
        }
      }
      if(!update) break;
      if(j==n-1){
        neg_loop=1;
        return INF;
      }
    }
    neg_loop=0;
    return ds[to];
  }
};
//END CUT HERE
//INSERT ABOVE HERE

signed main(){
  int n,m,p;
  cin>>n>>m>>p;
  BellmanFord<int> G(n);
  for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G.add_edge(a,b,p-c);
  }
  int neg_loop;
  int res=G.build(0,n-1,neg_loop);
  if(neg_loop){
    cout<<-1<<endl;
    return 0;
  }
  cout<<max(-res,0)<<endl;
  return 0;
}
/*
  verified on 2019/08/10
  https://atcoder.jp/contests/abc137/tasks/abc137_e
*/


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	ll sum = 0;
	vector<ll> a(n);
	vector<ll> cnt(100010);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
		cnt[a[i]]++;
	}
	int q;
	cin >> q;
	while (q--) {
		ll b, c;
		cin >> b >> c;
		sum += cnt[b] * (c - b);
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << sum << '\n';
	}
}

Measured memory_bytes: 4760
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){

	int n , w;
	int a , b , ary[100];

	cin >> w >> n;

	for(int i = 1; i <= w; i++){
		ary[i] = i;
	}

	for(int i = 0; i < n; i++){
		scanf("%d,%d" ,&a ,&b);

		int tmp = ary[a];
		ary[a] = ary[b];
		ary[b] = tmp;
	}

	for(int i = 1; i <= w; i++){
		cout << ary[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1240
import sys
sys.setrecursionlimit(10**8)
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 li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
print(S[:3] + '8' + S[4:])

Measured memory_bytes: 3188
n = int(input())
P_list = list(map(int,(input().split(" "))))
#print(P_list)
count = 0
i = 0
for i in range(n-2):
    if P_list[i] > P_list[i+1] > P_list[i+2] or P_list[i] < P_list[i+1] < P_list[i+2]:
        count = count + 1


print(count)


Measured memory_bytes: 3060
while(str = gets)
  between,last,again = str.split.map{|ngo|ngo.to_i}
  exit(0) if between == -1 and last == -1 and again == -1
  if between == -1 or last == -1
    puts "F"
    next
  end
  if between + last >= 80
    puts "A"
  elsif between + last >= 65
    puts "B"
  elsif between + last >= 50
    puts "C"
  elsif  between + last >=30
    if again >= 50
      puts "C"
    else
      puts "D"
    end
  else
    puts "F"
  end
end


Measured memory_bytes: 8720
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2 == 1) {
	    cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < n / 2; ++i) {
	    if (s[i] != s[i + n /2]) {
		    cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int h[] = new int[n];
		for(int i = 0; i < n; i++) {
			h[i] = scan.nextInt();
		}
		scan.close();
		
		ArrayList<Integer> s = new ArrayList<>();
		ArrayList<Integer> f = new ArrayList<>();
		
		int count = 0;
		boolean check = true;
		do{
			if(h[0] > 0) {
				s.add(0);
			}
			for(int i = 0; i < n - 1; i++) {
				if(h[i] == 0 && h[i+1] > 0) {	//花の連続開始位置の記録
					s.add(i+1);
				}
				if(h[i] > 0 && h[i+1] == 0) {	//花の連続終了位置の記録
					f.add(i);
				}
			}
			if(s.size() > f.size()) {	//終了位置が花の最後のとき、それは記録されてないので
				f.add(n - 1);
			}
			
			if(s.isEmpty()) {			//花の高さがすべて0ならsは空なので、終了判定
				check = false;
			}
			
			for(int i = 0; i < s.size(); i++) {
				downFlower(s.get(i), f.get(i), h);
				count += 1;
			}
			
			s.clear();
			f.clear();
		}while(check);
		
		System.out.println(count);
		

	}
	
	public static void downFlower(int s, int f, int h[]) {
		for(int i = s; i < f + 1; i++) {
			h[i] -= 1;
		}
	}

}


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

#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
#define OMAZINAI cin.tie(0); ios::sync_with_stdio(false);
typedef long long int ll;

int main() {
	ll n;
	cin >> n;
	if (n%2==0) n >>= 1;
	cout << n * 2 << endl;
	return 0;
}

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

int main()
{
	int H, W;

	while (1)
	{
		cin >> H >> W;
		
		if (H == 0 && W == 0)
		{
			break;
		}
		
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (j%2 == 0 && i%2 == 0 || j%2 == 1 && i%2 == 1)
				{
					cout << "#";
				}
				else
				{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152