akhauriyash/Code-Regression huggingface dataset:
/* ex4_1
  bonbonc */

#include<stdio.h>
int main(void){
	int tree, range;
	int assigned;//一人が割り当てられる木の本数の最大値

	scanf("%d %d",&tree,&range);
	assigned = 2*range+1; //自分のいる位置と左右にrange本

	if (tree%assigned==0){//木の本数がassignedで割り切れるとき
		printf("%d\n",tree/assigned);//木の本数をassignedで割った商を出力
	}else{
		printf("%d\n",tree/assigned +1);//木の本数をassignedで切り捨て除算し、1を加えて出力
	}

	
	return 0;
}

Measured memory_bytes: 128
#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)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#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); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
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 input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(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;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

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

    var(int, N);
    vector<i64> a(N);

    i64 leftSum = 0;
    i64 rightSum = 0;
    rep(i, N) {
        input(a[i]);
        leftSum += a[i];
    }

    leftSum -= a.back();
    rightSum = a.back();

    i64 ans = abs(leftSum - rightSum);
    repr(i, N - 2, 1) {
        leftSum -= a[i];
        rightSum += a[i];
        chmin(ans, abs(leftSum - rightSum));
    }

    print(ans);


    return 0;
}


Measured memory_bytes: 1792
m = 'Male'
f = 'Female'
v = 'Vacant'

N = int(input())
x = 0
y = N
cnt = 1
print(0)
p_bef = 0
h_bef = input()
if h_bef == v:
	exit()
while cnt < 50:
	p = (x+y+1)//2
	print(p)
	h = input()
	if h == v:
		break
	mod = 0 if h_bef == h else 1
	if (p-x) % 2 == mod:
		x = p
		h_bef = h
	else:
		y = p
	cnt += 1
exit()

Measured memory_bytes: 3660
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public struct coordinate
    {
        public int y;
        public int x;
    }

    static int max = new int();

    static int[,] map = new int[1000, 1000];
    static Queue<coordinate> que = new Queue<coordinate>();
    static int R;
    static int C;

    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        R = int.Parse(str[0]);
        C = int.Parse(str[1]);
        string str2 = "";

        List<coordinate> sList = new List<coordinate>();
        coordinate point = new coordinate();

        for (int i = 0; i < R; i++)
        {
            str2 = Console.ReadLine();
            for (int j = 0; j < C; j++)
            {
                if (str2[j] == '#')
                {
                    point.y = i;
                    point.x = j;
                    map[i, j] = -1;
                    sList.Add(point);
                }
            }
        }
        
        foreach(coordinate p in sList)
        que.Enqueue(p);

        while(que.Count() != 0)
        {
            widthSearch(que.Dequeue());
        }

        Console.WriteLine(max);

        return;
    }

    public static void widthSearch(coordinate point)
    {
        var nextPoint = new coordinate();
        nextPoint.y = point.y + 1;
        nextPoint.x = point.x;
        check(point, nextPoint);

        nextPoint.y = point.y - 1;
        nextPoint.x = point.x;
        check(point, nextPoint);

        nextPoint.y = point.y;
        nextPoint.x = point.x + 1;
        check(point, nextPoint);

        nextPoint.y = point.y;
        nextPoint.x = point.x - 1;
        check(point, nextPoint);
        return;
    }

    public static void check(coordinate point ,coordinate nextPoint)
    {
        if(nextPoint.y < 0 || nextPoint.y >= R || nextPoint.x < 0 || nextPoint.x >= C)
        {
            return;
        }
        if (map[nextPoint.y, nextPoint.x] == 0)
        {
            if(map[point.y, point.x] != -1)
            {
                map[nextPoint.y, nextPoint.x] = map[point.y, point.x] + 1;
                max = map[point.y, point.x] + 1;
            }
            else
            {
                map[nextPoint.y, nextPoint.x] = 1;
                max = 1;
            }
            que.Enqueue(nextPoint);
        }
        return;
    }

}

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

int main(){
  int i,len,count = 0;
  char s[10];

  scanf("%s",s);
  len = strlen(s);

  for(i=0;i<len;i++){
    if(s[i] <= 'Z'){
      count++;
    }
  }
  if(count != 2){
    printf("WA\n");
    return 0;
  }

  count = 0;

  if(s[0] == 'A'){
    for(i=2;i<len;i++){
      if(s[i] == 'C')
        count++;
    }
  }
  if(s[len-1] == 'C'){
    printf("WA\n");
    return 0;
  }

  if(count == 1)
    printf("AC\n");
  else
    printf("WA\n");

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    // Your code here!
    long int n,a,b;
    scanf("%ld %ld %ld",&n,&a,&b);
    if(n==1 && a==b){
        printf("1\n");
    }else if(n==1 && a!=b){
        printf("0\n");
    }else if(a>b){
        printf("0\n");
    }else{
        printf("%ld\n",(n-2)*(b-a)+1);
    }
}

