akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<string> v(n);
  rep(i,0,n)cin>>v[i];
  V<ll> mn(n,INF),rmn(n,INF),sc(n);
  V<PL> po(0),ne(0),ze(0);

  rep(i,0,n){
    int sco=0;
    rep(j,0,siz(v[i])){
      if(v[i][j]=='(')sco++;
      else sco--;
      chmin(mn[i],sco);
    }
    sc[i]=sco;

    if(sc[i]>0)po.eb(mn[i],i);
    else if(sc[i]==0) ze.eb(mn[i],i);
    else{
      sco=0;
      repr(j,0,siz(v[i])){
        if(v[i][j]=='(')sco--;
        else sco++;
        chmin(rmn[i],sco);

      }
      ne.eb(rmn[i],i);
    }
  }

  sort(all(po));
  reverse(all(po));

  sort(all(ne));
  reverse(all(ne));


  ll nowp=0,nown=0;
  rep(i,0,siz(po)){
    if(nowp+po[i].fs<0){
      cout<<"No"<<ENDL;
      return 0;
    }
    nowp+=sc[po[i].sc];
  }
  rep(i,0,siz(ze)){
    if(nowp+ze[i].fs<0){
      cout<<"No"<<ENDL;
      return 0;
    }
  }

  rep(i,0,siz(ne)){
    if(nown+ne[i].fs<0){
      cout<<"No"<<ENDL;
      return 0;
    }
    nown-=sc[ne[i].sc];
  }

  if(nowp==nown)cout<<"Yes"<<ENDL;
  else cout<<"No"<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 73652
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
int A, B, K;
void input() {
  cin >> A >> B >> K;
  ;
  ;
}
void solve() {
  int k = min(A, K);
  A -= k;
  K -= k;
  int kk = min(B, K);
  B -= kk;
  cout << A << " " << B << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;
const ll OO = 1e16;
const long double EPS = 1e-6;

int n,m;
char arr[1001][1001];
int dp[1001][1001];
int solve(int i,int j){

        if(i >= n || j >= m ||  arr[i][j] == '#')
            return 0;

        if(i == n - 1 && j == m - 1)
                return 1;
        int &ret = dp[i][j];
        if(~ret)
            return ret;
        ret = (solve(i + 1,j)%mod + solve(i, j + 1)%mod)%mod;
        return ret%mod;
}
int main()
{
    ios_base::sync_with_stdio();cin.tie(0),cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; ++i)
            for(int j = 0 ; j < m; ++j)
                cin >> arr[i][j];
    memset(dp,-1,sizeof dp);
    cout << solve(0,0) << "\n";
    return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


string s;

int main(){
	cin >> s;
	int n = s.size();
	
	int cnt = 0, c = 0;
	for(int i = 0; i < n; i++){
		if(i % 2){
			if(s[i] == '0') cnt++;
			else c++;
		}
		else{
			if(s[i] == '1') cnt++;
			else c++;
		}
	}
	
	cout << min(c,cnt) << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    int A, B, C, K;

    cin >> A >> B >> C >> K;

    int Max = max(max(A, B), C);

    cout << (Max == A ? A * (1 << K) + B + C : Max == B ? B * (1 << K) + A + C : C * (1 << K) + A + B);
}


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

ans = 0
for i in range(0, n-1):
    if a[i] > a[i+1]:
        ans += a[i] - a[i+1]
        a[i+1] = int(a[i])
    else:
        ans += 0
        
print(ans)

Measured memory_bytes: 32216
#include <bits/stdc++.h>
#define REP(i, n) for (long long 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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll k; cin >> k;
  ll n = 50;
  vector<ll> a(n);
  REP(i,n) a[i] = i + (k/n);
  int ind = 0;
  REP(kk,k%n){
    REP(i,n){
      if(i==ind) a[i] += n;
      else a[i]--;
    }
    ind = (ind+1) % 50;
  }
  
  cout << "50\n";
  REP(i,n) cout << a[i] << " ";
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n, y = map(int, input().split())

for yukichi in range(n + 1):
  for higuchi in range(n + 1 - yukichi):
    noguchi = n - yukichi - higuchi
    if (yukichi * 10000 + higuchi * 5000 + noguchi * 1000) == y:
      print(yukichi, higuchi, noguchi)
      exit()
print(-1, -1, -1)

Measured memory_bytes: 9056
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int h,w;
  std::cin >> h >> w;
  vt<std::string> s(h);
  rep(i,h)
    std::cin >> s[i];

  vvi cnt (h+2,vt<int>(w+2));
  rep(i,h){
    rep(j,w){
      if(s[i][j] == '#') {
        for(int p = i; p < i+3; p++)
          for(int q = j; q < j+3; q++){
            if(p == i+1 && q == q+1)
              continue;
            else
              cnt[p][q]++;
          }
      }
    }
  }

  rep(i,h) {
    rep(j,w){
      if(s[i][j] == '#')
        std::cout << '#';
      else
        std::cout << cnt[i+1][j+1];
    }
    std::cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

template<typename T>
T minT(T a, T b) {
	if (a < b) return a;
	else return b;
}

template<typename T>
T maxT(T a, T b) {
	if (a > b) return a;
	else return b;
}

template<typename T>
T absT(T a) {
	if (a < 0) a *= -1;
	return a;
}

template<typename T>
T powT(T a, T x) {
	T res = 1;
	while (x > 0) {
		if (x & 1) res = res*a;
		a = a*a;
		x >>= 1;
	}
	return res;
}

ll StoLL(string str) {
	ll ret = 0, ini = 0;
	if (str[0] == '-') ini = 1;
	repi(i, ini, str.length()) {
		ret *= 10;
		ret += (ll)(str[i] - '0');
	}
	if (ini) ret *= -1;
	return ret;
}

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

ll N;
ll leftW[MAX_10p5 * 3], rightE[MAX_10p5 * 3];
ll ans = MAX_10p18;

int main() {
	string str;
	cin >> N >> str;

	repi(i, 0, str.length()) {
		if (i > 0) leftW[i] = leftW[i - 1];
		if (str[i] == 'W') leftW[i]++;
	}
	repi(i, 0, str.length()) {
		if (i > 0) rightE[N - 1 - i] = rightE[N - 1 - i + 1];
		if (str[N - 1 - i] == 'E') rightE[N - 1 - i]++;
	}
	repi(i, 0, str.length()) {
		ll t;
		if (i == 0) t = rightE[1];
		else if (i == N - 1) t = leftW[N - 2];
		else t = rightE[i + 1] + leftW[i - 1];
		ans = min(ans, t);
	}

	wrln(ans);

	return 0;
}


Measured memory_bytes: 5380
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int n;
    cin >> n;

    int count = 0;
    int maxCount = 0;

    int hleft;
    cin >> hleft;
    rep(i, n - 1)
    {
        int h;
        cin >> h;

        //cout << "hleft : " << hleft << "\n";
        //cout << "h : " << h << "\n";

        if (h <= hleft)
        {
            count++;
            //cout << "count : " << count << "\n";
        }
        else
        {
            maxCount = max(maxCount, count);
            count = 0;
        }
        hleft = h;
    }

    cout << max(maxCount, count) << "\n";

    return 0;
}

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


public class  Main{
	static int mod=(int)1e9+7;
	static LinkedList<Integer>[]adj;
	static int k;
	static boolean[]v;
	static long dfs(int i) {
		v[i]=true;
		int start;
		long ans=1;
		if(i==0) {
			start=k-1;ans=k;
		}
		else {
			start=k-2;
		}
		for(int j:adj[i]) {
			if(!v[j]) {
				ans=((((ans*(start--))%mod)*dfs(j))%mod);
			}
			
		}
		return ans%mod;
	}
    public static void main(String[] args) throws Exception{
    	MScanner sc = new MScanner(System.in);
        //MScanner sc = new MScanner("reduce.in");
        PrintWriter pw=new PrintWriter(System.out);
        int n=sc.nextInt();
        k=sc.nextInt();
        adj=new LinkedList[n];
        for(int i=0;i<n;i++)adj[i]=new LinkedList<Integer>();
        for(int i=0;i<n-1;i++) {
        	int x=sc.nextInt()-1;int y=sc.nextInt()-1;
        	adj[x].add(y);adj[y].add(x);
        }
        v=new boolean[n];
        long x=dfs(0);
        pw.println(x);
        pw.flush();
    }
    static StringBuilder tosb(int[]in) {
    	StringBuilder s=new StringBuilder();
    	for(int i=0;i<in.length;i++) {
    		s.append(in[i]+" ");
    	}
    	return s;
    }
    static StringBuilder tosb(long[]in) {
    	StringBuilder s=new StringBuilder();
    	for(int i=0;i<in.length;i++) {
    		s.append(in[i]+" ");
    	}
    	return s;
    }
    
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

int main() {
  string S;
  int ans = 0;

  cin >> S;

  //曜日によって場合分け
  if (S == "SUN") {
    ans = 7;
  }
  else if (S == "MON") {
    ans = 6;
  }
  else if (S == "TUE") {
    ans = 5;
  }
  else if (S == "WED") {
    ans = 4;
  }
  else if (S == "THU") {
    ans = 3;
  }
  else if (S == "FRI") {
    ans = 2;
  }
  else if (S == "SAT") {
    ans = 1;
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3005,M=1e9+7;
int n,m,dp[N][N][2],ans;
signed main(){
	scanf("%lld%lld",&n,&m);
	for (int i=0;i<=n;i++)dp[0][i][i==0]=1; 
	for (int i=0;i<m;i++)
		for (int j=0;j<=n;j++)
			for (int k=0;k<=1;k++){
				if (j>=1)(dp[i+1][j-1][k|(j==1)]+=dp[i][j][k])%=M;
				if (j>=1)(dp[i+1][j][k|(j==1)]+=dp[i][j][k])%=M;
				if (j<n)(dp[i+1][j+1][k]+=dp[i][j][k])%=M;
				if (j<n)(dp[i+1][j][k]+=dp[i][j][k])%=M;
			}
	int ans=0;	
	for (int i=0;i<=n;i++)(ans+=dp[m][i][1])%=M;
	printf("%lld\n",ans);	
}

Measured memory_bytes: 141184
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
LL inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =1000000000000000000;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define F first
#define S second
class MinimizeAbsoluteDifferenceDiv1
{
    public:
vector <int> findTuple(vector <int> x)
{


}
};
int A[100005]={};
vector<int>node[100005]={};

int vis[100005]={};
vector<int>tmp;
void re(int now){
vis[now]=1;
tmp.push_back(now);
for(int i=0;i<node[now].sz;i++){
    int k=node[now][i];
    if(!vis[k]){
        re(k);
    }
}
}
int main()
{

int a,b;
while(cin>>a>>b){

    for(int i=1;i<=a;i++){
        cin>>A[i];
    }
    for(int i=0;i<b;i++){
        int x,y;
        cin>>x>>y;
        node[x].push_back(y);
        node[y].push_back(x);
    }
    int ans=0;
int mark[100005]={};
    for(int i=1;i<=a;i++){
        if(!vis[i]){
                    int num[100005]={};
                tmp.clear();
            re(i);

        for(int j=0;j<tmp.sz;j++){
            num[ tmp[j] ]=1;
        }
    vector<int>t;
    for(int j=0;j<tmp.sz;j++){
        t.push_back(A[ tmp[j] ]);
    }
        for(int j=0;j<t.sz;j++){
            if(num[ t[j] ])
                mark[ t[j] ]=1;
        }
        }
    }
    for(int i=1;i<=a;i++){
        if(i==A[i]||mark[i])
            ans++;
    }
    cout<<ans<<endl;






}

    return 0;
}


Measured memory_bytes: 10488
#include <bits/stdc++.h>
using namespace std;
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b, c;
    cin >> a >> b >> c;
    cout << (a.back() == b.front() && b.back() == c.front() ? "YES" : "NO")
         << endl;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  long long n,a,b;
  cin>>n>>a>>b;
  if(b<a||(n==1&&a!=b)){
    cout<<0<<endl;
  }else if((n==1&&a==b)){
    cout<<1<<endl;
  }else{
    long long maxi=b*(n-1)+a;
    long long mini=a*(n-1)+b;
    cout<<maxi-mini+1<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

ll gcd(ll a, ll b){
	if(!b) return a;
	return gcd(b, a%b);
}

int main(void){
	ll k;
	cin >> k;
	ll ans = 0;
	repn(a, k) repn(b, k) repn(c, k) ans += gcd(a, gcd(b, c));
	co(ans);

	return 0;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    
		try {
			int lima = Integer.parseInt(in.readLine());
			String[] sa = in.readLine().split(" ");
			
			int limb = Integer.parseInt(in.readLine());
			String[] sb = in.readLine().split(" ");

			int[] a = new int[lima];
			int[] b = new int[limb];

			for (int i = 0; i < lima; i++) {
				a[i] = Integer.parseInt(sa[i]);
			}
			
			for (int i = 0; i < limb; i++) {
				b[i] = Integer.parseInt(sb[i]);
			}
			
			Arrays.sort(a);
			Arrays.sort(b);
			
			int hit = 0;
			boolean[] flag = new boolean[limb];
			for (int i = 0; i < limb; i++) {
				flag[i] = false;
			}
			
			for (int j = 0; j < limb; j++) {
				if (flag[j]) continue;

				int s = 0;
				int g = lima - 1;	
				int i = (s + g) / 2;
				while (s <= g) {
					if (b[j] > a[i]) {
						s = i + 1;
					} else if (b[j] == a[i]) {
						flag[j] = true;
						hit++;
						break;
					} else {
						g = i - 1;
					}
					i = (s + g) / 2;
				}
			}
			
			System.out.println(hit);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

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

#define int long long

void solve() {
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++) {
		if(s[i]=='7') {
			cout<<"Yes\n";
			return;
		}
	}
	cout<<"No\n";
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--) {
		solve();
	}
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);

    String s;
    String sl[];
    s = r.readLine();
    sl = s.split(" ");

    int a = Integer.parseInt(sl[0]);
    
    System.out.println((a % 10 == 9 || a / 10 == 9) ? "Yes" : "No");

  }

}

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

#define ll long long int 
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i)) 
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main()
{
	_fastio
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<en;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
  string str;
  cin>>str;
  for(int i=0;i<str.size();i++){
    if((i+1)&1){
      if(str[i]=='L'){
        cout<<"No\n";
        return 0;
      }
    }
    else{
      if(str[i]=='R'){
        cout<<"No\n";
        return 0;
      }
    }
  }
  cout<<"Yes\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, d; cin >> a >> b >> c >> d;
	int x = a + b, y = c + d;
	if (x > y) cout <<  "Left";
	else if (x == y) cout << "Balanced";
	else cout << "Right";

	return 0;
}

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

int main()
{
  int n;
  string s;
  int k;
  cin >> n >> s >> k;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == s[k - 1])
    {
      cout << s[i];
    }
    else
    {
      cout << "*";
    }
  }
  cout << '\n';
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] str = br.readLine().split(" ");
    int r = Integer.parseInt(str[0]);
    int D = Integer.parseInt(str[1]);
    int x = Integer.parseInt(str[2]);
    
    for (int i = 0; i < 10; i++) {
      x = r * x - D;
      System.out.println(x);
    }
  }
}

