akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define sai(j,n) for(sei j=0;j<sei(n);++j)
#define gsai(j,n) for(sei j=sei(n)-1;j>=0;--j)
#define kan(j,m,n) for(sei j=m;j<sei(n);++j)
#define gkan(j,m,n) for(sei j=sei(n)-1;j>=sei(m);--j)
#define zen(h) (h).begin(),(h).end()
#define yu(h) v.erase(unique(zen(h)), h.end());
#define mugen 10000000111
#define yo 10000000711
#define kyo 1e-9
#define datu break
#define saiki(a) while(a)
#define seiri(h) sort(zen(h))
#define sin() main()
#define hen return
#define nyu(a) cin >> a
#define syutu(a) cout << a << endl
#define ru(a) if(a)
#define ta else
#define ruguo(a) else if(a)
#define tyo() length()
#define tei const

using namespace std;
typedef int seisu;
typedef void mu;
typedef long long sei;
typedef long double xyo;
typedef string moji;
typedef pair<sei, sei> so;
typedef pair<xyo, xyo> sox;
typedef vector<sei> hs;
typedef vector<xyo> hx;
typedef vector<hs> hhs;
typedef vector<hx> hhx;
typedef vector<moji> hm;
typedef vector<so> hso;
typedef vector<sox> hsox;
typedef bool singi;

const seisu h1[8] = {1,1,0,-1,-1,-1,0,1};
const seisu h2[8] = {0,1,1,1,0,-1,-1,-1};

sei dai(sei a, sei b){return max(a,b);}
sei syo(sei a, sei b){return min(a,b);}

sei r;