Measured memory_bytes: 1728
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

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

  int sum = 0;
  for (int i=n; i!=0; i/=10) {
    sum += i%10;
  }

  if (0 == n%sum)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

public class Main {

	private static void solve(){
		//Implement solution here.
		int m1 = ni();
		int d1 = ni();
		int m2 = ni();
		int d2 = ni();
		System.out.println(m1 != m2 ? 1 : 0);
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

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

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> v(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    vector<int> nums(n-1);
    rep(i,n-1) nums[i] = i+1;
    int ans = 0;
    do {
        bool flag = true;
        int fir = 0;
        int sec = nums[0];
        bool firexist = false;
        for(int j : v[fir]) {
            if (j == sec) firexist = true;
        }
        if(!firexist) flag = false;
        rep(i,n-2) {
            int now = nums[i];
            int next = nums[i+1];
            bool exist = false;
            for(int j : v[now]) {
                if (j == next) exist = true;
            }
            if(!exist) flag = false;
        }
        if(flag) ans++;
    } while(next_permutation(nums.begin(),nums.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For( i, j, k ) for(R int i = (j); i <= (k); ++i)
#define Rep( i, j, k ) for(R int i = (j); i >= (k); --i)
#define Cross( i, j, k ) for(R int i = (j); i; i = (k))
typedef long long ll;
using namespace std;
const ll N = 100011;
const ll INF = 5e16;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x); putchar (' '); }

	inline void wln ( ll x ) { write(x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x); wln (y); }

}

using namespace IO;

namespace Cesare {
	
	ll n, m, Ans;
	
	struct Node {
		ll l, r, c;
		inline bool operator < (const Node &b) const {
			return l == b.l? r < b.r: l < b.l;
		}
	} K[N];
	
	#define ls(x) (x << 1)
	#define rs(x) (x << 1 | 1)
	#define mid ((l + r) >> 1)
	
	ll T[N << 2], Tag[N << 2];
	
	inline void pushUp(ll p) {
		T[p] = min(T[ls(p)], T[rs(p)]);
	}
	
	inline void pushDown(ll p, ll l, ll r) {
		if (Tag[p] >= INF) return ;
		Tag[ls(p)] = min(Tag[ls(p)], Tag[p]);
		Tag[rs(p)] = min(Tag[rs(p)], Tag[p]);
		T[p] = min(T[p], Tag[p]);
		T[ls(p)] = min(T[ls(p)], Tag[p]), 
		T[rs(p)] = min(T[rs(p)], Tag[p]);
		Tag[p] = INF;
	}
	
	inline void Update(ll p, ll l, ll r, ll ul, ll ur, ll k) {
		if (l >= ul && r <= ur) {
			T[p] = min(T[p], k); 
			Tag[p] = min(Tag[p], k);
			return ;
		}
		pushDown(p, l, r);
		if (mid >= ul) Update(ls(p), l, mid, ul, ur, k);
		if (mid < ur)  Update(rs(p), mid + 1, r, ul, ur, k);
		pushUp(p);
	}
	
	inline ll Query(ll p, ll l, ll r, ll x, ll res = INF) {
		if (l == r) return T[p]; 
		pushDown(p, l, r);
		if (mid >= x) res = min(res, Query(ls(p), l, mid, x));
		if (mid < x)  res = min(res, Query(rs(p), mid + 1, r, x));
		return res;
	}
	
	int main() {
		n = read(), m = read();
		for (int i = 1; i <= m; ++i)
			K[i] = (Node) {read(), read(), read()};
		sort(K + 1, K + m + 1);
		Set (T, 0x3f);
		Set (Tag, 0x3f);
		Update(1, 1, n, 1, 1, 0);
		for (int i = 1, j = 1; i <= n; ++i) {
			ll Mn = Query(1, 1, n, i);
			for (; j <= m && K[j].l == i; ++j) 
				Update(1, 1, n, i, K[j].r, Mn + K[j].c);
		} 
		Ans = Query(1, 1, n, n);
		return wln(Ans >= INF? -1: Ans), 0;
	}
	
}

int main()
{
	return Cesare :: main();
}

/*

*/



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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  int G[n][n];
  rep(i,n) memset(G[i], 0, sizeof(G[i]));
  int u, k;
  rep(i,n) {
    cin >> u >> k;
    rep(j,k) {
      int t;
      cin >> t;
      G[i][t-1] = 1;
    }
  }

  rep(i,n) {
    rep(j,n) printf("%d%c", G[i][j], (j==n-1 ? '\n' : ' '));
  }
  return 0;
}



Measured memory_bytes: 3208
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > vec(n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    vec[i].first = a, vec[i].second = b;
  }
  sort(vec.begin(), vec.end());
  cout << vec[n - 1].first + vec[n - 1].second << endl;
  return 0;
}

