akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	string s;
	long long k, len;
	cin >> s >> k;
	len = s.length();
	long long ans = 0, cnt = 0;
	if (s[0] != s[len - 1])
	{
		cnt = 1;
		for (int i = 1; i < len; i++)
		{
			if (s[i] == s[i - 1])cnt++;
			else {
				ans += cnt / 2;
				cnt = 1;
			}
		}
		ans += cnt / 2;
		cout << ans * k << endl;
	}
	else
	{
		cnt = 1;
		long long tot = 1;
		for (int i = 1; i < len; i++)
		{
			if (s[i] == s[0]) {
				tot++; continue;
			}
			if (s[i] == s[i - 1])cnt++;
			else {
				ans += cnt / 2;
				cnt = 1;
			}
		}
		ans += cnt / 2;
		ans *= k;
		if (tot == len)
		{
			cout << tot * k / 2 << endl;
			return 0;
		}
		ans += tot / 2 * (k - 1);
		cnt = 1;
		for (int i = 1; i < len; i++)
		{
			if (s[i] == s[0])cnt++;
			else
			{
				ans += cnt / 2;
				cnt = 1;
				break;
			}
		}
		for (int i = len - 2; i >= 0; i--)
		{
			if (s[i] == s[0])cnt++;
			else
			{
				ans += cnt / 2;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(void){
    int n;
    string s;
    int M = 1000000007;
    long long int ans = 1;
    int x[26] = {0};

    cin >> n;
    cin >> s;

    for(int i = 0; i < n; i++){
        x[s[i] - 'a']++;
    }

    for(int i = 0; i < 26; i++){
        ans *= (x[i] + 1);
        ans %= M;
    }

    cout << ans - 1 << endl;

    return 0;
}

Measured memory_bytes: 512
I=input
n=int
for i in range(n(input())):
  I();t=[];x=0
  for i,j in zip(map(n,I().split()[::-1]),I()[::-1]):
    for k in t:i^=k*(i^k<i)
    j=n(j);t.append(i*(j^1));x|=(i>0)&j
  print(x)

Measured memory_bytes: 9044
#include<cstdio>
using namespace std;
int a[1001],b[1001];
int main()
{
	int n,l,min=200,minn=0,ans=0;
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)
	{
		a[i]=l+i-1;
		if(a[i]<=0)b[i]=0-a[i];
		else b[i]=a[i];
		if(b[i]<=min){
			min=b[i];
			minn=i;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(i==minn)continue;
		ans+=a[i];
	}
	printf("%d",ans);
	
	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int count=0;
  int k = s.size()%2;
  for(int i=0; i<(s.size()/2); i++){
        if(s[i]!=s[s.size()-i-1]){
          count++;
      }
  }

    cout << count << endl;

  return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> array(n);
    for(int i=0; i<n; i++) cin >> array.at(i);
    for(int i=0; i<n-k; i++){
        int before = array.at(i);
        int after = array.at(i+k);
        if(before < after){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 3968
def round_off(a):
    return int((2*a+1)//2)


sum1, sum2, count = 0, 0, 0
while 1:
    try:
        a, b = map(int, input().split(','))
        sum1 += a * b
        sum2 += b
        count += 1
    except:
        break

print(sum1)
print(round_off(sum2/count))



Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S == "SAT") printf("1");
	else if (S == "FRI") printf("2");
	else if (S == "THU") printf("3");
	else if (S == "WED") printf("4");
	else if (S == "TUE") printf("5");
	else if (S == "MON") printf("6");
	else printf("7");
	return 0;
}

Measured memory_bytes: 256
/*

	Code by : Ivan Zanov
	Competitione 2020
	First Competition

*/
#include <chrono>
#include <iostream>
#include <utility>
#include <bitset>
#include <vector>
#include <set>
#include <unordered_map>
#include <map>
#include <assert.h>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <memory>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <sstream>
#include <exception>
#include <functional>
#include <cstring>
#include <cstdlib>
using namespace std;
using namespace std :: chrono;
#define lowbit(x) ((x)&((x)^((x)-1)))
#define max(a,b) (a<b?b:a)
#define IOS ios_base::sync_with_stdio(0);
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define INF (int)1e9
#define EPS (int)1e-9
#define bit_count __builtin_popcount
#define gcd __gcd
#define max3(a, b, c) max(a, max(b,c))
#define min3(a, b, c) min(a, min(b,c))
#define abs(x) (x < 0 ? (-x) : x)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
inline void set_bit(int & n, int b) { n |= (1 << (int) b); }
inline void unset_bit(int & n, int b) { n &= ~(1 << (int) b); }
inline bool check_bit(int n, int pos) { return ( n & (1 << (pos))); }
inline ll lcm(ll a, ll b){ return (a * b / gcd(a,b));}
inline ll square(ll a){return (a * a);}
int main() {
	int n, r;
	cin>>n>>r;
	if(n >= 10)
		cout<<r<<endl;
	else
	{
		cout<<r + 100 * (10 - n)<<endl;
	}
	return 0;
	/*auto start = high_resolution_clock::now();
	auto end = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop - start);
	cout<<fixed<<setprecision(3)<<duration.count() * 1e-6<<endl;*/
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 606000;
int n,m;char s[N],t[N];map<ll,char>Map;
int gcd(int a, int b){return !b?a:gcd(b,a%b);}
int main() {
	read(n);read(m);scanf("%s%s",s,t);//WA
	ll l=1LL*n*m/gcd(n,m);
	rep(i,0,n-1)Map[1+l/n*i]=s[i];
	rep(i,0,m-1)if(Map.count(1+l/m*i)&&Map[1+l/m*i]!=t[i]){
		puts("-1");return 0;
	}
	cout<<l;
	return 0;
}


Measured memory_bytes: 6144
import java.util.*;
import java.lang.*;

public class Main{

    public static void solve(long s , long w){
        if(w >= s){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
    }

    public static void gora(){
        Scanner scn = new Scanner(System.in);

        // long test = scn.nextLong();

        long s = scn.nextLong();

        long w = scn.nextLong();

        // long arr[] = new long[n];

        // for(int i = 0 ; i < arr.length ; i++){
        //     arr[i] = scn.nextLong();
        // }

        solve(s, w);
    }

    public static void main(String args[]){
        gora();
    }
}




Measured memory_bytes: 35760
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define y0 u9cqu3jioajc

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

const int MN = 100111;
const int MOD = 1e9 + 7;
int top;
int st[MN];

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9);
    int n;
    while (GI(n) == 1) {
        int res = 1;
        FOR(i,1,n) {
            int a; GI(a);
            if (!top) st[++top] = 1;
            else {
                int cur = st[top];
                if (a >= cur + 2) st[++top] = cur + 2;
                else {
                    res = res * (top + 1) % MOD;
                }
            }
        }
        while (top > 0) {
            res = res * top % MOD;
            --top;
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 1152
#include<stdio.h>

#define N 101
#define INF 100000000

int main(){

  int n, i, j, k, l;
  int m[N], o[N][N];

  scanf("%d", &n);

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

  for( i = 1; i <= n; i++) o[i][i] = 0;

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

      k = j + i - 1;
      o[j][k] = INF;

      for( l = j; l < k; l++){

	if(o[j][k] > o[j][l] + o[l+1][k] + m[j-1] * m[l] * m[k]){
	  o[j][k] = o[j][l] + o[l+1][k] + m[j-1] * m[l] * m[k];

	}
      }
    }
  }

  printf("%d\n", o[1][n]);

  return 0;
}

Measured memory_bytes: 632
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
//#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

#define int ll


const int N = 1e5+33, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;        // #include <ext/pb_ds/assoc_container.hpp>
typedef pair <ll, ll> pll;         // #include <ext/pb_ds/tree_policy.hpp>
typedef vector <int> vi;          // #include <ext/rope>
bool prime(int n) {
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}
#define endl '\n'
ll pw[N];

void solve() {
    pw[0] = 1;
    for(int i = 1; i < N; i ++) {
        pw[i] = pw[i-1] * 3ll % mod;
    }
    string s;
    cin >> s;
    reverse(all(s));
    vi v;
    for(int i = 0; i < s.size(); i ++) {
        if(s[i] == '1') {
            v.pb(i);
        }
    }
    int cnt = v.size() - 1;
    ll ans = 0;
    ll cur = 1;
    while(~cnt) {
        ans += cur * pw[v[cnt--]] % mod;
        ans %= mod;
        cur <<= 1ll;
        cur %= mod;
    }
    ans += cur;
    ans %= mod;
    cout << ans;
}
/*
101
    dp[i] = dp[i-1] + bp(2ll , bit(i));

110000000
011000000
001110000
000001111
5 3
3 2 2

2 4 1

_ _ _ _ _
1 1 1
  2 2 3 3

*/

main() {
    ios;
    int tt = 1;
//    cin >> tt;
    while(tt --) {
        solve();
//        brute();
    }
    return 0;
}


Measured memory_bytes: 2248
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, M; long long int L; 
	long long int INF = 1e16; 
	cin >> N >> M >> L; 
	long long int D[310][310] = {}; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i != j) D[i][j] = INF; 
		}
	}
	for(int i = 0; i < M; i++){
		int a, b, c; 
		cin >> a >> b >> c; 
		a--; b--; 
		if(c > L) continue; 
		D[a][b] = c; D[b][a] = c; 
	}
	for(int k = 0; k < N; k++){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				D[i][j] = min(D[i][k] + D[k][j], D[i][j]); 
			}
		}
	}
	long long int P[310][310] = {}; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i == j) continue; 
			if(D[i][j] <= L) P[i][j] = 1; 
			else P[i][j] = INF; 
		}
	}	
	for(int k = 0; k < N; k++){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				P[i][j] = min(P[i][k] + P[k][j], P[i][j]); 
			}
		}
	}
	int Q; cin >> Q; 
	for(int q = 0; q < Q; q++){
		int s, t; cin >> s >> t; 
		s--; t--; 
		if(P[s][t] == INF) cout << -1 << endl; 
		else cout << P[s][t] - 1 << endl; 
	}
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());