seisu sin(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    nyu(r);
    ru(r<1200){
        syutu("ABC");
    }
    ruguo(r<2800){
        syutu("ARC");
    }
    ta{
        syutu("AGC");
    }
    hen 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M; cin >> N >> M;
  vector<ll> d(N, 0);
  vector<bool> visited(N, false);
  vector<vector<pair<ll, ll> > > E(N, vector<pair<ll, ll> >());
  vector<ll> LL(M);
  REPLL(i, M){
    ll L, R, D; cin >> L >> R >> D; L--; R--;
    E[L].push_back({R, D});
    E[R].push_back({L, -D});
    LL[i] = L;
  }
  bool flag = true;
  REPLL(i, M){
    if(visited[LL[i]]) continue;
    queue<pair<ll, ll> > q;
    q.push({LL[i], 0});
    visited[LL[i]] = true;
    d[LL[i]] = 0;
    while(!q.empty()){
      auto cur = q.front(); q.pop();
      for(auto i : E[cur.first]){
        if(visited[i.first]){
          if(d[i.first] == d[cur.first] + i.second){
            continue;
          }else{
            flag = false;
            break;
          }
        }
        visited[i.first] = true;
        d[i.first] = d[cur.first] + i.second;
        q.push(i);
      }
      if(!flag) break;
    }
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 19040
n, m = map(int, input().split())

sum = 0
countList = [0] * (m+1)

for i in range(n):
    l = list(map(int, input().split()))

    for j in range(1, len(l)):
        countList[l[j]] += 1

for k in countList:
    if k == n:
        sum += 1

print(sum)


Measured memory_bytes: 3060
def main():
	from collections import deque
	n=int(input())
	battle=n*(n-1)//2
	lis=[[] for i in range(battle)]
	num=[-1]*(n**2)
	cnt=-1
	for x in range(n**2):
		if x//n<x%n:
			cnt+=1
			num[x]=cnt
	for i in range(n):
		a=list(map(int,input().split()))
		for j in range(n-2):
			x=a[j]-1
			y=a[j+1]-1
			px=num[min(i*n+x,x*n+i)]
			py=num[min(i*n+y,y*n+i)]
			lis[px].append(py)
	node_in=[0]*(battle)
	for i in range(battle):
		for x in lis[i]:
			node_in[x]+=1
	zero=deque([])
	days=[10**9]*(battle)
	for i in range(battle):
		if node_in[i]==0:
			zero.append(i)
			days[i]=1
	while zero:
		r=zero.popleft()
		for x in lis[r]:
			node_in[x]-=1
			if node_in[x]==0:
				zero.append(x)
				days[x]=days[r]+1
	if 10**9 in days:
		print(-1)
	else:
		print(max(days))
if __name__ == '__main__':
	main()

Measured memory_bytes: 107992
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,a,b,c,d;
    while(~scanf("%d %d %d",&a,&b,&c))
    {
        if(c>=a&&c<=b)
            printf("Yes\n");
        else
            printf("No\n");
    }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
string days[7] = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

int main() {
  string day; cin >> day;
  for(int i = 1; i <= 7; i++) {
    if(days[i-1] == day) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int score,n,sum[100],i,j,blank;

  while(1){
  scanf("%d",&n);
  if(n == 0) break;

  for(i = 0; i < n; i++){

    sum[i]=0;

    for(j = 0; j < 5; j++){

      scanf("%d",&score);
      sum[i] +=	score;

    }

  }

  // for(i = 0; i < n; i++) printf("%d ",sum[i]);                                                                                                                                              

  for(i = 0; i < n-1; i++){

    for(j = 0; j < n-1; j++){

      if(sum[j] > sum[j+1]){

      blank=sum[j];
      sum[j]=sum[j+1];
      sum[j+1]=blank;

      }

    }

  }

  // for(i = 0; i < n; i++) printf("%dテ」ツ??,sum[i]);                                                                                                                                              

  printf("%d %d\n",sum[n-1],sum[0]);

  }

  return 0;

}

Measured memory_bytes: 596
package main

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

func main(){
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	if strings.Count(s.Text(), "5") == 2 && strings.Count(s.Text(), "7") == 1 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}



Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
int W, H, x, y, r;

scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);

if (x - r < 0 || y - r < 0 || x + r > W || y + r > H)
{
  printf("No\n");
}

else
{
	printf("Yes\n");
}

return 0;
}


Measured memory_bytes: 2140
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

int main() {
  ll a, b; cin >> a >> b;
  if (a==b) {
    cout << a << endl;
    return 0;
  }
  
  if (b-a==1) {
    cout << 1 << endl;
    return 0;
  }
  
  ll l = (a&1) ? a+1 : a; // lは偶数
  ll r = (b&1) ? b : b-1; // rは奇数
  ll C = ((r-l+1)/2)&1;
  if (a&1) C ^= a;
  if ((b&1)==0) C ^= b;
  cout << C << endl;
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		char line[2048],str[1024]={0};
		cin >> line;
		for(int i=0,j=500; line[i]; i++)
		{
			switch(line[i])
			{
				case '>': j++; break;
				case '<': j--; break;
				case '-': break;
				default: str[j]=line[i]; break;
			}
		}

		int i;
		for(i=0; !str[i]; i++);
		cout << &str[i] << endl;
	}
}

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