Measured memory_bytes: 4064
#include<bits/stdc++.h>
using namespace std;
const int Maxn=1e3;
int a[Maxn],x[Maxn],ans,p[Maxn],n,m;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cin>>m;
	for(int j=0;j<m;j++){
		cin>>p[j]>>x[j];
		p[j]--;
	}
	for(int i=0;i<m;i++){
		ans=0;
		for(int j=0;j<n;j++){
			if(p[i]==j)
				ans+=x[i];
			else
				ans+=a[j];
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 764
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){ 
  int h, w;
  cin >> h >> w;
  forn(i,h){
    string s;
    cin >> s;
    if (i == 0){
      cout << string(w+2, '#') << endl;
    }
    cout << "#";
    cout << s;
    cout << "#" << endl;
    if (i + 1 == h){
      cout << string(w+2, '#') << endl;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

6
1 1
7 1
2 2
6 2
1 3
7 3

 */

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> r(N);
	for (int i = 0; i < N; i++)
		cin >> r[i];
	sort(r.begin(), r.end());
	double ma = 0;
	for (int n = 3; n <= N; n++) {
		vector<int> a(r.end() - n, r.end());
		do {
			vector<double> x(n), y(n);
			for (int i = 0; i < n; i++) {
				x[i] = a[i] * cos(M_PI*2 / n * i);
				y[i] = a[i] * sin(M_PI*2 / n * i);
			}
			for (int t = 0; t < 10; t++) {
				int i = rand() % n;
				int j = (i + n - 1) % n, k = (i + 1) % n;
				double dx = x[k] - x[j], dy = y[k] - y[j];
				double _dx = dy, _dy = -dx;
				double r = sqrt(_dx * _dx + _dy * _dy);
				x[i] = _dx / r * a[i];
				y[i] = _dy / r * a[i];
			}
			double sum = 0;
			for (int i = 0; i < n; i++) {
				int j = (i + 1) % n;
				sum += x[i] * y[j] - y[i] * x[j];
			}
			ma = max(ma, sum);
		} while (next_permutation(a.begin() + 1, a.end()));
	}
	printf("%.15f\n", ma / 2);
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
    using namespace std;
    #define PAIN___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < ll, ll >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 100005
   /* string with spaces   getline(cin,s);*/

int main(){
    PAIN___;
	ll n,d;
	cin>>n;
	ll a[n];
	forl(i,0,n,n)
	cin>>a[i];
	ll max1=0,max2=0,ind1=0;
	forl(i,0,n,n)
	{
	    if(a[i]>max1){max1=a[i];ind1=i;}
	}
	forl(i,0,n,n)
	{
	    if(a[i]>max2&&i!=ind1)
        {
            max2=a[i];
        }
	}
	forl(i,0,n,n)
	{
	    if(a[i]==max1)cout<<max2<<endl;
	    else{
            cout<<max1<<endl;
	    }
	}
}


Measured memory_bytes: 3200
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

int n,m;
int main() {
    R(n,m);
    REP(i,n) REP(j,m) {
        char s[10];
        R(s);
        if ( strcmp(s,"snuke")==0 ) {
            printf("%c%d\n","ABCDEFGHIJKLMNOPQRSTUVWXYZ"[j],i+1);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 764
import itertools

n, m = map(int,input().split())
edges = [list(map(int,input().split())) for _ in range(m)]

node = [i for i in range(2,n+1)]
permutations_node = itertools.permutations(node)
ans = 0

for one_node in permutations_node:
    start = 1
    memo = []
    for x in one_node:
        for edge_x, edge_y in edges:
            if edge_x == start and edge_y == x and x not in memo:
                memo.append(x)
                start = x
            if edge_x == x and edge_y == start and x not in memo:
                memo.append(x)
                start = x
                
    if len(memo) == n-1:
        ans += 1
    
print(ans)

Measured memory_bytes: 3188
#include<cstdio>
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<set>
using namespace std;
using ll = long long;



int main(){
	int x;
	cin >> x;
	set<int> a;
	a.insert(1);
	for (int i = 2; i < 1000; i++) {
		for (int j = 2; j <= 1000; j++) {
			if (pow(i, j) > 1000) break;
			a.insert(pow(i, j));
		}
	}

	auto itr = a.upper_bound(x);
	cout << *(--itr) << endl;

	
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
char s[252521];
ll dp[252521][2][3][3];

int main(){
  scanf("%s",s);
  n = strlen(s);
  bool alla = false;
  alla = alla || (count(s,s+n,'a')==n);
  alla = alla || (count(s,s+n,'b')==n);
  alla = alla || (count(s,s+n,'c')==n);
  if(alla){
    puts("1");
    return 0;
  }
  if(n==3){
    int cnta = count(s,s+n,'a');
    int cntb = count(s,s+n,'b');
    int cntc = count(s,s+n,'c');
    if(cnta==1 && cntb==1 && cntc==1){
      puts("3");
    }else if(s[0]==s[1] || s[1]==s[2]){
      puts("6");
    }else{
      puts("7");
    }
    return 0;
  }
  dp[1][0][0][0] = dp[1][0][1][1] = dp[1][0][2][2] = 1;
  FOR(i,1,n)REP(ok,2)REP(m,3)REP(bef,3){
    REP(u,3){
      int nm = (m+u)%3;
      int nok = ok || (bef==u);
      (dp[i+1][nok][nm][u] += dp[i][ok][m][bef]) %= MOD;
    }
  }
  int md = 0;
  REP(i,n)md = (md + (s[i]-'a')) % 3;
  int ok = false;
  REP(i,n-1)ok = ok || (s[i]==s[i+1]);
  ll ans = 0;
  REP(i,3)ans += dp[n][1][md][i];
  if(!ok)ans++;
  ans %= MOD;
  printf("%lld\n",ans);
  return 0;
}


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

class two_value
{
public:
  int id;
  int point;
  string city;
  two_value(int i, int p, string c) {
    id = i;
    point = p; 
    city = c; 
  }
  static bool cmp_point(const two_value &tv1, const two_value &tv2) {
    return tv1.point > tv2.point; 
  }
  static bool cmp_city(const two_value &tv1, const two_value &tv2) {
    return tv1.city.compare(tv2.city)  < 0; 
  }
};

int main()
{
  int N, P;
  string S;
  cin >> N;
  vector<two_value> tv;
  for(int i = 0; i < N; i++) {
    cin >> S >> P;
    tv.push_back(two_value(i + 1, P, S));
  }
  stable_sort(tv.begin(), tv.end(), two_value::cmp_point);
  stable_sort(tv.begin(), tv.end(), two_value::cmp_city);
  for(auto set : tv) {
    cout << set.id << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    s = "0" + input()
    k = int(input())
    for i in range(1, len(s)):
        if s[i] != "1":
            print(s[i])
            break
        else:
            if i == k:
                print(1)
                break

if __name__ == "__main__":
    main()

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

int summ(int x){
	return (x*(x+1))/2;
}

double expec(int x){
	return summ(x)/(double)x;
}

int main(){
	
	int n,k; cin>>n>>k;
	double arr[n]; for(int i = 0; i < n; i++) cin>>arr[i];
	double pre[n+1];
	pre[0] = 0.0;
	for(int i = 1; i < n+1; i++){
		pre[i] = pre[i-1] + expec(arr[i-1]);
	}
	double best = 0.0;
	for(int i = k; i < n+1; i++){
		best = max(best,pre[i]-pre[i-k]);
	}
	cout<<setprecision(12)<<best<<"\n";
}

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

int c[502], s[502], f[502];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 1; i < n; i++) {
		int time = 0;
		int station = i;
		while (station < n) {
			if (time <= s[station]) {
				time = s[station] + c[station];
				station++;
			}
			else {
				int a;
				if (time%f[station] == 0) { a = 0; }
				else { a = 1; }
				time = (time / f[station])*f[station] + a*f[station] + c[station];
				station++;
			}
		}
		cout << time << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
    int main() {
	int N,left,right,total;
      cin >> N;
      
      rep ( i , N ) {
        cin >> left >> right;
        total += right - left + 1;
      }
      
      cout << total << endl;
      
    }

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

int main() {
	int H , W ;
  	cin >> H >> W ;
    vector<vector<char>> hyo(H , vector<char>(W));
  	for(int i = 0; i < H ; i++){
    	for(int j = 0; j < W ; j++){
        	cin >> hyo.at(i).at(j);
        }
    }
    int count = 0;
    for(int i = 0; i < W - count ; i++){
    	bool flag = false;
        for(int j = 0; j < H; j++){
        	if(hyo.at(j).at(i) == '#'){
                flag = true;
            	break;
            }
        }
        if(flag == false){
        	count++;
          	for(int m = 0; m < H ; m++){
          	  for(int n = i; n < W - count ; n++){
            	  hyo.at(m).at(n) = hyo.at(m).at(n + 1);
              }
            }
            i--;
        }
    }
    for(int i = 0; i < H ; i++){
      	bool flag2 = false;
    	for(int j = 0 ; j < W - count ; j++){
        	if(hyo.at(i).at(j) == '#'){
            	flag2 = true;
            }
        }
        if(flag2 == true){
        	for(int j = 0; j < W - count ; j++){
            	cout << hyo.at(i).at(j);
            }
            cout << endl;
        }
    }
}

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

int main() {
    ll n, k; 
    cin >> n >> k;
    ll x = n-n/k*k;
    ll y = n-(n/k+1)*k;
    if (x > -y) cout << -y << endl;
    else cout << x << endl;
}

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

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

int main() {
	int N, A;

	cin >> N >> A;

	cout << N * N - A << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int t= min(2,n)+1;
    while(t--){
        cerr << t << endl;
        if(2%t==0 && n%t==0) break;
    }
    cout << 2*n/t << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
const int N=1e5+2;
int hx[N];

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

int main(){
#ifndef ONLINE_JUDGE
	//freopen("b.in","r",stdin);
#endif
	int n=nxi(),m=nxi();
	for(int i=1;i<=m;++i){
		hx[i]=nxi();
	}
	for(int i=2;i<m;++i){
		if(hx[i]&1){
			if(hx[1]&1){
				if(hx[m]&1){
					puts("Impossible");
					return 0;
				}
				std::swap(hx[i],hx[m]);
			}
			else std::swap(hx[1],hx[i]);
		}
	}
	for(int i=1;i<=m;++i){
		printf("%d ",hx[i]);
	}
	puts("");
	if(m==1&&n!=1){
		printf("2\n%d 1\n",n-1);
		return 0;
	}
	++hx[1];
	if(!--hx[m]) --m;
	printf("%d\n",m);
	for(int i=1;i<=m;++i){
		printf("%d ",hx[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n][2];
	int f=0;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i][0];
		cin>>arr[i][1];
	}
	for(int i=0;i<n-2;i++)
	{
		if(arr[i][0]==arr[i][1] && arr[i+1][0]==arr[i+1][1] && arr[i+2][0]==arr[i+2][1] )
		{
			f=1;
			break;
		}
	}
	if(f==0)
	{
		cout<<"No";
	}
	else
	{
		cout<<"Yes";
	}
}


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

int main() {
  int n; cin >>n;
  int ans = 0;
  int buf;
  for (int i=0; i<n; i++){
    cin >>buf;
    while(buf%2==0){
      ans++; buf /= 2;
    }
  }
  
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
n, m, r = map(int, input().split())
R = tuple(map(lambda x: int(x)-1, input().split()))
INF = 10**9
dp = [[INF]*n for _ in range(n)]

for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    dp[a][b] = c
    dp[b][a] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

from itertools import permutations
ans = INF
for p in permutations(R):
    dist = 0
    for i in range(r-1):
        dist += dp[p[i]][p[i+1]]
    ans = min(ans, dist)
print(ans)

Measured memory_bytes: 74748
#include<iostream>
#include<stdio.h>
using namespace std;

int x, y, z;

int re=0, di=0;

int main(){
	while(scanf("%d,%d,%d", &x, &y, &z) != EOF){
		if(x*x + y*y == z*z) re++;
		else if(x == y) di++;
	}
	cout << re << endl;
	cout << di << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);
  vector<int> x(M*2);  
  
  for (int i=0; i < M * 2; i++) {
    cin >> x.at(i);
  }
  
  for (int i=0; i < M * 2; i++) {
    
  for (int j = 0; j < N; j++) {
    if (x.at(i) == j+1) {
      vec.at(j) += 1;
      break;
    }
  }
  }
  
  for (int i = 0; i < N; i++) {
    cout << vec.at(i) << endl;
  } 
}


Measured memory_bytes: 256
import sys
pre_S = input()
S = list(pre_S)

if not ( len(S) == 4 and pre_S.isupper() ): sys.exit()

uniq = set(S)
count = 0
if len(uniq) == 2:
    for I in uniq:
        if S.count(I) == 2: count += 1
print('Yes') if count == 2 else print('No')

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

# O(N^2)
cnt_self = 0
cnt_left = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            cnt_self += 1
        if A[i] != A[j]:
            cnt_left += 1

ans = 0
ans = (ans + (K * cnt_self)) % (10 ** 9 + 7)

coeff = (K * (K - 1) // 2) % (10 ** 9 + 7)
ans = (ans + (coeff * cnt_left)) % (10 ** 9 + 7)

print(ans)

Measured memory_bytes: 41708
from sys import stdin

num = int(input())

dict = {}
for i in range(num):
	cmd = stdin.readline().strip().split()

	if cmd[0] == "insert":
		dict[cmd[1]] = 1
	elif cmd[0] == "find":
		if cmd[1] in dict:
			print("yes")
		else:
			print("no")



Measured memory_bytes: 33448
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main(){
    int a,b,c; cin>>a>>b>>c;
    int maxa=a;
    if(b>maxa) maxa=b;
    else if(c>maxa) maxa=c;
    if (maxa==a) cout<<a*10+b+c;
    else if(maxa==b) cout<<b*10+a+c;
    else if(maxa==c) cout<<c*10+a+b;
    return 0;
}


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

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

    int n;
    cin >> n;
    vector<pair<int, int>> lr;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        lr.emplace_back(a - b, a + b);
    }
    sort(lr.begin(), lr.end(), [](auto& a, auto& b) { return a.second < b.second; });
    int ans = 0;
    int hoge = -2e9;
    for (int i = 0; i < n; i++) {
        if (lr[i].first >= hoge) {
            ans++;
            hoge = lr[i].second;
        }
    }
    cout << ans << endl;
}


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

int main(){
  int k, q; cin >> k >> q;
  vector<long long> d(k); rep(i, k) cin >> d[i];
  
  rep(Q, q) {
    int n, x, mod; cin >> n >> x >> mod;
    n--;
    x = x % mod;
    vector<int> D(k);
    vector<int> sum0(k + 1, 0);
    rep(i, k) {
      D[i] = d[i] % mod;
      sum0[i + 1] = sum0[i];
      if (D[i] == 0) sum0[i + 1]++;
    }
    vector<long long> sumD(k + 1, 0);
    rep(i, k) sumD[i + 1] = sumD[i] + D[i];

    long long goal = x + (sumD[k] * (n / k)) + sumD[n % k];
    long long zerocnt = (sum0[k] * (n / k)) + sum0[n % k];

    long long rev = goal / mod;

    cout << n - zerocnt - rev << endl;
  }
}


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

int main() {
  int A,B,a=0;
  string S;
  cin >> A >> B >>S;
  for (int i=0;i<A+B+1;i++){
  if (i==A && S.at(i)!='-'){
  a++;
  }
  else if (i!=A && S.at(i)=='-'){
  a++;
  }
  }

  if (a>0){
  cout << "No" << endl;
  }
  else {
  cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 256
n = int(input())
if n < 3:
    print(0)
    exit()
elif n < 5:
    print(1)
    exit()
elif n < 7:
    print(2)
    exit()
sft = []
tmp = ['33','35','37','53','55','57','73','75','77']
while True:
    a = []
    for j in tmp:
        t = set(j)
        if "5" in t and "7" in t: sft.append(j + "3")
        if "3" in t and "7" in t: sft.append(j + "5")
        if "5" in t and "3" in t: sft.append(j + "7")
        a.append(j + "3")
        a.append(j + "5")
        a.append(j + "7")
    tmp = a

    if int(sft[-1]) > n:
        for i in range(len(sft)):
            if int(sft[i]) > n:
                print(i)
                exit()


Measured memory_bytes: 14964
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    optimize_cin();
    lint N; cin >> N;
    vector<lint> a;
    a.resize(N);
    rep (i, N) { cin >> a[i]; }

    sort(ALL(a));

    vector<lint> l;

    lint mi = a[0];
    lint ma = a[a.size() - 1];
    for (lint i = -100; i <= 100; ++i)
    {
        lint cost = 0;
        for (lint k = 0; k < N; ++k)
        {
            cost += (a[k] - i)*(a[k] - i);
        }
        l.pb(cost);
    }

    sort(ALL(l));
    cout << l[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define w(x) scanf("%d",&x);while(x--)
#define ws(x) scanf("%d",&x);getchar();while(x--)
#define rep(i,b) for(i=0;i<=b;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 2*acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const int N=1e6+2;
long long  mod=1e9+9;
int t,j,cs=0,n,a,b,i;
string s;

int main()
{
    cin>>n;
    cout<<n+n*n+n*n*n<<endl;
}



Measured memory_bytes: 3620
N,x=map(int, input().split())
A = list(map(int, input().split()))

ans=0

if A[0] > x:
    ans += A[0]-x
    A[0]=x

for i in range(N-1):
    if A[i]+A[i+1] > x:
        ans +=  A[i]+A[i+1] -x
        A[i+1] = x-A[i]

print(ans)

Measured memory_bytes: 14132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n) : n(n), dat(n + 1, 0) {}

    T sum(int idx) {
        T res(0);
        for (int i = idx; i > 0; i -= i & -i) res += dat[i];
        return res;
    }

    T sum(int l, int r) {
        return sum(r - 1) - sum(l - 1);
    }

    void add(int idx, T x) {
        if (idx == 0) return;
        for (int i = idx; i <= n; i += i & -i) dat[i] += x;
    }

    int lower_bound(T x) {
        if (x <= 0) return T(0);
        int res = 0, r = 1;
        while (r < n) r <<= 1;
        for (; r > 0; r >>= 1) {
            if (res + r <= n && dat[res + r] < x) {
                x -= dat[res + r];
                res += r;
            }
        }
        return res + 1;
    }

    T sum0(int idx) {
        return sum(idx + 1);
    }

    T sum0(int l, int r) {
        return sum(r) - sum(l);
    }

    void add0(int idx, T x) {
        add(idx + 1, x);
    }
};

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    BIT<ll> bit(n);
    int a;
    rep(i, n) {
        cin >> a;
        bit.add0(i, a);
    }
    int Q, p, x, l, r;
    rep(i, q) {
        cin >> Q;
        if (Q) {
            cin >> l >> r;
            cout << bit.sum0(l, r) << endl;
        } else {
            cin >> p >> x;
            bit.add0(p, x);
        }
    }
    return 0;
}

Measured memory_bytes: 8236
#include<stdio.h>
int main(){
  long long n,i,j,c=0,a,b,sa=0,ans=0;
  scanf("%lld",&n);
  for(i=0;i<n;i++){//printf("%lld\n",i);
    scanf("%lld %lld",&a,&b);
    sa+=a*b;
    ans+=b;
  }
  while(sa>=10){
    ans+=sa/10;
    sa=sa/10+sa%10;
  }
  printf("%lld\n",ans-1);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
using LL = long long;
const int N = 3005;
const int mod = 998244353;

int a[N], f[N];

int main()
{
	int n, s;
	scanf("%d%d", &n, &s);

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

	LL res = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (a[i] > s)continue;
		else if (a[i] == s)
		{
			res = (res + 1LL * i * (n - i + 1)) % mod;
		}
		else
		{
			res = (res + 1LL * f[s - a[i]] * (n - i + 1)) % mod;
			for (int j = s; j > a[i]; --j)
				(f[j] += f[j - a[i]]) %= mod;
			f[a[i]] = (f[a[i]] + i) % mod;
		}
	}
	printf("%lld\n", res);
	

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <list>
#include<set>
#include<algorithm>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
ll n,m;
vector<ll>g[200005],v;
bool visit[200005];
set<ll>s;
void dfs(ll node)
{
    visit[node]=1;
    s.insert(node);
    for(auto child:g[node])
    {
        if(!visit[child])
            dfs(child);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,t,b,c,d,a,l,r;
    cin>>n>>m;
    for(i=1; i<=m; i++)
    {
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    for(i=1; i<=n; i++)
    {

        if(!visit[i])
        {
            dfs(i);
            v.pb(s.size());
            s.clear();
        }
    }
    sort(v.rbegin(),v.rend());
    if(v.size()==1)
        cout<<v[0]<<'\n';
    else
        cout<<(v[0]-v[1])+v[1]<<'\n';
}














Measured memory_bytes: 33512
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
 
using namespace std;
 
double EPS = 1e-10;
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
 
  point operator * (double d){
    return point(x*d,y*d);
  }
};
 
struct segment{
  point a,b;
};
 
double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}
 
double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}
 
int is_intersected_ls(point a1, point a2, point b1, point b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

 double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

int ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}
 
vector<segment> construct_edge(point* p, int n){
  vector<segment>seg,seg2;
   
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
    segment temp;
    temp.a=p[i];
    temp.b=p[j];
    seg.push_back(temp);
      }
    }
  }
 
  int t=seg.size();
  for(int i=0;i<t;i++){
    int fg=0;
    for(int j=0;j<t;j++){
  if(i!=j && vec_abs(seg[i].b-seg[j].a)<=EPS){
    if(ccw(seg[i].a,seg[i].b,seg[j].b)==1){
      fg=1;
      break;
    }
      }
    }
    if(!fg)seg2.push_back(seg[i]);
  }
  return seg2;
}
 
int point_contain(vector<segment> ps, point p, int n){
  int cnt=ccw(ps[0].a,ps[0].b,p);
 
  for(int i=0;i<n;i++)
    if(cnt!=ccw(ps[i].a,ps[i].b,p))return 0;
   
  return 1;
}
 
int main(void){
  int n;
  point p[3],k,s;
  vector<segment>seg;
 
  cin >> n;
  while(n--){
    for(int i=0;i<3;i++)
      cin >> p[i].x >> p[i].y;
     
    cin >> k.x >> k.y >> s.x >> s.y;
 
    seg=construct_edge(p,3);
 
    if(point_contain(seg,k,3)!=point_contain(seg,s,3))cout << "OK" << endl;
    else cout << "NG" << endl;
     
  }
 
  return 0;
}

Measured memory_bytes: 952
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int res = 0;
  for(int i = 0; i <= a; i++){
    int remain_a = x - i * 500;
    if(remain_a < 0)continue;
    for(int j = 0; j <= b; j++){
      int remain_b = remain_a - j * 100;
      if(remain_b < 0)continue;
      if(remain_b / 50 <= c)res++;
    }
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int[] num = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1,
                51 };
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println(num[n - 1]);
    }
}

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

/*
最大のものとそれぞれの差が1, 1ならいけるone step, 0, 2ならone step, 1, 3ならtwo step
偶数と奇数で考える？
差が両方偶数なら単純に２を足していけばおｋ
両方偶数になるまでなんとかする？
両方奇数ならばそれらに１を足せば両方偶数になる。

差が大きい方に偶数足していって、
最大値の差が同じ奇数になったらそれぞれに１を足すみたいな感じかな。
*/

/*
解説みるともっと簡単に解けるな！
A, B, CをいじってX, X, Xに到達する。
操作１と操作２で、和は２ずつ増えるので、操作回数は、{3*X - (A+B+C)} / 2
これを最小化したい。

制約はX>= max(A, B, C)と、
操作回数は整数なので、３＊Xと（A+B+C）の偶数奇数が一致していること。

このときのXは、A, B, CのMaxかそれに１を足したもの。
この二つをためせばよい。
制約を考えるとこうなる。
*/

// int main() {
//     vector<int> V(3);
//     cin >> V[0] >> V[1] >> V[2];
//     vector<int> D(3);
//     int res = 0;
//     while (!(V[0] == V[1] && V[1] == V[2]))
//     {
//         int maxv = -1, minv = 100000;
//         int min_i, max_i;
//         for (int i = 0; i < 3; i++)
//         {
//             if (minv > V[i]) {
//                 minv = V[i];
//                 min_i = i;
//             }
//             if (maxv < V[i]) {
//                 maxv = V[i];
//                 max_i = i;
//             }
//         }

//         for (int i = 0; i < 3; i++)
//         {
//             D[i] = maxv - V[i];
//         }

//         if (max_i == 0) {
//             if (D[1] == 1 && D[2] == 1) {
//                 res++;
//                 break;
//             }
//         }
//         else if (max_i == 1)
//         {
//             if (D[0] == 1 && D[2] == 1) {
//                 res++;
//                 break;
//             }
//         }
//         else
//         {
//             if (D[0] == 1 && D[1] == 1) {
//                 res++;
//                 break;
//             }
//         }

//         V[min_i] += 2;
//         res++;
//     }

//     cout << res << endl;
// }

int main() {
    int V[3];
    int maxv = -1;
    for (int i = 0; i < 3; i++)
    {
        cin >> V[i];
        maxv = max(maxv, V[i]);
    }

    int res1 = (3 * maxv) - (V[0] + V[1] + V[2]);
    int res2 = 3 * (maxv + 1) - (V[0] + V[1] + V[2]);

    if (res1 % 2 == 0)
        cout << res1 /2 << endl;
    else
    {
        cout << res2 / 2 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 100007
const ll inf=1e13+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();;
void sieve();
int main()
{
	//sieve();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(2);
	ll t=1;
	//cin>>t;
	for(ll i=1;i<=t;i++)
	solve();
	return 0;
}
ll w[101],val[101],dp[101][100005],n,k,cap,maxv=0;
void intl()
{
	for(ll i=0;i<100005;i++)
	{
		for(ll j=0;j<101;j++)
		dp[j][i]=inf;
	}
}

void solve()
{
	intl();
	cin>>n>>cap;
	for(ll i=0;i<n;i++)
	{
		cin>>w[i]>>val[i];
		maxv+=val[i];
	}
	dp[0][0]=0;
	dp[0][val[0]]=w[0];
	for(ll i=1;i<n;i++)
	{
		dp[i][0]=0;
		dp[i][val[i]]=w[i];
		for(ll value=1;value<=maxv;value++)
		{
			dp[i][value]=dp[i-1][value];
			if(value-val[i]>=0)
			dp[i][value]=min(dp[i-1][value],dp[i-1][value-val[i]]+w[i]);
		}
	}
	ll v;
	for(v=maxv;v>=0;v--)
	{
		if(dp[n-1][v]<=cap)
		break;
	}
	cout<<v<<endl;
}
	
	

		


Measured memory_bytes: 82544
#include<stdio.h>
 
int main(){
  int n, var=0;
  scanf("%d", &n);
  while(n!=0){
    if(n%10==7) {
      printf("Yes\n");
      var =1;
      break;
    }
    n/=10;
  }
  if(var==0)
    printf("No\n");
  
  return 0;
}

Measured memory_bytes: 1620