int main() {
ll n,k,q;
cin >> n >> k >> q;
int a;
ll num[n+1]={0};
REP(i,q) {
  cin >> a;
  num[a]++;
}
int ans;
for(int i=1;i<=n;i++) {
  ans = k-(q-num[i]);
  if(ans>0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int n, t;
    cin>>n>>t;
    cout<<(double)n / t<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    int sHalfLength = s.length() / 2;
    String sFront = "";
    String sBack = "";
    int count = 0;
    
    if (s.length() % 2 == 0) {
      sFront = s.substring(0, sHalfLength);
      sBack = s.substring(sHalfLength, s.length());
      for (int i = 0; i < sHalfLength; i++) {
        if (sFront.substring(i, i+1).equals(sBack.substring(sHalfLength - i - 1, sHalfLength - i))) {
        } else {
          count++;
        }
      }
    } else {
      sFront = s.substring(0, sHalfLength);
      sBack = s.substring(sHalfLength + 1);
      for (int i = 0; i < sHalfLength; i++) {
        if (sFront.substring(i, i+1).equals(sBack.substring(sHalfLength - i - 1, sHalfLength - i))) {
        } else {
          count++;
        }
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 24916
#include<cstdio>
#include<bitset>
#include<cmath>
using namespace std;

int h, w, a[80][80], b[80][80], mid = 6480;
bitset<12960> dp[80];
 
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &b[i][j]);
  dp[0][mid+a[0][0]-b[0][0]] = true;
  dp[0][mid-a[0][0]+b[0][0]] = true;
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (i + j > 0) {
    if (j != 0) dp[j] |= dp[j-1];
    int x = abs(a[i][j]-b[i][j]);
    dp[j] = (dp[j] >> x) | (dp[j] << x);
  }
  for (int i = 0;; i++) if (dp[w-1][mid-i] || dp[w-1][mid+i]) {
    printf("%d\n", i);
    return 0;
  }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define traceloop(x,a) {for(ll i=0;i<x;i++) cerr<<a[i]<<" "; cerr<<endl;}
ll ab(ll x) {return x>0LL?x:-x;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n;
	cin>>n;
	std::vector<ll> v(n),dp(n);
	for(int i=0; i<n; i++)
		cin>>v[i];
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(int i=2; i<n; i++)
	{
		dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2])); 
	}
	//traceloop(n,dp);
	cout<<dp[n-1];
	return 0;
}
	

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

string s;
ll k;

int main() {

	cin >> s >> k;

	int i = 0;

	while (s[i] == '1'){
		i++;
		if (i == k){
			i--;
			break;
		}
	}

	cout << s[i] << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
int N,M;
set<int> s1,s2;
int main(){
	cin>>N>>M;
	REP(i,M){
		int a,b;
		cin>>a>>b;
		if (a==1){
			s1.insert(b);
		}else if (b==N){
			s2.insert(a);
		}
	}
	bool ans=false;
	for(auto v:s1){
		if (s2.find(v)!=s2.end()){
			ans=true;
			break;
		}
	}
	cout<<(ans ? "POSSIBLE" : "IMPOSSIBLE")<<endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int ans = 0;
  
  for (int i = 1; i <= N; i++) {
    int x;
    cin >> x;
    
    if (x % 2 && i % 2) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3580
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

hash = { 1 => 0}
keiro = [1]
current = 1
nex = nil
count = 0
while true do
  nex = a[current-1]
  keiro.push(nex)
  break unless hash[nex].nil?
  count += 1
  hash[nex] = count
  current = nex
end

if keiro.size - 1 >= k
  puts keiro[k]
  exit
end

start = hash[nex]
loop = keiro[start..-1]

before_loop = keiro.size - loop.size
k = k - before_loop
k = k % (loop.size - 1)
puts loop[k]

Measured memory_bytes: 37984
import sys
N=int(input())
A=[int(input()) for i in range(N)]
B=sorted(A)
if N%2==0:
    C=B[:(N//2)]
    D=B[(N//2):]
    print(2*sum(D)-2*sum(C)+C[-1]-D[0])
    sys.exit()
C=B[:(N//2)]
D=B[((N//2)+1):]
s=B[(N//2)]
print(max(2*sum(D)-2*sum(C)+C[-1]-s,2*sum(D)-2*sum(C)+s-D[0]))

Measured memory_bytes: 52952
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if ((i+1) % 2 != 0 && a[i] % 2 != 0) {
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3556
#include<iostream>
using namespace std;
int main(){
  int a,b,c,x,i,j,k,total=0;
  cin>>a>>b>>c>>x;
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(k=0;k<=c;k++){
        if((i*500+j*100+k*50)==x)
          total++;
      }
    }
  }
  cout<<total<<"\n";
  return 0;
}

Measured memory_bytes: 764
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

T = int(raw_input())

for i in range(T):
    A,B,C,D = map(int,raw_input().split())
    if A<B:
        print 'No'
    elif B>D:
        print 'No'
    elif C>=B:
        print 'Yes'
    else:
        if A%B>C:
            print 'No'
        elif D%B==0:
            print 'Yes'
        elif gcd(D%B,B)>=B-C and ( (B-A%B)%(D%B)>=B-C or (B-A%B)%(D%B)==0):
            print 'Yes'
        else:
            print 'No'
        

Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define p pair<ll,ll>
ll N, M;
vector<p> A;

int main(){
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        ll add;
        cin >> add;
        A.push_back({add, 1});    
    }
    for(int i = 0; i < M; i++){
        ll B, C;
        cin >> B >> C;
        A.push_back({C, B});
    }
    ll ans = 0;
    sort(A.rbegin(), A.rend());
    for(auto u : A){
        if(N <= 0) break;
        ans += u.first * min(u.second, N);
        N -= u.second;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6256
from bisect import bisect_left
import sys
input = sys.stdin.readline


class BinaryIndexedTree():
    def __init__(self, N):
        self.N = N
        self.arr = [0] * (N+1)

    def query(self, i):
        ret = 0
        i += 1
        while i:
            ret += self.arr[i]
            lsb = i & (-i)
            i -= lsb
        return ret

    def add(self, i, v):
        i += 1
        while i < self.N+1:
            lsb = i & (-i)
            self.arr[i] += v
            i += lsb

    def search(self, x):
        lo = -1
        hi = self.N
        while lo < hi:
            mid = (lo+hi)//2
            if self.query(mid) < x:
                lo = mid + 1
            else:
                hi = mid
        return lo


def main():
    N, K = map(int, input().split())
    A = [int(input()) for _ in range(N)]
    B = [0] * (N+1)
    for i in range(N):
        B[i+1] = B[i] + A[i] - K
    sortedB = sorted(B)
    C = [0] * (N+1)
    bit = BinaryIndexedTree(N+1)
    ans = 0
    for i in range(N+1):
        x = bisect_left(sortedB, B[i])
        C[i] = x
        ans += bit.query(x)
        bit.add(C[i], 1)
    print(ans)


if __name__ == "__main__":
    main()


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

int main(void) {
  int r, D; cin >> r >> D;
  long long x; cin >> x;

  for (int i = 0; i < 10; i++) {
    x = r*x - D;
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[] = new int[n+1];
		for(int i=0; i<=n; i++) {
			a[i]=-1;
		}
		for(int i=0; i<m; i++) {
			int s = sc.nextInt();
			int c = sc.nextInt();
			if(a[s]!=-1 && a[s]!=c) {
				System.out.println(-1);
				sc.close();
				return;
			}
			a[s]=c;
		}
		int ans = 0;
		for(int i=1; i<=n; i++) {
			int d=-1;
			if(i==1) {
				if(n>1) {
					if(a[i]==0) {
						System.out.println(-1);
						sc.close();
						return;
					}else if(a[i]==-1) {
						d=1;
					} else {
						d=a[i];
					}
				}else {
					if(a[i]==-1) {
						d=0;
					}else {
						d=a[i];
					}
				}
			}else {
				if(a[i]==-1) {
					d=0;
				}else {
					d=a[i];
				}
			}
			ans = ans * 10 + d;
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 23892
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <vector>
#include <array>
#include <set>
#include <climits>
#include <sstream>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <numeric>
using namespace std;
using namespace __gnu_pbds;
typedef tree< // find_by_order & order_of_key
        int ,
        null_type ,
        less<int> ,
        rb_tree_tag ,
        tree_order_statistics_node_update 
> new_set;
#define MOD 1000000007
#define MAXW (int)(1e5+10000)
#define MAXN (int)(203)
long long dp[MAXN][MAXW];
array<pair<long long, long long>, MAXN>arr;
int main(void){
#ifdef HELL_JUDGE
    freopen("input","r",stdin);
    freopen("output","w",stdout);
    freopen("error","w",stderr);
#endif 
    memset(dp, 0ll, sizeof(dp));
    long long n, w; cin >> n >> w;
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i].first >> arr[i].second;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= w; ++j) {
            if (arr[i].first <= j) {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j - arr[i].first] + arr[i].second);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[n][w] << '\n';
    return 0;
}


Measured memory_bytes: 174720
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

using ll = long long;
using vll = vector<ll>;
using P = pair<ll, ll>;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e18;
const ll mod = 1e9 + 7;


int main(){
	IOS;
	string s;
	cin >> s;
	if(s.size() == 2){
		dump(s);
	}
	else {
		reverse(ALL(s));
		dump(s);
	}
}

Measured memory_bytes: 764
//A
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main(){

    int A,B;
    cin >> A >> B;
    if(A % 2 == 1 && B % 2 == 1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, Q; cin >> n >> Q;
	vector<vector<int>> tree(n);
	rep(i, 1, n - 1)
	{
		int a, b; cin >> a >> b;
		--a, --b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	vector<ll> counter(n);
	rep(i, 1, Q)
	{
		int p;
		ll x;
		cin >> p >> x;
		--p;
		counter[p] += x;
	}
	queue<pair<int, ll>> q;
	q.push({ 0,0 });
	vector<int> passed(n);
	while (!q.empty())
	{
		int pos = q.front().first;
		ll cnt = q.front().second;
		q.pop();
		if (!passed[pos])
		{
			passed[pos] = 1;
			cnt += counter[pos];
			counter[pos] = cnt;
			for (int next : tree[pos])
			{
				q.push({ next,cnt });
			}
		}
	}
	for (ll x : counter)cout << x << " ";
	cout << "" << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  if (a > b) swap(a, b);
  
  for (ll i = 0; i < n - 1; i++) {
    ll minUp = i * c;
    ll maxUp = i * d;
    ll minDown = (n - 1 - i) * c;
    ll maxDown = (n - 1 - i) * d;
    ll mini = a + minUp - maxDown;
    ll maxi = a + maxUp - minDown;
    if (mini <= b && b <= maxi) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


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

const int INF=1001001001;
vector<int>to[205];
int dp[205][205];
int color[205];

bool dfs(int v, int c=1){
    color[v]=c;
    for(int u:to[v]){
        if(color[u]==c)return false;
        if(color[u]==0&&!dfs(u,-c))return false;
    }
    return true;
}

int main(){
    int n;
    cin>>n;
    rep(i,n)rep(j,n){
        char c; cin>>c;
        if(c=='1')to[i].push_back(j);
    }
    //二部グラフ判定
    if(!dfs(0)){
        cout<<-1<<endl;
        return 0;
    }
    //WF
    rep(i,205)rep(j,205){
        dp[i][j]=INF;
        if(i==j)dp[i][j]=0;
    }
    rep(i,n)rep(j,to[i].size()){
        dp[i][to[i][j]]=1;
    }
    rep(k,n)rep(i,n)rep(j,n){
        dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    }
    int ans=0;
    rep(i,n)rep(j,n){
        ans=max(ans,dp[i][j]);
    }
    ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    ll a, b, c;
    ll k;
    cin >> a >> b >> c >> k;
    while (a >= b) {
        b *= 2;
        k--;
    }
    while (b >= c) {
        c *= 2;
        k--;
    }
    if (k >= 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL);
#define endl '\n'
using namespace std;


int main(){

    int a , b , c ;
    cin>>a>>b>>c;

    if(c >=a and c <= b )
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

vector<int> makesosu(int n){
    vector<char> line(n*2+1, 1);
    vector<int> res;
    for(int i=2;i<=n*2;++i){
        if(line[i]){
            res.push_back(i);
            for(int j=i*2;j<=n*2;j+=i)line[j]=0;
        }
    }
    return res;
}

int main(){
    string str;
    while(true){
        getline(cin, str);
        if(str==".")break;
        bool flag=true;
        stack<char> st;
        foreach(i, str){
            if(i=='('){
                st.push(i);
            }else if(i=='['){
                st.push(i);
            }else if(i==')'){
                if(st.empty()){
                    flag=false;
                    break;
                }
                if(st.top()=='['){
                    flag=false;
                    break;
                }
                st.pop();
            }else if(i==']'){
                if(st.empty()){
                    flag=false;
                    break;
                }
                if(st.top()=='('){
                    flag=false;
                    break;
                }
                st.pop();
            }
        }
        if(st.size())flag=false;
        cout << (flag?"yes":"no") << endl;
    }
    return 0;
}




Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>b)printf("a > b\n");
	else if(a<b)printf("a < b\n");
	else printf("a == b\n");
return 0;
}

Measured memory_bytes: 1168
int main(void){
 int W = 0;
 int H = 0;
 int x = 0;
 int y = 0;
 int r = 0;
 
 scanf("%d %d %d %d %d", &W , &H , &x , &y ,&r);
 
 if(0<=(x-r) && (x+r)<=W){
  if(0<=(y-r) && (y+r)<=H){
   printf("Yes\n");
  }else{
   printf("No\n");
  }
 }else{
  printf("No\n");
 }
 return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
int main(){
	int a[100];
	int total=0;
	int i;
	int max=0;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
		if(max<a[i]){
		max=a[i];
	}
}
	for(i=0;i<3;i++){
		total+=a[i];
	}
	total=total-max;
	if(max!=total){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
}

Measured memory_bytes: 128
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        long[] w = new long[N];
        long[] v = new long[N];
        for(int i=0;i<N;i++){
            w[i] = sc.nextLong();
            v[i] = sc.nextLong();
        }
        ArrayList<Long>[] a1 = new ArrayList[4];
        for(int i=0;i<4;i++) a1[i] = new ArrayList<>();
        for(int i=0;i<N;i++){
            a1[(int)(w[i]-w[0])].add(v[i]);
        }
        Long[][] map = new Long[4][];
        for(int i=0;i<4;i++){
            map[i] = new Long[a1[i].size()];
            map[i] = a1[i].toArray(map[i]);
            Arrays.sort(map[i],Comparator.reverseOrder());
        }
        long[][] sum = new long[4][];
        for(int i=0;i<4;i++){
            sum[i] = new long[map[i].length+1];
            for(int j=1;j<sum[i].length;j++){
                sum[i][j] = sum[i][j-1]+map[i][j-1];
            }
        }
        long ans = 0;
        for(int a=0;a<sum[0].length;a++){
            for(int b=0;b<sum[1].length;b++){
                for(int c=0;c<sum[2].length;c++){
                    for(int d=0;d<sum[3].length;d++){
                        long cur = sum[0][a]+sum[1][b]+sum[2][c]+sum[3][d];
                        long weight = (a+b+c+d)*w[0]+b+2*c+3*d;
                        if(weight<=W) ans = Math.max(ans,cur);
                    }
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    vector<Pi> sc;
    int n,m;cin>>n>>m;
    int keta[n],l=1;
    for(int i=n-1;i>=0;i--){
        keta[i]=l;
        l*=10;
    }
    rep(i,m){
        int x,y;cin>>x>>y;
        Pi tmp=make_pair(x,y);
        sc.push_back(tmp);
    } 
    sort(sc.begin(),sc.end());
    rep(i,m-1){
        if(sc[i].first==sc[i+1].first and sc[i].second!=sc[i+1].second){
            cout<<"-1"<<endl;
            return 0;
        }
    }
    int ans[n]={};
    if(n>1) ans[n-1]=1;
    int p=0;
    rep(i,m){
        if(n>1 and sc[i].first==1 and sc[i].second==0){
            cout<<"-1"<<endl;
            return 0;
        }
        ans[n-sc[i].first]=sc[i].second;
    }
    rep(i,n){
        p+=ans[i]*keta[n-i-1];
        //cout<<ans[i]<<endl;
        //cout<<p<<endl;
    }
    cout<<p<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long P, vector<long long> A) {
  bool isOdd = false;

  REP(i, N) if (A[i] % 2 != 0) isOdd = true;

  if (!isOdd && P == 1) {
    cout << "0" << endl;
    return;
  }

  ll ans = isOdd ? pow(2, N - 1) : pow(2, N);

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long P;
  long long N;
  cin >> N;
  vector<long long> A(N - 1 + 1);
  cin >> P;
  for (int i = 0; i <= N - 1; i++) {
    cin >> A[i];
  }
  solve(N, P, A);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
//#include<math.h>
//#include <algorithm>
//#include <functional>
//#include <numeric>
//#include<cmath>
//#include <stdio.h> 
//#include <cstdint>
//#include <string>
//#include <cstdlib>
//#define pi 3.14159265359
using namespace std;

int main() {

	
	uint64_t a;
	cin >> a;
	uint64_t sum=0;
	vector<uint64_t> b(a);
	for (uint64_t i = 0; i < a; i++) {
		cin >> b[i];
		sum += b[i];
	}

	uint64_t sum_half = 0;
	uint64_t sum_half_before = 0;
	uint64_t num_half = 0;
	while (sum_half < sum / 2) {
		sum_half_before = sum_half;
		sum_half += b[num_half];
		num_half ++;
	}

	if (sum_half == sum / 2) {
		cout << 0;
	}
	/*
	else {
		cout << sum_half * 2 - sum;
	}
	*/

	else if((sum_half-sum/2)<=(sum/2-sum_half_before)){
		cout << sum_half*2 - sum;
	}
	else {
		cout <<  sum- sum_half_before * 2;
	}
	

	return 0;

}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>

using namespace std;

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

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

    int maxPrice = 0;
    int sumPrice = 0;
    for(int i = 0; i < n; i++){
        maxPrice = max(maxPrice, p[i]);
        sumPrice += p[i];
    }

    sumPrice -= maxPrice/2;

    cout << sumPrice << endl;

    return 0;

}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> semi(n,vector<int>(m));
	REP(i, n){
		string s;
		cin >> s;
		REP(j, m){
			semi[i][j] =s[j]-'0';
		}
	}
	vector<vector<int>> dp(n, vector<int>(m));
	REP(i, n){
		REP(j, m){
			int a=1234;
			int b=1234;
			if (i != 0)a = dp[i - 1][j] + semi[i][j];
			if (j != 0)b = dp[i][j - 1] + semi[i][j];
			dp[i][j] = min(a,b);
			if (!(i | j))dp[0][0] = 0;
		}
	}
	cout << dp[n - 1][m - 1] << endl;
}

Measured memory_bytes: 3232
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775808;

int main() {
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a, a + N);
    int now = -1;
    int num = 1;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (now != a[i]) {
            if (now != -1 && now <= num) {
                ans += num - now;
            } else if (now != -1 && now > num) {
                ans += num;
            }
            now = a[i];
            num = 1;
        } else {
            num++;
        }
    }
    if (now <= num) {
        ans += num - now;
    } else {
        ans += num;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define L long long
#define LL long long
#define SS string
#define PB push_back
#define pp pair<L,L>
#define f(x,n) for (L i = x ; i <= n ; i++)
#define N 100005
using namespace std;
L visited[N];
L a[N][3] , h[N][3];
L n ,k;
L recursivedpMaximumcost(L i , L j)
{
    if (a[i][j])
    return a[i][j];
    if (j==0)
    a[i][j] = max(recursivedpMaximumcost(i-1,2)+h[i][j],recursivedpMaximumcost(i-1,1)+h[i][j]);

    else if (j == 1)
    a[i][j] = max(recursivedpMaximumcost(i-1,2)+h[i][j],recursivedpMaximumcost(i-1,0)+h[i][j]);

    else
    a[i][j] = max(recursivedpMaximumcost(i-1,1)+h[i][j],recursivedpMaximumcost(i-1,0)+h[i][j]);
    return a[i][j];
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    f(1,n)
    {
        cin >> h[i][0] >> h[i][1] >> h[i][2];
    }
    a[1][0] = h[1][0];
    a[1][1] = h[1][1];
    a[1][2] = h[1][2];
    cout << max(recursivedpMaximumcost(n,0),max(recursivedpMaximumcost(n,1)
    ,recursivedpMaximumcost(n,2)));
    return 0; 
}

Measured memory_bytes: 9600
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
  X = parseInt(readline())
  if 400<= X
    if 600> X
      println(8)
    end
  end
  if 600<= X
    if 800> X
      println(7)
    end
  end
  if 800<= X
    if 1000> X
      println(6)
    end
  end
  if 1000<= X
    if 1200> X
      println(5)
    end
  end
  if 1200<= X
    if 1400> X
      println(4)
    end
  end
  if 1400<= X
    if 1600> X
      println(3)
    end
  end
  if 1600<= X
    if 1800> X
      println(2)
    end
  end
  if 1800<= X
    if 2000> X
      println(1)
    end
  end
end
main()


Measured memory_bytes: 156376
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
const int maxn = 1e5 + 7;
using ll = long long ;
char s[maxn],t[maxn];
int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    scanf("%s%s",s,t);
    ll lcm = n * m / __gcd(n,m);
    bool ok = 1;
    for(ll i=0,j=0;i<n&&j<m;)
    {
        ll N = i * lcm / n + 1;
        ll M = j * lcm / m + 1;
        if(M==N)
        {
            if(s[i]!=t[j])
            {
                ok = 0 ;
                break;
            }
            else ++j;
        }
        else if(M<N)j++;
        else i++;
    }
    if(ok)
    {
        cout << lcm << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;


int N;

void rec(string S, int maximum) {
    if (S.length() == N) {
        cout << S << endl;
    } else {
        rep(i,maximum+1) rec(S + (char)('a' + i), maximum);
        rec(S + (char)('a' + maximum + 1), maximum + 1);
    }
}

int main() {

    cin >> N;

    rec("a", 0);
    
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    if (A+B == C+D) {
        cout << "Balanced" << endl;
    } else if (A+B > C+D) {
        cout << "Left" << endl;
    } else if (A+B < C+D) {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;
 
int main(){
  ll a;
  string b;
  cin >> a >> b;
  ll b2 = (b[0]-'0')*100 + (b[2] - '0')*10 + (b[3] - '0');
  //out << b2 << endl;
  cout <<ll((a*b2)/100) << endl;
  
} 

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

int top, S[1000];

void push(int x) {
  top++;
  S[top] = x;
}

int pop() {
  top--;
  return S[top+1];
}

int main() {
  int a, b;
  top = 0;
  char s[100];

  while( scanf("%s", s) != EOF ) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      b = pop();
      a = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }

  cout << pop() << endl;

  return 0;
}


Measured memory_bytes: 3156
import java.io.{PrintWriter, _}
import java.util._


object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  def ?(item: Boolean, first: Object, second: Object): Object = if (item) first else second

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val arr = new Array[Int](5)
      for {
        i <- 0 to 4
      } yield arr(i) = in.nextInt
      arr.sorted
      val k = in.nextInt
      out.println(?(arr(4) - arr(0) <= k, "Yay!", ":("))
    }

  }


  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new StringTokenizer("")


    def next: String = {
      while ( {
        tokenizer == null || !tokenizer.hasMoreTokens
      }) try
        tokenizer = new StringTokenizer(reader.readLine)
      catch {
        case e: IOException =>
          throw new RuntimeException(e)
      }
      tokenizer.nextToken
    }

    def nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


Measured memory_bytes: 25408