Measured memory_bytes: 21076
from heapq import *
N=int(input())
A=list(map(int,input().split()))
Q=[]
heapify(Q)
for i in range(N):
  heappush(Q,A[i])
ML=[sum(Q)]
for i in range(N):
  if Q[0]<A[N+i]:
    ML.append(ML[i]+A[N+i]-Q[0])
    heappop(Q)
    heappush(Q,A[N+i])
  else:
    ML.append(ML[i])
for i in range(3*N):
  A[i]*=-1
A=A[::-1]
Q=[]
heapify(Q)
for i in range(N):
  heappush(Q,A[i])
MR=[sum(Q)]
for i in range(N):
  if Q[0]<A[N+i]:
    MR.append(MR[i]+A[N+i]-Q[0])
    heappop(Q)
    heappush(Q,A[N+i])
  else:
    MR.append(MR[i])
MR=MR[::-1]
print(max([ML[i]+MR[i] for i in range(N+1)]))

Measured memory_bytes: 135784
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()

template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
using vpi = vector<Pi>;
using vpl = vector<Pl>;
 
void lyn(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}
 
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
	return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}
#define MOD 1000000000 + 7
template<int mod>
struct Modint {
  long long x; // typedef long long ll;
  Modint(long long x=0):x((x%mod+mod)%mod){}
  Modint& operator+=(const Modint a) { if((x+=a.x)>=mod)x-=mod;return *this;}
  Modint& operator-=(const Modint a) { if((x+=mod-a.x)>=mod)x-=mod; return *this;}
  Modint& operator*=(const Modint a) { (x *=a.x)%=mod; return *this;}
  Modint operator+(const Modint a) const { Modint res(*this);return res+=a;}
  Modint operator-(const Modint a) const { Modint res(*this);return res-=a;}
  Modint operator*(const Modint a) const { Modint res(*this);return res*=a;}
  Modint pow(ll t) const {
    if (!t) return 1;Modint a = pow(t>>1);a*=a;
    if (t&1) a *= *this;return a;
  }
  // for prime mod
  Modint inv() const { return pow(mod-2);}
  Modint& operator/=(const Modint a) { return (*this) *= a.inv();}
};
using mint = Modint<MOD>;
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(20);
  
  ll n;cin >> n;
  mint ans = mint(10).pow(n);
  ans -= (mint)2 * (mint)(mint(9).pow(n));
  ans += mint(8).pow(n);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <iomanip>    // setw 控制输出间隔函数