int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	string ans;
	rep(i, 2*n){
		if(i % 2 == 0) ans += s[i / 2];
		else ans += t[i / 2];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b;
    cin >> a >> b;
    if(a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

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

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int Maxn = 3000 + 100;

int N;
double A[Maxn], Dp[Maxn][Maxn];

inline void Solve ()
{
	Dp[0][0] = 1;
	for (int i = 1; i <= N; ++i)
		for (int j = 0; j <= i; ++j)
		{
			Dp[i][j] += Dp[i - 1][j - 1] * A[i];
			Dp[i][j] += Dp[i - 1][j] * (1.0 - A[i]);
		}
	double ans = 0;
	for (int i = N / 2 + 1; i <= N; ++i)
		ans += Dp[N][i];
	printf("%.10lf\n", ans);
}

inline void Input ()
{
	N = read<int>();
	for (int i = 1; i <= N; ++i) scanf("%lf", &A[i]);
}

int main()
{
#ifdef hk_cnyali
	freopen("I.in", "r", stdin);
	freopen("I.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}


Measured memory_bytes: 72448
def main():
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    B = [[] for _ in range(H * W + 1)]
    for h in range(H):
        for w in range(W):
            B[A[h][w]] = (h,w)
    C = []
    for d in range(1,D+1):
        tmp = []
        x, y = B[d]
        pre = 0
        while d <= H * W:
            nx, ny = B[d]
            now = abs(nx - x) + abs(ny - y) + pre
            tmp.append(now)
            pre = now
            x, y = nx, ny
            d += D
        C.append(tmp)
    Q = int(input())
    for _ in range(Q):
        L, R = map(int, input().split())
        index = L % D
        index -= 1
        cnt = L // D
        if L % D == 0:
            cnt -= 1
        ans = C[index][cnt + (R - L) // D] - C[index][cnt]
        print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 96088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int m,N,x=1;cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  m=a.at(0);
  for(int i=1;i<N;i++)if(m>a.at(i))m=a.at(i),x++;
  cout<<x<<endl;
}

Measured memory_bytes: 1024
#include <iostream>

//insertionsort

using namespace std;


void printA(int x[], int n){
	for(int i=0;i<n;i++){
		cout << x[i];
		if(i==n-1)cout<<"\n";
		else cout << " ";
	}
}

int main(){
	int n,v,j;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	printA(a,n);
	
	for(int i=1;i<n;i++){
		v = a[i];
		j = i-1;
		while(j>=0 && a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		printA(a,n);
	}
	return 0;
}


Measured memory_bytes: 3072
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int m=sc.nextInt();
        int x=sc.nextInt();
        int y=sc.nextInt();
        int a=-1000,b=1000;
        for(int i=0; i<n; i++) {
            a=max(sc.nextInt(),a);
        }
        for(int i=0; i<m; i++) {
            b=min(sc.nextInt(),b);
        }
        String ans="War";
        for(int i=x+1; i<=y; i++) {
            if(a<i && i<=b){ans="No War"; break;}
        }

        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  

    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 24660
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n;
  cin>>n;
  vector<long> vec(n);
  rep(i,n) cin>>vec[i];

  long ans = vec[0];
  rep(i,n) ans = ans/__gcd(ans, vec[i])*vec[i];

  cout << ans << endl;

  return 0;
}


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

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 each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n,m,q;
ll b[1010];

inline void output(int arg){
	if(__builtin_popcountll(b[arg])!=1)
		cout << '?';
	else{
		int bit;
		for(bit=0;bit<n;bit++)
			if(b[arg]&(1LL<<bit))
				break;
		if(bit>=10)
			cout << (char)(bit-10+'A');
		else
			cout << bit;
	}
}

int main(void){
	while(cin >> n >> m >> q){
		if(n==0)
			break;
		ll sw=0LL;
		rep(i,m) b[i]=((1LL<<n)-1LL);
		rep(i,q){
			ll nsw=0;
			string tmp;
			cin >> tmp;
			rep(j,n){
				if(tmp[j]=='1')
					nsw|=(1LL<<j);
			}
			sw^=nsw;
			cin >> tmp;
			rep(j,m){
				if(tmp[j]=='1')
					b[j]&=sw;
				else
					b[j]&=(~sw);
			}
		}
		rep(i,m) output(i);
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

int main(){
  ll N, L;
  cin >> N >> L;
  ll ans = 200;
  ll sum = 0;
  rep(i, N){
    if(abs(L + i) < abs(ans)) ans = L + i;
    sum += L + i;
  }
  cout << (sum - ans) << endl;
  return 0;
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
c=input()
cnt=Counter(c)

ans=0
for i in range(cnt["R"]):
    if c[i]!="R":
        ans+=1
print(ans)

Measured memory_bytes: 69232
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> P_;
typedef pair<ll, P_> P;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int N, H, W;
P p[100000];
bool used[100000];
bool used_root[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> H >> W;
    UnionFind uf(H+W);
    for(int i = 0; i < N; i++){
        int R, C;
        ll A;
        cin >> R >> C >> A;
        R--; C--;
        C += H;
        p[i] = P(A, P_(R, C));
    }
    sort(p, p+N, greater<P>());
    ll ans = 0;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        int r = p[i].second.first;
        int c = p[i].second.second;
        ll a = p[i].first;
        if(!uf.findSet(r,c)){
            int rr = uf.root(r);
            int rc = uf.root(c);
            if(used_root[rr] && used_root[rc]) continue;
            ans += a;
            uf.unionSet(r, c);
            int root = uf.root(r);
            if(used_root[rr] || used_root[rc]) {
                used_root[rc] = false;
                used_root[rr] = false;
                used_root[root] = true;
            }
            used[i] = true;
            cnt++;
            // cout << a << ' ' <<  r << ' ' << c << endl;
        }else{
            int root = uf.root(r);
            if(!used_root[root]){
                used_root[root] = true;
                ans += a;
                cnt++;
                // cout << a << ' ' <<  r << ' ' << c << endl;
            }
        }
    }
    // cout << cnt << endl;
    cout << ans << endl;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int64_t pow_int (int64_t a,int64_t b){
  int64_t res = 1;
  while(b != 0){
    if(b & 1){
      res *= a;
    }
    a = a*a;
    b = b >> 1;
  }
  return res;
}
int main(){
  vector<int64_t> primenum(1000000);
  vector<int64_t> primecnt(1000000);
  int64_t primeindex = 0;
  int64_t n;
  int64_t p;
  cin >> n >> p;
  int64_t np = p;
  for(int i=2;i<=sqrt(p)+1 && np != 1;i++){
    if(np % i == 0){
      primenum.at(primeindex) = i;
      while(np % i == 0){
        np /= i;
        primecnt.at(primeindex)++;
      }
      primeindex++;
    }
  }
  if(np != 1){
    primenum.at(primeindex) = np;
    primeindex++;
  }
  
  int64_t result = 1;
  
  for(int i=0;i<primeindex;i++){
    result *= pow_int(primenum.at(i),(primecnt.at(i))/n);
  }
  if(n != 1){
    cout << result << endl;
  }else{
    cout << p << endl;
  }
}
  
    
  

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

#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<ll,ll> ii;
const ll INF = 0x3f3f3f3f3f3f3f;
const double PI = acos(-1.0);

const int T = 2512;
vector<ii> g[T];
ll dist[T];
ll n,m,p;

void bellman() {
	for(int i = 0; i < n-1; i++)
		for(int u = 1; u <= n; u++)
			for(ii v : g[u])
				if(dist[u] < INF)
					dist[v.fi] = min(dist[v.fi],dist[u]+v.se);
}

void cycle() {
	for(int i = 0; i < n-1; i++)
		for(int u = 1; u <= n; u++)
			for(ii v : g[u])
				if(dist[u] < INF and dist[u]+v.se < dist[v.fi])
					dist[v.fi] = -INF;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> p;
	for(int i = 0; i < m; i++) {
		ll a,b,c;
		cin >> a >> b >> c;
		g[a].eb(b,p-c);
	}

	for(int i = 1; i <= n; i++) dist[i] = INF;
	dist[1] = 0;
	bellman();
	cycle();
	bellman();

	cout << (dist[n] <= -INF? -1 : dist[n] > 0? 0 : abs(dist[n])) << endl;
	return 0;
}


Measured memory_bytes: 512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((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())

using namespace std;

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

const int MOD = 1000000007;

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w, 'a'));

    REP(i, h) {
        REP(j, w) {
            cin >> a[i][j];
        }
    }
    int d[26] = {};
    REP(i, h) {
        REP(j, w) {
            d[a[i][j] - 'a']++;
        }
    }

    int t = (2 - h % 2) * (2 - w % 2);
    bool f = false;
    int c = 0;
    REP(i, 26) {
        if (d[i] % t != 0) {
            cout << "No" << endl;
            return 0;
        } else {
            if (d[i] % 2 == 1) {
                if (f) {
                    cout << "No" << endl;
                    return 0;
                } else {
                    f = true;
                    c += (d[i] % 4) / 2;
                }
            } else {
                c += (d[i] % 4) / 2;
            }
        }

    }

    if (c <= (w % 2) * (h / 2) + (h % 2) * (w / 2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var NAB = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];

            if((B-A)%2 == 0)
            {
                var c = (B - A) / 2;
                Console.WriteLine(c);
            }
            else
            {
                var A_sa = A - 1;
                var B_sa = N - B;

                if(B_sa > A_sa)
                {
                    var min1 = B - 1;
                    var min2 = A_sa + (B - A_sa) / 2;
                    
                    if(B-A >= 3)
                    {
                        Console.WriteLine(min2);
                    }
                    else
                    {
                        Console.WriteLine(min1);
                    }
                }
                else
                {
                    var min1 = N - A;
                    var min2 = B_sa + (N - A - B_sa - 1) / 2;

                    if (B - A >= 3)
                    {
                        Console.WriteLine(min2+1);
                    }
                    else
                    {
                        Console.WriteLine(min1);
                    }
                }
            }
        }
        
    }
    
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<"LBWNB    "<<x<<"---\n"
#define pb push_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mp make_pair
#define p() puts("")
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
//const int mod=998244353;
const int mod=1e9+7;
//const int inf=1e9+7;
const int maxn=2e3+10;
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}

int t,n,m,k;
int main(){
	ll n,ans=2;
	cin>>n;
	if(n==2) ans=1;
	for(ll k=2,i=n;k*k<=n;k++,i=n){
        if(k*k==n-1) {ans++;break;}
        if((n-1)%k==0&&k*k!=(n-1)) {ans+=2;continue;}
		while(i>=k) i%k?i%=k:i/=k;
		if(i==1) ans++;
		
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int n, k, sum=1;
    scanf("%d%d", &n, &k);

    rep(i, 0, n){
        int add = sum+k;
        int mul = sum*2;
        if(add>=mul) sum = sum * 2;
        else sum = sum + k;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  long station, runTime[499] = {}, firstTime[499] = {}, nextTime[499] = {}, result[500] = {};
  int i, j, k;
  
  scanf("%ld", &station);
  for(i = 0; i < station - 1; i++){
    scanf("%ld%ld%ld", &runTime[i], &firstTime[i], &nextTime[i]);
  }

  for(i = 0; i < station - 1; i++){
    result[i] += firstTime[i];
    for(j = i; j < station - 1; j++){
      if(firstTime[j] > result[i]){
        result[i] = firstTime[j];
      }
      else{
        for(k = 0; firstTime[j] + k * nextTime[j] < result[i]; k++){}
        result[i] = firstTime[j] + k * nextTime[j];
      }
      result[i] += runTime[j];
    }
  }

  for(i = 0; i < station; i++){
    printf("%ld\n", result[i]);
  }

  return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {
    string s;
    cin>>s;
    
    int ans=0;
    rep(i,4) if(s[i]=='2') ans++;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

ll dp[3001][3001][2];

ll recurse(int l, int r,int turn, vector<ll> &arr)
{
    if(l>r) return 0;
    if (dp[l][r][turn] != -1) return dp[l][r][turn];
    else
    {
        if(turn == 1) return dp[l][r][turn] = max(recurse(l+1,r,0,arr)+arr[l],recurse(l,r-1,0,arr)+arr[r]);
        else return dp[l][r][turn] = min(recurse(l+1,r,1,arr),recurse(l,r-1,1,arr));
    }
    
}

int main(int argc, char const *argv[])
{
    int n,temp;
    cin >> n;
    vector<ll> arr(n,0);
    ll sum = 0;

    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        arr[i] = temp;
        sum+= temp;
    }

    for(int i =0 ; i <= n ; i++)for(int j =0; j <=n ;j++)for(int k=0 ; k<=2 ;k++) dp[i][j][k] = -1;

    ll x = recurse(0,n-1,1,arr);
    ll y = sum -x ;

    cout << x-y;
    
    return 0;
}


Measured memory_bytes: 144452
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <set>
using namespace std;

double dist(pair<double, double> a, pair<double, double> b)
{
	return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

vector<pair<double, double>> v;
vector<int> perm;

void solve()
{
	int n;
	cin >> n;

	v.resize(n);
	perm.resize(n);
	
	int fact = 1;
	for (int i = 0; i < n; i++)
	{
		fact *= (i + 1);
		cin >> v[i].first >> v[i].second;
		perm[i] = i;
	}

	double res = 0;
	for (int i = 0; i < fact; i++)
	{
		for (int k = 0; k < n - 1; k++)
		{
			res += dist(v[perm[k]], v[perm[k + 1]]);
		}
		next_permutation(perm.begin(), perm.end());
	}

	cout << fixed << setprecision(12) << res / (1.0 * fact);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

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

int H,W;
int C[1401][1401];


int solve(){
    int dp[1401][1401];
    int max=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(C[i][j]==1) dp[i][j]=0;
            else dp[i][j]=min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+1;
            if(dp[i][j]>max) max=dp[i][j];
        }
    }
    return max;
}

int main(){
    cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++) cin>>C[i][j];
    }
    int ans=solve();
    cout<<ans*ans<<endl;
}


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

using namespace std;

int main(){
    int a, b, x;
    cin >> a >> b >> x;
    b = min(a, b);
    a = min(a, b * 2);
    cout << (x / 1000) * a + min(((x % 1000) / 500) * b + !!(x % 500) * b, !!(x % 1000) * a) << "\n";
}


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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

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

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (abs(a - b) % 2 == 0) {
        cout << abs(a - b) / 2 << EOL;
    } else {
        if (a > b) swap(a, b);
        cout << min((b - a - 1) / 2 + a, (b - a - 1) / 2 + n - b + 1) << EOL;
    }
}


Measured memory_bytes: 256
s=input()
if ((s[0]==s[1] and s[2]==s[3]) or (s[0]==s[2]and s[1]==s[3]) or (s[0]==s[3]and s[1]==s[2])):
  if s[0]==s[1]==s[2]==s[3]:
    print("No")
  else:  
    print("Yes") 
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

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

    int n, m;
    cin >> n >> m;
    vector<int> h(n + 1);
    set<int> st;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (h[a] <= h[b]) {
            st.insert(a);
        }
        if (h[b] <= h[a]) {
            st.insert(b);
        }
    }
    cout << n - st.size() << '\n';

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 6640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.14159265358979323846
using namespace std;
//
int main(){
  int N,K;
  set<char> S;
  cin>>N>>K;
  FOR(i,0,K){
    char D;
    cin>>D;
    S.insert(D);
  }
  while(1){
    int n=N;
    while(1){
      if(S.find('0'+n%10)!=S.end()){
        break;
      }
      n/=10;
      if(n==0){
        cout<<N<<endl;
        return 0;
      }
    }
    N++;
  }
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {x:usize,a:usize,b:usize}
    println! {"{}",(x-a)%b}
}


Measured memory_bytes: 4352
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    sum_a = sum(a_list)
    min_val = 100
    min_index = 0

    for i, a in enumerate(a_list):
        d = abs(n * a - sum_a)
        if d < min_val:
            min_val = d
            min_index = i

    print(min_index)


if __name__ == "__main__":
    main()


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

int main(){
	int n,x; cin>>n;
	n++;
	vector<int> v(n);
	rep(i,n) cin>>v[i];
	sort(all(v));
	n--;
	vector<int> d(n);
	rep(i,n) d[i]=v[i+1]-v[i];
	sort(all(d));
	for(int i=d[0]; i>0; i--){
		bool flg=true;
		for(int j=1; j<n; j++){
			if(d[j]%i!=0) {flg=false; break;}
		}
		if(flg) {cout<<i<<endl; return 0;}
	}
}

Measured memory_bytes: 4036
import java.util.*;
import java.util.Map.*;

public class Main {
    private static int[] colors;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n - 1;
        colors = new int[n];
        Arrays.fill(colors, -1);
        
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            points[i] = new Point(i);
        }
        
        while (m-- > 0) {
            int me = sc.nextInt() - 1;
            int you = sc.nextInt() - 1;
            int length = sc.nextInt();
            points[me].becomeFriend(points[you], length);
            points[you].becomeFriend(points[me], length);
        }
        
        dfs(points[0], 0);
        
        for (int c : colors) {
            System.out.println(c);
        }
    }
    
    public static void dfs(Point p, int length) {
        boolean alreadyKnown = colors[p.name] != -1;
        if (alreadyKnown) return;
        
        if (length % 2 == 0) {
            colors[p.name] = 0;
        } else {
            colors[p.name] = 1;
        }
        
        for (Entry<Point, Integer> entry : p.friends.entrySet()) {
            Point friend = entry.getKey();
            int length2 = entry.getValue();
            dfs(friend, length + length2);
        }
    }
    
    public static class Point {
        int name;
        Map<Point, Integer> friends;
        
        Point(int name) {
            this.name = name;
            this.friends = new HashMap<Point, Integer>();
        }
        
        void becomeFriend(Point p, int length) {
            this.friends.put(p, length);
        }
    }
}

Measured memory_bytes: 122260
'use strict';

function Main(input) {
    const tmp = input.split(" ");
    const N = parseInt(tmp[0], 10);
    const A = parseInt(tmp[1], 10);
    const B = parseInt(tmp[2], 10);
    let sum = 0;

    for (let i = 1; i <= N; i++) {
        let tmp = i;
        if (tmp >= 10) {
            let tmpStr = tmp + "";
            tmp = 0;
            for (let j = 0; j < tmpStr.length; j++) {
                tmp += parseInt(tmpStr[j], 10);
            }
        }
        if (tmp >= A && tmp <= B) {
            sum += i;
        }
    }

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


Measured memory_bytes: 14908
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){
  int N, M; cin >> N >> M;
  char A[N][N], B[M][M];

  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> A[i][j];
    }
  }
  for (int i = 0; i < M; i++){
    for (int j = 0; j < M; j++){
      cin >> B[i][j];
    }
  }  

  bool flag = false;
  for (int i = 0; i < N - M + 1; i++){
    for (int j = 0; j < N - M + 1; j++){
      bool f = true;
      for (int k = 0; k < M; k++){
        for (int l = 0; l < M; l++){
          if (A[i + k][j + l] != B[k][l]){
            f = false;
          }
        }
      }
      if (f == true){
        flag = true;
      }
    }
  }
  
  if (flag == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    int A, P;
    cin >> A >> P;
    P += A * 3;
    cout << P / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
	int w,h,n;
	
	scanf("%d %d %d", &w, &h, &n);
	
	int now[2];
	int road = 0;
	bool flag = true;
	
	for (int i = 0; i < n; i++){
		int x,y;
		
		scanf("%d %d", &x, &y);
		
		if(flag){
			now[0] = x;
			now[1] = y;
			flag = false;
		}
		
		while(!(now[0] == x && now[1] == y)){
			if (now[0] < x && now[1] < y){
				now[0]++;
				now[1]++;
			}
			else if(now[0] < x) now[0]++;
			else if(now[1] < y) now[1]++;
			
			else if(now[0] > x && now[1] > y){
				now[0]--;
				now[1]--;
			}
			else if(now[0] > x) now[0]--;
			else if(now[1] > y) now[1]--;
			
			road++;
		}
	}
	
	printf("%d\n", road);
	
	return (0);
}

