akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	HashMap<Integer, Integer> gcdMap;

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		
		gcdMap = new HashMap<>();
		
		long sum = 0;
		
		for (int i = 1; i <= n; i++) {
			for(int j = i; j <= n; j++) {
				for(int k = j; k <= n; k++) {
					if(i == j && j == k) {
						sum += gcd3(i, j,k);
					}else if(i == j || j == k || k == i){
						sum += 3*gcd3(i, j,k);
					}else {
						sum += 6*gcd3(i, j,k);
					}
				}
			}
		}
		
		System.out.println(sum);
	}
	
	long gcd3(int a , int b, int c) {
		int firstGCD = gcd(a,b);
		int secondGCD = gcd(firstGCD, c);
		return (long)secondGCD;
	}
	
	int gcd(int a,int b) {
		
		if(a < b) {
			int temp = a;
			a = b;
			b = temp;
		}
		
		int key = b*1000+a;
		if(gcdMap.containsKey(key)) {
			return gcdMap.get(key);
		}
		
		int r = a % b;
		while(r != 0) {
			a = b;
			b = r;
			r = a % b;
		}
		
		gcdMap.put(key, b);
		return b;
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 57172
#include <cstdio>
#include <cstring>
using namespace std;

bool prime[2000000];
bool dp[2000000];

int main()
{
	int n, x;
	
	prime[0] = true;
	for (int i = 2; i < 2000000; i++){
		prime[i] = true;
	}
	
	for (int i = 2; i * i < 2000000; i++){
		for (int j = i * i; j < 2000000; j += i){
			prime[j] = false;
		}
	}
	
	while (scanf("%d %d", &n, &x), n + x){
		memset(dp, 0, sizeof(dp));
		dp[0] = true;
		
		for (int i = 0; i < n; i++){
			int yen;
			scanf("%d", &yen);
			for (int i = 0; i <= 1000000; i++){
				if (dp[i]){
					dp[i + yen] = true;
				}
			}
		}
		
		for (int i = x; i >= 0; i--){
			if (dp[i] && prime[i]){
				if (i == 0){
					printf("NA\n");
				}
				else {
					printf("%d\n", i);
				}
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 4952
import fractions
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
import random

def is_prime(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True
  
A,B = map(int,input().split())

g = fractions.gcd(A,B)
l = make_divisors(g)
su = 1
for li in l:
  if is_prime(li):
    su+=1
    
print(su)

Measured memory_bytes: 6108
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

vi v(3);

signed main(){
    in(v);
    sort(all(v));

    out(v[0]*v[1]/2);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

long long inp_n1, inp_n2, i1;

long long inp_a[100005];

long long readNumber() {
	long long temp_func;
	scanf("%lld", &temp_func);
	return temp_func;
};
long long printNumber(long long temp_func) {
	printf("%lld", temp_func);
	return 0;
};

bool caler() {
	
	return inp_n1 > inp_n2;
	
};

int main() {
	
	inp_n1 = readNumber();
	
	inp_n2 = readNumber();
	
	if (caler()) {
		
		printf("safe");
		
	} else {
		
		printf("unsafe");
		
	};
	
}

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

int main(void){
	int n,x[25];

	while(cin>>n && n){
		for(int i=0;i<n;i++) cin>>x[i];

		int rem = 32, k=0;
		for(int j=0;rem > 0;j++){
			if(j % 2 == 0){
				rem -= (rem - 1) % 5;
			}
			else{
				rem -= x[k];
				if(rem < 0) rem = 0;
				k = (k + 1) % n;
			}
			cout<<rem<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k) for(int i=j;i<k;i++)
int main(){
    long long n,x,ans=0;
    cin>>n>>x;
    long long a[n];
    f(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    f(i,0,n){
        if(i!=n-1&&x>=a[i]){
            x-=a[i];
            ans++;
        }
        else if(i==n-1&&x==a[i]){
            ans++;
        }
        else{
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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;
  string s;
  cin >> n >> s;
  
  for(char &c : s){
    int x = c - 'A';
    x += n;
    x %= 26;
    c = 'A' + x;
  }

  cout << s << endl;

}


Measured memory_bytes: 256
#-*-coding:utf-8-*-
from collections import Counter

def main():
    n = int(input())
    a_list = []
    for _ in range(n):
        a_list.append(int(input()))
    
    ans = 0
    cnt = Counter(a_list)
    for i in set(a_list):
        if cnt[i] % 2 != 0:
            ans += 1
    print(ans)



if __name__ == '__main__':
    main()

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

typedef pair< int, int > P;

int H, W;
int fld[1000][1000];
int cnt[1000][1000];
int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1}, dy[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main() {
	cin >> H >> W;
	queue<P> Q;
	for (int i = 0; i < H; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < W; j++) {
			fld[i][j] = (s[j] == '.' ? 0 : s[j] - '0');
            if (fld[i][j] == 0) Q.push(P(i, j));
		}
	}
	int ans = -1;
    while(Q.size()) {
		ans++;
		int sz = Q.size();
		for (int i = 0; i < sz; i++) {
			P p = Q.front(); Q.pop();
			int x = p.second, y = p.first;
            for (int j = 0; j < 8; j++) {
				int nx = x + dx[j], ny = y + dy[j];
				if (nx < 0 || nx >= W || ny < 0 || ny >= H || fld[ny][nx] == 0) continue;
				cnt[ny][nx]++;
                if (cnt[ny][nx] >= fld[ny][nx]) {
					fld[ny][nx] = 0;
                    Q.push(P(ny, nx));
				}
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 11000
/*
 * 2335.cc: 10-Year-Old Dynamic Programming
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const int MAX_K = 10000;
const int MAX_F = MAX_N + MAX_M + MAX_K * 2;

typedef long long ll;
const ll MOD = 1000000007;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

ll fracs[MAX_F + 1], invfs[MAX_F + 1];

/* subroutines */

ll powmod(ll a, int n) {  // a^n % MOD
  ll pm = 1;
  while (n > 0) {
    if (n & 1) pm = (pm * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return pm;
}

inline ll combmod(int n, int k) {  // nCk % MOD
  return fracs[n] * invfs[n - k] % MOD * invfs[k] % MOD;
}

/* main */

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  int f = n + m + k * 2;
  fracs[0] = fracs[1] = 1;
  invfs[0] = invfs[1] = 1;
  for (int i = 2; i <= f; i++) {
    fracs[i] = (fracs[i - 1] * i) % MOD;
    invfs[i] = powmod(fracs[i], MOD - 2);
  }

  ll ans = 0;
  for (int x = 0, y = k; x <= k; x++, y--) {
    // right: n + x, left: x
    // up: m + y, down: y
    int nx2 = n + x * 2;
    int my2 = m + y * 2;
    ans =
      (ans +
       combmod(f, nx2) *
       ((combmod(nx2, x) + MOD - combmod(nx2, x - 1)) % MOD) % MOD *
       ((combmod(my2, y) + MOD - combmod(my2, y - 1)) % MOD) % MOD) % MOD;
  }

  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 4584
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}
 

void solve()
{
  int a,b;
  cin >> a >> b;

  if(a<=9 && b<=9)
  {
    cout<<a*b;
  }else cout<<"-1";
    
}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

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

//printVector(配列, 区切り文字)
template <typename T>
void printVector(vector<T> v, string delimiter) {
  for (int i=0; i<v.size(); i++) {
    if (i) cout << delimiter;
    cout << v[i];
  }
  cout << endl;
}

vector<int> insertionSort(vector<int> A) {
  for (int i=1; i<A.size(); i++) {
    printVector(A, " ");
    int tmp = A[i];
    int j = i-1;
    while (j>=0 && A[j]>tmp) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = tmp;
  }
  return A;
}
int main() {
  int n;
  cin >> n;

  std::vector<int> a(n);
  for (int i=0; i<n; i++) {
    cin >> a[i];
  }

  std::vector<int> b(n);
  b = insertionSort(a);
  printVector(b, " ");
}



Measured memory_bytes: 3200
task = input().split()
t_i = [int(s) for s in task]
cost = 0

for i in range(2):
    for j in range(2):
        if(t_i[j] > t_i[j+1]):
            t_i[j], t_i[j+1] = t_i[j+1], t_i[j]
cost = t_i[1] - t_i[0] + t_i[2] - t_i[1]
print(cost)

Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;
  ll sidx = 0;
  ll eidx = S.size() - 1;
  REP(i, 0, S.size() - 1) {
    if (S[i] == 'A') {
      sidx = i;
      break;
    }
  }
  REV(i, S.size() - 1, 1) {
    if (S[i] == 'Z') {
      eidx = i;
      break;
    }
  }
  cout << eidx - sidx + 1 << endl;

  return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
const int N=2005;
long long f[N][N],fac[N*N],inv[N*N];
long long fsp(long long x,int y){
	long long ans=1;
	while(y){
		if(y&1)	ans=ans*x%P;
		x=x*x%P,y>>=1;
	}
	return ans;
}
long long C(int n,int m){
	return fac[n]*inv[m]%P*inv[n-m]%P;
}
int n,m,k;
int main(){
	scanf("%d%d",&n,&k),m=n*k;
	fac[0]=inv[0]=f[0][0]=1;
	for(int i=1;i<=m;i++){
		fac[i]=fac[i-1]*i%P;
		inv[i]=fsp(fac[i],P-2);
	}
	if(k==1){
		puts("1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)
			f[i][j]=(f[i][j-1]*C(m-i-(j-1)*(k-1)-1,k-2)%P*(n-j+1)+f[i-1][j])%P;
	printf("%lld\n",f[n][n]);
	return 0;
}


Measured memory_bytes: 94464
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define INF 2000000000
using namespace std;

typedef long long ll;


int main(){
    int N;
    cin>>N;
    ll h[100005],dp[100005];
    for(int i = 0;i < N;i++){
        cin>>h[i];
        dp[i]=INF;
    }
    dp[0]=0;
    for(int i = 1;i < N;i++){
        dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>=2){
            dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
        }
    }
    cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
int main() {
    i64 n, x, d;
    cin >> n >> x >> d;
    if (d == 0) {
        cout << (x == 0 ? 1 : n+1) << endl;
        return 0;
    }
    map<i64, vector<pair<i64, int>>> evm;
    for (i64 k = 1; k < n; ++k) {
        i64 o = x * k,
            l = o + d * (k * (k - 1) / 2),
            r = o + d * (n * (n - 1) / 2 - (n - k) * (n - k - 1) / 2),
            m = max(o, -o) % max(d, -d);
        evm[m].emplace_back(min(l, r), -1);
        evm[m].emplace_back(max(l, r), 1);
    }
    evm[0].emplace_back(0, -1);
    evm[0].emplace_back(0, 1);
    i64 z = x * n + d * (n * (n - 1) / 2),
        m = n * max(x, -x) % max(d, -d);
    evm[m].emplace_back(z, -1);
    evm[m].emplace_back(z, 1);
    i64 ans = 0;
    for (auto&& p : evm) {
        auto evs = p.second;
        sort(begin(evs), end(evs));
        i64 lv = 0, ml = 0;
        // cerr << "--- " << p.first << endl;
        for (auto q : evs) {
            i64 v, type;
            tie(v, type) = q;
            if (lv == 0) {
                assert(type == -1);
                ml = v;
            }
            lv -= type;
            if (lv == 0) {
                assert(type == 1);
                assert((v - ml) % max(d, -d) == 0);
                ans += (v - ml) / max(d, -d) + 1;
            }
            // cerr << v << ' ' << type << ' ' << ans << endl;
        }
        assert(lv == 0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
using ll = long long;
using P = pair<ll, ll>;

const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void fail() {
    cout << -1 << endl;
    exit(0);
}

int main(){
    string s;
    cin >> s;
    ll K;
    cin >> K;
    for(ll i=0; i < s.size(); i++){
        if (s[i] > 'a' && 'z' - s[i] + 1 <= K) {
            K -= 'z' - s[i] + 1;
            s[i] = 'a';
        }
    }
    s[s.size() - 1] = 'a' + (s.back() - 'a' + K) % 26;
    cout << s << endl;
}

Measured memory_bytes: 592
s=str(input())
q=int(input())
a=[input()for i in range(q)]
b=0
c=""
d=""
if q<=10**5:
    for i in range(q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    if b==0:
        print(s)
    else:
        s= ''.join(list(reversed(s)))
        print(s)

else:
    for i in range(10**5):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    s=a[i][4]+s
                else:
                    s=s+a[i][4]
            else:
                if a[i][2]=="1":
                    s=s+a[i][4]
                else:
                    s=a[i][4]+s
    for i in range(10**5,q):
        if a[i]=="1":
            if b==0:
                b=1
            else:
                b=0
        else:
            if b==0:
                if a[i][2]=="1":
                    c=a[i][4]+c
                else:
                    d=d+a[i][4]
            else:
                if a[i][2]=="1":
                    d=d+a[i][4]
                else:
                    c=a[i][4]+c
    if b==0:
        print(c+s+d)
    else:
        c=''.join(list(reversed(c)))
        d=''.join(list(reversed(d)))
        s= ''.join(list(reversed(s)))
        print(d+s+c)


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll MOD = 1e9+7;
const ll INF = 1e18;

bool bingo[3][3];
int main(void)
{
    ll x,n; cin>>x>>n;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    sort(p.begin(),p.end());
    map<ll,ll> mp;
    rep(i,n) mp[p[i]]++;
    ll ans=-1,dist=1e9;
    for(int i=0;i<=101;i++){
        if(mp[i]>0) continue;
        if(abs(x-i)<dist){
            dist=abs(x-i);
            ans = i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
import java.util.*;
public class Main {

	private static int X(int [] a, int [] b, int C) {
		int num = 0;
		int sum = C;
		for (int i = 0; i < a.length; i++) {
			sum += a[i] * b[i];

		}
		if (sum > 0)
			num = 1;
		return num;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();
		
		int [][] A = new int [N][M];
		int [] B = new int [M];
		
		for ( int j = 0; j < M; j++) {
			B[j] = sc.nextInt();
		}
		
		for ( int i = 0; i < N; i++) {
			for ( int j = 0; j < M; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		
		int result = 0; 
		int count;
		for ( int i = 0; i < N; i++) {
			result += X(A[i], B, C);
		}
		
		System.out.println(result);
	}

}


Measured memory_bytes: 22356
#include <stdio.h>

int main() {
  
  int count;
  scanf("%d",&count);
  int height[count];
  for(int i=0; i<count; ++i){
  	scanf("%d",&height[i]);
  }
  int highest = 0;
  int sum = 0;
  for(int i=0; i<count; i=i+1){
   if(highest <= height[i]){
     	highest = height[i];
   		sum = sum + 1;
   }
  }
  
  printf("%d\n", sum);
  return 0;
}

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






int main(){
  



  long long n,m;
  cin>>n>>m;
  
  
  if (n>=2 and m>=2){
    cout<<(n-2)*(m-2)<<endl;
  }
  else if (n==1 and m>=2){
    cout<<m-2<<endl;
  }
  else if (n>=2 and m==1){
    cout<<n-2<<endl;
  }
  else if (n==1 and m==1){
    cout<<1<<endl;
  }
  

  
  


    
  
  
  
}

Measured memory_bytes: 256
local n = io.read("*n", "*l")
local t = {}
for i = 1, n do
  local s = io.read()
  if not t[s] then t[s] = 1
  else t[s] = t[s] + 1
  end
end
local cnt = 0
for k, v in pairs(t) do
  if cnt < v then
    cnt = v
  end
end
local ret = {}
for k, v in pairs(t) do
  if v == cnt then
    table.insert(ret, k)
  end
end
table.sort(ret)
print(table.concat(ret, "\n"))


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

using namespace std;
using i64 = int64_t;
#define int i64
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const i64 INFL = (1LL << 62);
const i64 MOD = 1000000007;

#undef int
int main() {
#define int i64
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 1001) {
    int c[3] = {i / 100, i / 10 % 10, i % 10};
    int index[3] = {-1, -1, -1};
    rep(j, 3) {
      if (j != 0 && index[j] == -1) break;
      for (int k = index[j] + 1; k < n; ++k) {
        if (s[k] == (c[j] + '0')) {
          if (j == 2) {
            ++ans;
            break;
          } else {
            index[j + 1] = k;
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

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


typedef long long ll;
#define MOD 1000000007

typedef long long ll;
#define MOD 1000000007
struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
// for prime mod
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint nCr (int n, int r)
{
  mint x = 1, y = 1;
  for (int i = 0; i < r; ++i) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    mint total = mint(2).pow(n);

    mint nCa = nCr(n,a);
    mint nCb = nCr(n,b);
    total -= nCa;
    total -= nCb;
    cout << total.x - 1 << endl;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
g = [[] for i in range(n)]
edges = []
res = [defaultdict(int) for i in range(n)]
for i in range(n-1):
    a,b = inpl()
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
    edges.append([a,b])
def dfs(e,prev_edge=-1):
    cnt = 1
    for ne in g[e]:
        if res[e][ne] or ne == prev_edge:
            continue
        if cnt == res[e][prev_edge]:
            cnt += 1
        res[e][ne] = cnt
        res[ne][e] = cnt
        dfs(ne,e)
        cnt += 1
dfs(0)
m = 0
for eee in g:
    m = max(m, len(eee))
print(m)
for a,b in edges:
    print(res[a][b])


Measured memory_bytes: 103208
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;


int main(){
	int P[200001];
	int N;
	cin >> N;

	for(int i = 0; i < N; ++i){
		int j;
		cin >> j;
		P[--j] = i;
	}

	int tmp = P[0], max_length = 1;
	int counter = 1;
	for(int i = 1; i < N; ++i){
		if(P[i - 1] < P[i]){
			counter++;
		} else{
			counter = 1;
		}
		max_length = MAX(max_length, counter);
	}

	cout << N - max_length << endl;

}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

set<int> G[MAX_N];
set<int> nG[MAX_N];
bool flag[MAX_N];
int w[MAX_N];
int n,m,opt;

void dfs(int s,int cost)
{
    if(nG[s].size() == 0){
        if(opt < cost){
            opt = cost;
        }
        return;
    }
    for(auto it = nG[s].begin(); it != nG[s].end() ;it++){
        dfs(*it,cost+w[(*it)]);
    }
    return;
}

int main()
{
	scanf("%d%d",&n,&m);
	rep(i,n){
		scanf("%d",&w[i]);
	}
    rep(i,m){
        int x,y;
        scanf("%d%d",&x,&y);
        G[x-1].insert(y-1);
        G[y-1].insert(x-1);
    }
    rep(i,n){
        flag[i] = false;
    }
    queue<P> que;
    for(int i=1;i<n;i++){
        if(G[i].size() == 1){
            flag[i] = true;
            if(*G[i].begin() == 0){
                nG[0].insert(i);
                continue;
            }
            G[*G[i].begin()].erase(i);
            if(G[*G[i].begin()].size() == 1){
                que.push(P(*G[i].begin(),i));
                flag[*G[i].begin()] = true;
                nG[*G[i].begin()].insert(i);
            }else{
                nG[*G[i].begin()].insert(i);
            }
        }
    }
    while(!que.empty()){
        P p = que.front();
        int u = p.first;
        que.pop();
        if(*G[u].begin() == 0){
            nG[0].insert(u);
            continue;
        }
        G[*G[u].begin()].erase(u);
        if(G[*G[u].begin()].size() == 1){
            que.push(P(*G[u].begin(),u));
            flag[*G[u].begin()] = true;
            nG[*G[u].begin()].insert(u);
        }else{
            nG[*G[u].begin()].insert(u);
        }
    }
    for(int i=1;i<n;i++){
        if(!flag[i]){
            if(nG[i].size() > 0){
                for(auto it = nG[i].begin(); it != nG[i].end() ;it++){
                    nG[0].insert(*it);
                }
                nG[i].clear();
            }
        }
    }
    int res = 0;
    for(int i = 1;i < n;i++){
        if(!flag[i]){
            res += w[i];
        }
    }
    dfs(0,w[0]);
    res += opt;
    printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 27104
a;b;main(t){
    scanf("%d%d",&a,&b);
    //t=b;while(t)t/=10,a*=10;
  	for(t=b;t;a*=10)t/=10;
    a+=b;    
    puts((pow((int)sqrt((float)a),2)==(float)a)?"Yes":"No");
}

Measured memory_bytes: 2076
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k,sum=0;scanf("%lld%lld",&n,&k);
	if(k==0)
	{
		printf("%lld\n",n*n);
		return 0;
	}
	for(int b=k+1;b<=n;b++)
	{
		int a=n%b;
		sum+=a-k>=0? a-k+1:0;
		sum+=n/b*(b-k);
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 128
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int e[200000][3];
long d[100001];
int search(int x, int l, int r){
	while(l<=r){
		int m=(l+r)/2;
		if(e[m][0]>=x) r=m-1; else l=m+1;
	}
	return l;
}

int main(void){
	int n, k, q, i;
	scanf("%d", &n);
	for(i=0; i<n-1; i++){
		int A, B, C;
		scanf("%d%d%d", &A, &B, &C);
		e[i*2][0]=A; e[i*2][1]=B; e[i*2][2]=C;
		e[i*2+1][0]=B; e[i*2+1][1]=A; e[i*2+1][2]=C;
	}
	scanf("%d%d", &q, &k);
	qsort(e, (n-1)*2, sizeof(int)*3, comp);

	int s[100000], S=0;
	d[k]=0;
	s[S++]=k;
	while(S>0){
		int p=s[--S];
		i=search(p, 0, (n-1)*2-1);
		for(; e[i][0]==p; i++){
			if(d[e[i][1]]==0){
				d[e[i][1]] = d[p] + e[i][2];
				s[S++]=e[i][1];
			}
		}
	}
	d[k]=0;

	for(i=0; i<q; i++){
		int x, y;
		scanf("%d%d", &x, &y);
		printf("%ld\n", d[x]+d[y]);
	}
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(void){

    int n;
    cin >> n;

    long long ans=1, a;
    bool zero = false, over = false;
    rep(i, n){
        cin >> a;
        if(a == 0){
            zero = true;
        } else if(ans <= 1000000000000000000 / a){
            ans *= a;
        } else {
            over = true;
        }
    }
    
    if(zero){
        cout << 0 << endl;
    } else if(over){
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;

}

Measured memory_bytes: 3588
#include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    #include<cctype>
    #include<climits>
    #include<iostream>
    #include<string>
    #include<vector>
    #include<map>
    #include<list>
    #include<queue>
    #include<deque>
    #include<algorithm>
    #include<numeric>
    #include<utility>
    #include<complex>
    #include<memory>
    #include<functional>
     
    using namespace std;
     
    #define ALL(g) (g).begin(),(g).end()
    #define REP(i, x, n) for(int i = x; i < n; i++)
    #define rep(i,n) REP(i,0,n)
    #define F(i,j,k) fill(i[0],i[0]+j*j,k)
    #define P(p) cout<<(p)<<endl;
    #define EXIST(s,e) ((s).find(e)!=(s).end())
    #define INF 1<<25
    #define pb push_back
     
    typedef vector<int> vi;
    typedef vector<long long> vl;
    typedef vector<double> vd;
    typedef pair<int,int> pii;
    typedef pair<long,long> pll;
    typedef long long ll;
     
    struct edge{
    	ll to,cost;
    };
     
    ll depth[100010];
    vector<edge> tree[100010];
     
    void dfs(int v,int p,ll d){
    	depth[v]=d;
    	for(edge e:tree[v]){
    		if(e.to==p)
    			continue;
    		dfs(e.to,v,d+e.cost);
    	}
    }
     
    int main(){
    	int n;
    	cin>>n;
    	rep(i,n-1){
    		int a,b,c;
    		cin>>a>>b>>c;
    		a--;b--;
    		tree[a].push_back({b,c});
    		tree[b].push_back({a,c});
    	}
    	int q,k;
    	cin>>q>>k;
    	k--;
    	dfs(k,-1,0);
    	rep(i,q){
    		int x,y;
    		cin>>x>>y;
    		x--;y--;
    		cout<<depth[x]+depth[y]<<endl;
    	}	
    	return 0;
    }

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

int gcd(int a,int b)
{
  if (a < b) return gcd(b,a);
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main()
{
  int n;
  vector<int> as;
  cin >> n;
  for(int i = 0; i < n; ++i){
    int a;
    cin >> a;
    as.push_back(a);
  }
  auto ans = as[0];
  for(auto v:as){
    ans = gcd(ans, v);
  }
  cout << ans << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a,b)+min(c,d) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

void solve(){
    int n;
    cin>>n;
    vi a(n);
    int sum=0;
    F0R(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    int curr=0;
    int ans=INT_MAX;
    F0R(i,n-1){
        curr+=a[i];
        ans=min(abs(sum-curr-curr),ans);
    }
    out(ans);

}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
//#define LOCAL

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int l, n, A[1000000];
long long cnt;
vector<int> G;

void insertionSort(int A[], int n, int g) {
	for(int i=g; i<n; ++i) {
		int v = A[i], j = i-g;
		while(j>=0 && A[j]>v) {
			A[j+g] = A[j];
			j -= g; ++cnt;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n) {
	for(int h=1;;) {
		if(h > n) break;
		G.push_back(h);
		h = 3*h+1;
	}
	for(int i=G.size()-1; i>=0; --i) {
		insertionSort(A, n, G[i]);
	}
}

int main()
{
	#ifdef LOCAL
			freopen("E:\\Temp\\input.txt", "r", stdin);
			freopen("E:\\Temp\\output.txt", "w", stdout);
	#endif

	scanf("%d", &n);
	for(int i=0; i<n; ++i) scanf("%d", &A[i]);
	cnt = 0;

	shellSort(A, n);
	printf("%d\n", G.size());
	for(int i=G.size()-1; i>=0; --i) {
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n%d\n", cnt);
	for(int i=0; i<n; ++i) printf("%d\n", A[i]);

	return 0;
}

Measured memory_bytes: 7196
#include <iostream>
using namespace std;
int l,a,b,c,d,ko,sa;
int main(){
	cin >>l;
	cin >>a;
	cin >>b;
	cin >>c;
	cin >>d;
	ko=a/c;
	if(a%c!=0)ko++;
	sa=b/d;
	if(b%d!=0)sa++;
	if(sa>ko){
		cout << l-sa<<endl;
	}else{
		cout << l-ko<<endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int n, x, h, y, v, w;
	while (~fscanf(stdin, "%d", &n), n) {
		v = 0;
		while(n--){
			fscanf(stdin, "%d%d%d%d", &x, &y, &h, &w);
				x += y + h;
				if (x <= 60 && w <= 2) v += 600;
				else if (x <= 80 && w <= 5) v += 800;
				else if (x <= 100 && w <= 10) v += 1000;
				else if (x <= 120 && w <= 15) v += 1200;
				else if (x <= 140 && w <= 20) v += 1400;
				else if (x <= 160 && w <= 25) v += 1600;
		}
		P(d, v);
	}
	return 0;
}

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

typedef long long ll;

/*
  let's try computer shogi!!!
 */


int main(){
  ll n;
  vector<ll> a;
  vector<ll> b;
  cin >> n ;
  a.resize(n);
  b.resize(n);
  for(ll i=0;i<n;++i){
    cin >> a[i];
    b[i] = 0;
  }
  ll sc = 0;
  ll add = a[n-1];
  ll id = n-1;
  if(a[0]!=0){
    cout<<"-1"<<endl;
    return 0;
  }
  for(ll i=n-1; i>0; --i){
    if(a[i] < b[i]){
      cout<<"-1"<<endl;
      return 0;
    }
    if(a[i-1] != a[i]-1){
      sc += add;
      cerr<<"add "<<add<<endl;
      if(id-add < 0 || a[i-1] < a[i]){
	cout<<"-1"<<endl;
	return 0;
      }
      /*
      for(ll j=0;j<add;++j){
	if(b[id-j-1] >= add-j-1){
	  break;
	}
	b[id-j-1] = add-j-1;
      }
      */
      id = i-1;
      add = a[i-1];
      cerr<<"add changed to "<<add<<" id"<<id<<endl;
    }
  }
  sc += add;
  cerr<<"ans"<<endl;
  cout<<sc<<endl;
  return 0;
}

Measured memory_bytes: 3328
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ret = 0
pre = -3
for i in range(N) :
    ret += B[A[i]-1]
    if A[i]-1 == pre + 1 :
        ret += C[pre]
    pre = A[i]-1
        
print(ret)

Measured memory_bytes: 38256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
 
int n, m;
ll d[1123];
int a[2123], b[2123], c[2123];
bool loop[1123];

int main() {
	cin >> n >> m;
	REP(i, m) {
		scanf("%d %d %d", a + i, b + i, c + i);
		a[i]--; b[i]--;
	}
	
	fill(d, d + n, -INF);
	d[0] = 0;
	
	REP(i, n - 1) {
		REP(j, m) {
			if (d[a[j]] == -INF) continue;
			chmax(d[b[j]], d[a[j]] + c[j]);
		}
	}
	
	REP(i, n + 1) {
		REP(j, m) {
			if (d[a[j]] == -INF) continue;
			if (chmax(d[b[j]], d[a[j]] + c[j])) loop[b[j]] = true;
		}
	}
	
	if (loop[n - 1]) puts("inf");
	else cout << d[n - 1] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j,d[110];
  char s[110],c[60];
  for(i=0;i<26;i++)c[i   ]=i+'a';
  for(i=0;i<26;i++)c[i+26]=i+'A';
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%d",&d[i]);
    scanf("%s",s);
    for(i=0;s[i];i++){
      for(j=0;c[j]-s[i];j++);
      printf("%c",c[(j-d[i%n]+52)%52]);
    }
    printf("\n");
  }
  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;



int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> d(3, -1);
    rep (i, m) {
        int s, c;
        cin >> s >> c;
        if (d[s - 1] != -1 && d[s - 1] != c) {
            cout << -1 << endl;
            return 0;
        }
        d[s - 1] = c;
    }

    if (n > 1 && d[0] == 0) {
        cout << -1 << endl;
        return 0;
    }
    if (n == 1) {
        if (d[0] == -1) cout << 0 << endl;
        else cout << d[0] << endl;
    } else if (n == 2) {
        rep (i, 2) {
            if (d[i] == -1) {
                if (i == 0) cout << 1;
                else cout << 0;
            }
            else cout << d[i];
        }
        cout << endl;
    } else{
        rep (i, 3) {
            if (d[i] == -1) {
                if (i == 0) cout << 1;
                else cout << 0;
            }
            else cout << d[i];
        }
        cout << endl;
    }
    
    return 0;
}



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

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

ll get(ll x){
    return x*(x-1)/2;
}

void solve(){ 
   ll n , k;
   cin >> n >> k;
   ll ans=0;
   
   for(ll i=k;i<=n+1;i++){
       ll MIN = get(i);
       ll MAX = n*i - get(i);
       ans += MAX - MIN + 1; 
       ans %= mod;
   }

   cout << ans << endl;
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    while(T--){  
        solve();
    }
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    int n;
    double a,m;
    while(1){
        cin >> n;
        if(n == 0)break;
        a = 0;
        int s[n] = {};
        for(int i=0;i<n;i++){
            cin >> s[i];
            a = a + s[i];
        }
        m = a / n;
        a = 0;
        for(int i=0;i<n;i++){
            a += (s[i]-m)*(s[i]-m);
        }
        a = a/n;
        a = sqrt(a);
        cout << fixed << a << endl;
    }
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;

ll N;
int main() {
  cin >> N;
  cout << (N-1) /2 << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
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(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	scanf("%d", &n);
	int t=-1;
	for (int x = 1; x*(x+1) <= 2*n; x++) {
		if (x*(x+1) == 2*n)t = x;
	}
	if (t == -1) {
		cout << "No" << endl;
		return 0;
	}
	VVI ans(t + 1, VI(t, 0));
	int k = 1, c = t, o = 0;
	REP(i, t) {
		REP(j, c) {
			ans[i][i + j] = j + k;
		}
		REP(j, c) {
			ans[i + j + 1][i] = j + k;
		}
		k += c;
		c--;
	}
	printf("Yes\n");
	printf("%d\n", t + 1);
	REP(i, t + 1) {
		printf("%d", t);
		REP(j, t) {
			printf(" %d", ans[i][j]);
		}
		printf("\n");
	}
	return 0;
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x=-1,y=-1;
    while(1){
        cin >> x>> y;
        if(x==0&&y==0)break;
        printf("%d %d\n",min(x,y),max(x,y));
    }
}


Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int N;
	cin >> N;
	vector<int> a(N);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int res = (int)1 << 60;
	int ts = 0;
	for (int i = 0; i < N; i++) {
		if (i > 0) {
			res = min(res, abs(sum - 2 * ts));
		}
		ts += a[i];
	}
	cout << res << endl;
	return 0;
	
}

Measured memory_bytes: 1792
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
 
        int[][] list1 = new int[a][b];
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                list1[i][j] = scanner.nextInt();
            }
        }
        int[][] list2 = new int[b][c];
        for (int i = 0; i < b; i++)
            for (int j = 0; j < c; j++)
                list2[i][j] = scanner.nextInt();
 
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < c; j++) {
                long sum = 0;
                for (int k = 0; k < b; k++) {
                    sum += list1[i][k] * list2[k][j];
                }
                if (j == 0)
                    System.out.print(sum);
                else
                    System.out.print(" " + sum);
            }
            System.out.println();
        }
 
    }
}


Measured memory_bytes: 52384
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

def func(string):
    if string == "r":
        return P
    if string == "s":
        return R
    if string == "p":
        return S

ans = 0
for k in range(K):
    ans += func(T[k])

boolean_lis = [True] * N
#boolean_lis[0] = 

for n in range(K, N):
    if T[n - K] != T[n]:
        ans += func(T[n])
    elif T[n - K] == T[n]:
        if not boolean_lis[n - K]:
            ans += func(T[n])
        else:
            boolean_lis[n] = False
    #print(ans)
print(ans)
#print(*boolean_lis)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s,p;cin>>s;
  for(int i=0;i<p.length();i++)if(s.at(i)>='A'&s.at(i)<='Z')s.at(i)+='a'-'A';
  int cnt=0;
  while(cin>>p){
    if(p=="END_OF_TEXT")break;
    for(int i=0;i<p.length();i++){
      if(p.at(i)>='A'&p.at(i)<='Z')p.at(i)+='a'-'A';
    }
    if(p==s)cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 3144