#include <iostream>   // cin, cout, abs
#include <algorithm>  // max, min, swap, sort
#include <cmath>      // pow
#include <cstring>    // strlen, memset
#include <set>        // set 集合
#include <stack>      // stack 栈
#include <queue>      // queue 队列
#include <string>     // string 字(yang)符(rou)串, substr
#include <map>
#include <fstream>
using namespace std;
int main()
{
    int n;
    scanf("%d", &n);
    int k = n / 15;
    n = n * 800 - k * 200;
    printf("%d\n", n);
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ns = list(map(int, input().split()))
min_x = float('inf')
sum_x = 0
total_sum = sum(ns)
for i in range(n-1):
    sum_x += ns[i]
    min_x = min(min_x, abs(total_sum-2*sum_x))
print(min_x)

Measured memory_bytes: 23800
h,w = map(int,input().split())
c = [list(map(int,input().split())) for i in range(10)]
for i in range(10):
    for j in range(10):
        for k in range(10):
            c[j][k] = min(c[j][k],c[j][i]+c[i][k])
a = [list(map(int,input().split())) for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == -1:continue
        ans += abs(c[a[i][j]][1])
print(ans)

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

using namespace std;

int main() {
    int n, k;
    int r, s, p;
    string t;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    int len = (int)t.size();
    vector <int> mp(26, 0);
    mp['r' - 'a'] = p;
    mp['s' - 'a'] = r;
    mp['p' - 'a'] = s;
    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += mp[t[i] - 'a'];
    }
    for (int i = k; i < len; i++) {
        if (t[i - k] != t[i]) {
            sum += mp[t[i] - 'a'];
        } else {
            t[i] = '*';
        }
    }
    cout << sum << endl;
    return 0; 
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

int main(void)
{
    int k, x;

    cin >> k >> x;
    
    int start = 0;
    int end = 0;

    if (x - k < -1000000) start = -1000000;
    else start = x - k + 1;
    
    if (x + k > 1000000) end = 1000000;
    else end = x + k;
    
    for (int i = start; i < end; i++)
    {
        cout << i << ' ';
    }
    return 0;
}


Measured memory_bytes: 888
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 100002;
#define endl '\n'
#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()

int32_t main()
{ 
   IOS


  int a;
  cin >> a;
  cout << a + a*a + a*a*a<<endl;  
  
    
    




  
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){
  int i,a,b=0;
  
  scanf("%d",&a);
  
  for(i=0;i<=2;i++){
	if(a%10==1)
      b++;
    a=a/10;
  }
   
  printf("%d",b);
  
  return 0;
}

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

const int INF = 1 << 30;
int x, pos;

struct Graph {
    struct Vertex { int n, v, c; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, 0 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i) {
        if (v[i].v) return;
        v[i].v = 1;
        if (v[i].c < x) x = v[i].c, pos = i;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            dfs(o.i);
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
};

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

    int n, m;
    cin >> n >> m;

    Graph g(n, m * 2);
    for (int i = 0; i < n; i++) {
        cin >> g.v[i].c;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    int64_t s = 0;
    int r = 0;
    for (int i = 0; i < n; i++) {
        x = INF;
        g.dfs(i);
        if (x != INF) {
            r++;
            s += x;
            g.v[pos].c = 0;
        }
    }

    int v = r * 2 - 2;

    if (n < v) {
        cout << "Impossible" << endl;
        quick_exit(0);
    }

    if (r == 1) {
        s = 0;
    } else {
        vector<int> a;
        for (int i = 0; i < n; i++) {
            int t = g.v[i].c;
            if (t > 0) a.push_back(t);
        }
        if (a.size() > 0) {
            sort(a.begin(), a.end());
            for (int i = 0; i < v - r; i++) {
                s += a[i];
            }
        }
    }

    cout << s << endl;

    return 0;
}

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

int main(){
    int n, m; cin >> n >> m;
    graph g(n);
    for(int i=0; i<m; ++i){
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> dist(n, -1);
    queue<int> que;
    vector<int> pre(n ,-1);

    dist[0] = 0; que.push(0);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(auto nv : g[v]){
            if(dist[nv]!=-1){continue;}
            dist[nv] = dist[v] + 1; 
            pre[nv] = v;
            que.push(nv);
        }
    }
    bool ok = false;
    for(int i=0; i<n; ++i){
        if(dist[i]!=-1){ok = true; break;}
    }
    //if(ok){cout << "Yes" << endl;}else{cout << "No" << endl;}
    cout << "Yes" << endl;
    for(int i=1; i<n; ++i){
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 10728
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int a, b, c;
	cin >> a >> b >> c;

	cout << ((a + b) * c) / 2 << endl;

	return 0;
}


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

#define min(a,b) (((a) > (b)) ? (b) : (a))
int main(void) {
    int64_t N;
    int64_t lastc,lastd;
    int64_t mincnt;
    int64_t cntc = 0,cntd = 0;

    cin >> N;
    vector<int64_t> p(N);
    vector<int64_t> a(N,0);
    vector<int64_t> b(N,0);
    vector<int64_t> c(N,0);
    vector<int64_t> d(N,0);
    for(int i=0;i<N;i++) {
        cin >> p[i];
        p[i]--;
    }

    for(int i=0;i<(N-1);i++) {
        a[i] = (p[i+1] == i);
    }
    for(int i=1;i<N;i++) {
        b[i] = (p[i-1] == i);
    }

    for(int i=0;i<N;i++) {
        if(p[i] == i) {
            if(i % 2) {
                c[i] = a[i] + 1;
                d[i] = b[i] + 1;
            } else {
                c[i] = b[i] + 1;
                d[i] = a[i] + 1;
            }
        }
    }

    lastc = 0;
    lastd = 0;
    cntc = 0;
    cntd = 0;
    for(int i=0;i<N;i++) {
        if(c[i]) {
            if(lastc) {
                lastc = 0;
            } else {
                lastc = 1;
                cntc++;
            }
        } else {
            lastc = 0;
        }

        if(d[i]) {
            if(lastd) {
                lastd = 0;
            } else {
                lastd = 1;
                cntd++;
            }
        } else {
            lastd = 0;
        }
    }

    cout << min(cntc,cntd) << "\n";

    return 0;
}


Measured memory_bytes: 4224
def main(input = STDIN)
  plane = {" " => "101", "'" => "000000", "," => "000011", "-" => "10010001", "." => "010001", "?" => "000001", "A" => "100101", "B" => "10011010", "C" => "0101", "D" => "0001", "E" => "110", "F" => "01001", "G" => "10011011", "H" => "010000", "I" => "0111", "J" => "10011000", "K" => "0110", "L" => "00100", "M" => "10011001", "N" => "10011110", "O" => "00101", "P" => "111", "Q" => "10011111", "R" => "1000", "S" => "00110", "T" => "00111", "U" => "10011100", "V" => "10011101", "W" => "000010", "X" => "10010010", "Y" => "10010011", "Z" => "10010000"}
  code = ["A"]
  for i in 1..25
    code[i] = code[i - 1].next
  end
  code.push " ", ".", ",", "-", "'", "?"
  while text = input.gets
    output = []
    coded = text.chomp.split(//).map{|char|plane[char]}.join
    coded << "0" * (-coded.size % 5)
    for i in 0...coded.size / 5
      output << code[coded.slice(i * 5, 5).to_i(2)]
    end
    puts output.join
  end
end
main

Measured memory_bytes: 6112
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    s = input()
    n = len(s) - 1

    for bit in range(1 << n):
        f = s[0]

        for i in range(n):
            if bit & (1 << i):
                f += "+"
                f += s[i + 1]
            else:
                f += "-"
                f += s[i + 1]

        if eval(f) == 7:
            print(f + "=7")
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
from functools import reduce
n = int(input())
ts = [int(input())for _ in range(n)]


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a*(b//gcd(a, b))


print(reduce(lcm, ts))


Measured memory_bytes: 3572
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a // g * b


def count(X, C, D):
    ans = X
    ans -= X // C
    ans -= X // D

    num = X // lcm(C, D)
    ans += num

    return ans


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

    print(count(B, C, D) - count(A - 1, C, D))

if __name__ == '__main__':
    main()


Measured memory_bytes: 4212
N, A, B = map(int, input().split())
S = list(input())

n = 0
b = 0

for s in S:
  if s == 'c':
    print('No')
  elif s == 'a':
    if n < A + B:
      print('Yes')
      n += 1
    else:
      print('No')
  else:
    if n < A + B and b < B:
      print('Yes')
      n += 1
      b += 1
    else:
      print('No')
    

Measured memory_bytes: 4712
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define vi vector<ll>
#define ff first
#define ss second
const int N = 100010;
ll a[N];
int main()
{
	int n,k,ind =-1;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]<0) ind=i;
		//else if(ind!=i-1) a[i]+=a[i-1];
	}
	if(ind==-1)
	{
		cout<<a[k];
		return 0;
	}
	ll res=-1;
	a[ind]=-a[ind];
	for(int i=ind-1;i>=1;i--)
		a[i]=-a[i];
	if(ind>=k)
		res=a[ind-k+1];
	a[0]=a[1];
	for(int i=1;i<k&&i+ind<=n;i++)
	{
		if(ind>=k-i)
		{
			if(res==-1||res>2*a[i+ind]+a[ind-(k-i)+1]||res>a[i+ind]+2*a[ind-(k-i)+1])
				res=min(2*a[i+ind]+a[ind-(k-i)+1],a[i+ind]+2*a[ind-(k-i)+1]);
		}
	}
	if(ind+k<=n)
	{
		if(res==-1||res>a[ind+k])
			res=a[ind+k];
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
 
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll x,k,d;
	cin>>x>>k>>d;
	x=abs(x);
 
	if(x>0 && x/d>=k)
	{
		x=x-k*d;
		cout<<x;
		return 0;
	}
	else
	{
		ll temp=x/d;
		x=x-temp*d;
		k=k-temp;
		if(k%2==0)
			cout<<abs(x);
		else
			cout<<abs(min(x-d,x+d));
		return 0;
	}
	
	
}

Measured memory_bytes: 3608
h, w =list(map(int, input().split())) 
mat = []
for i in range(h):
    s = input()
    mat.append([s[x] for x in range(w)])

flag = True
for i in range(h-1):
    for j in range(w-1):
        if mat[i][j] == '#':
            if( (mat[i+1][j]=='#')& (mat[i][j+1]=='#') ):
                flag = False

for i in range(1,h):
    for j in range(1,w):
        if mat[i][j] == '#':
            if( (mat[i-1][j]=='.')& (mat[i][j-1]=='.') ):
                flag = False

if flag :
    print('Possible')
else:
    print('Impossible')

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    string s;

    cin >> s;

    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    } else if (s == "Rainy") {
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
n = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))

l = []
def permutation(start, end):
    if end==start:
        #print(a)
        t = a[::]
        l.append(tuple(t))
        return
    for i in range(start, end+1):
        a[i],a[start] = a[start],a[i]
        permutation(start+1, end)
        a[i],a[start] = a[start],a[i]
permutation(0,len(a)-1)
l.sort()
x,y=0,0
for i in range(len(l)):
    if l[i]==tuple(a):
        x = i
    if l[i] == tuple(b):
        y=i

print(abs(x-y))

Measured memory_bytes: 8088
#?????¨????????\???
row, cow = (int(i) for i in input().split())
#??????????????????(??\?????????????????????????´??????????????????????)
array = []
#??\?????????????????????????´?
for i in range(row):
    swap_list = input().split()
    array.append(swap_list)
#?????????????¨????????´?????????????????????????
row_sum = [0 for i in range(row)]
cow_sum = [0 for i in range(cow)]

#?????????????¨?????¨????
for i in range(row):
    for j in range(cow):
        row_sum[i] += int(array[i][j])
        cow_sum[j] += int(array[i][j])
#??¨??????????¨?
all_sum = sum(row_sum)

#?¨???????????????¨???
for i in range(row):
    #?????¨??????????¨??????¨???
    print(" ".join(map(str,array[i][:])),end = "")
    print(" {0}".format(row_sum[i]))
#??????????¨???¨?????°?????¨???
print(" ".join(map(str,cow_sum)),end = "")
print(" {0}".format(all_sum))

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

int main() {
    int64_t n, a, b;
    cin >> n >> a >> b;

    int64_t d = b - a;
    int64_t r = d * (n - 2) + 1;

    cout << (r < 0 ? 0 : r) << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

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

void solve() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < size(s); i++)
		ans += s[i] != t[i];
	cout << ans;
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 3956
n, k = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

if c.max < 0
  puts c.max
  exit
end

loops = []
done = []

for i in 0..(n-1)
  next if done.include?(i)
  j = i
  scores = [c[p[j]-1]]
  while p[j]-1 != i
    j = p[j]-1
    scores << c[p[j]-1]
    done << j
  end
  loops << scores
end

ans = loops.map do |scores|
  if scores.size == 1
    next [scores[0], 0].max * k
  end
  score = [0, scores.sum].max
  scoresscores = scores + scores
  comsum = scoresscores.inject([0]) do |s, x|
    s << s.last + x
  end
  extra = (1..(scores.size-1)).map do |len|
    tmp = (0..(scores.size-1)).map do |start|
      comsum[start+len] - comsum[start]
    end.max
    if len > k
      0
    elsif len > k % scores.size && score > 0
      tmp - score
    else
      tmp
    end
  end.max
  extra = [0, extra].max
  score * (k / scores.size)  + extra
end.max

puts ans


Measured memory_bytes: 101668
#include <bits/stdc++.h>
using namespace std;
struct knife{
    int att;
    bool st;
} a[200010];
int n, h;
bool cmp(knife a, knife b) {
    return a.att > b.att;
}
int main() {
    scanf("%d%d", &n, &h);
    int cc = 0;
    for (int i = 1; i <= n; ++i) {
        ++cc;
        scanf("%d", &a[cc].att);
        ++cc;
        scanf("%d", &a[cc].att);
        a[cc].st = true;
    }
    sort(a + 1, a + cc + 1, cmp);
    int cnt = 0;
    for (int i = 1; i <= cc; ++i) {
        if (a[i].st) {
            ++cnt, h -= a[i].att;
            if (h <= 0) {
                cout << cnt << endl;
                return 0;
            }
        } else {
            cnt += h / a[i].att + (h % a[i].att != 0);
            cout << cnt << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1792