Measured memory_bytes: 1028
fun main(args: Array<String>) {
    val s = readLine()!!
    val w = readInteger()

    var ans = StringBuilder()
    for (i in 0 until s.length step w) {
        ans.append(s[i])
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 33788
#include<stdio.h>
int main(){
    char s[10];
    scanf("%s",s);
    if(s[0]==s[1]&&s[1]==s[2])printf("Yes\n");
    else if(s[1]==s[2]&&s[2]==s[3])printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
from collections import defaultdict, Counter

n  = int(input())
lis = [input() for _ in range(n)]

a = Counter(lis)

tmp = 0
for key, value in a.items():
    tmp = max(value, tmp)

ans =[]
for k, v in a.items():
    if v == tmp:
        ans.append(k)

for i in sorted(ans):
    print(i)

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

int main(void) {
    int a,b;
    cin >> a >> b;
    if((a+b)%2==0)cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    i64 N, K;
    read(N, K);

    vector<i64> A(N), F(N);
    rep(i, N) read(A[i]);
    rep(i, N) read(F[i]);

    sort(all(A));
    sort(all(F), greater<>());

    const auto isAble = [&](i64 limit) {
        i64 cnt = 0;
        rep(i, N) {
            cnt += max<i64>(0, A[i] - (limit / F[i]));
        }
        return cnt <= K;
    };

    i64 notAble = -1;
    i64 able = LINF;
    while (able - notAble > 1) {
        const i64 mid = (notAble + able) / 2;
        if (isAble(mid)) able = mid;
        else notAble = mid;
    }

    print(able);
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int k,t,a[10000],M=0;
  cin >> k >> t;
  for(int i=0; i<t; i++) {
    cin >> a[i];
    M=max(M,a[i]);
  }
  cout << max(0,M-1-(k-M)) << endl;
}

Measured memory_bytes: 256